comctl32: toolbar[1/4]: move add/remove/setrect tooltip code to separate functions

Mikołaj Zalewski mikolaj at zalewski.pl
Sun Oct 8 16:40:37 CDT 2006


This patch make the code a bit simpler and will avoid duplication of 
code in the next patch. It changes the code behaviour in one aspect - 
during the TB_ADDBUTTONW the lParam is not copied into the lParam of the 
new tooltip tool. That's because the lParam of the tool is not the 
lParam of the message and I couldn't work out what it is. In comctl32 v5 
it's a stack pointer but not any pointer that was passed to the control 
by the user. In comctl32 v6 it's a stack pointers for buttons added 
before NM_TOOLTIPCREATED and a "magic" value of 160 for buttons added 
after NM_TOOLTIPCREATED. It looks as if the lParam is not initialized 
and contains some data left on the stack so I set it to zero. (setting 
the lParam was added by the commit 
58038199716696ca2824a4a802cd62e388a42cdd but without explanation if it 
was needed by some app. For TB_ADDBUTTONA the lParam is always set to zero).
-------------- next part --------------
diff --git a/dlls/comctl32/toolbar.c b/dlls/comctl32/toolbar.c
index 945b40b..c25b01f 100644
--- a/dlls/comctl32/toolbar.c
+++ b/dlls/comctl32/toolbar.c
@@ -251,6 +251,7 @@ static LRESULT TOOLBAR_LButtonDown(HWND 
 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
+static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button);
 
 static LRESULT
 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
@@ -1726,19 +1727,7 @@ TOOLBAR_CalcToolbar (HWND hwnd)
 	if (infoPtr->rcBound.bottom < y + cy)
 	    infoPtr->rcBound.bottom = y + cy;
 
-	/* Set the toolTip only for non-hidden, non-separator button */
-	if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
-	{
-	    TTTOOLINFOW ti;
-
-	    ZeroMemory (&ti, sizeof(ti));
-	    ti.cbSize = sizeof(ti);
-	    ti.hwnd = hwnd;
-	    ti.uId = btnPtr->idCommand;
-	    ti.rect = btnPtr->rect;
-	    SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
-			    0, (LPARAM)&ti);
-	}
+        TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
 
 	/* btnPtr->nRow is zero based. The space between the rows is 	*/
 	/* also considered as a row. 					*/
@@ -1902,6 +1891,56 @@ TOOLBAR_RelayEvent (HWND hwndTip, HWND h
     SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
 }
 
+static void
+TOOLBAR_TooltipAddTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
+{
+    if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
+        TTTOOLINFOW ti;
+
+        ZeroMemory(&ti, sizeof(TTTOOLINFOW));
+        ti.cbSize   = sizeof (TTTOOLINFOW);
+        ti.hwnd     = infoPtr->hwndSelf;
+        ti.uId      = button->idCommand;
+        ti.hinst    = 0;
+        ti.lpszText = LPSTR_TEXTCALLBACKW;
+        /* ti.lParam = random value from the stack? */
+
+        SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
+            0, (LPARAM)&ti);
+    }
+}
+
+static void
+TOOLBAR_TooltipDelTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
+{
+    if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
+        TTTOOLINFOW ti;
+
+        ZeroMemory(&ti, sizeof(ti));
+        ti.cbSize   = sizeof(ti);
+        ti.hwnd     = infoPtr->hwndSelf;
+        ti.uId      = button->idCommand;
+
+        SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
+    }
+}
+
+static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
+{
+    /* Set the toolTip only for non-hidden, non-separator button */
+    if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
+    {
+        TTTOOLINFOW ti;
+
+        ZeroMemory(&ti, sizeof(ti));
+        ti.cbSize = sizeof(ti);
+        ti.hwnd = infoPtr->hwndSelf;
+        ti.uId = button->idCommand;
+        ti.rect = button->rect;
+        SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
+    }
+}
+
 /* keeps available button list box sorted by button id */
 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
 {
@@ -2835,19 +2874,7 @@ TOOLBAR_AddButtonsA (HWND hwnd, WPARAM w
             btnPtr->iString   = lpTbb[nCount].iString;
 	btnPtr->bHot      = FALSE;
 
-	if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
-	    TTTOOLINFOW ti;
-
-	    ZeroMemory (&ti, sizeof(ti));
-	    ti.cbSize   = sizeof(ti);
-	    ti.hwnd     = hwnd;
-	    ti.uId      = btnPtr->idCommand;
-	    ti.hinst    = 0;
-	    ti.lpszText = LPSTR_TEXTCALLBACKW;
-
-	    SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
-			    0, (LPARAM)&ti);
-	}
+        TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
     }
 
     TOOLBAR_CalcToolbar (hwnd);
