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 HIMAGELIST himlInt
; /* image list created internally */
146 PIMLENTRY
*himlDef
; /* default image list array */
147 INT cimlDef
; /* default image list array count */
148 PIMLENTRY
*himlHot
; /* hot image list array */
149 INT cimlHot
; /* hot image list array count */
150 PIMLENTRY
*himlDis
; /* disabled image list array */
151 INT cimlDis
; /* disabled image list array count */
152 HWND hwndToolTip
; /* handle to tool tip control */
153 HWND hwndNotify
; /* handle to the window that gets notifications */
154 HWND hwndSelf
; /* my own handle */
155 BOOL bAnchor
; /* anchor highlight enabled */
156 BOOL bDoRedraw
; /* Redraw status */
157 BOOL bDragOutSent
; /* has TBN_DRAGOUT notification been sent for this drag? */
158 BOOL bUnicode
; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
159 BOOL bCaptured
; /* mouse captured? */
160 DWORD dwStyle
; /* regular toolbar style */
161 DWORD dwExStyle
; /* extended toolbar style */
162 DWORD dwDTFlags
; /* DrawText flags */
164 COLORREF clrInsertMark
; /* insert mark color */
165 COLORREF clrBtnHighlight
; /* color for Flat Separator */
166 COLORREF clrBtnShadow
; /* color for Flag Separator */
168 LPWSTR pszTooltipText
; /* temporary store for a string > 80 characters
169 * for TTN_GETDISPINFOW notification */
170 TBINSERTMARK tbim
; /* info on insertion mark */
171 TBUTTON_INFO
*buttons
; /* pointer to button array */
172 LPWSTR
*strings
; /* pointer to string array */
173 TBITMAP_INFO
*bitmaps
;
174 } TOOLBAR_INFO
, *PTOOLBAR_INFO
;
177 /* used by customization dialog */
180 PTOOLBAR_INFO tbInfo
;
182 } CUSTDLG_INFO
, *PCUSTDLG_INFO
;
190 } CUSTOMBUTTON
, *PCUSTOMBUTTON
;
199 #define SEPARATOR_WIDTH 8
201 #define BOTTOM_BORDER 2
202 #define DDARROW_WIDTH 11
203 #define ARROW_HEIGHT 3
204 #define INSERTMARK_WIDTH 2
210 /* vertical padding used in list mode when image is present */
213 /* how wide to treat the bitmap if it isn't present */
214 #define NONLIST_NOTEXT_OFFSET 2
216 #define TOOLBAR_NOWHERE (-1)
218 /* Used to find undocumented extended styles */
219 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
220 TBSTYLE_EX_VERTICAL | \
221 TBSTYLE_EX_MIXEDBUTTONS | \
222 TBSTYLE_EX_DOUBLEBUFFER | \
223 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
225 /* all of the CCS_ styles */
226 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
227 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
229 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
230 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
231 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
232 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
233 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
235 static const WCHAR themeClass
[] = { 'T','o','o','l','b','a','r',0 };
237 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
);
238 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
);
239 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
);
240 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
);
241 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
);
242 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
);
243 static LRESULT
TOOLBAR_LButtonDown(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
);
244 static void TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
);
245 static LRESULT
TOOLBAR_AutoSize(TOOLBAR_INFO
*infoPtr
);
246 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
);
247 static void TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
248 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
249 static LRESULT
TOOLBAR_SetButtonInfo(TOOLBAR_INFO
*infoPtr
, INT Id
,
250 const TBBUTTONINFOW
*lptbbi
, BOOL isW
);
253 static inline int default_top_margin(const TOOLBAR_INFO
*infoPtr
)
255 return (infoPtr
->dwStyle
& TBSTYLE_FLAT
? 0 : TOP_BORDER
);
258 static inline BOOL
TOOLBAR_HasDropDownArrows(DWORD exStyle
)
260 return (exStyle
& TBSTYLE_EX_DRAWDDARROWS
) != 0;
263 static inline BOOL
button_has_ddarrow(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
265 return (TOOLBAR_HasDropDownArrows( infoPtr
->dwExStyle
) && (btnPtr
->fsStyle
& BTNS_DROPDOWN
)) ||
266 (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
270 TOOLBAR_GetText(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
272 LPWSTR lpText
= NULL
;
274 /* NOTE: iString == -1 is undocumented */
275 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1))
276 lpText
= (LPWSTR
)btnPtr
->iString
;
277 else if ((btnPtr
->iString
>= 0) && (btnPtr
->iString
< infoPtr
->nNumStrings
))
278 lpText
= infoPtr
->strings
[btnPtr
->iString
];
284 TOOLBAR_DumpTBButton(const TBBUTTON
*tbb
, BOOL fUnicode
)
286 TRACE("TBBUTTON: id %d, bitmap=%d, state=%02x, style=%02x, data=%p, stringid=%p (%s)\n", tbb
->idCommand
,
287 tbb
->iBitmap
, tbb
->fsState
, tbb
->fsStyle
, (void *)tbb
->dwData
, (void *)tbb
->iString
,
288 tbb
->iString
!= -1 ? (fUnicode
? debugstr_w((LPWSTR
)tbb
->iString
) : debugstr_a((LPSTR
)tbb
->iString
)) : "");
292 TOOLBAR_DumpButton(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*bP
, INT btn_num
)
294 if (TRACE_ON(toolbar
)){
295 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
296 btn_num
, bP
->idCommand
, GETIBITMAP(infoPtr
, bP
->iBitmap
),
297 bP
->fsState
, bP
->fsStyle
, bP
->dwData
, bP
->iString
);
298 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr
,bP
)));
299 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n",
300 btn_num
, bP
->idCommand
, (bP
->bHot
) ? "TRUE":"FALSE", bP
->nRow
,
301 wine_dbgstr_rect(&bP
->rect
));
307 TOOLBAR_DumpToolbar(const TOOLBAR_INFO
*iP
, INT line
)
309 if (TRACE_ON(toolbar
)) {
312 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
314 iP
->dwExStyle
, iP
->nNumButtons
, iP
->nNumBitmaps
,
315 iP
->nNumStrings
, iP
->dwStyle
);
316 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
318 iP
->himlInt
, iP
->himlDef
, iP
->himlHot
, iP
->himlDis
,
319 (iP
->bDoRedraw
) ? "TRUE" : "FALSE");
320 for(i
=0; i
<iP
->nNumButtons
; i
++) {
321 TOOLBAR_DumpButton(iP
, &iP
->buttons
[i
], i
);
327 TOOLBAR_ButtonHasString(const TBUTTON_INFO
*btnPtr
)
329 return HIWORD(btnPtr
->iString
) && btnPtr
->iString
!= -1;
332 static void set_string_index( TBUTTON_INFO
*btn
, INT_PTR str
, BOOL unicode
)
334 if (!IS_INTRESOURCE( str
) && str
!= -1)
336 if (!TOOLBAR_ButtonHasString( btn
)) btn
->iString
= 0;
339 Str_SetPtrW( (WCHAR
**)&btn
->iString
, (WCHAR
*)str
);
341 Str_SetPtrAtoW( (WCHAR
**)&btn
->iString
, (char *)str
);
345 if (TOOLBAR_ButtonHasString( btn
)) Free( (WCHAR
*)btn
->iString
);
351 static void set_stringT( TBUTTON_INFO
*btn
, const WCHAR
*str
, BOOL unicode
)
353 if (IS_INTRESOURCE( (DWORD_PTR
)str
) || (DWORD_PTR
)str
== -1) return;
354 set_string_index( btn
, (DWORD_PTR
)str
, unicode
);
357 static void free_string( TBUTTON_INFO
*btn
)
359 set_string_index( btn
, 0, TRUE
);
363 /***********************************************************************
366 * This function validates that the styles set are implemented and
367 * issues FIXMEs warning of possible problems. In a perfect world this
368 * function should be null.
371 TOOLBAR_CheckStyle (const TOOLBAR_INFO
*infoPtr
)
373 if (infoPtr
->dwStyle
& TBSTYLE_REGISTERDROP
)
374 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", infoPtr
->hwndSelf
);
379 TOOLBAR_SendNotify (NMHDR
*nmhdr
, const TOOLBAR_INFO
*infoPtr
, UINT code
)
381 if(!IsWindow(infoPtr
->hwndSelf
))
382 return 0; /* we have just been destroyed */
384 nmhdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
385 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
388 TRACE("to window %p, code=%08x, %s\n", infoPtr
->hwndNotify
, code
,
389 (infoPtr
->bUnicode
) ? "via Unicode" : "via ANSI");
391 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhdr
->idFrom
, (LPARAM
)nmhdr
);
394 /***********************************************************************
395 * TOOLBAR_GetBitmapIndex
397 * This function returns the bitmap index associated with a button.
398 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
399 * is issued to retrieve the index.
402 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
404 INT ret
= btnPtr
->iBitmap
;
406 if (ret
== I_IMAGECALLBACK
)
408 /* issue TBN_GETDISPINFO */
411 memset(&nmgd
, 0, sizeof(nmgd
));
412 nmgd
.idCommand
= btnPtr
->idCommand
;
413 nmgd
.lParam
= btnPtr
->dwData
;
414 nmgd
.dwMask
= TBNF_IMAGE
;
416 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
417 TOOLBAR_SendNotify(&nmgd
.hdr
, infoPtr
, TBN_GETDISPINFOW
);
418 if (nmgd
.dwMask
& TBNF_DI_SETITEM
)
419 btnPtr
->iBitmap
= nmgd
.iImage
;
421 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
422 ret
, nmgd
.dwMask
, infoPtr
->nNumBitmaps
);
425 if (ret
!= I_IMAGENONE
)
426 ret
= GETIBITMAP(infoPtr
, ret
);
433 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO
*infoPtr
, INT index
)
436 INT id
= GETHIMLID(infoPtr
, index
);
437 INT iBitmap
= GETIBITMAP(infoPtr
, index
);
439 if (((himl
= GETDEFIMAGELIST(infoPtr
, id
)) &&
440 iBitmap
>= 0 && iBitmap
< ImageList_GetImageCount(himl
)) ||
441 (index
== I_IMAGECALLBACK
))
449 TOOLBAR_IsValidImageList(const TOOLBAR_INFO
*infoPtr
, INT index
)
451 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, index
));
452 return (himl
!= NULL
) && (ImageList_GetImageCount(himl
) > 0);
456 /***********************************************************************
457 * TOOLBAR_GetImageListForDrawing
459 * This function validates the bitmap index (including I_IMAGECALLBACK
460 * functionality) and returns the corresponding image list.
463 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
,
464 IMAGE_LIST_TYPE imagelist
, INT
* index
)
468 if (!TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
)) {
469 if (btnPtr
->iBitmap
== I_IMAGENONE
) return NULL
;
470 WARN("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
471 HIWORD(btnPtr
->iBitmap
), LOWORD(btnPtr
->iBitmap
), infoPtr
->nNumBitmaps
);
475 if ((*index
= TOOLBAR_GetBitmapIndex(infoPtr
, btnPtr
)) < 0) {
476 if ((*index
== I_IMAGECALLBACK
) ||
477 (*index
== I_IMAGENONE
)) return NULL
;
478 ERR("TBN_GETDISPINFO returned invalid index %d\n",
485 case IMAGE_LIST_DEFAULT
:
486 himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
489 himl
= GETHOTIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
491 case IMAGE_LIST_DISABLED
:
492 himl
= GETDISIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
496 FIXME("Shouldn't reach here\n");
500 TRACE("no image list\n");
507 TOOLBAR_DrawFlatSeparator (const RECT
*lpRect
, HDC hdc
, const TOOLBAR_INFO
*infoPtr
)
510 COLORREF oldcolor
, newcolor
;
512 myrect
.left
= (lpRect
->left
+ lpRect
->right
) / 2 - 1;
513 myrect
.right
= myrect
.left
+ 1;
514 myrect
.top
= lpRect
->top
+ 2;
515 myrect
.bottom
= lpRect
->bottom
- 2;
517 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
518 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
519 oldcolor
= SetBkColor (hdc
, newcolor
);
520 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
522 myrect
.left
= myrect
.right
;
523 myrect
.right
= myrect
.left
+ 1;
525 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
526 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
527 SetBkColor (hdc
, newcolor
);
528 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
530 SetBkColor (hdc
, oldcolor
);
534 /***********************************************************************
535 * TOOLBAR_DrawFlatHorizontalSeparator
537 * This function draws horizontal separator for toolbars having CCS_VERT style.
538 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
539 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
540 * are horizontal as opposed to the vertical separators for not dropdown
543 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
546 TOOLBAR_DrawFlatHorizontalSeparator (const RECT
*lpRect
, HDC hdc
,
547 const TOOLBAR_INFO
*infoPtr
)
550 COLORREF oldcolor
, newcolor
;
552 myrect
.left
= lpRect
->left
;
553 myrect
.right
= lpRect
->right
;
554 myrect
.top
= lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
- 2)/2;
555 myrect
.bottom
= myrect
.top
+ 1;
557 InflateRect (&myrect
, -2, 0);
559 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect
));
561 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
562 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
563 oldcolor
= SetBkColor (hdc
, newcolor
);
564 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
566 myrect
.top
= myrect
.bottom
;
567 myrect
.bottom
= myrect
.top
+ 1;
569 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
570 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
571 SetBkColor (hdc
, newcolor
);
572 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
574 SetBkColor (hdc
, oldcolor
);
579 TOOLBAR_DrawArrow (HDC hdc
, INT left
, INT top
, COLORREF clr
)
584 if (!(hPen
= CreatePen( PS_SOLID
, 1, clr
))) return;
585 hOldPen
= SelectObject ( hdc
, hPen
);
588 MoveToEx (hdc
, x
, y
, NULL
);
589 LineTo (hdc
, x
+5, y
++); x
++;
590 MoveToEx (hdc
, x
, y
, NULL
);
591 LineTo (hdc
, x
+3, y
++); x
++;
592 MoveToEx (hdc
, x
, y
, NULL
);
593 LineTo (hdc
, x
+1, y
);
594 SelectObject( hdc
, hOldPen
);
595 DeleteObject( hPen
);
599 * Draw the text string for this button.
600 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
601 * is non-zero, so we can simply check himlDef to see if we have
605 TOOLBAR_DrawString (const TOOLBAR_INFO
*infoPtr
, RECT
*rcText
, LPCWSTR lpText
,
606 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
608 HDC hdc
= tbcd
->nmcd
.hdc
;
611 COLORREF clrOldBk
= 0;
613 UINT state
= tbcd
->nmcd
.uItemState
;
616 if (lpText
&& infoPtr
->nMaxTextRows
> 0) {
617 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText
),
618 wine_dbgstr_rect(rcText
));
620 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
621 if ((state
& CDIS_HOT
) && (dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)) {
622 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
624 else if (state
& CDIS_DISABLED
) {
625 clrOld
= SetTextColor (hdc
, tbcd
->clrBtnHighlight
);
626 OffsetRect (rcText
, 1, 1);
627 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
628 SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
629 OffsetRect (rcText
, -1, -1);
631 else if (state
& CDIS_INDETERMINATE
) {
632 clrOld
= SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
634 else if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
)) {
635 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
636 clrOldBk
= SetBkColor (hdc
, tbcd
->clrMark
);
637 oldBkMode
= SetBkMode (hdc
, tbcd
->nHLStringBkMode
);
640 clrOld
= SetTextColor (hdc
, tbcd
->clrText
);
643 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
644 SetTextColor (hdc
, clrOld
);
645 if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
))
647 SetBkColor (hdc
, clrOldBk
);
648 SetBkMode (hdc
, oldBkMode
);
650 SelectObject (hdc
, hOldFont
);
656 TOOLBAR_DrawPattern (const RECT
*lpRect
, const NMTBCUSTOMDRAW
*tbcd
)
658 HDC hdc
= tbcd
->nmcd
.hdc
;
659 HBRUSH hbr
= SelectObject (hdc
, tbcd
->hbrMonoDither
);
662 INT cx
= lpRect
->right
- lpRect
->left
;
663 INT cy
= lpRect
->bottom
- lpRect
->top
;
664 INT cxEdge
= GetSystemMetrics(SM_CXEDGE
);
665 INT cyEdge
= GetSystemMetrics(SM_CYEDGE
);
666 clrTextOld
= SetTextColor(hdc
, tbcd
->clrBtnHighlight
);
667 clrBkOld
= SetBkColor(hdc
, tbcd
->clrBtnFace
);
668 PatBlt (hdc
, lpRect
->left
+ cxEdge
, lpRect
->top
+ cyEdge
,
669 cx
- (2 * cxEdge
), cy
- (2 * cyEdge
), PATCOPY
);
670 SetBkColor(hdc
, clrBkOld
);
671 SetTextColor(hdc
, clrTextOld
);
672 SelectObject (hdc
, hbr
);
676 static void TOOLBAR_DrawMasked(HIMAGELIST himl
, int index
, HDC hdc
, INT x
, INT y
, UINT draw_flags
)
678 IMAGELISTDRAWPARAMS draw_params
= { 0 };
680 HBITMAP hbmMask
, hbmImage
;
681 HDC hdcMask
, hdcImage
;
683 ImageList_GetIconSize(himl
, &cx
, &cy
);
685 draw_params
.cbSize
= sizeof(draw_params
);
686 draw_params
.himl
= himl
;
687 draw_params
.i
= index
;
688 draw_params
.hdcDst
= hdc
;
693 draw_params
.rgbBk
= CLR_NONE
;
694 draw_params
.rgbFg
= CLR_NONE
;
695 draw_params
.fStyle
= draw_flags
;
696 draw_params
.fState
= ILS_NORMAL
;
698 /* 32bpp image with alpha channel is converted to grayscale */
699 if (imagelist_has_alpha(himl
, index
))
701 draw_params
.fState
= ILS_SATURATE
;
702 ImageList_DrawIndirect(&draw_params
);
706 /* Create src image */
707 hdcImage
= CreateCompatibleDC(hdc
);
708 hbmImage
= CreateCompatibleBitmap(hdc
, cx
, cy
);
709 SelectObject(hdcImage
, hbmImage
);
713 draw_params
.rgbBk
= RGB(0xff, 0xff, 0xff);
714 draw_params
.rgbFg
= RGB(0,0,0);
715 draw_params
.hdcDst
= hdcImage
;
716 ImageList_DrawIndirect(&draw_params
);
719 hdcMask
= CreateCompatibleDC(0);
720 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
721 SelectObject(hdcMask
, hbmMask
);
723 /* Remove the background and all white pixels */
724 draw_params
.fStyle
= ILD_MASK
;
725 draw_params
.hdcDst
= hdcMask
;
726 ImageList_DrawIndirect(&draw_params
);
727 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
728 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
730 /* draw the new mask 'etched' to hdc */
731 SetBkColor(hdc
, RGB(255, 255, 255));
732 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
733 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
734 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
735 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
736 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
739 DeleteObject(hbmImage
);
741 DeleteObject (hbmMask
);
747 TOOLBAR_TranslateState(const TBUTTON_INFO
*btnPtr
, BOOL captured
)
751 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
752 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
753 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
754 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
755 retstate
|= (btnPtr
->bHot
& !captured
) ? CDIS_HOT
: 0;
756 retstate
|= ((btnPtr
->fsState
& (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) == (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) ? CDIS_INDETERMINATE
: 0;
757 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
761 /* draws the image on a toolbar button */
763 TOOLBAR_DrawImage(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
,
764 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
766 HIMAGELIST himl
= NULL
;
767 BOOL draw_masked
= FALSE
;
770 UINT draw_flags
= ILD_TRANSPARENT
;
772 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
774 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
777 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
781 else if (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
||
782 ((tbcd
->nmcd
.uItemState
& CDIS_HOT
)
783 && ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))))
785 /* if hot, attempt to draw with hot image list, if fails,
786 use default image list */
787 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
789 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
792 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
797 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
798 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
801 if (!(dwItemCDFlag
& TBCDRF_NOMARK
) &&
802 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
803 draw_flags
|= ILD_BLEND50
;
805 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
806 index
, himl
, left
, top
, offset
);
809 TOOLBAR_DrawMasked (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
811 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
814 /* draws a blank frame for a toolbar button */
816 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, const RECT
*rect
, DWORD dwItemCDFlag
)
818 HDC hdc
= tbcd
->nmcd
.hdc
;
820 /* if the state is disabled or indeterminate then the button
821 * cannot have an interactive look like pressed or hot */
822 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
823 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
824 BOOL pressed_look
= !non_interactive_state
&&
825 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
826 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
828 /* app don't want us to draw any edges */
829 if (dwItemCDFlag
& TBCDRF_NOEDGES
)
832 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
835 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
836 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
837 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
842 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
844 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
845 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
850 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
, BOOL bDropDownPressed
, DWORD dwItemCDFlag
)
852 HDC hdc
= tbcd
->nmcd
.hdc
;
854 BOOL pressed
= bDropDownPressed
||
855 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
));
857 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
860 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
);
861 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
862 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
863 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
864 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
869 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
871 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
872 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
876 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
878 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
880 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
881 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
884 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
887 /* draws a complete toolbar button */
889 TOOLBAR_DrawButton (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, HDC hdc
, DWORD dwBaseCustDraw
)
891 DWORD dwStyle
= infoPtr
->dwStyle
;
892 BOOL hasDropDownArrow
= button_has_ddarrow( infoPtr
, btnPtr
);
893 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
894 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
895 RECT rc
, rcArrow
, rcBitmap
, rcText
;
896 LPWSTR lpText
= NULL
;
901 DWORD dwItemCustDraw
;
903 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
908 /* separator - doesn't send NM_CUSTOMDRAW */
909 if (btnPtr
->fsStyle
& BTNS_SEP
) {
912 DrawThemeBackground (theme
, hdc
,
913 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
917 /* with the FLAT style, iBitmap is the width and has already */
918 /* been taken into consideration in calculating the width */
919 /* so now we need to draw the vertical separator */
920 /* empirical tests show that iBitmap can/will be non-zero */
921 /* when drawing the vertical bar... */
922 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
923 if (dwStyle
& CCS_VERT
) {
925 InflateRect(&rcsep
, -infoPtr
->szPadding
.cx
, -infoPtr
->szPadding
.cy
);
926 TOOLBAR_DrawFlatHorizontalSeparator (&rcsep
, hdc
, infoPtr
);
929 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
931 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
932 FIXME("Draw some kind of separator: fsStyle=%x\n",
938 /* get a pointer to the text */
939 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
941 if (hasDropDownArrow
)
945 if (dwStyle
& TBSTYLE_FLAT
)
946 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
948 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
950 if (drawSepDropDownArrow
)
953 rcArrow
.left
= right
;
956 /* copy text & bitmap rects after adjusting for drop-down arrow
957 * so that text & bitmap is centered in the rectangle not containing
962 /* Center the bitmap horizontally and vertically */
963 if (dwStyle
& TBSTYLE_LIST
)
966 infoPtr
->nMaxTextRows
> 0 &&
967 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
968 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
969 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
971 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
974 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
976 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
978 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
979 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
980 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
981 TRACE("Text=%s\n", debugstr_w(lpText
));
982 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
984 /* calculate text position */
987 InflateRect(&rcText
, -GetSystemMetrics(SM_CXEDGE
), 0);
988 if (dwStyle
& TBSTYLE_LIST
)
990 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
994 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
995 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
997 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
1001 /* Initialize fields in all cases, because we use these later
1002 * NOTE: applications can and do alter these to customize their
1004 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1005 tbcd
.clrText
= comctl32_color
.clrBtnText
;
1006 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
1007 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
1008 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
1009 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
1010 tbcd
.clrHighlightHotTrack
= 0;
1011 tbcd
.nStringBkMode
= TRANSPARENT
;
1012 tbcd
.nHLStringBkMode
= OPAQUE
;
1013 tbcd
.rcText
.left
= 0;
1014 tbcd
.rcText
.top
= 0;
1015 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
1016 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
1017 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
, infoPtr
->bCaptured
);
1018 tbcd
.nmcd
.hdc
= hdc
;
1019 tbcd
.nmcd
.rc
= btnPtr
->rect
;
1020 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
1022 /* FIXME: what are these used for? */
1026 /* Issue Item Prepaint notify */
1029 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
1031 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
1032 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
1033 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
1034 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1035 /* reset these fields so the user can't alter the behaviour like native */
1036 tbcd
.nmcd
.hdc
= hdc
;
1037 tbcd
.nmcd
.rc
= btnPtr
->rect
;
1039 dwItemCustDraw
= ntfret
& 0xffff;
1040 dwItemCDFlag
= ntfret
& 0xffff0000;
1041 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
1043 /* save the only part of the rect that the user can change */
1044 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
1045 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
1048 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
1049 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
1050 OffsetRect(&rcText
, 1, 1);
1052 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
1053 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
1054 TOOLBAR_DrawPattern (&rc
, &tbcd
);
1056 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
1057 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
1059 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
1063 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
1064 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
1065 if (hasDropDownArrow
)
1066 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
1067 SetBkColor(hdc
, oldclr
);
1073 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
1074 int stateId
= TS_NORMAL
;
1076 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1077 stateId
= TS_DISABLED
;
1078 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1079 stateId
= TS_PRESSED
;
1080 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1081 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1082 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1083 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1086 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &rc
, NULL
);
1089 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, &rc
, dwItemCDFlag
);
1091 if (drawSepDropDownArrow
)
1095 int stateId
= TS_NORMAL
;
1097 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1098 stateId
= TS_DISABLED
;
1099 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1100 stateId
= TS_PRESSED
;
1101 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1102 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1103 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1106 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1107 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1110 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1113 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1114 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1115 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1116 SetBkMode (hdc
, oldBkMode
);
1118 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1120 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1122 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1124 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1125 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1127 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1129 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1130 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1133 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1136 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1138 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1139 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1146 TOOLBAR_Refresh (TOOLBAR_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
1148 TBUTTON_INFO
*btnPtr
;
1150 RECT rcTemp
, rcClient
;
1151 NMTBCUSTOMDRAW tbcd
;
1153 DWORD dwBaseCustDraw
;
1155 /* the app has told us not to redraw the toolbar */
1156 if (!infoPtr
->bDoRedraw
)
1159 /* if imagelist belongs to the app, it can be changed
1160 by the app after setting it */
1161 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1163 infoPtr
->nNumBitmaps
= 0;
1164 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1165 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1168 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1170 /* change the imagelist icon size if we manage the list and it is necessary */
1171 TOOLBAR_CheckImageListIconSize(infoPtr
);
1173 /* Send initial notify */
1174 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1175 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1176 tbcd
.nmcd
.hdc
= hdc
;
1177 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1178 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1179 dwBaseCustDraw
= ntfret
& 0xffff;
1181 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1183 /* redraw necessary buttons */
1184 btnPtr
= infoPtr
->buttons
;
1185 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1188 if (!RectVisible(hdc
, &btnPtr
->rect
))
1190 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1192 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1193 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1197 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1198 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1200 TOOLBAR_DrawButton(infoPtr
, btnPtr
, hdc
, dwBaseCustDraw
);
1203 /* draw insert mark if required */
1204 if (infoPtr
->tbim
.iButton
!= -1)
1206 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1208 rcInsertMark
.top
= rcButton
.top
;
1209 rcInsertMark
.bottom
= rcButton
.bottom
;
1210 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1211 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1213 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1214 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1217 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1219 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1220 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1221 tbcd
.nmcd
.hdc
= hdc
;
1222 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1223 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1227 /***********************************************************************
1228 * TOOLBAR_MeasureString
1230 * This function gets the width and height of a string in pixels. This
1231 * is done first by using GetTextExtentPoint to get the basic width
1232 * and height. The DrawText is called with DT_CALCRECT to get the exact
1233 * width. The reason is because the text may have more than one "&" (or
1234 * prefix characters as M$ likes to call them). The prefix character
1235 * indicates where the underline goes, except for the string "&&" which
1236 * is reduced to a single "&". GetTextExtentPoint does not process these
1237 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1240 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1241 HDC hdc
, LPSIZE lpSize
)
1248 if (infoPtr
->nMaxTextRows
> 0 &&
1249 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1250 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1251 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1253 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1255 if(lpText
!= NULL
) {
1256 /* first get size of all the text */
1257 GetTextExtentPoint32W (hdc
, lpText
, lstrlenW (lpText
), lpSize
);
1259 /* feed above size into the rectangle for DrawText */
1260 SetRect(&myrect
, 0, 0, lpSize
->cx
, lpSize
->cy
);
1262 /* Use DrawText to get true size as drawn (less pesky "&") */
1263 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1264 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1267 /* feed back to caller */
1268 lpSize
->cx
= myrect
.right
;
1269 lpSize
->cy
= myrect
.bottom
;
1273 TRACE("string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1276 /***********************************************************************
1277 * TOOLBAR_CalcStrings
1279 * This function walks through each string and measures it and returns
1280 * the largest height and width to caller.
1283 TOOLBAR_CalcStrings (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
1285 TBUTTON_INFO
*btnPtr
;
1294 if (infoPtr
->nMaxTextRows
== 0)
1297 hdc
= GetDC (infoPtr
->hwndSelf
);
1298 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1300 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1304 GetTextMetricsW(hdc
, &tm
);
1305 lpSize
->cy
= tm
.tmHeight
;
1308 btnPtr
= infoPtr
->buttons
;
1309 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1310 if(TOOLBAR_GetText(infoPtr
, btnPtr
))
1312 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1313 if (sz
.cx
> lpSize
->cx
)
1315 if (sz
.cy
> lpSize
->cy
)
1320 SelectObject (hdc
, hOldFont
);
1321 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1323 TRACE("max string size %d x %d\n", lpSize
->cx
, lpSize
->cy
);
1326 /***********************************************************************
1327 * TOOLBAR_WrapToolbar
1329 * This function walks through the buttons and separators in the
1330 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1331 * wrapping should occur based on the width of the toolbar window.
1332 * It does *not* calculate button placement itself. That task
1333 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1334 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1335 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1337 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_VERTICAL can be used also to allow
1338 * vertical toolbar lists.
1342 TOOLBAR_WrapToolbar(TOOLBAR_INFO
*infoPtr
)
1344 TBUTTON_INFO
*btnPtr
;
1345 INT x
, cx
, i
, j
, width
;
1348 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1349 /* no layout is necessary. Applications may use this style */
1350 /* to perform their own layout on the toolbar. */
1351 if( !(infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) &&
1352 !(infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
) ) return;
1354 btnPtr
= infoPtr
->buttons
;
1355 x
= infoPtr
->nIndent
;
1356 width
= infoPtr
->client_rect
.right
- infoPtr
->client_rect
.left
;
1358 bButtonWrap
= FALSE
;
1360 TRACE("start ButtonWidth=%d, BitmapWidth=%d, width=%d, nIndent=%d\n",
1361 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, width
,
1364 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1366 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1368 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1371 if (btnPtr
[i
].cx
> 0)
1373 /* horizontal separators are treated as buttons for width */
1374 else if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1375 !(infoPtr
->dwStyle
& CCS_VERT
))
1376 cx
= (btnPtr
[i
].iBitmap
> 0) ? btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1378 cx
= infoPtr
->nButtonWidth
;
1380 if (!btnPtr
[i
].cx
&& button_has_ddarrow( infoPtr
, btnPtr
+ i
))
1381 cx
+= DDARROW_WIDTH
;
1383 /* Two or more adjacent separators form a separator group. */
1384 /* The first separator in a group should be wrapped to the */
1385 /* next row if the previous wrapping is on a button. */
1387 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1388 (i
+ 1 < infoPtr
->nNumButtons
) &&
1389 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1391 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1392 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1393 x
= infoPtr
->nIndent
;
1395 bButtonWrap
= FALSE
;
1399 /* The layout makes sure the bitmap is visible, but not the button. */
1400 /* Test added to also wrap after a button that starts a row but */
1401 /* is bigger than the area. - GA 8/01 */
1402 if ((x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2 > width
) ||
1403 ((x
== infoPtr
->nIndent
) && (cx
> width
)))
1405 BOOL bFound
= FALSE
;
1407 /* If the current button is a separator and not hidden, */
1408 /* go to the next until it reaches a non separator. */
1409 /* Wrap the last separator if it is before a button. */
1410 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1411 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1412 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1413 i
< infoPtr
->nNumButtons
)
1419 if( bFound
&& i
< infoPtr
->nNumButtons
)
1422 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1423 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1424 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1425 x
= infoPtr
->nIndent
;
1426 bButtonWrap
= FALSE
;
1429 else if ( i
>= infoPtr
->nNumButtons
)
1432 /* If the current button is not a separator, find the last */
1433 /* separator and wrap it. */
1434 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1436 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1437 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1441 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1442 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1443 x
= infoPtr
->nIndent
;
1444 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1445 bButtonWrap
= FALSE
;
1450 /* If no separator available for wrapping, wrap one of */
1451 /* non-hidden previous button. */
1455 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1457 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1462 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1463 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1464 x
= infoPtr
->nIndent
;
1465 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1471 /* If all above failed, wrap the current button. */
1474 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1475 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1476 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1477 x
= infoPtr
->nIndent
;
1478 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1479 bButtonWrap
= FALSE
;
1485 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1486 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1493 /***********************************************************************
1494 * TOOLBAR_MeasureButton
1496 * Calculates the width and height required for a button. Used in
1497 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1498 * the width of buttons that are autosized.
1500 * Note that it would have been rather elegant to use one piece of code for
1501 * both the laying out of the toolbar and for controlling where button parts
1502 * are drawn, but the native control has inconsistencies between the two that
1503 * prevent this from being effectively. These inconsistencies can be seen as
1504 * artefacts where parts of the button appear outside of the bounding button
1507 * There are several cases for the calculation of the button dimensions and
1508 * button part positioning:
1515 * +--------------------------------------------------------+ ^
1517 * | | pad.cy / 2 | centered | |
1518 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1519 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1520 * | |<------------>| | | | |
1521 * | +--------------+ +------------+ | |
1522 * |<-------------------------------------->| | |
1523 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1525 * +--------------------------------------------------------+ -
1526 * <-------------------------------------------------------->
1527 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1529 * Without Bitmap (I_IMAGENONE):
1531 * +-----------------------------------+ ^
1533 * | | centered | | LISTPAD_CY +
1534 * | +------------+ | | szText.cy
1537 * | +------------+ | |
1538 * |<----------------->| | |
1539 * | cxedge |<-----------> | |
1541 * +-----------------------------------+ -
1542 * <----------------------------------->
1543 * szText.cx + pad.cx
1547 * +--------------------------------------+ ^
1549 * | | padding.cy/2 | | DEFPAD_CY +
1550 * | +------------+ | | nBitmapHeight
1553 * | +------------+ | |
1554 * |<------------------->| | |
1555 * | cxedge + iListGap/2 |<-----------> | |
1556 * | nBitmapWidth | |
1557 * +--------------------------------------+ -
1558 * <-------------------------------------->
1559 * 2*cxedge + nBitmapWidth + iListGap
1566 * +-----------------------------------+ ^
1568 * | | pad.cy / 2 | | nBitmapHeight +
1569 * | - | | szText.cy +
1570 * | +------------+ | | DEFPAD_CY + 1
1571 * | centered | Bitmap | | |
1572 * |<----------------->| | | |
1573 * | +------------+ | |
1577 * | centered +---------------+ | |
1578 * |<--------------->| Text | | |
1579 * | +---------------+ | |
1580 * +-----------------------------------+ -
1581 * <----------------------------------->
1582 * pad.cx + max(nBitmapWidth, szText.cx)
1584 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1586 * +---------------------------------------+ ^
1588 * | | 2 + pad.cy / 2 | |
1589 * | - | | szText.cy +
1590 * | centered +-----------------+ | | pad.cy + 2
1591 * |<--------------->| Text | | |
1592 * | +-----------------+ | |
1594 * +---------------------------------------+ -
1595 * <--------------------------------------->
1596 * 2*cxedge + pad.cx + szText.cx
1599 * As for with bitmaps, but with szText.cx zero.
1601 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1602 BOOL bHasBitmap
, BOOL bValidImageList
)
1605 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1607 /* set button height from bitmap / text height... */
1608 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1611 /* ... add on the necessary padding */
1612 if (bValidImageList
)
1615 sizeButton
.cy
+= DEFPAD_CY
;
1617 sizeButton
.cy
+= LISTPAD_CY
;
1620 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1622 /* calculate button width */
1623 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1624 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1625 if (sizeString
.cx
> 0)
1626 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1633 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1634 if (sizeString
.cy
> 0)
1635 sizeButton
.cy
+= 1 + sizeString
.cy
;
1636 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1637 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1641 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1642 NONLIST_NOTEXT_OFFSET
;
1643 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1644 max(2*GetSystemMetrics(SM_CXEDGE
) + sizeString
.cx
, infoPtr
->nBitmapWidth
);
1651 /***********************************************************************
1652 * TOOLBAR_CalcToolbar
1654 * This function calculates button and separator placement. It first
1655 * calculates the button sizes, gets the toolbar window width and then
1656 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1657 * on. It assigns a new location to each item and sends this location to
1658 * the tooltip window if appropriate. Finally, it updates the rcBound
1659 * rect and calculates the new required toolbar window height.
1662 TOOLBAR_CalcToolbar (TOOLBAR_INFO
*infoPtr
)
1664 SIZE sizeString
, sizeButton
;
1665 BOOL validImageList
= FALSE
;
1667 TOOLBAR_CalcStrings (infoPtr
, &sizeString
);
1669 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1671 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1672 validImageList
= TRUE
;
1673 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1674 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1675 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1676 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1678 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1679 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1680 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1681 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1683 TOOLBAR_LayoutToolbar(infoPtr
);
1687 TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
)
1689 TBUTTON_INFO
*btnPtr
;
1691 INT i
, nRows
, nSepRows
;
1694 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1696 TOOLBAR_WrapToolbar(infoPtr
);
1698 x
= infoPtr
->nIndent
;
1699 y
= infoPtr
->iTopMargin
;
1700 cx
= infoPtr
->nButtonWidth
;
1701 cy
= infoPtr
->nButtonHeight
;
1703 nRows
= nSepRows
= 0;
1705 infoPtr
->rcBound
.top
= y
;
1706 infoPtr
->rcBound
.left
= x
;
1707 infoPtr
->rcBound
.bottom
= y
+ cy
;
1708 infoPtr
->rcBound
.right
= x
;
1710 btnPtr
= infoPtr
->buttons
;
1712 TRACE("cy=%d\n", cy
);
1714 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1717 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1719 SetRectEmpty (&btnPtr
->rect
);
1720 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1724 cy
= infoPtr
->nButtonHeight
;
1726 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1727 if (infoPtr
->dwStyle
& CCS_VERT
) {
1728 cy
= (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1729 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
: infoPtr
->nButtonWidth
;
1732 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
:
1733 (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1739 else if (btnPtr
->fsStyle
& BTNS_AUTOSIZE
)
1745 hdc
= GetDC (infoPtr
->hwndSelf
);
1746 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1748 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1750 SelectObject (hdc
, hOldFont
);
1751 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1753 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1754 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1759 cx
= infoPtr
->nButtonWidth
;
1761 /* if size has been set manually then don't add on extra space
1762 * for the drop down arrow */
1763 if (!btnPtr
->cx
&& button_has_ddarrow( infoPtr
, btnPtr
))
1764 cx
+= DDARROW_WIDTH
;
1766 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1769 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1771 if (infoPtr
->rcBound
.left
> x
)
1772 infoPtr
->rcBound
.left
= x
;
1773 if (infoPtr
->rcBound
.right
< x
+ cx
)
1774 infoPtr
->rcBound
.right
= x
+ cx
;
1775 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1776 infoPtr
->rcBound
.bottom
= y
+ cy
;
1778 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1780 /* btnPtr->nRow is zero based. The space between the rows is */
1781 /* also considered as a row. */
1782 btnPtr
->nRow
= nRows
+ nSepRows
;
1784 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1785 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1790 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1794 if ( !(infoPtr
->dwStyle
& CCS_VERT
))
1795 y
+= cy
+ ( (btnPtr
->cx
> 0 ) ?
1796 btnPtr
->cx
: SEPARATOR_WIDTH
) * 2 /3;
1800 /* nSepRows is used to calculate the extra height following */
1804 x
= infoPtr
->nIndent
;
1806 /* Increment row number unless this is the last button */
1807 /* and it has Wrap set. */
1808 if (i
!= infoPtr
->nNumButtons
-1)
1815 /* infoPtr->nRows is the number of rows on the toolbar */
1816 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1818 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1823 TOOLBAR_InternalHitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
*lpPt
, BOOL
*button
)
1825 TBUTTON_INFO
*btnPtr
;
1831 btnPtr
= infoPtr
->buttons
;
1832 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1833 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1836 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1837 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1838 TRACE(" ON SEPARATOR %d\n", i
);
1843 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1844 TRACE(" ON BUTTON %d\n", i
);
1852 TRACE(" NOWHERE\n");
1853 return TOOLBAR_NOWHERE
;
1857 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1859 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO
*infoPtr
, INT iIndex
, UINT nAddButtons
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
1861 INT nOldButtons
, nNewButtons
, iButton
;
1862 BOOL fHasString
= FALSE
;
1864 if (iIndex
< 0) /* iIndex can be negative, what means adding at the end */
1865 iIndex
= infoPtr
->nNumButtons
;
1867 nOldButtons
= infoPtr
->nNumButtons
;
1868 nNewButtons
= nOldButtons
+ nAddButtons
;
1870 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
1871 memmove(&infoPtr
->buttons
[iIndex
+ nAddButtons
], &infoPtr
->buttons
[iIndex
],
1872 (nOldButtons
- iIndex
) * sizeof(TBUTTON_INFO
));
1873 infoPtr
->nNumButtons
+= nAddButtons
;
1875 /* insert new buttons data */
1876 for (iButton
= 0; iButton
< nAddButtons
; iButton
++) {
1877 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[iIndex
+ iButton
];
1880 TOOLBAR_DumpTBButton(lpTbb
+ iButton
, fUnicode
);
1882 ZeroMemory(btnPtr
, sizeof(*btnPtr
));
1884 btnPtr
->iBitmap
= lpTbb
[iButton
].iBitmap
;
1885 btnPtr
->idCommand
= lpTbb
[iButton
].idCommand
;
1886 btnPtr
->fsState
= lpTbb
[iButton
].fsState
;
1887 btnPtr
->fsStyle
= lpTbb
[iButton
].fsStyle
;
1888 btnPtr
->dwData
= lpTbb
[iButton
].dwData
;
1890 if (btnPtr
->fsStyle
& BTNS_SEP
)
1893 str
= lpTbb
[iButton
].iString
;
1894 set_string_index( btnPtr
, str
, fUnicode
);
1895 fHasString
|= TOOLBAR_ButtonHasString( btnPtr
);
1897 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
1900 if (infoPtr
->nNumStrings
> 0 || fHasString
)
1901 TOOLBAR_CalcToolbar(infoPtr
);
1903 TOOLBAR_LayoutToolbar(infoPtr
);
1904 TOOLBAR_AutoSize(infoPtr
);
1906 TOOLBAR_DumpToolbar(infoPtr
, __LINE__
);
1907 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1913 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1915 TBUTTON_INFO
*btnPtr
;
1918 if (CommandIsIndex
) {
1919 TRACE("command is really index command=%d\n", idCommand
);
1920 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1923 btnPtr
= infoPtr
->buttons
;
1924 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1925 if (btnPtr
->idCommand
== idCommand
) {
1926 TRACE("command=%d index=%d\n", idCommand
, i
);
1930 TRACE("no index found for command=%d\n", idCommand
);
1936 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1938 TBUTTON_INFO
*btnPtr
;
1941 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1944 /* check index button */
1945 btnPtr
= &infoPtr
->buttons
[nIndex
];
1946 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1947 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1951 /* check previous buttons */
1952 nRunIndex
= nIndex
- 1;
1953 while (nRunIndex
>= 0) {
1954 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1955 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1956 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1964 /* check next buttons */
1965 nRunIndex
= nIndex
+ 1;
1966 while (nRunIndex
< infoPtr
->nNumButtons
) {
1967 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1968 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1969 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1982 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1983 WPARAM wParam
, LPARAM lParam
)
1989 msg
.wParam
= wParam
;
1990 msg
.lParam
= lParam
;
1991 msg
.time
= GetMessageTime ();
1992 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
1993 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
1995 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1999 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2001 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
2004 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
2005 ti
.cbSize
= sizeof (TTTOOLINFOW
);
2006 ti
.hwnd
= infoPtr
->hwndSelf
;
2007 ti
.uId
= button
->idCommand
;
2009 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
2010 /* ti.lParam = random value from the stack? */
2012 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
2018 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2020 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
2023 ZeroMemory(&ti
, sizeof(ti
));
2024 ti
.cbSize
= sizeof(ti
);
2025 ti
.hwnd
= infoPtr
->hwndSelf
;
2026 ti
.uId
= button
->idCommand
;
2028 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
2032 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2034 /* Set the toolTip only for non-hidden, non-separator button */
2035 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
2039 ZeroMemory(&ti
, sizeof(ti
));
2040 ti
.cbSize
= sizeof(ti
);
2041 ti
.hwnd
= infoPtr
->hwndSelf
;
2042 ti
.uId
= button
->idCommand
;
2043 ti
.rect
= button
->rect
;
2044 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
2048 /* Creates the tooltip control */
2050 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
2053 NMTOOLTIPSCREATED nmttc
;
2055 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
2056 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2057 infoPtr
->hwndSelf
, 0, 0, 0);
2059 if (!infoPtr
->hwndToolTip
)
2062 /* Send NM_TOOLTIPSCREATED notification */
2063 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
2064 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
2066 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
2068 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
2069 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
2073 /* keeps available button list box sorted by button id */
2074 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
2078 PCUSTOMBUTTON btnInfo
;
2079 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2081 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
2083 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2085 /* position 0 is always separator */
2086 for (i
= 1; i
< count
; i
++)
2088 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2089 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2091 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2092 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2096 /* id higher than all others add to end */
2097 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2098 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2101 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2105 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2107 if (nIndexFrom
== nIndexTo
)
2110 /* MSDN states that iItem is the index of the button, rather than the
2111 * command ID as used by every other NMTOOLBAR notification */
2112 nmtb
.iItem
= nIndexFrom
;
2113 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2115 PCUSTOMBUTTON btnInfo
;
2117 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2118 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2120 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2122 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2123 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2124 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2125 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2128 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2130 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2132 /* last item is always separator, so -2 instead of -1 */
2133 if (nIndexTo
>= (count
- 2))
2134 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2136 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2138 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2139 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2141 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2145 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2149 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2151 /* MSDN states that iItem is the index of the button, rather than the
2152 * command ID as used by every other NMTOOLBAR notification */
2153 nmtb
.iItem
= nIndexAvail
;
2154 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2156 PCUSTOMBUTTON btnInfo
;
2158 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2159 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2160 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2162 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2164 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2166 /* remove from 'available buttons' list */
2167 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2168 if (nIndexAvail
== count
-1)
2169 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2171 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2175 PCUSTOMBUTTON btnNew
;
2177 /* duplicate 'separator' button */
2178 btnNew
= Alloc(sizeof(CUSTOMBUTTON
));
2183 /* insert into 'toolbar button' list */
2184 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2185 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2187 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2189 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2193 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2195 PCUSTOMBUTTON btnInfo
;
2196 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2198 TRACE("Remove: index %d\n", index
);
2200 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2202 /* send TBN_QUERYDELETE notification */
2203 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2207 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2208 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2210 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2212 /* insert into 'available button' list */
2213 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2214 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2218 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2222 /* drag list notification function for toolbar buttons list box */
2223 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2224 const DRAGLISTINFO
*pDLI
)
2226 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2227 switch (pDLI
->uNotification
)
2231 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2232 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2233 /* no dragging for last item (separator) */
2234 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2239 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2240 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2241 /* no dragging past last item (separator) */
2242 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2244 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2245 /* FIXME: native uses "move button" cursor */
2246 return DL_COPYCURSOR
;
2249 /* not over toolbar buttons list */
2250 if (nCurrentItem
< 0)
2252 POINT ptWindow
= pDLI
->ptCursor
;
2253 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2254 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2255 /* over available buttons list? */
2256 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2257 /* FIXME: native uses "move button" cursor */
2258 return DL_COPYCURSOR
;
2260 /* clear drag arrow */
2261 DrawInsert(hwnd
, hwndList
, -1);
2262 return DL_STOPCURSOR
;
2266 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2267 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2268 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2269 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2271 /* clear drag arrow */
2272 DrawInsert(hwnd
, hwndList
, -1);
2274 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2276 /* not over toolbar buttons list */
2279 POINT ptWindow
= pDLI
->ptCursor
;
2280 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2281 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2282 /* over available buttons list? */
2283 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2284 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2289 /* Clear drag arrow */
2290 DrawInsert(hwnd
, hwndList
, -1);
2297 /* drag list notification function for available buttons list box */
2298 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2299 const DRAGLISTINFO
*pDLI
)
2301 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2302 switch (pDLI
->uNotification
)
2308 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2309 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2310 /* no dragging past last item (separator) */
2311 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2313 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2314 /* FIXME: native uses "move button" cursor */
2315 return DL_COPYCURSOR
;
2318 /* not over toolbar buttons list */
2319 if (nCurrentItem
< 0)
2321 POINT ptWindow
= pDLI
->ptCursor
;
2322 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2323 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2324 /* over available buttons list? */
2325 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2326 /* FIXME: native uses "move button" cursor */
2327 return DL_COPYCURSOR
;
2329 /* clear drag arrow */
2330 DrawInsert(hwnd
, hwndList
, -1);
2331 return DL_STOPCURSOR
;
2335 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2336 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2337 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2338 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2340 /* clear drag arrow */
2341 DrawInsert(hwnd
, hwndList
, -1);
2343 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2347 /* Clear drag arrow */
2348 DrawInsert(hwnd
, hwndList
, -1);
2354 extern UINT uDragListMessage DECLSPEC_HIDDEN
;
2356 /***********************************************************************
2357 * TOOLBAR_CustomizeDialogProc
2358 * This function implements the toolbar customization dialog.
2360 static INT_PTR CALLBACK
2361 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2363 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2364 PCUSTOMBUTTON btnInfo
;
2366 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2371 custInfo
= (PCUSTDLG_INFO
)lParam
;
2372 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2379 NMTBINITCUSTOMIZE nmtbic
;
2381 infoPtr
= custInfo
->tbInfo
;
2383 /* send TBN_QUERYINSERT notification */
2384 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2386 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2389 nmtbic
.hwndDialog
= hwnd
;
2390 /* Send TBN_INITCUSTOMIZE notification */
2391 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2394 TRACE("TBNRF_HIDEHELP requested\n");
2395 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2398 /* add items to 'toolbar buttons' list and check if removable */
2399 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2401 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2402 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2403 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2404 btnInfo
->bVirtual
= FALSE
;
2405 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2407 /* send TBN_QUERYDELETE notification */
2408 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2410 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2411 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2414 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2416 /* insert separator button into 'available buttons' list */
2417 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2418 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2419 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2420 btnInfo
->bVirtual
= FALSE
;
2421 btnInfo
->bRemovable
= TRUE
;
2422 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2423 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2424 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2426 /* insert all buttons into dsa */
2429 /* send TBN_GETBUTTONINFO notification */
2432 nmtb
.pszText
= Buffer
;
2435 /* Clear previous button's text */
2436 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2438 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2441 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2442 nmtb
.tbButton
.fsStyle
, i
,
2443 nmtb
.tbButton
.idCommand
,
2444 nmtb
.tbButton
.iString
,
2445 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2448 /* insert button into the appropriate list */
2449 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2452 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2453 btnInfo
->bVirtual
= FALSE
;
2454 btnInfo
->bRemovable
= TRUE
;
2458 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2459 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2462 btnInfo
->btn
= nmtb
.tbButton
;
2463 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2466 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2467 else if (nmtb
.tbButton
.iString
>= 0 &&
2468 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2470 lstrcpyW(btnInfo
->text
,
2471 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2476 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2479 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2481 /* select first item in the 'available' list */
2482 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2484 /* append 'virtual' separator button to the 'toolbar buttons' list */
2485 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2486 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2487 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2488 btnInfo
->bVirtual
= TRUE
;
2489 btnInfo
->bRemovable
= FALSE
;
2490 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2491 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2492 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2494 /* select last item in the 'toolbar' list */
2495 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2496 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2498 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2499 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2501 /* set focus and disable buttons */
2502 PostMessageW (hwnd
, WM_USER
, 0, 0);
2507 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2508 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2509 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2510 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2514 EndDialog(hwnd
, FALSE
);
2518 switch (LOWORD(wParam
))
2520 case IDC_TOOLBARBTN_LBOX
:
2521 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2523 PCUSTOMBUTTON btnInfo
;
2528 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2529 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2531 /* send TBN_QUERYINSERT notification */
2533 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2535 /* get list box item */
2536 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2538 if (index
== (count
- 1))
2540 /* last item (virtual separator) */
2541 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2542 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2544 else if (index
== (count
- 2))
2546 /* second last item (last non-virtual item) */
2547 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2548 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2550 else if (index
== 0)
2553 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2554 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2558 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2559 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2562 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2566 case IDC_MOVEUP_BTN
:
2568 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2569 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2573 case IDC_MOVEDN_BTN
: /* move down */
2575 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2576 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2580 case IDC_REMOVE_BTN
: /* remove button */
2582 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2584 if (LB_ERR
== index
)
2587 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2591 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2594 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2597 case IDOK
: /* Add button */
2602 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2603 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2605 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2610 EndDialog(hwnd
, FALSE
);
2620 /* delete items from 'toolbar buttons' listbox*/
2621 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2622 for (i
= 0; i
< count
; i
++)
2624 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2626 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2628 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2631 /* delete items from 'available buttons' listbox*/
2632 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2633 for (i
= 0; i
< count
; i
++)
2635 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2637 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2639 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2644 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2646 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2651 COLORREF oldText
= 0;
2655 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, lpdis
->itemID
, 0);
2656 if (btnInfo
== NULL
)
2658 FIXME("btnInfo invalid\n");
2662 /* set colors and select objects */
2663 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2664 if (btnInfo
->bVirtual
)
2665 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2667 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2668 hPen
= CreatePen( PS_SOLID
, 1,
2669 (lpdis
->itemState
& ODS_SELECTED
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2670 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2671 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2673 /* fill background rectangle */
2674 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2675 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2677 /* calculate button and text rectangles */
2678 rcButton
= lpdis
->rcItem
;
2679 InflateRect (&rcButton
, -1, -1);
2681 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2682 rcText
.left
= rcButton
.right
+ 2;
2684 /* draw focus rectangle */
2685 if (lpdis
->itemState
& ODS_FOCUS
)
2686 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2689 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2690 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2692 /* draw image and text */
2693 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2694 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2695 btnInfo
->btn
.iBitmap
));
2696 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2697 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2699 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2700 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2702 /* delete objects and reset colors */
2703 SelectObject (lpdis
->hDC
, hOldBrush
);
2704 SelectObject (lpdis
->hDC
, hOldPen
);
2705 SetBkColor (lpdis
->hDC
, oldBk
);
2706 SetTextColor (lpdis
->hDC
, oldText
);
2707 DeleteObject( hPen
);
2712 case WM_MEASUREITEM
:
2713 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2715 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2717 lpmis
->itemHeight
= 15 + 8; /* default height */
2724 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2726 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2728 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2729 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2730 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2733 else if (wParam
== IDC_AVAILBTN_LBOX
)
2735 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2736 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2737 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2746 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2749 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2755 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2756 /* Add bitmaps to the default image list */
2757 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2758 hbmLoad
= CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2759 else if (bitmap
->hInst
== COMCTL32_hModule
)
2760 hbmLoad
= LoadImageW( bitmap
->hInst
, MAKEINTRESOURCEW(bitmap
->nID
),
2761 IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
2763 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2765 /* enlarge the bitmap if needed */
2766 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2767 if (bitmap
->hInst
!= COMCTL32_hModule
)
2768 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2770 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2771 DeleteObject(hbmLoad
);
2775 nCountAfter
= ImageList_GetImageCount(himlDef
);
2776 nAdded
= nCountAfter
- nCountBefore
;
2777 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2779 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2780 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2781 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2782 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2785 infoPtr
->nNumBitmaps
+= nAdded
;
2790 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2797 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2798 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2800 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2802 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2805 TRACE("Update icon size: %dx%d -> %dx%d\n",
2806 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2808 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2809 ILC_COLOR32
|ILC_MASK
, 8, 2);
2810 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2811 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2812 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2813 infoPtr
->himlInt
= himlNew
;
2815 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2816 ImageList_Destroy(himlDef
);
2819 /***********************************************************************
2820 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2824 TOOLBAR_AddBitmap (TOOLBAR_INFO
*infoPtr
, INT count
, const TBADDBITMAP
*lpAddBmp
)
2830 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr
->hwndSelf
, count
, lpAddBmp
);
2834 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2836 info
.hInst
= COMCTL32_hModule
;
2837 switch (lpAddBmp
->nID
)
2839 case IDB_STD_SMALL_COLOR
:
2842 info
.nID
= IDB_STD_SMALL
;
2844 case IDB_STD_LARGE_COLOR
:
2847 info
.nID
= IDB_STD_LARGE
;
2849 case IDB_VIEW_SMALL_COLOR
:
2852 info
.nID
= IDB_VIEW_SMALL
;
2854 case IDB_VIEW_LARGE_COLOR
:
2857 info
.nID
= IDB_VIEW_LARGE
;
2859 case IDB_HIST_SMALL_COLOR
:
2861 info
.nID
= IDB_HIST_SMALL
;
2863 case IDB_HIST_LARGE_COLOR
:
2865 info
.nID
= IDB_HIST_LARGE
;
2868 WARN("unknown bitmap id, %ld\n", lpAddBmp
->nID
);
2872 TRACE ("adding %d internal bitmaps\n", info
.nButtons
);
2874 /* Windows resize all the buttons to the size of a newly added standard image */
2875 if (lpAddBmp
->nID
& 1)
2877 /* large icons: 24x24. Will make the button 31x30 */
2878 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2882 /* small icons: 16x16. Will make the buttons 23x22 */
2883 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2886 TOOLBAR_CalcToolbar (infoPtr
);
2890 info
.nButtons
= count
;
2891 info
.hInst
= lpAddBmp
->hInst
;
2892 info
.nID
= lpAddBmp
->nID
;
2893 TRACE("adding %d bitmaps\n", info
.nButtons
);
2896 /* check if the bitmap is already loaded and compute iSumButtons */
2898 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2900 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2901 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2903 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2906 if (!infoPtr
->cimlDef
) {
2907 /* create new default image list */
2908 TRACE ("creating default image list\n");
2910 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2911 ILC_COLOR32
| ILC_MASK
, info
.nButtons
, 2);
2912 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2913 infoPtr
->himlInt
= himlDef
;
2916 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2920 WARN("No default image list available\n");
2924 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2927 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2928 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2929 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2930 infoPtr
->nNumBitmapInfos
++;
2931 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2933 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2939 TOOLBAR_AddButtonsT(TOOLBAR_INFO
*infoPtr
, INT nAddButtons
, const TBBUTTON
* lpTbb
, BOOL fUnicode
)
2941 TRACE("adding %d buttons (unicode=%d)\n", nAddButtons
, fUnicode
);
2943 return TOOLBAR_InternalInsertButtonsT(infoPtr
, -1, nAddButtons
, lpTbb
, fUnicode
);
2948 TOOLBAR_AddStringW (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
2950 #define MAX_RESOURCE_STRING_LENGTH 512
2951 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2952 INT nIndex
= infoPtr
->nNumStrings
;
2954 TRACE("%p, %lx\n", hInstance
, lParam
);
2956 if (IS_INTRESOURCE(lParam
)) {
2957 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2964 TRACE("adding string from resource\n");
2966 if (!hInstance
) return -1;
2968 hrsrc
= FindResourceW( hInstance
, MAKEINTRESOURCEW((LOWORD(lParam
) >> 4) + 1),
2969 (LPWSTR
)RT_STRING
);
2972 TRACE("string not found in resources\n");
2976 len
= LoadStringW (hInstance
, (UINT
)lParam
,
2977 szString
, MAX_RESOURCE_STRING_LENGTH
);
2979 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2980 if (len
== 0 || len
== 1)
2983 TRACE("delimiter: 0x%x\n", *szString
);
2984 delimiter
= *szString
;
2987 while ((next_delim
= wcschr(p
, delimiter
)) != NULL
) {
2989 if (next_delim
+ 1 >= szString
+ len
)
2991 /* this may happen if delimiter == '\0' or if the last char is a
2992 * delimiter (then it is ignored like the native does) */
2996 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2997 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2998 infoPtr
->nNumStrings
++;
3004 LPWSTR p
= (LPWSTR
)lParam
;
3009 TRACE("adding string(s) from array\n");
3013 TRACE("len=%d %s\n", len
, debugstr_w(p
));
3014 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3015 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3016 infoPtr
->nNumStrings
++;
3023 TOOLBAR_CalcToolbar(infoPtr
);
3029 TOOLBAR_AddStringA (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
3031 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
3036 TRACE("%p, %lx\n", hInstance
, lParam
);
3038 if (IS_INTRESOURCE(lParam
)) /* load from resources */
3039 return TOOLBAR_AddStringW(infoPtr
, hInstance
, lParam
);
3045 TRACE("adding string(s) from array\n");
3046 nIndex
= infoPtr
->nNumStrings
;
3049 TRACE("len=%d \"%s\"\n", len
, p
);
3051 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3052 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3053 infoPtr
->nNumStrings
++;
3059 TOOLBAR_CalcToolbar(infoPtr
);
3065 TOOLBAR_AutoSize (TOOLBAR_INFO
*infoPtr
)
3067 TRACE("auto sizing, style=%#x\n", infoPtr
->dwStyle
);
3068 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3070 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3072 RECT window_rect
, parent_rect
;
3073 UINT uPosFlags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
3077 parent
= GetParent (infoPtr
->hwndSelf
);
3079 if (!parent
|| !infoPtr
->bDoRedraw
)
3082 GetClientRect(parent
, &parent_rect
);
3084 x
= parent_rect
.left
;
3085 y
= parent_rect
.top
;
3087 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3088 cx
= parent_rect
.right
- parent_rect
.left
;
3090 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3092 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3093 MapWindowPoints( 0, parent
, (POINT
*)&window_rect
, 2 );
3094 y
= window_rect
.top
;
3096 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3098 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3099 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3102 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3103 uPosFlags
|= SWP_NOMOVE
;
3105 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3106 cy
+= GetSystemMetrics(SM_CYEDGE
);
3108 if (infoPtr
->dwStyle
& WS_BORDER
)
3110 cx
+= 2 * GetSystemMetrics(SM_CXBORDER
);
3111 cy
+= 2 * GetSystemMetrics(SM_CYBORDER
);
3114 SetWindowPos(infoPtr
->hwndSelf
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3117 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
))
3119 TOOLBAR_LayoutToolbar(infoPtr
);
3120 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
3127 static inline LRESULT
3128 TOOLBAR_ButtonCount (const TOOLBAR_INFO
*infoPtr
)
3130 return infoPtr
->nNumButtons
;
3134 static inline LRESULT
3135 TOOLBAR_ButtonStructSize (TOOLBAR_INFO
*infoPtr
, DWORD Size
)
3137 infoPtr
->dwStructSize
= Size
;
3144 TOOLBAR_ChangeBitmap (TOOLBAR_INFO
*infoPtr
, INT Id
, INT Index
)
3146 TBUTTON_INFO
*btnPtr
;
3149 TRACE("button %d, iBitmap now %d\n", Id
, Index
);
3151 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3155 btnPtr
= &infoPtr
->buttons
[nIndex
];
3156 btnPtr
->iBitmap
= Index
;
3158 /* we HAVE to erase the background, the new bitmap could be */
3160 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3167 TOOLBAR_CheckButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3169 TBUTTON_INFO
*btnPtr
;
3172 BOOL bChecked
= FALSE
;
3174 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3176 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, nIndex
, lParam
);
3181 btnPtr
= &infoPtr
->buttons
[nIndex
];
3183 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) != 0;
3185 if (!LOWORD(lParam
))
3186 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3188 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3190 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3191 if (nOldIndex
== nIndex
)
3193 if (nOldIndex
!= -1)
3194 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3196 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3199 if( bChecked
!= LOWORD(lParam
) )
3201 if (nOldIndex
!= -1)
3202 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3203 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3206 /* FIXME: Send a WM_NOTIFY?? */
3213 TOOLBAR_CommandToIndex (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3215 return TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3220 TOOLBAR_Customize (TOOLBAR_INFO
*infoPtr
)
3222 CUSTDLG_INFO custInfo
;
3226 custInfo
.tbInfo
= infoPtr
;
3227 custInfo
.tbHwnd
= infoPtr
->hwndSelf
;
3229 /* send TBN_BEGINADJUST notification */
3230 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3232 ret
= DialogBoxParamW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3233 infoPtr
->hwndSelf
, TOOLBAR_CustomizeDialogProc
, (LPARAM
)&custInfo
);
3235 /* send TBN_ENDADJUST notification */
3236 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3243 TOOLBAR_DeleteButton (TOOLBAR_INFO
*infoPtr
, INT nIndex
)
3246 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3248 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3251 memset(&nmtb
, 0, sizeof(nmtb
));
3252 nmtb
.iItem
= btnPtr
->idCommand
;
3253 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3254 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3255 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3256 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3257 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3258 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3259 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3261 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3263 infoPtr
->nHotItem
= -1;
3264 if (infoPtr
->nNumButtons
== 1) {
3265 TRACE(" simple delete\n");
3266 free_string( infoPtr
->buttons
);
3267 Free (infoPtr
->buttons
);
3268 infoPtr
->buttons
= NULL
;
3269 infoPtr
->nNumButtons
= 0;
3272 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3273 TRACE("complex delete [nIndex=%d]\n", nIndex
);
3275 infoPtr
->nNumButtons
--;
3276 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3278 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3279 nIndex
* sizeof(TBUTTON_INFO
));
3282 if (nIndex
< infoPtr
->nNumButtons
) {
3283 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3284 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3287 free_string( oldButtons
+ nIndex
);
3291 TOOLBAR_LayoutToolbar(infoPtr
);
3293 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3300 TOOLBAR_EnableButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3302 TBUTTON_INFO
*btnPtr
;
3306 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3308 TRACE("hwnd=%p, btn id=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, Id
, lParam
);
3313 btnPtr
= &infoPtr
->buttons
[nIndex
];
3315 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3317 /* update the toolbar button state */
3318 if(!LOWORD(lParam
)) {
3319 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3321 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3324 /* redraw the button only if the state of the button changed */
3325 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3326 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3332 static inline LRESULT
3333 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO
*infoPtr
)
3335 return infoPtr
->bAnchor
;
3340 TOOLBAR_GetBitmap (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3344 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3348 return infoPtr
->buttons
[nIndex
].iBitmap
;
3352 static inline LRESULT
3353 TOOLBAR_GetBitmapFlags (void)
3355 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3360 TOOLBAR_GetButton (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, TBBUTTON
*lpTbb
)
3362 TBUTTON_INFO
*btnPtr
;
3367 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3370 btnPtr
= &infoPtr
->buttons
[nIndex
];
3371 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3372 lpTbb
->idCommand
= btnPtr
->idCommand
;
3373 lpTbb
->fsState
= btnPtr
->fsState
;
3374 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3375 lpTbb
->bReserved
[0] = 0;
3376 lpTbb
->bReserved
[1] = 0;
3377 lpTbb
->dwData
= btnPtr
->dwData
;
3378 lpTbb
->iString
= btnPtr
->iString
;
3385 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO
*infoPtr
, INT Id
, LPTBBUTTONINFOW lpTbInfo
, BOOL bUnicode
)
3387 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3388 TBUTTON_INFO
*btnPtr
;
3391 if (lpTbInfo
== NULL
)
3394 /* MSDN documents an iImageLabel field added in Vista but it is not present in
3395 * the headers and tests shows that even with comctl 6 Vista accepts only the
3396 * original TBBUTTONINFO size
3398 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3400 WARN("Invalid button size\n");
3404 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lpTbInfo
->dwMask
& TBIF_BYINDEX
);
3408 btnPtr
= &infoPtr
->buttons
[nIndex
];
3409 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3410 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3411 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3412 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3413 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3414 lpTbInfo
->lParam
= btnPtr
->dwData
;
3415 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3416 /* tests show that for separators TBIF_SIZE returns not calculated width,
3417 but cx property, that differs from 0 only if application have
3418 specifically set it */
3419 lpTbInfo
->cx
= (btnPtr
->fsStyle
& BTNS_SEP
)
3420 ? btnPtr
->cx
: (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3421 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3422 lpTbInfo
->fsState
= btnPtr
->fsState
;
3423 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3424 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3425 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3426 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3427 can't use TOOLBAR_GetText here */
3428 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3429 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3431 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3433 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3434 } else if (!bUnicode
|| lpTbInfo
->pszText
)
3435 lpTbInfo
->pszText
[0] = '\0';
3441 static inline LRESULT
3442 TOOLBAR_GetButtonSize (const TOOLBAR_INFO
*infoPtr
)
3444 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3445 (WORD
)infoPtr
->nButtonHeight
);
3450 TOOLBAR_GetButtonText (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPWSTR lpStr
, BOOL isW
)
3456 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3460 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3466 ret
= lstrlenW (lpText
);
3467 if (lpStr
) lstrcpyW (lpStr
, lpText
);
3471 ret
= WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3472 (LPSTR
)lpStr
, lpStr
? 0x7fffffff : 0, NULL
, NULL
) - 1;
3478 TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3480 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3481 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3482 return (LRESULT
)GETDISIMAGELIST(infoPtr
, wParam
);
3486 static inline LRESULT
3487 TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO
*infoPtr
)
3491 return infoPtr
->dwExStyle
;
3496 TOOLBAR_GetHotImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3498 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3499 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3500 return (LRESULT
)GETHOTIMAGELIST(infoPtr
, wParam
);
3505 TOOLBAR_GetHotItem (const TOOLBAR_INFO
*infoPtr
)
3507 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3510 if (infoPtr
->nHotItem
< 0)
3513 return (LRESULT
)infoPtr
->nHotItem
;
3518 TOOLBAR_GetDefImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3520 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3521 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3522 return (LRESULT
) GETDEFIMAGELIST(infoPtr
, wParam
);
3527 TOOLBAR_GetInsertMark (const TOOLBAR_INFO
*infoPtr
, TBINSERTMARK
*lptbim
)
3529 TRACE("hwnd = %p, lptbim = %p\n", infoPtr
->hwndSelf
, lptbim
);
3531 *lptbim
= infoPtr
->tbim
;
3537 static inline LRESULT
3538 TOOLBAR_GetInsertMarkColor (const TOOLBAR_INFO
*infoPtr
)
3540 TRACE("hwnd = %p\n", infoPtr
->hwndSelf
);
3542 return (LRESULT
)infoPtr
->clrInsertMark
;
3547 TOOLBAR_GetItemRect (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, LPRECT lpRect
)
3549 TBUTTON_INFO
*btnPtr
;
3551 btnPtr
= &infoPtr
->buttons
[nIndex
];
3552 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3557 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3560 lpRect
->left
= btnPtr
->rect
.left
;
3561 lpRect
->right
= btnPtr
->rect
.right
;
3562 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3563 lpRect
->top
= btnPtr
->rect
.top
;
3570 TOOLBAR_GetMaxSize (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
3575 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3576 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3578 TRACE("maximum size %d x %d\n",
3579 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3580 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3586 /* << TOOLBAR_GetObject >> */
3589 static inline LRESULT
3590 TOOLBAR_GetPadding (const TOOLBAR_INFO
*infoPtr
)
3592 return MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3597 TOOLBAR_GetRect (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPRECT lpRect
)
3599 TBUTTON_INFO
*btnPtr
;
3602 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3603 btnPtr
= &infoPtr
->buttons
[nIndex
];
3604 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3610 lpRect
->left
= btnPtr
->rect
.left
;
3611 lpRect
->right
= btnPtr
->rect
.right
;
3612 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3613 lpRect
->top
= btnPtr
->rect
.top
;
3619 static inline LRESULT
3620 TOOLBAR_GetRows (const TOOLBAR_INFO
*infoPtr
)
3622 return infoPtr
->nRows
;
3627 TOOLBAR_GetState (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3631 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3635 return infoPtr
->buttons
[nIndex
].fsState
;
3639 static inline LRESULT
3640 TOOLBAR_GetStyle (const TOOLBAR_INFO
*infoPtr
)
3642 return infoPtr
->dwStyle
;
3646 static inline LRESULT
3647 TOOLBAR_GetTextRows (const TOOLBAR_INFO
*infoPtr
)
3649 return infoPtr
->nMaxTextRows
;
3654 TOOLBAR_GetToolTips (TOOLBAR_INFO
*infoPtr
)
3656 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3657 TOOLBAR_TooltipCreateControl(infoPtr
);
3658 return (LRESULT
)infoPtr
->hwndToolTip
;
3663 TOOLBAR_GetUnicodeFormat (const TOOLBAR_INFO
*infoPtr
)
3665 TRACE("%s hwnd=%p\n",
3666 infoPtr
->bUnicode
? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
3668 return infoPtr
->bUnicode
;
3672 static inline LRESULT
3673 TOOLBAR_GetVersion (const TOOLBAR_INFO
*infoPtr
)
3675 return infoPtr
->iVersion
;
3680 TOOLBAR_HideButton (TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fHide
)
3682 TBUTTON_INFO
*btnPtr
;
3688 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3692 btnPtr
= &infoPtr
->buttons
[nIndex
];
3693 oldState
= btnPtr
->fsState
;
3696 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3698 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3700 if (oldState
!= btnPtr
->fsState
) {
3701 TOOLBAR_LayoutToolbar (infoPtr
);
3702 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3709 static inline LRESULT
3710 TOOLBAR_HitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
* lpPt
)
3712 return TOOLBAR_InternalHitTest (infoPtr
, lpPt
, NULL
);
3717 TOOLBAR_Indeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fIndeterminate
)
3719 TBUTTON_INFO
*btnPtr
;
3723 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3727 btnPtr
= &infoPtr
->buttons
[nIndex
];
3728 oldState
= btnPtr
->fsState
;
3731 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3733 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3735 if(oldState
!= btnPtr
->fsState
)
3736 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3743 TOOLBAR_InsertButtonT(TOOLBAR_INFO
*infoPtr
, INT nIndex
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
3749 /* EPP: this seems to be an undocumented call (from my IE4)
3750 * I assume in that case that:
3751 * - index of insertion is at the end of existing buttons
3752 * I only see this happen with nIndex == -1, but it could have a special
3753 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3755 nIndex
= infoPtr
->nNumButtons
;
3757 } else if (nIndex
< 0)
3760 TRACE("inserting button index=%d\n", nIndex
);
3761 if (nIndex
> infoPtr
->nNumButtons
) {
3762 nIndex
= infoPtr
->nNumButtons
;
3763 TRACE("adjust index=%d\n", nIndex
);
3766 return TOOLBAR_InternalInsertButtonsT(infoPtr
, nIndex
, 1, lpTbb
, fUnicode
);
3769 /* << TOOLBAR_InsertMarkHitTest >> */
3773 TOOLBAR_IsButtonChecked (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3777 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3781 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3786 TOOLBAR_IsButtonEnabled (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3790 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3794 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3799 TOOLBAR_IsButtonHidden (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3803 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3807 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3812 TOOLBAR_IsButtonHighlighted (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3816 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3820 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3825 TOOLBAR_IsButtonIndeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3829 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3833 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3838 TOOLBAR_IsButtonPressed (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3842 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3846 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3851 TOOLBAR_LoadImages (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HINSTANCE hInstance
)
3854 tbab
.hInst
= hInstance
;
3857 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", infoPtr
->hwndSelf
, tbab
.hInst
, tbab
.nID
);
3859 return TOOLBAR_AddBitmap(infoPtr
, 0, &tbab
);
3864 TOOLBAR_MapAccelerator (const TOOLBAR_INFO
*infoPtr
, WCHAR wAccel
, UINT
*pIDButton
)
3866 WCHAR wszAccel
[] = {'&',wAccel
,0};
3869 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3870 infoPtr
->hwndSelf
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3872 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3874 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3875 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3876 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3878 int iLen
= lstrlenW(wszAccel
);
3879 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3886 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3891 if (!wcsnicmp(lpszStr
, wszAccel
, iLen
))
3893 *pIDButton
= btnPtr
->idCommand
;
3905 TOOLBAR_MarkButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fMark
)
3909 TBUTTON_INFO
*btnPtr
;
3911 TRACE("hwnd = %p, Id = %d, fMark = 0%d\n", infoPtr
->hwndSelf
, Id
, fMark
);
3913 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3917 btnPtr
= &infoPtr
->buttons
[nIndex
];
3918 oldState
= btnPtr
->fsState
;
3921 btnPtr
->fsState
|= TBSTATE_MARKED
;
3923 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
3925 if(oldState
!= btnPtr
->fsState
)
3926 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3932 /* fixes up an index of a button affected by a move */
3933 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
3937 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
3939 else if (*pIndex
== nIndex
)
3940 *pIndex
= nMoveIndex
;
3944 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
3946 else if (*pIndex
== nIndex
)
3947 *pIndex
= nMoveIndex
;
3953 TOOLBAR_MoveButton (TOOLBAR_INFO
*infoPtr
, INT Id
, INT nMoveIndex
)
3957 TBUTTON_INFO button
;
3959 TRACE("hwnd=%p, Id=%d, nMoveIndex=%d\n", infoPtr
->hwndSelf
, Id
, nMoveIndex
);
3961 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, TRUE
);
3962 if ((nIndex
== -1) || (nMoveIndex
< 0))
3965 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
3966 nMoveIndex
= infoPtr
->nNumButtons
- 1;
3968 button
= infoPtr
->buttons
[nIndex
];
3970 /* move button right */
3971 if (nIndex
< nMoveIndex
)
3973 nCount
= nMoveIndex
- nIndex
;
3974 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
3975 infoPtr
->buttons
[nMoveIndex
] = button
;
3977 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
3978 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
3979 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
3980 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
3982 else if (nIndex
> nMoveIndex
) /* move button left */
3984 nCount
= nIndex
- nMoveIndex
;
3985 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
3986 infoPtr
->buttons
[nMoveIndex
] = button
;
3988 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
3989 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
3990 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
3991 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
3994 TOOLBAR_LayoutToolbar(infoPtr
);
3995 TOOLBAR_AutoSize(infoPtr
);
3996 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4003 TOOLBAR_PressButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fPress
)
4005 TBUTTON_INFO
*btnPtr
;
4009 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
4013 btnPtr
= &infoPtr
->buttons
[nIndex
];
4014 oldState
= btnPtr
->fsState
;
4017 btnPtr
->fsState
|= TBSTATE_PRESSED
;
4019 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
4021 if(oldState
!= btnPtr
->fsState
)
4022 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4027 /* FIXME: there might still be some confusion her between number of buttons
4028 * and number of bitmaps */
4030 TOOLBAR_ReplaceBitmap (TOOLBAR_INFO
*infoPtr
, const TBREPLACEBITMAP
*lpReplace
)
4033 int i
= 0, nOldButtons
= 0, pos
= 0;
4034 int nOldBitmaps
, nNewBitmaps
= 0;
4035 HIMAGELIST himlDef
= 0;
4037 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4038 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
4039 lpReplace
->nButtons
);
4041 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4043 FIXME("changing standard bitmaps not implemented\n");
4046 else if (lpReplace
->hInstOld
!= 0 && lpReplace
->hInstOld
!= lpReplace
->hInstNew
)
4047 FIXME("resources not in the current module not implemented\n");
4049 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4050 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4051 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4052 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4053 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4055 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4056 nOldButtons
= tbi
->nButtons
;
4057 tbi
->nButtons
= lpReplace
->nButtons
;
4058 tbi
->hInst
= lpReplace
->hInstNew
;
4059 tbi
->nID
= lpReplace
->nIDNew
;
4060 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4063 pos
+= tbi
->nButtons
;
4066 if (nOldButtons
== 0)
4068 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4072 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4075 if (lpReplace
->hInstNew
)
4076 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4078 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4080 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4081 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4083 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4085 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4086 ImageList_Remove(himlDef
, i
);
4090 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4091 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4092 DeleteObject(hBitmap
);
4095 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4097 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4098 pos
, nOldBitmaps
, nNewBitmaps
);
4100 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4105 /* helper for TOOLBAR_SaveRestoreW */
4107 TOOLBAR_Save(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*params
)
4111 BOOL alloced
= FALSE
;
4114 TRACE( "save to %s %s\n", debugstr_w(params
->pszSubKey
), debugstr_w(params
->pszValueName
) );
4116 memset( &save
, 0, sizeof(save
) );
4117 save
.cbData
= infoPtr
->nNumButtons
* sizeof(DWORD
);
4119 save
.cButtons
= infoPtr
->nNumButtons
;
4120 save
.tbButton
.idCommand
= -1;
4121 TOOLBAR_SendNotify( &save
.hdr
, infoPtr
, TBN_SAVE
);
4125 save
.pData
= Alloc( save
.cbData
);
4126 if (!save
.pData
) return FALSE
;
4129 if (!save
.pCurrent
) save
.pCurrent
= save
.pData
;
4131 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4134 save
.tbButton
.iBitmap
= infoPtr
->buttons
[i
].iBitmap
;
4135 save
.tbButton
.idCommand
= infoPtr
->buttons
[i
].idCommand
;
4136 save
.tbButton
.fsState
= infoPtr
->buttons
[i
].fsState
;
4137 save
.tbButton
.fsStyle
= infoPtr
->buttons
[i
].fsStyle
;
4138 memset( save
.tbButton
.bReserved
, 0, sizeof(save
.tbButton
.bReserved
) );
4139 save
.tbButton
.dwData
= infoPtr
->buttons
[i
].dwData
;
4140 save
.tbButton
.iString
= infoPtr
->buttons
[i
].iString
;
4142 *save
.pCurrent
++ = save
.tbButton
.idCommand
;
4144 TOOLBAR_SendNotify( &save
.hdr
, infoPtr
, TBN_SAVE
);
4147 ret
= RegCreateKeyW( params
->hkr
, params
->pszSubKey
, &key
);
4148 if (ret
== ERROR_SUCCESS
)
4150 ret
= RegSetValueExW( key
, params
->pszValueName
, 0, REG_BINARY
, (BYTE
*)save
.pData
, save
.cbData
);
4154 if (alloced
) Free( save
.pData
);
4159 /* helper for TOOLBAR_Restore */
4161 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4165 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4167 free_string( infoPtr
->buttons
+ i
);
4168 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4171 Free(infoPtr
->buttons
);
4172 infoPtr
->buttons
= NULL
;
4173 infoPtr
->nNumButtons
= 0;
4177 /* helper for TOOLBAR_SaveRestoreW */
4179 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4189 /* restore toolbar information */
4190 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4191 debugstr_w(lpSave
->pszValueName
));
4193 memset(&nmtbr
, 0, sizeof(nmtbr
));
4195 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4196 KEY_QUERY_VALUE
, &hkey
);
4198 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4200 if (!res
&& dwType
!= REG_BINARY
)
4201 res
= ERROR_FILE_NOT_FOUND
;
4204 nmtbr
.pData
= Alloc(dwSize
);
4205 nmtbr
.cbData
= dwSize
;
4206 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4209 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4210 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4213 nmtbr
.pCurrent
= nmtbr
.pData
;
4215 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4216 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4218 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4220 INT i
, count
= nmtbr
.cButtons
;
4222 /* remove all existing buttons as this function is designed to
4223 * restore the toolbar to a previously saved state */
4224 TOOLBAR_DeleteAllButtons(infoPtr
);
4226 for (i
= 0; i
< count
; i
++)
4229 nmtbr
.tbButton
.iBitmap
= -1;
4230 nmtbr
.tbButton
.fsState
= 0;
4231 nmtbr
.tbButton
.fsStyle
= 0;
4232 nmtbr
.tbButton
.dwData
= 0;
4233 nmtbr
.tbButton
.iString
= 0;
4235 if (*nmtbr
.pCurrent
& 0x80000000)
4238 nmtbr
.tbButton
.iBitmap
= SEPARATOR_WIDTH
;
4239 nmtbr
.tbButton
.idCommand
= 0;
4240 nmtbr
.tbButton
.fsStyle
= BTNS_SEP
;
4241 if (*nmtbr
.pCurrent
!= (DWORD
)-1)
4242 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4245 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4249 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4251 /* All returned ptrs and -1 are ignored */
4252 if (!IS_INTRESOURCE(nmtbr
.tbButton
.iString
))
4253 nmtbr
.tbButton
.iString
= 0;
4255 TOOLBAR_InsertButtonT(infoPtr
, -1, &nmtbr
.tbButton
, TRUE
);
4258 TOOLBAR_SendNotify( &hdr
, infoPtr
, TBN_BEGINADJUST
);
4264 UINT code
= infoPtr
->bUnicode
? TBN_GETBUTTONINFOW
: TBN_GETBUTTONINFOA
;
4267 memset( &tb
, 0, sizeof(tb
) );
4269 tb
.cchText
= ARRAY_SIZE(buf
);
4272 /* Use the same struct for both A and W versions since the layout is the same. */
4273 if (!TOOLBAR_SendNotify( &tb
.hdr
, infoPtr
, code
))
4276 idx
= TOOLBAR_GetButtonIndex( infoPtr
, tb
.tbButton
.idCommand
, FALSE
);
4277 if (idx
== -1) continue;
4279 /* tb.pszText is ignored - the string comes from tb.tbButton.iString, which may
4280 be an index or a ptr. Either way it is simply copied. There is no api to change
4281 the string index, so we set it manually. The other properties can be set with SetButtonInfo. */
4282 free_string( infoPtr
->buttons
+ idx
);
4283 infoPtr
->buttons
[idx
].iString
= tb
.tbButton
.iString
;
4285 memset( &bi
, 0, sizeof(bi
) );
4286 bi
.cbSize
= sizeof(bi
);
4287 bi
.dwMask
= TBIF_IMAGE
| TBIF_STATE
| TBIF_STYLE
| TBIF_LPARAM
;
4288 bi
.iImage
= tb
.tbButton
.iBitmap
;
4289 bi
.fsState
= tb
.tbButton
.fsState
;
4290 bi
.fsStyle
= tb
.tbButton
.fsStyle
;
4291 bi
.lParam
= tb
.tbButton
.dwData
;
4293 TOOLBAR_SetButtonInfo( infoPtr
, tb
.tbButton
.idCommand
, &bi
, TRUE
);
4295 TOOLBAR_SendNotify( &hdr
, infoPtr
, TBN_ENDADJUST
);
4297 /* remove all uninitialised buttons
4298 * note: loop backwards to avoid having to fixup i on a
4300 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4301 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4302 TOOLBAR_DeleteButton(infoPtr
, i
);
4304 /* only indicate success if at least one button survived */
4305 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4316 TOOLBAR_SaveRestoreW (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4318 if (lpSave
== NULL
) return 0;
4321 return TOOLBAR_Save(infoPtr
, lpSave
);
4323 return TOOLBAR_Restore(infoPtr
, lpSave
);
4328 TOOLBAR_SaveRestoreA (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4330 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4331 TBSAVEPARAMSW SaveW
;
4335 if (lpSave
== NULL
) return 0;
4337 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4338 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4339 if (!pszSubKey
) goto exit
;
4340 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4342 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4343 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4344 if (!pszValueName
) goto exit
;
4345 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4347 SaveW
.pszValueName
= pszValueName
;
4348 SaveW
.pszSubKey
= pszSubKey
;
4349 SaveW
.hkr
= lpSave
->hkr
;
4350 result
= TOOLBAR_SaveRestoreW(infoPtr
, wParam
, &SaveW
);
4353 Free (pszValueName
);
4361 TOOLBAR_SetAnchorHighlight (TOOLBAR_INFO
*infoPtr
, BOOL bAnchor
)
4363 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4365 TRACE("hwnd=%p, bAnchor = %s\n", infoPtr
->hwndSelf
, bAnchor
? "TRUE" : "FALSE");
4367 infoPtr
->bAnchor
= bAnchor
;
4369 /* Native does not remove the hot effect from an already hot button */
4371 return (LRESULT
)bOldAnchor
;
4376 TOOLBAR_SetBitmapSize (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4378 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4379 short width
= (short)LOWORD(lParam
);
4380 short height
= (short)HIWORD(lParam
);
4382 TRACE("hwnd=%p, wParam=%ld, size %d x %d\n", infoPtr
->hwndSelf
, wParam
, width
, height
);
4385 FIXME("wParam is %ld. Perhaps image list index?\n", wParam
);
4387 /* 0 width or height is changed to 1 */
4393 if (infoPtr
->nNumButtons
> 0)
4394 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4395 infoPtr
->nNumButtons
,
4396 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
, width
, height
);
4398 if (width
< -1 || height
< -1)
4400 /* Windows destroys the imagelist and seems to actually use negative
4401 * values to compute button sizes */
4402 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width
, height
);
4406 /* width or height of -1 means no change */
4408 infoPtr
->nBitmapWidth
= width
;
4410 infoPtr
->nBitmapHeight
= height
;
4412 if ((himlDef
== infoPtr
->himlInt
) &&
4413 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4415 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4416 infoPtr
->nBitmapHeight
);
4419 TOOLBAR_CalcToolbar(infoPtr
);
4420 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4426 TOOLBAR_SetButtonInfo (TOOLBAR_INFO
*infoPtr
, INT Id
,
4427 const TBBUTTONINFOW
*lptbbi
, BOOL isW
)
4429 TBUTTON_INFO
*btnPtr
;
4435 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4438 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lptbbi
->dwMask
& TBIF_BYINDEX
);
4442 btnPtr
= &infoPtr
->buttons
[nIndex
];
4443 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4444 btnPtr
->idCommand
= lptbbi
->idCommand
;
4445 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4446 btnPtr
->iBitmap
= lptbbi
->iImage
;
4447 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4448 btnPtr
->dwData
= lptbbi
->lParam
;
4449 if (lptbbi
->dwMask
& TBIF_SIZE
)
4450 btnPtr
->cx
= lptbbi
->cx
;
4451 if (lptbbi
->dwMask
& TBIF_STATE
)
4452 btnPtr
->fsState
= lptbbi
->fsState
;
4453 if (lptbbi
->dwMask
& TBIF_STYLE
)
4454 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4456 if (lptbbi
->dwMask
& TBIF_TEXT
)
4457 set_stringT( btnPtr
, lptbbi
->pszText
, isW
);
4459 /* save the button rect to see if we need to redraw the whole toolbar */
4460 oldBtnRect
= btnPtr
->rect
;
4461 TOOLBAR_LayoutToolbar(infoPtr
);
4463 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4464 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4466 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4473 TOOLBAR_SetButtonSize (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4475 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4476 int top
= default_top_margin(infoPtr
);
4478 if ((cx
< 0) || (cy
< 0))
4480 ERR("invalid parameter 0x%08x\n", (DWORD
)lParam
);
4484 TRACE("%p, cx = %d, cy = %d\n", infoPtr
->hwndSelf
, cx
, cy
);
4486 /* The documentation claims you can only change the button size before
4487 * any button has been added. But this is wrong.
4488 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4489 * it to the toolbar, and it checks that the return value is nonzero - mjm
4490 * Further testing shows that we must actually perform the change too.
4493 * The documentation also does not mention that if 0 is supplied for
4494 * either size, the system changes it to the default of 24 wide and
4495 * 22 high. Demonstrated in ControlSpy Toolbar. GLA 3/02
4497 if (cx
== 0) cx
= 24;
4498 if (cy
== 0) cy
= 22;
4500 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4501 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4503 if (cx
!= infoPtr
->nButtonWidth
|| cy
!= infoPtr
->nButtonHeight
||
4504 top
!= infoPtr
->iTopMargin
)
4506 infoPtr
->nButtonWidth
= cx
;
4507 infoPtr
->nButtonHeight
= cy
;
4508 infoPtr
->iTopMargin
= top
;
4510 TOOLBAR_LayoutToolbar( infoPtr
);
4511 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
4518 TOOLBAR_SetButtonWidth (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4520 /* if setting to current values, ignore */
4521 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4522 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4523 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4524 infoPtr
->cxMin
, infoPtr
->cxMax
);
4528 /* save new values */
4529 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4530 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4532 /* otherwise we need to recalc the toolbar and in some cases
4533 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4534 which doesn't actually draw - GA). */
4535 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4536 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4538 TOOLBAR_CalcToolbar (infoPtr
);
4540 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
4547 TOOLBAR_SetCmdId (TOOLBAR_INFO
*infoPtr
, INT nIndex
, INT nId
)
4549 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4552 infoPtr
->buttons
[nIndex
].idCommand
= nId
;
4554 if (infoPtr
->hwndToolTip
) {
4556 FIXME("change tool tip\n");
4565 TOOLBAR_SetDisabledImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4567 HIMAGELIST himlTemp
;
4570 if (infoPtr
->iVersion
>= 5)
4573 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4574 &infoPtr
->cimlDis
, himl
, id
);
4576 /* FIXME: redraw ? */
4578 return (LRESULT
)himlTemp
;
4583 TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD flags
)
4587 TRACE("hwnd = %p, mask = 0x%08x, flags = 0x%08x\n", infoPtr
->hwndSelf
, mask
, flags
);
4589 old_flags
= infoPtr
->dwDTFlags
;
4590 infoPtr
->dwDTFlags
= (old_flags
& ~mask
) | (flags
& mask
);
4592 return (LRESULT
)old_flags
;
4595 /* This function differs a bit from what MSDN says it does:
4596 * 1. lParam contains extended style flags to OR with current style
4597 * (MSDN isn't clear on the OR bit)
4598 * 2. wParam appears to contain extended style flags to be reset
4599 * (MSDN says that this parameter is reserved)
4602 TOOLBAR_SetExtendedStyle (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD style
)
4604 DWORD old_style
= infoPtr
->dwExStyle
;
4606 TRACE("mask=0x%08x, style=0x%08x\n", mask
, style
);
4609 infoPtr
->dwExStyle
= (old_style
& ~mask
) | (style
& mask
);
4611 infoPtr
->dwExStyle
= style
;
4613 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4614 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4615 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4617 if ((old_style
^ infoPtr
->dwExStyle
) & TBSTYLE_EX_MIXEDBUTTONS
)
4618 TOOLBAR_CalcToolbar(infoPtr
);
4620 TOOLBAR_LayoutToolbar(infoPtr
);
4622 TOOLBAR_AutoSize(infoPtr
);
4623 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4630 TOOLBAR_SetHotImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4632 HIMAGELIST himlTemp
;
4635 if (infoPtr
->iVersion
>= 5)
4638 TRACE("hwnd = %p, himl = %p, id = %d\n", infoPtr
->hwndSelf
, himl
, id
);
4640 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4641 &infoPtr
->cimlHot
, himl
, id
);
4643 /* FIXME: redraw ? */
4645 return (LRESULT
)himlTemp
;
4649 /* Makes previous hot button no longer hot, makes the specified
4650 * button hot and sends appropriate notifications. dwReason is one or
4651 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4652 * NOTE 1: this function does not validate nHit
4653 * NOTE 2: the name of this function is completely made up and
4654 * not based on any documentation from Microsoft. */
4656 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4658 if (infoPtr
->nHotItem
!= nHit
)
4660 NMTBHOTITEM nmhotitem
;
4661 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4663 nmhotitem
.dwFlags
= dwReason
;
4664 if(infoPtr
->nHotItem
>= 0)
4666 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4667 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4671 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4672 nmhotitem
.idOld
= 0;
4677 btnPtr
= &infoPtr
->buttons
[nHit
];
4678 nmhotitem
.idNew
= btnPtr
->idCommand
;
4682 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4683 nmhotitem
.idNew
= 0;
4686 /* now change the hot and invalidate the old and new buttons - if the
4688 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4691 oldBtnPtr
->bHot
= FALSE
;
4692 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4694 /* setting disabled buttons as hot fails even if the notify contains the button id */
4695 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4696 btnPtr
->bHot
= TRUE
;
4697 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4698 infoPtr
->nHotItem
= nHit
;
4701 infoPtr
->nHotItem
= -1;
4707 TOOLBAR_SetHotItem (TOOLBAR_INFO
*infoPtr
, INT nHotItem
)
4709 INT nOldHotItem
= infoPtr
->nHotItem
;
4711 TRACE("hwnd = %p, nHotItem = %d\n", infoPtr
->hwndSelf
, nHotItem
);
4713 if (nHotItem
>= infoPtr
->nNumButtons
)
4714 return infoPtr
->nHotItem
;
4719 /* NOTE: an application can still remove the hot item even if anchor
4720 * highlighting is enabled */
4722 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, HICF_OTHER
);
4724 if (nOldHotItem
< 0)
4727 return (LRESULT
)nOldHotItem
;
4732 TOOLBAR_SetImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4734 HIMAGELIST himlTemp
;
4735 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4736 INT oldBitmapWidth
= infoPtr
->nBitmapWidth
;
4737 INT oldBitmapHeight
= infoPtr
->nBitmapHeight
;
4740 if (infoPtr
->iVersion
>= 5)
4743 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4744 &infoPtr
->cimlDef
, himl
, id
);
4746 infoPtr
->nNumBitmaps
= 0;
4747 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4748 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4750 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4751 &infoPtr
->nBitmapHeight
))
4753 infoPtr
->nBitmapWidth
= 1;
4754 infoPtr
->nBitmapHeight
= 1;
4756 if ((oldBitmapWidth
!= infoPtr
->nBitmapWidth
) || (oldBitmapHeight
!= infoPtr
->nBitmapHeight
))
4758 TOOLBAR_CalcToolbar(infoPtr
);
4759 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4760 TOOLBAR_SetButtonSize(infoPtr
, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4763 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4764 infoPtr
->hwndSelf
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4765 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4767 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4769 return (LRESULT
)himlTemp
;
4774 TOOLBAR_SetIndent (TOOLBAR_INFO
*infoPtr
, INT nIndent
)
4776 infoPtr
->nIndent
= nIndent
;
4780 /* process only on indent changing */
4781 if(infoPtr
->nIndent
!= nIndent
)
4783 infoPtr
->nIndent
= nIndent
;
4784 TOOLBAR_CalcToolbar (infoPtr
);
4785 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4793 TOOLBAR_SetInsertMark (TOOLBAR_INFO
*infoPtr
, const TBINSERTMARK
*lptbim
)
4795 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", infoPtr
->hwndSelf
, lptbim
->iButton
, lptbim
->dwFlags
);
4797 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4799 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4803 if ((lptbim
->iButton
== -1) ||
4804 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4805 (lptbim
->iButton
>= 0)))
4807 infoPtr
->tbim
= *lptbim
;
4808 /* FIXME: don't need to update entire toolbar */
4809 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4812 ERR("Invalid button index %d\n", lptbim
->iButton
);
4819 TOOLBAR_SetInsertMarkColor (TOOLBAR_INFO
*infoPtr
, COLORREF clr
)
4821 infoPtr
->clrInsertMark
= clr
;
4823 /* FIXME: don't need to update entire toolbar */
4824 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4831 TOOLBAR_SetMaxTextRows (TOOLBAR_INFO
*infoPtr
, INT nMaxRows
)
4833 infoPtr
->nMaxTextRows
= nMaxRows
;
4835 TOOLBAR_CalcToolbar(infoPtr
);
4840 /* MSDN gives slightly wrong info on padding.
4841 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4842 * 2. It is not used to create a blank area between the edge of the button
4843 * and the text or image if TBSTYLE_LIST is set. It is used to control
4844 * the gap between the image and text.
4845 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4846 * to control the bottom and right borders [with the border being
4847 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4848 * is shared evenly on both sides of the button.
4849 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4852 TOOLBAR_SetPadding (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4856 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4857 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4858 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4859 TRACE("cx=%d, cy=%d\n",
4860 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4861 return (LRESULT
) oldPad
;
4866 TOOLBAR_SetParent (TOOLBAR_INFO
*infoPtr
, HWND hParent
)
4872 hwndOldNotify
= infoPtr
->hwndNotify
;
4873 infoPtr
->hwndNotify
= hParent
;
4875 return (LRESULT
)hwndOldNotify
;
4880 TOOLBAR_SetRows (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPRECT lprc
)
4882 int rows
= LOWORD(wParam
);
4883 BOOL bLarger
= HIWORD(wParam
);
4887 TRACE("Setting rows to %d (%d)\n", rows
, bLarger
);
4889 if(infoPtr
->nRows
!= rows
)
4891 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
;
4892 int curColumn
= 0; /* Current column */
4893 int curRow
= 0; /* Current row */
4894 int hidden
= 0; /* Number of hidden buttons */
4895 int seps
= 0; /* Number of separators */
4896 int idealWrap
= 0; /* Ideal wrap point */
4901 Calculate new size and wrap points - Under windows, setrows will
4902 change the dimensions if needed to show the number of requested
4903 rows (if CCS_NORESIZE is set), or will take up the whole window
4904 (if no CCS_NORESIZE).
4906 Basic algorithm - If N buttons, and y rows requested, each row
4907 contains N/y buttons.
4909 FIXME: Handling of separators not obvious from testing results
4910 FIXME: Take width of window into account?
4913 /* Loop through the buttons one by one counting key items */
4914 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4916 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
4917 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4919 else if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
4923 /* FIXME: Separators make this quite complex */
4924 if (seps
) FIXME("Separators unhandled\n");
4926 /* Round up so more per line, i.e., less rows */
4927 idealWrap
= (infoPtr
->nNumButtons
- hidden
+ (rows
-1)) / (rows
? rows
: 1);
4929 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4930 achieve the requested number of rows. */
4931 if (bLarger
&& idealWrap
> 1)
4933 int resRows
= (infoPtr
->nNumButtons
+ (idealWrap
-1)) / idealWrap
;
4934 int moreRows
= (infoPtr
->nNumButtons
+ (idealWrap
-2)) / (idealWrap
-1);
4936 if (resRows
< rows
&& moreRows
> rows
)
4939 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap
);
4943 curColumn
= curRow
= 0;
4945 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap
,
4946 infoPtr
->nNumButtons
, hidden
, rows
);
4948 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4950 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4953 /* Step on, wrap if necessary or flag next to wrap */
4962 if (curColumn
> (idealWrap
-1)) {
4964 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
4968 TRACE("Result - %d rows\n", curRow
+ 1);
4970 /* recalculate toolbar */
4971 TOOLBAR_CalcToolbar (infoPtr
);
4973 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
4974 if NORESIZE is NOT set, then the toolbar will always be resized to
4975 take up the whole window. With it set, sizing needs to be manual. */
4976 if (infoPtr
->dwStyle
& CCS_NORESIZE
) {
4977 SetWindowPos(infoPtr
->hwndSelf
, NULL
, 0, 0,
4978 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
4979 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
,
4980 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
4983 /* repaint toolbar */
4984 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4987 /* return bounding rectangle */
4989 lprc
->left
= infoPtr
->rcBound
.left
;
4990 lprc
->right
= infoPtr
->rcBound
.right
;
4991 lprc
->top
= infoPtr
->rcBound
.top
;
4992 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
5000 TOOLBAR_SetState (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
5002 TBUTTON_INFO
*btnPtr
;
5005 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
5009 btnPtr
= &infoPtr
->buttons
[nIndex
];
5011 /* if hidden state has changed the invalidate entire window and recalc */
5012 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
5013 btnPtr
->fsState
= LOWORD(lParam
);
5014 TOOLBAR_CalcToolbar (infoPtr
);
5015 InvalidateRect(infoPtr
->hwndSelf
, 0, TRUE
);
5019 /* process state changing if current state doesn't match new state */
5020 if(btnPtr
->fsState
!= LOWORD(lParam
))
5022 btnPtr
->fsState
= LOWORD(lParam
);
5023 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5029 static inline void unwrap(TOOLBAR_INFO
*info
)
5033 for (i
= 0; i
< info
->nNumButtons
; i
++)
5034 info
->buttons
[i
].fsState
&= ~TBSTATE_WRAP
;
5038 TOOLBAR_SetStyle (TOOLBAR_INFO
*infoPtr
, DWORD style
)
5040 DWORD dwOldStyle
= infoPtr
->dwStyle
;
5042 TRACE("new style 0x%08x\n", style
);
5044 if (style
& TBSTYLE_LIST
)
5045 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
5047 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
5049 infoPtr
->dwStyle
= style
;
5050 TOOLBAR_CheckStyle(infoPtr
);
5052 if ((dwOldStyle
^ style
) & TBSTYLE_WRAPABLE
)
5054 if (dwOldStyle
& TBSTYLE_WRAPABLE
)
5056 TOOLBAR_CalcToolbar(infoPtr
);
5058 else if ((dwOldStyle
^ style
) & CCS_VERT
)
5059 TOOLBAR_LayoutToolbar(infoPtr
);
5061 /* only resize if one of the CCS_* styles was changed */
5062 if ((dwOldStyle
^ style
) & COMMON_STYLES
)
5064 TOOLBAR_AutoSize(infoPtr
);
5065 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5072 static inline LRESULT
5073 TOOLBAR_SetToolTips (TOOLBAR_INFO
*infoPtr
, HWND hwndTooltip
)
5075 TRACE("hwnd=%p, hwndTooltip=%p\n", infoPtr
->hwndSelf
, hwndTooltip
);
5077 infoPtr
->hwndToolTip
= hwndTooltip
;
5083 TOOLBAR_SetUnicodeFormat (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
5087 TRACE("%s hwnd=%p\n",
5088 ((BOOL
)wParam
) ? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
5090 bTemp
= infoPtr
->bUnicode
;
5091 infoPtr
->bUnicode
= (BOOL
)wParam
;
5098 TOOLBAR_GetColorScheme (const TOOLBAR_INFO
*infoPtr
, LPCOLORSCHEME lParam
)
5100 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
5101 comctl32_color
.clrBtnHighlight
:
5102 infoPtr
->clrBtnHighlight
;
5103 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
5104 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
5110 TOOLBAR_SetColorScheme (TOOLBAR_INFO
*infoPtr
, const COLORSCHEME
*lParam
)
5112 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5113 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
5114 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
5116 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
5117 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
5118 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5124 TOOLBAR_SetVersion (TOOLBAR_INFO
*infoPtr
, INT iVersion
)
5126 INT iOldVersion
= infoPtr
->iVersion
;
5128 infoPtr
->iVersion
= iVersion
;
5130 if (infoPtr
->iVersion
>= 5)
5131 TOOLBAR_SetUnicodeFormat(infoPtr
, TRUE
);
5138 TOOLBAR_GetStringA (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPSTR str
)
5140 WORD iString
= HIWORD(wParam
);
5141 WORD buffersize
= LOWORD(wParam
);
5144 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, buffersize
, str
);
5146 if (iString
< infoPtr
->nNumStrings
)
5148 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
5151 TRACE("returning %s\n", debugstr_a(str
));
5154 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5161 TOOLBAR_GetStringW (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPWSTR str
)
5163 WORD iString
= HIWORD(wParam
);
5164 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5167 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, LOWORD(wParam
), str
);
5169 if (iString
< infoPtr
->nNumStrings
)
5171 len
= min(len
, lstrlenW(infoPtr
->strings
[iString
]));
5172 ret
= (len
+1)*sizeof(WCHAR
);
5175 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5180 TRACE("returning %s\n", debugstr_w(str
));
5183 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5188 static LRESULT
TOOLBAR_SetBoundingSize(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5190 SIZE
* pSize
= (SIZE
*)lParam
;
5191 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5195 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5196 * caller to specify a reason why the hot item changed (rather than just the
5197 * HICF_OTHER that TB_SETHOTITEM sends). */
5199 TOOLBAR_SetHotItem2 (TOOLBAR_INFO
*infoPtr
, INT nHotItem
, LPARAM lParam
)
5201 INT nOldHotItem
= infoPtr
->nHotItem
;
5203 TRACE("old item=%d, new item=%d, flags=%08x\n",
5204 nOldHotItem
, nHotItem
, (DWORD
)lParam
);
5206 if (nHotItem
< 0 || nHotItem
> infoPtr
->nNumButtons
)
5209 /* NOTE: an application can still remove the hot item even if anchor
5210 * highlighting is enabled */
5212 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, lParam
);
5214 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5217 /* Sets the toolbar global iListGap parameter which controls the amount of
5218 * spacing between the image and the text of buttons for TBSTYLE_LIST
5220 static LRESULT
TOOLBAR_SetListGap(TOOLBAR_INFO
*infoPtr
, INT iListGap
)
5222 TRACE("hwnd=%p iListGap=%d\n", infoPtr
->hwndSelf
, iListGap
);
5224 infoPtr
->iListGap
= iListGap
;
5226 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5231 /* Returns the number of maximum number of image lists associated with the
5232 * various states. */
5233 static LRESULT
TOOLBAR_GetImageListCount(const TOOLBAR_INFO
*infoPtr
)
5235 TRACE("hwnd=%p\n", infoPtr
->hwndSelf
);
5237 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5241 TOOLBAR_GetIdealSize (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5243 LPSIZE lpsize
= (LPSIZE
)lParam
;
5249 * Testing shows the following:
5250 * wParam = 0 adjust cx value
5251 * = 1 set cy value to max size.
5252 * lParam pointer to SIZE structure
5255 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5256 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5260 if (lpsize
->cx
== -1) {
5261 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5263 else if(HIWORD(lpsize
->cx
)) {
5265 HWND hwndParent
= GetParent(infoPtr
->hwndSelf
);
5267 GetWindowRect(infoPtr
->hwndSelf
, &rc
);
5268 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5269 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc
));
5270 lpsize
->cx
= max(rc
.right
-rc
.left
,
5271 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5274 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5278 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5281 FIXME("Unknown wParam %ld\n", wParam
);
5284 TRACE("set to -> 0x%08x 0x%08x\n",
5285 lpsize
->cx
, lpsize
->cy
);
5289 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5291 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5293 InvalidateRect(hwnd
, NULL
, TRUE
);
5299 TOOLBAR_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
5301 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
5304 TRACE("hwnd = %p, style=0x%08x\n", hwnd
, lpcs
->style
);
5306 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5307 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5308 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5309 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_REQUERY
));
5310 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5312 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5313 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5315 OpenThemeData (hwnd
, themeClass
);
5317 TOOLBAR_CheckStyle (infoPtr
);
5324 TOOLBAR_Destroy (TOOLBAR_INFO
*infoPtr
)
5328 /* delete tooltip control */
5329 if (infoPtr
->hwndToolTip
)
5330 DestroyWindow (infoPtr
->hwndToolTip
);
5332 /* delete temporary buffer for tooltip text */
5333 Free (infoPtr
->pszTooltipText
);
5334 Free (infoPtr
->bitmaps
); /* bitmaps list */
5336 /* delete button data */
5337 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5338 free_string( infoPtr
->buttons
+ i
);
5339 Free (infoPtr
->buttons
);
5341 /* delete strings */
5342 if (infoPtr
->strings
) {
5343 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5344 Free (infoPtr
->strings
[i
]);
5346 Free (infoPtr
->strings
);
5349 /* destroy internal image list */
5350 if (infoPtr
->himlInt
)
5351 ImageList_Destroy (infoPtr
->himlInt
);
5353 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5354 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5355 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5357 /* delete default font */
5358 DeleteObject (infoPtr
->hDefaultFont
);
5360 CloseThemeData (GetWindowTheme (infoPtr
->hwndSelf
));
5362 /* free toolbar info data */
5363 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
5371 TOOLBAR_EraseBackground (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5373 NMTBCUSTOMDRAW tbcd
;
5376 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
5377 DWORD dwEraseCustDraw
= 0;
5379 /* the app has told us not to redraw the toolbar */
5380 if (!infoPtr
->bDoRedraw
)
5383 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5384 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5385 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5386 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5387 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5388 dwEraseCustDraw
= ntfret
& 0xffff;
5390 /* FIXME: in general the return flags *can* be or'ed together */
5391 switch (dwEraseCustDraw
)
5393 case CDRF_DODEFAULT
:
5395 case CDRF_SKIPDEFAULT
:
5398 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5399 infoPtr
->hwndSelf
, ntfret
);
5403 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5404 * to my parent for processing.
5406 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5408 HDC hdc
= (HDC
)wParam
;
5413 parent
= GetParent(infoPtr
->hwndSelf
);
5414 MapWindowPoints(infoPtr
->hwndSelf
, parent
, &pt
, 1);
5415 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5416 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5417 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5420 ret
= DefWindowProcW (infoPtr
->hwndSelf
, WM_ERASEBKGND
, wParam
, lParam
);
5422 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5423 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5424 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5425 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5426 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5427 dwEraseCustDraw
= ntfret
& 0xffff;
5428 switch (dwEraseCustDraw
)
5430 case CDRF_DODEFAULT
:
5432 case CDRF_SKIPDEFAULT
:
5435 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5436 infoPtr
->hwndSelf
, ntfret
);
5443 static inline LRESULT
5444 TOOLBAR_GetFont (const TOOLBAR_INFO
*infoPtr
)
5446 return (LRESULT
)infoPtr
->hFont
;
5451 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5454 INT nNewHotItem
= infoPtr
->nHotItem
;
5456 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5459 if ((nNewHotItem
+ iDirection
< 0) ||
5460 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5462 NMTBWRAPHOTITEM nmtbwhi
;
5463 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5464 nmtbwhi
.iDirection
= iDirection
;
5465 nmtbwhi
.dwReason
= dwReason
;
5467 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5471 nNewHotItem
+= iDirection
;
5472 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5474 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5475 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5477 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5484 TOOLBAR_KeyDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5488 nmkey
.nVKey
= (UINT
)wParam
;
5489 nmkey
.uFlags
= HIWORD(lParam
);
5491 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5492 return DefWindowProcW(infoPtr
->hwndSelf
, WM_KEYDOWN
, wParam
, lParam
);
5494 switch ((UINT
)wParam
)
5498 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5502 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5506 if ((infoPtr
->nHotItem
>= 0) &&
5507 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5509 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5510 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5511 (LPARAM
)infoPtr
->hwndSelf
);
5521 TOOLBAR_LButtonDblClk (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5526 pt
.x
= (short)LOWORD(lParam
);
5527 pt
.y
= (short)HIWORD(lParam
);
5528 TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5531 TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
5532 else if (infoPtr
->dwStyle
& CCS_ADJUSTABLE
)
5533 TOOLBAR_Customize (infoPtr
);
5540 TOOLBAR_LButtonDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5542 TBUTTON_INFO
*btnPtr
;
5547 BOOL bDragKeyPressed
;
5552 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5553 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5555 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5557 if (infoPtr
->hwndToolTip
)
5558 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5559 WM_LBUTTONDOWN
, wParam
, lParam
);
5561 pt
.x
= (short)LOWORD(lParam
);
5562 pt
.y
= (short)HIWORD(lParam
);
5563 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5567 btnPtr
= &infoPtr
->buttons
[nHit
];
5569 if (bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5571 infoPtr
->nButtonDrag
= nHit
;
5572 SetCapture (infoPtr
->hwndSelf
);
5574 /* If drag cursor has not been loaded, load it.
5575 * Note: it doesn't need to be freed */
5577 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5578 SetCursor(hCursorDrag
);
5583 infoPtr
->nOldHit
= nHit
;
5585 arrowRect
= btnPtr
->rect
;
5586 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5588 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5589 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5590 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5591 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5592 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5593 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5597 /* draw in pressed state */
5598 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5599 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5601 btnPtr
->bDropDownPressed
= TRUE
;
5602 RedrawWindow(infoPtr
->hwndSelf
, &btnPtr
->rect
, 0, RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5604 memset(&nmtb
, 0, sizeof(nmtb
));
5605 nmtb
.iItem
= btnPtr
->idCommand
;
5606 nmtb
.rcButton
= btnPtr
->rect
;
5607 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
, TBN_DROPDOWN
);
5608 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5610 if (res
!= TBDDRET_TREATPRESSED
)
5614 /* redraw button in unpressed state */
5615 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5616 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5618 btnPtr
->bDropDownPressed
= FALSE
;
5619 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5621 /* find and set hot item */
5623 ScreenToClient(infoPtr
->hwndSelf
, &pt
);
5624 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5625 if (!infoPtr
->bAnchor
|| button
)
5626 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5628 /* remove any left mouse button down or double-click messages
5629 * so that we can get a toggle effect on the button */
5630 while (PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5631 PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5636 /* otherwise drop through and process as pushed */
5638 infoPtr
->bCaptured
= TRUE
;
5639 infoPtr
->nButtonDown
= nHit
;
5640 infoPtr
->bDragOutSent
= FALSE
;
5642 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5644 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5646 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5647 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5648 UpdateWindow(infoPtr
->hwndSelf
);
5649 SetCapture (infoPtr
->hwndSelf
);
5652 memset(&nmtb
, 0, sizeof(nmtb
));
5653 nmtb
.iItem
= btnPtr
->idCommand
;
5654 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5657 nmmouse
.dwHitInfo
= nHit
;
5659 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5661 nmmouse
.dwItemSpec
= -1;
5664 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5665 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5668 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5671 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5672 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, wParam
, lParam
);
5678 TOOLBAR_LButtonUp (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5680 TBUTTON_INFO
*btnPtr
;
5689 if (infoPtr
->hwndToolTip
)
5690 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5691 WM_LBUTTONUP
, wParam
, lParam
);
5693 pt
.x
= (short)LOWORD(lParam
);
5694 pt
.y
= (short)HIWORD(lParam
);
5695 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5697 if (!infoPtr
->bAnchor
|| button
)
5698 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5700 if (infoPtr
->nButtonDrag
>= 0) {
5704 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5707 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5709 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5710 if (PtInRect(&rcClient
, pt
))
5717 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5720 if (nButton
== infoPtr
->nButtonDrag
)
5722 /* if the button is moved slightly left and we have a
5723 * separator there then remove it */
5724 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5726 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5727 TOOLBAR_DeleteButton(infoPtr
, nButton
- 1);
5729 else /* else insert a separator before the dragged button */
5732 memset(&tbb
, 0, sizeof(tbb
));
5733 tbb
.fsStyle
= BTNS_SEP
;
5735 TOOLBAR_InsertButtonT(infoPtr
, nButton
, &tbb
, TRUE
);
5742 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5743 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, 0);
5745 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5748 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, nButton
);
5753 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5754 TOOLBAR_DeleteButton(infoPtr
, infoPtr
->nButtonDrag
);
5757 /* button under cursor changed so need to re-set hot item */
5758 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5759 infoPtr
->nButtonDrag
= -1;
5761 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5763 else if (infoPtr
->nButtonDown
>= 0)
5765 BOOL was_clicked
= nHit
== infoPtr
->nButtonDown
;
5767 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5768 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5770 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5771 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5772 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5774 if ((nOldIndex
!= nHit
) &&
5776 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5777 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5780 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5781 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5783 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5787 if (nOldIndex
!= -1)
5788 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5791 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5792 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5793 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5795 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5797 infoPtr
->nButtonDown
= -1;
5799 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5800 TOOLBAR_SendNotify (&hdr
, infoPtr
,
5801 NM_RELEASEDCAPTURE
);
5803 memset(&nmtb
, 0, sizeof(nmtb
));
5804 nmtb
.iItem
= btnPtr
->idCommand
;
5805 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5808 if (was_clicked
&& btnPtr
->fsState
& TBSTATE_ENABLED
)
5810 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5811 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)infoPtr
->hwndSelf
);
5813 /* In case we have just been destroyed... */
5814 if(!IsWindow(infoPtr
->hwndSelf
))
5819 /* !!! Undocumented - toolbar at 4.71 level and above sends
5820 * NM_CLICK with the NMMOUSE structure. */
5821 nmmouse
.dwHitInfo
= nHit
;
5824 nmmouse
.dwItemSpec
= -1;
5827 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5828 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5831 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5834 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5835 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONUP
, wParam
, lParam
);
5841 TOOLBAR_RButtonUp(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5848 pt
.x
= (short)LOWORD(lParam
);
5849 pt
.y
= (short)HIWORD(lParam
);
5851 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5852 nmmouse
.dwHitInfo
= nHit
;
5855 nmmouse
.dwItemSpec
= -1;
5857 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5858 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5861 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5864 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5865 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONUP
, wParam
, lParam
);
5871 TOOLBAR_RButtonDblClk( TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5875 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5876 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
5882 TOOLBAR_CaptureChanged(TOOLBAR_INFO
*infoPtr
)
5884 TBUTTON_INFO
*btnPtr
;
5886 infoPtr
->bCaptured
= FALSE
;
5888 if (infoPtr
->nButtonDown
>= 0)
5890 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5891 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5893 infoPtr
->nOldHit
= -1;
5895 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5896 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5902 TOOLBAR_MouseLeave (TOOLBAR_INFO
*infoPtr
)
5904 /* don't remove hot effects when in anchor highlighting mode or when a
5905 * drop-down button is pressed */
5906 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
5908 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
5909 if (!hotBtnPtr
->bDropDownPressed
)
5910 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
5913 if (infoPtr
->nOldHit
< 0)
5916 /* If the last button we were over is depressed then make it not */
5917 /* depressed and redraw it */
5918 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
5920 TBUTTON_INFO
*btnPtr
;
5923 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5925 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5928 InflateRect (&rc1
, 1, 1);
5929 InvalidateRect (infoPtr
->hwndSelf
, &rc1
, TRUE
);
5932 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
5935 ZeroMemory(&nmt
, sizeof(nmt
));
5936 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5937 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5938 infoPtr
->bDragOutSent
= TRUE
;
5941 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
5947 TOOLBAR_MouseMove (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5950 TRACKMOUSEEVENT trackinfo
;
5952 TBUTTON_INFO
*btnPtr
;
5955 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
5956 TOOLBAR_TooltipCreateControl(infoPtr
);
5958 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
5959 /* fill in the TRACKMOUSEEVENT struct */
5960 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5961 trackinfo
.dwFlags
= TME_QUERY
;
5963 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5964 _TrackMouseEvent(&trackinfo
);
5966 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5967 if(trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
5968 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5969 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
5971 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5972 /* and can properly deactivate the hot toolbar button */
5973 _TrackMouseEvent(&trackinfo
);
5977 if (infoPtr
->hwndToolTip
)
5978 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5979 WM_MOUSEMOVE
, wParam
, lParam
);
5981 pt
.x
= (short)LOWORD(lParam
);
5982 pt
.y
= (short)HIWORD(lParam
);
5984 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5986 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
5987 && (!infoPtr
->bAnchor
|| button
))
5988 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
);
5990 if (infoPtr
->nOldHit
!= nHit
)
5992 if (infoPtr
->bCaptured
)
5994 if (!infoPtr
->bDragOutSent
)
5997 ZeroMemory(&nmt
, sizeof(nmt
));
5998 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5999 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6000 infoPtr
->bDragOutSent
= TRUE
;
6003 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6004 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
6005 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6006 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6008 else if (nHit
== infoPtr
->nButtonDown
) {
6009 btnPtr
->fsState
|= TBSTATE_PRESSED
;
6010 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6012 infoPtr
->nOldHit
= nHit
;
6020 static inline LRESULT
6021 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6023 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6024 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
6026 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6030 static inline LRESULT
6031 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6033 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
6034 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
6036 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
6041 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
6043 TOOLBAR_INFO
*infoPtr
;
6046 /* allocate memory for info structure */
6047 infoPtr
= Alloc (sizeof(TOOLBAR_INFO
));
6048 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
6051 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
6054 /* initialize info structure */
6055 infoPtr
->nButtonWidth
= 23;
6056 infoPtr
->nButtonHeight
= 22;
6057 infoPtr
->nBitmapHeight
= 16;
6058 infoPtr
->nBitmapWidth
= 16;
6060 infoPtr
->nMaxTextRows
= 1;
6061 infoPtr
->cxMin
= -1;
6062 infoPtr
->cxMax
= -1;
6063 infoPtr
->nNumBitmaps
= 0;
6064 infoPtr
->nNumStrings
= 0;
6066 infoPtr
->bCaptured
= FALSE
;
6067 infoPtr
->nButtonDown
= -1;
6068 infoPtr
->nButtonDrag
= -1;
6069 infoPtr
->nOldHit
= -1;
6070 infoPtr
->nHotItem
= -1;
6071 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
6072 infoPtr
->dwDTFlags
= (lpcs
->style
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
6073 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
6074 infoPtr
->bDragOutSent
= FALSE
;
6075 infoPtr
->iVersion
= 0;
6076 infoPtr
->hwndSelf
= hwnd
;
6077 infoPtr
->bDoRedraw
= TRUE
;
6078 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
6079 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
6080 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
6081 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
6082 infoPtr
->iListGap
= DEFLISTGAP
;
6083 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
6084 infoPtr
->dwStyle
= lpcs
->style
;
6085 infoPtr
->tbim
.iButton
= -1;
6087 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6088 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
6089 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
6090 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
6093 /* I think the code below is a bug, but it is the way that the native
6094 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6095 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6096 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6097 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6098 * Somehow, the only cases of this seem to be MFC programs.
6100 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6101 * does not occur in the WM_STYLECHANGING routine.
6102 * (Guy Albertelli 9/2001)
6105 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6106 && !(lpcs
->style
& TBSTYLE_TRANSPARENT
))
6107 styleadd
|= TBSTYLE_TRANSPARENT
;
6108 if (!(lpcs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
6109 styleadd
|= CCS_TOP
; /* default to top */
6110 SetWindowLongW (hwnd
, GWL_STYLE
, lpcs
->style
| styleadd
);
6113 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
6118 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6120 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
6124 if (dwStyle
& WS_MINIMIZE
)
6125 return 0; /* Nothing to do */
6127 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
6129 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
6132 if (!(dwStyle
& CCS_NODIVIDER
))
6134 GetWindowRect (hwnd
, &rcWindow
);
6135 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
6136 if( dwStyle
& WS_BORDER
)
6137 InflateRect (&rcWindow
, -1, -1);
6138 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6141 ReleaseDC( hwnd
, hdc
);
6147 /* handles requests from the tooltip control on what text to display */
6148 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6150 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6151 NMTTDISPINFOA nmtdi
;
6155 TRACE("button index = %d\n", index
);
6157 Free (infoPtr
->pszTooltipText
);
6158 infoPtr
->pszTooltipText
= NULL
;
6163 if (infoPtr
->bUnicode
)
6165 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6166 NMTBGETINFOTIPW tbgit
;
6168 wszBuffer
[0] = '\0';
6169 wszBuffer
[INFOTIPSIZE
] = '\0';
6171 tbgit
.pszText
= wszBuffer
;
6172 tbgit
.cchTextMax
= INFOTIPSIZE
;
6173 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6174 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6176 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6178 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6180 len
= tbgit
.pszText
? lstrlenW(tbgit
.pszText
) : 0;
6181 if (len
> ARRAY_SIZE(lpnmtdi
->szText
) - 1)
6183 /* need to allocate temporary buffer in infoPtr as there
6184 * isn't enough space in buffer passed to us by the
6185 * tooltip control */
6186 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6187 if (infoPtr
->pszTooltipText
)
6189 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6190 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6196 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6202 CHAR szBuffer
[INFOTIPSIZE
+1];
6203 NMTBGETINFOTIPA tbgit
;
6206 szBuffer
[INFOTIPSIZE
] = '\0';
6208 tbgit
.pszText
= szBuffer
;
6209 tbgit
.cchTextMax
= INFOTIPSIZE
;
6210 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6211 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6213 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6215 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6217 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6218 if (len
> ARRAY_SIZE(lpnmtdi
->szText
))
6220 /* need to allocate temporary buffer in infoPtr as there
6221 * isn't enough space in buffer passed to us by the
6222 * tooltip control */
6223 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6224 if (infoPtr
->pszTooltipText
)
6226 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6227 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6231 else if (tbgit
.pszText
&& tbgit
.pszText
[0])
6233 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, lpnmtdi
->lpszText
, ARRAY_SIZE(lpnmtdi
->szText
));
6238 /* if button has text, but it is not shown then automatically
6239 * use that text as tooltip */
6240 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6241 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6243 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6244 len
= pszText
? lstrlenW(pszText
) : 0;
6246 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6248 if (len
> ARRAY_SIZE(lpnmtdi
->szText
) - 1)
6250 /* need to allocate temporary buffer in infoPtr as there
6251 * isn't enough space in buffer passed to us by the
6252 * tooltip control */
6253 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6254 if (infoPtr
->pszTooltipText
)
6256 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6257 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6263 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6268 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6270 /* Last resort, forward TTN_GETDISPINFO to the app:
6272 - NFR_UNICODE gets TTN_GETDISPINFOW, and TTN_GETDISPINFOA if -W returned no text;
6273 - NFR_ANSI gets only TTN_GETDISPINFOA.
6275 if (infoPtr
->bUnicode
)
6277 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmtdi
->hdr
.idFrom
, (LPARAM
)lpnmtdi
);
6279 TRACE("TTN_GETDISPINFOW - got string %s\n", debugstr_w(lpnmtdi
->lpszText
));
6281 if (IS_INTRESOURCE(lpnmtdi
->lpszText
))
6284 if (lpnmtdi
->lpszText
&& *lpnmtdi
->lpszText
)
6288 nmtdi
.hdr
.hwndFrom
= lpnmtdi
->hdr
.hwndFrom
;
6289 nmtdi
.hdr
.idFrom
= lpnmtdi
->hdr
.idFrom
;
6290 nmtdi
.hdr
.code
= TTN_GETDISPINFOA
;
6291 nmtdi
.lpszText
= nmtdi
.szText
;
6292 nmtdi
.szText
[0] = 0;
6293 nmtdi
.hinst
= lpnmtdi
->hinst
;
6294 nmtdi
.uFlags
= lpnmtdi
->uFlags
;
6295 nmtdi
.lParam
= lpnmtdi
->lParam
;
6297 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmtdi
.hdr
.idFrom
, (LPARAM
)&nmtdi
);
6299 TRACE("TTN_GETDISPINFOA - got string %s\n", debugstr_a(nmtdi
.lpszText
));
6301 lpnmtdi
->hinst
= nmtdi
.hinst
;
6302 lpnmtdi
->uFlags
= nmtdi
.uFlags
;
6303 lpnmtdi
->lParam
= nmtdi
.lParam
;
6305 if (IS_INTRESOURCE(nmtdi
.lpszText
))
6307 lpnmtdi
->lpszText
= (WCHAR
*)nmtdi
.lpszText
;
6311 if (!nmtdi
.lpszText
|| !*nmtdi
.lpszText
)
6314 len
= MultiByteToWideChar(CP_ACP
, 0, nmtdi
.lpszText
, -1, NULL
, 0);
6315 if (len
> ARRAY_SIZE(lpnmtdi
->szText
))
6317 infoPtr
->pszTooltipText
= Alloc(len
* sizeof(WCHAR
));
6318 if (infoPtr
->pszTooltipText
)
6320 MultiByteToWideChar(CP_ACP
, 0, nmtdi
.lpszText
, -1, infoPtr
->pszTooltipText
, len
);
6321 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6327 MultiByteToWideChar(CP_ACP
, 0, nmtdi
.lpszText
, -1, lpnmtdi
->lpszText
, ARRAY_SIZE(nmtdi
.szText
));
6335 static inline LRESULT
6336 TOOLBAR_Notify (TOOLBAR_INFO
*infoPtr
, LPNMHDR lpnmh
)
6338 switch (lpnmh
->code
)
6342 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lpnmh
;
6344 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6345 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6346 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6350 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6351 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6359 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lpnmh
;
6361 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6362 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6363 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6364 lppgs
->iScroll
, lppgs
->iDir
);
6368 case TTN_GETDISPINFOW
:
6369 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lpnmh
);
6371 case TTN_GETDISPINFOA
:
6372 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6382 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6386 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam
, lParam
);
6388 if (lParam
== NF_QUERY
)
6391 if (lParam
== NF_REQUERY
) {
6392 format
= SendMessageW(infoPtr
->hwndNotify
,
6393 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6394 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6395 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6406 TOOLBAR_Paint (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6411 /* fill ps.rcPaint with a default rect */
6412 ps
.rcPaint
= infoPtr
->rcBound
;
6414 hdc
= wParam
==0 ? BeginPaint(infoPtr
->hwndSelf
, &ps
) : (HDC
)wParam
;
6416 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps
.rcPaint
));
6418 TOOLBAR_Refresh (infoPtr
, hdc
, &ps
);
6419 if (!wParam
) EndPaint (infoPtr
->hwndSelf
, &ps
);
6426 TOOLBAR_SetFocus (TOOLBAR_INFO
*infoPtr
)
6428 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6430 /* make first item hot */
6431 if (infoPtr
->nNumButtons
> 0)
6432 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6438 TOOLBAR_SetFont(TOOLBAR_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
6440 TRACE("font=%p redraw=%d\n", hFont
, Redraw
);
6443 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6445 infoPtr
->hFont
= hFont
;
6447 TOOLBAR_CalcToolbar(infoPtr
);
6450 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6455 TOOLBAR_SetRedraw (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6456 /*****************************************************
6459 * Handles the WM_SETREDRAW message.
6462 * According to testing V4.71 of COMCTL32 returns the
6463 * *previous* status of the redraw flag (either 0 or 1)
6464 * instead of the MSDN documented value of 0 if handled.
6465 * (For laughs see the "consistency" with same function
6468 *****************************************************/
6470 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6472 TRACE("set to %s\n",
6473 (wParam
) ? "TRUE" : "FALSE");
6474 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6476 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6478 return (oldredraw
) ? 1 : 0;
6483 TOOLBAR_Size (TOOLBAR_INFO
*infoPtr
)
6485 TRACE("sizing toolbar\n");
6487 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6489 RECT delta_width
, delta_height
, client
, dummy
;
6490 DWORD min_x
, max_x
, min_y
, max_y
;
6491 TBUTTON_INFO
*btnPtr
;
6494 GetClientRect(infoPtr
->hwndSelf
, &client
);
6495 if(client
.right
> infoPtr
->client_rect
.right
)
6497 min_x
= infoPtr
->client_rect
.right
;
6498 max_x
= client
.right
;
6502 max_x
= infoPtr
->client_rect
.right
;
6503 min_x
= client
.right
;
6505 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6507 min_y
= infoPtr
->client_rect
.bottom
;
6508 max_y
= client
.bottom
;
6512 max_y
= infoPtr
->client_rect
.bottom
;
6513 min_y
= client
.bottom
;
6516 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6517 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6519 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6520 btnPtr
= infoPtr
->buttons
;
6521 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6522 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6523 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6524 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6526 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->client_rect
);
6527 TOOLBAR_AutoSize(infoPtr
);
6533 TOOLBAR_StyleChanged (TOOLBAR_INFO
*infoPtr
, INT nType
, const STYLESTRUCT
*lpStyle
)
6535 if (nType
== GWL_STYLE
)
6536 return TOOLBAR_SetStyle(infoPtr
, lpStyle
->styleNew
);
6543 TOOLBAR_SysColorChange (void)
6545 COMCTL32_RefreshSysColors();
6551 /* update theme after a WM_THEMECHANGED message */
6552 static LRESULT
theme_changed (HWND hwnd
)
6554 HTHEME theme
= GetWindowTheme (hwnd
);
6555 CloseThemeData (theme
);
6556 OpenThemeData (hwnd
, themeClass
);
6561 static LRESULT WINAPI
6562 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6564 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
6566 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6567 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6569 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6570 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6575 return TOOLBAR_AddBitmap (infoPtr
, (INT
)wParam
, (TBADDBITMAP
*)lParam
);
6577 case TB_ADDBUTTONSA
:
6578 case TB_ADDBUTTONSW
:
6579 return TOOLBAR_AddButtonsT (infoPtr
, wParam
, (LPTBBUTTON
)lParam
,
6580 uMsg
== TB_ADDBUTTONSW
);
6582 return TOOLBAR_AddStringA (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6585 return TOOLBAR_AddStringW (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6588 return TOOLBAR_AutoSize (infoPtr
);
6590 case TB_BUTTONCOUNT
:
6591 return TOOLBAR_ButtonCount (infoPtr
);
6593 case TB_BUTTONSTRUCTSIZE
:
6594 return TOOLBAR_ButtonStructSize (infoPtr
, wParam
);
6596 case TB_CHANGEBITMAP
:
6597 return TOOLBAR_ChangeBitmap (infoPtr
, wParam
, LOWORD(lParam
));
6599 case TB_CHECKBUTTON
:
6600 return TOOLBAR_CheckButton (infoPtr
, wParam
, lParam
);
6602 case TB_COMMANDTOINDEX
:
6603 return TOOLBAR_CommandToIndex (infoPtr
, wParam
);
6606 return TOOLBAR_Customize (infoPtr
);
6608 case TB_DELETEBUTTON
:
6609 return TOOLBAR_DeleteButton (infoPtr
, wParam
);
6611 case TB_ENABLEBUTTON
:
6612 return TOOLBAR_EnableButton (infoPtr
, wParam
, lParam
);
6614 case TB_GETANCHORHIGHLIGHT
:
6615 return TOOLBAR_GetAnchorHighlight (infoPtr
);
6618 return TOOLBAR_GetBitmap (infoPtr
, wParam
);
6620 case TB_GETBITMAPFLAGS
:
6621 return TOOLBAR_GetBitmapFlags ();
6624 return TOOLBAR_GetButton (infoPtr
, wParam
, (TBBUTTON
*)lParam
);
6626 case TB_GETBUTTONINFOA
:
6627 case TB_GETBUTTONINFOW
:
6628 return TOOLBAR_GetButtonInfoT (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6629 uMsg
== TB_GETBUTTONINFOW
);
6630 case TB_GETBUTTONSIZE
:
6631 return TOOLBAR_GetButtonSize (infoPtr
);
6633 case TB_GETBUTTONTEXTA
:
6634 case TB_GETBUTTONTEXTW
:
6635 return TOOLBAR_GetButtonText (infoPtr
, wParam
, (LPWSTR
)lParam
,
6636 uMsg
== TB_GETBUTTONTEXTW
);
6638 case TB_GETDISABLEDIMAGELIST
:
6639 return TOOLBAR_GetDisabledImageList (infoPtr
, wParam
);
6641 case TB_GETEXTENDEDSTYLE
:
6642 return TOOLBAR_GetExtendedStyle (infoPtr
);
6644 case TB_GETHOTIMAGELIST
:
6645 return TOOLBAR_GetHotImageList (infoPtr
, wParam
);
6648 return TOOLBAR_GetHotItem (infoPtr
);
6650 case TB_GETIMAGELIST
:
6651 return TOOLBAR_GetDefImageList (infoPtr
, wParam
);
6653 case TB_GETINSERTMARK
:
6654 return TOOLBAR_GetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6656 case TB_GETINSERTMARKCOLOR
:
6657 return TOOLBAR_GetInsertMarkColor (infoPtr
);
6659 case TB_GETITEMRECT
:
6660 return TOOLBAR_GetItemRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6663 return TOOLBAR_GetMaxSize (infoPtr
, (LPSIZE
)lParam
);
6665 /* case TB_GETOBJECT: */ /* 4.71 */
6668 return TOOLBAR_GetPadding (infoPtr
);
6671 return TOOLBAR_GetRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6674 return TOOLBAR_GetRows (infoPtr
);
6677 return TOOLBAR_GetState (infoPtr
, wParam
);
6680 return TOOLBAR_GetStringA (infoPtr
, wParam
, (LPSTR
)lParam
);
6683 return TOOLBAR_GetStringW (infoPtr
, wParam
, (LPWSTR
)lParam
);
6686 return TOOLBAR_GetStyle (infoPtr
);
6688 case TB_GETTEXTROWS
:
6689 return TOOLBAR_GetTextRows (infoPtr
);
6691 case TB_GETTOOLTIPS
:
6692 return TOOLBAR_GetToolTips (infoPtr
);
6694 case TB_GETUNICODEFORMAT
:
6695 return TOOLBAR_GetUnicodeFormat (infoPtr
);
6698 return TOOLBAR_HideButton (infoPtr
, wParam
, LOWORD(lParam
));
6701 return TOOLBAR_HitTest (infoPtr
, (LPPOINT
)lParam
);
6703 case TB_INDETERMINATE
:
6704 return TOOLBAR_Indeterminate (infoPtr
, wParam
, LOWORD(lParam
));
6706 case TB_INSERTBUTTONA
:
6707 case TB_INSERTBUTTONW
:
6708 return TOOLBAR_InsertButtonT(infoPtr
, wParam
, (TBBUTTON
*)lParam
,
6709 uMsg
== TB_INSERTBUTTONW
);
6711 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6713 case TB_ISBUTTONCHECKED
:
6714 return TOOLBAR_IsButtonChecked (infoPtr
, wParam
);
6716 case TB_ISBUTTONENABLED
:
6717 return TOOLBAR_IsButtonEnabled (infoPtr
, wParam
);
6719 case TB_ISBUTTONHIDDEN
:
6720 return TOOLBAR_IsButtonHidden (infoPtr
, wParam
);
6722 case TB_ISBUTTONHIGHLIGHTED
:
6723 return TOOLBAR_IsButtonHighlighted (infoPtr
, wParam
);
6725 case TB_ISBUTTONINDETERMINATE
:
6726 return TOOLBAR_IsButtonIndeterminate (infoPtr
, wParam
);
6728 case TB_ISBUTTONPRESSED
:
6729 return TOOLBAR_IsButtonPressed (infoPtr
, wParam
);
6732 return TOOLBAR_LoadImages (infoPtr
, wParam
, (HINSTANCE
)lParam
);
6734 case TB_MAPACCELERATORA
:
6735 case TB_MAPACCELERATORW
:
6736 return TOOLBAR_MapAccelerator (infoPtr
, wParam
, (UINT
*)lParam
);
6739 return TOOLBAR_MarkButton (infoPtr
, wParam
, LOWORD(lParam
));
6742 return TOOLBAR_MoveButton (infoPtr
, wParam
, lParam
);
6744 case TB_PRESSBUTTON
:
6745 return TOOLBAR_PressButton (infoPtr
, wParam
, LOWORD(lParam
));
6747 case TB_REPLACEBITMAP
:
6748 return TOOLBAR_ReplaceBitmap (infoPtr
, (LPTBREPLACEBITMAP
)lParam
);
6750 case TB_SAVERESTOREA
:
6751 return TOOLBAR_SaveRestoreA (infoPtr
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6753 case TB_SAVERESTOREW
:
6754 return TOOLBAR_SaveRestoreW (infoPtr
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6756 case TB_SETANCHORHIGHLIGHT
:
6757 return TOOLBAR_SetAnchorHighlight (infoPtr
, (BOOL
)wParam
);
6759 case TB_SETBITMAPSIZE
:
6760 return TOOLBAR_SetBitmapSize (infoPtr
, wParam
, lParam
);
6762 case TB_SETBUTTONINFOA
:
6763 case TB_SETBUTTONINFOW
:
6764 return TOOLBAR_SetButtonInfo (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6765 uMsg
== TB_SETBUTTONINFOW
);
6766 case TB_SETBUTTONSIZE
:
6767 return TOOLBAR_SetButtonSize (infoPtr
, lParam
);
6769 case TB_SETBUTTONWIDTH
:
6770 return TOOLBAR_SetButtonWidth (infoPtr
, lParam
);
6773 return TOOLBAR_SetCmdId (infoPtr
, wParam
, lParam
);
6775 case TB_SETDISABLEDIMAGELIST
:
6776 return TOOLBAR_SetDisabledImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6778 case TB_SETDRAWTEXTFLAGS
:
6779 return TOOLBAR_SetDrawTextFlags (infoPtr
, wParam
, lParam
);
6781 case TB_SETEXTENDEDSTYLE
:
6782 return TOOLBAR_SetExtendedStyle (infoPtr
, wParam
, lParam
);
6784 case TB_SETHOTIMAGELIST
:
6785 return TOOLBAR_SetHotImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6788 return TOOLBAR_SetHotItem (infoPtr
, wParam
);
6790 case TB_SETIMAGELIST
:
6791 return TOOLBAR_SetImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6794 return TOOLBAR_SetIndent (infoPtr
, wParam
);
6796 case TB_SETINSERTMARK
:
6797 return TOOLBAR_SetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6799 case TB_SETINSERTMARKCOLOR
:
6800 return TOOLBAR_SetInsertMarkColor (infoPtr
, lParam
);
6802 case TB_SETMAXTEXTROWS
:
6803 return TOOLBAR_SetMaxTextRows (infoPtr
, wParam
);
6806 return TOOLBAR_SetPadding (infoPtr
, lParam
);
6809 return TOOLBAR_SetParent (infoPtr
, (HWND
)wParam
);
6812 return TOOLBAR_SetRows (infoPtr
, wParam
, (LPRECT
)lParam
);
6815 return TOOLBAR_SetState (infoPtr
, wParam
, lParam
);
6818 return TOOLBAR_SetStyle (infoPtr
, lParam
);
6820 case TB_SETTOOLTIPS
:
6821 return TOOLBAR_SetToolTips (infoPtr
, (HWND
)wParam
);
6823 case TB_SETUNICODEFORMAT
:
6824 return TOOLBAR_SetUnicodeFormat (infoPtr
, wParam
);
6826 case TB_SETBOUNDINGSIZE
:
6827 return TOOLBAR_SetBoundingSize(hwnd
, wParam
, lParam
);
6829 case TB_SETHOTITEM2
:
6830 return TOOLBAR_SetHotItem2 (infoPtr
, wParam
, lParam
);
6833 return TOOLBAR_SetListGap(infoPtr
, wParam
);
6835 case TB_GETIMAGELISTCOUNT
:
6836 return TOOLBAR_GetImageListCount(infoPtr
);
6838 case TB_GETIDEALSIZE
:
6839 return TOOLBAR_GetIdealSize (infoPtr
, wParam
, lParam
);
6842 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6844 /* Common Control Messages */
6846 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6847 case CCM_GETCOLORSCHEME
:
6848 return TOOLBAR_GetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6850 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6851 case CCM_SETCOLORSCHEME
:
6852 return TOOLBAR_SetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6854 case CCM_GETVERSION
:
6855 return TOOLBAR_GetVersion (infoPtr
);
6857 case CCM_SETVERSION
:
6858 return TOOLBAR_SetVersion (infoPtr
, (INT
)wParam
);
6864 return TOOLBAR_Create (hwnd
, (CREATESTRUCTW
*)lParam
);
6867 return TOOLBAR_Destroy (infoPtr
);
6870 return TOOLBAR_EraseBackground (infoPtr
, wParam
, lParam
);
6873 return TOOLBAR_GetFont (infoPtr
);
6876 return TOOLBAR_KeyDown (infoPtr
, wParam
, lParam
);
6878 /* case WM_KILLFOCUS: */
6880 case WM_LBUTTONDBLCLK
:
6881 return TOOLBAR_LButtonDblClk (infoPtr
, wParam
, lParam
);
6883 case WM_LBUTTONDOWN
:
6884 return TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
6887 return TOOLBAR_LButtonUp (infoPtr
, wParam
, lParam
);
6890 return TOOLBAR_RButtonUp (infoPtr
, wParam
, lParam
);
6892 case WM_RBUTTONDBLCLK
:
6893 return TOOLBAR_RButtonDblClk (infoPtr
, wParam
, lParam
);
6896 return TOOLBAR_MouseMove (infoPtr
, wParam
, lParam
);
6899 return TOOLBAR_MouseLeave (infoPtr
);
6901 case WM_CAPTURECHANGED
:
6902 if (hwnd
== (HWND
)lParam
) return 0;
6903 return TOOLBAR_CaptureChanged(infoPtr
);
6906 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6909 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6912 return TOOLBAR_NCCreate (hwnd
, wParam
, (CREATESTRUCTW
*)lParam
);
6915 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
6918 return TOOLBAR_Notify (infoPtr
, (LPNMHDR
)lParam
);
6920 case WM_NOTIFYFORMAT
:
6921 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
6923 case WM_PRINTCLIENT
:
6925 return TOOLBAR_Paint (infoPtr
, wParam
);
6928 return TOOLBAR_SetFocus (infoPtr
);
6931 return TOOLBAR_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
6934 return TOOLBAR_SetRedraw (infoPtr
, wParam
);
6937 return TOOLBAR_Size (infoPtr
);
6939 case WM_STYLECHANGED
:
6940 return TOOLBAR_StyleChanged (infoPtr
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
6942 case WM_SYSCOLORCHANGE
:
6943 return TOOLBAR_SysColorChange ();
6945 case WM_THEMECHANGED
:
6946 return theme_changed (hwnd
);
6948 /* case WM_WININICHANGE: */
6953 case WM_MEASUREITEM
:
6955 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
6957 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6958 case PGM_FORWARDMOUSE
:
6959 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6962 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
6963 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
6964 uMsg
, wParam
, lParam
);
6965 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6971 TOOLBAR_Register (void)
6975 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
6976 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
6977 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
6978 wndClass
.cbClsExtra
= 0;
6979 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
6980 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
6981 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
6982 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
6984 RegisterClassW (&wndClass
);
6989 TOOLBAR_Unregister (void)
6991 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
6994 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
6999 /* Check if the entry already exists */
7000 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
7002 /* Don't add new entry for NULL imagelist */
7006 /* If this is a new entry we must create it and insert into the array */
7011 c
= Alloc(sizeof(IMLENTRY
));
7014 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
7015 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
7030 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
7034 for (i
= 0; i
< *cies
; i
++)
7044 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
7052 for (i
= 0; i
< cies
; i
++)
7054 if (pies
[i
]->id
== id
)
7066 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
7068 HIMAGELIST himlDef
= 0;
7069 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
7072 himlDef
= pie
->himl
;
7078 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
7080 if (infoPtr
->bUnicode
)
7081 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
7088 nmtba
.iItem
= nmtb
->iItem
;
7089 nmtba
.pszText
= Buffer
;
7090 nmtba
.cchText
= 256;
7091 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
7093 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
7095 int ccht
= strlen(nmtba
.pszText
);
7097 MultiByteToWideChar(CP_ACP
, 0, nmtba
.pszText
, -1,
7098 nmtb
->pszText
, nmtb
->cchText
);
7100 nmtb
->tbButton
= nmtba
.tbButton
;
7109 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
)
7113 /* MSDN states that iItem is the index of the button, rather than the
7114 * command ID as used by every other NMTOOLBAR notification */
7116 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
7118 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);