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
)
679 HBITMAP hbmMask
, hbmImage
;
680 HDC hdcMask
, hdcImage
;
682 ImageList_GetIconSize(himl
, &cx
, &cy
);
684 /* Create src image */
685 hdcImage
= CreateCompatibleDC(hdc
);
686 hbmImage
= CreateCompatibleBitmap(hdc
, cx
, cy
);
687 SelectObject(hdcImage
, hbmImage
);
688 ImageList_DrawEx(himl
, index
, hdcImage
, 0, 0, cx
, cy
,
689 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags
);
692 hdcMask
= CreateCompatibleDC(0);
693 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
694 SelectObject(hdcMask
, hbmMask
);
696 /* Remove the background and all white pixels */
697 ImageList_DrawEx(himl
, index
, hdcMask
, 0, 0, cx
, cy
,
698 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK
);
699 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
700 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
702 /* draw the new mask 'etched' to hdc */
703 SetBkColor(hdc
, RGB(255, 255, 255));
704 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
705 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
706 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
707 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
708 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
711 DeleteObject(hbmImage
);
713 DeleteObject (hbmMask
);
719 TOOLBAR_TranslateState(const TBUTTON_INFO
*btnPtr
, BOOL captured
)
723 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
724 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
725 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
726 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
727 retstate
|= (btnPtr
->bHot
& !captured
) ? CDIS_HOT
: 0;
728 retstate
|= ((btnPtr
->fsState
& (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) == (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) ? CDIS_INDETERMINATE
: 0;
729 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
733 /* draws the image on a toolbar button */
735 TOOLBAR_DrawImage(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
,
736 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
738 HIMAGELIST himl
= NULL
;
739 BOOL draw_masked
= FALSE
;
742 UINT draw_flags
= ILD_TRANSPARENT
;
744 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
746 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
749 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
753 else if (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
||
754 ((tbcd
->nmcd
.uItemState
& CDIS_HOT
)
755 && ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))))
757 /* if hot, attempt to draw with hot image list, if fails,
758 use default image list */
759 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
761 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
764 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
769 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
770 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
773 if (!(dwItemCDFlag
& TBCDRF_NOMARK
) &&
774 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
775 draw_flags
|= ILD_BLEND50
;
777 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
778 index
, himl
, left
, top
, offset
);
781 TOOLBAR_DrawMasked (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
783 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
786 /* draws a blank frame for a toolbar button */
788 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, const RECT
*rect
, DWORD dwItemCDFlag
)
790 HDC hdc
= tbcd
->nmcd
.hdc
;
792 /* if the state is disabled or indeterminate then the button
793 * cannot have an interactive look like pressed or hot */
794 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
795 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
796 BOOL pressed_look
= !non_interactive_state
&&
797 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
798 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
800 /* app don't want us to draw any edges */
801 if (dwItemCDFlag
& TBCDRF_NOEDGES
)
804 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
807 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
808 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
809 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
814 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
816 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
817 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
822 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
, BOOL bDropDownPressed
, DWORD dwItemCDFlag
)
824 HDC hdc
= tbcd
->nmcd
.hdc
;
826 BOOL pressed
= bDropDownPressed
||
827 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
));
829 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
832 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
);
833 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
834 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
835 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
836 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
841 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
843 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
844 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
848 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
850 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
852 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
853 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
856 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
859 /* draws a complete toolbar button */
861 TOOLBAR_DrawButton (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, HDC hdc
, DWORD dwBaseCustDraw
)
863 DWORD dwStyle
= infoPtr
->dwStyle
;
864 BOOL hasDropDownArrow
= button_has_ddarrow( infoPtr
, btnPtr
);
865 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
866 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
867 RECT rc
, rcArrow
, rcBitmap
, rcText
;
868 LPWSTR lpText
= NULL
;
873 DWORD dwItemCustDraw
;
875 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
880 /* separator - doesn't send NM_CUSTOMDRAW */
881 if (btnPtr
->fsStyle
& BTNS_SEP
) {
884 DrawThemeBackground (theme
, hdc
,
885 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
889 /* with the FLAT style, iBitmap is the width and has already */
890 /* been taken into consideration in calculating the width */
891 /* so now we need to draw the vertical separator */
892 /* empirical tests show that iBitmap can/will be non-zero */
893 /* when drawing the vertical bar... */
894 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
895 if (dwStyle
& CCS_VERT
) {
897 InflateRect(&rcsep
, -infoPtr
->szPadding
.cx
, -infoPtr
->szPadding
.cy
);
898 TOOLBAR_DrawFlatHorizontalSeparator (&rcsep
, hdc
, infoPtr
);
901 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
903 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
904 FIXME("Draw some kind of separator: fsStyle=%x\n",
910 /* get a pointer to the text */
911 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
913 if (hasDropDownArrow
)
917 if (dwStyle
& TBSTYLE_FLAT
)
918 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
920 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
922 if (drawSepDropDownArrow
)
925 rcArrow
.left
= right
;
928 /* copy text & bitmap rects after adjusting for drop-down arrow
929 * so that text & bitmap is centered in the rectangle not containing
934 /* Center the bitmap horizontally and vertically */
935 if (dwStyle
& TBSTYLE_LIST
)
938 infoPtr
->nMaxTextRows
> 0 &&
939 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
940 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
941 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
943 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
946 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
948 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
950 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
951 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
952 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
953 TRACE("Text=%s\n", debugstr_w(lpText
));
954 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
956 /* calculate text position */
959 InflateRect(&rcText
, -GetSystemMetrics(SM_CXEDGE
), 0);
960 if (dwStyle
& TBSTYLE_LIST
)
962 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
966 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
967 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
969 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
973 /* Initialize fields in all cases, because we use these later
974 * NOTE: applications can and do alter these to customize their
976 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
977 tbcd
.clrText
= comctl32_color
.clrBtnText
;
978 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
979 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
980 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
981 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
982 tbcd
.clrHighlightHotTrack
= 0;
983 tbcd
.nStringBkMode
= TRANSPARENT
;
984 tbcd
.nHLStringBkMode
= OPAQUE
;
985 tbcd
.rcText
.left
= 0;
987 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
988 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
989 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
, infoPtr
->bCaptured
);
991 tbcd
.nmcd
.rc
= btnPtr
->rect
;
992 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
994 /* FIXME: what are these used for? */
998 /* Issue Item Prepaint notify */
1001 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
1003 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
1004 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
1005 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
1006 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1007 /* reset these fields so the user can't alter the behaviour like native */
1008 tbcd
.nmcd
.hdc
= hdc
;
1009 tbcd
.nmcd
.rc
= btnPtr
->rect
;
1011 dwItemCustDraw
= ntfret
& 0xffff;
1012 dwItemCDFlag
= ntfret
& 0xffff0000;
1013 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
1015 /* save the only part of the rect that the user can change */
1016 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
1017 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
1020 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
1021 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
1022 OffsetRect(&rcText
, 1, 1);
1024 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
1025 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
1026 TOOLBAR_DrawPattern (&rc
, &tbcd
);
1028 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
1029 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
1031 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
1035 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
1036 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
1037 if (hasDropDownArrow
)
1038 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
1039 SetBkColor(hdc
, oldclr
);
1045 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
1046 int stateId
= TS_NORMAL
;
1048 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1049 stateId
= TS_DISABLED
;
1050 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1051 stateId
= TS_PRESSED
;
1052 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1053 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1054 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1055 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1058 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &rc
, NULL
);
1061 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, &rc
, dwItemCDFlag
);
1063 if (drawSepDropDownArrow
)
1067 int stateId
= TS_NORMAL
;
1069 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1070 stateId
= TS_DISABLED
;
1071 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1072 stateId
= TS_PRESSED
;
1073 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1074 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1075 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1078 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1079 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1082 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1085 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1086 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1087 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1088 SetBkMode (hdc
, oldBkMode
);
1090 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1092 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1094 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1096 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1097 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1099 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1101 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1102 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1105 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1108 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1110 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1111 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1118 TOOLBAR_Refresh (TOOLBAR_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
1120 TBUTTON_INFO
*btnPtr
;
1122 RECT rcTemp
, rcClient
;
1123 NMTBCUSTOMDRAW tbcd
;
1125 DWORD dwBaseCustDraw
;
1127 /* the app has told us not to redraw the toolbar */
1128 if (!infoPtr
->bDoRedraw
)
1131 /* if imagelist belongs to the app, it can be changed
1132 by the app after setting it */
1133 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1135 infoPtr
->nNumBitmaps
= 0;
1136 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1137 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1140 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1142 /* change the imagelist icon size if we manage the list and it is necessary */
1143 TOOLBAR_CheckImageListIconSize(infoPtr
);
1145 /* Send initial notify */
1146 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1147 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1148 tbcd
.nmcd
.hdc
= hdc
;
1149 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1150 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1151 dwBaseCustDraw
= ntfret
& 0xffff;
1153 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1155 /* redraw necessary buttons */
1156 btnPtr
= infoPtr
->buttons
;
1157 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1160 if (!RectVisible(hdc
, &btnPtr
->rect
))
1162 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1164 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1165 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1169 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1170 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1172 TOOLBAR_DrawButton(infoPtr
, btnPtr
, hdc
, dwBaseCustDraw
);
1175 /* draw insert mark if required */
1176 if (infoPtr
->tbim
.iButton
!= -1)
1178 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1180 rcInsertMark
.top
= rcButton
.top
;
1181 rcInsertMark
.bottom
= rcButton
.bottom
;
1182 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1183 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1185 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1186 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1189 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1191 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1192 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1193 tbcd
.nmcd
.hdc
= hdc
;
1194 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1195 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1199 /***********************************************************************
1200 * TOOLBAR_MeasureString
1202 * This function gets the width and height of a string in pixels. This
1203 * is done first by using GetTextExtentPoint to get the basic width
1204 * and height. The DrawText is called with DT_CALCRECT to get the exact
1205 * width. The reason is because the text may have more than one "&" (or
1206 * prefix characters as M$ likes to call them). The prefix character
1207 * indicates where the underline goes, except for the string "&&" which
1208 * is reduced to a single "&". GetTextExtentPoint does not process these
1209 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1212 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1213 HDC hdc
, LPSIZE lpSize
)
1220 if (infoPtr
->nMaxTextRows
> 0 &&
1221 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1222 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1223 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1225 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1227 if(lpText
!= NULL
) {
1228 /* first get size of all the text */
1229 GetTextExtentPoint32W (hdc
, lpText
, lstrlenW (lpText
), lpSize
);
1231 /* feed above size into the rectangle for DrawText */
1232 SetRect(&myrect
, 0, 0, lpSize
->cx
, lpSize
->cy
);
1234 /* Use DrawText to get true size as drawn (less pesky "&") */
1235 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1236 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1239 /* feed back to caller */
1240 lpSize
->cx
= myrect
.right
;
1241 lpSize
->cy
= myrect
.bottom
;
1245 TRACE("string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1248 /***********************************************************************
1249 * TOOLBAR_CalcStrings
1251 * This function walks through each string and measures it and returns
1252 * the largest height and width to caller.
1255 TOOLBAR_CalcStrings (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
1257 TBUTTON_INFO
*btnPtr
;
1266 if (infoPtr
->nMaxTextRows
== 0)
1269 hdc
= GetDC (infoPtr
->hwndSelf
);
1270 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1272 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1276 GetTextMetricsW(hdc
, &tm
);
1277 lpSize
->cy
= tm
.tmHeight
;
1280 btnPtr
= infoPtr
->buttons
;
1281 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1282 if(TOOLBAR_GetText(infoPtr
, btnPtr
))
1284 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1285 if (sz
.cx
> lpSize
->cx
)
1287 if (sz
.cy
> lpSize
->cy
)
1292 SelectObject (hdc
, hOldFont
);
1293 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1295 TRACE("max string size %d x %d\n", lpSize
->cx
, lpSize
->cy
);
1298 /***********************************************************************
1299 * TOOLBAR_WrapToolbar
1301 * This function walks through the buttons and separators in the
1302 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1303 * wrapping should occur based on the width of the toolbar window.
1304 * It does *not* calculate button placement itself. That task
1305 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1306 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1307 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1309 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_VERTICAL can be used also to allow
1310 * vertical toolbar lists.
1314 TOOLBAR_WrapToolbar(TOOLBAR_INFO
*infoPtr
)
1316 TBUTTON_INFO
*btnPtr
;
1317 INT x
, cx
, i
, j
, width
;
1320 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1321 /* no layout is necessary. Applications may use this style */
1322 /* to perform their own layout on the toolbar. */
1323 if( !(infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) &&
1324 !(infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
) ) return;
1326 btnPtr
= infoPtr
->buttons
;
1327 x
= infoPtr
->nIndent
;
1328 width
= infoPtr
->client_rect
.right
- infoPtr
->client_rect
.left
;
1330 bButtonWrap
= FALSE
;
1332 TRACE("start ButtonWidth=%d, BitmapWidth=%d, width=%d, nIndent=%d\n",
1333 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, width
,
1336 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1338 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1340 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1343 if (btnPtr
[i
].cx
> 0)
1345 /* horizontal separators are treated as buttons for width */
1346 else if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1347 !(infoPtr
->dwStyle
& CCS_VERT
))
1348 cx
= (btnPtr
[i
].iBitmap
> 0) ? btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1350 cx
= infoPtr
->nButtonWidth
;
1352 if (!btnPtr
[i
].cx
&& button_has_ddarrow( infoPtr
, btnPtr
+ i
))
1353 cx
+= DDARROW_WIDTH
;
1355 /* Two or more adjacent separators form a separator group. */
1356 /* The first separator in a group should be wrapped to the */
1357 /* next row if the previous wrapping is on a button. */
1359 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1360 (i
+ 1 < infoPtr
->nNumButtons
) &&
1361 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1363 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1364 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1365 x
= infoPtr
->nIndent
;
1367 bButtonWrap
= FALSE
;
1371 /* The layout makes sure the bitmap is visible, but not the button. */
1372 /* Test added to also wrap after a button that starts a row but */
1373 /* is bigger than the area. - GA 8/01 */
1374 if ((x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2 > width
) ||
1375 ((x
== infoPtr
->nIndent
) && (cx
> width
)))
1377 BOOL bFound
= FALSE
;
1379 /* If the current button is a separator and not hidden, */
1380 /* go to the next until it reaches a non separator. */
1381 /* Wrap the last separator if it is before a button. */
1382 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1383 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1384 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1385 i
< infoPtr
->nNumButtons
)
1391 if( bFound
&& i
< infoPtr
->nNumButtons
)
1394 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1395 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1396 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1397 x
= infoPtr
->nIndent
;
1398 bButtonWrap
= FALSE
;
1401 else if ( i
>= infoPtr
->nNumButtons
)
1404 /* If the current button is not a separator, find the last */
1405 /* separator and wrap it. */
1406 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1408 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1409 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1413 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1414 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1415 x
= infoPtr
->nIndent
;
1416 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1417 bButtonWrap
= FALSE
;
1422 /* If no separator available for wrapping, wrap one of */
1423 /* non-hidden previous button. */
1427 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1429 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1434 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1435 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1436 x
= infoPtr
->nIndent
;
1437 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1443 /* If all above failed, wrap the current button. */
1446 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1447 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1448 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1449 x
= infoPtr
->nIndent
;
1450 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1451 bButtonWrap
= FALSE
;
1457 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1458 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1465 /***********************************************************************
1466 * TOOLBAR_MeasureButton
1468 * Calculates the width and height required for a button. Used in
1469 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1470 * the width of buttons that are autosized.
1472 * Note that it would have been rather elegant to use one piece of code for
1473 * both the laying out of the toolbar and for controlling where button parts
1474 * are drawn, but the native control has inconsistencies between the two that
1475 * prevent this from being effectively. These inconsistencies can be seen as
1476 * artefacts where parts of the button appear outside of the bounding button
1479 * There are several cases for the calculation of the button dimensions and
1480 * button part positioning:
1487 * +--------------------------------------------------------+ ^
1489 * | | pad.cy / 2 | centered | |
1490 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1491 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1492 * | |<------------>| | | | |
1493 * | +--------------+ +------------+ | |
1494 * |<-------------------------------------->| | |
1495 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1497 * +--------------------------------------------------------+ -
1498 * <-------------------------------------------------------->
1499 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1501 * Without Bitmap (I_IMAGENONE):
1503 * +-----------------------------------+ ^
1505 * | | centered | | LISTPAD_CY +
1506 * | +------------+ | | szText.cy
1509 * | +------------+ | |
1510 * |<----------------->| | |
1511 * | cxedge |<-----------> | |
1513 * +-----------------------------------+ -
1514 * <----------------------------------->
1515 * szText.cx + pad.cx
1519 * +--------------------------------------+ ^
1521 * | | padding.cy/2 | | DEFPAD_CY +
1522 * | +------------+ | | nBitmapHeight
1525 * | +------------+ | |
1526 * |<------------------->| | |
1527 * | cxedge + iListGap/2 |<-----------> | |
1528 * | nBitmapWidth | |
1529 * +--------------------------------------+ -
1530 * <-------------------------------------->
1531 * 2*cxedge + nBitmapWidth + iListGap
1538 * +-----------------------------------+ ^
1540 * | | pad.cy / 2 | | nBitmapHeight +
1541 * | - | | szText.cy +
1542 * | +------------+ | | DEFPAD_CY + 1
1543 * | centered | Bitmap | | |
1544 * |<----------------->| | | |
1545 * | +------------+ | |
1549 * | centered +---------------+ | |
1550 * |<--------------->| Text | | |
1551 * | +---------------+ | |
1552 * +-----------------------------------+ -
1553 * <----------------------------------->
1554 * pad.cx + max(nBitmapWidth, szText.cx)
1556 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1558 * +---------------------------------------+ ^
1560 * | | 2 + pad.cy / 2 | |
1561 * | - | | szText.cy +
1562 * | centered +-----------------+ | | pad.cy + 2
1563 * |<--------------->| Text | | |
1564 * | +-----------------+ | |
1566 * +---------------------------------------+ -
1567 * <--------------------------------------->
1568 * 2*cxedge + pad.cx + szText.cx
1571 * As for with bitmaps, but with szText.cx zero.
1573 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1574 BOOL bHasBitmap
, BOOL bValidImageList
)
1577 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1579 /* set button height from bitmap / text height... */
1580 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1583 /* ... add on the necessary padding */
1584 if (bValidImageList
)
1587 sizeButton
.cy
+= DEFPAD_CY
;
1589 sizeButton
.cy
+= LISTPAD_CY
;
1592 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1594 /* calculate button width */
1595 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1596 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1597 if (sizeString
.cx
> 0)
1598 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1605 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1606 if (sizeString
.cy
> 0)
1607 sizeButton
.cy
+= 1 + sizeString
.cy
;
1608 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1609 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1613 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1614 NONLIST_NOTEXT_OFFSET
;
1615 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1616 max(2*GetSystemMetrics(SM_CXEDGE
) + sizeString
.cx
, infoPtr
->nBitmapWidth
);
1623 /***********************************************************************
1624 * TOOLBAR_CalcToolbar
1626 * This function calculates button and separator placement. It first
1627 * calculates the button sizes, gets the toolbar window width and then
1628 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1629 * on. It assigns a new location to each item and sends this location to
1630 * the tooltip window if appropriate. Finally, it updates the rcBound
1631 * rect and calculates the new required toolbar window height.
1634 TOOLBAR_CalcToolbar (TOOLBAR_INFO
*infoPtr
)
1636 SIZE sizeString
, sizeButton
;
1637 BOOL validImageList
= FALSE
;
1639 TOOLBAR_CalcStrings (infoPtr
, &sizeString
);
1641 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1643 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1644 validImageList
= TRUE
;
1645 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1646 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1647 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1648 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1650 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1651 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1652 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1653 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1655 TOOLBAR_LayoutToolbar(infoPtr
);
1659 TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
)
1661 TBUTTON_INFO
*btnPtr
;
1663 INT i
, nRows
, nSepRows
;
1666 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1668 TOOLBAR_WrapToolbar(infoPtr
);
1670 x
= infoPtr
->nIndent
;
1671 y
= infoPtr
->iTopMargin
;
1672 cx
= infoPtr
->nButtonWidth
;
1673 cy
= infoPtr
->nButtonHeight
;
1675 nRows
= nSepRows
= 0;
1677 infoPtr
->rcBound
.top
= y
;
1678 infoPtr
->rcBound
.left
= x
;
1679 infoPtr
->rcBound
.bottom
= y
+ cy
;
1680 infoPtr
->rcBound
.right
= x
;
1682 btnPtr
= infoPtr
->buttons
;
1684 TRACE("cy=%d\n", cy
);
1686 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1689 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1691 SetRectEmpty (&btnPtr
->rect
);
1692 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1696 cy
= infoPtr
->nButtonHeight
;
1698 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1699 if (infoPtr
->dwStyle
& CCS_VERT
) {
1700 cy
= (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1701 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
: infoPtr
->nButtonWidth
;
1704 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
:
1705 (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1711 else if (btnPtr
->fsStyle
& BTNS_AUTOSIZE
)
1717 hdc
= GetDC (infoPtr
->hwndSelf
);
1718 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1720 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1722 SelectObject (hdc
, hOldFont
);
1723 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1725 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1726 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1731 cx
= infoPtr
->nButtonWidth
;
1733 /* if size has been set manually then don't add on extra space
1734 * for the drop down arrow */
1735 if (!btnPtr
->cx
&& button_has_ddarrow( infoPtr
, btnPtr
))
1736 cx
+= DDARROW_WIDTH
;
1738 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1741 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1743 if (infoPtr
->rcBound
.left
> x
)
1744 infoPtr
->rcBound
.left
= x
;
1745 if (infoPtr
->rcBound
.right
< x
+ cx
)
1746 infoPtr
->rcBound
.right
= x
+ cx
;
1747 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1748 infoPtr
->rcBound
.bottom
= y
+ cy
;
1750 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1752 /* btnPtr->nRow is zero based. The space between the rows is */
1753 /* also considered as a row. */
1754 btnPtr
->nRow
= nRows
+ nSepRows
;
1756 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1757 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1762 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1766 if ( !(infoPtr
->dwStyle
& CCS_VERT
))
1767 y
+= cy
+ ( (btnPtr
->cx
> 0 ) ?
1768 btnPtr
->cx
: SEPARATOR_WIDTH
) * 2 /3;
1772 /* nSepRows is used to calculate the extra height following */
1776 x
= infoPtr
->nIndent
;
1778 /* Increment row number unless this is the last button */
1779 /* and it has Wrap set. */
1780 if (i
!= infoPtr
->nNumButtons
-1)
1787 /* infoPtr->nRows is the number of rows on the toolbar */
1788 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1790 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1795 TOOLBAR_InternalHitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
*lpPt
, BOOL
*button
)
1797 TBUTTON_INFO
*btnPtr
;
1803 btnPtr
= infoPtr
->buttons
;
1804 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1805 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1808 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1809 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1810 TRACE(" ON SEPARATOR %d\n", i
);
1815 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1816 TRACE(" ON BUTTON %d\n", i
);
1824 TRACE(" NOWHERE\n");
1825 return TOOLBAR_NOWHERE
;
1829 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1831 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO
*infoPtr
, INT iIndex
, UINT nAddButtons
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
1833 INT nOldButtons
, nNewButtons
, iButton
;
1834 BOOL fHasString
= FALSE
;
1836 if (iIndex
< 0) /* iIndex can be negative, what means adding at the end */
1837 iIndex
= infoPtr
->nNumButtons
;
1839 nOldButtons
= infoPtr
->nNumButtons
;
1840 nNewButtons
= nOldButtons
+ nAddButtons
;
1842 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
1843 memmove(&infoPtr
->buttons
[iIndex
+ nAddButtons
], &infoPtr
->buttons
[iIndex
],
1844 (nOldButtons
- iIndex
) * sizeof(TBUTTON_INFO
));
1845 infoPtr
->nNumButtons
+= nAddButtons
;
1847 /* insert new buttons data */
1848 for (iButton
= 0; iButton
< nAddButtons
; iButton
++) {
1849 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[iIndex
+ iButton
];
1852 TOOLBAR_DumpTBButton(lpTbb
+ iButton
, fUnicode
);
1854 ZeroMemory(btnPtr
, sizeof(*btnPtr
));
1856 btnPtr
->iBitmap
= lpTbb
[iButton
].iBitmap
;
1857 btnPtr
->idCommand
= lpTbb
[iButton
].idCommand
;
1858 btnPtr
->fsState
= lpTbb
[iButton
].fsState
;
1859 btnPtr
->fsStyle
= lpTbb
[iButton
].fsStyle
;
1860 btnPtr
->dwData
= lpTbb
[iButton
].dwData
;
1862 if (btnPtr
->fsStyle
& BTNS_SEP
)
1865 str
= lpTbb
[iButton
].iString
;
1866 set_string_index( btnPtr
, str
, fUnicode
);
1867 fHasString
|= TOOLBAR_ButtonHasString( btnPtr
);
1869 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
1872 if (infoPtr
->nNumStrings
> 0 || fHasString
)
1873 TOOLBAR_CalcToolbar(infoPtr
);
1875 TOOLBAR_LayoutToolbar(infoPtr
);
1876 TOOLBAR_AutoSize(infoPtr
);
1878 TOOLBAR_DumpToolbar(infoPtr
, __LINE__
);
1879 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1885 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1887 TBUTTON_INFO
*btnPtr
;
1890 if (CommandIsIndex
) {
1891 TRACE("command is really index command=%d\n", idCommand
);
1892 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1895 btnPtr
= infoPtr
->buttons
;
1896 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1897 if (btnPtr
->idCommand
== idCommand
) {
1898 TRACE("command=%d index=%d\n", idCommand
, i
);
1902 TRACE("no index found for command=%d\n", idCommand
);
1908 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1910 TBUTTON_INFO
*btnPtr
;
1913 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1916 /* check index button */
1917 btnPtr
= &infoPtr
->buttons
[nIndex
];
1918 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1919 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1923 /* check previous buttons */
1924 nRunIndex
= nIndex
- 1;
1925 while (nRunIndex
>= 0) {
1926 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1927 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1928 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1936 /* check next buttons */
1937 nRunIndex
= nIndex
+ 1;
1938 while (nRunIndex
< infoPtr
->nNumButtons
) {
1939 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1940 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1941 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1954 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1955 WPARAM wParam
, LPARAM lParam
)
1961 msg
.wParam
= wParam
;
1962 msg
.lParam
= lParam
;
1963 msg
.time
= GetMessageTime ();
1964 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
1965 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
1967 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1971 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1973 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
1976 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
1977 ti
.cbSize
= sizeof (TTTOOLINFOW
);
1978 ti
.hwnd
= infoPtr
->hwndSelf
;
1979 ti
.uId
= button
->idCommand
;
1981 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
1982 /* ti.lParam = random value from the stack? */
1984 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
1990 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1992 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
1995 ZeroMemory(&ti
, sizeof(ti
));
1996 ti
.cbSize
= sizeof(ti
);
1997 ti
.hwnd
= infoPtr
->hwndSelf
;
1998 ti
.uId
= button
->idCommand
;
2000 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
2004 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2006 /* Set the toolTip only for non-hidden, non-separator button */
2007 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
2011 ZeroMemory(&ti
, sizeof(ti
));
2012 ti
.cbSize
= sizeof(ti
);
2013 ti
.hwnd
= infoPtr
->hwndSelf
;
2014 ti
.uId
= button
->idCommand
;
2015 ti
.rect
= button
->rect
;
2016 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
2020 /* Creates the tooltip control */
2022 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
2025 NMTOOLTIPSCREATED nmttc
;
2027 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
2028 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2029 infoPtr
->hwndSelf
, 0, 0, 0);
2031 if (!infoPtr
->hwndToolTip
)
2034 /* Send NM_TOOLTIPSCREATED notification */
2035 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
2036 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
2038 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
2040 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
2041 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
2045 /* keeps available button list box sorted by button id */
2046 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
2050 PCUSTOMBUTTON btnInfo
;
2051 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2053 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
2055 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2057 /* position 0 is always separator */
2058 for (i
= 1; i
< count
; i
++)
2060 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2061 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2063 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2064 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2068 /* id higher than all others add to end */
2069 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2070 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2073 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2077 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2079 if (nIndexFrom
== nIndexTo
)
2082 /* MSDN states that iItem is the index of the button, rather than the
2083 * command ID as used by every other NMTOOLBAR notification */
2084 nmtb
.iItem
= nIndexFrom
;
2085 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2087 PCUSTOMBUTTON btnInfo
;
2089 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2090 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2092 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2094 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2095 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2096 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2097 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2100 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2102 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2104 /* last item is always separator, so -2 instead of -1 */
2105 if (nIndexTo
>= (count
- 2))
2106 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2108 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2110 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2111 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2113 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2117 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2121 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2123 /* MSDN states that iItem is the index of the button, rather than the
2124 * command ID as used by every other NMTOOLBAR notification */
2125 nmtb
.iItem
= nIndexAvail
;
2126 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2128 PCUSTOMBUTTON btnInfo
;
2130 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2131 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2132 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2134 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2136 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2138 /* remove from 'available buttons' list */
2139 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2140 if (nIndexAvail
== count
-1)
2141 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2143 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2147 PCUSTOMBUTTON btnNew
;
2149 /* duplicate 'separator' button */
2150 btnNew
= Alloc(sizeof(CUSTOMBUTTON
));
2155 /* insert into 'toolbar button' list */
2156 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2157 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2159 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2161 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2165 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2167 PCUSTOMBUTTON btnInfo
;
2168 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2170 TRACE("Remove: index %d\n", index
);
2172 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2174 /* send TBN_QUERYDELETE notification */
2175 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2179 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2180 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2182 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2184 /* insert into 'available button' list */
2185 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2186 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2190 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2194 /* drag list notification function for toolbar buttons list box */
2195 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2196 const DRAGLISTINFO
*pDLI
)
2198 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2199 switch (pDLI
->uNotification
)
2203 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2204 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2205 /* no dragging for last item (separator) */
2206 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2211 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2212 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2213 /* no dragging past last item (separator) */
2214 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2216 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2217 /* FIXME: native uses "move button" cursor */
2218 return DL_COPYCURSOR
;
2221 /* not over toolbar buttons list */
2222 if (nCurrentItem
< 0)
2224 POINT ptWindow
= pDLI
->ptCursor
;
2225 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2226 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2227 /* over available buttons list? */
2228 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2229 /* FIXME: native uses "move button" cursor */
2230 return DL_COPYCURSOR
;
2232 /* clear drag arrow */
2233 DrawInsert(hwnd
, hwndList
, -1);
2234 return DL_STOPCURSOR
;
2238 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2239 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2240 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2241 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2243 /* clear drag arrow */
2244 DrawInsert(hwnd
, hwndList
, -1);
2246 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2248 /* not over toolbar buttons list */
2251 POINT ptWindow
= pDLI
->ptCursor
;
2252 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2253 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2254 /* over available buttons list? */
2255 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2256 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2261 /* Clear drag arrow */
2262 DrawInsert(hwnd
, hwndList
, -1);
2269 /* drag list notification function for available buttons list box */
2270 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2271 const DRAGLISTINFO
*pDLI
)
2273 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2274 switch (pDLI
->uNotification
)
2280 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2281 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2282 /* no dragging past last item (separator) */
2283 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2285 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2286 /* FIXME: native uses "move button" cursor */
2287 return DL_COPYCURSOR
;
2290 /* not over toolbar buttons list */
2291 if (nCurrentItem
< 0)
2293 POINT ptWindow
= pDLI
->ptCursor
;
2294 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2295 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2296 /* over available buttons list? */
2297 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2298 /* FIXME: native uses "move button" cursor */
2299 return DL_COPYCURSOR
;
2301 /* clear drag arrow */
2302 DrawInsert(hwnd
, hwndList
, -1);
2303 return DL_STOPCURSOR
;
2307 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2308 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2309 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2310 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2312 /* clear drag arrow */
2313 DrawInsert(hwnd
, hwndList
, -1);
2315 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2319 /* Clear drag arrow */
2320 DrawInsert(hwnd
, hwndList
, -1);
2326 extern UINT uDragListMessage DECLSPEC_HIDDEN
;
2328 /***********************************************************************
2329 * TOOLBAR_CustomizeDialogProc
2330 * This function implements the toolbar customization dialog.
2332 static INT_PTR CALLBACK
2333 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2335 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2336 PCUSTOMBUTTON btnInfo
;
2338 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2343 custInfo
= (PCUSTDLG_INFO
)lParam
;
2344 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2351 NMTBINITCUSTOMIZE nmtbic
;
2353 infoPtr
= custInfo
->tbInfo
;
2355 /* send TBN_QUERYINSERT notification */
2356 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2358 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2361 nmtbic
.hwndDialog
= hwnd
;
2362 /* Send TBN_INITCUSTOMIZE notification */
2363 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2366 TRACE("TBNRF_HIDEHELP requested\n");
2367 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2370 /* add items to 'toolbar buttons' list and check if removable */
2371 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2373 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2374 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2375 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2376 btnInfo
->bVirtual
= FALSE
;
2377 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2379 /* send TBN_QUERYDELETE notification */
2380 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2382 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2383 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2386 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2388 /* insert separator button into 'available buttons' list */
2389 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2390 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2391 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2392 btnInfo
->bVirtual
= FALSE
;
2393 btnInfo
->bRemovable
= TRUE
;
2394 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2395 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2396 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2398 /* insert all buttons into dsa */
2401 /* send TBN_GETBUTTONINFO notification */
2404 nmtb
.pszText
= Buffer
;
2407 /* Clear previous button's text */
2408 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2410 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2413 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2414 nmtb
.tbButton
.fsStyle
, i
,
2415 nmtb
.tbButton
.idCommand
,
2416 nmtb
.tbButton
.iString
,
2417 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2420 /* insert button into the appropriate list */
2421 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2424 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2425 btnInfo
->bVirtual
= FALSE
;
2426 btnInfo
->bRemovable
= TRUE
;
2430 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2431 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2434 btnInfo
->btn
= nmtb
.tbButton
;
2435 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2438 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2439 else if (nmtb
.tbButton
.iString
>= 0 &&
2440 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2442 lstrcpyW(btnInfo
->text
,
2443 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2448 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2451 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2453 /* select first item in the 'available' list */
2454 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2456 /* append 'virtual' separator button to the 'toolbar buttons' list */
2457 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2458 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2459 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2460 btnInfo
->bVirtual
= TRUE
;
2461 btnInfo
->bRemovable
= FALSE
;
2462 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2463 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2464 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2466 /* select last item in the 'toolbar' list */
2467 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2468 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2470 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2471 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2473 /* set focus and disable buttons */
2474 PostMessageW (hwnd
, WM_USER
, 0, 0);
2479 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2480 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2481 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2482 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2486 EndDialog(hwnd
, FALSE
);
2490 switch (LOWORD(wParam
))
2492 case IDC_TOOLBARBTN_LBOX
:
2493 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2495 PCUSTOMBUTTON btnInfo
;
2500 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2501 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2503 /* send TBN_QUERYINSERT notification */
2505 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2507 /* get list box item */
2508 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2510 if (index
== (count
- 1))
2512 /* last item (virtual separator) */
2513 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2514 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2516 else if (index
== (count
- 2))
2518 /* second last item (last non-virtual item) */
2519 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2520 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2522 else if (index
== 0)
2525 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2526 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2530 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2531 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2534 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2538 case IDC_MOVEUP_BTN
:
2540 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2541 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2545 case IDC_MOVEDN_BTN
: /* move down */
2547 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2548 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2552 case IDC_REMOVE_BTN
: /* remove button */
2554 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2556 if (LB_ERR
== index
)
2559 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2563 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2566 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2569 case IDOK
: /* Add button */
2574 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2575 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2577 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2582 EndDialog(hwnd
, FALSE
);
2592 /* delete items from 'toolbar buttons' listbox*/
2593 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2594 for (i
= 0; i
< count
; i
++)
2596 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2598 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2600 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2603 /* delete items from 'available buttons' listbox*/
2604 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2605 for (i
= 0; i
< count
; i
++)
2607 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2609 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2611 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2616 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2618 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2623 COLORREF oldText
= 0;
2627 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, lpdis
->itemID
, 0);
2628 if (btnInfo
== NULL
)
2630 FIXME("btnInfo invalid\n");
2634 /* set colors and select objects */
2635 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2636 if (btnInfo
->bVirtual
)
2637 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2639 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2640 hPen
= CreatePen( PS_SOLID
, 1,
2641 (lpdis
->itemState
& ODS_SELECTED
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2642 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2643 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2645 /* fill background rectangle */
2646 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2647 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2649 /* calculate button and text rectangles */
2650 rcButton
= lpdis
->rcItem
;
2651 InflateRect (&rcButton
, -1, -1);
2653 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2654 rcText
.left
= rcButton
.right
+ 2;
2656 /* draw focus rectangle */
2657 if (lpdis
->itemState
& ODS_FOCUS
)
2658 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2661 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2662 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2664 /* draw image and text */
2665 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2666 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2667 btnInfo
->btn
.iBitmap
));
2668 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2669 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2671 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2672 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2674 /* delete objects and reset colors */
2675 SelectObject (lpdis
->hDC
, hOldBrush
);
2676 SelectObject (lpdis
->hDC
, hOldPen
);
2677 SetBkColor (lpdis
->hDC
, oldBk
);
2678 SetTextColor (lpdis
->hDC
, oldText
);
2679 DeleteObject( hPen
);
2684 case WM_MEASUREITEM
:
2685 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2687 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2689 lpmis
->itemHeight
= 15 + 8; /* default height */
2696 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2698 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2700 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2701 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2702 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2705 else if (wParam
== IDC_AVAILBTN_LBOX
)
2707 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2708 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2709 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2718 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2721 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2727 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2728 /* Add bitmaps to the default image list */
2729 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2730 hbmLoad
= CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2731 else if (bitmap
->hInst
== COMCTL32_hModule
)
2732 hbmLoad
= LoadImageW( bitmap
->hInst
, MAKEINTRESOURCEW(bitmap
->nID
),
2733 IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
2735 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2737 /* enlarge the bitmap if needed */
2738 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2739 if (bitmap
->hInst
!= COMCTL32_hModule
)
2740 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2742 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2743 DeleteObject(hbmLoad
);
2747 nCountAfter
= ImageList_GetImageCount(himlDef
);
2748 nAdded
= nCountAfter
- nCountBefore
;
2749 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2751 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2752 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2753 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2754 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2757 infoPtr
->nNumBitmaps
+= nAdded
;
2762 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2769 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2770 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2772 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2774 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2777 TRACE("Update icon size: %dx%d -> %dx%d\n",
2778 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2780 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2781 ILC_COLOR32
|ILC_MASK
, 8, 2);
2782 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2783 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2784 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2785 infoPtr
->himlInt
= himlNew
;
2787 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2788 ImageList_Destroy(himlDef
);
2791 /***********************************************************************
2792 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2796 TOOLBAR_AddBitmap (TOOLBAR_INFO
*infoPtr
, INT count
, const TBADDBITMAP
*lpAddBmp
)
2802 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr
->hwndSelf
, count
, lpAddBmp
);
2806 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2808 info
.hInst
= COMCTL32_hModule
;
2809 switch (lpAddBmp
->nID
)
2811 case IDB_STD_SMALL_COLOR
:
2814 info
.nID
= IDB_STD_SMALL
;
2816 case IDB_STD_LARGE_COLOR
:
2819 info
.nID
= IDB_STD_LARGE
;
2821 case IDB_VIEW_SMALL_COLOR
:
2824 info
.nID
= IDB_VIEW_SMALL
;
2826 case IDB_VIEW_LARGE_COLOR
:
2829 info
.nID
= IDB_VIEW_LARGE
;
2831 case IDB_HIST_SMALL_COLOR
:
2833 info
.nID
= IDB_HIST_SMALL
;
2835 case IDB_HIST_LARGE_COLOR
:
2837 info
.nID
= IDB_HIST_LARGE
;
2840 WARN("unknown bitmap id, %ld\n", lpAddBmp
->nID
);
2844 TRACE ("adding %d internal bitmaps\n", info
.nButtons
);
2846 /* Windows resize all the buttons to the size of a newly added standard image */
2847 if (lpAddBmp
->nID
& 1)
2849 /* large icons: 24x24. Will make the button 31x30 */
2850 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2854 /* small icons: 16x16. Will make the buttons 23x22 */
2855 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2858 TOOLBAR_CalcToolbar (infoPtr
);
2862 info
.nButtons
= count
;
2863 info
.hInst
= lpAddBmp
->hInst
;
2864 info
.nID
= lpAddBmp
->nID
;
2865 TRACE("adding %d bitmaps\n", info
.nButtons
);
2868 /* check if the bitmap is already loaded and compute iSumButtons */
2870 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2872 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2873 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2875 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2878 if (!infoPtr
->cimlDef
) {
2879 /* create new default image list */
2880 TRACE ("creating default image list\n");
2882 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2883 ILC_COLOR32
| ILC_MASK
, info
.nButtons
, 2);
2884 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2885 infoPtr
->himlInt
= himlDef
;
2888 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2892 WARN("No default image list available\n");
2896 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2899 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2900 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2901 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2902 infoPtr
->nNumBitmapInfos
++;
2903 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2905 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2911 TOOLBAR_AddButtonsT(TOOLBAR_INFO
*infoPtr
, INT nAddButtons
, const TBBUTTON
* lpTbb
, BOOL fUnicode
)
2913 TRACE("adding %d buttons (unicode=%d)\n", nAddButtons
, fUnicode
);
2915 return TOOLBAR_InternalInsertButtonsT(infoPtr
, -1, nAddButtons
, lpTbb
, fUnicode
);
2920 TOOLBAR_AddStringW (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
2922 #define MAX_RESOURCE_STRING_LENGTH 512
2923 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2924 INT nIndex
= infoPtr
->nNumStrings
;
2926 TRACE("%p, %lx\n", hInstance
, lParam
);
2928 if (IS_INTRESOURCE(lParam
)) {
2929 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2936 TRACE("adding string from resource\n");
2938 if (!hInstance
) return -1;
2940 hrsrc
= FindResourceW( hInstance
, MAKEINTRESOURCEW((LOWORD(lParam
) >> 4) + 1),
2941 (LPWSTR
)RT_STRING
);
2944 TRACE("string not found in resources\n");
2948 len
= LoadStringW (hInstance
, (UINT
)lParam
,
2949 szString
, MAX_RESOURCE_STRING_LENGTH
);
2951 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2952 if (len
== 0 || len
== 1)
2955 TRACE("delimiter: 0x%x\n", *szString
);
2956 delimiter
= *szString
;
2959 while ((next_delim
= wcschr(p
, delimiter
)) != NULL
) {
2961 if (next_delim
+ 1 >= szString
+ len
)
2963 /* this may happen if delimiter == '\0' or if the last char is a
2964 * delimiter (then it is ignored like the native does) */
2968 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2969 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2970 infoPtr
->nNumStrings
++;
2976 LPWSTR p
= (LPWSTR
)lParam
;
2981 TRACE("adding string(s) from array\n");
2985 TRACE("len=%d %s\n", len
, debugstr_w(p
));
2986 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2987 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2988 infoPtr
->nNumStrings
++;
2995 TOOLBAR_CalcToolbar(infoPtr
);
3001 TOOLBAR_AddStringA (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
3003 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
3008 TRACE("%p, %lx\n", hInstance
, lParam
);
3010 if (IS_INTRESOURCE(lParam
)) /* load from resources */
3011 return TOOLBAR_AddStringW(infoPtr
, hInstance
, lParam
);
3017 TRACE("adding string(s) from array\n");
3018 nIndex
= infoPtr
->nNumStrings
;
3021 TRACE("len=%d \"%s\"\n", len
, p
);
3023 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3024 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3025 infoPtr
->nNumStrings
++;
3031 TOOLBAR_CalcToolbar(infoPtr
);
3037 TOOLBAR_AutoSize (TOOLBAR_INFO
*infoPtr
)
3039 TRACE("auto sizing, style=%#x\n", infoPtr
->dwStyle
);
3040 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3042 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3044 RECT window_rect
, parent_rect
;
3045 UINT uPosFlags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
3049 parent
= GetParent (infoPtr
->hwndSelf
);
3051 if (!parent
|| !infoPtr
->bDoRedraw
)
3054 GetClientRect(parent
, &parent_rect
);
3056 x
= parent_rect
.left
;
3057 y
= parent_rect
.top
;
3059 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3060 cx
= parent_rect
.right
- parent_rect
.left
;
3062 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3064 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3065 MapWindowPoints( 0, parent
, (POINT
*)&window_rect
, 2 );
3066 y
= window_rect
.top
;
3068 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3070 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3071 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3074 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3075 uPosFlags
|= SWP_NOMOVE
;
3077 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3078 cy
+= GetSystemMetrics(SM_CYEDGE
);
3080 if (infoPtr
->dwStyle
& WS_BORDER
)
3082 cx
+= 2 * GetSystemMetrics(SM_CXBORDER
);
3083 cy
+= 2 * GetSystemMetrics(SM_CYBORDER
);
3086 SetWindowPos(infoPtr
->hwndSelf
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3089 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
))
3091 TOOLBAR_LayoutToolbar(infoPtr
);
3092 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
3099 static inline LRESULT
3100 TOOLBAR_ButtonCount (const TOOLBAR_INFO
*infoPtr
)
3102 return infoPtr
->nNumButtons
;
3106 static inline LRESULT
3107 TOOLBAR_ButtonStructSize (TOOLBAR_INFO
*infoPtr
, DWORD Size
)
3109 infoPtr
->dwStructSize
= Size
;
3116 TOOLBAR_ChangeBitmap (TOOLBAR_INFO
*infoPtr
, INT Id
, INT Index
)
3118 TBUTTON_INFO
*btnPtr
;
3121 TRACE("button %d, iBitmap now %d\n", Id
, Index
);
3123 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3127 btnPtr
= &infoPtr
->buttons
[nIndex
];
3128 btnPtr
->iBitmap
= Index
;
3130 /* we HAVE to erase the background, the new bitmap could be */
3132 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3139 TOOLBAR_CheckButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3141 TBUTTON_INFO
*btnPtr
;
3144 BOOL bChecked
= FALSE
;
3146 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3148 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, nIndex
, lParam
);
3153 btnPtr
= &infoPtr
->buttons
[nIndex
];
3155 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) != 0;
3157 if (!LOWORD(lParam
))
3158 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3160 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3162 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3163 if (nOldIndex
== nIndex
)
3165 if (nOldIndex
!= -1)
3166 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3168 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3171 if( bChecked
!= LOWORD(lParam
) )
3173 if (nOldIndex
!= -1)
3174 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3175 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3178 /* FIXME: Send a WM_NOTIFY?? */
3185 TOOLBAR_CommandToIndex (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3187 return TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3192 TOOLBAR_Customize (TOOLBAR_INFO
*infoPtr
)
3194 CUSTDLG_INFO custInfo
;
3198 custInfo
.tbInfo
= infoPtr
;
3199 custInfo
.tbHwnd
= infoPtr
->hwndSelf
;
3201 /* send TBN_BEGINADJUST notification */
3202 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3204 ret
= DialogBoxParamW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3205 infoPtr
->hwndSelf
, TOOLBAR_CustomizeDialogProc
, (LPARAM
)&custInfo
);
3207 /* send TBN_ENDADJUST notification */
3208 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3215 TOOLBAR_DeleteButton (TOOLBAR_INFO
*infoPtr
, INT nIndex
)
3218 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3220 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3223 memset(&nmtb
, 0, sizeof(nmtb
));
3224 nmtb
.iItem
= btnPtr
->idCommand
;
3225 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3226 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3227 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3228 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3229 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3230 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3231 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3233 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3235 infoPtr
->nHotItem
= -1;
3236 if (infoPtr
->nNumButtons
== 1) {
3237 TRACE(" simple delete\n");
3238 free_string( infoPtr
->buttons
);
3239 Free (infoPtr
->buttons
);
3240 infoPtr
->buttons
= NULL
;
3241 infoPtr
->nNumButtons
= 0;
3244 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3245 TRACE("complex delete [nIndex=%d]\n", nIndex
);
3247 infoPtr
->nNumButtons
--;
3248 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3250 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3251 nIndex
* sizeof(TBUTTON_INFO
));
3254 if (nIndex
< infoPtr
->nNumButtons
) {
3255 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3256 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3259 free_string( oldButtons
+ nIndex
);
3263 TOOLBAR_LayoutToolbar(infoPtr
);
3265 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3272 TOOLBAR_EnableButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3274 TBUTTON_INFO
*btnPtr
;
3278 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3280 TRACE("hwnd=%p, btn id=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, Id
, lParam
);
3285 btnPtr
= &infoPtr
->buttons
[nIndex
];
3287 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3289 /* update the toolbar button state */
3290 if(!LOWORD(lParam
)) {
3291 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3293 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3296 /* redraw the button only if the state of the button changed */
3297 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3298 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3304 static inline LRESULT
3305 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO
*infoPtr
)
3307 return infoPtr
->bAnchor
;
3312 TOOLBAR_GetBitmap (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3316 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3320 return infoPtr
->buttons
[nIndex
].iBitmap
;
3324 static inline LRESULT
3325 TOOLBAR_GetBitmapFlags (void)
3327 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3332 TOOLBAR_GetButton (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, TBBUTTON
*lpTbb
)
3334 TBUTTON_INFO
*btnPtr
;
3339 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3342 btnPtr
= &infoPtr
->buttons
[nIndex
];
3343 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3344 lpTbb
->idCommand
= btnPtr
->idCommand
;
3345 lpTbb
->fsState
= btnPtr
->fsState
;
3346 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3347 lpTbb
->bReserved
[0] = 0;
3348 lpTbb
->bReserved
[1] = 0;
3349 lpTbb
->dwData
= btnPtr
->dwData
;
3350 lpTbb
->iString
= btnPtr
->iString
;
3357 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO
*infoPtr
, INT Id
, LPTBBUTTONINFOW lpTbInfo
, BOOL bUnicode
)
3359 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3360 TBUTTON_INFO
*btnPtr
;
3363 if (lpTbInfo
== NULL
)
3366 /* MSDN documents an iImageLabel field added in Vista but it is not present in
3367 * the headers and tests shows that even with comctl 6 Vista accepts only the
3368 * original TBBUTTONINFO size
3370 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3372 WARN("Invalid button size\n");
3376 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lpTbInfo
->dwMask
& TBIF_BYINDEX
);
3380 btnPtr
= &infoPtr
->buttons
[nIndex
];
3381 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3382 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3383 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3384 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3385 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3386 lpTbInfo
->lParam
= btnPtr
->dwData
;
3387 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3388 /* tests show that for separators TBIF_SIZE returns not calculated width,
3389 but cx property, that differs from 0 only if application have
3390 specifically set it */
3391 lpTbInfo
->cx
= (btnPtr
->fsStyle
& BTNS_SEP
)
3392 ? btnPtr
->cx
: (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3393 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3394 lpTbInfo
->fsState
= btnPtr
->fsState
;
3395 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3396 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3397 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3398 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3399 can't use TOOLBAR_GetText here */
3400 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3401 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3403 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3405 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3406 } else if (!bUnicode
|| lpTbInfo
->pszText
)
3407 lpTbInfo
->pszText
[0] = '\0';
3413 static inline LRESULT
3414 TOOLBAR_GetButtonSize (const TOOLBAR_INFO
*infoPtr
)
3416 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3417 (WORD
)infoPtr
->nButtonHeight
);
3422 TOOLBAR_GetButtonText (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPWSTR lpStr
, BOOL isW
)
3428 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3432 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3438 ret
= lstrlenW (lpText
);
3439 if (lpStr
) lstrcpyW (lpStr
, lpText
);
3443 ret
= WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3444 (LPSTR
)lpStr
, lpStr
? 0x7fffffff : 0, NULL
, NULL
) - 1;
3450 TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3452 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3453 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3454 return (LRESULT
)GETDISIMAGELIST(infoPtr
, wParam
);
3458 static inline LRESULT
3459 TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO
*infoPtr
)
3463 return infoPtr
->dwExStyle
;
3468 TOOLBAR_GetHotImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3470 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3471 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3472 return (LRESULT
)GETHOTIMAGELIST(infoPtr
, wParam
);
3477 TOOLBAR_GetHotItem (const TOOLBAR_INFO
*infoPtr
)
3479 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3482 if (infoPtr
->nHotItem
< 0)
3485 return (LRESULT
)infoPtr
->nHotItem
;
3490 TOOLBAR_GetDefImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3492 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3493 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3494 return (LRESULT
) GETDEFIMAGELIST(infoPtr
, wParam
);
3499 TOOLBAR_GetInsertMark (const TOOLBAR_INFO
*infoPtr
, TBINSERTMARK
*lptbim
)
3501 TRACE("hwnd = %p, lptbim = %p\n", infoPtr
->hwndSelf
, lptbim
);
3503 *lptbim
= infoPtr
->tbim
;
3509 static inline LRESULT
3510 TOOLBAR_GetInsertMarkColor (const TOOLBAR_INFO
*infoPtr
)
3512 TRACE("hwnd = %p\n", infoPtr
->hwndSelf
);
3514 return (LRESULT
)infoPtr
->clrInsertMark
;
3519 TOOLBAR_GetItemRect (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, LPRECT lpRect
)
3521 TBUTTON_INFO
*btnPtr
;
3523 btnPtr
= &infoPtr
->buttons
[nIndex
];
3524 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3529 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3532 lpRect
->left
= btnPtr
->rect
.left
;
3533 lpRect
->right
= btnPtr
->rect
.right
;
3534 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3535 lpRect
->top
= btnPtr
->rect
.top
;
3542 TOOLBAR_GetMaxSize (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
3547 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3548 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3550 TRACE("maximum size %d x %d\n",
3551 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3552 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3558 /* << TOOLBAR_GetObject >> */
3561 static inline LRESULT
3562 TOOLBAR_GetPadding (const TOOLBAR_INFO
*infoPtr
)
3564 return MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3569 TOOLBAR_GetRect (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPRECT lpRect
)
3571 TBUTTON_INFO
*btnPtr
;
3574 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3575 btnPtr
= &infoPtr
->buttons
[nIndex
];
3576 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3582 lpRect
->left
= btnPtr
->rect
.left
;
3583 lpRect
->right
= btnPtr
->rect
.right
;
3584 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3585 lpRect
->top
= btnPtr
->rect
.top
;
3591 static inline LRESULT
3592 TOOLBAR_GetRows (const TOOLBAR_INFO
*infoPtr
)
3594 return infoPtr
->nRows
;
3599 TOOLBAR_GetState (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3603 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3607 return infoPtr
->buttons
[nIndex
].fsState
;
3611 static inline LRESULT
3612 TOOLBAR_GetStyle (const TOOLBAR_INFO
*infoPtr
)
3614 return infoPtr
->dwStyle
;
3618 static inline LRESULT
3619 TOOLBAR_GetTextRows (const TOOLBAR_INFO
*infoPtr
)
3621 return infoPtr
->nMaxTextRows
;
3626 TOOLBAR_GetToolTips (TOOLBAR_INFO
*infoPtr
)
3628 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3629 TOOLBAR_TooltipCreateControl(infoPtr
);
3630 return (LRESULT
)infoPtr
->hwndToolTip
;
3635 TOOLBAR_GetUnicodeFormat (const TOOLBAR_INFO
*infoPtr
)
3637 TRACE("%s hwnd=%p\n",
3638 infoPtr
->bUnicode
? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
3640 return infoPtr
->bUnicode
;
3644 static inline LRESULT
3645 TOOLBAR_GetVersion (const TOOLBAR_INFO
*infoPtr
)
3647 return infoPtr
->iVersion
;
3652 TOOLBAR_HideButton (TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fHide
)
3654 TBUTTON_INFO
*btnPtr
;
3660 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3664 btnPtr
= &infoPtr
->buttons
[nIndex
];
3665 oldState
= btnPtr
->fsState
;
3668 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3670 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3672 if (oldState
!= btnPtr
->fsState
) {
3673 TOOLBAR_LayoutToolbar (infoPtr
);
3674 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3681 static inline LRESULT
3682 TOOLBAR_HitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
* lpPt
)
3684 return TOOLBAR_InternalHitTest (infoPtr
, lpPt
, NULL
);
3689 TOOLBAR_Indeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fIndeterminate
)
3691 TBUTTON_INFO
*btnPtr
;
3695 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3699 btnPtr
= &infoPtr
->buttons
[nIndex
];
3700 oldState
= btnPtr
->fsState
;
3703 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3705 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3707 if(oldState
!= btnPtr
->fsState
)
3708 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3715 TOOLBAR_InsertButtonT(TOOLBAR_INFO
*infoPtr
, INT nIndex
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
3721 /* EPP: this seems to be an undocumented call (from my IE4)
3722 * I assume in that case that:
3723 * - index of insertion is at the end of existing buttons
3724 * I only see this happen with nIndex == -1, but it could have a special
3725 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3727 nIndex
= infoPtr
->nNumButtons
;
3729 } else if (nIndex
< 0)
3732 TRACE("inserting button index=%d\n", nIndex
);
3733 if (nIndex
> infoPtr
->nNumButtons
) {
3734 nIndex
= infoPtr
->nNumButtons
;
3735 TRACE("adjust index=%d\n", nIndex
);
3738 return TOOLBAR_InternalInsertButtonsT(infoPtr
, nIndex
, 1, lpTbb
, fUnicode
);
3741 /* << TOOLBAR_InsertMarkHitTest >> */
3745 TOOLBAR_IsButtonChecked (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3749 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3753 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3758 TOOLBAR_IsButtonEnabled (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3762 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3766 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3771 TOOLBAR_IsButtonHidden (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3775 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3779 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3784 TOOLBAR_IsButtonHighlighted (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3788 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3792 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3797 TOOLBAR_IsButtonIndeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3801 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3805 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3810 TOOLBAR_IsButtonPressed (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3814 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3818 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3823 TOOLBAR_LoadImages (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HINSTANCE hInstance
)
3826 tbab
.hInst
= hInstance
;
3829 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", infoPtr
->hwndSelf
, tbab
.hInst
, tbab
.nID
);
3831 return TOOLBAR_AddBitmap(infoPtr
, 0, &tbab
);
3836 TOOLBAR_MapAccelerator (const TOOLBAR_INFO
*infoPtr
, WCHAR wAccel
, UINT
*pIDButton
)
3838 WCHAR wszAccel
[] = {'&',wAccel
,0};
3841 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3842 infoPtr
->hwndSelf
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3844 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3846 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3847 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3848 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3850 int iLen
= lstrlenW(wszAccel
);
3851 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3858 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3863 if (!wcsnicmp(lpszStr
, wszAccel
, iLen
))
3865 *pIDButton
= btnPtr
->idCommand
;
3877 TOOLBAR_MarkButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fMark
)
3881 TBUTTON_INFO
*btnPtr
;
3883 TRACE("hwnd = %p, Id = %d, fMark = 0%d\n", infoPtr
->hwndSelf
, Id
, fMark
);
3885 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3889 btnPtr
= &infoPtr
->buttons
[nIndex
];
3890 oldState
= btnPtr
->fsState
;
3893 btnPtr
->fsState
|= TBSTATE_MARKED
;
3895 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
3897 if(oldState
!= btnPtr
->fsState
)
3898 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3904 /* fixes up an index of a button affected by a move */
3905 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
3909 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
3911 else if (*pIndex
== nIndex
)
3912 *pIndex
= nMoveIndex
;
3916 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
3918 else if (*pIndex
== nIndex
)
3919 *pIndex
= nMoveIndex
;
3925 TOOLBAR_MoveButton (TOOLBAR_INFO
*infoPtr
, INT Id
, INT nMoveIndex
)
3929 TBUTTON_INFO button
;
3931 TRACE("hwnd=%p, Id=%d, nMoveIndex=%d\n", infoPtr
->hwndSelf
, Id
, nMoveIndex
);
3933 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, TRUE
);
3934 if ((nIndex
== -1) || (nMoveIndex
< 0))
3937 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
3938 nMoveIndex
= infoPtr
->nNumButtons
- 1;
3940 button
= infoPtr
->buttons
[nIndex
];
3942 /* move button right */
3943 if (nIndex
< nMoveIndex
)
3945 nCount
= nMoveIndex
- nIndex
;
3946 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
3947 infoPtr
->buttons
[nMoveIndex
] = button
;
3949 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
3950 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
3951 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
3952 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
3954 else if (nIndex
> nMoveIndex
) /* move button left */
3956 nCount
= nIndex
- nMoveIndex
;
3957 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
3958 infoPtr
->buttons
[nMoveIndex
] = button
;
3960 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
3961 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
3962 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
3963 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
3966 TOOLBAR_LayoutToolbar(infoPtr
);
3967 TOOLBAR_AutoSize(infoPtr
);
3968 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
3975 TOOLBAR_PressButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fPress
)
3977 TBUTTON_INFO
*btnPtr
;
3981 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3985 btnPtr
= &infoPtr
->buttons
[nIndex
];
3986 oldState
= btnPtr
->fsState
;
3989 btnPtr
->fsState
|= TBSTATE_PRESSED
;
3991 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
3993 if(oldState
!= btnPtr
->fsState
)
3994 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3999 /* FIXME: there might still be some confusion her between number of buttons
4000 * and number of bitmaps */
4002 TOOLBAR_ReplaceBitmap (TOOLBAR_INFO
*infoPtr
, const TBREPLACEBITMAP
*lpReplace
)
4005 int i
= 0, nOldButtons
= 0, pos
= 0;
4006 int nOldBitmaps
, nNewBitmaps
= 0;
4007 HIMAGELIST himlDef
= 0;
4009 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4010 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
4011 lpReplace
->nButtons
);
4013 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4015 FIXME("changing standard bitmaps not implemented\n");
4018 else if (lpReplace
->hInstOld
!= 0 && lpReplace
->hInstOld
!= lpReplace
->hInstNew
)
4019 FIXME("resources not in the current module not implemented\n");
4021 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4022 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4023 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4024 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4025 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4027 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4028 nOldButtons
= tbi
->nButtons
;
4029 tbi
->nButtons
= lpReplace
->nButtons
;
4030 tbi
->hInst
= lpReplace
->hInstNew
;
4031 tbi
->nID
= lpReplace
->nIDNew
;
4032 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4035 pos
+= tbi
->nButtons
;
4038 if (nOldButtons
== 0)
4040 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4044 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4047 if (lpReplace
->hInstNew
)
4048 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4050 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4052 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4053 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4055 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4057 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4058 ImageList_Remove(himlDef
, i
);
4062 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4063 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4064 DeleteObject(hBitmap
);
4067 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4069 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4070 pos
, nOldBitmaps
, nNewBitmaps
);
4072 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4077 /* helper for TOOLBAR_SaveRestoreW */
4079 TOOLBAR_Save(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*params
)
4083 BOOL alloced
= FALSE
;
4086 TRACE( "save to %s %s\n", debugstr_w(params
->pszSubKey
), debugstr_w(params
->pszValueName
) );
4088 memset( &save
, 0, sizeof(save
) );
4089 save
.cbData
= infoPtr
->nNumButtons
* sizeof(DWORD
);
4091 save
.cButtons
= infoPtr
->nNumButtons
;
4092 save
.tbButton
.idCommand
= -1;
4093 TOOLBAR_SendNotify( &save
.hdr
, infoPtr
, TBN_SAVE
);
4097 save
.pData
= Alloc( save
.cbData
);
4098 if (!save
.pData
) return FALSE
;
4101 if (!save
.pCurrent
) save
.pCurrent
= save
.pData
;
4103 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4106 save
.tbButton
.iBitmap
= infoPtr
->buttons
[i
].iBitmap
;
4107 save
.tbButton
.idCommand
= infoPtr
->buttons
[i
].idCommand
;
4108 save
.tbButton
.fsState
= infoPtr
->buttons
[i
].fsState
;
4109 save
.tbButton
.fsStyle
= infoPtr
->buttons
[i
].fsStyle
;
4110 memset( save
.tbButton
.bReserved
, 0, sizeof(save
.tbButton
.bReserved
) );
4111 save
.tbButton
.dwData
= infoPtr
->buttons
[i
].dwData
;
4112 save
.tbButton
.iString
= infoPtr
->buttons
[i
].iString
;
4114 *save
.pCurrent
++ = save
.tbButton
.idCommand
;
4116 TOOLBAR_SendNotify( &save
.hdr
, infoPtr
, TBN_SAVE
);
4119 ret
= RegCreateKeyW( params
->hkr
, params
->pszSubKey
, &key
);
4120 if (ret
== ERROR_SUCCESS
)
4122 ret
= RegSetValueExW( key
, params
->pszValueName
, 0, REG_BINARY
, (BYTE
*)save
.pData
, save
.cbData
);
4126 if (alloced
) Free( save
.pData
);
4131 /* helper for TOOLBAR_Restore */
4133 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4137 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4139 free_string( infoPtr
->buttons
+ i
);
4140 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4143 Free(infoPtr
->buttons
);
4144 infoPtr
->buttons
= NULL
;
4145 infoPtr
->nNumButtons
= 0;
4149 /* helper for TOOLBAR_SaveRestoreW */
4151 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4161 /* restore toolbar information */
4162 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4163 debugstr_w(lpSave
->pszValueName
));
4165 memset(&nmtbr
, 0, sizeof(nmtbr
));
4167 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4168 KEY_QUERY_VALUE
, &hkey
);
4170 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4172 if (!res
&& dwType
!= REG_BINARY
)
4173 res
= ERROR_FILE_NOT_FOUND
;
4176 nmtbr
.pData
= Alloc(dwSize
);
4177 nmtbr
.cbData
= dwSize
;
4178 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4181 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4182 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4185 nmtbr
.pCurrent
= nmtbr
.pData
;
4187 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4188 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4190 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4192 INT i
, count
= nmtbr
.cButtons
;
4194 /* remove all existing buttons as this function is designed to
4195 * restore the toolbar to a previously saved state */
4196 TOOLBAR_DeleteAllButtons(infoPtr
);
4198 for (i
= 0; i
< count
; i
++)
4201 nmtbr
.tbButton
.iBitmap
= -1;
4202 nmtbr
.tbButton
.fsState
= 0;
4203 nmtbr
.tbButton
.fsStyle
= 0;
4204 nmtbr
.tbButton
.dwData
= 0;
4205 nmtbr
.tbButton
.iString
= 0;
4207 if (*nmtbr
.pCurrent
& 0x80000000)
4210 nmtbr
.tbButton
.iBitmap
= SEPARATOR_WIDTH
;
4211 nmtbr
.tbButton
.idCommand
= 0;
4212 nmtbr
.tbButton
.fsStyle
= BTNS_SEP
;
4213 if (*nmtbr
.pCurrent
!= (DWORD
)-1)
4214 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4217 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4221 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4223 /* All returned ptrs and -1 are ignored */
4224 if (!IS_INTRESOURCE(nmtbr
.tbButton
.iString
))
4225 nmtbr
.tbButton
.iString
= 0;
4227 TOOLBAR_InsertButtonT(infoPtr
, -1, &nmtbr
.tbButton
, TRUE
);
4230 TOOLBAR_SendNotify( &hdr
, infoPtr
, TBN_BEGINADJUST
);
4236 UINT code
= infoPtr
->bUnicode
? TBN_GETBUTTONINFOW
: TBN_GETBUTTONINFOA
;
4239 memset( &tb
, 0, sizeof(tb
) );
4241 tb
.cchText
= ARRAY_SIZE(buf
);
4244 /* Use the same struct for both A and W versions since the layout is the same. */
4245 if (!TOOLBAR_SendNotify( &tb
.hdr
, infoPtr
, code
))
4248 idx
= TOOLBAR_GetButtonIndex( infoPtr
, tb
.tbButton
.idCommand
, FALSE
);
4249 if (idx
== -1) continue;
4251 /* tb.pszText is ignored - the string comes from tb.tbButton.iString, which may
4252 be an index or a ptr. Either way it is simply copied. There is no api to change
4253 the string index, so we set it manually. The other properties can be set with SetButtonInfo. */
4254 free_string( infoPtr
->buttons
+ idx
);
4255 infoPtr
->buttons
[idx
].iString
= tb
.tbButton
.iString
;
4257 memset( &bi
, 0, sizeof(bi
) );
4258 bi
.cbSize
= sizeof(bi
);
4259 bi
.dwMask
= TBIF_IMAGE
| TBIF_STATE
| TBIF_STYLE
| TBIF_LPARAM
;
4260 bi
.iImage
= tb
.tbButton
.iBitmap
;
4261 bi
.fsState
= tb
.tbButton
.fsState
;
4262 bi
.fsStyle
= tb
.tbButton
.fsStyle
;
4263 bi
.lParam
= tb
.tbButton
.dwData
;
4265 TOOLBAR_SetButtonInfo( infoPtr
, tb
.tbButton
.idCommand
, &bi
, TRUE
);
4267 TOOLBAR_SendNotify( &hdr
, infoPtr
, TBN_ENDADJUST
);
4269 /* remove all uninitialised buttons
4270 * note: loop backwards to avoid having to fixup i on a
4272 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4273 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4274 TOOLBAR_DeleteButton(infoPtr
, i
);
4276 /* only indicate success if at least one button survived */
4277 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4288 TOOLBAR_SaveRestoreW (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4290 if (lpSave
== NULL
) return 0;
4293 return TOOLBAR_Save(infoPtr
, lpSave
);
4295 return TOOLBAR_Restore(infoPtr
, lpSave
);
4300 TOOLBAR_SaveRestoreA (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4302 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4303 TBSAVEPARAMSW SaveW
;
4307 if (lpSave
== NULL
) return 0;
4309 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4310 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4311 if (!pszSubKey
) goto exit
;
4312 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4314 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4315 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4316 if (!pszValueName
) goto exit
;
4317 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4319 SaveW
.pszValueName
= pszValueName
;
4320 SaveW
.pszSubKey
= pszSubKey
;
4321 SaveW
.hkr
= lpSave
->hkr
;
4322 result
= TOOLBAR_SaveRestoreW(infoPtr
, wParam
, &SaveW
);
4325 Free (pszValueName
);
4333 TOOLBAR_SetAnchorHighlight (TOOLBAR_INFO
*infoPtr
, BOOL bAnchor
)
4335 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4337 TRACE("hwnd=%p, bAnchor = %s\n", infoPtr
->hwndSelf
, bAnchor
? "TRUE" : "FALSE");
4339 infoPtr
->bAnchor
= bAnchor
;
4341 /* Native does not remove the hot effect from an already hot button */
4343 return (LRESULT
)bOldAnchor
;
4348 TOOLBAR_SetBitmapSize (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4350 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4351 short width
= (short)LOWORD(lParam
);
4352 short height
= (short)HIWORD(lParam
);
4354 TRACE("hwnd=%p, wParam=%ld, size %d x %d\n", infoPtr
->hwndSelf
, wParam
, width
, height
);
4357 FIXME("wParam is %ld. Perhaps image list index?\n", wParam
);
4359 /* 0 width or height is changed to 1 */
4365 if (infoPtr
->nNumButtons
> 0)
4366 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4367 infoPtr
->nNumButtons
,
4368 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
, width
, height
);
4370 if (width
< -1 || height
< -1)
4372 /* Windows destroys the imagelist and seems to actually use negative
4373 * values to compute button sizes */
4374 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width
, height
);
4378 /* width or height of -1 means no change */
4380 infoPtr
->nBitmapWidth
= width
;
4382 infoPtr
->nBitmapHeight
= height
;
4384 if ((himlDef
== infoPtr
->himlInt
) &&
4385 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4387 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4388 infoPtr
->nBitmapHeight
);
4391 TOOLBAR_CalcToolbar(infoPtr
);
4392 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4398 TOOLBAR_SetButtonInfo (TOOLBAR_INFO
*infoPtr
, INT Id
,
4399 const TBBUTTONINFOW
*lptbbi
, BOOL isW
)
4401 TBUTTON_INFO
*btnPtr
;
4407 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4410 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lptbbi
->dwMask
& TBIF_BYINDEX
);
4414 btnPtr
= &infoPtr
->buttons
[nIndex
];
4415 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4416 btnPtr
->idCommand
= lptbbi
->idCommand
;
4417 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4418 btnPtr
->iBitmap
= lptbbi
->iImage
;
4419 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4420 btnPtr
->dwData
= lptbbi
->lParam
;
4421 if (lptbbi
->dwMask
& TBIF_SIZE
)
4422 btnPtr
->cx
= lptbbi
->cx
;
4423 if (lptbbi
->dwMask
& TBIF_STATE
)
4424 btnPtr
->fsState
= lptbbi
->fsState
;
4425 if (lptbbi
->dwMask
& TBIF_STYLE
)
4426 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4428 if (lptbbi
->dwMask
& TBIF_TEXT
)
4429 set_stringT( btnPtr
, lptbbi
->pszText
, isW
);
4431 /* save the button rect to see if we need to redraw the whole toolbar */
4432 oldBtnRect
= btnPtr
->rect
;
4433 TOOLBAR_LayoutToolbar(infoPtr
);
4435 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4436 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4438 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4445 TOOLBAR_SetButtonSize (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4447 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4448 int top
= default_top_margin(infoPtr
);
4450 if ((cx
< 0) || (cy
< 0))
4452 ERR("invalid parameter 0x%08x\n", (DWORD
)lParam
);
4456 TRACE("%p, cx = %d, cy = %d\n", infoPtr
->hwndSelf
, cx
, cy
);
4458 /* The documentation claims you can only change the button size before
4459 * any button has been added. But this is wrong.
4460 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4461 * it to the toolbar, and it checks that the return value is nonzero - mjm
4462 * Further testing shows that we must actually perform the change too.
4465 * The documentation also does not mention that if 0 is supplied for
4466 * either size, the system changes it to the default of 24 wide and
4467 * 22 high. Demonstrated in ControlSpy Toolbar. GLA 3/02
4469 if (cx
== 0) cx
= 24;
4470 if (cy
== 0) cy
= 22;
4472 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4473 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4475 if (cx
!= infoPtr
->nButtonWidth
|| cy
!= infoPtr
->nButtonHeight
||
4476 top
!= infoPtr
->iTopMargin
)
4478 infoPtr
->nButtonWidth
= cx
;
4479 infoPtr
->nButtonHeight
= cy
;
4480 infoPtr
->iTopMargin
= top
;
4482 TOOLBAR_LayoutToolbar( infoPtr
);
4483 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
4490 TOOLBAR_SetButtonWidth (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4492 /* if setting to current values, ignore */
4493 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4494 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4495 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4496 infoPtr
->cxMin
, infoPtr
->cxMax
);
4500 /* save new values */
4501 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4502 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4504 /* otherwise we need to recalc the toolbar and in some cases
4505 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4506 which doesn't actually draw - GA). */
4507 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4508 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4510 TOOLBAR_CalcToolbar (infoPtr
);
4512 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
4519 TOOLBAR_SetCmdId (TOOLBAR_INFO
*infoPtr
, INT nIndex
, INT nId
)
4521 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4524 infoPtr
->buttons
[nIndex
].idCommand
= nId
;
4526 if (infoPtr
->hwndToolTip
) {
4528 FIXME("change tool tip\n");
4537 TOOLBAR_SetDisabledImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4539 HIMAGELIST himlTemp
;
4542 if (infoPtr
->iVersion
>= 5)
4545 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4546 &infoPtr
->cimlDis
, himl
, id
);
4548 /* FIXME: redraw ? */
4550 return (LRESULT
)himlTemp
;
4555 TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD flags
)
4559 TRACE("hwnd = %p, mask = 0x%08x, flags = 0x%08x\n", infoPtr
->hwndSelf
, mask
, flags
);
4561 old_flags
= infoPtr
->dwDTFlags
;
4562 infoPtr
->dwDTFlags
= (old_flags
& ~mask
) | (flags
& mask
);
4564 return (LRESULT
)old_flags
;
4567 /* This function differs a bit from what MSDN says it does:
4568 * 1. lParam contains extended style flags to OR with current style
4569 * (MSDN isn't clear on the OR bit)
4570 * 2. wParam appears to contain extended style flags to be reset
4571 * (MSDN says that this parameter is reserved)
4574 TOOLBAR_SetExtendedStyle (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD style
)
4576 DWORD old_style
= infoPtr
->dwExStyle
;
4578 TRACE("mask=0x%08x, style=0x%08x\n", mask
, style
);
4581 infoPtr
->dwExStyle
= (old_style
& ~mask
) | (style
& mask
);
4583 infoPtr
->dwExStyle
= style
;
4585 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4586 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4587 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4589 if ((old_style
^ infoPtr
->dwExStyle
) & TBSTYLE_EX_MIXEDBUTTONS
)
4590 TOOLBAR_CalcToolbar(infoPtr
);
4592 TOOLBAR_LayoutToolbar(infoPtr
);
4594 TOOLBAR_AutoSize(infoPtr
);
4595 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4602 TOOLBAR_SetHotImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4604 HIMAGELIST himlTemp
;
4607 if (infoPtr
->iVersion
>= 5)
4610 TRACE("hwnd = %p, himl = %p, id = %d\n", infoPtr
->hwndSelf
, himl
, id
);
4612 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4613 &infoPtr
->cimlHot
, himl
, id
);
4615 /* FIXME: redraw ? */
4617 return (LRESULT
)himlTemp
;
4621 /* Makes previous hot button no longer hot, makes the specified
4622 * button hot and sends appropriate notifications. dwReason is one or
4623 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4624 * NOTE 1: this function does not validate nHit
4625 * NOTE 2: the name of this function is completely made up and
4626 * not based on any documentation from Microsoft. */
4628 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4630 if (infoPtr
->nHotItem
!= nHit
)
4632 NMTBHOTITEM nmhotitem
;
4633 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4635 nmhotitem
.dwFlags
= dwReason
;
4636 if(infoPtr
->nHotItem
>= 0)
4638 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4639 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4643 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4644 nmhotitem
.idOld
= 0;
4649 btnPtr
= &infoPtr
->buttons
[nHit
];
4650 nmhotitem
.idNew
= btnPtr
->idCommand
;
4654 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4655 nmhotitem
.idNew
= 0;
4658 /* now change the hot and invalidate the old and new buttons - if the
4660 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4663 oldBtnPtr
->bHot
= FALSE
;
4664 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4666 /* setting disabled buttons as hot fails even if the notify contains the button id */
4667 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4668 btnPtr
->bHot
= TRUE
;
4669 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4670 infoPtr
->nHotItem
= nHit
;
4673 infoPtr
->nHotItem
= -1;
4679 TOOLBAR_SetHotItem (TOOLBAR_INFO
*infoPtr
, INT nHotItem
)
4681 INT nOldHotItem
= infoPtr
->nHotItem
;
4683 TRACE("hwnd = %p, nHotItem = %d\n", infoPtr
->hwndSelf
, nHotItem
);
4685 if (nHotItem
>= infoPtr
->nNumButtons
)
4686 return infoPtr
->nHotItem
;
4691 /* NOTE: an application can still remove the hot item even if anchor
4692 * highlighting is enabled */
4694 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, HICF_OTHER
);
4696 if (nOldHotItem
< 0)
4699 return (LRESULT
)nOldHotItem
;
4704 TOOLBAR_SetImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4706 HIMAGELIST himlTemp
;
4707 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4708 INT oldBitmapWidth
= infoPtr
->nBitmapWidth
;
4709 INT oldBitmapHeight
= infoPtr
->nBitmapHeight
;
4712 if (infoPtr
->iVersion
>= 5)
4715 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4716 &infoPtr
->cimlDef
, himl
, id
);
4718 infoPtr
->nNumBitmaps
= 0;
4719 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4720 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4722 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4723 &infoPtr
->nBitmapHeight
))
4725 infoPtr
->nBitmapWidth
= 1;
4726 infoPtr
->nBitmapHeight
= 1;
4728 if ((oldBitmapWidth
!= infoPtr
->nBitmapWidth
) || (oldBitmapHeight
!= infoPtr
->nBitmapHeight
))
4730 TOOLBAR_CalcToolbar(infoPtr
);
4731 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4732 TOOLBAR_SetButtonSize(infoPtr
, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4735 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4736 infoPtr
->hwndSelf
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4737 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4739 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4741 return (LRESULT
)himlTemp
;
4746 TOOLBAR_SetIndent (TOOLBAR_INFO
*infoPtr
, INT nIndent
)
4748 infoPtr
->nIndent
= nIndent
;
4752 /* process only on indent changing */
4753 if(infoPtr
->nIndent
!= nIndent
)
4755 infoPtr
->nIndent
= nIndent
;
4756 TOOLBAR_CalcToolbar (infoPtr
);
4757 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4765 TOOLBAR_SetInsertMark (TOOLBAR_INFO
*infoPtr
, const TBINSERTMARK
*lptbim
)
4767 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", infoPtr
->hwndSelf
, lptbim
->iButton
, lptbim
->dwFlags
);
4769 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4771 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4775 if ((lptbim
->iButton
== -1) ||
4776 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4777 (lptbim
->iButton
>= 0)))
4779 infoPtr
->tbim
= *lptbim
;
4780 /* FIXME: don't need to update entire toolbar */
4781 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4784 ERR("Invalid button index %d\n", lptbim
->iButton
);
4791 TOOLBAR_SetInsertMarkColor (TOOLBAR_INFO
*infoPtr
, COLORREF clr
)
4793 infoPtr
->clrInsertMark
= clr
;
4795 /* FIXME: don't need to update entire toolbar */
4796 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4803 TOOLBAR_SetMaxTextRows (TOOLBAR_INFO
*infoPtr
, INT nMaxRows
)
4805 infoPtr
->nMaxTextRows
= nMaxRows
;
4807 TOOLBAR_CalcToolbar(infoPtr
);
4812 /* MSDN gives slightly wrong info on padding.
4813 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4814 * 2. It is not used to create a blank area between the edge of the button
4815 * and the text or image if TBSTYLE_LIST is set. It is used to control
4816 * the gap between the image and text.
4817 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4818 * to control the bottom and right borders [with the border being
4819 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4820 * is shared evenly on both sides of the button.
4821 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4824 TOOLBAR_SetPadding (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4828 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4829 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4830 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4831 TRACE("cx=%d, cy=%d\n",
4832 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4833 return (LRESULT
) oldPad
;
4838 TOOLBAR_SetParent (TOOLBAR_INFO
*infoPtr
, HWND hParent
)
4844 hwndOldNotify
= infoPtr
->hwndNotify
;
4845 infoPtr
->hwndNotify
= hParent
;
4847 return (LRESULT
)hwndOldNotify
;
4852 TOOLBAR_SetRows (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPRECT lprc
)
4854 int rows
= LOWORD(wParam
);
4855 BOOL bLarger
= HIWORD(wParam
);
4859 TRACE("Setting rows to %d (%d)\n", rows
, bLarger
);
4861 if(infoPtr
->nRows
!= rows
)
4863 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
;
4864 int curColumn
= 0; /* Current column */
4865 int curRow
= 0; /* Current row */
4866 int hidden
= 0; /* Number of hidden buttons */
4867 int seps
= 0; /* Number of separators */
4868 int idealWrap
= 0; /* Ideal wrap point */
4873 Calculate new size and wrap points - Under windows, setrows will
4874 change the dimensions if needed to show the number of requested
4875 rows (if CCS_NORESIZE is set), or will take up the whole window
4876 (if no CCS_NORESIZE).
4878 Basic algorithm - If N buttons, and y rows requested, each row
4879 contains N/y buttons.
4881 FIXME: Handling of separators not obvious from testing results
4882 FIXME: Take width of window into account?
4885 /* Loop through the buttons one by one counting key items */
4886 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4888 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
4889 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4891 else if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
4895 /* FIXME: Separators make this quite complex */
4896 if (seps
) FIXME("Separators unhandled\n");
4898 /* Round up so more per line, i.e., less rows */
4899 idealWrap
= (infoPtr
->nNumButtons
- hidden
+ (rows
-1)) / (rows
? rows
: 1);
4901 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4902 achieve the requested number of rows. */
4903 if (bLarger
&& idealWrap
> 1)
4905 int resRows
= (infoPtr
->nNumButtons
+ (idealWrap
-1)) / idealWrap
;
4906 int moreRows
= (infoPtr
->nNumButtons
+ (idealWrap
-2)) / (idealWrap
-1);
4908 if (resRows
< rows
&& moreRows
> rows
)
4911 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap
);
4915 curColumn
= curRow
= 0;
4917 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap
,
4918 infoPtr
->nNumButtons
, hidden
, rows
);
4920 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4922 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4925 /* Step on, wrap if necessary or flag next to wrap */
4934 if (curColumn
> (idealWrap
-1)) {
4936 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
4940 TRACE("Result - %d rows\n", curRow
+ 1);
4942 /* recalculate toolbar */
4943 TOOLBAR_CalcToolbar (infoPtr
);
4945 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
4946 if NORESIZE is NOT set, then the toolbar will always be resized to
4947 take up the whole window. With it set, sizing needs to be manual. */
4948 if (infoPtr
->dwStyle
& CCS_NORESIZE
) {
4949 SetWindowPos(infoPtr
->hwndSelf
, NULL
, 0, 0,
4950 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
4951 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
,
4952 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
4955 /* repaint toolbar */
4956 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4959 /* return bounding rectangle */
4961 lprc
->left
= infoPtr
->rcBound
.left
;
4962 lprc
->right
= infoPtr
->rcBound
.right
;
4963 lprc
->top
= infoPtr
->rcBound
.top
;
4964 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
4972 TOOLBAR_SetState (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
4974 TBUTTON_INFO
*btnPtr
;
4977 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
4981 btnPtr
= &infoPtr
->buttons
[nIndex
];
4983 /* if hidden state has changed the invalidate entire window and recalc */
4984 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
4985 btnPtr
->fsState
= LOWORD(lParam
);
4986 TOOLBAR_CalcToolbar (infoPtr
);
4987 InvalidateRect(infoPtr
->hwndSelf
, 0, TRUE
);
4991 /* process state changing if current state doesn't match new state */
4992 if(btnPtr
->fsState
!= LOWORD(lParam
))
4994 btnPtr
->fsState
= LOWORD(lParam
);
4995 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5001 static inline void unwrap(TOOLBAR_INFO
*info
)
5005 for (i
= 0; i
< info
->nNumButtons
; i
++)
5006 info
->buttons
[i
].fsState
&= ~TBSTATE_WRAP
;
5010 TOOLBAR_SetStyle (TOOLBAR_INFO
*infoPtr
, DWORD style
)
5012 DWORD dwOldStyle
= infoPtr
->dwStyle
;
5014 TRACE("new style 0x%08x\n", style
);
5016 if (style
& TBSTYLE_LIST
)
5017 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
5019 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
5021 infoPtr
->dwStyle
= style
;
5022 TOOLBAR_CheckStyle(infoPtr
);
5024 if ((dwOldStyle
^ style
) & TBSTYLE_WRAPABLE
)
5026 if (dwOldStyle
& TBSTYLE_WRAPABLE
)
5028 TOOLBAR_CalcToolbar(infoPtr
);
5030 else if ((dwOldStyle
^ style
) & CCS_VERT
)
5031 TOOLBAR_LayoutToolbar(infoPtr
);
5033 /* only resize if one of the CCS_* styles was changed */
5034 if ((dwOldStyle
^ style
) & COMMON_STYLES
)
5036 TOOLBAR_AutoSize(infoPtr
);
5037 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5044 static inline LRESULT
5045 TOOLBAR_SetToolTips (TOOLBAR_INFO
*infoPtr
, HWND hwndTooltip
)
5047 TRACE("hwnd=%p, hwndTooltip=%p\n", infoPtr
->hwndSelf
, hwndTooltip
);
5049 infoPtr
->hwndToolTip
= hwndTooltip
;
5055 TOOLBAR_SetUnicodeFormat (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
5059 TRACE("%s hwnd=%p\n",
5060 ((BOOL
)wParam
) ? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
5062 bTemp
= infoPtr
->bUnicode
;
5063 infoPtr
->bUnicode
= (BOOL
)wParam
;
5070 TOOLBAR_GetColorScheme (const TOOLBAR_INFO
*infoPtr
, LPCOLORSCHEME lParam
)
5072 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
5073 comctl32_color
.clrBtnHighlight
:
5074 infoPtr
->clrBtnHighlight
;
5075 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
5076 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
5082 TOOLBAR_SetColorScheme (TOOLBAR_INFO
*infoPtr
, const COLORSCHEME
*lParam
)
5084 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5085 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
5086 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
5088 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
5089 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
5090 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5096 TOOLBAR_SetVersion (TOOLBAR_INFO
*infoPtr
, INT iVersion
)
5098 INT iOldVersion
= infoPtr
->iVersion
;
5100 infoPtr
->iVersion
= iVersion
;
5102 if (infoPtr
->iVersion
>= 5)
5103 TOOLBAR_SetUnicodeFormat(infoPtr
, TRUE
);
5110 TOOLBAR_GetStringA (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPSTR str
)
5112 WORD iString
= HIWORD(wParam
);
5113 WORD buffersize
= LOWORD(wParam
);
5116 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, buffersize
, str
);
5118 if (iString
< infoPtr
->nNumStrings
)
5120 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
5123 TRACE("returning %s\n", debugstr_a(str
));
5126 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5133 TOOLBAR_GetStringW (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPWSTR str
)
5135 WORD iString
= HIWORD(wParam
);
5136 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5139 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, LOWORD(wParam
), str
);
5141 if (iString
< infoPtr
->nNumStrings
)
5143 len
= min(len
, lstrlenW(infoPtr
->strings
[iString
]));
5144 ret
= (len
+1)*sizeof(WCHAR
);
5147 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5152 TRACE("returning %s\n", debugstr_w(str
));
5155 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5160 static LRESULT
TOOLBAR_SetBoundingSize(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5162 SIZE
* pSize
= (SIZE
*)lParam
;
5163 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5167 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5168 * caller to specify a reason why the hot item changed (rather than just the
5169 * HICF_OTHER that TB_SETHOTITEM sends). */
5171 TOOLBAR_SetHotItem2 (TOOLBAR_INFO
*infoPtr
, INT nHotItem
, LPARAM lParam
)
5173 INT nOldHotItem
= infoPtr
->nHotItem
;
5175 TRACE("old item=%d, new item=%d, flags=%08x\n",
5176 nOldHotItem
, nHotItem
, (DWORD
)lParam
);
5178 if (nHotItem
< 0 || nHotItem
> infoPtr
->nNumButtons
)
5181 /* NOTE: an application can still remove the hot item even if anchor
5182 * highlighting is enabled */
5184 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, lParam
);
5186 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5189 /* Sets the toolbar global iListGap parameter which controls the amount of
5190 * spacing between the image and the text of buttons for TBSTYLE_LIST
5192 static LRESULT
TOOLBAR_SetListGap(TOOLBAR_INFO
*infoPtr
, INT iListGap
)
5194 TRACE("hwnd=%p iListGap=%d\n", infoPtr
->hwndSelf
, iListGap
);
5196 infoPtr
->iListGap
= iListGap
;
5198 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5203 /* Returns the number of maximum number of image lists associated with the
5204 * various states. */
5205 static LRESULT
TOOLBAR_GetImageListCount(const TOOLBAR_INFO
*infoPtr
)
5207 TRACE("hwnd=%p\n", infoPtr
->hwndSelf
);
5209 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5213 TOOLBAR_GetIdealSize (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5215 LPSIZE lpsize
= (LPSIZE
)lParam
;
5221 * Testing shows the following:
5222 * wParam = 0 adjust cx value
5223 * = 1 set cy value to max size.
5224 * lParam pointer to SIZE structure
5227 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5228 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5232 if (lpsize
->cx
== -1) {
5233 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5235 else if(HIWORD(lpsize
->cx
)) {
5237 HWND hwndParent
= GetParent(infoPtr
->hwndSelf
);
5239 GetWindowRect(infoPtr
->hwndSelf
, &rc
);
5240 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5241 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc
));
5242 lpsize
->cx
= max(rc
.right
-rc
.left
,
5243 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5246 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5250 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5253 FIXME("Unknown wParam %ld\n", wParam
);
5256 TRACE("set to -> 0x%08x 0x%08x\n",
5257 lpsize
->cx
, lpsize
->cy
);
5261 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5263 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5265 InvalidateRect(hwnd
, NULL
, TRUE
);
5271 TOOLBAR_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
5273 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
5276 TRACE("hwnd = %p, style=0x%08x\n", hwnd
, lpcs
->style
);
5278 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5279 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5280 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5281 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_REQUERY
));
5282 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5284 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5285 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5287 OpenThemeData (hwnd
, themeClass
);
5289 TOOLBAR_CheckStyle (infoPtr
);
5296 TOOLBAR_Destroy (TOOLBAR_INFO
*infoPtr
)
5300 /* delete tooltip control */
5301 if (infoPtr
->hwndToolTip
)
5302 DestroyWindow (infoPtr
->hwndToolTip
);
5304 /* delete temporary buffer for tooltip text */
5305 Free (infoPtr
->pszTooltipText
);
5306 Free (infoPtr
->bitmaps
); /* bitmaps list */
5308 /* delete button data */
5309 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5310 free_string( infoPtr
->buttons
+ i
);
5311 Free (infoPtr
->buttons
);
5313 /* delete strings */
5314 if (infoPtr
->strings
) {
5315 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5316 Free (infoPtr
->strings
[i
]);
5318 Free (infoPtr
->strings
);
5321 /* destroy internal image list */
5322 if (infoPtr
->himlInt
)
5323 ImageList_Destroy (infoPtr
->himlInt
);
5325 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5326 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5327 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5329 /* delete default font */
5330 DeleteObject (infoPtr
->hDefaultFont
);
5332 CloseThemeData (GetWindowTheme (infoPtr
->hwndSelf
));
5334 /* free toolbar info data */
5335 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
5343 TOOLBAR_EraseBackground (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5345 NMTBCUSTOMDRAW tbcd
;
5348 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
5349 DWORD dwEraseCustDraw
= 0;
5351 /* the app has told us not to redraw the toolbar */
5352 if (!infoPtr
->bDoRedraw
)
5355 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5356 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5357 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5358 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5359 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5360 dwEraseCustDraw
= ntfret
& 0xffff;
5362 /* FIXME: in general the return flags *can* be or'ed together */
5363 switch (dwEraseCustDraw
)
5365 case CDRF_DODEFAULT
:
5367 case CDRF_SKIPDEFAULT
:
5370 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5371 infoPtr
->hwndSelf
, ntfret
);
5375 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5376 * to my parent for processing.
5378 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5380 HDC hdc
= (HDC
)wParam
;
5385 parent
= GetParent(infoPtr
->hwndSelf
);
5386 MapWindowPoints(infoPtr
->hwndSelf
, parent
, &pt
, 1);
5387 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5388 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5389 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5392 ret
= DefWindowProcW (infoPtr
->hwndSelf
, WM_ERASEBKGND
, wParam
, lParam
);
5394 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5395 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5396 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5397 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5398 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5399 dwEraseCustDraw
= ntfret
& 0xffff;
5400 switch (dwEraseCustDraw
)
5402 case CDRF_DODEFAULT
:
5404 case CDRF_SKIPDEFAULT
:
5407 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5408 infoPtr
->hwndSelf
, ntfret
);
5415 static inline LRESULT
5416 TOOLBAR_GetFont (const TOOLBAR_INFO
*infoPtr
)
5418 return (LRESULT
)infoPtr
->hFont
;
5423 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5426 INT nNewHotItem
= infoPtr
->nHotItem
;
5428 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5431 if ((nNewHotItem
+ iDirection
< 0) ||
5432 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5434 NMTBWRAPHOTITEM nmtbwhi
;
5435 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5436 nmtbwhi
.iDirection
= iDirection
;
5437 nmtbwhi
.dwReason
= dwReason
;
5439 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5443 nNewHotItem
+= iDirection
;
5444 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5446 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5447 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5449 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5456 TOOLBAR_KeyDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5460 nmkey
.nVKey
= (UINT
)wParam
;
5461 nmkey
.uFlags
= HIWORD(lParam
);
5463 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5464 return DefWindowProcW(infoPtr
->hwndSelf
, WM_KEYDOWN
, wParam
, lParam
);
5466 switch ((UINT
)wParam
)
5470 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5474 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5478 if ((infoPtr
->nHotItem
>= 0) &&
5479 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5481 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5482 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5483 (LPARAM
)infoPtr
->hwndSelf
);
5493 TOOLBAR_LButtonDblClk (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5498 pt
.x
= (short)LOWORD(lParam
);
5499 pt
.y
= (short)HIWORD(lParam
);
5500 TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5503 TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
5504 else if (infoPtr
->dwStyle
& CCS_ADJUSTABLE
)
5505 TOOLBAR_Customize (infoPtr
);
5512 TOOLBAR_LButtonDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5514 TBUTTON_INFO
*btnPtr
;
5519 BOOL bDragKeyPressed
;
5524 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5525 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5527 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5529 if (infoPtr
->hwndToolTip
)
5530 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5531 WM_LBUTTONDOWN
, wParam
, lParam
);
5533 pt
.x
= (short)LOWORD(lParam
);
5534 pt
.y
= (short)HIWORD(lParam
);
5535 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5539 btnPtr
= &infoPtr
->buttons
[nHit
];
5541 if (bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5543 infoPtr
->nButtonDrag
= nHit
;
5544 SetCapture (infoPtr
->hwndSelf
);
5546 /* If drag cursor has not been loaded, load it.
5547 * Note: it doesn't need to be freed */
5549 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5550 SetCursor(hCursorDrag
);
5555 infoPtr
->nOldHit
= nHit
;
5557 arrowRect
= btnPtr
->rect
;
5558 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5560 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5561 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5562 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5563 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5564 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5565 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5569 /* draw in pressed state */
5570 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5571 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5573 btnPtr
->bDropDownPressed
= TRUE
;
5574 RedrawWindow(infoPtr
->hwndSelf
, &btnPtr
->rect
, 0, RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5576 memset(&nmtb
, 0, sizeof(nmtb
));
5577 nmtb
.iItem
= btnPtr
->idCommand
;
5578 nmtb
.rcButton
= btnPtr
->rect
;
5579 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
, TBN_DROPDOWN
);
5580 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5582 if (res
!= TBDDRET_TREATPRESSED
)
5586 /* redraw button in unpressed state */
5587 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5588 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5590 btnPtr
->bDropDownPressed
= FALSE
;
5591 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5593 /* find and set hot item */
5595 ScreenToClient(infoPtr
->hwndSelf
, &pt
);
5596 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5597 if (!infoPtr
->bAnchor
|| button
)
5598 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5600 /* remove any left mouse button down or double-click messages
5601 * so that we can get a toggle effect on the button */
5602 while (PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5603 PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5608 /* otherwise drop through and process as pushed */
5610 infoPtr
->bCaptured
= TRUE
;
5611 infoPtr
->nButtonDown
= nHit
;
5612 infoPtr
->bDragOutSent
= FALSE
;
5614 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5616 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5618 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5619 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5620 UpdateWindow(infoPtr
->hwndSelf
);
5621 SetCapture (infoPtr
->hwndSelf
);
5624 memset(&nmtb
, 0, sizeof(nmtb
));
5625 nmtb
.iItem
= btnPtr
->idCommand
;
5626 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5629 nmmouse
.dwHitInfo
= nHit
;
5631 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5633 nmmouse
.dwItemSpec
= -1;
5636 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5637 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5640 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5643 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5644 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, wParam
, lParam
);
5650 TOOLBAR_LButtonUp (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5652 TBUTTON_INFO
*btnPtr
;
5661 if (infoPtr
->hwndToolTip
)
5662 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5663 WM_LBUTTONUP
, wParam
, lParam
);
5665 pt
.x
= (short)LOWORD(lParam
);
5666 pt
.y
= (short)HIWORD(lParam
);
5667 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5669 if (!infoPtr
->bAnchor
|| button
)
5670 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5672 if (infoPtr
->nButtonDrag
>= 0) {
5676 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5679 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5681 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5682 if (PtInRect(&rcClient
, pt
))
5689 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5692 if (nButton
== infoPtr
->nButtonDrag
)
5694 /* if the button is moved slightly left and we have a
5695 * separator there then remove it */
5696 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5698 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5699 TOOLBAR_DeleteButton(infoPtr
, nButton
- 1);
5701 else /* else insert a separator before the dragged button */
5704 memset(&tbb
, 0, sizeof(tbb
));
5705 tbb
.fsStyle
= BTNS_SEP
;
5707 TOOLBAR_InsertButtonT(infoPtr
, nButton
, &tbb
, TRUE
);
5714 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5715 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, 0);
5717 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5720 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, nButton
);
5725 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5726 TOOLBAR_DeleteButton(infoPtr
, infoPtr
->nButtonDrag
);
5729 /* button under cursor changed so need to re-set hot item */
5730 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5731 infoPtr
->nButtonDrag
= -1;
5733 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5735 else if (infoPtr
->nButtonDown
>= 0)
5737 BOOL was_clicked
= nHit
== infoPtr
->nButtonDown
;
5739 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5740 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5742 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5743 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5744 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5746 if ((nOldIndex
!= nHit
) &&
5748 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5749 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5752 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5753 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5755 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5759 if (nOldIndex
!= -1)
5760 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5763 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5764 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5765 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5767 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5769 infoPtr
->nButtonDown
= -1;
5771 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5772 TOOLBAR_SendNotify (&hdr
, infoPtr
,
5773 NM_RELEASEDCAPTURE
);
5775 memset(&nmtb
, 0, sizeof(nmtb
));
5776 nmtb
.iItem
= btnPtr
->idCommand
;
5777 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5780 if (was_clicked
&& btnPtr
->fsState
& TBSTATE_ENABLED
)
5782 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5783 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)infoPtr
->hwndSelf
);
5785 /* In case we have just been destroyed... */
5786 if(!IsWindow(infoPtr
->hwndSelf
))
5791 /* !!! Undocumented - toolbar at 4.71 level and above sends
5792 * NM_CLICK with the NMMOUSE structure. */
5793 nmmouse
.dwHitInfo
= nHit
;
5796 nmmouse
.dwItemSpec
= -1;
5799 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5800 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5803 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5806 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5807 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONUP
, wParam
, lParam
);
5813 TOOLBAR_RButtonUp(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5820 pt
.x
= (short)LOWORD(lParam
);
5821 pt
.y
= (short)HIWORD(lParam
);
5823 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5824 nmmouse
.dwHitInfo
= nHit
;
5827 nmmouse
.dwItemSpec
= -1;
5829 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5830 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5833 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5836 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5837 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONUP
, wParam
, lParam
);
5843 TOOLBAR_RButtonDblClk( TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5847 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5848 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
5854 TOOLBAR_CaptureChanged(TOOLBAR_INFO
*infoPtr
)
5856 TBUTTON_INFO
*btnPtr
;
5858 infoPtr
->bCaptured
= FALSE
;
5860 if (infoPtr
->nButtonDown
>= 0)
5862 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5863 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5865 infoPtr
->nOldHit
= -1;
5867 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5868 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5874 TOOLBAR_MouseLeave (TOOLBAR_INFO
*infoPtr
)
5876 /* don't remove hot effects when in anchor highlighting mode or when a
5877 * drop-down button is pressed */
5878 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
5880 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
5881 if (!hotBtnPtr
->bDropDownPressed
)
5882 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
5885 if (infoPtr
->nOldHit
< 0)
5888 /* If the last button we were over is depressed then make it not */
5889 /* depressed and redraw it */
5890 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
5892 TBUTTON_INFO
*btnPtr
;
5895 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5897 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5900 InflateRect (&rc1
, 1, 1);
5901 InvalidateRect (infoPtr
->hwndSelf
, &rc1
, TRUE
);
5904 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
5907 ZeroMemory(&nmt
, sizeof(nmt
));
5908 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5909 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5910 infoPtr
->bDragOutSent
= TRUE
;
5913 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
5919 TOOLBAR_MouseMove (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5922 TRACKMOUSEEVENT trackinfo
;
5924 TBUTTON_INFO
*btnPtr
;
5927 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
5928 TOOLBAR_TooltipCreateControl(infoPtr
);
5930 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
5931 /* fill in the TRACKMOUSEEVENT struct */
5932 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5933 trackinfo
.dwFlags
= TME_QUERY
;
5935 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5936 _TrackMouseEvent(&trackinfo
);
5938 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5939 if(trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
5940 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5941 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
5943 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5944 /* and can properly deactivate the hot toolbar button */
5945 _TrackMouseEvent(&trackinfo
);
5949 if (infoPtr
->hwndToolTip
)
5950 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5951 WM_MOUSEMOVE
, wParam
, lParam
);
5953 pt
.x
= (short)LOWORD(lParam
);
5954 pt
.y
= (short)HIWORD(lParam
);
5956 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5958 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
5959 && (!infoPtr
->bAnchor
|| button
))
5960 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
);
5962 if (infoPtr
->nOldHit
!= nHit
)
5964 if (infoPtr
->bCaptured
)
5966 if (!infoPtr
->bDragOutSent
)
5969 ZeroMemory(&nmt
, sizeof(nmt
));
5970 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5971 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5972 infoPtr
->bDragOutSent
= TRUE
;
5975 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5976 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
5977 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5978 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5980 else if (nHit
== infoPtr
->nButtonDown
) {
5981 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5982 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5984 infoPtr
->nOldHit
= nHit
;
5992 static inline LRESULT
5993 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5995 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5996 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
5998 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6002 static inline LRESULT
6003 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6005 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
6006 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
6008 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
6013 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
6015 TOOLBAR_INFO
*infoPtr
;
6018 /* allocate memory for info structure */
6019 infoPtr
= Alloc (sizeof(TOOLBAR_INFO
));
6020 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
6023 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
6026 /* initialize info structure */
6027 infoPtr
->nButtonWidth
= 23;
6028 infoPtr
->nButtonHeight
= 22;
6029 infoPtr
->nBitmapHeight
= 16;
6030 infoPtr
->nBitmapWidth
= 16;
6032 infoPtr
->nMaxTextRows
= 1;
6033 infoPtr
->cxMin
= -1;
6034 infoPtr
->cxMax
= -1;
6035 infoPtr
->nNumBitmaps
= 0;
6036 infoPtr
->nNumStrings
= 0;
6038 infoPtr
->bCaptured
= FALSE
;
6039 infoPtr
->nButtonDown
= -1;
6040 infoPtr
->nButtonDrag
= -1;
6041 infoPtr
->nOldHit
= -1;
6042 infoPtr
->nHotItem
= -1;
6043 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
6044 infoPtr
->dwDTFlags
= (lpcs
->style
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
6045 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
6046 infoPtr
->bDragOutSent
= FALSE
;
6047 infoPtr
->iVersion
= 0;
6048 infoPtr
->hwndSelf
= hwnd
;
6049 infoPtr
->bDoRedraw
= TRUE
;
6050 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
6051 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
6052 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
6053 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
6054 infoPtr
->iListGap
= DEFLISTGAP
;
6055 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
6056 infoPtr
->dwStyle
= lpcs
->style
;
6057 infoPtr
->tbim
.iButton
= -1;
6059 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6060 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
6061 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
6062 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
6065 /* I think the code below is a bug, but it is the way that the native
6066 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6067 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6068 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6069 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6070 * Somehow, the only cases of this seem to be MFC programs.
6072 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6073 * does not occur in the WM_STYLECHANGING routine.
6074 * (Guy Albertelli 9/2001)
6077 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6078 && !(lpcs
->style
& TBSTYLE_TRANSPARENT
))
6079 styleadd
|= TBSTYLE_TRANSPARENT
;
6080 if (!(lpcs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
6081 styleadd
|= CCS_TOP
; /* default to top */
6082 SetWindowLongW (hwnd
, GWL_STYLE
, lpcs
->style
| styleadd
);
6085 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
6090 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6092 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
6096 if (dwStyle
& WS_MINIMIZE
)
6097 return 0; /* Nothing to do */
6099 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
6101 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
6104 if (!(dwStyle
& CCS_NODIVIDER
))
6106 GetWindowRect (hwnd
, &rcWindow
);
6107 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
6108 if( dwStyle
& WS_BORDER
)
6109 InflateRect (&rcWindow
, -1, -1);
6110 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6113 ReleaseDC( hwnd
, hdc
);
6119 /* handles requests from the tooltip control on what text to display */
6120 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6122 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6123 NMTTDISPINFOA nmtdi
;
6127 TRACE("button index = %d\n", index
);
6129 Free (infoPtr
->pszTooltipText
);
6130 infoPtr
->pszTooltipText
= NULL
;
6135 if (infoPtr
->bUnicode
)
6137 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6138 NMTBGETINFOTIPW tbgit
;
6140 wszBuffer
[0] = '\0';
6141 wszBuffer
[INFOTIPSIZE
] = '\0';
6143 tbgit
.pszText
= wszBuffer
;
6144 tbgit
.cchTextMax
= INFOTIPSIZE
;
6145 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6146 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6148 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6150 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6152 len
= tbgit
.pszText
? lstrlenW(tbgit
.pszText
) : 0;
6153 if (len
> ARRAY_SIZE(lpnmtdi
->szText
) - 1)
6155 /* need to allocate temporary buffer in infoPtr as there
6156 * isn't enough space in buffer passed to us by the
6157 * tooltip control */
6158 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6159 if (infoPtr
->pszTooltipText
)
6161 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6162 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6168 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6174 CHAR szBuffer
[INFOTIPSIZE
+1];
6175 NMTBGETINFOTIPA tbgit
;
6178 szBuffer
[INFOTIPSIZE
] = '\0';
6180 tbgit
.pszText
= szBuffer
;
6181 tbgit
.cchTextMax
= INFOTIPSIZE
;
6182 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6183 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6185 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6187 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6189 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6190 if (len
> ARRAY_SIZE(lpnmtdi
->szText
))
6192 /* need to allocate temporary buffer in infoPtr as there
6193 * isn't enough space in buffer passed to us by the
6194 * tooltip control */
6195 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6196 if (infoPtr
->pszTooltipText
)
6198 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6199 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6203 else if (tbgit
.pszText
&& tbgit
.pszText
[0])
6205 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, lpnmtdi
->lpszText
, ARRAY_SIZE(lpnmtdi
->szText
));
6210 /* if button has text, but it is not shown then automatically
6211 * use that text as tooltip */
6212 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6213 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6215 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6216 len
= pszText
? lstrlenW(pszText
) : 0;
6218 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6220 if (len
> ARRAY_SIZE(lpnmtdi
->szText
) - 1)
6222 /* need to allocate temporary buffer in infoPtr as there
6223 * isn't enough space in buffer passed to us by the
6224 * tooltip control */
6225 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6226 if (infoPtr
->pszTooltipText
)
6228 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6229 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6235 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6240 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6242 /* Last resort, forward TTN_GETDISPINFO to the app:
6244 - NFR_UNICODE gets TTN_GETDISPINFOW, and TTN_GETDISPINFOA if -W returned no text;
6245 - NFR_ANSI gets only TTN_GETDISPINFOA.
6247 if (infoPtr
->bUnicode
)
6249 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmtdi
->hdr
.idFrom
, (LPARAM
)lpnmtdi
);
6251 TRACE("TTN_GETDISPINFOW - got string %s\n", debugstr_w(lpnmtdi
->lpszText
));
6253 if (IS_INTRESOURCE(lpnmtdi
->lpszText
))
6256 if (lpnmtdi
->lpszText
&& *lpnmtdi
->lpszText
)
6260 nmtdi
.hdr
.hwndFrom
= lpnmtdi
->hdr
.hwndFrom
;
6261 nmtdi
.hdr
.idFrom
= lpnmtdi
->hdr
.idFrom
;
6262 nmtdi
.hdr
.code
= TTN_GETDISPINFOA
;
6263 nmtdi
.lpszText
= nmtdi
.szText
;
6264 nmtdi
.szText
[0] = 0;
6265 nmtdi
.hinst
= lpnmtdi
->hinst
;
6266 nmtdi
.uFlags
= lpnmtdi
->uFlags
;
6267 nmtdi
.lParam
= lpnmtdi
->lParam
;
6269 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmtdi
.hdr
.idFrom
, (LPARAM
)&nmtdi
);
6271 TRACE("TTN_GETDISPINFOA - got string %s\n", debugstr_a(nmtdi
.lpszText
));
6273 lpnmtdi
->hinst
= nmtdi
.hinst
;
6274 lpnmtdi
->uFlags
= nmtdi
.uFlags
;
6275 lpnmtdi
->lParam
= nmtdi
.lParam
;
6277 if (IS_INTRESOURCE(nmtdi
.lpszText
))
6279 lpnmtdi
->lpszText
= (WCHAR
*)nmtdi
.lpszText
;
6283 if (!nmtdi
.lpszText
|| !*nmtdi
.lpszText
)
6286 len
= MultiByteToWideChar(CP_ACP
, 0, nmtdi
.lpszText
, -1, NULL
, 0);
6287 if (len
> ARRAY_SIZE(lpnmtdi
->szText
))
6289 infoPtr
->pszTooltipText
= Alloc(len
* sizeof(WCHAR
));
6290 if (infoPtr
->pszTooltipText
)
6292 MultiByteToWideChar(CP_ACP
, 0, nmtdi
.lpszText
, -1, infoPtr
->pszTooltipText
, len
);
6293 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6299 MultiByteToWideChar(CP_ACP
, 0, nmtdi
.lpszText
, -1, lpnmtdi
->lpszText
, ARRAY_SIZE(nmtdi
.szText
));
6307 static inline LRESULT
6308 TOOLBAR_Notify (TOOLBAR_INFO
*infoPtr
, LPNMHDR lpnmh
)
6310 switch (lpnmh
->code
)
6314 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lpnmh
;
6316 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6317 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6318 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6322 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6323 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6331 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lpnmh
;
6333 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6334 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6335 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6336 lppgs
->iScroll
, lppgs
->iDir
);
6340 case TTN_GETDISPINFOW
:
6341 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lpnmh
);
6343 case TTN_GETDISPINFOA
:
6344 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6354 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6358 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam
, lParam
);
6360 if (lParam
== NF_QUERY
)
6363 if (lParam
== NF_REQUERY
) {
6364 format
= SendMessageW(infoPtr
->hwndNotify
,
6365 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6366 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6367 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6378 TOOLBAR_Paint (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6383 /* fill ps.rcPaint with a default rect */
6384 ps
.rcPaint
= infoPtr
->rcBound
;
6386 hdc
= wParam
==0 ? BeginPaint(infoPtr
->hwndSelf
, &ps
) : (HDC
)wParam
;
6388 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps
.rcPaint
));
6390 TOOLBAR_Refresh (infoPtr
, hdc
, &ps
);
6391 if (!wParam
) EndPaint (infoPtr
->hwndSelf
, &ps
);
6398 TOOLBAR_SetFocus (TOOLBAR_INFO
*infoPtr
)
6400 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6402 /* make first item hot */
6403 if (infoPtr
->nNumButtons
> 0)
6404 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6410 TOOLBAR_SetFont(TOOLBAR_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
6412 TRACE("font=%p redraw=%d\n", hFont
, Redraw
);
6415 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6417 infoPtr
->hFont
= hFont
;
6419 TOOLBAR_CalcToolbar(infoPtr
);
6422 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6427 TOOLBAR_SetRedraw (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6428 /*****************************************************
6431 * Handles the WM_SETREDRAW message.
6434 * According to testing V4.71 of COMCTL32 returns the
6435 * *previous* status of the redraw flag (either 0 or 1)
6436 * instead of the MSDN documented value of 0 if handled.
6437 * (For laughs see the "consistency" with same function
6440 *****************************************************/
6442 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6444 TRACE("set to %s\n",
6445 (wParam
) ? "TRUE" : "FALSE");
6446 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6448 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6450 return (oldredraw
) ? 1 : 0;
6455 TOOLBAR_Size (TOOLBAR_INFO
*infoPtr
)
6457 TRACE("sizing toolbar\n");
6459 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6461 RECT delta_width
, delta_height
, client
, dummy
;
6462 DWORD min_x
, max_x
, min_y
, max_y
;
6463 TBUTTON_INFO
*btnPtr
;
6466 GetClientRect(infoPtr
->hwndSelf
, &client
);
6467 if(client
.right
> infoPtr
->client_rect
.right
)
6469 min_x
= infoPtr
->client_rect
.right
;
6470 max_x
= client
.right
;
6474 max_x
= infoPtr
->client_rect
.right
;
6475 min_x
= client
.right
;
6477 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6479 min_y
= infoPtr
->client_rect
.bottom
;
6480 max_y
= client
.bottom
;
6484 max_y
= infoPtr
->client_rect
.bottom
;
6485 min_y
= client
.bottom
;
6488 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6489 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6491 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6492 btnPtr
= infoPtr
->buttons
;
6493 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6494 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6495 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6496 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6498 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->client_rect
);
6499 TOOLBAR_AutoSize(infoPtr
);
6505 TOOLBAR_StyleChanged (TOOLBAR_INFO
*infoPtr
, INT nType
, const STYLESTRUCT
*lpStyle
)
6507 if (nType
== GWL_STYLE
)
6508 return TOOLBAR_SetStyle(infoPtr
, lpStyle
->styleNew
);
6515 TOOLBAR_SysColorChange (void)
6517 COMCTL32_RefreshSysColors();
6523 /* update theme after a WM_THEMECHANGED message */
6524 static LRESULT
theme_changed (HWND hwnd
)
6526 HTHEME theme
= GetWindowTheme (hwnd
);
6527 CloseThemeData (theme
);
6528 OpenThemeData (hwnd
, themeClass
);
6533 static LRESULT WINAPI
6534 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6536 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
6538 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6539 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6541 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6542 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6547 return TOOLBAR_AddBitmap (infoPtr
, (INT
)wParam
, (TBADDBITMAP
*)lParam
);
6549 case TB_ADDBUTTONSA
:
6550 case TB_ADDBUTTONSW
:
6551 return TOOLBAR_AddButtonsT (infoPtr
, wParam
, (LPTBBUTTON
)lParam
,
6552 uMsg
== TB_ADDBUTTONSW
);
6554 return TOOLBAR_AddStringA (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6557 return TOOLBAR_AddStringW (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6560 return TOOLBAR_AutoSize (infoPtr
);
6562 case TB_BUTTONCOUNT
:
6563 return TOOLBAR_ButtonCount (infoPtr
);
6565 case TB_BUTTONSTRUCTSIZE
:
6566 return TOOLBAR_ButtonStructSize (infoPtr
, wParam
);
6568 case TB_CHANGEBITMAP
:
6569 return TOOLBAR_ChangeBitmap (infoPtr
, wParam
, LOWORD(lParam
));
6571 case TB_CHECKBUTTON
:
6572 return TOOLBAR_CheckButton (infoPtr
, wParam
, lParam
);
6574 case TB_COMMANDTOINDEX
:
6575 return TOOLBAR_CommandToIndex (infoPtr
, wParam
);
6578 return TOOLBAR_Customize (infoPtr
);
6580 case TB_DELETEBUTTON
:
6581 return TOOLBAR_DeleteButton (infoPtr
, wParam
);
6583 case TB_ENABLEBUTTON
:
6584 return TOOLBAR_EnableButton (infoPtr
, wParam
, lParam
);
6586 case TB_GETANCHORHIGHLIGHT
:
6587 return TOOLBAR_GetAnchorHighlight (infoPtr
);
6590 return TOOLBAR_GetBitmap (infoPtr
, wParam
);
6592 case TB_GETBITMAPFLAGS
:
6593 return TOOLBAR_GetBitmapFlags ();
6596 return TOOLBAR_GetButton (infoPtr
, wParam
, (TBBUTTON
*)lParam
);
6598 case TB_GETBUTTONINFOA
:
6599 case TB_GETBUTTONINFOW
:
6600 return TOOLBAR_GetButtonInfoT (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6601 uMsg
== TB_GETBUTTONINFOW
);
6602 case TB_GETBUTTONSIZE
:
6603 return TOOLBAR_GetButtonSize (infoPtr
);
6605 case TB_GETBUTTONTEXTA
:
6606 case TB_GETBUTTONTEXTW
:
6607 return TOOLBAR_GetButtonText (infoPtr
, wParam
, (LPWSTR
)lParam
,
6608 uMsg
== TB_GETBUTTONTEXTW
);
6610 case TB_GETDISABLEDIMAGELIST
:
6611 return TOOLBAR_GetDisabledImageList (infoPtr
, wParam
);
6613 case TB_GETEXTENDEDSTYLE
:
6614 return TOOLBAR_GetExtendedStyle (infoPtr
);
6616 case TB_GETHOTIMAGELIST
:
6617 return TOOLBAR_GetHotImageList (infoPtr
, wParam
);
6620 return TOOLBAR_GetHotItem (infoPtr
);
6622 case TB_GETIMAGELIST
:
6623 return TOOLBAR_GetDefImageList (infoPtr
, wParam
);
6625 case TB_GETINSERTMARK
:
6626 return TOOLBAR_GetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6628 case TB_GETINSERTMARKCOLOR
:
6629 return TOOLBAR_GetInsertMarkColor (infoPtr
);
6631 case TB_GETITEMRECT
:
6632 return TOOLBAR_GetItemRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6635 return TOOLBAR_GetMaxSize (infoPtr
, (LPSIZE
)lParam
);
6637 /* case TB_GETOBJECT: */ /* 4.71 */
6640 return TOOLBAR_GetPadding (infoPtr
);
6643 return TOOLBAR_GetRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6646 return TOOLBAR_GetRows (infoPtr
);
6649 return TOOLBAR_GetState (infoPtr
, wParam
);
6652 return TOOLBAR_GetStringA (infoPtr
, wParam
, (LPSTR
)lParam
);
6655 return TOOLBAR_GetStringW (infoPtr
, wParam
, (LPWSTR
)lParam
);
6658 return TOOLBAR_GetStyle (infoPtr
);
6660 case TB_GETTEXTROWS
:
6661 return TOOLBAR_GetTextRows (infoPtr
);
6663 case TB_GETTOOLTIPS
:
6664 return TOOLBAR_GetToolTips (infoPtr
);
6666 case TB_GETUNICODEFORMAT
:
6667 return TOOLBAR_GetUnicodeFormat (infoPtr
);
6670 return TOOLBAR_HideButton (infoPtr
, wParam
, LOWORD(lParam
));
6673 return TOOLBAR_HitTest (infoPtr
, (LPPOINT
)lParam
);
6675 case TB_INDETERMINATE
:
6676 return TOOLBAR_Indeterminate (infoPtr
, wParam
, LOWORD(lParam
));
6678 case TB_INSERTBUTTONA
:
6679 case TB_INSERTBUTTONW
:
6680 return TOOLBAR_InsertButtonT(infoPtr
, wParam
, (TBBUTTON
*)lParam
,
6681 uMsg
== TB_INSERTBUTTONW
);
6683 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6685 case TB_ISBUTTONCHECKED
:
6686 return TOOLBAR_IsButtonChecked (infoPtr
, wParam
);
6688 case TB_ISBUTTONENABLED
:
6689 return TOOLBAR_IsButtonEnabled (infoPtr
, wParam
);
6691 case TB_ISBUTTONHIDDEN
:
6692 return TOOLBAR_IsButtonHidden (infoPtr
, wParam
);
6694 case TB_ISBUTTONHIGHLIGHTED
:
6695 return TOOLBAR_IsButtonHighlighted (infoPtr
, wParam
);
6697 case TB_ISBUTTONINDETERMINATE
:
6698 return TOOLBAR_IsButtonIndeterminate (infoPtr
, wParam
);
6700 case TB_ISBUTTONPRESSED
:
6701 return TOOLBAR_IsButtonPressed (infoPtr
, wParam
);
6704 return TOOLBAR_LoadImages (infoPtr
, wParam
, (HINSTANCE
)lParam
);
6706 case TB_MAPACCELERATORA
:
6707 case TB_MAPACCELERATORW
:
6708 return TOOLBAR_MapAccelerator (infoPtr
, wParam
, (UINT
*)lParam
);
6711 return TOOLBAR_MarkButton (infoPtr
, wParam
, LOWORD(lParam
));
6714 return TOOLBAR_MoveButton (infoPtr
, wParam
, lParam
);
6716 case TB_PRESSBUTTON
:
6717 return TOOLBAR_PressButton (infoPtr
, wParam
, LOWORD(lParam
));
6719 case TB_REPLACEBITMAP
:
6720 return TOOLBAR_ReplaceBitmap (infoPtr
, (LPTBREPLACEBITMAP
)lParam
);
6722 case TB_SAVERESTOREA
:
6723 return TOOLBAR_SaveRestoreA (infoPtr
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6725 case TB_SAVERESTOREW
:
6726 return TOOLBAR_SaveRestoreW (infoPtr
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6728 case TB_SETANCHORHIGHLIGHT
:
6729 return TOOLBAR_SetAnchorHighlight (infoPtr
, (BOOL
)wParam
);
6731 case TB_SETBITMAPSIZE
:
6732 return TOOLBAR_SetBitmapSize (infoPtr
, wParam
, lParam
);
6734 case TB_SETBUTTONINFOA
:
6735 case TB_SETBUTTONINFOW
:
6736 return TOOLBAR_SetButtonInfo (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6737 uMsg
== TB_SETBUTTONINFOW
);
6738 case TB_SETBUTTONSIZE
:
6739 return TOOLBAR_SetButtonSize (infoPtr
, lParam
);
6741 case TB_SETBUTTONWIDTH
:
6742 return TOOLBAR_SetButtonWidth (infoPtr
, lParam
);
6745 return TOOLBAR_SetCmdId (infoPtr
, wParam
, lParam
);
6747 case TB_SETDISABLEDIMAGELIST
:
6748 return TOOLBAR_SetDisabledImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6750 case TB_SETDRAWTEXTFLAGS
:
6751 return TOOLBAR_SetDrawTextFlags (infoPtr
, wParam
, lParam
);
6753 case TB_SETEXTENDEDSTYLE
:
6754 return TOOLBAR_SetExtendedStyle (infoPtr
, wParam
, lParam
);
6756 case TB_SETHOTIMAGELIST
:
6757 return TOOLBAR_SetHotImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6760 return TOOLBAR_SetHotItem (infoPtr
, wParam
);
6762 case TB_SETIMAGELIST
:
6763 return TOOLBAR_SetImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6766 return TOOLBAR_SetIndent (infoPtr
, wParam
);
6768 case TB_SETINSERTMARK
:
6769 return TOOLBAR_SetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6771 case TB_SETINSERTMARKCOLOR
:
6772 return TOOLBAR_SetInsertMarkColor (infoPtr
, lParam
);
6774 case TB_SETMAXTEXTROWS
:
6775 return TOOLBAR_SetMaxTextRows (infoPtr
, wParam
);
6778 return TOOLBAR_SetPadding (infoPtr
, lParam
);
6781 return TOOLBAR_SetParent (infoPtr
, (HWND
)wParam
);
6784 return TOOLBAR_SetRows (infoPtr
, wParam
, (LPRECT
)lParam
);
6787 return TOOLBAR_SetState (infoPtr
, wParam
, lParam
);
6790 return TOOLBAR_SetStyle (infoPtr
, lParam
);
6792 case TB_SETTOOLTIPS
:
6793 return TOOLBAR_SetToolTips (infoPtr
, (HWND
)wParam
);
6795 case TB_SETUNICODEFORMAT
:
6796 return TOOLBAR_SetUnicodeFormat (infoPtr
, wParam
);
6798 case TB_SETBOUNDINGSIZE
:
6799 return TOOLBAR_SetBoundingSize(hwnd
, wParam
, lParam
);
6801 case TB_SETHOTITEM2
:
6802 return TOOLBAR_SetHotItem2 (infoPtr
, wParam
, lParam
);
6805 return TOOLBAR_SetListGap(infoPtr
, wParam
);
6807 case TB_GETIMAGELISTCOUNT
:
6808 return TOOLBAR_GetImageListCount(infoPtr
);
6810 case TB_GETIDEALSIZE
:
6811 return TOOLBAR_GetIdealSize (infoPtr
, wParam
, lParam
);
6814 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6816 /* Common Control Messages */
6818 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6819 case CCM_GETCOLORSCHEME
:
6820 return TOOLBAR_GetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6822 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6823 case CCM_SETCOLORSCHEME
:
6824 return TOOLBAR_SetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6826 case CCM_GETVERSION
:
6827 return TOOLBAR_GetVersion (infoPtr
);
6829 case CCM_SETVERSION
:
6830 return TOOLBAR_SetVersion (infoPtr
, (INT
)wParam
);
6836 return TOOLBAR_Create (hwnd
, (CREATESTRUCTW
*)lParam
);
6839 return TOOLBAR_Destroy (infoPtr
);
6842 return TOOLBAR_EraseBackground (infoPtr
, wParam
, lParam
);
6845 return TOOLBAR_GetFont (infoPtr
);
6848 return TOOLBAR_KeyDown (infoPtr
, wParam
, lParam
);
6850 /* case WM_KILLFOCUS: */
6852 case WM_LBUTTONDBLCLK
:
6853 return TOOLBAR_LButtonDblClk (infoPtr
, wParam
, lParam
);
6855 case WM_LBUTTONDOWN
:
6856 return TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
6859 return TOOLBAR_LButtonUp (infoPtr
, wParam
, lParam
);
6862 return TOOLBAR_RButtonUp (infoPtr
, wParam
, lParam
);
6864 case WM_RBUTTONDBLCLK
:
6865 return TOOLBAR_RButtonDblClk (infoPtr
, wParam
, lParam
);
6868 return TOOLBAR_MouseMove (infoPtr
, wParam
, lParam
);
6871 return TOOLBAR_MouseLeave (infoPtr
);
6873 case WM_CAPTURECHANGED
:
6874 if (hwnd
== (HWND
)lParam
) return 0;
6875 return TOOLBAR_CaptureChanged(infoPtr
);
6878 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6881 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6884 return TOOLBAR_NCCreate (hwnd
, wParam
, (CREATESTRUCTW
*)lParam
);
6887 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
6890 return TOOLBAR_Notify (infoPtr
, (LPNMHDR
)lParam
);
6892 case WM_NOTIFYFORMAT
:
6893 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
6895 case WM_PRINTCLIENT
:
6897 return TOOLBAR_Paint (infoPtr
, wParam
);
6900 return TOOLBAR_SetFocus (infoPtr
);
6903 return TOOLBAR_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
6906 return TOOLBAR_SetRedraw (infoPtr
, wParam
);
6909 return TOOLBAR_Size (infoPtr
);
6911 case WM_STYLECHANGED
:
6912 return TOOLBAR_StyleChanged (infoPtr
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
6914 case WM_SYSCOLORCHANGE
:
6915 return TOOLBAR_SysColorChange ();
6917 case WM_THEMECHANGED
:
6918 return theme_changed (hwnd
);
6920 /* case WM_WININICHANGE: */
6925 case WM_MEASUREITEM
:
6927 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
6929 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6930 case PGM_FORWARDMOUSE
:
6931 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6934 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
6935 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
6936 uMsg
, wParam
, lParam
);
6937 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6943 TOOLBAR_Register (void)
6947 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
6948 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
6949 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
6950 wndClass
.cbClsExtra
= 0;
6951 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
6952 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
6953 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
6954 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
6956 RegisterClassW (&wndClass
);
6961 TOOLBAR_Unregister (void)
6963 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
6966 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
6971 /* Check if the entry already exists */
6972 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
6974 /* Don't add new entry for NULL imagelist */
6978 /* If this is a new entry we must create it and insert into the array */
6983 c
= Alloc(sizeof(IMLENTRY
));
6986 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
6987 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
7002 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
7006 for (i
= 0; i
< *cies
; i
++)
7016 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
7024 for (i
= 0; i
< cies
; i
++)
7026 if (pies
[i
]->id
== id
)
7038 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
7040 HIMAGELIST himlDef
= 0;
7041 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
7044 himlDef
= pie
->himl
;
7050 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
7052 if (infoPtr
->bUnicode
)
7053 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
7060 nmtba
.iItem
= nmtb
->iItem
;
7061 nmtba
.pszText
= Buffer
;
7062 nmtba
.cchText
= 256;
7063 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
7065 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
7067 int ccht
= strlen(nmtba
.pszText
);
7069 MultiByteToWideChar(CP_ACP
, 0, nmtba
.pszText
, -1,
7070 nmtb
->pszText
, nmtb
->cchText
);
7072 nmtb
->tbButton
= nmtba
.tbButton
;
7081 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
)
7085 /* MSDN states that iItem is the index of the button, rather than the
7086 * command ID as used by every other NMTOOLBAR notification */
7088 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
7090 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);