4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
38 * - TB_INSERTMARKHITTEST
46 * - Button wrapping (under construction).
47 * - Fix TB_SETROWS and Separators.
48 * - iListGap custom draw support.
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
84 #include "wine/debug.h"
86 WINE_DEFAULT_DEBUG_CHANNEL(toolbar
);
88 static HCURSOR hCursorDrag
= NULL
;
97 BOOL bDropDownPressed
;
102 INT cx
; /* manually set size */
116 } IMLENTRY
, *PIMLENTRY
;
120 DWORD dwStructSize
; /* size of TBBUTTON struct */
122 RECT rcBound
; /* bounding rectangle */
128 INT nRows
; /* number of button rows */
129 INT nMaxTextRows
; /* maximum number of text rows */
130 INT cxMin
; /* minimum button width */
131 INT cxMax
; /* maximum button width */
132 INT nNumButtons
; /* number of buttons */
133 INT nNumBitmaps
; /* number of bitmaps */
134 INT nNumStrings
; /* number of strings */
136 INT nButtonDown
; /* toolbar button being pressed or -1 if none */
137 INT nButtonDrag
; /* toolbar button being dragged or -1 if none */
139 INT nHotItem
; /* index of the "hot" item */
140 SIZE szPadding
; /* padding values around button */
141 INT iTopMargin
; /* the top margin */
142 INT iListGap
; /* default gap between text and image for toolbar with list style */
144 HFONT hFont
; /* text font */
145 HTHEME hTheme
; /* theme */
146 HIMAGELIST himlInt
; /* image list created internally */
147 PIMLENTRY
*himlDef
; /* default image list array */
148 INT cimlDef
; /* default image list array count */
149 PIMLENTRY
*himlHot
; /* hot image list array */
150 INT cimlHot
; /* hot image list array count */
151 PIMLENTRY
*himlDis
; /* disabled image list array */
152 INT cimlDis
; /* disabled image list array count */
153 HWND hwndToolTip
; /* handle to tool tip control */
154 HWND hwndNotify
; /* handle to the window that gets notifications */
155 HWND hwndSelf
; /* my own handle */
156 BOOL bAnchor
; /* anchor highlight enabled */
157 BOOL bDoRedraw
; /* Redraw status */
158 BOOL bDragOutSent
; /* has TBN_DRAGOUT notification been sent for this drag? */
159 BOOL bUnicode
; /* Notifications are ANSI (FALSE) or Unicode (TRUE)? */
160 BOOL bCaptured
; /* mouse captured? */
161 DWORD dwStyle
; /* regular toolbar style */
162 DWORD dwExStyle
; /* extended toolbar style */
163 DWORD dwDTFlags
; /* DrawText flags */
165 COLORREF clrInsertMark
; /* insert mark color */
166 COLORREF clrBtnHighlight
; /* color for Flat Separator */
167 COLORREF clrBtnShadow
; /* color for Flag Separator */
169 LPWSTR pszTooltipText
; /* temporary store for a string > 80 characters
170 * for TTN_GETDISPINFOW notification */
171 TBINSERTMARK tbim
; /* info on insertion mark */
172 TBUTTON_INFO
*buttons
; /* pointer to button array */
173 LPWSTR
*strings
; /* pointer to string array */
174 TBITMAP_INFO
*bitmaps
;
175 } TOOLBAR_INFO
, *PTOOLBAR_INFO
;
178 /* used by customization dialog */
181 PTOOLBAR_INFO tbInfo
;
183 } CUSTDLG_INFO
, *PCUSTDLG_INFO
;
191 } CUSTOMBUTTON
, *PCUSTOMBUTTON
;
200 #define SEPARATOR_WIDTH 8
202 #define BOTTOM_BORDER 2
203 #define DDARROW_WIDTH 11
204 #define ARROW_HEIGHT 3
205 #define INSERTMARK_WIDTH 2
211 /* vertical padding used in list mode when image is present */
214 /* how wide to treat the bitmap if it isn't present */
215 #define NONLIST_NOTEXT_OFFSET 2
217 #define TOOLBAR_NOWHERE (-1)
219 /* Used to find undocumented extended styles */
220 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
221 TBSTYLE_EX_VERTICAL | \
222 TBSTYLE_EX_MIXEDBUTTONS | \
223 TBSTYLE_EX_DOUBLEBUFFER | \
224 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
226 /* all of the CCS_ styles */
227 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
228 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
230 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
231 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
232 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
233 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
234 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
236 static const WCHAR themeClass
[] = L
"Toolbar";
238 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
);
239 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
);
240 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
);
241 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
);
242 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
);
243 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
);
244 static LRESULT
TOOLBAR_LButtonDown(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
);
245 static void TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
);
246 static LRESULT
TOOLBAR_AutoSize(TOOLBAR_INFO
*infoPtr
);
247 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
);
248 static void TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
249 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
250 static LRESULT
TOOLBAR_SetButtonInfo(TOOLBAR_INFO
*infoPtr
, INT Id
,
251 const TBBUTTONINFOW
*lptbbi
, BOOL isW
);
254 static inline int default_top_margin(const TOOLBAR_INFO
*infoPtr
)
256 return (infoPtr
->dwStyle
& TBSTYLE_FLAT
? 0 : TOP_BORDER
);
259 static inline BOOL
TOOLBAR_HasDropDownArrows(DWORD exStyle
)
261 return (exStyle
& TBSTYLE_EX_DRAWDDARROWS
) != 0;
264 static inline BOOL
button_has_ddarrow(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
266 return (TOOLBAR_HasDropDownArrows( infoPtr
->dwExStyle
) && (btnPtr
->fsStyle
& BTNS_DROPDOWN
)) ||
267 (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
271 TOOLBAR_GetText(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
273 LPWSTR lpText
= NULL
;
275 /* NOTE: iString == -1 is undocumented */
276 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1))
277 lpText
= (LPWSTR
)btnPtr
->iString
;
278 else if ((btnPtr
->iString
>= 0) && (btnPtr
->iString
< infoPtr
->nNumStrings
))
279 lpText
= infoPtr
->strings
[btnPtr
->iString
];
285 TOOLBAR_DumpTBButton(const TBBUTTON
*tbb
, BOOL fUnicode
)
287 TRACE("TBBUTTON: id %d, bitmap=%d, state=%02x, style=%02x, data=%p, stringid=%p (%s)\n", tbb
->idCommand
,
288 tbb
->iBitmap
, tbb
->fsState
, tbb
->fsStyle
, (void *)tbb
->dwData
, (void *)tbb
->iString
,
289 tbb
->iString
!= -1 ? (fUnicode
? debugstr_w((LPWSTR
)tbb
->iString
) : debugstr_a((LPSTR
)tbb
->iString
)) : "");
293 TOOLBAR_DumpButton(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*bP
, INT btn_num
)
295 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%Ix, stringid=%Ix\n",
296 btn_num
, bP
->idCommand
, GETIBITMAP(infoPtr
, bP
->iBitmap
), bP
->fsState
, bP
->fsStyle
, bP
->dwData
, bP
->iString
);
297 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr
,bP
)));
298 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n", btn_num
, bP
->idCommand
, (bP
->bHot
) ? "TRUE":"FALSE", bP
->nRow
,
299 wine_dbgstr_rect(&bP
->rect
));
304 TOOLBAR_DumpToolbar(const TOOLBAR_INFO
*iP
, INT line
)
308 if (!TRACE_ON(toolbar
))
311 TRACE("toolbar %p at line %d, exStyle=%#lx, buttons=%d, bitmaps=%d, strings=%d, style=%#lx\n",
312 iP
->hwndSelf
, line
, iP
->dwExStyle
, iP
->nNumButtons
, iP
->nNumBitmaps
, iP
->nNumStrings
, iP
->dwStyle
);
313 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
314 iP
->hwndSelf
, line
, iP
->himlInt
, iP
->himlDef
, iP
->himlHot
, iP
->himlDis
, (iP
->bDoRedraw
) ? "TRUE" : "FALSE");
316 for (i
= 0; i
< iP
->nNumButtons
; ++i
)
317 TOOLBAR_DumpButton(iP
, &iP
->buttons
[i
], i
);
321 TOOLBAR_ButtonHasString(const TBUTTON_INFO
*btnPtr
)
323 return HIWORD(btnPtr
->iString
) && btnPtr
->iString
!= -1;
326 static void set_string_index( TBUTTON_INFO
*btn
, INT_PTR str
, BOOL unicode
)
328 if (!IS_INTRESOURCE( str
) && str
!= -1)
330 if (!TOOLBAR_ButtonHasString( btn
)) btn
->iString
= 0;
333 Str_SetPtrW( (WCHAR
**)&btn
->iString
, (WCHAR
*)str
);
335 Str_SetPtrAtoW( (WCHAR
**)&btn
->iString
, (char *)str
);
339 if (TOOLBAR_ButtonHasString( btn
)) Free( (WCHAR
*)btn
->iString
);
345 static void set_stringT( TBUTTON_INFO
*btn
, const WCHAR
*str
, BOOL unicode
)
347 if (IS_INTRESOURCE( (DWORD_PTR
)str
) || (DWORD_PTR
)str
== -1) return;
348 set_string_index( btn
, (DWORD_PTR
)str
, unicode
);
351 static void free_string( TBUTTON_INFO
*btn
)
353 set_string_index( btn
, 0, TRUE
);
357 /***********************************************************************
360 * This function validates that the styles set are implemented and
361 * issues FIXMEs warning of possible problems. In a perfect world this
362 * function should be null.
365 TOOLBAR_CheckStyle (const TOOLBAR_INFO
*infoPtr
)
367 if (infoPtr
->dwStyle
& TBSTYLE_REGISTERDROP
)
368 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", infoPtr
->hwndSelf
);
373 TOOLBAR_SendNotify (NMHDR
*nmhdr
, const TOOLBAR_INFO
*infoPtr
, UINT code
)
375 if(!IsWindow(infoPtr
->hwndSelf
))
376 return 0; /* we have just been destroyed */
378 nmhdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
379 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
382 TRACE("to window %p, code=%08x, %s\n", infoPtr
->hwndNotify
, code
,
383 (infoPtr
->bUnicode
) ? "via Unicode" : "via ANSI");
385 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhdr
->idFrom
, (LPARAM
)nmhdr
);
388 /***********************************************************************
389 * TOOLBAR_GetBitmapIndex
391 * This function returns the bitmap index associated with a button.
392 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
393 * is issued to retrieve the index.
396 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
398 INT ret
= btnPtr
->iBitmap
;
400 if (ret
== I_IMAGECALLBACK
)
402 /* issue TBN_GETDISPINFO */
405 memset(&nmgd
, 0, sizeof(nmgd
));
406 nmgd
.idCommand
= btnPtr
->idCommand
;
407 nmgd
.lParam
= btnPtr
->dwData
;
408 nmgd
.dwMask
= TBNF_IMAGE
;
410 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
411 TOOLBAR_SendNotify(&nmgd
.hdr
, infoPtr
, TBN_GETDISPINFOW
);
412 if (nmgd
.dwMask
& TBNF_DI_SETITEM
)
413 btnPtr
->iBitmap
= nmgd
.iImage
;
415 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask %#lx, nNumBitmaps %d\n",
416 ret
, nmgd
.dwMask
, infoPtr
->nNumBitmaps
);
419 if (ret
!= I_IMAGENONE
)
420 ret
= GETIBITMAP(infoPtr
, ret
);
427 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO
*infoPtr
, INT index
)
430 INT id
= GETHIMLID(infoPtr
, index
);
431 INT iBitmap
= GETIBITMAP(infoPtr
, index
);
433 if (((himl
= GETDEFIMAGELIST(infoPtr
, id
)) &&
434 iBitmap
>= 0 && iBitmap
< ImageList_GetImageCount(himl
)) ||
435 (index
== I_IMAGECALLBACK
))
443 TOOLBAR_IsValidImageList(const TOOLBAR_INFO
*infoPtr
, INT index
)
445 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, index
));
446 return (himl
!= NULL
) && (ImageList_GetImageCount(himl
) > 0);
450 /***********************************************************************
451 * TOOLBAR_GetImageListForDrawing
453 * This function validates the bitmap index (including I_IMAGECALLBACK
454 * functionality) and returns the corresponding image list.
457 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
,
458 IMAGE_LIST_TYPE imagelist
, INT
* index
)
462 if (!TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
)) {
463 if (btnPtr
->iBitmap
== I_IMAGENONE
) return NULL
;
464 WARN("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
465 HIWORD(btnPtr
->iBitmap
), LOWORD(btnPtr
->iBitmap
), infoPtr
->nNumBitmaps
);
469 if ((*index
= TOOLBAR_GetBitmapIndex(infoPtr
, btnPtr
)) < 0) {
470 if ((*index
== I_IMAGECALLBACK
) ||
471 (*index
== I_IMAGENONE
)) return NULL
;
472 ERR("TBN_GETDISPINFO returned invalid index %d\n",
479 case IMAGE_LIST_DEFAULT
:
480 himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
483 himl
= GETHOTIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
485 case IMAGE_LIST_DISABLED
:
486 himl
= GETDISIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
490 FIXME("Shouldn't reach here\n");
494 TRACE("no image list\n");
501 TOOLBAR_DrawFlatSeparator (const RECT
*lpRect
, HDC hdc
, const TOOLBAR_INFO
*infoPtr
)
504 COLORREF oldcolor
, newcolor
;
506 myrect
.left
= (lpRect
->left
+ lpRect
->right
) / 2 - 1;
507 myrect
.right
= myrect
.left
+ 1;
508 myrect
.top
= lpRect
->top
+ 2;
509 myrect
.bottom
= lpRect
->bottom
- 2;
511 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
512 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
513 oldcolor
= SetBkColor (hdc
, newcolor
);
514 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
516 myrect
.left
= myrect
.right
;
517 myrect
.right
= myrect
.left
+ 1;
519 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
520 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
521 SetBkColor (hdc
, newcolor
);
522 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
524 SetBkColor (hdc
, oldcolor
);
528 /***********************************************************************
529 * TOOLBAR_DrawFlatHorizontalSeparator
531 * This function draws horizontal separator for toolbars having CCS_VERT style.
532 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
533 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
534 * are horizontal as opposed to the vertical separators for not dropdown
537 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
540 TOOLBAR_DrawFlatHorizontalSeparator (const RECT
*lpRect
, HDC hdc
,
541 const TOOLBAR_INFO
*infoPtr
)
544 COLORREF oldcolor
, newcolor
;
546 myrect
.left
= lpRect
->left
;
547 myrect
.right
= lpRect
->right
;
548 myrect
.top
= lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
- 2)/2;
549 myrect
.bottom
= myrect
.top
+ 1;
551 InflateRect (&myrect
, -2, 0);
553 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect
));
555 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
556 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
557 oldcolor
= SetBkColor (hdc
, newcolor
);
558 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
560 myrect
.top
= myrect
.bottom
;
561 myrect
.bottom
= myrect
.top
+ 1;
563 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
564 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
565 SetBkColor (hdc
, newcolor
);
566 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
568 SetBkColor (hdc
, oldcolor
);
573 TOOLBAR_DrawArrow (HDC hdc
, INT left
, INT top
, COLORREF clr
)
578 if (!(hPen
= CreatePen( PS_SOLID
, 1, clr
))) return;
579 hOldPen
= SelectObject ( hdc
, hPen
);
582 MoveToEx (hdc
, x
, y
, NULL
);
583 LineTo (hdc
, x
+5, y
++); x
++;
584 MoveToEx (hdc
, x
, y
, NULL
);
585 LineTo (hdc
, x
+3, y
++); x
++;
586 MoveToEx (hdc
, x
, y
, NULL
);
587 LineTo (hdc
, x
+1, y
);
588 SelectObject( hdc
, hOldPen
);
589 DeleteObject( hPen
);
593 * Draw the text string for this button.
594 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
595 * is non-zero, so we can simply check himlDef to see if we have
599 TOOLBAR_DrawString (const TOOLBAR_INFO
*infoPtr
, RECT
*rcText
, LPCWSTR lpText
,
600 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
602 HDC hdc
= tbcd
->nmcd
.hdc
;
605 COLORREF clrOldBk
= 0;
607 UINT state
= tbcd
->nmcd
.uItemState
;
610 if (lpText
&& infoPtr
->nMaxTextRows
> 0) {
611 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText
),
612 wine_dbgstr_rect(rcText
));
614 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
615 if ((state
& CDIS_HOT
) && (dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)) {
616 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
618 else if (state
& CDIS_DISABLED
) {
619 clrOld
= SetTextColor (hdc
, tbcd
->clrBtnHighlight
);
620 OffsetRect (rcText
, 1, 1);
621 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
622 SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
623 OffsetRect (rcText
, -1, -1);
625 else if (state
& CDIS_INDETERMINATE
) {
626 clrOld
= SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
628 else if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
)) {
629 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
630 clrOldBk
= SetBkColor (hdc
, tbcd
->clrMark
);
631 oldBkMode
= SetBkMode (hdc
, tbcd
->nHLStringBkMode
);
634 clrOld
= SetTextColor (hdc
, tbcd
->clrText
);
637 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
638 SetTextColor (hdc
, clrOld
);
639 if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
))
641 SetBkColor (hdc
, clrOldBk
);
642 SetBkMode (hdc
, oldBkMode
);
644 SelectObject (hdc
, hOldFont
);
650 TOOLBAR_DrawPattern (const RECT
*lpRect
, const NMTBCUSTOMDRAW
*tbcd
)
652 HDC hdc
= tbcd
->nmcd
.hdc
;
653 HBRUSH hbr
= SelectObject (hdc
, tbcd
->hbrMonoDither
);
656 INT cx
= lpRect
->right
- lpRect
->left
;
657 INT cy
= lpRect
->bottom
- lpRect
->top
;
658 INT cxEdge
= GetSystemMetrics(SM_CXEDGE
);
659 INT cyEdge
= GetSystemMetrics(SM_CYEDGE
);
660 clrTextOld
= SetTextColor(hdc
, tbcd
->clrBtnHighlight
);
661 clrBkOld
= SetBkColor(hdc
, tbcd
->clrBtnFace
);
662 PatBlt (hdc
, lpRect
->left
+ cxEdge
, lpRect
->top
+ cyEdge
,
663 cx
- (2 * cxEdge
), cy
- (2 * cyEdge
), PATCOPY
);
664 SetBkColor(hdc
, clrBkOld
);
665 SetTextColor(hdc
, clrTextOld
);
666 SelectObject (hdc
, hbr
);
670 static void TOOLBAR_DrawMasked(HIMAGELIST himl
, int index
, HDC hdc
, INT x
, INT y
, UINT draw_flags
)
672 IMAGELISTDRAWPARAMS draw_params
= { 0 };
674 HBITMAP hbmMask
, hbmImage
;
675 HDC hdcMask
, hdcImage
;
677 ImageList_GetIconSize(himl
, &cx
, &cy
);
679 draw_params
.cbSize
= sizeof(draw_params
);
680 draw_params
.himl
= himl
;
681 draw_params
.i
= index
;
682 draw_params
.hdcDst
= hdc
;
687 draw_params
.rgbBk
= CLR_NONE
;
688 draw_params
.rgbFg
= CLR_NONE
;
689 draw_params
.fStyle
= draw_flags
;
690 draw_params
.fState
= ILS_NORMAL
;
692 /* 32bpp image with alpha channel is converted to grayscale */
693 if (imagelist_has_alpha(himl
, index
))
695 draw_params
.fState
= ILS_SATURATE
;
696 ImageList_DrawIndirect(&draw_params
);
700 /* Create src image */
701 hdcImage
= CreateCompatibleDC(hdc
);
702 hbmImage
= CreateCompatibleBitmap(hdc
, cx
, cy
);
703 SelectObject(hdcImage
, hbmImage
);
707 draw_params
.rgbBk
= RGB(0xff, 0xff, 0xff);
708 draw_params
.rgbFg
= RGB(0,0,0);
709 draw_params
.hdcDst
= hdcImage
;
710 ImageList_DrawIndirect(&draw_params
);
713 hdcMask
= CreateCompatibleDC(0);
714 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
715 SelectObject(hdcMask
, hbmMask
);
717 /* Remove the background and all white pixels */
718 draw_params
.fStyle
= ILD_MASK
;
719 draw_params
.hdcDst
= hdcMask
;
720 ImageList_DrawIndirect(&draw_params
);
721 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
722 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
724 /* draw the new mask 'etched' to hdc */
725 SetBkColor(hdc
, RGB(255, 255, 255));
726 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
727 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
728 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
729 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
730 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
733 DeleteObject(hbmImage
);
735 DeleteObject (hbmMask
);
741 TOOLBAR_TranslateState(const TBUTTON_INFO
*btnPtr
, BOOL captured
)
745 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
746 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
747 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
748 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
749 retstate
|= (btnPtr
->bHot
& !captured
) ? CDIS_HOT
: 0;
750 retstate
|= ((btnPtr
->fsState
& (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) == (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) ? CDIS_INDETERMINATE
: 0;
751 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
755 /* draws the image on a toolbar button */
757 TOOLBAR_DrawImage(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
,
758 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
760 HIMAGELIST himl
= NULL
;
761 BOOL draw_masked
= FALSE
;
764 UINT draw_flags
= ILD_TRANSPARENT
;
766 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
768 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
771 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
775 else if (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
||
776 ((tbcd
->nmcd
.uItemState
& CDIS_HOT
)
777 && ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || infoPtr
->hTheme
)))
779 /* if hot, attempt to draw with hot image list, if fails,
780 use default image list */
781 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
783 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
786 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
791 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
792 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
795 if (!(dwItemCDFlag
& TBCDRF_NOMARK
) &&
796 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
797 draw_flags
|= ILD_BLEND50
;
799 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
800 index
, himl
, left
, top
, offset
);
803 TOOLBAR_DrawMasked (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
805 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
808 /* draws a blank frame for a toolbar button */
810 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, const RECT
*rect
, DWORD dwItemCDFlag
)
812 HDC hdc
= tbcd
->nmcd
.hdc
;
814 /* if the state is disabled or indeterminate then the button
815 * cannot have an interactive look like pressed or hot */
816 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
817 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
818 BOOL pressed_look
= !non_interactive_state
&&
819 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
820 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
822 /* app don't want us to draw any edges */
823 if (dwItemCDFlag
& TBCDRF_NOEDGES
)
826 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
829 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
830 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
831 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
836 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
838 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
839 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
844 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
, BOOL bDropDownPressed
, DWORD dwItemCDFlag
)
846 HDC hdc
= tbcd
->nmcd
.hdc
;
848 BOOL pressed
= bDropDownPressed
||
849 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
));
851 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
854 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
);
855 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
856 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
857 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
858 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
863 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
865 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
866 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
870 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
872 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
874 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
875 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
878 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
881 /* draws a complete toolbar button */
883 TOOLBAR_DrawButton (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, HDC hdc
, DWORD dwBaseCustDraw
)
885 DWORD dwStyle
= infoPtr
->dwStyle
;
886 BOOL hasDropDownArrow
= button_has_ddarrow( infoPtr
, btnPtr
);
887 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
888 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
889 RECT rc
, rcArrow
, rcBitmap
, rcText
;
890 LPWSTR lpText
= NULL
;
895 DWORD dwItemCustDraw
;
897 HTHEME theme
= infoPtr
->hTheme
;
902 /* separator - doesn't send NM_CUSTOMDRAW */
903 if (btnPtr
->fsStyle
& BTNS_SEP
) {
906 DrawThemeBackground (theme
, hdc
,
907 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
911 /* with the FLAT style, iBitmap is the width and has already */
912 /* been taken into consideration in calculating the width */
913 /* so now we need to draw the vertical separator */
914 /* empirical tests show that iBitmap can/will be non-zero */
915 /* when drawing the vertical bar... */
916 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
917 if (dwStyle
& CCS_VERT
) {
919 InflateRect(&rcsep
, -infoPtr
->szPadding
.cx
, -infoPtr
->szPadding
.cy
);
920 TOOLBAR_DrawFlatHorizontalSeparator (&rcsep
, hdc
, infoPtr
);
923 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
925 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
926 FIXME("Draw some kind of separator: fsStyle=%x\n",
932 /* get a pointer to the text */
933 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
935 if (hasDropDownArrow
)
939 if (dwStyle
& TBSTYLE_FLAT
)
940 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
942 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
944 if (drawSepDropDownArrow
)
947 rcArrow
.left
= right
;
950 /* copy text & bitmap rects after adjusting for drop-down arrow
951 * so that text & bitmap is centered in the rectangle not containing
956 /* Center the bitmap horizontally and vertically */
957 if (dwStyle
& TBSTYLE_LIST
)
960 infoPtr
->nMaxTextRows
> 0 &&
961 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
962 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
963 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
965 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
968 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
970 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
972 TRACE("iBitmap=%d, start=(%ld,%ld) w=%d, h=%d\n", btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
973 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
974 TRACE("Text=%s\n", debugstr_w(lpText
));
975 TRACE("iListGap=%d, padding = { %ld, %ld }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
977 /* calculate text position */
980 InflateRect(&rcText
, -GetSystemMetrics(SM_CXEDGE
), 0);
981 if (dwStyle
& TBSTYLE_LIST
)
983 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
987 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
988 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
990 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
994 /* Initialize fields in all cases, because we use these later
995 * NOTE: applications can and do alter these to customize their
997 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
998 tbcd
.clrText
= comctl32_color
.clrBtnText
;
999 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
1000 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
1001 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
1002 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
1003 tbcd
.clrHighlightHotTrack
= 0;
1004 tbcd
.nStringBkMode
= TRANSPARENT
;
1005 tbcd
.nHLStringBkMode
= OPAQUE
;
1006 tbcd
.rcText
.left
= 0;
1007 tbcd
.rcText
.top
= 0;
1008 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
1009 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
1010 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
, infoPtr
->bCaptured
);
1011 tbcd
.nmcd
.hdc
= hdc
;
1012 tbcd
.nmcd
.rc
= btnPtr
->rect
;
1013 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
1015 /* FIXME: what are these used for? */
1019 /* Issue Item Prepaint notify */
1022 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
1024 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
1025 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
1026 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
1027 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1028 /* reset these fields so the user can't alter the behaviour like native */
1029 tbcd
.nmcd
.hdc
= hdc
;
1030 tbcd
.nmcd
.rc
= btnPtr
->rect
;
1032 dwItemCustDraw
= ntfret
& 0xffff;
1033 dwItemCDFlag
= ntfret
& 0xffff0000;
1034 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
1036 /* save the only part of the rect that the user can change */
1037 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
1038 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
1041 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
1042 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
1043 OffsetRect(&rcText
, 1, 1);
1045 if (!theme
&& !(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
1046 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
1047 TOOLBAR_DrawPattern (&rc
, &tbcd
);
1049 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || theme
) && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
1051 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
1055 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
1056 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
1057 if (hasDropDownArrow
)
1058 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
1059 SetBkColor(hdc
, oldclr
);
1065 if (!(dwItemCDFlag
& TBCDRF_NOBACKGROUND
))
1067 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
1068 int stateId
= TS_NORMAL
;
1070 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1071 stateId
= TS_DISABLED
;
1072 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1073 stateId
= TS_PRESSED
;
1074 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1075 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_CHECKED
;
1076 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1077 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1080 DrawThemeBackground(theme
, hdc
, partId
, stateId
, &rc
, NULL
);
1084 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, &rc
, dwItemCDFlag
);
1086 if (drawSepDropDownArrow
)
1090 int stateId
= TS_NORMAL
;
1092 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1093 stateId
= TS_DISABLED
;
1094 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1095 stateId
= TS_PRESSED
;
1096 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1097 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_CHECKED
;
1098 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1101 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1102 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1105 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1108 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1109 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1110 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1111 SetBkMode (hdc
, oldBkMode
);
1113 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1115 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1117 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1119 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1120 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1122 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1124 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1125 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1128 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1131 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1133 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1134 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1141 TOOLBAR_Refresh (TOOLBAR_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
1143 TBUTTON_INFO
*btnPtr
;
1145 RECT rcTemp
, rcClient
;
1146 NMTBCUSTOMDRAW tbcd
;
1148 DWORD dwBaseCustDraw
;
1150 /* the app has told us not to redraw the toolbar */
1151 if (!infoPtr
->bDoRedraw
)
1154 /* if imagelist belongs to the app, it can be changed
1155 by the app after setting it */
1156 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1158 infoPtr
->nNumBitmaps
= 0;
1159 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1160 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1163 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1165 /* change the imagelist icon size if we manage the list and it is necessary */
1166 TOOLBAR_CheckImageListIconSize(infoPtr
);
1168 /* Send initial notify */
1169 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1170 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1171 tbcd
.nmcd
.hdc
= hdc
;
1172 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1173 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1174 dwBaseCustDraw
= ntfret
& 0xffff;
1176 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1178 /* redraw necessary buttons */
1179 btnPtr
= infoPtr
->buttons
;
1180 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1183 if (!RectVisible(hdc
, &btnPtr
->rect
))
1185 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1187 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1188 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1192 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1193 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1195 TOOLBAR_DrawButton(infoPtr
, btnPtr
, hdc
, dwBaseCustDraw
);
1198 /* draw insert mark if required */
1199 if (infoPtr
->tbim
.iButton
!= -1)
1201 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1203 rcInsertMark
.top
= rcButton
.top
;
1204 rcInsertMark
.bottom
= rcButton
.bottom
;
1205 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1206 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1208 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1209 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1212 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1214 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1215 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1216 tbcd
.nmcd
.hdc
= hdc
;
1217 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1218 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1222 /***********************************************************************
1223 * TOOLBAR_MeasureString
1225 * This function gets the width and height of a string in pixels. This
1226 * is done first by using GetTextExtentPoint to get the basic width
1227 * and height. The DrawText is called with DT_CALCRECT to get the exact
1228 * width. The reason is because the text may have more than one "&" (or
1229 * prefix characters as M$ likes to call them). The prefix character
1230 * indicates where the underline goes, except for the string "&&" which
1231 * is reduced to a single "&". GetTextExtentPoint does not process these
1232 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1235 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1236 HDC hdc
, LPSIZE lpSize
)
1243 if (infoPtr
->nMaxTextRows
> 0 &&
1244 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1245 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1246 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1248 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1250 if(lpText
!= NULL
) {
1251 /* first get size of all the text */
1252 GetTextExtentPoint32W (hdc
, lpText
, lstrlenW (lpText
), lpSize
);
1254 /* feed above size into the rectangle for DrawText */
1255 SetRect(&myrect
, 0, 0, lpSize
->cx
, lpSize
->cy
);
1257 /* Use DrawText to get true size as drawn (less pesky "&") */
1258 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1259 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1262 /* feed back to caller */
1263 lpSize
->cx
= myrect
.right
;
1264 lpSize
->cy
= myrect
.bottom
;
1268 TRACE("string size %ld x %ld.\n", lpSize
->cx
, lpSize
->cy
);
1271 /***********************************************************************
1272 * TOOLBAR_CalcStrings
1274 * This function walks through each string and measures it and returns
1275 * the largest height and width to caller.
1278 TOOLBAR_CalcStrings (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
1280 TBUTTON_INFO
*btnPtr
;
1289 if (infoPtr
->nMaxTextRows
== 0)
1292 hdc
= GetDC (infoPtr
->hwndSelf
);
1293 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1295 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1299 GetTextMetricsW(hdc
, &tm
);
1300 lpSize
->cy
= tm
.tmHeight
;
1303 btnPtr
= infoPtr
->buttons
;
1304 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1305 if(TOOLBAR_GetText(infoPtr
, btnPtr
))
1307 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1308 if (sz
.cx
> lpSize
->cx
)
1310 if (sz
.cy
> lpSize
->cy
)
1315 SelectObject (hdc
, hOldFont
);
1316 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1318 TRACE("max string size %ld x %ld\n", lpSize
->cx
, lpSize
->cy
);
1321 /***********************************************************************
1322 * TOOLBAR_WrapToolbar
1324 * This function walks through the buttons and separators in the
1325 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1326 * wrapping should occur based on the width of the toolbar window.
1327 * It does *not* calculate button placement itself. That task
1328 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1329 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1330 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1332 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_VERTICAL can be used also to allow
1333 * vertical toolbar lists.
1337 TOOLBAR_WrapToolbar(TOOLBAR_INFO
*infoPtr
)
1339 TBUTTON_INFO
*btnPtr
;
1340 INT x
, cx
, i
, j
, width
;
1343 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1344 /* no layout is necessary. Applications may use this style */
1345 /* to perform their own layout on the toolbar. */
1346 if( !(infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) &&
1347 !(infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
) ) return;
1349 btnPtr
= infoPtr
->buttons
;
1350 x
= infoPtr
->nIndent
;
1351 width
= infoPtr
->client_rect
.right
- infoPtr
->client_rect
.left
;
1353 bButtonWrap
= FALSE
;
1355 TRACE("start ButtonWidth=%d, BitmapWidth=%d, width=%d, nIndent=%d\n",
1356 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, width
,
1359 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1361 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1363 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1366 if (btnPtr
[i
].cx
> 0)
1368 /* horizontal separators are treated as buttons for width */
1369 else if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1370 !(infoPtr
->dwStyle
& CCS_VERT
))
1371 cx
= (btnPtr
[i
].iBitmap
> 0) ? btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1373 cx
= infoPtr
->nButtonWidth
;
1375 if (!btnPtr
[i
].cx
&& button_has_ddarrow( infoPtr
, btnPtr
+ i
))
1376 cx
+= DDARROW_WIDTH
;
1378 /* Two or more adjacent separators form a separator group. */
1379 /* The first separator in a group should be wrapped to the */
1380 /* next row if the previous wrapping is on a button. */
1382 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1383 (i
+ 1 < infoPtr
->nNumButtons
) &&
1384 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1386 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1387 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1388 x
= infoPtr
->nIndent
;
1390 bButtonWrap
= FALSE
;
1394 /* The layout makes sure the bitmap is visible, but not the button. */
1395 /* Test added to also wrap after a button that starts a row but */
1396 /* is bigger than the area. - GA 8/01 */
1397 if ((x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2 > width
) ||
1398 ((x
== infoPtr
->nIndent
) && (cx
> width
)))
1400 BOOL bFound
= FALSE
;
1402 /* If the current button is a separator and not hidden, */
1403 /* go to the next until it reaches a non separator. */
1404 /* Wrap the last separator if it is before a button. */
1405 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1406 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1407 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1408 i
< infoPtr
->nNumButtons
)
1414 if( bFound
&& i
< infoPtr
->nNumButtons
)
1417 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1418 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1419 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1420 x
= infoPtr
->nIndent
;
1421 bButtonWrap
= FALSE
;
1424 else if ( i
>= infoPtr
->nNumButtons
)
1427 /* If the current button is not a separator, find the last */
1428 /* separator and wrap it. */
1429 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1431 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1432 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1436 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1437 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1438 x
= infoPtr
->nIndent
;
1439 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1440 bButtonWrap
= FALSE
;
1445 /* If no separator available for wrapping, wrap one of */
1446 /* non-hidden previous button. */
1450 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1452 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1457 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1458 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1459 x
= infoPtr
->nIndent
;
1460 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1466 /* If all above failed, wrap the current button. */
1469 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1470 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1471 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1472 x
= infoPtr
->nIndent
;
1473 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1474 bButtonWrap
= FALSE
;
1480 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1481 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1488 /***********************************************************************
1489 * TOOLBAR_MeasureButton
1491 * Calculates the width and height required for a button. Used in
1492 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1493 * the width of buttons that are autosized.
1495 * Note that it would have been rather elegant to use one piece of code for
1496 * both the laying out of the toolbar and for controlling where button parts
1497 * are drawn, but the native control has inconsistencies between the two that
1498 * prevent this from being effectively. These inconsistencies can be seen as
1499 * artefacts where parts of the button appear outside of the bounding button
1502 * There are several cases for the calculation of the button dimensions and
1503 * button part positioning:
1510 * +--------------------------------------------------------+ ^
1512 * | | pad.cy / 2 | centered | |
1513 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1514 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1515 * | |<------------>| | | | |
1516 * | +--------------+ +------------+ | |
1517 * |<-------------------------------------->| | |
1518 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1520 * +--------------------------------------------------------+ -
1521 * <-------------------------------------------------------->
1522 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1524 * Without Bitmap (I_IMAGENONE):
1526 * +-----------------------------------+ ^
1528 * | | centered | | LISTPAD_CY +
1529 * | +------------+ | | szText.cy
1532 * | +------------+ | |
1533 * |<----------------->| | |
1534 * | cxedge |<-----------> | |
1536 * +-----------------------------------+ -
1537 * <----------------------------------->
1538 * szText.cx + pad.cx
1542 * +--------------------------------------+ ^
1544 * | | padding.cy/2 | | DEFPAD_CY +
1545 * | +------------+ | | nBitmapHeight
1548 * | +------------+ | |
1549 * |<------------------->| | |
1550 * | cxedge + iListGap/2 |<-----------> | |
1551 * | nBitmapWidth | |
1552 * +--------------------------------------+ -
1553 * <-------------------------------------->
1554 * 2*cxedge + nBitmapWidth + iListGap
1561 * +-----------------------------------+ ^
1563 * | | pad.cy / 2 | | nBitmapHeight +
1564 * | - | | szText.cy +
1565 * | +------------+ | | DEFPAD_CY + 1
1566 * | centered | Bitmap | | |
1567 * |<----------------->| | | |
1568 * | +------------+ | |
1572 * | centered +---------------+ | |
1573 * |<--------------->| Text | | |
1574 * | +---------------+ | |
1575 * +-----------------------------------+ -
1576 * <----------------------------------->
1577 * pad.cx + max(nBitmapWidth, szText.cx)
1579 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1581 * +---------------------------------------+ ^
1583 * | | 2 + pad.cy / 2 | |
1584 * | - | | szText.cy +
1585 * | centered +-----------------+ | | pad.cy + 2
1586 * |<--------------->| Text | | |
1587 * | +-----------------+ | |
1589 * +---------------------------------------+ -
1590 * <--------------------------------------->
1591 * 2*cxedge + pad.cx + szText.cx
1594 * As for with bitmaps, but with szText.cx zero.
1596 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1597 BOOL bHasBitmap
, BOOL bValidImageList
)
1600 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1602 /* set button height from bitmap / text height... */
1603 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1606 /* ... add on the necessary padding */
1607 if (bValidImageList
)
1610 sizeButton
.cy
+= DEFPAD_CY
;
1612 sizeButton
.cy
+= LISTPAD_CY
;
1615 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1617 /* calculate button width */
1618 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1619 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1620 if (sizeString
.cx
> 0)
1621 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1628 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1629 if (sizeString
.cy
> 0)
1630 sizeButton
.cy
+= 1 + sizeString
.cy
;
1631 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1632 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1636 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1637 NONLIST_NOTEXT_OFFSET
;
1638 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1639 max(2*GetSystemMetrics(SM_CXEDGE
) + sizeString
.cx
, infoPtr
->nBitmapWidth
);
1646 /***********************************************************************
1647 * TOOLBAR_CalcToolbar
1649 * This function calculates button and separator placement. It first
1650 * calculates the button sizes, gets the toolbar window width and then
1651 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1652 * on. It assigns a new location to each item and sends this location to
1653 * the tooltip window if appropriate. Finally, it updates the rcBound
1654 * rect and calculates the new required toolbar window height.
1657 TOOLBAR_CalcToolbar (TOOLBAR_INFO
*infoPtr
)
1659 SIZE sizeString
, sizeButton
;
1660 BOOL validImageList
= FALSE
;
1662 TOOLBAR_CalcStrings (infoPtr
, &sizeString
);
1664 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1666 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1667 validImageList
= TRUE
;
1668 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1669 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1670 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1671 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1673 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1674 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1675 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1676 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1678 TOOLBAR_LayoutToolbar(infoPtr
);
1682 TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
)
1684 TBUTTON_INFO
*btnPtr
;
1686 INT i
, nRows
, nSepRows
;
1689 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1691 TOOLBAR_WrapToolbar(infoPtr
);
1693 x
= infoPtr
->nIndent
;
1694 y
= infoPtr
->iTopMargin
;
1695 cx
= infoPtr
->nButtonWidth
;
1696 cy
= infoPtr
->nButtonHeight
;
1698 nRows
= nSepRows
= 0;
1700 infoPtr
->rcBound
.top
= y
;
1701 infoPtr
->rcBound
.left
= x
;
1702 infoPtr
->rcBound
.bottom
= y
+ cy
;
1703 infoPtr
->rcBound
.right
= x
;
1705 btnPtr
= infoPtr
->buttons
;
1707 TRACE("cy=%d\n", cy
);
1709 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1712 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1714 SetRectEmpty (&btnPtr
->rect
);
1715 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1719 cy
= infoPtr
->nButtonHeight
;
1721 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1722 if (infoPtr
->dwStyle
& CCS_VERT
) {
1723 cy
= (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1724 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
: infoPtr
->nButtonWidth
;
1727 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
:
1728 (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1734 else if (btnPtr
->fsStyle
& BTNS_AUTOSIZE
)
1740 hdc
= GetDC (infoPtr
->hwndSelf
);
1741 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1743 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1745 SelectObject (hdc
, hOldFont
);
1746 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1748 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1749 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1754 cx
= infoPtr
->nButtonWidth
;
1756 /* if size has been set manually then don't add on extra space
1757 * for the drop down arrow */
1758 if (!btnPtr
->cx
&& button_has_ddarrow( infoPtr
, btnPtr
))
1759 cx
+= DDARROW_WIDTH
;
1761 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1764 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1766 if (infoPtr
->rcBound
.left
> x
)
1767 infoPtr
->rcBound
.left
= x
;
1768 if (infoPtr
->rcBound
.right
< x
+ cx
)
1769 infoPtr
->rcBound
.right
= x
+ cx
;
1770 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1771 infoPtr
->rcBound
.bottom
= y
+ cy
;
1773 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1775 /* btnPtr->nRow is zero based. The space between the rows is */
1776 /* also considered as a row. */
1777 btnPtr
->nRow
= nRows
+ nSepRows
;
1779 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1780 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1785 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1789 if ( !(infoPtr
->dwStyle
& CCS_VERT
))
1790 y
+= cy
+ ( (btnPtr
->cx
> 0 ) ?
1791 btnPtr
->cx
: SEPARATOR_WIDTH
) * 2 /3;
1795 /* nSepRows is used to calculate the extra height following */
1799 x
= infoPtr
->nIndent
;
1801 /* Increment row number unless this is the last button */
1802 /* and it has Wrap set. */
1803 if (i
!= infoPtr
->nNumButtons
-1)
1810 /* infoPtr->nRows is the number of rows on the toolbar */
1811 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1813 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1818 TOOLBAR_InternalHitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
*lpPt
, BOOL
*button
)
1820 TBUTTON_INFO
*btnPtr
;
1826 btnPtr
= infoPtr
->buttons
;
1827 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1828 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1831 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1832 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1833 TRACE(" ON SEPARATOR %d\n", i
);
1838 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1839 TRACE(" ON BUTTON %d\n", i
);
1847 TRACE(" NOWHERE\n");
1848 return TOOLBAR_NOWHERE
;
1852 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1854 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO
*infoPtr
, INT iIndex
, UINT nAddButtons
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
1856 INT nOldButtons
, nNewButtons
, iButton
;
1857 BOOL fHasString
= FALSE
;
1859 if (iIndex
< 0) /* iIndex can be negative, what means adding at the end */
1860 iIndex
= infoPtr
->nNumButtons
;
1862 nOldButtons
= infoPtr
->nNumButtons
;
1863 nNewButtons
= nOldButtons
+ nAddButtons
;
1865 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
1866 memmove(&infoPtr
->buttons
[iIndex
+ nAddButtons
], &infoPtr
->buttons
[iIndex
],
1867 (nOldButtons
- iIndex
) * sizeof(TBUTTON_INFO
));
1868 infoPtr
->nNumButtons
+= nAddButtons
;
1870 /* insert new buttons data */
1871 for (iButton
= 0; iButton
< nAddButtons
; iButton
++) {
1872 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[iIndex
+ iButton
];
1875 TOOLBAR_DumpTBButton(lpTbb
+ iButton
, fUnicode
);
1877 ZeroMemory(btnPtr
, sizeof(*btnPtr
));
1879 btnPtr
->iBitmap
= lpTbb
[iButton
].iBitmap
;
1880 btnPtr
->idCommand
= lpTbb
[iButton
].idCommand
;
1881 btnPtr
->fsState
= lpTbb
[iButton
].fsState
;
1882 btnPtr
->fsStyle
= lpTbb
[iButton
].fsStyle
;
1883 btnPtr
->dwData
= lpTbb
[iButton
].dwData
;
1885 if (btnPtr
->fsStyle
& BTNS_SEP
)
1888 str
= lpTbb
[iButton
].iString
;
1889 set_string_index( btnPtr
, str
, fUnicode
);
1890 fHasString
|= TOOLBAR_ButtonHasString( btnPtr
);
1892 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
1895 if (infoPtr
->nNumStrings
> 0 || fHasString
)
1896 TOOLBAR_CalcToolbar(infoPtr
);
1898 TOOLBAR_LayoutToolbar(infoPtr
);
1899 TOOLBAR_AutoSize(infoPtr
);
1901 TOOLBAR_DumpToolbar(infoPtr
, __LINE__
);
1902 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1908 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1910 TBUTTON_INFO
*btnPtr
;
1913 if (CommandIsIndex
) {
1914 TRACE("command is really index command=%d\n", idCommand
);
1915 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1918 btnPtr
= infoPtr
->buttons
;
1919 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1920 if (btnPtr
->idCommand
== idCommand
) {
1921 TRACE("command=%d index=%d\n", idCommand
, i
);
1925 TRACE("no index found for command=%d\n", idCommand
);
1931 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1933 TBUTTON_INFO
*btnPtr
;
1936 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1939 /* check index button */
1940 btnPtr
= &infoPtr
->buttons
[nIndex
];
1941 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1942 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1946 /* check previous buttons */
1947 nRunIndex
= nIndex
- 1;
1948 while (nRunIndex
>= 0) {
1949 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1950 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1951 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1959 /* check next buttons */
1960 nRunIndex
= nIndex
+ 1;
1961 while (nRunIndex
< infoPtr
->nNumButtons
) {
1962 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1963 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1964 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1977 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1978 WPARAM wParam
, LPARAM lParam
)
1984 msg
.wParam
= wParam
;
1985 msg
.lParam
= lParam
;
1986 msg
.time
= GetMessageTime ();
1987 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
1988 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
1990 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1994 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1996 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
1999 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
2000 ti
.cbSize
= sizeof (TTTOOLINFOW
);
2001 ti
.hwnd
= infoPtr
->hwndSelf
;
2002 ti
.uId
= button
->idCommand
;
2004 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
2005 /* ti.lParam = random value from the stack? */
2007 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
2013 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2015 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
2018 ZeroMemory(&ti
, sizeof(ti
));
2019 ti
.cbSize
= sizeof(ti
);
2020 ti
.hwnd
= infoPtr
->hwndSelf
;
2021 ti
.uId
= button
->idCommand
;
2023 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
2027 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2029 /* Set the toolTip only for non-hidden, non-separator button */
2030 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
2034 ZeroMemory(&ti
, sizeof(ti
));
2035 ti
.cbSize
= sizeof(ti
);
2036 ti
.hwnd
= infoPtr
->hwndSelf
;
2037 ti
.uId
= button
->idCommand
;
2038 ti
.rect
= button
->rect
;
2039 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
2043 /* Creates the tooltip control */
2045 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
2048 NMTOOLTIPSCREATED nmttc
;
2050 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
2051 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2052 infoPtr
->hwndSelf
, 0, 0, 0);
2054 if (!infoPtr
->hwndToolTip
)
2057 /* Send NM_TOOLTIPSCREATED notification */
2058 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
2059 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
2061 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
2063 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
2064 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
2068 /* keeps available button list box sorted by button id */
2069 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
2073 PCUSTOMBUTTON btnInfo
;
2074 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2076 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
2078 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2080 /* position 0 is always separator */
2081 for (i
= 1; i
< count
; i
++)
2083 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2084 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2086 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2087 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2091 /* id higher than all others add to end */
2092 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2093 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2096 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2100 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2102 if (nIndexFrom
== nIndexTo
)
2105 /* MSDN states that iItem is the index of the button, rather than the
2106 * command ID as used by every other NMTOOLBAR notification */
2107 nmtb
.iItem
= nIndexFrom
;
2108 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2110 PCUSTOMBUTTON btnInfo
;
2112 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2113 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2115 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2117 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2118 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2119 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2120 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2123 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2125 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2127 /* last item is always separator, so -2 instead of -1 */
2128 if (nIndexTo
>= (count
- 2))
2129 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2131 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2133 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2134 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2136 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2140 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2144 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2146 /* MSDN states that iItem is the index of the button, rather than the
2147 * command ID as used by every other NMTOOLBAR notification */
2148 nmtb
.iItem
= nIndexAvail
;
2149 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2151 PCUSTOMBUTTON btnInfo
;
2153 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2154 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2155 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2157 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2159 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2161 /* remove from 'available buttons' list */
2162 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2163 if (nIndexAvail
== count
-1)
2164 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2166 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2170 PCUSTOMBUTTON btnNew
;
2172 /* duplicate 'separator' button */
2173 btnNew
= Alloc(sizeof(CUSTOMBUTTON
));
2178 /* insert into 'toolbar button' list */
2179 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2180 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2182 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2184 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2188 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2190 PCUSTOMBUTTON btnInfo
;
2191 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2193 TRACE("Remove: index %d\n", index
);
2195 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2197 /* send TBN_QUERYDELETE notification */
2198 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2202 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2203 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2205 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2207 /* insert into 'available button' list */
2208 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2209 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2213 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2217 /* drag list notification function for toolbar buttons list box */
2218 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2219 const DRAGLISTINFO
*pDLI
)
2221 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2222 switch (pDLI
->uNotification
)
2226 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2227 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2228 /* no dragging for last item (separator) */
2229 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2234 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2235 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2236 /* no dragging past last item (separator) */
2237 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2239 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2240 /* FIXME: native uses "move button" cursor */
2241 return DL_COPYCURSOR
;
2244 /* not over toolbar buttons list */
2245 if (nCurrentItem
< 0)
2247 POINT ptWindow
= pDLI
->ptCursor
;
2248 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2249 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2250 /* over available buttons list? */
2251 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2252 /* FIXME: native uses "move button" cursor */
2253 return DL_COPYCURSOR
;
2255 /* clear drag arrow */
2256 DrawInsert(hwnd
, hwndList
, -1);
2257 return DL_STOPCURSOR
;
2261 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2262 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2263 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2264 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2266 /* clear drag arrow */
2267 DrawInsert(hwnd
, hwndList
, -1);
2269 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2271 /* not over toolbar buttons list */
2274 POINT ptWindow
= pDLI
->ptCursor
;
2275 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2276 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2277 /* over available buttons list? */
2278 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2279 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2284 /* Clear drag arrow */
2285 DrawInsert(hwnd
, hwndList
, -1);
2292 /* drag list notification function for available buttons list box */
2293 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2294 const DRAGLISTINFO
*pDLI
)
2296 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2297 switch (pDLI
->uNotification
)
2303 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2304 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2305 /* no dragging past last item (separator) */
2306 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2308 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2309 /* FIXME: native uses "move button" cursor */
2310 return DL_COPYCURSOR
;
2313 /* not over toolbar buttons list */
2314 if (nCurrentItem
< 0)
2316 POINT ptWindow
= pDLI
->ptCursor
;
2317 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2318 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2319 /* over available buttons list? */
2320 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2321 /* FIXME: native uses "move button" cursor */
2322 return DL_COPYCURSOR
;
2324 /* clear drag arrow */
2325 DrawInsert(hwnd
, hwndList
, -1);
2326 return DL_STOPCURSOR
;
2330 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2331 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2332 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2333 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2335 /* clear drag arrow */
2336 DrawInsert(hwnd
, hwndList
, -1);
2338 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2342 /* Clear drag arrow */
2343 DrawInsert(hwnd
, hwndList
, -1);
2349 extern UINT uDragListMessage DECLSPEC_HIDDEN
;
2351 /***********************************************************************
2352 * TOOLBAR_CustomizeDialogProc
2353 * This function implements the toolbar customization dialog.
2355 static INT_PTR CALLBACK
2356 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2358 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2359 PCUSTOMBUTTON btnInfo
;
2361 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2366 custInfo
= (PCUSTDLG_INFO
)lParam
;
2367 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2374 NMTBINITCUSTOMIZE nmtbic
;
2376 infoPtr
= custInfo
->tbInfo
;
2378 /* send TBN_QUERYINSERT notification */
2379 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2381 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2384 nmtbic
.hwndDialog
= hwnd
;
2385 /* Send TBN_INITCUSTOMIZE notification */
2386 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2389 TRACE("TBNRF_HIDEHELP requested\n");
2390 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2393 /* add items to 'toolbar buttons' list and check if removable */
2394 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2396 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2397 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2398 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2399 btnInfo
->bVirtual
= FALSE
;
2400 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2402 /* send TBN_QUERYDELETE notification */
2403 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2405 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2406 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2409 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2411 /* insert separator button into 'available buttons' list */
2412 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2413 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2414 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2415 btnInfo
->bVirtual
= FALSE
;
2416 btnInfo
->bRemovable
= TRUE
;
2417 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2418 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2419 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2421 /* insert all buttons into dsa */
2424 /* send TBN_GETBUTTONINFO notification */
2427 nmtb
.pszText
= Buffer
;
2430 /* Clear previous button's text */
2431 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2433 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2436 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%Id) %s\n",
2437 nmtb
.tbButton
.fsStyle
, i
,
2438 nmtb
.tbButton
.idCommand
,
2439 nmtb
.tbButton
.iString
,
2440 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2443 /* insert button into the appropriate list */
2444 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2447 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2448 btnInfo
->bVirtual
= FALSE
;
2449 btnInfo
->bRemovable
= TRUE
;
2453 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2454 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2457 btnInfo
->btn
= nmtb
.tbButton
;
2458 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2461 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2462 else if (nmtb
.tbButton
.iString
>= 0 &&
2463 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2465 lstrcpyW(btnInfo
->text
,
2466 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2471 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2474 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2476 /* select first item in the 'available' list */
2477 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2479 /* append 'virtual' separator button to the 'toolbar buttons' list */
2480 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2481 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2482 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2483 btnInfo
->bVirtual
= TRUE
;
2484 btnInfo
->bRemovable
= FALSE
;
2485 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2486 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2487 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2489 /* select last item in the 'toolbar' list */
2490 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2491 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2493 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2494 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2496 /* set focus and disable buttons */
2497 PostMessageW (hwnd
, WM_USER
, 0, 0);
2502 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2503 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2504 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2505 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2509 EndDialog(hwnd
, FALSE
);
2513 switch (LOWORD(wParam
))
2515 case IDC_TOOLBARBTN_LBOX
:
2516 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2518 PCUSTOMBUTTON btnInfo
;
2523 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2524 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2526 /* send TBN_QUERYINSERT notification */
2528 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2530 /* get list box item */
2531 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2533 if (index
== (count
- 1))
2535 /* last item (virtual separator) */
2536 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2537 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2539 else if (index
== (count
- 2))
2541 /* second last item (last non-virtual item) */
2542 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2543 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2545 else if (index
== 0)
2548 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2549 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2553 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2554 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2557 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2561 case IDC_MOVEUP_BTN
:
2563 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2564 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2568 case IDC_MOVEDN_BTN
: /* move down */
2570 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2571 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2575 case IDC_REMOVE_BTN
: /* remove button */
2577 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2579 if (LB_ERR
== index
)
2582 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2586 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2589 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2592 case IDOK
: /* Add button */
2597 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2598 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2600 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2605 EndDialog(hwnd
, FALSE
);
2615 /* delete items from 'toolbar buttons' listbox*/
2616 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2617 for (i
= 0; i
< count
; i
++)
2619 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2621 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2623 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2626 /* delete items from 'available buttons' listbox*/
2627 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2628 for (i
= 0; i
< count
; i
++)
2630 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2632 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2634 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2639 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2641 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2646 COLORREF oldText
= 0;
2650 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, lpdis
->itemID
, 0);
2651 if (btnInfo
== NULL
)
2653 FIXME("btnInfo invalid\n");
2657 /* set colors and select objects */
2658 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2659 if (btnInfo
->bVirtual
)
2660 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2662 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2663 hPen
= CreatePen( PS_SOLID
, 1,
2664 (lpdis
->itemState
& ODS_SELECTED
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2665 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2666 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2668 /* fill background rectangle */
2669 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2670 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2672 /* calculate button and text rectangles */
2673 rcButton
= lpdis
->rcItem
;
2674 InflateRect (&rcButton
, -1, -1);
2676 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2677 rcText
.left
= rcButton
.right
+ 2;
2679 /* draw focus rectangle */
2680 if (lpdis
->itemState
& ODS_FOCUS
)
2681 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2684 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2685 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2687 /* draw image and text */
2688 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2689 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2690 btnInfo
->btn
.iBitmap
));
2691 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2692 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2694 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2695 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2697 /* delete objects and reset colors */
2698 SelectObject (lpdis
->hDC
, hOldBrush
);
2699 SelectObject (lpdis
->hDC
, hOldPen
);
2700 SetBkColor (lpdis
->hDC
, oldBk
);
2701 SetTextColor (lpdis
->hDC
, oldText
);
2702 DeleteObject( hPen
);
2707 case WM_MEASUREITEM
:
2708 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2710 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2712 lpmis
->itemHeight
= 15 + 8; /* default height */
2719 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2721 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2723 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2724 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2725 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2728 else if (wParam
== IDC_AVAILBTN_LBOX
)
2730 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2731 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2732 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2741 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2744 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2750 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2751 /* Add bitmaps to the default image list */
2752 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2753 hbmLoad
= CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2754 else if (bitmap
->hInst
== COMCTL32_hModule
)
2755 hbmLoad
= LoadImageW( bitmap
->hInst
, MAKEINTRESOURCEW(bitmap
->nID
),
2756 IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
2758 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2760 /* enlarge the bitmap if needed */
2761 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2762 if (bitmap
->hInst
!= COMCTL32_hModule
)
2763 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2765 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2766 DeleteObject(hbmLoad
);
2770 nCountAfter
= ImageList_GetImageCount(himlDef
);
2771 nAdded
= nCountAfter
- nCountBefore
;
2772 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2774 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2775 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2776 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2777 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2780 infoPtr
->nNumBitmaps
+= nAdded
;
2785 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2792 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2793 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2795 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2797 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2800 TRACE("Update icon size: %dx%d -> %dx%d\n",
2801 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2803 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2804 ILC_COLOR32
|ILC_MASK
, 8, 2);
2805 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2806 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2807 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2808 infoPtr
->himlInt
= himlNew
;
2810 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2811 ImageList_Destroy(himlDef
);
2814 /***********************************************************************
2815 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2819 TOOLBAR_AddBitmap (TOOLBAR_INFO
*infoPtr
, INT count
, const TBADDBITMAP
*lpAddBmp
)
2825 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr
->hwndSelf
, count
, lpAddBmp
);
2829 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2831 info
.hInst
= COMCTL32_hModule
;
2832 switch (lpAddBmp
->nID
)
2834 case IDB_STD_SMALL_COLOR
:
2837 info
.nID
= IDB_STD_SMALL
;
2839 case IDB_STD_LARGE_COLOR
:
2842 info
.nID
= IDB_STD_LARGE
;
2844 case IDB_VIEW_SMALL_COLOR
:
2847 info
.nID
= IDB_VIEW_SMALL
;
2849 case IDB_VIEW_LARGE_COLOR
:
2852 info
.nID
= IDB_VIEW_LARGE
;
2854 case IDB_HIST_SMALL_COLOR
:
2856 info
.nID
= IDB_HIST_SMALL
;
2858 case IDB_HIST_LARGE_COLOR
:
2860 info
.nID
= IDB_HIST_LARGE
;
2863 WARN("unknown bitmap id, %Id\n", lpAddBmp
->nID
);
2867 TRACE ("adding %d internal bitmaps\n", info
.nButtons
);
2869 /* Windows resize all the buttons to the size of a newly added standard image */
2870 if (lpAddBmp
->nID
& 1)
2872 /* large icons: 24x24. Will make the button 31x30 */
2873 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2877 /* small icons: 16x16. Will make the buttons 23x22 */
2878 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2881 TOOLBAR_CalcToolbar (infoPtr
);
2885 info
.nButtons
= count
;
2886 info
.hInst
= lpAddBmp
->hInst
;
2887 info
.nID
= lpAddBmp
->nID
;
2888 TRACE("adding %d bitmaps\n", info
.nButtons
);
2891 /* check if the bitmap is already loaded and compute iSumButtons */
2893 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2895 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2896 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2898 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2901 if (!infoPtr
->cimlDef
) {
2902 /* create new default image list */
2903 TRACE ("creating default image list\n");
2905 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2906 ILC_COLOR32
| ILC_MASK
, info
.nButtons
, 2);
2907 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2908 infoPtr
->himlInt
= himlDef
;
2911 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2915 WARN("No default image list available\n");
2919 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2922 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2923 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2924 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2925 infoPtr
->nNumBitmapInfos
++;
2926 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2928 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2934 TOOLBAR_AddButtonsT(TOOLBAR_INFO
*infoPtr
, INT nAddButtons
, const TBBUTTON
* lpTbb
, BOOL fUnicode
)
2936 TRACE("adding %d buttons (unicode=%d)\n", nAddButtons
, fUnicode
);
2938 return TOOLBAR_InternalInsertButtonsT(infoPtr
, -1, nAddButtons
, lpTbb
, fUnicode
);
2943 TOOLBAR_AddStringW (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
2945 #define MAX_RESOURCE_STRING_LENGTH 512
2946 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2947 INT nIndex
= infoPtr
->nNumStrings
;
2949 TRACE("%p, %Ix\n", hInstance
, lParam
);
2951 if (IS_INTRESOURCE(lParam
)) {
2952 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2959 TRACE("adding string from resource\n");
2961 if (!hInstance
) return -1;
2963 hrsrc
= FindResourceW( hInstance
, MAKEINTRESOURCEW((LOWORD(lParam
) >> 4) + 1),
2964 (LPWSTR
)RT_STRING
);
2967 TRACE("string not found in resources\n");
2971 len
= LoadStringW (hInstance
, (UINT
)lParam
,
2972 szString
, MAX_RESOURCE_STRING_LENGTH
);
2974 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2975 if (len
== 0 || len
== 1)
2978 TRACE("delimiter: 0x%x\n", *szString
);
2979 delimiter
= *szString
;
2982 while ((next_delim
= wcschr(p
, delimiter
)) != NULL
) {
2984 if (next_delim
+ 1 >= szString
+ len
)
2986 /* this may happen if delimiter == '\0' or if the last char is a
2987 * delimiter (then it is ignored like the native does) */
2991 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2992 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2993 infoPtr
->nNumStrings
++;
2999 LPWSTR p
= (LPWSTR
)lParam
;
3004 TRACE("adding string(s) from array\n");
3008 TRACE("len=%d %s\n", len
, debugstr_w(p
));
3009 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3010 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3011 infoPtr
->nNumStrings
++;
3018 TOOLBAR_CalcToolbar(infoPtr
);
3024 TOOLBAR_AddStringA (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
3026 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
3031 TRACE("%p, %Ix\n", hInstance
, lParam
);
3033 if (IS_INTRESOURCE(lParam
)) /* load from resources */
3034 return TOOLBAR_AddStringW(infoPtr
, hInstance
, lParam
);
3040 TRACE("adding string(s) from array\n");
3041 nIndex
= infoPtr
->nNumStrings
;
3044 TRACE("len=%d \"%s\"\n", len
, p
);
3046 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3047 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3048 infoPtr
->nNumStrings
++;
3054 TOOLBAR_CalcToolbar(infoPtr
);
3060 TOOLBAR_AutoSize (TOOLBAR_INFO
*infoPtr
)
3062 TRACE("auto sizing, style=%#lx\n", infoPtr
->dwStyle
);
3063 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3065 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3067 RECT window_rect
, client_rect
, parent_rect
, border
;
3068 UINT uPosFlags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
3072 parent
= GetParent (infoPtr
->hwndSelf
);
3074 if (!parent
|| !infoPtr
->bDoRedraw
)
3077 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3078 GetClientRect(infoPtr
->hwndSelf
, &client_rect
);
3079 border
= window_rect
;
3080 MapWindowPoints(0, infoPtr
->hwndSelf
, (POINT
*)&border
, 2);
3081 border
.right
-= border
.left
+ client_rect
.right
- client_rect
.left
;
3082 border
.bottom
-= border
.top
+ client_rect
.bottom
- client_rect
.top
;
3084 GetClientRect(parent
, &parent_rect
);
3086 x
= parent_rect
.left
;
3087 y
= parent_rect
.top
;
3089 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3090 cx
= parent_rect
.right
- parent_rect
.left
;
3092 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3094 MapWindowPoints( 0, parent
, (POINT
*)&window_rect
, 2 );
3095 y
= window_rect
.top
;
3097 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3098 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3100 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3101 uPosFlags
|= SWP_NOMOVE
;
3103 if (!(infoPtr
->dwStyle
& CCS_NOMOVEY
) && !(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3104 y
+= GetSystemMetrics(SM_CYEDGE
);
3109 cy
+= border
.bottom
;
3111 SetWindowPos(infoPtr
->hwndSelf
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3114 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
))
3116 TOOLBAR_LayoutToolbar(infoPtr
);
3117 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
3124 static inline LRESULT
3125 TOOLBAR_ButtonCount (const TOOLBAR_INFO
*infoPtr
)
3127 return infoPtr
->nNumButtons
;
3131 static inline LRESULT
3132 TOOLBAR_ButtonStructSize (TOOLBAR_INFO
*infoPtr
, DWORD Size
)
3134 infoPtr
->dwStructSize
= Size
;
3141 TOOLBAR_ChangeBitmap (TOOLBAR_INFO
*infoPtr
, INT Id
, INT Index
)
3143 TBUTTON_INFO
*btnPtr
;
3146 TRACE("button %d, iBitmap now %d\n", Id
, Index
);
3148 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3152 btnPtr
= &infoPtr
->buttons
[nIndex
];
3153 btnPtr
->iBitmap
= Index
;
3155 /* we HAVE to erase the background, the new bitmap could be */
3157 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3164 TOOLBAR_CheckButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3166 TBUTTON_INFO
*btnPtr
;
3169 BOOL bChecked
= FALSE
;
3171 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3173 TRACE("hwnd %p, btn index %d, lParam %Ix\n", infoPtr
->hwndSelf
, nIndex
, lParam
);
3178 btnPtr
= &infoPtr
->buttons
[nIndex
];
3180 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) != 0;
3182 if (!LOWORD(lParam
))
3183 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3185 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3187 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3188 if (nOldIndex
== nIndex
)
3190 if (nOldIndex
!= -1)
3191 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3193 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3196 if( bChecked
!= LOWORD(lParam
) )
3198 if (nOldIndex
!= -1)
3199 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3200 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3203 /* FIXME: Send a WM_NOTIFY?? */
3210 TOOLBAR_CommandToIndex (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3212 return TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3217 TOOLBAR_Customize (TOOLBAR_INFO
*infoPtr
)
3219 CUSTDLG_INFO custInfo
;
3223 custInfo
.tbInfo
= infoPtr
;
3224 custInfo
.tbHwnd
= infoPtr
->hwndSelf
;
3226 /* send TBN_BEGINADJUST notification */
3227 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3229 ret
= DialogBoxParamW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3230 infoPtr
->hwndSelf
, TOOLBAR_CustomizeDialogProc
, (LPARAM
)&custInfo
);
3232 /* send TBN_ENDADJUST notification */
3233 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3240 TOOLBAR_DeleteButton (TOOLBAR_INFO
*infoPtr
, INT nIndex
)
3243 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3245 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3248 memset(&nmtb
, 0, sizeof(nmtb
));
3249 nmtb
.iItem
= btnPtr
->idCommand
;
3250 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3251 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3252 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3253 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3254 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3255 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3256 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3258 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3260 infoPtr
->nHotItem
= -1;
3261 if (infoPtr
->nNumButtons
== 1) {
3262 TRACE(" simple delete\n");
3263 free_string( infoPtr
->buttons
);
3264 Free (infoPtr
->buttons
);
3265 infoPtr
->buttons
= NULL
;
3266 infoPtr
->nNumButtons
= 0;
3269 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3270 TRACE("complex delete [nIndex=%d]\n", nIndex
);
3272 infoPtr
->nNumButtons
--;
3273 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3275 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3276 nIndex
* sizeof(TBUTTON_INFO
));
3279 if (nIndex
< infoPtr
->nNumButtons
) {
3280 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3281 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3284 free_string( oldButtons
+ nIndex
);
3288 TOOLBAR_LayoutToolbar(infoPtr
);
3290 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3297 TOOLBAR_EnableButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3299 TBUTTON_INFO
*btnPtr
;
3303 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3305 TRACE("hwnd %p, btn id %d, lParam %Ix\n", infoPtr
->hwndSelf
, Id
, lParam
);
3310 btnPtr
= &infoPtr
->buttons
[nIndex
];
3312 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3314 /* update the toolbar button state */
3315 if(!LOWORD(lParam
)) {
3316 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3318 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3321 /* redraw the button only if the state of the button changed */
3322 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3323 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3329 static inline LRESULT
3330 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO
*infoPtr
)
3332 return infoPtr
->bAnchor
;
3337 TOOLBAR_GetBitmap (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3341 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3345 return infoPtr
->buttons
[nIndex
].iBitmap
;
3349 static inline LRESULT
3350 TOOLBAR_GetBitmapFlags (void)
3352 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3357 TOOLBAR_GetButton (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, TBBUTTON
*lpTbb
)
3359 TBUTTON_INFO
*btnPtr
;
3364 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3367 btnPtr
= &infoPtr
->buttons
[nIndex
];
3368 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3369 lpTbb
->idCommand
= btnPtr
->idCommand
;
3370 lpTbb
->fsState
= btnPtr
->fsState
;
3371 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3372 lpTbb
->bReserved
[0] = 0;
3373 lpTbb
->bReserved
[1] = 0;
3374 lpTbb
->dwData
= btnPtr
->dwData
;
3375 lpTbb
->iString
= btnPtr
->iString
;
3382 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO
*infoPtr
, INT Id
, LPTBBUTTONINFOW lpTbInfo
, BOOL bUnicode
)
3384 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3385 TBUTTON_INFO
*btnPtr
;
3388 if (lpTbInfo
== NULL
)
3391 /* MSDN documents an iImageLabel field added in Vista but it is not present in
3392 * the headers and tests shows that even with comctl 6 Vista accepts only the
3393 * original TBBUTTONINFO size
3395 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3397 WARN("Invalid button size\n");
3401 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lpTbInfo
->dwMask
& TBIF_BYINDEX
);
3405 btnPtr
= &infoPtr
->buttons
[nIndex
];
3406 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3407 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3408 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3409 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3410 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3411 lpTbInfo
->lParam
= btnPtr
->dwData
;
3412 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3413 /* tests show that for separators TBIF_SIZE returns not calculated width,
3414 but cx property, that differs from 0 only if application have
3415 specifically set it */
3416 lpTbInfo
->cx
= (btnPtr
->fsStyle
& BTNS_SEP
)
3417 ? btnPtr
->cx
: (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3418 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3419 lpTbInfo
->fsState
= btnPtr
->fsState
;
3420 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3421 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3422 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3423 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3424 can't use TOOLBAR_GetText here */
3425 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3426 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3428 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3430 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3431 } else if (!bUnicode
|| lpTbInfo
->pszText
)
3432 lpTbInfo
->pszText
[0] = '\0';
3438 static inline LRESULT
3439 TOOLBAR_GetButtonSize (const TOOLBAR_INFO
*infoPtr
)
3441 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3442 (WORD
)infoPtr
->nButtonHeight
);
3447 TOOLBAR_GetButtonText (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPWSTR lpStr
, BOOL isW
)
3453 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3457 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3463 ret
= lstrlenW (lpText
);
3464 if (lpStr
) lstrcpyW (lpStr
, lpText
);
3468 ret
= WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3469 (LPSTR
)lpStr
, lpStr
? 0x7fffffff : 0, NULL
, NULL
) - 1;
3475 TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3477 TRACE("hwnd %p, wParam %Id\n", infoPtr
->hwndSelf
, wParam
);
3478 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3479 return (LRESULT
)GETDISIMAGELIST(infoPtr
, wParam
);
3483 static inline LRESULT
3484 TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO
*infoPtr
)
3488 return infoPtr
->dwExStyle
;
3493 TOOLBAR_GetHotImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3495 TRACE("hwnd %p, wParam %Id\n", infoPtr
->hwndSelf
, wParam
);
3496 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3497 return (LRESULT
)GETHOTIMAGELIST(infoPtr
, wParam
);
3502 TOOLBAR_GetHotItem (const TOOLBAR_INFO
*infoPtr
)
3504 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || infoPtr
->hTheme
))
3507 if (infoPtr
->nHotItem
< 0)
3510 return (LRESULT
)infoPtr
->nHotItem
;
3515 TOOLBAR_GetDefImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3517 TRACE("hwnd %p, wParam %Id\n", infoPtr
->hwndSelf
, wParam
);
3518 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3519 return (LRESULT
) GETDEFIMAGELIST(infoPtr
, wParam
);
3524 TOOLBAR_GetInsertMark (const TOOLBAR_INFO
*infoPtr
, TBINSERTMARK
*lptbim
)
3526 TRACE("hwnd = %p, lptbim = %p\n", infoPtr
->hwndSelf
, lptbim
);
3528 *lptbim
= infoPtr
->tbim
;
3534 static inline LRESULT
3535 TOOLBAR_GetInsertMarkColor (const TOOLBAR_INFO
*infoPtr
)
3537 TRACE("hwnd = %p\n", infoPtr
->hwndSelf
);
3539 return (LRESULT
)infoPtr
->clrInsertMark
;
3544 TOOLBAR_GetItemRect (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, LPRECT lpRect
)
3546 TBUTTON_INFO
*btnPtr
;
3548 btnPtr
= &infoPtr
->buttons
[nIndex
];
3549 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3554 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3557 lpRect
->left
= btnPtr
->rect
.left
;
3558 lpRect
->right
= btnPtr
->rect
.right
;
3559 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3560 lpRect
->top
= btnPtr
->rect
.top
;
3567 TOOLBAR_GetMaxSize (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
3572 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3573 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3575 TRACE("maximum size %ld x %ld\n", infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3576 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3582 /* << TOOLBAR_GetObject >> */
3585 static inline LRESULT
3586 TOOLBAR_GetPadding (const TOOLBAR_INFO
*infoPtr
)
3588 return MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3593 TOOLBAR_GetRect (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPRECT lpRect
)
3595 TBUTTON_INFO
*btnPtr
;
3598 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3599 btnPtr
= &infoPtr
->buttons
[nIndex
];
3600 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3606 lpRect
->left
= btnPtr
->rect
.left
;
3607 lpRect
->right
= btnPtr
->rect
.right
;
3608 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3609 lpRect
->top
= btnPtr
->rect
.top
;
3615 static inline LRESULT
3616 TOOLBAR_GetRows (const TOOLBAR_INFO
*infoPtr
)
3618 return infoPtr
->nRows
;
3623 TOOLBAR_GetState (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3627 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3631 return infoPtr
->buttons
[nIndex
].fsState
;
3635 static inline LRESULT
3636 TOOLBAR_GetStyle (const TOOLBAR_INFO
*infoPtr
)
3638 return infoPtr
->dwStyle
;
3642 static inline LRESULT
3643 TOOLBAR_GetTextRows (const TOOLBAR_INFO
*infoPtr
)
3645 return infoPtr
->nMaxTextRows
;
3650 TOOLBAR_GetToolTips (TOOLBAR_INFO
*infoPtr
)
3652 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3653 TOOLBAR_TooltipCreateControl(infoPtr
);
3654 return (LRESULT
)infoPtr
->hwndToolTip
;
3659 TOOLBAR_GetUnicodeFormat (const TOOLBAR_INFO
*infoPtr
)
3661 TRACE("%s hwnd=%p\n",
3662 infoPtr
->bUnicode
? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
3664 return infoPtr
->bUnicode
;
3668 static inline LRESULT
3669 TOOLBAR_GetVersion (const TOOLBAR_INFO
*infoPtr
)
3671 return infoPtr
->iVersion
;
3676 TOOLBAR_HideButton (TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fHide
)
3678 TBUTTON_INFO
*btnPtr
;
3684 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3688 btnPtr
= &infoPtr
->buttons
[nIndex
];
3689 oldState
= btnPtr
->fsState
;
3692 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3694 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3696 if (oldState
!= btnPtr
->fsState
) {
3697 TOOLBAR_LayoutToolbar (infoPtr
);
3698 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3705 static inline LRESULT
3706 TOOLBAR_HitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
* lpPt
)
3708 return TOOLBAR_InternalHitTest (infoPtr
, lpPt
, NULL
);
3713 TOOLBAR_Indeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fIndeterminate
)
3715 TBUTTON_INFO
*btnPtr
;
3719 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3723 btnPtr
= &infoPtr
->buttons
[nIndex
];
3724 oldState
= btnPtr
->fsState
;
3727 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3729 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3731 if(oldState
!= btnPtr
->fsState
)
3732 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3739 TOOLBAR_InsertButtonT(TOOLBAR_INFO
*infoPtr
, INT nIndex
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
3745 /* EPP: this seems to be an undocumented call (from my IE4)
3746 * I assume in that case that:
3747 * - index of insertion is at the end of existing buttons
3748 * I only see this happen with nIndex == -1, but it could have a special
3749 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3751 nIndex
= infoPtr
->nNumButtons
;
3753 } else if (nIndex
< 0)
3756 TRACE("inserting button index=%d\n", nIndex
);
3757 if (nIndex
> infoPtr
->nNumButtons
) {
3758 nIndex
= infoPtr
->nNumButtons
;
3759 TRACE("adjust index=%d\n", nIndex
);
3762 return TOOLBAR_InternalInsertButtonsT(infoPtr
, nIndex
, 1, lpTbb
, fUnicode
);
3765 /* << TOOLBAR_InsertMarkHitTest >> */
3769 TOOLBAR_IsButtonChecked (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3773 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3777 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3782 TOOLBAR_IsButtonEnabled (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3786 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3790 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3795 TOOLBAR_IsButtonHidden (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3799 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3803 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3808 TOOLBAR_IsButtonHighlighted (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3812 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3816 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3821 TOOLBAR_IsButtonIndeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3825 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3829 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3834 TOOLBAR_IsButtonPressed (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3838 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3842 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3847 TOOLBAR_LoadImages (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HINSTANCE hInstance
)
3850 tbab
.hInst
= hInstance
;
3853 TRACE("hwnd = %p, hInst = %p, nID = %Iu\n", infoPtr
->hwndSelf
, tbab
.hInst
, tbab
.nID
);
3855 return TOOLBAR_AddBitmap(infoPtr
, 0, &tbab
);
3860 TOOLBAR_MapAccelerator (const TOOLBAR_INFO
*infoPtr
, WCHAR wAccel
, UINT
*pIDButton
)
3862 WCHAR wszAccel
[] = {'&',wAccel
,0};
3865 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3866 infoPtr
->hwndSelf
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3868 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3870 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3871 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3872 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3874 int iLen
= lstrlenW(wszAccel
);
3875 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3882 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3887 if (!wcsnicmp(lpszStr
, wszAccel
, iLen
))
3889 *pIDButton
= btnPtr
->idCommand
;
3901 TOOLBAR_MarkButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fMark
)
3905 TBUTTON_INFO
*btnPtr
;
3907 TRACE("hwnd = %p, Id = %d, fMark = 0%d\n", infoPtr
->hwndSelf
, Id
, fMark
);
3909 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3913 btnPtr
= &infoPtr
->buttons
[nIndex
];
3914 oldState
= btnPtr
->fsState
;
3917 btnPtr
->fsState
|= TBSTATE_MARKED
;
3919 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
3921 if(oldState
!= btnPtr
->fsState
)
3922 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3928 /* fixes up an index of a button affected by a move */
3929 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
3933 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
3935 else if (*pIndex
== nIndex
)
3936 *pIndex
= nMoveIndex
;
3940 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
3942 else if (*pIndex
== nIndex
)
3943 *pIndex
= nMoveIndex
;
3949 TOOLBAR_MoveButton (TOOLBAR_INFO
*infoPtr
, INT Id
, INT nMoveIndex
)
3953 TBUTTON_INFO button
;
3955 TRACE("hwnd=%p, Id=%d, nMoveIndex=%d\n", infoPtr
->hwndSelf
, Id
, nMoveIndex
);
3957 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, TRUE
);
3958 if ((nIndex
== -1) || (nMoveIndex
< 0))
3961 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
3962 nMoveIndex
= infoPtr
->nNumButtons
- 1;
3964 button
= infoPtr
->buttons
[nIndex
];
3966 /* move button right */
3967 if (nIndex
< nMoveIndex
)
3969 nCount
= nMoveIndex
- nIndex
;
3970 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
3971 infoPtr
->buttons
[nMoveIndex
] = button
;
3973 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
3974 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
3975 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
3976 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
3978 else if (nIndex
> nMoveIndex
) /* move button left */
3980 nCount
= nIndex
- nMoveIndex
;
3981 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
3982 infoPtr
->buttons
[nMoveIndex
] = button
;
3984 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
3985 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
3986 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
3987 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
3990 TOOLBAR_LayoutToolbar(infoPtr
);
3991 TOOLBAR_AutoSize(infoPtr
);
3992 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
3999 TOOLBAR_PressButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fPress
)
4001 TBUTTON_INFO
*btnPtr
;
4005 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
4009 btnPtr
= &infoPtr
->buttons
[nIndex
];
4010 oldState
= btnPtr
->fsState
;
4013 btnPtr
->fsState
|= TBSTATE_PRESSED
;
4015 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
4017 if(oldState
!= btnPtr
->fsState
)
4018 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4023 /* FIXME: there might still be some confusion her between number of buttons
4024 * and number of bitmaps */
4026 TOOLBAR_ReplaceBitmap (TOOLBAR_INFO
*infoPtr
, const TBREPLACEBITMAP
*lpReplace
)
4029 int i
= 0, nOldButtons
= 0, pos
= 0;
4030 int nOldBitmaps
, nNewBitmaps
= 0;
4031 HIMAGELIST himlDef
= 0;
4033 TRACE("hInstOld %p nIDOld %Ix hInstNew %p nIDNew %Ix nButtons %x\n",
4034 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
4035 lpReplace
->nButtons
);
4037 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4039 FIXME("changing standard bitmaps not implemented\n");
4042 else if (lpReplace
->hInstOld
!= 0 && lpReplace
->hInstOld
!= lpReplace
->hInstNew
)
4043 FIXME("resources not in the current module not implemented\n");
4045 TRACE("To be replaced hInstOld %p nIDOld %Ix\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4046 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4047 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4048 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4049 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4051 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4052 nOldButtons
= tbi
->nButtons
;
4053 tbi
->nButtons
= lpReplace
->nButtons
;
4054 tbi
->hInst
= lpReplace
->hInstNew
;
4055 tbi
->nID
= lpReplace
->nIDNew
;
4056 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4059 pos
+= tbi
->nButtons
;
4062 if (nOldButtons
== 0)
4064 WARN("No hinst/bitmap found! hInst %p nID %Ix\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4068 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4071 if (lpReplace
->hInstNew
)
4072 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4074 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4076 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4077 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4079 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4081 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4082 ImageList_Remove(himlDef
, i
);
4086 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4087 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4088 DeleteObject(hBitmap
);
4091 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4093 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4094 pos
, nOldBitmaps
, nNewBitmaps
);
4096 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4101 /* helper for TOOLBAR_SaveRestoreW */
4103 TOOLBAR_Save(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*params
)
4107 BOOL alloced
= FALSE
;
4110 TRACE( "save to %s %s\n", debugstr_w(params
->pszSubKey
), debugstr_w(params
->pszValueName
) );
4112 memset( &save
, 0, sizeof(save
) );
4113 save
.cbData
= infoPtr
->nNumButtons
* sizeof(DWORD
);
4115 save
.cButtons
= infoPtr
->nNumButtons
;
4116 save
.tbButton
.idCommand
= -1;
4117 TOOLBAR_SendNotify( &save
.hdr
, infoPtr
, TBN_SAVE
);
4121 save
.pData
= Alloc( save
.cbData
);
4122 if (!save
.pData
) return FALSE
;
4125 if (!save
.pCurrent
) save
.pCurrent
= save
.pData
;
4127 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4130 save
.tbButton
.iBitmap
= infoPtr
->buttons
[i
].iBitmap
;
4131 save
.tbButton
.idCommand
= infoPtr
->buttons
[i
].idCommand
;
4132 save
.tbButton
.fsState
= infoPtr
->buttons
[i
].fsState
;
4133 save
.tbButton
.fsStyle
= infoPtr
->buttons
[i
].fsStyle
;
4134 memset( save
.tbButton
.bReserved
, 0, sizeof(save
.tbButton
.bReserved
) );
4135 save
.tbButton
.dwData
= infoPtr
->buttons
[i
].dwData
;
4136 save
.tbButton
.iString
= infoPtr
->buttons
[i
].iString
;
4138 *save
.pCurrent
++ = save
.tbButton
.idCommand
;
4140 TOOLBAR_SendNotify( &save
.hdr
, infoPtr
, TBN_SAVE
);
4143 ret
= RegCreateKeyW( params
->hkr
, params
->pszSubKey
, &key
);
4144 if (ret
== ERROR_SUCCESS
)
4146 ret
= RegSetValueExW( key
, params
->pszValueName
, 0, REG_BINARY
, (BYTE
*)save
.pData
, save
.cbData
);
4150 if (alloced
) Free( save
.pData
);
4155 /* helper for TOOLBAR_Restore */
4157 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4161 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4163 free_string( infoPtr
->buttons
+ i
);
4164 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4167 Free(infoPtr
->buttons
);
4168 infoPtr
->buttons
= NULL
;
4169 infoPtr
->nNumButtons
= 0;
4173 /* helper for TOOLBAR_SaveRestoreW */
4175 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4185 /* restore toolbar information */
4186 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4187 debugstr_w(lpSave
->pszValueName
));
4189 memset(&nmtbr
, 0, sizeof(nmtbr
));
4191 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4192 KEY_QUERY_VALUE
, &hkey
);
4194 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4196 if (!res
&& dwType
!= REG_BINARY
)
4197 res
= ERROR_FILE_NOT_FOUND
;
4200 nmtbr
.pData
= Alloc(dwSize
);
4201 nmtbr
.cbData
= dwSize
;
4202 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4205 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4206 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4209 nmtbr
.pCurrent
= nmtbr
.pData
;
4211 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4212 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4214 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4216 INT i
, count
= nmtbr
.cButtons
;
4218 /* remove all existing buttons as this function is designed to
4219 * restore the toolbar to a previously saved state */
4220 TOOLBAR_DeleteAllButtons(infoPtr
);
4222 for (i
= 0; i
< count
; i
++)
4225 nmtbr
.tbButton
.iBitmap
= -1;
4226 nmtbr
.tbButton
.fsState
= 0;
4227 nmtbr
.tbButton
.fsStyle
= 0;
4228 nmtbr
.tbButton
.dwData
= 0;
4229 nmtbr
.tbButton
.iString
= 0;
4231 if (*nmtbr
.pCurrent
& 0x80000000)
4234 nmtbr
.tbButton
.iBitmap
= SEPARATOR_WIDTH
;
4235 nmtbr
.tbButton
.idCommand
= 0;
4236 nmtbr
.tbButton
.fsStyle
= BTNS_SEP
;
4237 if (*nmtbr
.pCurrent
!= (DWORD
)-1)
4238 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4241 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4245 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4247 /* All returned ptrs and -1 are ignored */
4248 if (!IS_INTRESOURCE(nmtbr
.tbButton
.iString
))
4249 nmtbr
.tbButton
.iString
= 0;
4251 TOOLBAR_InsertButtonT(infoPtr
, -1, &nmtbr
.tbButton
, TRUE
);
4254 TOOLBAR_SendNotify( &hdr
, infoPtr
, TBN_BEGINADJUST
);
4260 UINT code
= infoPtr
->bUnicode
? TBN_GETBUTTONINFOW
: TBN_GETBUTTONINFOA
;
4263 memset( &tb
, 0, sizeof(tb
) );
4265 tb
.cchText
= ARRAY_SIZE(buf
);
4268 /* Use the same struct for both A and W versions since the layout is the same. */
4269 if (!TOOLBAR_SendNotify( &tb
.hdr
, infoPtr
, code
))
4272 idx
= TOOLBAR_GetButtonIndex( infoPtr
, tb
.tbButton
.idCommand
, FALSE
);
4273 if (idx
== -1) continue;
4275 /* tb.pszText is ignored - the string comes from tb.tbButton.iString, which may
4276 be an index or a ptr. Either way it is simply copied. There is no api to change
4277 the string index, so we set it manually. The other properties can be set with SetButtonInfo. */
4278 free_string( infoPtr
->buttons
+ idx
);
4279 infoPtr
->buttons
[idx
].iString
= tb
.tbButton
.iString
;
4281 memset( &bi
, 0, sizeof(bi
) );
4282 bi
.cbSize
= sizeof(bi
);
4283 bi
.dwMask
= TBIF_IMAGE
| TBIF_STATE
| TBIF_STYLE
| TBIF_LPARAM
;
4284 bi
.iImage
= tb
.tbButton
.iBitmap
;
4285 bi
.fsState
= tb
.tbButton
.fsState
;
4286 bi
.fsStyle
= tb
.tbButton
.fsStyle
;
4287 bi
.lParam
= tb
.tbButton
.dwData
;
4289 TOOLBAR_SetButtonInfo( infoPtr
, tb
.tbButton
.idCommand
, &bi
, TRUE
);
4291 TOOLBAR_SendNotify( &hdr
, infoPtr
, TBN_ENDADJUST
);
4293 /* remove all uninitialised buttons
4294 * note: loop backwards to avoid having to fixup i on a
4296 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4297 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4298 TOOLBAR_DeleteButton(infoPtr
, i
);
4300 /* only indicate success if at least one button survived */
4301 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4312 TOOLBAR_SaveRestoreW (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4314 if (lpSave
== NULL
) return 0;
4317 return TOOLBAR_Save(infoPtr
, lpSave
);
4319 return TOOLBAR_Restore(infoPtr
, lpSave
);
4324 TOOLBAR_SaveRestoreA (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4326 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4327 TBSAVEPARAMSW SaveW
;
4331 if (lpSave
== NULL
) return 0;
4333 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4334 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4335 if (!pszSubKey
) goto exit
;
4336 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4338 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4339 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4340 if (!pszValueName
) goto exit
;
4341 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4343 SaveW
.pszValueName
= pszValueName
;
4344 SaveW
.pszSubKey
= pszSubKey
;
4345 SaveW
.hkr
= lpSave
->hkr
;
4346 result
= TOOLBAR_SaveRestoreW(infoPtr
, wParam
, &SaveW
);
4349 Free (pszValueName
);
4357 TOOLBAR_SetAnchorHighlight (TOOLBAR_INFO
*infoPtr
, BOOL bAnchor
)
4359 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4361 TRACE("hwnd=%p, bAnchor = %s\n", infoPtr
->hwndSelf
, bAnchor
? "TRUE" : "FALSE");
4363 infoPtr
->bAnchor
= bAnchor
;
4365 /* Native does not remove the hot effect from an already hot button */
4367 return (LRESULT
)bOldAnchor
;
4372 TOOLBAR_SetBitmapSize (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4374 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4375 short width
= (short)LOWORD(lParam
);
4376 short height
= (short)HIWORD(lParam
);
4378 TRACE("hwnd %p, wParam %Id, size %d x %d\n", infoPtr
->hwndSelf
, wParam
, width
, height
);
4381 FIXME("wParam is %Id. Perhaps image list index?\n", wParam
);
4383 /* 0 width or height is changed to 1 */
4389 if (infoPtr
->nNumButtons
> 0)
4390 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4391 infoPtr
->nNumButtons
,
4392 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
, width
, height
);
4394 if (width
< -1 || height
< -1)
4396 /* Windows destroys the imagelist and seems to actually use negative
4397 * values to compute button sizes */
4398 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width
, height
);
4402 /* width or height of -1 means no change */
4404 infoPtr
->nBitmapWidth
= width
;
4406 infoPtr
->nBitmapHeight
= height
;
4408 if ((himlDef
== infoPtr
->himlInt
) &&
4409 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4411 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4412 infoPtr
->nBitmapHeight
);
4415 TOOLBAR_CalcToolbar(infoPtr
);
4416 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4422 TOOLBAR_SetButtonInfo (TOOLBAR_INFO
*infoPtr
, INT Id
,
4423 const TBBUTTONINFOW
*lptbbi
, BOOL isW
)
4425 TBUTTON_INFO
*btnPtr
;
4431 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4434 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lptbbi
->dwMask
& TBIF_BYINDEX
);
4438 btnPtr
= &infoPtr
->buttons
[nIndex
];
4439 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4440 btnPtr
->idCommand
= lptbbi
->idCommand
;
4441 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4442 btnPtr
->iBitmap
= lptbbi
->iImage
;
4443 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4444 btnPtr
->dwData
= lptbbi
->lParam
;
4445 if (lptbbi
->dwMask
& TBIF_SIZE
)
4446 btnPtr
->cx
= lptbbi
->cx
;
4447 if (lptbbi
->dwMask
& TBIF_STATE
)
4448 btnPtr
->fsState
= lptbbi
->fsState
;
4449 if (lptbbi
->dwMask
& TBIF_STYLE
)
4450 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4452 if (lptbbi
->dwMask
& TBIF_TEXT
)
4453 set_stringT( btnPtr
, lptbbi
->pszText
, isW
);
4455 /* save the button rect to see if we need to redraw the whole toolbar */
4456 oldBtnRect
= btnPtr
->rect
;
4457 TOOLBAR_LayoutToolbar(infoPtr
);
4459 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4460 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4462 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4469 TOOLBAR_SetButtonSize (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4471 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4472 int top
= default_top_margin(infoPtr
);
4474 if ((cx
< 0) || (cy
< 0))
4476 ERR("invalid parameter %#Ix\n", lParam
);
4480 TRACE("%p, cx = %d, cy = %d\n", infoPtr
->hwndSelf
, cx
, cy
);
4482 /* The documentation claims you can only change the button size before
4483 * any button has been added. But this is wrong.
4484 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4485 * it to the toolbar, and it checks that the return value is nonzero - mjm
4486 * Further testing shows that we must actually perform the change too.
4489 * The documentation also does not mention that if 0 is supplied for
4490 * either size, the system changes it to the default of 24 wide and
4491 * 22 high. Demonstrated in ControlSpy Toolbar. GLA 3/02
4493 if (cx
== 0) cx
= 24;
4494 if (cy
== 0) cy
= 22;
4496 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4497 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4499 if (cx
!= infoPtr
->nButtonWidth
|| cy
!= infoPtr
->nButtonHeight
||
4500 top
!= infoPtr
->iTopMargin
)
4502 infoPtr
->nButtonWidth
= cx
;
4503 infoPtr
->nButtonHeight
= cy
;
4504 infoPtr
->iTopMargin
= top
;
4506 TOOLBAR_LayoutToolbar( infoPtr
);
4507 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
4514 TOOLBAR_SetButtonWidth (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4516 /* if setting to current values, ignore */
4517 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4518 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4519 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4520 infoPtr
->cxMin
, infoPtr
->cxMax
);
4524 /* save new values */
4525 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4526 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4528 /* otherwise we need to recalc the toolbar and in some cases
4529 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4530 which doesn't actually draw - GA). */
4531 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4532 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4534 TOOLBAR_CalcToolbar (infoPtr
);
4536 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
4543 TOOLBAR_SetCmdId (TOOLBAR_INFO
*infoPtr
, INT nIndex
, INT nId
)
4545 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4548 infoPtr
->buttons
[nIndex
].idCommand
= nId
;
4550 if (infoPtr
->hwndToolTip
) {
4552 FIXME("change tool tip\n");
4561 TOOLBAR_SetDisabledImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4563 HIMAGELIST himlTemp
;
4566 if (infoPtr
->iVersion
>= 5)
4569 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4570 &infoPtr
->cimlDis
, himl
, id
);
4572 /* FIXME: redraw ? */
4574 return (LRESULT
)himlTemp
;
4579 TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD flags
)
4583 TRACE("hwnd = %p, mask = %#lx, flags %#lx\n", infoPtr
->hwndSelf
, mask
, flags
);
4585 old_flags
= infoPtr
->dwDTFlags
;
4586 infoPtr
->dwDTFlags
= (old_flags
& ~mask
) | (flags
& mask
);
4588 return (LRESULT
)old_flags
;
4591 /* This function differs a bit from what MSDN says it does:
4592 * 1. lParam contains extended style flags to OR with current style
4593 * (MSDN isn't clear on the OR bit)
4594 * 2. wParam appears to contain extended style flags to be reset
4595 * (MSDN says that this parameter is reserved)
4598 TOOLBAR_SetExtendedStyle (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD style
)
4600 DWORD old_style
= infoPtr
->dwExStyle
;
4602 TRACE("mask %#lx, style %#lx\n", mask
, style
);
4605 infoPtr
->dwExStyle
= (old_style
& ~mask
) | (style
& mask
);
4607 infoPtr
->dwExStyle
= style
;
4609 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4610 FIXME("Unknown Toolbar Extended Style %#lx. Please report.\n", (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4612 if ((old_style
^ infoPtr
->dwExStyle
) & TBSTYLE_EX_MIXEDBUTTONS
)
4613 TOOLBAR_CalcToolbar(infoPtr
);
4615 TOOLBAR_LayoutToolbar(infoPtr
);
4617 TOOLBAR_AutoSize(infoPtr
);
4618 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4625 TOOLBAR_SetHotImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4627 HIMAGELIST himlTemp
;
4630 if (infoPtr
->iVersion
>= 5)
4633 TRACE("hwnd = %p, himl = %p, id = %d\n", infoPtr
->hwndSelf
, himl
, id
);
4635 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4636 &infoPtr
->cimlHot
, himl
, id
);
4638 /* FIXME: redraw ? */
4640 return (LRESULT
)himlTemp
;
4644 /* Makes previous hot button no longer hot, makes the specified
4645 * button hot and sends appropriate notifications. dwReason is one or
4646 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4647 * NOTE 1: this function does not validate nHit
4648 * NOTE 2: the name of this function is completely made up and
4649 * not based on any documentation from Microsoft. */
4651 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4653 if (infoPtr
->nHotItem
!= nHit
)
4655 NMTBHOTITEM nmhotitem
;
4656 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4658 nmhotitem
.dwFlags
= dwReason
;
4659 if(infoPtr
->nHotItem
>= 0)
4661 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4662 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4666 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4667 nmhotitem
.idOld
= 0;
4672 btnPtr
= &infoPtr
->buttons
[nHit
];
4673 nmhotitem
.idNew
= btnPtr
->idCommand
;
4677 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4678 nmhotitem
.idNew
= 0;
4681 /* now change the hot and invalidate the old and new buttons - if the
4683 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4686 oldBtnPtr
->bHot
= FALSE
;
4687 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4689 /* setting disabled buttons as hot fails even if the notify contains the button id */
4690 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4691 btnPtr
->bHot
= TRUE
;
4692 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4693 infoPtr
->nHotItem
= nHit
;
4696 infoPtr
->nHotItem
= -1;
4702 TOOLBAR_SetHotItem (TOOLBAR_INFO
*infoPtr
, INT nHotItem
)
4704 INT nOldHotItem
= infoPtr
->nHotItem
;
4706 TRACE("hwnd = %p, nHotItem = %d\n", infoPtr
->hwndSelf
, nHotItem
);
4708 if (nHotItem
>= infoPtr
->nNumButtons
)
4709 return infoPtr
->nHotItem
;
4714 /* NOTE: an application can still remove the hot item even if anchor
4715 * highlighting is enabled */
4717 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, HICF_OTHER
);
4719 if (nOldHotItem
< 0)
4722 return (LRESULT
)nOldHotItem
;
4727 TOOLBAR_SetImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4729 HIMAGELIST himlTemp
;
4730 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4731 INT oldBitmapWidth
= infoPtr
->nBitmapWidth
;
4732 INT oldBitmapHeight
= infoPtr
->nBitmapHeight
;
4735 if (infoPtr
->iVersion
>= 5)
4738 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4739 &infoPtr
->cimlDef
, himl
, id
);
4741 infoPtr
->nNumBitmaps
= 0;
4742 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4743 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4745 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4746 &infoPtr
->nBitmapHeight
))
4748 infoPtr
->nBitmapWidth
= 1;
4749 infoPtr
->nBitmapHeight
= 1;
4751 if ((oldBitmapWidth
!= infoPtr
->nBitmapWidth
) || (oldBitmapHeight
!= infoPtr
->nBitmapHeight
))
4753 TOOLBAR_CalcToolbar(infoPtr
);
4754 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4755 TOOLBAR_SetButtonSize(infoPtr
, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4758 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4759 infoPtr
->hwndSelf
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4760 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4762 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4764 return (LRESULT
)himlTemp
;
4769 TOOLBAR_SetIndent (TOOLBAR_INFO
*infoPtr
, INT nIndent
)
4771 infoPtr
->nIndent
= nIndent
;
4775 /* process only on indent changing */
4776 if(infoPtr
->nIndent
!= nIndent
)
4778 infoPtr
->nIndent
= nIndent
;
4779 TOOLBAR_CalcToolbar (infoPtr
);
4780 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4788 TOOLBAR_SetInsertMark (TOOLBAR_INFO
*infoPtr
, const TBINSERTMARK
*lptbim
)
4790 TRACE("hwnd = %p, lptbim = { %d, %#lx}\n", infoPtr
->hwndSelf
, lptbim
->iButton
, lptbim
->dwFlags
);
4792 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4794 FIXME("Unrecognized flag(s): %#lx\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4798 if ((lptbim
->iButton
== -1) ||
4799 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4800 (lptbim
->iButton
>= 0)))
4802 infoPtr
->tbim
= *lptbim
;
4803 /* FIXME: don't need to update entire toolbar */
4804 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4807 ERR("Invalid button index %d\n", lptbim
->iButton
);
4814 TOOLBAR_SetInsertMarkColor (TOOLBAR_INFO
*infoPtr
, COLORREF clr
)
4816 infoPtr
->clrInsertMark
= clr
;
4818 /* FIXME: don't need to update entire toolbar */
4819 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4826 TOOLBAR_SetMaxTextRows (TOOLBAR_INFO
*infoPtr
, INT nMaxRows
)
4828 infoPtr
->nMaxTextRows
= nMaxRows
;
4830 TOOLBAR_CalcToolbar(infoPtr
);
4835 /* MSDN gives slightly wrong info on padding.
4836 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4837 * 2. It is not used to create a blank area between the edge of the button
4838 * and the text or image if TBSTYLE_LIST is set. It is used to control
4839 * the gap between the image and text.
4840 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4841 * to control the bottom and right borders [with the border being
4842 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4843 * is shared evenly on both sides of the button.
4844 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4847 TOOLBAR_SetPadding (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4851 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4852 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4853 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4854 TRACE("cx %ld, cy %ld\n", infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4855 return (LRESULT
) oldPad
;
4860 TOOLBAR_SetParent (TOOLBAR_INFO
*infoPtr
, HWND hParent
)
4866 hwndOldNotify
= infoPtr
->hwndNotify
;
4867 infoPtr
->hwndNotify
= hParent
;
4869 return (LRESULT
)hwndOldNotify
;
4874 TOOLBAR_SetRows (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPRECT lprc
)
4876 int rows
= LOWORD(wParam
);
4877 BOOL bLarger
= HIWORD(wParam
);
4881 TRACE("Setting rows to %d (%d)\n", rows
, bLarger
);
4883 if(infoPtr
->nRows
!= rows
)
4885 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
;
4886 int curColumn
= 0; /* Current column */
4887 int curRow
= 0; /* Current row */
4888 int hidden
= 0; /* Number of hidden buttons */
4889 int seps
= 0; /* Number of separators */
4890 int idealWrap
= 0; /* Ideal wrap point */
4895 Calculate new size and wrap points - Under windows, setrows will
4896 change the dimensions if needed to show the number of requested
4897 rows (if CCS_NORESIZE is set), or will take up the whole window
4898 (if no CCS_NORESIZE).
4900 Basic algorithm - If N buttons, and y rows requested, each row
4901 contains N/y buttons.
4903 FIXME: Handling of separators not obvious from testing results
4904 FIXME: Take width of window into account?
4907 /* Loop through the buttons one by one counting key items */
4908 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4910 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
4911 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4913 else if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
4917 /* FIXME: Separators make this quite complex */
4918 if (seps
) FIXME("Separators unhandled\n");
4920 /* Round up so more per line, i.e., less rows */
4921 idealWrap
= (infoPtr
->nNumButtons
- hidden
+ (rows
-1)) / (rows
? rows
: 1);
4923 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4924 achieve the requested number of rows. */
4925 if (bLarger
&& idealWrap
> 1)
4927 int resRows
= (infoPtr
->nNumButtons
+ (idealWrap
-1)) / idealWrap
;
4928 int moreRows
= (infoPtr
->nNumButtons
+ (idealWrap
-2)) / (idealWrap
-1);
4930 if (resRows
< rows
&& moreRows
> rows
)
4933 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap
);
4937 curColumn
= curRow
= 0;
4939 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap
,
4940 infoPtr
->nNumButtons
, hidden
, rows
);
4942 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4944 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4947 /* Step on, wrap if necessary or flag next to wrap */
4956 if (curColumn
> (idealWrap
-1)) {
4958 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
4962 TRACE("Result - %d rows\n", curRow
+ 1);
4964 /* recalculate toolbar */
4965 TOOLBAR_CalcToolbar (infoPtr
);
4967 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
4968 if NORESIZE is NOT set, then the toolbar will always be resized to
4969 take up the whole window. With it set, sizing needs to be manual. */
4970 if (infoPtr
->dwStyle
& CCS_NORESIZE
) {
4971 SetWindowPos(infoPtr
->hwndSelf
, NULL
, 0, 0,
4972 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
4973 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
,
4974 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
4977 /* repaint toolbar */
4978 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4981 /* return bounding rectangle */
4983 lprc
->left
= infoPtr
->rcBound
.left
;
4984 lprc
->right
= infoPtr
->rcBound
.right
;
4985 lprc
->top
= infoPtr
->rcBound
.top
;
4986 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
4994 TOOLBAR_SetState (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
4996 TBUTTON_INFO
*btnPtr
;
4999 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
5003 btnPtr
= &infoPtr
->buttons
[nIndex
];
5005 /* if hidden state has changed the invalidate entire window and recalc */
5006 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
5007 btnPtr
->fsState
= LOWORD(lParam
);
5008 TOOLBAR_CalcToolbar (infoPtr
);
5009 InvalidateRect(infoPtr
->hwndSelf
, 0, TRUE
);
5013 /* process state changing if current state doesn't match new state */
5014 if(btnPtr
->fsState
!= LOWORD(lParam
))
5016 btnPtr
->fsState
= LOWORD(lParam
);
5017 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5023 static inline void unwrap(TOOLBAR_INFO
*info
)
5027 for (i
= 0; i
< info
->nNumButtons
; i
++)
5028 info
->buttons
[i
].fsState
&= ~TBSTATE_WRAP
;
5032 TOOLBAR_SetStyle (TOOLBAR_INFO
*infoPtr
, DWORD style
)
5034 DWORD dwOldStyle
= infoPtr
->dwStyle
;
5036 TRACE("new style %#lx\n", style
);
5038 if (style
& TBSTYLE_LIST
)
5039 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
5041 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
5043 infoPtr
->dwStyle
= style
;
5044 TOOLBAR_CheckStyle(infoPtr
);
5046 if ((dwOldStyle
^ style
) & TBSTYLE_WRAPABLE
)
5048 if (dwOldStyle
& TBSTYLE_WRAPABLE
)
5050 TOOLBAR_CalcToolbar(infoPtr
);
5052 else if ((dwOldStyle
^ style
) & CCS_VERT
)
5053 TOOLBAR_LayoutToolbar(infoPtr
);
5055 /* only resize if one of the CCS_* styles was changed */
5056 if ((dwOldStyle
^ style
) & COMMON_STYLES
)
5058 TOOLBAR_AutoSize(infoPtr
);
5059 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5066 static inline LRESULT
5067 TOOLBAR_SetToolTips (TOOLBAR_INFO
*infoPtr
, HWND hwndTooltip
)
5069 TRACE("hwnd=%p, hwndTooltip=%p\n", infoPtr
->hwndSelf
, hwndTooltip
);
5071 infoPtr
->hwndToolTip
= hwndTooltip
;
5077 TOOLBAR_SetUnicodeFormat (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
5081 TRACE("%s hwnd=%p\n",
5082 ((BOOL
)wParam
) ? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
5084 bTemp
= infoPtr
->bUnicode
;
5085 infoPtr
->bUnicode
= (BOOL
)wParam
;
5092 TOOLBAR_GetColorScheme (const TOOLBAR_INFO
*infoPtr
, LPCOLORSCHEME lParam
)
5094 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
5095 comctl32_color
.clrBtnHighlight
:
5096 infoPtr
->clrBtnHighlight
;
5097 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
5098 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
5104 TOOLBAR_SetColorScheme (TOOLBAR_INFO
*infoPtr
, const COLORSCHEME
*lParam
)
5106 TRACE("new colors Hl=%#lx Shd=%#lx, old colors Hl=%#lx Shd=%#lx\n",
5107 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
5108 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
5110 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
5111 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
5112 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5118 TOOLBAR_SetVersion (TOOLBAR_INFO
*infoPtr
, INT iVersion
)
5120 INT iOldVersion
= infoPtr
->iVersion
;
5122 infoPtr
->iVersion
= iVersion
;
5124 if (infoPtr
->iVersion
>= 5)
5125 TOOLBAR_SetUnicodeFormat(infoPtr
, TRUE
);
5132 TOOLBAR_GetStringA (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPSTR str
)
5134 WORD iString
= HIWORD(wParam
);
5135 WORD buffersize
= LOWORD(wParam
);
5138 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, buffersize
, str
);
5140 if (iString
< infoPtr
->nNumStrings
)
5142 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
5145 TRACE("returning %s\n", debugstr_a(str
));
5148 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5155 TOOLBAR_GetStringW (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPWSTR str
)
5157 WORD iString
= HIWORD(wParam
);
5158 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5161 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, LOWORD(wParam
), str
);
5163 if (iString
< infoPtr
->nNumStrings
)
5165 len
= min(len
, lstrlenW(infoPtr
->strings
[iString
]));
5166 ret
= (len
+1)*sizeof(WCHAR
);
5169 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5174 TRACE("returning %s\n", debugstr_w(str
));
5177 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5182 static LRESULT
TOOLBAR_SetBoundingSize(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5184 SIZE
* pSize
= (SIZE
*)lParam
;
5185 FIXME("hwnd=%p, wParam=%Ix, size.cx=%ld, size.cy=%ld stub\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5189 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5190 * caller to specify a reason why the hot item changed (rather than just the
5191 * HICF_OTHER that TB_SETHOTITEM sends). */
5193 TOOLBAR_SetHotItem2 (TOOLBAR_INFO
*infoPtr
, INT nHotItem
, LPARAM lParam
)
5195 INT nOldHotItem
= infoPtr
->nHotItem
;
5197 TRACE("old item %d, new item %d, flags %Ix\n", nOldHotItem
, nHotItem
, lParam
);
5199 if (nHotItem
< 0 || nHotItem
> infoPtr
->nNumButtons
)
5202 /* NOTE: an application can still remove the hot item even if anchor
5203 * highlighting is enabled */
5205 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, lParam
);
5207 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5210 /* Sets the toolbar global iListGap parameter which controls the amount of
5211 * spacing between the image and the text of buttons for TBSTYLE_LIST
5213 static LRESULT
TOOLBAR_SetListGap(TOOLBAR_INFO
*infoPtr
, INT iListGap
)
5215 TRACE("hwnd=%p iListGap=%d\n", infoPtr
->hwndSelf
, iListGap
);
5217 infoPtr
->iListGap
= iListGap
;
5219 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5224 /* Returns the number of maximum number of image lists associated with the
5225 * various states. */
5226 static LRESULT
TOOLBAR_GetImageListCount(const TOOLBAR_INFO
*infoPtr
)
5228 TRACE("hwnd=%p\n", infoPtr
->hwndSelf
);
5230 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5234 TOOLBAR_GetIdealSize (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5236 LPSIZE lpsize
= (LPSIZE
)lParam
;
5242 * Testing shows the following:
5243 * wParam = 0 adjust cx value
5244 * = 1 set cy value to max size.
5245 * lParam pointer to SIZE structure
5248 TRACE("wParam %Id, lParam %Ix -> %lx, %lx\n", wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5252 if (lpsize
->cx
== -1) {
5253 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5255 else if(HIWORD(lpsize
->cx
)) {
5257 HWND hwndParent
= GetParent(infoPtr
->hwndSelf
);
5259 GetWindowRect(infoPtr
->hwndSelf
, &rc
);
5260 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5261 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc
));
5262 lpsize
->cx
= max(rc
.right
-rc
.left
,
5263 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5266 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5270 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5273 FIXME("Unknown wParam %Id\n", wParam
);
5276 TRACE("set to -> %lu, %lu\n", lpsize
->cx
, lpsize
->cy
);
5280 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5282 FIXME("hwnd %p, wParam %Ix, lParam %Ix\n", hwnd
, wParam
, lParam
);
5284 InvalidateRect(hwnd
, NULL
, TRUE
);
5290 TOOLBAR_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
5292 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
5295 TRACE("hwnd = %p, style = %#lx\n", hwnd
, lpcs
->style
);
5297 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5298 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5299 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5300 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_REQUERY
));
5301 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5303 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5304 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5305 infoPtr
->hTheme
= OpenThemeDataForDpi (NULL
, themeClass
, GetDpiForWindow (hwnd
));
5307 TOOLBAR_CheckStyle (infoPtr
);
5314 TOOLBAR_Destroy (TOOLBAR_INFO
*infoPtr
)
5318 /* delete tooltip control */
5319 if (infoPtr
->hwndToolTip
)
5320 DestroyWindow (infoPtr
->hwndToolTip
);
5322 /* delete temporary buffer for tooltip text */
5323 Free (infoPtr
->pszTooltipText
);
5324 Free (infoPtr
->bitmaps
); /* bitmaps list */
5326 /* delete button data */
5327 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5328 free_string( infoPtr
->buttons
+ i
);
5329 Free (infoPtr
->buttons
);
5331 /* delete strings */
5332 if (infoPtr
->strings
) {
5333 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5334 Free (infoPtr
->strings
[i
]);
5336 Free (infoPtr
->strings
);
5339 /* destroy internal image list */
5340 if (infoPtr
->himlInt
)
5341 ImageList_Destroy (infoPtr
->himlInt
);
5343 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5344 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5345 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5347 /* delete default font */
5348 DeleteObject (infoPtr
->hDefaultFont
);
5350 CloseThemeData (infoPtr
->hTheme
);
5352 /* free toolbar info data */
5353 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
5361 TOOLBAR_EraseBackground (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5363 NMTBCUSTOMDRAW tbcd
;
5366 DWORD dwEraseCustDraw
= 0;
5368 /* the app has told us not to redraw the toolbar */
5369 if (!infoPtr
->bDoRedraw
)
5372 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5373 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5374 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5375 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5376 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5377 dwEraseCustDraw
= ntfret
& 0xffff;
5379 /* FIXME: in general the return flags *can* be or'ed together */
5380 switch (dwEraseCustDraw
)
5382 case CDRF_DODEFAULT
:
5384 case CDRF_SKIPDEFAULT
:
5387 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5388 infoPtr
->hwndSelf
, ntfret
);
5392 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5393 * to my parent for processing.
5395 if (infoPtr
->hTheme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5397 HDC hdc
= (HDC
)wParam
;
5402 parent
= GetParent(infoPtr
->hwndSelf
);
5403 MapWindowPoints(infoPtr
->hwndSelf
, parent
, &pt
, 1);
5404 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5405 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5406 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5409 ret
= DefWindowProcW (infoPtr
->hwndSelf
, WM_ERASEBKGND
, wParam
, lParam
);
5411 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5412 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5413 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5414 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5415 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5416 dwEraseCustDraw
= ntfret
& 0xffff;
5417 switch (dwEraseCustDraw
)
5419 case CDRF_DODEFAULT
:
5421 case CDRF_SKIPDEFAULT
:
5424 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5425 infoPtr
->hwndSelf
, ntfret
);
5432 static inline LRESULT
5433 TOOLBAR_GetFont (const TOOLBAR_INFO
*infoPtr
)
5435 return (LRESULT
)infoPtr
->hFont
;
5440 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5443 INT nNewHotItem
= infoPtr
->nHotItem
;
5445 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5448 if ((nNewHotItem
+ iDirection
< 0) ||
5449 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5451 NMTBWRAPHOTITEM nmtbwhi
;
5452 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5453 nmtbwhi
.iDirection
= iDirection
;
5454 nmtbwhi
.dwReason
= dwReason
;
5456 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5460 nNewHotItem
+= iDirection
;
5461 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5463 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5464 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5466 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5473 TOOLBAR_KeyDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5477 nmkey
.nVKey
= (UINT
)wParam
;
5478 nmkey
.uFlags
= HIWORD(lParam
);
5480 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5481 return DefWindowProcW(infoPtr
->hwndSelf
, WM_KEYDOWN
, wParam
, lParam
);
5483 switch ((UINT
)wParam
)
5487 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5491 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5495 if ((infoPtr
->nHotItem
>= 0) &&
5496 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5498 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5499 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5500 (LPARAM
)infoPtr
->hwndSelf
);
5510 TOOLBAR_LButtonDblClk (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5515 pt
.x
= (short)LOWORD(lParam
);
5516 pt
.y
= (short)HIWORD(lParam
);
5517 TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5520 TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
5521 else if (infoPtr
->dwStyle
& CCS_ADJUSTABLE
)
5522 TOOLBAR_Customize (infoPtr
);
5529 TOOLBAR_LButtonDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5531 TBUTTON_INFO
*btnPtr
;
5536 BOOL bDragKeyPressed
;
5541 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5542 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5544 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5546 if (infoPtr
->hwndToolTip
)
5547 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5548 WM_LBUTTONDOWN
, wParam
, lParam
);
5550 pt
.x
= (short)LOWORD(lParam
);
5551 pt
.y
= (short)HIWORD(lParam
);
5552 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5556 btnPtr
= &infoPtr
->buttons
[nHit
];
5558 if (bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5560 infoPtr
->nButtonDrag
= nHit
;
5561 SetCapture (infoPtr
->hwndSelf
);
5563 /* If drag cursor has not been loaded, load it.
5564 * Note: it doesn't need to be freed */
5566 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5567 SetCursor(hCursorDrag
);
5572 infoPtr
->nOldHit
= nHit
;
5574 arrowRect
= btnPtr
->rect
;
5575 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5577 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5578 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5579 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5580 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5581 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5582 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5586 /* draw in pressed state */
5587 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5588 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5590 btnPtr
->bDropDownPressed
= TRUE
;
5591 RedrawWindow(infoPtr
->hwndSelf
, &btnPtr
->rect
, 0, RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5593 memset(&nmtb
, 0, sizeof(nmtb
));
5594 nmtb
.iItem
= btnPtr
->idCommand
;
5595 nmtb
.rcButton
= btnPtr
->rect
;
5596 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
, TBN_DROPDOWN
);
5597 TRACE("TBN_DROPDOWN responded with %Id\n", res
);
5599 if (res
!= TBDDRET_TREATPRESSED
)
5603 /* redraw button in unpressed state */
5604 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5605 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5607 btnPtr
->bDropDownPressed
= FALSE
;
5608 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5610 /* find and set hot item */
5612 ScreenToClient(infoPtr
->hwndSelf
, &pt
);
5613 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5614 if (!infoPtr
->bAnchor
|| button
)
5615 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5617 /* remove any left mouse button down or double-click messages
5618 * so that we can get a toggle effect on the button */
5619 while (PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5620 PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5625 /* otherwise drop through and process as pushed */
5627 infoPtr
->bCaptured
= TRUE
;
5628 infoPtr
->nButtonDown
= nHit
;
5629 infoPtr
->bDragOutSent
= FALSE
;
5631 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5633 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5635 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5636 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5637 UpdateWindow(infoPtr
->hwndSelf
);
5638 SetCapture (infoPtr
->hwndSelf
);
5641 memset(&nmtb
, 0, sizeof(nmtb
));
5642 nmtb
.iItem
= btnPtr
->idCommand
;
5643 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5646 nmmouse
.dwHitInfo
= nHit
;
5648 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5650 nmmouse
.dwItemSpec
= -1;
5653 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5654 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5657 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5660 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5661 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, wParam
, lParam
);
5667 TOOLBAR_LButtonUp (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5669 TBUTTON_INFO
*btnPtr
;
5678 if (infoPtr
->hwndToolTip
)
5679 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5680 WM_LBUTTONUP
, wParam
, lParam
);
5682 pt
.x
= (short)LOWORD(lParam
);
5683 pt
.y
= (short)HIWORD(lParam
);
5684 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5686 if (!infoPtr
->bAnchor
|| button
)
5687 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5689 if (infoPtr
->nButtonDrag
>= 0) {
5693 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5696 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5698 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5699 if (PtInRect(&rcClient
, pt
))
5706 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5709 if (nButton
== infoPtr
->nButtonDrag
)
5711 /* if the button is moved slightly left and we have a
5712 * separator there then remove it */
5713 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5715 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5716 TOOLBAR_DeleteButton(infoPtr
, nButton
- 1);
5718 else /* else insert a separator before the dragged button */
5721 memset(&tbb
, 0, sizeof(tbb
));
5722 tbb
.fsStyle
= BTNS_SEP
;
5724 TOOLBAR_InsertButtonT(infoPtr
, nButton
, &tbb
, TRUE
);
5731 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5732 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, 0);
5734 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5737 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, nButton
);
5742 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5743 TOOLBAR_DeleteButton(infoPtr
, infoPtr
->nButtonDrag
);
5746 /* button under cursor changed so need to re-set hot item */
5747 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5748 infoPtr
->nButtonDrag
= -1;
5750 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5752 else if (infoPtr
->nButtonDown
>= 0)
5754 BOOL was_clicked
= nHit
== infoPtr
->nButtonDown
;
5756 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5757 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5759 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5760 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5761 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5763 if ((nOldIndex
!= nHit
) &&
5765 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5766 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5769 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5770 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5772 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5776 if (nOldIndex
!= -1)
5777 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5780 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5781 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5782 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5784 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5786 infoPtr
->nButtonDown
= -1;
5788 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5789 TOOLBAR_SendNotify (&hdr
, infoPtr
,
5790 NM_RELEASEDCAPTURE
);
5792 memset(&nmtb
, 0, sizeof(nmtb
));
5793 nmtb
.iItem
= btnPtr
->idCommand
;
5794 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5797 if (was_clicked
&& btnPtr
->fsState
& TBSTATE_ENABLED
)
5799 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5800 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)infoPtr
->hwndSelf
);
5802 /* In case we have just been destroyed... */
5803 if(!IsWindow(infoPtr
->hwndSelf
))
5808 /* !!! Undocumented - toolbar at 4.71 level and above sends
5809 * NM_CLICK with the NMMOUSE structure. */
5810 nmmouse
.dwHitInfo
= nHit
;
5813 nmmouse
.dwItemSpec
= -1;
5816 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5817 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5820 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5823 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5824 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONUP
, wParam
, lParam
);
5830 TOOLBAR_RButtonUp(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5837 pt
.x
= (short)LOWORD(lParam
);
5838 pt
.y
= (short)HIWORD(lParam
);
5840 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5841 nmmouse
.dwHitInfo
= nHit
;
5844 nmmouse
.dwItemSpec
= -1;
5846 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5847 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5850 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5853 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5854 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONUP
, wParam
, lParam
);
5860 TOOLBAR_RButtonDblClk( TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5864 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5865 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
5871 TOOLBAR_CaptureChanged(TOOLBAR_INFO
*infoPtr
)
5873 TBUTTON_INFO
*btnPtr
;
5875 infoPtr
->bCaptured
= FALSE
;
5877 if (infoPtr
->nButtonDown
>= 0)
5879 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5880 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5882 infoPtr
->nOldHit
= -1;
5884 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5885 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5891 TOOLBAR_MouseLeave (TOOLBAR_INFO
*infoPtr
)
5893 /* don't remove hot effects when in anchor highlighting mode or when a
5894 * drop-down button is pressed */
5895 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
5897 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
5898 if (!hotBtnPtr
->bDropDownPressed
)
5899 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
5902 if (infoPtr
->nOldHit
< 0)
5905 /* If the last button we were over is depressed then make it not */
5906 /* depressed and redraw it */
5907 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
5909 TBUTTON_INFO
*btnPtr
;
5912 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5914 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5917 InflateRect (&rc1
, 1, 1);
5918 InvalidateRect (infoPtr
->hwndSelf
, &rc1
, TRUE
);
5921 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
5924 ZeroMemory(&nmt
, sizeof(nmt
));
5925 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5926 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5927 infoPtr
->bDragOutSent
= TRUE
;
5930 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
5936 TOOLBAR_MouseMove (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5939 TRACKMOUSEEVENT trackinfo
;
5941 TBUTTON_INFO
*btnPtr
;
5944 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
5945 TOOLBAR_TooltipCreateControl(infoPtr
);
5947 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || infoPtr
->hTheme
) {
5948 /* fill in the TRACKMOUSEEVENT struct */
5949 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5950 trackinfo
.dwFlags
= TME_QUERY
;
5952 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5953 _TrackMouseEvent(&trackinfo
);
5955 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5956 if(trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
5957 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5958 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
5960 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5961 /* and can properly deactivate the hot toolbar button */
5962 _TrackMouseEvent(&trackinfo
);
5966 if (infoPtr
->hwndToolTip
)
5967 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5968 WM_MOUSEMOVE
, wParam
, lParam
);
5970 pt
.x
= (short)LOWORD(lParam
);
5971 pt
.y
= (short)HIWORD(lParam
);
5973 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5975 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || infoPtr
->hTheme
) && (!infoPtr
->bAnchor
|| button
))
5976 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
);
5978 if (infoPtr
->nOldHit
!= nHit
)
5980 if (infoPtr
->bCaptured
)
5982 if (!infoPtr
->bDragOutSent
)
5985 ZeroMemory(&nmt
, sizeof(nmt
));
5986 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5987 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5988 infoPtr
->bDragOutSent
= TRUE
;
5991 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5992 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
5993 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5994 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5996 else if (nHit
== infoPtr
->nButtonDown
) {
5997 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5998 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6000 infoPtr
->nOldHit
= nHit
;
6008 static inline LRESULT
6009 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6011 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6012 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
6014 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6018 static inline LRESULT
6019 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6021 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
6022 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
6024 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
6029 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
6031 TOOLBAR_INFO
*infoPtr
;
6034 /* allocate memory for info structure */
6035 infoPtr
= Alloc (sizeof(TOOLBAR_INFO
));
6036 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
6039 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
6042 /* initialize info structure */
6043 infoPtr
->nButtonWidth
= 23;
6044 infoPtr
->nButtonHeight
= 22;
6045 infoPtr
->nBitmapHeight
= 16;
6046 infoPtr
->nBitmapWidth
= 16;
6048 infoPtr
->nMaxTextRows
= 1;
6049 infoPtr
->cxMin
= -1;
6050 infoPtr
->cxMax
= -1;
6051 infoPtr
->nNumBitmaps
= 0;
6052 infoPtr
->nNumStrings
= 0;
6054 infoPtr
->bCaptured
= FALSE
;
6055 infoPtr
->nButtonDown
= -1;
6056 infoPtr
->nButtonDrag
= -1;
6057 infoPtr
->nOldHit
= -1;
6058 infoPtr
->nHotItem
= -1;
6059 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
6060 infoPtr
->dwDTFlags
= (lpcs
->style
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
6061 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
6062 infoPtr
->bDragOutSent
= FALSE
;
6063 infoPtr
->iVersion
= 0;
6064 infoPtr
->hwndSelf
= hwnd
;
6065 infoPtr
->bDoRedraw
= TRUE
;
6066 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
6067 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
6068 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
6069 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
6070 infoPtr
->iListGap
= DEFLISTGAP
;
6071 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
6072 infoPtr
->dwStyle
= lpcs
->style
;
6073 infoPtr
->tbim
.iButton
= -1;
6075 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6076 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
6077 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
6078 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
6081 /* I think the code below is a bug, but it is the way that the native
6082 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6083 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6084 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6085 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6086 * Somehow, the only cases of this seem to be MFC programs.
6088 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6089 * does not occur in the WM_STYLECHANGING routine.
6090 * (Guy Albertelli 9/2001)
6093 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) && !(lpcs
->style
& TBSTYLE_TRANSPARENT
))
6094 styleadd
|= TBSTYLE_TRANSPARENT
;
6095 if (!(lpcs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
6096 styleadd
|= CCS_TOP
; /* default to top */
6097 SetWindowLongW (hwnd
, GWL_STYLE
, lpcs
->style
| styleadd
);
6100 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
6105 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6107 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
6111 if (dwStyle
& WS_MINIMIZE
)
6112 return 0; /* Nothing to do */
6114 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
6116 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
6119 if (!(dwStyle
& CCS_NODIVIDER
))
6121 GetWindowRect (hwnd
, &rcWindow
);
6122 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
6123 if( dwStyle
& WS_BORDER
)
6124 InflateRect (&rcWindow
, -1, -1);
6125 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6128 ReleaseDC( hwnd
, hdc
);
6134 /* handles requests from the tooltip control on what text to display */
6135 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6137 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6138 NMTTDISPINFOA nmtdi
;
6142 TRACE("button index = %d\n", index
);
6144 Free (infoPtr
->pszTooltipText
);
6145 infoPtr
->pszTooltipText
= NULL
;
6150 if (infoPtr
->bUnicode
)
6152 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6153 NMTBGETINFOTIPW tbgit
;
6155 wszBuffer
[0] = '\0';
6156 wszBuffer
[INFOTIPSIZE
] = '\0';
6158 tbgit
.pszText
= wszBuffer
;
6159 tbgit
.cchTextMax
= INFOTIPSIZE
;
6160 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6161 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6163 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6165 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6167 len
= tbgit
.pszText
? lstrlenW(tbgit
.pszText
) : 0;
6168 if (len
> ARRAY_SIZE(lpnmtdi
->szText
) - 1)
6170 /* need to allocate temporary buffer in infoPtr as there
6171 * isn't enough space in buffer passed to us by the
6172 * tooltip control */
6173 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6174 if (infoPtr
->pszTooltipText
)
6176 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6177 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6183 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6189 CHAR szBuffer
[INFOTIPSIZE
+1];
6190 NMTBGETINFOTIPA tbgit
;
6193 szBuffer
[INFOTIPSIZE
] = '\0';
6195 tbgit
.pszText
= szBuffer
;
6196 tbgit
.cchTextMax
= INFOTIPSIZE
;
6197 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6198 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6200 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6202 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6204 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6205 if (len
> ARRAY_SIZE(lpnmtdi
->szText
))
6207 /* need to allocate temporary buffer in infoPtr as there
6208 * isn't enough space in buffer passed to us by the
6209 * tooltip control */
6210 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6211 if (infoPtr
->pszTooltipText
)
6213 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6214 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6218 else if (tbgit
.pszText
&& tbgit
.pszText
[0])
6220 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, lpnmtdi
->lpszText
, ARRAY_SIZE(lpnmtdi
->szText
));
6225 /* if button has text, but it is not shown then automatically
6226 * use that text as tooltip */
6227 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6228 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6230 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6231 len
= pszText
? lstrlenW(pszText
) : 0;
6233 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6235 if (len
> ARRAY_SIZE(lpnmtdi
->szText
) - 1)
6237 /* need to allocate temporary buffer in infoPtr as there
6238 * isn't enough space in buffer passed to us by the
6239 * tooltip control */
6240 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6241 if (infoPtr
->pszTooltipText
)
6243 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6244 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6250 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6255 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6257 /* Last resort, forward TTN_GETDISPINFO to the app:
6259 - NFR_UNICODE gets TTN_GETDISPINFOW, and TTN_GETDISPINFOA if -W returned no text;
6260 - NFR_ANSI gets only TTN_GETDISPINFOA.
6262 if (infoPtr
->bUnicode
)
6264 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmtdi
->hdr
.idFrom
, (LPARAM
)lpnmtdi
);
6266 TRACE("TTN_GETDISPINFOW - got string %s\n", debugstr_w(lpnmtdi
->lpszText
));
6268 if (IS_INTRESOURCE(lpnmtdi
->lpszText
))
6271 if (lpnmtdi
->lpszText
&& *lpnmtdi
->lpszText
)
6275 nmtdi
.hdr
.hwndFrom
= lpnmtdi
->hdr
.hwndFrom
;
6276 nmtdi
.hdr
.idFrom
= lpnmtdi
->hdr
.idFrom
;
6277 nmtdi
.hdr
.code
= TTN_GETDISPINFOA
;
6278 nmtdi
.lpszText
= nmtdi
.szText
;
6279 nmtdi
.szText
[0] = 0;
6280 nmtdi
.hinst
= lpnmtdi
->hinst
;
6281 nmtdi
.uFlags
= lpnmtdi
->uFlags
;
6282 nmtdi
.lParam
= lpnmtdi
->lParam
;
6284 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmtdi
.hdr
.idFrom
, (LPARAM
)&nmtdi
);
6286 TRACE("TTN_GETDISPINFOA - got string %s\n", debugstr_a(nmtdi
.lpszText
));
6288 lpnmtdi
->hinst
= nmtdi
.hinst
;
6289 lpnmtdi
->uFlags
= nmtdi
.uFlags
;
6290 lpnmtdi
->lParam
= nmtdi
.lParam
;
6292 if (IS_INTRESOURCE(nmtdi
.lpszText
))
6294 lpnmtdi
->lpszText
= (WCHAR
*)nmtdi
.lpszText
;
6298 if (!nmtdi
.lpszText
|| !*nmtdi
.lpszText
)
6301 len
= MultiByteToWideChar(CP_ACP
, 0, nmtdi
.lpszText
, -1, NULL
, 0);
6302 if (len
> ARRAY_SIZE(lpnmtdi
->szText
))
6304 infoPtr
->pszTooltipText
= Alloc(len
* sizeof(WCHAR
));
6305 if (infoPtr
->pszTooltipText
)
6307 MultiByteToWideChar(CP_ACP
, 0, nmtdi
.lpszText
, -1, infoPtr
->pszTooltipText
, len
);
6308 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6314 MultiByteToWideChar(CP_ACP
, 0, nmtdi
.lpszText
, -1, lpnmtdi
->lpszText
, ARRAY_SIZE(nmtdi
.szText
));
6322 static inline LRESULT
6323 TOOLBAR_Notify (TOOLBAR_INFO
*infoPtr
, LPNMHDR lpnmh
)
6325 switch (lpnmh
->code
)
6329 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lpnmh
;
6331 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6332 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6333 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6337 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6338 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6346 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lpnmh
;
6348 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6349 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6350 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6351 lppgs
->iScroll
, lppgs
->iDir
);
6355 case TTN_GETDISPINFOW
:
6356 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lpnmh
);
6358 case TTN_GETDISPINFOA
:
6359 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6369 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6373 TRACE("wParam %Ix, lParam %Ix\n", wParam
, lParam
);
6375 if (lParam
== NF_QUERY
)
6378 if (lParam
== NF_REQUERY
) {
6379 format
= SendMessageW(infoPtr
->hwndNotify
,
6380 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6381 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6382 ERR("wrong response to WM_NOTIFYFORMAT (%Id), assuming ANSI\n", format
);
6392 TOOLBAR_Paint (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6397 /* fill ps.rcPaint with a default rect */
6398 ps
.rcPaint
= infoPtr
->rcBound
;
6400 hdc
= wParam
==0 ? BeginPaint(infoPtr
->hwndSelf
, &ps
) : (HDC
)wParam
;
6402 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps
.rcPaint
));
6404 TOOLBAR_Refresh (infoPtr
, hdc
, &ps
);
6405 if (!wParam
) EndPaint (infoPtr
->hwndSelf
, &ps
);
6412 TOOLBAR_SetFocus (TOOLBAR_INFO
*infoPtr
)
6414 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6416 /* make first item hot */
6417 if (infoPtr
->nNumButtons
> 0)
6418 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6424 TOOLBAR_SetFont(TOOLBAR_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
6426 TRACE("font=%p redraw=%d\n", hFont
, Redraw
);
6429 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6431 infoPtr
->hFont
= hFont
;
6433 TOOLBAR_CalcToolbar(infoPtr
);
6436 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6441 TOOLBAR_SetRedraw (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6442 /*****************************************************
6445 * Handles the WM_SETREDRAW message.
6448 * According to testing V4.71 of COMCTL32 returns the
6449 * *previous* status of the redraw flag (either 0 or 1)
6450 * instead of the MSDN documented value of 0 if handled.
6451 * (For laughs see the "consistency" with same function
6454 *****************************************************/
6456 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6458 TRACE("set to %s\n",
6459 (wParam
) ? "TRUE" : "FALSE");
6460 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6462 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6464 return (oldredraw
) ? 1 : 0;
6469 TOOLBAR_Size (TOOLBAR_INFO
*infoPtr
)
6471 TRACE("sizing toolbar\n");
6473 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6475 RECT delta_width
, delta_height
, client
, dummy
;
6476 DWORD min_x
, max_x
, min_y
, max_y
;
6477 TBUTTON_INFO
*btnPtr
;
6480 GetClientRect(infoPtr
->hwndSelf
, &client
);
6481 if(client
.right
> infoPtr
->client_rect
.right
)
6483 min_x
= infoPtr
->client_rect
.right
;
6484 max_x
= client
.right
;
6488 max_x
= infoPtr
->client_rect
.right
;
6489 min_x
= client
.right
;
6491 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6493 min_y
= infoPtr
->client_rect
.bottom
;
6494 max_y
= client
.bottom
;
6498 max_y
= infoPtr
->client_rect
.bottom
;
6499 min_y
= client
.bottom
;
6502 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6503 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6505 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6506 btnPtr
= infoPtr
->buttons
;
6507 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6508 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6509 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6510 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6512 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->client_rect
);
6513 TOOLBAR_AutoSize(infoPtr
);
6519 TOOLBAR_StyleChanged (TOOLBAR_INFO
*infoPtr
, INT nType
, const STYLESTRUCT
*lpStyle
)
6521 if (nType
== GWL_STYLE
)
6522 return TOOLBAR_SetStyle(infoPtr
, lpStyle
->styleNew
);
6529 TOOLBAR_SysColorChange (void)
6531 COMCTL32_RefreshSysColors();
6537 /* update theme after a WM_THEMECHANGED message */
6538 static LRESULT
theme_changed (TOOLBAR_INFO
*infoPtr
)
6540 CloseThemeData (infoPtr
->hTheme
);
6541 infoPtr
->hTheme
= OpenThemeDataForDpi (NULL
, themeClass
, GetDpiForWindow (infoPtr
->hwndSelf
));
6542 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
6547 static LRESULT WINAPI
6548 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6550 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
6552 TRACE("hwnd %p, msg %x, wparam %Ix, lparam %Ix\n", hwnd
, uMsg
, wParam
, lParam
);
6554 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6555 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6560 return TOOLBAR_AddBitmap (infoPtr
, (INT
)wParam
, (TBADDBITMAP
*)lParam
);
6562 case TB_ADDBUTTONSA
:
6563 case TB_ADDBUTTONSW
:
6564 return TOOLBAR_AddButtonsT (infoPtr
, wParam
, (LPTBBUTTON
)lParam
,
6565 uMsg
== TB_ADDBUTTONSW
);
6567 return TOOLBAR_AddStringA (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6570 return TOOLBAR_AddStringW (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6573 return TOOLBAR_AutoSize (infoPtr
);
6575 case TB_BUTTONCOUNT
:
6576 return TOOLBAR_ButtonCount (infoPtr
);
6578 case TB_BUTTONSTRUCTSIZE
:
6579 return TOOLBAR_ButtonStructSize (infoPtr
, wParam
);
6581 case TB_CHANGEBITMAP
:
6582 return TOOLBAR_ChangeBitmap (infoPtr
, wParam
, LOWORD(lParam
));
6584 case TB_CHECKBUTTON
:
6585 return TOOLBAR_CheckButton (infoPtr
, wParam
, lParam
);
6587 case TB_COMMANDTOINDEX
:
6588 return TOOLBAR_CommandToIndex (infoPtr
, wParam
);
6591 return TOOLBAR_Customize (infoPtr
);
6593 case TB_DELETEBUTTON
:
6594 return TOOLBAR_DeleteButton (infoPtr
, wParam
);
6596 case TB_ENABLEBUTTON
:
6597 return TOOLBAR_EnableButton (infoPtr
, wParam
, lParam
);
6599 case TB_GETANCHORHIGHLIGHT
:
6600 return TOOLBAR_GetAnchorHighlight (infoPtr
);
6603 return TOOLBAR_GetBitmap (infoPtr
, wParam
);
6605 case TB_GETBITMAPFLAGS
:
6606 return TOOLBAR_GetBitmapFlags ();
6609 return TOOLBAR_GetButton (infoPtr
, wParam
, (TBBUTTON
*)lParam
);
6611 case TB_GETBUTTONINFOA
:
6612 case TB_GETBUTTONINFOW
:
6613 return TOOLBAR_GetButtonInfoT (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6614 uMsg
== TB_GETBUTTONINFOW
);
6615 case TB_GETBUTTONSIZE
:
6616 return TOOLBAR_GetButtonSize (infoPtr
);
6618 case TB_GETBUTTONTEXTA
:
6619 case TB_GETBUTTONTEXTW
:
6620 return TOOLBAR_GetButtonText (infoPtr
, wParam
, (LPWSTR
)lParam
,
6621 uMsg
== TB_GETBUTTONTEXTW
);
6623 case TB_GETDISABLEDIMAGELIST
:
6624 return TOOLBAR_GetDisabledImageList (infoPtr
, wParam
);
6626 case TB_GETEXTENDEDSTYLE
:
6627 return TOOLBAR_GetExtendedStyle (infoPtr
);
6629 case TB_GETHOTIMAGELIST
:
6630 return TOOLBAR_GetHotImageList (infoPtr
, wParam
);
6633 return TOOLBAR_GetHotItem (infoPtr
);
6635 case TB_GETIMAGELIST
:
6636 return TOOLBAR_GetDefImageList (infoPtr
, wParam
);
6638 case TB_GETINSERTMARK
:
6639 return TOOLBAR_GetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6641 case TB_GETINSERTMARKCOLOR
:
6642 return TOOLBAR_GetInsertMarkColor (infoPtr
);
6644 case TB_GETITEMRECT
:
6645 return TOOLBAR_GetItemRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6648 return TOOLBAR_GetMaxSize (infoPtr
, (LPSIZE
)lParam
);
6650 /* case TB_GETOBJECT: */ /* 4.71 */
6653 return TOOLBAR_GetPadding (infoPtr
);
6656 return TOOLBAR_GetRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6659 return TOOLBAR_GetRows (infoPtr
);
6662 return TOOLBAR_GetState (infoPtr
, wParam
);
6665 return TOOLBAR_GetStringA (infoPtr
, wParam
, (LPSTR
)lParam
);
6668 return TOOLBAR_GetStringW (infoPtr
, wParam
, (LPWSTR
)lParam
);
6671 return TOOLBAR_GetStyle (infoPtr
);
6673 case TB_GETTEXTROWS
:
6674 return TOOLBAR_GetTextRows (infoPtr
);
6676 case TB_GETTOOLTIPS
:
6677 return TOOLBAR_GetToolTips (infoPtr
);
6679 case TB_GETUNICODEFORMAT
:
6680 return TOOLBAR_GetUnicodeFormat (infoPtr
);
6683 return TOOLBAR_HideButton (infoPtr
, wParam
, LOWORD(lParam
));
6686 return TOOLBAR_HitTest (infoPtr
, (LPPOINT
)lParam
);
6688 case TB_INDETERMINATE
:
6689 return TOOLBAR_Indeterminate (infoPtr
, wParam
, LOWORD(lParam
));
6691 case TB_INSERTBUTTONA
:
6692 case TB_INSERTBUTTONW
:
6693 return TOOLBAR_InsertButtonT(infoPtr
, wParam
, (TBBUTTON
*)lParam
,
6694 uMsg
== TB_INSERTBUTTONW
);
6696 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6698 case TB_ISBUTTONCHECKED
:
6699 return TOOLBAR_IsButtonChecked (infoPtr
, wParam
);
6701 case TB_ISBUTTONENABLED
:
6702 return TOOLBAR_IsButtonEnabled (infoPtr
, wParam
);
6704 case TB_ISBUTTONHIDDEN
:
6705 return TOOLBAR_IsButtonHidden (infoPtr
, wParam
);
6707 case TB_ISBUTTONHIGHLIGHTED
:
6708 return TOOLBAR_IsButtonHighlighted (infoPtr
, wParam
);
6710 case TB_ISBUTTONINDETERMINATE
:
6711 return TOOLBAR_IsButtonIndeterminate (infoPtr
, wParam
);
6713 case TB_ISBUTTONPRESSED
:
6714 return TOOLBAR_IsButtonPressed (infoPtr
, wParam
);
6717 return TOOLBAR_LoadImages (infoPtr
, wParam
, (HINSTANCE
)lParam
);
6719 case TB_MAPACCELERATORA
:
6720 case TB_MAPACCELERATORW
:
6721 return TOOLBAR_MapAccelerator (infoPtr
, wParam
, (UINT
*)lParam
);
6724 return TOOLBAR_MarkButton (infoPtr
, wParam
, LOWORD(lParam
));
6727 return TOOLBAR_MoveButton (infoPtr
, wParam
, lParam
);
6729 case TB_PRESSBUTTON
:
6730 return TOOLBAR_PressButton (infoPtr
, wParam
, LOWORD(lParam
));
6732 case TB_REPLACEBITMAP
:
6733 return TOOLBAR_ReplaceBitmap (infoPtr
, (LPTBREPLACEBITMAP
)lParam
);
6735 case TB_SAVERESTOREA
:
6736 return TOOLBAR_SaveRestoreA (infoPtr
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6738 case TB_SAVERESTOREW
:
6739 return TOOLBAR_SaveRestoreW (infoPtr
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6741 case TB_SETANCHORHIGHLIGHT
:
6742 return TOOLBAR_SetAnchorHighlight (infoPtr
, (BOOL
)wParam
);
6744 case TB_SETBITMAPSIZE
:
6745 return TOOLBAR_SetBitmapSize (infoPtr
, wParam
, lParam
);
6747 case TB_SETBUTTONINFOA
:
6748 case TB_SETBUTTONINFOW
:
6749 return TOOLBAR_SetButtonInfo (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6750 uMsg
== TB_SETBUTTONINFOW
);
6751 case TB_SETBUTTONSIZE
:
6752 return TOOLBAR_SetButtonSize (infoPtr
, lParam
);
6754 case TB_SETBUTTONWIDTH
:
6755 return TOOLBAR_SetButtonWidth (infoPtr
, lParam
);
6758 return TOOLBAR_SetCmdId (infoPtr
, wParam
, lParam
);
6760 case TB_SETDISABLEDIMAGELIST
:
6761 return TOOLBAR_SetDisabledImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6763 case TB_SETDRAWTEXTFLAGS
:
6764 return TOOLBAR_SetDrawTextFlags (infoPtr
, wParam
, lParam
);
6766 case TB_SETEXTENDEDSTYLE
:
6767 return TOOLBAR_SetExtendedStyle (infoPtr
, wParam
, lParam
);
6769 case TB_SETHOTIMAGELIST
:
6770 return TOOLBAR_SetHotImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6773 return TOOLBAR_SetHotItem (infoPtr
, wParam
);
6775 case TB_SETIMAGELIST
:
6776 return TOOLBAR_SetImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6779 return TOOLBAR_SetIndent (infoPtr
, wParam
);
6781 case TB_SETINSERTMARK
:
6782 return TOOLBAR_SetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6784 case TB_SETINSERTMARKCOLOR
:
6785 return TOOLBAR_SetInsertMarkColor (infoPtr
, lParam
);
6787 case TB_SETMAXTEXTROWS
:
6788 return TOOLBAR_SetMaxTextRows (infoPtr
, wParam
);
6791 return TOOLBAR_SetPadding (infoPtr
, lParam
);
6794 return TOOLBAR_SetParent (infoPtr
, (HWND
)wParam
);
6797 return TOOLBAR_SetRows (infoPtr
, wParam
, (LPRECT
)lParam
);
6800 return TOOLBAR_SetState (infoPtr
, wParam
, lParam
);
6803 return TOOLBAR_SetStyle (infoPtr
, lParam
);
6805 case TB_SETTOOLTIPS
:
6806 return TOOLBAR_SetToolTips (infoPtr
, (HWND
)wParam
);
6808 case TB_SETUNICODEFORMAT
:
6809 return TOOLBAR_SetUnicodeFormat (infoPtr
, wParam
);
6811 case TB_SETBOUNDINGSIZE
:
6812 return TOOLBAR_SetBoundingSize(hwnd
, wParam
, lParam
);
6814 case TB_SETHOTITEM2
:
6815 return TOOLBAR_SetHotItem2 (infoPtr
, wParam
, lParam
);
6818 return TOOLBAR_SetListGap(infoPtr
, wParam
);
6820 case TB_GETIMAGELISTCOUNT
:
6821 return TOOLBAR_GetImageListCount(infoPtr
);
6823 case TB_GETIDEALSIZE
:
6824 return TOOLBAR_GetIdealSize (infoPtr
, wParam
, lParam
);
6827 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6829 /* Common Control Messages */
6831 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6832 case CCM_GETCOLORSCHEME
:
6833 return TOOLBAR_GetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6835 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6836 case CCM_SETCOLORSCHEME
:
6837 return TOOLBAR_SetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6839 case CCM_GETVERSION
:
6840 return TOOLBAR_GetVersion (infoPtr
);
6842 case CCM_SETVERSION
:
6843 return TOOLBAR_SetVersion (infoPtr
, (INT
)wParam
);
6849 return TOOLBAR_Create (hwnd
, (CREATESTRUCTW
*)lParam
);
6852 return TOOLBAR_Destroy (infoPtr
);
6855 return TOOLBAR_EraseBackground (infoPtr
, wParam
, lParam
);
6858 return TOOLBAR_GetFont (infoPtr
);
6861 return TOOLBAR_KeyDown (infoPtr
, wParam
, lParam
);
6863 /* case WM_KILLFOCUS: */
6865 case WM_LBUTTONDBLCLK
:
6866 return TOOLBAR_LButtonDblClk (infoPtr
, wParam
, lParam
);
6868 case WM_LBUTTONDOWN
:
6869 return TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
6872 return TOOLBAR_LButtonUp (infoPtr
, wParam
, lParam
);
6875 return TOOLBAR_RButtonUp (infoPtr
, wParam
, lParam
);
6877 case WM_RBUTTONDBLCLK
:
6878 return TOOLBAR_RButtonDblClk (infoPtr
, wParam
, lParam
);
6881 return TOOLBAR_MouseMove (infoPtr
, wParam
, lParam
);
6884 return TOOLBAR_MouseLeave (infoPtr
);
6886 case WM_CAPTURECHANGED
:
6887 if (hwnd
== (HWND
)lParam
) return 0;
6888 return TOOLBAR_CaptureChanged(infoPtr
);
6891 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6894 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6897 return TOOLBAR_NCCreate (hwnd
, wParam
, (CREATESTRUCTW
*)lParam
);
6900 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
6903 return TOOLBAR_Notify (infoPtr
, (LPNMHDR
)lParam
);
6905 case WM_NOTIFYFORMAT
:
6906 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
6908 case WM_PRINTCLIENT
:
6910 return TOOLBAR_Paint (infoPtr
, wParam
);
6913 return TOOLBAR_SetFocus (infoPtr
);
6916 return TOOLBAR_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
6919 return TOOLBAR_SetRedraw (infoPtr
, wParam
);
6922 return TOOLBAR_Size (infoPtr
);
6924 case WM_STYLECHANGED
:
6925 return TOOLBAR_StyleChanged (infoPtr
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
6927 case WM_SYSCOLORCHANGE
:
6928 return TOOLBAR_SysColorChange ();
6930 case WM_THEMECHANGED
:
6931 return theme_changed (infoPtr
);
6933 /* case WM_WININICHANGE: */
6938 case WM_MEASUREITEM
:
6940 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
6942 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6943 case PGM_FORWARDMOUSE
:
6944 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6947 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
6948 ERR("unknown msg %04x, wp %Ix, lp %Ix\n", uMsg
, wParam
, lParam
);
6949 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6955 TOOLBAR_Register (void)
6959 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
6960 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
6961 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
6962 wndClass
.cbClsExtra
= 0;
6963 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
6964 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
6965 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
6966 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
6968 RegisterClassW (&wndClass
);
6973 TOOLBAR_Unregister (void)
6975 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
6978 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
6983 /* Check if the entry already exists */
6984 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
6986 /* Don't add new entry for NULL imagelist */
6990 /* If this is a new entry we must create it and insert into the array */
6995 c
= Alloc(sizeof(IMLENTRY
));
6998 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
6999 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
7014 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
7018 for (i
= 0; i
< *cies
; i
++)
7028 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
7036 for (i
= 0; i
< cies
; i
++)
7038 if (pies
[i
]->id
== id
)
7050 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
7052 HIMAGELIST himlDef
= 0;
7053 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
7056 himlDef
= pie
->himl
;
7062 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
7064 if (infoPtr
->bUnicode
)
7065 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
7072 nmtba
.iItem
= nmtb
->iItem
;
7073 nmtba
.pszText
= Buffer
;
7074 nmtba
.cchText
= 256;
7075 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
7077 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
7079 int ccht
= strlen(nmtba
.pszText
);
7081 MultiByteToWideChar(CP_ACP
, 0, nmtba
.pszText
, -1,
7082 nmtb
->pszText
, nmtb
->cchText
);
7084 nmtb
->tbButton
= nmtba
.tbButton
;
7093 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
)
7097 /* MSDN states that iItem is the index of the button, rather than the
7098 * command ID as used by every other NMTOOLBAR notification */
7100 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
7102 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);