Nikolay Sivov : comctl32/tab: Implement TCM_REMOVEIMAGE.

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


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

Author: Nikolay Sivov <bunglehead at gmail.com>
Date:   Mon Mar 23 15:45:44 2009 -0400

comctl32/tab: Implement TCM_REMOVEIMAGE.

---

 dlls/comctl32/tab.c       |   35 ++++++++++++++++++++++--
 dlls/comctl32/tests/tab.c |   64 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+), 3 deletions(-)

diff --git a/dlls/comctl32/tab.c b/dlls/comctl32/tab.c
index 3880ceb..ae4f035 100644
--- a/dlls/comctl32/tab.c
+++ b/dlls/comctl32/tab.c
@@ -53,7 +53,6 @@
  *   TCN_KEYDOWN
  *
  *  Messages:
- *   TCM_REMOVEIMAGE
  *   TCM_DESELECTALL
  *   TCM_GETEXTENDEDSTYLE
  *   TCM_SETEXTENDEDSTYLE
@@ -3099,6 +3098,37 @@ TAB_SetItemExtra (TAB_INFO *infoPtr, INT cbInfo)
   return TRUE;
 }
 
+static LRESULT TAB_RemoveImage (TAB_INFO *infoPtr, INT image)
+{
+  if (!infoPtr)
+    return 0;
+
+  if (ImageList_Remove (infoPtr->himl, image))
+  {
+    INT i, *idx;
+    RECT r;
+
+    /* shift indices, repaint items if needed */
+    for (i = 0; i < infoPtr->uNumItem; i++)
+    {
+      idx = &infoPtr->items[i].iImage;
+      if (*idx >= image)
+      {
+        if (*idx == image)
+          *idx = -1;
+        else
+          (*idx)--;
+
+        /* repaint item */
+        if (TAB_InternalGetItemRect (infoPtr, i, &r, NULL))
+          InvalidateRect (infoPtr->hwnd, &r, TRUE);
+      }
+    }
+  }
+
+  return 0;
+}
+
 static LRESULT WINAPI
 TAB_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
@@ -3159,8 +3189,7 @@ TAB_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
       return TAB_SetItemSize (infoPtr, lParam);
 
     case TCM_REMOVEIMAGE:
-      FIXME("Unimplemented msg TCM_REMOVEIMAGE\n");
-      return 0;
+      return TAB_RemoveImage (infoPtr, wParam);
 
     case TCM_SETPADDING:
       return TAB_SetPadding (infoPtr, lParam);
diff --git a/dlls/comctl32/tests/tab.c b/dlls/comctl32/tests/tab.c
index 4b1c7f4..daef97f 100644
--- a/dlls/comctl32/tests/tab.c
+++ b/dlls/comctl32/tests/tab.c
@@ -984,6 +984,69 @@ static void test_delete_focus(HWND parent_wnd)
     DestroyWindow(hTab);
 }
 
+static void test_removeimage(HWND parent_wnd)
+{
+    static const BYTE bits[32];
+    HWND hwTab;
+    INT i;
+    TCITEM item;
+    HICON hicon;
+    HIMAGELIST himl = ImageList_Create(16, 16, ILC_COLOR, 3, 4);
+
+    hicon = CreateIcon(NULL, 16, 16, 1, 1, bits, bits);
+    ImageList_AddIcon(himl, hicon);
+    ImageList_AddIcon(himl, hicon);
+    ImageList_AddIcon(himl, hicon);
+
+    hwTab = create_tabcontrol(TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE);
+    SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
+
+    memset(&item, 0, sizeof(TCITEM));
+    item.mask = TCIF_IMAGE;
+
+    for(i = 0; i < 3; i++) {
+        SendMessage(hwTab, TCM_GETITEM, i, (LPARAM)&item);
+        expect(i, item.iImage);
+    }
+
+    /* remove image middle image */
+    SendMessage(hwTab, TCM_REMOVEIMAGE, 1, 0);
+    expect(2, ImageList_GetImageCount(himl));
+    item.iImage = -1;
+    SendMessage(hwTab, TCM_GETITEM, 0, (LPARAM)&item);
+    expect(0, item.iImage);
+    item.iImage = 0;
+    SendMessage(hwTab, TCM_GETITEM, 1, (LPARAM)&item);
+    expect(-1, item.iImage);
+    item.iImage = 0;
+    SendMessage(hwTab, TCM_GETITEM, 2, (LPARAM)&item);
+    expect(1, item.iImage);
+    /* remove first image */
+    SendMessage(hwTab, TCM_REMOVEIMAGE, 0, 0);
+    expect(1, ImageList_GetImageCount(himl));
+    item.iImage = 0;
+    SendMessage(hwTab, TCM_GETITEM, 0, (LPARAM)&item);
+    expect(-1, item.iImage);
+    item.iImage = 0;
+    SendMessage(hwTab, TCM_GETITEM, 1, (LPARAM)&item);
+    expect(-1, item.iImage);
+    item.iImage = -1;
+    SendMessage(hwTab, TCM_GETITEM, 2, (LPARAM)&item);
+    expect(0, item.iImage);
+    /* remove the last one */
+    SendMessage(hwTab, TCM_REMOVEIMAGE, 0, 0);
+    expect(0, ImageList_GetImageCount(himl));
+    for(i = 0; i < 3; i++) {
+        item.iImage = 0;
+        SendMessage(hwTab, TCM_GETITEM, i, (LPARAM)&item);
+        expect(-1, item.iImage);
+    }
+
+    DestroyWindow(hwTab);
+    ImageList_Destroy(himl);
+    DestroyIcon(hicon);
+}
+
 START_TEST(tab)
 {
     HWND parent_wnd;
@@ -1021,6 +1084,7 @@ START_TEST(tab)
 
     test_insert_focus(parent_wnd);
     test_delete_focus(parent_wnd);
+    test_removeimage(parent_wnd);
 
     DestroyWindow(parent_wnd);
 }




More information about the wine-cvs mailing list