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
37 * - TB_INSERTMARKHITTEST
44 * - Button wrapping (under construction).
45 * - Fix TB_SETROWS and Separators.
46 * - iListGap custom draw support.
49 * - Run tests using Waite Group Windows95 API Bible Volume 2.
50 * The second cdrom contains executables addstr.exe, btncount.exe,
51 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
52 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
53 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
54 * setparnt.exe, setrows.exe, toolwnd.exe.
55 * - Microsoft's controlspy examples.
56 * - Charles Petzold's 'Programming Windows': gadgets.exe
58 * Differences between MSDN and actual native control operation:
59 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
60 * to the right of the bitmap. Otherwise, this style is
61 * identical to TBSTYLE_FLAT."
62 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
63 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
64 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
65 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
71 WINE_DEFAULT_DEBUG_CHANNEL(toolbar
);
73 static HCURSOR hCursorDrag
= NULL
;
82 BOOL bDropDownPressed
;
87 INT cx
; /* manually set size */
101 } IMLENTRY
, *PIMLENTRY
;
105 DWORD dwStructSize
; /* size of TBBUTTON struct */
107 RECT rcBound
; /* bounding rectangle */
113 INT nRows
; /* number of button rows */
114 INT nMaxTextRows
; /* maximum number of text rows */
115 INT cxMin
; /* minimum button width */
116 INT cxMax
; /* maximum button width */
117 INT nNumButtons
; /* number of buttons */
118 INT nNumBitmaps
; /* number of bitmaps */
119 INT nNumStrings
; /* number of strings */
121 INT nButtonDown
; /* toolbar button being pressed or -1 if none */
122 INT nButtonDrag
; /* toolbar button being dragged or -1 if none */
124 INT nHotItem
; /* index of the "hot" item */
125 SIZE szPadding
; /* padding values around button */
127 SIZE szBarPadding
; /* padding values around the toolbar (NOT USED BUT STORED) */
128 SIZE szSpacing
; /* spacing values between buttons */
130 INT iTopMargin
; /* the top margin */
131 INT iListGap
; /* default gap between text and image for toolbar with list style */
133 HFONT hFont
; /* text font */
134 HIMAGELIST himlInt
; /* image list created internally */
135 PIMLENTRY
*himlDef
; /* default image list array */
136 INT cimlDef
; /* default image list array count */
137 PIMLENTRY
*himlHot
; /* hot image list array */
138 INT cimlHot
; /* hot image list array count */
139 PIMLENTRY
*himlDis
; /* disabled image list array */
140 INT cimlDis
; /* disabled image list array count */
141 HWND hwndToolTip
; /* handle to tool tip control */
142 HWND hwndNotify
; /* handle to the window that gets notifications */
143 HWND hwndSelf
; /* my own handle */
144 BOOL bAnchor
; /* anchor highlight enabled */
145 BOOL bDoRedraw
; /* Redraw status */
146 BOOL bDragOutSent
; /* has TBN_DRAGOUT notification been sent for this drag? */
147 BOOL bUnicode
; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
148 BOOL bCaptured
; /* mouse captured? */
149 DWORD dwStyle
; /* regular toolbar style */
150 DWORD dwExStyle
; /* extended toolbar style */
151 DWORD dwDTFlags
; /* DrawText flags */
153 COLORREF clrInsertMark
; /* insert mark color */
154 COLORREF clrBtnHighlight
; /* color for Flat Separator */
155 COLORREF clrBtnShadow
; /* color for Flag Separator */
157 LPWSTR pszTooltipText
; /* temporary store for a string > 80 characters
158 * for TTN_GETDISPINFOW notification */
159 TBINSERTMARK tbim
; /* info on insertion mark */
160 TBUTTON_INFO
*buttons
; /* pointer to button array */
161 LPWSTR
*strings
; /* pointer to string array */
162 TBITMAP_INFO
*bitmaps
;
163 } TOOLBAR_INFO
, *PTOOLBAR_INFO
;
166 /* used by customization dialog */
169 PTOOLBAR_INFO tbInfo
;
171 } CUSTDLG_INFO
, *PCUSTDLG_INFO
;
179 } CUSTOMBUTTON
, *PCUSTOMBUTTON
;
188 #define SEPARATOR_WIDTH 8
190 #define BOTTOM_BORDER 2
191 #define DDARROW_WIDTH 11
192 #define ARROW_HEIGHT 3
193 #define INSERTMARK_WIDTH 2
195 /* default padding inside a button */
200 /* default space between buttons and between rows */
201 #define DEFSPACE_CX 7
202 #define DEFSPACE_CY 6
207 /* 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
[] = { 'T','o','o','l','b','a','r',0 };
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
)
257 return (infoPtr
->dwStyle
& TBSTYLE_FLAT
? 0 : TOP_BORDER
);
259 /* This is the behaviour in comctl32 v6 */
264 static inline BOOL
TOOLBAR_HasDropDownArrows(DWORD exStyle
)
266 return (exStyle
& TBSTYLE_EX_DRAWDDARROWS
) != 0;
269 static inline BOOL
button_has_ddarrow(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
271 return (TOOLBAR_HasDropDownArrows( infoPtr
->dwExStyle
) && (btnPtr
->fsStyle
& BTNS_DROPDOWN
)) ||
272 (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
276 TOOLBAR_GetText(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
278 LPWSTR lpText
= NULL
;
280 /* NOTE: iString == -1 is undocumented */
281 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1))
282 lpText
= (LPWSTR
)btnPtr
->iString
;
283 else if ((btnPtr
->iString
>= 0) && (btnPtr
->iString
< infoPtr
->nNumStrings
))
284 lpText
= infoPtr
->strings
[btnPtr
->iString
];
290 TOOLBAR_DumpTBButton(const TBBUTTON
*tbb
, BOOL fUnicode
)
292 TRACE("TBBUTTON: id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx (%s)\n",
293 tbb
->idCommand
,tbb
->iBitmap
, tbb
->fsState
, tbb
->fsStyle
, tbb
->dwData
, tbb
->iString
,
294 (fUnicode
? wine_dbgstr_w((LPWSTR
)tbb
->iString
) : wine_dbgstr_a((LPSTR
)tbb
->iString
)));
298 TOOLBAR_DumpButton(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*bP
, INT btn_num
)
300 if (TRACE_ON(toolbar
)){
301 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
302 btn_num
, bP
->idCommand
, GETIBITMAP(infoPtr
, bP
->iBitmap
),
303 bP
->fsState
, bP
->fsStyle
, bP
->dwData
, bP
->iString
);
304 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr
,bP
)));
305 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n",
306 btn_num
, bP
->idCommand
, (bP
->bHot
) ? "TRUE":"FALSE", bP
->nRow
,
307 wine_dbgstr_rect(&bP
->rect
));
313 TOOLBAR_DumpToolbar(const TOOLBAR_INFO
*iP
, INT line
)
315 if (TRACE_ON(toolbar
)) {
318 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
320 iP
->dwExStyle
, iP
->nNumButtons
, iP
->nNumBitmaps
,
321 iP
->nNumStrings
, iP
->dwStyle
);
322 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
324 iP
->himlInt
, iP
->himlDef
, iP
->himlHot
, iP
->himlDis
,
325 (iP
->bDoRedraw
) ? "TRUE" : "FALSE");
326 for(i
=0; i
<iP
->nNumButtons
; i
++) {
327 TOOLBAR_DumpButton(iP
, &iP
->buttons
[i
], i
);
333 TOOLBAR_ButtonHasString(const TBUTTON_INFO
*btnPtr
)
335 return HIWORD(btnPtr
->iString
) && btnPtr
->iString
!= -1;
338 static void set_string_index( TBUTTON_INFO
*btn
, INT_PTR str
, BOOL unicode
)
340 if (!IS_INTRESOURCE( str
) && str
!= -1)
342 if (!TOOLBAR_ButtonHasString( btn
)) btn
->iString
= 0;
345 Str_SetPtrW( (WCHAR
**)&btn
->iString
, (WCHAR
*)str
);
347 Str_SetPtrAtoW( (WCHAR
**)&btn
->iString
, (char *)str
);
351 if (TOOLBAR_ButtonHasString( btn
)) Free( (WCHAR
*)btn
->iString
);
357 static void set_stringT( TBUTTON_INFO
*btn
, const WCHAR
*str
, BOOL unicode
)
359 if (IS_INTRESOURCE( (DWORD_PTR
)str
) || (DWORD_PTR
)str
== -1) return;
360 set_string_index( btn
, (DWORD_PTR
)str
, unicode
);
363 static void free_string( TBUTTON_INFO
*btn
)
365 set_string_index( btn
, 0, TRUE
);
369 /***********************************************************************
372 * This function validates that the styles set are implemented and
373 * issues FIXMEs warning of possible problems. In a perfect world this
374 * function should be null.
377 TOOLBAR_CheckStyle (const TOOLBAR_INFO
*infoPtr
)
379 if (infoPtr
->dwStyle
& TBSTYLE_REGISTERDROP
)
380 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", infoPtr
->hwndSelf
);
385 TOOLBAR_SendNotify (NMHDR
*nmhdr
, const TOOLBAR_INFO
*infoPtr
, UINT code
)
387 if(!IsWindow(infoPtr
->hwndSelf
))
388 return 0; /* we have just been destroyed */
390 nmhdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
391 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
394 TRACE("to window %p, code=%08x, %s\n", infoPtr
->hwndNotify
, code
,
395 (infoPtr
->bUnicode
) ? "via Unicode" : "via ANSI");
397 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhdr
->idFrom
, (LPARAM
)nmhdr
);
400 /***********************************************************************
401 * TOOLBAR_GetBitmapIndex
403 * This function returns the bitmap index associated with a button.
404 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
405 * is issued to retrieve the index.
408 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
410 INT ret
= btnPtr
->iBitmap
;
412 if (ret
== I_IMAGECALLBACK
)
414 /* issue TBN_GETDISPINFO */
417 memset(&nmgd
, 0, sizeof(nmgd
));
418 nmgd
.idCommand
= btnPtr
->idCommand
;
419 nmgd
.lParam
= btnPtr
->dwData
;
420 nmgd
.dwMask
= TBNF_IMAGE
;
422 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
423 TOOLBAR_SendNotify(&nmgd
.hdr
, infoPtr
, TBN_GETDISPINFOW
);
424 if (nmgd
.dwMask
& TBNF_DI_SETITEM
)
425 btnPtr
->iBitmap
= nmgd
.iImage
;
427 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
428 ret
, nmgd
.dwMask
, infoPtr
->nNumBitmaps
);
431 if (ret
!= I_IMAGENONE
)
432 ret
= GETIBITMAP(infoPtr
, ret
);
439 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO
*infoPtr
, INT index
)
442 INT id
= GETHIMLID(infoPtr
, index
);
443 INT iBitmap
= GETIBITMAP(infoPtr
, index
);
445 if (((himl
= GETDEFIMAGELIST(infoPtr
, id
)) &&
446 iBitmap
>= 0 && iBitmap
< ImageList_GetImageCount(himl
)) ||
447 (index
== I_IMAGECALLBACK
))
455 TOOLBAR_IsValidImageList(const TOOLBAR_INFO
*infoPtr
, INT index
)
457 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, index
));
458 return (himl
!= NULL
) && (ImageList_GetImageCount(himl
) > 0);
462 /***********************************************************************
463 * TOOLBAR_GetImageListForDrawing
465 * This function validates the bitmap index (including I_IMAGECALLBACK
466 * functionality) and returns the corresponding image list.
469 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
,
470 IMAGE_LIST_TYPE imagelist
, INT
* index
)
474 if (!TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
)) {
475 if (btnPtr
->iBitmap
== I_IMAGENONE
) return NULL
;
476 WARN("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
477 HIWORD(btnPtr
->iBitmap
), LOWORD(btnPtr
->iBitmap
), infoPtr
->nNumBitmaps
);
481 if ((*index
= TOOLBAR_GetBitmapIndex(infoPtr
, btnPtr
)) < 0) {
482 if ((*index
== I_IMAGECALLBACK
) ||
483 (*index
== I_IMAGENONE
)) return NULL
;
484 ERR("TBN_GETDISPINFO returned invalid index %d\n",
491 case IMAGE_LIST_DEFAULT
:
492 himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
495 himl
= GETHOTIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
497 case IMAGE_LIST_DISABLED
:
498 himl
= GETDISIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
502 FIXME("Shouldn't reach here\n");
506 TRACE("no image list\n");
513 TOOLBAR_DrawFlatSeparator (const RECT
*lpRect
, HDC hdc
, const TOOLBAR_INFO
*infoPtr
)
516 COLORREF oldcolor
, newcolor
;
518 myrect
.left
= (lpRect
->left
+ lpRect
->right
) / 2 - 1;
519 myrect
.right
= myrect
.left
+ 1;
520 myrect
.top
= lpRect
->top
+ 2;
521 myrect
.bottom
= lpRect
->bottom
- 2;
523 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
524 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
525 oldcolor
= SetBkColor (hdc
, newcolor
);
526 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
528 myrect
.left
= myrect
.right
;
529 myrect
.right
= myrect
.left
+ 1;
531 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
532 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
533 SetBkColor (hdc
, newcolor
);
534 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
536 SetBkColor (hdc
, oldcolor
);
540 /***********************************************************************
541 * TOOLBAR_DrawFlatHorizontalSeparator
543 * This function draws horizontal separator for toolbars having CCS_VERT style.
544 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
545 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
546 * are horizontal as opposed to the vertical separators for not dropdown
549 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
552 TOOLBAR_DrawFlatHorizontalSeparator (const RECT
*lpRect
, HDC hdc
,
553 const TOOLBAR_INFO
*infoPtr
)
556 COLORREF oldcolor
, newcolor
;
558 myrect
.left
= lpRect
->left
;
559 myrect
.right
= lpRect
->right
;
560 myrect
.top
= lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
- 2)/2;
561 myrect
.bottom
= myrect
.top
+ 1;
563 InflateRect (&myrect
, -2, 0);
565 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect
));
567 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
568 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
569 oldcolor
= SetBkColor (hdc
, newcolor
);
570 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
572 myrect
.top
= myrect
.bottom
;
573 myrect
.bottom
= myrect
.top
+ 1;
575 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
576 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
577 SetBkColor (hdc
, newcolor
);
578 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
580 SetBkColor (hdc
, oldcolor
);
585 TOOLBAR_DrawArrow (HDC hdc
, INT left
, INT top
, COLORREF clr
)
590 if (!(hPen
= CreatePen( PS_SOLID
, 1, clr
))) return;
591 hOldPen
= SelectObject ( hdc
, hPen
);
594 MoveToEx (hdc
, x
, y
, NULL
);
595 LineTo (hdc
, x
+5, y
++); x
++;
596 MoveToEx (hdc
, x
, y
, NULL
);
597 LineTo (hdc
, x
+3, y
++); x
++;
598 MoveToEx (hdc
, x
, y
, NULL
);
599 LineTo (hdc
, x
+1, y
);
600 SelectObject( hdc
, hOldPen
);
601 DeleteObject( hPen
);
605 * Draw the text string for this button.
606 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
607 * is non-zero, so we can simply check himlDef to see if we have
611 TOOLBAR_DrawString (const TOOLBAR_INFO
*infoPtr
, RECT
*rcText
, LPCWSTR lpText
,
612 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
614 HDC hdc
= tbcd
->nmcd
.hdc
;
617 COLORREF clrOldBk
= 0;
619 UINT state
= tbcd
->nmcd
.uItemState
;
622 if (lpText
&& infoPtr
->nMaxTextRows
> 0) {
623 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText
),
624 wine_dbgstr_rect(rcText
));
626 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
627 if ((state
& CDIS_HOT
) && (dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)) {
628 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
630 else if (state
& CDIS_DISABLED
) {
631 clrOld
= SetTextColor (hdc
, tbcd
->clrBtnHighlight
);
632 OffsetRect (rcText
, 1, 1);
633 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
634 SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
635 OffsetRect (rcText
, -1, -1);
637 else if (state
& CDIS_INDETERMINATE
) {
638 clrOld
= SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
640 else if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
)) {
641 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
642 clrOldBk
= SetBkColor (hdc
, tbcd
->clrMark
);
643 oldBkMode
= SetBkMode (hdc
, tbcd
->nHLStringBkMode
);
646 clrOld
= SetTextColor (hdc
, tbcd
->clrText
);
649 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
650 SetTextColor (hdc
, clrOld
);
651 if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
))
653 SetBkColor (hdc
, clrOldBk
);
654 SetBkMode (hdc
, oldBkMode
);
656 SelectObject (hdc
, hOldFont
);
662 TOOLBAR_DrawPattern (const RECT
*lpRect
, const NMTBCUSTOMDRAW
*tbcd
)
664 HDC hdc
= tbcd
->nmcd
.hdc
;
665 HBRUSH hbr
= SelectObject (hdc
, tbcd
->hbrMonoDither
);
668 INT cx
= lpRect
->right
- lpRect
->left
;
669 INT cy
= lpRect
->bottom
- lpRect
->top
;
670 INT cxEdge
= GetSystemMetrics(SM_CXEDGE
);
671 INT cyEdge
= GetSystemMetrics(SM_CYEDGE
);
672 clrTextOld
= SetTextColor(hdc
, tbcd
->clrBtnHighlight
);
673 clrBkOld
= SetBkColor(hdc
, tbcd
->clrBtnFace
);
674 PatBlt (hdc
, lpRect
->left
+ cxEdge
, lpRect
->top
+ cyEdge
,
675 cx
- (2 * cxEdge
), cy
- (2 * cyEdge
), PATCOPY
);
676 SetBkColor(hdc
, clrBkOld
);
677 SetTextColor(hdc
, clrTextOld
);
678 SelectObject (hdc
, hbr
);
682 static void TOOLBAR_DrawMasked(HIMAGELIST himl
, int index
, HDC hdc
, INT x
, INT y
, UINT draw_flags
)
685 HBITMAP hbmMask
, hbmImage
;
686 HDC hdcMask
, hdcImage
;
688 ImageList_GetIconSize(himl
, &cx
, &cy
);
690 /* Create src image */
691 hdcImage
= CreateCompatibleDC(hdc
);
692 hbmImage
= CreateCompatibleBitmap(hdc
, cx
, cy
);
693 SelectObject(hdcImage
, hbmImage
);
694 ImageList_DrawEx(himl
, index
, hdcImage
, 0, 0, cx
, cy
,
695 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags
);
698 hdcMask
= CreateCompatibleDC(0);
699 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
700 SelectObject(hdcMask
, hbmMask
);
702 /* Remove the background and all white pixels */
703 ImageList_DrawEx(himl
, index
, hdcMask
, 0, 0, cx
, cy
,
704 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK
);
705 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
706 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
708 /* draw the new mask 'etched' to hdc */
709 SetBkColor(hdc
, RGB(255, 255, 255));
710 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
711 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
712 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
713 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
714 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
717 DeleteObject(hbmImage
);
719 DeleteObject (hbmMask
);
725 TOOLBAR_TranslateState(const TBUTTON_INFO
*btnPtr
)
729 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
730 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
731 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
732 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
733 retstate
|= (btnPtr
->bHot
) ? CDIS_HOT
: 0;
734 retstate
|= ((btnPtr
->fsState
& (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) == (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) ? CDIS_INDETERMINATE
: 0;
735 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
739 /* draws the image on a toolbar button */
741 TOOLBAR_DrawImage(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
,
742 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
744 HIMAGELIST himl
= NULL
;
745 BOOL draw_masked
= FALSE
, draw_desaturated
= FALSE
;
748 UINT draw_flags
= ILD_TRANSPARENT
;
750 IMAGEINFO info
= {0};
754 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
756 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
759 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
762 ImageList_GetImageInfo(himl
, index
, &info
);
763 GetObjectW(info
.hbmImage
, sizeof(bm
), &bm
);
765 if (bm
.bmBitsPixel
== 32)
767 draw_desaturated
= TRUE
;
778 else if (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
||
779 ((tbcd
->nmcd
.uItemState
& CDIS_HOT
)
780 && ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))))
782 /* if hot, attempt to draw with hot image list, if fails,
783 use default image list */
784 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
786 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
789 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
794 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
795 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
798 if (!(dwItemCDFlag
& TBCDRF_NOMARK
) &&
799 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
800 draw_flags
|= ILD_BLEND50
;
802 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
803 index
, himl
, left
, top
, offset
);
807 /* code path for drawing flat disabled icons without alpha channel */
808 TOOLBAR_DrawMasked (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
810 else if (draw_desaturated
)
812 /* code path for drawing disabled, alpha-blended (32bpp) icons */
813 IMAGELISTDRAWPARAMS imldp
= {0};
815 imldp
.cbSize
= sizeof(imldp
);
818 imldp
.hdcDst
= tbcd
->nmcd
.hdc
,
819 imldp
.x
= offset
+ left
;
820 imldp
.y
= offset
+ top
;
821 imldp
.rgbBk
= CLR_NONE
;
822 imldp
.rgbFg
= CLR_DEFAULT
;
823 imldp
.fStyle
= ILD_TRANSPARENT
;
824 imldp
.fState
= ILS_ALPHA
| ILS_SATURATE
;
827 ImageList_DrawIndirect (&imldp
);
831 /* code path for drawing standard icons as-is */
832 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
836 /* draws a blank frame for a toolbar button */
838 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, const RECT
*rect
, DWORD dwItemCDFlag
)
840 HDC hdc
= tbcd
->nmcd
.hdc
;
842 /* if the state is disabled or indeterminate then the button
843 * cannot have an interactive look like pressed or hot */
844 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
845 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
846 BOOL pressed_look
= !non_interactive_state
&&
847 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
848 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
850 /* app don't want us to draw any edges */
851 if (dwItemCDFlag
& TBCDRF_NOEDGES
)
854 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
857 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
858 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
859 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
864 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
866 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
867 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
872 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
, BOOL bDropDownPressed
, DWORD dwItemCDFlag
)
874 HDC hdc
= tbcd
->nmcd
.hdc
;
876 BOOL pressed
= bDropDownPressed
||
877 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
));
879 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
882 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
);
883 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
884 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
885 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
886 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
891 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
893 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
894 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
898 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
900 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
902 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
903 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
906 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
909 /* draws a complete toolbar button */
911 TOOLBAR_DrawButton (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, HDC hdc
, DWORD dwBaseCustDraw
)
913 DWORD dwStyle
= infoPtr
->dwStyle
;
914 BOOL hasDropDownArrow
= button_has_ddarrow( infoPtr
, btnPtr
);
915 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
916 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
917 RECT rc
, rcArrow
, rcBitmap
, rcText
;
918 LPWSTR lpText
= NULL
;
923 DWORD dwItemCustDraw
;
925 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
928 CopyRect (&rcArrow
, &rc
);
930 /* separator - doesn't send NM_CUSTOMDRAW */
931 if (btnPtr
->fsStyle
& BTNS_SEP
) {
934 DrawThemeBackground (theme
, hdc
,
935 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
939 /* with the FLAT style, iBitmap is the width and has already */
940 /* been taken into consideration in calculating the width */
941 /* so now we need to draw the vertical separator */
942 /* empirical tests show that iBitmap can/will be non-zero */
943 /* when drawing the vertical bar... */
944 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
945 if (dwStyle
& CCS_VERT
) {
947 InflateRect(&rcsep
, -infoPtr
->szPadding
.cx
, -infoPtr
->szPadding
.cy
);
948 TOOLBAR_DrawFlatHorizontalSeparator (&rcsep
, hdc
, infoPtr
);
951 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
954 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
955 FIXME("Draw some kind of separator: fsStyle=%x\n",
961 /* get a pointer to the text */
962 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
964 if (hasDropDownArrow
)
968 if (dwStyle
& TBSTYLE_FLAT
)
969 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
971 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
973 if (drawSepDropDownArrow
)
976 rcArrow
.left
= right
;
979 /* copy text & bitmap rects after adjusting for drop-down arrow
980 * so that text & bitmap is centered in the rectangle not containing
982 CopyRect(&rcText
, &rc
);
983 CopyRect(&rcBitmap
, &rc
);
985 /* Center the bitmap horizontally and vertically */
986 if (dwStyle
& TBSTYLE_LIST
)
989 infoPtr
->nMaxTextRows
> 0 &&
990 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
991 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
992 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
994 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
997 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
999 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
1001 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
1002 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
1003 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
1004 TRACE("Text=%s\n", debugstr_w(lpText
));
1005 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
1007 /* calculate text position */
1010 rcText
.left
+= GetSystemMetrics(SM_CXEDGE
);
1011 rcText
.right
-= GetSystemMetrics(SM_CXEDGE
);
1012 if (dwStyle
& TBSTYLE_LIST
)
1014 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
1018 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
1019 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
1021 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
1025 /* Initialize fields in all cases, because we use these later
1026 * NOTE: applications can and do alter these to customize their
1028 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1029 tbcd
.clrText
= comctl32_color
.clrBtnText
;
1030 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
1031 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
1032 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
1033 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
1034 tbcd
.clrHighlightHotTrack
= 0;
1035 tbcd
.nStringBkMode
= TRANSPARENT
;
1036 tbcd
.nHLStringBkMode
= OPAQUE
;
1037 tbcd
.rcText
.left
= 0;
1038 tbcd
.rcText
.top
= 0;
1039 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
1040 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
1041 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
1042 tbcd
.nmcd
.hdc
= hdc
;
1043 tbcd
.nmcd
.rc
= btnPtr
->rect
;
1044 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
1046 /* FIXME: what are these used for? */
1050 /* Issue Item Prepaint notify */
1053 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
1055 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
1056 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
1057 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
1058 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1059 /* reset these fields so the user can't alter the behaviour like native */
1060 tbcd
.nmcd
.hdc
= hdc
;
1061 tbcd
.nmcd
.rc
= btnPtr
->rect
;
1063 dwItemCustDraw
= ntfret
& 0xffff;
1064 dwItemCDFlag
= ntfret
& 0xffff0000;
1065 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
1067 /* save the only part of the rect that the user can change */
1068 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
1069 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
1072 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
1073 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
1074 OffsetRect(&rcText
, 1, 1);
1076 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
1077 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
1078 TOOLBAR_DrawPattern (&rc
, &tbcd
);
1080 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
1081 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
1083 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
1087 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
1088 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
1089 if (hasDropDownArrow
)
1090 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
1091 SetBkColor(hdc
, oldclr
);
1096 if (theme
&& !(dwItemCDFlag
& TBCDRF_NOBACKGROUND
))
1101 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
1102 int stateId
= TS_NORMAL
;
1104 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1105 stateId
= TS_DISABLED
;
1106 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1107 stateId
= TS_PRESSED
;
1108 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1109 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1110 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1111 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1114 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &rc
, NULL
);
1122 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, &rc
, dwItemCDFlag
);
1124 if (drawSepDropDownArrow
)
1128 int stateId
= TS_NORMAL
;
1130 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1131 stateId
= TS_DISABLED
;
1132 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1133 stateId
= TS_PRESSED
;
1134 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1135 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1136 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1139 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1140 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1143 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1146 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1147 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1148 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1149 SetBkMode (hdc
, oldBkMode
);
1151 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1153 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1155 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1157 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1158 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1160 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1162 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1163 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1166 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1169 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1171 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1172 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1179 TOOLBAR_Refresh (TOOLBAR_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
1181 TBUTTON_INFO
*btnPtr
;
1183 RECT rcTemp
, rcClient
;
1184 NMTBCUSTOMDRAW tbcd
;
1186 DWORD dwBaseCustDraw
;
1188 /* the app has told us not to redraw the toolbar */
1189 if (!infoPtr
->bDoRedraw
)
1192 /* if imagelist belongs to the app, it can be changed
1193 by the app after setting it */
1194 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1196 infoPtr
->nNumBitmaps
= 0;
1197 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1198 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1201 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1203 /* change the imagelist icon size if we manage the list and it is necessary */
1204 TOOLBAR_CheckImageListIconSize(infoPtr
);
1206 /* Send initial notify */
1207 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1208 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1209 tbcd
.nmcd
.hdc
= hdc
;
1210 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1211 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1212 dwBaseCustDraw
= ntfret
& 0xffff;
1214 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1216 /* redraw necessary buttons */
1217 btnPtr
= infoPtr
->buttons
;
1218 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1221 if (!RectVisible(hdc
, &btnPtr
->rect
))
1223 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1225 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1226 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1230 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1231 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1233 TOOLBAR_DrawButton(infoPtr
, btnPtr
, hdc
, dwBaseCustDraw
);
1236 /* draw insert mark if required */
1237 if (infoPtr
->tbim
.iButton
!= -1)
1239 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1241 rcInsertMark
.top
= rcButton
.top
;
1242 rcInsertMark
.bottom
= rcButton
.bottom
;
1243 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1244 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1246 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1247 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1250 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1252 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1253 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1254 tbcd
.nmcd
.hdc
= hdc
;
1255 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1256 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1260 /***********************************************************************
1261 * TOOLBAR_MeasureString
1263 * This function gets the width and height of a string in pixels. This
1264 * is done first by using GetTextExtentPoint to get the basic width
1265 * and height. The DrawText is called with DT_CALCRECT to get the exact
1266 * width. The reason is because the text may have more than one "&" (or
1267 * prefix characters as M$ likes to call them). The prefix character
1268 * indicates where the underline goes, except for the string "&&" which
1269 * is reduced to a single "&". GetTextExtentPoint does not process these
1270 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1273 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1274 HDC hdc
, LPSIZE lpSize
)
1281 if (infoPtr
->nMaxTextRows
> 0 &&
1282 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1283 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1284 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1286 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1288 if(lpText
!= NULL
) {
1289 /* first get size of all the text */
1290 GetTextExtentPoint32W (hdc
, lpText
, strlenW (lpText
), lpSize
);
1292 /* feed above size into the rectangle for DrawText */
1293 myrect
.left
= myrect
.top
= 0;
1294 myrect
.right
= lpSize
->cx
;
1295 myrect
.bottom
= lpSize
->cy
;
1297 /* Use DrawText to get true size as drawn (less pesky "&") */
1298 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1299 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1302 /* feed back to caller */
1303 lpSize
->cx
= myrect
.right
;
1304 lpSize
->cy
= myrect
.bottom
;
1308 TRACE("string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1311 /***********************************************************************
1312 * TOOLBAR_CalcStrings
1314 * This function walks through each string and measures it and returns
1315 * the largest height and width to caller.
1318 TOOLBAR_CalcStrings (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
1320 TBUTTON_INFO
*btnPtr
;
1329 if (infoPtr
->nMaxTextRows
== 0)
1332 hdc
= GetDC (infoPtr
->hwndSelf
);
1333 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1335 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1339 GetTextMetricsW(hdc
, &tm
);
1340 lpSize
->cy
= tm
.tmHeight
;
1343 btnPtr
= infoPtr
->buttons
;
1344 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1345 if(TOOLBAR_GetText(infoPtr
, btnPtr
))
1347 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1348 if (sz
.cx
> lpSize
->cx
)
1350 if (sz
.cy
> lpSize
->cy
)
1355 SelectObject (hdc
, hOldFont
);
1356 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1358 TRACE("max string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1361 /***********************************************************************
1362 * TOOLBAR_WrapToolbar
1364 * This function walks through the buttons and separators in the
1365 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1366 * wrapping should occur based on the width of the toolbar window.
1367 * It does *not* calculate button placement itself. That task
1368 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1369 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1370 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1372 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_VERTICAL can be used also to allow
1373 * vertical toolbar lists.
1377 TOOLBAR_WrapToolbar(TOOLBAR_INFO
*infoPtr
)
1379 TBUTTON_INFO
*btnPtr
;
1380 INT x
, cx
, i
, j
, width
;
1383 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1384 /* no layout is necessary. Applications may use this style */
1385 /* to perform their own layout on the toolbar. */
1386 if( !(infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) &&
1387 !(infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
) ) return;
1389 btnPtr
= infoPtr
->buttons
;
1390 x
= infoPtr
->nIndent
;
1391 width
= infoPtr
->client_rect
.right
- infoPtr
->client_rect
.left
;
1393 bButtonWrap
= FALSE
;
1395 TRACE("start ButtonWidth=%d, BitmapWidth=%d, width=%d, nIndent=%d\n",
1396 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, width
,
1399 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1401 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1403 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1406 if (btnPtr
[i
].cx
> 0)
1408 /* horizontal separators are treated as buttons for width */
1409 else if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1410 !(infoPtr
->dwStyle
& CCS_VERT
))
1411 cx
= (btnPtr
[i
].iBitmap
> 0) ? btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1413 cx
= infoPtr
->nButtonWidth
;
1415 if (!btnPtr
[i
].cx
&& button_has_ddarrow( infoPtr
, btnPtr
+ i
))
1416 cx
+= DDARROW_WIDTH
;
1418 /* Two or more adjacent separators form a separator group. */
1419 /* The first separator in a group should be wrapped to the */
1420 /* next row if the previous wrapping is on a button. */
1422 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1423 (i
+ 1 < infoPtr
->nNumButtons
) &&
1424 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1426 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1427 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1428 x
= infoPtr
->nIndent
;
1430 bButtonWrap
= FALSE
;
1434 /* The layout makes sure the bitmap is visible, but not the button. */
1435 /* Test added to also wrap after a button that starts a row but */
1436 /* is bigger than the area. - GA 8/01 */
1437 if ((x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2 > width
) ||
1438 ((x
== infoPtr
->nIndent
) && (cx
> width
)))
1440 BOOL bFound
= FALSE
;
1442 /* If the current button is a separator and not hidden, */
1443 /* go to the next until it reaches a non separator. */
1444 /* Wrap the last separator if it is before a button. */
1445 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1446 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1447 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1448 i
< infoPtr
->nNumButtons
)
1454 if( bFound
&& i
< infoPtr
->nNumButtons
)
1457 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1458 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1459 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1460 x
= infoPtr
->nIndent
;
1461 bButtonWrap
= FALSE
;
1464 else if ( i
>= infoPtr
->nNumButtons
)
1467 /* If the current button is not a separator, find the last */
1468 /* separator and wrap it. */
1469 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1471 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1472 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1476 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1477 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1478 x
= infoPtr
->nIndent
;
1479 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1480 bButtonWrap
= FALSE
;
1485 /* If no separator available for wrapping, wrap one of */
1486 /* non-hidden previous button. */
1490 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1492 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1497 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1498 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1499 x
= infoPtr
->nIndent
;
1500 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1506 /* If all above failed, wrap the current button. */
1509 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1510 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1511 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1512 x
= infoPtr
->nIndent
;
1513 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1514 bButtonWrap
= FALSE
;
1520 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1521 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1528 /***********************************************************************
1529 * TOOLBAR_MeasureButton
1531 * Calculates the width and height required for a button. Used in
1532 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1533 * the width of buttons that are autosized.
1535 * Note that it would have been rather elegant to use one piece of code for
1536 * both the laying out of the toolbar and for controlling where button parts
1537 * are drawn, but the native control has inconsistencies between the two that
1538 * prevent this from being effectively. These inconsistencies can be seen as
1539 * artefacts where parts of the button appear outside of the bounding button
1542 * There are several cases for the calculation of the button dimensions and
1543 * button part positioning:
1550 * +--------------------------------------------------------+ ^
1552 * | | pad.cy / 2 | centered | |
1553 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1554 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1555 * | |<------------>| | | | |
1556 * | +--------------+ +------------+ | |
1557 * |<-------------------------------------->| | |
1558 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1560 * +--------------------------------------------------------+ -
1561 * <-------------------------------------------------------->
1562 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1564 * Without Bitmap (I_IMAGENONE):
1566 * +-----------------------------------+ ^
1568 * | | centered | | LISTPAD_CY +
1569 * | +------------+ | | szText.cy
1572 * | +------------+ | |
1573 * |<----------------->| | |
1574 * | cxedge |<-----------> | |
1576 * +-----------------------------------+ -
1577 * <----------------------------------->
1578 * szText.cx + pad.cx
1582 * +--------------------------------------+ ^
1584 * | | padding.cy/2 | | DEFPAD_CY +
1585 * | +------------+ | | nBitmapHeight
1588 * | +------------+ | |
1589 * |<------------------->| | |
1590 * | cxedge + iListGap/2 |<-----------> | |
1591 * | nBitmapWidth | |
1592 * +--------------------------------------+ -
1593 * <-------------------------------------->
1594 * 2*cxedge + nBitmapWidth + iListGap
1601 * +-----------------------------------+ ^
1603 * | | pad.cy / 2 | | nBitmapHeight +
1604 * | - | | szText.cy +
1605 * | +------------+ | | DEFPAD_CY + 1
1606 * | centered | Bitmap | | |
1607 * |<----------------->| | | |
1608 * | +------------+ | |
1612 * | centered +---------------+ | |
1613 * |<--------------->| Text | | |
1614 * | +---------------+ | |
1615 * +-----------------------------------+ -
1616 * <----------------------------------->
1617 * pad.cx + max(nBitmapWidth, szText.cx)
1619 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1621 * +---------------------------------------+ ^
1623 * | | 2 + pad.cy / 2 | |
1624 * | - | | szText.cy +
1625 * | centered +-----------------+ | | pad.cy + 2
1626 * |<--------------->| Text | | |
1627 * | +-----------------+ | |
1629 * +---------------------------------------+ -
1630 * <--------------------------------------->
1631 * 2*cxedge + pad.cx + szText.cx
1634 * As for with bitmaps, but with szText.cx zero.
1636 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1637 BOOL bHasBitmap
, BOOL bValidImageList
)
1640 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1642 /* set button height from bitmap / text height... */
1643 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1646 /* ... add on the necessary padding */
1647 if (bValidImageList
)
1650 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1654 sizeButton
.cy
+= DEFPAD_CY
;
1657 sizeButton
.cy
+= LISTPAD_CY
;
1660 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1662 /* calculate button width */
1663 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1664 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1665 if (sizeString
.cx
> 0)
1666 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1674 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ infoPtr
->szPadding
.cy
;
1676 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1678 if (sizeString
.cy
> 0)
1679 sizeButton
.cy
+= 1 + sizeString
.cy
;
1680 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1681 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1685 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1686 NONLIST_NOTEXT_OFFSET
;
1687 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1688 max(2*GetSystemMetrics(SM_CXEDGE
) + sizeString
.cx
, infoPtr
->nBitmapWidth
);
1695 /***********************************************************************
1696 * TOOLBAR_CalcToolbar
1698 * This function calculates button and separator placement. It first
1699 * calculates the button sizes, gets the toolbar window width and then
1700 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1701 * on. It assigns a new location to each item and sends this location to
1702 * the tooltip window if appropriate. Finally, it updates the rcBound
1703 * rect and calculates the new required toolbar window height.
1706 TOOLBAR_CalcToolbar (TOOLBAR_INFO
*infoPtr
)
1708 SIZE sizeString
, sizeButton
;
1709 BOOL validImageList
= FALSE
;
1711 TOOLBAR_CalcStrings (infoPtr
, &sizeString
);
1713 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1715 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1716 validImageList
= TRUE
;
1717 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1718 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1719 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1720 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1722 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1723 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1724 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1725 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1727 TOOLBAR_LayoutToolbar(infoPtr
);
1731 TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
)
1733 TBUTTON_INFO
*btnPtr
;
1735 INT i
, nRows
, nSepRows
;
1738 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1740 TOOLBAR_WrapToolbar(infoPtr
);
1742 x
= infoPtr
->nIndent
;
1743 y
= infoPtr
->iTopMargin
;
1744 cx
= infoPtr
->nButtonWidth
;
1745 cy
= infoPtr
->nButtonHeight
;
1747 nRows
= nSepRows
= 0;
1749 infoPtr
->rcBound
.top
= y
;
1750 infoPtr
->rcBound
.left
= x
;
1751 infoPtr
->rcBound
.bottom
= y
+ cy
;
1752 infoPtr
->rcBound
.right
= x
;
1754 btnPtr
= infoPtr
->buttons
;
1756 TRACE("cy=%d\n", cy
);
1758 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1761 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1763 SetRectEmpty (&btnPtr
->rect
);
1767 cy
= infoPtr
->nButtonHeight
;
1769 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1770 if (infoPtr
->dwStyle
& CCS_VERT
) {
1771 cy
= (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1772 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
: infoPtr
->nButtonWidth
;
1775 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
:
1776 (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1783 /* Revert Wine Commit 5b7b911 as it breaks Explorer Toolbar Buttons
1784 FIXME: Revisit this when the bug is fixed. CORE-9970 */
1785 else if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1786 (btnPtr
->fsStyle
& BTNS_AUTOSIZE
))
1788 else if (btnPtr
->fsStyle
& BTNS_AUTOSIZE
)
1795 hdc
= GetDC (infoPtr
->hwndSelf
);
1796 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1798 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1800 SelectObject (hdc
, hOldFont
);
1801 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1803 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1804 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1809 cx
= infoPtr
->nButtonWidth
;
1811 /* if size has been set manually then don't add on extra space
1812 * for the drop down arrow */
1813 if (!btnPtr
->cx
&& button_has_ddarrow( infoPtr
, btnPtr
))
1814 cx
+= DDARROW_WIDTH
;
1816 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1819 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1821 if (infoPtr
->rcBound
.left
> x
)
1822 infoPtr
->rcBound
.left
= x
;
1823 if (infoPtr
->rcBound
.right
< x
+ cx
)
1824 infoPtr
->rcBound
.right
= x
+ cx
;
1825 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1826 infoPtr
->rcBound
.bottom
= y
+ cy
;
1828 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1830 /* btnPtr->nRow is zero based. The space between the rows is */
1831 /* also considered as a row. */
1832 btnPtr
->nRow
= nRows
+ nSepRows
;
1834 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1835 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1840 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1844 if ( !(infoPtr
->dwStyle
& CCS_VERT
))
1845 y
+= cy
+ ( (btnPtr
->cx
> 0 ) ?
1846 btnPtr
->cx
: SEPARATOR_WIDTH
) * 2 /3;
1850 /* nSepRows is used to calculate the extra height following */
1854 x
= infoPtr
->nIndent
;
1856 /* Increment row number unless this is the last button */
1857 /* and it has Wrap set. */
1858 if (i
!= infoPtr
->nNumButtons
-1)
1865 /* infoPtr->nRows is the number of rows on the toolbar */
1866 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1868 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1873 TOOLBAR_InternalHitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
*lpPt
, BOOL
*button
)
1875 TBUTTON_INFO
*btnPtr
;
1881 btnPtr
= infoPtr
->buttons
;
1882 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1883 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1886 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1887 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1888 TRACE(" ON SEPARATOR %d!\n", i
);
1893 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1894 TRACE(" ON BUTTON %d!\n", i
);
1902 TRACE(" NOWHERE!\n");
1903 return TOOLBAR_NOWHERE
;
1907 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1909 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO
*infoPtr
, INT iIndex
, UINT nAddButtons
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
1911 INT nOldButtons
, nNewButtons
, iButton
;
1912 BOOL fHasString
= FALSE
;
1914 if (iIndex
< 0) /* iIndex can be negative, what means adding at the end */
1915 iIndex
= infoPtr
->nNumButtons
;
1917 nOldButtons
= infoPtr
->nNumButtons
;
1918 nNewButtons
= nOldButtons
+ nAddButtons
;
1920 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
1921 memmove(&infoPtr
->buttons
[iIndex
+ nAddButtons
], &infoPtr
->buttons
[iIndex
],
1922 (nOldButtons
- iIndex
) * sizeof(TBUTTON_INFO
));
1923 infoPtr
->nNumButtons
+= nAddButtons
;
1925 /* insert new buttons data */
1926 for (iButton
= 0; iButton
< nAddButtons
; iButton
++) {
1927 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[iIndex
+ iButton
];
1930 TOOLBAR_DumpTBButton(lpTbb
+ iButton
, fUnicode
);
1932 ZeroMemory(btnPtr
, sizeof(*btnPtr
));
1934 btnPtr
->iBitmap
= lpTbb
[iButton
].iBitmap
;
1935 btnPtr
->idCommand
= lpTbb
[iButton
].idCommand
;
1936 btnPtr
->fsState
= lpTbb
[iButton
].fsState
;
1937 btnPtr
->fsStyle
= lpTbb
[iButton
].fsStyle
;
1938 btnPtr
->dwData
= lpTbb
[iButton
].dwData
;
1940 if (btnPtr
->fsStyle
& BTNS_SEP
)
1943 str
= lpTbb
[iButton
].iString
;
1944 set_string_index( btnPtr
, str
, fUnicode
);
1945 fHasString
|= TOOLBAR_ButtonHasString( btnPtr
);
1947 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
1950 if (infoPtr
->nNumStrings
> 0 || fHasString
)
1951 TOOLBAR_CalcToolbar(infoPtr
);
1953 TOOLBAR_LayoutToolbar(infoPtr
);
1954 TOOLBAR_AutoSize(infoPtr
);
1956 TOOLBAR_DumpToolbar(infoPtr
, __LINE__
);
1957 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1963 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1965 TBUTTON_INFO
*btnPtr
;
1968 if (CommandIsIndex
) {
1969 TRACE("command is really index command=%d\n", idCommand
);
1970 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1973 btnPtr
= infoPtr
->buttons
;
1974 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1975 if (btnPtr
->idCommand
== idCommand
) {
1976 TRACE("command=%d index=%d\n", idCommand
, i
);
1980 TRACE("no index found for command=%d\n", idCommand
);
1986 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1988 TBUTTON_INFO
*btnPtr
;
1991 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1994 /* check index button */
1995 btnPtr
= &infoPtr
->buttons
[nIndex
];
1996 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1997 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
2001 /* check previous buttons */
2002 nRunIndex
= nIndex
- 1;
2003 while (nRunIndex
>= 0) {
2004 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
2005 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
2006 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
2014 /* check next buttons */
2015 nRunIndex
= nIndex
+ 1;
2016 while (nRunIndex
< infoPtr
->nNumButtons
) {
2017 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
2018 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
2019 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
2032 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
2033 WPARAM wParam
, LPARAM lParam
)
2039 msg
.wParam
= wParam
;
2040 msg
.lParam
= lParam
;
2041 msg
.time
= GetMessageTime ();
2042 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
2043 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
2045 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
2050 TOOLBAR_ThemeChanged(HWND hwnd
)
2052 HTHEME theme
= GetWindowTheme(hwnd
);
2053 CloseThemeData(theme
);
2054 OpenThemeData(hwnd
, themeClass
);
2060 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2062 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
2065 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
2066 ti
.cbSize
= sizeof (TTTOOLINFOW
);
2067 ti
.hwnd
= infoPtr
->hwndSelf
;
2068 ti
.uId
= button
->idCommand
;
2070 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
2071 /* ti.lParam = random value from the stack? */
2073 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
2079 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2081 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
2084 ZeroMemory(&ti
, sizeof(ti
));
2085 ti
.cbSize
= sizeof(ti
);
2086 ti
.hwnd
= infoPtr
->hwndSelf
;
2087 ti
.uId
= button
->idCommand
;
2089 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
2093 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2095 /* Set the toolTip only for non-hidden, non-separator button */
2096 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
2100 ZeroMemory(&ti
, sizeof(ti
));
2101 ti
.cbSize
= sizeof(ti
);
2102 ti
.hwnd
= infoPtr
->hwndSelf
;
2103 ti
.uId
= button
->idCommand
;
2104 ti
.rect
= button
->rect
;
2105 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
2109 /* Creates the tooltip control */
2111 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
2114 NMTOOLTIPSCREATED nmttc
;
2116 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
2117 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2118 infoPtr
->hwndSelf
, 0, 0, 0);
2120 if (!infoPtr
->hwndToolTip
)
2123 /* Send NM_TOOLTIPSCREATED notification */
2124 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
2125 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
2127 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
2129 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
2130 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
2134 /* keeps available button list box sorted by button id */
2135 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
2139 PCUSTOMBUTTON btnInfo
;
2140 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2142 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
2144 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2146 /* position 0 is always separator */
2147 for (i
= 1; i
< count
; i
++)
2149 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2150 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2152 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2153 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2157 /* id higher than all others add to end */
2158 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2159 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2162 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2166 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2168 if (nIndexFrom
== nIndexTo
)
2171 /* MSDN states that iItem is the index of the button, rather than the
2172 * command ID as used by every other NMTOOLBAR notification */
2173 nmtb
.iItem
= nIndexFrom
;
2174 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2176 PCUSTOMBUTTON btnInfo
;
2178 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2179 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2181 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2183 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2184 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2185 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2186 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2189 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2191 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2193 /* last item is always separator, so -2 instead of -1 */
2194 if (nIndexTo
>= (count
- 2))
2195 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2197 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2199 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2200 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2202 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2206 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2210 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2212 /* MSDN states that iItem is the index of the button, rather than the
2213 * command ID as used by every other NMTOOLBAR notification */
2214 nmtb
.iItem
= nIndexAvail
;
2215 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2217 PCUSTOMBUTTON btnInfo
;
2219 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2220 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2221 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2223 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2225 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2227 /* remove from 'available buttons' list */
2228 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2229 if (nIndexAvail
== count
-1)
2230 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2232 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2236 PCUSTOMBUTTON btnNew
;
2238 /* duplicate 'separator' button */
2239 btnNew
= Alloc(sizeof(CUSTOMBUTTON
));
2244 /* insert into 'toolbar button' list */
2245 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2246 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2248 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2250 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2254 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2256 PCUSTOMBUTTON btnInfo
;
2257 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2259 TRACE("Remove: index %d\n", index
);
2261 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2263 /* send TBN_QUERYDELETE notification */
2264 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2268 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2269 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2271 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2273 /* insert into 'available button' list */
2274 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2275 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2279 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2283 /* drag list notification function for toolbar buttons list box */
2284 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2285 const DRAGLISTINFO
*pDLI
)
2287 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2288 switch (pDLI
->uNotification
)
2292 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2293 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2294 /* no dragging for last item (separator) */
2295 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2300 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2301 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2302 /* no dragging past last item (separator) */
2303 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2305 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2306 /* FIXME: native uses "move button" cursor */
2307 return DL_COPYCURSOR
;
2310 /* not over toolbar buttons list */
2311 if (nCurrentItem
< 0)
2313 POINT ptWindow
= pDLI
->ptCursor
;
2314 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2315 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2316 /* over available buttons list? */
2317 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2318 /* FIXME: native uses "move button" cursor */
2319 return DL_COPYCURSOR
;
2321 /* clear drag arrow */
2322 DrawInsert(hwnd
, hwndList
, -1);
2323 return DL_STOPCURSOR
;
2327 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2328 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2329 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2330 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2332 /* clear drag arrow */
2333 DrawInsert(hwnd
, hwndList
, -1);
2335 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2337 /* not over toolbar buttons list */
2340 POINT ptWindow
= pDLI
->ptCursor
;
2341 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2342 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2343 /* over available buttons list? */
2344 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2345 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2350 /* Clear drag arrow */
2351 DrawInsert(hwnd
, hwndList
, -1);
2358 /* drag list notification function for available buttons list box */
2359 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2360 const DRAGLISTINFO
*pDLI
)
2362 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2363 switch (pDLI
->uNotification
)
2369 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2370 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2371 /* no dragging past last item (separator) */
2372 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2374 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2375 /* FIXME: native uses "move button" cursor */
2376 return DL_COPYCURSOR
;
2379 /* not over toolbar buttons list */
2380 if (nCurrentItem
< 0)
2382 POINT ptWindow
= pDLI
->ptCursor
;
2383 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2384 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2385 /* over available buttons list? */
2386 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2387 /* FIXME: native uses "move button" cursor */
2388 return DL_COPYCURSOR
;
2390 /* clear drag arrow */
2391 DrawInsert(hwnd
, hwndList
, -1);
2392 return DL_STOPCURSOR
;
2396 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2397 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2398 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2399 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2401 /* clear drag arrow */
2402 DrawInsert(hwnd
, hwndList
, -1);
2404 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2408 /* Clear drag arrow */
2409 DrawInsert(hwnd
, hwndList
, -1);
2415 extern UINT uDragListMessage DECLSPEC_HIDDEN
;
2417 /***********************************************************************
2418 * TOOLBAR_CustomizeDialogProc
2419 * This function implements the toolbar customization dialog.
2421 static INT_PTR CALLBACK
2422 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2424 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2425 PCUSTOMBUTTON btnInfo
;
2427 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2432 custInfo
= (PCUSTDLG_INFO
)lParam
;
2433 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2440 NMTBINITCUSTOMIZE nmtbic
;
2442 infoPtr
= custInfo
->tbInfo
;
2444 /* send TBN_QUERYINSERT notification */
2445 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2447 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2450 nmtbic
.hwndDialog
= hwnd
;
2451 /* Send TBN_INITCUSTOMIZE notification */
2452 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2455 TRACE("TBNRF_HIDEHELP requested\n");
2456 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2459 /* add items to 'toolbar buttons' list and check if removable */
2460 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2462 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2463 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2464 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2465 btnInfo
->bVirtual
= FALSE
;
2466 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2468 /* send TBN_QUERYDELETE notification */
2469 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2471 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2472 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2475 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2477 /* insert separator button into 'available buttons' list */
2478 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2479 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2480 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2481 btnInfo
->bVirtual
= FALSE
;
2482 btnInfo
->bRemovable
= TRUE
;
2483 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2484 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2485 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2487 /* insert all buttons into dsa */
2490 /* send TBN_GETBUTTONINFO notification */
2493 nmtb
.pszText
= Buffer
;
2496 /* Clear previous button's text */
2497 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2499 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2502 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2503 nmtb
.tbButton
.fsStyle
, i
,
2504 nmtb
.tbButton
.idCommand
,
2505 nmtb
.tbButton
.iString
,
2506 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2509 /* insert button into the appropriate list */
2510 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2513 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2514 btnInfo
->bVirtual
= FALSE
;
2515 btnInfo
->bRemovable
= TRUE
;
2519 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2520 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2523 btnInfo
->btn
= nmtb
.tbButton
;
2524 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2526 if (lstrlenW(nmtb
.pszText
))
2527 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2528 else if (nmtb
.tbButton
.iString
>= 0 &&
2529 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2531 lstrcpyW(btnInfo
->text
,
2532 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2537 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2540 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2542 /* select first item in the 'available' list */
2543 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2545 /* append 'virtual' separator button to the 'toolbar buttons' list */
2546 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2547 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2548 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2549 btnInfo
->bVirtual
= TRUE
;
2550 btnInfo
->bRemovable
= FALSE
;
2551 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2552 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2553 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2555 /* select last item in the 'toolbar' list */
2556 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2557 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2559 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2560 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2562 /* set focus and disable buttons */
2563 PostMessageW (hwnd
, WM_USER
, 0, 0);
2568 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2569 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2570 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2571 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2575 EndDialog(hwnd
, FALSE
);
2579 switch (LOWORD(wParam
))
2581 case IDC_TOOLBARBTN_LBOX
:
2582 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2584 PCUSTOMBUTTON btnInfo
;
2589 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2590 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2592 /* send TBN_QUERYINSERT notification */
2594 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2596 /* get list box item */
2597 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2599 if (index
== (count
- 1))
2601 /* last item (virtual separator) */
2602 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2603 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2605 else if (index
== (count
- 2))
2607 /* second last item (last non-virtual item) */
2608 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2609 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2611 else if (index
== 0)
2614 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2615 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2619 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2620 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2623 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2627 case IDC_MOVEUP_BTN
:
2629 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2630 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2634 case IDC_MOVEDN_BTN
: /* move down */
2636 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2637 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2641 case IDC_REMOVE_BTN
: /* remove button */
2643 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2645 if (LB_ERR
== index
)
2648 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2652 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2655 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2658 case IDOK
: /* Add button */
2663 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2664 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2666 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2671 EndDialog(hwnd
, FALSE
);
2681 /* delete items from 'toolbar buttons' listbox*/
2682 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2683 for (i
= 0; i
< count
; i
++)
2685 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2687 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2689 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2692 /* delete items from 'available buttons' listbox*/
2693 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2694 for (i
= 0; i
< count
; i
++)
2696 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2698 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2700 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2705 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2707 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2712 COLORREF oldText
= 0;
2716 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, lpdis
->itemID
, 0);
2717 if (btnInfo
== NULL
)
2719 FIXME("btnInfo invalid!\n");
2723 /* set colors and select objects */
2724 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2725 if (btnInfo
->bVirtual
)
2726 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2728 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2729 hPen
= CreatePen( PS_SOLID
, 1,
2730 (lpdis
->itemState
& ODS_SELECTED
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2731 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2732 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2734 /* fill background rectangle */
2735 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2736 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2738 /* calculate button and text rectangles */
2739 CopyRect (&rcButton
, &lpdis
->rcItem
);
2740 InflateRect (&rcButton
, -1, -1);
2741 CopyRect (&rcText
, &rcButton
);
2742 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2743 rcText
.left
= rcButton
.right
+ 2;
2745 /* draw focus rectangle */
2746 if (lpdis
->itemState
& ODS_FOCUS
)
2747 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2750 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2751 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2753 /* draw image and text */
2754 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2755 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2756 btnInfo
->btn
.iBitmap
));
2757 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2758 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2760 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2761 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2763 /* delete objects and reset colors */
2764 SelectObject (lpdis
->hDC
, hOldBrush
);
2765 SelectObject (lpdis
->hDC
, hOldPen
);
2766 SetBkColor (lpdis
->hDC
, oldBk
);
2767 SetTextColor (lpdis
->hDC
, oldText
);
2768 DeleteObject( hPen
);
2773 case WM_MEASUREITEM
:
2774 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2776 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2778 lpmis
->itemHeight
= 15 + 8; /* default height */
2785 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2787 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2789 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2790 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2791 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2794 else if (wParam
== IDC_AVAILBTN_LBOX
)
2796 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2797 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2798 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2807 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2810 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2816 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2817 /* Add bitmaps to the default image list */
2818 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2819 hbmLoad
= CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2820 else if (bitmap
->hInst
== COMCTL32_hModule
)
2821 hbmLoad
= LoadImageW( bitmap
->hInst
, MAKEINTRESOURCEW(bitmap
->nID
),
2822 IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
2824 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2826 /* enlarge the bitmap if needed */
2827 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2828 if (bitmap
->hInst
!= COMCTL32_hModule
)
2829 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2831 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2832 DeleteObject(hbmLoad
);
2836 nCountAfter
= ImageList_GetImageCount(himlDef
);
2837 nAdded
= nCountAfter
- nCountBefore
;
2838 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2840 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2841 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2842 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2843 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2846 infoPtr
->nNumBitmaps
+= nAdded
;
2851 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2858 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2859 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2861 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2863 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2866 TRACE("Update icon size: %dx%d -> %dx%d\n",
2867 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2869 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2870 ILC_COLOR32
|ILC_MASK
, 8, 2);
2871 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2872 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2873 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2874 infoPtr
->himlInt
= himlNew
;
2876 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2877 ImageList_Destroy(himlDef
);
2880 /***********************************************************************
2881 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2885 TOOLBAR_AddBitmap (TOOLBAR_INFO
*infoPtr
, INT count
, const TBADDBITMAP
*lpAddBmp
)
2891 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr
->hwndSelf
, count
, lpAddBmp
);
2895 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2897 info
.hInst
= COMCTL32_hModule
;
2898 switch (lpAddBmp
->nID
)
2900 case IDB_STD_SMALL_COLOR
:
2902 info
.nID
= IDB_STD_SMALL
;
2904 case IDB_STD_LARGE_COLOR
:
2906 info
.nID
= IDB_STD_LARGE
;
2908 case IDB_VIEW_SMALL_COLOR
:
2910 info
.nID
= IDB_VIEW_SMALL
;
2912 case IDB_VIEW_LARGE_COLOR
:
2914 info
.nID
= IDB_VIEW_LARGE
;
2916 case IDB_HIST_SMALL_COLOR
:
2918 info
.nID
= IDB_HIST_SMALL
;
2920 case IDB_HIST_LARGE_COLOR
:
2922 info
.nID
= IDB_HIST_LARGE
;
2928 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2930 /* Windows resize all the buttons to the size of a newly added standard image */
2931 if (lpAddBmp
->nID
& 1)
2933 /* large icons: 24x24. Will make the button 31x30 */
2934 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2938 /* small icons: 16x16. Will make the buttons 23x22 */
2939 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2942 TOOLBAR_CalcToolbar (infoPtr
);
2946 info
.nButtons
= count
;
2947 info
.hInst
= lpAddBmp
->hInst
;
2948 info
.nID
= lpAddBmp
->nID
;
2949 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2952 /* check if the bitmap is already loaded and compute iSumButtons */
2954 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2956 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2957 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2959 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2962 if (!infoPtr
->cimlDef
) {
2963 /* create new default image list */
2964 TRACE ("creating default image list!\n");
2966 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2967 ILC_COLOR32
| ILC_MASK
, info
.nButtons
, 2);
2968 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2969 infoPtr
->himlInt
= himlDef
;
2972 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2976 WARN("No default image list available\n");
2980 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2983 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2984 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2985 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2986 infoPtr
->nNumBitmapInfos
++;
2987 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2989 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2995 TOOLBAR_AddButtonsT(TOOLBAR_INFO
*infoPtr
, INT nAddButtons
, const TBBUTTON
* lpTbb
, BOOL fUnicode
)
2997 TRACE("adding %d buttons (unicode=%d)!\n", nAddButtons
, fUnicode
);
2999 return TOOLBAR_InternalInsertButtonsT(infoPtr
, -1, nAddButtons
, lpTbb
, fUnicode
);
3004 TOOLBAR_AddStringW (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
3006 #define MAX_RESOURCE_STRING_LENGTH 512
3007 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
3008 INT nIndex
= infoPtr
->nNumStrings
;
3010 TRACE("%p, %lx\n", hInstance
, lParam
);
3012 if (IS_INTRESOURCE(lParam
)) {
3013 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
3020 TRACE("adding string from resource\n");
3022 if (!hInstance
) return -1;
3024 hrsrc
= FindResourceW( hInstance
, MAKEINTRESOURCEW((LOWORD(lParam
) >> 4) + 1),
3025 (LPWSTR
)RT_STRING
);
3028 TRACE("string not found in resources\n");
3032 len
= LoadStringW (hInstance
, (UINT
)lParam
,
3033 szString
, MAX_RESOURCE_STRING_LENGTH
);
3035 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
3036 if (len
== 0 || len
== 1)
3039 TRACE("delimiter: 0x%x\n", *szString
);
3040 delimiter
= *szString
;