comctl32: toolbar: Fix the tests and handling of TB_SETHOTITEM on a disabled button.

This commit is contained in:
Mikołaj Zalewski 2006-10-18 16:06:42 +02:00 committed by Alexandre Julliard
parent 2d6b9cafc6
commit 39c4bbe56a
2 changed files with 51 additions and 19 deletions

View File

@ -35,7 +35,11 @@
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 idCommand, int fsStyle, int nString) {
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);

View File

@ -4783,40 +4783,45 @@ TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
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;
}
}
}