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)
79 #include "wine/unicode.h"
85 #include "wine/debug.h"
87 WINE_DEFAULT_DEBUG_CHANNEL(toolbar
);
89 static HCURSOR hCursorDrag
= NULL
;
98 BOOL bDropDownPressed
;
103 INT cx
; /* manually set size */
117 } IMLENTRY
, *PIMLENTRY
;
121 DWORD dwStructSize
; /* size of TBBUTTON struct */
123 RECT rcBound
; /* bounding rectangle */
129 INT nRows
; /* number of button rows */
130 INT nMaxTextRows
; /* maximum number of text rows */
131 INT cxMin
; /* minimum button width */
132 INT cxMax
; /* maximum button width */
133 INT nNumButtons
; /* number of buttons */
134 INT nNumBitmaps
; /* number of bitmaps */
135 INT nNumStrings
; /* number of strings */
137 INT nButtonDown
; /* toolbar button being pressed or -1 if none */
138 INT nButtonDrag
; /* toolbar button being dragged or -1 if none */
140 INT nHotItem
; /* index of the "hot" item */
141 SIZE szPadding
; /* padding values around button */
142 INT iTopMargin
; /* the top margin */
143 INT iListGap
; /* default gap between text and image for toolbar with list style */
145 HFONT hFont
; /* text font */
146 HIMAGELIST himlInt
; /* image list created internally */
147 PIMLENTRY
*himlDef
; /* default image list array */
148 INT cimlDef
; /* default image list array count */
149 PIMLENTRY
*himlHot
; /* hot image list array */
150 INT cimlHot
; /* hot image list array count */
151 PIMLENTRY
*himlDis
; /* disabled image list array */
152 INT cimlDis
; /* disabled image list array count */
153 HWND hwndToolTip
; /* handle to tool tip control */
154 HWND hwndNotify
; /* handle to the window that gets notifications */
155 HWND hwndSelf
; /* my own handle */
156 BOOL bAnchor
; /* anchor highlight enabled */
157 BOOL bDoRedraw
; /* Redraw status */
158 BOOL bDragOutSent
; /* has TBN_DRAGOUT notification been sent for this drag? */
159 BOOL bUnicode
; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
160 BOOL bCaptured
; /* mouse captured? */
161 DWORD dwStyle
; /* regular toolbar style */
162 DWORD dwExStyle
; /* extended toolbar style */
163 DWORD dwDTFlags
; /* DrawText flags */
165 COLORREF clrInsertMark
; /* insert mark color */
166 COLORREF clrBtnHighlight
; /* color for Flat Separator */
167 COLORREF clrBtnShadow
; /* color for Flag Separator */
169 LPWSTR pszTooltipText
; /* temporary store for a string > 80 characters
170 * for TTN_GETDISPINFOW notification */
171 TBINSERTMARK tbim
; /* info on insertion mark */
172 TBUTTON_INFO
*buttons
; /* pointer to button array */
173 LPWSTR
*strings
; /* pointer to string array */
174 TBITMAP_INFO
*bitmaps
;
175 } TOOLBAR_INFO
, *PTOOLBAR_INFO
;
178 /* used by customization dialog */
181 PTOOLBAR_INFO tbInfo
;
183 } CUSTDLG_INFO
, *PCUSTDLG_INFO
;
191 } CUSTOMBUTTON
, *PCUSTOMBUTTON
;
200 #define SEPARATOR_WIDTH 8
202 #define BOTTOM_BORDER 2
203 #define DDARROW_WIDTH 11
204 #define ARROW_HEIGHT 3
205 #define INSERTMARK_WIDTH 2
211 /* vertical padding used in list mode when image is present */
214 /* how wide to treat the bitmap if it isn't present */
215 #define NONLIST_NOTEXT_OFFSET 2
217 #define TOOLBAR_NOWHERE (-1)
219 /* Used to find undocumented extended styles */
220 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
221 TBSTYLE_EX_VERTICAL | \
222 TBSTYLE_EX_MIXEDBUTTONS | \
223 TBSTYLE_EX_DOUBLEBUFFER | \
224 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
226 /* all of the CCS_ styles */
227 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
228 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
230 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
231 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
232 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
233 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
234 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
236 static const WCHAR themeClass
[] = { 'T','o','o','l','b','a','r',0 };
238 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
);
239 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
);
240 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
);
241 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
);
242 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
);
243 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
);
244 static LRESULT
TOOLBAR_LButtonDown(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
);
245 static void TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
);
246 static LRESULT
TOOLBAR_AutoSize(TOOLBAR_INFO
*infoPtr
);
247 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
);
248 static void TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
249 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
250 static LRESULT
TOOLBAR_SetButtonInfo(TOOLBAR_INFO
*infoPtr
, INT Id
,
251 const TBBUTTONINFOW
*lptbbi
, BOOL isW
);
254 static inline int default_top_margin(const TOOLBAR_INFO
*infoPtr
)
256 return (infoPtr
->dwStyle
& TBSTYLE_FLAT
? 0 : TOP_BORDER
);
259 static inline BOOL
TOOLBAR_HasDropDownArrows(DWORD exStyle
)
261 return (exStyle
& TBSTYLE_EX_DRAWDDARROWS
) != 0;
264 static inline BOOL
button_has_ddarrow(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
266 return (TOOLBAR_HasDropDownArrows( infoPtr
->dwExStyle
) && (btnPtr
->fsStyle
& BTNS_DROPDOWN
)) ||
267 (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
271 TOOLBAR_GetText(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
273 LPWSTR lpText
= NULL
;
275 /* NOTE: iString == -1 is undocumented */
276 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1))
277 lpText
= (LPWSTR
)btnPtr
->iString
;
278 else if ((btnPtr
->iString
>= 0) && (btnPtr
->iString
< infoPtr
->nNumStrings
))
279 lpText
= infoPtr
->strings
[btnPtr
->iString
];
285 TOOLBAR_DumpTBButton(const TBBUTTON
*tbb
, BOOL fUnicode
)
287 TRACE("TBBUTTON: id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx (%s)\n",
288 tbb
->idCommand
,tbb
->iBitmap
, tbb
->fsState
, tbb
->fsStyle
, tbb
->dwData
, tbb
->iString
,
289 (fUnicode
? wine_dbgstr_w((LPWSTR
)tbb
->iString
) : wine_dbgstr_a((LPSTR
)tbb
->iString
)));
293 TOOLBAR_DumpButton(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*bP
, INT btn_num
)
295 if (TRACE_ON(toolbar
)){
296 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
297 btn_num
, bP
->idCommand
, GETIBITMAP(infoPtr
, bP
->iBitmap
),
298 bP
->fsState
, bP
->fsStyle
, bP
->dwData
, bP
->iString
);
299 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr
,bP
)));
300 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n",
301 btn_num
, bP
->idCommand
, (bP
->bHot
) ? "TRUE":"FALSE", bP
->nRow
,
302 wine_dbgstr_rect(&bP
->rect
));
308 TOOLBAR_DumpToolbar(const TOOLBAR_INFO
*iP
, INT line
)
310 if (TRACE_ON(toolbar
)) {
313 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
315 iP
->dwExStyle
, iP
->nNumButtons
, iP
->nNumBitmaps
,
316 iP
->nNumStrings
, iP
->dwStyle
);
317 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
319 iP
->himlInt
, iP
->himlDef
, iP
->himlHot
, iP
->himlDis
,
320 (iP
->bDoRedraw
) ? "TRUE" : "FALSE");
321 for(i
=0; i
<iP
->nNumButtons
; i
++) {
322 TOOLBAR_DumpButton(iP
, &iP
->buttons
[i
], i
);
328 TOOLBAR_ButtonHasString(const TBUTTON_INFO
*btnPtr
)
330 return HIWORD(btnPtr
->iString
) && btnPtr
->iString
!= -1;
333 static void set_string_index( TBUTTON_INFO
*btn
, INT_PTR str
, BOOL unicode
)
335 if (!IS_INTRESOURCE( str
) && str
!= -1)
337 if (!TOOLBAR_ButtonHasString( btn
)) btn
->iString
= 0;
340 Str_SetPtrW( (WCHAR
**)&btn
->iString
, (WCHAR
*)str
);
342 Str_SetPtrAtoW( (WCHAR
**)&btn
->iString
, (char *)str
);
346 if (TOOLBAR_ButtonHasString( btn
)) Free( (WCHAR
*)btn
->iString
);
352 static void set_stringT( TBUTTON_INFO
*btn
, const WCHAR
*str
, BOOL unicode
)
354 if (IS_INTRESOURCE( (DWORD_PTR
)str
) || (DWORD_PTR
)str
== -1) return;
355 set_string_index( btn
, (DWORD_PTR
)str
, unicode
);
358 static void free_string( TBUTTON_INFO
*btn
)
360 set_string_index( btn
, 0, TRUE
);
364 /***********************************************************************
367 * This function validates that the styles set are implemented and
368 * issues FIXMEs warning of possible problems. In a perfect world this
369 * function should be null.
372 TOOLBAR_CheckStyle (const TOOLBAR_INFO
*infoPtr
)
374 if (infoPtr
->dwStyle
& TBSTYLE_REGISTERDROP
)
375 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", infoPtr
->hwndSelf
);
380 TOOLBAR_SendNotify (NMHDR
*nmhdr
, const TOOLBAR_INFO
*infoPtr
, UINT code
)
382 if(!IsWindow(infoPtr
->hwndSelf
))
383 return 0; /* we have just been destroyed */
385 nmhdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
386 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
389 TRACE("to window %p, code=%08x, %s\n", infoPtr
->hwndNotify
, code
,
390 (infoPtr
->bUnicode
) ? "via Unicode" : "via ANSI");
392 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhdr
->idFrom
, (LPARAM
)nmhdr
);
395 /***********************************************************************
396 * TOOLBAR_GetBitmapIndex
398 * This function returns the bitmap index associated with a button.
399 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
400 * is issued to retrieve the index.
403 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
405 INT ret
= btnPtr
->iBitmap
;
407 if (ret
== I_IMAGECALLBACK
)
409 /* issue TBN_GETDISPINFO */
412 memset(&nmgd
, 0, sizeof(nmgd
));
413 nmgd
.idCommand
= btnPtr
->idCommand
;
414 nmgd
.lParam
= btnPtr
->dwData
;
415 nmgd
.dwMask
= TBNF_IMAGE
;
417 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
418 TOOLBAR_SendNotify(&nmgd
.hdr
, infoPtr
, TBN_GETDISPINFOW
);
419 if (nmgd
.dwMask
& TBNF_DI_SETITEM
)
420 btnPtr
->iBitmap
= nmgd
.iImage
;
422 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
423 ret
, nmgd
.dwMask
, infoPtr
->nNumBitmaps
);
426 if (ret
!= I_IMAGENONE
)
427 ret
= GETIBITMAP(infoPtr
, ret
);
434 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO
*infoPtr
, INT index
)
437 INT id
= GETHIMLID(infoPtr
, index
);
438 INT iBitmap
= GETIBITMAP(infoPtr
, index
);
440 if (((himl
= GETDEFIMAGELIST(infoPtr
, id
)) &&
441 iBitmap
>= 0 && iBitmap
< ImageList_GetImageCount(himl
)) ||
442 (index
== I_IMAGECALLBACK
))
450 TOOLBAR_IsValidImageList(const TOOLBAR_INFO
*infoPtr
, INT index
)
452 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, index
));
453 return (himl
!= NULL
) && (ImageList_GetImageCount(himl
) > 0);
457 /***********************************************************************
458 * TOOLBAR_GetImageListForDrawing
460 * This function validates the bitmap index (including I_IMAGECALLBACK
461 * functionality) and returns the corresponding image list.
464 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
,
465 IMAGE_LIST_TYPE imagelist
, INT
* index
)
469 if (!TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
)) {
470 if (btnPtr
->iBitmap
== I_IMAGENONE
) return NULL
;
471 WARN("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
472 HIWORD(btnPtr
->iBitmap
), LOWORD(btnPtr
->iBitmap
), infoPtr
->nNumBitmaps
);
476 if ((*index
= TOOLBAR_GetBitmapIndex(infoPtr
, btnPtr
)) < 0) {
477 if ((*index
== I_IMAGECALLBACK
) ||
478 (*index
== I_IMAGENONE
)) return NULL
;
479 ERR("TBN_GETDISPINFO returned invalid index %d\n",
486 case IMAGE_LIST_DEFAULT
:
487 himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
490 himl
= GETHOTIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
492 case IMAGE_LIST_DISABLED
:
493 himl
= GETDISIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
497 FIXME("Shouldn't reach here\n");
501 TRACE("no image list\n");
508 TOOLBAR_DrawFlatSeparator (const RECT
*lpRect
, HDC hdc
, const TOOLBAR_INFO
*infoPtr
)
511 COLORREF oldcolor
, newcolor
;
513 myrect
.left
= (lpRect
->left
+ lpRect
->right
) / 2 - 1;
514 myrect
.right
= myrect
.left
+ 1;
515 myrect
.top
= lpRect
->top
+ 2;
516 myrect
.bottom
= lpRect
->bottom
- 2;
518 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
519 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
520 oldcolor
= SetBkColor (hdc
, newcolor
);
521 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
523 myrect
.left
= myrect
.right
;
524 myrect
.right
= myrect
.left
+ 1;
526 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
527 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
528 SetBkColor (hdc
, newcolor
);
529 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
531 SetBkColor (hdc
, oldcolor
);
535 /***********************************************************************
536 * TOOLBAR_DrawFlatHorizontalSeparator
538 * This function draws horizontal separator for toolbars having CCS_VERT style.
539 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
540 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
541 * are horizontal as opposed to the vertical separators for not dropdown
544 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
547 TOOLBAR_DrawFlatHorizontalSeparator (const RECT
*lpRect
, HDC hdc
,
548 const TOOLBAR_INFO
*infoPtr
)
551 COLORREF oldcolor
, newcolor
;
553 myrect
.left
= lpRect
->left
;
554 myrect
.right
= lpRect
->right
;
555 myrect
.top
= lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
- 2)/2;
556 myrect
.bottom
= myrect
.top
+ 1;
558 InflateRect (&myrect
, -2, 0);
560 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect
));
562 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
563 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
564 oldcolor
= SetBkColor (hdc
, newcolor
);
565 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
567 myrect
.top
= myrect
.bottom
;
568 myrect
.bottom
= myrect
.top
+ 1;
570 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
571 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
572 SetBkColor (hdc
, newcolor
);
573 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
575 SetBkColor (hdc
, oldcolor
);
580 TOOLBAR_DrawArrow (HDC hdc
, INT left
, INT top
, COLORREF clr
)
585 if (!(hPen
= CreatePen( PS_SOLID
, 1, clr
))) return;
586 hOldPen
= SelectObject ( hdc
, hPen
);
589 MoveToEx (hdc
, x
, y
, NULL
);
590 LineTo (hdc
, x
+5, y
++); x
++;
591 MoveToEx (hdc
, x
, y
, NULL
);
592 LineTo (hdc
, x
+3, y
++); x
++;
593 MoveToEx (hdc
, x
, y
, NULL
);
594 LineTo (hdc
, x
+1, y
);
595 SelectObject( hdc
, hOldPen
);
596 DeleteObject( hPen
);
600 * Draw the text string for this button.
601 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
602 * is non-zero, so we can simply check himlDef to see if we have
606 TOOLBAR_DrawString (const TOOLBAR_INFO
*infoPtr
, RECT
*rcText
, LPCWSTR lpText
,
607 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
609 HDC hdc
= tbcd
->nmcd
.hdc
;
612 COLORREF clrOldBk
= 0;
614 UINT state
= tbcd
->nmcd
.uItemState
;
617 if (lpText
&& infoPtr
->nMaxTextRows
> 0) {
618 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText
),
619 wine_dbgstr_rect(rcText
));
621 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
622 if ((state
& CDIS_HOT
) && (dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)) {
623 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
625 else if (state
& CDIS_DISABLED
) {
626 clrOld
= SetTextColor (hdc
, tbcd
->clrBtnHighlight
);
627 OffsetRect (rcText
, 1, 1);
628 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
629 SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
630 OffsetRect (rcText
, -1, -1);
632 else if (state
& CDIS_INDETERMINATE
) {
633 clrOld
= SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
635 else if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
)) {
636 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
637 clrOldBk
= SetBkColor (hdc
, tbcd
->clrMark
);
638 oldBkMode
= SetBkMode (hdc
, tbcd
->nHLStringBkMode
);
641 clrOld
= SetTextColor (hdc
, tbcd
->clrText
);
644 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
645 SetTextColor (hdc
, clrOld
);
646 if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
))
648 SetBkColor (hdc
, clrOldBk
);
649 SetBkMode (hdc
, oldBkMode
);
651 SelectObject (hdc
, hOldFont
);
657 TOOLBAR_DrawPattern (const RECT
*lpRect
, const NMTBCUSTOMDRAW
*tbcd
)
659 HDC hdc
= tbcd
->nmcd
.hdc
;
660 HBRUSH hbr
= SelectObject (hdc
, tbcd
->hbrMonoDither
);
663 INT cx
= lpRect
->right
- lpRect
->left
;
664 INT cy
= lpRect
->bottom
- lpRect
->top
;
665 INT cxEdge
= GetSystemMetrics(SM_CXEDGE
);
666 INT cyEdge
= GetSystemMetrics(SM_CYEDGE
);
667 clrTextOld
= SetTextColor(hdc
, tbcd
->clrBtnHighlight
);
668 clrBkOld
= SetBkColor(hdc
, tbcd
->clrBtnFace
);
669 PatBlt (hdc
, lpRect
->left
+ cxEdge
, lpRect
->top
+ cyEdge
,
670 cx
- (2 * cxEdge
), cy
- (2 * cyEdge
), PATCOPY
);
671 SetBkColor(hdc
, clrBkOld
);
672 SetTextColor(hdc
, clrTextOld
);
673 SelectObject (hdc
, hbr
);
677 static void TOOLBAR_DrawMasked(HIMAGELIST himl
, int index
, HDC hdc
, INT x
, INT y
, UINT draw_flags
)
680 HBITMAP hbmMask
, hbmImage
;
681 HDC hdcMask
, hdcImage
;
683 ImageList_GetIconSize(himl
, &cx
, &cy
);
685 /* Create src image */
686 hdcImage
= CreateCompatibleDC(hdc
);
687 hbmImage
= CreateCompatibleBitmap(hdc
, cx
, cy
);
688 SelectObject(hdcImage
, hbmImage
);
689 ImageList_DrawEx(himl
, index
, hdcImage
, 0, 0, cx
, cy
,
690 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags
);
693 hdcMask
= CreateCompatibleDC(0);
694 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
695 SelectObject(hdcMask
, hbmMask
);
697 /* Remove the background and all white pixels */
698 ImageList_DrawEx(himl
, index
, hdcMask
, 0, 0, cx
, cy
,
699 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK
);
700 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
701 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
703 /* draw the new mask 'etched' to hdc */
704 SetBkColor(hdc
, RGB(255, 255, 255));
705 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
706 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
707 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
708 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
709 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
712 DeleteObject(hbmImage
);
714 DeleteObject (hbmMask
);
720 TOOLBAR_TranslateState(const TBUTTON_INFO
*btnPtr
)
724 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
725 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
726 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
727 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
728 retstate
|= (btnPtr
->bHot
) ? CDIS_HOT
: 0;
729 retstate
|= ((btnPtr
->fsState
& (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) == (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) ? CDIS_INDETERMINATE
: 0;
730 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
734 /* draws the image on a toolbar button */
736 TOOLBAR_DrawImage(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
,
737 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
739 HIMAGELIST himl
= NULL
;
740 BOOL draw_masked
= FALSE
;
743 UINT draw_flags
= ILD_TRANSPARENT
;
745 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
747 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
750 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
754 else if (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
||
755 ((tbcd
->nmcd
.uItemState
& CDIS_HOT
)
756 && ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))))
758 /* if hot, attempt to draw with hot image list, if fails,
759 use default image list */
760 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
762 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
765 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
770 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
771 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
774 if (!(dwItemCDFlag
& TBCDRF_NOMARK
) &&
775 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
776 draw_flags
|= ILD_BLEND50
;
778 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
779 index
, himl
, left
, top
, offset
);
782 TOOLBAR_DrawMasked (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
784 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
787 /* draws a blank frame for a toolbar button */
789 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, const RECT
*rect
, DWORD dwItemCDFlag
)
791 HDC hdc
= tbcd
->nmcd
.hdc
;
793 /* if the state is disabled or indeterminate then the button
794 * cannot have an interactive look like pressed or hot */
795 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
796 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
797 BOOL pressed_look
= !non_interactive_state
&&
798 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
799 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
801 /* app don't want us to draw any edges */
802 if (dwItemCDFlag
& TBCDRF_NOEDGES
)
805 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
808 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
809 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
810 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
815 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
817 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
818 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
823 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
, BOOL bDropDownPressed
, DWORD dwItemCDFlag
)
825 HDC hdc
= tbcd
->nmcd
.hdc
;
827 BOOL pressed
= bDropDownPressed
||
828 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
));
830 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
833 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
);
834 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
835 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
836 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
837 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
842 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
844 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
845 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
849 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
851 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
853 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
854 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
857 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
860 /* draws a complete toolbar button */
862 TOOLBAR_DrawButton (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, HDC hdc
, DWORD dwBaseCustDraw
)
864 DWORD dwStyle
= infoPtr
->dwStyle
;
865 BOOL hasDropDownArrow
= button_has_ddarrow( infoPtr
, btnPtr
);
866 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
867 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
868 RECT rc
, rcArrow
, rcBitmap
, rcText
;
869 LPWSTR lpText
= NULL
;
874 DWORD dwItemCustDraw
;
876 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
879 CopyRect (&rcArrow
, &rc
);
881 /* separator - doesn't send NM_CUSTOMDRAW */
882 if (btnPtr
->fsStyle
& BTNS_SEP
) {
885 DrawThemeBackground (theme
, hdc
,
886 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
890 /* with the FLAT style, iBitmap is the width and has already */
891 /* been taken into consideration in calculating the width */
892 /* so now we need to draw the vertical separator */
893 /* empirical tests show that iBitmap can/will be non-zero */
894 /* when drawing the vertical bar... */
895 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
896 if (dwStyle
& CCS_VERT
) {
898 InflateRect(&rcsep
, -infoPtr
->szPadding
.cx
, -infoPtr
->szPadding
.cy
);
899 TOOLBAR_DrawFlatHorizontalSeparator (&rcsep
, hdc
, infoPtr
);
902 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
904 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
905 FIXME("Draw some kind of separator: fsStyle=%x\n",
911 /* get a pointer to the text */
912 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
914 if (hasDropDownArrow
)
918 if (dwStyle
& TBSTYLE_FLAT
)
919 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
921 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
923 if (drawSepDropDownArrow
)
926 rcArrow
.left
= right
;
929 /* copy text & bitmap rects after adjusting for drop-down arrow
930 * so that text & bitmap is centered in the rectangle not containing
932 CopyRect(&rcText
, &rc
);
933 CopyRect(&rcBitmap
, &rc
);
935 /* Center the bitmap horizontally and vertically */
936 if (dwStyle
& TBSTYLE_LIST
)
939 infoPtr
->nMaxTextRows
> 0 &&
940 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
941 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
942 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
944 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
947 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
949 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
951 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
952 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
953 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
954 TRACE("Text=%s\n", debugstr_w(lpText
));
955 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
957 /* calculate text position */
960 rcText
.left
+= GetSystemMetrics(SM_CXEDGE
);
961 rcText
.right
-= GetSystemMetrics(SM_CXEDGE
);
962 if (dwStyle
& TBSTYLE_LIST
)
964 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
968 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
969 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
971 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
975 /* Initialize fields in all cases, because we use these later
976 * NOTE: applications can and do alter these to customize their
978 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
979 tbcd
.clrText
= comctl32_color
.clrBtnText
;
980 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
981 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
982 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
983 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
984 tbcd
.clrHighlightHotTrack
= 0;
985 tbcd
.nStringBkMode
= TRANSPARENT
;
986 tbcd
.nHLStringBkMode
= OPAQUE
;
987 tbcd
.rcText
.left
= 0;
989 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
990 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
991 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
993 tbcd
.nmcd
.rc
= btnPtr
->rect
;
994 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
996 /* FIXME: what are these used for? */
1000 /* Issue Item Prepaint notify */
1003 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
1005 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
1006 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
1007 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
1008 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1009 /* reset these fields so the user can't alter the behaviour like native */
1010 tbcd
.nmcd
.hdc
= hdc
;
1011 tbcd
.nmcd
.rc
= btnPtr
->rect
;
1013 dwItemCustDraw
= ntfret
& 0xffff;
1014 dwItemCDFlag
= ntfret
& 0xffff0000;
1015 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
1017 /* save the only part of the rect that the user can change */
1018 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
1019 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
1022 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
1023 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
1024 OffsetRect(&rcText
, 1, 1);
1026 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
1027 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
1028 TOOLBAR_DrawPattern (&rc
, &tbcd
);
1030 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
1031 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
1033 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
1037 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
1038 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
1039 if (hasDropDownArrow
)
1040 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
1041 SetBkColor(hdc
, oldclr
);
1047 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
1048 int stateId
= TS_NORMAL
;
1050 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1051 stateId
= TS_DISABLED
;
1052 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1053 stateId
= TS_PRESSED
;
1054 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1055 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1056 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1057 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1060 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &rc
, NULL
);
1063 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, &rc
, dwItemCDFlag
);
1065 if (drawSepDropDownArrow
)
1069 int stateId
= TS_NORMAL
;
1071 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1072 stateId
= TS_DISABLED
;
1073 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1074 stateId
= TS_PRESSED
;
1075 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1076 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1077 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1080 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1081 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1084 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1087 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1088 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1089 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1090 SetBkMode (hdc
, oldBkMode
);
1092 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1094 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1096 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1098 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1099 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1101 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1103 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1104 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1107 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1110 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1112 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1113 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1120 TOOLBAR_Refresh (TOOLBAR_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
1122 TBUTTON_INFO
*btnPtr
;
1124 RECT rcTemp
, rcClient
;
1125 NMTBCUSTOMDRAW tbcd
;
1127 DWORD dwBaseCustDraw
;
1129 /* the app has told us not to redraw the toolbar */
1130 if (!infoPtr
->bDoRedraw
)
1133 /* if imagelist belongs to the app, it can be changed
1134 by the app after setting it */
1135 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1137 infoPtr
->nNumBitmaps
= 0;
1138 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1139 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1142 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1144 /* change the imagelist icon size if we manage the list and it is necessary */
1145 TOOLBAR_CheckImageListIconSize(infoPtr
);
1147 /* Send initial notify */
1148 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1149 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1150 tbcd
.nmcd
.hdc
= hdc
;
1151 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1152 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1153 dwBaseCustDraw
= ntfret
& 0xffff;
1155 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1157 /* redraw necessary buttons */
1158 btnPtr
= infoPtr
->buttons
;
1159 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1162 if (!RectVisible(hdc
, &btnPtr
->rect
))
1164 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1166 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1167 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1171 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1172 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1174 TOOLBAR_DrawButton(infoPtr
, btnPtr
, hdc
, dwBaseCustDraw
);
1177 /* draw insert mark if required */
1178 if (infoPtr
->tbim
.iButton
!= -1)
1180 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1182 rcInsertMark
.top
= rcButton
.top
;
1183 rcInsertMark
.bottom
= rcButton
.bottom
;
1184 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1185 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1187 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1188 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1191 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1193 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1194 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1195 tbcd
.nmcd
.hdc
= hdc
;
1196 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1197 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1201 /***********************************************************************
1202 * TOOLBAR_MeasureString
1204 * This function gets the width and height of a string in pixels. This
1205 * is done first by using GetTextExtentPoint to get the basic width
1206 * and height. The DrawText is called with DT_CALCRECT to get the exact
1207 * width. The reason is because the text may have more than one "&" (or
1208 * prefix characters as M$ likes to call them). The prefix character
1209 * indicates where the underline goes, except for the string "&&" which
1210 * is reduced to a single "&". GetTextExtentPoint does not process these
1211 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1214 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1215 HDC hdc
, LPSIZE lpSize
)
1222 if (infoPtr
->nMaxTextRows
> 0 &&
1223 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1224 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1225 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1227 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1229 if(lpText
!= NULL
) {
1230 /* first get size of all the text */
1231 GetTextExtentPoint32W (hdc
, lpText
, strlenW (lpText
), lpSize
);
1233 /* feed above size into the rectangle for DrawText */
1234 myrect
.left
= myrect
.top
= 0;
1235 myrect
.right
= lpSize
->cx
;
1236 myrect
.bottom
= lpSize
->cy
;
1238 /* Use DrawText to get true size as drawn (less pesky "&") */
1239 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1240 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1243 /* feed back to caller */
1244 lpSize
->cx
= myrect
.right
;
1245 lpSize
->cy
= myrect
.bottom
;
1249 TRACE("string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1252 /***********************************************************************
1253 * TOOLBAR_CalcStrings
1255 * This function walks through each string and measures it and returns
1256 * the largest height and width to caller.
1259 TOOLBAR_CalcStrings (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
1261 TBUTTON_INFO
*btnPtr
;
1270 if (infoPtr
->nMaxTextRows
== 0)
1273 hdc
= GetDC (infoPtr
->hwndSelf
);
1274 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1276 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1280 GetTextMetricsW(hdc
, &tm
);
1281 lpSize
->cy
= tm
.tmHeight
;
1284 btnPtr
= infoPtr
->buttons
;
1285 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1286 if(TOOLBAR_GetText(infoPtr
, btnPtr
))
1288 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1289 if (sz
.cx
> lpSize
->cx
)
1291 if (sz
.cy
> lpSize
->cy
)
1296 SelectObject (hdc
, hOldFont
);
1297 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1299 TRACE("max string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1302 /***********************************************************************
1303 * TOOLBAR_WrapToolbar
1305 * This function walks through the buttons and separators in the
1306 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1307 * wrapping should occur based on the width of the toolbar window.
1308 * It does *not* calculate button placement itself. That task
1309 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1310 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1311 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1313 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_VERTICAL can be used also to allow
1314 * vertical toolbar lists.
1318 TOOLBAR_WrapToolbar(TOOLBAR_INFO
*infoPtr
)
1320 TBUTTON_INFO
*btnPtr
;
1321 INT x
, cx
, i
, j
, width
;
1324 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1325 /* no layout is necessary. Applications may use this style */
1326 /* to perform their own layout on the toolbar. */
1327 if( !(infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) &&
1328 !(infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
) ) return;
1330 btnPtr
= infoPtr
->buttons
;
1331 x
= infoPtr
->nIndent
;
1332 width
= infoPtr
->client_rect
.right
- infoPtr
->client_rect
.left
;
1334 bButtonWrap
= FALSE
;
1336 TRACE("start ButtonWidth=%d, BitmapWidth=%d, width=%d, nIndent=%d\n",
1337 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, width
,
1340 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1342 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1344 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1347 if (btnPtr
[i
].cx
> 0)
1349 /* horizontal separators are treated as buttons for width */
1350 else if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1351 !(infoPtr
->dwStyle
& CCS_VERT
))
1352 cx
= (btnPtr
[i
].iBitmap
> 0) ? btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1354 cx
= infoPtr
->nButtonWidth
;
1356 if (!btnPtr
[i
].cx
&& button_has_ddarrow( infoPtr
, btnPtr
+ i
))
1357 cx
+= DDARROW_WIDTH
;
1359 /* Two or more adjacent separators form a separator group. */
1360 /* The first separator in a group should be wrapped to the */
1361 /* next row if the previous wrapping is on a button. */
1363 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1364 (i
+ 1 < infoPtr
->nNumButtons
) &&
1365 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1367 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1368 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1369 x
= infoPtr
->nIndent
;
1371 bButtonWrap
= FALSE
;
1375 /* The layout makes sure the bitmap is visible, but not the button. */
1376 /* Test added to also wrap after a button that starts a row but */
1377 /* is bigger than the area. - GA 8/01 */
1378 if ((x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2 > width
) ||
1379 ((x
== infoPtr
->nIndent
) && (cx
> width
)))
1381 BOOL bFound
= FALSE
;
1383 /* If the current button is a separator and not hidden, */
1384 /* go to the next until it reaches a non separator. */
1385 /* Wrap the last separator if it is before a button. */
1386 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1387 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1388 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1389 i
< infoPtr
->nNumButtons
)
1395 if( bFound
&& i
< infoPtr
->nNumButtons
)
1398 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1399 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1400 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1401 x
= infoPtr
->nIndent
;
1402 bButtonWrap
= FALSE
;
1405 else if ( i
>= infoPtr
->nNumButtons
)
1408 /* If the current button is not a separator, find the last */
1409 /* separator and wrap it. */
1410 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1412 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1413 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1417 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1418 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1419 x
= infoPtr
->nIndent
;
1420 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1421 bButtonWrap
= FALSE
;
1426 /* If no separator available for wrapping, wrap one of */
1427 /* non-hidden previous button. */
1431 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1433 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1438 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1439 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1440 x
= infoPtr
->nIndent
;
1441 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1447 /* If all above failed, wrap the current button. */
1450 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1451 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1452 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1453 x
= infoPtr
->nIndent
;
1454 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1455 bButtonWrap
= FALSE
;
1461 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1462 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1469 /***********************************************************************
1470 * TOOLBAR_MeasureButton
1472 * Calculates the width and height required for a button. Used in
1473 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1474 * the width of buttons that are autosized.
1476 * Note that it would have been rather elegant to use one piece of code for
1477 * both the laying out of the toolbar and for controlling where button parts
1478 * are drawn, but the native control has inconsistencies between the two that
1479 * prevent this from being effectively. These inconsistencies can be seen as
1480 * artefacts where parts of the button appear outside of the bounding button
1483 * There are several cases for the calculation of the button dimensions and
1484 * button part positioning:
1491 * +--------------------------------------------------------+ ^
1493 * | | pad.cy / 2 | centered | |
1494 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1495 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1496 * | |<------------>| | | | |
1497 * | +--------------+ +------------+ | |
1498 * |<-------------------------------------->| | |
1499 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1501 * +--------------------------------------------------------+ -
1502 * <-------------------------------------------------------->
1503 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1505 * Without Bitmap (I_IMAGENONE):
1507 * +-----------------------------------+ ^
1509 * | | centered | | LISTPAD_CY +
1510 * | +------------+ | | szText.cy
1513 * | +------------+ | |
1514 * |<----------------->| | |
1515 * | cxedge |<-----------> | |
1517 * +-----------------------------------+ -
1518 * <----------------------------------->
1519 * szText.cx + pad.cx
1523 * +--------------------------------------+ ^
1525 * | | padding.cy/2 | | DEFPAD_CY +
1526 * | +------------+ | | nBitmapHeight
1529 * | +------------+ | |
1530 * |<------------------->| | |
1531 * | cxedge + iListGap/2 |<-----------> | |
1532 * | nBitmapWidth | |
1533 * +--------------------------------------+ -
1534 * <-------------------------------------->
1535 * 2*cxedge + nBitmapWidth + iListGap
1542 * +-----------------------------------+ ^
1544 * | | pad.cy / 2 | | nBitmapHeight +
1545 * | - | | szText.cy +
1546 * | +------------+ | | DEFPAD_CY + 1
1547 * | centered | Bitmap | | |
1548 * |<----------------->| | | |
1549 * | +------------+ | |
1553 * | centered +---------------+ | |
1554 * |<--------------->| Text | | |
1555 * | +---------------+ | |
1556 * +-----------------------------------+ -
1557 * <----------------------------------->
1558 * pad.cx + max(nBitmapWidth, szText.cx)
1560 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1562 * +---------------------------------------+ ^
1564 * | | 2 + pad.cy / 2 | |
1565 * | - | | szText.cy +
1566 * | centered +-----------------+ | | pad.cy + 2
1567 * |<--------------->| Text | | |
1568 * | +-----------------+ | |
1570 * +---------------------------------------+ -
1571 * <--------------------------------------->
1572 * 2*cxedge + pad.cx + szText.cx
1575 * As for with bitmaps, but with szText.cx zero.
1577 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1578 BOOL bHasBitmap
, BOOL bValidImageList
)
1581 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1583 /* set button height from bitmap / text height... */
1584 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1587 /* ... add on the necessary padding */
1588 if (bValidImageList
)
1591 sizeButton
.cy
+= DEFPAD_CY
;
1593 sizeButton
.cy
+= LISTPAD_CY
;
1596 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1598 /* calculate button width */
1599 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1600 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1601 if (sizeString
.cx
> 0)
1602 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1609 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1610 if (sizeString
.cy
> 0)
1611 sizeButton
.cy
+= 1 + sizeString
.cy
;
1612 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1613 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1617 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1618 NONLIST_NOTEXT_OFFSET
;
1619 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1620 max(2*GetSystemMetrics(SM_CXEDGE
) + sizeString
.cx
, infoPtr
->nBitmapWidth
);
1627 /***********************************************************************
1628 * TOOLBAR_CalcToolbar
1630 * This function calculates button and separator placement. It first
1631 * calculates the button sizes, gets the toolbar window width and then
1632 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1633 * on. It assigns a new location to each item and sends this location to
1634 * the tooltip window if appropriate. Finally, it updates the rcBound
1635 * rect and calculates the new required toolbar window height.
1638 TOOLBAR_CalcToolbar (TOOLBAR_INFO
*infoPtr
)
1640 SIZE sizeString
, sizeButton
;
1641 BOOL validImageList
= FALSE
;
1643 TOOLBAR_CalcStrings (infoPtr
, &sizeString
);
1645 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1647 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1648 validImageList
= TRUE
;
1649 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1650 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1651 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1652 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1654 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1655 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1656 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1657 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1659 TOOLBAR_LayoutToolbar(infoPtr
);
1663 TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
)
1665 TBUTTON_INFO
*btnPtr
;
1667 INT i
, nRows
, nSepRows
;
1670 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1672 TOOLBAR_WrapToolbar(infoPtr
);
1674 x
= infoPtr
->nIndent
;
1675 y
= infoPtr
->iTopMargin
;
1676 cx
= infoPtr
->nButtonWidth
;
1677 cy
= infoPtr
->nButtonHeight
;
1679 nRows
= nSepRows
= 0;
1681 infoPtr
->rcBound
.top
= y
;
1682 infoPtr
->rcBound
.left
= x
;
1683 infoPtr
->rcBound
.bottom
= y
+ cy
;
1684 infoPtr
->rcBound
.right
= x
;
1686 btnPtr
= infoPtr
->buttons
;
1688 TRACE("cy=%d\n", cy
);
1690 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1693 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1695 SetRectEmpty (&btnPtr
->rect
);
1699 cy
= infoPtr
->nButtonHeight
;
1701 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1702 if (infoPtr
->dwStyle
& CCS_VERT
) {
1703 cy
= (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1704 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
: infoPtr
->nButtonWidth
;
1707 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
:
1708 (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1714 else if (btnPtr
->fsStyle
& BTNS_AUTOSIZE
)
1720 hdc
= GetDC (infoPtr
->hwndSelf
);
1721 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1723 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1725 SelectObject (hdc
, hOldFont
);
1726 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1728 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1729 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1734 cx
= infoPtr
->nButtonWidth
;
1736 /* if size has been set manually then don't add on extra space
1737 * for the drop down arrow */
1738 if (!btnPtr
->cx
&& button_has_ddarrow( infoPtr
, btnPtr
))
1739 cx
+= DDARROW_WIDTH
;
1741 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1744 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1746 if (infoPtr
->rcBound
.left
> x
)
1747 infoPtr
->rcBound
.left
= x
;
1748 if (infoPtr
->rcBound
.right
< x
+ cx
)
1749 infoPtr
->rcBound
.right
= x
+ cx
;
1750 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1751 infoPtr
->rcBound
.bottom
= y
+ cy
;
1753 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1755 /* btnPtr->nRow is zero based. The space between the rows is */
1756 /* also considered as a row. */
1757 btnPtr
->nRow
= nRows
+ nSepRows
;
1759 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1760 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1765 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1769 if ( !(infoPtr
->dwStyle
& CCS_VERT
))
1770 y
+= cy
+ ( (btnPtr
->cx
> 0 ) ?
1771 btnPtr
->cx
: SEPARATOR_WIDTH
) * 2 /3;
1775 /* nSepRows is used to calculate the extra height following */
1779 x
= infoPtr
->nIndent
;
1781 /* Increment row number unless this is the last button */
1782 /* and it has Wrap set. */
1783 if (i
!= infoPtr
->nNumButtons
-1)
1790 /* infoPtr->nRows is the number of rows on the toolbar */
1791 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1793 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1798 TOOLBAR_InternalHitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
*lpPt
, BOOL
*button
)
1800 TBUTTON_INFO
*btnPtr
;
1806 btnPtr
= infoPtr
->buttons
;
1807 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1808 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1811 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1812 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1813 TRACE(" ON SEPARATOR %d!\n", i
);
1818 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1819 TRACE(" ON BUTTON %d!\n", i
);
1827 TRACE(" NOWHERE!\n");
1828 return TOOLBAR_NOWHERE
;
1832 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1834 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO
*infoPtr
, INT iIndex
, UINT nAddButtons
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
1836 INT nOldButtons
, nNewButtons
, iButton
;
1837 BOOL fHasString
= FALSE
;
1839 if (iIndex
< 0) /* iIndex can be negative, what means adding at the end */
1840 iIndex
= infoPtr
->nNumButtons
;
1842 nOldButtons
= infoPtr
->nNumButtons
;
1843 nNewButtons
= nOldButtons
+ nAddButtons
;
1845 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
1846 memmove(&infoPtr
->buttons
[iIndex
+ nAddButtons
], &infoPtr
->buttons
[iIndex
],
1847 (nOldButtons
- iIndex
) * sizeof(TBUTTON_INFO
));
1848 infoPtr
->nNumButtons
+= nAddButtons
;
1850 /* insert new buttons data */
1851 for (iButton
= 0; iButton
< nAddButtons
; iButton
++) {
1852 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[iIndex
+ iButton
];
1855 TOOLBAR_DumpTBButton(lpTbb
+ iButton
, fUnicode
);
1857 ZeroMemory(btnPtr
, sizeof(*btnPtr
));
1859 btnPtr
->iBitmap
= lpTbb
[iButton
].iBitmap
;
1860 btnPtr
->idCommand
= lpTbb
[iButton
].idCommand
;
1861 btnPtr
->fsState
= lpTbb
[iButton
].fsState
;
1862 btnPtr
->fsStyle
= lpTbb
[iButton
].fsStyle
;
1863 btnPtr
->dwData
= lpTbb
[iButton
].dwData
;
1865 if (btnPtr
->fsStyle
& BTNS_SEP
)
1868 str
= lpTbb
[iButton
].iString
;
1869 set_string_index( btnPtr
, str
, fUnicode
);
1870 fHasString
|= TOOLBAR_ButtonHasString( btnPtr
);
1872 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
1875 if (infoPtr
->nNumStrings
> 0 || fHasString
)
1876 TOOLBAR_CalcToolbar(infoPtr
);
1878 TOOLBAR_LayoutToolbar(infoPtr
);
1879 TOOLBAR_AutoSize(infoPtr
);
1881 TOOLBAR_DumpToolbar(infoPtr
, __LINE__
);
1882 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1888 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1890 TBUTTON_INFO
*btnPtr
;
1893 if (CommandIsIndex
) {
1894 TRACE("command is really index command=%d\n", idCommand
);
1895 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1898 btnPtr
= infoPtr
->buttons
;
1899 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1900 if (btnPtr
->idCommand
== idCommand
) {
1901 TRACE("command=%d index=%d\n", idCommand
, i
);
1905 TRACE("no index found for command=%d\n", idCommand
);
1911 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1913 TBUTTON_INFO
*btnPtr
;
1916 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1919 /* check index button */
1920 btnPtr
= &infoPtr
->buttons
[nIndex
];
1921 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1922 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1926 /* check previous buttons */
1927 nRunIndex
= nIndex
- 1;
1928 while (nRunIndex
>= 0) {
1929 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1930 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1931 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1939 /* check next buttons */
1940 nRunIndex
= nIndex
+ 1;
1941 while (nRunIndex
< infoPtr
->nNumButtons
) {
1942 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1943 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1944 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1957 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1958 WPARAM wParam
, LPARAM lParam
)
1964 msg
.wParam
= wParam
;
1965 msg
.lParam
= lParam
;
1966 msg
.time
= GetMessageTime ();
1967 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
1968 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
1970 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1974 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1976 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
1979 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
1980 ti
.cbSize
= sizeof (TTTOOLINFOW
);
1981 ti
.hwnd
= infoPtr
->hwndSelf
;
1982 ti
.uId
= button
->idCommand
;
1984 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
1985 /* ti.lParam = random value from the stack? */
1987 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
1993 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1995 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
1998 ZeroMemory(&ti
, sizeof(ti
));
1999 ti
.cbSize
= sizeof(ti
);
2000 ti
.hwnd
= infoPtr
->hwndSelf
;
2001 ti
.uId
= button
->idCommand
;
2003 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
2007 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2009 /* Set the toolTip only for non-hidden, non-separator button */
2010 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
2014 ZeroMemory(&ti
, sizeof(ti
));
2015 ti
.cbSize
= sizeof(ti
);
2016 ti
.hwnd
= infoPtr
->hwndSelf
;
2017 ti
.uId
= button
->idCommand
;
2018 ti
.rect
= button
->rect
;
2019 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
2023 /* Creates the tooltip control */
2025 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
2028 NMTOOLTIPSCREATED nmttc
;
2030 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
2031 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2032 infoPtr
->hwndSelf
, 0, 0, 0);
2034 if (!infoPtr
->hwndToolTip
)
2037 /* Send NM_TOOLTIPSCREATED notification */
2038 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
2039 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
2041 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
2043 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
2044 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
2048 /* keeps available button list box sorted by button id */
2049 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
2053 PCUSTOMBUTTON btnInfo
;
2054 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2056 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
2058 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2060 /* position 0 is always separator */
2061 for (i
= 1; i
< count
; i
++)
2063 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2064 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2066 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2067 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2071 /* id higher than all others add to end */
2072 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2073 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2076 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2080 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2082 if (nIndexFrom
== nIndexTo
)
2085 /* MSDN states that iItem is the index of the button, rather than the
2086 * command ID as used by every other NMTOOLBAR notification */
2087 nmtb
.iItem
= nIndexFrom
;
2088 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2090 PCUSTOMBUTTON btnInfo
;
2092 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2093 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2095 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2097 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2098 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2099 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2100 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2103 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2105 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2107 /* last item is always separator, so -2 instead of -1 */
2108 if (nIndexTo
>= (count
- 2))
2109 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2111 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2113 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2114 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2116 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2120 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2124 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2126 /* MSDN states that iItem is the index of the button, rather than the
2127 * command ID as used by every other NMTOOLBAR notification */
2128 nmtb
.iItem
= nIndexAvail
;
2129 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2131 PCUSTOMBUTTON btnInfo
;
2133 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2134 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2135 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2137 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2139 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2141 /* remove from 'available buttons' list */
2142 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2143 if (nIndexAvail
== count
-1)
2144 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2146 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2150 PCUSTOMBUTTON btnNew
;
2152 /* duplicate 'separator' button */
2153 btnNew
= Alloc(sizeof(CUSTOMBUTTON
));
2158 /* insert into 'toolbar button' list */
2159 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2160 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2162 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2164 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2168 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2170 PCUSTOMBUTTON btnInfo
;
2171 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2173 TRACE("Remove: index %d\n", index
);
2175 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2177 /* send TBN_QUERYDELETE notification */
2178 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2182 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2183 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2185 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2187 /* insert into 'available button' list */
2188 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2189 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2193 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2197 /* drag list notification function for toolbar buttons list box */
2198 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2199 const DRAGLISTINFO
*pDLI
)
2201 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2202 switch (pDLI
->uNotification
)
2206 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2207 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2208 /* no dragging for last item (separator) */
2209 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2214 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2215 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2216 /* no dragging past last item (separator) */
2217 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2219 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2220 /* FIXME: native uses "move button" cursor */
2221 return DL_COPYCURSOR
;
2224 /* not over toolbar buttons list */
2225 if (nCurrentItem
< 0)
2227 POINT ptWindow
= pDLI
->ptCursor
;
2228 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2229 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2230 /* over available buttons list? */
2231 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2232 /* FIXME: native uses "move button" cursor */
2233 return DL_COPYCURSOR
;
2235 /* clear drag arrow */
2236 DrawInsert(hwnd
, hwndList
, -1);
2237 return DL_STOPCURSOR
;
2241 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2242 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2243 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2244 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2246 /* clear drag arrow */
2247 DrawInsert(hwnd
, hwndList
, -1);
2249 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2251 /* not over toolbar buttons list */
2254 POINT ptWindow
= pDLI
->ptCursor
;
2255 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2256 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2257 /* over available buttons list? */
2258 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2259 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2264 /* Clear drag arrow */
2265 DrawInsert(hwnd
, hwndList
, -1);
2272 /* drag list notification function for available buttons list box */
2273 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2274 const DRAGLISTINFO
*pDLI
)
2276 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2277 switch (pDLI
->uNotification
)
2283 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2284 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2285 /* no dragging past last item (separator) */
2286 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2288 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2289 /* FIXME: native uses "move button" cursor */
2290 return DL_COPYCURSOR
;
2293 /* not over toolbar buttons list */
2294 if (nCurrentItem
< 0)
2296 POINT ptWindow
= pDLI
->ptCursor
;
2297 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2298 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2299 /* over available buttons list? */
2300 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2301 /* FIXME: native uses "move button" cursor */
2302 return DL_COPYCURSOR
;
2304 /* clear drag arrow */
2305 DrawInsert(hwnd
, hwndList
, -1);
2306 return DL_STOPCURSOR
;
2310 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2311 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2312 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2313 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2315 /* clear drag arrow */
2316 DrawInsert(hwnd
, hwndList
, -1);
2318 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2322 /* Clear drag arrow */
2323 DrawInsert(hwnd
, hwndList
, -1);
2329 extern UINT uDragListMessage DECLSPEC_HIDDEN
;
2331 /***********************************************************************
2332 * TOOLBAR_CustomizeDialogProc
2333 * This function implements the toolbar customization dialog.
2335 static INT_PTR CALLBACK
2336 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2338 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2339 PCUSTOMBUTTON btnInfo
;
2341 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2346 custInfo
= (PCUSTDLG_INFO
)lParam
;
2347 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2354 NMTBINITCUSTOMIZE nmtbic
;
2356 infoPtr
= custInfo
->tbInfo
;
2358 /* send TBN_QUERYINSERT notification */
2359 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2361 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2364 nmtbic
.hwndDialog
= hwnd
;
2365 /* Send TBN_INITCUSTOMIZE notification */
2366 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2369 TRACE("TBNRF_HIDEHELP requested\n");
2370 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2373 /* add items to 'toolbar buttons' list and check if removable */
2374 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2376 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2377 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2378 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2379 btnInfo
->bVirtual
= FALSE
;
2380 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2382 /* send TBN_QUERYDELETE notification */
2383 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2385 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2386 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2389 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2391 /* insert separator button into 'available buttons' list */
2392 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2393 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2394 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2395 btnInfo
->bVirtual
= FALSE
;
2396 btnInfo
->bRemovable
= TRUE
;
2397 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2398 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2399 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2401 /* insert all buttons into dsa */
2404 /* send TBN_GETBUTTONINFO notification */
2407 nmtb
.pszText
= Buffer
;
2410 /* Clear previous button's text */
2411 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2413 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2416 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2417 nmtb
.tbButton
.fsStyle
, i
,
2418 nmtb
.tbButton
.idCommand
,
2419 nmtb
.tbButton
.iString
,
2420 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2423 /* insert button into the appropriate list */
2424 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2427 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2428 btnInfo
->bVirtual
= FALSE
;
2429 btnInfo
->bRemovable
= TRUE
;
2433 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2434 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2437 btnInfo
->btn
= nmtb
.tbButton
;
2438 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2440 if (lstrlenW(nmtb
.pszText
))
2441 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2442 else if (nmtb
.tbButton
.iString
>= 0 &&
2443 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2445 lstrcpyW(btnInfo
->text
,
2446 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2451 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2454 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2456 /* select first item in the 'available' list */
2457 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2459 /* append 'virtual' separator button to the 'toolbar buttons' list */
2460 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2461 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2462 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2463 btnInfo
->bVirtual
= TRUE
;
2464 btnInfo
->bRemovable
= FALSE
;
2465 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2466 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2467 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2469 /* select last item in the 'toolbar' list */
2470 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2471 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2473 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2474 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2476 /* set focus and disable buttons */
2477 PostMessageW (hwnd
, WM_USER
, 0, 0);
2482 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2483 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2484 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2485 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2489 EndDialog(hwnd
, FALSE
);
2493 switch (LOWORD(wParam
))
2495 case IDC_TOOLBARBTN_LBOX
:
2496 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2498 PCUSTOMBUTTON btnInfo
;
2503 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2504 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2506 /* send TBN_QUERYINSERT notification */
2508 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2510 /* get list box item */
2511 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2513 if (index
== (count
- 1))
2515 /* last item (virtual separator) */
2516 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2517 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2519 else if (index
== (count
- 2))
2521 /* second last item (last non-virtual item) */
2522 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2523 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2525 else if (index
== 0)
2528 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2529 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2533 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2534 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2537 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2541 case IDC_MOVEUP_BTN
:
2543 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2544 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2548 case IDC_MOVEDN_BTN
: /* move down */
2550 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2551 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2555 case IDC_REMOVE_BTN
: /* remove button */
2557 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2559 if (LB_ERR
== index
)
2562 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2566 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2569 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2572 case IDOK
: /* Add button */
2577 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2578 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2580 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2585 EndDialog(hwnd
, FALSE
);
2595 /* delete items from 'toolbar buttons' listbox*/
2596 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2597 for (i
= 0; i
< count
; i
++)
2599 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2601 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2603 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2606 /* delete items from 'available buttons' listbox*/
2607 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2608 for (i
= 0; i
< count
; i
++)
2610 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2612 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2614 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2619 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2621 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2626 COLORREF oldText
= 0;
2630 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, lpdis
->itemID
, 0);
2631 if (btnInfo
== NULL
)
2633 FIXME("btnInfo invalid!\n");
2637 /* set colors and select objects */
2638 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2639 if (btnInfo
->bVirtual
)
2640 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2642 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2643 hPen
= CreatePen( PS_SOLID
, 1,
2644 (lpdis
->itemState
& ODS_SELECTED
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2645 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2646 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2648 /* fill background rectangle */
2649 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2650 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2652 /* calculate button and text rectangles */
2653 CopyRect (&rcButton
, &lpdis
->rcItem
);
2654 InflateRect (&rcButton
, -1, -1);
2655 CopyRect (&rcText
, &rcButton
);
2656 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2657 rcText
.left
= rcButton
.right
+ 2;
2659 /* draw focus rectangle */
2660 if (lpdis
->itemState
& ODS_FOCUS
)
2661 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2664 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2665 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2667 /* draw image and text */
2668 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2669 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2670 btnInfo
->btn
.iBitmap
));
2671 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2672 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2674 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2675 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2677 /* delete objects and reset colors */
2678 SelectObject (lpdis
->hDC
, hOldBrush
);
2679 SelectObject (lpdis
->hDC
, hOldPen
);
2680 SetBkColor (lpdis
->hDC
, oldBk
);
2681 SetTextColor (lpdis
->hDC
, oldText
);
2682 DeleteObject( hPen
);
2687 case WM_MEASUREITEM
:
2688 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2690 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2692 lpmis
->itemHeight
= 15 + 8; /* default height */
2699 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2701 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2703 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2704 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2705 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2708 else if (wParam
== IDC_AVAILBTN_LBOX
)
2710 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2711 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2712 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2721 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2724 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2730 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2731 /* Add bitmaps to the default image list */
2732 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2733 hbmLoad
= CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2734 else if (bitmap
->hInst
== COMCTL32_hModule
)
2735 hbmLoad
= LoadImageW( bitmap
->hInst
, MAKEINTRESOURCEW(bitmap
->nID
),
2736 IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
2738 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2740 /* enlarge the bitmap if needed */
2741 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2742 if (bitmap
->hInst
!= COMCTL32_hModule
)
2743 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2745 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2746 DeleteObject(hbmLoad
);
2750 nCountAfter
= ImageList_GetImageCount(himlDef
);
2751 nAdded
= nCountAfter
- nCountBefore
;
2752 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2754 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2755 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2756 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2757 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2760 infoPtr
->nNumBitmaps
+= nAdded
;
2765 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2772 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2773 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2775 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2777 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2780 TRACE("Update icon size: %dx%d -> %dx%d\n",
2781 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2783 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2784 ILC_COLOR32
|ILC_MASK
, 8, 2);
2785 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2786 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2787 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2788 infoPtr
->himlInt
= himlNew
;
2790 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2791 ImageList_Destroy(himlDef
);
2794 /***********************************************************************
2795 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2799 TOOLBAR_AddBitmap (TOOLBAR_INFO
*infoPtr
, INT count
, const TBADDBITMAP
*lpAddBmp
)
2805 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr
->hwndSelf
, count
, lpAddBmp
);
2809 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2811 info
.hInst
= COMCTL32_hModule
;
2812 switch (lpAddBmp
->nID
)
2814 case IDB_STD_SMALL_COLOR
:
2816 info
.nID
= IDB_STD_SMALL
;
2818 case IDB_STD_LARGE_COLOR
:
2820 info
.nID
= IDB_STD_LARGE
;
2822 case IDB_VIEW_SMALL_COLOR
:
2824 info
.nID
= IDB_VIEW_SMALL
;
2826 case IDB_VIEW_LARGE_COLOR
:
2828 info
.nID
= IDB_VIEW_LARGE
;
2830 case IDB_HIST_SMALL_COLOR
:
2832 info
.nID
= IDB_HIST_SMALL
;
2834 case IDB_HIST_LARGE_COLOR
:
2836 info
.nID
= IDB_HIST_LARGE
;
2842 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2844 /* Windows resize all the buttons to the size of a newly added standard image */
2845 if (lpAddBmp
->nID
& 1)
2847 /* large icons: 24x24. Will make the button 31x30 */
2848 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2852 /* small icons: 16x16. Will make the buttons 23x22 */
2853 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2856 TOOLBAR_CalcToolbar (infoPtr
);
2860 info
.nButtons
= count
;
2861 info
.hInst
= lpAddBmp
->hInst
;
2862 info
.nID
= lpAddBmp
->nID
;
2863 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2866 /* check if the bitmap is already loaded and compute iSumButtons */
2868 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2870 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2871 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2873 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2876 if (!infoPtr
->cimlDef
) {
2877 /* create new default image list */
2878 TRACE ("creating default image list!\n");
2880 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2881 ILC_COLOR32
| ILC_MASK
, info
.nButtons
, 2);
2882 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2883 infoPtr
->himlInt
= himlDef
;
2886 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2890 WARN("No default image list available\n");
2894 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2897 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2898 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2899 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2900 infoPtr
->nNumBitmapInfos
++;
2901 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2903 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2909 TOOLBAR_AddButtonsT(TOOLBAR_INFO
*infoPtr
, INT nAddButtons
, const TBBUTTON
* lpTbb
, BOOL fUnicode
)
2911 TRACE("adding %d buttons (unicode=%d)!\n", nAddButtons
, fUnicode
);
2913 return TOOLBAR_InternalInsertButtonsT(infoPtr
, -1, nAddButtons
, lpTbb
, fUnicode
);
2918 TOOLBAR_AddStringW (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
2920 #define MAX_RESOURCE_STRING_LENGTH 512
2921 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2922 INT nIndex
= infoPtr
->nNumStrings
;
2924 TRACE("%p, %lx\n", hInstance
, lParam
);
2926 if (IS_INTRESOURCE(lParam
)) {
2927 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2934 TRACE("adding string from resource\n");
2936 if (!hInstance
) return -1;
2938 hrsrc
= FindResourceW( hInstance
, MAKEINTRESOURCEW((LOWORD(lParam
) >> 4) + 1),
2939 (LPWSTR
)RT_STRING
);
2942 TRACE("string not found in resources\n");
2946 len
= LoadStringW (hInstance
, (UINT
)lParam
,
2947 szString
, MAX_RESOURCE_STRING_LENGTH
);
2949 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2950 if (len
== 0 || len
== 1)
2953 TRACE("delimiter: 0x%x\n", *szString
);
2954 delimiter
= *szString
;
2957 while ((next_delim
= strchrW(p
, delimiter
)) != NULL
) {
2959 if (next_delim
+ 1 >= szString
+ len
)
2961 /* this may happen if delimiter == '\0' or if the last char is a
2962 * delimiter (then it is ignored like the native does) */
2966 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2967 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2968 infoPtr
->nNumStrings
++;
2974 LPWSTR p
= (LPWSTR
)lParam
;
2979 TRACE("adding string(s) from array\n");
2983 TRACE("len=%d %s\n", len
, debugstr_w(p
));
2984 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2985 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2986 infoPtr
->nNumStrings
++;
2993 TOOLBAR_CalcToolbar(infoPtr
);
2999 TOOLBAR_AddStringA (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
3001 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
3006 TRACE("%p, %lx\n", hInstance
, lParam
);
3008 if (IS_INTRESOURCE(lParam
)) /* load from resources */
3009 return TOOLBAR_AddStringW(infoPtr
, hInstance
, lParam
);
3015 TRACE("adding string(s) from array\n");
3016 nIndex
= infoPtr
->nNumStrings
;
3019 TRACE("len=%d \"%s\"\n", len
, p
);
3021 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3022 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3023 infoPtr
->nNumStrings
++;
3029 TOOLBAR_CalcToolbar(infoPtr
);
3035 TOOLBAR_AutoSize (TOOLBAR_INFO
*infoPtr
)
3037 TRACE("auto sizing, style=%x!\n", infoPtr
->dwStyle
);
3038 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3040 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3042 RECT window_rect
, parent_rect
;
3043 UINT uPosFlags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
3047 parent
= GetParent (infoPtr
->hwndSelf
);
3049 if (!parent
|| !infoPtr
->bDoRedraw
)
3052 GetClientRect(parent
, &parent_rect
);
3054 x
= parent_rect
.left
;
3055 y
= parent_rect
.top
;
3057 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3058 cx
= parent_rect
.right
- parent_rect
.left
;
3060 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3062 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3063 MapWindowPoints( 0, parent
, (POINT
*)&window_rect
, 2 );
3064 y
= window_rect
.top
;
3066 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3068 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3069 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3072 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3073 uPosFlags
|= SWP_NOMOVE
;
3075 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3076 cy
+= GetSystemMetrics(SM_CYEDGE
);
3078 if (infoPtr
->dwStyle
& WS_BORDER
)
3080 cx
+= 2 * GetSystemMetrics(SM_CXBORDER
);
3081 cy
+= 2 * GetSystemMetrics(SM_CYBORDER
);
3084 SetWindowPos(infoPtr
->hwndSelf
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3087 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
))
3089 TOOLBAR_LayoutToolbar(infoPtr
);
3090 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
3097 static inline LRESULT
3098 TOOLBAR_ButtonCount (const TOOLBAR_INFO
*infoPtr
)
3100 return infoPtr
->nNumButtons
;
3104 static inline LRESULT
3105 TOOLBAR_ButtonStructSize (TOOLBAR_INFO
*infoPtr
, DWORD Size
)
3107 infoPtr
->dwStructSize
= Size
;
3114 TOOLBAR_ChangeBitmap (TOOLBAR_INFO
*infoPtr
, INT Id
, INT Index
)
3116 TBUTTON_INFO
*btnPtr
;
3119 TRACE("button %d, iBitmap now %d\n", Id
, Index
);
3121 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3125 btnPtr
= &infoPtr
->buttons
[nIndex
];
3126 btnPtr
->iBitmap
= Index
;
3128 /* we HAVE to erase the background, the new bitmap could be */
3130 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3137 TOOLBAR_CheckButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3139 TBUTTON_INFO
*btnPtr
;
3142 BOOL bChecked
= FALSE
;
3144 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3146 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, nIndex
, lParam
);
3151 btnPtr
= &infoPtr
->buttons
[nIndex
];
3153 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) != 0;
3155 if (!LOWORD(lParam
))
3156 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3158 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3160 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3161 if (nOldIndex
== nIndex
)
3163 if (nOldIndex
!= -1)
3164 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3166 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3169 if( bChecked
!= LOWORD(lParam
) )
3171 if (nOldIndex
!= -1)
3172 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3173 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3176 /* FIXME: Send a WM_NOTIFY?? */
3183 TOOLBAR_CommandToIndex (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3185 return TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3190 TOOLBAR_Customize (TOOLBAR_INFO
*infoPtr
)
3192 CUSTDLG_INFO custInfo
;
3196 custInfo
.tbInfo
= infoPtr
;
3197 custInfo
.tbHwnd
= infoPtr
->hwndSelf
;
3199 /* send TBN_BEGINADJUST notification */
3200 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3202 ret
= DialogBoxParamW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3203 infoPtr
->hwndSelf
, TOOLBAR_CustomizeDialogProc
, (LPARAM
)&custInfo
);
3205 /* send TBN_ENDADJUST notification */
3206 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3213 TOOLBAR_DeleteButton (TOOLBAR_INFO
*infoPtr
, INT nIndex
)
3216 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3218 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3221 memset(&nmtb
, 0, sizeof(nmtb
));
3222 nmtb
.iItem
= btnPtr
->idCommand
;
3223 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3224 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3225 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3226 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3227 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3228 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3229 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3231 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3233 if (infoPtr
->nNumButtons
== 1) {
3234 TRACE(" simple delete!\n");
3235 free_string( infoPtr
->buttons
);
3236 Free (infoPtr
->buttons
);
3237 infoPtr
->buttons
= NULL
;
3238 infoPtr
->nNumButtons
= 0;
3241 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3242 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3244 infoPtr
->nNumButtons
--;
3245 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3247 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3248 nIndex
* sizeof(TBUTTON_INFO
));
3251 if (nIndex
< infoPtr
->nNumButtons
) {
3252 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3253 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3256 free_string( oldButtons
+ nIndex
);
3260 TOOLBAR_LayoutToolbar(infoPtr
);
3262 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3269 TOOLBAR_EnableButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3271 TBUTTON_INFO
*btnPtr
;
3275 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3277 TRACE("hwnd=%p, btn id=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, Id
, lParam
);
3282 btnPtr
= &infoPtr
->buttons
[nIndex
];
3284 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3286 /* update the toolbar button state */
3287 if(!LOWORD(lParam
)) {
3288 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3290 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3293 /* redraw the button only if the state of the button changed */
3294 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3295 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3301 static inline LRESULT
3302 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO
*infoPtr
)
3304 return infoPtr
->bAnchor
;
3309 TOOLBAR_GetBitmap (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3313 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3317 return infoPtr
->buttons
[nIndex
].iBitmap
;
3321 static inline LRESULT
3322 TOOLBAR_GetBitmapFlags (void)
3324 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3329 TOOLBAR_GetButton (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, TBBUTTON
*lpTbb
)
3331 TBUTTON_INFO
*btnPtr
;
3336 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3339 btnPtr
= &infoPtr
->buttons
[nIndex
];
3340 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3341 lpTbb
->idCommand
= btnPtr
->idCommand
;
3342 lpTbb
->fsState
= btnPtr
->fsState
;
3343 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3344 lpTbb
->bReserved
[0] = 0;
3345 lpTbb
->bReserved
[1] = 0;
3346 lpTbb
->dwData
= btnPtr
->dwData
;
3347 lpTbb
->iString
= btnPtr
->iString
;
3354 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO
*infoPtr
, INT Id
, LPTBBUTTONINFOW lpTbInfo
, BOOL bUnicode
)
3356 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3357 TBUTTON_INFO
*btnPtr
;
3360 if (lpTbInfo
== NULL
)
3363 /* MSDN documents an iImageLabel field added in Vista but it is not present in
3364 * the headers and tests shows that even with comctl 6 Vista accepts only the
3365 * original TBBUTTONINFO size
3367 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3369 WARN("Invalid button size\n");
3373 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lpTbInfo
->dwMask
& TBIF_BYINDEX
);
3377 btnPtr
= &infoPtr
->buttons
[nIndex
];
3378 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3379 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3380 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3381 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3382 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3383 lpTbInfo
->lParam
= btnPtr
->dwData
;
3384 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3385 /* tests show that for separators TBIF_SIZE returns not calculated width,
3386 but cx property, that differs from 0 only if application have
3387 specifically set it */
3388 lpTbInfo
->cx
= (btnPtr
->fsStyle
& BTNS_SEP
)
3389 ? btnPtr
->cx
: (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3390 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3391 lpTbInfo
->fsState
= btnPtr
->fsState
;
3392 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3393 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3394 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3395 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3396 can't use TOOLBAR_GetText here */
3397 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3398 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3400 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3402 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3404 lpTbInfo
->pszText
[0] = '\0';
3410 static inline LRESULT
3411 TOOLBAR_GetButtonSize (const TOOLBAR_INFO
*infoPtr
)
3413 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3414 (WORD
)infoPtr
->nButtonHeight
);
3419 TOOLBAR_GetButtonText (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPWSTR lpStr
, BOOL isW
)
3425 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3429 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3435 ret
= strlenW (lpText
);
3436 if (lpStr
) strcpyW (lpStr
, lpText
);
3440 ret
= WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3441 (LPSTR
)lpStr
, lpStr
? 0x7fffffff : 0, NULL
, NULL
) - 1;
3447 TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3449 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3450 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3451 return (LRESULT
)GETDISIMAGELIST(infoPtr
, wParam
);
3455 static inline LRESULT
3456 TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO
*infoPtr
)
3460 return infoPtr
->dwExStyle
;
3465 TOOLBAR_GetHotImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3467 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3468 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3469 return (LRESULT
)GETHOTIMAGELIST(infoPtr
, wParam
);
3474 TOOLBAR_GetHotItem (const TOOLBAR_INFO
*infoPtr
)
3476 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3479 if (infoPtr
->nHotItem
< 0)
3482 return (LRESULT
)infoPtr
->nHotItem
;
3487 TOOLBAR_GetDefImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3489 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3490 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3491 return (LRESULT
) GETDEFIMAGELIST(infoPtr
, wParam
);
3496 TOOLBAR_GetInsertMark (const TOOLBAR_INFO
*infoPtr
, TBINSERTMARK
*lptbim
)
3498 TRACE("hwnd = %p, lptbim = %p\n", infoPtr
->hwndSelf
, lptbim
);
3500 *lptbim
= infoPtr
->tbim
;
3506 static inline LRESULT
3507 TOOLBAR_GetInsertMarkColor (const TOOLBAR_INFO
*infoPtr
)
3509 TRACE("hwnd = %p\n", infoPtr
->hwndSelf
);
3511 return (LRESULT
)infoPtr
->clrInsertMark
;
3516 TOOLBAR_GetItemRect (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, LPRECT lpRect
)
3518 TBUTTON_INFO
*btnPtr
;
3520 btnPtr
= &infoPtr
->buttons
[nIndex
];
3521 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3526 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3529 lpRect
->left
= btnPtr
->rect
.left
;
3530 lpRect
->right
= btnPtr
->rect
.right
;
3531 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3532 lpRect
->top
= btnPtr
->rect
.top
;
3539 TOOLBAR_GetMaxSize (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
3544 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3545 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3547 TRACE("maximum size %d x %d\n",
3548 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3549 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3555 /* << TOOLBAR_GetObject >> */
3558 static inline LRESULT
3559 TOOLBAR_GetPadding (const TOOLBAR_INFO
*infoPtr
)
3561 return MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3566 TOOLBAR_GetRect (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPRECT lpRect
)
3568 TBUTTON_INFO
*btnPtr
;
3571 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3572 btnPtr
= &infoPtr
->buttons
[nIndex
];
3573 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3579 lpRect
->left
= btnPtr
->rect
.left
;
3580 lpRect
->right
= btnPtr
->rect
.right
;
3581 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3582 lpRect
->top
= btnPtr
->rect
.top
;
3588 static inline LRESULT
3589 TOOLBAR_GetRows (const TOOLBAR_INFO
*infoPtr
)
3591 return infoPtr
->nRows
;
3596 TOOLBAR_GetState (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3600 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3604 return infoPtr
->buttons
[nIndex
].fsState
;
3608 static inline LRESULT
3609 TOOLBAR_GetStyle (const TOOLBAR_INFO
*infoPtr
)
3611 return infoPtr
->dwStyle
;
3615 static inline LRESULT
3616 TOOLBAR_GetTextRows (const TOOLBAR_INFO
*infoPtr
)
3618 return infoPtr
->nMaxTextRows
;
3623 TOOLBAR_GetToolTips (TOOLBAR_INFO
*infoPtr
)
3625 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3626 TOOLBAR_TooltipCreateControl(infoPtr
);
3627 return (LRESULT
)infoPtr
->hwndToolTip
;
3632 TOOLBAR_GetUnicodeFormat (const TOOLBAR_INFO
*infoPtr
)
3634 TRACE("%s hwnd=%p\n",
3635 infoPtr
->bUnicode
? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
3637 return infoPtr
->bUnicode
;
3641 static inline LRESULT
3642 TOOLBAR_GetVersion (const TOOLBAR_INFO
*infoPtr
)
3644 return infoPtr
->iVersion
;
3649 TOOLBAR_HideButton (TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fHide
)
3651 TBUTTON_INFO
*btnPtr
;
3657 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3661 btnPtr
= &infoPtr
->buttons
[nIndex
];
3662 oldState
= btnPtr
->fsState
;
3665 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3667 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3669 if (oldState
!= btnPtr
->fsState
) {
3670 TOOLBAR_LayoutToolbar (infoPtr
);
3671 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3678 static inline LRESULT
3679 TOOLBAR_HitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
* lpPt
)
3681 return TOOLBAR_InternalHitTest (infoPtr
, lpPt
, NULL
);
3686 TOOLBAR_Indeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fIndeterminate
)
3688 TBUTTON_INFO
*btnPtr
;
3692 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3696 btnPtr
= &infoPtr
->buttons
[nIndex
];
3697 oldState
= btnPtr
->fsState
;
3700 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3702 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3704 if(oldState
!= btnPtr
->fsState
)
3705 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3712 TOOLBAR_InsertButtonT(TOOLBAR_INFO
*infoPtr
, INT nIndex
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
3718 /* EPP: this seems to be an undocumented call (from my IE4)
3719 * I assume in that case that:
3720 * - index of insertion is at the end of existing buttons
3721 * I only see this happen with nIndex == -1, but it could have a special
3722 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3724 nIndex
= infoPtr
->nNumButtons
;
3726 } else if (nIndex
< 0)
3729 TRACE("inserting button index=%d\n", nIndex
);
3730 if (nIndex
> infoPtr
->nNumButtons
) {
3731 nIndex
= infoPtr
->nNumButtons
;
3732 TRACE("adjust index=%d\n", nIndex
);
3735 return TOOLBAR_InternalInsertButtonsT(infoPtr
, nIndex
, 1, lpTbb
, fUnicode
);
3738 /* << TOOLBAR_InsertMarkHitTest >> */
3742 TOOLBAR_IsButtonChecked (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3746 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3750 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3755 TOOLBAR_IsButtonEnabled (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3759 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3763 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3768 TOOLBAR_IsButtonHidden (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3772 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3776 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3781 TOOLBAR_IsButtonHighlighted (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3785 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3789 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3794 TOOLBAR_IsButtonIndeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3798 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3802 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3807 TOOLBAR_IsButtonPressed (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3811 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3815 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3820 TOOLBAR_LoadImages (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HINSTANCE hInstance
)
3823 tbab
.hInst
= hInstance
;
3826 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", infoPtr
->hwndSelf
, tbab
.hInst
, tbab
.nID
);
3828 return TOOLBAR_AddBitmap(infoPtr
, 0, &tbab
);
3833 TOOLBAR_MapAccelerator (const TOOLBAR_INFO
*infoPtr
, WCHAR wAccel
, UINT
*pIDButton
)
3835 WCHAR wszAccel
[] = {'&',wAccel
,0};
3838 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3839 infoPtr
->hwndSelf
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3841 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3843 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3844 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3845 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3847 int iLen
= strlenW(wszAccel
);
3848 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3855 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3860 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
3862 *pIDButton
= btnPtr
->idCommand
;
3874 TOOLBAR_MarkButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fMark
)
3878 TBUTTON_INFO
*btnPtr
;
3880 TRACE("hwnd = %p, Id = %d, fMark = 0%d\n", infoPtr
->hwndSelf
, Id
, fMark
);
3882 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3886 btnPtr
= &infoPtr
->buttons
[nIndex
];
3887 oldState
= btnPtr
->fsState
;
3890 btnPtr
->fsState
|= TBSTATE_MARKED
;
3892 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
3894 if(oldState
!= btnPtr
->fsState
)
3895 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3901 /* fixes up an index of a button affected by a move */
3902 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
3906 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
3908 else if (*pIndex
== nIndex
)
3909 *pIndex
= nMoveIndex
;
3913 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
3915 else if (*pIndex
== nIndex
)
3916 *pIndex
= nMoveIndex
;
3922 TOOLBAR_MoveButton (TOOLBAR_INFO
*infoPtr
, INT Id
, INT nMoveIndex
)
3926 TBUTTON_INFO button
;
3928 TRACE("hwnd=%p, Id=%d, nMoveIndex=%d\n", infoPtr
->hwndSelf
, Id
, nMoveIndex
);
3930 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, TRUE
);
3931 if ((nIndex
== -1) || (nMoveIndex
< 0))
3934 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
3935 nMoveIndex
= infoPtr
->nNumButtons
- 1;
3937 button
= infoPtr
->buttons
[nIndex
];
3939 /* move button right */
3940 if (nIndex
< nMoveIndex
)
3942 nCount
= nMoveIndex
- nIndex
;
3943 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
3944 infoPtr
->buttons
[nMoveIndex
] = button
;
3946 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
3947 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
3948 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
3949 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
3951 else if (nIndex
> nMoveIndex
) /* move button left */
3953 nCount
= nIndex
- nMoveIndex
;
3954 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
3955 infoPtr
->buttons
[nMoveIndex
] = button
;
3957 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
3958 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
3959 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
3960 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
3963 TOOLBAR_LayoutToolbar(infoPtr
);
3964 TOOLBAR_AutoSize(infoPtr
);
3965 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
3972 TOOLBAR_PressButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fPress
)
3974 TBUTTON_INFO
*btnPtr
;
3978 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3982 btnPtr
= &infoPtr
->buttons
[nIndex
];
3983 oldState
= btnPtr
->fsState
;
3986 btnPtr
->fsState
|= TBSTATE_PRESSED
;
3988 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
3990 if(oldState
!= btnPtr
->fsState
)
3991 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3996 /* FIXME: there might still be some confusion her between number of buttons
3997 * and number of bitmaps */
3999 TOOLBAR_ReplaceBitmap (TOOLBAR_INFO
*infoPtr
, const TBREPLACEBITMAP
*lpReplace
)
4002 int i
= 0, nOldButtons
= 0, pos
= 0;
4003 int nOldBitmaps
, nNewBitmaps
= 0;
4004 HIMAGELIST himlDef
= 0;
4006 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4007 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
4008 lpReplace
->nButtons
);
4010 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4012 FIXME("changing standard bitmaps not implemented\n");
4015 else if (lpReplace
->hInstOld
!= 0 && lpReplace
->hInstOld
!= lpReplace
->hInstNew
)
4016 FIXME("resources not in the current module not implemented\n");
4018 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4019 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4020 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4021 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4022 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4024 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4025 nOldButtons
= tbi
->nButtons
;
4026 tbi
->nButtons
= lpReplace
->nButtons
;
4027 tbi
->hInst
= lpReplace
->hInstNew
;
4028 tbi
->nID
= lpReplace
->nIDNew
;
4029 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4032 pos
+= tbi
->nButtons
;
4035 if (nOldButtons
== 0)
4037 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4041 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4044 if (lpReplace
->hInstNew
)
4045 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4047 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4049 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4050 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4052 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4054 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4055 ImageList_Remove(himlDef
, i
);
4059 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4060 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4061 DeleteObject(hBitmap
);
4064 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4066 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4067 pos
, nOldBitmaps
, nNewBitmaps
);
4069 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4074 /* helper for TOOLBAR_SaveRestoreW */
4076 TOOLBAR_Save(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*params
)
4080 BOOL alloced
= FALSE
;
4083 TRACE( "save to %s %s\n", debugstr_w(params
->pszSubKey
), debugstr_w(params
->pszValueName
) );
4085 memset( &save
, 0, sizeof(save
) );
4086 save
.cbData
= infoPtr
->nNumButtons
* sizeof(DWORD
);
4088 save
.cButtons
= infoPtr
->nNumButtons
;
4089 save
.tbButton
.idCommand
= -1;
4090 TOOLBAR_SendNotify( &save
.hdr
, infoPtr
, TBN_SAVE
);
4094 save
.pData
= Alloc( save
.cbData
);
4095 if (!save
.pData
) return FALSE
;
4098 if (!save
.pCurrent
) save
.pCurrent
= save
.pData
;
4100 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4103 save
.tbButton
.iBitmap
= infoPtr
->buttons
[i
].iBitmap
;
4104 save
.tbButton
.idCommand
= infoPtr
->buttons
[i
].idCommand
;
4105 save
.tbButton
.fsState
= infoPtr
->buttons
[i
].fsState
;
4106 save
.tbButton
.fsStyle
= infoPtr
->buttons
[i
].fsStyle
;
4107 memset( save
.tbButton
.bReserved
, 0, sizeof(save
.tbButton
.bReserved
) );
4108 save
.tbButton
.dwData
= infoPtr
->buttons
[i
].dwData
;
4109 save
.tbButton
.iString
= infoPtr
->buttons
[i
].iString
;
4111 *save
.pCurrent
++ = save
.tbButton
.idCommand
;
4113 TOOLBAR_SendNotify( &save
.hdr
, infoPtr
, TBN_SAVE
);
4116 ret
= RegCreateKeyW( params
->hkr
, params
->pszSubKey
, &key
);
4117 if (ret
== ERROR_SUCCESS
)
4119 ret
= RegSetValueExW( key
, params
->pszValueName
, 0, REG_BINARY
, (BYTE
*)save
.pData
, save
.cbData
);
4123 if (alloced
) Free( save
.pData
);
4128 /* helper for TOOLBAR_Restore */
4130 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4134 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4136 free_string( infoPtr
->buttons
+ i
);
4137 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4140 Free(infoPtr
->buttons
);
4141 infoPtr
->buttons
= NULL
;
4142 infoPtr
->nNumButtons
= 0;
4146 /* helper for TOOLBAR_SaveRestoreW */
4148 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4158 /* restore toolbar information */
4159 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4160 debugstr_w(lpSave
->pszValueName
));
4162 memset(&nmtbr
, 0, sizeof(nmtbr
));
4164 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4165 KEY_QUERY_VALUE
, &hkey
);
4167 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4169 if (!res
&& dwType
!= REG_BINARY
)
4170 res
= ERROR_FILE_NOT_FOUND
;
4173 nmtbr
.pData
= Alloc(dwSize
);
4174 nmtbr
.cbData
= dwSize
;
4175 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4178 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4179 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4182 nmtbr
.pCurrent
= nmtbr
.pData
;
4184 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4185 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4187 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4189 INT i
, count
= nmtbr
.cButtons
;
4191 /* remove all existing buttons as this function is designed to
4192 * restore the toolbar to a previously saved state */
4193 TOOLBAR_DeleteAllButtons(infoPtr
);
4195 for (i
= 0; i
< count
; i
++)
4198 nmtbr
.tbButton
.iBitmap
= -1;
4199 nmtbr
.tbButton
.fsState
= 0;
4200 nmtbr
.tbButton
.fsStyle
= 0;
4201 nmtbr
.tbButton
.dwData
= 0;
4202 nmtbr
.tbButton
.iString
= 0;
4204 if (*nmtbr
.pCurrent
& 0x80000000)
4207 nmtbr
.tbButton
.iBitmap
= SEPARATOR_WIDTH
;
4208 nmtbr
.tbButton
.idCommand
= 0;
4209 nmtbr
.tbButton
.fsStyle
= BTNS_SEP
;
4210 if (*nmtbr
.pCurrent
!= (DWORD
)-1)
4211 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4214 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4218 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4220 /* All returned ptrs and -1 are ignored */
4221 if (!IS_INTRESOURCE(nmtbr
.tbButton
.iString
))
4222 nmtbr
.tbButton
.iString
= 0;
4224 TOOLBAR_InsertButtonT(infoPtr
, -1, &nmtbr
.tbButton
, TRUE
);
4227 TOOLBAR_SendNotify( &hdr
, infoPtr
, TBN_BEGINADJUST
);
4233 UINT code
= infoPtr
->bUnicode
? TBN_GETBUTTONINFOW
: TBN_GETBUTTONINFOA
;
4236 memset( &tb
, 0, sizeof(tb
) );
4238 tb
.cchText
= sizeof(buf
) / sizeof(buf
[0]);
4241 /* Use the same struct for both A and W versions since the layout is the same. */
4242 if (!TOOLBAR_SendNotify( &tb
.hdr
, infoPtr
, code
))
4245 idx
= TOOLBAR_GetButtonIndex( infoPtr
, tb
.tbButton
.idCommand
, FALSE
);
4246 if (idx
== -1) continue;
4248 /* tb.pszText is ignored - the string comes from tb.tbButton.iString, which may
4249 be an index or a ptr. Either way it is simply copied. There is no api to change
4250 the string index, so we set it manually. The other properties can be set with SetButtonInfo. */
4251 free_string( infoPtr
->buttons
+ idx
);
4252 infoPtr
->buttons
[idx
].iString
= tb
.tbButton
.iString
;
4254 memset( &bi
, 0, sizeof(bi
) );
4255 bi
.cbSize
= sizeof(bi
);
4256 bi
.dwMask
= TBIF_IMAGE
| TBIF_STATE
| TBIF_STYLE
| TBIF_LPARAM
;
4257 bi
.iImage
= tb
.tbButton
.iBitmap
;
4258 bi
.fsState
= tb
.tbButton
.fsState
;
4259 bi
.fsStyle
= tb
.tbButton
.fsStyle
;
4260 bi
.lParam
= tb
.tbButton
.dwData
;
4262 TOOLBAR_SetButtonInfo( infoPtr
, tb
.tbButton
.idCommand
, &bi
, TRUE
);
4264 TOOLBAR_SendNotify( &hdr
, infoPtr
, TBN_ENDADJUST
);
4266 /* remove all uninitialised buttons
4267 * note: loop backwards to avoid having to fixup i on a
4269 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4270 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4271 TOOLBAR_DeleteButton(infoPtr
, i
);
4273 /* only indicate success if at least one button survived */
4274 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4285 TOOLBAR_SaveRestoreW (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4287 if (lpSave
== NULL
) return 0;
4290 return TOOLBAR_Save(infoPtr
, lpSave
);
4292 return TOOLBAR_Restore(infoPtr
, lpSave
);
4297 TOOLBAR_SaveRestoreA (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4299 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4300 TBSAVEPARAMSW SaveW
;
4304 if (lpSave
== NULL
) return 0;
4306 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4307 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4308 if (!pszSubKey
) goto exit
;
4309 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4311 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4312 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4313 if (!pszValueName
) goto exit
;
4314 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4316 SaveW
.pszValueName
= pszValueName
;
4317 SaveW
.pszSubKey
= pszSubKey
;
4318 SaveW
.hkr
= lpSave
->hkr
;
4319 result
= TOOLBAR_SaveRestoreW(infoPtr
, wParam
, &SaveW
);
4322 Free (pszValueName
);
4330 TOOLBAR_SetAnchorHighlight (TOOLBAR_INFO
*infoPtr
, BOOL bAnchor
)
4332 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4334 TRACE("hwnd=%p, bAnchor = %s\n", infoPtr
->hwndSelf
, bAnchor
? "TRUE" : "FALSE");
4336 infoPtr
->bAnchor
= bAnchor
;
4338 /* Native does not remove the hot effect from an already hot button */
4340 return (LRESULT
)bOldAnchor
;
4345 TOOLBAR_SetBitmapSize (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4347 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4348 short width
= (short)LOWORD(lParam
);
4349 short height
= (short)HIWORD(lParam
);
4351 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", infoPtr
->hwndSelf
, wParam
, lParam
);
4354 FIXME("wParam is %ld. Perhaps image list index?\n", wParam
);
4356 /* 0 width or height is changed to 1 */
4362 if (infoPtr
->nNumButtons
> 0)
4363 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4364 infoPtr
->nNumButtons
,
4365 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
, width
, height
);
4367 if (width
< -1 || height
< -1)
4369 /* Windows destroys the imagelist and seems to actually use negative
4370 * values to compute button sizes */
4371 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width
, height
);
4375 /* width or height of -1 means no change */
4377 infoPtr
->nBitmapWidth
= width
;
4379 infoPtr
->nBitmapHeight
= height
;
4381 if ((himlDef
== infoPtr
->himlInt
) &&
4382 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4384 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4385 infoPtr
->nBitmapHeight
);
4388 TOOLBAR_CalcToolbar(infoPtr
);
4389 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4395 TOOLBAR_SetButtonInfo (TOOLBAR_INFO
*infoPtr
, INT Id
,
4396 const TBBUTTONINFOW
*lptbbi
, BOOL isW
)
4398 TBUTTON_INFO
*btnPtr
;
4404 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4407 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lptbbi
->dwMask
& TBIF_BYINDEX
);
4411 btnPtr
= &infoPtr
->buttons
[nIndex
];
4412 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4413 btnPtr
->idCommand
= lptbbi
->idCommand
;
4414 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4415 btnPtr
->iBitmap
= lptbbi
->iImage
;
4416 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4417 btnPtr
->dwData
= lptbbi
->lParam
;
4418 if (lptbbi
->dwMask
& TBIF_SIZE
)
4419 btnPtr
->cx
= lptbbi
->cx
;
4420 if (lptbbi
->dwMask
& TBIF_STATE
)
4421 btnPtr
->fsState
= lptbbi
->fsState
;
4422 if (lptbbi
->dwMask
& TBIF_STYLE
)
4423 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4425 if (lptbbi
->dwMask
& TBIF_TEXT
)
4426 set_stringT( btnPtr
, lptbbi
->pszText
, isW
);
4428 /* save the button rect to see if we need to redraw the whole toolbar */
4429 oldBtnRect
= btnPtr
->rect
;
4430 TOOLBAR_LayoutToolbar(infoPtr
);
4432 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4433 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4435 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4442 TOOLBAR_SetButtonSize (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4444 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4445 int top
= default_top_margin(infoPtr
);
4447 if ((cx
< 0) || (cy
< 0))
4449 ERR("invalid parameter 0x%08x\n", (DWORD
)lParam
);
4453 TRACE("%p, cx = %d, cy = %d\n", infoPtr
->hwndSelf
, cx
, cy
);
4455 /* The documentation claims you can only change the button size before
4456 * any button has been added. But this is wrong.
4457 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4458 * it to the toolbar, and it checks that the return value is nonzero - mjm
4459 * Further testing shows that we must actually perform the change too.
4462 * The documentation also does not mention that if 0 is supplied for
4463 * either size, the system changes it to the default of 24 wide and
4464 * 22 high. Demonstrated in ControlSpy Toolbar. GLA 3/02
4466 if (cx
== 0) cx
= 24;
4467 if (cy
== 0) cy
= 22;
4469 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4470 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4472 if (cx
!= infoPtr
->nButtonWidth
|| cy
!= infoPtr
->nButtonHeight
||
4473 top
!= infoPtr
->iTopMargin
)
4475 infoPtr
->nButtonWidth
= cx
;
4476 infoPtr
->nButtonHeight
= cy
;
4477 infoPtr
->iTopMargin
= top
;
4479 TOOLBAR_LayoutToolbar( infoPtr
);
4480 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
4487 TOOLBAR_SetButtonWidth (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4489 /* if setting to current values, ignore */
4490 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4491 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4492 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4493 infoPtr
->cxMin
, infoPtr
->cxMax
);
4497 /* save new values */
4498 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4499 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4501 /* otherwise we need to recalc the toolbar and in some cases
4502 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4503 which doesn't actually draw - GA). */
4504 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4505 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4507 TOOLBAR_CalcToolbar (infoPtr
);
4509 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
4516 TOOLBAR_SetCmdId (TOOLBAR_INFO
*infoPtr
, INT nIndex
, INT nId
)
4518 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4521 infoPtr
->buttons
[nIndex
].idCommand
= nId
;
4523 if (infoPtr
->hwndToolTip
) {
4525 FIXME("change tool tip!\n");
4534 TOOLBAR_SetDisabledImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4536 HIMAGELIST himlTemp
;
4539 if (infoPtr
->iVersion
>= 5)
4542 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4543 &infoPtr
->cimlDis
, himl
, id
);
4545 /* FIXME: redraw ? */
4547 return (LRESULT
)himlTemp
;
4552 TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4556 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", infoPtr
->hwndSelf
, (DWORD
)wParam
, (DWORD
)lParam
);
4558 dwTemp
= infoPtr
->dwDTFlags
;
4559 infoPtr
->dwDTFlags
=
4560 (infoPtr
->dwDTFlags
& (DWORD
)wParam
) | (DWORD
)lParam
;
4562 return (LRESULT
)dwTemp
;
4565 /* This function differs a bit from what MSDN says it does:
4566 * 1. lParam contains extended style flags to OR with current style
4567 * (MSDN isn't clear on the OR bit)
4568 * 2. wParam appears to contain extended style flags to be reset
4569 * (MSDN says that this parameter is reserved)
4572 TOOLBAR_SetExtendedStyle (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD style
)
4574 DWORD old_style
= infoPtr
->dwExStyle
;
4576 TRACE("mask=0x%08x, style=0x%08x\n", mask
, style
);
4579 infoPtr
->dwExStyle
= (old_style
& ~mask
) | (style
& mask
);
4581 infoPtr
->dwExStyle
= style
;
4583 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4584 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4585 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4587 if ((old_style
^ infoPtr
->dwExStyle
) & TBSTYLE_EX_MIXEDBUTTONS
)
4588 TOOLBAR_CalcToolbar(infoPtr
);
4590 TOOLBAR_LayoutToolbar(infoPtr
);
4592 TOOLBAR_AutoSize(infoPtr
);
4593 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4600 TOOLBAR_SetHotImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4602 HIMAGELIST himlTemp
;
4605 if (infoPtr
->iVersion
>= 5)
4608 TRACE("hwnd = %p, himl = %p, id = %d\n", infoPtr
->hwndSelf
, himl
, id
);
4610 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4611 &infoPtr
->cimlHot
, himl
, id
);
4613 /* FIXME: redraw ? */
4615 return (LRESULT
)himlTemp
;
4619 /* Makes previous hot button no longer hot, makes the specified
4620 * button hot and sends appropriate notifications. dwReason is one or
4621 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4622 * NOTE 1: this function does not validate nHit
4623 * NOTE 2: the name of this function is completely made up and
4624 * not based on any documentation from Microsoft. */
4626 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4628 if (infoPtr
->nHotItem
!= nHit
)
4630 NMTBHOTITEM nmhotitem
;
4631 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4633 nmhotitem
.dwFlags
= dwReason
;
4634 if(infoPtr
->nHotItem
>= 0)
4636 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4637 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4641 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4642 nmhotitem
.idOld
= 0;
4647 btnPtr
= &infoPtr
->buttons
[nHit
];
4648 nmhotitem
.idNew
= btnPtr
->idCommand
;
4652 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4653 nmhotitem
.idNew
= 0;
4656 /* now change the hot and invalidate the old and new buttons - if the
4658 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4661 oldBtnPtr
->bHot
= FALSE
;
4662 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4664 /* setting disabled buttons as hot fails even if the notify contains the button id */
4665 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4666 btnPtr
->bHot
= TRUE
;
4667 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4668 infoPtr
->nHotItem
= nHit
;
4671 infoPtr
->nHotItem
= -1;
4677 TOOLBAR_SetHotItem (TOOLBAR_INFO
*infoPtr
, INT nHotItem
)
4679 INT nOldHotItem
= infoPtr
->nHotItem
;
4681 TRACE("hwnd = %p, nHotItem = %d\n", infoPtr
->hwndSelf
, nHotItem
);
4683 if (nHotItem
>= infoPtr
->nNumButtons
)
4684 return infoPtr
->nHotItem
;
4689 /* NOTE: an application can still remove the hot item even if anchor
4690 * highlighting is enabled */
4692 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, HICF_OTHER
);
4694 if (nOldHotItem
< 0)
4697 return (LRESULT
)nOldHotItem
;
4702 TOOLBAR_SetImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4704 HIMAGELIST himlTemp
;
4705 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4706 INT oldBitmapWidth
= infoPtr
->nBitmapWidth
;
4707 INT oldBitmapHeight
= infoPtr
->nBitmapHeight
;
4710 if (infoPtr
->iVersion
>= 5)
4713 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4714 &infoPtr
->cimlDef
, himl
, id
);
4716 infoPtr
->nNumBitmaps
= 0;
4717 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4718 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4720 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4721 &infoPtr
->nBitmapHeight
))
4723 infoPtr
->nBitmapWidth
= 1;
4724 infoPtr
->nBitmapHeight
= 1;
4726 if ((oldBitmapWidth
!= infoPtr
->nBitmapWidth
) || (oldBitmapHeight
!= infoPtr
->nBitmapHeight
))
4728 TOOLBAR_CalcToolbar(infoPtr
);
4729 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4730 TOOLBAR_SetButtonSize(infoPtr
, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4733 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4734 infoPtr
->hwndSelf
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4735 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4737 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4739 return (LRESULT
)himlTemp
;
4744 TOOLBAR_SetIndent (TOOLBAR_INFO
*infoPtr
, INT nIndent
)
4746 infoPtr
->nIndent
= nIndent
;
4750 /* process only on indent changing */
4751 if(infoPtr
->nIndent
!= nIndent
)
4753 infoPtr
->nIndent
= nIndent
;
4754 TOOLBAR_CalcToolbar (infoPtr
);
4755 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4763 TOOLBAR_SetInsertMark (TOOLBAR_INFO
*infoPtr
, const TBINSERTMARK
*lptbim
)
4765 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", infoPtr
->hwndSelf
, lptbim
->iButton
, lptbim
->dwFlags
);
4767 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4769 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4773 if ((lptbim
->iButton
== -1) ||
4774 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4775 (lptbim
->iButton
>= 0)))
4777 infoPtr
->tbim
= *lptbim
;
4778 /* FIXME: don't need to update entire toolbar */
4779 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4782 ERR("Invalid button index %d\n", lptbim
->iButton
);
4789 TOOLBAR_SetInsertMarkColor (TOOLBAR_INFO
*infoPtr
, COLORREF clr
)
4791 infoPtr
->clrInsertMark
= clr
;
4793 /* FIXME: don't need to update entire toolbar */
4794 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4801 TOOLBAR_SetMaxTextRows (TOOLBAR_INFO
*infoPtr
, INT nMaxRows
)
4803 infoPtr
->nMaxTextRows
= nMaxRows
;
4805 TOOLBAR_CalcToolbar(infoPtr
);
4810 /* MSDN gives slightly wrong info on padding.
4811 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4812 * 2. It is not used to create a blank area between the edge of the button
4813 * and the text or image if TBSTYLE_LIST is set. It is used to control
4814 * the gap between the image and text.
4815 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4816 * to control the bottom and right borders [with the border being
4817 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4818 * is shared evenly on both sides of the button.
4819 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4822 TOOLBAR_SetPadding (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4826 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4827 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4828 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4829 TRACE("cx=%d, cy=%d\n",
4830 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4831 return (LRESULT
) oldPad
;
4836 TOOLBAR_SetParent (TOOLBAR_INFO
*infoPtr
, HWND hParent
)
4842 hwndOldNotify
= infoPtr
->hwndNotify
;
4843 infoPtr
->hwndNotify
= hParent
;
4845 return (LRESULT
)hwndOldNotify
;
4850 TOOLBAR_SetRows (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPRECT lprc
)
4852 int rows
= LOWORD(wParam
);
4853 BOOL bLarger
= HIWORD(wParam
);
4857 TRACE("Setting rows to %d (%d)\n", rows
, bLarger
);
4859 if(infoPtr
->nRows
!= rows
)
4861 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
;
4862 int curColumn
= 0; /* Current column */
4863 int curRow
= 0; /* Current row */
4864 int hidden
= 0; /* Number of hidden buttons */
4865 int seps
= 0; /* Number of separators */
4866 int idealWrap
= 0; /* Ideal wrap point */
4871 Calculate new size and wrap points - Under windows, setrows will
4872 change the dimensions if needed to show the number of requested
4873 rows (if CCS_NORESIZE is set), or will take up the whole window
4874 (if no CCS_NORESIZE).
4876 Basic algorithm - If N buttons, and y rows requested, each row
4877 contains N/y buttons.
4879 FIXME: Handling of separators not obvious from testing results
4880 FIXME: Take width of window into account?
4883 /* Loop through the buttons one by one counting key items */
4884 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4886 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
4887 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4889 else if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
4893 /* FIXME: Separators make this quite complex */
4894 if (seps
) FIXME("Separators unhandled\n");
4896 /* Round up so more per line, i.e., less rows */
4897 idealWrap
= (infoPtr
->nNumButtons
- hidden
+ (rows
-1)) / (rows
? rows
: 1);
4899 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4900 achieve the requested number of rows. */
4901 if (bLarger
&& idealWrap
> 1)
4903 int resRows
= (infoPtr
->nNumButtons
+ (idealWrap
-1)) / idealWrap
;
4904 int moreRows
= (infoPtr
->nNumButtons
+ (idealWrap
-2)) / (idealWrap
-1);
4906 if (resRows
< rows
&& moreRows
> rows
)
4909 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap
);
4913 curColumn
= curRow
= 0;
4915 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap
,
4916 infoPtr
->nNumButtons
, hidden
, rows
);
4918 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4920 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4923 /* Step on, wrap if necessary or flag next to wrap */
4932 if (curColumn
> (idealWrap
-1)) {
4934 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
4938 TRACE("Result - %d rows\n", curRow
+ 1);
4940 /* recalculate toolbar */
4941 TOOLBAR_CalcToolbar (infoPtr
);
4943 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
4944 if NORESIZE is NOT set, then the toolbar will always be resized to
4945 take up the whole window. With it set, sizing needs to be manual. */
4946 if (infoPtr
->dwStyle
& CCS_NORESIZE
) {
4947 SetWindowPos(infoPtr
->hwndSelf
, NULL
, 0, 0,
4948 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
4949 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
,
4950 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
4953 /* repaint toolbar */
4954 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4957 /* return bounding rectangle */
4959 lprc
->left
= infoPtr
->rcBound
.left
;
4960 lprc
->right
= infoPtr
->rcBound
.right
;
4961 lprc
->top
= infoPtr
->rcBound
.top
;
4962 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
4970 TOOLBAR_SetState (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
4972 TBUTTON_INFO
*btnPtr
;
4975 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
4979 btnPtr
= &infoPtr
->buttons
[nIndex
];
4981 /* if hidden state has changed the invalidate entire window and recalc */
4982 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
4983 btnPtr
->fsState
= LOWORD(lParam
);
4984 TOOLBAR_CalcToolbar (infoPtr
);
4985 InvalidateRect(infoPtr
->hwndSelf
, 0, TRUE
);
4989 /* process state changing if current state doesn't match new state */
4990 if(btnPtr
->fsState
!= LOWORD(lParam
))
4992 btnPtr
->fsState
= LOWORD(lParam
);
4993 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4999 static inline void unwrap(TOOLBAR_INFO
*info
)
5003 for (i
= 0; i
< info
->nNumButtons
; i
++)
5004 info
->buttons
[i
].fsState
&= ~TBSTATE_WRAP
;
5008 TOOLBAR_SetStyle (TOOLBAR_INFO
*infoPtr
, DWORD style
)
5010 DWORD dwOldStyle
= infoPtr
->dwStyle
;
5012 TRACE("new style 0x%08x\n", style
);
5014 if (style
& TBSTYLE_LIST
)
5015 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
5017 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
5019 infoPtr
->dwStyle
= style
;
5020 TOOLBAR_CheckStyle(infoPtr
);
5022 if ((dwOldStyle
^ style
) & TBSTYLE_WRAPABLE
)
5024 if (dwOldStyle
& TBSTYLE_WRAPABLE
)
5026 TOOLBAR_CalcToolbar(infoPtr
);
5028 else if ((dwOldStyle
^ style
) & CCS_VERT
)
5029 TOOLBAR_LayoutToolbar(infoPtr
);
5031 /* only resize if one of the CCS_* styles was changed */
5032 if ((dwOldStyle
^ style
) & COMMON_STYLES
)
5034 TOOLBAR_AutoSize(infoPtr
);
5035 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5042 static inline LRESULT
5043 TOOLBAR_SetToolTips (TOOLBAR_INFO
*infoPtr
, HWND hwndTooltip
)
5045 TRACE("hwnd=%p, hwndTooltip=%p\n", infoPtr
->hwndSelf
, hwndTooltip
);
5047 infoPtr
->hwndToolTip
= hwndTooltip
;
5053 TOOLBAR_SetUnicodeFormat (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
5057 TRACE("%s hwnd=%p\n",
5058 ((BOOL
)wParam
) ? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
5060 bTemp
= infoPtr
->bUnicode
;
5061 infoPtr
->bUnicode
= (BOOL
)wParam
;
5068 TOOLBAR_GetColorScheme (const TOOLBAR_INFO
*infoPtr
, LPCOLORSCHEME lParam
)
5070 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
5071 comctl32_color
.clrBtnHighlight
:
5072 infoPtr
->clrBtnHighlight
;
5073 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
5074 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
5080 TOOLBAR_SetColorScheme (TOOLBAR_INFO
*infoPtr
, const COLORSCHEME
*lParam
)
5082 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5083 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
5084 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
5086 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
5087 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
5088 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5094 TOOLBAR_SetVersion (TOOLBAR_INFO
*infoPtr
, INT iVersion
)
5096 INT iOldVersion
= infoPtr
->iVersion
;
5098 infoPtr
->iVersion
= iVersion
;
5100 if (infoPtr
->iVersion
>= 5)
5101 TOOLBAR_SetUnicodeFormat(infoPtr
, TRUE
);
5108 TOOLBAR_GetStringA (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPSTR str
)
5110 WORD iString
= HIWORD(wParam
);
5111 WORD buffersize
= LOWORD(wParam
);
5114 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, buffersize
, str
);
5116 if (iString
< infoPtr
->nNumStrings
)
5118 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
5121 TRACE("returning %s\n", debugstr_a(str
));
5124 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5131 TOOLBAR_GetStringW (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPWSTR str
)
5133 WORD iString
= HIWORD(wParam
);
5134 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5137 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, LOWORD(wParam
), str
);
5139 if (iString
< infoPtr
->nNumStrings
)
5141 len
= min(len
, strlenW(infoPtr
->strings
[iString
]));
5142 ret
= (len
+1)*sizeof(WCHAR
);
5145 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5150 TRACE("returning %s\n", debugstr_w(str
));
5153 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5158 static LRESULT
TOOLBAR_SetBoundingSize(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5160 SIZE
* pSize
= (SIZE
*)lParam
;
5161 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5165 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5166 * caller to specify a reason why the hot item changed (rather than just the
5167 * HICF_OTHER that TB_SETHOTITEM sends). */
5169 TOOLBAR_SetHotItem2 (TOOLBAR_INFO
*infoPtr
, INT nHotItem
, LPARAM lParam
)
5171 INT nOldHotItem
= infoPtr
->nHotItem
;
5173 TRACE("old item=%d, new item=%d, flags=%08x\n",
5174 nOldHotItem
, nHotItem
, (DWORD
)lParam
);
5176 if (nHotItem
< 0 || nHotItem
> infoPtr
->nNumButtons
)
5179 /* NOTE: an application can still remove the hot item even if anchor
5180 * highlighting is enabled */
5182 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, lParam
);
5184 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5187 /* Sets the toolbar global iListGap parameter which controls the amount of
5188 * spacing between the image and the text of buttons for TBSTYLE_LIST
5190 static LRESULT
TOOLBAR_SetListGap(TOOLBAR_INFO
*infoPtr
, INT iListGap
)
5192 TRACE("hwnd=%p iListGap=%d\n", infoPtr
->hwndSelf
, iListGap
);
5194 infoPtr
->iListGap
= iListGap
;
5196 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5201 /* Returns the number of maximum number of image lists associated with the
5202 * various states. */
5203 static LRESULT
TOOLBAR_GetImageListCount(const TOOLBAR_INFO
*infoPtr
)
5205 TRACE("hwnd=%p\n", infoPtr
->hwndSelf
);
5207 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5211 TOOLBAR_GetIdealSize (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5213 LPSIZE lpsize
= (LPSIZE
)lParam
;
5219 * Testing shows the following:
5220 * wParam = 0 adjust cx value
5221 * = 1 set cy value to max size.
5222 * lParam pointer to SIZE structure
5225 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5226 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5230 if (lpsize
->cx
== -1) {
5231 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5233 else if(HIWORD(lpsize
->cx
)) {
5235 HWND hwndParent
= GetParent(infoPtr
->hwndSelf
);
5237 GetWindowRect(infoPtr
->hwndSelf
, &rc
);
5238 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5239 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc
));
5240 lpsize
->cx
= max(rc
.right
-rc
.left
,
5241 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5244 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5248 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5251 FIXME("Unknown wParam %ld\n", wParam
);
5254 TRACE("set to -> 0x%08x 0x%08x\n",
5255 lpsize
->cx
, lpsize
->cy
);
5259 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5261 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5263 InvalidateRect(hwnd
, NULL
, TRUE
);
5269 TOOLBAR_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
5271 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
5274 TRACE("hwnd = %p, style=0x%08x\n", hwnd
, lpcs
->style
);
5276 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5277 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5278 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5279 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_REQUERY
));
5280 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5282 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5283 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5285 OpenThemeData (hwnd
, themeClass
);
5287 TOOLBAR_CheckStyle (infoPtr
);
5294 TOOLBAR_Destroy (TOOLBAR_INFO
*infoPtr
)
5298 /* delete tooltip control */
5299 if (infoPtr
->hwndToolTip
)
5300 DestroyWindow (infoPtr
->hwndToolTip
);
5302 /* delete temporary buffer for tooltip text */
5303 Free (infoPtr
->pszTooltipText
);
5304 Free (infoPtr
->bitmaps
); /* bitmaps list */
5306 /* delete button data */
5307 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5308 free_string( infoPtr
->buttons
+ i
);
5309 Free (infoPtr
->buttons
);
5311 /* delete strings */
5312 if (infoPtr
->strings
) {
5313 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5314 Free (infoPtr
->strings
[i
]);
5316 Free (infoPtr
->strings
);
5319 /* destroy internal image list */
5320 if (infoPtr
->himlInt
)
5321 ImageList_Destroy (infoPtr
->himlInt
);
5323 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5324 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5325 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5327 /* delete default font */
5328 DeleteObject (infoPtr
->hDefaultFont
);
5330 CloseThemeData (GetWindowTheme (infoPtr
->hwndSelf
));
5332 /* free toolbar info data */
5333 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
5341 TOOLBAR_EraseBackground (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5343 NMTBCUSTOMDRAW tbcd
;
5346 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
5347 DWORD dwEraseCustDraw
= 0;
5349 /* the app has told us not to redraw the toolbar */
5350 if (!infoPtr
->bDoRedraw
)
5353 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5354 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5355 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5356 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5357 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5358 dwEraseCustDraw
= ntfret
& 0xffff;
5360 /* FIXME: in general the return flags *can* be or'ed together */
5361 switch (dwEraseCustDraw
)
5363 case CDRF_DODEFAULT
:
5365 case CDRF_SKIPDEFAULT
:
5368 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5369 infoPtr
->hwndSelf
, ntfret
);
5373 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5374 * to my parent for processing.
5376 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5378 HDC hdc
= (HDC
)wParam
;
5383 parent
= GetParent(infoPtr
->hwndSelf
);
5384 MapWindowPoints(infoPtr
->hwndSelf
, parent
, &pt
, 1);
5385 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5386 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5387 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5390 ret
= DefWindowProcW (infoPtr
->hwndSelf
, WM_ERASEBKGND
, wParam
, lParam
);
5392 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5393 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5394 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5395 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5396 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5397 dwEraseCustDraw
= ntfret
& 0xffff;
5398 switch (dwEraseCustDraw
)
5400 case CDRF_DODEFAULT
:
5402 case CDRF_SKIPDEFAULT
:
5405 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5406 infoPtr
->hwndSelf
, ntfret
);
5413 static inline LRESULT
5414 TOOLBAR_GetFont (const TOOLBAR_INFO
*infoPtr
)
5416 return (LRESULT
)infoPtr
->hFont
;
5421 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5424 INT nNewHotItem
= infoPtr
->nHotItem
;
5426 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5429 if ((nNewHotItem
+ iDirection
< 0) ||
5430 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5432 NMTBWRAPHOTITEM nmtbwhi
;
5433 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5434 nmtbwhi
.iDirection
= iDirection
;
5435 nmtbwhi
.dwReason
= dwReason
;
5437 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5441 nNewHotItem
+= iDirection
;
5442 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5444 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5445 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5447 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5454 TOOLBAR_KeyDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5458 nmkey
.nVKey
= (UINT
)wParam
;
5459 nmkey
.uFlags
= HIWORD(lParam
);
5461 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5462 return DefWindowProcW(infoPtr
->hwndSelf
, WM_KEYDOWN
, wParam
, lParam
);
5464 switch ((UINT
)wParam
)
5468 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5472 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5476 if ((infoPtr
->nHotItem
>= 0) &&
5477 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5479 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5480 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5481 (LPARAM
)infoPtr
->hwndSelf
);
5491 TOOLBAR_LButtonDblClk (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5496 pt
.x
= (short)LOWORD(lParam
);
5497 pt
.y
= (short)HIWORD(lParam
);
5498 TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5501 TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
5502 else if (infoPtr
->dwStyle
& CCS_ADJUSTABLE
)
5503 TOOLBAR_Customize (infoPtr
);
5510 TOOLBAR_LButtonDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5512 TBUTTON_INFO
*btnPtr
;
5517 BOOL bDragKeyPressed
;
5522 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5523 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5525 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5527 if (infoPtr
->hwndToolTip
)
5528 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5529 WM_LBUTTONDOWN
, wParam
, lParam
);
5531 pt
.x
= (short)LOWORD(lParam
);
5532 pt
.y
= (short)HIWORD(lParam
);
5533 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5537 btnPtr
= &infoPtr
->buttons
[nHit
];
5539 if (bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5541 infoPtr
->nButtonDrag
= nHit
;
5542 SetCapture (infoPtr
->hwndSelf
);
5544 /* If drag cursor has not been loaded, load it.
5545 * Note: it doesn't need to be freed */
5547 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5548 SetCursor(hCursorDrag
);
5553 infoPtr
->nOldHit
= nHit
;
5555 CopyRect(&arrowRect
, &btnPtr
->rect
);
5556 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5558 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5559 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5560 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5561 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5562 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5563 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5567 /* draw in pressed state */
5568 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5569 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5571 btnPtr
->bDropDownPressed
= TRUE
;
5572 RedrawWindow(infoPtr
->hwndSelf
, &btnPtr
->rect
, 0, RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5574 memset(&nmtb
, 0, sizeof(nmtb
));
5575 nmtb
.iItem
= btnPtr
->idCommand
;
5576 nmtb
.rcButton
= btnPtr
->rect
;
5577 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
, TBN_DROPDOWN
);
5578 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5580 if (res
!= TBDDRET_TREATPRESSED
)
5584 /* redraw button in unpressed state */
5585 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5586 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5588 btnPtr
->bDropDownPressed
= FALSE
;
5589 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5591 /* find and set hot item */
5593 ScreenToClient(infoPtr
->hwndSelf
, &pt
);
5594 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5595 if (!infoPtr
->bAnchor
|| button
)
5596 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5598 /* remove any left mouse button down or double-click messages
5599 * so that we can get a toggle effect on the button */
5600 while (PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5601 PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5606 /* otherwise drop through and process as pushed */
5608 infoPtr
->bCaptured
= TRUE
;
5609 infoPtr
->nButtonDown
= nHit
;
5610 infoPtr
->bDragOutSent
= FALSE
;
5612 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5614 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5616 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5617 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5618 UpdateWindow(infoPtr
->hwndSelf
);
5619 SetCapture (infoPtr
->hwndSelf
);
5622 memset(&nmtb
, 0, sizeof(nmtb
));
5623 nmtb
.iItem
= btnPtr
->idCommand
;
5624 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5627 nmmouse
.dwHitInfo
= nHit
;
5629 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5631 nmmouse
.dwItemSpec
= -1;
5634 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5635 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5638 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5641 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5642 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, wParam
, lParam
);
5648 TOOLBAR_LButtonUp (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5650 TBUTTON_INFO
*btnPtr
;
5659 if (infoPtr
->hwndToolTip
)
5660 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5661 WM_LBUTTONUP
, wParam
, lParam
);
5663 pt
.x
= (short)LOWORD(lParam
);
5664 pt
.y
= (short)HIWORD(lParam
);
5665 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5667 if (!infoPtr
->bAnchor
|| button
)
5668 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5670 if (infoPtr
->nButtonDrag
>= 0) {
5674 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5677 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5679 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5680 if (PtInRect(&rcClient
, pt
))
5687 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5690 if (nButton
== infoPtr
->nButtonDrag
)
5692 /* if the button is moved sightly left and we have a
5693 * separator there then remove it */
5694 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5696 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5697 TOOLBAR_DeleteButton(infoPtr
, nButton
- 1);
5699 else /* else insert a separator before the dragged button */
5702 memset(&tbb
, 0, sizeof(tbb
));
5703 tbb
.fsStyle
= BTNS_SEP
;
5705 TOOLBAR_InsertButtonT(infoPtr
, nButton
, &tbb
, TRUE
);
5712 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5713 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, 0);
5715 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5718 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, nButton
);
5723 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5724 TOOLBAR_DeleteButton(infoPtr
, infoPtr
->nButtonDrag
);
5727 /* button under cursor changed so need to re-set hot item */
5728 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5729 infoPtr
->nButtonDrag
= -1;
5731 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5733 else if (infoPtr
->nButtonDown
>= 0) {
5734 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5735 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5737 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5738 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5739 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5741 if ((nOldIndex
!= nHit
) &&
5743 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5744 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5747 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5748 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5750 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5754 if (nOldIndex
!= -1)
5755 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5758 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5759 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5760 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5762 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5764 infoPtr
->nButtonDown
= -1;
5766 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5767 TOOLBAR_SendNotify (&hdr
, infoPtr
,
5768 NM_RELEASEDCAPTURE
);
5770 memset(&nmtb
, 0, sizeof(nmtb
));
5771 nmtb
.iItem
= btnPtr
->idCommand
;
5772 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5775 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5777 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5778 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)infoPtr
->hwndSelf
);
5780 /* In case we have just been destroyed... */
5781 if(!IsWindow(infoPtr
->hwndSelf
))
5786 /* !!! Undocumented - toolbar at 4.71 level and above sends
5787 * NM_CLICK with the NMMOUSE structure. */
5788 nmmouse
.dwHitInfo
= nHit
;
5791 nmmouse
.dwItemSpec
= -1;
5794 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5795 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5798 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5801 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5802 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONUP
, wParam
, lParam
);
5808 TOOLBAR_RButtonUp(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5815 pt
.x
= (short)LOWORD(lParam
);
5816 pt
.y
= (short)HIWORD(lParam
);
5818 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5819 nmmouse
.dwHitInfo
= nHit
;
5822 nmmouse
.dwItemSpec
= -1;
5824 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5825 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5828 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5831 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5832 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONUP
, wParam
, lParam
);
5838 TOOLBAR_RButtonDblClk( TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5842 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5843 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
5849 TOOLBAR_CaptureChanged(TOOLBAR_INFO
*infoPtr
)
5851 TBUTTON_INFO
*btnPtr
;
5853 infoPtr
->bCaptured
= FALSE
;
5855 if (infoPtr
->nButtonDown
>= 0)
5857 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5858 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5860 infoPtr
->nOldHit
= -1;
5862 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5863 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5869 TOOLBAR_MouseLeave (TOOLBAR_INFO
*infoPtr
)
5871 /* don't remove hot effects when in anchor highlighting mode or when a
5872 * drop-down button is pressed */
5873 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
5875 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
5876 if (!hotBtnPtr
->bDropDownPressed
)
5877 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
5880 if (infoPtr
->nOldHit
< 0)
5883 /* If the last button we were over is depressed then make it not */
5884 /* depressed and redraw it */
5885 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
5887 TBUTTON_INFO
*btnPtr
;
5890 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5892 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5895 InflateRect (&rc1
, 1, 1);
5896 InvalidateRect (infoPtr
->hwndSelf
, &rc1
, TRUE
);
5899 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
5902 ZeroMemory(&nmt
, sizeof(nmt
));
5903 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5904 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5905 infoPtr
->bDragOutSent
= TRUE
;
5908 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
5914 TOOLBAR_MouseMove (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5917 TRACKMOUSEEVENT trackinfo
;
5919 TBUTTON_INFO
*btnPtr
;
5922 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
5923 TOOLBAR_TooltipCreateControl(infoPtr
);
5925 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
5926 /* fill in the TRACKMOUSEEVENT struct */
5927 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5928 trackinfo
.dwFlags
= TME_QUERY
;
5930 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5931 _TrackMouseEvent(&trackinfo
);
5933 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5934 if(trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
5935 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5936 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
5938 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5939 /* and can properly deactivate the hot toolbar button */
5940 _TrackMouseEvent(&trackinfo
);
5944 if (infoPtr
->hwndToolTip
)
5945 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5946 WM_MOUSEMOVE
, wParam
, lParam
);
5948 pt
.x
= (short)LOWORD(lParam
);
5949 pt
.y
= (short)HIWORD(lParam
);
5951 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5953 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
5954 && (!infoPtr
->bAnchor
|| button
))
5955 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
);
5957 if (infoPtr
->nOldHit
!= nHit
)
5959 if (infoPtr
->bCaptured
)
5961 if (!infoPtr
->bDragOutSent
)
5964 ZeroMemory(&nmt
, sizeof(nmt
));
5965 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5966 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5967 infoPtr
->bDragOutSent
= TRUE
;
5970 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5971 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
5972 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5973 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5975 else if (nHit
== infoPtr
->nButtonDown
) {
5976 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5977 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5979 infoPtr
->nOldHit
= nHit
;
5987 static inline LRESULT
5988 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5990 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5991 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
5993 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5997 static inline LRESULT
5998 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6000 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
6001 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
6003 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
6008 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
6010 TOOLBAR_INFO
*infoPtr
;
6013 /* allocate memory for info structure */
6014 infoPtr
= Alloc (sizeof(TOOLBAR_INFO
));
6015 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
6018 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
6021 /* initialize info structure */
6022 infoPtr
->nButtonWidth
= 23;
6023 infoPtr
->nButtonHeight
= 22;
6024 infoPtr
->nBitmapHeight
= 16;
6025 infoPtr
->nBitmapWidth
= 16;
6027 infoPtr
->nMaxTextRows
= 1;
6028 infoPtr
->cxMin
= -1;
6029 infoPtr
->cxMax
= -1;
6030 infoPtr
->nNumBitmaps
= 0;
6031 infoPtr
->nNumStrings
= 0;
6033 infoPtr
->bCaptured
= FALSE
;
6034 infoPtr
->nButtonDown
= -1;
6035 infoPtr
->nButtonDrag
= -1;
6036 infoPtr
->nOldHit
= -1;
6037 infoPtr
->nHotItem
= -1;
6038 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
6039 infoPtr
->dwDTFlags
= (lpcs
->style
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
6040 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
6041 infoPtr
->bDragOutSent
= FALSE
;
6042 infoPtr
->iVersion
= 0;
6043 infoPtr
->hwndSelf
= hwnd
;
6044 infoPtr
->bDoRedraw
= TRUE
;
6045 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
6046 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
6047 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
6048 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
6049 infoPtr
->iListGap
= DEFLISTGAP
;
6050 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
6051 infoPtr
->dwStyle
= lpcs
->style
;
6052 infoPtr
->tbim
.iButton
= -1;
6054 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6055 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
6056 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
6057 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
6060 /* I think the code below is a bug, but it is the way that the native
6061 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6062 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6063 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6064 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6065 * Somehow, the only cases of this seem to be MFC programs.
6067 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6068 * does not occur in the WM_STYLECHANGING routine.
6069 * (Guy Albertelli 9/2001)
6072 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6073 && !(lpcs
->style
& TBSTYLE_TRANSPARENT
))
6074 styleadd
|= TBSTYLE_TRANSPARENT
;
6075 if (!(lpcs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
6076 styleadd
|= CCS_TOP
; /* default to top */
6077 SetWindowLongW (hwnd
, GWL_STYLE
, lpcs
->style
| styleadd
);
6080 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
6085 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6087 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
6091 if (dwStyle
& WS_MINIMIZE
)
6092 return 0; /* Nothing to do */
6094 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
6096 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
6099 if (!(dwStyle
& CCS_NODIVIDER
))
6101 GetWindowRect (hwnd
, &rcWindow
);
6102 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
6103 if( dwStyle
& WS_BORDER
)
6104 InflateRect (&rcWindow
, -1, -1);
6105 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6108 ReleaseDC( hwnd
, hdc
);
6114 /* handles requests from the tooltip control on what text to display */
6115 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6117 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6119 TRACE("button index = %d\n", index
);
6121 Free (infoPtr
->pszTooltipText
);
6122 infoPtr
->pszTooltipText
= NULL
;
6127 if (infoPtr
->bUnicode
)
6129 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6130 NMTBGETINFOTIPW tbgit
;
6131 unsigned int len
; /* in chars */
6133 wszBuffer
[0] = '\0';
6134 wszBuffer
[INFOTIPSIZE
] = '\0';
6136 tbgit
.pszText
= wszBuffer
;
6137 tbgit
.cchTextMax
= INFOTIPSIZE
;
6138 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6139 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6141 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6143 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6145 len
= strlenW(tbgit
.pszText
);
6146 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6148 /* need to allocate temporary buffer in infoPtr as there
6149 * isn't enough space in buffer passed to us by the
6150 * tooltip control */
6151 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6152 if (infoPtr
->pszTooltipText
)
6154 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6155 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6161 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6167 CHAR szBuffer
[INFOTIPSIZE
+1];
6168 NMTBGETINFOTIPA tbgit
;
6169 unsigned int len
; /* in chars */
6172 szBuffer
[INFOTIPSIZE
] = '\0';
6174 tbgit
.pszText
= szBuffer
;
6175 tbgit
.cchTextMax
= INFOTIPSIZE
;
6176 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6177 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6179 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6181 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6183 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6184 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]))
6186 /* need to allocate temporary buffer in infoPtr as there
6187 * isn't enough space in buffer passed to us by the
6188 * tooltip control */
6189 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6190 if (infoPtr
->pszTooltipText
)
6192 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6193 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6197 else if (tbgit
.pszText
&& tbgit
.pszText
[0])
6199 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1,
6200 lpnmtdi
->lpszText
, sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]));
6205 /* if button has text, but it is not shown then automatically
6206 * use that text as tooltip */
6207 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6208 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6210 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6211 unsigned int len
= pszText
? strlenW(pszText
) : 0;
6213 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6215 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6217 /* need to allocate temporary buffer in infoPtr as there
6218 * isn't enough space in buffer passed to us by the
6219 * tooltip control */
6220 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6221 if (infoPtr
->pszTooltipText
)
6223 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6224 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6230 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6235 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6237 /* last resort: send notification on to app */
6238 /* FIXME: find out what is really used here */
6239 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmtdi
->hdr
.idFrom
, (LPARAM
)lpnmtdi
);
6243 static inline LRESULT
6244 TOOLBAR_Notify (TOOLBAR_INFO
*infoPtr
, LPNMHDR lpnmh
)
6246 switch (lpnmh
->code
)
6250 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lpnmh
;
6252 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6253 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6254 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6258 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6259 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6267 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lpnmh
;
6269 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6270 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6271 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6272 lppgs
->iScroll
, lppgs
->iDir
);
6276 case TTN_GETDISPINFOW
:
6277 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lpnmh
);
6279 case TTN_GETDISPINFOA
:
6280 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6290 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6294 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam
, lParam
);
6296 if (lParam
== NF_QUERY
)
6299 if (lParam
== NF_REQUERY
) {
6300 format
= SendMessageW(infoPtr
->hwndNotify
,
6301 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6302 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6303 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6314 TOOLBAR_Paint (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6319 /* fill ps.rcPaint with a default rect */
6320 ps
.rcPaint
= infoPtr
->rcBound
;
6322 hdc
= wParam
==0 ? BeginPaint(infoPtr
->hwndSelf
, &ps
) : (HDC
)wParam
;
6324 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps
.rcPaint
));
6326 TOOLBAR_Refresh (infoPtr
, hdc
, &ps
);
6327 if (!wParam
) EndPaint (infoPtr
->hwndSelf
, &ps
);
6334 TOOLBAR_SetFocus (TOOLBAR_INFO
*infoPtr
)
6336 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6338 /* make first item hot */
6339 if (infoPtr
->nNumButtons
> 0)
6340 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6346 TOOLBAR_SetFont(TOOLBAR_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
6348 TRACE("font=%p redraw=%d\n", hFont
, Redraw
);
6351 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6353 infoPtr
->hFont
= hFont
;
6355 TOOLBAR_CalcToolbar(infoPtr
);
6358 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6363 TOOLBAR_SetRedraw (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6364 /*****************************************************
6367 * Handles the WM_SETREDRAW message.
6370 * According to testing V4.71 of COMCTL32 returns the
6371 * *previous* status of the redraw flag (either 0 or 1)
6372 * instead of the MSDN documented value of 0 if handled.
6373 * (For laughs see the "consistency" with same function
6376 *****************************************************/
6378 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6380 TRACE("set to %s\n",
6381 (wParam
) ? "TRUE" : "FALSE");
6382 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6384 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6386 return (oldredraw
) ? 1 : 0;
6391 TOOLBAR_Size (TOOLBAR_INFO
*infoPtr
)
6393 TRACE("sizing toolbar!\n");
6395 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6397 RECT delta_width
, delta_height
, client
, dummy
;
6398 DWORD min_x
, max_x
, min_y
, max_y
;
6399 TBUTTON_INFO
*btnPtr
;
6402 GetClientRect(infoPtr
->hwndSelf
, &client
);
6403 if(client
.right
> infoPtr
->client_rect
.right
)
6405 min_x
= infoPtr
->client_rect
.right
;
6406 max_x
= client
.right
;
6410 max_x
= infoPtr
->client_rect
.right
;
6411 min_x
= client
.right
;
6413 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6415 min_y
= infoPtr
->client_rect
.bottom
;
6416 max_y
= client
.bottom
;
6420 max_y
= infoPtr
->client_rect
.bottom
;
6421 min_y
= client
.bottom
;
6424 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6425 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6427 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6428 btnPtr
= infoPtr
->buttons
;
6429 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6430 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6431 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6432 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6434 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->client_rect
);
6435 TOOLBAR_AutoSize(infoPtr
);
6441 TOOLBAR_StyleChanged (TOOLBAR_INFO
*infoPtr
, INT nType
, const STYLESTRUCT
*lpStyle
)
6443 if (nType
== GWL_STYLE
)
6444 return TOOLBAR_SetStyle(infoPtr
, lpStyle
->styleNew
);
6451 TOOLBAR_SysColorChange (void)
6453 COMCTL32_RefreshSysColors();
6459 /* update theme after a WM_THEMECHANGED message */
6460 static LRESULT
theme_changed (HWND hwnd
)
6462 HTHEME theme
= GetWindowTheme (hwnd
);
6463 CloseThemeData (theme
);
6464 OpenThemeData (hwnd
, themeClass
);
6469 static LRESULT WINAPI
6470 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6472 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
6474 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6475 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6477 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6478 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6483 return TOOLBAR_AddBitmap (infoPtr
, (INT
)wParam
, (TBADDBITMAP
*)lParam
);
6485 case TB_ADDBUTTONSA
:
6486 case TB_ADDBUTTONSW
:
6487 return TOOLBAR_AddButtonsT (infoPtr
, wParam
, (LPTBBUTTON
)lParam
,
6488 uMsg
== TB_ADDBUTTONSW
);
6490 return TOOLBAR_AddStringA (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6493 return TOOLBAR_AddStringW (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6496 return TOOLBAR_AutoSize (infoPtr
);
6498 case TB_BUTTONCOUNT
:
6499 return TOOLBAR_ButtonCount (infoPtr
);
6501 case TB_BUTTONSTRUCTSIZE
:
6502 return TOOLBAR_ButtonStructSize (infoPtr
, wParam
);
6504 case TB_CHANGEBITMAP
:
6505 return TOOLBAR_ChangeBitmap (infoPtr
, wParam
, LOWORD(lParam
));
6507 case TB_CHECKBUTTON
:
6508 return TOOLBAR_CheckButton (infoPtr
, wParam
, lParam
);
6510 case TB_COMMANDTOINDEX
:
6511 return TOOLBAR_CommandToIndex (infoPtr
, wParam
);
6514 return TOOLBAR_Customize (infoPtr
);
6516 case TB_DELETEBUTTON
:
6517 return TOOLBAR_DeleteButton (infoPtr
, wParam
);
6519 case TB_ENABLEBUTTON
:
6520 return TOOLBAR_EnableButton (infoPtr
, wParam
, lParam
);
6522 case TB_GETANCHORHIGHLIGHT
:
6523 return TOOLBAR_GetAnchorHighlight (infoPtr
);
6526 return TOOLBAR_GetBitmap (infoPtr
, wParam
);
6528 case TB_GETBITMAPFLAGS
:
6529 return TOOLBAR_GetBitmapFlags ();
6532 return TOOLBAR_GetButton (infoPtr
, wParam
, (TBBUTTON
*)lParam
);
6534 case TB_GETBUTTONINFOA
:
6535 case TB_GETBUTTONINFOW
:
6536 return TOOLBAR_GetButtonInfoT (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6537 uMsg
== TB_GETBUTTONINFOW
);
6538 case TB_GETBUTTONSIZE
:
6539 return TOOLBAR_GetButtonSize (infoPtr
);
6541 case TB_GETBUTTONTEXTA
:
6542 case TB_GETBUTTONTEXTW
:
6543 return TOOLBAR_GetButtonText (infoPtr
, wParam
, (LPWSTR
)lParam
,
6544 uMsg
== TB_GETBUTTONTEXTW
);
6546 case TB_GETDISABLEDIMAGELIST
:
6547 return TOOLBAR_GetDisabledImageList (infoPtr
, wParam
);
6549 case TB_GETEXTENDEDSTYLE
:
6550 return TOOLBAR_GetExtendedStyle (infoPtr
);
6552 case TB_GETHOTIMAGELIST
:
6553 return TOOLBAR_GetHotImageList (infoPtr
, wParam
);
6556 return TOOLBAR_GetHotItem (infoPtr
);
6558 case TB_GETIMAGELIST
:
6559 return TOOLBAR_GetDefImageList (infoPtr
, wParam
);
6561 case TB_GETINSERTMARK
:
6562 return TOOLBAR_GetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6564 case TB_GETINSERTMARKCOLOR
:
6565 return TOOLBAR_GetInsertMarkColor (infoPtr
);
6567 case TB_GETITEMRECT
:
6568 return TOOLBAR_GetItemRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6571 return TOOLBAR_GetMaxSize (infoPtr
, (LPSIZE
)lParam
);
6573 /* case TB_GETOBJECT: */ /* 4.71 */
6576 return TOOLBAR_GetPadding (infoPtr
);
6579 return TOOLBAR_GetRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6582 return TOOLBAR_GetRows (infoPtr
);
6585 return TOOLBAR_GetState (infoPtr
, wParam
);
6588 return TOOLBAR_GetStringA (infoPtr
, wParam
, (LPSTR
)lParam
);
6591 return TOOLBAR_GetStringW (infoPtr
, wParam
, (LPWSTR
)lParam
);
6594 return TOOLBAR_GetStyle (infoPtr
);
6596 case TB_GETTEXTROWS
:
6597 return TOOLBAR_GetTextRows (infoPtr
);
6599 case TB_GETTOOLTIPS
:
6600 return TOOLBAR_GetToolTips (infoPtr
);
6602 case TB_GETUNICODEFORMAT
:
6603 return TOOLBAR_GetUnicodeFormat (infoPtr
);
6606 return TOOLBAR_HideButton (infoPtr
, wParam
, LOWORD(lParam
));
6609 return TOOLBAR_HitTest (infoPtr
, (LPPOINT
)lParam
);
6611 case TB_INDETERMINATE
:
6612 return TOOLBAR_Indeterminate (infoPtr
, wParam
, LOWORD(lParam
));
6614 case TB_INSERTBUTTONA
:
6615 case TB_INSERTBUTTONW
:
6616 return TOOLBAR_InsertButtonT(infoPtr
, wParam
, (TBBUTTON
*)lParam
,
6617 uMsg
== TB_INSERTBUTTONW
);
6619 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6621 case TB_ISBUTTONCHECKED
:
6622 return TOOLBAR_IsButtonChecked (infoPtr
, wParam
);
6624 case TB_ISBUTTONENABLED
:
6625 return TOOLBAR_IsButtonEnabled (infoPtr
, wParam
);
6627 case TB_ISBUTTONHIDDEN
:
6628 return TOOLBAR_IsButtonHidden (infoPtr
, wParam
);
6630 case TB_ISBUTTONHIGHLIGHTED
:
6631 return TOOLBAR_IsButtonHighlighted (infoPtr
, wParam
);
6633 case TB_ISBUTTONINDETERMINATE
:
6634 return TOOLBAR_IsButtonIndeterminate (infoPtr
, wParam
);
6636 case TB_ISBUTTONPRESSED
:
6637 return TOOLBAR_IsButtonPressed (infoPtr
, wParam
);
6640 return TOOLBAR_LoadImages (infoPtr
, wParam
, (HINSTANCE
)lParam
);
6642 case TB_MAPACCELERATORA
:
6643 case TB_MAPACCELERATORW
:
6644 return TOOLBAR_MapAccelerator (infoPtr
, wParam
, (UINT
*)lParam
);
6647 return TOOLBAR_MarkButton (infoPtr
, wParam
, LOWORD(lParam
));
6650 return TOOLBAR_MoveButton (infoPtr
, wParam
, lParam
);
6652 case TB_PRESSBUTTON
:
6653 return TOOLBAR_PressButton (infoPtr
, wParam
, LOWORD(lParam
));
6655 case TB_REPLACEBITMAP
:
6656 return TOOLBAR_ReplaceBitmap (infoPtr
, (LPTBREPLACEBITMAP
)lParam
);
6658 case TB_SAVERESTOREA
:
6659 return TOOLBAR_SaveRestoreA (infoPtr
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6661 case TB_SAVERESTOREW
:
6662 return TOOLBAR_SaveRestoreW (infoPtr
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6664 case TB_SETANCHORHIGHLIGHT
:
6665 return TOOLBAR_SetAnchorHighlight (infoPtr
, (BOOL
)wParam
);
6667 case TB_SETBITMAPSIZE
:
6668 return TOOLBAR_SetBitmapSize (infoPtr
, wParam
, lParam
);
6670 case TB_SETBUTTONINFOA
:
6671 case TB_SETBUTTONINFOW
:
6672 return TOOLBAR_SetButtonInfo (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6673 uMsg
== TB_SETBUTTONINFOW
);
6674 case TB_SETBUTTONSIZE
:
6675 return TOOLBAR_SetButtonSize (infoPtr
, lParam
);
6677 case TB_SETBUTTONWIDTH
:
6678 return TOOLBAR_SetButtonWidth (infoPtr
, lParam
);
6681 return TOOLBAR_SetCmdId (infoPtr
, wParam
, lParam
);
6683 case TB_SETDISABLEDIMAGELIST
:
6684 return TOOLBAR_SetDisabledImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6686 case TB_SETDRAWTEXTFLAGS
:
6687 return TOOLBAR_SetDrawTextFlags (infoPtr
, wParam
, lParam
);
6689 case TB_SETEXTENDEDSTYLE
:
6690 return TOOLBAR_SetExtendedStyle (infoPtr
, wParam
, lParam
);
6692 case TB_SETHOTIMAGELIST
:
6693 return TOOLBAR_SetHotImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6696 return TOOLBAR_SetHotItem (infoPtr
, wParam
);
6698 case TB_SETIMAGELIST
:
6699 return TOOLBAR_SetImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6702 return TOOLBAR_SetIndent (infoPtr
, wParam
);
6704 case TB_SETINSERTMARK
:
6705 return TOOLBAR_SetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6707 case TB_SETINSERTMARKCOLOR
:
6708 return TOOLBAR_SetInsertMarkColor (infoPtr
, lParam
);
6710 case TB_SETMAXTEXTROWS
:
6711 return TOOLBAR_SetMaxTextRows (infoPtr
, wParam
);
6714 return TOOLBAR_SetPadding (infoPtr
, lParam
);
6717 return TOOLBAR_SetParent (infoPtr
, (HWND
)wParam
);
6720 return TOOLBAR_SetRows (infoPtr
, wParam
, (LPRECT
)lParam
);
6723 return TOOLBAR_SetState (infoPtr
, wParam
, lParam
);
6726 return TOOLBAR_SetStyle (infoPtr
, lParam
);
6728 case TB_SETTOOLTIPS
:
6729 return TOOLBAR_SetToolTips (infoPtr
, (HWND
)wParam
);
6731 case TB_SETUNICODEFORMAT
:
6732 return TOOLBAR_SetUnicodeFormat (infoPtr
, wParam
);
6734 case TB_SETBOUNDINGSIZE
:
6735 return TOOLBAR_SetBoundingSize(hwnd
, wParam
, lParam
);
6737 case TB_SETHOTITEM2
:
6738 return TOOLBAR_SetHotItem2 (infoPtr
, wParam
, lParam
);
6741 return TOOLBAR_SetListGap(infoPtr
, wParam
);
6743 case TB_GETIMAGELISTCOUNT
:
6744 return TOOLBAR_GetImageListCount(infoPtr
);
6746 case TB_GETIDEALSIZE
:
6747 return TOOLBAR_GetIdealSize (infoPtr
, wParam
, lParam
);
6750 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6752 /* Common Control Messages */
6754 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6755 case CCM_GETCOLORSCHEME
:
6756 return TOOLBAR_GetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6758 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6759 case CCM_SETCOLORSCHEME
:
6760 return TOOLBAR_SetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6762 case CCM_GETVERSION
:
6763 return TOOLBAR_GetVersion (infoPtr
);
6765 case CCM_SETVERSION
:
6766 return TOOLBAR_SetVersion (infoPtr
, (INT
)wParam
);
6772 return TOOLBAR_Create (hwnd
, (CREATESTRUCTW
*)lParam
);
6775 return TOOLBAR_Destroy (infoPtr
);
6778 return TOOLBAR_EraseBackground (infoPtr
, wParam
, lParam
);
6781 return TOOLBAR_GetFont (infoPtr
);
6784 return TOOLBAR_KeyDown (infoPtr
, wParam
, lParam
);
6786 /* case WM_KILLFOCUS: */
6788 case WM_LBUTTONDBLCLK
:
6789 return TOOLBAR_LButtonDblClk (infoPtr
, wParam
, lParam
);
6791 case WM_LBUTTONDOWN
:
6792 return TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
6795 return TOOLBAR_LButtonUp (infoPtr
, wParam
, lParam
);
6798 return TOOLBAR_RButtonUp (infoPtr
, wParam
, lParam
);
6800 case WM_RBUTTONDBLCLK
:
6801 return TOOLBAR_RButtonDblClk (infoPtr
, wParam
, lParam
);
6804 return TOOLBAR_MouseMove (infoPtr
, wParam
, lParam
);
6807 return TOOLBAR_MouseLeave (infoPtr
);
6809 case WM_CAPTURECHANGED
:
6810 return TOOLBAR_CaptureChanged(infoPtr
);
6813 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6816 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6819 return TOOLBAR_NCCreate (hwnd
, wParam
, (CREATESTRUCTW
*)lParam
);
6822 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
6825 return TOOLBAR_Notify (infoPtr
, (LPNMHDR
)lParam
);
6827 case WM_NOTIFYFORMAT
:
6828 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
6830 case WM_PRINTCLIENT
:
6832 return TOOLBAR_Paint (infoPtr
, wParam
);
6835 return TOOLBAR_SetFocus (infoPtr
);
6838 return TOOLBAR_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
6841 return TOOLBAR_SetRedraw (infoPtr
, wParam
);
6844 return TOOLBAR_Size (infoPtr
);
6846 case WM_STYLECHANGED
:
6847 return TOOLBAR_StyleChanged (infoPtr
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
6849 case WM_SYSCOLORCHANGE
:
6850 return TOOLBAR_SysColorChange ();
6852 case WM_THEMECHANGED
:
6853 return theme_changed (hwnd
);
6855 /* case WM_WININICHANGE: */
6860 case WM_MEASUREITEM
:
6862 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
6864 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6865 case PGM_FORWARDMOUSE
:
6866 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6869 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
6870 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
6871 uMsg
, wParam
, lParam
);
6872 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6878 TOOLBAR_Register (void)
6882 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
6883 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
6884 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
6885 wndClass
.cbClsExtra
= 0;
6886 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
6887 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
6888 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
6889 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
6891 RegisterClassW (&wndClass
);
6896 TOOLBAR_Unregister (void)
6898 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
6901 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
6906 /* Check if the entry already exists */
6907 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
6909 /* If this is a new entry we must create it and insert into the array */
6914 c
= Alloc(sizeof(IMLENTRY
));
6917 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
6918 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
6933 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
6937 for (i
= 0; i
< *cies
; i
++)
6947 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
6955 for (i
= 0; i
< cies
; i
++)
6957 if (pies
[i
]->id
== id
)
6969 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
6971 HIMAGELIST himlDef
= 0;
6972 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
6975 himlDef
= pie
->himl
;
6981 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
6983 if (infoPtr
->bUnicode
)
6984 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
6991 nmtba
.iItem
= nmtb
->iItem
;
6992 nmtba
.pszText
= Buffer
;
6993 nmtba
.cchText
= 256;
6994 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
6996 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
6998 int ccht
= strlen(nmtba
.pszText
);
7000 MultiByteToWideChar(CP_ACP
, 0, nmtba
.pszText
, -1,
7001 nmtb
->pszText
, nmtb
->cchText
);
7003 nmtb
->tbButton
= nmtba
.tbButton
;
7012 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
)
7016 /* MSDN states that iItem is the index of the button, rather than the
7017 * command ID as used by every other NMTOOLBAR notification */
7019 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
7021 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);