Sync with trunk r58033.
[reactos.git] / dll / win32 / comctl32 / toolbar.c
index bd35533..c26d70e 100644 (file)
@@ -217,9 +217,6 @@ typedef enum
 
 #define TOOLBAR_NOWHERE (-1)
 
-#define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
-#define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
-
 /* Used to find undocumented extended styles */
 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
                         TBSTYLE_EX_UNDOC1 | \
@@ -258,6 +255,11 @@ static inline int default_top_margin(const TOOLBAR_INFO *infoPtr)
     return (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
 }
 
+static inline BOOL TOOLBAR_HasDropDownArrows(DWORD exStyle)
+{
+    return (exStyle & TBSTYLE_EX_DRAWDDARROWS) != 0;
+}
+
 static LPWSTR
 TOOLBAR_GetText(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr)
 {
@@ -428,7 +430,7 @@ TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPt
 
     if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
        if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
-       ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
+       WARN("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
            HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
        return NULL;
     }
@@ -1247,7 +1249,7 @@ TOOLBAR_CalcStrings (const TOOLBAR_INFO *infoPtr, LPSIZE lpSize)
 
     btnPtr = infoPtr->buttons;
     for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
-        if(TOOLBAR_HasText(infoPtr, btnPtr))
+        if(TOOLBAR_GetText(infoPtr, btnPtr))
         {
             TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
             if (sz.cx > lpSize->cx)
@@ -1775,11 +1777,14 @@ TOOLBAR_LayoutToolbar(TOOLBAR_INFO *infoPtr)
 
 
 static INT
-TOOLBAR_InternalHitTest (const TOOLBAR_INFO *infoPtr, const POINT *lpPt)
+TOOLBAR_InternalHitTest (const TOOLBAR_INFO *infoPtr, const POINT *lpPt, BOOL *button)
 {
     TBUTTON_INFO *btnPtr;
     INT i;
 
+    if (button)
+        *button = FALSE;
+
     btnPtr = infoPtr->buttons;
     for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
        if (btnPtr->fsState & TBSTATE_HIDDEN)
@@ -1794,6 +1799,8 @@ TOOLBAR_InternalHitTest (const TOOLBAR_INFO *infoPtr, const POINT *lpPt)
        else {
            if (PtInRect (&btnPtr->rect, *lpPt)) {
                TRACE(" ON BUTTON %d!\n", i);
+                if (button)
+                    *button = TRUE;
                return i;
            }
        }
@@ -2399,7 +2406,7 @@ TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
                         nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
                         : "");
 
-                   /* insert button into the apropriate list */
+                   /* insert button into the appropriate list */
                    index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
                    if (index == -1)
                    {
@@ -3133,7 +3140,7 @@ TOOLBAR_CheckButton (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
 
     btnPtr = &infoPtr->buttons[nIndex];
 
-    bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
+    bChecked = (btnPtr->fsState & TBSTATE_CHECKED) != 0;
 
     if (LOWORD(lParam) == FALSE)
        btnPtr->fsState &= ~TBSTATE_CHECKED;
@@ -3664,7 +3671,7 @@ TOOLBAR_HideButton (TOOLBAR_INFO *infoPtr, INT Id, BOOL fHide)
 static inline LRESULT
 TOOLBAR_HitTest (const TOOLBAR_INFO *infoPtr, const POINT* lpPt)
 {
-    return TOOLBAR_InternalHitTest (infoPtr, lpPt);
+    return TOOLBAR_InternalHitTest (infoPtr, lpPt, NULL);
 }
 
 
@@ -4481,20 +4488,22 @@ TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
  *  (MSDN says that this parameter is reserved)
  */
 static LRESULT
-TOOLBAR_SetExtendedStyle (TOOLBAR_INFO *infoPtr, LPARAM lParam)
+TOOLBAR_SetExtendedStyle (TOOLBAR_INFO *infoPtr, DWORD mask, DWORD style)
 {
-    DWORD dwOldStyle;
+    DWORD old_style = infoPtr->dwExStyle;
 
-    dwOldStyle = infoPtr->dwExStyle;
-    infoPtr->dwExStyle = (DWORD)lParam;
+    TRACE("mask=0x%08x, style=0x%08x\n", mask, style);
 
-    TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
+    if (mask)
+       infoPtr->dwExStyle = (old_style & ~mask) | (style & mask);
+    else
+       infoPtr->dwExStyle = style;
 
     if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
        FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
              (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
 
-    if ((dwOldStyle ^ infoPtr->dwExStyle) & TBSTYLE_EX_MIXEDBUTTONS)
+    if ((old_style ^ infoPtr->dwExStyle) & TBSTYLE_EX_MIXEDBUTTONS)
         TOOLBAR_CalcToolbar(infoPtr);
     else
         TOOLBAR_LayoutToolbar(infoPtr);
@@ -4502,7 +4511,7 @@ TOOLBAR_SetExtendedStyle (TOOLBAR_INFO *infoPtr, LPARAM lParam)
     TOOLBAR_AutoSize(infoPtr);
     InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
 
-    return (LRESULT)dwOldStyle;
+    return old_style;
 }
 
 
@@ -5155,7 +5164,7 @@ TOOLBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
 
     TRACE("hwnd = %p, style=0x%08x\n", hwnd, lpcs->style);
 
-    infoPtr->dwStyle = lpcs->style;
+    infoPtr->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
     GetClientRect(hwnd, &infoPtr->client_rect);
     infoPtr->bUnicode = infoPtr->hwndNotify && 
         (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_REQUERY));
@@ -5374,13 +5383,13 @@ static LRESULT
 TOOLBAR_LButtonDblClk (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 {
     POINT pt;
-    INT   nHit;
+    BOOL button;
 
     pt.x = (short)LOWORD(lParam);
     pt.y = (short)HIWORD(lParam);
-    nHit = TOOLBAR_InternalHitTest (infoPtr, &pt);
+    TOOLBAR_InternalHitTest (infoPtr, &pt, &button);
 
-    if (nHit >= 0)
+    if (button)
         TOOLBAR_LButtonDown (infoPtr, wParam, lParam);
     else if (infoPtr->dwStyle & CCS_ADJUSTABLE)
        TOOLBAR_Customize (infoPtr);
@@ -5398,6 +5407,7 @@ TOOLBAR_LButtonDown (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     NMTOOLBARA nmtb;
     NMMOUSE nmmouse;
     BOOL bDragKeyPressed;
+    BOOL button;
 
     TRACE("\n");
 
@@ -5412,11 +5422,12 @@ TOOLBAR_LButtonDown (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
     pt.x = (short)LOWORD(lParam);
     pt.y = (short)HIWORD(lParam);
-    nHit = TOOLBAR_InternalHitTest (infoPtr, &pt);
+    nHit = TOOLBAR_InternalHitTest (infoPtr, &pt, &button);
 
-    btnPtr = &infoPtr->buttons[nHit];
+    if (button)
+        btnPtr = &infoPtr->buttons[nHit];
 
-    if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
+    if (button && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
     {
         infoPtr->nButtonDrag = nHit;
         SetCapture (infoPtr->hwndSelf);
@@ -5427,7 +5438,7 @@ TOOLBAR_LButtonDown (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
             hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
         SetCursor(hCursorDrag);
     }
-    else if (nHit >= 0)
+    else if (button)
     {
        RECT arrowRect;
        infoPtr->nOldHit = nHit;
@@ -5474,9 +5485,9 @@ TOOLBAR_LButtonDown (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
                  * NOTE: native doesn't do this, but that is a bug */
                 GetCursorPos(&pt);
                 ScreenToClient(infoPtr->hwndSelf, &pt);
-                nHit = TOOLBAR_InternalHitTest(infoPtr, &pt);
-                if (!infoPtr->bAnchor || (nHit >= 0))
-                    TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
+                nHit = TOOLBAR_InternalHitTest(infoPtr, &pt, &button);
+                if (!infoPtr->bAnchor || button)
+                    TOOLBAR_SetHotItemEx(infoPtr, button ? nHit : TOOLBAR_NOWHERE, HICF_MOUSE | HICF_LMOUSE);
                 
                 /* remove any left mouse button down or double-click messages
                  * so that we can get a toggle effect on the button */
@@ -5494,7 +5505,7 @@ TOOLBAR_LButtonDown (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
        btnPtr->fsState |= TBSTATE_PRESSED;
 
-        TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
+        TOOLBAR_SetHotItemEx(infoPtr, button ? nHit : TOOLBAR_NOWHERE, HICF_MOUSE | HICF_LMOUSE);
 
         if (btnPtr->fsState & TBSTATE_ENABLED)
            InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
@@ -5502,7 +5513,7 @@ TOOLBAR_LButtonDown (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
        SetCapture (infoPtr->hwndSelf);
     }
 
-    if (nHit >=0)
+    if (button)
     {
         memset(&nmtb, 0, sizeof(nmtb));
         nmtb.iItem = btnPtr->idCommand;
@@ -5512,7 +5523,7 @@ TOOLBAR_LButtonDown (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     nmmouse.dwHitInfo = nHit;
 
     /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
-    if (nHit < 0)
+    if (!button)
         nmmouse.dwItemSpec = -1;
     else
     {
@@ -5539,6 +5550,7 @@ TOOLBAR_LButtonUp (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     NMHDR hdr;
     NMMOUSE nmmouse;
     NMTOOLBARA nmtb;
+    BOOL button;
 
     if (infoPtr->hwndToolTip)
        TOOLBAR_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwndSelf,
@@ -5546,10 +5558,10 @@ TOOLBAR_LButtonUp (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
     pt.x = (short)LOWORD(lParam);
     pt.y = (short)HIWORD(lParam);
-    nHit = TOOLBAR_InternalHitTest (infoPtr, &pt);
+    nHit = TOOLBAR_InternalHitTest (infoPtr, &pt, &button);
 
-    if (!infoPtr->bAnchor || (nHit >= 0))
-        TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
+    if (!infoPtr->bAnchor || button)
+        TOOLBAR_SetHotItemEx(infoPtr, button ? nHit : TOOLBAR_NOWHERE, HICF_MOUSE | HICF_LMOUSE);
 
     if (infoPtr->nButtonDrag >= 0) {
         RECT rcClient;
@@ -5609,7 +5621,7 @@ TOOLBAR_LButtonUp (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
         }
 
         /* button under cursor changed so need to re-set hot item */
-        TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
+        TOOLBAR_SetHotItemEx(infoPtr, button ? nHit : TOOLBAR_NOWHERE, HICF_MOUSE | HICF_LMOUSE);
         infoPtr->nButtonDrag = -1;
 
         TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
@@ -5674,7 +5686,7 @@ TOOLBAR_LButtonUp (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     * NM_CLICK with the NMMOUSE structure. */
     nmmouse.dwHitInfo = nHit;
 
-    if (nHit < 0)
+    if (!button)
         nmmouse.dwItemSpec = -1;
     else
     {
@@ -5697,14 +5709,15 @@ TOOLBAR_RButtonUp(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     INT nHit;
     NMMOUSE nmmouse;
     POINT pt;
+    BOOL button;
 
     pt.x = (short)LOWORD(lParam);
     pt.y = (short)HIWORD(lParam);
 
-    nHit = TOOLBAR_InternalHitTest(infoPtr, &pt);
+    nHit = TOOLBAR_InternalHitTest(infoPtr, &pt, &button);
     nmmouse.dwHitInfo = nHit;
 
-    if (nHit < 0) {
+    if (!button) {
        nmmouse.dwItemSpec = -1;
     } else {
        nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
@@ -5803,6 +5816,7 @@ TOOLBAR_MouseMove (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     TRACKMOUSEEVENT trackinfo;
     INT   nHit;
     TBUTTON_INFO *btnPtr;
+    BOOL button;
     
     if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
         TOOLBAR_TooltipCreateControl(infoPtr);
@@ -5833,11 +5847,11 @@ TOOLBAR_MouseMove (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     pt.x = (short)LOWORD(lParam);
     pt.y = (short)HIWORD(lParam);
 
-    nHit = TOOLBAR_InternalHitTest (infoPtr, &pt);
+    nHit = TOOLBAR_InternalHitTest (infoPtr, &pt, &button);
 
     if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) 
-        && (!infoPtr->bAnchor || (nHit >= 0)))
-        TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
+        && (!infoPtr->bAnchor || button))
+        TOOLBAR_SetHotItemEx(infoPtr, button ? nHit : TOOLBAR_NOWHERE, HICF_MOUSE);
 
     if (infoPtr->nOldHit != nHit)
     {
@@ -6629,7 +6643,7 @@ ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
            return TOOLBAR_SetDrawTextFlags (infoPtr, wParam, lParam);
 
        case TB_SETEXTENDEDSTYLE:
-           return TOOLBAR_SetExtendedStyle (infoPtr, lParam);
+           return TOOLBAR_SetExtendedStyle (infoPtr, wParam, lParam);
 
        case TB_SETHOTIMAGELIST:
            return TOOLBAR_SetHotImageList (infoPtr, wParam, (HIMAGELIST)lParam);