[1/6] comctl32/tab: Implement TCM_REMOVEIMAGE (try3)
Nikolay Sivov
bunglehead at gmail.com
Mon Mar 23 15:33:12 CDT 2009
Thanks Vitaliy for review.
Changelog:
- try3: it only worked for zero-index item, indices shifting fixed,
tests added
- Implement TCM_REMOVEIMAGE
>From e1bb4330fa903a60e3a9767cfa0b0b9bd8bb6990 Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <bunglehead at gmail.com>
Date: Mon, 23 Mar 2009 15:45:44 -0400
Subject: 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);
}
--
1.5.6.5
More information about the wine-patches
mailing list