Mikołaj Zalewski : comctl32: toolbar: Fix the tests and handling of TB_SETHOTITEM on a disabled button.
Alexandre Julliard
julliard at wine.codeweavers.com
Thu Oct 19 07:19:21 CDT 2006
Module: wine
Branch: master
Commit: 39c4bbe56aa535f4d37e8e60115bbe2e9149e622
URL: http://source.winehq.org/git/wine.git/?a=commit;h=39c4bbe56aa535f4d37e8e60115bbe2e9149e622
Author: Mikołaj Zalewski <mikolaj at zalewski.pl>
Date: Wed Oct 18 16:06:42 2006 +0200
comctl32: toolbar: Fix the tests and handling of TB_SETHOTITEM on a disabled button.
---
dlls/comctl32/tests/toolbar.c | 45 +++++++++++++++++++++++++++++++++--------
dlls/comctl32/toolbar.c | 25 ++++++++++++++---------
2 files changed, 51 insertions(+), 19 deletions(-)
diff --git a/dlls/comctl32/tests/toolbar.c b/dlls/comctl32/tests/toolbar.c
index 110e8cb..217874d 100644
--- a/dlls/comctl32/tests/toolbar.c
+++ b/dlls/comctl32/tests/toolbar.c
@@ -35,7 +35,11 @@ #include "wine/test.h"
HWND hMainWnd;
BOOL g_fBlockHotItemChange;
BOOL g_fReceivedHotItemChange;
+BOOL g_fExpectedHotItemOld;
+BOOL g_fExpectedHotItemNew;
+#define compare(val, exp, format) ok((val) == (exp), #val " value " format " expected " format "\n", (val), (exp));
+
static void MakeButton(TBBUTTON *p, int idCommand, int fsStyle, int nString) {
p->iBitmap = -2;
p->idCommand = idCommand;
@@ -47,10 +51,17 @@ static void MakeButton(TBBUTTON *p, int
LRESULT MyWnd_Notify(hWnd, wParam, lParam)
{
NMHDR *hdr = (NMHDR *)lParam;
+ NMTBHOTITEM *nmhi;
switch (hdr->code)
{
case TBN_HOTITEMCHANGE:
+ nmhi = (NMTBHOTITEM *)lParam;
g_fReceivedHotItemChange = TRUE;
+ if (g_fExpectedHotItemOld != g_fExpectedHotItemNew)
+ {
+ compare(nmhi->idOld, g_fExpectedHotItemOld, "%d");
+ compare(nmhi->idNew, g_fExpectedHotItemNew, "%d");
+ }
if (g_fBlockHotItemChange)
return 1;
break;
@@ -422,6 +433,17 @@ void test_add_string()
CHECK_STRING_TABLE(14, ret7);
}
+static void expect_hot_notify(int idold, int idnew)
+{
+ g_fExpectedHotItemOld = idold;
+ g_fExpectedHotItemNew = idnew;
+ g_fReceivedHotItemChange = FALSE;
+}
+
+#define check_hot_notify() \
+ ok(g_fReceivedHotItemChange, "TBN_HOTITEMCHANGE not received\n"); \
+ g_fExpectedHotItemOld = g_fExpectedHotItemNew = 0;
+
void test_hotitem()
{
HWND hToolbar = NULL;
@@ -452,10 +474,10 @@ void test_hotitem()
ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
ok(ret == -1, "Hot item: %lx, expected -1\n", ret);
- g_fReceivedHotItemChange = FALSE;
+ expect_hot_notify(0, 7);
ret = SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
- ok(g_fReceivedHotItemChange, "TBN_HOTITEMCHANGE not received\n");
+ check_hot_notify();
ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
ok(ret == 3, "Hot item: %lx, expected 3\n", ret);
g_fBlockHotItemChange = TRUE;
@@ -475,22 +497,27 @@ void test_hotitem()
ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
ok(g_fReceivedHotItemChange == FALSE, "TBN_HOTITEMCHANGE received after a duplication\n");
+ expect_hot_notify(7, 0);
ret = SendMessage(hToolbar, TB_SETHOTITEM, -0xbeaf, 0);
ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
- ok(g_fReceivedHotItemChange, "TBN_HOTITEMCHANGE not received\n");
+ check_hot_notify();
SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
- /* setting disabled buttons as hot failed and generates no notify */
- g_fReceivedHotItemChange = FALSE;
+ /* setting disabled buttons will generate a notify with the button id but no button will be hot */
+ expect_hot_notify(7, 9);
ret = SendMessage(hToolbar, TB_SETHOTITEM, 4, 0);
ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
- ok(!g_fReceivedHotItemChange, "TBN_HOTITEMCHANGE received\n");
+ check_hot_notify();
ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
- ok(ret == 3, "Hot item: %lx, expected 3\n", ret);
+ ok(ret == -1, "Hot item: %lx, expected -1\n", ret);
+ /* enabling the button won't change that */
+ SendMessage(hToolbar, TB_ENABLEBUTTON, 9, TRUE);
+ ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
+ ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
- /* but disabling a hot button works */
+ /* disabling a hot button works */
ret = SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
- ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
+ ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
g_fReceivedHotItemChange = FALSE;
SendMessage(hToolbar, TB_ENABLEBUTTON, 7, FALSE);
ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
diff --git a/dlls/comctl32/toolbar.c b/dlls/comctl32/toolbar.c
index da41486..fa3eee4 100644
--- a/dlls/comctl32/toolbar.c
+++ b/dlls/comctl32/toolbar.c
@@ -4783,40 +4783,45 @@ TOOLBAR_SetHotItemEx (TOOLBAR_INFO *info
NMTBHOTITEM nmhotitem;
TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
+ nmhotitem.dwFlags = dwReason;
if(infoPtr->nHotItem >= 0)
{
oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
nmhotitem.idOld = oldBtnPtr->idCommand;
}
else
+ {
nmhotitem.dwFlags |= HICF_ENTERING;
+ nmhotitem.idOld = 0;
+ }
if (nHit >= 0)
{
btnPtr = &infoPtr->buttons[nHit];
nmhotitem.idNew = btnPtr->idCommand;
- /* setting disabled buttons as hot fails */
- if (!(btnPtr->fsState & TBSTATE_ENABLED))
- return;
}
else
+ {
nmhotitem.dwFlags |= HICF_LEAVING;
-
- nmhotitem.dwFlags = dwReason;
+ nmhotitem.idNew = 0;
+ }
/* now change the hot and invalidate the old and new buttons - if the
* parent agrees */
if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
{
- infoPtr->nHotItem = nHit;
- if (btnPtr) {
- btnPtr->bHot = TRUE;
- InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
- }
if (oldBtnPtr) {
oldBtnPtr->bHot = FALSE;
InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
}
+ /* setting disabled buttons as hot fails even if the notify contains the button id */
+ if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
+ btnPtr->bHot = TRUE;
+ InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
+ infoPtr->nHotItem = nHit;
+ }
+ else
+ infoPtr->nHotItem = -1;
}
}
}
More information about the wine-cvs
mailing list