4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
38 * - TB_INSERTMARKHITTEST
46 * - Button wrapping (under construction).
47 * - Fix TB_SETROWS and Separators.
48 * - iListGap custom draw support.
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
84 #include "wine/debug.h"
86 WINE_DEFAULT_DEBUG_CHANNEL(toolbar
);
88 static HCURSOR hCursorDrag
= NULL
;
97 BOOL bDropDownPressed
;
102 INT cx
; /* manually set size */
116 } IMLENTRY
, *PIMLENTRY
;
120 DWORD dwStructSize
; /* size of TBBUTTON struct */
122 RECT rcBound
; /* bounding rectangle */
128 INT nRows
; /* number of button rows */
129 INT nMaxTextRows
; /* maximum number of text rows */
130 INT cxMin
; /* minimum button width */
131 INT cxMax
; /* maximum button width */
132 INT nNumButtons
; /* number of buttons */
133 INT nNumBitmaps
; /* number of bitmaps */
134 INT nNumStrings
; /* number of strings */
136 INT nButtonDown
; /* toolbar button being pressed or -1 if none */
137 INT nButtonDrag
; /* toolbar button being dragged or -1 if none */
139 INT nHotItem
; /* index of the "hot" item */
140 SIZE szPadding
; /* padding values around button */
141 INT iTopMargin
; /* the top margin */
142 INT iListGap
; /* default gap between text and image for toolbar with list style */
144 HFONT hFont
; /* text font */
145 HTHEME hTheme
; /* theme */
146 HIMAGELIST himlInt
; /* image list created internally */
147 PIMLENTRY
*himlDef
; /* default image list array */
148 INT cimlDef
; /* default image list array count */
149 PIMLENTRY
*himlHot
; /* hot image list array */
150 INT cimlHot
; /* hot image list array count */
151 PIMLENTRY
*himlDis
; /* disabled image list array */
152 INT cimlDis
; /* disabled image list array count */
153 HWND hwndToolTip
; /* handle to tool tip control */
154 HWND hwndNotify
; /* handle to the window that gets notifications */
155 HWND hwndSelf
; /* my own handle */
156 BOOL bAnchor
; /* anchor highlight enabled */
157 BOOL bDoRedraw
; /* Redraw status */
158 BOOL bDragOutSent
; /* has TBN_DRAGOUT notification been sent for this drag? */
159 BOOL bUnicode
; /* Notifications are ANSI (FALSE) or Unicode (TRUE)? */
160 BOOL bCaptured
; /* mouse captured? */
161 DWORD dwStyle
; /* regular toolbar style */
162 DWORD dwExStyle
; /* extended toolbar style */
163 DWORD dwDTFlags
; /* DrawText flags */
165 COLORREF clrInsertMark
; /* insert mark color */
166 COLORREF clrBtnHighlight
; /* color for Flat Separator */
167 COLORREF clrBtnShadow
; /* color for Flag Separator */
169 LPWSTR pszTooltipText
; /* temporary store for a string > 80 characters
170 * for TTN_GETDISPINFOW notification */
171 TBINSERTMARK tbim
; /* info on insertion mark */
172 TBUTTON_INFO
*buttons
; /* pointer to button array */
173 LPWSTR
*strings
; /* pointer to string array */
174 TBITMAP_INFO
*bitmaps
;
175 } TOOLBAR_INFO
, *PTOOLBAR_INFO
;
178 /* used by customization dialog */
181 PTOOLBAR_INFO tbInfo
;
183 } CUSTDLG_INFO
, *PCUSTDLG_INFO
;
191 } CUSTOMBUTTON
, *PCUSTOMBUTTON
;
200 #define SEPARATOR_WIDTH 8
202 #define BOTTOM_BORDER 2
203 #define DDARROW_WIDTH 11
204 #define ARROW_HEIGHT 3
205 #define INSERTMARK_WIDTH 2
211 /* vertical padding used in list mode when image is present */
214 /* how wide to treat the bitmap if it isn't present */
215 #define NONLIST_NOTEXT_OFFSET 2
217 #define TOOLBAR_NOWHERE (-1)
219 /* Used to find undocumented extended styles */
220 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
221 TBSTYLE_EX_VERTICAL | \
222 TBSTYLE_EX_MIXEDBUTTONS | \
223 TBSTYLE_EX_DOUBLEBUFFER | \
224 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
226 /* all of the CCS_ styles */
227 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
228 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
230 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
231 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
232 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
233 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
234 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
236 static const WCHAR themeClass
[] = L
"Toolbar";
238 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
);
239 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
);
240 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
);
241 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
);
242 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
);
243 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
);
244 static LRESULT
TOOLBAR_LButtonDown(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
);
245 static void TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
);
246 static LRESULT
TOOLBAR_AutoSize(TOOLBAR_INFO
*infoPtr
);
247 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
);
248 static void TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
249 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
250 static LRESULT
TOOLBAR_SetButtonInfo(TOOLBAR_INFO
*infoPtr
, INT Id
,
251 const TBBUTTONINFOW
*lptbbi
, BOOL isW
);
254 static inline int default_top_margin(const TOOLBAR_INFO
*infoPtr
)
256 return (infoPtr
->dwStyle
& TBSTYLE_FLAT
? 0 : TOP_BORDER
);
259 static inline BOOL
TOOLBAR_HasDropDownArrows(DWORD exStyle
)
261 return (exStyle
& TBSTYLE_EX_DRAWDDARROWS
) != 0;
264 static inline BOOL
button_has_ddarrow(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
266 return (TOOLBAR_HasDropDownArrows( infoPtr
->dwExStyle
) && (btnPtr
->fsStyle
& BTNS_DROPDOWN
)) ||
267 (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
271 TOOLBAR_GetText(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
273 LPWSTR lpText
= NULL
;
275 /* NOTE: iString == -1 is undocumented */
276 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1))
277 lpText
= (LPWSTR
)btnPtr
->iString
;
278 else if ((btnPtr
->iString
>= 0) && (btnPtr
->iString
< infoPtr
->nNumStrings
))
279 lpText
= infoPtr
->strings
[btnPtr
->iString
];
285 TOOLBAR_DumpTBButton(const TBBUTTON
*tbb
, BOOL fUnicode
)
287 TRACE("TBBUTTON: id %d, bitmap=%d, state=%02x, style=%02x, data=%p, stringid=%p (%s)\n", tbb
->idCommand
,
288 tbb
->iBitmap
, tbb
->fsState
, tbb
->fsStyle
, (void *)tbb
->dwData
, (void *)tbb
->iString
,
289 tbb
->iString
!= -1 ? (fUnicode
? debugstr_w((LPWSTR
)tbb
->iString
) : debugstr_a((LPSTR
)tbb
->iString
)) : "");
293 TOOLBAR_DumpButton(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*bP
, INT btn_num
)
295 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%Ix, stringid=%Ix\n",
296 btn_num
, bP
->idCommand
, GETIBITMAP(infoPtr
, bP
->iBitmap
), bP
->fsState
, bP
->fsStyle
, bP
->dwData
, bP
->iString
);
297 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr
,bP
)));
298 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n", btn_num
, bP
->idCommand
, (bP
->bHot
) ? "TRUE":"FALSE", bP
->nRow
,
299 wine_dbgstr_rect(&bP
->rect
));
304 TOOLBAR_DumpToolbar(const TOOLBAR_INFO
*iP
, INT line
)
308 if (!TRACE_ON(toolbar
))
311 TRACE("toolbar %p at line %d, exStyle=%#lx, buttons=%d, bitmaps=%d, strings=%d, style=%#lx\n",
312 iP
->hwndSelf
, line
, iP
->dwExStyle
, iP
->nNumButtons
, iP
->nNumBitmaps
, iP
->nNumStrings
, iP
->dwStyle
);
313 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
314 iP
->hwndSelf
, line
, iP
->himlInt
, iP
->himlDef
, iP
->himlHot
, iP
->himlDis
, (iP
->bDoRedraw
) ? "TRUE" : "FALSE");
316 for (i
= 0; i
< iP
->nNumButtons
; ++i
)
317 TOOLBAR_DumpButton(iP
, &iP
->buttons
[i
], i
);
321 TOOLBAR_ButtonHasString(const TBUTTON_INFO
*btnPtr
)
323 return HIWORD(btnPtr
->iString
) && btnPtr
->iString
!= -1;
326 static void set_string_index( TBUTTON_INFO
*btn
, INT_PTR str
, BOOL unicode
)
328 if (!IS_INTRESOURCE( str
) && str
!= -1)
330 if (!TOOLBAR_ButtonHasString( btn
)) btn
->iString
= 0;
333 Str_SetPtrW( (WCHAR
**)&btn
->iString
, (WCHAR
*)str
);
335 Str_SetPtrAtoW( (WCHAR
**)&btn
->iString
, (char *)str
);
339 if (TOOLBAR_ButtonHasString( btn
)) Free( (WCHAR
*)btn
->iString
);
345 static void set_stringT( TBUTTON_INFO
*btn
, const WCHAR
*str
, BOOL unicode
)
347 if (IS_INTRESOURCE( (DWORD_PTR
)str
) || (DWORD_PTR
)str
== -1) return;
348 set_string_index( btn
, (DWORD_PTR
)str
, unicode
);
351 static void free_string( TBUTTON_INFO
*btn
)
353 set_string_index( btn
, 0, TRUE
);
357 /***********************************************************************
360 * This function validates that the styles set are implemented and
361 * issues FIXMEs warning of possible problems. In a perfect world this
362 * function should be null.
365 TOOLBAR_CheckStyle (const TOOLBAR_INFO
*infoPtr
)
367 if (infoPtr
->dwStyle
& TBSTYLE_REGISTERDROP
)
368 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", infoPtr
->hwndSelf
);
373 TOOLBAR_SendNotify (NMHDR
*nmhdr
, const TOOLBAR_INFO
*infoPtr
, UINT code
)
375 if(!IsWindow(infoPtr
->hwndSelf
))
376 return 0; /* we have just been destroyed */
378 nmhdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
379 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
382 TRACE("to window %p, code=%08x, %s\n", infoPtr
->hwndNotify
, code
,
383 (infoPtr
->bUnicode
) ? "via Unicode" : "via ANSI");
385 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhdr
->idFrom
, (LPARAM
)nmhdr
);
388 /***********************************************************************
389 * TOOLBAR_GetBitmapIndex
391 * This function returns the bitmap index associated with a button.
392 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
393 * is issued to retrieve the index.
396 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
398 INT ret
= btnPtr
->iBitmap
;
400 if (ret
== I_IMAGECALLBACK
)
402 /* issue TBN_GETDISPINFO */
405 memset(&nmgd
, 0, sizeof(nmgd
));
406 nmgd
.idCommand
= btnPtr
->idCommand
;
407 nmgd
.lParam
= btnPtr
->dwData
;
408 nmgd
.dwMask
= TBNF_IMAGE
;
410 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
411 TOOLBAR_SendNotify(&nmgd
.hdr
, infoPtr
, TBN_GETDISPINFOW
);
412 if (nmgd
.dwMask
& TBNF_DI_SETITEM
)
413 btnPtr
->iBitmap
= nmgd
.iImage
;
415 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask %#lx, nNumBitmaps %d\n",
416 ret
, nmgd
.dwMask
, infoPtr
->nNumBitmaps
);
419 if (ret
!= I_IMAGENONE
)
420 ret
= GETIBITMAP(infoPtr
, ret
);
427 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO
*infoPtr
, INT index
)
430 INT id
= GETHIMLID(infoPtr
, index
);
431 INT iBitmap
= GETIBITMAP(infoPtr
, index
);
433 if (((himl
= GETDEFIMAGELIST(infoPtr
, id
)) &&
434 iBitmap
>= 0 && iBitmap
< ImageList_GetImageCount(himl
)) ||
435 (index
== I_IMAGECALLBACK
))
443 TOOLBAR_IsValidImageList(const TOOLBAR_INFO
*infoPtr
, INT index
)
445 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, index
));
446 return (himl
!= NULL
) && (ImageList_GetImageCount(himl
) > 0);
450 /***********************************************************************
451 * TOOLBAR_GetImageListForDrawing
453 * This function validates the bitmap index (including I_IMAGECALLBACK
454 * functionality) and returns the corresponding image list.
457 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
,
458 IMAGE_LIST_TYPE imagelist
, INT
* index
)
462 if (!TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
)) {
463 if (btnPtr
->iBitmap
== I_IMAGENONE
) return NULL
;
464 WARN("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
465 HIWORD(btnPtr
->iBitmap
), LOWORD(btnPtr
->iBitmap
), infoPtr
->nNumBitmaps
);
469 if ((*index
= TOOLBAR_GetBitmapIndex(infoPtr
, btnPtr
)) < 0) {
470 if ((*index
== I_IMAGECALLBACK
) ||
471 (*index
== I_IMAGENONE
)) return NULL
;
472 ERR("TBN_GETDISPINFO returned invalid index %d\n",
479 case IMAGE_LIST_DEFAULT
:
480 himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
483 himl
= GETHOTIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
485 case IMAGE_LIST_DISABLED
:
486 himl
= GETDISIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
490 FIXME("Shouldn't reach here\n");
494 TRACE("no image list\n");
501 TOOLBAR_DrawFlatSeparator (const RECT
*lpRect
, HDC hdc
, const TOOLBAR_INFO
*infoPtr
)
504 COLORREF oldcolor
, newcolor
;
506 myrect
.left
= (lpRect
->left
+ lpRect
->right
) / 2 - 1;
507 myrect
.right
= myrect
.left
+ 1;
508 myrect
.top
= lpRect
->top
+ 2;
509 myrect
.bottom
= lpRect
->bottom
- 2;
511 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
512 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
513 oldcolor
= SetBkColor (hdc
, newcolor
);
514 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
516 myrect
.left
= myrect
.right
;
517 myrect
.right
= myrect
.left
+ 1;
519 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
520 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
521 SetBkColor (hdc
, newcolor
);
522 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
524 SetBkColor (hdc
, oldcolor
);
528 /***********************************************************************
529 * TOOLBAR_DrawFlatHorizontalSeparator
531 * This function draws horizontal separator for toolbars having CCS_VERT style.
532 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
533 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
534 * are horizontal as opposed to the vertical separators for not dropdown
537 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
540 TOOLBAR_DrawFlatHorizontalSeparator (const RECT
*lpRect
, HDC hdc
,
541 const TOOLBAR_INFO
*infoPtr
)
544 COLORREF oldcolor
, newcolor
;
546 myrect
.left
= lpRect
->left
;
547 myrect
.right
= lpRect
->right
;
548 myrect
.top
= lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
- 2)/2;
549 myrect
.bottom
= myrect
.top
+ 1;
551 InflateRect (&myrect
, -2, 0);
553 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect
));
555 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
556 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
557 oldcolor
= SetBkColor (hdc
, newcolor
);
558 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
560 myrect
.top
= myrect
.bottom
;
561 myrect
.bottom
= myrect
.top
+ 1;
563 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
564 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
565 SetBkColor (hdc
, newcolor
);
566 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
568 SetBkColor (hdc
, oldcolor
);
573 TOOLBAR_DrawArrow (HDC hdc
, INT left
, INT top
, COLORREF clr
)
578 if (!(hPen
= CreatePen( PS_SOLID
, 1, clr
))) return;
579 hOldPen
= SelectObject ( hdc
, hPen
);
582 MoveToEx (hdc
, x
, y
, NULL
);
583 LineTo (hdc
, x
+5, y
++); x
++;
584 MoveToEx (hdc
, x
, y
, NULL
);
585 LineTo (hdc
, x
+3, y
++); x
++;
586 MoveToEx (hdc
, x
, y
, NULL
);
587 LineTo (hdc
, x
+1, y
);
588 SelectObject( hdc
, hOldPen
);
589 DeleteObject( hPen
);
593 * Draw the text string for this button.
594 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
595 * is non-zero, so we can simply check himlDef to see if we have
599 TOOLBAR_DrawString (const TOOLBAR_INFO
*infoPtr
, RECT
*rcText
, LPCWSTR lpText
,
600 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
602 HDC hdc
= tbcd
->nmcd
.hdc
;
605 COLORREF clrOldBk
= 0;
607 UINT state
= tbcd
->nmcd
.uItemState
;
610 if (lpText
&& infoPtr
->nMaxTextRows
> 0) {
611 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText
),
612 wine_dbgstr_rect(rcText
));
614 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
615 if ((state
& CDIS_HOT
) && (dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)) {
616 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
618 else if (state
& CDIS_DISABLED
) {
619 clrOld
= SetTextColor (hdc
, tbcd
->clrBtnHighlight
);
620 OffsetRect (rcText
, 1, 1);
621 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
622 SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
623 OffsetRect (rcText
, -1, -1);
625 else if (state
& CDIS_INDETERMINATE
) {
626 clrOld
= SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
628 else if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
)) {
629 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
630 clrOldBk
= SetBkColor (hdc
, tbcd
->clrMark
);
631 oldBkMode
= SetBkMode (hdc
, tbcd
->nHLStringBkMode
);
634 clrOld
= SetTextColor (hdc
, tbcd
->clrText
);
637 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
638 SetTextColor (hdc
, clrOld
);
639 if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
))
641 SetBkColor (hdc
, clrOldBk
);
642 SetBkMode (hdc
, oldBkMode
);
644 SelectObject (hdc
, hOldFont
);
650 TOOLBAR_DrawPattern (const RECT
*lpRect
, const NMTBCUSTOMDRAW
*tbcd
)
652 HDC hdc
= tbcd
->nmcd
.hdc
;
653 HBRUSH hbr
= SelectObject (hdc
, tbcd
->hbrMonoDither
);
656 INT cx
= lpRect
->right
- lpRect
->left
;
657 INT cy
= lpRect
->bottom
- lpRect
->top
;
658 INT cxEdge
= GetSystemMetrics(SM_CXEDGE
);
659 INT cyEdge
= GetSystemMetrics(SM_CYEDGE
);
660 clrTextOld
= SetTextColor(hdc
, tbcd
->clrBtnHighlight
);
661 clrBkOld
= SetBkColor(hdc
, tbcd
->clrBtnFace
);
662 PatBlt (hdc
, lpRect
->left
+ cxEdge
, lpRect
->top
+ cyEdge
,
663 cx
- (2 * cxEdge
), cy
- (2 * cyEdge
), PATCOPY
);
664 SetBkColor(hdc
, clrBkOld
);
665 SetTextColor(hdc
, clrTextOld
);
666 SelectObject (hdc
, hbr
);
670 static void TOOLBAR_DrawMasked(HIMAGELIST himl
, int index
, HDC hdc
, INT x
, INT y
, UINT draw_flags
)
672 IMAGELISTDRAWPARAMS draw_params
= { 0 };
674 HBITMAP hbmMask
, hbmImage
;
675 HDC hdcMask
, hdcImage
;
677 ImageList_GetIconSize(himl
, &cx
, &cy
);
679 draw_params
.cbSize
= sizeof(draw_params
);
680 draw_params
.himl
= himl
;
681 draw_params
.i
= index
;
682 draw_params
.hdcDst
= hdc
;
687 draw_params
.rgbBk
= CLR_NONE
;
688 draw_params
.rgbFg
= CLR_NONE
;
689 draw_params
.fStyle
= draw_flags
;
690 draw_params
.fState
= ILS_NORMAL
;
692 /* 32bpp image with alpha channel is converted to grayscale */
693 if (imagelist_has_alpha(himl
, index
))
695 draw_params
.fState
= ILS_SATURATE
;
696 ImageList_DrawIndirect(&draw_params
);
700 /* Create src image */
701 hdcImage
= CreateCompatibleDC(hdc
);
702 hbmImage
= CreateCompatibleBitmap(hdc
, cx
, cy
);
703 SelectObject(hdcImage
, hbmImage
);
707 draw_params
.rgbBk
= RGB(0xff, 0xff, 0xff);
708 draw_params
.rgbFg
= RGB(0,0,0);
709 draw_params
.hdcDst
= hdcImage
;
710 ImageList_DrawIndirect(&draw_params
);
713 hdcMask
= CreateCompatibleDC(0);
714 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
715 SelectObject(hdcMask
, hbmMask
);
717 /* Remove the background and all white pixels */
718 draw_params
.fStyle
= ILD_MASK
;
719 draw_params
.hdcDst
= hdcMask
;
720 ImageList_DrawIndirect(&draw_params
);
721 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
722 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
724 /* draw the new mask 'etched' to hdc */
725 SetBkColor(hdc
, RGB(255, 255, 255));
726 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
727 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
728 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
729 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
730 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
733 DeleteObject(hbmImage
);
735 DeleteObject (hbmMask
);
741 TOOLBAR_TranslateState(const TBUTTON_INFO
*btnPtr
, BOOL captured
)
745 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
746 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
747 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
748 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
749 retstate
|= (btnPtr
->bHot
& !captured
) ? CDIS_HOT
: 0;
750 retstate
|= ((btnPtr
->fsState
& (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) == (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) ? CDIS_INDETERMINATE
: 0;
751 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
755 /* draws the image on a toolbar button */
757 TOOLBAR_DrawImage(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
,
758 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
760 HIMAGELIST himl
= NULL
;
761 BOOL draw_masked
= FALSE
;
764 UINT draw_flags
= ILD_TRANSPARENT
;
766 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
768 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
771 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
775 else if (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
||
776 ((tbcd
->nmcd
.uItemState
& CDIS_HOT
)
777 && ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || infoPtr
->hTheme
)))
779 /* if hot, attempt to draw with hot image list, if fails,
780 use default image list */
781 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
783 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
786 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
791 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
792 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
795 if (!(dwItemCDFlag
& TBCDRF_NOMARK
) &&
796 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
797 draw_flags
|= ILD_BLEND50
;
799 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
800 index
, himl
, left
, top
, offset
);
803 TOOLBAR_DrawMasked (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
805 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
808 /* draws a blank frame for a toolbar button */
810 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, const RECT
*rect
, DWORD dwItemCDFlag
)
812 HDC hdc
= tbcd
->nmcd
.hdc
;
814 /* if the state is disabled or indeterminate then the button
815 * cannot have an interactive look like pressed or hot */
816 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
817 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
818 BOOL pressed_look
= !non_interactive_state
&&
819 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
820 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
822 /* app don't want us to draw any edges */
823 if (dwItemCDFlag
& TBCDRF_NOEDGES
)
826 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
829 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
830 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
831 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
836 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
838 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
839 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
844 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
, BOOL bDropDownPressed
, DWORD dwItemCDFlag
)
846 HDC hdc
= tbcd
->nmcd
.hdc
;
848 BOOL pressed
= bDropDownPressed
||
849 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
));
851 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
854 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
);
855 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
856 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
857 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
858 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
863 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
865 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
866 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
870 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
872 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
874 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
875 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
878 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
881 /* draws a complete toolbar button */
883 TOOLBAR_DrawButton (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, HDC hdc
, DWORD dwBaseCustDraw
)
885 DWORD dwStyle
= infoPtr
->dwStyle
;
886 BOOL hasDropDownArrow
= button_has_ddarrow( infoPtr
, btnPtr
);
887 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
888 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
889 RECT rc
, rcArrow
, rcBitmap
, rcText
;
890 LPWSTR lpText
= NULL
;
895 DWORD dwItemCustDraw
;
897 HTHEME theme
= infoPtr
->hTheme
;
902 /* separator - doesn't send NM_CUSTOMDRAW */
903 if (btnPtr
->fsStyle
& BTNS_SEP
) {
906 DrawThemeBackground (theme
, hdc
,
907 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
911 /* with the FLAT style, iBitmap is the width and has already */
912 /* been taken into consideration in calculating the width */
913 /* so now we need to draw the vertical separator */
914 /* empirical tests show that iBitmap can/will be non-zero */
915 /* when drawing the vertical bar... */
916 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
917 if (dwStyle
& CCS_VERT
) {
919 InflateRect(&rcsep
, -infoPtr
->szPadding
.cx
, -infoPtr
->szPadding
.cy
);
920 TOOLBAR_DrawFlatHorizontalSeparator (&rcsep
, hdc
, infoPtr
);
923 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
925 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
926 FIXME("Draw some kind of separator: fsStyle=%x\n",
932 /* get a pointer to the text */
933 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
935 if (hasDropDownArrow
)
939 if (dwStyle
& TBSTYLE_FLAT
)
940 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
942 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
944 if (drawSepDropDownArrow
)
947 rcArrow
.left
= right
;
950 /* copy text & bitmap rects after adjusting for drop-down arrow
951 * so that text & bitmap is centered in the rectangle not containing
956 /* Center the bitmap horizontally and vertically */
957 if (dwStyle
& TBSTYLE_LIST
)
960 infoPtr
->nMaxTextRows
> 0 &&
961 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
962 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
963 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
965 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
968 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
970 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
972 TRACE("iBitmap=%d, start=(%ld,%ld) w=%d, h=%d\n", btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
973 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
974 TRACE("Text=%s\n", debugstr_w(lpText
));
975 TRACE("iListGap=%d, padding = { %ld, %ld }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
977 /* calculate text position */
980 InflateRect(&rcText
, -GetSystemMetrics(SM_CXEDGE
), 0);
981 if (dwStyle
& TBSTYLE_LIST
)
983 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
987 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
988 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
990 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
994 /* Initialize fields in all cases, because we use these later
995 * NOTE: applications can and do alter these to customize their
997 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
998 tbcd
.clrText
= comctl32_color
.clrBtnText
;
999 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
1000 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
1001 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
1002 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
1003 tbcd
.clrHighlightHotTrack
= 0;
1004 tbcd
.nStringBkMode
= TRANSPARENT
;
1005 tbcd
.nHLStringBkMode
= OPAQUE
;
1006 tbcd
.rcText
.left
= 0;
1007 tbcd
.rcText
.top
= 0;
1008 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
1009 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
1010 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
, infoPtr
->bCaptured
);
1011 tbcd
.nmcd
.hdc
= hdc
;
1012 tbcd
.nmcd
.rc
= btnPtr
->rect
;
1013 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
1015 /* FIXME: what are these used for? */
1019 /* Issue Item Prepaint notify */
1022 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
1024 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
1025 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
1026 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
1027 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1028 /* reset these fields so the user can't alter the behaviour like native */
1029 tbcd
.nmcd
.hdc
= hdc
;
1030 tbcd
.nmcd
.rc
= btnPtr
->rect
;
1032 dwItemCustDraw
= ntfret
& 0xffff;
1033 dwItemCDFlag
= ntfret
& 0xffff0000;
1034 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
1036 /* save the only part of the rect that the user can change */
1037 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
1038 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
1041 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
1042 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
1043 OffsetRect(&rcText
, 1, 1);
1045 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
1046 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
1047 TOOLBAR_DrawPattern (&rc
, &tbcd
);
1049 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || theme
) && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
1051 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
1055 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
1056 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
1057 if (hasDropDownArrow
)
1058 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
1059 SetBkColor(hdc
, oldclr
);
1065 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
1066 int stateId
= TS_NORMAL
;
1068 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1069 stateId
= TS_DISABLED
;
1070 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1071 stateId
= TS_PRESSED
;
1072 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1073 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_CHECKED
;
1074 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1075 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1078 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &rc
, NULL
);
1081 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, &rc
, dwItemCDFlag
);
1083 if (drawSepDropDownArrow
)
1087 int stateId
= TS_NORMAL
;
1089 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1090 stateId
= TS_DISABLED
;
1091 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1092 stateId
= TS_PRESSED
;
1093 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1094 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_CHECKED
;
1095 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1098 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1099 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1102 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1105 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1106 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1107 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1108 SetBkMode (hdc
, oldBkMode
);
1110 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1112 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1114 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1116 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1117 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1119 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1121 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1122 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1125 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1128 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1130 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1131 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1138 TOOLBAR_Refresh (TOOLBAR_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
1140 TBUTTON_INFO
*btnPtr
;
1142 RECT rcTemp
, rcClient
;
1143 NMTBCUSTOMDRAW tbcd
;
1145 DWORD dwBaseCustDraw
;
1147 /* the app has told us not to redraw the toolbar */
1148 if (!infoPtr
->bDoRedraw
)
1151 /* if imagelist belongs to the app, it can be changed
1152 by the app after setting it */
1153 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1155 infoPtr
->nNumBitmaps
= 0;
1156 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1157 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1160 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1162 /* change the imagelist icon size if we manage the list and it is necessary */
1163 TOOLBAR_CheckImageListIconSize(infoPtr
);
1165 /* Send initial notify */
1166 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1167 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1168 tbcd
.nmcd
.hdc
= hdc
;
1169 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1170 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1171 dwBaseCustDraw
= ntfret
& 0xffff;
1173 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1175 /* redraw necessary buttons */
1176 btnPtr
= infoPtr
->buttons
;
1177 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1180 if (!RectVisible(hdc
, &btnPtr
->rect
))
1182 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1184 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1185 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1189 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1190 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1192 TOOLBAR_DrawButton(infoPtr
, btnPtr
, hdc
, dwBaseCustDraw
);
1195 /* draw insert mark if required */
1196 if (infoPtr
->tbim
.iButton
!= -1)
1198 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1200 rcInsertMark
.top
= rcButton
.top
;
1201 rcInsertMark
.bottom
= rcButton
.bottom
;
1202 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1203 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1205 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1206 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1209 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1211 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1212 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1213 tbcd
.nmcd
.hdc
= hdc
;
1214 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1215 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1219 /***********************************************************************
1220 * TOOLBAR_MeasureString
1222 * This function gets the width and height of a string in pixels. This
1223 * is done first by using GetTextExtentPoint to get the basic width
1224 * and height. The DrawText is called with DT_CALCRECT to get the exact
1225 * width. The reason is because the text may have more than one "&" (or
1226 * prefix characters as M$ likes to call them). The prefix character
1227 * indicates where the underline goes, except for the string "&&" which
1228 * is reduced to a single "&". GetTextExtentPoint does not process these
1229 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1232 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1233 HDC hdc
, LPSIZE lpSize
)
1240 if (infoPtr
->nMaxTextRows
> 0 &&
1241 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1242 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1243 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1245 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1247 if(lpText
!= NULL
) {
1248 /* first get size of all the text */
1249 GetTextExtentPoint32W (hdc
, lpText
, lstrlenW (lpText
), lpSize
);
1251 /* feed above size into the rectangle for DrawText */
1252 SetRect(&myrect
, 0, 0, lpSize
->cx
, lpSize
->cy
);
1254 /* Use DrawText to get true size as drawn (less pesky "&") */
1255 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1256 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1259 /* feed back to caller */
1260 lpSize
->cx
= myrect
.right
;
1261 lpSize
->cy
= myrect
.bottom
;
1265 TRACE("string size %ld x %ld.\n", lpSize
->cx
, lpSize
->cy
);
1268 /***********************************************************************
1269 * TOOLBAR_CalcStrings
1271 * This function walks through each string and measures it and returns
1272 * the largest height and width to caller.
1275 TOOLBAR_CalcStrings (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
1277 TBUTTON_INFO
*btnPtr
;
1286 if (infoPtr
->nMaxTextRows
== 0)
1289 hdc
= GetDC (infoPtr
->hwndSelf
);
1290 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1292 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1296 GetTextMetricsW(hdc
, &tm
);
1297 lpSize
->cy
= tm
.tmHeight
;
1300 btnPtr
= infoPtr
->buttons
;
1301 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1302 if(TOOLBAR_GetText(infoPtr
, btnPtr
))
1304 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1305 if (sz
.cx
> lpSize
->cx
)
1307 if (sz
.cy
> lpSize
->cy
)
1312 SelectObject (hdc
, hOldFont
);
1313 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1315 TRACE("max string size %ld x %ld\n", lpSize
->cx
, lpSize
->cy
);
1318 /***********************************************************************
1319 * TOOLBAR_WrapToolbar
1321 * This function walks through the buttons and separators in the
1322 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1323 * wrapping should occur based on the width of the toolbar window.
1324 * It does *not* calculate button placement itself. That task
1325 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1326 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1327 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1329 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_VERTICAL can be used also to allow
1330 * vertical toolbar lists.
1334 TOOLBAR_WrapToolbar(TOOLBAR_INFO
*infoPtr
)
1336 TBUTTON_INFO
*btnPtr
;
1337 INT x
, cx
, i
, j
, width
;
1340 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1341 /* no layout is necessary. Applications may use this style */
1342 /* to perform their own layout on the toolbar. */
1343 if( !(infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) &&
1344 !(infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
) ) return;
1346 btnPtr
= infoPtr
->buttons
;
1347 x
= infoPtr
->nIndent
;
1348 width
= infoPtr
->client_rect
.right
- infoPtr
->client_rect
.left
;
1350 bButtonWrap
= FALSE
;
1352 TRACE("start ButtonWidth=%d, BitmapWidth=%d, width=%d, nIndent=%d\n",
1353 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, width
,
1356 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1358 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1360 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1363 if (btnPtr
[i
].cx
> 0)
1365 /* horizontal separators are treated as buttons for width */
1366 else if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1367 !(infoPtr
->dwStyle
& CCS_VERT
))
1368 cx
= (btnPtr
[i
].iBitmap
> 0) ? btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1370 cx
= infoPtr
->nButtonWidth
;
1372 if (!btnPtr
[i
].cx
&& button_has_ddarrow( infoPtr
, btnPtr
+ i
))
1373 cx
+= DDARROW_WIDTH
;
1375 /* Two or more adjacent separators form a separator group. */
1376 /* The first separator in a group should be wrapped to the */
1377 /* next row if the previous wrapping is on a button. */
1379 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1380 (i
+ 1 < infoPtr
->nNumButtons
) &&
1381 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1383 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1384 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1385 x
= infoPtr
->nIndent
;
1387 bButtonWrap
= FALSE
;
1391 /* The layout makes sure the bitmap is visible, but not the button. */
1392 /* Test added to also wrap after a button that starts a row but */
1393 /* is bigger than the area. - GA 8/01 */
1394 if ((x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2 > width
) ||
1395 ((x
== infoPtr
->nIndent
) && (cx
> width
)))
1397 BOOL bFound
= FALSE
;
1399 /* If the current button is a separator and not hidden, */
1400 /* go to the next until it reaches a non separator. */
1401 /* Wrap the last separator if it is before a button. */
1402 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1403 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1404 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1405 i
< infoPtr
->nNumButtons
)
1411 if( bFound
&& i
< infoPtr
->nNumButtons
)
1414 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1415 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1416 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1417 x
= infoPtr
->nIndent
;
1418 bButtonWrap
= FALSE
;
1421 else if ( i
>= infoPtr
->nNumButtons
)
1424 /* If the current button is not a separator, find the last */
1425 /* separator and wrap it. */
1426 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1428 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1429 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1433 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1434 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1435 x
= infoPtr
->nIndent
;
1436 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1437 bButtonWrap
= FALSE
;
1442 /* If no separator available for wrapping, wrap one of */
1443 /* non-hidden previous button. */
1447 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1449 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1454 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1455 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1456 x
= infoPtr
->nIndent
;
1457 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1463 /* If all above failed, wrap the current button. */
1466 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1467 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1468 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1469 x
= infoPtr
->nIndent
;
1470 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1471 bButtonWrap
= FALSE
;
1477 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1478 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1485 /***********************************************************************
1486 * TOOLBAR_MeasureButton
1488 * Calculates the width and height required for a button. Used in
1489 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1490 * the width of buttons that are autosized.
1492 * Note that it would have been rather elegant to use one piece of code for
1493 * both the laying out of the toolbar and for controlling where button parts
1494 * are drawn, but the native control has inconsistencies between the two that
1495 * prevent this from being effectively. These inconsistencies can be seen as
1496 * artefacts where parts of the button appear outside of the bounding button
1499 * There are several cases for the calculation of the button dimensions and
1500 * button part positioning:
1507 * +--------------------------------------------------------+ ^
1509 * | | pad.cy / 2 | centered | |
1510 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1511 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1512 * | |<------------>| | | | |
1513 * | +--------------+ +------------+ | |
1514 * |<-------------------------------------->| | |
1515 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1517 * +--------------------------------------------------------+ -
1518 * <-------------------------------------------------------->
1519 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1521 * Without Bitmap (I_IMAGENONE):
1523 * +-----------------------------------+ ^
1525 * | | centered | | LISTPAD_CY +
1526 * | +------------+ | | szText.cy
1529 * | +------------+ | |
1530 * |<----------------->| | |
1531 * | cxedge |<-----------> | |
1533 * +-----------------------------------+ -
1534 * <----------------------------------->
1535 * szText.cx + pad.cx
1539 * +--------------------------------------+ ^
1541 * | | padding.cy/2 | | DEFPAD_CY +
1542 * | +------------+ | | nBitmapHeight
1545 * | +------------+ | |
1546 * |<------------------->| | |
1547 * | cxedge + iListGap/2 |<-----------> | |
1548 * | nBitmapWidth | |
1549 * +--------------------------------------+ -
1550 * <-------------------------------------->
1551 * 2*cxedge + nBitmapWidth + iListGap
1558 * +-----------------------------------+ ^
1560 * | | pad.cy / 2 | | nBitmapHeight +
1561 * | - | | szText.cy +
1562 * | +------------+ | | DEFPAD_CY + 1
1563 * | centered | Bitmap | | |
1564 * |<----------------->| | | |
1565 * | +------------+ | |
1569 * | centered +---------------+ | |
1570 * |<--------------->| Text | | |
1571 * | +---------------+ | |
1572 * +-----------------------------------+ -
1573 * <----------------------------------->
1574 * pad.cx + max(nBitmapWidth, szText.cx)
1576 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1578 * +---------------------------------------+ ^
1580 * | | 2 + pad.cy / 2 | |
1581 * | - | | szText.cy +
1582 * | centered +-----------------+ | | pad.cy + 2
1583 * |<--------------->| Text | | |
1584 * | +-----------------+ | |
1586 * +---------------------------------------+ -
1587 * <--------------------------------------->
1588 * 2*cxedge + pad.cx + szText.cx
1591 * As for with bitmaps, but with szText.cx zero.
1593 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1594 BOOL bHasBitmap
, BOOL bValidImageList
)
1597 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1599 /* set button height from bitmap / text height... */
1600 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1603 /* ... add on the necessary padding */
1604 if (bValidImageList
)
1607 sizeButton
.cy
+= DEFPAD_CY
;
1609 sizeButton
.cy
+= LISTPAD_CY
;
1612 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1614 /* calculate button width */
1615 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1616 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1617 if (sizeString
.cx
> 0)
1618 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1625 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1626 if (sizeString
.cy
> 0)
1627 sizeButton
.cy
+= 1 + sizeString
.cy
;
1628 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1629 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1633 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1634 NONLIST_NOTEXT_OFFSET
;
1635 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1636 max(2*GetSystemMetrics(SM_CXEDGE
) + sizeString
.cx
, infoPtr
->nBitmapWidth
);
1643 /***********************************************************************
1644 * TOOLBAR_CalcToolbar
1646 * This function calculates button and separator placement. It first
1647 * calculates the button sizes, gets the toolbar window width and then
1648 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1649 * on. It assigns a new location to each item and sends this location to
1650 * the tooltip window if appropriate. Finally, it updates the rcBound
1651 * rect and calculates the new required toolbar window height.
1654 TOOLBAR_CalcToolbar (TOOLBAR_INFO
*infoPtr
)
1656 SIZE sizeString
, sizeButton
;
1657 BOOL validImageList
= FALSE
;
1659 TOOLBAR_CalcStrings (infoPtr
, &sizeString
);
1661 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1663 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1664 validImageList
= TRUE
;
1665 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1666 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1667 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1668 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1670 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1671 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1672 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1673 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1675 TOOLBAR_LayoutToolbar(infoPtr
);
1679 TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
)
1681 TBUTTON_INFO
*btnPtr
;
1683 INT i
, nRows
, nSepRows
;
1686 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1688 TOOLBAR_WrapToolbar(infoPtr
);
1690 x
= infoPtr
->nIndent
;
1691 y
= infoPtr
->iTopMargin
;
1692 cx
= infoPtr
->nButtonWidth
;
1693 cy
= infoPtr
->nButtonHeight
;
1695 nRows
= nSepRows
= 0;
1697 infoPtr
->rcBound
.top
= y
;
1698 infoPtr
->rcBound
.left
= x
;
1699 infoPtr
->rcBound
.bottom
= y
+ cy
;
1700 infoPtr
->rcBound
.right
= x
;
1702 btnPtr
= infoPtr
->buttons
;
1704 TRACE("cy=%d\n", cy
);
1706 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1709 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1711 SetRectEmpty (&btnPtr
->rect
);
1712 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1716 cy
= infoPtr
->nButtonHeight
;
1718 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1719 if (infoPtr
->dwStyle
& CCS_VERT
) {
1720 cy
= (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1721 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
: infoPtr
->nButtonWidth
;
1724 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
:
1725 (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1731 else if (btnPtr
->fsStyle
& BTNS_AUTOSIZE
)
1737 hdc
= GetDC (infoPtr
->hwndSelf
);
1738 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1740 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1742 SelectObject (hdc
, hOldFont
);
1743 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1745 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1746 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1751 cx
= infoPtr
->nButtonWidth
;
1753 /* if size has been set manually then don't add on extra space
1754 * for the drop down arrow */
1755 if (!btnPtr
->cx
&& button_has_ddarrow( infoPtr
, btnPtr
))
1756 cx
+= DDARROW_WIDTH
;
1758 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1761 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1763 if (infoPtr
->rcBound
.left
> x
)
1764 infoPtr
->rcBound
.left
= x
;
1765 if (infoPtr
->rcBound
.right
< x
+ cx
)
1766 infoPtr
->rcBound
.right
= x
+ cx
;
1767 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1768 infoPtr
->rcBound
.bottom
= y
+ cy
;
1770 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1772 /* btnPtr->nRow is zero based. The space between the rows is */
1773 /* also considered as a row. */
1774 btnPtr
->nRow
= nRows
+ nSepRows
;
1776 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1777 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1782 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1786 if ( !(infoPtr
->dwStyle
& CCS_VERT
))
1787 y
+= cy
+ ( (btnPtr
->cx
> 0 ) ?
1788 btnPtr
->cx
: SEPARATOR_WIDTH
) * 2 /3;
1792 /* nSepRows is used to calculate the extra height following */
1796 x
= infoPtr
->nIndent
;
1798 /* Increment row number unless this is the last button */
1799 /* and it has Wrap set. */
1800 if (i
!= infoPtr
->nNumButtons
-1)
1807 /* infoPtr->nRows is the number of rows on the toolbar */
1808 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1810 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1815 TOOLBAR_InternalHitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
*lpPt
, BOOL
*button
)
1817 TBUTTON_INFO
*btnPtr
;
1823 btnPtr
= infoPtr
->buttons
;
1824 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1825 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1828 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1829 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1830 TRACE(" ON SEPARATOR %d\n", i
);
1835 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1836 TRACE(" ON BUTTON %d\n", i
);
1844 TRACE(" NOWHERE\n");
1845 return TOOLBAR_NOWHERE
;
1849 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1851 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO
*infoPtr
, INT iIndex
, UINT nAddButtons
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
1853 INT nOldButtons
, nNewButtons
, iButton
;
1854 BOOL fHasString
= FALSE
;
1856 if (iIndex
< 0) /* iIndex can be negative, what means adding at the end */
1857 iIndex
= infoPtr
->nNumButtons
;
1859 nOldButtons
= infoPtr
->nNumButtons
;
1860 nNewButtons
= nOldButtons
+ nAddButtons
;
1862 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
1863 memmove(&infoPtr
->buttons
[iIndex
+ nAddButtons
], &infoPtr
->buttons
[iIndex
],
1864 (nOldButtons
- iIndex
) * sizeof(TBUTTON_INFO
));
1865 infoPtr
->nNumButtons
+= nAddButtons
;
1867 /* insert new buttons data */
1868 for (iButton
= 0; iButton
< nAddButtons
; iButton
++) {
1869 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[iIndex
+ iButton
];
1872 TOOLBAR_DumpTBButton(lpTbb
+ iButton
, fUnicode
);
1874 ZeroMemory(btnPtr
, sizeof(*btnPtr
));
1876 btnPtr
->iBitmap
= lpTbb
[iButton
].iBitmap
;
1877 btnPtr
->idCommand
= lpTbb
[iButton
].idCommand
;
1878 btnPtr
->fsState
= lpTbb
[iButton
].fsState
;
1879 btnPtr
->fsStyle
= lpTbb
[iButton
].fsStyle
;
1880 btnPtr
->dwData
= lpTbb
[iButton
].dwData
;
1882 if (btnPtr
->fsStyle
& BTNS_SEP
)
1885 str
= lpTbb
[iButton
].iString
;
1886 set_string_index( btnPtr
, str
, fUnicode
);
1887 fHasString
|= TOOLBAR_ButtonHasString( btnPtr
);
1889 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
1892 if (infoPtr
->nNumStrings
> 0 || fHasString
)
1893 TOOLBAR_CalcToolbar(infoPtr
);
1895 TOOLBAR_LayoutToolbar(infoPtr
);
1896 TOOLBAR_AutoSize(infoPtr
);
1898 TOOLBAR_DumpToolbar(infoPtr
, __LINE__
);
1899 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1905 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1907 TBUTTON_INFO
*btnPtr
;
1910 if (CommandIsIndex
) {
1911 TRACE("command is really index command=%d\n", idCommand
);
1912 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1915 btnPtr
= infoPtr
->buttons
;
1916 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1917 if (btnPtr
->idCommand
== idCommand
) {
1918 TRACE("command=%d index=%d\n", idCommand
, i
);
1922 TRACE("no index found for command=%d\n", idCommand
);
1928 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1930 TBUTTON_INFO
*btnPtr
;
1933 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1936 /* check index button */
1937 btnPtr
= &infoPtr
->buttons
[nIndex
];
1938 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1939 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1943 /* check previous buttons */
1944 nRunIndex
= nIndex
- 1;
1945 while (nRunIndex
>= 0) {
1946 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1947 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1948 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1956 /* check next buttons */
1957 nRunIndex
= nIndex
+ 1;
1958 while (nRunIndex
< infoPtr
->nNumButtons
) {
1959 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1960 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1961 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1974 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1975 WPARAM wParam
, LPARAM lParam
)
1981 msg
.wParam
= wParam
;
1982 msg
.lParam
= lParam
;
1983 msg
.time
= GetMessageTime ();
1984 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
1985 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
1987 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1991 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1993 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
1996 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
1997 ti
.cbSize
= sizeof (TTTOOLINFOW
);
1998 ti
.hwnd
= infoPtr
->hwndSelf
;
1999 ti
.uId
= button
->idCommand
;
2001 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
2002 /* ti.lParam = random value from the stack? */
2004 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
2010 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2012 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
2015 ZeroMemory(&ti
, sizeof(ti
));
2016 ti
.cbSize
= sizeof(ti
);
2017 ti
.hwnd
= infoPtr
->hwndSelf
;
2018 ti
.uId
= button
->idCommand
;
2020 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
2024 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2026 /* Set the toolTip only for non-hidden, non-separator button */
2027 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
2031 ZeroMemory(&ti
, sizeof(ti
));
2032 ti
.cbSize
= sizeof(ti
);
2033 ti
.hwnd
= infoPtr
->hwndSelf
;
2034 ti
.uId
= button
->idCommand
;
2035 ti
.rect
= button
->rect
;
2036 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
2040 /* Creates the tooltip control */
2042 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
2045 NMTOOLTIPSCREATED nmttc
;
2047 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
2048 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2049 infoPtr
->hwndSelf
, 0, 0, 0);
2051 if (!infoPtr
->hwndToolTip
)
2054 /* Send NM_TOOLTIPSCREATED notification */
2055 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
2056 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
2058 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
2060 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
2061 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
2065 /* keeps available button list box sorted by button id */
2066 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
2070 PCUSTOMBUTTON btnInfo
;
2071 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2073 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
2075 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2077 /* position 0 is always separator */
2078 for (i
= 1; i
< count
; i
++)
2080 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2081 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2083 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2084 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2088 /* id higher than all others add to end */
2089 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2090 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2093 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2097 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2099 if (nIndexFrom
== nIndexTo
)
2102 /* MSDN states that iItem is the index of the button, rather than the
2103 * command ID as used by every other NMTOOLBAR notification */
2104 nmtb
.iItem
= nIndexFrom
;
2105 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2107 PCUSTOMBUTTON btnInfo
;
2109 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2110 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2112 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2114 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2115 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2116 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2117 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2120 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2122 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2124 /* last item is always separator, so -2 instead of -1 */
2125 if (nIndexTo
>= (count
- 2))
2126 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2128 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2130 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2131 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2133 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2137 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2141 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2143 /* MSDN states that iItem is the index of the button, rather than the
2144 * command ID as used by every other NMTOOLBAR notification */
2145 nmtb
.iItem
= nIndexAvail
;
2146 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2148 PCUSTOMBUTTON btnInfo
;
2150 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2151 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2152 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2154 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2156 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2158 /* remove from 'available buttons' list */
2159 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2160 if (nIndexAvail
== count
-1)
2161 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2163 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2167 PCUSTOMBUTTON btnNew
;
2169 /* duplicate 'separator' button */
2170 btnNew
= Alloc(sizeof(CUSTOMBUTTON
));
2175 /* insert into 'toolbar button' list */
2176 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2177 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2179 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2181 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2185 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2187 PCUSTOMBUTTON btnInfo
;
2188 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2190 TRACE("Remove: index %d\n", index
);
2192 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2194 /* send TBN_QUERYDELETE notification */
2195 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2199 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2200 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2202 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2204 /* insert into 'available button' list */
2205 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2206 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2210 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2214 /* drag list notification function for toolbar buttons list box */
2215 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2216 const DRAGLISTINFO
*pDLI
)
2218 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2219 switch (pDLI
->uNotification
)
2223 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2224 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2225 /* no dragging for last item (separator) */
2226 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2231 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2232 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2233 /* no dragging past last item (separator) */
2234 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2236 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2237 /* FIXME: native uses "move button" cursor */
2238 return DL_COPYCURSOR
;
2241 /* not over toolbar buttons list */
2242 if (nCurrentItem
< 0)
2244 POINT ptWindow
= pDLI
->ptCursor
;
2245 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2246 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2247 /* over available buttons list? */
2248 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2249 /* FIXME: native uses "move button" cursor */
2250 return DL_COPYCURSOR
;
2252 /* clear drag arrow */
2253 DrawInsert(hwnd
, hwndList
, -1);
2254 return DL_STOPCURSOR
;
2258 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2259 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2260 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2261 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2263 /* clear drag arrow */
2264 DrawInsert(hwnd
, hwndList
, -1);
2266 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2268 /* not over toolbar buttons list */
2271 POINT ptWindow
= pDLI
->ptCursor
;
2272 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2273 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2274 /* over available buttons list? */
2275 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2276 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2281 /* Clear drag arrow */
2282 DrawInsert(hwnd
, hwndList
, -1);
2289 /* drag list notification function for available buttons list box */
2290 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2291 const DRAGLISTINFO
*pDLI
)
2293 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2294 switch (pDLI
->uNotification
)
2300 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2301 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2302 /* no dragging past last item (separator) */
2303 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2305 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2306 /* FIXME: native uses "move button" cursor */
2307 return DL_COPYCURSOR
;
2310 /* not over toolbar buttons list */
2311 if (nCurrentItem
< 0)
2313 POINT ptWindow
= pDLI
->ptCursor
;
2314 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2315 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2316 /* over available buttons list? */
2317 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2318 /* FIXME: native uses "move button" cursor */
2319 return DL_COPYCURSOR
;
2321 /* clear drag arrow */
2322 DrawInsert(hwnd
, hwndList
, -1);
2323 return DL_STOPCURSOR
;
2327 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2328 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2329 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2330 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2332 /* clear drag arrow */
2333 DrawInsert(hwnd
, hwndList
, -1);
2335 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2339 /* Clear drag arrow */
2340 DrawInsert(hwnd
, hwndList
, -1);
2346 extern UINT uDragListMessage DECLSPEC_HIDDEN
;
2348 /***********************************************************************
2349 * TOOLBAR_CustomizeDialogProc
2350 * This function implements the toolbar customization dialog.
2352 static INT_PTR CALLBACK
2353 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2355 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2356 PCUSTOMBUTTON btnInfo
;
2358 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2363 custInfo
= (PCUSTDLG_INFO
)lParam
;
2364 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2371 NMTBINITCUSTOMIZE nmtbic
;
2373 infoPtr
= custInfo
->tbInfo
;
2375 /* send TBN_QUERYINSERT notification */
2376 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2378 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2381 nmtbic
.hwndDialog
= hwnd
;
2382 /* Send TBN_INITCUSTOMIZE notification */
2383 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2386 TRACE("TBNRF_HIDEHELP requested\n");
2387 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2390 /* add items to 'toolbar buttons' list and check if removable */
2391 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2393 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2394 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2395 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2396 btnInfo
->bVirtual
= FALSE
;
2397 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2399 /* send TBN_QUERYDELETE notification */
2400 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2402 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2403 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2406 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2408 /* insert separator button into 'available buttons' list */
2409 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2410 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2411 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2412 btnInfo
->bVirtual
= FALSE
;
2413 btnInfo
->bRemovable
= TRUE
;
2414 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2415 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2416 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2418 /* insert all buttons into dsa */
2421 /* send TBN_GETBUTTONINFO notification */
2424 nmtb
.pszText
= Buffer
;
2427 /* Clear previous button's text */
2428 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2430 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2433 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%Id) %s\n",
2434 nmtb
.tbButton
.fsStyle
, i
,
2435 nmtb
.tbButton
.idCommand
,
2436 nmtb
.tbButton
.iString
,
2437 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2440 /* insert button into the appropriate list */
2441 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2444 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2445 btnInfo
->bVirtual
= FALSE
;
2446 btnInfo
->bRemovable
= TRUE
;
2450 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2451 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2454 btnInfo
->btn
= nmtb
.tbButton
;
2455 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2458 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2459 else if (nmtb
.tbButton
.iString
>= 0 &&
2460 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2462 lstrcpyW(btnInfo
->text
,
2463 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2468 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2471 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2473 /* select first item in the 'available' list */
2474 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2476 /* append 'virtual' separator button to the 'toolbar buttons' list */
2477 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2478 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2479 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2480 btnInfo
->bVirtual
= TRUE
;
2481 btnInfo
->bRemovable
= FALSE
;
2482 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2483 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2484 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2486 /* select last item in the 'toolbar' list */
2487 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2488 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2490 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2491 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2493 /* set focus and disable buttons */
2494 PostMessageW (hwnd
, WM_USER
, 0, 0);
2499 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2500 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2501 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2502 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2506 EndDialog(hwnd
, FALSE
);
2510 switch (LOWORD(wParam
))
2512 case IDC_TOOLBARBTN_LBOX
:
2513 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2515 PCUSTOMBUTTON btnInfo
;
2520 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2521 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2523 /* send TBN_QUERYINSERT notification */
2525 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2527 /* get list box item */
2528 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2530 if (index
== (count
- 1))
2532 /* last item (virtual separator) */
2533 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2534 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2536 else if (index
== (count
- 2))
2538 /* second last item (last non-virtual item) */
2539 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2540 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2542 else if (index
== 0)
2545 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2546 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2550 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2551 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2554 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2558 case IDC_MOVEUP_BTN
:
2560 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2561 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2565 case IDC_MOVEDN_BTN
: /* move down */
2567 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2568 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2572 case IDC_REMOVE_BTN
: /* remove button */
2574 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2576 if (LB_ERR
== index
)
2579 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2583 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2586 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2589 case IDOK
: /* Add button */
2594 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2595 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2597 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2602 EndDialog(hwnd
, FALSE
);
2612 /* delete items from 'toolbar buttons' listbox*/
2613 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2614 for (i
= 0; i
< count
; i
++)
2616 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2618 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2620 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2623 /* delete items from 'available buttons' listbox*/
2624 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2625 for (i
= 0; i
< count
; i
++)
2627 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2629 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2631 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2636 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2638 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2643 COLORREF oldText
= 0;
2647 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, lpdis
->itemID
, 0);
2648 if (btnInfo
== NULL
)
2650 FIXME("btnInfo invalid\n");
2654 /* set colors and select objects */
2655 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2656 if (btnInfo
->bVirtual
)
2657 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2659 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2660 hPen
= CreatePen( PS_SOLID
, 1,
2661 (lpdis
->itemState
& ODS_SELECTED
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2662 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2663 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2665 /* fill background rectangle */
2666 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2667 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2669 /* calculate button and text rectangles */
2670 rcButton
= lpdis
->rcItem
;
2671 InflateRect (&rcButton
, -1, -1);
2673 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2674 rcText
.left
= rcButton
.right
+ 2;
2676 /* draw focus rectangle */
2677 if (lpdis
->itemState
& ODS_FOCUS
)
2678 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2681 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2682 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2684 /* draw image and text */
2685 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2686 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2687 btnInfo
->btn
.iBitmap
));
2688 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2689 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2691 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2692 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2694 /* delete objects and reset colors */
2695 SelectObject (lpdis
->hDC
, hOldBrush
);
2696 SelectObject (lpdis
->hDC
, hOldPen
);
2697 SetBkColor (lpdis
->hDC
, oldBk
);
2698 SetTextColor (lpdis
->hDC
, oldText
);
2699 DeleteObject( hPen
);
2704 case WM_MEASUREITEM
:
2705 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2707 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2709 lpmis
->itemHeight
= 15 + 8; /* default height */
2716 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2718 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2720 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2721 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2722 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2725 else if (wParam
== IDC_AVAILBTN_LBOX
)
2727 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2728 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2729 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2738 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2741 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2747 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2748 /* Add bitmaps to the default image list */
2749 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2750 hbmLoad
= CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2751 else if (bitmap
->hInst
== COMCTL32_hModule
)
2752 hbmLoad
= LoadImageW( bitmap
->hInst
, MAKEINTRESOURCEW(bitmap
->nID
),
2753 IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
2755 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2757 /* enlarge the bitmap if needed */
2758 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2759 if (bitmap
->hInst
!= COMCTL32_hModule
)
2760 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2762 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2763 DeleteObject(hbmLoad
);
2767 nCountAfter
= ImageList_GetImageCount(himlDef
);
2768 nAdded
= nCountAfter
- nCountBefore
;
2769 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2771 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2772 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2773 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2774 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2777 infoPtr
->nNumBitmaps
+= nAdded
;
2782 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2789 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2790 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2792 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2794 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2797 TRACE("Update icon size: %dx%d -> %dx%d\n",
2798 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2800 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2801 ILC_COLOR32
|ILC_MASK
, 8, 2);
2802 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2803 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2804 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2805 infoPtr
->himlInt
= himlNew
;
2807 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2808 ImageList_Destroy(himlDef
);
2811 /***********************************************************************
2812 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2816 TOOLBAR_AddBitmap (TOOLBAR_INFO
*infoPtr
, INT count
, const TBADDBITMAP
*lpAddBmp
)
2822 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr
->hwndSelf
, count
, lpAddBmp
);
2826 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2828 info
.hInst
= COMCTL32_hModule
;
2829 switch (lpAddBmp
->nID
)
2831 case IDB_STD_SMALL_COLOR
:
2834 info
.nID
= IDB_STD_SMALL
;
2836 case IDB_STD_LARGE_COLOR
:
2839 info
.nID
= IDB_STD_LARGE
;
2841 case IDB_VIEW_SMALL_COLOR
:
2844 info
.nID
= IDB_VIEW_SMALL
;
2846 case IDB_VIEW_LARGE_COLOR
:
2849 info
.nID
= IDB_VIEW_LARGE
;
2851 case IDB_HIST_SMALL_COLOR
:
2853 info
.nID
= IDB_HIST_SMALL
;
2855 case IDB_HIST_LARGE_COLOR
:
2857 info
.nID
= IDB_HIST_LARGE
;
2860 WARN("unknown bitmap id, %Id\n", lpAddBmp
->nID
);
2864 TRACE ("adding %d internal bitmaps\n", info
.nButtons
);
2866 /* Windows resize all the buttons to the size of a newly added standard image */
2867 if (lpAddBmp
->nID
& 1)
2869 /* large icons: 24x24. Will make the button 31x30 */
2870 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2874 /* small icons: 16x16. Will make the buttons 23x22 */
2875 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2878 TOOLBAR_CalcToolbar (infoPtr
);
2882 info
.nButtons
= count
;
2883 info
.hInst
= lpAddBmp
->hInst
;
2884 info
.nID
= lpAddBmp
->nID
;
2885 TRACE("adding %d bitmaps\n", info
.nButtons
);
2888 /* check if the bitmap is already loaded and compute iSumButtons */
2890 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2892 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2893 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2895 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2898 if (!infoPtr
->cimlDef
) {
2899 /* create new default image list */
2900 TRACE ("creating default image list\n");
2902 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2903 ILC_COLOR32
| ILC_MASK
, info
.nButtons
, 2);
2904 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2905 infoPtr
->himlInt
= himlDef
;
2908 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2912 WARN("No default image list available\n");
2916 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2919 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2920 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2921 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2922 infoPtr
->nNumBitmapInfos
++;
2923 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2925 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2931 TOOLBAR_AddButtonsT(TOOLBAR_INFO
*infoPtr
, INT nAddButtons
, const TBBUTTON
* lpTbb
, BOOL fUnicode
)
2933 TRACE("adding %d buttons (unicode=%d)\n", nAddButtons
, fUnicode
);
2935 return TOOLBAR_InternalInsertButtonsT(infoPtr
, -1, nAddButtons
, lpTbb
, fUnicode
);
2940 TOOLBAR_AddStringW (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
2942 #define MAX_RESOURCE_STRING_LENGTH 512
2943 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2944 INT nIndex
= infoPtr
->nNumStrings
;
2946 TRACE("%p, %Ix\n", hInstance
, lParam
);
2948 if (IS_INTRESOURCE(lParam
)) {
2949 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2956 TRACE("adding string from resource\n");
2958 if (!hInstance
) return -1;
2960 hrsrc
= FindResourceW( hInstance
, MAKEINTRESOURCEW((LOWORD(lParam
) >> 4) + 1),
2961 (LPWSTR
)RT_STRING
);
2964 TRACE("string not found in resources\n");
2968 len
= LoadStringW (hInstance
, (UINT
)lParam
,
2969 szString
, MAX_RESOURCE_STRING_LENGTH
);
2971 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2972 if (len
== 0 || len
== 1)
2975 TRACE("delimiter: 0x%x\n", *szString
);
2976 delimiter
= *szString
;
2979 while ((next_delim
= wcschr(p
, delimiter
)) != NULL
) {
2981 if (next_delim
+ 1 >= szString
+ len
)
2983 /* this may happen if delimiter == '\0' or if the last char is a
2984 * delimiter (then it is ignored like the native does) */
2988 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2989 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2990 infoPtr
->nNumStrings
++;
2996 LPWSTR p
= (LPWSTR
)lParam
;
3001 TRACE("adding string(s) from array\n");
3005 TRACE("len=%d %s\n", len
, debugstr_w(p
));
3006 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3007 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3008 infoPtr
->nNumStrings
++;
3015 TOOLBAR_CalcToolbar(infoPtr
);
3021 TOOLBAR_AddStringA (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
3023 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
3028 TRACE("%p, %Ix\n", hInstance
, lParam
);
3030 if (IS_INTRESOURCE(lParam
)) /* load from resources */
3031 return TOOLBAR_AddStringW(infoPtr
, hInstance
, lParam
);
3037 TRACE("adding string(s) from array\n");
3038 nIndex
= infoPtr
->nNumStrings
;
3041 TRACE("len=%d \"%s\"\n", len
, p
);
3043 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3044 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3045 infoPtr
->nNumStrings
++;
3051 TOOLBAR_CalcToolbar(infoPtr
);
3057 TOOLBAR_AutoSize (TOOLBAR_INFO
*infoPtr
)
3059 TRACE("auto sizing, style=%#lx\n", infoPtr
->dwStyle
);
3060 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3062 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3064 RECT window_rect
, client_rect
, parent_rect
, border
;
3065 UINT uPosFlags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
3069 parent
= GetParent (infoPtr
->hwndSelf
);
3071 if (!parent
|| !infoPtr
->bDoRedraw
)
3074 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3075 GetClientRect(infoPtr
->hwndSelf
, &client_rect
);
3076 border
= window_rect
;
3077 MapWindowPoints(0, infoPtr
->hwndSelf
, (POINT
*)&border
, 2);
3078 border
.right
-= border
.left
+ client_rect
.right
- client_rect
.left
;
3079 border
.bottom
-= border
.top
+ client_rect
.bottom
- client_rect
.top
;
3081 GetClientRect(parent
, &parent_rect
);
3083 x
= parent_rect
.left
;
3084 y
= parent_rect
.top
;
3086 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3087 cx
= parent_rect
.right
- parent_rect
.left
;
3089 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3091 MapWindowPoints( 0, parent
, (POINT
*)&window_rect
, 2 );
3092 y
= window_rect
.top
;
3094 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3095 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3097 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3098 uPosFlags
|= SWP_NOMOVE
;
3100 if (!(infoPtr
->dwStyle
& CCS_NOMOVEY
) && !(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3101 y
+= GetSystemMetrics(SM_CYEDGE
);
3106 cy
+= border
.bottom
;
3108 SetWindowPos(infoPtr
->hwndSelf
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3111 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
))
3113 TOOLBAR_LayoutToolbar(infoPtr
);
3114 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
3121 static inline LRESULT
3122 TOOLBAR_ButtonCount (const TOOLBAR_INFO
*infoPtr
)
3124 return infoPtr
->nNumButtons
;
3128 static inline LRESULT
3129 TOOLBAR_ButtonStructSize (TOOLBAR_INFO
*infoPtr
, DWORD Size
)
3131 infoPtr
->dwStructSize
= Size
;
3138 TOOLBAR_ChangeBitmap (TOOLBAR_INFO
*infoPtr
, INT Id
, INT Index
)
3140 TBUTTON_INFO
*btnPtr
;
3143 TRACE("button %d, iBitmap now %d\n", Id
, Index
);
3145 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3149 btnPtr
= &infoPtr
->buttons
[nIndex
];
3150 btnPtr
->iBitmap
= Index
;
3152 /* we HAVE to erase the background, the new bitmap could be */
3154 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3161 TOOLBAR_CheckButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3163 TBUTTON_INFO
*btnPtr
;
3166 BOOL bChecked
= FALSE
;
3168 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3170 TRACE("hwnd %p, btn index %d, lParam %Ix\n", infoPtr
->hwndSelf
, nIndex
, lParam
);
3175 btnPtr
= &infoPtr
->buttons
[nIndex
];
3177 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) != 0;
3179 if (!LOWORD(lParam
))
3180 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3182 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3184 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3185 if (nOldIndex
== nIndex
)
3187 if (nOldIndex
!= -1)
3188 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3190 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3193 if( bChecked
!= LOWORD(lParam
) )
3195 if (nOldIndex
!= -1)
3196 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3197 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3200 /* FIXME: Send a WM_NOTIFY?? */
3207 TOOLBAR_CommandToIndex (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3209 return TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3214 TOOLBAR_Customize (TOOLBAR_INFO
*infoPtr
)
3216 CUSTDLG_INFO custInfo
;
3220 custInfo
.tbInfo
= infoPtr
;
3221 custInfo
.tbHwnd
= infoPtr
->hwndSelf
;
3223 /* send TBN_BEGINADJUST notification */
3224 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3226 ret
= DialogBoxParamW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3227 infoPtr
->hwndSelf
, TOOLBAR_CustomizeDialogProc
, (LPARAM
)&custInfo
);
3229 /* send TBN_ENDADJUST notification */
3230 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3237 TOOLBAR_DeleteButton (TOOLBAR_INFO
*infoPtr
, INT nIndex
)
3240 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3242 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3245 memset(&nmtb
, 0, sizeof(nmtb
));
3246 nmtb
.iItem
= btnPtr
->idCommand
;
3247 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3248 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3249 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3250 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3251 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3252 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3253 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3255 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3257 infoPtr
->nHotItem
= -1;
3258 if (infoPtr
->nNumButtons
== 1) {
3259 TRACE(" simple delete\n");
3260 free_string( infoPtr
->buttons
);
3261 Free (infoPtr
->buttons
);
3262 infoPtr
->buttons
= NULL
;
3263 infoPtr
->nNumButtons
= 0;
3266 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3267 TRACE("complex delete [nIndex=%d]\n", nIndex
);
3269 infoPtr
->nNumButtons
--;
3270 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3272 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3273 nIndex
* sizeof(TBUTTON_INFO
));
3276 if (nIndex
< infoPtr
->nNumButtons
) {
3277 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3278 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3281 free_string( oldButtons
+ nIndex
);
3285 TOOLBAR_LayoutToolbar(infoPtr
);
3287 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3294 TOOLBAR_EnableButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3296 TBUTTON_INFO
*btnPtr
;
3300 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3302 TRACE("hwnd %p, btn id %d, lParam %Ix\n", infoPtr
->hwndSelf
, Id
, lParam
);
3307 btnPtr
= &infoPtr
->buttons
[nIndex
];
3309 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3311 /* update the toolbar button state */
3312 if(!LOWORD(lParam
)) {
3313 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3315 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3318 /* redraw the button only if the state of the button changed */
3319 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3320 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3326 static inline LRESULT
3327 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO
*infoPtr
)
3329 return infoPtr
->bAnchor
;
3334 TOOLBAR_GetBitmap (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3338 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3342 return infoPtr
->buttons
[nIndex
].iBitmap
;
3346 static inline LRESULT
3347 TOOLBAR_GetBitmapFlags (void)
3349 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3354 TOOLBAR_GetButton (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, TBBUTTON
*lpTbb
)
3356 TBUTTON_INFO
*btnPtr
;
3361 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3364 btnPtr
= &infoPtr
->buttons
[nIndex
];
3365 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3366 lpTbb
->idCommand
= btnPtr
->idCommand
;
3367 lpTbb
->fsState
= btnPtr
->fsState
;
3368 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3369 lpTbb
->bReserved
[0] = 0;
3370 lpTbb
->bReserved
[1] = 0;
3371 lpTbb
->dwData
= btnPtr
->dwData
;
3372 lpTbb
->iString
= btnPtr
->iString
;
3379 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO
*infoPtr
, INT Id
, LPTBBUTTONINFOW lpTbInfo
, BOOL bUnicode
)
3381 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3382 TBUTTON_INFO
*btnPtr
;
3385 if (lpTbInfo
== NULL
)
3388 /* MSDN documents an iImageLabel field added in Vista but it is not present in
3389 * the headers and tests shows that even with comctl 6 Vista accepts only the
3390 * original TBBUTTONINFO size
3392 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3394 WARN("Invalid button size\n");
3398 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lpTbInfo
->dwMask
& TBIF_BYINDEX
);
3402 btnPtr
= &infoPtr
->buttons
[nIndex
];
3403 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3404 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3405 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3406 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3407 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3408 lpTbInfo
->lParam
= btnPtr
->dwData
;
3409 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3410 /* tests show that for separators TBIF_SIZE returns not calculated width,
3411 but cx property, that differs from 0 only if application have
3412 specifically set it */
3413 lpTbInfo
->cx
= (btnPtr
->fsStyle
& BTNS_SEP
)
3414 ? btnPtr
->cx
: (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3415 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3416 lpTbInfo
->fsState
= btnPtr
->fsState
;
3417 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3418 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3419 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3420 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3421 can't use TOOLBAR_GetText here */
3422 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3423 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3425 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3427 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3428 } else if (!bUnicode
|| lpTbInfo
->pszText
)
3429 lpTbInfo
->pszText
[0] = '\0';
3435 static inline LRESULT
3436 TOOLBAR_GetButtonSize (const TOOLBAR_INFO
*infoPtr
)
3438 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3439 (WORD
)infoPtr
->nButtonHeight
);
3444 TOOLBAR_GetButtonText (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPWSTR lpStr
, BOOL isW
)
3450 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3454 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3460 ret
= lstrlenW (lpText
);
3461 if (lpStr
) lstrcpyW (lpStr
, lpText
);
3465 ret
= WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3466 (LPSTR
)lpStr
, lpStr
? 0x7fffffff : 0, NULL
, NULL
) - 1;
3472 TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3474 TRACE("hwnd %p, wParam %Id\n", infoPtr
->hwndSelf
, wParam
);
3475 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3476 return (LRESULT
)GETDISIMAGELIST(infoPtr
, wParam
);
3480 static inline LRESULT
3481 TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO
*infoPtr
)
3485 return infoPtr
->dwExStyle
;
3490 TOOLBAR_GetHotImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3492 TRACE("hwnd %p, wParam %Id\n", infoPtr
->hwndSelf
, wParam
);
3493 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3494 return (LRESULT
)GETHOTIMAGELIST(infoPtr
, wParam
);
3499 TOOLBAR_GetHotItem (const TOOLBAR_INFO
*infoPtr
)
3501 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || infoPtr
->hTheme
))
3504 if (infoPtr
->nHotItem
< 0)
3507 return (LRESULT
)infoPtr
->nHotItem
;
3512 TOOLBAR_GetDefImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3514 TRACE("hwnd %p, wParam %Id\n", infoPtr
->hwndSelf
, wParam
);
3515 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3516 return (LRESULT
) GETDEFIMAGELIST(infoPtr
, wParam
);
3521 TOOLBAR_GetInsertMark (const TOOLBAR_INFO
*infoPtr
, TBINSERTMARK
*lptbim
)
3523 TRACE("hwnd = %p, lptbim = %p\n", infoPtr
->hwndSelf
, lptbim
);
3525 *lptbim
= infoPtr
->tbim
;
3531 static inline LRESULT
3532 TOOLBAR_GetInsertMarkColor (const TOOLBAR_INFO
*infoPtr
)
3534 TRACE("hwnd = %p\n", infoPtr
->hwndSelf
);
3536 return (LRESULT
)infoPtr
->clrInsertMark
;
3541 TOOLBAR_GetItemRect (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, LPRECT lpRect
)
3543 TBUTTON_INFO
*btnPtr
;
3545 btnPtr
= &infoPtr
->buttons
[nIndex
];
3546 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3551 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3554 lpRect
->left
= btnPtr
->rect
.left
;
3555 lpRect
->right
= btnPtr
->rect
.right
;
3556 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3557 lpRect
->top
= btnPtr
->rect
.top
;
3564 TOOLBAR_GetMaxSize (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
3569 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3570 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3572 TRACE("maximum size %ld x %ld\n", infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3573 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3579 /* << TOOLBAR_GetObject >> */
3582 static inline LRESULT
3583 TOOLBAR_GetPadding (const TOOLBAR_INFO
*infoPtr
)
3585 return MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3590 TOOLBAR_GetRect (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPRECT lpRect
)
3592 TBUTTON_INFO
*btnPtr
;
3595 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3596 btnPtr
= &infoPtr
->buttons
[nIndex
];
3597 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3603 lpRect
->left
= btnPtr
->rect
.left
;
3604 lpRect
->right
= btnPtr
->rect
.right
;
3605 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3606 lpRect
->top
= btnPtr
->rect
.top
;
3612 static inline LRESULT
3613 TOOLBAR_GetRows (const TOOLBAR_INFO
*infoPtr
)
3615 return infoPtr
->nRows
;
3620 TOOLBAR_GetState (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3624 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3628 return infoPtr
->buttons
[nIndex
].fsState
;
3632 static inline LRESULT
3633 TOOLBAR_GetStyle (const TOOLBAR_INFO
*infoPtr
)
3635 return infoPtr
->dwStyle
;
3639 static inline LRESULT
3640 TOOLBAR_GetTextRows (const TOOLBAR_INFO
*infoPtr
)
3642 return infoPtr
->nMaxTextRows
;
3647 TOOLBAR_GetToolTips (TOOLBAR_INFO
*infoPtr
)
3649 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3650 TOOLBAR_TooltipCreateControl(infoPtr
);
3651 return (LRESULT
)infoPtr
->hwndToolTip
;
3656 TOOLBAR_GetUnicodeFormat (const TOOLBAR_INFO
*infoPtr
)
3658 TRACE("%s hwnd=%p\n",
3659 infoPtr
->bUnicode
? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
3661 return infoPtr
->bUnicode
;
3665 static inline LRESULT
3666 TOOLBAR_GetVersion (const TOOLBAR_INFO
*infoPtr
)
3668 return infoPtr
->iVersion
;
3673 TOOLBAR_HideButton (TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fHide
)
3675 TBUTTON_INFO
*btnPtr
;
3681 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3685 btnPtr
= &infoPtr
->buttons
[nIndex
];
3686 oldState
= btnPtr
->fsState
;
3689 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3691 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3693 if (oldState
!= btnPtr
->fsState
) {
3694 TOOLBAR_LayoutToolbar (infoPtr
);
3695 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3702 static inline LRESULT
3703 TOOLBAR_HitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
* lpPt
)
3705 return TOOLBAR_InternalHitTest (infoPtr
, lpPt
, NULL
);
3710 TOOLBAR_Indeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fIndeterminate
)
3712 TBUTTON_INFO
*btnPtr
;
3716 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3720 btnPtr
= &infoPtr
->buttons
[nIndex
];
3721 oldState
= btnPtr
->fsState
;
3724 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3726 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3728 if(oldState
!= btnPtr
->fsState
)
3729 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3736 TOOLBAR_InsertButtonT(TOOLBAR_INFO
*infoPtr
, INT nIndex
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
3742 /* EPP: this seems to be an undocumented call (from my IE4)
3743 * I assume in that case that:
3744 * - index of insertion is at the end of existing buttons
3745 * I only see this happen with nIndex == -1, but it could have a special
3746 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3748 nIndex
= infoPtr
->nNumButtons
;
3750 } else if (nIndex
< 0)
3753 TRACE("inserting button index=%d\n", nIndex
);
3754 if (nIndex
> infoPtr
->nNumButtons
) {
3755 nIndex
= infoPtr
->nNumButtons
;
3756 TRACE("adjust index=%d\n", nIndex
);
3759 return TOOLBAR_InternalInsertButtonsT(infoPtr
, nIndex
, 1, lpTbb
, fUnicode
);
3762 /* << TOOLBAR_InsertMarkHitTest >> */
3766 TOOLBAR_IsButtonChecked (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3770 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3774 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3779 TOOLBAR_IsButtonEnabled (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3783 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3787 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3792 TOOLBAR_IsButtonHidden (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3796 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3800 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3805 TOOLBAR_IsButtonHighlighted (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3809 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3813 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3818 TOOLBAR_IsButtonIndeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3822 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3826 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3831 TOOLBAR_IsButtonPressed (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3835 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3839 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3844 TOOLBAR_LoadImages (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HINSTANCE hInstance
)
3847 tbab
.hInst
= hInstance
;
3850 TRACE("hwnd = %p, hInst = %p, nID = %Iu\n", infoPtr
->hwndSelf
, tbab
.hInst
, tbab
.nID
);
3852 return TOOLBAR_AddBitmap(infoPtr
, 0, &tbab
);
3857 TOOLBAR_MapAccelerator (const TOOLBAR_INFO
*infoPtr
, WCHAR wAccel
, UINT
*pIDButton
)
3859 WCHAR wszAccel
[] = {'&',wAccel
,0};
3862 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3863 infoPtr
->hwndSelf
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3865 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3867 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3868 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3869 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3871 int iLen
= lstrlenW(wszAccel
);
3872 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3879 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3884 if (!wcsnicmp(lpszStr
, wszAccel
, iLen
))
3886 *pIDButton
= btnPtr
->idCommand
;
3898 TOOLBAR_MarkButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fMark
)
3902 TBUTTON_INFO
*btnPtr
;
3904 TRACE("hwnd = %p, Id = %d, fMark = 0%d\n", infoPtr
->hwndSelf
, Id
, fMark
);
3906 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3910 btnPtr
= &infoPtr
->buttons
[nIndex
];
3911 oldState
= btnPtr
->fsState
;
3914 btnPtr
->fsState
|= TBSTATE_MARKED
;
3916 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
3918 if(oldState
!= btnPtr
->fsState
)
3919 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3925 /* fixes up an index of a button affected by a move */
3926 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
3930 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
3932 else if (*pIndex
== nIndex
)
3933 *pIndex
= nMoveIndex
;
3937 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
3939 else if (*pIndex
== nIndex
)
3940 *pIndex
= nMoveIndex
;
3946 TOOLBAR_MoveButton (TOOLBAR_INFO
*infoPtr
, INT Id
, INT nMoveIndex
)
3950 TBUTTON_INFO button
;
3952 TRACE("hwnd=%p, Id=%d, nMoveIndex=%d\n", infoPtr
->hwndSelf
, Id
, nMoveIndex
);
3954 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, TRUE
);
3955 if ((nIndex
== -1) || (nMoveIndex
< 0))
3958 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
3959 nMoveIndex
= infoPtr
->nNumButtons
- 1;
3961 button
= infoPtr
->buttons
[nIndex
];
3963 /* move button right */
3964 if (nIndex
< nMoveIndex
)
3966 nCount
= nMoveIndex
- nIndex
;
3967 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
3968 infoPtr
->buttons
[nMoveIndex
] = button
;
3970 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
3971 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
3972 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
3973 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
3975 else if (nIndex
> nMoveIndex
) /* move button left */
3977 nCount
= nIndex
- nMoveIndex
;
3978 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
3979 infoPtr
->buttons
[nMoveIndex
] = button
;
3981 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
3982 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
3983 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
3984 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
3987 TOOLBAR_LayoutToolbar(infoPtr
);
3988 TOOLBAR_AutoSize(infoPtr
);
3989 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
3996 TOOLBAR_PressButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fPress
)
3998 TBUTTON_INFO
*btnPtr
;
4002 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
4006 btnPtr
= &infoPtr
->buttons
[nIndex
];
4007 oldState
= btnPtr
->fsState
;
4010 btnPtr
->fsState
|= TBSTATE_PRESSED
;
4012 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
4014 if(oldState
!= btnPtr
->fsState
)
4015 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4020 /* FIXME: there might still be some confusion her between number of buttons
4021 * and number of bitmaps */
4023 TOOLBAR_ReplaceBitmap (TOOLBAR_INFO
*infoPtr
, const TBREPLACEBITMAP
*lpReplace
)
4026 int i
= 0, nOldButtons
= 0, pos
= 0;
4027 int nOldBitmaps
, nNewBitmaps
= 0;
4028 HIMAGELIST himlDef
= 0;
4030 TRACE("hInstOld %p nIDOld %Ix hInstNew %p nIDNew %Ix nButtons %x\n",
4031 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
4032 lpReplace
->nButtons
);
4034 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4036 FIXME("changing standard bitmaps not implemented\n");
4039 else if (lpReplace
->hInstOld
!= 0 && lpReplace
->hInstOld
!= lpReplace
->hInstNew
)
4040 FIXME("resources not in the current module not implemented\n");
4042 TRACE("To be replaced hInstOld %p nIDOld %Ix\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4043 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4044 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4045 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4046 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4048 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4049 nOldButtons
= tbi
->nButtons
;
4050 tbi
->nButtons
= lpReplace
->nButtons
;
4051 tbi
->hInst
= lpReplace
->hInstNew
;
4052 tbi
->nID
= lpReplace
->nIDNew
;
4053 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4056 pos
+= tbi
->nButtons
;
4059 if (nOldButtons
== 0)
4061 WARN("No hinst/bitmap found! hInst %p nID %Ix\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4065 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4068 if (lpReplace
->hInstNew
)
4069 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4071 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4073 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4074 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4076 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4078 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4079 ImageList_Remove(himlDef
, i
);
4083 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4084 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4085 DeleteObject(hBitmap
);
4088 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4090 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4091 pos
, nOldBitmaps
, nNewBitmaps
);
4093 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4098 /* helper for TOOLBAR_SaveRestoreW */
4100 TOOLBAR_Save(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*params
)
4104 BOOL alloced
= FALSE
;
4107 TRACE( "save to %s %s\n", debugstr_w(params
->pszSubKey
), debugstr_w(params
->pszValueName
) );
4109 memset( &save
, 0, sizeof(save
) );
4110 save
.cbData
= infoPtr
->nNumButtons
* sizeof(DWORD
);
4112 save
.cButtons
= infoPtr
->nNumButtons
;
4113 save
.tbButton
.idCommand
= -1;
4114 TOOLBAR_SendNotify( &save
.hdr
, infoPtr
, TBN_SAVE
);
4118 save
.pData
= Alloc( save
.cbData
);
4119 if (!save
.pData
) return FALSE
;
4122 if (!save
.pCurrent
) save
.pCurrent
= save
.pData
;
4124 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4127 save
.tbButton
.iBitmap
= infoPtr
->buttons
[i
].iBitmap
;
4128 save
.tbButton
.idCommand
= infoPtr
->buttons
[i
].idCommand
;
4129 save
.tbButton
.fsState
= infoPtr
->buttons
[i
].fsState
;
4130 save
.tbButton
.fsStyle
= infoPtr
->buttons
[i
].fsStyle
;
4131 memset( save
.tbButton
.bReserved
, 0, sizeof(save
.tbButton
.bReserved
) );
4132 save
.tbButton
.dwData
= infoPtr
->buttons
[i
].dwData
;
4133 save
.tbButton
.iString
= infoPtr
->buttons
[i
].iString
;
4135 *save
.pCurrent
++ = save
.tbButton
.idCommand
;
4137 TOOLBAR_SendNotify( &save
.hdr
, infoPtr
, TBN_SAVE
);
4140 ret
= RegCreateKeyW( params
->hkr
, params
->pszSubKey
, &key
);
4141 if (ret
== ERROR_SUCCESS
)
4143 ret
= RegSetValueExW( key
, params
->pszValueName
, 0, REG_BINARY
, (BYTE
*)save
.pData
, save
.cbData
);
4147 if (alloced
) Free( save
.pData
);
4152 /* helper for TOOLBAR_Restore */
4154 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4158 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4160 free_string( infoPtr
->buttons
+ i
);
4161 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4164 Free(infoPtr
->buttons
);
4165 infoPtr
->buttons
= NULL
;
4166 infoPtr
->nNumButtons
= 0;
4170 /* helper for TOOLBAR_SaveRestoreW */
4172 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4182 /* restore toolbar information */
4183 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4184 debugstr_w(lpSave
->pszValueName
));
4186 memset(&nmtbr
, 0, sizeof(nmtbr
));
4188 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4189 KEY_QUERY_VALUE
, &hkey
);
4191 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4193 if (!res
&& dwType
!= REG_BINARY
)
4194 res
= ERROR_FILE_NOT_FOUND
;
4197 nmtbr
.pData
= Alloc(dwSize
);
4198 nmtbr
.cbData
= dwSize
;
4199 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4202 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4203 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4206 nmtbr
.pCurrent
= nmtbr
.pData
;
4208 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4209 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4211 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4213 INT i
, count
= nmtbr
.cButtons
;
4215 /* remove all existing buttons as this function is designed to
4216 * restore the toolbar to a previously saved state */
4217 TOOLBAR_DeleteAllButtons(infoPtr
);
4219 for (i
= 0; i
< count
; i
++)
4222 nmtbr
.tbButton
.iBitmap
= -1;
4223 nmtbr
.tbButton
.fsState
= 0;
4224 nmtbr
.tbButton
.fsStyle
= 0;
4225 nmtbr
.tbButton
.dwData
= 0;
4226 nmtbr
.tbButton
.iString
= 0;
4228 if (*nmtbr
.pCurrent
& 0x80000000)
4231 nmtbr
.tbButton
.iBitmap
= SEPARATOR_WIDTH
;
4232 nmtbr
.tbButton
.idCommand
= 0;
4233 nmtbr
.tbButton
.fsStyle
= BTNS_SEP
;
4234 if (*nmtbr
.pCurrent
!= (DWORD
)-1)
4235 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4238 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4242 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4244 /* All returned ptrs and -1 are ignored */
4245 if (!IS_INTRESOURCE(nmtbr
.tbButton
.iString
))
4246 nmtbr
.tbButton
.iString
= 0;
4248 TOOLBAR_InsertButtonT(infoPtr
, -1, &nmtbr
.tbButton
, TRUE
);
4251 TOOLBAR_SendNotify( &hdr
, infoPtr
, TBN_BEGINADJUST
);
4257 UINT code
= infoPtr
->bUnicode
? TBN_GETBUTTONINFOW
: TBN_GETBUTTONINFOA
;
4260 memset( &tb
, 0, sizeof(tb
) );
4262 tb
.cchText
= ARRAY_SIZE(buf
);
4265 /* Use the same struct for both A and W versions since the layout is the same. */
4266 if (!TOOLBAR_SendNotify( &tb
.hdr
, infoPtr
, code
))
4269 idx
= TOOLBAR_GetButtonIndex( infoPtr
, tb
.tbButton
.idCommand
, FALSE
);
4270 if (idx
== -1) continue;
4272 /* tb.pszText is ignored - the string comes from tb.tbButton.iString, which may
4273 be an index or a ptr. Either way it is simply copied. There is no api to change
4274 the string index, so we set it manually. The other properties can be set with SetButtonInfo. */
4275 free_string( infoPtr
->buttons
+ idx
);
4276 infoPtr
->buttons
[idx
].iString
= tb
.tbButton
.iString
;
4278 memset( &bi
, 0, sizeof(bi
) );
4279 bi
.cbSize
= sizeof(bi
);
4280 bi
.dwMask
= TBIF_IMAGE
| TBIF_STATE
| TBIF_STYLE
| TBIF_LPARAM
;
4281 bi
.iImage
= tb
.tbButton
.iBitmap
;
4282 bi
.fsState
= tb
.tbButton
.fsState
;
4283 bi
.fsStyle
= tb
.tbButton
.fsStyle
;
4284 bi
.lParam
= tb
.tbButton
.dwData
;
4286 TOOLBAR_SetButtonInfo( infoPtr
, tb
.tbButton
.idCommand
, &bi
, TRUE
);
4288 TOOLBAR_SendNotify( &hdr
, infoPtr
, TBN_ENDADJUST
);
4290 /* remove all uninitialised buttons
4291 * note: loop backwards to avoid having to fixup i on a
4293 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4294 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4295 TOOLBAR_DeleteButton(infoPtr
, i
);
4297 /* only indicate success if at least one button survived */
4298 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4309 TOOLBAR_SaveRestoreW (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4311 if (lpSave
== NULL
) return 0;
4314 return TOOLBAR_Save(infoPtr
, lpSave
);
4316 return TOOLBAR_Restore(infoPtr
, lpSave
);
4321 TOOLBAR_SaveRestoreA (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4323 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4324 TBSAVEPARAMSW SaveW
;
4328 if (lpSave
== NULL
) return 0;
4330 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4331 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4332 if (!pszSubKey
) goto exit
;
4333 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4335 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4336 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4337 if (!pszValueName
) goto exit
;
4338 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4340 SaveW
.pszValueName
= pszValueName
;
4341 SaveW
.pszSubKey
= pszSubKey
;
4342 SaveW
.hkr
= lpSave
->hkr
;
4343 result
= TOOLBAR_SaveRestoreW(infoPtr
, wParam
, &SaveW
);
4346 Free (pszValueName
);
4354 TOOLBAR_SetAnchorHighlight (TOOLBAR_INFO
*infoPtr
, BOOL bAnchor
)
4356 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4358 TRACE("hwnd=%p, bAnchor = %s\n", infoPtr
->hwndSelf
, bAnchor
? "TRUE" : "FALSE");
4360 infoPtr
->bAnchor
= bAnchor
;
4362 /* Native does not remove the hot effect from an already hot button */
4364 return (LRESULT
)bOldAnchor
;
4369 TOOLBAR_SetBitmapSize (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4371 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4372 short width
= (short)LOWORD(lParam
);
4373 short height
= (short)HIWORD(lParam
);
4375 TRACE("hwnd %p, wParam %Id, size %d x %d\n", infoPtr
->hwndSelf
, wParam
, width
, height
);
4378 FIXME("wParam is %Id. Perhaps image list index?\n", wParam
);
4380 /* 0 width or height is changed to 1 */
4386 if (infoPtr
->nNumButtons
> 0)
4387 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4388 infoPtr
->nNumButtons
,
4389 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
, width
, height
);
4391 if (width
< -1 || height
< -1)
4393 /* Windows destroys the imagelist and seems to actually use negative
4394 * values to compute button sizes */
4395 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width
, height
);
4399 /* width or height of -1 means no change */
4401 infoPtr
->nBitmapWidth
= width
;
4403 infoPtr
->nBitmapHeight
= height
;
4405 if ((himlDef
== infoPtr
->himlInt
) &&
4406 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4408 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4409 infoPtr
->nBitmapHeight
);
4412 TOOLBAR_CalcToolbar(infoPtr
);
4413 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4419 TOOLBAR_SetButtonInfo (TOOLBAR_INFO
*infoPtr
, INT Id
,
4420 const TBBUTTONINFOW
*lptbbi
, BOOL isW
)
4422 TBUTTON_INFO
*btnPtr
;
4428 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4431 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lptbbi
->dwMask
& TBIF_BYINDEX
);
4435 btnPtr
= &infoPtr
->buttons
[nIndex
];
4436 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4437 btnPtr
->idCommand
= lptbbi
->idCommand
;
4438 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4439 btnPtr
->iBitmap
= lptbbi
->iImage
;
4440 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4441 btnPtr
->dwData
= lptbbi
->lParam
;
4442 if (lptbbi
->dwMask
& TBIF_SIZE
)
4443 btnPtr
->cx
= lptbbi
->cx
;
4444 if (lptbbi
->dwMask
& TBIF_STATE
)
4445 btnPtr
->fsState
= lptbbi
->fsState
;
4446 if (lptbbi
->dwMask
& TBIF_STYLE
)
4447 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4449 if (lptbbi
->dwMask
& TBIF_TEXT
)
4450 set_stringT( btnPtr
, lptbbi
->pszText
, isW
);
4452 /* save the button rect to see if we need to redraw the whole toolbar */
4453 oldBtnRect
= btnPtr
->rect
;
4454 TOOLBAR_LayoutToolbar(infoPtr
);
4456 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4457 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4459 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4466 TOOLBAR_SetButtonSize (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4468 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4469 int top
= default_top_margin(infoPtr
);
4471 if ((cx
< 0) || (cy
< 0))
4473 ERR("invalid parameter %#Ix\n", lParam
);
4477 TRACE("%p, cx = %d, cy = %d\n", infoPtr
->hwndSelf
, cx
, cy
);
4479 /* The documentation claims you can only change the button size before
4480 * any button has been added. But this is wrong.
4481 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4482 * it to the toolbar, and it checks that the return value is nonzero - mjm
4483 * Further testing shows that we must actually perform the change too.
4486 * The documentation also does not mention that if 0 is supplied for
4487 * either size, the system changes it to the default of 24 wide and
4488 * 22 high. Demonstrated in ControlSpy Toolbar. GLA 3/02
4490 if (cx
== 0) cx
= 24;
4491 if (cy
== 0) cy
= 22;
4493 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4494 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4496 if (cx
!= infoPtr
->nButtonWidth
|| cy
!= infoPtr
->nButtonHeight
||
4497 top
!= infoPtr
->iTopMargin
)
4499 infoPtr
->nButtonWidth
= cx
;
4500 infoPtr
->nButtonHeight
= cy
;
4501 infoPtr
->iTopMargin
= top
;
4503 TOOLBAR_LayoutToolbar( infoPtr
);
4504 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
4511 TOOLBAR_SetButtonWidth (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4513 /* if setting to current values, ignore */
4514 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4515 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4516 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4517 infoPtr
->cxMin
, infoPtr
->cxMax
);
4521 /* save new values */
4522 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4523 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4525 /* otherwise we need to recalc the toolbar and in some cases
4526 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4527 which doesn't actually draw - GA). */
4528 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4529 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4531 TOOLBAR_CalcToolbar (infoPtr
);
4533 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
4540 TOOLBAR_SetCmdId (TOOLBAR_INFO
*infoPtr
, INT nIndex
, INT nId
)
4542 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4545 infoPtr
->buttons
[nIndex
].idCommand
= nId
;
4547 if (infoPtr
->hwndToolTip
) {
4549 FIXME("change tool tip\n");
4558 TOOLBAR_SetDisabledImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4560 HIMAGELIST himlTemp
;
4563 if (infoPtr
->iVersion
>= 5)
4566 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4567 &infoPtr
->cimlDis
, himl
, id
);
4569 /* FIXME: redraw ? */
4571 return (LRESULT
)himlTemp
;
4576 TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD flags
)
4580 TRACE("hwnd = %p, mask = %#lx, flags %#lx\n", infoPtr
->hwndSelf
, mask
, flags
);
4582 old_flags
= infoPtr
->dwDTFlags
;
4583 infoPtr
->dwDTFlags
= (old_flags
& ~mask
) | (flags
& mask
);
4585 return (LRESULT
)old_flags
;
4588 /* This function differs a bit from what MSDN says it does:
4589 * 1. lParam contains extended style flags to OR with current style
4590 * (MSDN isn't clear on the OR bit)
4591 * 2. wParam appears to contain extended style flags to be reset
4592 * (MSDN says that this parameter is reserved)
4595 TOOLBAR_SetExtendedStyle (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD style
)
4597 DWORD old_style
= infoPtr
->dwExStyle
;
4599 TRACE("mask %#lx, style %#lx\n", mask
, style
);
4602 infoPtr
->dwExStyle
= (old_style
& ~mask
) | (style
& mask
);
4604 infoPtr
->dwExStyle
= style
;
4606 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4607 FIXME("Unknown Toolbar Extended Style %#lx. Please report.\n", (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4609 if ((old_style
^ infoPtr
->dwExStyle
) & TBSTYLE_EX_MIXEDBUTTONS
)
4610 TOOLBAR_CalcToolbar(infoPtr
);
4612 TOOLBAR_LayoutToolbar(infoPtr
);
4614 TOOLBAR_AutoSize(infoPtr
);
4615 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4622 TOOLBAR_SetHotImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4624 HIMAGELIST himlTemp
;
4627 if (infoPtr
->iVersion
>= 5)
4630 TRACE("hwnd = %p, himl = %p, id = %d\n", infoPtr
->hwndSelf
, himl
, id
);
4632 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4633 &infoPtr
->cimlHot
, himl
, id
);
4635 /* FIXME: redraw ? */
4637 return (LRESULT
)himlTemp
;
4641 /* Makes previous hot button no longer hot, makes the specified
4642 * button hot and sends appropriate notifications. dwReason is one or
4643 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4644 * NOTE 1: this function does not validate nHit
4645 * NOTE 2: the name of this function is completely made up and
4646 * not based on any documentation from Microsoft. */
4648 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4650 if (infoPtr
->nHotItem
!= nHit
)
4652 NMTBHOTITEM nmhotitem
;
4653 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4655 nmhotitem
.dwFlags
= dwReason
;
4656 if(infoPtr
->nHotItem
>= 0)
4658 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4659 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4663 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4664 nmhotitem
.idOld
= 0;
4669 btnPtr
= &infoPtr
->buttons
[nHit
];
4670 nmhotitem
.idNew
= btnPtr
->idCommand
;
4674 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4675 nmhotitem
.idNew
= 0;
4678 /* now change the hot and invalidate the old and new buttons - if the
4680 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4683 oldBtnPtr
->bHot
= FALSE
;
4684 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4686 /* setting disabled buttons as hot fails even if the notify contains the button id */
4687 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4688 btnPtr
->bHot
= TRUE
;
4689 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4690 infoPtr
->nHotItem
= nHit
;
4693 infoPtr
->nHotItem
= -1;
4699 TOOLBAR_SetHotItem (TOOLBAR_INFO
*infoPtr
, INT nHotItem
)
4701 INT nOldHotItem
= infoPtr
->nHotItem
;
4703 TRACE("hwnd = %p, nHotItem = %d\n", infoPtr
->hwndSelf
, nHotItem
);
4705 if (nHotItem
>= infoPtr
->nNumButtons
)
4706 return infoPtr
->nHotItem
;
4711 /* NOTE: an application can still remove the hot item even if anchor
4712 * highlighting is enabled */
4714 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, HICF_OTHER
);
4716 if (nOldHotItem
< 0)
4719 return (LRESULT
)nOldHotItem
;
4724 TOOLBAR_SetImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4726 HIMAGELIST himlTemp
;
4727 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4728 INT oldBitmapWidth
= infoPtr
->nBitmapWidth
;
4729 INT oldBitmapHeight
= infoPtr
->nBitmapHeight
;
4732 if (infoPtr
->iVersion
>= 5)
4735 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4736 &infoPtr
->cimlDef
, himl
, id
);
4738 infoPtr
->nNumBitmaps
= 0;
4739 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4740 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4742 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4743 &infoPtr
->nBitmapHeight
))
4745 infoPtr
->nBitmapWidth
= 1;
4746 infoPtr
->nBitmapHeight
= 1;
4748 if ((oldBitmapWidth
!= infoPtr
->nBitmapWidth
) || (oldBitmapHeight
!= infoPtr
->nBitmapHeight
))
4750 TOOLBAR_CalcToolbar(infoPtr
);
4751 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4752 TOOLBAR_SetButtonSize(infoPtr
, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4755 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4756 infoPtr
->hwndSelf
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4757 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4759 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4761 return (LRESULT
)himlTemp
;
4766 TOOLBAR_SetIndent (TOOLBAR_INFO
*infoPtr
, INT nIndent
)
4768 infoPtr
->nIndent
= nIndent
;
4772 /* process only on indent changing */
4773 if(infoPtr
->nIndent
!= nIndent
)
4775 infoPtr
->nIndent
= nIndent
;
4776 TOOLBAR_CalcToolbar (infoPtr
);
4777 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4785 TOOLBAR_SetInsertMark (TOOLBAR_INFO
*infoPtr
, const TBINSERTMARK
*lptbim
)
4787 TRACE("hwnd = %p, lptbim = { %d, %#lx}\n", infoPtr
->hwndSelf
, lptbim
->iButton
, lptbim
->dwFlags
);
4789 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4791 FIXME("Unrecognized flag(s): %#lx\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4795 if ((lptbim
->iButton
== -1) ||
4796 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4797 (lptbim
->iButton
>= 0)))
4799 infoPtr
->tbim
= *lptbim
;
4800 /* FIXME: don't need to update entire toolbar */
4801 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4804 ERR("Invalid button index %d\n", lptbim
->iButton
);
4811 TOOLBAR_SetInsertMarkColor (TOOLBAR_INFO
*infoPtr
, COLORREF clr
)
4813 infoPtr
->clrInsertMark
= clr
;
4815 /* FIXME: don't need to update entire toolbar */
4816 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4823 TOOLBAR_SetMaxTextRows (TOOLBAR_INFO
*infoPtr
, INT nMaxRows
)
4825 infoPtr
->nMaxTextRows
= nMaxRows
;
4827 TOOLBAR_CalcToolbar(infoPtr
);
4832 /* MSDN gives slightly wrong info on padding.
4833 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4834 * 2. It is not used to create a blank area between the edge of the button
4835 * and the text or image if TBSTYLE_LIST is set. It is used to control
4836 * the gap between the image and text.
4837 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4838 * to control the bottom and right borders [with the border being
4839 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4840 * is shared evenly on both sides of the button.
4841 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4844 TOOLBAR_SetPadding (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4848 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4849 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4850 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4851 TRACE("cx %ld, cy %ld\n", infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4852 return (LRESULT
) oldPad
;
4857 TOOLBAR_SetParent (TOOLBAR_INFO
*infoPtr
, HWND hParent
)
4863 hwndOldNotify
= infoPtr
->hwndNotify
;
4864 infoPtr
->hwndNotify
= hParent
;
4866 return (LRESULT
)hwndOldNotify
;
4871 TOOLBAR_SetRows (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPRECT lprc
)
4873 int rows
= LOWORD(wParam
);
4874 BOOL bLarger
= HIWORD(wParam
);
4878 TRACE("Setting rows to %d (%d)\n", rows
, bLarger
);
4880 if(infoPtr
->nRows
!= rows
)
4882 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
;
4883 int curColumn
= 0; /* Current column */
4884 int curRow
= 0; /* Current row */
4885 int hidden
= 0; /* Number of hidden buttons */
4886 int seps
= 0; /* Number of separators */
4887 int idealWrap
= 0; /* Ideal wrap point */
4892 Calculate new size and wrap points - Under windows, setrows will
4893 change the dimensions if needed to show the number of requested
4894 rows (if CCS_NORESIZE is set), or will take up the whole window
4895 (if no CCS_NORESIZE).
4897 Basic algorithm - If N buttons, and y rows requested, each row
4898 contains N/y buttons.
4900 FIXME: Handling of separators not obvious from testing results
4901 FIXME: Take width of window into account?
4904 /* Loop through the buttons one by one counting key items */
4905 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4907 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
4908 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4910 else if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
4914 /* FIXME: Separators make this quite complex */
4915 if (seps
) FIXME("Separators unhandled\n");
4917 /* Round up so more per line, i.e., less rows */
4918 idealWrap
= (infoPtr
->nNumButtons
- hidden
+ (rows
-1)) / (rows
? rows
: 1);
4920 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4921 achieve the requested number of rows. */
4922 if (bLarger
&& idealWrap
> 1)
4924 int resRows
= (infoPtr
->nNumButtons
+ (idealWrap
-1)) / idealWrap
;
4925 int moreRows
= (infoPtr
->nNumButtons
+ (idealWrap
-2)) / (idealWrap
-1);
4927 if (resRows
< rows
&& moreRows
> rows
)
4930 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap
);
4934 curColumn
= curRow
= 0;
4936 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap
,
4937 infoPtr
->nNumButtons
, hidden
, rows
);
4939 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4941 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4944 /* Step on, wrap if necessary or flag next to wrap */
4953 if (curColumn
> (idealWrap
-1)) {
4955 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
4959 TRACE("Result - %d rows\n", curRow
+ 1);
4961 /* recalculate toolbar */
4962 TOOLBAR_CalcToolbar (infoPtr
);
4964 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
4965 if NORESIZE is NOT set, then the toolbar will always be resized to
4966 take up the whole window. With it set, sizing needs to be manual. */
4967 if (infoPtr
->dwStyle
& CCS_NORESIZE
) {
4968 SetWindowPos(infoPtr
->hwndSelf
, NULL
, 0, 0,
4969 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
4970 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
,
4971 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
4974 /* repaint toolbar */
4975 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4978 /* return bounding rectangle */
4980 lprc
->left
= infoPtr
->rcBound
.left
;
4981 lprc
->right
= infoPtr
->rcBound
.right
;
4982 lprc
->top
= infoPtr
->rcBound
.top
;
4983 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
4991 TOOLBAR_SetState (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
4993 TBUTTON_INFO
*btnPtr
;
4996 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
5000 btnPtr
= &infoPtr
->buttons
[nIndex
];
5002 /* if hidden state has changed the invalidate entire window and recalc */
5003 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
5004 btnPtr
->fsState
= LOWORD(lParam
);
5005 TOOLBAR_CalcToolbar (infoPtr
);
5006 InvalidateRect(infoPtr
->hwndSelf
, 0, TRUE
);
5010 /* process state changing if current state doesn't match new state */
5011 if(btnPtr
->fsState
!= LOWORD(lParam
))
5013 btnPtr
->fsState
= LOWORD(lParam
);
5014 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5020 static inline void unwrap(TOOLBAR_INFO
*info
)
5024 for (i
= 0; i
< info
->nNumButtons
; i
++)
5025 info
->buttons
[i
].fsState
&= ~TBSTATE_WRAP
;
5029 TOOLBAR_SetStyle (TOOLBAR_INFO
*infoPtr
, DWORD style
)
5031 DWORD dwOldStyle
= infoPtr
->dwStyle
;
5033 TRACE("new style %#lx\n", style
);
5035 if (style
& TBSTYLE_LIST
)
5036 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
5038 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
5040 infoPtr
->dwStyle
= style
;
5041 TOOLBAR_CheckStyle(infoPtr
);
5043 if ((dwOldStyle
^ style
) & TBSTYLE_WRAPABLE
)
5045 if (dwOldStyle
& TBSTYLE_WRAPABLE
)
5047 TOOLBAR_CalcToolbar(infoPtr
);
5049 else if ((dwOldStyle
^ style
) & CCS_VERT
)
5050 TOOLBAR_LayoutToolbar(infoPtr
);
5052 /* only resize if one of the CCS_* styles was changed */
5053 if ((dwOldStyle
^ style
) & COMMON_STYLES
)
5055 TOOLBAR_AutoSize(infoPtr
);
5056 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5063 static inline LRESULT
5064 TOOLBAR_SetToolTips (TOOLBAR_INFO
*infoPtr
, HWND hwndTooltip
)
5066 TRACE("hwnd=%p, hwndTooltip=%p\n", infoPtr
->hwndSelf
, hwndTooltip
);
5068 infoPtr
->hwndToolTip
= hwndTooltip
;
5074 TOOLBAR_SetUnicodeFormat (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
5078 TRACE("%s hwnd=%p\n",
5079 ((BOOL
)wParam
) ? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
5081 bTemp
= infoPtr
->bUnicode
;
5082 infoPtr
->bUnicode
= (BOOL
)wParam
;
5089 TOOLBAR_GetColorScheme (const TOOLBAR_INFO
*infoPtr
, LPCOLORSCHEME lParam
)
5091 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
5092 comctl32_color
.clrBtnHighlight
:
5093 infoPtr
->clrBtnHighlight
;
5094 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
5095 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
5101 TOOLBAR_SetColorScheme (TOOLBAR_INFO
*infoPtr
, const COLORSCHEME
*lParam
)
5103 TRACE("new colors Hl=%#lx Shd=%#lx, old colors Hl=%#lx Shd=%#lx\n",
5104 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
5105 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
5107 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
5108 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
5109 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5115 TOOLBAR_SetVersion (TOOLBAR_INFO
*infoPtr
, INT iVersion
)
5117 INT iOldVersion
= infoPtr
->iVersion
;
5119 infoPtr
->iVersion
= iVersion
;
5121 if (infoPtr
->iVersion
>= 5)
5122 TOOLBAR_SetUnicodeFormat(infoPtr
, TRUE
);
5129 TOOLBAR_GetStringA (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPSTR str
)
5131 WORD iString
= HIWORD(wParam
);
5132 WORD buffersize
= LOWORD(wParam
);
5135 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, buffersize
, str
);
5137 if (iString
< infoPtr
->nNumStrings
)
5139 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
5142 TRACE("returning %s\n", debugstr_a(str
));
5145 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5152 TOOLBAR_GetStringW (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPWSTR str
)
5154 WORD iString
= HIWORD(wParam
);
5155 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5158 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, LOWORD(wParam
), str
);
5160 if (iString
< infoPtr
->nNumStrings
)
5162 len
= min(len
, lstrlenW(infoPtr
->strings
[iString
]));
5163 ret
= (len
+1)*sizeof(WCHAR
);
5166 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5171 TRACE("returning %s\n", debugstr_w(str
));
5174 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5179 static LRESULT
TOOLBAR_SetBoundingSize(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5181 SIZE
* pSize
= (SIZE
*)lParam
;
5182 FIXME("hwnd=%p, wParam=%Ix, size.cx=%ld, size.cy=%ld stub\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5186 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5187 * caller to specify a reason why the hot item changed (rather than just the
5188 * HICF_OTHER that TB_SETHOTITEM sends). */
5190 TOOLBAR_SetHotItem2 (TOOLBAR_INFO
*infoPtr
, INT nHotItem
, LPARAM lParam
)
5192 INT nOldHotItem
= infoPtr
->nHotItem
;
5194 TRACE("old item %d, new item %d, flags %Ix\n", nOldHotItem
, nHotItem
, lParam
);
5196 if (nHotItem
< 0 || nHotItem
> infoPtr
->nNumButtons
)
5199 /* NOTE: an application can still remove the hot item even if anchor
5200 * highlighting is enabled */
5202 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, lParam
);
5204 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5207 /* Sets the toolbar global iListGap parameter which controls the amount of
5208 * spacing between the image and the text of buttons for TBSTYLE_LIST
5210 static LRESULT
TOOLBAR_SetListGap(TOOLBAR_INFO
*infoPtr
, INT iListGap
)
5212 TRACE("hwnd=%p iListGap=%d\n", infoPtr
->hwndSelf
, iListGap
);
5214 infoPtr
->iListGap
= iListGap
;
5216 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5221 /* Returns the number of maximum number of image lists associated with the
5222 * various states. */
5223 static LRESULT
TOOLBAR_GetImageListCount(const TOOLBAR_INFO
*infoPtr
)
5225 TRACE("hwnd=%p\n", infoPtr
->hwndSelf
);
5227 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5231 TOOLBAR_GetIdealSize (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5233 LPSIZE lpsize
= (LPSIZE
)lParam
;
5239 * Testing shows the following:
5240 * wParam = 0 adjust cx value
5241 * = 1 set cy value to max size.
5242 * lParam pointer to SIZE structure
5245 TRACE("wParam %Id, lParam %Ix -> %lx, %lx\n", wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5249 if (lpsize
->cx
== -1) {
5250 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5252 else if(HIWORD(lpsize
->cx
)) {
5254 HWND hwndParent
= GetParent(infoPtr
->hwndSelf
);
5256 GetWindowRect(infoPtr
->hwndSelf
, &rc
);
5257 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5258 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc
));
5259 lpsize
->cx
= max(rc
.right
-rc
.left
,
5260 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5263 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5267 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5270 FIXME("Unknown wParam %Id\n", wParam
);
5273 TRACE("set to -> %lu, %lu\n", lpsize
->cx
, lpsize
->cy
);
5277 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5279 FIXME("hwnd %p, wParam %Ix, lParam %Ix\n", hwnd
, wParam
, lParam
);
5281 InvalidateRect(hwnd
, NULL
, TRUE
);
5287 TOOLBAR_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
5289 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
5292 TRACE("hwnd = %p, style = %#lx\n", hwnd
, lpcs
->style
);
5294 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5295 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5296 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5297 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_REQUERY
));
5298 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5300 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5301 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5302 infoPtr
->hTheme
= OpenThemeDataForDpi (NULL
, themeClass
, GetDpiForWindow (hwnd
));
5304 TOOLBAR_CheckStyle (infoPtr
);
5311 TOOLBAR_Destroy (TOOLBAR_INFO
*infoPtr
)
5315 /* delete tooltip control */
5316 if (infoPtr
->hwndToolTip
)
5317 DestroyWindow (infoPtr
->hwndToolTip
);
5319 /* delete temporary buffer for tooltip text */
5320 Free (infoPtr
->pszTooltipText
);
5321 Free (infoPtr
->bitmaps
); /* bitmaps list */
5323 /* delete button data */
5324 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5325 free_string( infoPtr
->buttons
+ i
);
5326 Free (infoPtr
->buttons
);
5328 /* delete strings */
5329 if (infoPtr
->strings
) {
5330 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5331 Free (infoPtr
->strings
[i
]);
5333 Free (infoPtr
->strings
);
5336 /* destroy internal image list */
5337 if (infoPtr
->himlInt
)
5338 ImageList_Destroy (infoPtr
->himlInt
);
5340 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5341 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5342 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5344 /* delete default font */
5345 DeleteObject (infoPtr
->hDefaultFont
);
5347 CloseThemeData (infoPtr
->hTheme
);
5349 /* free toolbar info data */
5350 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
5358 TOOLBAR_EraseBackground (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5360 NMTBCUSTOMDRAW tbcd
;
5363 DWORD dwEraseCustDraw
= 0;
5365 /* the app has told us not to redraw the toolbar */
5366 if (!infoPtr
->bDoRedraw
)
5369 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5370 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5371 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5372 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5373 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5374 dwEraseCustDraw
= ntfret
& 0xffff;
5376 /* FIXME: in general the return flags *can* be or'ed together */
5377 switch (dwEraseCustDraw
)
5379 case CDRF_DODEFAULT
:
5381 case CDRF_SKIPDEFAULT
:
5384 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5385 infoPtr
->hwndSelf
, ntfret
);
5389 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5390 * to my parent for processing.
5392 if (infoPtr
->hTheme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5394 HDC hdc
= (HDC
)wParam
;
5399 parent
= GetParent(infoPtr
->hwndSelf
);
5400 MapWindowPoints(infoPtr
->hwndSelf
, parent
, &pt
, 1);
5401 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5402 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5403 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5406 ret
= DefWindowProcW (infoPtr
->hwndSelf
, WM_ERASEBKGND
, wParam
, lParam
);
5408 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5409 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5410 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5411 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5412 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5413 dwEraseCustDraw
= ntfret
& 0xffff;
5414 switch (dwEraseCustDraw
)
5416 case CDRF_DODEFAULT
:
5418 case CDRF_SKIPDEFAULT
:
5421 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5422 infoPtr
->hwndSelf
, ntfret
);
5429 static inline LRESULT
5430 TOOLBAR_GetFont (const TOOLBAR_INFO
*infoPtr
)
5432 return (LRESULT
)infoPtr
->hFont
;
5437 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5440 INT nNewHotItem
= infoPtr
->nHotItem
;
5442 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5445 if ((nNewHotItem
+ iDirection
< 0) ||
5446 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5448 NMTBWRAPHOTITEM nmtbwhi
;
5449 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5450 nmtbwhi
.iDirection
= iDirection
;
5451 nmtbwhi
.dwReason
= dwReason
;
5453 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5457 nNewHotItem
+= iDirection
;
5458 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5460 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5461 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5463 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5470 TOOLBAR_KeyDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5474 nmkey
.nVKey
= (UINT
)wParam
;
5475 nmkey
.uFlags
= HIWORD(lParam
);
5477 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5478 return DefWindowProcW(infoPtr
->hwndSelf
, WM_KEYDOWN
, wParam
, lParam
);
5480 switch ((UINT
)wParam
)
5484 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5488 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5492 if ((infoPtr
->nHotItem
>= 0) &&
5493 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5495 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5496 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5497 (LPARAM
)infoPtr
->hwndSelf
);
5507 TOOLBAR_LButtonDblClk (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5512 pt
.x
= (short)LOWORD(lParam
);
5513 pt
.y
= (short)HIWORD(lParam
);
5514 TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5517 TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
5518 else if (infoPtr
->dwStyle
& CCS_ADJUSTABLE
)
5519 TOOLBAR_Customize (infoPtr
);
5526 TOOLBAR_LButtonDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5528 TBUTTON_INFO
*btnPtr
;
5533 BOOL bDragKeyPressed
;
5538 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5539 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5541 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5543 if (infoPtr
->hwndToolTip
)
5544 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5545 WM_LBUTTONDOWN
, wParam
, lParam
);
5547 pt
.x
= (short)LOWORD(lParam
);
5548 pt
.y
= (short)HIWORD(lParam
);
5549 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5553 btnPtr
= &infoPtr
->buttons
[nHit
];
5555 if (bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5557 infoPtr
->nButtonDrag
= nHit
;
5558 SetCapture (infoPtr
->hwndSelf
);
5560 /* If drag cursor has not been loaded, load it.
5561 * Note: it doesn't need to be freed */
5563 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5564 SetCursor(hCursorDrag
);
5569 infoPtr
->nOldHit
= nHit
;
5571 arrowRect
= btnPtr
->rect
;
5572 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5574 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5575 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5576 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5577 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5578 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5579 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5583 /* draw in pressed state */
5584 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5585 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5587 btnPtr
->bDropDownPressed
= TRUE
;
5588 RedrawWindow(infoPtr
->hwndSelf
, &btnPtr
->rect
, 0, RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5590 memset(&nmtb
, 0, sizeof(nmtb
));
5591 nmtb
.iItem
= btnPtr
->idCommand
;
5592 nmtb
.rcButton
= btnPtr
->rect
;
5593 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
, TBN_DROPDOWN
);
5594 TRACE("TBN_DROPDOWN responded with %Id\n", res
);
5596 if (res
!= TBDDRET_TREATPRESSED
)
5600 /* redraw button in unpressed state */
5601 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5602 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5604 btnPtr
->bDropDownPressed
= FALSE
;
5605 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5607 /* find and set hot item */
5609 ScreenToClient(infoPtr
->hwndSelf
, &pt
);
5610 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5611 if (!infoPtr
->bAnchor
|| button
)
5612 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5614 /* remove any left mouse button down or double-click messages
5615 * so that we can get a toggle effect on the button */
5616 while (PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5617 PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5622 /* otherwise drop through and process as pushed */
5624 infoPtr
->bCaptured
= TRUE
;
5625 infoPtr
->nButtonDown
= nHit
;
5626 infoPtr
->bDragOutSent
= FALSE
;
5628 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5630 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5632 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5633 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5634 UpdateWindow(infoPtr
->hwndSelf
);
5635 SetCapture (infoPtr
->hwndSelf
);
5638 memset(&nmtb
, 0, sizeof(nmtb
));
5639 nmtb
.iItem
= btnPtr
->idCommand
;
5640 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5643 nmmouse
.dwHitInfo
= nHit
;
5645 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5647 nmmouse
.dwItemSpec
= -1;
5650 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5651 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5654 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5657 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5658 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, wParam
, lParam
);
5664 TOOLBAR_LButtonUp (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5666 TBUTTON_INFO
*btnPtr
;
5675 if (infoPtr
->hwndToolTip
)
5676 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5677 WM_LBUTTONUP
, wParam
, lParam
);
5679 pt
.x
= (short)LOWORD(lParam
);
5680 pt
.y
= (short)HIWORD(lParam
);
5681 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5683 if (!infoPtr
->bAnchor
|| button
)
5684 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5686 if (infoPtr
->nButtonDrag
>= 0) {
5690 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5693 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5695 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5696 if (PtInRect(&rcClient
, pt
))
5703 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5706 if (nButton
== infoPtr
->nButtonDrag
)
5708 /* if the button is moved slightly left and we have a
5709 * separator there then remove it */
5710 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5712 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5713 TOOLBAR_DeleteButton(infoPtr
, nButton
- 1);
5715 else /* else insert a separator before the dragged button */
5718 memset(&tbb
, 0, sizeof(tbb
));
5719 tbb
.fsStyle
= BTNS_SEP
;
5721 TOOLBAR_InsertButtonT(infoPtr
, nButton
, &tbb
, TRUE
);
5728 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5729 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, 0);
5731 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5734 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, nButton
);
5739 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5740 TOOLBAR_DeleteButton(infoPtr
, infoPtr
->nButtonDrag
);
5743 /* button under cursor changed so need to re-set hot item */
5744 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5745 infoPtr
->nButtonDrag
= -1;
5747 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5749 else if (infoPtr
->nButtonDown
>= 0)
5751 BOOL was_clicked
= nHit
== infoPtr
->nButtonDown
;
5753 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5754 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5756 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5757 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5758 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5760 if ((nOldIndex
!= nHit
) &&
5762 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5763 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5766 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5767 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5769 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5773 if (nOldIndex
!= -1)
5774 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5777 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5778 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5779 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5781 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5783 infoPtr
->nButtonDown
= -1;
5785 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5786 TOOLBAR_SendNotify (&hdr
, infoPtr
,
5787 NM_RELEASEDCAPTURE
);
5789 memset(&nmtb
, 0, sizeof(nmtb
));
5790 nmtb
.iItem
= btnPtr
->idCommand
;
5791 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5794 if (was_clicked
&& btnPtr
->fsState
& TBSTATE_ENABLED
)
5796 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5797 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)infoPtr
->hwndSelf
);
5799 /* In case we have just been destroyed... */
5800 if(!IsWindow(infoPtr
->hwndSelf
))
5805 /* !!! Undocumented - toolbar at 4.71 level and above sends
5806 * NM_CLICK with the NMMOUSE structure. */
5807 nmmouse
.dwHitInfo
= nHit
;
5810 nmmouse
.dwItemSpec
= -1;
5813 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5814 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5817 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5820 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5821 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONUP
, wParam
, lParam
);
5827 TOOLBAR_RButtonUp(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5834 pt
.x
= (short)LOWORD(lParam
);
5835 pt
.y
= (short)HIWORD(lParam
);
5837 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5838 nmmouse
.dwHitInfo
= nHit
;
5841 nmmouse
.dwItemSpec
= -1;
5843 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5844 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5847 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5850 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5851 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONUP
, wParam
, lParam
);
5857 TOOLBAR_RButtonDblClk( TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5861 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5862 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
5868 TOOLBAR_CaptureChanged(TOOLBAR_INFO
*infoPtr
)
5870 TBUTTON_INFO
*btnPtr
;
5872 infoPtr
->bCaptured
= FALSE
;
5874 if (infoPtr
->nButtonDown
>= 0)
5876 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5877 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5879 infoPtr
->nOldHit
= -1;
5881 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5882 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5888 TOOLBAR_MouseLeave (TOOLBAR_INFO
*infoPtr
)
5890 /* don't remove hot effects when in anchor highlighting mode or when a
5891 * drop-down button is pressed */
5892 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
5894 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
5895 if (!hotBtnPtr
->bDropDownPressed
)
5896 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
5899 if (infoPtr
->nOldHit
< 0)
5902 /* If the last button we were over is depressed then make it not */
5903 /* depressed and redraw it */
5904 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
5906 TBUTTON_INFO
*btnPtr
;
5909 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5911 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5914 InflateRect (&rc1
, 1, 1);
5915 InvalidateRect (infoPtr
->hwndSelf
, &rc1
, TRUE
);
5918 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
5921 ZeroMemory(&nmt
, sizeof(nmt
));
5922 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5923 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5924 infoPtr
->bDragOutSent
= TRUE
;
5927 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
5933 TOOLBAR_MouseMove (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5936 TRACKMOUSEEVENT trackinfo
;
5938 TBUTTON_INFO
*btnPtr
;
5941 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
5942 TOOLBAR_TooltipCreateControl(infoPtr
);
5944 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || infoPtr
->hTheme
) {
5945 /* fill in the TRACKMOUSEEVENT struct */
5946 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5947 trackinfo
.dwFlags
= TME_QUERY
;
5949 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5950 _TrackMouseEvent(&trackinfo
);
5952 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5953 if(trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
5954 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5955 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
5957 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5958 /* and can properly deactivate the hot toolbar button */
5959 _TrackMouseEvent(&trackinfo
);
5963 if (infoPtr
->hwndToolTip
)
5964 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5965 WM_MOUSEMOVE
, wParam
, lParam
);
5967 pt
.x
= (short)LOWORD(lParam
);
5968 pt
.y
= (short)HIWORD(lParam
);
5970 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5972 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || infoPtr
->hTheme
) && (!infoPtr
->bAnchor
|| button
))
5973 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
);
5975 if (infoPtr
->nOldHit
!= nHit
)
5977 if (infoPtr
->bCaptured
)
5979 if (!infoPtr
->bDragOutSent
)
5982 ZeroMemory(&nmt
, sizeof(nmt
));
5983 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5984 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5985 infoPtr
->bDragOutSent
= TRUE
;
5988 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5989 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
5990 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5991 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5993 else if (nHit
== infoPtr
->nButtonDown
) {
5994 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5995 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5997 infoPtr
->nOldHit
= nHit
;
6005 static inline LRESULT
6006 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6008 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6009 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
6011 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6015 static inline LRESULT
6016 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6018 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
6019 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
6021 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
6026 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
6028 TOOLBAR_INFO
*infoPtr
;
6031 /* allocate memory for info structure */
6032 infoPtr
= Alloc (sizeof(TOOLBAR_INFO
));
6033 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
6036 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
6039 /* initialize info structure */
6040 infoPtr
->nButtonWidth
= 23;
6041 infoPtr
->nButtonHeight
= 22;
6042 infoPtr
->nBitmapHeight
= 16;
6043 infoPtr
->nBitmapWidth
= 16;
6045 infoPtr
->nMaxTextRows
= 1;
6046 infoPtr
->cxMin
= -1;
6047 infoPtr
->cxMax
= -1;
6048 infoPtr
->nNumBitmaps
= 0;
6049 infoPtr
->nNumStrings
= 0;
6051 infoPtr
->bCaptured
= FALSE
;
6052 infoPtr
->nButtonDown
= -1;
6053 infoPtr
->nButtonDrag
= -1;
6054 infoPtr
->nOldHit
= -1;
6055 infoPtr
->nHotItem
= -1;
6056 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
6057 infoPtr
->dwDTFlags
= (lpcs
->style
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
6058 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
6059 infoPtr
->bDragOutSent
= FALSE
;
6060 infoPtr
->iVersion
= 0;
6061 infoPtr
->hwndSelf
= hwnd
;
6062 infoPtr
->bDoRedraw
= TRUE
;
6063 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
6064 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
6065 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
6066 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
6067 infoPtr
->iListGap
= DEFLISTGAP
;
6068 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
6069 infoPtr
->dwStyle
= lpcs
->style
;
6070 infoPtr
->tbim
.iButton
= -1;
6072 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6073 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
6074 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
6075 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
6078 /* I think the code below is a bug, but it is the way that the native
6079 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6080 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6081 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6082 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6083 * Somehow, the only cases of this seem to be MFC programs.
6085 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6086 * does not occur in the WM_STYLECHANGING routine.
6087 * (Guy Albertelli 9/2001)
6090 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) && !(lpcs
->style
& TBSTYLE_TRANSPARENT
))
6091 styleadd
|= TBSTYLE_TRANSPARENT
;
6092 if (!(lpcs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
6093 styleadd
|= CCS_TOP
; /* default to top */
6094 SetWindowLongW (hwnd
, GWL_STYLE
, lpcs
->style
| styleadd
);
6097 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
6102 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6104 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
6108 if (dwStyle
& WS_MINIMIZE
)
6109 return 0; /* Nothing to do */
6111 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
6113 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
6116 if (!(dwStyle
& CCS_NODIVIDER
))
6118 GetWindowRect (hwnd
, &rcWindow
);
6119 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
6120 if( dwStyle
& WS_BORDER
)
6121 InflateRect (&rcWindow
, -1, -1);
6122 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6125 ReleaseDC( hwnd
, hdc
);
6131 /* handles requests from the tooltip control on what text to display */
6132 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6134 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6135 NMTTDISPINFOA nmtdi
;
6139 TRACE("button index = %d\n", index
);
6141 Free (infoPtr
->pszTooltipText
);
6142 infoPtr
->pszTooltipText
= NULL
;
6147 if (infoPtr
->bUnicode
)
6149 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6150 NMTBGETINFOTIPW tbgit
;
6152 wszBuffer
[0] = '\0';
6153 wszBuffer
[INFOTIPSIZE
] = '\0';
6155 tbgit
.pszText
= wszBuffer
;
6156 tbgit
.cchTextMax
= INFOTIPSIZE
;
6157 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6158 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6160 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6162 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6164 len
= tbgit
.pszText
? lstrlenW(tbgit
.pszText
) : 0;
6165 if (len
> ARRAY_SIZE(lpnmtdi
->szText
) - 1)
6167 /* need to allocate temporary buffer in infoPtr as there
6168 * isn't enough space in buffer passed to us by the
6169 * tooltip control */
6170 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6171 if (infoPtr
->pszTooltipText
)
6173 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6174 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6180 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6186 CHAR szBuffer
[INFOTIPSIZE
+1];
6187 NMTBGETINFOTIPA tbgit
;
6190 szBuffer
[INFOTIPSIZE
] = '\0';
6192 tbgit
.pszText
= szBuffer
;
6193 tbgit
.cchTextMax
= INFOTIPSIZE
;
6194 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6195 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6197 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6199 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6201 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6202 if (len
> ARRAY_SIZE(lpnmtdi
->szText
))
6204 /* need to allocate temporary buffer in infoPtr as there
6205 * isn't enough space in buffer passed to us by the
6206 * tooltip control */
6207 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6208 if (infoPtr
->pszTooltipText
)
6210 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6211 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6215 else if (tbgit
.pszText
&& tbgit
.pszText
[0])
6217 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, lpnmtdi
->lpszText
, ARRAY_SIZE(lpnmtdi
->szText
));
6222 /* if button has text, but it is not shown then automatically
6223 * use that text as tooltip */
6224 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6225 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6227 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6228 len
= pszText
? lstrlenW(pszText
) : 0;
6230 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6232 if (len
> ARRAY_SIZE(lpnmtdi
->szText
) - 1)
6234 /* need to allocate temporary buffer in infoPtr as there
6235 * isn't enough space in buffer passed to us by the
6236 * tooltip control */
6237 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6238 if (infoPtr
->pszTooltipText
)
6240 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6241 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6247 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6252 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6254 /* Last resort, forward TTN_GETDISPINFO to the app:
6256 - NFR_UNICODE gets TTN_GETDISPINFOW, and TTN_GETDISPINFOA if -W returned no text;
6257 - NFR_ANSI gets only TTN_GETDISPINFOA.
6259 if (infoPtr
->bUnicode
)
6261 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmtdi
->hdr
.idFrom
, (LPARAM
)lpnmtdi
);
6263 TRACE("TTN_GETDISPINFOW - got string %s\n", debugstr_w(lpnmtdi
->lpszText
));
6265 if (IS_INTRESOURCE(lpnmtdi
->lpszText
))
6268 if (lpnmtdi
->lpszText
&& *lpnmtdi
->lpszText
)
6272 nmtdi
.hdr
.hwndFrom
= lpnmtdi
->hdr
.hwndFrom
;
6273 nmtdi
.hdr
.idFrom
= lpnmtdi
->hdr
.idFrom
;
6274 nmtdi
.hdr
.code
= TTN_GETDISPINFOA
;
6275 nmtdi
.lpszText
= nmtdi
.szText
;
6276 nmtdi
.szText
[0] = 0;
6277 nmtdi
.hinst
= lpnmtdi
->hinst
;
6278 nmtdi
.uFlags
= lpnmtdi
->uFlags
;
6279 nmtdi
.lParam
= lpnmtdi
->lParam
;
6281 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmtdi
.hdr
.idFrom
, (LPARAM
)&nmtdi
);
6283 TRACE("TTN_GETDISPINFOA - got string %s\n", debugstr_a(nmtdi
.lpszText
));
6285 lpnmtdi
->hinst
= nmtdi
.hinst
;
6286 lpnmtdi
->uFlags
= nmtdi
.uFlags
;
6287 lpnmtdi
->lParam
= nmtdi
.lParam
;
6289 if (IS_INTRESOURCE(nmtdi
.lpszText
))
6291 lpnmtdi
->lpszText
= (WCHAR
*)nmtdi
.lpszText
;
6295 if (!nmtdi
.lpszText
|| !*nmtdi
.lpszText
)
6298 len
= MultiByteToWideChar(CP_ACP
, 0, nmtdi
.lpszText
, -1, NULL
, 0);
6299 if (len
> ARRAY_SIZE(lpnmtdi
->szText
))
6301 infoPtr
->pszTooltipText
= Alloc(len
* sizeof(WCHAR
));
6302 if (infoPtr
->pszTooltipText
)
6304 MultiByteToWideChar(CP_ACP
, 0, nmtdi
.lpszText
, -1, infoPtr
->pszTooltipText
, len
);
6305 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6311 MultiByteToWideChar(CP_ACP
, 0, nmtdi
.lpszText
, -1, lpnmtdi
->lpszText
, ARRAY_SIZE(nmtdi
.szText
));
6319 static inline LRESULT
6320 TOOLBAR_Notify (TOOLBAR_INFO
*infoPtr
, LPNMHDR lpnmh
)
6322 switch (lpnmh
->code
)
6326 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lpnmh
;
6328 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6329 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6330 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6334 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6335 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6343 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lpnmh
;
6345 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6346 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6347 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6348 lppgs
->iScroll
, lppgs
->iDir
);
6352 case TTN_GETDISPINFOW
:
6353 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lpnmh
);
6355 case TTN_GETDISPINFOA
:
6356 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6366 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6370 TRACE("wParam %Ix, lParam %Ix\n", wParam
, lParam
);
6372 if (lParam
== NF_QUERY
)
6375 if (lParam
== NF_REQUERY
) {
6376 format
= SendMessageW(infoPtr
->hwndNotify
,
6377 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6378 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6379 ERR("wrong response to WM_NOTIFYFORMAT (%Id), assuming ANSI\n", format
);
6389 TOOLBAR_Paint (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6394 /* fill ps.rcPaint with a default rect */
6395 ps
.rcPaint
= infoPtr
->rcBound
;
6397 hdc
= wParam
==0 ? BeginPaint(infoPtr
->hwndSelf
, &ps
) : (HDC
)wParam
;
6399 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps
.rcPaint
));
6401 TOOLBAR_Refresh (infoPtr
, hdc
, &ps
);
6402 if (!wParam
) EndPaint (infoPtr
->hwndSelf
, &ps
);
6409 TOOLBAR_SetFocus (TOOLBAR_INFO
*infoPtr
)
6411 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6413 /* make first item hot */
6414 if (infoPtr
->nNumButtons
> 0)
6415 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6421 TOOLBAR_SetFont(TOOLBAR_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
6423 TRACE("font=%p redraw=%d\n", hFont
, Redraw
);
6426 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6428 infoPtr
->hFont
= hFont
;
6430 TOOLBAR_CalcToolbar(infoPtr
);
6433 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6438 TOOLBAR_SetRedraw (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6439 /*****************************************************
6442 * Handles the WM_SETREDRAW message.
6445 * According to testing V4.71 of COMCTL32 returns the
6446 * *previous* status of the redraw flag (either 0 or 1)
6447 * instead of the MSDN documented value of 0 if handled.
6448 * (For laughs see the "consistency" with same function
6451 *****************************************************/
6453 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6455 TRACE("set to %s\n",
6456 (wParam
) ? "TRUE" : "FALSE");
6457 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6459 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6461 return (oldredraw
) ? 1 : 0;
6466 TOOLBAR_Size (TOOLBAR_INFO
*infoPtr
)
6468 TRACE("sizing toolbar\n");
6470 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6472 RECT delta_width
, delta_height
, client
, dummy
;
6473 DWORD min_x
, max_x
, min_y
, max_y
;
6474 TBUTTON_INFO
*btnPtr
;
6477 GetClientRect(infoPtr
->hwndSelf
, &client
);
6478 if(client
.right
> infoPtr
->client_rect
.right
)
6480 min_x
= infoPtr
->client_rect
.right
;
6481 max_x
= client
.right
;
6485 max_x
= infoPtr
->client_rect
.right
;
6486 min_x
= client
.right
;
6488 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6490 min_y
= infoPtr
->client_rect
.bottom
;
6491 max_y
= client
.bottom
;
6495 max_y
= infoPtr
->client_rect
.bottom
;
6496 min_y
= client
.bottom
;
6499 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6500 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6502 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6503 btnPtr
= infoPtr
->buttons
;
6504 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6505 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6506 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6507 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6509 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->client_rect
);
6510 TOOLBAR_AutoSize(infoPtr
);
6516 TOOLBAR_StyleChanged (TOOLBAR_INFO
*infoPtr
, INT nType
, const STYLESTRUCT
*lpStyle
)
6518 if (nType
== GWL_STYLE
)
6519 return TOOLBAR_SetStyle(infoPtr
, lpStyle
->styleNew
);
6526 TOOLBAR_SysColorChange (void)
6528 COMCTL32_RefreshSysColors();
6534 /* update theme after a WM_THEMECHANGED message */
6535 static LRESULT
theme_changed (TOOLBAR_INFO
*infoPtr
)
6537 CloseThemeData (infoPtr
->hTheme
);
6538 infoPtr
->hTheme
= OpenThemeDataForDpi (NULL
, themeClass
, GetDpiForWindow (infoPtr
->hwndSelf
));
6539 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
6544 static LRESULT WINAPI
6545 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6547 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
6549 TRACE("hwnd %p, msg %x, wparam %Ix, lparam %Ix\n", hwnd
, uMsg
, wParam
, lParam
);
6551 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6552 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6557 return TOOLBAR_AddBitmap (infoPtr
, (INT
)wParam
, (TBADDBITMAP
*)lParam
);
6559 case TB_ADDBUTTONSA
:
6560 case TB_ADDBUTTONSW
:
6561 return TOOLBAR_AddButtonsT (infoPtr
, wParam
, (LPTBBUTTON
)lParam
,
6562 uMsg
== TB_ADDBUTTONSW
);
6564 return TOOLBAR_AddStringA (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6567 return TOOLBAR_AddStringW (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6570 return TOOLBAR_AutoSize (infoPtr
);
6572 case TB_BUTTONCOUNT
:
6573 return TOOLBAR_ButtonCount (infoPtr
);
6575 case TB_BUTTONSTRUCTSIZE
:
6576 return TOOLBAR_ButtonStructSize (infoPtr
, wParam
);
6578 case TB_CHANGEBITMAP
:
6579 return TOOLBAR_ChangeBitmap (infoPtr
, wParam
, LOWORD(lParam
));
6581 case TB_CHECKBUTTON
:
6582 return TOOLBAR_CheckButton (infoPtr
, wParam
, lParam
);
6584 case TB_COMMANDTOINDEX
:
6585 return TOOLBAR_CommandToIndex (infoPtr
, wParam
);
6588 return TOOLBAR_Customize (infoPtr
);
6590 case TB_DELETEBUTTON
:
6591 return TOOLBAR_DeleteButton (infoPtr
, wParam
);
6593 case TB_ENABLEBUTTON
:
6594 return TOOLBAR_EnableButton (infoPtr
, wParam
, lParam
);
6596 case TB_GETANCHORHIGHLIGHT
:
6597 return TOOLBAR_GetAnchorHighlight (infoPtr
);
6600 return TOOLBAR_GetBitmap (infoPtr
, wParam
);
6602 case TB_GETBITMAPFLAGS
:
6603 return TOOLBAR_GetBitmapFlags ();
6606 return TOOLBAR_GetButton (infoPtr
, wParam
, (TBBUTTON
*)lParam
);
6608 case TB_GETBUTTONINFOA
:
6609 case TB_GETBUTTONINFOW
:
6610 return TOOLBAR_GetButtonInfoT (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6611 uMsg
== TB_GETBUTTONINFOW
);
6612 case TB_GETBUTTONSIZE
:
6613 return TOOLBAR_GetButtonSize (infoPtr
);
6615 case TB_GETBUTTONTEXTA
:
6616 case TB_GETBUTTONTEXTW
:
6617 return TOOLBAR_GetButtonText (infoPtr
, wParam
, (LPWSTR
)lParam
,
6618 uMsg
== TB_GETBUTTONTEXTW
);
6620 case TB_GETDISABLEDIMAGELIST
:
6621 return TOOLBAR_GetDisabledImageList (infoPtr
, wParam
);
6623 case TB_GETEXTENDEDSTYLE
:
6624 return TOOLBAR_GetExtendedStyle (infoPtr
);
6626 case TB_GETHOTIMAGELIST
:
6627 return TOOLBAR_GetHotImageList (infoPtr
, wParam
);
6630 return TOOLBAR_GetHotItem (infoPtr
);
6632 case TB_GETIMAGELIST
:
6633 return TOOLBAR_GetDefImageList (infoPtr
, wParam
);
6635 case TB_GETINSERTMARK
:
6636 return TOOLBAR_GetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6638 case TB_GETINSERTMARKCOLOR
:
6639 return TOOLBAR_GetInsertMarkColor (infoPtr
);
6641 case TB_GETITEMRECT
:
6642 return TOOLBAR_GetItemRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6645 return TOOLBAR_GetMaxSize (infoPtr
, (LPSIZE
)lParam
);
6647 /* case TB_GETOBJECT: */ /* 4.71 */
6650 return TOOLBAR_GetPadding (infoPtr
);
6653 return TOOLBAR_GetRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6656 return TOOLBAR_GetRows (infoPtr
);
6659 return TOOLBAR_GetState (infoPtr
, wParam
);
6662 return TOOLBAR_GetStringA (infoPtr
, wParam
, (LPSTR
)lParam
);
6665 return TOOLBAR_GetStringW (infoPtr
, wParam
, (LPWSTR
)lParam
);
6668 return TOOLBAR_GetStyle (infoPtr
);
6670 case TB_GETTEXTROWS
:
6671 return TOOLBAR_GetTextRows (infoPtr
);
6673 case TB_GETTOOLTIPS
:
6674 return TOOLBAR_GetToolTips (infoPtr
);
6676 case TB_GETUNICODEFORMAT
:
6677 return TOOLBAR_GetUnicodeFormat (infoPtr
);
6680 return TOOLBAR_HideButton (infoPtr
, wParam
, LOWORD(lParam
));
6683 return TOOLBAR_HitTest (infoPtr
, (LPPOINT
)lParam
);
6685 case TB_INDETERMINATE
:
6686 return TOOLBAR_Indeterminate (infoPtr
, wParam
, LOWORD(lParam
));
6688 case TB_INSERTBUTTONA
:
6689 case TB_INSERTBUTTONW
:
6690 return TOOLBAR_InsertButtonT(infoPtr
, wParam
, (TBBUTTON
*)lParam
,
6691 uMsg
== TB_INSERTBUTTONW
);
6693 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6695 case TB_ISBUTTONCHECKED
:
6696 return TOOLBAR_IsButtonChecked (infoPtr
, wParam
);
6698 case TB_ISBUTTONENABLED
:
6699 return TOOLBAR_IsButtonEnabled (infoPtr
, wParam
);
6701 case TB_ISBUTTONHIDDEN
:
6702 return TOOLBAR_IsButtonHidden (infoPtr
, wParam
);
6704 case TB_ISBUTTONHIGHLIGHTED
:
6705 return TOOLBAR_IsButtonHighlighted (infoPtr
, wParam
);
6707 case TB_ISBUTTONINDETERMINATE
:
6708 return TOOLBAR_IsButtonIndeterminate (infoPtr
, wParam
);
6710 case TB_ISBUTTONPRESSED
:
6711 return TOOLBAR_IsButtonPressed (infoPtr
, wParam
);
6714 return TOOLBAR_LoadImages (infoPtr
, wParam
, (HINSTANCE
)lParam
);
6716 case TB_MAPACCELERATORA
:
6717 case TB_MAPACCELERATORW
:
6718 return TOOLBAR_MapAccelerator (infoPtr
, wParam
, (UINT
*)lParam
);
6721 return TOOLBAR_MarkButton (infoPtr
, wParam
, LOWORD(lParam
));
6724 return TOOLBAR_MoveButton (infoPtr
, wParam
, lParam
);
6726 case TB_PRESSBUTTON
:
6727 return TOOLBAR_PressButton (infoPtr
, wParam
, LOWORD(lParam
));
6729 case TB_REPLACEBITMAP
:
6730 return TOOLBAR_ReplaceBitmap (infoPtr
, (LPTBREPLACEBITMAP
)lParam
);
6732 case TB_SAVERESTOREA
:
6733 return TOOLBAR_SaveRestoreA (infoPtr
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6735 case TB_SAVERESTOREW
:
6736 return TOOLBAR_SaveRestoreW (infoPtr
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6738 case TB_SETANCHORHIGHLIGHT
:
6739 return TOOLBAR_SetAnchorHighlight (infoPtr
, (BOOL
)wParam
);
6741 case TB_SETBITMAPSIZE
:
6742 return TOOLBAR_SetBitmapSize (infoPtr
, wParam
, lParam
);
6744 case TB_SETBUTTONINFOA
:
6745 case TB_SETBUTTONINFOW
:
6746 return TOOLBAR_SetButtonInfo (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6747 uMsg
== TB_SETBUTTONINFOW
);
6748 case TB_SETBUTTONSIZE
:
6749 return TOOLBAR_SetButtonSize (infoPtr
, lParam
);
6751 case TB_SETBUTTONWIDTH
:
6752 return TOOLBAR_SetButtonWidth (infoPtr
, lParam
);
6755 return TOOLBAR_SetCmdId (infoPtr
, wParam
, lParam
);
6757 case TB_SETDISABLEDIMAGELIST
:
6758 return TOOLBAR_SetDisabledImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6760 case TB_SETDRAWTEXTFLAGS
:
6761 return TOOLBAR_SetDrawTextFlags (infoPtr
, wParam
, lParam
);
6763 case TB_SETEXTENDEDSTYLE
:
6764 return TOOLBAR_SetExtendedStyle (infoPtr
, wParam
, lParam
);
6766 case TB_SETHOTIMAGELIST
:
6767 return TOOLBAR_SetHotImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6770 return TOOLBAR_SetHotItem (infoPtr
, wParam
);
6772 case TB_SETIMAGELIST
:
6773 return TOOLBAR_SetImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6776 return TOOLBAR_SetIndent (infoPtr
, wParam
);
6778 case TB_SETINSERTMARK
:
6779 return TOOLBAR_SetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6781 case TB_SETINSERTMARKCOLOR
:
6782 return TOOLBAR_SetInsertMarkColor (infoPtr
, lParam
);
6784 case TB_SETMAXTEXTROWS
:
6785 return TOOLBAR_SetMaxTextRows (infoPtr
, wParam
);
6788 return TOOLBAR_SetPadding (infoPtr
, lParam
);
6791 return TOOLBAR_SetParent (infoPtr
, (HWND
)wParam
);
6794 return TOOLBAR_SetRows (infoPtr
, wParam
, (LPRECT
)lParam
);
6797 return TOOLBAR_SetState (infoPtr
, wParam
, lParam
);
6800 return TOOLBAR_SetStyle (infoPtr
, lParam
);
6802 case TB_SETTOOLTIPS
:
6803 return TOOLBAR_SetToolTips (infoPtr
, (HWND
)wParam
);
6805 case TB_SETUNICODEFORMAT
:
6806 return TOOLBAR_SetUnicodeFormat (infoPtr
, wParam
);
6808 case TB_SETBOUNDINGSIZE
:
6809 return TOOLBAR_SetBoundingSize(hwnd
, wParam
, lParam
);
6811 case TB_SETHOTITEM2
:
6812 return TOOLBAR_SetHotItem2 (infoPtr
, wParam
, lParam
);
6815 return TOOLBAR_SetListGap(infoPtr
, wParam
);
6817 case TB_GETIMAGELISTCOUNT
:
6818 return TOOLBAR_GetImageListCount(infoPtr
);
6820 case TB_GETIDEALSIZE
:
6821 return TOOLBAR_GetIdealSize (infoPtr
, wParam
, lParam
);
6824 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6826 /* Common Control Messages */
6828 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6829 case CCM_GETCOLORSCHEME
:
6830 return TOOLBAR_GetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6832 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6833 case CCM_SETCOLORSCHEME
:
6834 return TOOLBAR_SetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6836 case CCM_GETVERSION
:
6837 return TOOLBAR_GetVersion (infoPtr
);
6839 case CCM_SETVERSION
:
6840 return TOOLBAR_SetVersion (infoPtr
, (INT
)wParam
);
6846 return TOOLBAR_Create (hwnd
, (CREATESTRUCTW
*)lParam
);
6849 return TOOLBAR_Destroy (infoPtr
);
6852 return TOOLBAR_EraseBackground (infoPtr
, wParam
, lParam
);
6855 return TOOLBAR_GetFont (infoPtr
);
6858 return TOOLBAR_KeyDown (infoPtr
, wParam
, lParam
);
6860 /* case WM_KILLFOCUS: */
6862 case WM_LBUTTONDBLCLK
:
6863 return TOOLBAR_LButtonDblClk (infoPtr
, wParam
, lParam
);
6865 case WM_LBUTTONDOWN
:
6866 return TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
6869 return TOOLBAR_LButtonUp (infoPtr
, wParam
, lParam
);
6872 return TOOLBAR_RButtonUp (infoPtr
, wParam
, lParam
);
6874 case WM_RBUTTONDBLCLK
:
6875 return TOOLBAR_RButtonDblClk (infoPtr
, wParam
, lParam
);
6878 return TOOLBAR_MouseMove (infoPtr
, wParam
, lParam
);
6881 return TOOLBAR_MouseLeave (infoPtr
);
6883 case WM_CAPTURECHANGED
:
6884 if (hwnd
== (HWND
)lParam
) return 0;
6885 return TOOLBAR_CaptureChanged(infoPtr
);
6888 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6891 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6894 return TOOLBAR_NCCreate (hwnd
, wParam
, (CREATESTRUCTW
*)lParam
);
6897 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
6900 return TOOLBAR_Notify (infoPtr
, (LPNMHDR
)lParam
);
6902 case WM_NOTIFYFORMAT
:
6903 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
6905 case WM_PRINTCLIENT
:
6907 return TOOLBAR_Paint (infoPtr
, wParam
);
6910 return TOOLBAR_SetFocus (infoPtr
);
6913 return TOOLBAR_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
6916 return TOOLBAR_SetRedraw (infoPtr
, wParam
);
6919 return TOOLBAR_Size (infoPtr
);
6921 case WM_STYLECHANGED
:
6922 return TOOLBAR_StyleChanged (infoPtr
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
6924 case WM_SYSCOLORCHANGE
:
6925 return TOOLBAR_SysColorChange ();
6927 case WM_THEMECHANGED
:
6928 return theme_changed (infoPtr
);
6930 /* case WM_WININICHANGE: */
6935 case WM_MEASUREITEM
:
6937 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
6939 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6940 case PGM_FORWARDMOUSE
:
6941 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6944 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
6945 ERR("unknown msg %04x, wp %Ix, lp %Ix\n", uMsg
, wParam
, lParam
);
6946 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6952 TOOLBAR_Register (void)
6956 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
6957 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
6958 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
6959 wndClass
.cbClsExtra
= 0;
6960 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
6961 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
6962 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
6963 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
6965 RegisterClassW (&wndClass
);
6970 TOOLBAR_Unregister (void)
6972 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
6975 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
6980 /* Check if the entry already exists */
6981 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
6983 /* Don't add new entry for NULL imagelist */
6987 /* If this is a new entry we must create it and insert into the array */
6992 c
= Alloc(sizeof(IMLENTRY
));
6995 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
6996 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
7011 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
7015 for (i
= 0; i
< *cies
; i
++)
7025 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
7033 for (i
= 0; i
< cies
; i
++)
7035 if (pies
[i
]->id
== id
)
7047 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
7049 HIMAGELIST himlDef
= 0;
7050 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
7053 himlDef
= pie
->himl
;
7059 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
7061 if (infoPtr
->bUnicode
)
7062 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
7069 nmtba
.iItem
= nmtb
->iItem
;
7070 nmtba
.pszText
= Buffer
;
7071 nmtba
.cchText
= 256;
7072 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
7074 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
7076 int ccht
= strlen(nmtba
.pszText
);
7078 MultiByteToWideChar(CP_ACP
, 0, nmtba
.pszText
, -1,
7079 nmtb
->pszText
, nmtb
->cchText
);
7081 nmtb
->tbButton
= nmtba
.tbButton
;
7090 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
)
7094 /* MSDN states that iItem is the index of the button, rather than the
7095 * command ID as used by every other NMTOOLBAR notification */
7097 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
7099 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);