4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
37 * - TB_INSERTMARKHITTEST
44 * - Button wrapping (under construction).
45 * - Fix TB_SETROWS and Separators.
46 * - iListGap custom draw support.
49 * - Run tests using Waite Group Windows95 API Bible Volume 2.
50 * The second cdrom contains executables addstr.exe, btncount.exe,
51 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
52 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
53 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
54 * setparnt.exe, setrows.exe, toolwnd.exe.
55 * - Microsoft's controlspy examples.
56 * - Charles Petzold's 'Programming Windows': gadgets.exe
58 * Differences between MSDN and actual native control operation:
59 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
60 * to the right of the bitmap. Otherwise, this style is
61 * identical to TBSTYLE_FLAT."
62 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
63 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
64 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
65 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
71 WINE_DEFAULT_DEBUG_CHANNEL(toolbar
);
73 static HCURSOR hCursorDrag
= NULL
;
82 BOOL bDropDownPressed
;
87 INT cx
; /* manually set size */
101 } IMLENTRY
, *PIMLENTRY
;
105 DWORD dwStructSize
; /* size of TBBUTTON struct */
107 RECT rcBound
; /* bounding rectangle */
113 INT nRows
; /* number of button rows */
114 INT nMaxTextRows
; /* maximum number of text rows */
115 INT cxMin
; /* minimum button width */
116 INT cxMax
; /* maximum button width */
117 INT nNumButtons
; /* number of buttons */
118 INT nNumBitmaps
; /* number of bitmaps */
119 INT nNumStrings
; /* number of strings */
121 INT nButtonDown
; /* toolbar button being pressed or -1 if none */
122 INT nButtonDrag
; /* toolbar button being dragged or -1 if none */
124 INT nHotItem
; /* index of the "hot" item */
125 SIZE szPadding
; /* padding values around button */
127 SIZE szBarPadding
; /* padding values around the toolbar (NOT USED BUT STORED) */
128 SIZE szSpacing
; /* spacing values between buttons */
130 INT iTopMargin
; /* the top margin */
131 INT iListGap
; /* default gap between text and image for toolbar with list style */
133 HFONT hFont
; /* text font */
134 HIMAGELIST himlInt
; /* image list created internally */
135 PIMLENTRY
*himlDef
; /* default image list array */
136 INT cimlDef
; /* default image list array count */
137 PIMLENTRY
*himlHot
; /* hot image list array */
138 INT cimlHot
; /* hot image list array count */
139 PIMLENTRY
*himlDis
; /* disabled image list array */
140 INT cimlDis
; /* disabled image list array count */
141 HWND hwndToolTip
; /* handle to tool tip control */
142 HWND hwndNotify
; /* handle to the window that gets notifications */
143 HWND hwndSelf
; /* my own handle */
144 BOOL bAnchor
; /* anchor highlight enabled */
145 BOOL bDoRedraw
; /* Redraw status */
146 BOOL bDragOutSent
; /* has TBN_DRAGOUT notification been sent for this drag? */
147 BOOL bUnicode
; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
148 BOOL bCaptured
; /* mouse captured? */
149 DWORD dwStyle
; /* regular toolbar style */
150 DWORD dwExStyle
; /* extended toolbar style */
151 DWORD dwDTFlags
; /* DrawText flags */
153 COLORREF clrInsertMark
; /* insert mark color */
154 COLORREF clrBtnHighlight
; /* color for Flat Separator */
155 COLORREF clrBtnShadow
; /* color for Flag Separator */
157 LPWSTR pszTooltipText
; /* temporary store for a string > 80 characters
158 * for TTN_GETDISPINFOW notification */
159 TBINSERTMARK tbim
; /* info on insertion mark */
160 TBUTTON_INFO
*buttons
; /* pointer to button array */
161 LPWSTR
*strings
; /* pointer to string array */
162 TBITMAP_INFO
*bitmaps
;
163 } TOOLBAR_INFO
, *PTOOLBAR_INFO
;
166 /* used by customization dialog */
169 PTOOLBAR_INFO tbInfo
;
171 } CUSTDLG_INFO
, *PCUSTDLG_INFO
;
179 } CUSTOMBUTTON
, *PCUSTOMBUTTON
;
188 #define SEPARATOR_WIDTH 8
190 #define BOTTOM_BORDER 2
191 #define DDARROW_WIDTH 11
192 #define ARROW_HEIGHT 3
193 #define INSERTMARK_WIDTH 2
195 /* default padding inside a button */
200 /* default space between buttons and between rows */
201 #define DEFSPACE_CX 7
202 #define DEFSPACE_CY 6
207 /* vertical padding used in list mode when image is present */
214 /* how wide to treat the bitmap if it isn't present */
215 #define NONLIST_NOTEXT_OFFSET 2
217 #define TOOLBAR_NOWHERE (-1)
219 /* Used to find undocumented extended styles */
220 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
221 TBSTYLE_EX_VERTICAL | \
222 TBSTYLE_EX_MIXEDBUTTONS | \
223 TBSTYLE_EX_DOUBLEBUFFER | \
224 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
226 /* all of the CCS_ styles */
227 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
228 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
230 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
231 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
232 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
233 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
234 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
236 static const WCHAR themeClass
[] = { 'T','o','o','l','b','a','r',0 };
238 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
);
239 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
);
240 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
);
241 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
);
242 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
);
243 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
);
244 static LRESULT
TOOLBAR_LButtonDown(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
);
245 static void TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
);
246 static LRESULT
TOOLBAR_AutoSize(TOOLBAR_INFO
*infoPtr
);
247 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
);
248 static void TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
249 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
250 static LRESULT
TOOLBAR_SetButtonInfo(TOOLBAR_INFO
*infoPtr
, INT Id
,
251 const TBBUTTONINFOW
*lptbbi
, BOOL isW
);
254 static inline int default_top_margin(const TOOLBAR_INFO
*infoPtr
)
257 return (infoPtr
->dwStyle
& TBSTYLE_FLAT
? 0 : TOP_BORDER
);
259 /* This is the behaviour in comctl32 v6 */
264 static inline BOOL
TOOLBAR_HasDropDownArrows(DWORD exStyle
)
266 return (exStyle
& TBSTYLE_EX_DRAWDDARROWS
) != 0;
269 static inline BOOL
button_has_ddarrow(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
271 return (TOOLBAR_HasDropDownArrows( infoPtr
->dwExStyle
) && (btnPtr
->fsStyle
& BTNS_DROPDOWN
)) ||
272 (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
276 TOOLBAR_GetText(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
278 LPWSTR lpText
= NULL
;
280 /* NOTE: iString == -1 is undocumented */
281 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1))
282 lpText
= (LPWSTR
)btnPtr
->iString
;
283 else if ((btnPtr
->iString
>= 0) && (btnPtr
->iString
< infoPtr
->nNumStrings
))
284 lpText
= infoPtr
->strings
[btnPtr
->iString
];
290 TOOLBAR_DumpTBButton(const TBBUTTON
*tbb
, BOOL fUnicode
)
292 TRACE("TBBUTTON: id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx (%s)\n",
293 tbb
->idCommand
,tbb
->iBitmap
, tbb
->fsState
, tbb
->fsStyle
, tbb
->dwData
, tbb
->iString
,
294 (fUnicode
? wine_dbgstr_w((LPWSTR
)tbb
->iString
) : wine_dbgstr_a((LPSTR
)tbb
->iString
)));
298 TOOLBAR_DumpButton(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*bP
, INT btn_num
)
300 if (TRACE_ON(toolbar
)){
301 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
302 btn_num
, bP
->idCommand
, GETIBITMAP(infoPtr
, bP
->iBitmap
),
303 bP
->fsState
, bP
->fsStyle
, bP
->dwData
, bP
->iString
);
304 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr
,bP
)));
305 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n",
306 btn_num
, bP
->idCommand
, (bP
->bHot
) ? "TRUE":"FALSE", bP
->nRow
,
307 wine_dbgstr_rect(&bP
->rect
));
313 TOOLBAR_DumpToolbar(const TOOLBAR_INFO
*iP
, INT line
)
315 if (TRACE_ON(toolbar
)) {
318 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
320 iP
->dwExStyle
, iP
->nNumButtons
, iP
->nNumBitmaps
,
321 iP
->nNumStrings
, iP
->dwStyle
);
322 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
324 iP
->himlInt
, iP
->himlDef
, iP
->himlHot
, iP
->himlDis
,
325 (iP
->bDoRedraw
) ? "TRUE" : "FALSE");
326 for(i
=0; i
<iP
->nNumButtons
; i
++) {
327 TOOLBAR_DumpButton(iP
, &iP
->buttons
[i
], i
);
333 TOOLBAR_ButtonHasString(const TBUTTON_INFO
*btnPtr
)
335 return HIWORD(btnPtr
->iString
) && btnPtr
->iString
!= -1;
338 static void set_string_index( TBUTTON_INFO
*btn
, INT_PTR str
, BOOL unicode
)
340 if (!IS_INTRESOURCE( str
) && str
!= -1)
342 if (!TOOLBAR_ButtonHasString( btn
)) btn
->iString
= 0;
345 Str_SetPtrW( (WCHAR
**)&btn
->iString
, (WCHAR
*)str
);
347 Str_SetPtrAtoW( (WCHAR
**)&btn
->iString
, (char *)str
);
351 if (TOOLBAR_ButtonHasString( btn
)) Free( (WCHAR
*)btn
->iString
);
357 static void set_stringT( TBUTTON_INFO
*btn
, const WCHAR
*str
, BOOL unicode
)
359 if (IS_INTRESOURCE( (DWORD_PTR
)str
) || (DWORD_PTR
)str
== -1) return;
360 set_string_index( btn
, (DWORD_PTR
)str
, unicode
);
363 static void free_string( TBUTTON_INFO
*btn
)
365 set_string_index( btn
, 0, TRUE
);
369 /***********************************************************************
372 * This function validates that the styles set are implemented and
373 * issues FIXMEs warning of possible problems. In a perfect world this
374 * function should be null.
377 TOOLBAR_CheckStyle (const TOOLBAR_INFO
*infoPtr
)
379 if (infoPtr
->dwStyle
& TBSTYLE_REGISTERDROP
)
380 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", infoPtr
->hwndSelf
);
385 TOOLBAR_SendNotify (NMHDR
*nmhdr
, const TOOLBAR_INFO
*infoPtr
, UINT code
)
387 if(!IsWindow(infoPtr
->hwndSelf
))
388 return 0; /* we have just been destroyed */
390 nmhdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
391 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
394 TRACE("to window %p, code=%08x, %s\n", infoPtr
->hwndNotify
, code
,
395 (infoPtr
->bUnicode
) ? "via Unicode" : "via ANSI");
397 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhdr
->idFrom
, (LPARAM
)nmhdr
);
400 /***********************************************************************
401 * TOOLBAR_GetBitmapIndex
403 * This function returns the bitmap index associated with a button.
404 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
405 * is issued to retrieve the index.
408 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
410 INT ret
= btnPtr
->iBitmap
;
412 if (ret
== I_IMAGECALLBACK
)
414 /* issue TBN_GETDISPINFO */
417 memset(&nmgd
, 0, sizeof(nmgd
));
418 nmgd
.idCommand
= btnPtr
->idCommand
;
419 nmgd
.lParam
= btnPtr
->dwData
;
420 nmgd
.dwMask
= TBNF_IMAGE
;
422 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
423 TOOLBAR_SendNotify(&nmgd
.hdr
, infoPtr
, TBN_GETDISPINFOW
);
424 if (nmgd
.dwMask
& TBNF_DI_SETITEM
)
425 btnPtr
->iBitmap
= nmgd
.iImage
;
427 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
428 ret
, nmgd
.dwMask
, infoPtr
->nNumBitmaps
);
431 if (ret
!= I_IMAGENONE
)
432 ret
= GETIBITMAP(infoPtr
, ret
);
439 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO
*infoPtr
, INT index
)
442 INT id
= GETHIMLID(infoPtr
, index
);
443 INT iBitmap
= GETIBITMAP(infoPtr
, index
);
445 if (((himl
= GETDEFIMAGELIST(infoPtr
, id
)) &&
446 iBitmap
>= 0 && iBitmap
< ImageList_GetImageCount(himl
)) ||
447 (index
== I_IMAGECALLBACK
))
455 TOOLBAR_IsValidImageList(const TOOLBAR_INFO
*infoPtr
, INT index
)
457 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, index
));
458 return (himl
!= NULL
) && (ImageList_GetImageCount(himl
) > 0);
462 /***********************************************************************
463 * TOOLBAR_GetImageListForDrawing
465 * This function validates the bitmap index (including I_IMAGECALLBACK
466 * functionality) and returns the corresponding image list.
469 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
,
470 IMAGE_LIST_TYPE imagelist
, INT
* index
)
474 if (!TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
)) {
475 if (btnPtr
->iBitmap
== I_IMAGENONE
) return NULL
;
476 WARN("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
477 HIWORD(btnPtr
->iBitmap
), LOWORD(btnPtr
->iBitmap
), infoPtr
->nNumBitmaps
);
481 if ((*index
= TOOLBAR_GetBitmapIndex(infoPtr
, btnPtr
)) < 0) {
482 if ((*index
== I_IMAGECALLBACK
) ||
483 (*index
== I_IMAGENONE
)) return NULL
;
484 ERR("TBN_GETDISPINFO returned invalid index %d\n",
491 case IMAGE_LIST_DEFAULT
:
492 himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
495 himl
= GETHOTIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
497 case IMAGE_LIST_DISABLED
:
498 himl
= GETDISIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
502 FIXME("Shouldn't reach here\n");
506 TRACE("no image list\n");
513 TOOLBAR_DrawFlatSeparator (const RECT
*lpRect
, HDC hdc
, const TOOLBAR_INFO
*infoPtr
)
516 COLORREF oldcolor
, newcolor
;
518 myrect
.left
= (lpRect
->left
+ lpRect
->right
) / 2 - 1;
519 myrect
.right
= myrect
.left
+ 1;
520 myrect
.top
= lpRect
->top
+ 2;
521 myrect
.bottom
= lpRect
->bottom
- 2;
523 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
524 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
525 oldcolor
= SetBkColor (hdc
, newcolor
);
526 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
528 myrect
.left
= myrect
.right
;
529 myrect
.right
= myrect
.left
+ 1;
531 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
532 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
533 SetBkColor (hdc
, newcolor
);
534 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
536 SetBkColor (hdc
, oldcolor
);
540 /***********************************************************************
541 * TOOLBAR_DrawFlatHorizontalSeparator
543 * This function draws horizontal separator for toolbars having CCS_VERT style.
544 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
545 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
546 * are horizontal as opposed to the vertical separators for not dropdown
549 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
552 TOOLBAR_DrawFlatHorizontalSeparator (const RECT
*lpRect
, HDC hdc
,
553 const TOOLBAR_INFO
*infoPtr
)
556 COLORREF oldcolor
, newcolor
;
558 myrect
.left
= lpRect
->left
;
559 myrect
.right
= lpRect
->right
;
560 myrect
.top
= lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
- 2)/2;
561 myrect
.bottom
= myrect
.top
+ 1;
563 InflateRect (&myrect
, -2, 0);
565 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect
));
567 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
568 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
569 oldcolor
= SetBkColor (hdc
, newcolor
);
570 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
572 myrect
.top
= myrect
.bottom
;
573 myrect
.bottom
= myrect
.top
+ 1;
575 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
576 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
577 SetBkColor (hdc
, newcolor
);
578 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
580 SetBkColor (hdc
, oldcolor
);
585 TOOLBAR_DrawArrow (HDC hdc
, INT left
, INT top
, COLORREF clr
)
590 if (!(hPen
= CreatePen( PS_SOLID
, 1, clr
))) return;
591 hOldPen
= SelectObject ( hdc
, hPen
);
594 MoveToEx (hdc
, x
, y
, NULL
);
595 LineTo (hdc
, x
+5, y
++); x
++;
596 MoveToEx (hdc
, x
, y
, NULL
);
597 LineTo (hdc
, x
+3, y
++); x
++;
598 MoveToEx (hdc
, x
, y
, NULL
);
599 LineTo (hdc
, x
+1, y
);
600 SelectObject( hdc
, hOldPen
);
601 DeleteObject( hPen
);
605 * Draw the text string for this button.
606 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
607 * is non-zero, so we can simply check himlDef to see if we have
611 TOOLBAR_DrawString (const TOOLBAR_INFO
*infoPtr
, RECT
*rcText
, LPCWSTR lpText
,
612 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
614 HDC hdc
= tbcd
->nmcd
.hdc
;
617 COLORREF clrOldBk
= 0;
619 UINT state
= tbcd
->nmcd
.uItemState
;
622 if (lpText
&& infoPtr
->nMaxTextRows
> 0) {
623 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText
),
624 wine_dbgstr_rect(rcText
));
626 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
627 if ((state
& CDIS_HOT
) && (dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)) {
628 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
630 else if (state
& CDIS_DISABLED
) {
631 clrOld
= SetTextColor (hdc
, tbcd
->clrBtnHighlight
);
632 OffsetRect (rcText
, 1, 1);
633 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
634 SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
635 OffsetRect (rcText
, -1, -1);
637 else if (state
& CDIS_INDETERMINATE
) {
638 clrOld
= SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
640 else if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
)) {
641 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
642 clrOldBk
= SetBkColor (hdc
, tbcd
->clrMark
);
643 oldBkMode
= SetBkMode (hdc
, tbcd
->nHLStringBkMode
);
646 clrOld
= SetTextColor (hdc
, tbcd
->clrText
);
649 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
650 SetTextColor (hdc
, clrOld
);
651 if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
))
653 SetBkColor (hdc
, clrOldBk
);
654 SetBkMode (hdc
, oldBkMode
);
656 SelectObject (hdc
, hOldFont
);
662 TOOLBAR_DrawPattern (const RECT
*lpRect
, const NMTBCUSTOMDRAW
*tbcd
)
664 HDC hdc
= tbcd
->nmcd
.hdc
;
665 HBRUSH hbr
= SelectObject (hdc
, tbcd
->hbrMonoDither
);
668 INT cx
= lpRect
->right
- lpRect
->left
;
669 INT cy
= lpRect
->bottom
- lpRect
->top
;
670 INT cxEdge
= GetSystemMetrics(SM_CXEDGE
);
671 INT cyEdge
= GetSystemMetrics(SM_CYEDGE
);
672 clrTextOld
= SetTextColor(hdc
, tbcd
->clrBtnHighlight
);
673 clrBkOld
= SetBkColor(hdc
, tbcd
->clrBtnFace
);
674 PatBlt (hdc
, lpRect
->left
+ cxEdge
, lpRect
->top
+ cyEdge
,
675 cx
- (2 * cxEdge
), cy
- (2 * cyEdge
), PATCOPY
);
676 SetBkColor(hdc
, clrBkOld
);
677 SetTextColor(hdc
, clrTextOld
);
678 SelectObject (hdc
, hbr
);
682 static void TOOLBAR_DrawMasked(HIMAGELIST himl
, int index
, HDC hdc
, INT x
, INT y
, UINT draw_flags
)
685 HBITMAP hbmMask
, hbmImage
;
686 HDC hdcMask
, hdcImage
;
688 ImageList_GetIconSize(himl
, &cx
, &cy
);
690 /* Create src image */
691 hdcImage
= CreateCompatibleDC(hdc
);
692 hbmImage
= CreateCompatibleBitmap(hdc
, cx
, cy
);
693 SelectObject(hdcImage
, hbmImage
);
694 ImageList_DrawEx(himl
, index
, hdcImage
, 0, 0, cx
, cy
,
695 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags
);
698 hdcMask
= CreateCompatibleDC(0);
699 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
700 SelectObject(hdcMask
, hbmMask
);
702 /* Remove the background and all white pixels */
703 ImageList_DrawEx(himl
, index
, hdcMask
, 0, 0, cx
, cy
,
704 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK
);
705 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
706 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
708 /* draw the new mask 'etched' to hdc */
709 SetBkColor(hdc
, RGB(255, 255, 255));
710 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
711 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
712 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
713 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
714 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
717 DeleteObject(hbmImage
);
719 DeleteObject (hbmMask
);
725 TOOLBAR_TranslateState(const TBUTTON_INFO
*btnPtr
)
729 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
730 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
731 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
732 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
733 retstate
|= (btnPtr
->bHot
) ? CDIS_HOT
: 0;
734 retstate
|= ((btnPtr
->fsState
& (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) == (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) ? CDIS_INDETERMINATE
: 0;
735 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
739 /* draws the image on a toolbar button */
741 TOOLBAR_DrawImage(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
,
742 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
744 HIMAGELIST himl
= NULL
;
745 BOOL draw_masked
= FALSE
, draw_desaturated
= FALSE
;
748 UINT draw_flags
= ILD_TRANSPARENT
;
750 IMAGEINFO info
= {0};
754 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
756 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
759 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
762 ImageList_GetImageInfo(himl
, index
, &info
);
763 GetObjectW(info
.hbmImage
, sizeof(bm
), &bm
);
765 if (bm
.bmBitsPixel
== 32)
767 draw_desaturated
= TRUE
;
778 else if (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
||
779 ((tbcd
->nmcd
.uItemState
& CDIS_HOT
)
780 && ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))))
782 /* if hot, attempt to draw with hot image list, if fails,
783 use default image list */
784 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
786 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
789 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
794 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
795 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
798 if (!(dwItemCDFlag
& TBCDRF_NOMARK
) &&
799 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
800 draw_flags
|= ILD_BLEND50
;
802 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
803 index
, himl
, left
, top
, offset
);
807 /* code path for drawing flat disabled icons without alpha channel */
808 TOOLBAR_DrawMasked (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
810 else if (draw_desaturated
)
812 /* code path for drawing disabled, alpha-blended (32bpp) icons */
813 IMAGELISTDRAWPARAMS imldp
= {0};
815 imldp
.cbSize
= sizeof(imldp
);
818 imldp
.hdcDst
= tbcd
->nmcd
.hdc
,
819 imldp
.x
= offset
+ left
;
820 imldp
.y
= offset
+ top
;
821 imldp
.rgbBk
= CLR_NONE
;
822 imldp
.rgbFg
= CLR_DEFAULT
;
823 imldp
.fStyle
= ILD_TRANSPARENT
;
824 imldp
.fState
= ILS_ALPHA
| ILS_SATURATE
;
827 ImageList_DrawIndirect (&imldp
);
831 /* code path for drawing standard icons as-is */
832 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
836 /* draws a blank frame for a toolbar button */
838 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, const RECT
*rect
, DWORD dwItemCDFlag
)
840 HDC hdc
= tbcd
->nmcd
.hdc
;
842 /* if the state is disabled or indeterminate then the button
843 * cannot have an interactive look like pressed or hot */
844 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
845 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
846 BOOL pressed_look
= !non_interactive_state
&&
847 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
848 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
850 /* app don't want us to draw any edges */
851 if (dwItemCDFlag
& TBCDRF_NOEDGES
)
854 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
857 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
858 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
859 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
864 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
866 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
867 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
872 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
, BOOL bDropDownPressed
, DWORD dwItemCDFlag
)
874 HDC hdc
= tbcd
->nmcd
.hdc
;
876 BOOL pressed
= bDropDownPressed
||
877 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
));
879 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
882 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
);
883 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
884 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
885 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
886 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
891 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
893 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
894 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
898 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
900 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
902 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
903 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
906 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
909 /* draws a complete toolbar button */
911 TOOLBAR_DrawButton (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, HDC hdc
, DWORD dwBaseCustDraw
)
913 DWORD dwStyle
= infoPtr
->dwStyle
;
914 BOOL hasDropDownArrow
= button_has_ddarrow( infoPtr
, btnPtr
);
915 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
916 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
917 RECT rc
, rcArrow
, rcBitmap
, rcText
;
918 LPWSTR lpText
= NULL
;
923 DWORD dwItemCustDraw
;
925 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
928 CopyRect (&rcArrow
, &rc
);
930 /* separator - doesn't send NM_CUSTOMDRAW */
931 if (btnPtr
->fsStyle
& BTNS_SEP
) {
934 DrawThemeBackground (theme
, hdc
,
935 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
939 /* with the FLAT style, iBitmap is the width and has already */
940 /* been taken into consideration in calculating the width */
941 /* so now we need to draw the vertical separator */
942 /* empirical tests show that iBitmap can/will be non-zero */
943 /* when drawing the vertical bar... */
944 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
945 if (dwStyle
& CCS_VERT
) {
947 InflateRect(&rcsep
, -infoPtr
->szPadding
.cx
, -infoPtr
->szPadding
.cy
);
948 TOOLBAR_DrawFlatHorizontalSeparator (&rcsep
, hdc
, infoPtr
);
951 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
954 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
955 FIXME("Draw some kind of separator: fsStyle=%x\n",
961 /* get a pointer to the text */
962 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
964 if (hasDropDownArrow
)
968 if (dwStyle
& TBSTYLE_FLAT
)
969 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
971 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
973 if (drawSepDropDownArrow
)
976 rcArrow
.left
= right
;
979 /* copy text & bitmap rects after adjusting for drop-down arrow
980 * so that text & bitmap is centered in the rectangle not containing
982 CopyRect(&rcText
, &rc
);
983 CopyRect(&rcBitmap
, &rc
);
985 /* Center the bitmap horizontally and vertically */
986 if (dwStyle
& TBSTYLE_LIST
)
989 infoPtr
->nMaxTextRows
> 0 &&
990 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
991 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
992 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
994 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
997 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
999 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
1001 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
1002 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
1003 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
1004 TRACE("Text=%s\n", debugstr_w(lpText
));
1005 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
1007 /* calculate text position */
1010 rcText
.left
+= GetSystemMetrics(SM_CXEDGE
);
1011 rcText
.right
-= GetSystemMetrics(SM_CXEDGE
);
1012 if (dwStyle
& TBSTYLE_LIST
)
1014 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
1018 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
1019 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
1021 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
1025 /* Initialize fields in all cases, because we use these later
1026 * NOTE: applications can and do alter these to customize their
1028 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1029 tbcd
.clrText
= comctl32_color
.clrBtnText
;
1030 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
1031 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
1032 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
1033 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
1034 tbcd
.clrHighlightHotTrack
= 0;
1035 tbcd
.nStringBkMode
= TRANSPARENT
;
1036 tbcd
.nHLStringBkMode
= OPAQUE
;
1037 tbcd
.rcText
.left
= 0;
1038 tbcd
.rcText
.top
= 0;
1039 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
1040 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
1041 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
1042 tbcd
.nmcd
.hdc
= hdc
;
1043 tbcd
.nmcd
.rc
= btnPtr
->rect
;
1044 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
1046 /* FIXME: what are these used for? */
1050 /* Issue Item Prepaint notify */
1053 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
1055 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
1056 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
1057 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
1058 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1059 /* reset these fields so the user can't alter the behaviour like native */
1060 tbcd
.nmcd
.hdc
= hdc
;
1061 tbcd
.nmcd
.rc
= btnPtr
->rect
;
1063 dwItemCustDraw
= ntfret
& 0xffff;
1064 dwItemCDFlag
= ntfret
& 0xffff0000;
1065 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
1067 /* save the only part of the rect that the user can change */
1068 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
1069 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
1072 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
1073 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
1074 OffsetRect(&rcText
, 1, 1);
1076 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
1077 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
1078 TOOLBAR_DrawPattern (&rc
, &tbcd
);
1080 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
1081 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
1083 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
1087 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
1088 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
1089 if (hasDropDownArrow
)
1090 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
1091 SetBkColor(hdc
, oldclr
);
1096 if (theme
&& !(dwItemCDFlag
& TBCDRF_NOBACKGROUND
))
1101 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
1102 int stateId
= TS_NORMAL
;
1104 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1105 stateId
= TS_DISABLED
;
1106 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1107 stateId
= TS_PRESSED
;
1108 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1109 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1110 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1111 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1114 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &rc
, NULL
);
1122 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, &rc
, dwItemCDFlag
);
1124 if (drawSepDropDownArrow
)
1128 int stateId
= TS_NORMAL
;
1130 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1131 stateId
= TS_DISABLED
;
1132 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1133 stateId
= TS_PRESSED
;
1134 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1135 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1136 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1139 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1140 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1143 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1146 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1147 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1148 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1149 SetBkMode (hdc
, oldBkMode
);
1151 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1153 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1155 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1157 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1158 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1160 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1162 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1163 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1166 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1169 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1171 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1172 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1179 TOOLBAR_Refresh (TOOLBAR_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
1181 TBUTTON_INFO
*btnPtr
;
1183 RECT rcTemp
, rcClient
;
1184 NMTBCUSTOMDRAW tbcd
;
1186 DWORD dwBaseCustDraw
;
1188 /* the app has told us not to redraw the toolbar */
1189 if (!infoPtr
->bDoRedraw
)
1192 /* if imagelist belongs to the app, it can be changed
1193 by the app after setting it */
1194 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1196 infoPtr
->nNumBitmaps
= 0;
1197 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1198 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1201 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1203 /* change the imagelist icon size if we manage the list and it is necessary */
1204 TOOLBAR_CheckImageListIconSize(infoPtr
);
1206 /* Send initial notify */
1207 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1208 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1209 tbcd
.nmcd
.hdc
= hdc
;
1210 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1211 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1212 dwBaseCustDraw
= ntfret
& 0xffff;
1214 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1216 /* redraw necessary buttons */
1217 btnPtr
= infoPtr
->buttons
;
1218 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1221 if (!RectVisible(hdc
, &btnPtr
->rect
))
1223 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1225 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1226 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1230 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1231 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1233 TOOLBAR_DrawButton(infoPtr
, btnPtr
, hdc
, dwBaseCustDraw
);
1236 /* draw insert mark if required */
1237 if (infoPtr
->tbim
.iButton
!= -1)
1239 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1241 rcInsertMark
.top
= rcButton
.top
;
1242 rcInsertMark
.bottom
= rcButton
.bottom
;
1243 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1244 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1246 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1247 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1250 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1252 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1253 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1254 tbcd
.nmcd
.hdc
= hdc
;
1255 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1256 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1260 /***********************************************************************
1261 * TOOLBAR_MeasureString
1263 * This function gets the width and height of a string in pixels. This
1264 * is done first by using GetTextExtentPoint to get the basic width
1265 * and height. The DrawText is called with DT_CALCRECT to get the exact
1266 * width. The reason is because the text may have more than one "&" (or
1267 * prefix characters as M$ likes to call them). The prefix character
1268 * indicates where the underline goes, except for the string "&&" which
1269 * is reduced to a single "&". GetTextExtentPoint does not process these
1270 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1273 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1274 HDC hdc
, LPSIZE lpSize
)
1281 if (infoPtr
->nMaxTextRows
> 0 &&
1282 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1283 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1284 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1286 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1288 if(lpText
!= NULL
) {
1289 /* first get size of all the text */
1290 GetTextExtentPoint32W (hdc
, lpText
, strlenW (lpText
), lpSize
);
1292 /* feed above size into the rectangle for DrawText */
1293 myrect
.left
= myrect
.top
= 0;
1294 myrect
.right
= lpSize
->cx
;
1295 myrect
.bottom
= lpSize
->cy
;
1297 /* Use DrawText to get true size as drawn (less pesky "&") */
1298 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1299 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1302 /* feed back to caller */
1303 lpSize
->cx
= myrect
.right
;
1304 lpSize
->cy
= myrect
.bottom
;
1308 TRACE("string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1311 /***********************************************************************
1312 * TOOLBAR_CalcStrings
1314 * This function walks through each string and measures it and returns
1315 * the largest height and width to caller.
1318 TOOLBAR_CalcStrings (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
1320 TBUTTON_INFO
*btnPtr
;
1329 if (infoPtr
->nMaxTextRows
== 0)
1332 hdc
= GetDC (infoPtr
->hwndSelf
);
1333 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1335 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1339 GetTextMetricsW(hdc
, &tm
);
1340 lpSize
->cy
= tm
.tmHeight
;
1343 btnPtr
= infoPtr
->buttons
;
1344 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1345 if(TOOLBAR_GetText(infoPtr
, btnPtr
))
1347 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1348 if (sz
.cx
> lpSize
->cx
)
1350 if (sz
.cy
> lpSize
->cy
)
1355 SelectObject (hdc
, hOldFont
);
1356 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1358 TRACE("max string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1361 /***********************************************************************
1362 * TOOLBAR_WrapToolbar
1364 * This function walks through the buttons and separators in the
1365 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1366 * wrapping should occur based on the width of the toolbar window.
1367 * It does *not* calculate button placement itself. That task
1368 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1369 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1370 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1372 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_VERTICAL can be used also to allow
1373 * vertical toolbar lists.
1377 TOOLBAR_WrapToolbar(TOOLBAR_INFO
*infoPtr
)
1379 TBUTTON_INFO
*btnPtr
;
1380 INT x
, cx
, i
, j
, width
;
1383 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1384 /* no layout is necessary. Applications may use this style */
1385 /* to perform their own layout on the toolbar. */
1386 if( !(infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) &&
1387 !(infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
) ) return;
1389 btnPtr
= infoPtr
->buttons
;
1390 x
= infoPtr
->nIndent
;
1391 width
= infoPtr
->client_rect
.right
- infoPtr
->client_rect
.left
;
1393 bButtonWrap
= FALSE
;
1395 TRACE("start ButtonWidth=%d, BitmapWidth=%d, width=%d, nIndent=%d\n",
1396 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, width
,
1399 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1401 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1403 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1406 if (btnPtr
[i
].cx
> 0)
1408 /* horizontal separators are treated as buttons for width */
1409 else if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1410 !(infoPtr
->dwStyle
& CCS_VERT
))
1411 cx
= (btnPtr
[i
].iBitmap
> 0) ? btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1413 cx
= infoPtr
->nButtonWidth
;
1415 if (!btnPtr
[i
].cx
&& button_has_ddarrow( infoPtr
, btnPtr
+ i
))
1416 cx
+= DDARROW_WIDTH
;
1418 /* Two or more adjacent separators form a separator group. */
1419 /* The first separator in a group should be wrapped to the */
1420 /* next row if the previous wrapping is on a button. */
1422 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1423 (i
+ 1 < infoPtr
->nNumButtons
) &&
1424 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1426 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1427 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1428 x
= infoPtr
->nIndent
;
1430 bButtonWrap
= FALSE
;
1434 /* The layout makes sure the bitmap is visible, but not the button. */
1435 /* Test added to also wrap after a button that starts a row but */
1436 /* is bigger than the area. - GA 8/01 */
1437 if ((x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2 > width
) ||
1438 ((x
== infoPtr
->nIndent
) && (cx
> width
)))
1440 BOOL bFound
= FALSE
;
1442 /* If the current button is a separator and not hidden, */
1443 /* go to the next until it reaches a non separator. */
1444 /* Wrap the last separator if it is before a button. */
1445 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1446 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1447 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1448 i
< infoPtr
->nNumButtons
)
1454 if( bFound
&& i
< infoPtr
->nNumButtons
)
1457 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1458 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1459 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1460 x
= infoPtr
->nIndent
;
1461 bButtonWrap
= FALSE
;
1464 else if ( i
>= infoPtr
->nNumButtons
)
1467 /* If the current button is not a separator, find the last */
1468 /* separator and wrap it. */
1469 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1471 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1472 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1476 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1477 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1478 x
= infoPtr
->nIndent
;
1479 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1480 bButtonWrap
= FALSE
;
1485 /* If no separator available for wrapping, wrap one of */
1486 /* non-hidden previous button. */
1490 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1492 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1497 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1498 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1499 x
= infoPtr
->nIndent
;
1500 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1506 /* If all above failed, wrap the current button. */
1509 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1510 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1511 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1512 x
= infoPtr
->nIndent
;
1513 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1514 bButtonWrap
= FALSE
;
1520 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1521 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1528 /***********************************************************************
1529 * TOOLBAR_MeasureButton
1531 * Calculates the width and height required for a button. Used in
1532 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1533 * the width of buttons that are autosized.
1535 * Note that it would have been rather elegant to use one piece of code for
1536 * both the laying out of the toolbar and for controlling where button parts
1537 * are drawn, but the native control has inconsistencies between the two that
1538 * prevent this from being effectively. These inconsistencies can be seen as
1539 * artefacts where parts of the button appear outside of the bounding button
1542 * There are several cases for the calculation of the button dimensions and
1543 * button part positioning:
1550 * +--------------------------------------------------------+ ^
1552 * | | pad.cy / 2 | centered | |
1553 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1554 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1555 * | |<------------>| | | | |
1556 * | +--------------+ +------------+ | |
1557 * |<-------------------------------------->| | |
1558 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1560 * +--------------------------------------------------------+ -
1561 * <-------------------------------------------------------->
1562 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1564 * Without Bitmap (I_IMAGENONE):
1566 * +-----------------------------------+ ^
1568 * | | centered | | LISTPAD_CY +
1569 * | +------------+ | | szText.cy
1572 * | +------------+ | |
1573 * |<----------------->| | |
1574 * | cxedge |<-----------> | |
1576 * +-----------------------------------+ -
1577 * <----------------------------------->
1578 * szText.cx + pad.cx
1582 * +--------------------------------------+ ^
1584 * | | padding.cy/2 | | DEFPAD_CY +
1585 * | +------------+ | | nBitmapHeight
1588 * | +------------+ | |
1589 * |<------------------->| | |
1590 * | cxedge + iListGap/2 |<-----------> | |
1591 * | nBitmapWidth | |
1592 * +--------------------------------------+ -
1593 * <-------------------------------------->
1594 * 2*cxedge + nBitmapWidth + iListGap
1601 * +-----------------------------------+ ^
1603 * | | pad.cy / 2 | | nBitmapHeight +
1604 * | - | | szText.cy +
1605 * | +------------+ | | DEFPAD_CY + 1
1606 * | centered | Bitmap | | |
1607 * |<----------------->| | | |
1608 * | +------------+ | |
1612 * | centered +---------------+ | |
1613 * |<--------------->| Text | | |
1614 * | +---------------+ | |
1615 * +-----------------------------------+ -
1616 * <----------------------------------->
1617 * pad.cx + max(nBitmapWidth, szText.cx)
1619 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1621 * +---------------------------------------+ ^
1623 * | | 2 + pad.cy / 2 | |
1624 * | - | | szText.cy +
1625 * | centered +-----------------+ | | pad.cy + 2
1626 * |<--------------->| Text | | |
1627 * | +-----------------+ | |
1629 * +---------------------------------------+ -
1630 * <--------------------------------------->
1631 * 2*cxedge + pad.cx + szText.cx
1634 * As for with bitmaps, but with szText.cx zero.
1636 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1637 BOOL bHasBitmap
, BOOL bValidImageList
)
1640 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1642 /* set button height from bitmap / text height... */
1643 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1646 /* ... add on the necessary padding */
1647 if (bValidImageList
)
1650 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1654 sizeButton
.cy
+= DEFPAD_CY
;
1657 sizeButton
.cy
+= LISTPAD_CY
;
1660 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1662 /* calculate button width */
1663 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1664 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1665 if (sizeString
.cx
> 0)
1666 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1674 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ infoPtr
->szPadding
.cy
;
1676 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1678 if (sizeString
.cy
> 0)
1679 sizeButton
.cy
+= 1 + sizeString
.cy
;
1680 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1681 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1685 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1686 NONLIST_NOTEXT_OFFSET
;
1687 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1688 max(2*GetSystemMetrics(SM_CXEDGE
) + sizeString
.cx
, infoPtr
->nBitmapWidth
);
1695 /***********************************************************************
1696 * TOOLBAR_CalcToolbar
1698 * This function calculates button and separator placement. It first
1699 * calculates the button sizes, gets the toolbar window width and then
1700 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1701 * on. It assigns a new location to each item and sends this location to
1702 * the tooltip window if appropriate. Finally, it updates the rcBound
1703 * rect and calculates the new required toolbar window height.
1706 TOOLBAR_CalcToolbar (TOOLBAR_INFO
*infoPtr
)
1708 SIZE sizeString
, sizeButton
;
1709 BOOL validImageList
= FALSE
;
1711 TOOLBAR_CalcStrings (infoPtr
, &sizeString
);
1713 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1715 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1716 validImageList
= TRUE
;
1717 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1718 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1719 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1720 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1722 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1723 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1724 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1725 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1727 TOOLBAR_LayoutToolbar(infoPtr
);
1731 TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
)
1733 TBUTTON_INFO
*btnPtr
;
1735 INT i
, nRows
, nSepRows
;
1738 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1740 TOOLBAR_WrapToolbar(infoPtr
);
1742 x
= infoPtr
->nIndent
;
1743 y
= infoPtr
->iTopMargin
;
1744 cx
= infoPtr
->nButtonWidth
;
1745 cy
= infoPtr
->nButtonHeight
;
1747 nRows
= nSepRows
= 0;
1749 infoPtr
->rcBound
.top
= y
;
1750 infoPtr
->rcBound
.left
= x
;
1751 infoPtr
->rcBound
.bottom
= y
+ cy
;
1752 infoPtr
->rcBound
.right
= x
;
1754 btnPtr
= infoPtr
->buttons
;
1756 TRACE("cy=%d\n", cy
);
1758 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1761 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1763 SetRectEmpty (&btnPtr
->rect
);
1767 cy
= infoPtr
->nButtonHeight
;
1769 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1770 if (infoPtr
->dwStyle
& CCS_VERT
) {
1771 cy
= (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1772 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
: infoPtr
->nButtonWidth
;
1775 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
:
1776 (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1782 else if (btnPtr
->fsStyle
& BTNS_AUTOSIZE
)
1788 hdc
= GetDC (infoPtr
->hwndSelf
);
1789 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1791 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1793 SelectObject (hdc
, hOldFont
);
1794 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1796 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1797 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1802 cx
= infoPtr
->nButtonWidth
;
1804 /* if size has been set manually then don't add on extra space
1805 * for the drop down arrow */
1806 if (!btnPtr
->cx
&& button_has_ddarrow( infoPtr
, btnPtr
))
1807 cx
+= DDARROW_WIDTH
;
1809 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1812 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1814 if (infoPtr
->rcBound
.left
> x
)
1815 infoPtr
->rcBound
.left
= x
;
1816 if (infoPtr
->rcBound
.right
< x
+ cx
)
1817 infoPtr
->rcBound
.right
= x
+ cx
;
1818 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1819 infoPtr
->rcBound
.bottom
= y
+ cy
;
1821 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1823 /* btnPtr->nRow is zero based. The space between the rows is */
1824 /* also considered as a row. */
1825 btnPtr
->nRow
= nRows
+ nSepRows
;
1827 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1828 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1833 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1837 if ( !(infoPtr
->dwStyle
& CCS_VERT
))
1838 y
+= cy
+ ( (btnPtr
->cx
> 0 ) ?
1839 btnPtr
->cx
: SEPARATOR_WIDTH
) * 2 /3;
1843 /* nSepRows is used to calculate the extra height following */
1847 x
= infoPtr
->nIndent
;
1849 /* Increment row number unless this is the last button */
1850 /* and it has Wrap set. */
1851 if (i
!= infoPtr
->nNumButtons
-1)
1858 /* infoPtr->nRows is the number of rows on the toolbar */
1859 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1861 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1866 TOOLBAR_InternalHitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
*lpPt
, BOOL
*button
)
1868 TBUTTON_INFO
*btnPtr
;
1874 btnPtr
= infoPtr
->buttons
;
1875 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1876 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1879 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1880 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1881 TRACE(" ON SEPARATOR %d!\n", i
);
1886 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1887 TRACE(" ON BUTTON %d!\n", i
);
1895 TRACE(" NOWHERE!\n");
1896 return TOOLBAR_NOWHERE
;
1900 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1902 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO
*infoPtr
, INT iIndex
, UINT nAddButtons
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
1904 INT nOldButtons
, nNewButtons
, iButton
;
1905 BOOL fHasString
= FALSE
;
1907 if (iIndex
< 0) /* iIndex can be negative, what means adding at the end */
1908 iIndex
= infoPtr
->nNumButtons
;
1910 nOldButtons
= infoPtr
->nNumButtons
;
1911 nNewButtons
= nOldButtons
+ nAddButtons
;
1913 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
1914 memmove(&infoPtr
->buttons
[iIndex
+ nAddButtons
], &infoPtr
->buttons
[iIndex
],
1915 (nOldButtons
- iIndex
) * sizeof(TBUTTON_INFO
));
1916 infoPtr
->nNumButtons
+= nAddButtons
;
1918 /* insert new buttons data */
1919 for (iButton
= 0; iButton
< nAddButtons
; iButton
++) {
1920 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[iIndex
+ iButton
];
1923 TOOLBAR_DumpTBButton(lpTbb
+ iButton
, fUnicode
);
1925 ZeroMemory(btnPtr
, sizeof(*btnPtr
));
1927 btnPtr
->iBitmap
= lpTbb
[iButton
].iBitmap
;
1928 btnPtr
->idCommand
= lpTbb
[iButton
].idCommand
;
1929 btnPtr
->fsState
= lpTbb
[iButton
].fsState
;
1930 btnPtr
->fsStyle
= lpTbb
[iButton
].fsStyle
;
1931 btnPtr
->dwData
= lpTbb
[iButton
].dwData
;
1933 if (btnPtr
->fsStyle
& BTNS_SEP
)
1936 str
= lpTbb
[iButton
].iString
;
1937 set_string_index( btnPtr
, str
, fUnicode
);
1938 fHasString
|= TOOLBAR_ButtonHasString( btnPtr
);
1940 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
1943 if (infoPtr
->nNumStrings
> 0 || fHasString
)
1944 TOOLBAR_CalcToolbar(infoPtr
);
1946 TOOLBAR_LayoutToolbar(infoPtr
);
1947 TOOLBAR_AutoSize(infoPtr
);
1949 TOOLBAR_DumpToolbar(infoPtr
, __LINE__
);
1950 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1956 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1958 TBUTTON_INFO
*btnPtr
;
1961 if (CommandIsIndex
) {
1962 TRACE("command is really index command=%d\n", idCommand
);
1963 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1966 btnPtr
= infoPtr
->buttons
;
1967 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1968 if (btnPtr
->idCommand
== idCommand
) {
1969 TRACE("command=%d index=%d\n", idCommand
, i
);
1973 TRACE("no index found for command=%d\n", idCommand
);
1979 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1981 TBUTTON_INFO
*btnPtr
;
1984 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1987 /* check index button */
1988 btnPtr
= &infoPtr
->buttons
[nIndex
];
1989 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1990 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1994 /* check previous buttons */
1995 nRunIndex
= nIndex
- 1;
1996 while (nRunIndex
>= 0) {
1997 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1998 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1999 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
2007 /* check next buttons */
2008 nRunIndex
= nIndex
+ 1;
2009 while (nRunIndex
< infoPtr
->nNumButtons
) {
2010 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
2011 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
2012 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
2025 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
2026 WPARAM wParam
, LPARAM lParam
)
2032 msg
.wParam
= wParam
;
2033 msg
.lParam
= lParam
;
2034 msg
.time
= GetMessageTime ();
2035 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
2036 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
2038 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
2043 TOOLBAR_ThemeChanged(HWND hwnd
)
2045 HTHEME theme
= GetWindowTheme(hwnd
);
2046 CloseThemeData(theme
);
2047 OpenThemeData(hwnd
, themeClass
);
2053 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2055 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
2058 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
2059 ti
.cbSize
= sizeof (TTTOOLINFOW
);
2060 ti
.hwnd
= infoPtr
->hwndSelf
;
2061 ti
.uId
= button
->idCommand
;
2063 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
2064 /* ti.lParam = random value from the stack? */
2066 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
2072 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2074 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
2077 ZeroMemory(&ti
, sizeof(ti
));
2078 ti
.cbSize
= sizeof(ti
);
2079 ti
.hwnd
= infoPtr
->hwndSelf
;
2080 ti
.uId
= button
->idCommand
;
2082 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
2086 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2088 /* Set the toolTip only for non-hidden, non-separator button */
2089 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
2093 ZeroMemory(&ti
, sizeof(ti
));
2094 ti
.cbSize
= sizeof(ti
);
2095 ti
.hwnd
= infoPtr
->hwndSelf
;
2096 ti
.uId
= button
->idCommand
;
2097 ti
.rect
= button
->rect
;
2098 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
2102 /* Creates the tooltip control */
2104 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
2107 NMTOOLTIPSCREATED nmttc
;
2109 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
2110 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2111 infoPtr
->hwndSelf
, 0, 0, 0);
2113 if (!infoPtr
->hwndToolTip
)
2116 /* Send NM_TOOLTIPSCREATED notification */
2117 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
2118 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
2120 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
2122 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
2123 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
2127 /* keeps available button list box sorted by button id */
2128 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
2132 PCUSTOMBUTTON btnInfo
;
2133 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2135 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
2137 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2139 /* position 0 is always separator */
2140 for (i
= 1; i
< count
; i
++)
2142 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2143 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2145 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2146 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2150 /* id higher than all others add to end */
2151 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2152 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2155 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2159 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2161 if (nIndexFrom
== nIndexTo
)
2164 /* MSDN states that iItem is the index of the button, rather than the
2165 * command ID as used by every other NMTOOLBAR notification */
2166 nmtb
.iItem
= nIndexFrom
;
2167 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2169 PCUSTOMBUTTON btnInfo
;
2171 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2172 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2174 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2176 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2177 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2178 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2179 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2182 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2184 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2186 /* last item is always separator, so -2 instead of -1 */
2187 if (nIndexTo
>= (count
- 2))
2188 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2190 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2192 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2193 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2195 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2199 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2203 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2205 /* MSDN states that iItem is the index of the button, rather than the
2206 * command ID as used by every other NMTOOLBAR notification */
2207 nmtb
.iItem
= nIndexAvail
;
2208 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2210 PCUSTOMBUTTON btnInfo
;
2212 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2213 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2214 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2216 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2218 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2220 /* remove from 'available buttons' list */
2221 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2222 if (nIndexAvail
== count
-1)
2223 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2225 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2229 PCUSTOMBUTTON btnNew
;
2231 /* duplicate 'separator' button */
2232 btnNew
= Alloc(sizeof(CUSTOMBUTTON
));
2237 /* insert into 'toolbar button' list */
2238 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2239 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2241 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2243 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2247 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2249 PCUSTOMBUTTON btnInfo
;
2250 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2252 TRACE("Remove: index %d\n", index
);
2254 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2256 /* send TBN_QUERYDELETE notification */
2257 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2261 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2262 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2264 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2266 /* insert into 'available button' list */
2267 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2268 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2272 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2276 /* drag list notification function for toolbar buttons list box */
2277 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2278 const DRAGLISTINFO
*pDLI
)
2280 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2281 switch (pDLI
->uNotification
)
2285 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2286 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2287 /* no dragging for last item (separator) */
2288 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2293 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2294 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2295 /* no dragging past last item (separator) */
2296 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2298 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2299 /* FIXME: native uses "move button" cursor */
2300 return DL_COPYCURSOR
;
2303 /* not over toolbar buttons list */
2304 if (nCurrentItem
< 0)
2306 POINT ptWindow
= pDLI
->ptCursor
;
2307 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2308 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2309 /* over available buttons list? */
2310 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2311 /* FIXME: native uses "move button" cursor */
2312 return DL_COPYCURSOR
;
2314 /* clear drag arrow */
2315 DrawInsert(hwnd
, hwndList
, -1);
2316 return DL_STOPCURSOR
;
2320 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2321 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2322 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2323 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2325 /* clear drag arrow */
2326 DrawInsert(hwnd
, hwndList
, -1);
2328 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2330 /* not over toolbar buttons list */
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 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2343 /* Clear drag arrow */
2344 DrawInsert(hwnd
, hwndList
, -1);
2351 /* drag list notification function for available buttons list box */
2352 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2353 const DRAGLISTINFO
*pDLI
)
2355 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2356 switch (pDLI
->uNotification
)
2362 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2363 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2364 /* no dragging past last item (separator) */
2365 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2367 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2368 /* FIXME: native uses "move button" cursor */
2369 return DL_COPYCURSOR
;
2372 /* not over toolbar buttons list */
2373 if (nCurrentItem
< 0)
2375 POINT ptWindow
= pDLI
->ptCursor
;
2376 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2377 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2378 /* over available buttons list? */
2379 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2380 /* FIXME: native uses "move button" cursor */
2381 return DL_COPYCURSOR
;
2383 /* clear drag arrow */
2384 DrawInsert(hwnd
, hwndList
, -1);
2385 return DL_STOPCURSOR
;
2389 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2390 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2391 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2392 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2394 /* clear drag arrow */
2395 DrawInsert(hwnd
, hwndList
, -1);
2397 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2401 /* Clear drag arrow */
2402 DrawInsert(hwnd
, hwndList
, -1);
2408 extern UINT uDragListMessage DECLSPEC_HIDDEN
;
2410 /***********************************************************************
2411 * TOOLBAR_CustomizeDialogProc
2412 * This function implements the toolbar customization dialog.
2414 static INT_PTR CALLBACK
2415 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2417 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2418 PCUSTOMBUTTON btnInfo
;
2420 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2425 custInfo
= (PCUSTDLG_INFO
)lParam
;
2426 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2433 NMTBINITCUSTOMIZE nmtbic
;
2435 infoPtr
= custInfo
->tbInfo
;
2437 /* send TBN_QUERYINSERT notification */
2438 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2440 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2443 nmtbic
.hwndDialog
= hwnd
;
2444 /* Send TBN_INITCUSTOMIZE notification */
2445 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2448 TRACE("TBNRF_HIDEHELP requested\n");
2449 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2452 /* add items to 'toolbar buttons' list and check if removable */
2453 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2455 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2456 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2457 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2458 btnInfo
->bVirtual
= FALSE
;
2459 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2461 /* send TBN_QUERYDELETE notification */
2462 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2464 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2465 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2468 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2470 /* insert separator button into 'available buttons' list */
2471 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2472 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2473 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2474 btnInfo
->bVirtual
= FALSE
;
2475 btnInfo
->bRemovable
= TRUE
;
2476 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2477 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2478 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2480 /* insert all buttons into dsa */
2483 /* send TBN_GETBUTTONINFO notification */
2486 nmtb
.pszText
= Buffer
;
2489 /* Clear previous button's text */
2490 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2492 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2495 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2496 nmtb
.tbButton
.fsStyle
, i
,
2497 nmtb
.tbButton
.idCommand
,
2498 nmtb
.tbButton
.iString
,
2499 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2502 /* insert button into the appropriate list */
2503 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2506 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2507 btnInfo
->bVirtual
= FALSE
;
2508 btnInfo
->bRemovable
= TRUE
;
2512 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2513 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2516 btnInfo
->btn
= nmtb
.tbButton
;
2517 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2519 if (lstrlenW(nmtb
.pszText
))
2520 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2521 else if (nmtb
.tbButton
.iString
>= 0 &&
2522 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2524 lstrcpyW(btnInfo
->text
,
2525 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2530 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2533 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2535 /* select first item in the 'available' list */
2536 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2538 /* append 'virtual' separator button to the 'toolbar buttons' list */
2539 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2540 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2541 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2542 btnInfo
->bVirtual
= TRUE
;
2543 btnInfo
->bRemovable
= FALSE
;
2544 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2545 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2546 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2548 /* select last item in the 'toolbar' list */
2549 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2550 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2552 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2553 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2555 /* set focus and disable buttons */
2556 PostMessageW (hwnd
, WM_USER
, 0, 0);
2561 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2562 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2563 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2564 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2568 EndDialog(hwnd
, FALSE
);
2572 switch (LOWORD(wParam
))
2574 case IDC_TOOLBARBTN_LBOX
:
2575 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2577 PCUSTOMBUTTON btnInfo
;
2582 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2583 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2585 /* send TBN_QUERYINSERT notification */
2587 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2589 /* get list box item */
2590 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2592 if (index
== (count
- 1))
2594 /* last item (virtual separator) */
2595 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2596 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2598 else if (index
== (count
- 2))
2600 /* second last item (last non-virtual item) */
2601 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2602 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2604 else if (index
== 0)
2607 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2608 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2612 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2613 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2616 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2620 case IDC_MOVEUP_BTN
:
2622 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2623 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2627 case IDC_MOVEDN_BTN
: /* move down */
2629 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2630 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2634 case IDC_REMOVE_BTN
: /* remove button */
2636 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2638 if (LB_ERR
== index
)
2641 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2645 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2648 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2651 case IDOK
: /* Add button */
2656 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2657 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2659 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2664 EndDialog(hwnd
, FALSE
);
2674 /* delete items from 'toolbar buttons' listbox*/
2675 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2676 for (i
= 0; i
< count
; i
++)
2678 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2680 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2682 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2685 /* delete items from 'available buttons' listbox*/
2686 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2687 for (i
= 0; i
< count
; i
++)
2689 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2691 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2693 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2698 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2700 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2705 COLORREF oldText
= 0;
2709 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, lpdis
->itemID
, 0);
2710 if (btnInfo
== NULL
)
2712 FIXME("btnInfo invalid!\n");
2716 /* set colors and select objects */
2717 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2718 if (btnInfo
->bVirtual
)
2719 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2721 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2722 hPen
= CreatePen( PS_SOLID
, 1,
2723 (lpdis
->itemState
& ODS_SELECTED
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2724 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2725 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2727 /* fill background rectangle */
2728 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2729 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2731 /* calculate button and text rectangles */
2732 CopyRect (&rcButton
, &lpdis
->rcItem
);
2733 InflateRect (&rcButton
, -1, -1);
2734 CopyRect (&rcText
, &rcButton
);
2735 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2736 rcText
.left
= rcButton
.right
+ 2;
2738 /* draw focus rectangle */
2739 if (lpdis
->itemState
& ODS_FOCUS
)
2740 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2743 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2744 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2746 /* draw image and text */
2747 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2748 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2749 btnInfo
->btn
.iBitmap
));
2750 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2751 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2753 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2754 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2756 /* delete objects and reset colors */
2757 SelectObject (lpdis
->hDC
, hOldBrush
);
2758 SelectObject (lpdis
->hDC
, hOldPen
);
2759 SetBkColor (lpdis
->hDC
, oldBk
);
2760 SetTextColor (lpdis
->hDC
, oldText
);
2761 DeleteObject( hPen
);
2766 case WM_MEASUREITEM
:
2767 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2769 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2771 lpmis
->itemHeight
= 15 + 8; /* default height */
2778 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2780 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2782 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2783 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2784 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2787 else if (wParam
== IDC_AVAILBTN_LBOX
)
2789 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2790 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2791 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2800 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2803 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2809 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2810 /* Add bitmaps to the default image list */
2811 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2812 hbmLoad
= CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2813 else if (bitmap
->hInst
== COMCTL32_hModule
)
2814 hbmLoad
= LoadImageW( bitmap
->hInst
, MAKEINTRESOURCEW(bitmap
->nID
),
2815 IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
2817 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2819 /* enlarge the bitmap if needed */
2820 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2821 if (bitmap
->hInst
!= COMCTL32_hModule
)
2822 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2824 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2825 DeleteObject(hbmLoad
);
2829 nCountAfter
= ImageList_GetImageCount(himlDef
);
2830 nAdded
= nCountAfter
- nCountBefore
;
2831 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2833 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2834 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2835 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2836 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2839 infoPtr
->nNumBitmaps
+= nAdded
;
2844 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2851 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2852 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2854 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2856 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2859 TRACE("Update icon size: %dx%d -> %dx%d\n",
2860 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2862 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2863 ILC_COLOR32
|ILC_MASK
, 8, 2);
2864 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2865 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2866 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2867 infoPtr
->himlInt
= himlNew
;
2869 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2870 ImageList_Destroy(himlDef
);
2873 /***********************************************************************
2874 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2878 TOOLBAR_AddBitmap (TOOLBAR_INFO
*infoPtr
, INT count
, const TBADDBITMAP
*lpAddBmp
)
2884 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr
->hwndSelf
, count
, lpAddBmp
);
2888 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2890 info
.hInst
= COMCTL32_hModule
;
2891 switch (lpAddBmp
->nID
)
2893 case IDB_STD_SMALL_COLOR
:
2895 info
.nID
= IDB_STD_SMALL
;
2897 case IDB_STD_LARGE_COLOR
:
2899 info
.nID
= IDB_STD_LARGE
;
2901 case IDB_VIEW_SMALL_COLOR
:
2903 info
.nID
= IDB_VIEW_SMALL
;
2905 case IDB_VIEW_LARGE_COLOR
:
2907 info
.nID
= IDB_VIEW_LARGE
;
2909 case IDB_HIST_SMALL_COLOR
:
2911 info
.nID
= IDB_HIST_SMALL
;
2913 case IDB_HIST_LARGE_COLOR
:
2915 info
.nID
= IDB_HIST_LARGE
;
2921 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2923 /* Windows resize all the buttons to the size of a newly added standard image */
2924 if (lpAddBmp
->nID
& 1)
2926 /* large icons: 24x24. Will make the button 31x30 */
2927 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2931 /* small icons: 16x16. Will make the buttons 23x22 */
2932 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2935 TOOLBAR_CalcToolbar (infoPtr
);
2939 info
.nButtons
= count
;
2940 info
.hInst
= lpAddBmp
->hInst
;
2941 info
.nID
= lpAddBmp
->nID
;
2942 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2945 /* check if the bitmap is already loaded and compute iSumButtons */
2947 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2949 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2950 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2952 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2955 if (!infoPtr
->cimlDef
) {
2956 /* create new default image list */
2957 TRACE ("creating default image list!\n");
2959 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2960 ILC_COLOR32
| ILC_MASK
, info
.nButtons
, 2);
2961 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2962 infoPtr
->himlInt
= himlDef
;
2965 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2969 WARN("No default image list available\n");
2973 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2976 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2977 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2978 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2979 infoPtr
->nNumBitmapInfos
++;
2980 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2982 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2988 TOOLBAR_AddButtonsT(TOOLBAR_INFO
*infoPtr
, INT nAddButtons
, const TBBUTTON
* lpTbb
, BOOL fUnicode
)
2990 TRACE("adding %d buttons (unicode=%d)!\n", nAddButtons
, fUnicode
);
2992 return TOOLBAR_InternalInsertButtonsT(infoPtr
, -1, nAddButtons
, lpTbb
, fUnicode
);
2997 TOOLBAR_AddStringW (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
2999 #define MAX_RESOURCE_STRING_LENGTH 512
3000 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
3001 INT nIndex
= infoPtr
->nNumStrings
;
3003 TRACE("%p, %lx\n", hInstance
, lParam
);
3005 if (IS_INTRESOURCE(lParam
)) {
3006 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
3013 TRACE("adding string from resource\n");
3015 if (!hInstance
) return -1;
3017 hrsrc
= FindResourceW( hInstance
, MAKEINTRESOURCEW((LOWORD(lParam
) >> 4) + 1),
3018 (LPWSTR
)RT_STRING
);
3021 TRACE("string not found in resources\n");
3025 len
= LoadStringW (hInstance
, (UINT
)lParam
,
3026 szString
, MAX_RESOURCE_STRING_LENGTH
);
3028 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
3029 if (len
== 0 || len
== 1)
3032 TRACE("delimiter: 0x%x\n", *szString
);
3033 delimiter
= *szString
;
3036 while ((next_delim
= strchrW(p
, delimiter
)) != NULL
) {
3038 if (next_delim
+ 1 >= szString
+ len
)
3040 /* this may happen if delimiter == '\0' or if the last char is a
3041 * delimiter (then it is ignored like the native does) */
3045 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3046 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3047 infoPtr
->nNumStrings
++;
3053 LPWSTR p
= (LPWSTR
)lParam
;
3058 TRACE("adding string(s) from array\n");
3062 TRACE("len=%d %s\n", len
, debugstr_w(p
));
3063 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3064 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3065 infoPtr
->nNumStrings
++;
3072 TOOLBAR_CalcToolbar(infoPtr
);
3078 TOOLBAR_AddStringA (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
3080 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
3085 TRACE("%p, %lx\n", hInstance
, lParam
);
3087 if (IS_INTRESOURCE(lParam
)) /* load from resources */
3088 return TOOLBAR_AddStringW(infoPtr
, hInstance
, lParam
);
3094 TRACE("adding string(s) from array\n");
3095 nIndex
= infoPtr
->nNumStrings
;
3098 TRACE("len=%d \"%s\"\n", len
, p
);
3100 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3101 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3102 infoPtr
->nNumStrings
++;
3108 TOOLBAR_CalcToolbar(infoPtr
);
3114 TOOLBAR_AutoSize (TOOLBAR_INFO
*infoPtr
)
3116 TRACE("auto sizing, style=%x!\n", infoPtr
->dwStyle
);
3117 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3119 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3121 RECT window_rect
, parent_rect
;
3122 UINT uPosFlags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
3126 parent
= GetParent (infoPtr
->hwndSelf
);
3128 if (!parent
|| !infoPtr
->bDoRedraw
)
3131 GetClientRect(parent
, &parent_rect
);
3133 x
= parent_rect
.left
;
3134 y
= parent_rect
.top
;
3136 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3137 cx
= parent_rect
.right
- parent_rect
.left
;
3139 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3141 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3142 MapWindowPoints( 0, parent
, (POINT
*)&window_rect
, 2 );
3143 y
= window_rect
.top
;
3145 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3147 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3148 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3151 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3152 uPosFlags
|= SWP_NOMOVE
;
3154 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3155 cy
+= GetSystemMetrics(SM_CYEDGE
);
3157 if (infoPtr
->dwStyle
& WS_BORDER
)
3159 cx
+= 2 * GetSystemMetrics(SM_CXBORDER
);
3160 cy
+= 2 * GetSystemMetrics(SM_CYBORDER
);
3163 SetWindowPos(infoPtr
->hwndSelf
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3166 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
))
3168 TOOLBAR_LayoutToolbar(infoPtr
);
3169 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
3176 static inline LRESULT
3177 TOOLBAR_ButtonCount (const TOOLBAR_INFO
*infoPtr
)
3179 return infoPtr
->nNumButtons
;
3183 static inline LRESULT
3184 TOOLBAR_ButtonStructSize (TOOLBAR_INFO
*infoPtr
, DWORD Size
)
3186 infoPtr
->dwStructSize
= Size
;
3193 TOOLBAR_ChangeBitmap (TOOLBAR_INFO
*infoPtr
, INT Id
, INT Index
)
3195 TBUTTON_INFO
*btnPtr
;
3198 TRACE("button %d, iBitmap now %d\n", Id
, Index
);
3200 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3204 btnPtr
= &infoPtr
->buttons
[nIndex
];
3205 btnPtr
->iBitmap
= Index
;
3207 /* we HAVE to erase the background, the new bitmap could be */
3209 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3216 TOOLBAR_CheckButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3218 TBUTTON_INFO
*btnPtr
;
3221 BOOL bChecked
= FALSE
;
3223 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3225 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, nIndex
, lParam
);
3230 btnPtr
= &infoPtr
->buttons
[nIndex
];
3232 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) != 0;
3234 if (LOWORD(lParam
) == FALSE
)
3235 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3237 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3239 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3240 if (nOldIndex
== nIndex
)
3242 if (nOldIndex
!= -1)
3243 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3245 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3248 if( bChecked
!= LOWORD(lParam
) )
3250 if (nOldIndex
!= -1)
3251 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3252 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3255 /* FIXME: Send a WM_NOTIFY?? */
3262 TOOLBAR_CommandToIndex (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3264 return TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3269 TOOLBAR_Customize (TOOLBAR_INFO
*infoPtr
)
3271 CUSTDLG_INFO custInfo
;
3275 custInfo
.tbInfo
= infoPtr
;
3276 custInfo
.tbHwnd
= infoPtr
->hwndSelf
;
3278 /* send TBN_BEGINADJUST notification */
3279 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3281 ret
= DialogBoxParamW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3282 infoPtr
->hwndSelf
, TOOLBAR_CustomizeDialogProc
, (LPARAM
)&custInfo
);
3284 /* send TBN_ENDADJUST notification */
3285 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3292 TOOLBAR_DeleteButton (TOOLBAR_INFO
*infoPtr
, INT nIndex
)
3295 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3297 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3300 memset(&nmtb
, 0, sizeof(nmtb
));
3301 nmtb
.iItem
= btnPtr
->idCommand
;
3302 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3303 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3304 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3305 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3306 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3307 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3308 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3310 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3312 if (infoPtr
->nNumButtons
== 1) {
3313 TRACE(" simple delete!\n");
3314 free_string( infoPtr
->buttons
);
3315 Free (infoPtr
->buttons
);
3316 infoPtr
->buttons
= NULL
;
3317 infoPtr
->nNumButtons
= 0;
3320 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3321 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3323 infoPtr
->nNumButtons
--;
3324 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3326 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3327 nIndex
* sizeof(TBUTTON_INFO
));
3330 if (nIndex
< infoPtr
->nNumButtons
) {
3331 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3332 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3335 free_string( oldButtons
+ nIndex
);
3339 TOOLBAR_LayoutToolbar(infoPtr
);
3341 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3348 TOOLBAR_EnableButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3350 TBUTTON_INFO
*btnPtr
;
3354 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3356 TRACE("hwnd=%p, btn id=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, Id
, lParam
);
3361 btnPtr
= &infoPtr
->buttons
[nIndex
];
3363 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3365 /* update the toolbar button state */
3366 if(LOWORD(lParam
) == FALSE
) {
3367 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3369 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3372 /* redraw the button only if the state of the button changed */
3373 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3374 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3380 static inline LRESULT
3381 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO
*infoPtr
)
3383 return infoPtr
->bAnchor
;
3388 TOOLBAR_GetBitmap (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3392 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3396 return infoPtr
->buttons
[nIndex
].iBitmap
;
3400 static inline LRESULT
3401 TOOLBAR_GetBitmapFlags (void)
3403 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3408 TOOLBAR_GetButton (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, TBBUTTON
*lpTbb
)
3410 TBUTTON_INFO
*btnPtr
;
3415 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3418 btnPtr
= &infoPtr
->buttons
[nIndex
];
3419 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3420 lpTbb
->idCommand
= btnPtr
->idCommand
;
3421 lpTbb
->fsState
= btnPtr
->fsState
;
3422 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3423 lpTbb
->bReserved
[0] = 0;
3424 lpTbb
->bReserved
[1] = 0;
3425 lpTbb
->dwData
= btnPtr
->dwData
;
3426 lpTbb
->iString
= btnPtr
->iString
;
3433 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO
*infoPtr
, INT Id
, LPTBBUTTONINFOW lpTbInfo
, BOOL bUnicode
)
3435 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3436 TBUTTON_INFO
*btnPtr
;
3439 if (lpTbInfo
== NULL
)
3442 /* MSDN documents an iImageLabel field added in Vista but it is not present in
3443 * the headers and tests shows that even with comctl 6 Vista accepts only the
3444 * original TBBUTTONINFO size
3446 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3448 WARN("Invalid button size\n");
3452 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lpTbInfo
->dwMask
& TBIF_BYINDEX
);
3456 btnPtr
= &infoPtr
->buttons
[nIndex
];
3457 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3458 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3459 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3460 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3461 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3462 lpTbInfo
->lParam
= btnPtr
->dwData
;
3463 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3464 /* tests show that for separators TBIF_SIZE returns not calculated width,
3465 but cx property, that differs from 0 only if application have
3466 specifically set it */
3467 lpTbInfo
->cx
= (btnPtr
->fsStyle
& BTNS_SEP
)
3468 ? btnPtr
->cx
: (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3469 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3470 lpTbInfo
->fsState
= btnPtr
->fsState
;
3471 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3472 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3473 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3474 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3475 can't use TOOLBAR_GetText here */
3476 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3477 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3479 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3481 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3483 lpTbInfo
->pszText
[0] = '\0';
3489 static inline LRESULT
3490 TOOLBAR_GetButtonSize (const TOOLBAR_INFO
*infoPtr
)
3492 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3493 (WORD
)infoPtr
->nButtonHeight
);
3498 TOOLBAR_GetButtonText (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPWSTR lpStr
, BOOL isW
)
3504 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3508 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3514 ret
= strlenW (lpText
);
3515 if (lpStr
) strcpyW (lpStr
, lpText
);
3519 ret
= WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3520 (LPSTR
)lpStr
, lpStr
? 0x7fffffff : 0, NULL
, NULL
) - 1;
3526 TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3528 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3529 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3530 return (LRESULT
)GETDISIMAGELIST(infoPtr
, wParam
);
3534 static inline LRESULT
3535 TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO
*infoPtr
)
3539 return infoPtr
->dwExStyle
;
3544 TOOLBAR_GetHotImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3546 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3547 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3548 return (LRESULT
)GETHOTIMAGELIST(infoPtr
, wParam
);
3553 TOOLBAR_GetHotItem (const TOOLBAR_INFO
*infoPtr
)
3555 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3558 if (infoPtr
->nHotItem
< 0)
3561 return (LRESULT
)infoPtr
->nHotItem
;
3566 TOOLBAR_GetDefImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3568 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3569 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3570 return (LRESULT
) GETDEFIMAGELIST(infoPtr
, wParam
);
3575 TOOLBAR_GetInsertMark (const TOOLBAR_INFO
*infoPtr
, TBINSERTMARK
*lptbim
)
3577 TRACE("hwnd = %p, lptbim = %p\n", infoPtr
->hwndSelf
, lptbim
);
3579 *lptbim
= infoPtr
->tbim
;
3585 static inline LRESULT
3586 TOOLBAR_GetInsertMarkColor (const TOOLBAR_INFO
*infoPtr
)
3588 TRACE("hwnd = %p\n", infoPtr
->hwndSelf
);
3590 return (LRESULT
)infoPtr
->clrInsertMark
;
3595 TOOLBAR_GetItemRect (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, LPRECT lpRect
)
3597 TBUTTON_INFO
*btnPtr
;
3599 btnPtr
= &infoPtr
->buttons
[nIndex
];
3600 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3605 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3608 lpRect
->left
= btnPtr
->rect
.left
;
3609 lpRect
->right
= btnPtr
->rect
.right
;
3610 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3611 lpRect
->top
= btnPtr
->rect
.top
;
3618 TOOLBAR_GetMaxSize (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
3623 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3624 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3626 TRACE("maximum size %d x %d\n",
3627 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3628 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3635 TOOLBAR_GetMetrics(const TOOLBAR_INFO
*infoPtr
, TBMETRICS
*pMetrics
)
3637 if (pMetrics
== NULL
)
3640 /* TODO: check if cbSize is a valid value */
3642 if (pMetrics
->dwMask
& TBMF_PAD
)
3644 pMetrics
->cxPad
= infoPtr
->szPadding
.cx
;
3645 pMetrics
->cyPad
= infoPtr
->szPadding
.cy
;
3648 if (pMetrics
->dwMask
& TBMF_BARPAD
)
3650 pMetrics
->cxBarPad
= infoPtr
->szBarPadding
.cx
;
3651 pMetrics
->cyBarPad
= infoPtr
->szBarPadding
.cy
;
3654 if (pMetrics
->dwMask
& TBMF_BUTTONSPACING
)
3656 pMetrics
->cxButtonSpacing
= infoPtr
->szSpacing
.cx
;
3657 pMetrics
->cyButtonSpacing
= infoPtr
->szSpacing
.cy
;
3664 /* << TOOLBAR_GetObject >> */
3667 static inline LRESULT
3668 TOOLBAR_GetPadding (const TOOLBAR_INFO
*infoPtr
)
3670 return MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3675 TOOLBAR_GetRect (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPRECT lpRect
)
3677 TBUTTON_INFO
*btnPtr
;
3680 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3681 btnPtr
= &infoPtr
->buttons
[nIndex
];
3682 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3688 lpRect
->left
= btnPtr
->rect
.left
;
3689 lpRect
->right
= btnPtr
->rect
.right
;
3690 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3691 lpRect
->top
= btnPtr
->rect
.top
;
3697 static inline LRESULT
3698 TOOLBAR_GetRows (const TOOLBAR_INFO
*infoPtr
)
3700 return infoPtr
->nRows
;
3705 TOOLBAR_GetState (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3709 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3713 return infoPtr
->buttons
[nIndex
].fsState
;
3717 static inline LRESULT
3718 TOOLBAR_GetStyle (const TOOLBAR_INFO
*infoPtr
)
3720 return infoPtr
->dwStyle
;
3724 static inline LRESULT
3725 TOOLBAR_GetTextRows (const TOOLBAR_INFO
*infoPtr
)
3727 return infoPtr
->nMaxTextRows
;
3732 TOOLBAR_GetToolTips (TOOLBAR_INFO
*infoPtr
)
3734 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3735 TOOLBAR_TooltipCreateControl(infoPtr
);
3736 return (LRESULT
)infoPtr
->hwndToolTip
;
3741 TOOLBAR_GetUnicodeFormat (const TOOLBAR_INFO
*infoPtr
)
3743 TRACE("%s hwnd=%p\n",
3744 infoPtr
->bUnicode
? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
3746 return infoPtr
->bUnicode
;
3750 static inline LRESULT
3751 TOOLBAR_GetVersion (const TOOLBAR_INFO
*infoPtr
)
3753 return infoPtr
->iVersion
;
3758 TOOLBAR_HideButton (TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fHide
)
3760 TBUTTON_INFO
*btnPtr
;
3766 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3770 btnPtr
= &infoPtr
->buttons
[nIndex
];
3771 oldState
= btnPtr
->fsState
;
3774 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3776 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3778 if (oldState
!= btnPtr
->fsState
) {
3779 TOOLBAR_LayoutToolbar (infoPtr
);
3780 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3787 static inline LRESULT
3788 TOOLBAR_HitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
* lpPt
)
3790 return TOOLBAR_InternalHitTest (infoPtr
, lpPt
, NULL
);
3795 TOOLBAR_Indeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fIndeterminate
)
3797 TBUTTON_INFO
*btnPtr
;
3801 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3805 btnPtr
= &infoPtr
->buttons
[nIndex
];
3806 oldState
= btnPtr
->fsState
;
3809 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3811 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3813 if(oldState
!= btnPtr
->fsState
)
3814 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3821 TOOLBAR_InsertButtonT(TOOLBAR_INFO
*infoPtr
, INT nIndex
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
3827 /* EPP: this seems to be an undocumented call (from my IE4)
3828 * I assume in that case that:
3829 * - index of insertion is at the end of existing buttons
3830 * I only see this happen with nIndex == -1, but it could have a special
3831 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3833 nIndex
= infoPtr
->nNumButtons
;
3835 } else if (nIndex
< 0)
3838 TRACE("inserting button index=%d\n", nIndex
);
3839 if (nIndex
> infoPtr
->nNumButtons
) {
3840 nIndex
= infoPtr
->nNumButtons
;
3841 TRACE("adjust index=%d\n", nIndex
);
3844 return TOOLBAR_InternalInsertButtonsT(infoPtr
, nIndex
, 1, lpTbb
, fUnicode
);
3847 /* << TOOLBAR_InsertMarkHitTest >> */
3851 TOOLBAR_IsButtonChecked (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3855 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3859 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3864 TOOLBAR_IsButtonEnabled (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3868 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3872 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3877 TOOLBAR_IsButtonHidden (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3881 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3885 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3890 TOOLBAR_IsButtonHighlighted (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3894 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3898 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3903 TOOLBAR_IsButtonIndeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3907 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3911 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3916 TOOLBAR_IsButtonPressed (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3920 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3924 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3929 TOOLBAR_LoadImages (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HINSTANCE hInstance
)
3932 tbab
.hInst
= hInstance
;
3935 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", infoPtr
->hwndSelf
, tbab
.hInst
, tbab
.nID
);
3937 return TOOLBAR_AddBitmap(infoPtr
, 0, &tbab
);
3942 TOOLBAR_MapAccelerator (const TOOLBAR_INFO
*infoPtr
, WCHAR wAccel
, UINT
*pIDButton
)
3944 WCHAR wszAccel
[] = {'&',wAccel
,0};
3947 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3948 infoPtr
->hwndSelf
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3950 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3952 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3953 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3954 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3956 int iLen
= strlenW(wszAccel
);
3957 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3964 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3969 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
3971 *pIDButton
= btnPtr
->idCommand
;
3983 TOOLBAR_MarkButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fMark
)
3987 TBUTTON_INFO
*btnPtr
;
3989 TRACE("hwnd = %p, Id = %d, fMark = 0%d\n", infoPtr
->hwndSelf
, Id
, fMark
);
3991 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3995 btnPtr
= &infoPtr
->buttons
[nIndex
];
3996 oldState
= btnPtr
->fsState
;
3999 btnPtr
->fsState
|= TBSTATE_MARKED
;
4001 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
4003 if(oldState
!= btnPtr
->fsState
)
4004 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4010 /* fixes up an index of a button affected by a move */
4011 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
4015 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
4017 else if (*pIndex
== nIndex
)
4018 *pIndex
= nMoveIndex
;
4022 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
4024 else if (*pIndex
== nIndex
)
4025 *pIndex
= nMoveIndex
;
4031 TOOLBAR_MoveButton (TOOLBAR_INFO
*infoPtr
, INT Id
, INT nMoveIndex
)
4035 TBUTTON_INFO button
;
4037 TRACE("hwnd=%p, Id=%d, nMoveIndex=%d\n", infoPtr
->hwndSelf
, Id
, nMoveIndex
);
4039 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, TRUE
);
4040 if ((nIndex
== -1) || (nMoveIndex
< 0))
4043 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
4044 nMoveIndex
= infoPtr
->nNumButtons
- 1;
4046 button
= infoPtr
->buttons
[nIndex
];
4048 /* move button right */
4049 if (nIndex
< nMoveIndex
)
4051 nCount
= nMoveIndex
- nIndex
;
4052 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
4053 infoPtr
->buttons
[nMoveIndex
] = button
;
4055 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
4056 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
4057 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
4058 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
4060 else if (nIndex
> nMoveIndex
) /* move button left */
4062 nCount
= nIndex
- nMoveIndex
;
4063 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
4064 infoPtr
->buttons
[nMoveIndex
] = button
;
4066 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
4067 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
4068 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
4069 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
4072 TOOLBAR_LayoutToolbar(infoPtr
);
4073 TOOLBAR_AutoSize(infoPtr
);
4074 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4081 TOOLBAR_PressButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fPress
)
4083 TBUTTON_INFO
*btnPtr
;
4087 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
4091 btnPtr
= &infoPtr
->buttons
[nIndex
];
4092 oldState
= btnPtr
->fsState
;
4095 btnPtr
->fsState
|= TBSTATE_PRESSED
;
4097 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
4099 if(oldState
!= btnPtr
->fsState
)
4100 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4105 /* FIXME: there might still be some confusion her between number of buttons
4106 * and number of bitmaps */
4108 TOOLBAR_ReplaceBitmap (TOOLBAR_INFO
*infoPtr
, const TBREPLACEBITMAP
*lpReplace
)
4111 int i
= 0, nOldButtons
= 0, pos
= 0;
4112 int nOldBitmaps
, nNewBitmaps
= 0;
4113 HIMAGELIST himlDef
= 0;
4115 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4116 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
4117 lpReplace
->nButtons
);
4119 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4121 FIXME("changing standard bitmaps not implemented\n");
4124 else if (lpReplace
->hInstOld
!= 0 && lpReplace
->hInstOld
!= lpReplace
->hInstNew
)
4125 FIXME("resources not in the current module not implemented\n");
4127 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4128 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4129 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4130 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4131 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4133 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4134 nOldButtons
= tbi
->nButtons
;
4135 tbi
->nButtons
= lpReplace
->nButtons
;
4136 tbi
->hInst
= lpReplace
->hInstNew
;
4137 tbi
->nID
= lpReplace
->nIDNew
;
4138 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4141 pos
+= tbi
->nButtons
;
4144 if (nOldButtons
== 0)
4146 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4150 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4153 if (lpReplace
->hInstNew
)
4154 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4156 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4158 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4159 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4161 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4163 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4164 ImageList_Remove(himlDef
, i
);
4168 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4169 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4170 DeleteObject(hBitmap
);
4173 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4175 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4176 pos
, nOldBitmaps
, nNewBitmaps
);
4178 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4183 /* helper for TOOLBAR_SaveRestoreW */
4185 TOOLBAR_Save(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*params
)
4189 BOOL alloced
= FALSE
;
4192 TRACE( "save to %s %s\n", debugstr_w(params
->pszSubKey
), debugstr_w(params
->pszValueName
) );
4194 memset( &save
, 0, sizeof(save
) );
4195 save
.cbData
= infoPtr
->nNumButtons
* sizeof(DWORD
);
4197 save
.cButtons
= infoPtr
->nNumButtons
;
4198 save
.tbButton
.idCommand
= -1;
4199 TOOLBAR_SendNotify( &save
.hdr
, infoPtr
, TBN_SAVE
);
4203 save
.pData
= Alloc( save
.cbData
);
4204 if (!save
.pData
) return FALSE
;
4207 if (!save
.pCurrent
) save
.pCurrent
= save
.pData
;
4209 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4212 save
.tbButton
.iBitmap
= infoPtr
->buttons
[i
].iBitmap
;
4213 save
.tbButton
.idCommand
= infoPtr
->buttons
[i
].idCommand
;
4214 save
.tbButton
.fsState
= infoPtr
->buttons
[i
].fsState
;
4215 save
.tbButton
.fsStyle
= infoPtr
->buttons
[i
].fsStyle
;
4216 memset( save
.tbButton
.bReserved
, 0, sizeof(save
.tbButton
.bReserved
) );
4217 save
.tbButton
.dwData
= infoPtr
->buttons
[i
].dwData
;
4218 save
.tbButton
.iString
= infoPtr
->buttons
[i
].iString
;
4220 *save
.pCurrent
++ = save
.tbButton
.idCommand
;
4222 TOOLBAR_SendNotify( &save
.hdr
, infoPtr
, TBN_SAVE
);
4225 ret
= RegCreateKeyW( params
->hkr
, params
->pszSubKey
, &key
);
4226 if (ret
== ERROR_SUCCESS
)
4228 ret
= RegSetValueExW( key
, params
->pszValueName
, 0, REG_BINARY
, (BYTE
*)save
.pData
, save
.cbData
);
4232 if (alloced
) Free( save
.pData
);
4237 /* helper for TOOLBAR_Restore */
4239 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4243 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4245 free_string( infoPtr
->buttons
+ i
);
4246 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4249 Free(infoPtr
->buttons
);
4250 infoPtr
->buttons
= NULL
;
4251 infoPtr
->nNumButtons
= 0;
4255 /* helper for TOOLBAR_SaveRestoreW */
4257 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4267 /* restore toolbar information */
4268 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4269 debugstr_w(lpSave
->pszValueName
));
4271 memset(&nmtbr
, 0, sizeof(nmtbr
));
4273 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4274 KEY_QUERY_VALUE
, &hkey
);
4276 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4278 if (!res
&& dwType
!= REG_BINARY
)
4279 res
= ERROR_FILE_NOT_FOUND
;
4282 nmtbr
.pData
= Alloc(dwSize
);
4283 nmtbr
.cbData
= dwSize
;
4284 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4287 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4288 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4291 nmtbr
.pCurrent
= nmtbr
.pData
;
4293 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4294 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4296 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4298 INT i
, count
= nmtbr
.cButtons
;
4300 /* remove all existing buttons as this function is designed to
4301 * restore the toolbar to a previously saved state */
4302 TOOLBAR_DeleteAllButtons(infoPtr
);
4304 for (i
= 0; i
< count
; i
++)
4307 nmtbr
.tbButton
.iBitmap
= -1;
4308 nmtbr
.tbButton
.fsState
= 0;
4309 nmtbr
.tbButton
.fsStyle
= 0;
4310 nmtbr
.tbButton
.dwData
= 0;
4311 nmtbr
.tbButton
.iString
= 0;
4313 if (*nmtbr
.pCurrent
& 0x80000000)
4316 nmtbr
.tbButton
.iBitmap
= SEPARATOR_WIDTH
;
4317 nmtbr
.tbButton
.idCommand
= 0;
4318 nmtbr
.tbButton
.fsStyle
= BTNS_SEP
;
4319 if (*nmtbr
.pCurrent
!= (DWORD
)-1)
4320 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4323 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4327 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4329 /* All returned ptrs and -1 are ignored */
4330 if (!IS_INTRESOURCE(nmtbr
.tbButton
.iString
))
4331 nmtbr
.tbButton
.iString
= 0;
4333 TOOLBAR_InsertButtonT(infoPtr
, -1, &nmtbr
.tbButton
, TRUE
);
4336 TOOLBAR_SendNotify( &hdr
, infoPtr
, TBN_BEGINADJUST
);
4342 UINT code
= infoPtr
->bUnicode
? TBN_GETBUTTONINFOW
: TBN_GETBUTTONINFOA
;
4345 memset( &tb
, 0, sizeof(tb
) );
4347 tb
.cchText
= sizeof(buf
) / sizeof(buf
[0]);
4350 /* Use the same struct for both A and W versions since the layout is the same. */
4351 if (!TOOLBAR_SendNotify( &tb
.hdr
, infoPtr
, code
))
4354 idx
= TOOLBAR_GetButtonIndex( infoPtr
, tb
.tbButton
.idCommand
, FALSE
);
4355 if (idx
== -1) continue;
4357 /* tb.pszText is ignored - the string comes from tb.tbButton.iString, which may
4358 be an index or a ptr. Either way it is simply copied. There is no api to change
4359 the string index, so we set it manually. The other properties can be set with SetButtonInfo. */
4360 free_string( infoPtr
->buttons
+ idx
);
4361 infoPtr
->buttons
[idx
].iString
= tb
.tbButton
.iString
;
4363 memset( &bi
, 0, sizeof(bi
) );
4364 bi
.cbSize
= sizeof(bi
);
4365 bi
.dwMask
= TBIF_IMAGE
| TBIF_STATE
| TBIF_STYLE
| TBIF_LPARAM
;
4366 bi
.iImage
= tb
.tbButton
.iBitmap
;
4367 bi
.fsState
= tb
.tbButton
.fsState
;
4368 bi
.fsStyle
= tb
.tbButton
.fsStyle
;
4369 bi
.lParam
= tb
.tbButton
.dwData
;
4371 TOOLBAR_SetButtonInfo( infoPtr
, tb
.tbButton
.idCommand
, &bi
, TRUE
);
4373 TOOLBAR_SendNotify( &hdr
, infoPtr
, TBN_ENDADJUST
);
4375 /* remove all uninitialised buttons
4376 * note: loop backwards to avoid having to fixup i on a
4378 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4379 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4380 TOOLBAR_DeleteButton(infoPtr
, i
);
4382 /* only indicate success if at least one button survived */
4383 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4394 TOOLBAR_SaveRestoreW (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4396 if (lpSave
== NULL
) return 0;
4399 return TOOLBAR_Save(infoPtr
, lpSave
);
4401 return TOOLBAR_Restore(infoPtr
, lpSave
);
4406 TOOLBAR_SaveRestoreA (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4408 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4409 TBSAVEPARAMSW SaveW
;
4413 if (lpSave
== NULL
) return 0;
4415 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4416 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4417 if (!pszSubKey
) goto exit
;
4418 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4420 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4421 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4422 if (!pszValueName
) goto exit
;
4423 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4425 SaveW
.pszValueName
= pszValueName
;
4426 SaveW
.pszSubKey
= pszSubKey
;
4427 SaveW
.hkr
= lpSave
->hkr
;
4428 result
= TOOLBAR_SaveRestoreW(infoPtr
, wParam
, &SaveW
);
4431 Free (pszValueName
);
4439 TOOLBAR_SetAnchorHighlight (TOOLBAR_INFO
*infoPtr
, BOOL bAnchor
)
4441 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4443 TRACE("hwnd=%p, bAnchor = %s\n", infoPtr
->hwndSelf
, bAnchor
? "TRUE" : "FALSE");
4445 infoPtr
->bAnchor
= bAnchor
;
4447 /* Native does not remove the hot effect from an already hot button */
4449 return (LRESULT
)bOldAnchor
;
4454 TOOLBAR_SetBitmapSize (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4456 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4457 short width
= (short)LOWORD(lParam
);
4458 short height
= (short)HIWORD(lParam
);
4460 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", infoPtr
->hwndSelf
, wParam
, lParam
);
4463 FIXME("wParam is %ld. Perhaps image list index?\n", wParam
);
4465 /* 0 width or height is changed to 1 */
4471 if (infoPtr
->nNumButtons
> 0)
4472 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4473 infoPtr
->nNumButtons
,
4474 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
, width
, height
);
4476 if (width
< -1 || height
< -1)
4478 /* Windows destroys the imagelist and seems to actually use negative
4479 * values to compute button sizes */
4480 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width
, height
);
4484 /* width or height of -1 means no change */
4486 infoPtr
->nBitmapWidth
= width
;
4488 infoPtr
->nBitmapHeight
= height
;
4490 if ((himlDef
== infoPtr
->himlInt
) &&
4491 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4493 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4494 infoPtr
->nBitmapHeight
);
4497 TOOLBAR_CalcToolbar(infoPtr
);
4498 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4504 TOOLBAR_SetButtonInfo (TOOLBAR_INFO
*infoPtr
, INT Id
,
4505 const TBBUTTONINFOW
*lptbbi
, BOOL isW
)
4507 TBUTTON_INFO
*btnPtr
;
4513 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4516 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lptbbi
->dwMask
& TBIF_BYINDEX
);
4520 btnPtr
= &infoPtr
->buttons
[nIndex
];
4521 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4522 btnPtr
->idCommand
= lptbbi
->idCommand
;
4523 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4524 btnPtr
->iBitmap
= lptbbi
->iImage
;
4525 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4526 btnPtr
->dwData
= lptbbi
->lParam
;
4527 if (lptbbi
->dwMask
& TBIF_SIZE
)
4528 btnPtr
->cx
= lptbbi
->cx
;
4529 if (lptbbi
->dwMask
& TBIF_STATE
)
4530 btnPtr
->fsState
= lptbbi
->fsState
;
4531 if (lptbbi
->dwMask
& TBIF_STYLE
)
4532 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4534 if (lptbbi
->dwMask
& TBIF_TEXT
)
4535 set_stringT( btnPtr
, lptbbi
->pszText
, isW
);
4537 /* save the button rect to see if we need to redraw the whole toolbar */
4538 oldBtnRect
= btnPtr
->rect
;
4539 TOOLBAR_LayoutToolbar(infoPtr
);
4541 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4542 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4544 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4551 TOOLBAR_SetButtonSize (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4553 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4554 int top
= default_top_margin(infoPtr
);
4556 if ((cx
< 0) || (cy
< 0))
4558 ERR("invalid parameter 0x%08x\n", (DWORD
)lParam
);
4562 TRACE("%p, cx = %d, cy = %d\n", infoPtr
->hwndSelf
, cx
, cy
);
4564 /* The documentation claims you can only change the button size before
4565 * any button has been added. But this is wrong.
4566 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4567 * it to the toolbar, and it checks that the return value is nonzero - mjm
4568 * Further testing shows that we must actually perform the change too.
4571 * The documentation also does not mention that if 0 is supplied for
4572 * either size, the system changes it to the default of 24 wide and
4573 * 22 high. Demonstrated in ControlSpy Toolbar. GLA 3/02
4575 if (cx
== 0) cx
= 24;
4576 if (cy
== 0) cy
= 22;
4578 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4579 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4581 if (cx
!= infoPtr
->nButtonWidth
|| cy
!= infoPtr
->nButtonHeight
||
4582 top
!= infoPtr
->iTopMargin
)
4584 infoPtr
->nButtonWidth
= cx
;
4585 infoPtr
->nButtonHeight
= cy
;
4586 infoPtr
->iTopMargin
= top
;
4588 TOOLBAR_LayoutToolbar( infoPtr
);
4589 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
4596 TOOLBAR_SetButtonWidth (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4598 /* if setting to current values, ignore */
4599 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4600 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4601 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4602 infoPtr
->cxMin
, infoPtr
->cxMax
);
4606 /* save new values */
4607 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4608 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4610 /* otherwise we need to recalc the toolbar and in some cases
4611 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4612 which doesn't actually draw - GA). */
4613 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4614 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4616 TOOLBAR_CalcToolbar (infoPtr
);
4618 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
4625 TOOLBAR_SetCmdId (TOOLBAR_INFO
*infoPtr
, INT nIndex
, INT nId
)
4627 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4630 infoPtr
->buttons
[nIndex
].idCommand
= nId
;
4632 if (infoPtr
->hwndToolTip
) {
4634 FIXME("change tool tip!\n");
4643 TOOLBAR_SetDisabledImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4645 HIMAGELIST himlTemp
;
4648 if (infoPtr
->iVersion
>= 5)
4651 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4652 &infoPtr
->cimlDis
, himl
, id
);
4654 /* FIXME: redraw ? */
4656 return (LRESULT
)himlTemp
;
4661 TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4665 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", infoPtr
->hwndSelf
, (DWORD
)wParam
, (DWORD
)lParam
);
4667 dwTemp
= infoPtr
->dwDTFlags
;
4668 infoPtr
->dwDTFlags
=
4669 (infoPtr
->dwDTFlags
& (DWORD
)wParam
) | (DWORD
)lParam
;
4671 return (LRESULT
)dwTemp
;
4674 /* This function differs a bit from what MSDN says it does:
4675 * 1. lParam contains extended style flags to OR with current style
4676 * (MSDN isn't clear on the OR bit)
4677 * 2. wParam appears to contain extended style flags to be reset
4678 * (MSDN says that this parameter is reserved)
4681 TOOLBAR_SetExtendedStyle (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD style
)
4683 DWORD old_style
= infoPtr
->dwExStyle
;
4685 TRACE("mask=0x%08x, style=0x%08x\n", mask
, style
);
4688 infoPtr
->dwExStyle
= (old_style
& ~mask
) | (style
& mask
);
4690 infoPtr
->dwExStyle
= style
;
4692 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4693 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4694 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4696 if ((old_style
^ infoPtr
->dwExStyle
) & TBSTYLE_EX_MIXEDBUTTONS
)
4697 TOOLBAR_CalcToolbar(infoPtr
);
4699 TOOLBAR_LayoutToolbar(infoPtr
);
4701 TOOLBAR_AutoSize(infoPtr
);
4702 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4709 TOOLBAR_SetHotImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4711 HIMAGELIST himlTemp
;
4714 if (infoPtr
->iVersion
>= 5)
4717 TRACE("hwnd = %p, himl = %p, id = %d\n", infoPtr
->hwndSelf
, himl
, id
);
4719 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4720 &infoPtr
->cimlHot
, himl
, id
);
4722 /* FIXME: redraw ? */
4724 return (LRESULT
)himlTemp
;
4728 /* Makes previous hot button no longer hot, makes the specified
4729 * button hot and sends appropriate notifications. dwReason is one or
4730 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4731 * NOTE 1: this function does not validate nHit
4732 * NOTE 2: the name of this function is completely made up and
4733 * not based on any documentation from Microsoft. */
4735 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4737 if (infoPtr
->nHotItem
!= nHit
)
4739 NMTBHOTITEM nmhotitem
;
4740 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4742 nmhotitem
.dwFlags
= dwReason
;
4743 if(infoPtr
->nHotItem
>= 0)
4745 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4746 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4750 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4751 nmhotitem
.idOld
= 0;
4756 btnPtr
= &infoPtr
->buttons
[nHit
];
4757 nmhotitem
.idNew
= btnPtr
->idCommand
;
4761 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4762 nmhotitem
.idNew
= 0;
4765 /* now change the hot and invalidate the old and new buttons - if the
4767 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4770 oldBtnPtr
->bHot
= FALSE
;
4771 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4773 /* setting disabled buttons as hot fails even if the notify contains the button id */
4774 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4775 btnPtr
->bHot
= TRUE
;
4776 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4777 infoPtr
->nHotItem
= nHit
;
4780 infoPtr
->nHotItem
= -1;
4786 TOOLBAR_SetHotItem (TOOLBAR_INFO
*infoPtr
, INT nHotItem
)
4788 INT nOldHotItem
= infoPtr
->nHotItem
;
4790 TRACE("hwnd = %p, nHotItem = %d\n", infoPtr
->hwndSelf
, nHotItem
);
4792 if (nHotItem
>= infoPtr
->nNumButtons
)
4793 return infoPtr
->nHotItem
;
4798 /* NOTE: an application can still remove the hot item even if anchor
4799 * highlighting is enabled */
4801 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, HICF_OTHER
);
4803 if (nOldHotItem
< 0)
4806 return (LRESULT
)nOldHotItem
;
4811 TOOLBAR_SetImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4813 HIMAGELIST himlTemp
;
4814 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4815 INT oldBitmapWidth
= infoPtr
->nBitmapWidth
;
4816 INT oldBitmapHeight
= infoPtr
->nBitmapHeight
;
4819 if (infoPtr
->iVersion
>= 5)
4822 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4823 &infoPtr
->cimlDef
, himl
, id
);
4825 infoPtr
->nNumBitmaps
= 0;
4826 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4827 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4829 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4830 &infoPtr
->nBitmapHeight
))
4832 infoPtr
->nBitmapWidth
= 1;
4833 infoPtr
->nBitmapHeight
= 1;
4835 if ((oldBitmapWidth
!= infoPtr
->nBitmapWidth
) || (oldBitmapHeight
!= infoPtr
->nBitmapHeight
))
4837 TOOLBAR_CalcToolbar(infoPtr
);
4838 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4839 TOOLBAR_SetButtonSize(infoPtr
, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4842 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4843 infoPtr
->hwndSelf
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4844 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4846 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4848 return (LRESULT
)himlTemp
;
4853 TOOLBAR_SetIndent (TOOLBAR_INFO
*infoPtr
, INT nIndent
)
4855 infoPtr
->nIndent
= nIndent
;
4859 /* process only on indent changing */
4860 if(infoPtr
->nIndent
!= nIndent
)
4862 infoPtr
->nIndent
= nIndent
;
4863 TOOLBAR_CalcToolbar (infoPtr
);
4864 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4872 TOOLBAR_SetInsertMark (TOOLBAR_INFO
*infoPtr
, const TBINSERTMARK
*lptbim
)
4874 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", infoPtr
->hwndSelf
, lptbim
->iButton
, lptbim
->dwFlags
);
4876 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4878 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4882 if ((lptbim
->iButton
== -1) ||
4883 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4884 (lptbim
->iButton
>= 0)))
4886 infoPtr
->tbim
= *lptbim
;
4887 /* FIXME: don't need to update entire toolbar */
4888 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4891 ERR("Invalid button index %d\n", lptbim
->iButton
);
4898 TOOLBAR_SetInsertMarkColor (TOOLBAR_INFO
*infoPtr
, COLORREF clr
)
4900 infoPtr
->clrInsertMark
= clr
;
4902 /* FIXME: don't need to update entire toolbar */
4903 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4910 TOOLBAR_SetMaxTextRows (TOOLBAR_INFO
*infoPtr
, INT nMaxRows
)
4912 infoPtr
->nMaxTextRows
= nMaxRows
;
4914 TOOLBAR_CalcToolbar(infoPtr
);
4920 TOOLBAR_SetMetrics(TOOLBAR_INFO
*infoPtr
, TBMETRICS
*pMetrics
)
4922 BOOL changed
= FALSE
;
4927 /* TODO: check if cbSize is a valid value */
4929 if (pMetrics
->dwMask
& TBMF_PAD
)
4931 infoPtr
->szPadding
.cx
= pMetrics
->cxPad
;
4932 infoPtr
->szPadding
.cy
= pMetrics
->cyPad
;
4936 if (pMetrics
->dwMask
& TBMF_PAD
)
4938 infoPtr
->szBarPadding
.cx
= pMetrics
->cxBarPad
;
4939 infoPtr
->szBarPadding
.cy
= pMetrics
->cyBarPad
;
4943 if (pMetrics
->dwMask
& TBMF_BUTTONSPACING
)
4945 infoPtr
->szSpacing
.cx
= pMetrics
->cxButtonSpacing
;
4946 infoPtr
->szSpacing
.cy
= pMetrics
->cyButtonSpacing
;
4951 TOOLBAR_CalcToolbar(infoPtr
);
4957 /* MSDN gives slightly wrong info on padding.
4958 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4959 * 2. It is not used to create a blank area between the edge of the button
4960 * and the text or image if TBSTYLE_LIST is set. It is used to control
4961 * the gap between the image and text.
4962 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4963 * to control the bottom and right borders [with the border being
4964 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4965 * is shared evenly on both sides of the button.
4966 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4969 TOOLBAR_SetPadding (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4973 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4974 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4975 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4976 TRACE("cx=%d, cy=%d\n",
4977 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4978 return (LRESULT
) oldPad
;
4983 TOOLBAR_SetParent (TOOLBAR_INFO
*infoPtr
, HWND hParent
)
4989 hwndOldNotify
= infoPtr
->hwndNotify
;
4990 infoPtr
->hwndNotify
= hParent
;
4992 return (LRESULT
)hwndOldNotify
;
4997 TOOLBAR_SetRows (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPRECT lprc
)
4999 int rows
= LOWORD(wParam
);
5000 BOOL bLarger
= HIWORD(wParam
);
5004 TRACE("Setting rows to %d (%d)\n", rows
, bLarger
);
5006 if(infoPtr
->nRows
!= rows
)
5008 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
;
5009 int curColumn
= 0; /* Current column */
5010 int curRow
= 0; /* Current row */
5011 int hidden
= 0; /* Number of hidden buttons */
5012 int seps
= 0; /* Number of separators */
5013 int idealWrap
= 0; /* Ideal wrap point */
5018 Calculate new size and wrap points - Under windows, setrows will
5019 change the dimensions if needed to show the number of requested
5020 rows (if CCS_NORESIZE is set), or will take up the whole window
5021 (if no CCS_NORESIZE).
5023 Basic algorithm - If N buttons, and y rows requested, each row
5024 contains N/y buttons.
5026 FIXME: Handling of separators not obvious from testing results
5027 FIXME: Take width of window into account?
5030 /* Loop through the buttons one by one counting key items */
5031 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
5033 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
5034 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
5036 else if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
5040 /* FIXME: Separators make this quite complex */
5041 if (seps
) FIXME("Separators unhandled\n");
5043 /* Round up so more per line, i.e., less rows */
5044 idealWrap
= (infoPtr
->nNumButtons
- hidden
+ (rows
-1)) / (rows
? rows
: 1);
5046 /* Calculate ideal wrap point if we are allowed to grow, but cannot
5047 achieve the requested number of rows. */
5048 if (bLarger
&& idealWrap
> 1)
5050 int resRows
= (infoPtr
->nNumButtons
+ (idealWrap
-1)) / idealWrap
;
5051 int moreRows
= (infoPtr
->nNumButtons
+ (idealWrap
-2)) / (idealWrap
-1);
5053 if (resRows
< rows
&& moreRows
> rows
)
5056 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap
);
5060 curColumn
= curRow
= 0;
5062 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap
,
5063 infoPtr
->nNumButtons
, hidden
, rows
);
5065 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
5067 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
5070 /* Step on, wrap if necessary or flag next to wrap */
5079 if (curColumn
> (idealWrap
-1)) {
5081 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
5085 TRACE("Result - %d rows\n", curRow
+ 1);
5087 /* recalculate toolbar */
5088 TOOLBAR_CalcToolbar (infoPtr
);
5090 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
5091 if NORESIZE is NOT set, then the toolbar will always be resized to
5092 take up the whole window. With it set, sizing needs to be manual. */
5093 if (infoPtr
->dwStyle
& CCS_NORESIZE
) {
5094 SetWindowPos(infoPtr
->hwndSelf
, NULL
, 0, 0,
5095 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
5096 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
,
5097 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
5100 /* repaint toolbar */
5101 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5104 /* return bounding rectangle */
5106 lprc
->left
= infoPtr
->rcBound
.left
;
5107 lprc
->right
= infoPtr
->rcBound
.right
;
5108 lprc
->top
= infoPtr
->rcBound
.top
;
5109 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
5117 TOOLBAR_SetState (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
5119 TBUTTON_INFO
*btnPtr
;
5122 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
5126 btnPtr
= &infoPtr
->buttons
[nIndex
];
5128 /* if hidden state has changed the invalidate entire window and recalc */
5129 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
5130 btnPtr
->fsState
= LOWORD(lParam
);
5131 TOOLBAR_CalcToolbar (infoPtr
);
5132 InvalidateRect(infoPtr
->hwndSelf
, 0, TRUE
);
5136 /* process state changing if current state doesn't match new state */
5137 if(btnPtr
->fsState
!= LOWORD(lParam
))
5139 btnPtr
->fsState
= LOWORD(lParam
);
5140 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5146 static inline void unwrap(TOOLBAR_INFO
*info
)
5150 for (i
= 0; i
< info
->nNumButtons
; i
++)
5151 info
->buttons
[i
].fsState
&= ~TBSTATE_WRAP
;
5155 TOOLBAR_SetStyle (TOOLBAR_INFO
*infoPtr
, DWORD style
)
5157 DWORD dwOldStyle
= infoPtr
->dwStyle
;
5159 TRACE("new style 0x%08x\n", style
);
5161 if (style
& TBSTYLE_LIST
)
5162 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
5164 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
5166 infoPtr
->dwStyle
= style
;
5167 TOOLBAR_CheckStyle(infoPtr
);
5169 if ((dwOldStyle
^ style
) & TBSTYLE_WRAPABLE
)
5171 if (dwOldStyle
& TBSTYLE_WRAPABLE
)
5173 TOOLBAR_CalcToolbar(infoPtr
);
5175 else if ((dwOldStyle
^ style
) & CCS_VERT
)
5176 TOOLBAR_LayoutToolbar(infoPtr
);
5178 /* only resize if one of the CCS_* styles was changed */
5179 if ((dwOldStyle
^ style
) & COMMON_STYLES
)
5181 TOOLBAR_AutoSize(infoPtr
);
5182 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5189 static inline LRESULT
5190 TOOLBAR_SetToolTips (TOOLBAR_INFO
*infoPtr
, HWND hwndTooltip
)
5192 TRACE("hwnd=%p, hwndTooltip=%p\n", infoPtr
->hwndSelf
, hwndTooltip
);
5194 infoPtr
->hwndToolTip
= hwndTooltip
;
5200 TOOLBAR_SetUnicodeFormat (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
5204 TRACE("%s hwnd=%p\n",
5205 ((BOOL
)wParam
) ? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
5207 bTemp
= infoPtr
->bUnicode
;
5208 infoPtr
->bUnicode
= (BOOL
)wParam
;
5215 TOOLBAR_GetColorScheme (const TOOLBAR_INFO
*infoPtr
, LPCOLORSCHEME lParam
)
5217 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
5218 comctl32_color
.clrBtnHighlight
:
5219 infoPtr
->clrBtnHighlight
;
5220 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
5221 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
5227 TOOLBAR_SetColorScheme (TOOLBAR_INFO
*infoPtr
, const COLORSCHEME
*lParam
)
5229 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5230 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
5231 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
5233 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
5234 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
5235 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5241 TOOLBAR_SetVersion (TOOLBAR_INFO
*infoPtr
, INT iVersion
)
5243 INT iOldVersion
= infoPtr
->iVersion
;
5245 infoPtr
->iVersion
= iVersion
;
5247 if (infoPtr
->iVersion
>= 5)
5248 TOOLBAR_SetUnicodeFormat(infoPtr
, TRUE
);
5255 TOOLBAR_GetStringA (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPSTR str
)
5257 WORD iString
= HIWORD(wParam
);
5258 WORD buffersize
= LOWORD(wParam
);
5261 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, buffersize
, str
);
5263 if (iString
< infoPtr
->nNumStrings
)
5265 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
5268 TRACE("returning %s\n", debugstr_a(str
));
5271 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5278 TOOLBAR_GetStringW (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPWSTR str
)
5280 WORD iString
= HIWORD(wParam
);
5281 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5284 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, LOWORD(wParam
), str
);
5286 if (iString
< infoPtr
->nNumStrings
)
5288 len
= min(len
, strlenW(infoPtr
->strings
[iString
]));
5289 ret
= (len
+1)*sizeof(WCHAR
);
5292 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5297 TRACE("returning %s\n", debugstr_w(str
));
5300 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5305 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5306 * is the maximum size of the toolbar? */
5307 static LRESULT
TOOLBAR_Unkwn45D(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5309 SIZE
* pSize
= (SIZE
*)lParam
;
5310 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5315 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5316 * caller to specify a reason why the hot item changed (rather than just the
5317 * HICF_OTHER that TB_SETHOTITEM sends). */
5319 TOOLBAR_SetHotItem2 (TOOLBAR_INFO
*infoPtr
, INT nHotItem
, LPARAM lParam
)
5321 INT nOldHotItem
= infoPtr
->nHotItem
;
5323 TRACE("old item=%d, new item=%d, flags=%08x\n",
5324 nOldHotItem
, nHotItem
, (DWORD
)lParam
);
5326 if (nHotItem
< 0 || nHotItem
> infoPtr
->nNumButtons
)
5329 /* NOTE: an application can still remove the hot item even if anchor
5330 * highlighting is enabled */
5332 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, lParam
);
5334 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5337 /* Sets the toolbar global iListGap parameter which controls the amount of
5338 * spacing between the image and the text of buttons for TBSTYLE_LIST
5340 static LRESULT
TOOLBAR_SetListGap(TOOLBAR_INFO
*infoPtr
, INT iListGap
)
5342 TRACE("hwnd=%p iListGap=%d\n", infoPtr
->hwndSelf
, iListGap
);
5344 infoPtr
->iListGap
= iListGap
;
5346 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5351 /* Returns the number of maximum number of image lists associated with the
5352 * various states. */
5353 static LRESULT
TOOLBAR_GetImageListCount(const TOOLBAR_INFO
*infoPtr
)
5355 TRACE("hwnd=%p\n", infoPtr
->hwndSelf
);
5357 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5361 TOOLBAR_GetIdealSize (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5363 LPSIZE lpsize
= (LPSIZE
)lParam
;
5369 * Testing shows the following:
5370 * wParam = 0 adjust cx value
5371 * = 1 set cy value to max size.
5372 * lParam pointer to SIZE structure
5375 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5376 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5380 if (lpsize
->cx
== -1) {
5381 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5383 else if(HIWORD(lpsize
->cx
)) {
5385 HWND hwndParent
= GetParent(infoPtr
->hwndSelf
);
5387 GetWindowRect(infoPtr
->hwndSelf
, &rc
);
5388 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5389 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc
));
5390 lpsize
->cx
= max(rc
.right
-rc
.left
,
5391 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5394 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5398 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5401 FIXME("Unknown wParam %ld\n", wParam
);
5404 TRACE("set to -> 0x%08x 0x%08x\n",
5405 lpsize
->cx
, lpsize
->cy
);
5409 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5411 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5413 InvalidateRect(hwnd
, NULL
, TRUE
);
5419 TOOLBAR_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
5421 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
5424 TRACE("hwnd = %p, style=0x%08x\n", hwnd
, lpcs
->style
);
5426 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5427 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5428 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5429 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_REQUERY
));
5430 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5432 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5433 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5435 OpenThemeData (hwnd
, themeClass
);
5437 TOOLBAR_CheckStyle (infoPtr
);
5444 TOOLBAR_Destroy (TOOLBAR_INFO
*infoPtr
)
5448 /* delete tooltip control */
5449 if (infoPtr
->hwndToolTip
)
5450 DestroyWindow (infoPtr
->hwndToolTip
);
5452 /* delete temporary buffer for tooltip text */
5453 Free (infoPtr
->pszTooltipText
);
5454 Free (infoPtr
->bitmaps
); /* bitmaps list */
5456 /* delete button data */
5457 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5458 free_string( infoPtr
->buttons
+ i
);
5459 Free (infoPtr
->buttons
);
5461 /* delete strings */
5462 if (infoPtr
->strings
) {
5463 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5464 Free (infoPtr
->strings
[i
]);
5466 Free (infoPtr
->strings
);
5469 /* destroy internal image list */
5470 if (infoPtr
->himlInt
)
5471 ImageList_Destroy (infoPtr
->himlInt
);
5473 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5474 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5475 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5477 /* delete default font */
5478 DeleteObject (infoPtr
->hDefaultFont
);
5480 CloseThemeData (GetWindowTheme (infoPtr
->hwndSelf
));
5482 /* free toolbar info data */
5483 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
5491 TOOLBAR_EraseBackground (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5493 NMTBCUSTOMDRAW tbcd
;
5496 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
5497 DWORD dwEraseCustDraw
= 0;
5499 /* the app has told us not to redraw the toolbar */
5500 if (!infoPtr
->bDoRedraw
)
5503 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5504 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5505 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5506 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5507 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5508 dwEraseCustDraw
= ntfret
& 0xffff;
5510 /* FIXME: in general the return flags *can* be or'ed together */
5511 switch (dwEraseCustDraw
)
5513 case CDRF_DODEFAULT
:
5515 case CDRF_SKIPDEFAULT
:
5518 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5519 infoPtr
->hwndSelf
, ntfret
);
5523 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5524 * to my parent for processing.
5526 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5528 HDC hdc
= (HDC
)wParam
;
5533 parent
= GetParent(infoPtr
->hwndSelf
);
5534 MapWindowPoints(infoPtr
->hwndSelf
, parent
, &pt
, 1);
5535 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5536 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5537 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5540 ret
= DefWindowProcW (infoPtr
->hwndSelf
, WM_ERASEBKGND
, wParam
, lParam
);
5542 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5543 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5544 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5545 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5546 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5547 dwEraseCustDraw
= ntfret
& 0xffff;
5548 switch (dwEraseCustDraw
)
5550 case CDRF_DODEFAULT
:
5552 case CDRF_SKIPDEFAULT
:
5555 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5556 infoPtr
->hwndSelf
, ntfret
);
5563 static inline LRESULT
5564 TOOLBAR_GetFont (const TOOLBAR_INFO
*infoPtr
)
5566 return (LRESULT
)infoPtr
->hFont
;
5571 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5574 INT nNewHotItem
= infoPtr
->nHotItem
;
5576 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5579 if ((nNewHotItem
+ iDirection
< 0) ||
5580 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5582 NMTBWRAPHOTITEM nmtbwhi
;
5583 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5584 nmtbwhi
.iDirection
= iDirection
;
5585 nmtbwhi
.dwReason
= dwReason
;
5587 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5591 nNewHotItem
+= iDirection
;
5592 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5594 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5595 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5597 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5604 TOOLBAR_KeyDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5608 nmkey
.nVKey
= (UINT
)wParam
;
5609 nmkey
.uFlags
= HIWORD(lParam
);
5611 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5612 return DefWindowProcW(infoPtr
->hwndSelf
, WM_KEYDOWN
, wParam
, lParam
);
5614 switch ((UINT
)wParam
)
5618 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5622 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5626 if ((infoPtr
->nHotItem
>= 0) &&
5627 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5629 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5630 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5631 (LPARAM
)infoPtr
->hwndSelf
);
5641 TOOLBAR_LButtonDblClk (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5646 pt
.x
= (short)LOWORD(lParam
);
5647 pt
.y
= (short)HIWORD(lParam
);
5648 TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5651 TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
5652 else if (infoPtr
->dwStyle
& CCS_ADJUSTABLE
)
5653 TOOLBAR_Customize (infoPtr
);
5660 TOOLBAR_LButtonDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5662 TBUTTON_INFO
*btnPtr
;
5667 BOOL bDragKeyPressed
;
5672 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5673 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5675 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5677 if (infoPtr
->hwndToolTip
)
5678 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5679 WM_LBUTTONDOWN
, wParam
, lParam
);
5681 pt
.x
= (short)LOWORD(lParam
);
5682 pt
.y
= (short)HIWORD(lParam
);
5683 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5686 btnPtr
= &infoPtr
->buttons
[nHit
];
5688 if (button
&& bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5690 infoPtr
->nButtonDrag
= nHit
;
5691 SetCapture (infoPtr
->hwndSelf
);
5693 /* If drag cursor has not been loaded, load it.
5694 * Note: it doesn't need to be freed */
5696 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5697 SetCursor(hCursorDrag
);
5702 infoPtr
->nOldHit
= nHit
;
5704 CopyRect(&arrowRect
, &btnPtr
->rect
);
5705 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5707 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5708 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5709 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5710 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5711 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5712 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5716 /* draw in pressed state */
5717 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5718 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5720 btnPtr
->bDropDownPressed
= TRUE
;
5721 RedrawWindow(infoPtr
->hwndSelf
,&btnPtr
->rect
,0,
5722 RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5724 memset(&nmtb
, 0, sizeof(nmtb
));
5725 nmtb
.iItem
= btnPtr
->idCommand
;
5726 nmtb
.rcButton
= btnPtr
->rect
;
5727 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5729 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5731 if (res
!= TBDDRET_TREATPRESSED
)
5735 /* redraw button in unpressed state */
5736 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5737 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5739 btnPtr
->bDropDownPressed
= FALSE
;
5740 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5742 /* find and set hot item */
5744 ScreenToClient(infoPtr
->hwndSelf
, &pt
);
5745 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5746 if (!infoPtr
->bAnchor
|| button
)
5747 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5749 /* remove any left mouse button down or double-click messages
5750 * so that we can get a toggle effect on the button */
5751 while (PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5752 PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5757 /* otherwise drop through and process as pushed */
5759 infoPtr
->bCaptured
= TRUE
;
5760 infoPtr
->nButtonDown
= nHit
;
5761 infoPtr
->bDragOutSent
= FALSE
;
5763 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5765 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5767 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5768 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5769 UpdateWindow(infoPtr
->hwndSelf
);
5770 SetCapture (infoPtr
->hwndSelf
);
5775 memset(&nmtb
, 0, sizeof(nmtb
));
5776 nmtb
.iItem
= btnPtr
->idCommand
;
5777 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5780 nmmouse
.dwHitInfo
= nHit
;
5782 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5784 nmmouse
.dwItemSpec
= -1;
5787 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5788 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5791 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5794 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5795 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, wParam
, lParam
);
5801 TOOLBAR_LButtonUp (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5803 TBUTTON_INFO
*btnPtr
;
5812 if (infoPtr
->hwndToolTip
)
5813 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5814 WM_LBUTTONUP
, wParam
, lParam
);
5816 pt
.x
= (short)LOWORD(lParam
);
5817 pt
.y
= (short)HIWORD(lParam
);
5818 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5820 if (!infoPtr
->bAnchor
|| button
)
5821 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5823 if (infoPtr
->nButtonDrag
>= 0) {
5827 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5830 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5832 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5833 if (PtInRect(&rcClient
, pt
))
5840 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5843 if (nButton
== infoPtr
->nButtonDrag
)
5845 /* if the button is moved sightly left and we have a
5846 * separator there then remove it */
5847 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5849 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5850 TOOLBAR_DeleteButton(infoPtr
, nButton
- 1);
5852 else /* else insert a separator before the dragged button */
5855 memset(&tbb
, 0, sizeof(tbb
));
5856 tbb
.fsStyle
= BTNS_SEP
;
5858 TOOLBAR_InsertButtonT(infoPtr
, nButton
, &tbb
, TRUE
);
5865 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5866 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, 0);
5868 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5871 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, nButton
);
5876 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5877 TOOLBAR_DeleteButton(infoPtr
, infoPtr
->nButtonDrag
);
5880 /* button under cursor changed so need to re-set hot item */
5881 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5882 infoPtr
->nButtonDrag
= -1;
5884 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5886 else if (infoPtr
->nButtonDown
>= 0) {
5887 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5888 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5890 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5891 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5892 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5894 if ((nOldIndex
!= nHit
) &&
5896 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5897 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5900 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5901 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5903 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5907 if (nOldIndex
!= -1)
5908 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5911 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5912 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5913 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5915 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5917 infoPtr
->nButtonDown
= -1;
5919 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5920 TOOLBAR_SendNotify (&hdr
, infoPtr
,
5921 NM_RELEASEDCAPTURE
);
5923 memset(&nmtb
, 0, sizeof(nmtb
));
5924 nmtb
.iItem
= btnPtr
->idCommand
;
5925 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5928 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5930 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5931 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)infoPtr
->hwndSelf
);
5933 /* In case we have just been destroyed... */
5934 if(!IsWindow(infoPtr
->hwndSelf
))
5939 /* !!! Undocumented - toolbar at 4.71 level and above sends
5940 * NM_CLICK with the NMMOUSE structure. */
5941 nmmouse
.dwHitInfo
= nHit
;
5944 nmmouse
.dwItemSpec
= -1;
5947 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5948 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5951 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5954 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5955 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONUP
, wParam
, lParam
);
5961 TOOLBAR_RButtonUp(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5968 pt
.x
= (short)LOWORD(lParam
);
5969 pt
.y
= (short)HIWORD(lParam
);
5971 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5972 nmmouse
.dwHitInfo
= nHit
;
5975 nmmouse
.dwItemSpec
= -1;
5977 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5978 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5981 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5984 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5985 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONUP
, wParam
, lParam
);
5991 TOOLBAR_RButtonDblClk( TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5995 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5996 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
6002 TOOLBAR_CaptureChanged(TOOLBAR_INFO
*infoPtr
)
6004 TBUTTON_INFO
*btnPtr
;
6006 infoPtr
->bCaptured
= FALSE
;
6008 if (infoPtr
->nButtonDown
>= 0)
6010 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6011 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6013 infoPtr
->nOldHit
= -1;
6015 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
6016 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6022 TOOLBAR_MouseLeave (TOOLBAR_INFO
*infoPtr
)
6024 /* don't remove hot effects when in anchor highlighting mode or when a
6025 * drop-down button is pressed */
6026 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
6028 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
6029 if (!hotBtnPtr
->bDropDownPressed
)
6030 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
6033 if (infoPtr
->nOldHit
< 0)
6036 /* If the last button we were over is depressed then make it not */
6037 /* depressed and redraw it */
6038 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
6040 TBUTTON_INFO
*btnPtr
;
6043 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6045 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6048 InflateRect (&rc1
, 1, 1);
6049 InvalidateRect (infoPtr
->hwndSelf
, &rc1
, TRUE
);
6052 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
6055 ZeroMemory(&nmt
, sizeof(nmt
));
6056 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6057 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6058 infoPtr
->bDragOutSent
= TRUE
;
6061 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
6067 TOOLBAR_MouseMove (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6070 TRACKMOUSEEVENT trackinfo
;
6072 TBUTTON_INFO
*btnPtr
;
6075 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
6076 TOOLBAR_TooltipCreateControl(infoPtr
);
6078 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
6079 /* fill in the TRACKMOUSEEVENT struct */
6080 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
6081 trackinfo
.dwFlags
= TME_QUERY
;
6083 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6084 _TrackMouseEvent(&trackinfo
);
6086 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6087 if(trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
6088 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
6089 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
6091 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6092 /* and can properly deactivate the hot toolbar button */
6093 _TrackMouseEvent(&trackinfo
);
6097 if (infoPtr
->hwndToolTip
)
6098 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
6099 WM_MOUSEMOVE
, wParam
, lParam
);
6101 pt
.x
= (short)LOWORD(lParam
);
6102 pt
.y
= (short)HIWORD(lParam
);
6104 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
6106 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6107 && (!infoPtr
->bAnchor
|| button
))
6108 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
);
6110 if (infoPtr
->nOldHit
!= nHit
)
6112 if (infoPtr
->bCaptured
)
6114 if (!infoPtr
->bDragOutSent
)
6117 ZeroMemory(&nmt
, sizeof(nmt
));
6118 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6119 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6120 infoPtr
->bDragOutSent
= TRUE
;
6123 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6124 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
6125 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6126 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6128 else if (nHit
== infoPtr
->nButtonDown
) {
6129 btnPtr
->fsState
|= TBSTATE_PRESSED
;
6130 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6132 infoPtr
->nOldHit
= nHit
;
6140 static inline LRESULT
6141 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6143 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6144 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
6146 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6150 static inline LRESULT
6151 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6153 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
6154 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
6156 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
6161 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
6163 TOOLBAR_INFO
*infoPtr
;
6166 /* allocate memory for info structure */
6167 infoPtr
= Alloc (sizeof(TOOLBAR_INFO
));
6168 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
6171 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
6174 /* initialize info structure */
6175 infoPtr
->nButtonWidth
= 23;
6176 infoPtr
->nButtonHeight
= 22;
6177 infoPtr
->nBitmapHeight
= 16;
6178 infoPtr
->nBitmapWidth
= 16;
6180 infoPtr
->nMaxTextRows
= 1;
6181 infoPtr
->cxMin
= -1;
6182 infoPtr
->cxMax
= -1;
6183 infoPtr
->nNumBitmaps
= 0;
6184 infoPtr
->nNumStrings
= 0;
6186 infoPtr
->bCaptured
= FALSE
;
6187 infoPtr
->nButtonDown
= -1;
6188 infoPtr
->nButtonDrag
= -1;
6189 infoPtr
->nOldHit
= -1;
6190 infoPtr
->nHotItem
= -1;
6191 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
6192 infoPtr
->dwDTFlags
= (lpcs
->style
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
6193 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
6194 infoPtr
->bDragOutSent
= FALSE
;
6195 infoPtr
->iVersion
= 0;
6196 infoPtr
->hwndSelf
= hwnd
;
6197 infoPtr
->bDoRedraw
= TRUE
;
6198 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
6199 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
6200 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
6201 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
6202 infoPtr
->szSpacing
.cx
= DEFSPACE_CX
;
6203 infoPtr
->szSpacing
.cy
= DEFSPACE_CY
;
6204 infoPtr
->iListGap
= DEFLISTGAP
;
6205 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
6206 infoPtr
->dwStyle
= lpcs
->style
;
6207 infoPtr
->tbim
.iButton
= -1;
6209 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6210 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
6211 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
6212 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
6215 /* I think the code below is a bug, but it is the way that the native
6216 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6217 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6218 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6219 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6220 * Somehow, the only cases of this seem to be MFC programs.
6222 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6223 * does not occur in the WM_STYLECHANGING routine.
6224 * (Guy Albertelli 9/2001)
6227 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6228 && !(lpcs
->style
& TBSTYLE_TRANSPARENT
))
6229 styleadd
|= TBSTYLE_TRANSPARENT
;
6230 if (!(lpcs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
6231 styleadd
|= CCS_TOP
; /* default to top */
6232 SetWindowLongW (hwnd
, GWL_STYLE
, lpcs
->style
| styleadd
);
6235 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
6240 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6242 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
6246 if (dwStyle
& WS_MINIMIZE
)
6247 return 0; /* Nothing to do */
6249 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
6251 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
6254 if (!(dwStyle
& CCS_NODIVIDER
))
6256 GetWindowRect (hwnd
, &rcWindow
);
6257 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
6258 if( dwStyle
& WS_BORDER
)
6259 InflateRect (&rcWindow
, -1, -1);
6260 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6263 ReleaseDC( hwnd
, hdc
);
6269 /* handles requests from the tooltip control on what text to display */
6270 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6272 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6274 TRACE("button index = %d\n", index
);
6276 Free (infoPtr
->pszTooltipText
);
6277 infoPtr
->pszTooltipText
= NULL
;
6282 if (infoPtr
->bUnicode
)
6284 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6285 NMTBGETINFOTIPW tbgit
;
6286 unsigned int len
; /* in chars */
6288 wszBuffer
[0] = '\0';
6289 wszBuffer
[INFOTIPSIZE
] = '\0';
6291 tbgit
.pszText
= wszBuffer
;
6292 tbgit
.cchTextMax
= INFOTIPSIZE
;
6293 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6294 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6296 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6298 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6300 len
= strlenW(tbgit
.pszText
);
6301 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6303 /* need to allocate temporary buffer in infoPtr as there
6304 * isn't enough space in buffer passed to us by the
6305 * tooltip control */
6306 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6307 if (infoPtr
->pszTooltipText
)
6309 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6310 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6316 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6322 CHAR szBuffer
[INFOTIPSIZE
+1];
6323 NMTBGETINFOTIPA tbgit
;
6324 unsigned int len
; /* in chars */
6327 szBuffer
[INFOTIPSIZE
] = '\0';
6329 tbgit
.pszText
= szBuffer
;
6330 tbgit
.cchTextMax
= INFOTIPSIZE
;
6331 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6332 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6334 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6336 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6338 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6339 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]))
6341 /* need to allocate temporary buffer in infoPtr as there
6342 * isn't enough space in buffer passed to us by the
6343 * tooltip control */
6344 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6345 if (infoPtr
->pszTooltipText
)
6347 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6348 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6352 else if (tbgit
.pszText
&& tbgit
.pszText
[0])
6354 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1,
6355 lpnmtdi
->lpszText
, sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]));
6360 /* if button has text, but it is not shown then automatically
6361 * use that text as tooltip */
6362 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6363 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6365 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6366 unsigned int len
= pszText
? strlenW(pszText
) : 0;
6368 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6370 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6372 /* need to allocate temporary buffer in infoPtr as there
6373 * isn't enough space in buffer passed to us by the
6374 * tooltip control */
6375 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6376 if (infoPtr
->pszTooltipText
)
6378 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6379 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6385 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6390 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6392 /* last resort: send notification on to app */
6393 /* FIXME: find out what is really used here */
6394 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmtdi
->hdr
.idFrom
, (LPARAM
)lpnmtdi
);
6398 static inline LRESULT
6399 TOOLBAR_Notify (TOOLBAR_INFO
*infoPtr
, LPNMHDR lpnmh
)
6401 switch (lpnmh
->code
)
6405 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lpnmh
;
6407 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6408 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6409 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6413 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6414 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6422 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lpnmh
;
6424 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6425 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6426 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6427 lppgs
->iScroll
, lppgs
->iDir
);
6431 case TTN_GETDISPINFOW
:
6432 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lpnmh
);
6434 case TTN_GETDISPINFOA
:
6435 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6445 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6449 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam
, lParam
);
6451 if (lParam
== NF_QUERY
)
6454 if (lParam
== NF_REQUERY
) {
6455 format
= SendMessageW(infoPtr
->hwndNotify
,
6456 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6457 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6458 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6469 TOOLBAR_Paint (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6474 /* fill ps.rcPaint with a default rect */
6475 ps
.rcPaint
= infoPtr
->rcBound
;
6477 hdc
= wParam
==0 ? BeginPaint(infoPtr
->hwndSelf
, &ps
) : (HDC
)wParam
;
6479 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps
.rcPaint
));
6481 TOOLBAR_Refresh (infoPtr
, hdc
, &ps
);
6482 if (!wParam
) EndPaint (infoPtr
->hwndSelf
, &ps
);
6489 TOOLBAR_SetFocus (TOOLBAR_INFO
*infoPtr
)
6491 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6493 /* make first item hot */
6494 if (infoPtr
->nNumButtons
> 0)
6495 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6501 TOOLBAR_SetFont(TOOLBAR_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
6503 TRACE("font=%p redraw=%d\n", hFont
, Redraw
);
6506 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6508 infoPtr
->hFont
= hFont
;
6510 TOOLBAR_CalcToolbar(infoPtr
);
6513 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6518 TOOLBAR_SetRedraw (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6519 /*****************************************************
6522 * Handles the WM_SETREDRAW message.
6525 * According to testing V4.71 of COMCTL32 returns the
6526 * *previous* status of the redraw flag (either 0 or 1)
6527 * instead of the MSDN documented value of 0 if handled.
6528 * (For laughs see the "consistency" with same function
6531 *****************************************************/
6533 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6535 TRACE("set to %s\n",
6536 (wParam
) ? "TRUE" : "FALSE");
6537 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6539 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6541 return (oldredraw
) ? 1 : 0;
6546 TOOLBAR_Size (TOOLBAR_INFO
*infoPtr
)
6548 TRACE("sizing toolbar!\n");
6550 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6552 RECT delta_width
, delta_height
, client
, dummy
;
6553 DWORD min_x
, max_x
, min_y
, max_y
;
6554 TBUTTON_INFO
*btnPtr
;
6557 GetClientRect(infoPtr
->hwndSelf
, &client
);
6558 if(client
.right
> infoPtr
->client_rect
.right
)
6560 min_x
= infoPtr
->client_rect
.right
;
6561 max_x
= client
.right
;
6565 max_x
= infoPtr
->client_rect
.right
;
6566 min_x
= client
.right
;
6568 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6570 min_y
= infoPtr
->client_rect
.bottom
;
6571 max_y
= client
.bottom
;
6575 max_y
= infoPtr
->client_rect
.bottom
;
6576 min_y
= client
.bottom
;
6579 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6580 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6582 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6583 btnPtr
= infoPtr
->buttons
;
6584 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6585 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6586 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6587 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6589 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->client_rect
);
6590 TOOLBAR_AutoSize(infoPtr
);
6596 TOOLBAR_StyleChanged (TOOLBAR_INFO
*infoPtr
, INT nType
, const STYLESTRUCT
*lpStyle
)
6598 if (nType
== GWL_STYLE
)
6599 return TOOLBAR_SetStyle(infoPtr
, lpStyle
->styleNew
);
6606 TOOLBAR_SysColorChange (void)
6608 COMCTL32_RefreshSysColors();
6614 /* update theme after a WM_THEMECHANGED message */
6615 static LRESULT
theme_changed (HWND hwnd
)
6617 HTHEME theme
= GetWindowTheme (hwnd
);
6618 CloseThemeData (theme
);
6619 OpenThemeData (hwnd
, themeClass
);
6624 static LRESULT WINAPI
6625 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6627 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
6629 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6630 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6632 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6633 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6638 return TOOLBAR_AddBitmap (infoPtr
, (INT
)wParam
, (TBADDBITMAP
*)lParam
);
6640 case TB_ADDBUTTONSA
:
6641 case TB_ADDBUTTONSW
:
6642 return TOOLBAR_AddButtonsT (infoPtr
, wParam
, (LPTBBUTTON
)lParam
,
6643 uMsg
== TB_ADDBUTTONSW
);
6645 return TOOLBAR_AddStringA (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6648 return TOOLBAR_AddStringW (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6651 return TOOLBAR_AutoSize (infoPtr
);
6653 case TB_BUTTONCOUNT
:
6654 return TOOLBAR_ButtonCount (infoPtr
);
6656 case TB_BUTTONSTRUCTSIZE
:
6657 return TOOLBAR_ButtonStructSize (infoPtr
, wParam
);
6659 case TB_CHANGEBITMAP
:
6660 return TOOLBAR_ChangeBitmap (infoPtr
, wParam
, LOWORD(lParam
));
6662 case TB_CHECKBUTTON
:
6663 return TOOLBAR_CheckButton (infoPtr
, wParam
, lParam
);
6665 case TB_COMMANDTOINDEX
:
6666 return TOOLBAR_CommandToIndex (infoPtr
, wParam
);
6669 return TOOLBAR_Customize (infoPtr
);
6671 case TB_DELETEBUTTON
:
6672 return TOOLBAR_DeleteButton (infoPtr
, wParam
);
6674 case TB_ENABLEBUTTON
:
6675 return TOOLBAR_EnableButton (infoPtr
, wParam
, lParam
);
6677 case TB_GETANCHORHIGHLIGHT
:
6678 return TOOLBAR_GetAnchorHighlight (infoPtr
);
6681 return TOOLBAR_GetBitmap (infoPtr
, wParam
);
6683 case TB_GETBITMAPFLAGS
:
6684 return TOOLBAR_GetBitmapFlags ();
6687 return TOOLBAR_GetButton (infoPtr
, wParam
, (TBBUTTON
*)lParam
);
6689 case TB_GETBUTTONINFOA
:
6690 case TB_GETBUTTONINFOW
:
6691 return TOOLBAR_GetButtonInfoT (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6692 uMsg
== TB_GETBUTTONINFOW
);
6693 case TB_GETBUTTONSIZE
:
6694 return TOOLBAR_GetButtonSize (infoPtr
);
6696 case TB_GETBUTTONTEXTA
:
6697 case TB_GETBUTTONTEXTW
:
6698 return TOOLBAR_GetButtonText (infoPtr
, wParam
, (LPWSTR
)lParam
,
6699 uMsg
== TB_GETBUTTONTEXTW
);
6701 case TB_GETDISABLEDIMAGELIST
:
6702 return TOOLBAR_GetDisabledImageList (infoPtr
, wParam
);
6704 case TB_GETEXTENDEDSTYLE
:
6705 return TOOLBAR_GetExtendedStyle (infoPtr
);
6707 case TB_GETHOTIMAGELIST
:
6708 return TOOLBAR_GetHotImageList (infoPtr
, wParam
);
6711 return TOOLBAR_GetHotItem (infoPtr
);
6713 case TB_GETIMAGELIST
:
6714 return TOOLBAR_GetDefImageList (infoPtr
, wParam
);
6716 case TB_GETINSERTMARK
:
6717 return TOOLBAR_GetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6719 case TB_GETINSERTMARKCOLOR
:
6720 return TOOLBAR_GetInsertMarkColor (infoPtr
);
6722 case TB_GETITEMRECT
:
6723 return TOOLBAR_GetItemRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6726 return TOOLBAR_GetMaxSize (infoPtr
, (LPSIZE
)lParam
);
6729 return TOOLBAR_GetMetrics (infoPtr
, (TBMETRICS
*)lParam
);
6732 /* case TB_GETOBJECT: */ /* 4.71 */
6735 return TOOLBAR_GetPadding (infoPtr
);
6738 return TOOLBAR_GetRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6741 return TOOLBAR_GetRows (infoPtr
);
6744 return TOOLBAR_GetState (infoPtr
, wParam
);
6747 return TOOLBAR_GetStringA (infoPtr
, wParam
, (LPSTR
)lParam
);
6750 return TOOLBAR_GetStringW (infoPtr
, wParam
, (LPWSTR
)lParam
);
6753 return TOOLBAR_GetStyle (infoPtr
);
6755 case TB_GETTEXTROWS
:
6756 return TOOLBAR_GetTextRows (infoPtr
);
6758 case TB_GETTOOLTIPS
:
6759 return TOOLBAR_GetToolTips (infoPtr
);
6761 case TB_GETUNICODEFORMAT
:
6762 return TOOLBAR_GetUnicodeFormat (infoPtr
);
6765 return TOOLBAR_HideButton (infoPtr
, wParam
, LOWORD(lParam
));
6768 return TOOLBAR_HitTest (infoPtr
, (LPPOINT
)lParam
);
6770 case TB_INDETERMINATE
:
6771 return TOOLBAR_Indeterminate (infoPtr
, wParam
, LOWORD(lParam
));
6773 case TB_INSERTBUTTONA
:
6774 case TB_INSERTBUTTONW
:
6775 return TOOLBAR_InsertButtonT(infoPtr
, wParam
, (TBBUTTON
*)lParam
,
6776 uMsg
== TB_INSERTBUTTONW
);
6778 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6780 case TB_ISBUTTONCHECKED
:
6781 return TOOLBAR_IsButtonChecked (infoPtr
, wParam
);
6783 case TB_ISBUTTONENABLED
:
6784 return TOOLBAR_IsButtonEnabled (infoPtr
, wParam
);
6786 case TB_ISBUTTONHIDDEN
:
6787 return TOOLBAR_IsButtonHidden (infoPtr
, wParam
);
6789 case TB_ISBUTTONHIGHLIGHTED
:
6790 return TOOLBAR_IsButtonHighlighted (infoPtr
, wParam
);
6792 case TB_ISBUTTONINDETERMINATE
:
6793 return TOOLBAR_IsButtonIndeterminate (infoPtr
, wParam
);
6795 case TB_ISBUTTONPRESSED
:
6796 return TOOLBAR_IsButtonPressed (infoPtr
, wParam
);
6799 return TOOLBAR_LoadImages (infoPtr
, wParam
, (HINSTANCE
)lParam
);
6801 case TB_MAPACCELERATORA
:
6802 case TB_MAPACCELERATORW
:
6803 return TOOLBAR_MapAccelerator (infoPtr
, wParam
, (UINT
*)lParam
);
6806 return TOOLBAR_MarkButton (infoPtr
, wParam
, LOWORD(lParam
));
6809 return TOOLBAR_MoveButton (infoPtr
, wParam
, lParam
);
6811 case TB_PRESSBUTTON
:
6812 return TOOLBAR_PressButton (infoPtr
, wParam
, LOWORD(lParam
));
6814 case TB_REPLACEBITMAP
:
6815 return TOOLBAR_ReplaceBitmap (infoPtr
, (LPTBREPLACEBITMAP
)lParam
);
6817 case TB_SAVERESTOREA
:
6818 return TOOLBAR_SaveRestoreA (infoPtr
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6820 case TB_SAVERESTOREW
:
6821 return TOOLBAR_SaveRestoreW (infoPtr
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6823 case TB_SETANCHORHIGHLIGHT
:
6824 return TOOLBAR_SetAnchorHighlight (infoPtr
, (BOOL
)wParam
);
6826 case TB_SETBITMAPSIZE
:
6827 return TOOLBAR_SetBitmapSize (infoPtr
, wParam
, lParam
);
6829 case TB_SETBUTTONINFOA
:
6830 case TB_SETBUTTONINFOW
:
6831 return TOOLBAR_SetButtonInfo (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6832 uMsg
== TB_SETBUTTONINFOW
);
6833 case TB_SETBUTTONSIZE
:
6834 return TOOLBAR_SetButtonSize (infoPtr
, lParam
);
6836 case TB_SETBUTTONWIDTH
:
6837 return TOOLBAR_SetButtonWidth (infoPtr
, lParam
);
6840 return TOOLBAR_SetCmdId (infoPtr
, wParam
, lParam
);
6842 case TB_SETDISABLEDIMAGELIST
:
6843 return TOOLBAR_SetDisabledImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6845 case TB_SETDRAWTEXTFLAGS
:
6846 return TOOLBAR_SetDrawTextFlags (infoPtr
, wParam
, lParam
);
6848 case TB_SETEXTENDEDSTYLE
:
6849 return TOOLBAR_SetExtendedStyle (infoPtr
, wParam
, lParam
);
6851 case TB_SETHOTIMAGELIST
:
6852 return TOOLBAR_SetHotImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6855 return TOOLBAR_SetHotItem (infoPtr
, wParam
);
6857 case TB_SETIMAGELIST
:
6858 return TOOLBAR_SetImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6861 return TOOLBAR_SetIndent (infoPtr
, wParam
);
6863 case TB_SETINSERTMARK
:
6864 return TOOLBAR_SetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6866 case TB_SETINSERTMARKCOLOR
:
6867 return TOOLBAR_SetInsertMarkColor (infoPtr
, lParam
);
6869 case TB_SETMAXTEXTROWS
:
6870 return TOOLBAR_SetMaxTextRows (infoPtr
, wParam
);
6874 return TOOLBAR_SetMetrics (infoPtr
, (TBMETRICS
*)lParam
);
6878 return TOOLBAR_SetPadding (infoPtr
, lParam
);
6881 return TOOLBAR_SetParent (infoPtr
, (HWND
)wParam
);
6884 return TOOLBAR_SetRows (infoPtr
, wParam
, (LPRECT
)lParam
);
6887 return TOOLBAR_SetState (infoPtr
, wParam
, lParam
);
6890 return TOOLBAR_SetStyle (infoPtr
, lParam
);
6892 case TB_SETTOOLTIPS
:
6893 return TOOLBAR_SetToolTips (infoPtr
, (HWND
)wParam
);
6895 case TB_SETUNICODEFORMAT
:
6896 return TOOLBAR_SetUnicodeFormat (infoPtr
, wParam
);
6899 return TOOLBAR_Unkwn45D(hwnd
, wParam
, lParam
);
6901 case TB_SETHOTITEM2
:
6902 return TOOLBAR_SetHotItem2 (infoPtr
, wParam
, lParam
);
6905 return TOOLBAR_SetListGap(infoPtr
, wParam
);
6907 case TB_GETIMAGELISTCOUNT
:
6908 return TOOLBAR_GetImageListCount(infoPtr
);
6910 case TB_GETIDEALSIZE
:
6911 return TOOLBAR_GetIdealSize (infoPtr
, wParam
, lParam
);
6914 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6916 /* Common Control Messages */
6918 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6919 case CCM_GETCOLORSCHEME
:
6920 return TOOLBAR_GetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6922 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6923 case CCM_SETCOLORSCHEME
:
6924 return TOOLBAR_SetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6926 case CCM_GETVERSION
:
6927 return TOOLBAR_GetVersion (infoPtr
);
6929 case CCM_SETVERSION
:
6930 return TOOLBAR_SetVersion (infoPtr
, (INT
)wParam
);
6936 return TOOLBAR_Create (hwnd
, (CREATESTRUCTW
*)lParam
);
6939 return TOOLBAR_Destroy (infoPtr
);
6942 return TOOLBAR_EraseBackground (infoPtr
, wParam
, lParam
);
6945 return TOOLBAR_GetFont (infoPtr
);
6948 return TOOLBAR_KeyDown (infoPtr
, wParam
, lParam
);
6950 /* case WM_KILLFOCUS: */
6952 case WM_LBUTTONDBLCLK
:
6953 return TOOLBAR_LButtonDblClk (infoPtr
, wParam
, lParam
);
6955 case WM_LBUTTONDOWN
:
6956 return TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
6959 return TOOLBAR_LButtonUp (infoPtr
, wParam
, lParam
);
6962 return TOOLBAR_RButtonUp (infoPtr
, wParam
, lParam
);
6964 case WM_RBUTTONDBLCLK
:
6965 return TOOLBAR_RButtonDblClk (infoPtr
, wParam
, lParam
);
6968 return TOOLBAR_MouseMove (infoPtr
, wParam
, lParam
);
6971 return TOOLBAR_MouseLeave (infoPtr
);
6973 case WM_CAPTURECHANGED
:
6974 return TOOLBAR_CaptureChanged(infoPtr
);
6977 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6980 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6983 return TOOLBAR_NCCreate (hwnd
, wParam
, (CREATESTRUCTW
*)lParam
);
6986 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
6989 return TOOLBAR_Notify (infoPtr
, (LPNMHDR
)lParam
);
6991 case WM_NOTIFYFORMAT
:
6992 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
6994 case WM_PRINTCLIENT
:
6996 return TOOLBAR_Paint (infoPtr
, wParam
);
6999 return TOOLBAR_SetFocus (infoPtr
);
7002 return TOOLBAR_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
7005 return TOOLBAR_SetRedraw (infoPtr
, wParam
);
7008 return TOOLBAR_Size (infoPtr
);
7010 case WM_STYLECHANGED
:
7011 return TOOLBAR_StyleChanged (infoPtr
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
7013 case WM_SYSCOLORCHANGE
:
7014 return TOOLBAR_SysColorChange ();
7016 case WM_THEMECHANGED
:
7018 return TOOLBAR_ThemeChanged(hwnd
);
7020 return theme_changed (hwnd
);
7023 /* case WM_WININICHANGE: */
7028 case WM_MEASUREITEM
:
7030 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
7032 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7033 case PGM_FORWARDMOUSE
:
7034 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7037 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
7038 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
7039 uMsg
, wParam
, lParam
);
7040 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7046 TOOLBAR_Register (void)
7050 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
7051 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
7052 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
7053 wndClass
.cbClsExtra
= 0;
7054 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
7055 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
7056 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
7057 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
7059 RegisterClassW (&wndClass
);
7064 TOOLBAR_Unregister (void)
7066 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
7069 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
7074 /* Check if the entry already exists */
7075 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
7077 /* If this is a new entry we must create it and insert into the array */
7082 c
= Alloc(sizeof(IMLENTRY
));
7085 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
7086 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
7101 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
7105 for (i
= 0; i
< *cies
; i
++)
7115 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
7123 for (i
= 0; i
< cies
; i
++)
7125 if (pies
[i
]->id
== id
)
7137 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
7139 HIMAGELIST himlDef
= 0;
7140 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
7143 himlDef
= pie
->himl
;
7149 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
7151 if (infoPtr
->bUnicode
)
7152 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
7159 nmtba
.iItem
= nmtb
->iItem
;
7160 nmtba
.pszText
= Buffer
;
7161 nmtba
.cchText
= 256;
7162 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
7164 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
7166 int ccht
= strlen(nmtba
.pszText
);
7168 MultiByteToWideChar(CP_ACP
, 0, nmtba
.pszText
, -1,
7169 nmtb
->pszText
, nmtb
->cchText
);
7171 nmtb
->tbButton
= nmtba
.tbButton
;
7180 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
)
7184 /* MSDN states that iItem is the index of the button, rather than the
7185 * command ID as used by every other NMTOOLBAR notification */
7187 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
7189 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);