@@ -2903,20 +2930,7 @@ TOOLBAR_AddButtonsW (HWND hwnd, WPARAM w
             btnPtr->iString   = lpTbb[nCount].iString;
 	btnPtr->bHot      = FALSE;
 
-	if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
-	    TTTOOLINFOW ti;
-
-	    ZeroMemory (&ti, sizeof(TTTOOLINFOW));
-	    ti.cbSize   = sizeof (TTTOOLINFOW);
-	    ti.hwnd     = hwnd;
-	    ti.uId      = btnPtr->idCommand;
-	    ti.hinst    = 0;
-	    ti.lpszText = LPSTR_TEXTCALLBACKW;
-	    ti.lParam   = lParam;
-
-	    SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
-			    0, (LPARAM)&ti);
-	}
+        TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
     }
 
     TOOLBAR_CalcToolbar (hwnd);
@@ -3251,17 +3265,7 @@ TOOLBAR_DeleteButton (HWND hwnd, WPARAM 
     nmtb.tbButton.iString = btnPtr->iString;
     TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
 
-    if ((infoPtr->hwndToolTip) &&
-	!(btnPtr->fsStyle & BTNS_SEP)) {
-	TTTOOLINFOW ti;
-
-	ZeroMemory (&ti, sizeof(ti));
-	ti.cbSize   = sizeof(ti);
-	ti.hwnd     = hwnd;
-	ti.uId      = infoPtr->buttons[nIndex].idCommand;
-
-	SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
-    }
+    TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
 
     if (infoPtr->nNumButtons == 1) {
 	TRACE(" simple delete!\n");
@@ -3909,19 +3913,7 @@ TOOLBAR_InsertButtonA (HWND hwnd, WPARAM
     else
         infoPtr->buttons[nIndex].iString   = lpTbb->iString;
 
-    if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
-	TTTOOLINFOW ti;
-
-	ZeroMemory (&ti, sizeof(ti));
-	ti.cbSize   = sizeof (ti);
-	ti.hwnd     = hwnd;
-	ti.uId      = lpTbb->idCommand;
-	ti.hinst    = 0;
-	ti.lpszText = LPSTR_TEXTCALLBACKW;
-
-	SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
-			0, (LPARAM)&ti);
-    }
+    TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
 
     /* post insert copy */
     if (nIndex < infoPtr->nNumButtons - 1) {
@@ -4010,19 +4002,7 @@ TOOLBAR_InsertButtonW (HWND hwnd, WPARAM
     else
         infoPtr->buttons[nIndex].iString   = lpTbb->iString;
 
-    if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
-	TTTOOLINFOW ti;
-
-	ZeroMemory (&ti, sizeof(TTTOOLINFOW));
-	ti.cbSize   = sizeof (TTTOOLINFOW);
-	ti.hwnd     = hwnd;
-	ti.uId      = lpTbb->idCommand;
-	ti.hinst    = 0;
-	ti.lpszText = LPSTR_TEXTCALLBACKW;
-
-	SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
-			0, (LPARAM)&ti);
-    }
+    TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
 
     /* post insert copy */
     if (nIndex < infoPtr->nNumButtons - 1) {
@@ -4441,20 +4421,10 @@ static void
 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
 {
     INT i;
-    TTTOOLINFOW ti;
-
-    ZeroMemory(&ti, sizeof(ti));
-    ti.cbSize   = sizeof(ti);
-    ti.hwnd     = infoPtr->hwndSelf;
 
     for (i = 0; i < infoPtr->nNumButtons; i++)
     {
-        if ((infoPtr->hwndToolTip) &&
-            !(infoPtr->buttons[i].fsStyle & BTNS_SEP))
-        {
-            ti.uId      = infoPtr->buttons[i].idCommand;
-            SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
-        }
+        TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
     }
 
     Free(infoPtr->buttons);
-- 
1.4.2.1


More information about the wine-patches mailing list