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
;
621 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
625 if (lpText
&& infoPtr
->nMaxTextRows
> 0) {
626 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText
),
627 wine_dbgstr_rect(rcText
));
629 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
630 if ((state
& CDIS_HOT
) && (dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)) {
631 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
633 else if (state
& CDIS_DISABLED
) {
634 clrOld
= SetTextColor (hdc
, tbcd
->clrBtnHighlight
);
635 OffsetRect (rcText
, 1, 1);
636 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
637 SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
638 OffsetRect (rcText
, -1, -1);
640 else if (state
& CDIS_INDETERMINATE
) {
641 clrOld
= SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
643 else if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
)) {
644 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
645 clrOldBk
= SetBkColor (hdc
, tbcd
->clrMark
);
646 oldBkMode
= SetBkMode (hdc
, tbcd
->nHLStringBkMode
);
649 clrOld
= SetTextColor (hdc
, tbcd
->clrText
);
655 int partId
= TP_BUTTON
;
656 int stateId
= TS_NORMAL
;
658 if (state
& CDIS_DISABLED
)
659 stateId
= TS_DISABLED
;
660 else if (state
& CDIS_SELECTED
)
661 stateId
= TS_PRESSED
;
662 else if (state
& CDIS_CHECKED
)
663 stateId
= (state
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
664 else if (state
& CDIS_HOT
)
667 DrawThemeText(theme
, hdc
, partId
, stateId
, lpText
, -1, infoPtr
->dwDTFlags
, 0, rcText
);
671 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
672 SetTextColor (hdc
, clrOld
);
673 if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
))
675 SetBkColor (hdc
, clrOldBk
);
676 SetBkMode (hdc
, oldBkMode
);
678 SelectObject (hdc
, hOldFont
);
684 TOOLBAR_DrawPattern (const RECT
*lpRect
, const NMTBCUSTOMDRAW
*tbcd
)
686 HDC hdc
= tbcd
->nmcd
.hdc
;
687 HBRUSH hbr
= SelectObject (hdc
, tbcd
->hbrMonoDither
);
690 INT cx
= lpRect
->right
- lpRect
->left
;
691 INT cy
= lpRect
->bottom
- lpRect
->top
;
692 INT cxEdge
= GetSystemMetrics(SM_CXEDGE
);
693 INT cyEdge
= GetSystemMetrics(SM_CYEDGE
);
694 clrTextOld
= SetTextColor(hdc
, tbcd
->clrBtnHighlight
);
695 clrBkOld
= SetBkColor(hdc
, tbcd
->clrBtnFace
);
696 PatBlt (hdc
, lpRect
->left
+ cxEdge
, lpRect
->top
+ cyEdge
,
697 cx
- (2 * cxEdge
), cy
- (2 * cyEdge
), PATCOPY
);
698 SetBkColor(hdc
, clrBkOld
);
699 SetTextColor(hdc
, clrTextOld
);
700 SelectObject (hdc
, hbr
);
704 static void TOOLBAR_DrawMasked(HIMAGELIST himl
, int index
, HDC hdc
, INT x
, INT y
, UINT draw_flags
)
707 HBITMAP hbmMask
, hbmImage
;
708 HDC hdcMask
, hdcImage
;
710 ImageList_GetIconSize(himl
, &cx
, &cy
);
712 /* Create src image */
713 hdcImage
= CreateCompatibleDC(hdc
);
714 hbmImage
= CreateCompatibleBitmap(hdc
, cx
, cy
);
715 SelectObject(hdcImage
, hbmImage
);
716 ImageList_DrawEx(himl
, index
, hdcImage
, 0, 0, cx
, cy
,
717 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags
);
720 hdcMask
= CreateCompatibleDC(0);
721 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
722 SelectObject(hdcMask
, hbmMask
);
724 /* Remove the background and all white pixels */
725 ImageList_DrawEx(himl
, index
, hdcMask
, 0, 0, cx
, cy
,
726 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK
);
727 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
728 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
730 /* draw the new mask 'etched' to hdc */
731 SetBkColor(hdc
, RGB(255, 255, 255));
732 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
733 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
734 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
735 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
736 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
739 DeleteObject(hbmImage
);
741 DeleteObject (hbmMask
);
747 TOOLBAR_TranslateState(const TBUTTON_INFO
*btnPtr
)
751 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
752 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
753 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
754 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
755 retstate
|= (btnPtr
->bHot
) ? CDIS_HOT
: 0;
756 retstate
|= ((btnPtr
->fsState
& (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) == (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) ? CDIS_INDETERMINATE
: 0;
757 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
761 /* draws the image on a toolbar button */
763 TOOLBAR_DrawImage(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
,
764 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
766 HIMAGELIST himl
= NULL
;
767 BOOL draw_masked
= FALSE
, draw_desaturated
= FALSE
;
770 UINT draw_flags
= ILD_TRANSPARENT
;
772 IMAGEINFO info
= {0};
776 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
778 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
781 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
784 ImageList_GetImageInfo(himl
, index
, &info
);
785 GetObjectW(info
.hbmImage
, sizeof(bm
), &bm
);
787 if (bm
.bmBitsPixel
== 32)
789 draw_desaturated
= TRUE
;
800 else if (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
||
801 ((tbcd
->nmcd
.uItemState
& CDIS_HOT
)
802 && ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))))
804 /* if hot, attempt to draw with hot image list, if fails,
805 use default image list */
806 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
808 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
811 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
816 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
817 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
820 if (!(dwItemCDFlag
& TBCDRF_NOMARK
) &&
821 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
822 draw_flags
|= ILD_BLEND50
;
824 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
825 index
, himl
, left
, top
, offset
);
829 /* code path for drawing flat disabled icons without alpha channel */
830 TOOLBAR_DrawMasked (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
832 else if (draw_desaturated
)
834 /* code path for drawing disabled, alpha-blended (32bpp) icons */
835 IMAGELISTDRAWPARAMS imldp
= {0};
837 imldp
.cbSize
= sizeof(imldp
);
840 imldp
.hdcDst
= tbcd
->nmcd
.hdc
,
841 imldp
.x
= offset
+ left
;
842 imldp
.y
= offset
+ top
;
843 imldp
.rgbBk
= CLR_NONE
;
844 imldp
.rgbFg
= CLR_DEFAULT
;
845 imldp
.fStyle
= ILD_TRANSPARENT
;
846 imldp
.fState
= ILS_ALPHA
| ILS_SATURATE
;
849 ImageList_DrawIndirect (&imldp
);
853 /* code path for drawing standard icons as-is */
854 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
858 /* draws a blank frame for a toolbar button */
860 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, const RECT
*rect
, DWORD dwItemCDFlag
)
862 HDC hdc
= tbcd
->nmcd
.hdc
;
864 /* if the state is disabled or indeterminate then the button
865 * cannot have an interactive look like pressed or hot */
866 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
867 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
868 BOOL pressed_look
= !non_interactive_state
&&
869 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
870 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
872 /* app don't want us to draw any edges */
873 if (dwItemCDFlag
& TBCDRF_NOEDGES
)
876 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
879 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
880 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
881 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
886 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
888 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
889 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
894 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
, BOOL bDropDownPressed
, DWORD dwItemCDFlag
)
896 HDC hdc
= tbcd
->nmcd
.hdc
;
898 BOOL pressed
= bDropDownPressed
||
899 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
));
901 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
904 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
);
905 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
906 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
907 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
908 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
913 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
915 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
916 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
920 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
922 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
924 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
925 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
928 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
931 /* draws a complete toolbar button */
933 TOOLBAR_DrawButton (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, HDC hdc
, DWORD dwBaseCustDraw
)
935 DWORD dwStyle
= infoPtr
->dwStyle
;
936 BOOL hasDropDownArrow
= button_has_ddarrow( infoPtr
, btnPtr
);
937 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
938 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
939 RECT rc
, rcArrow
, rcBitmap
, rcText
;
940 LPWSTR lpText
= NULL
;
945 DWORD dwItemCustDraw
;
947 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
952 /* separator - doesn't send NM_CUSTOMDRAW */
953 if (btnPtr
->fsStyle
& BTNS_SEP
) {
956 DrawThemeBackground (theme
, hdc
,
957 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
961 /* with the FLAT style, iBitmap is the width and has already */
962 /* been taken into consideration in calculating the width */
963 /* so now we need to draw the vertical separator */
964 /* empirical tests show that iBitmap can/will be non-zero */
965 /* when drawing the vertical bar... */
966 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
967 if (dwStyle
& CCS_VERT
) {
969 InflateRect(&rcsep
, -infoPtr
->szPadding
.cx
, -infoPtr
->szPadding
.cy
);
970 TOOLBAR_DrawFlatHorizontalSeparator (&rcsep
, hdc
, infoPtr
);
973 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
976 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
977 FIXME("Draw some kind of separator: fsStyle=%x\n",
983 /* get a pointer to the text */
984 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
986 if (hasDropDownArrow
)
990 if (dwStyle
& TBSTYLE_FLAT
)
991 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
993 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
995 if (drawSepDropDownArrow
)
998 rcArrow
.left
= right
;
1001 /* copy text & bitmap rects after adjusting for drop-down arrow
1002 * so that text & bitmap is centered in the rectangle not containing
1007 /* Center the bitmap horizontally and vertically */
1008 if (dwStyle
& TBSTYLE_LIST
)
1011 infoPtr
->nMaxTextRows
> 0 &&
1012 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1013 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1014 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
1016 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
1019 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
1021 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
1023 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
1024 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
1025 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
1026 TRACE("Text=%s\n", debugstr_w(lpText
));
1027 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
1029 /* calculate text position */
1032 InflateRect(&rcText
, -GetSystemMetrics(SM_CXEDGE
), 0);
1033 if (dwStyle
& TBSTYLE_LIST
)
1035 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
1039 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
1040 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
1042 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
1046 /* Initialize fields in all cases, because we use these later
1047 * NOTE: applications can and do alter these to customize their
1049 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1050 tbcd
.clrText
= comctl32_color
.clrBtnText
;
1051 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
1052 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
1053 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
1054 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
1055 tbcd
.clrHighlightHotTrack
= 0;
1056 tbcd
.nStringBkMode
= TRANSPARENT
;
1057 tbcd
.nHLStringBkMode
= OPAQUE
;
1058 tbcd
.rcText
.left
= 0;
1059 tbcd
.rcText
.top
= 0;
1060 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
1061 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
1062 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
1063 tbcd
.nmcd
.hdc
= hdc
;
1064 tbcd
.nmcd
.rc
= btnPtr
->rect
;
1065 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
1067 /* FIXME: what are these used for? */
1071 /* Issue Item Prepaint notify */
1074 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
1076 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
1077 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
1078 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
1079 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1080 /* reset these fields so the user can't alter the behaviour like native */
1081 tbcd
.nmcd
.hdc
= hdc
;
1082 tbcd
.nmcd
.rc
= btnPtr
->rect
;
1084 dwItemCustDraw
= ntfret
& 0xffff;
1085 dwItemCDFlag
= ntfret
& 0xffff0000;
1086 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
1088 /* save the only part of the rect that the user can change */
1089 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
1090 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
1093 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
1094 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
1095 OffsetRect(&rcText
, 1, 1);
1097 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
1098 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
1099 TOOLBAR_DrawPattern (&rc
, &tbcd
);
1101 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
1102 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
1104 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
1108 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
1109 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
1110 if (hasDropDownArrow
)
1111 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
1112 SetBkColor(hdc
, oldclr
);
1117 if (theme
&& !(dwItemCDFlag
& TBCDRF_NOBACKGROUND
))
1122 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
1123 int stateId
= TS_NORMAL
;
1125 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1126 stateId
= TS_DISABLED
;
1127 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1128 stateId
= TS_PRESSED
;
1129 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1130 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1131 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1132 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1135 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &rc
, NULL
);
1143 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, &rc
, dwItemCDFlag
);
1145 if (drawSepDropDownArrow
)
1149 int stateId
= TS_NORMAL
;
1151 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1152 stateId
= TS_DISABLED
;
1153 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1154 stateId
= TS_PRESSED
;
1155 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1156 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1157 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1160 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1161 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1164 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1167 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1168 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1169 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1170 SetBkMode (hdc
, oldBkMode
);
1172 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1174 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1176 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1178 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1179 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1181 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1183 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1184 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1187 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1190 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1192 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1193 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1200 TOOLBAR_Refresh (TOOLBAR_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
1202 TBUTTON_INFO
*btnPtr
;
1204 RECT rcTemp
, rcClient
;
1205 NMTBCUSTOMDRAW tbcd
;
1207 DWORD dwBaseCustDraw
;
1209 /* the app has told us not to redraw the toolbar */
1210 if (!infoPtr
->bDoRedraw
)
1213 /* if imagelist belongs to the app, it can be changed
1214 by the app after setting it */
1215 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1217 infoPtr
->nNumBitmaps
= 0;
1218 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1219 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1222 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1224 /* change the imagelist icon size if we manage the list and it is necessary */
1225 TOOLBAR_CheckImageListIconSize(infoPtr
);
1227 /* Send initial notify */
1228 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1229 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1230 tbcd
.nmcd
.hdc
= hdc
;
1231 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1232 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1233 dwBaseCustDraw
= ntfret
& 0xffff;
1235 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1237 /* redraw necessary buttons */
1238 btnPtr
= infoPtr
->buttons
;
1239 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1242 if (!RectVisible(hdc
, &btnPtr
->rect
))
1244 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1246 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1247 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1251 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1252 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1254 TOOLBAR_DrawButton(infoPtr
, btnPtr
, hdc
, dwBaseCustDraw
);
1257 /* draw insert mark if required */
1258 if (infoPtr
->tbim
.iButton
!= -1)
1260 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1262 rcInsertMark
.top
= rcButton
.top
;
1263 rcInsertMark
.bottom
= rcButton
.bottom
;
1264 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1265 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1267 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1268 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1271 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1273 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1274 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1275 tbcd
.nmcd
.hdc
= hdc
;
1276 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1277 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1281 /***********************************************************************
1282 * TOOLBAR_MeasureString
1284 * This function gets the width and height of a string in pixels. This
1285 * is done first by using GetTextExtentPoint to get the basic width
1286 * and height. The DrawText is called with DT_CALCRECT to get the exact
1287 * width. The reason is because the text may have more than one "&" (or
1288 * prefix characters as M$ likes to call them). The prefix character
1289 * indicates where the underline goes, except for the string "&&" which
1290 * is reduced to a single "&". GetTextExtentPoint does not process these
1291 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1294 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1295 HDC hdc
, LPSIZE lpSize
)
1302 if (infoPtr
->nMaxTextRows
> 0 &&
1303 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1304 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1305 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1307 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1309 if(lpText
!= NULL
) {
1310 /* first get size of all the text */
1311 GetTextExtentPoint32W (hdc
, lpText
, strlenW (lpText
), lpSize
);
1313 /* feed above size into the rectangle for DrawText */
1314 SetRect(&myrect
, 0, 0, lpSize
->cx
, lpSize
->cy
);
1316 /* Use DrawText to get true size as drawn (less pesky "&") */
1317 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1318 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1321 /* feed back to caller */
1322 lpSize
->cx
= myrect
.right
;
1323 lpSize
->cy
= myrect
.bottom
;
1327 TRACE("string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1330 /***********************************************************************
1331 * TOOLBAR_CalcStrings
1333 * This function walks through each string and measures it and returns
1334 * the largest height and width to caller.
1337 TOOLBAR_CalcStrings (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
1339 TBUTTON_INFO
*btnPtr
;
1348 if (infoPtr
->nMaxTextRows
== 0)
1351 hdc
= GetDC (infoPtr
->hwndSelf
);
1352 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1354 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1358 GetTextMetricsW(hdc
, &tm
);
1359 lpSize
->cy
= tm
.tmHeight
;
1362 btnPtr
= infoPtr
->buttons
;
1363 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1364 if(TOOLBAR_GetText(infoPtr
, btnPtr
))
1366 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1367 if (sz
.cx
> lpSize
->cx
)
1369 if (sz
.cy
> lpSize
->cy
)
1374 SelectObject (hdc
, hOldFont
);
1375 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1377 TRACE("max string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1380 /***********************************************************************
1381 * TOOLBAR_WrapToolbar
1383 * This function walks through the buttons and separators in the
1384 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1385 * wrapping should occur based on the width of the toolbar window.
1386 * It does *not* calculate button placement itself. That task
1387 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1388 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1389 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1391 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_VERTICAL can be used also to allow
1392 * vertical toolbar lists.
1396 TOOLBAR_WrapToolbar(TOOLBAR_INFO
*infoPtr
)
1398 TBUTTON_INFO
*btnPtr
;
1399 INT x
, cx
, i
, j
, width
;
1402 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1403 /* no layout is necessary. Applications may use this style */
1404 /* to perform their own layout on the toolbar. */
1405 if( !(infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) &&
1406 !(infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
) ) return;
1408 btnPtr
= infoPtr
->buttons
;
1409 x
= infoPtr
->nIndent
;
1410 width
= infoPtr
->client_rect
.right
- infoPtr
->client_rect
.left
;
1412 bButtonWrap
= FALSE
;
1414 TRACE("start ButtonWidth=%d, BitmapWidth=%d, width=%d, nIndent=%d\n",
1415 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, width
,
1418 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1420 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1422 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1425 if (btnPtr
[i
].cx
> 0)
1427 /* horizontal separators are treated as buttons for width */
1428 else if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1429 !(infoPtr
->dwStyle
& CCS_VERT
))
1430 cx
= (btnPtr
[i
].iBitmap
> 0) ? btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1432 cx
= infoPtr
->nButtonWidth
;
1434 if (!btnPtr
[i
].cx
&& button_has_ddarrow( infoPtr
, btnPtr
+ i
))
1435 cx
+= DDARROW_WIDTH
;
1437 /* Two or more adjacent separators form a separator group. */
1438 /* The first separator in a group should be wrapped to the */
1439 /* next row if the previous wrapping is on a button. */
1441 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1442 (i
+ 1 < infoPtr
->nNumButtons
) &&
1443 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1445 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1446 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1447 x
= infoPtr
->nIndent
;
1449 bButtonWrap
= FALSE
;
1453 /* The layout makes sure the bitmap is visible, but not the button. */
1454 /* Test added to also wrap after a button that starts a row but */
1455 /* is bigger than the area. - GA 8/01 */
1456 if ((x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2 > width
) ||
1457 ((x
== infoPtr
->nIndent
) && (cx
> width
)))
1459 BOOL bFound
= FALSE
;
1461 /* If the current button is a separator and not hidden, */
1462 /* go to the next until it reaches a non separator. */
1463 /* Wrap the last separator if it is before a button. */
1464 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1465 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1466 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1467 i
< infoPtr
->nNumButtons
)
1473 if( bFound
&& i
< infoPtr
->nNumButtons
)
1476 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1477 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1478 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1479 x
= infoPtr
->nIndent
;
1480 bButtonWrap
= FALSE
;
1483 else if ( i
>= infoPtr
->nNumButtons
)
1486 /* If the current button is not a separator, find the last */
1487 /* separator and wrap it. */
1488 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1490 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1491 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1495 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1496 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1497 x
= infoPtr
->nIndent
;
1498 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1499 bButtonWrap
= FALSE
;
1504 /* If no separator available for wrapping, wrap one of */
1505 /* non-hidden previous button. */
1509 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1511 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1516 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1517 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1518 x
= infoPtr
->nIndent
;
1519 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1525 /* If all above failed, wrap the current button. */
1528 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1529 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1530 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1531 x
= infoPtr
->nIndent
;
1532 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1533 bButtonWrap
= FALSE
;
1539 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1540 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1547 /***********************************************************************
1548 * TOOLBAR_MeasureButton
1550 * Calculates the width and height required for a button. Used in
1551 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1552 * the width of buttons that are autosized.
1554 * Note that it would have been rather elegant to use one piece of code for
1555 * both the laying out of the toolbar and for controlling where button parts
1556 * are drawn, but the native control has inconsistencies between the two that
1557 * prevent this from being effectively. These inconsistencies can be seen as
1558 * artefacts where parts of the button appear outside of the bounding button
1561 * There are several cases for the calculation of the button dimensions and
1562 * button part positioning:
1569 * +--------------------------------------------------------+ ^
1571 * | | pad.cy / 2 | centered | |
1572 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1573 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1574 * | |<------------>| | | | |
1575 * | +--------------+ +------------+ | |
1576 * |<-------------------------------------->| | |
1577 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1579 * +--------------------------------------------------------+ -
1580 * <-------------------------------------------------------->
1581 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1583 * Without Bitmap (I_IMAGENONE):
1585 * +-----------------------------------+ ^
1587 * | | centered | | LISTPAD_CY +
1588 * | +------------+ | | szText.cy
1591 * | +------------+ | |
1592 * |<----------------->| | |
1593 * | cxedge |<-----------> | |
1595 * +-----------------------------------+ -
1596 * <----------------------------------->
1597 * szText.cx + pad.cx
1601 * +--------------------------------------+ ^
1603 * | | padding.cy/2 | | DEFPAD_CY +
1604 * | +------------+ | | nBitmapHeight
1607 * | +------------+ | |
1608 * |<------------------->| | |
1609 * | cxedge + iListGap/2 |<-----------> | |
1610 * | nBitmapWidth | |
1611 * +--------------------------------------+ -
1612 * <-------------------------------------->
1613 * 2*cxedge + nBitmapWidth + iListGap
1620 * +-----------------------------------+ ^
1622 * | | pad.cy / 2 | | nBitmapHeight +
1623 * | - | | szText.cy +
1624 * | +------------+ | | DEFPAD_CY + 1
1625 * | centered | Bitmap | | |
1626 * |<----------------->| | | |
1627 * | +------------+ | |
1631 * | centered +---------------+ | |
1632 * |<--------------->| Text | | |
1633 * | +---------------+ | |
1634 * +-----------------------------------+ -
1635 * <----------------------------------->
1636 * pad.cx + max(nBitmapWidth, szText.cx)
1638 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1640 * +---------------------------------------+ ^
1642 * | | 2 + pad.cy / 2 | |
1643 * | - | | szText.cy +
1644 * | centered +-----------------+ | | pad.cy + 2
1645 * |<--------------->| Text | | |
1646 * | +-----------------+ | |
1648 * +---------------------------------------+ -
1649 * <--------------------------------------->
1650 * 2*cxedge + pad.cx + szText.cx
1653 * As for with bitmaps, but with szText.cx zero.
1655 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1656 BOOL bHasBitmap
, BOOL bValidImageList
)
1659 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1661 /* set button height from bitmap / text height... */
1662 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1665 /* ... add on the necessary padding */
1666 if (bValidImageList
)
1669 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1673 sizeButton
.cy
+= DEFPAD_CY
;
1676 sizeButton
.cy
+= LISTPAD_CY
;
1679 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1681 /* calculate button width */
1682 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1683 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1684 if (sizeString
.cx
> 0)
1685 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1693 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ infoPtr
->szPadding
.cy
;
1695 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1697 if (sizeString
.cy
> 0)
1698 sizeButton
.cy
+= 1 + sizeString
.cy
;
1699 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1700 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1704 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1705 NONLIST_NOTEXT_OFFSET
;
1706 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1707 max(2*GetSystemMetrics(SM_CXEDGE
) + sizeString
.cx
, infoPtr
->nBitmapWidth
);
1714 /***********************************************************************
1715 * TOOLBAR_CalcToolbar
1717 * This function calculates button and separator placement. It first
1718 * calculates the button sizes, gets the toolbar window width and then
1719 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1720 * on. It assigns a new location to each item and sends this location to
1721 * the tooltip window if appropriate. Finally, it updates the rcBound
1722 * rect and calculates the new required toolbar window height.
1725 TOOLBAR_CalcToolbar (TOOLBAR_INFO
*infoPtr
)
1727 SIZE sizeString
, sizeButton
;
1728 BOOL validImageList
= FALSE
;
1730 TOOLBAR_CalcStrings (infoPtr
, &sizeString
);
1732 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1734 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1735 validImageList
= TRUE
;
1736 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1737 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1738 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1739 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1741 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1742 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1743 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1744 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1746 TOOLBAR_LayoutToolbar(infoPtr
);
1750 TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
)
1752 TBUTTON_INFO
*btnPtr
;
1754 INT i
, nRows
, nSepRows
;
1757 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1759 TOOLBAR_WrapToolbar(infoPtr
);
1761 x
= infoPtr
->nIndent
;
1762 y
= infoPtr
->iTopMargin
;
1763 cx
= infoPtr
->nButtonWidth
;
1764 cy
= infoPtr
->nButtonHeight
;
1766 nRows
= nSepRows
= 0;
1768 infoPtr
->rcBound
.top
= y
;
1769 infoPtr
->rcBound
.left
= x
;
1770 infoPtr
->rcBound
.bottom
= y
+ cy
;
1771 infoPtr
->rcBound
.right
= x
;
1773 btnPtr
= infoPtr
->buttons
;
1775 TRACE("cy=%d\n", cy
);
1777 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1780 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1782 SetRectEmpty (&btnPtr
->rect
);
1783 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1787 cy
= infoPtr
->nButtonHeight
;
1789 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1790 if (infoPtr
->dwStyle
& CCS_VERT
) {
1791 cy
= (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1792 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
: infoPtr
->nButtonWidth
;
1795 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
:
1796 (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1803 /* Revert Wine Commit 5b7b911 as it breaks Explorer Toolbar Buttons
1804 FIXME: Revisit this when the bug is fixed. CORE-9970 */
1805 else if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1806 (btnPtr
->fsStyle
& BTNS_AUTOSIZE
))
1808 else if (btnPtr
->fsStyle
& BTNS_AUTOSIZE
)
1815 hdc
= GetDC (infoPtr
->hwndSelf
);
1816 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1818 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1820 SelectObject (hdc
, hOldFont
);
1821 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1823 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1824 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1829 cx
= infoPtr
->nButtonWidth
;
1831 /* if size has been set manually then don't add on extra space
1832 * for the drop down arrow */
1833 if (!btnPtr
->cx
&& button_has_ddarrow( infoPtr
, btnPtr
))
1834 cx
+= DDARROW_WIDTH
;
1836 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1839 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1841 if (infoPtr
->rcBound
.left
> x
)
1842 infoPtr
->rcBound
.left
= x
;
1843 if (infoPtr
->rcBound
.right
< x
+ cx
)
1844 infoPtr
->rcBound
.right
= x
+ cx
;
1845 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1846 infoPtr
->rcBound
.bottom
= y
+ cy
;
1848 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1850 /* btnPtr->nRow is zero based. The space between the rows is */
1851 /* also considered as a row. */
1852 btnPtr
->nRow
= nRows
+ nSepRows
;
1854 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1855 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1860 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1864 if ( !(infoPtr
->dwStyle
& CCS_VERT
))
1865 y
+= cy
+ ( (btnPtr
->cx
> 0 ) ?
1866 btnPtr
->cx
: SEPARATOR_WIDTH
) * 2 /3;
1870 /* nSepRows is used to calculate the extra height following */
1874 x
= infoPtr
->nIndent
;
1876 /* Increment row number unless this is the last button */
1877 /* and it has Wrap set. */
1878 if (i
!= infoPtr
->nNumButtons
-1)
1885 /* infoPtr->nRows is the number of rows on the toolbar */
1886 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1888 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1893 TOOLBAR_InternalHitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
*lpPt
, BOOL
*button
)
1895 TBUTTON_INFO
*btnPtr
;
1901 btnPtr
= infoPtr
->buttons
;
1902 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1903 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1906 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1907 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1908 TRACE(" ON SEPARATOR %d!\n", i
);
1913 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1914 TRACE(" ON BUTTON %d!\n", i
);
1922 TRACE(" NOWHERE!\n");
1923 return TOOLBAR_NOWHERE
;
1927 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1929 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO
*infoPtr
, INT iIndex
, UINT nAddButtons
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
1931 INT nOldButtons
, nNewButtons
, iButton
;
1932 BOOL fHasString
= FALSE
;
1934 if (iIndex
< 0) /* iIndex can be negative, what means adding at the end */
1935 iIndex
= infoPtr
->nNumButtons
;
1937 nOldButtons
= infoPtr
->nNumButtons
;
1938 nNewButtons
= nOldButtons
+ nAddButtons
;
1940 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
1941 memmove(&infoPtr
->buttons
[iIndex
+ nAddButtons
], &infoPtr
->buttons
[iIndex
],
1942 (nOldButtons
- iIndex
) * sizeof(TBUTTON_INFO
));
1943 infoPtr
->nNumButtons
+= nAddButtons
;
1945 /* insert new buttons data */
1946 for (iButton
= 0; iButton
< nAddButtons
; iButton
++) {
1947 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[iIndex
+ iButton
];
1950 TOOLBAR_DumpTBButton(lpTbb
+ iButton
, fUnicode
);
1952 ZeroMemory(btnPtr
, sizeof(*btnPtr
));
1954 btnPtr
->iBitmap
= lpTbb
[iButton
].iBitmap
;
1955 btnPtr
->idCommand
= lpTbb
[iButton
].idCommand
;
1956 btnPtr
->fsState
= lpTbb
[iButton
].fsState
;
1957 btnPtr
->fsStyle
= lpTbb
[iButton
].fsStyle
;
1958 btnPtr
->dwData
= lpTbb
[iButton
].dwData
;
1960 if (btnPtr
->fsStyle
& BTNS_SEP
)
1963 str
= lpTbb
[iButton
].iString
;
1964 set_string_index( btnPtr
, str
, fUnicode
);
1965 fHasString
|= TOOLBAR_ButtonHasString( btnPtr
);
1967 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
1970 if (infoPtr
->nNumStrings
> 0 || fHasString
)
1971 TOOLBAR_CalcToolbar(infoPtr
);
1973 TOOLBAR_LayoutToolbar(infoPtr
);
1974 TOOLBAR_AutoSize(infoPtr
);
1976 TOOLBAR_DumpToolbar(infoPtr
, __LINE__
);
1977 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1983 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1985 TBUTTON_INFO
*btnPtr
;
1988 if (CommandIsIndex
) {
1989 TRACE("command is really index command=%d\n", idCommand
);
1990 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1993 btnPtr
= infoPtr
->buttons
;
1994 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1995 if (btnPtr
->idCommand
== idCommand
) {
1996 TRACE("command=%d index=%d\n", idCommand
, i
);
2000 TRACE("no index found for command=%d\n", idCommand
);
2006 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
2008 TBUTTON_INFO
*btnPtr
;
2011 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
2014 /* check index button */
2015 btnPtr
= &infoPtr
->buttons
[nIndex
];
2016 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
2017 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
2021 /* check previous buttons */
2022 nRunIndex
= nIndex
- 1;
2023 while (nRunIndex
>= 0) {
2024 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
2025 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
2026 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
2034 /* check next buttons */
2035 nRunIndex
= nIndex
+ 1;
2036 while (nRunIndex
< infoPtr
->nNumButtons
) {
2037 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
2038 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
2039 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
2052 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
2053 WPARAM wParam
, LPARAM lParam
)
2059 msg
.wParam
= wParam
;
2060 msg
.lParam
= lParam
;
2061 msg
.time
= GetMessageTime ();
2062 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
2063 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
2065 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
2070 TOOLBAR_ThemeChanged(HWND hwnd
)
2072 HTHEME theme
= GetWindowTheme(hwnd
);
2073 CloseThemeData(theme
);
2074 OpenThemeData(hwnd
, themeClass
);
2080 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2082 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
2085 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
2086 ti
.cbSize
= sizeof (TTTOOLINFOW
);
2087 ti
.hwnd
= infoPtr
->hwndSelf
;
2088 ti
.uId
= button
->idCommand
;
2090 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
2091 /* ti.lParam = random value from the stack? */
2093 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
2099 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2101 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
2104 ZeroMemory(&ti
, sizeof(ti
));
2105 ti
.cbSize
= sizeof(ti
);
2106 ti
.hwnd
= infoPtr
->hwndSelf
;
2107 ti
.uId
= button
->idCommand
;
2109 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
2113 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2115 /* Set the toolTip only for non-hidden, non-separator button */
2116 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
2120 ZeroMemory(&ti
, sizeof(ti
));
2121 ti
.cbSize
= sizeof(ti
);
2122 ti
.hwnd
= infoPtr
->hwndSelf
;
2123 ti
.uId
= button
->idCommand
;
2124 ti
.rect
= button
->rect
;
2125 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
2129 /* Creates the tooltip control */
2131 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
2134 NMTOOLTIPSCREATED nmttc
;
2136 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
2137 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2138 infoPtr
->hwndSelf
, 0, 0, 0);
2140 if (!infoPtr
->hwndToolTip
)
2143 /* Send NM_TOOLTIPSCREATED notification */
2144 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
2145 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
2147 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
2149 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
2150 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
2154 /* keeps available button list box sorted by button id */
2155 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
2159 PCUSTOMBUTTON btnInfo
;
2160 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2162 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
2164 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2166 /* position 0 is always separator */
2167 for (i
= 1; i
< count
; i
++)
2169 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2170 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2172 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2173 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2177 /* id higher than all others add to end */
2178 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2179 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2182 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2186 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2188 if (nIndexFrom
== nIndexTo
)
2191 /* MSDN states that iItem is the index of the button, rather than the
2192 * command ID as used by every other NMTOOLBAR notification */
2193 nmtb
.iItem
= nIndexFrom
;
2194 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2196 PCUSTOMBUTTON btnInfo
;
2198 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2199 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2201 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2203 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2204 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2205 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2206 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2209 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2211 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2213 /* last item is always separator, so -2 instead of -1 */
2214 if (nIndexTo
>= (count
- 2))
2215 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2217 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2219 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2220 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2222 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2226 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2230 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2232 /* MSDN states that iItem is the index of the button, rather than the
2233 * command ID as used by every other NMTOOLBAR notification */
2234 nmtb
.iItem
= nIndexAvail
;
2235 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2237 PCUSTOMBUTTON btnInfo
;
2239 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2240 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2241 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2243 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2245 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2247 /* remove from 'available buttons' list */
2248 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2249 if (nIndexAvail
== count
-1)
2250 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2252 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2256 PCUSTOMBUTTON btnNew
;
2258 /* duplicate 'separator' button */
2259 btnNew
= Alloc(sizeof(CUSTOMBUTTON
));
2264 /* insert into 'toolbar button' list */
2265 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2266 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2268 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2270 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2274 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2276 PCUSTOMBUTTON btnInfo
;
2277 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2279 TRACE("Remove: index %d\n", index
);
2281 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2283 /* send TBN_QUERYDELETE notification */
2284 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2288 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2289 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2291 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2293 /* insert into 'available button' list */
2294 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2295 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2299 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2303 /* drag list notification function for toolbar buttons list box */
2304 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2305 const DRAGLISTINFO
*pDLI
)
2307 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2308 switch (pDLI
->uNotification
)
2312 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2313 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2314 /* no dragging for last item (separator) */
2315 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2320 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2321 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2322 /* no dragging past last item (separator) */
2323 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2325 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2326 /* FIXME: native uses "move button" cursor */
2327 return DL_COPYCURSOR
;
2330 /* not over toolbar buttons list */
2331 if (nCurrentItem
< 0)
2333 POINT ptWindow
= pDLI
->ptCursor
;
2334 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2335 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2336 /* over available buttons list? */
2337 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2338 /* FIXME: native uses "move button" cursor */
2339 return DL_COPYCURSOR
;
2341 /* clear drag arrow */
2342 DrawInsert(hwnd
, hwndList
, -1);
2343 return DL_STOPCURSOR
;
2347 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2348 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2349 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2350 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2352 /* clear drag arrow */
2353 DrawInsert(hwnd
, hwndList
, -1);
2355 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2357 /* not over toolbar buttons list */
2360 POINT ptWindow
= pDLI
->ptCursor
;
2361 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2362 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2363 /* over available buttons list? */
2364 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2365 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2370 /* Clear drag arrow */
2371 DrawInsert(hwnd
, hwndList
, -1);
2378 /* drag list notification function for available buttons list box */
2379 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2380 const DRAGLISTINFO
*pDLI
)
2382 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2383 switch (pDLI
->uNotification
)
2389 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2390 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2391 /* no dragging past last item (separator) */
2392 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2394 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2395 /* FIXME: native uses "move button" cursor */
2396 return DL_COPYCURSOR
;
2399 /* not over toolbar buttons list */
2400 if (nCurrentItem
< 0)
2402 POINT ptWindow
= pDLI
->ptCursor
;
2403 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2404 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2405 /* over available buttons list? */
2406 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2407 /* FIXME: native uses "move button" cursor */
2408 return DL_COPYCURSOR
;
2410 /* clear drag arrow */
2411 DrawInsert(hwnd
, hwndList
, -1);
2412 return DL_STOPCURSOR
;
2416 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2417 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2418 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2419 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2421 /* clear drag arrow */
2422 DrawInsert(hwnd
, hwndList
, -1);
2424 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2428 /* Clear drag arrow */
2429 DrawInsert(hwnd
, hwndList
, -1);
2435 extern UINT uDragListMessage DECLSPEC_HIDDEN
;
2437 /***********************************************************************
2438 * TOOLBAR_CustomizeDialogProc
2439 * This function implements the toolbar customization dialog.
2441 static INT_PTR CALLBACK
2442 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2444 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2445 PCUSTOMBUTTON btnInfo
;
2447 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2452 custInfo
= (PCUSTDLG_INFO
)lParam
;
2453 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2460 NMTBINITCUSTOMIZE nmtbic
;
2462 infoPtr
= custInfo
->tbInfo
;
2464 /* send TBN_QUERYINSERT notification */
2465 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2467 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2470 nmtbic
.hwndDialog
= hwnd
;
2471 /* Send TBN_INITCUSTOMIZE notification */
2472 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2475 TRACE("TBNRF_HIDEHELP requested\n");
2476 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2479 /* add items to 'toolbar buttons' list and check if removable */
2480 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2482 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2483 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2484 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2485 btnInfo
->bVirtual
= FALSE
;
2486 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2488 /* send TBN_QUERYDELETE notification */
2489 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2491 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2492 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2495 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2497 /* insert separator button into 'available buttons' list */
2498 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2499 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2500 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2501 btnInfo
->bVirtual
= FALSE
;
2502 btnInfo
->bRemovable
= TRUE
;
2503 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2504 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2505 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2507 /* insert all buttons into dsa */
2510 /* send TBN_GETBUTTONINFO notification */
2513 nmtb
.pszText
= Buffer
;
2516 /* Clear previous button's text */
2517 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2519 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2522 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2523 nmtb
.tbButton
.fsStyle
, i
,
2524 nmtb
.tbButton
.idCommand
,
2525 nmtb
.tbButton
.iString
,
2526 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2529 /* insert button into the appropriate list */
2530 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2533 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2534 btnInfo
->bVirtual
= FALSE
;
2535 btnInfo
->bRemovable
= TRUE
;
2539 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2540 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2543 btnInfo
->btn
= nmtb
.tbButton
;
2544 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2546 if (lstrlenW(nmtb
.pszText
))
2547 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2548 else if (nmtb
.tbButton
.iString
>= 0 &&
2549 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2551 lstrcpyW(btnInfo
->text
,
2552 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2557 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2560 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2562 /* select first item in the 'available' list */
2563 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2565 /* append 'virtual' separator button to the 'toolbar buttons' list */
2566 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2567 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2568 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2569 btnInfo
->bVirtual
= TRUE
;
2570 btnInfo
->bRemovable
= FALSE
;
2571 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2572 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2573 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2575 /* select last item in the 'toolbar' list */
2576 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2577 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2579 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2580 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2582 /* set focus and disable buttons */
2583 PostMessageW (hwnd
, WM_USER
, 0, 0);
2588 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2589 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2590 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2591 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2595 EndDialog(hwnd
, FALSE
);
2599 switch (LOWORD(wParam
))
2601 case IDC_TOOLBARBTN_LBOX
:
2602 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2604 PCUSTOMBUTTON btnInfo
;
2609 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2610 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2612 /* send TBN_QUERYINSERT notification */
2614 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2616 /* get list box item */
2617 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2619 if (index
== (count
- 1))
2621 /* last item (virtual separator) */
2622 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2623 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2625 else if (index
== (count
- 2))
2627 /* second last item (last non-virtual item) */
2628 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2629 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2631 else if (index
== 0)
2634 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2635 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2639 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2640 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2643 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2647 case IDC_MOVEUP_BTN
:
2649 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2650 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2654 case IDC_MOVEDN_BTN
: /* move down */
2656 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2657 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2661 case IDC_REMOVE_BTN
: /* remove button */
2663 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2665 if (LB_ERR
== index
)
2668 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2672 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2675 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2678 case IDOK
: /* Add button */
2683 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2684 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2686 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2691 EndDialog(hwnd
, FALSE
);
2701 /* delete items from 'toolbar buttons' listbox*/
2702 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2703 for (i
= 0; i
< count
; i
++)
2705 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2707 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2709 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2712 /* delete items from 'available buttons' listbox*/
2713 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2714 for (i
= 0; i
< count
; i
++)
2716 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2718 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2720 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2725 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2727 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2732 COLORREF oldText
= 0;
2736 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, lpdis
->itemID
, 0);
2737 if (btnInfo
== NULL
)
2739 FIXME("btnInfo invalid!\n");
2743 /* set colors and select objects */
2744 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2745 if (btnInfo
->bVirtual
)
2746 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2748 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2749 hPen
= CreatePen( PS_SOLID
, 1,
2750 (lpdis
->itemState
& ODS_SELECTED
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2751 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2752 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2754 /* fill background rectangle */
2755 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2756 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2758 /* calculate button and text rectangles */
2759 rcButton
= lpdis
->rcItem
;
2760 InflateRect (&rcButton
, -1, -1);
2762 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2763 rcText
.left
= rcButton
.right
+ 2;
2765 /* draw focus rectangle */
2766 if (lpdis
->itemState
& ODS_FOCUS
)
2767 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2770 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2771 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2773 /* draw image and text */
2774 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2775 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2776 btnInfo
->btn
.iBitmap
));
2777 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2778 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2780 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2781 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2783 /* delete objects and reset colors */
2784 SelectObject (lpdis
->hDC
, hOldBrush
);
2785 SelectObject (lpdis
->hDC
, hOldPen
);
2786 SetBkColor (lpdis
->hDC
, oldBk
);
2787 SetTextColor (lpdis
->hDC
, oldText
);
2788 DeleteObject( hPen
);
2793 case WM_MEASUREITEM
:
2794 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2796 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2798 lpmis
->itemHeight
= 15 + 8; /* default height */
2805 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2807 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2809 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2810 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2811 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2814 else if (wParam
== IDC_AVAILBTN_LBOX
)
2816 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2817 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2818 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2827 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2830 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2836 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2837 /* Add bitmaps to the default image list */
2838 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2839 hbmLoad
= CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2840 else if (bitmap
->hInst
== COMCTL32_hModule
)
2841 hbmLoad
= LoadImageW( bitmap
->hInst
, MAKEINTRESOURCEW(bitmap
->nID
),
2842 IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
2844 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2846 /* enlarge the bitmap if needed */
2847 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2848 if (bitmap
->hInst
!= COMCTL32_hModule
)
2849 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2851 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2852 DeleteObject(hbmLoad
);
2856 nCountAfter
= ImageList_GetImageCount(himlDef
);
2857 nAdded
= nCountAfter
- nCountBefore
;
2858 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2860 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2861 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2862 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2863 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2866 infoPtr
->nNumBitmaps
+= nAdded
;
2871 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2878 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2879 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2881 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2883 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2886 TRACE("Update icon size: %dx%d -> %dx%d\n",
2887 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2889 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2890 ILC_COLOR32
|ILC_MASK
, 8, 2);
2891 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2892 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2893 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2894 infoPtr
->himlInt
= himlNew
;
2896 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2897 ImageList_Destroy(himlDef
);
2900 /***********************************************************************
2901 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2905 TOOLBAR_AddBitmap (TOOLBAR_INFO
*infoPtr
, INT count
, const TBADDBITMAP
*lpAddBmp
)
2911 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr
->hwndSelf
, count
, lpAddBmp
);
2915 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2917 info
.hInst
= COMCTL32_hModule
;
2918 switch (lpAddBmp
->nID
)
2920 case IDB_STD_SMALL_COLOR
:
2922 info
.nID
= IDB_STD_SMALL
;
2924 case IDB_STD_LARGE_COLOR
:
2926 info
.nID
= IDB_STD_LARGE
;
2928 case IDB_VIEW_SMALL_COLOR
:
2930 info
.nID
= IDB_VIEW_SMALL
;
2932 case IDB_VIEW_LARGE_COLOR
:
2934 info
.nID
= IDB_VIEW_LARGE
;
2936 case IDB_HIST_SMALL_COLOR
:
2938 info
.nID
= IDB_HIST_SMALL
;
2940 case IDB_HIST_LARGE_COLOR
:
2942 info
.nID
= IDB_HIST_LARGE
;
2948 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2950 /* Windows resize all the buttons to the size of a newly added standard image */
2951 if (lpAddBmp
->nID
& 1)
2953 /* large icons: 24x24. Will make the button 31x30 */
2954 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2958 /* small icons: 16x16. Will make the buttons 23x22 */
2959 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2962 TOOLBAR_CalcToolbar (infoPtr
);
2966 info
.nButtons
= count
;
2967 info
.hInst
= lpAddBmp
->hInst
;
2968 info
.nID
= lpAddBmp
->nID
;
2969 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2972 /* check if the bitmap is already loaded and compute iSumButtons */
2974 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2976 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2977 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2979 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2982 if (!infoPtr
->cimlDef
) {
2983 /* create new default image list */
2984 TRACE ("creating default image list!\n");
2986 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2987 ILC_COLOR32
| ILC_MASK
, info
.nButtons
, 2);
2988 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2989 infoPtr
->himlInt
= himlDef
;
2992 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2996 WARN("No default image list available\n");
3000 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
3003 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
3004 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
3005 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
3006 infoPtr
->nNumBitmapInfos
++;
3007 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
3009 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
3015 TOOLBAR_AddButtonsT(TOOLBAR_INFO
*infoPtr
, INT nAddButtons
, const TBBUTTON
* lpTbb
, BOOL fUnicode
)
3017 TRACE("adding %d buttons (unicode=%d)!\n", nAddButtons
, fUnicode
);
3019 return TOOLBAR_InternalInsertButtonsT(infoPtr
, -1, nAddButtons
, lpTbb
, fUnicode
);
3024 TOOLBAR_AddStringW (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
3026 #define MAX_RESOURCE_STRING_LENGTH 512
3027 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
3028 INT nIndex
= infoPtr
->nNumStrings
;
3030 TRACE("%p, %lx\n", hInstance
, lParam
);
3032 if (IS_INTRESOURCE(lParam
)) {
3033 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
3040 TRACE("adding string from resource\n");
3042 if (!hInstance
) return -1;
3044 hrsrc
= FindResourceW( hInstance
, MAKEINTRESOURCEW((LOWORD(lParam
) >> 4) + 1),
3045 (LPWSTR
)RT_STRING
);
3048 TRACE("string not found in resources\n");
3052 len
= LoadStringW (hInstance
, (UINT
)lParam
,
3053 szString
, MAX_RESOURCE_STRING_LENGTH
);
3055 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
3056 if (len
== 0 || len
== 1)
3059 TRACE("delimiter: 0x%x\n", *szString
);
3060 delimiter
= *szString
;
3063 while ((next_delim
= strchrW(p
, delimiter
)) != NULL
) {
3065 if (next_delim
+ 1 >= szString
+ len
)
3067 /* this may happen if delimiter == '\0' or if the last char is a
3068 * delimiter (then it is ignored like the native does) */
3072 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3073 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3074 infoPtr
->nNumStrings
++;
3080 LPWSTR p
= (LPWSTR
)lParam
;
3085 TRACE("adding string(s) from array\n");
3089 TRACE("len=%d %s\n", len
, debugstr_w(p
));
3090 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3091 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3092 infoPtr
->nNumStrings
++;
3099 TOOLBAR_CalcToolbar(infoPtr
);
3105 TOOLBAR_AddStringA (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
3107 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
3112 TRACE("%p, %lx\n", hInstance
, lParam
);
3114 if (IS_INTRESOURCE(lParam
)) /* load from resources */
3115 return TOOLBAR_AddStringW(infoPtr
, hInstance
, lParam
);
3121 TRACE("adding string(s) from array\n");
3122 nIndex
= infoPtr
->nNumStrings
;
3125 TRACE("len=%d \"%s\"\n", len
, p
);
3127 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3128 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3129 infoPtr
->nNumStrings
++;
3135 TOOLBAR_CalcToolbar(infoPtr
);
3141 TOOLBAR_AutoSize (TOOLBAR_INFO
*infoPtr
)
3143 TRACE("auto sizing, style=%x!\n", infoPtr
->dwStyle
);
3144 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3146 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3148 RECT window_rect
, parent_rect
;
3149 UINT uPosFlags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
3153 parent
= GetParent (infoPtr
->hwndSelf
);
3155 if (!parent
|| !infoPtr
->bDoRedraw
)
3158 GetClientRect(parent
, &parent_rect
);
3160 x
= parent_rect
.left
;
3161 y
= parent_rect
.top
;
3163 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3164 cx
= parent_rect
.right
- parent_rect
.left
;
3166 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3168 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3169 MapWindowPoints( 0, parent
, (POINT
*)&window_rect
, 2 );
3170 y
= window_rect
.top
;
3172 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3174 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3175 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3178 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3179 uPosFlags
|= SWP_NOMOVE
;
3181 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3182 cy
+= GetSystemMetrics(SM_CYEDGE
);
3184 if (infoPtr
->dwStyle
& WS_BORDER
)
3186 cx
+= 2 * GetSystemMetrics(SM_CXBORDER
);
3187 cy
+= 2 * GetSystemMetrics(SM_CYBORDER
);
3190 SetWindowPos(infoPtr
->hwndSelf
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3193 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
))
3195 TOOLBAR_LayoutToolbar(infoPtr
);
3196 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
3203 static inline LRESULT
3204 TOOLBAR_ButtonCount (const TOOLBAR_INFO
*infoPtr
)
3206 return infoPtr
->nNumButtons
;
3210 static inline LRESULT
3211 TOOLBAR_ButtonStructSize (TOOLBAR_INFO
*infoPtr
, DWORD Size
)
3213 infoPtr
->dwStructSize
= Size
;
3220 TOOLBAR_ChangeBitmap (TOOLBAR_INFO
*infoPtr
, INT Id
, INT Index
)
3222 TBUTTON_INFO
*btnPtr
;
3225 TRACE("button %d, iBitmap now %d\n", Id
, Index
);
3227 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3231 btnPtr
= &infoPtr
->buttons
[nIndex
];
3232 btnPtr
->iBitmap
= Index
;
3234 /* we HAVE to erase the background, the new bitmap could be */
3236 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3243 TOOLBAR_CheckButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3245 TBUTTON_INFO
*btnPtr
;
3248 BOOL bChecked
= FALSE
;
3250 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3252 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, nIndex
, lParam
);
3257 btnPtr
= &infoPtr
->buttons
[nIndex
];
3259 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) != 0;
3261 if (!LOWORD(lParam
))
3262 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3264 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3266 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3267 if (nOldIndex
== nIndex
)
3269 if (nOldIndex
!= -1)
3270 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3272 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3275 if( bChecked
!= LOWORD(lParam
) )
3277 if (nOldIndex
!= -1)
3278 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3279 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3282 /* FIXME: Send a WM_NOTIFY?? */
3289 TOOLBAR_CommandToIndex (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3291 return TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3296 TOOLBAR_Customize (TOOLBAR_INFO
*infoPtr
)
3298 CUSTDLG_INFO custInfo
;
3302 custInfo
.tbInfo
= infoPtr
;
3303 custInfo
.tbHwnd
= infoPtr
->hwndSelf
;
3305 /* send TBN_BEGINADJUST notification */
3306 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3308 ret
= DialogBoxParamW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3309 infoPtr
->hwndSelf
, TOOLBAR_CustomizeDialogProc
, (LPARAM
)&custInfo
);
3311 /* send TBN_ENDADJUST notification */
3312 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3319 TOOLBAR_DeleteButton (TOOLBAR_INFO
*infoPtr
, INT nIndex
)
3322 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3324 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3327 memset(&nmtb
, 0, sizeof(nmtb
));
3328 nmtb
.iItem
= btnPtr
->idCommand
;
3329 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3330 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3331 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3332 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3333 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3334 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3335 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3337 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3339 if (infoPtr
->nNumButtons
== 1) {
3340 TRACE(" simple delete!\n");
3341 free_string( infoPtr
->buttons
);
3342 Free (infoPtr
->buttons
);
3343 infoPtr
->buttons
= NULL
;
3344 infoPtr
->nNumButtons
= 0;
3347 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3348 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3350 infoPtr
->nNumButtons
--;
3351 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3353 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3354 nIndex
* sizeof(TBUTTON_INFO
));
3357 if (nIndex
< infoPtr
->nNumButtons
) {
3358 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3359 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3362 free_string( oldButtons
+ nIndex
);
3366 TOOLBAR_LayoutToolbar(infoPtr
);
3368 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3375 TOOLBAR_EnableButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3377 TBUTTON_INFO
*btnPtr
;
3381 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3383 TRACE("hwnd=%p, btn id=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, Id
, lParam
);
3388 btnPtr
= &infoPtr
->buttons
[nIndex
];
3390 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3392 /* update the toolbar button state */
3393 if(!LOWORD(lParam
)) {
3394 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3396 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3399 /* redraw the button only if the state of the button changed */
3400 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3401 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3407 static inline LRESULT
3408 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO
*infoPtr
)
3410 return infoPtr
->bAnchor
;
3415 TOOLBAR_GetBitmap (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3419 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3423 return infoPtr
->buttons
[nIndex
].iBitmap
;
3427 static inline LRESULT
3428 TOOLBAR_GetBitmapFlags (void)
3430 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3435 TOOLBAR_GetButton (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, TBBUTTON
*lpTbb
)
3437 TBUTTON_INFO
*btnPtr
;
3442 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3445 btnPtr
= &infoPtr
->buttons
[nIndex
];
3446 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3447 lpTbb
->idCommand
= btnPtr
->idCommand
;
3448 lpTbb
->fsState
= btnPtr
->fsState
;
3449 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3450 lpTbb
->bReserved
[0] = 0;
3451 lpTbb
->bReserved
[1] = 0;
3452 lpTbb
->dwData
= btnPtr
->dwData
;
3453 lpTbb
->iString
= btnPtr
->iString
;
3460 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO
*infoPtr
, INT Id
, LPTBBUTTONINFOW lpTbInfo
, BOOL bUnicode
)
3462 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3463 TBUTTON_INFO
*btnPtr
;
3466 if (lpTbInfo
== NULL
)
3469 /* MSDN documents an iImageLabel field added in Vista but it is not present in
3470 * the headers and tests shows that even with comctl 6 Vista accepts only the
3471 * original TBBUTTONINFO size
3473 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3475 WARN("Invalid button size\n");
3479 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lpTbInfo
->dwMask
& TBIF_BYINDEX
);
3483 btnPtr
= &infoPtr
->buttons
[nIndex
];
3484 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3485 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3486 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3487 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3488 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3489 lpTbInfo
->lParam
= btnPtr
->dwData
;
3490 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3491 /* tests show that for separators TBIF_SIZE returns not calculated width,
3492 but cx property, that differs from 0 only if application have
3493 specifically set it */
3494 lpTbInfo
->cx
= (btnPtr
->fsStyle
& BTNS_SEP
)
3495 ? btnPtr
->cx
: (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3496 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3497 lpTbInfo
->fsState
= btnPtr
->fsState
;
3498 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3499 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3500 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3501 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3502 can't use TOOLBAR_GetText here */
3503 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3504 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3506 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3508 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3509 } else if (!bUnicode
|| lpTbInfo
->pszText
)
3510 lpTbInfo
->pszText
[0] = '\0';
3516 static inline LRESULT
3517 TOOLBAR_GetButtonSize (const TOOLBAR_INFO
*infoPtr
)
3519 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3520 (WORD
)infoPtr
->nButtonHeight
);
3525 TOOLBAR_GetButtonText (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPWSTR lpStr
, BOOL isW
)
3531 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3535 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3541 ret
= strlenW (lpText
);
3542 if (lpStr
) strcpyW (lpStr
, lpText
);
3546 ret
= WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3547 (LPSTR
)lpStr
, lpStr
? 0x7fffffff : 0, NULL
, NULL
) - 1;
3553 TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3555 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3556 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3557 return (LRESULT
)GETDISIMAGELIST(infoPtr
, wParam
);
3561 static inline LRESULT
3562 TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO
*infoPtr
)
3566 return infoPtr
->dwExStyle
;
3571 TOOLBAR_GetHotImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3573 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3574 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3575 return (LRESULT
)GETHOTIMAGELIST(infoPtr
, wParam
);
3580 TOOLBAR_GetHotItem (const TOOLBAR_INFO
*infoPtr
)
3582 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3585 if (infoPtr
->nHotItem
< 0)
3588 return (LRESULT
)infoPtr
->nHotItem
;
3593 TOOLBAR_GetDefImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3595 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3596 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3597 return (LRESULT
) GETDEFIMAGELIST(infoPtr
, wParam
);
3602 TOOLBAR_GetInsertMark (const TOOLBAR_INFO
*infoPtr
, TBINSERTMARK
*lptbim
)
3604 TRACE("hwnd = %p, lptbim = %p\n", infoPtr
->hwndSelf
, lptbim
);
3606 *lptbim
= infoPtr
->tbim
;
3612 static inline LRESULT
3613 TOOLBAR_GetInsertMarkColor (const TOOLBAR_INFO
*infoPtr
)
3615 TRACE("hwnd = %p\n", infoPtr
->hwndSelf
);
3617 return (LRESULT
)infoPtr
->clrInsertMark
;
3622 TOOLBAR_GetItemRect (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, LPRECT lpRect
)
3624 TBUTTON_INFO
*btnPtr
;
3626 btnPtr
= &infoPtr
->buttons
[nIndex
];
3627 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3632 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3635 lpRect
->left
= btnPtr
->rect
.left
;
3636 lpRect
->right
= btnPtr
->rect
.right
;
3637 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3638 lpRect
->top
= btnPtr
->rect
.top
;
3645 TOOLBAR_GetMaxSize (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
3650 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3651 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3653 TRACE("maximum size %d x %d\n",
3654 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3655 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3662 TOOLBAR_GetMetrics(const TOOLBAR_INFO
*infoPtr
, TBMETRICS
*pMetrics
)
3664 if (pMetrics
== NULL
)
3667 /* TODO: check if cbSize is a valid value */
3669 if (pMetrics
->dwMask
& TBMF_PAD
)
3671 pMetrics
->cxPad
= infoPtr
->szPadding
.cx
;
3672 pMetrics
->cyPad
= infoPtr
->szPadding
.cy
;
3675 if (pMetrics
->dwMask
& TBMF_BARPAD
)
3677 pMetrics
->cxBarPad
= infoPtr
->szBarPadding
.cx
;
3678 pMetrics
->cyBarPad
= infoPtr
->szBarPadding
.cy
;
3681 if (pMetrics
->dwMask
& TBMF_BUTTONSPACING
)
3683 pMetrics
->cxButtonSpacing
= infoPtr
->szSpacing
.cx
;
3684 pMetrics
->cyButtonSpacing
= infoPtr
->szSpacing
.cy
;
3691 /* << TOOLBAR_GetObject >> */
3694 static inline LRESULT
3695 TOOLBAR_GetPadding (const TOOLBAR_INFO
*infoPtr
)
3697 return MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3702 TOOLBAR_GetRect (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPRECT lpRect
)
3704 TBUTTON_INFO
*btnPtr
;
3707 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3708 btnPtr
= &infoPtr
->buttons
[nIndex
];
3709 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3715 lpRect
->left
= btnPtr
->rect
.left
;
3716 lpRect
->right
= btnPtr
->rect
.right
;
3717 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3718 lpRect
->top
= btnPtr
->rect
.top
;
3724 static inline LRESULT
3725 TOOLBAR_GetRows (const TOOLBAR_INFO
*infoPtr
)
3727 return infoPtr
->nRows
;
3732 TOOLBAR_GetState (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3736 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3740 return infoPtr
->buttons
[nIndex
].fsState
;
3744 static inline LRESULT
3745 TOOLBAR_GetStyle (const TOOLBAR_INFO
*infoPtr
)
3747 return infoPtr
->dwStyle
;
3751 static inline LRESULT
3752 TOOLBAR_GetTextRows (const TOOLBAR_INFO
*infoPtr
)
3754 return infoPtr
->nMaxTextRows
;
3759 TOOLBAR_GetToolTips (TOOLBAR_INFO
*infoPtr
)
3761 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3762 TOOLBAR_TooltipCreateControl(infoPtr
);
3763 return (LRESULT
)infoPtr
->hwndToolTip
;
3768 TOOLBAR_GetUnicodeFormat (const TOOLBAR_INFO
*infoPtr
)
3770 TRACE("%s hwnd=%p\n",
3771 infoPtr
->bUnicode
? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
3773 return infoPtr
->bUnicode
;
3777 static inline LRESULT
3778 TOOLBAR_GetVersion (const TOOLBAR_INFO
*infoPtr
)
3780 return infoPtr
->iVersion
;
3785 TOOLBAR_HideButton (TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fHide
)
3787 TBUTTON_INFO
*btnPtr
;
3793 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3797 btnPtr
= &infoPtr
->buttons
[nIndex
];
3798 oldState
= btnPtr
->fsState
;
3801 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3803 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3805 if (oldState
!= btnPtr
->fsState
) {
3806 TOOLBAR_LayoutToolbar (infoPtr
);
3807 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3814 static inline LRESULT
3815 TOOLBAR_HitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
* lpPt
)
3817 return TOOLBAR_InternalHitTest (infoPtr
, lpPt
, NULL
);
3822 TOOLBAR_Indeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fIndeterminate
)
3824 TBUTTON_INFO
*btnPtr
;
3828 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3832 btnPtr
= &infoPtr
->buttons
[nIndex
];
3833 oldState
= btnPtr
->fsState
;
3836 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3838 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3840 if(oldState
!= btnPtr
->fsState
)
3841 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3848 TOOLBAR_InsertButtonT(TOOLBAR_INFO
*infoPtr
, INT nIndex
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
3854 /* EPP: this seems to be an undocumented call (from my IE4)
3855 * I assume in that case that:
3856 * - index of insertion is at the end of existing buttons
3857 * I only see this happen with nIndex == -1, but it could have a special
3858 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3860 nIndex
= infoPtr
->nNumButtons
;
3862 } else if (nIndex
< 0)
3865 TRACE("inserting button index=%d\n", nIndex
);
3866 if (nIndex
> infoPtr
->nNumButtons
) {
3867 nIndex
= infoPtr
->nNumButtons
;
3868 TRACE("adjust index=%d\n", nIndex
);
3871 return TOOLBAR_InternalInsertButtonsT(infoPtr
, nIndex
, 1, lpTbb
, fUnicode
);
3874 /* << TOOLBAR_InsertMarkHitTest >> */
3878 TOOLBAR_IsButtonChecked (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3882 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3886 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3891 TOOLBAR_IsButtonEnabled (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3895 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3899 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3904 TOOLBAR_IsButtonHidden (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3908 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3912 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3917 TOOLBAR_IsButtonHighlighted (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3921 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3925 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3930 TOOLBAR_IsButtonIndeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3934 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3938 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3943 TOOLBAR_IsButtonPressed (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3947 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3951 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3956 TOOLBAR_LoadImages (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HINSTANCE hInstance
)
3959 tbab
.hInst
= hInstance
;
3962 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", infoPtr
->hwndSelf
, tbab
.hInst
, tbab
.nID
);
3964 return TOOLBAR_AddBitmap(infoPtr
, 0, &tbab
);
3969 TOOLBAR_MapAccelerator (const TOOLBAR_INFO
*infoPtr
, WCHAR wAccel
, UINT
*pIDButton
)
3971 WCHAR wszAccel
[] = {'&',wAccel
,0};
3974 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3975 infoPtr
->hwndSelf
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3977 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3979 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3980 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3981 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3983 int iLen
= strlenW(wszAccel
);
3984 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3991 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3996 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
3998 *pIDButton
= btnPtr
->idCommand
;
4010 TOOLBAR_MarkButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fMark
)
4014 TBUTTON_INFO
*btnPtr
;
4016 TRACE("hwnd = %p, Id = %d, fMark = 0%d\n", infoPtr
->hwndSelf
, Id
, fMark
);
4018 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
4022 btnPtr
= &infoPtr
->buttons
[nIndex
];
4023 oldState
= btnPtr
->fsState
;
4026 btnPtr
->fsState
|= TBSTATE_MARKED
;
4028 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
4030 if(oldState
!= btnPtr
->fsState
)
4031 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4037 /* fixes up an index of a button affected by a move */
4038 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
4042 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
4044 else if (*pIndex
== nIndex
)
4045 *pIndex
= nMoveIndex
;
4049 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
4051 else if (*pIndex
== nIndex
)
4052 *pIndex
= nMoveIndex
;
4058 TOOLBAR_MoveButton (TOOLBAR_INFO
*infoPtr
, INT Id
, INT nMoveIndex
)
4062 TBUTTON_INFO button
;
4064 TRACE("hwnd=%p, Id=%d, nMoveIndex=%d\n", infoPtr
->hwndSelf
, Id
, nMoveIndex
);
4066 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, TRUE
);
4067 if ((nIndex
== -1) || (nMoveIndex
< 0))
4070 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
4071 nMoveIndex
= infoPtr
->nNumButtons
- 1;
4073 button
= infoPtr
->buttons
[nIndex
];
4075 /* move button right */
4076 if (nIndex
< nMoveIndex
)
4078 nCount
= nMoveIndex
- nIndex
;
4079 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
4080 infoPtr
->buttons
[nMoveIndex
] = button
;
4082 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
4083 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
4084 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
4085 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
4087 else if (nIndex
> nMoveIndex
) /* move button left */
4089 nCount
= nIndex
- nMoveIndex
;
4090 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
4091 infoPtr
->buttons
[nMoveIndex
] = button
;
4093 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
4094 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
4095 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
4096 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
4099 TOOLBAR_LayoutToolbar(infoPtr
);
4100 TOOLBAR_AutoSize(infoPtr
);
4101 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4108 TOOLBAR_PressButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fPress
)
4110 TBUTTON_INFO
*btnPtr
;
4114 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
4118 btnPtr
= &infoPtr
->buttons
[nIndex
];
4119 oldState
= btnPtr
->fsState
;
4122 btnPtr
->fsState
|= TBSTATE_PRESSED
;
4124 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
4126 if(oldState
!= btnPtr
->fsState
)
4127 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4132 /* FIXME: there might still be some confusion her between number of buttons
4133 * and number of bitmaps */
4135 TOOLBAR_ReplaceBitmap (TOOLBAR_INFO
*infoPtr
, const TBREPLACEBITMAP
*lpReplace
)
4138 int i
= 0, nOldButtons
= 0, pos
= 0;
4139 int nOldBitmaps
, nNewBitmaps
= 0;
4140 HIMAGELIST himlDef
= 0;
4142 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4143 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
4144 lpReplace
->nButtons
);
4146 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4148 FIXME("changing standard bitmaps not implemented\n");
4151 else if (lpReplace
->hInstOld
!= 0 && lpReplace
->hInstOld
!= lpReplace
->hInstNew
)
4152 FIXME("resources not in the current module not implemented\n");
4154 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4155 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4156 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4157 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4158 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4160 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4161 nOldButtons
= tbi
->nButtons
;
4162 tbi
->nButtons
= lpReplace
->nButtons
;
4163 tbi
->hInst
= lpReplace
->hInstNew
;
4164 tbi
->nID
= lpReplace
->nIDNew
;
4165 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4168 pos
+= tbi
->nButtons
;
4171 if (nOldButtons
== 0)
4173 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4177 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4180 if (lpReplace
->hInstNew
)
4181 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4183 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4185 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4186 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4188 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4190 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4191 ImageList_Remove(himlDef
, i
);
4195 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4196 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4197 DeleteObject(hBitmap
);
4200 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4202 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4203 pos
, nOldBitmaps
, nNewBitmaps
);
4205 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4210 /* helper for TOOLBAR_SaveRestoreW */
4212 TOOLBAR_Save(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*params
)
4216 BOOL alloced
= FALSE
;
4219 TRACE( "save to %s %s\n", debugstr_w(params
->pszSubKey
), debugstr_w(params
->pszValueName
) );
4221 memset( &save
, 0, sizeof(save
) );
4222 save
.cbData
= infoPtr
->nNumButtons
* sizeof(DWORD
);
4224 save
.cButtons
= infoPtr
->nNumButtons
;
4225 save
.tbButton
.idCommand
= -1;
4226 TOOLBAR_SendNotify( &save
.hdr
, infoPtr
, TBN_SAVE
);
4230 save
.pData
= Alloc( save
.cbData
);
4231 if (!save
.pData
) return FALSE
;
4234 if (!save
.pCurrent
) save
.pCurrent
= save
.pData
;
4236 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4239 save
.tbButton
.iBitmap
= infoPtr
->buttons
[i
].iBitmap
;
4240 save
.tbButton
.idCommand
= infoPtr
->buttons
[i
].idCommand
;
4241 save
.tbButton
.fsState
= infoPtr
->buttons
[i
].fsState
;
4242 save
.tbButton
.fsStyle
= infoPtr
->buttons
[i
].fsStyle
;
4243 memset( save
.tbButton
.bReserved
, 0, sizeof(save
.tbButton
.bReserved
) );
4244 save
.tbButton
.dwData
= infoPtr
->buttons
[i
].dwData
;
4245 save
.tbButton
.iString
= infoPtr
->buttons
[i
].iString
;
4247 *save
.pCurrent
++ = save
.tbButton
.idCommand
;
4249 TOOLBAR_SendNotify( &save
.hdr
, infoPtr
, TBN_SAVE
);
4252 ret
= RegCreateKeyW( params
->hkr
, params
->pszSubKey
, &key
);
4253 if (ret
== ERROR_SUCCESS
)
4255 ret
= RegSetValueExW( key
, params
->pszValueName
, 0, REG_BINARY
, (BYTE
*)save
.pData
, save
.cbData
);
4259 if (alloced
) Free( save
.pData
);
4264 /* helper for TOOLBAR_Restore */
4266 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4270 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4272 free_string( infoPtr
->buttons
+ i
);
4273 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4276 Free(infoPtr
->buttons
);
4277 infoPtr
->buttons
= NULL
;
4278 infoPtr
->nNumButtons
= 0;
4282 /* helper for TOOLBAR_SaveRestoreW */
4284 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4294 /* restore toolbar information */
4295 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4296 debugstr_w(lpSave
->pszValueName
));
4298 memset(&nmtbr
, 0, sizeof(nmtbr
));
4300 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4301 KEY_QUERY_VALUE
, &hkey
);
4303 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4305 if (!res
&& dwType
!= REG_BINARY
)
4306 res
= ERROR_FILE_NOT_FOUND
;
4309 nmtbr
.pData
= Alloc(dwSize
);
4310 nmtbr
.cbData
= dwSize
;
4311 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4314 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4315 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4318 nmtbr
.pCurrent
= nmtbr
.pData
;
4320 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4321 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4323 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4325 INT i
, count
= nmtbr
.cButtons
;
4327 /* remove all existing buttons as this function is designed to
4328 * restore the toolbar to a previously saved state */
4329 TOOLBAR_DeleteAllButtons(infoPtr
);
4331 for (i
= 0; i
< count
; i
++)
4334 nmtbr
.tbButton
.iBitmap
= -1;
4335 nmtbr
.tbButton
.fsState
= 0;
4336 nmtbr
.tbButton
.fsStyle
= 0;
4337 nmtbr
.tbButton
.dwData
= 0;
4338 nmtbr
.tbButton
.iString
= 0;
4340 if (*nmtbr
.pCurrent
& 0x80000000)
4343 nmtbr
.tbButton
.iBitmap
= SEPARATOR_WIDTH
;
4344 nmtbr
.tbButton
.idCommand
= 0;
4345 nmtbr
.tbButton
.fsStyle
= BTNS_SEP
;
4346 if (*nmtbr
.pCurrent
!= (DWORD
)-1)
4347 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4350 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4354 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4356 /* All returned ptrs and -1 are ignored */
4357 if (!IS_INTRESOURCE(nmtbr
.tbButton
.iString
))
4358 nmtbr
.tbButton
.iString
= 0;
4360 TOOLBAR_InsertButtonT(infoPtr
, -1, &nmtbr
.tbButton
, TRUE
);
4363 TOOLBAR_SendNotify( &hdr
, infoPtr
, TBN_BEGINADJUST
);
4369 UINT code
= infoPtr
->bUnicode
? TBN_GETBUTTONINFOW
: TBN_GETBUTTONINFOA
;
4372 memset( &tb
, 0, sizeof(tb
) );
4374 tb
.cchText
= sizeof(buf
) / sizeof(buf
[0]);
4377 /* Use the same struct for both A and W versions since the layout is the same. */
4378 if (!TOOLBAR_SendNotify( &tb
.hdr
, infoPtr
, code
))
4381 idx
= TOOLBAR_GetButtonIndex( infoPtr
, tb
.tbButton
.idCommand
, FALSE
);
4382 if (idx
== -1) continue;
4384 /* tb.pszText is ignored - the string comes from tb.tbButton.iString, which may
4385 be an index or a ptr. Either way it is simply copied. There is no api to change
4386 the string index, so we set it manually. The other properties can be set with SetButtonInfo. */
4387 free_string( infoPtr
->buttons
+ idx
);
4388 infoPtr
->buttons
[idx
].iString
= tb
.tbButton
.iString
;
4390 memset( &bi
, 0, sizeof(bi
) );
4391 bi
.cbSize
= sizeof(bi
);
4392 bi
.dwMask
= TBIF_IMAGE
| TBIF_STATE
| TBIF_STYLE
| TBIF_LPARAM
;
4393 bi
.iImage
= tb
.tbButton
.iBitmap
;
4394 bi
.fsState
= tb
.tbButton
.fsState
;
4395 bi
.fsStyle
= tb
.tbButton
.fsStyle
;
4396 bi
.lParam
= tb
.tbButton
.dwData
;
4398 TOOLBAR_SetButtonInfo( infoPtr
, tb
.tbButton
.idCommand
, &bi
, TRUE
);
4400 TOOLBAR_SendNotify( &hdr
, infoPtr
, TBN_ENDADJUST
);
4402 /* remove all uninitialised buttons
4403 * note: loop backwards to avoid having to fixup i on a
4405 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4406 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4407 TOOLBAR_DeleteButton(infoPtr
, i
);
4409 /* only indicate success if at least one button survived */
4410 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4421 TOOLBAR_SaveRestoreW (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4423 if (lpSave
== NULL
) return 0;
4426 return TOOLBAR_Save(infoPtr
, lpSave
);
4428 return TOOLBAR_Restore(infoPtr
, lpSave
);
4433 TOOLBAR_SaveRestoreA (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4435 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4436 TBSAVEPARAMSW SaveW
;
4440 if (lpSave
== NULL
) return 0;
4442 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4443 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4444 if (!pszSubKey
) goto exit
;
4445 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4447 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4448 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4449 if (!pszValueName
) goto exit
;
4450 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4452 SaveW
.pszValueName
= pszValueName
;
4453 SaveW
.pszSubKey
= pszSubKey
;
4454 SaveW
.hkr
= lpSave
->hkr
;
4455 result
= TOOLBAR_SaveRestoreW(infoPtr
, wParam
, &SaveW
);
4458 Free (pszValueName
);
4466 TOOLBAR_SetAnchorHighlight (TOOLBAR_INFO
*infoPtr
, BOOL bAnchor
)
4468 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4470 TRACE("hwnd=%p, bAnchor = %s\n", infoPtr
->hwndSelf
, bAnchor
? "TRUE" : "FALSE");
4472 infoPtr
->bAnchor
= bAnchor
;
4474 /* Native does not remove the hot effect from an already hot button */
4476 return (LRESULT
)bOldAnchor
;
4481 TOOLBAR_SetBitmapSize (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4483 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4484 short width
= (short)LOWORD(lParam
);
4485 short height
= (short)HIWORD(lParam
);
4487 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", infoPtr
->hwndSelf
, wParam
, lParam
);
4490 FIXME("wParam is %ld. Perhaps image list index?\n", wParam
);
4492 /* 0 width or height is changed to 1 */
4498 if (infoPtr
->nNumButtons
> 0)
4499 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4500 infoPtr
->nNumButtons
,
4501 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
, width
, height
);
4503 if (width
< -1 || height
< -1)
4505 /* Windows destroys the imagelist and seems to actually use negative
4506 * values to compute button sizes */
4507 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width
, height
);
4511 /* width or height of -1 means no change */
4513 infoPtr
->nBitmapWidth
= width
;
4515 infoPtr
->nBitmapHeight
= height
;
4517 if ((himlDef
== infoPtr
->himlInt
) &&
4518 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4520 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4521 infoPtr
->nBitmapHeight
);
4524 TOOLBAR_CalcToolbar(infoPtr
);
4525 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4531 TOOLBAR_SetButtonInfo (TOOLBAR_INFO
*infoPtr
, INT Id
,
4532 const TBBUTTONINFOW
*lptbbi
, BOOL isW
)
4534 TBUTTON_INFO
*btnPtr
;
4540 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4543 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lptbbi
->dwMask
& TBIF_BYINDEX
);
4547 btnPtr
= &infoPtr
->buttons
[nIndex
];
4548 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4549 btnPtr
->idCommand
= lptbbi
->idCommand
;
4550 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4551 btnPtr
->iBitmap
= lptbbi
->iImage
;
4552 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4553 btnPtr
->dwData
= lptbbi
->lParam
;
4554 if (lptbbi
->dwMask
& TBIF_SIZE
)
4555 btnPtr
->cx
= lptbbi
->cx
;
4556 if (lptbbi
->dwMask
& TBIF_STATE
)
4557 btnPtr
->fsState
= lptbbi
->fsState
;
4558 if (lptbbi
->dwMask
& TBIF_STYLE
)
4559 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4561 if (lptbbi
->dwMask
& TBIF_TEXT
)
4562 set_stringT( btnPtr
, lptbbi
->pszText
, isW
);
4564 /* save the button rect to see if we need to redraw the whole toolbar */
4565 oldBtnRect
= btnPtr
->rect
;
4566 TOOLBAR_LayoutToolbar(infoPtr
);
4568 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4569 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4571 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4578 TOOLBAR_SetButtonSize (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4580 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4581 int top
= default_top_margin(infoPtr
);
4583 if ((cx
< 0) || (cy
< 0))
4585 ERR("invalid parameter 0x%08x\n", (DWORD
)lParam
);
4589 TRACE("%p, cx = %d, cy = %d\n", infoPtr
->hwndSelf
, cx
, cy
);
4591 /* The documentation claims you can only change the button size before
4592 * any button has been added. But this is wrong.
4593 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4594 * it to the toolbar, and it checks that the return value is nonzero - mjm
4595 * Further testing shows that we must actually perform the change too.
4598 * The documentation also does not mention that if 0 is supplied for
4599 * either size, the system changes it to the default of 24 wide and
4600 * 22 high. Demonstrated in ControlSpy Toolbar. GLA 3/02
4602 if (cx
== 0) cx
= 24;
4603 if (cy
== 0) cy
= 22;
4605 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4606 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4608 if (cx
!= infoPtr
->nButtonWidth
|| cy
!= infoPtr
->nButtonHeight
||
4609 top
!= infoPtr
->iTopMargin
)
4611 infoPtr
->nButtonWidth
= cx
;
4612 infoPtr
->nButtonHeight
= cy
;
4613 infoPtr
->iTopMargin
= top
;
4615 TOOLBAR_LayoutToolbar( infoPtr
);
4616 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
4623 TOOLBAR_SetButtonWidth (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4625 /* if setting to current values, ignore */
4626 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4627 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4628 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4629 infoPtr
->cxMin
, infoPtr
->cxMax
);
4633 /* save new values */
4634 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4635 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4637 /* otherwise we need to recalc the toolbar and in some cases
4638 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4639 which doesn't actually draw - GA). */
4640 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4641 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4643 TOOLBAR_CalcToolbar (infoPtr
);
4645 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
4652 TOOLBAR_SetCmdId (TOOLBAR_INFO
*infoPtr
, INT nIndex
, INT nId
)
4654 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4657 infoPtr
->buttons
[nIndex
].idCommand
= nId
;
4659 if (infoPtr
->hwndToolTip
) {
4661 FIXME("change tool tip!\n");
4670 TOOLBAR_SetDisabledImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4672 HIMAGELIST himlTemp
;
4675 if (infoPtr
->iVersion
>= 5)
4678 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4679 &infoPtr
->cimlDis
, himl
, id
);
4681 /* FIXME: redraw ? */
4683 return (LRESULT
)himlTemp
;
4688 TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD flags
)
4692 TRACE("hwnd = %p, mask = 0x%08x, flags = 0x%08x\n", infoPtr
->hwndSelf
, mask
, flags
);
4694 old_flags
= infoPtr
->dwDTFlags
;
4695 infoPtr
->dwDTFlags
= (old_flags
& ~mask
) | (flags
& mask
);
4697 return (LRESULT
)old_flags
;
4700 /* This function differs a bit from what MSDN says it does:
4701 * 1. lParam contains extended style flags to OR with current style
4702 * (MSDN isn't clear on the OR bit)
4703 * 2. wParam appears to contain extended style flags to be reset
4704 * (MSDN says that this parameter is reserved)
4707 TOOLBAR_SetExtendedStyle (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD style
)
4709 DWORD old_style
= infoPtr
->dwExStyle
;
4711 TRACE("mask=0x%08x, style=0x%08x\n", mask
, style
);
4714 infoPtr
->dwExStyle
= (old_style
& ~mask
) | (style
& mask
);
4716 infoPtr
->dwExStyle
= style
;
4718 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4719 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4720 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4722 if ((old_style
^ infoPtr
->dwExStyle
) & TBSTYLE_EX_MIXEDBUTTONS
)
4723 TOOLBAR_CalcToolbar(infoPtr
);
4725 TOOLBAR_LayoutToolbar(infoPtr
);
4727 TOOLBAR_AutoSize(infoPtr
);
4728 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4735 TOOLBAR_SetHotImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4737 HIMAGELIST himlTemp
;
4740 if (infoPtr
->iVersion
>= 5)
4743 TRACE("hwnd = %p, himl = %p, id = %d\n", infoPtr
->hwndSelf
, himl
, id
);
4745 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4746 &infoPtr
->cimlHot
, himl
, id
);
4748 /* FIXME: redraw ? */
4750 return (LRESULT
)himlTemp
;
4754 /* Makes previous hot button no longer hot, makes the specified
4755 * button hot and sends appropriate notifications. dwReason is one or
4756 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4757 * NOTE 1: this function does not validate nHit
4758 * NOTE 2: the name of this function is completely made up and
4759 * not based on any documentation from Microsoft. */
4761 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4763 if (infoPtr
->nHotItem
!= nHit
)
4765 NMTBHOTITEM nmhotitem
;
4766 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4768 nmhotitem
.dwFlags
= dwReason
;
4769 if(infoPtr
->nHotItem
>= 0)
4771 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4772 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4776 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4777 nmhotitem
.idOld
= 0;
4782 btnPtr
= &infoPtr
->buttons
[nHit
];
4783 nmhotitem
.idNew
= btnPtr
->idCommand
;
4787 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4788 nmhotitem
.idNew
= 0;
4791 /* now change the hot and invalidate the old and new buttons - if the
4793 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4796 oldBtnPtr
->bHot
= FALSE
;
4797 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4799 /* setting disabled buttons as hot fails even if the notify contains the button id */
4800 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4801 btnPtr
->bHot
= TRUE
;
4802 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4803 infoPtr
->nHotItem
= nHit
;
4806 infoPtr
->nHotItem
= -1;
4812 TOOLBAR_SetHotItem (TOOLBAR_INFO
*infoPtr
, INT nHotItem
)
4814 INT nOldHotItem
= infoPtr
->nHotItem
;
4816 TRACE("hwnd = %p, nHotItem = %d\n", infoPtr
->hwndSelf
, nHotItem
);
4818 if (nHotItem
>= infoPtr
->nNumButtons
)
4819 return infoPtr
->nHotItem
;
4824 /* NOTE: an application can still remove the hot item even if anchor
4825 * highlighting is enabled */
4827 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, HICF_OTHER
);
4829 if (nOldHotItem
< 0)
4832 return (LRESULT
)nOldHotItem
;
4837 TOOLBAR_SetImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4839 HIMAGELIST himlTemp
;
4840 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4841 INT oldBitmapWidth
= infoPtr
->nBitmapWidth
;
4842 INT oldBitmapHeight
= infoPtr
->nBitmapHeight
;
4845 if (infoPtr
->iVersion
>= 5)
4848 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4849 &infoPtr
->cimlDef
, himl
, id
);
4851 infoPtr
->nNumBitmaps
= 0;
4852 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4853 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4855 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4856 &infoPtr
->nBitmapHeight
))
4858 infoPtr
->nBitmapWidth
= 1;
4859 infoPtr
->nBitmapHeight
= 1;
4861 if ((oldBitmapWidth
!= infoPtr
->nBitmapWidth
) || (oldBitmapHeight
!= infoPtr
->nBitmapHeight
))
4863 TOOLBAR_CalcToolbar(infoPtr
);
4864 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4865 TOOLBAR_SetButtonSize(infoPtr
, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4868 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4869 infoPtr
->hwndSelf
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4870 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4872 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4874 return (LRESULT
)himlTemp
;
4879 TOOLBAR_SetIndent (TOOLBAR_INFO
*infoPtr
, INT nIndent
)
4881 infoPtr
->nIndent
= nIndent
;
4885 /* process only on indent changing */
4886 if(infoPtr
->nIndent
!= nIndent
)
4888 infoPtr
->nIndent
= nIndent
;
4889 TOOLBAR_CalcToolbar (infoPtr
);
4890 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4898 TOOLBAR_SetInsertMark (TOOLBAR_INFO
*infoPtr
, const TBINSERTMARK
*lptbim
)
4900 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", infoPtr
->hwndSelf
, lptbim
->iButton
, lptbim
->dwFlags
);
4902 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4904 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4908 if ((lptbim
->iButton
== -1) ||
4909 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4910 (lptbim
->iButton
>= 0)))
4912 infoPtr
->tbim
= *lptbim
;
4913 /* FIXME: don't need to update entire toolbar */
4914 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4917 ERR("Invalid button index %d\n", lptbim
->iButton
);
4924 TOOLBAR_SetInsertMarkColor (TOOLBAR_INFO
*infoPtr
, COLORREF clr
)
4926 infoPtr
->clrInsertMark
= clr
;
4928 /* FIXME: don't need to update entire toolbar */
4929 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4936 TOOLBAR_SetMaxTextRows (TOOLBAR_INFO
*infoPtr
, INT nMaxRows
)
4938 infoPtr
->nMaxTextRows
= nMaxRows
;
4940 TOOLBAR_CalcToolbar(infoPtr
);
4946 TOOLBAR_SetMetrics(TOOLBAR_INFO
*infoPtr
, TBMETRICS
*pMetrics
)
4948 BOOL changed
= FALSE
;
4953 /* TODO: check if cbSize is a valid value */
4955 if (pMetrics
->dwMask
& TBMF_PAD
)
4957 infoPtr
->szPadding
.cx
= pMetrics
->cxPad
;
4958 infoPtr
->szPadding
.cy
= pMetrics
->cyPad
;
4962 if (pMetrics
->dwMask
& TBMF_PAD
)
4964 infoPtr
->szBarPadding
.cx
= pMetrics
->cxBarPad
;
4965 infoPtr
->szBarPadding
.cy
= pMetrics
->cyBarPad
;
4969 if (pMetrics
->dwMask
& TBMF_BUTTONSPACING
)
4971 infoPtr
->szSpacing
.cx
= pMetrics
->cxButtonSpacing
;
4972 infoPtr
->szSpacing
.cy
= pMetrics
->cyButtonSpacing
;
4977 TOOLBAR_CalcToolbar(infoPtr
);
4983 /* MSDN gives slightly wrong info on padding.
4984 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4985 * 2. It is not used to create a blank area between the edge of the button
4986 * and the text or image if TBSTYLE_LIST is set. It is used to control
4987 * the gap between the image and text.
4988 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4989 * to control the bottom and right borders [with the border being
4990 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4991 * is shared evenly on both sides of the button.
4992 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4995 TOOLBAR_SetPadding (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4999 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
5000 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
5001 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
5002 TRACE("cx=%d, cy=%d\n",
5003 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
5004 return (LRESULT
) oldPad
;
5009 TOOLBAR_SetParent (TOOLBAR_INFO
*infoPtr
, HWND hParent
)
5015 hwndOldNotify
= infoPtr
->hwndNotify
;
5016 infoPtr
->hwndNotify
= hParent
;
5018 return (LRESULT
)hwndOldNotify
;
5023 TOOLBAR_SetRows (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPRECT lprc
)
5025 int rows
= LOWORD(wParam
);
5026 BOOL bLarger
= HIWORD(wParam
);
5030 TRACE("Setting rows to %d (%d)\n", rows
, bLarger
);
5032 if(infoPtr
->nRows
!= rows
)
5034 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
;
5035 int curColumn
= 0; /* Current column */
5036 int curRow
= 0; /* Current row */
5037 int hidden
= 0; /* Number of hidden buttons */
5038 int seps
= 0; /* Number of separators */
5039 int idealWrap
= 0; /* Ideal wrap point */
5044 Calculate new size and wrap points - Under windows, setrows will
5045 change the dimensions if needed to show the number of requested
5046 rows (if CCS_NORESIZE is set), or will take up the whole window
5047 (if no CCS_NORESIZE).
5049 Basic algorithm - If N buttons, and y rows requested, each row
5050 contains N/y buttons.
5052 FIXME: Handling of separators not obvious from testing results
5053 FIXME: Take width of window into account?
5056 /* Loop through the buttons one by one counting key items */
5057 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
5059 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
5060 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
5062 else if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
5066 /* FIXME: Separators make this quite complex */
5067 if (seps
) FIXME("Separators unhandled\n");
5069 /* Round up so more per line, i.e., less rows */
5070 idealWrap
= (infoPtr
->nNumButtons
- hidden
+ (rows
-1)) / (rows
? rows
: 1);
5072 /* Calculate ideal wrap point if we are allowed to grow, but cannot
5073 achieve the requested number of rows. */
5074 if (bLarger
&& idealWrap
> 1)
5076 int resRows
= (infoPtr
->nNumButtons
+ (idealWrap
-1)) / idealWrap
;
5077 int moreRows
= (infoPtr
->nNumButtons
+ (idealWrap
-2)) / (idealWrap
-1);
5079 if (resRows
< rows
&& moreRows
> rows
)
5082 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap
);
5086 curColumn
= curRow
= 0;
5088 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap
,
5089 infoPtr
->nNumButtons
, hidden
, rows
);
5091 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
5093 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
5096 /* Step on, wrap if necessary or flag next to wrap */
5105 if (curColumn
> (idealWrap
-1)) {
5107 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
5111 TRACE("Result - %d rows\n", curRow
+ 1);
5113 /* recalculate toolbar */
5114 TOOLBAR_CalcToolbar (infoPtr
);
5116 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
5117 if NORESIZE is NOT set, then the toolbar will always be resized to
5118 take up the whole window. With it set, sizing needs to be manual. */
5119 if (infoPtr
->dwStyle
& CCS_NORESIZE
) {
5120 SetWindowPos(infoPtr
->hwndSelf
, NULL
, 0, 0,
5121 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
5122 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
,
5123 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
5126 /* repaint toolbar */
5127 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5130 /* return bounding rectangle */
5132 lprc
->left
= infoPtr
->rcBound
.left
;
5133 lprc
->right
= infoPtr
->rcBound
.right
;
5134 lprc
->top
= infoPtr
->rcBound
.top
;
5135 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
5143 TOOLBAR_SetState (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
5145 TBUTTON_INFO
*btnPtr
;
5148 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
5152 btnPtr
= &infoPtr
->buttons
[nIndex
];
5154 /* if hidden state has changed the invalidate entire window and recalc */
5155 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
5156 btnPtr
->fsState
= LOWORD(lParam
);
5157 TOOLBAR_CalcToolbar (infoPtr
);
5158 InvalidateRect(infoPtr
->hwndSelf
, 0, TRUE
);
5162 /* process state changing if current state doesn't match new state */
5163 if(btnPtr
->fsState
!= LOWORD(lParam
))
5165 btnPtr
->fsState
= LOWORD(lParam
);
5166 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5172 static inline void unwrap(TOOLBAR_INFO
*info
)
5176 for (i
= 0; i
< info
->nNumButtons
; i
++)
5177 info
->buttons
[i
].fsState
&= ~TBSTATE_WRAP
;
5181 TOOLBAR_SetStyle (TOOLBAR_INFO
*infoPtr
, DWORD style
)
5183 DWORD dwOldStyle
= infoPtr
->dwStyle
;
5185 TRACE("new style 0x%08x\n", style
);
5187 if (style
& TBSTYLE_LIST
)
5188 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
5190 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
5192 infoPtr
->dwStyle
= style
;
5193 TOOLBAR_CheckStyle(infoPtr
);
5195 if ((dwOldStyle
^ style
) & TBSTYLE_WRAPABLE
)
5197 if (dwOldStyle
& TBSTYLE_WRAPABLE
)
5199 TOOLBAR_CalcToolbar(infoPtr
);
5201 else if ((dwOldStyle
^ style
) & CCS_VERT
)
5202 TOOLBAR_LayoutToolbar(infoPtr
);
5204 /* only resize if one of the CCS_* styles was changed */
5205 if ((dwOldStyle
^ style
) & COMMON_STYLES
)
5207 TOOLBAR_AutoSize(infoPtr
);
5208 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5215 static inline LRESULT
5216 TOOLBAR_SetToolTips (TOOLBAR_INFO
*infoPtr
, HWND hwndTooltip
)
5218 TRACE("hwnd=%p, hwndTooltip=%p\n", infoPtr
->hwndSelf
, hwndTooltip
);
5220 infoPtr
->hwndToolTip
= hwndTooltip
;
5226 TOOLBAR_SetUnicodeFormat (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
5230 TRACE("%s hwnd=%p\n",
5231 ((BOOL
)wParam
) ? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
5233 bTemp
= infoPtr
->bUnicode
;
5234 infoPtr
->bUnicode
= (BOOL
)wParam
;
5241 TOOLBAR_GetColorScheme (const TOOLBAR_INFO
*infoPtr
, LPCOLORSCHEME lParam
)
5243 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
5244 comctl32_color
.clrBtnHighlight
:
5245 infoPtr
->clrBtnHighlight
;
5246 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
5247 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
5253 TOOLBAR_SetColorScheme (TOOLBAR_INFO
*infoPtr
, const COLORSCHEME
*lParam
)
5255 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5256 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
5257 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
5259 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
5260 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
5261 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5267 TOOLBAR_SetVersion (TOOLBAR_INFO
*infoPtr
, INT iVersion
)
5269 INT iOldVersion
= infoPtr
->iVersion
;
5271 infoPtr
->iVersion
= iVersion
;
5273 if (infoPtr
->iVersion
>= 5)
5274 TOOLBAR_SetUnicodeFormat(infoPtr
, TRUE
);
5281 TOOLBAR_GetStringA (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPSTR str
)
5283 WORD iString
= HIWORD(wParam
);
5284 WORD buffersize
= LOWORD(wParam
);
5287 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, buffersize
, str
);
5289 if (iString
< infoPtr
->nNumStrings
)
5291 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
5294 TRACE("returning %s\n", debugstr_a(str
));
5297 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5304 TOOLBAR_GetStringW (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPWSTR str
)
5306 WORD iString
= HIWORD(wParam
);
5307 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5310 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, LOWORD(wParam
), str
);
5312 if (iString
< infoPtr
->nNumStrings
)
5314 len
= min(len
, strlenW(infoPtr
->strings
[iString
]));
5315 ret
= (len
+1)*sizeof(WCHAR
);
5318 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5323 TRACE("returning %s\n", debugstr_w(str
));
5326 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5331 static LRESULT
TOOLBAR_SetBoundingSize(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5333 SIZE
* pSize
= (SIZE
*)lParam
;
5334 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5338 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5339 * caller to specify a reason why the hot item changed (rather than just the
5340 * HICF_OTHER that TB_SETHOTITEM sends). */
5342 TOOLBAR_SetHotItem2 (TOOLBAR_INFO
*infoPtr
, INT nHotItem
, LPARAM lParam
)
5344 INT nOldHotItem
= infoPtr
->nHotItem
;
5346 TRACE("old item=%d, new item=%d, flags=%08x\n",
5347 nOldHotItem
, nHotItem
, (DWORD
)lParam
);
5349 if (nHotItem
< 0 || nHotItem
> infoPtr
->nNumButtons
)
5352 /* NOTE: an application can still remove the hot item even if anchor
5353 * highlighting is enabled */
5355 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, lParam
);
5357 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5360 /* Sets the toolbar global iListGap parameter which controls the amount of
5361 * spacing between the image and the text of buttons for TBSTYLE_LIST
5363 static LRESULT
TOOLBAR_SetListGap(TOOLBAR_INFO
*infoPtr
, INT iListGap
)
5365 TRACE("hwnd=%p iListGap=%d\n", infoPtr
->hwndSelf
, iListGap
);
5367 infoPtr
->iListGap
= iListGap
;
5369 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5374 /* Returns the number of maximum number of image lists associated with the
5375 * various states. */
5376 static LRESULT
TOOLBAR_GetImageListCount(const TOOLBAR_INFO
*infoPtr
)
5378 TRACE("hwnd=%p\n", infoPtr
->hwndSelf
);
5380 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5384 TOOLBAR_GetIdealSize (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5386 LPSIZE lpsize
= (LPSIZE
)lParam
;
5392 * Testing shows the following:
5393 * wParam = 0 adjust cx value
5394 * = 1 set cy value to max size.
5395 * lParam pointer to SIZE structure
5398 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5399 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5403 if (lpsize
->cx
== -1) {
5404 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5406 else if(HIWORD(lpsize
->cx
)) {
5408 HWND hwndParent
= GetParent(infoPtr
->hwndSelf
);
5410 GetWindowRect(infoPtr
->hwndSelf
, &rc
);
5411 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5412 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc
));
5413 lpsize
->cx
= max(rc
.right
-rc
.left
,
5414 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5417 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5421 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5424 FIXME("Unknown wParam %ld\n", wParam
);
5427 TRACE("set to -> 0x%08x 0x%08x\n",
5428 lpsize
->cx
, lpsize
->cy
);
5432 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5434 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5436 InvalidateRect(hwnd
, NULL
, TRUE
);
5442 TOOLBAR_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
5444 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
5447 TRACE("hwnd = %p, style=0x%08x\n", hwnd
, lpcs
->style
);
5449 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5450 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5451 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5452 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_REQUERY
));
5453 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5455 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5456 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5458 OpenThemeData (hwnd
, themeClass
);
5460 TOOLBAR_CheckStyle (infoPtr
);
5467 TOOLBAR_Destroy (TOOLBAR_INFO
*infoPtr
)
5471 /* delete tooltip control */
5472 if (infoPtr
->hwndToolTip
)
5473 DestroyWindow (infoPtr
->hwndToolTip
);
5475 /* delete temporary buffer for tooltip text */
5476 Free (infoPtr
->pszTooltipText
);
5477 Free (infoPtr
->bitmaps
); /* bitmaps list */
5479 /* delete button data */
5480 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5481 free_string( infoPtr
->buttons
+ i
);
5482 Free (infoPtr
->buttons
);
5484 /* delete strings */
5485 if (infoPtr
->strings
) {
5486 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5487 Free (infoPtr
->strings
[i
]);
5489 Free (infoPtr
->strings
);
5492 /* destroy internal image list */
5493 if (infoPtr
->himlInt
)
5494 ImageList_Destroy (infoPtr
->himlInt
);
5496 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5497 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5498 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5500 /* delete default font */
5501 DeleteObject (infoPtr
->hDefaultFont
);
5503 CloseThemeData (GetWindowTheme (infoPtr
->hwndSelf
));
5505 /* free toolbar info data */
5506 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
5514 TOOLBAR_EraseBackground (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5516 NMTBCUSTOMDRAW tbcd
;
5519 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
5520 DWORD dwEraseCustDraw
= 0;
5522 /* the app has told us not to redraw the toolbar */
5523 if (!infoPtr
->bDoRedraw
)
5526 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5527 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5528 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5529 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5530 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5531 dwEraseCustDraw
= ntfret
& 0xffff;
5533 /* FIXME: in general the return flags *can* be or'ed together */
5534 switch (dwEraseCustDraw
)
5536 case CDRF_DODEFAULT
:
5538 case CDRF_SKIPDEFAULT
:
5541 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5542 infoPtr
->hwndSelf
, ntfret
);
5546 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5547 * to my parent for processing.
5549 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5551 HDC hdc
= (HDC
)wParam
;
5556 parent
= GetParent(infoPtr
->hwndSelf
);
5557 MapWindowPoints(infoPtr
->hwndSelf
, parent
, &pt
, 1);
5558 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5559 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5560 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5563 ret
= DefWindowProcW (infoPtr
->hwndSelf
, WM_ERASEBKGND
, wParam
, lParam
);
5565 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5566 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5567 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5568 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5569 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5570 dwEraseCustDraw
= ntfret
& 0xffff;
5571 switch (dwEraseCustDraw
)
5573 case CDRF_DODEFAULT
:
5575 case CDRF_SKIPDEFAULT
:
5578 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5579 infoPtr
->hwndSelf
, ntfret
);
5586 static inline LRESULT
5587 TOOLBAR_GetFont (const TOOLBAR_INFO
*infoPtr
)
5589 return (LRESULT
)infoPtr
->hFont
;
5594 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5597 INT nNewHotItem
= infoPtr
->nHotItem
;
5599 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5602 if ((nNewHotItem
+ iDirection
< 0) ||
5603 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5605 NMTBWRAPHOTITEM nmtbwhi
;
5606 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5607 nmtbwhi
.iDirection
= iDirection
;
5608 nmtbwhi
.dwReason
= dwReason
;
5610 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5614 nNewHotItem
+= iDirection
;
5615 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5617 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5618 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5620 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5627 TOOLBAR_KeyDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5631 nmkey
.nVKey
= (UINT
)wParam
;
5632 nmkey
.uFlags
= HIWORD(lParam
);
5634 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5635 return DefWindowProcW(infoPtr
->hwndSelf
, WM_KEYDOWN
, wParam
, lParam
);
5637 switch ((UINT
)wParam
)
5641 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5645 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5649 if ((infoPtr
->nHotItem
>= 0) &&
5650 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5652 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5653 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5654 (LPARAM
)infoPtr
->hwndSelf
);
5664 TOOLBAR_LButtonDblClk (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5669 pt
.x
= (short)LOWORD(lParam
);
5670 pt
.y
= (short)HIWORD(lParam
);
5671 TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5674 TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
5675 else if (infoPtr
->dwStyle
& CCS_ADJUSTABLE
)
5676 TOOLBAR_Customize (infoPtr
);
5683 TOOLBAR_LButtonDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5685 TBUTTON_INFO
*btnPtr
;
5690 BOOL bDragKeyPressed
;
5695 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5696 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5698 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5700 if (infoPtr
->hwndToolTip
)
5701 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5702 WM_LBUTTONDOWN
, wParam
, lParam
);
5704 pt
.x
= (short)LOWORD(lParam
);
5705 pt
.y
= (short)HIWORD(lParam
);
5706 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5710 btnPtr
= &infoPtr
->buttons
[nHit
];
5712 if (bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5714 infoPtr
->nButtonDrag
= nHit
;
5715 SetCapture (infoPtr
->hwndSelf
);
5717 /* If drag cursor has not been loaded, load it.
5718 * Note: it doesn't need to be freed */
5720 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5721 SetCursor(hCursorDrag
);
5726 infoPtr
->nOldHit
= nHit
;
5728 arrowRect
= btnPtr
->rect
;
5729 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5731 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5732 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5733 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5734 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5735 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5736 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5740 /* draw in pressed state */
5741 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5742 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5744 btnPtr
->bDropDownPressed
= TRUE
;
5745 RedrawWindow(infoPtr
->hwndSelf
, &btnPtr
->rect
, 0, RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5747 memset(&nmtb
, 0, sizeof(nmtb
));
5748 nmtb
.iItem
= btnPtr
->idCommand
;
5749 nmtb
.rcButton
= btnPtr
->rect
;
5750 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
, TBN_DROPDOWN
);
5751 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5753 if (res
!= TBDDRET_TREATPRESSED
)
5757 /* redraw button in unpressed state */
5758 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5759 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5761 btnPtr
->bDropDownPressed
= FALSE
;
5762 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5764 /* find and set hot item */
5766 ScreenToClient(infoPtr
->hwndSelf
, &pt
);
5767 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5768 if (!infoPtr
->bAnchor
|| button
)
5769 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5771 /* remove any left mouse button down or double-click messages
5772 * so that we can get a toggle effect on the button */
5773 while (PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5774 PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5779 /* otherwise drop through and process as pushed */
5781 infoPtr
->bCaptured
= TRUE
;
5782 infoPtr
->nButtonDown
= nHit
;
5783 infoPtr
->bDragOutSent
= FALSE
;
5785 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5787 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5789 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5790 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5791 UpdateWindow(infoPtr
->hwndSelf
);
5792 SetCapture (infoPtr
->hwndSelf
);
5795 memset(&nmtb
, 0, sizeof(nmtb
));
5796 nmtb
.iItem
= btnPtr
->idCommand
;
5797 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5800 nmmouse
.dwHitInfo
= nHit
;
5802 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5804 nmmouse
.dwItemSpec
= -1;
5807 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5808 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5811 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5814 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5815 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, wParam
, lParam
);
5821 TOOLBAR_LButtonUp (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5823 TBUTTON_INFO
*btnPtr
;
5832 if (infoPtr
->hwndToolTip
)
5833 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5834 WM_LBUTTONUP
, wParam
, lParam
);
5836 pt
.x
= (short)LOWORD(lParam
);
5837 pt
.y
= (short)HIWORD(lParam
);
5838 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5840 if (!infoPtr
->bAnchor
|| button
)
5841 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5843 if (infoPtr
->nButtonDrag
>= 0) {
5847 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5850 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5852 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5853 if (PtInRect(&rcClient
, pt
))
5860 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5863 if (nButton
== infoPtr
->nButtonDrag
)
5865 /* if the button is moved sightly left and we have a
5866 * separator there then remove it */
5867 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5869 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5870 TOOLBAR_DeleteButton(infoPtr
, nButton
- 1);
5872 else /* else insert a separator before the dragged button */
5875 memset(&tbb
, 0, sizeof(tbb
));
5876 tbb
.fsStyle
= BTNS_SEP
;
5878 TOOLBAR_InsertButtonT(infoPtr
, nButton
, &tbb
, TRUE
);
5885 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5886 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, 0);
5888 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5891 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, nButton
);
5896 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5897 TOOLBAR_DeleteButton(infoPtr
, infoPtr
->nButtonDrag
);
5900 /* button under cursor changed so need to re-set hot item */
5901 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5902 infoPtr
->nButtonDrag
= -1;
5904 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5906 else if (infoPtr
->nButtonDown
>= 0) {
5907 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5908 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5910 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5911 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5912 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5914 if ((nOldIndex
!= nHit
) &&
5916 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5917 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5920 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5921 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5923 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5927 if (nOldIndex
!= -1)
5928 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5931 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5932 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5933 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5935 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5937 infoPtr
->nButtonDown
= -1;
5939 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5940 TOOLBAR_SendNotify (&hdr
, infoPtr
,
5941 NM_RELEASEDCAPTURE
);
5943 memset(&nmtb
, 0, sizeof(nmtb
));
5944 nmtb
.iItem
= btnPtr
->idCommand
;
5945 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5948 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5950 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5951 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)infoPtr
->hwndSelf
);
5953 /* In case we have just been destroyed... */
5954 if(!IsWindow(infoPtr
->hwndSelf
))
5959 /* !!! Undocumented - toolbar at 4.71 level and above sends
5960 * NM_CLICK with the NMMOUSE structure. */
5961 nmmouse
.dwHitInfo
= nHit
;
5964 nmmouse
.dwItemSpec
= -1;
5967 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5968 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5971 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5974 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5975 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONUP
, wParam
, lParam
);
5981 TOOLBAR_RButtonUp(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5988 pt
.x
= (short)LOWORD(lParam
);
5989 pt
.y
= (short)HIWORD(lParam
);
5991 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5992 nmmouse
.dwHitInfo
= nHit
;
5995 nmmouse
.dwItemSpec
= -1;
5997 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5998 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
6001 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
6004 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
6005 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONUP
, wParam
, lParam
);
6011 TOOLBAR_RButtonDblClk( TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6015 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
6016 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
6022 TOOLBAR_CaptureChanged(TOOLBAR_INFO
*infoPtr
)
6024 TBUTTON_INFO
*btnPtr
;
6026 infoPtr
->bCaptured
= FALSE
;
6028 if (infoPtr
->nButtonDown
>= 0)
6030 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6031 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6033 infoPtr
->nOldHit
= -1;
6035 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
6036 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6042 TOOLBAR_MouseLeave (TOOLBAR_INFO
*infoPtr
)
6044 /* don't remove hot effects when in anchor highlighting mode or when a
6045 * drop-down button is pressed */
6046 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
6048 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
6049 if (!hotBtnPtr
->bDropDownPressed
)
6050 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
6053 if (infoPtr
->nOldHit
< 0)
6056 /* If the last button we were over is depressed then make it not */
6057 /* depressed and redraw it */
6058 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
6060 TBUTTON_INFO
*btnPtr
;
6063 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6065 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6068 InflateRect (&rc1
, 1, 1);
6069 InvalidateRect (infoPtr
->hwndSelf
, &rc1
, TRUE
);
6072 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
6075 ZeroMemory(&nmt
, sizeof(nmt
));
6076 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6077 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6078 infoPtr
->bDragOutSent
= TRUE
;
6081 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
6087 TOOLBAR_MouseMove (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6090 TRACKMOUSEEVENT trackinfo
;
6092 TBUTTON_INFO
*btnPtr
;
6095 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
6096 TOOLBAR_TooltipCreateControl(infoPtr
);
6098 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
6099 /* fill in the TRACKMOUSEEVENT struct */
6100 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
6101 trackinfo
.dwFlags
= TME_QUERY
;
6103 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6104 _TrackMouseEvent(&trackinfo
);
6106 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6107 if(trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
6108 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
6109 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
6111 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6112 /* and can properly deactivate the hot toolbar button */
6113 _TrackMouseEvent(&trackinfo
);
6117 if (infoPtr
->hwndToolTip
)
6118 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
6119 WM_MOUSEMOVE
, wParam
, lParam
);
6121 pt
.x
= (short)LOWORD(lParam
);
6122 pt
.y
= (short)HIWORD(lParam
);
6124 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
6126 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6127 && (!infoPtr
->bAnchor
|| button
))
6128 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
);
6130 if (infoPtr
->nOldHit
!= nHit
)
6132 if (infoPtr
->bCaptured
)
6134 if (!infoPtr
->bDragOutSent
)
6137 ZeroMemory(&nmt
, sizeof(nmt
));
6138 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6139 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6140 infoPtr
->bDragOutSent
= TRUE
;
6143 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6144 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
6145 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6146 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6148 else if (nHit
== infoPtr
->nButtonDown
) {
6149 btnPtr
->fsState
|= TBSTATE_PRESSED
;
6150 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6152 infoPtr
->nOldHit
= nHit
;
6160 static inline LRESULT
6161 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6163 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6164 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
6166 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6170 static inline LRESULT
6171 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6173 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
6174 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
6176 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
6181 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
6183 TOOLBAR_INFO
*infoPtr
;
6186 /* allocate memory for info structure */
6187 infoPtr
= Alloc (sizeof(TOOLBAR_INFO
));
6188 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
6191 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
6194 /* initialize info structure */
6195 infoPtr
->nButtonWidth
= 23;
6196 infoPtr
->nButtonHeight
= 22;
6197 infoPtr
->nBitmapHeight
= 16;
6198 infoPtr
->nBitmapWidth
= 16;
6200 infoPtr
->nMaxTextRows
= 1;
6201 infoPtr
->cxMin
= -1;
6202 infoPtr
->cxMax
= -1;
6203 infoPtr
->nNumBitmaps
= 0;
6204 infoPtr
->nNumStrings
= 0;
6206 infoPtr
->bCaptured
= FALSE
;
6207 infoPtr
->nButtonDown
= -1;
6208 infoPtr
->nButtonDrag
= -1;
6209 infoPtr
->nOldHit
= -1;
6210 infoPtr
->nHotItem
= -1;
6211 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
6212 infoPtr
->dwDTFlags
= (lpcs
->style
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
6213 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
6214 infoPtr
->bDragOutSent
= FALSE
;
6215 infoPtr
->iVersion
= 0;
6216 infoPtr
->hwndSelf
= hwnd
;
6217 infoPtr
->bDoRedraw
= TRUE
;
6218 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
6219 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
6220 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
6221 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
6223 infoPtr
->szSpacing
.cx
= DEFSPACE_CX
;
6224 infoPtr
->szSpacing
.cy
= DEFSPACE_CY
;
6226 infoPtr
->iListGap
= DEFLISTGAP
;
6227 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
6228 infoPtr
->dwStyle
= lpcs
->style
;
6229 infoPtr
->tbim
.iButton
= -1;
6231 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6232 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
6233 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
6234 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
6237 /* I think the code below is a bug, but it is the way that the native
6238 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6239 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6240 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6241 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6242 * Somehow, the only cases of this seem to be MFC programs.
6244 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6245 * does not occur in the WM_STYLECHANGING routine.
6246 * (Guy Albertelli 9/2001)
6249 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6250 && !(lpcs
->style
& TBSTYLE_TRANSPARENT
))
6251 styleadd
|= TBSTYLE_TRANSPARENT
;
6252 if (!(lpcs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
6253 styleadd
|= CCS_TOP
; /* default to top */
6254 SetWindowLongW (hwnd
, GWL_STYLE
, lpcs
->style
| styleadd
);
6257 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
6262 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6264 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
6268 if (dwStyle
& WS_MINIMIZE
)
6269 return 0; /* Nothing to do */
6271 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
6273 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
6276 if (!(dwStyle
& CCS_NODIVIDER
))
6278 GetWindowRect (hwnd
, &rcWindow
);
6279 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
6280 if( dwStyle
& WS_BORDER
)
6281 InflateRect (&rcWindow
, -1, -1);
6282 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6285 ReleaseDC( hwnd
, hdc
);
6291 /* handles requests from the tooltip control on what text to display */
6292 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6294 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6296 TRACE("button index = %d\n", index
);
6298 Free (infoPtr
->pszTooltipText
);
6299 infoPtr
->pszTooltipText
= NULL
;
6304 if (infoPtr
->bUnicode
)
6306 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6307 NMTBGETINFOTIPW tbgit
;
6308 unsigned int len
; /* in chars */
6310 wszBuffer
[0] = '\0';
6311 wszBuffer
[INFOTIPSIZE
] = '\0';
6313 tbgit
.pszText
= wszBuffer
;
6314 tbgit
.cchTextMax
= INFOTIPSIZE
;
6315 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6316 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6318 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6320 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6322 len
= strlenW(tbgit
.pszText
);
6323 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6325 /* need to allocate temporary buffer in infoPtr as there
6326 * isn't enough space in buffer passed to us by the
6327 * tooltip control */
6328 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6329 if (infoPtr
->pszTooltipText
)
6331 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6332 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6338 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6344 CHAR szBuffer
[INFOTIPSIZE
+1];
6345 NMTBGETINFOTIPA tbgit
;
6346 unsigned int len
; /* in chars */
6349 szBuffer
[INFOTIPSIZE
] = '\0';
6351 tbgit
.pszText
= szBuffer
;
6352 tbgit
.cchTextMax
= INFOTIPSIZE
;
6353 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6354 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6356 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6358 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6360 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6361 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]))
6363 /* need to allocate temporary buffer in infoPtr as there
6364 * isn't enough space in buffer passed to us by the
6365 * tooltip control */
6366 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6367 if (infoPtr
->pszTooltipText
)
6369 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6370 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6374 else if (tbgit
.pszText
&& tbgit
.pszText
[0])
6376 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1,
6377 lpnmtdi
->lpszText
, sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]));
6382 /* if button has text, but it is not shown then automatically
6383 * use that text as tooltip */
6384 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6385 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6387 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6388 unsigned int len
= pszText
? strlenW(pszText
) : 0;
6390 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6392 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6394 /* need to allocate temporary buffer in infoPtr as there
6395 * isn't enough space in buffer passed to us by the
6396 * tooltip control */
6397 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6398 if (infoPtr
->pszTooltipText
)
6400 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6401 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6407 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6412 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6414 /* last resort: send notification on to app */
6415 /* FIXME: find out what is really used here */
6416 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmtdi
->hdr
.idFrom
, (LPARAM
)lpnmtdi
);
6420 static inline LRESULT
6421 TOOLBAR_Notify (TOOLBAR_INFO
*infoPtr
, LPNMHDR lpnmh
)
6423 switch (lpnmh
->code
)
6427 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lpnmh
;
6429 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6430 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6431 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6435 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6436 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6444 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lpnmh
;
6446 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6447 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6448 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6449 lppgs
->iScroll
, lppgs
->iDir
);
6453 case TTN_GETDISPINFOW
:
6454 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lpnmh
);
6456 case TTN_GETDISPINFOA
:
6457 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6467 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6471 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam
, lParam
);
6473 if (lParam
== NF_QUERY
)
6476 if (lParam
== NF_REQUERY
) {
6477 format
= SendMessageW(infoPtr
->hwndNotify
,
6478 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6479 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6480 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6491 TOOLBAR_Paint (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6496 /* fill ps.rcPaint with a default rect */
6497 ps
.rcPaint
= infoPtr
->rcBound
;
6499 hdc
= wParam
==0 ? BeginPaint(infoPtr
->hwndSelf
, &ps
) : (HDC
)wParam
;
6501 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps
.rcPaint
));
6503 TOOLBAR_Refresh (infoPtr
, hdc
, &ps
);
6504 if (!wParam
) EndPaint (infoPtr
->hwndSelf
, &ps
);
6511 TOOLBAR_SetFocus (TOOLBAR_INFO
*infoPtr
)
6513 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6515 /* make first item hot */
6516 if (infoPtr
->nNumButtons
> 0)
6517 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6523 TOOLBAR_SetFont(TOOLBAR_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
6525 TRACE("font=%p redraw=%d\n", hFont
, Redraw
);
6528 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6530 infoPtr
->hFont
= hFont
;
6532 TOOLBAR_CalcToolbar(infoPtr
);
6535 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6540 TOOLBAR_SetRedraw (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6541 /*****************************************************
6544 * Handles the WM_SETREDRAW message.
6547 * According to testing V4.71 of COMCTL32 returns the
6548 * *previous* status of the redraw flag (either 0 or 1)
6549 * instead of the MSDN documented value of 0 if handled.
6550 * (For laughs see the "consistency" with same function
6553 *****************************************************/
6555 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6557 TRACE("set to %s\n",
6558 (wParam
) ? "TRUE" : "FALSE");
6559 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6561 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6563 return (oldredraw
) ? 1 : 0;
6568 TOOLBAR_Size (TOOLBAR_INFO
*infoPtr
)
6570 TRACE("sizing toolbar!\n");
6572 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6574 RECT delta_width
, delta_height
, client
, dummy
;
6575 DWORD min_x
, max_x
, min_y
, max_y
;
6576 TBUTTON_INFO
*btnPtr
;
6579 GetClientRect(infoPtr
->hwndSelf
, &client
);
6580 if(client
.right
> infoPtr
->client_rect
.right
)
6582 min_x
= infoPtr
->client_rect
.right
;
6583 max_x
= client
.right
;
6587 max_x
= infoPtr
->client_rect
.right
;
6588 min_x
= client
.right
;
6590 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6592 min_y
= infoPtr
->client_rect
.bottom
;
6593 max_y
= client
.bottom
;
6597 max_y
= infoPtr
->client_rect
.bottom
;
6598 min_y
= client
.bottom
;
6601 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6602 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6604 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6605 btnPtr
= infoPtr
->buttons
;
6606 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6607 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6608 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6609 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6611 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->client_rect
);
6612 TOOLBAR_AutoSize(infoPtr
);
6618 TOOLBAR_StyleChanged (TOOLBAR_INFO
*infoPtr
, INT nType
, const STYLESTRUCT
*lpStyle
)
6620 if (nType
== GWL_STYLE
)
6621 return TOOLBAR_SetStyle(infoPtr
, lpStyle
->styleNew
);
6628 TOOLBAR_SysColorChange (void)
6630 COMCTL32_RefreshSysColors();
6636 /* update theme after a WM_THEMECHANGED message */
6637 static LRESULT
theme_changed (HWND hwnd
)
6639 HTHEME theme
= GetWindowTheme (hwnd
);
6640 CloseThemeData (theme
);
6641 OpenThemeData (hwnd
, themeClass
);
6646 static LRESULT WINAPI
6647 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6649 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
6651 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6652 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6654 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6655 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6660 return TOOLBAR_AddBitmap (infoPtr
, (INT
)wParam
, (TBADDBITMAP
*)lParam
);
6662 case TB_ADDBUTTONSA
:
6663 case TB_ADDBUTTONSW
:
6664 return TOOLBAR_AddButtonsT (infoPtr
, wParam
, (LPTBBUTTON
)lParam
,
6665 uMsg
== TB_ADDBUTTONSW
);
6667 return TOOLBAR_AddStringA (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6670 return TOOLBAR_AddStringW (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6673 return TOOLBAR_AutoSize (infoPtr
);
6675 case TB_BUTTONCOUNT
:
6676 return TOOLBAR_ButtonCount (infoPtr
);
6678 case TB_BUTTONSTRUCTSIZE
:
6679 return TOOLBAR_ButtonStructSize (infoPtr
, wParam
);
6681 case TB_CHANGEBITMAP
:
6682 return TOOLBAR_ChangeBitmap (infoPtr
, wParam
, LOWORD(lParam
));
6684 case TB_CHECKBUTTON
:
6685 return TOOLBAR_CheckButton (infoPtr
, wParam
, lParam
);
6687 case TB_COMMANDTOINDEX
:
6688 return TOOLBAR_CommandToIndex (infoPtr
, wParam
);
6691 return TOOLBAR_Customize (infoPtr
);
6693 case TB_DELETEBUTTON
:
6694 return TOOLBAR_DeleteButton (infoPtr
, wParam
);
6696 case TB_ENABLEBUTTON
:
6697 return TOOLBAR_EnableButton (infoPtr
, wParam
, lParam
);
6699 case TB_GETANCHORHIGHLIGHT
:
6700 return TOOLBAR_GetAnchorHighlight (infoPtr
);
6703 return TOOLBAR_GetBitmap (infoPtr
, wParam
);
6705 case TB_GETBITMAPFLAGS
:
6706 return TOOLBAR_GetBitmapFlags ();
6709 return TOOLBAR_GetButton (infoPtr
, wParam
, (TBBUTTON
*)lParam
);
6711 case TB_GETBUTTONINFOA
:
6712 case TB_GETBUTTONINFOW
:
6713 return TOOLBAR_GetButtonInfoT (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6714 uMsg
== TB_GETBUTTONINFOW
);
6715 case TB_GETBUTTONSIZE
:
6716 return TOOLBAR_GetButtonSize (infoPtr
);
6718 case TB_GETBUTTONTEXTA
:
6719 case TB_GETBUTTONTEXTW
:
6720 return TOOLBAR_GetButtonText (infoPtr
, wParam
, (LPWSTR
)lParam
,
6721 uMsg
== TB_GETBUTTONTEXTW
);
6723 case TB_GETDISABLEDIMAGELIST
:
6724 return TOOLBAR_GetDisabledImageList (infoPtr
, wParam
);
6726 case TB_GETEXTENDEDSTYLE
:
6727 return TOOLBAR_GetExtendedStyle (infoPtr
);
6729 case TB_GETHOTIMAGELIST
:
6730 return TOOLBAR_GetHotImageList (infoPtr
, wParam
);
6733 return TOOLBAR_GetHotItem (infoPtr
);
6735 case TB_GETIMAGELIST
:
6736 return TOOLBAR_GetDefImageList (infoPtr
, wParam
);
6738 case TB_GETINSERTMARK
:
6739 return TOOLBAR_GetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6741 case TB_GETINSERTMARKCOLOR
:
6742 return TOOLBAR_GetInsertMarkColor (infoPtr
);
6744 case TB_GETITEMRECT
:
6745 return TOOLBAR_GetItemRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6748 return TOOLBAR_GetMaxSize (infoPtr
, (LPSIZE
)lParam
);
6751 return TOOLBAR_GetMetrics (infoPtr
, (TBMETRICS
*)lParam
);
6754 /* case TB_GETOBJECT: */ /* 4.71 */
6757 return TOOLBAR_GetPadding (infoPtr
);
6760 return TOOLBAR_GetRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6763 return TOOLBAR_GetRows (infoPtr
);
6766 return TOOLBAR_GetState (infoPtr
, wParam
);
6769 return TOOLBAR_GetStringA (infoPtr
, wParam
, (LPSTR
)lParam
);
6772 return TOOLBAR_GetStringW (infoPtr
, wParam
, (LPWSTR
)lParam
);
6775 return TOOLBAR_GetStyle (infoPtr
);
6777 case TB_GETTEXTROWS
:
6778 return TOOLBAR_GetTextRows (infoPtr
);
6780 case TB_GETTOOLTIPS
:
6781 return TOOLBAR_GetToolTips (infoPtr
);
6783 case TB_GETUNICODEFORMAT
:
6784 return TOOLBAR_GetUnicodeFormat (infoPtr
);
6787 return TOOLBAR_HideButton (infoPtr
, wParam
, LOWORD(lParam
));
6790 return TOOLBAR_HitTest (infoPtr
, (LPPOINT
)lParam
);
6792 case TB_INDETERMINATE
:
6793 return TOOLBAR_Indeterminate (infoPtr
, wParam
, LOWORD(lParam
));
6795 case TB_INSERTBUTTONA
:
6796 case TB_INSERTBUTTONW
:
6797 return TOOLBAR_InsertButtonT(infoPtr
, wParam
, (TBBUTTON
*)lParam
,
6798 uMsg
== TB_INSERTBUTTONW
);
6800 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6802 case TB_ISBUTTONCHECKED
:
6803 return TOOLBAR_IsButtonChecked (infoPtr
, wParam
);
6805 case TB_ISBUTTONENABLED
:
6806 return TOOLBAR_IsButtonEnabled (infoPtr
, wParam
);
6808 case TB_ISBUTTONHIDDEN
:
6809 return TOOLBAR_IsButtonHidden (infoPtr
, wParam
);
6811 case TB_ISBUTTONHIGHLIGHTED
:
6812 return TOOLBAR_IsButtonHighlighted (infoPtr
, wParam
);
6814 case TB_ISBUTTONINDETERMINATE
:
6815 return TOOLBAR_IsButtonIndeterminate (infoPtr
, wParam
);
6817 case TB_ISBUTTONPRESSED
:
6818 return TOOLBAR_IsButtonPressed (infoPtr
, wParam
);
6821 return TOOLBAR_LoadImages (infoPtr
, wParam
, (HINSTANCE
)lParam
);
6823 case TB_MAPACCELERATORA
:
6824 case TB_MAPACCELERATORW
:
6825 return TOOLBAR_MapAccelerator (infoPtr
, wParam
, (UINT
*)lParam
);
6828 return TOOLBAR_MarkButton (infoPtr
, wParam
, LOWORD(lParam
));
6831 return TOOLBAR_MoveButton (infoPtr
, wParam
, lParam
);
6833 case TB_PRESSBUTTON
:
6834 return TOOLBAR_PressButton (infoPtr
, wParam
, LOWORD(lParam
));
6836 case TB_REPLACEBITMAP
:
6837 return TOOLBAR_ReplaceBitmap (infoPtr
, (LPTBREPLACEBITMAP
)lParam
);
6839 case TB_SAVERESTOREA
:
6840 return TOOLBAR_SaveRestoreA (infoPtr
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6842 case TB_SAVERESTOREW
:
6843 return TOOLBAR_SaveRestoreW (infoPtr
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6845 case TB_SETANCHORHIGHLIGHT
:
6846 return TOOLBAR_SetAnchorHighlight (infoPtr
, (BOOL
)wParam
);
6848 case TB_SETBITMAPSIZE
:
6849 return TOOLBAR_SetBitmapSize (infoPtr
, wParam
, lParam
);
6851 case TB_SETBUTTONINFOA
:
6852 case TB_SETBUTTONINFOW
:
6853 return TOOLBAR_SetButtonInfo (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6854 uMsg
== TB_SETBUTTONINFOW
);
6855 case TB_SETBUTTONSIZE
:
6856 return TOOLBAR_SetButtonSize (infoPtr
, lParam
);
6858 case TB_SETBUTTONWIDTH
:
6859 return TOOLBAR_SetButtonWidth (infoPtr
, lParam
);
6862 return TOOLBAR_SetCmdId (infoPtr
, wParam
, lParam
);
6864 case TB_SETDISABLEDIMAGELIST
:
6865 return TOOLBAR_SetDisabledImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6867 case TB_SETDRAWTEXTFLAGS
:
6868 return TOOLBAR_SetDrawTextFlags (infoPtr
, wParam
, lParam
);
6870 case TB_SETEXTENDEDSTYLE
:
6871 return TOOLBAR_SetExtendedStyle (infoPtr
, wParam
, lParam
);
6873 case TB_SETHOTIMAGELIST
:
6874 return TOOLBAR_SetHotImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6877 return TOOLBAR_SetHotItem (infoPtr
, wParam
);
6879 case TB_SETIMAGELIST
:
6880 return TOOLBAR_SetImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6883 return TOOLBAR_SetIndent (infoPtr
, wParam
);
6885 case TB_SETINSERTMARK
:
6886 return TOOLBAR_SetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6888 case TB_SETINSERTMARKCOLOR
:
6889 return TOOLBAR_SetInsertMarkColor (infoPtr
, lParam
);
6891 case TB_SETMAXTEXTROWS
:
6892 return TOOLBAR_SetMaxTextRows (infoPtr
, wParam
);
6896 return TOOLBAR_SetMetrics (infoPtr
, (TBMETRICS
*)lParam
);
6900 return TOOLBAR_SetPadding (infoPtr
, lParam
);
6903 return TOOLBAR_SetParent (infoPtr
, (HWND
)wParam
);
6906 return TOOLBAR_SetRows (infoPtr
, wParam
, (LPRECT
)lParam
);
6909 return TOOLBAR_SetState (infoPtr
, wParam
, lParam
);
6912 return TOOLBAR_SetStyle (infoPtr
, lParam
);
6914 case TB_SETTOOLTIPS
:
6915 return TOOLBAR_SetToolTips (infoPtr
, (HWND
)wParam
);
6917 case TB_SETUNICODEFORMAT
:
6918 return TOOLBAR_SetUnicodeFormat (infoPtr
, wParam
);
6920 case TB_SETBOUNDINGSIZE
:
6921 return TOOLBAR_SetBoundingSize(hwnd
, wParam
, lParam
);
6923 case TB_SETHOTITEM2
:
6924 return TOOLBAR_SetHotItem2 (infoPtr
, wParam
, lParam
);
6927 return TOOLBAR_SetListGap(infoPtr
, wParam
);
6929 case TB_GETIMAGELISTCOUNT
:
6930 return TOOLBAR_GetImageListCount(infoPtr
);
6932 case TB_GETIDEALSIZE
:
6933 return TOOLBAR_GetIdealSize (infoPtr
, wParam
, lParam
);
6936 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6938 /* Common Control Messages */
6940 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6941 case CCM_GETCOLORSCHEME
:
6942 return TOOLBAR_GetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6944 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6945 case CCM_SETCOLORSCHEME
:
6946 return TOOLBAR_SetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6948 case CCM_GETVERSION
:
6949 return TOOLBAR_GetVersion (infoPtr
);
6951 case CCM_SETVERSION
:
6952 return TOOLBAR_SetVersion (infoPtr
, (INT
)wParam
);
6958 return TOOLBAR_Create (hwnd
, (CREATESTRUCTW
*)lParam
);
6961 return TOOLBAR_Destroy (infoPtr
);
6964 return TOOLBAR_EraseBackground (infoPtr
, wParam
, lParam
);
6967 return TOOLBAR_GetFont (infoPtr
);
6970 return TOOLBAR_KeyDown (infoPtr
, wParam
, lParam
);
6972 /* case WM_KILLFOCUS: */
6974 case WM_LBUTTONDBLCLK
:
6975 return TOOLBAR_LButtonDblClk (infoPtr
, wParam
, lParam
);
6977 case WM_LBUTTONDOWN
:
6978 return TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
6981 return TOOLBAR_LButtonUp (infoPtr
, wParam
, lParam
);
6984 return TOOLBAR_RButtonUp (infoPtr
, wParam
, lParam
);
6986 case WM_RBUTTONDBLCLK
:
6987 return TOOLBAR_RButtonDblClk (infoPtr
, wParam
, lParam
);
6990 return TOOLBAR_MouseMove (infoPtr
, wParam
, lParam
);
6993 return TOOLBAR_MouseLeave (infoPtr
);
6995 case WM_CAPTURECHANGED
:
6996 if (hwnd
== (HWND
)lParam
) return 0;
6997 return TOOLBAR_CaptureChanged(infoPtr
);
7000 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
7003 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
7006 return TOOLBAR_NCCreate (hwnd
, wParam
, (CREATESTRUCTW
*)lParam
);
7009 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
7012 return TOOLBAR_Notify (infoPtr
, (LPNMHDR
)lParam
);
7014 case WM_NOTIFYFORMAT
:
7015 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
7017 case WM_PRINTCLIENT
:
7019 return TOOLBAR_Paint (infoPtr
, wParam
);
7022 return TOOLBAR_SetFocus (infoPtr
);
7025 return TOOLBAR_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
7028 return TOOLBAR_SetRedraw (infoPtr
, wParam
);
7031 return TOOLBAR_Size (infoPtr
);
7033 case WM_STYLECHANGED
:
7034 return TOOLBAR_StyleChanged (infoPtr
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
7036 case WM_SYSCOLORCHANGE
:
7037 return TOOLBAR_SysColorChange ();
7039 case WM_THEMECHANGED
:
7041 return TOOLBAR_ThemeChanged(hwnd
);
7043 return theme_changed (hwnd
);
7046 /* case WM_WININICHANGE: */
7051 case WM_MEASUREITEM
:
7053 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
7055 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7056 case PGM_FORWARDMOUSE
:
7057 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7060 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
7061 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
7062 uMsg
, wParam
, lParam
);
7063 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7069 TOOLBAR_Register (void)
7073 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
7074 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
7075 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
7076 wndClass
.cbClsExtra
= 0;
7077 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
7078 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
7079 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
7080 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
7082 RegisterClassW (&wndClass
);
7087 TOOLBAR_Unregister (void)
7089 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
7092 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
7097 /* Check if the entry already exists */
7098 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
7100 /* If this is a new entry we must create it and insert into the array */
7105 c
= Alloc(sizeof(IMLENTRY
));
7108 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
7109 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
7124 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
7128 for (i
= 0; i
< *cies
; i
++)
7138 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
7146 for (i
= 0; i
< cies
; i
++)
7148 if (pies
[i
]->id
== id
)
7160 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
7162 HIMAGELIST himlDef
= 0;
7163 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
7166 himlDef
= pie
->himl
;
7172 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
7174 if (infoPtr
->bUnicode
)
7175 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
7182 nmtba
.iItem
= nmtb
->iItem
;
7183 nmtba
.pszText
= Buffer
;
7184 nmtba
.cchText
= 256;
7185 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
7187 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
7189 int ccht
= strlen(nmtba
.pszText
);
7191 MultiByteToWideChar(CP_ACP
, 0, nmtba
.pszText
, -1,
7192 nmtb
->pszText
, nmtb
->cchText
);
7194 nmtb
->tbButton
= nmtba
.tbButton
;
7203 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
)
7207 /* MSDN states that iItem is the index of the button, rather than the
7208 * command ID as used by every other NMTOOLBAR notification */
7210 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
7212 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);