Nikolay Sivov : comctl32/ipaddress: Store current IP address text as a window text for IP Address control.

Alexandre Julliard julliard at winehq.org
Tue Mar 24 09:01:57 CDT 2009


Module: wine
Branch: master
Commit: 85c03a5a3160814ac21d76b624c98f9b7a935e95
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=85c03a5a3160814ac21d76b624c98f9b7a935e95

Author: Nikolay Sivov <bunglehead at gmail.com>
Date:   Mon Mar 23 16:08:02 2009 -0400

comctl32/ipaddress: Store current IP address text as a window text for IP Address control.

---

 dlls/comctl32/ipaddress.c       |   26 +++++++++++
 dlls/comctl32/tests/Makefile.in |    1 +
 dlls/comctl32/tests/ipaddress.c |   89 +++++++++++++++++++++++++++++++++++++++
 include/commctrl.h              |    2 +-
 4 files changed, 117 insertions(+), 1 deletions(-)

diff --git a/dlls/comctl32/ipaddress.c b/dlls/comctl32/ipaddress.c
index 15d39f5..e5631a2 100644
--- a/dlls/comctl32/ipaddress.c
+++ b/dlls/comctl32/ipaddress.c
@@ -77,6 +77,29 @@ static const WCHAR IP_SUBCLASS_PROP[] =
 static LRESULT CALLBACK
 IPADDRESS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
+static void IPADDRESS_UpdateText (const IPADDRESS_INFO *infoPtr)
+{
+    static const WCHAR zero[2] = {'0', 0};
+    static const WCHAR dot[2]  = {'.', 0};
+    WCHAR field[4];
+    WCHAR ip[16];
+    INT i;
+
+    ip[0] = 0;
+
+    for (i = 0; i < 4; i++) {
+        if (GetWindowTextW (infoPtr->Part[i].EditHwnd, field, 4))
+            strcatW(ip, field);
+        else
+            /* empty edit treated as zero */
+            strcatW(ip, zero);
+        if (i != 3)
+            strcatW(ip, dot);
+    }
+
+    SetWindowTextW(infoPtr->Self, ip);
+}
+
 static LRESULT IPADDRESS_Notify (const IPADDRESS_INFO *infoPtr, UINT command)
 {
     HWND hwnd = infoPtr->Self;
@@ -219,6 +242,8 @@ static LRESULT IPADDRESS_Create (HWND hwnd, const CREATESTRUCTA *lpCreate)
         EnableWindow(part->EditHwnd, infoPtr->Enabled);
     }
 
+    IPADDRESS_UpdateText (infoPtr);
+
     return 0;
 }
 
@@ -561,6 +586,7 @@ IPADDRESS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 	case WM_COMMAND:
 	    switch(wParam >> 16) {
 		case EN_CHANGE:
+		    IPADDRESS_UpdateText(infoPtr);
 		    IPADDRESS_Notify(infoPtr, EN_CHANGE);
 		    break;
 		case EN_KILLFOCUS:
diff --git a/dlls/comctl32/tests/Makefile.in b/dlls/comctl32/tests/Makefile.in
index 45bd219..6fe2000 100644
--- a/dlls/comctl32/tests/Makefile.in
+++ b/dlls/comctl32/tests/Makefile.in
@@ -11,6 +11,7 @@ CTESTS = \
 	dpa.c \
 	header.c \
 	imagelist.c \
+	ipaddress.c \
 	listview.c \
 	misc.c \
 	monthcal.c \
diff --git a/dlls/comctl32/tests/ipaddress.c b/dlls/comctl32/tests/ipaddress.c
new file mode 100644
index 0000000..32ecdc1
--- /dev/null
+++ b/dlls/comctl32/tests/ipaddress.c
@@ -0,0 +1,89 @@
+/* Unit test suite for IP Address control.
+ *
+ * Copyright 2009 Nikolay Sivov
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+
+#include <windows.h>
+#include <commctrl.h>
+#include <assert.h>
+
+#include "wine/test.h"
+
+#define expect(expected, got) ok(expected == got, "expected %d, got %d\n", expected,got)
+
+static HWND create_ipaddress_control (void)
+{
+    HWND handle;
+
+    handle = CreateWindowEx(0, WC_IPADDRESS, NULL,
+			    WS_BORDER|WS_VISIBLE, 0, 0, 0, 0,
+			    NULL, NULL, NULL, NULL);
+    assert(handle);
+
+    return handle;
+}
+
+static void test_get_set_text(void)
+{
+    HWND hwnd;
+    CHAR ip[16];
+    INT r;
+
+    hwnd = create_ipaddress_control();
+
+    /* check text just after creation */
+    r = GetWindowText(hwnd, ip, sizeof(ip)/sizeof(CHAR));
+    expect(7, r);
+    ok(strcmp(ip, "0.0.0.0") == 0, "Expected null IP address, got %s\n", ip);
+
+    SendMessage(hwnd, IPM_SETADDRESS, 0, MAKEIPADDRESS(127, 0, 0, 1));
+    r = GetWindowText(hwnd, ip, sizeof(ip)/sizeof(CHAR));
+    expect(9, r);
+    ok(strcmp(ip, "127.0.0.1") == 0, "Expected 127.0.0.1, got %s\n", ip);
+
+    DestroyWindow(hwnd);
+}
+
+static int init(void)
+{
+    HMODULE hComctl32;
+    BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
+    INITCOMMONCONTROLSEX iccex;
+
+    hComctl32 = GetModuleHandleA("comctl32.dll");
+    pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
+    if (!pInitCommonControlsEx)
+    {
+        skip("InitCommonControlsEx() is missing. Skipping the tests\n");
+        return 0;
+    }
+
+    iccex.dwSize = sizeof(iccex);
+    iccex.dwICC  = ICC_USEREX_CLASSES;
+    pInitCommonControlsEx(&iccex);
+
+    return 1;
+}
+
+START_TEST(ipaddress)
+{
+    if (!init())
+        return;
+
+    test_get_set_text();
+}
diff --git a/include/commctrl.h b/include/commctrl.h
index b055bee..bebdb27 100644
--- a/include/commctrl.h
+++ b/include/commctrl.h
@@ -4459,7 +4459,7 @@ typedef struct tagNMIPADDRESS
 #define MAKEIPRANGE(low,high) \
     ((LPARAM)(WORD)(((BYTE)(high)<<8)+(BYTE)(low)))
 #define MAKEIPADDRESS(b1,b2,b3,b4) \
-    ((LPARAM)(((DWORD)(b1)<<24)+((DWORD)(b2)<16)+((DWORD)(b3)<<8)+((DWORD)(b4))))
+    ((LPARAM)(((DWORD)(b1)<<24)+((DWORD)(b2)<<16)+((DWORD)(b3)<<8)+((DWORD)(b4))))
 
 #define FIRST_IPADDRESS(x)	(((x)>>24)&0xff)
 #define SECOND_IPADDRESS(x)	(((x)>>16)&0xff)




More information about the wine-cvs mailing list