Mikołaj Zalewski : comctl32: listview: Create the LISTVIEW_INFO in WM_NCCREATE.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Feb 8 06:20:42 CST 2007


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

Author: Mikołaj Zalewski <mikolaj at zalewski.pl>
Date:   Wed Feb  7 21:12:52 2007 +0100

comctl32: listview: Create the LISTVIEW_INFO in WM_NCCREATE.

---

 dlls/comctl32/listview.c       |   89 ++++++++++++++++++++++++++--------------
 dlls/comctl32/tests/listview.c |   29 +++++++++++++
 2 files changed, 87 insertions(+), 31 deletions(-)

diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c
index 91cafca..208d28b 100644
--- a/dlls/comctl32/listview.c
+++ b/dlls/comctl32/listview.c
@@ -7673,17 +7673,17 @@ static CALLBACK VOID LISTVIEW_DelayedEdi
 
 /***
  * DESCRIPTION:
- * Creates the listview control.
+ * Creates the listview control - the WM_NCCREATE phase.
  *
  * PARAMETER(S):
  * [I] hwnd : window handle
  * [I] lpcs : the create parameters
  *
  * RETURN:
- *   Success: 0
- *   Failure: -1
+ *   Success: TRUE
+ *   Failure: FALSE
  */
-static LRESULT LISTVIEW_Create(HWND hwnd, const CREATESTRUCTW *lpcs)
+static LRESULT LISTVIEW_NCCreate(HWND hwnd, const CREATESTRUCTW *lpcs)
 {
   LISTVIEW_INFO *infoPtr;
   UINT uView = lpcs->style & LVS_TYPEMASK;
@@ -7693,7 +7693,7 @@ static LRESULT LISTVIEW_Create(HWND hwnd
 
   /* initialize info pointer */
   infoPtr = Alloc(sizeof(LISTVIEW_INFO));
-  if (!infoPtr) return -1;
+  if (!infoPtr) return FALSE;
 
   SetWindowLongPtrW(hwnd, 0, (DWORD_PTR)infoPtr);
 
@@ -7701,8 +7701,7 @@ static LRESULT LISTVIEW_Create(HWND hwnd
   infoPtr->dwStyle = lpcs->style;
   /* determine the type of structures to use */
   infoPtr->hwndNotify = lpcs->hwndParent;
-  infoPtr->notifyFormat = SendMessageW(infoPtr->hwndNotify, WM_NOTIFYFORMAT,
-                                       (WPARAM)infoPtr->hwndSelf, (LPARAM)NF_QUERY);
+  /* infoPtr->notifyFormat will be filled in WM_CREATE */
 
   /* initialize color information  */
   infoPtr->clrBk = CLR_NONE;
@@ -7731,12 +7730,58 @@ static LRESULT LISTVIEW_Create(HWND hwnd
   infoPtr->hFont = infoPtr->hDefaultFont;
   LISTVIEW_SaveTextMetrics(infoPtr);
 
+  /* allocate memory for the data structure */
+  if (!(infoPtr->selectionRanges = ranges_create(10))) goto fail;
+  if (!(infoPtr->hdpaItems = DPA_Create(10))) goto fail;
+  if (!(infoPtr->hdpaPosX  = DPA_Create(10))) goto fail;
+  if (!(infoPtr->hdpaPosY  = DPA_Create(10))) goto fail;
+  if (!(infoPtr->hdpaColumns = DPA_Create(10))) goto fail;
+
+  /* initialize the icon sizes */
+  set_icon_size(&infoPtr->iconSize, infoPtr->himlNormal, uView != LVS_ICON);
+  set_icon_size(&infoPtr->iconStateSize, infoPtr->himlState, TRUE);
+  return TRUE;
+
+fail:
+    DestroyWindow(infoPtr->hwndHeader);
+    ranges_destroy(infoPtr->selectionRanges);
+    DPA_Destroy(infoPtr->hdpaItems);
+    DPA_Destroy(infoPtr->hdpaPosX);
+    DPA_Destroy(infoPtr->hdpaPosY);
+    DPA_Destroy(infoPtr->hdpaColumns);
+    Free(infoPtr);
+    return FALSE;
+}
+
+/***
+ * DESCRIPTION:
+ * Creates the listview control - the WM_CREATE phase. Most of the data is
+ * already set up in LISTVIEW_NCCreate
+ *
+ * PARAMETER(S):
+ * [I] hwnd : window handle
+ * [I] lpcs : the create parameters
+ *
+ * RETURN:
+ *   Success: 0
+ *   Failure: -1
+ */
+static LRESULT LISTVIEW_Create(HWND hwnd, const CREATESTRUCTW *lpcs)
+{
+  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongPtrW(hwnd, 0);
+  UINT uView = lpcs->style & LVS_TYPEMASK;
+
+  TRACE("(lpcs=%p)\n", lpcs);
+
+  infoPtr->notifyFormat = SendMessageW(infoPtr->hwndNotify, WM_NOTIFYFORMAT,
+                                       (WPARAM)infoPtr->hwndSelf, (LPARAM)NF_QUERY);
+
   /* create header */
   infoPtr->hwndHeader =	CreateWindowW(WC_HEADERW, NULL,
     WS_CHILD | HDS_HORZ | HDS_FULLDRAG | (DWORD)((LVS_NOSORTHEADER & lpcs->style)?0:HDS_BUTTONS),
     0, 0, 0, 0, hwnd, NULL,
     lpcs->hInstance, NULL);
-  if (!infoPtr->hwndHeader) goto fail;
+  if (!infoPtr->hwndHeader) return -1;
 
   /* set header unicode format */
   SendMessageW(infoPtr->hwndHeader, HDM_SETUNICODEFORMAT, (WPARAM)TRUE, (LPARAM)NULL);
@@ -7744,20 +7789,9 @@ static LRESULT LISTVIEW_Create(HWND hwnd
   /* set header font */
   SendMessageW(infoPtr->hwndHeader, WM_SETFONT, (WPARAM)infoPtr->hFont, (LPARAM)TRUE);
 
-  /* allocate memory for the data structure */
-  if (!(infoPtr->selectionRanges = ranges_create(10))) goto fail;
-  if (!(infoPtr->hdpaItems = DPA_Create(10))) goto fail;
-  if (!(infoPtr->hdpaPosX  = DPA_Create(10))) goto fail;
-  if (!(infoPtr->hdpaPosY  = DPA_Create(10))) goto fail;
-  if (!(infoPtr->hdpaColumns = DPA_Create(10))) goto fail;
-
-  /* initialize the icon sizes */
-  set_icon_size(&infoPtr->iconSize, infoPtr->himlNormal, uView != LVS_ICON);
-  set_icon_size(&infoPtr->iconStateSize, infoPtr->himlState, TRUE);
-
   /* init item size to avoid division by 0 */
   LISTVIEW_UpdateItemSize (infoPtr);
-  
+
   if (uView == LVS_REPORT)
   {
     if (!(LVS_NOCOLUMNHEADER & lpcs->style))
@@ -7775,16 +7809,6 @@ static LRESULT LISTVIEW_Create(HWND hwnd
   OpenThemeData(hwnd, themeClass);
 
   return 0;
-
-fail:
-    DestroyWindow(infoPtr->hwndHeader);
-    ranges_destroy(infoPtr->selectionRanges);
-    DPA_Destroy(infoPtr->hdpaItems);
-    DPA_Destroy(infoPtr->hdpaPosX);
-    DPA_Destroy(infoPtr->hdpaPosY);
-    DPA_Destroy(infoPtr->hdpaColumns);
-    Free(infoPtr);
-    return -1;
 }
 
 /***
@@ -9246,7 +9270,7 @@ LISTVIEW_WindowProc(HWND hwnd, UINT uMsg
 
   TRACE("(uMsg=%x wParam=%x lParam=%lx)\n", uMsg, wParam, lParam);
 
-  if (!infoPtr && (uMsg != WM_CREATE))
+  if (!infoPtr && (uMsg != WM_NCCREATE))
     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
 
   switch (uMsg)
@@ -9605,6 +9629,9 @@ LISTVIEW_WindowProc(HWND hwnd, UINT uMsg
   case WM_COMMAND:
     return LISTVIEW_Command(infoPtr, wParam, lParam);
 
+  case WM_NCCREATE:
+    return LISTVIEW_NCCreate(hwnd, (LPCREATESTRUCTW)lParam);
+
   case WM_CREATE:
     return LISTVIEW_Create(hwnd, (LPCREATESTRUCTW)lParam);
 
diff --git a/dlls/comctl32/tests/listview.c b/dlls/comctl32/tests/listview.c
index 9d14e39..6c1a3b1 100644
--- a/dlls/comctl32/tests/listview.c
+++ b/dlls/comctl32/tests/listview.c
@@ -343,6 +343,34 @@ static void test_items(void)
     DestroyWindow(hwnd);
 }
 
+/* test setting imagelist between WM_NCCREATE and WM_CREATE */
+static WNDPROC listviewWndProc;
+static HIMAGELIST test_create_imagelist;
+
+static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+    if (uMsg == WM_CREATE)
+        SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
+    return CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
+}
+
+static void test_create()
+{
+    HWND hList;
+    WNDCLASSEX cls;
+    cls.cbSize = sizeof(WNDCLASSEX);
+    ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
+    listviewWndProc = cls.lpfnWndProc;
+    cls.lpfnWndProc = create_test_wndproc;
+    cls.lpszClassName = "MyListView32";
+    ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
+
+    test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
+    hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
+    ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
+    DestroyWindow(hList);
+}
+
 START_TEST(listview)
 {
     INITCOMMONCONTROLSEX icc;
@@ -354,4 +382,5 @@ START_TEST(listview)
     test_images();
     test_checkboxes();
     test_items();
+    test_create();
 }




More information about the wine-cvs mailing list