Mikołaj Zalewski : comctl32: header: Automatically set some format fields.

Alexandre Julliard julliard at wine.codeweavers.com
Tue May 16 13:54:24 CDT 2006


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

Author: Mikołaj Zalewski <mikolaj at zalewski.pl>
Date:   Tue May 16 00:03:14 2006 +0200

comctl32: header: Automatically set some format fields.

---

 dlls/comctl32/header.c       |   11 +++++++
 dlls/comctl32/tests/header.c |   65 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 0 deletions(-)

diff --git a/dlls/comctl32/header.c b/dlls/comctl32/header.c
index fea902b..b91524e 100644
--- a/dlls/comctl32/header.c
+++ b/dlls/comctl32/header.c
@@ -1156,8 +1156,19 @@ HEADER_InsertItemT (HWND hwnd, INT nItem
     ZeroMemory(lpItem, sizeof(HEADER_ITEM));
     HEADER_StoreHDItemInHeader(lpItem, phdi, bUnicode);
 
+    /* set automatically some format bits */
     if (phdi->mask & HDI_TEXT)
         lpItem->fmt |= HDF_STRING;
+    else
+        lpItem->fmt &= ~HDF_STRING;
+
+    if (lpItem->hbm != NULL)
+        lpItem->fmt |= HDF_BITMAP;
+    else
+        lpItem->fmt &= ~HDF_BITMAP;
+
+    if (phdi->mask & HDI_IMAGE)
+        lpItem->fmt |= HDF_IMAGE;
 
     lpItem->iOrder = iOrder;
 
diff --git a/dlls/comctl32/tests/header.c b/dlls/comctl32/tests/header.c
index f85b92c..7e0fda7 100644
--- a/dlls/comctl32/tests/header.c
+++ b/dlls/comctl32/tests/header.c
@@ -130,6 +130,15 @@ static LONG getItem(HWND hdex, int idx, 
     return (LONG)SendMessage(hdex, HDM_GETITEMA, (WPARAM)idx, (LPARAM)&hdItem);
 }
 
+static void addReadDelItem(HWND hdex, HDITEMA *phdiCreate, int maskRead, HDITEMA *phdiRead)
+{
+    ok(SendMessage(hdex, HDM_INSERTITEMA, (WPARAM)0, (LPARAM)phdiCreate)!=-1, "Adding item failed\n");
+    ZeroMemory(phdiRead, sizeof(HDITEMA));
+    phdiRead->mask = maskRead;
+    ok(SendMessage(hdex, HDM_GETITEMA, (WPARAM)0, (LPARAM)phdiRead)!=0, "Getting item data failed\n");
+    ok(SendMessage(hdex, HDM_DELETEITEM, (WPARAM)0, (LPARAM)0)!=0, "Deleteing item failed\n");
+}
+
 static HWND create_header_control (void)
 {
     HWND handle;
@@ -207,6 +216,59 @@ #define TEST_GET_ITEMCOUNT(i)\
     ok(res == i, "Got Item Count as %ld\n", res);\
 }
 
+static void check_auto_format(void)
+{
+    HDITEMA hdiCreate;
+    HDITEMA hdiRead;
+    ZeroMemory(&hdiCreate, sizeof(HDITEMA));
+
+    /* Windows implicitly sets some format bits in INSERTITEM */
+
+    /* HDF_STRING is automaticaly set and cleared for no text */
+    hdiCreate.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
+    hdiCreate.pszText = "Test";
+    hdiCreate.cxy = 100;
+    hdiCreate.fmt=HDF_CENTER;
+    addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
+    ok(hdiRead.fmt == (HDF_STRING|HDF_CENTER), "HDF_STRING not set automatically (fmt=%x)\n", hdiRead.fmt);
+
+    hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
+    hdiCreate.pszText = "Test";
+    hdiCreate.fmt = HDF_CENTER|HDF_STRING;
+    addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
+    ok(hdiRead.fmt == (HDF_CENTER), "HDF_STRING should be automatically cleared (fmt=%x)\n", hdiRead.fmt);
+
+    /* HDF_BITMAP is automatically set and cleared for a NULL bitmap or no bitmap */
+    hdiCreate.mask = HDI_BITMAP|HDI_WIDTH|HDI_FORMAT;
+    hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
+    hdiCreate.fmt = HDF_CENTER;
+    addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
+    ok(hdiRead.fmt == (HDF_BITMAP|HDF_CENTER), "HDF_BITMAP not set automatically (fmt=%x)\n", hdiRead.fmt);
+    DeleteObject(hdiCreate.hbm);
+
+    hdiCreate.hbm = NULL;
+    hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
+    addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
+    ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for NULL bitmap (fmt=%x)\n", hdiRead.fmt);
+
+    hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
+    hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
+    addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
+    ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for no bitmap (fmt=%x)\n", hdiRead.fmt);
+
+    /* HDF_IMAGE is automatically set but not cleared */
+    hdiCreate.mask = HDI_IMAGE|HDI_WIDTH|HDI_FORMAT;
+    hdiCreate.iImage = 17;
+    addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
+    ok(hdiRead.fmt == (HDF_IMAGE|HDF_CENTER), "HDF_IMAGE not set automatically (fmt=%x)\n", hdiRead.fmt);
+
+    hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
+    hdiCreate.fmt = HDF_CENTER|HDF_IMAGE;
+    hdiCreate.iImage = 0;
+    addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
+    ok(hdiRead.fmt == (HDF_CENTER|HDF_IMAGE), "HDF_IMAGE shouldn't be cleared automatically (fmt=%x)\n", hdiRead.fmt);
+}
+
 static void test_header_control (void)
 {
     LONG res;
@@ -278,6 +340,9 @@ static void test_header_control (void)
     /* unexpected notifies cleared by notifies_received in setItem */
     delItem(hWndHeader, 0);
 
+    check_auto_format();
+    TEST_GET_ITEMCOUNT(6);
+
     res = delItem(hWndHeader, 5);
     ok(res == 1, "Deleting Out of Range item should fail with 1 (%ld)\n", res);
     res = delItem(hWndHeader, -2);




More information about the wine-cvs mailing list