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 */
122 INT nWidth
; /* width of the toolbar */
124 RECT rcBound
; /* bounding rectangle */
130 INT nRows
; /* number of button rows */
131 INT nMaxTextRows
; /* maximum number of text rows */
132 INT cxMin
; /* minimum button width */
133 INT cxMax
; /* maximum button width */
134 INT nNumButtons
; /* number of buttons */
135 INT nNumBitmaps
; /* number of bitmaps */
136 INT nNumStrings
; /* number of strings */
138 INT nButtonDown
; /* toolbar button being pressed or -1 if none */
139 INT nButtonDrag
; /* toolbar button being dragged or -1 if none */
141 INT nHotItem
; /* index of the "hot" item */
142 SIZE szPadding
; /* padding values around button */
143 INT iTopMargin
; /* the top margin */
144 INT iListGap
; /* default gap between text and image for toolbar with list style */
146 HFONT hFont
; /* text font */
147 HIMAGELIST himlInt
; /* image list created internally */
148 PIMLENTRY
*himlDef
; /* default image list array */
149 INT cimlDef
; /* default image list array count */
150 PIMLENTRY
*himlHot
; /* hot image list array */
151 INT cimlHot
; /* hot image list array count */
152 PIMLENTRY
*himlDis
; /* disabled image list array */
153 INT cimlDis
; /* disabled image list array count */
154 HWND hwndToolTip
; /* handle to tool tip control */
155 HWND hwndNotify
; /* handle to the window that gets notifications */
156 HWND hwndSelf
; /* my own handle */
157 BOOL bAnchor
; /* anchor highlight enabled */
158 BOOL bDoRedraw
; /* Redraw status */
159 BOOL bDragOutSent
; /* has TBN_DRAGOUT notification been sent for this drag? */
160 BOOL bUnicode
; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
161 BOOL bCaptured
; /* mouse captured? */
162 DWORD dwStyle
; /* regular toolbar style */
163 DWORD dwExStyle
; /* extended toolbar style */
164 DWORD dwDTFlags
; /* DrawText flags */
166 COLORREF clrInsertMark
; /* insert mark color */
167 COLORREF clrBtnHighlight
; /* color for Flat Separator */
168 COLORREF clrBtnShadow
; /* color for Flag Separator */
170 LPWSTR pszTooltipText
; /* temporary store for a string > 80 characters
171 * for TTN_GETDISPINFOW notification */
172 TBINSERTMARK tbim
; /* info on insertion mark */
173 TBUTTON_INFO
*buttons
; /* pointer to button array */
174 LPWSTR
*strings
; /* pointer to string array */
175 TBITMAP_INFO
*bitmaps
;
176 } TOOLBAR_INFO
, *PTOOLBAR_INFO
;
179 /* used by customization dialog */
182 PTOOLBAR_INFO tbInfo
;
184 } CUSTDLG_INFO
, *PCUSTDLG_INFO
;
192 } CUSTOMBUTTON
, *PCUSTOMBUTTON
;
201 #define SEPARATOR_WIDTH 8
203 #define BOTTOM_BORDER 2
204 #define DDARROW_WIDTH 11
205 #define ARROW_HEIGHT 3
206 #define INSERTMARK_WIDTH 2
212 /* vertical padding used in list mode when image is present */
215 /* how wide to treat the bitmap if it isn't present */
216 #define NONLIST_NOTEXT_OFFSET 2
218 #define TOOLBAR_NOWHERE (-1)
220 /* Used to find undocumented extended styles */
221 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
222 TBSTYLE_EX_VERTICAL | \
223 TBSTYLE_EX_MIXEDBUTTONS | \
224 TBSTYLE_EX_DOUBLEBUFFER | \
225 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
227 /* all of the CCS_ styles */
228 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
229 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
231 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
232 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
233 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
234 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
235 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
237 static const WCHAR themeClass
[] = { 'T','o','o','l','b','a','r',0 };
239 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
);
240 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
);
241 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
);
242 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
);
243 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
);
244 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
);
245 static LRESULT
TOOLBAR_LButtonDown(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
);
246 static void TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
);
247 static LRESULT
TOOLBAR_AutoSize(TOOLBAR_INFO
*infoPtr
);
248 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
);
249 static void TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
250 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
253 static inline int default_top_margin(const TOOLBAR_INFO
*infoPtr
)
255 return (infoPtr
->dwStyle
& TBSTYLE_FLAT
? 0 : TOP_BORDER
);
258 static inline BOOL
TOOLBAR_HasDropDownArrows(DWORD exStyle
)
260 return (exStyle
& TBSTYLE_EX_DRAWDDARROWS
) != 0;
264 TOOLBAR_GetText(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
266 LPWSTR lpText
= NULL
;
268 /* NOTE: iString == -1 is undocumented */
269 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1))
270 lpText
= (LPWSTR
)btnPtr
->iString
;
271 else if ((btnPtr
->iString
>= 0) && (btnPtr
->iString
< infoPtr
->nNumStrings
))
272 lpText
= infoPtr
->strings
[btnPtr
->iString
];
278 TOOLBAR_DumpTBButton(const TBBUTTON
*tbb
, BOOL fUnicode
)
280 TRACE("TBBUTTON: id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx (%s)\n",
281 tbb
->idCommand
,tbb
->iBitmap
, tbb
->fsState
, tbb
->fsStyle
, tbb
->dwData
, tbb
->iString
,
282 (fUnicode
? wine_dbgstr_w((LPWSTR
)tbb
->iString
) : wine_dbgstr_a((LPSTR
)tbb
->iString
)));
286 TOOLBAR_DumpButton(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*bP
, INT btn_num
)
288 if (TRACE_ON(toolbar
)){
289 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
290 btn_num
, bP
->idCommand
, GETIBITMAP(infoPtr
, bP
->iBitmap
),
291 bP
->fsState
, bP
->fsStyle
, bP
->dwData
, bP
->iString
);
292 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr
,bP
)));
293 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n",
294 btn_num
, bP
->idCommand
, (bP
->bHot
) ? "TRUE":"FALSE", bP
->nRow
,
295 wine_dbgstr_rect(&bP
->rect
));
301 TOOLBAR_DumpToolbar(const TOOLBAR_INFO
*iP
, INT line
)
303 if (TRACE_ON(toolbar
)) {
306 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
308 iP
->dwExStyle
, iP
->nNumButtons
, iP
->nNumBitmaps
,
309 iP
->nNumStrings
, iP
->dwStyle
);
310 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
312 iP
->himlInt
, iP
->himlDef
, iP
->himlHot
, iP
->himlDis
,
313 (iP
->bDoRedraw
) ? "TRUE" : "FALSE");
314 for(i
=0; i
<iP
->nNumButtons
; i
++) {
315 TOOLBAR_DumpButton(iP
, &iP
->buttons
[i
], i
);
321 TOOLBAR_ButtonHasString(const TBUTTON_INFO
*btnPtr
)
323 return HIWORD(btnPtr
->iString
) && btnPtr
->iString
!= -1;
326 /***********************************************************************
329 * This function validates that the styles set are implemented and
330 * issues FIXMEs warning of possible problems. In a perfect world this
331 * function should be null.
334 TOOLBAR_CheckStyle (const TOOLBAR_INFO
*infoPtr
)
336 if (infoPtr
->dwStyle
& TBSTYLE_REGISTERDROP
)
337 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", infoPtr
->hwndSelf
);
342 TOOLBAR_SendNotify (NMHDR
*nmhdr
, const TOOLBAR_INFO
*infoPtr
, UINT code
)
344 if(!IsWindow(infoPtr
->hwndSelf
))
345 return 0; /* we have just been destroyed */
347 nmhdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
348 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
351 TRACE("to window %p, code=%08x, %s\n", infoPtr
->hwndNotify
, code
,
352 (infoPtr
->bUnicode
) ? "via Unicode" : "via ANSI");
354 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhdr
->idFrom
, (LPARAM
)nmhdr
);
357 /***********************************************************************
358 * TOOLBAR_GetBitmapIndex
360 * This function returns the bitmap index associated with a button.
361 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
362 * is issued to retrieve the index.
365 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
367 INT ret
= btnPtr
->iBitmap
;
369 if (ret
== I_IMAGECALLBACK
)
371 /* issue TBN_GETDISPINFO */
374 memset(&nmgd
, 0, sizeof(nmgd
));
375 nmgd
.idCommand
= btnPtr
->idCommand
;
376 nmgd
.lParam
= btnPtr
->dwData
;
377 nmgd
.dwMask
= TBNF_IMAGE
;
379 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
380 TOOLBAR_SendNotify(&nmgd
.hdr
, infoPtr
, TBN_GETDISPINFOW
);
381 if (nmgd
.dwMask
& TBNF_DI_SETITEM
)
382 btnPtr
->iBitmap
= nmgd
.iImage
;
384 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
385 ret
, nmgd
.dwMask
, infoPtr
->nNumBitmaps
);
388 if (ret
!= I_IMAGENONE
)
389 ret
= GETIBITMAP(infoPtr
, ret
);
396 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO
*infoPtr
, INT index
)
399 INT id
= GETHIMLID(infoPtr
, index
);
400 INT iBitmap
= GETIBITMAP(infoPtr
, index
);
402 if (((himl
= GETDEFIMAGELIST(infoPtr
, id
)) &&
403 iBitmap
>= 0 && iBitmap
< ImageList_GetImageCount(himl
)) ||
404 (index
== I_IMAGECALLBACK
))
412 TOOLBAR_IsValidImageList(const TOOLBAR_INFO
*infoPtr
, INT index
)
414 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, index
));
415 return (himl
!= NULL
) && (ImageList_GetImageCount(himl
) > 0);
419 /***********************************************************************
420 * TOOLBAR_GetImageListForDrawing
422 * This function validates the bitmap index (including I_IMAGECALLBACK
423 * functionality) and returns the corresponding image list.
426 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
,
427 IMAGE_LIST_TYPE imagelist
, INT
* index
)
431 if (!TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
)) {
432 if (btnPtr
->iBitmap
== I_IMAGENONE
) return NULL
;
433 WARN("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
434 HIWORD(btnPtr
->iBitmap
), LOWORD(btnPtr
->iBitmap
), infoPtr
->nNumBitmaps
);
438 if ((*index
= TOOLBAR_GetBitmapIndex(infoPtr
, btnPtr
)) < 0) {
439 if ((*index
== I_IMAGECALLBACK
) ||
440 (*index
== I_IMAGENONE
)) return NULL
;
441 ERR("TBN_GETDISPINFO returned invalid index %d\n",
448 case IMAGE_LIST_DEFAULT
:
449 himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
452 himl
= GETHOTIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
454 case IMAGE_LIST_DISABLED
:
455 himl
= GETDISIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
459 FIXME("Shouldn't reach here\n");
463 TRACE("no image list\n");
470 TOOLBAR_DrawFlatSeparator (const RECT
*lpRect
, HDC hdc
, const TOOLBAR_INFO
*infoPtr
)
473 COLORREF oldcolor
, newcolor
;
475 myrect
.left
= (lpRect
->left
+ lpRect
->right
) / 2 - 1;
476 myrect
.right
= myrect
.left
+ 1;
477 myrect
.top
= lpRect
->top
+ 2;
478 myrect
.bottom
= lpRect
->bottom
- 2;
480 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
481 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
482 oldcolor
= SetBkColor (hdc
, newcolor
);
483 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
485 myrect
.left
= myrect
.right
;
486 myrect
.right
= myrect
.left
+ 1;
488 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
489 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
490 SetBkColor (hdc
, newcolor
);
491 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
493 SetBkColor (hdc
, oldcolor
);
497 /***********************************************************************
498 * TOOLBAR_DrawFlatHorizontalSeparator
500 * This function draws horizontal separator for toolbars having CCS_VERT style.
501 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
502 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
503 * are horizontal as opposed to the vertical separators for not dropdown
506 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
509 TOOLBAR_DrawFlatHorizontalSeparator (const RECT
*lpRect
, HDC hdc
,
510 const TOOLBAR_INFO
*infoPtr
)
513 COLORREF oldcolor
, newcolor
;
515 myrect
.left
= lpRect
->left
;
516 myrect
.right
= lpRect
->right
;
517 myrect
.top
= lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
- 2)/2;
518 myrect
.bottom
= myrect
.top
+ 1;
520 InflateRect (&myrect
, -2, 0);
522 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect
));
524 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
525 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
526 oldcolor
= SetBkColor (hdc
, newcolor
);
527 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
529 myrect
.top
= myrect
.bottom
;
530 myrect
.bottom
= myrect
.top
+ 1;
532 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
533 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
534 SetBkColor (hdc
, newcolor
);
535 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
537 SetBkColor (hdc
, oldcolor
);
542 TOOLBAR_DrawArrow (HDC hdc
, INT left
, INT top
, COLORREF clr
)
547 if (!(hPen
= CreatePen( PS_SOLID
, 1, clr
))) return;
548 hOldPen
= SelectObject ( hdc
, hPen
);
551 MoveToEx (hdc
, x
, y
, NULL
);
552 LineTo (hdc
, x
+5, y
++); x
++;
553 MoveToEx (hdc
, x
, y
, NULL
);
554 LineTo (hdc
, x
+3, y
++); x
++;
555 MoveToEx (hdc
, x
, y
, NULL
);
556 LineTo (hdc
, x
+1, y
);
557 SelectObject( hdc
, hOldPen
);
558 DeleteObject( hPen
);
562 * Draw the text string for this button.
563 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
564 * is non-zero, so we can simply check himlDef to see if we have
568 TOOLBAR_DrawString (const TOOLBAR_INFO
*infoPtr
, RECT
*rcText
, LPCWSTR lpText
,
569 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
571 HDC hdc
= tbcd
->nmcd
.hdc
;
574 COLORREF clrOldBk
= 0;
576 UINT state
= tbcd
->nmcd
.uItemState
;
579 if (lpText
&& infoPtr
->nMaxTextRows
> 0) {
580 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText
),
581 wine_dbgstr_rect(rcText
));
583 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
584 if ((state
& CDIS_HOT
) && (dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)) {
585 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
587 else if (state
& CDIS_DISABLED
) {
588 clrOld
= SetTextColor (hdc
, tbcd
->clrBtnHighlight
);
589 OffsetRect (rcText
, 1, 1);
590 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
591 SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
592 OffsetRect (rcText
, -1, -1);
594 else if (state
& CDIS_INDETERMINATE
) {
595 clrOld
= SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
597 else if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
)) {
598 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
599 clrOldBk
= SetBkColor (hdc
, tbcd
->clrMark
);
600 oldBkMode
= SetBkMode (hdc
, tbcd
->nHLStringBkMode
);
603 clrOld
= SetTextColor (hdc
, tbcd
->clrText
);
606 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
607 SetTextColor (hdc
, clrOld
);
608 if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
))
610 SetBkColor (hdc
, clrOldBk
);
611 SetBkMode (hdc
, oldBkMode
);
613 SelectObject (hdc
, hOldFont
);
619 TOOLBAR_DrawPattern (const RECT
*lpRect
, const NMTBCUSTOMDRAW
*tbcd
)
621 HDC hdc
= tbcd
->nmcd
.hdc
;
622 HBRUSH hbr
= SelectObject (hdc
, tbcd
->hbrMonoDither
);
625 INT cx
= lpRect
->right
- lpRect
->left
;
626 INT cy
= lpRect
->bottom
- lpRect
->top
;
627 INT cxEdge
= GetSystemMetrics(SM_CXEDGE
);
628 INT cyEdge
= GetSystemMetrics(SM_CYEDGE
);
629 clrTextOld
= SetTextColor(hdc
, tbcd
->clrBtnHighlight
);
630 clrBkOld
= SetBkColor(hdc
, tbcd
->clrBtnFace
);
631 PatBlt (hdc
, lpRect
->left
+ cxEdge
, lpRect
->top
+ cyEdge
,
632 cx
- (2 * cxEdge
), cy
- (2 * cyEdge
), PATCOPY
);
633 SetBkColor(hdc
, clrBkOld
);
634 SetTextColor(hdc
, clrTextOld
);
635 SelectObject (hdc
, hbr
);
639 static void TOOLBAR_DrawMasked(HIMAGELIST himl
, int index
, HDC hdc
, INT x
, INT y
, UINT draw_flags
)
642 HBITMAP hbmMask
, hbmImage
;
643 HDC hdcMask
, hdcImage
;
645 ImageList_GetIconSize(himl
, &cx
, &cy
);
647 /* Create src image */
648 hdcImage
= CreateCompatibleDC(hdc
);
649 hbmImage
= CreateCompatibleBitmap(hdc
, cx
, cy
);
650 SelectObject(hdcImage
, hbmImage
);
651 ImageList_DrawEx(himl
, index
, hdcImage
, 0, 0, cx
, cy
,
652 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags
);
655 hdcMask
= CreateCompatibleDC(0);
656 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
657 SelectObject(hdcMask
, hbmMask
);
659 /* Remove the background and all white pixels */
660 ImageList_DrawEx(himl
, index
, hdcMask
, 0, 0, cx
, cy
,
661 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK
);
662 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
663 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
665 /* draw the new mask 'etched' to hdc */
666 SetBkColor(hdc
, RGB(255, 255, 255));
667 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
668 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
669 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
670 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
671 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
674 DeleteObject(hbmImage
);
676 DeleteObject (hbmMask
);
682 TOOLBAR_TranslateState(const TBUTTON_INFO
*btnPtr
)
686 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
687 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
688 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
689 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
690 retstate
|= (btnPtr
->bHot
) ? CDIS_HOT
: 0;
691 retstate
|= ((btnPtr
->fsState
& (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) == (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) ? CDIS_INDETERMINATE
: 0;
692 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
696 /* draws the image on a toolbar button */
698 TOOLBAR_DrawImage(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
,
699 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
701 HIMAGELIST himl
= NULL
;
702 BOOL draw_masked
= FALSE
;
705 UINT draw_flags
= ILD_TRANSPARENT
;
707 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
709 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
712 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
716 else if (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
||
717 ((tbcd
->nmcd
.uItemState
& CDIS_HOT
)
718 && ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))))
720 /* if hot, attempt to draw with hot image list, if fails,
721 use default image list */
722 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
724 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
727 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
732 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
733 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
736 if (!(dwItemCDFlag
& TBCDRF_NOMARK
) &&
737 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
738 draw_flags
|= ILD_BLEND50
;
740 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
741 index
, himl
, left
, top
, offset
);
744 TOOLBAR_DrawMasked (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
746 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
749 /* draws a blank frame for a toolbar button */
751 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
753 HDC hdc
= tbcd
->nmcd
.hdc
;
754 RECT rc
= tbcd
->nmcd
.rc
;
755 /* if the state is disabled or indeterminate then the button
756 * cannot have an interactive look like pressed or hot */
757 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
758 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
759 BOOL pressed_look
= !non_interactive_state
&&
760 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
761 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
763 /* app don't want us to draw any edges */
764 if (dwItemCDFlag
& TBCDRF_NOEDGES
)
767 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
770 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
771 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
772 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
777 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
779 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
780 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
785 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
, BOOL bDropDownPressed
, DWORD dwItemCDFlag
)
787 HDC hdc
= tbcd
->nmcd
.hdc
;
789 BOOL pressed
= bDropDownPressed
||
790 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
));
792 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
795 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
);
796 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
797 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
798 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
799 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
804 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
806 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
807 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
811 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
813 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
815 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
816 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
819 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
822 /* draws a complete toolbar button */
824 TOOLBAR_DrawButton (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, HDC hdc
, DWORD dwBaseCustDraw
)
826 DWORD dwStyle
= infoPtr
->dwStyle
;
827 BOOL hasDropDownArrow
= (TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) &&
828 (btnPtr
->fsStyle
& BTNS_DROPDOWN
)) ||
829 (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
830 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
831 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
832 RECT rc
, rcArrow
, rcBitmap
, rcText
;
833 LPWSTR lpText
= NULL
;
838 DWORD dwItemCustDraw
;
840 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
843 CopyRect (&rcArrow
, &rc
);
845 /* separator - doesn't send NM_CUSTOMDRAW */
846 if (btnPtr
->fsStyle
& BTNS_SEP
) {
849 DrawThemeBackground (theme
, hdc
,
850 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
854 /* with the FLAT style, iBitmap is the width and has already */
855 /* been taken into consideration in calculating the width */
856 /* so now we need to draw the vertical separator */
857 /* empirical tests show that iBitmap can/will be non-zero */
858 /* when drawing the vertical bar... */
859 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
860 if (dwStyle
& CCS_VERT
) {
862 InflateRect(&rcsep
, -infoPtr
->szPadding
.cx
, -infoPtr
->szPadding
.cy
);
863 TOOLBAR_DrawFlatHorizontalSeparator (&rcsep
, hdc
, infoPtr
);
866 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
868 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
869 FIXME("Draw some kind of separator: fsStyle=%x\n",
875 /* get a pointer to the text */
876 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
878 if (hasDropDownArrow
)
882 if (dwStyle
& TBSTYLE_FLAT
)
883 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
885 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
887 if (drawSepDropDownArrow
)
890 rcArrow
.left
= right
;
893 /* copy text & bitmap rects after adjusting for drop-down arrow
894 * so that text & bitmap is centered in the rectangle not containing
896 CopyRect(&rcText
, &rc
);
897 CopyRect(&rcBitmap
, &rc
);
899 /* Center the bitmap horizontally and vertically */
900 if (dwStyle
& TBSTYLE_LIST
)
903 infoPtr
->nMaxTextRows
> 0 &&
904 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
905 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
906 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
908 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
911 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
913 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
915 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
916 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
917 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
918 TRACE("Text=%s\n", debugstr_w(lpText
));
919 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
921 /* calculate text position */
924 rcText
.left
+= GetSystemMetrics(SM_CXEDGE
);
925 rcText
.right
-= GetSystemMetrics(SM_CXEDGE
);
926 if (dwStyle
& TBSTYLE_LIST
)
928 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
932 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
933 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
935 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
939 /* Initialize fields in all cases, because we use these later
940 * NOTE: applications can and do alter these to customize their
942 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
943 tbcd
.clrText
= comctl32_color
.clrBtnText
;
944 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
945 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
946 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
947 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
948 tbcd
.clrHighlightHotTrack
= 0;
949 tbcd
.nStringBkMode
= TRANSPARENT
;
950 tbcd
.nHLStringBkMode
= OPAQUE
;
951 tbcd
.rcText
.left
= 0;
953 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
954 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
955 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
958 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
960 /* FIXME: what are these used for? */
964 /* Issue Item Prepaint notify */
967 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
969 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
970 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
971 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
972 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
973 /* reset these fields so the user can't alter the behaviour like native */
977 dwItemCustDraw
= ntfret
& 0xffff;
978 dwItemCDFlag
= ntfret
& 0xffff0000;
979 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
981 /* save the only part of the rect that the user can change */
982 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
983 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
986 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
987 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
988 OffsetRect(&rcText
, 1, 1);
990 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
991 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
992 TOOLBAR_DrawPattern (&rc
, &tbcd
);
994 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
995 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
997 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
1001 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
1002 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
1003 if (hasDropDownArrow
)
1004 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
1005 SetBkColor(hdc
, oldclr
);
1011 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
1012 int stateId
= TS_NORMAL
;
1014 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1015 stateId
= TS_DISABLED
;
1016 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1017 stateId
= TS_PRESSED
;
1018 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1019 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1020 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1021 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1024 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &tbcd
.nmcd
.rc
, NULL
);
1027 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, dwItemCDFlag
);
1029 if (drawSepDropDownArrow
)
1033 int stateId
= TS_NORMAL
;
1035 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1036 stateId
= TS_DISABLED
;
1037 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1038 stateId
= TS_PRESSED
;
1039 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1040 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1041 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1044 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1045 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1048 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1051 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1052 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1053 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1054 SetBkMode (hdc
, oldBkMode
);
1056 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1058 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1060 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1062 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1063 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1065 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1067 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1068 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1071 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1074 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1076 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1077 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1084 TOOLBAR_Refresh (TOOLBAR_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
1086 TBUTTON_INFO
*btnPtr
;
1088 RECT rcTemp
, rcClient
;
1089 NMTBCUSTOMDRAW tbcd
;
1091 DWORD dwBaseCustDraw
;
1093 /* the app has told us not to redraw the toolbar */
1094 if (!infoPtr
->bDoRedraw
)
1097 /* if imagelist belongs to the app, it can be changed
1098 by the app after setting it */
1099 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1101 infoPtr
->nNumBitmaps
= 0;
1102 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1103 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1106 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1108 /* change the imagelist icon size if we manage the list and it is necessary */
1109 TOOLBAR_CheckImageListIconSize(infoPtr
);
1111 /* Send initial notify */
1112 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1113 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1114 tbcd
.nmcd
.hdc
= hdc
;
1115 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1116 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1117 dwBaseCustDraw
= ntfret
& 0xffff;
1119 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1121 /* redraw necessary buttons */
1122 btnPtr
= infoPtr
->buttons
;
1123 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1126 if (!RectVisible(hdc
, &btnPtr
->rect
))
1128 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1130 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1131 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1135 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1136 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1138 TOOLBAR_DrawButton(infoPtr
, btnPtr
, hdc
, dwBaseCustDraw
);
1141 /* draw insert mark if required */
1142 if (infoPtr
->tbim
.iButton
!= -1)
1144 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1146 rcInsertMark
.top
= rcButton
.top
;
1147 rcInsertMark
.bottom
= rcButton
.bottom
;
1148 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1149 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1151 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1152 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1155 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1157 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1158 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1159 tbcd
.nmcd
.hdc
= hdc
;
1160 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1161 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1165 /***********************************************************************
1166 * TOOLBAR_MeasureString
1168 * This function gets the width and height of a string in pixels. This
1169 * is done first by using GetTextExtentPoint to get the basic width
1170 * and height. The DrawText is called with DT_CALCRECT to get the exact
1171 * width. The reason is because the text may have more than one "&" (or
1172 * prefix characters as M$ likes to call them). The prefix character
1173 * indicates where the underline goes, except for the string "&&" which
1174 * is reduced to a single "&". GetTextExtentPoint does not process these
1175 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1178 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1179 HDC hdc
, LPSIZE lpSize
)
1186 if (infoPtr
->nMaxTextRows
> 0 &&
1187 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1188 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1189 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1191 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1193 if(lpText
!= NULL
) {
1194 /* first get size of all the text */
1195 GetTextExtentPoint32W (hdc
, lpText
, strlenW (lpText
), lpSize
);
1197 /* feed above size into the rectangle for DrawText */
1198 myrect
.left
= myrect
.top
= 0;
1199 myrect
.right
= lpSize
->cx
;
1200 myrect
.bottom
= lpSize
->cy
;
1202 /* Use DrawText to get true size as drawn (less pesky "&") */
1203 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1204 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1207 /* feed back to caller */
1208 lpSize
->cx
= myrect
.right
;
1209 lpSize
->cy
= myrect
.bottom
;
1213 TRACE("string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1216 /***********************************************************************
1217 * TOOLBAR_CalcStrings
1219 * This function walks through each string and measures it and returns
1220 * the largest height and width to caller.
1223 TOOLBAR_CalcStrings (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
1225 TBUTTON_INFO
*btnPtr
;
1234 if (infoPtr
->nMaxTextRows
== 0)
1237 hdc
= GetDC (infoPtr
->hwndSelf
);
1238 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1240 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1244 GetTextMetricsW(hdc
, &tm
);
1245 lpSize
->cy
= tm
.tmHeight
;
1248 btnPtr
= infoPtr
->buttons
;
1249 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1250 if(TOOLBAR_GetText(infoPtr
, btnPtr
))
1252 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1253 if (sz
.cx
> lpSize
->cx
)
1255 if (sz
.cy
> lpSize
->cy
)
1260 SelectObject (hdc
, hOldFont
);
1261 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1263 TRACE("max string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1266 /***********************************************************************
1267 * TOOLBAR_WrapToolbar
1269 * This function walks through the buttons and separators in the
1270 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1271 * wrapping should occur based on the width of the toolbar window.
1272 * It does *not* calculate button placement itself. That task
1273 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1274 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1275 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1277 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_VERTICAL can be used also to allow
1278 * vertical toolbar lists.
1282 TOOLBAR_WrapToolbar(TOOLBAR_INFO
*infoPtr
)
1284 TBUTTON_INFO
*btnPtr
;
1289 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1290 /* no layout is necessary. Applications may use this style */
1291 /* to perform their own layout on the toolbar. */
1292 if( !(infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) &&
1293 !(infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
) ) return;
1295 btnPtr
= infoPtr
->buttons
;
1296 x
= infoPtr
->nIndent
;
1298 if (GetParent(infoPtr
->hwndSelf
))
1300 /* this can get the parents width, to know how far we can extend
1301 * this toolbar. We cannot use its height, as there may be multiple
1302 * toolbars in a rebar control
1304 GetClientRect( GetParent(infoPtr
->hwndSelf
), &rc
);
1305 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1309 GetWindowRect( infoPtr
->hwndSelf
, &rc
);
1310 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1313 bButtonWrap
= FALSE
;
1315 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1316 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, infoPtr
->nWidth
,
1319 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1321 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1323 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1326 if (btnPtr
[i
].cx
> 0)
1328 /* horizontal separators are treated as buttons for width */
1329 else if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1330 !(infoPtr
->dwStyle
& CCS_VERT
))
1331 cx
= (btnPtr
[i
].iBitmap
> 0) ? btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1333 cx
= infoPtr
->nButtonWidth
;
1335 /* Two or more adjacent separators form a separator group. */
1336 /* The first separator in a group should be wrapped to the */
1337 /* next row if the previous wrapping is on a button. */
1339 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1340 (i
+ 1 < infoPtr
->nNumButtons
) &&
1341 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1343 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1344 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1345 x
= infoPtr
->nIndent
;
1347 bButtonWrap
= FALSE
;
1351 /* The layout makes sure the bitmap is visible, but not the button. */
1352 /* Test added to also wrap after a button that starts a row but */
1353 /* is bigger than the area. - GA 8/01 */
1354 if (( x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2
1355 > infoPtr
->nWidth
) ||
1356 ((x
== infoPtr
->nIndent
) && (cx
> infoPtr
->nWidth
)))
1358 BOOL bFound
= FALSE
;
1360 /* If the current button is a separator and not hidden, */
1361 /* go to the next until it reaches a non separator. */
1362 /* Wrap the last separator if it is before a button. */
1363 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1364 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1365 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1366 i
< infoPtr
->nNumButtons
)
1372 if( bFound
&& i
< infoPtr
->nNumButtons
)
1375 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1376 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1377 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1378 x
= infoPtr
->nIndent
;
1379 bButtonWrap
= FALSE
;
1382 else if ( i
>= infoPtr
->nNumButtons
)
1385 /* If the current button is not a separator, find the last */
1386 /* separator and wrap it. */
1387 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1389 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1390 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1394 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1395 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1396 x
= infoPtr
->nIndent
;
1397 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1398 bButtonWrap
= FALSE
;
1403 /* If no separator available for wrapping, wrap one of */
1404 /* non-hidden previous button. */
1408 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1410 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1415 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1416 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1417 x
= infoPtr
->nIndent
;
1418 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1424 /* If all above failed, wrap the current button. */
1427 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1428 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1429 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1430 x
= infoPtr
->nIndent
;
1431 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1432 bButtonWrap
= FALSE
;
1438 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1439 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1446 /***********************************************************************
1447 * TOOLBAR_MeasureButton
1449 * Calculates the width and height required for a button. Used in
1450 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1451 * the width of buttons that are autosized.
1453 * Note that it would have been rather elegant to use one piece of code for
1454 * both the laying out of the toolbar and for controlling where button parts
1455 * are drawn, but the native control has inconsistencies between the two that
1456 * prevent this from being effectively. These inconsistencies can be seen as
1457 * artefacts where parts of the button appear outside of the bounding button
1460 * There are several cases for the calculation of the button dimensions and
1461 * button part positioning:
1468 * +--------------------------------------------------------+ ^
1470 * | | pad.cy / 2 | centered | |
1471 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1472 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1473 * | |<------------>| | | | |
1474 * | +--------------+ +------------+ | |
1475 * |<-------------------------------------->| | |
1476 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1478 * +--------------------------------------------------------+ -
1479 * <-------------------------------------------------------->
1480 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1482 * Without Bitmap (I_IMAGENONE):
1484 * +-----------------------------------+ ^
1486 * | | centered | | LISTPAD_CY +
1487 * | +------------+ | | szText.cy
1490 * | +------------+ | |
1491 * |<----------------->| | |
1492 * | cxedge |<-----------> | |
1494 * +-----------------------------------+ -
1495 * <----------------------------------->
1496 * szText.cx + pad.cx
1500 * +--------------------------------------+ ^
1502 * | | padding.cy/2 | | DEFPAD_CY +
1503 * | +------------+ | | nBitmapHeight
1506 * | +------------+ | |
1507 * |<------------------->| | |
1508 * | cxedge + iListGap/2 |<-----------> | |
1509 * | nBitmapWidth | |
1510 * +--------------------------------------+ -
1511 * <-------------------------------------->
1512 * 2*cxedge + nBitmapWidth + iListGap
1519 * +-----------------------------------+ ^
1521 * | | pad.cy / 2 | | nBitmapHeight +
1522 * | - | | szText.cy +
1523 * | +------------+ | | DEFPAD_CY + 1
1524 * | centered | Bitmap | | |
1525 * |<----------------->| | | |
1526 * | +------------+ | |
1530 * | centered +---------------+ | |
1531 * |<--------------->| Text | | |
1532 * | +---------------+ | |
1533 * +-----------------------------------+ -
1534 * <----------------------------------->
1535 * pad.cx + max(nBitmapWidth, szText.cx)
1537 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1539 * +---------------------------------------+ ^
1541 * | | 2 + pad.cy / 2 | |
1542 * | - | | szText.cy +
1543 * | centered +-----------------+ | | pad.cy + 2
1544 * |<--------------->| Text | | |
1545 * | +-----------------+ | |
1547 * +---------------------------------------+ -
1548 * <--------------------------------------->
1549 * 2*cxedge + pad.cx + szText.cx
1552 * As for with bitmaps, but with szText.cx zero.
1554 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1555 BOOL bHasBitmap
, BOOL bValidImageList
)
1558 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1560 /* set button height from bitmap / text height... */
1561 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1564 /* ... add on the necessary padding */
1565 if (bValidImageList
)
1568 sizeButton
.cy
+= DEFPAD_CY
;
1570 sizeButton
.cy
+= LISTPAD_CY
;
1573 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1575 /* calculate button width */
1576 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1577 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1578 if (sizeString
.cx
> 0)
1579 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1586 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1587 if (sizeString
.cy
> 0)
1588 sizeButton
.cy
+= 1 + sizeString
.cy
;
1589 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1590 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1594 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1595 NONLIST_NOTEXT_OFFSET
;
1596 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1597 max(2*GetSystemMetrics(SM_CXEDGE
) + sizeString
.cx
, infoPtr
->nBitmapWidth
);
1604 /***********************************************************************
1605 * TOOLBAR_CalcToolbar
1607 * This function calculates button and separator placement. It first
1608 * calculates the button sizes, gets the toolbar window width and then
1609 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1610 * on. It assigns a new location to each item and sends this location to
1611 * the tooltip window if appropriate. Finally, it updates the rcBound
1612 * rect and calculates the new required toolbar window height.
1615 TOOLBAR_CalcToolbar (TOOLBAR_INFO
*infoPtr
)
1617 SIZE sizeString
, sizeButton
;
1618 BOOL validImageList
= FALSE
;
1620 TOOLBAR_CalcStrings (infoPtr
, &sizeString
);
1622 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1624 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1625 validImageList
= TRUE
;
1626 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1627 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1628 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1629 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1631 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1632 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1633 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1634 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1636 TOOLBAR_LayoutToolbar(infoPtr
);
1640 TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
)
1642 TBUTTON_INFO
*btnPtr
;
1644 INT i
, nRows
, nSepRows
;
1647 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1648 BOOL hasDropDownArrows
= TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
);
1650 TOOLBAR_WrapToolbar(infoPtr
);
1652 x
= infoPtr
->nIndent
;
1653 y
= infoPtr
->iTopMargin
;
1654 cx
= infoPtr
->nButtonWidth
;
1655 cy
= infoPtr
->nButtonHeight
;
1657 nRows
= nSepRows
= 0;
1659 infoPtr
->rcBound
.top
= y
;
1660 infoPtr
->rcBound
.left
= x
;
1661 infoPtr
->rcBound
.bottom
= y
+ cy
;
1662 infoPtr
->rcBound
.right
= x
;
1664 btnPtr
= infoPtr
->buttons
;
1666 TRACE("cy=%d\n", cy
);
1668 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1671 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1673 SetRectEmpty (&btnPtr
->rect
);
1677 cy
= infoPtr
->nButtonHeight
;
1679 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1680 if (infoPtr
->dwStyle
& CCS_VERT
) {
1681 cy
= (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1682 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
: infoPtr
->nButtonWidth
;
1685 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
:
1686 (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1692 else if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1693 (btnPtr
->fsStyle
& BTNS_AUTOSIZE
))
1699 hdc
= GetDC (infoPtr
->hwndSelf
);
1700 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1702 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1704 SelectObject (hdc
, hOldFont
);
1705 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1707 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1708 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1713 cx
= infoPtr
->nButtonWidth
;
1715 /* if size has been set manually then don't add on extra space
1716 * for the drop down arrow */
1717 if (!btnPtr
->cx
&& hasDropDownArrows
&&
1718 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) || (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)))
1719 cx
+= DDARROW_WIDTH
;
1721 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1724 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1726 if (infoPtr
->rcBound
.left
> x
)
1727 infoPtr
->rcBound
.left
= x
;
1728 if (infoPtr
->rcBound
.right
< x
+ cx
)
1729 infoPtr
->rcBound
.right
= x
+ cx
;
1730 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1731 infoPtr
->rcBound
.bottom
= y
+ cy
;
1733 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1735 /* btnPtr->nRow is zero based. The space between the rows is */
1736 /* also considered as a row. */
1737 btnPtr
->nRow
= nRows
+ nSepRows
;
1739 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1740 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1745 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1749 if ( !(infoPtr
->dwStyle
& CCS_VERT
))
1750 y
+= cy
+ ( (btnPtr
->cx
> 0 ) ?
1751 btnPtr
->cx
: SEPARATOR_WIDTH
) * 2 /3;
1755 /* nSepRows is used to calculate the extra height following */
1759 x
= infoPtr
->nIndent
;
1761 /* Increment row number unless this is the last button */
1762 /* and it has Wrap set. */
1763 if (i
!= infoPtr
->nNumButtons
-1)
1770 /* infoPtr->nRows is the number of rows on the toolbar */
1771 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1773 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1778 TOOLBAR_InternalHitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
*lpPt
, BOOL
*button
)
1780 TBUTTON_INFO
*btnPtr
;
1786 btnPtr
= infoPtr
->buttons
;
1787 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1788 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1791 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1792 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1793 TRACE(" ON SEPARATOR %d!\n", i
);
1798 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1799 TRACE(" ON BUTTON %d!\n", i
);
1807 TRACE(" NOWHERE!\n");
1808 return TOOLBAR_NOWHERE
;
1812 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1814 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO
*infoPtr
, INT iIndex
, UINT nAddButtons
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
1816 INT nOldButtons
, nNewButtons
, iButton
;
1817 BOOL fHasString
= FALSE
;
1819 if (iIndex
< 0) /* iIndex can be negative, what means adding at the end */
1820 iIndex
= infoPtr
->nNumButtons
;
1822 nOldButtons
= infoPtr
->nNumButtons
;
1823 nNewButtons
= nOldButtons
+ nAddButtons
;
1825 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
1826 memmove(&infoPtr
->buttons
[iIndex
+ nAddButtons
], &infoPtr
->buttons
[iIndex
],
1827 (nOldButtons
- iIndex
) * sizeof(TBUTTON_INFO
));
1828 infoPtr
->nNumButtons
+= nAddButtons
;
1830 /* insert new buttons data */
1831 for (iButton
= 0; iButton
< nAddButtons
; iButton
++) {
1832 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[iIndex
+ iButton
];
1834 TOOLBAR_DumpTBButton(lpTbb
+ iButton
, fUnicode
);
1836 ZeroMemory(btnPtr
, sizeof(*btnPtr
));
1838 btnPtr
->iBitmap
= lpTbb
[iButton
].iBitmap
;
1839 btnPtr
->idCommand
= lpTbb
[iButton
].idCommand
;
1840 btnPtr
->fsState
= lpTbb
[iButton
].fsState
;
1841 btnPtr
->fsStyle
= lpTbb
[iButton
].fsStyle
;
1842 btnPtr
->dwData
= lpTbb
[iButton
].dwData
;
1843 if (btnPtr
->fsStyle
& BTNS_SEP
)
1844 btnPtr
->iString
= -1;
1845 else if(!IS_INTRESOURCE(lpTbb
[iButton
].iString
) && lpTbb
[iButton
].iString
!= -1)
1848 Str_SetPtrW((LPWSTR
*)&btnPtr
->iString
, (LPWSTR
)lpTbb
[iButton
].iString
);
1850 Str_SetPtrAtoW((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lpTbb
[iButton
].iString
);
1854 btnPtr
->iString
= lpTbb
[iButton
].iString
;
1856 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
1859 if (infoPtr
->nNumStrings
> 0 || fHasString
)
1860 TOOLBAR_CalcToolbar(infoPtr
);
1862 TOOLBAR_LayoutToolbar(infoPtr
);
1863 TOOLBAR_AutoSize(infoPtr
);
1865 TOOLBAR_DumpToolbar(infoPtr
, __LINE__
);
1866 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1872 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1874 TBUTTON_INFO
*btnPtr
;
1877 if (CommandIsIndex
) {
1878 TRACE("command is really index command=%d\n", idCommand
);
1879 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1882 btnPtr
= infoPtr
->buttons
;
1883 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1884 if (btnPtr
->idCommand
== idCommand
) {
1885 TRACE("command=%d index=%d\n", idCommand
, i
);
1889 TRACE("no index found for command=%d\n", idCommand
);
1895 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1897 TBUTTON_INFO
*btnPtr
;
1900 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1903 /* check index button */
1904 btnPtr
= &infoPtr
->buttons
[nIndex
];
1905 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1906 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1910 /* check previous buttons */
1911 nRunIndex
= nIndex
- 1;
1912 while (nRunIndex
>= 0) {
1913 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1914 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1915 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1923 /* check next buttons */
1924 nRunIndex
= nIndex
+ 1;
1925 while (nRunIndex
< infoPtr
->nNumButtons
) {
1926 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1927 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1928 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1941 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1942 WPARAM wParam
, LPARAM lParam
)
1948 msg
.wParam
= wParam
;
1949 msg
.lParam
= lParam
;
1950 msg
.time
= GetMessageTime ();
1951 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
1952 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
1954 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1958 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1960 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
1963 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
1964 ti
.cbSize
= sizeof (TTTOOLINFOW
);
1965 ti
.hwnd
= infoPtr
->hwndSelf
;
1966 ti
.uId
= button
->idCommand
;
1968 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
1969 /* ti.lParam = random value from the stack? */
1971 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
1977 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1979 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
1982 ZeroMemory(&ti
, sizeof(ti
));
1983 ti
.cbSize
= sizeof(ti
);
1984 ti
.hwnd
= infoPtr
->hwndSelf
;
1985 ti
.uId
= button
->idCommand
;
1987 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
1991 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1993 /* Set the toolTip only for non-hidden, non-separator button */
1994 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
;
2002 ti
.rect
= button
->rect
;
2003 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
2007 /* Creates the tooltip control */
2009 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
2012 NMTOOLTIPSCREATED nmttc
;
2014 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
2015 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2016 infoPtr
->hwndSelf
, 0, 0, 0);
2018 if (!infoPtr
->hwndToolTip
)
2021 /* Send NM_TOOLTIPSCREATED notification */
2022 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
2023 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
2025 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
2027 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
2028 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
2032 /* keeps available button list box sorted by button id */
2033 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
2037 PCUSTOMBUTTON btnInfo
;
2038 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2040 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
2042 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2044 /* position 0 is always separator */
2045 for (i
= 1; i
< count
; i
++)
2047 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2048 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2050 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2051 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2055 /* id higher than all others add to end */
2056 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2057 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2060 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2064 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2066 if (nIndexFrom
== nIndexTo
)
2069 /* MSDN states that iItem is the index of the button, rather than the
2070 * command ID as used by every other NMTOOLBAR notification */
2071 nmtb
.iItem
= nIndexFrom
;
2072 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2074 PCUSTOMBUTTON btnInfo
;
2076 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2077 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2079 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2081 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2082 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2083 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2084 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2087 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2089 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2091 /* last item is always separator, so -2 instead of -1 */
2092 if (nIndexTo
>= (count
- 2))
2093 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2095 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2097 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2098 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2100 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2104 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2108 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2110 /* MSDN states that iItem is the index of the button, rather than the
2111 * command ID as used by every other NMTOOLBAR notification */
2112 nmtb
.iItem
= nIndexAvail
;
2113 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2115 PCUSTOMBUTTON btnInfo
;
2117 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2118 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2119 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2121 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2123 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2125 /* remove from 'available buttons' list */
2126 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2127 if (nIndexAvail
== count
-1)
2128 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2130 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2134 PCUSTOMBUTTON btnNew
;
2136 /* duplicate 'separator' button */
2137 btnNew
= Alloc(sizeof(CUSTOMBUTTON
));
2142 /* insert into 'toolbar button' list */
2143 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2144 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2146 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2148 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2152 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2154 PCUSTOMBUTTON btnInfo
;
2155 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2157 TRACE("Remove: index %d\n", index
);
2159 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2161 /* send TBN_QUERYDELETE notification */
2162 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2166 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2167 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2169 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2171 /* insert into 'available button' list */
2172 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2173 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2177 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2181 /* drag list notification function for toolbar buttons list box */
2182 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2183 const DRAGLISTINFO
*pDLI
)
2185 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2186 switch (pDLI
->uNotification
)
2190 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2191 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2192 /* no dragging for last item (separator) */
2193 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2198 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2199 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2200 /* no dragging past last item (separator) */
2201 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2203 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2204 /* FIXME: native uses "move button" cursor */
2205 return DL_COPYCURSOR
;
2208 /* not over toolbar buttons list */
2209 if (nCurrentItem
< 0)
2211 POINT ptWindow
= pDLI
->ptCursor
;
2212 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2213 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2214 /* over available buttons list? */
2215 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2216 /* FIXME: native uses "move button" cursor */
2217 return DL_COPYCURSOR
;
2219 /* clear drag arrow */
2220 DrawInsert(hwnd
, hwndList
, -1);
2221 return DL_STOPCURSOR
;
2225 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2226 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2227 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2228 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2230 /* clear drag arrow */
2231 DrawInsert(hwnd
, hwndList
, -1);
2233 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2235 /* not over toolbar buttons list */
2238 POINT ptWindow
= pDLI
->ptCursor
;
2239 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2240 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2241 /* over available buttons list? */
2242 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2243 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2248 /* Clear drag arrow */
2249 DrawInsert(hwnd
, hwndList
, -1);
2256 /* drag list notification function for available buttons list box */
2257 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2258 const DRAGLISTINFO
*pDLI
)
2260 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2261 switch (pDLI
->uNotification
)
2267 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2268 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2269 /* no dragging past last item (separator) */
2270 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2272 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2273 /* FIXME: native uses "move button" cursor */
2274 return DL_COPYCURSOR
;
2277 /* not over toolbar buttons list */
2278 if (nCurrentItem
< 0)
2280 POINT ptWindow
= pDLI
->ptCursor
;
2281 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2282 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2283 /* over available buttons list? */
2284 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2285 /* FIXME: native uses "move button" cursor */
2286 return DL_COPYCURSOR
;
2288 /* clear drag arrow */
2289 DrawInsert(hwnd
, hwndList
, -1);
2290 return DL_STOPCURSOR
;
2294 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2295 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2296 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2297 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2299 /* clear drag arrow */
2300 DrawInsert(hwnd
, hwndList
, -1);
2302 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2306 /* Clear drag arrow */
2307 DrawInsert(hwnd
, hwndList
, -1);
2313 extern UINT uDragListMessage DECLSPEC_HIDDEN
;
2315 /***********************************************************************
2316 * TOOLBAR_CustomizeDialogProc
2317 * This function implements the toolbar customization dialog.
2319 static INT_PTR CALLBACK
2320 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2322 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2323 PCUSTOMBUTTON btnInfo
;
2325 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2330 custInfo
= (PCUSTDLG_INFO
)lParam
;
2331 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2338 NMTBINITCUSTOMIZE nmtbic
;
2340 infoPtr
= custInfo
->tbInfo
;
2342 /* send TBN_QUERYINSERT notification */
2343 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2345 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2348 nmtbic
.hwndDialog
= hwnd
;
2349 /* Send TBN_INITCUSTOMIZE notification */
2350 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2353 TRACE("TBNRF_HIDEHELP requested\n");
2354 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2357 /* add items to 'toolbar buttons' list and check if removable */
2358 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2360 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2361 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2362 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2363 btnInfo
->bVirtual
= FALSE
;
2364 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2366 /* send TBN_QUERYDELETE notification */
2367 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2369 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2370 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2373 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2375 /* insert separator button into 'available buttons' list */
2376 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2377 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2378 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2379 btnInfo
->bVirtual
= FALSE
;
2380 btnInfo
->bRemovable
= TRUE
;
2381 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2382 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2383 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2385 /* insert all buttons into dsa */
2388 /* send TBN_GETBUTTONINFO notification */
2391 nmtb
.pszText
= Buffer
;
2394 /* Clear previous button's text */
2395 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2397 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2400 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2401 nmtb
.tbButton
.fsStyle
, i
,
2402 nmtb
.tbButton
.idCommand
,
2403 nmtb
.tbButton
.iString
,
2404 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2407 /* insert button into the appropriate list */
2408 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2411 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2412 btnInfo
->bVirtual
= FALSE
;
2413 btnInfo
->bRemovable
= TRUE
;
2417 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2418 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2421 btnInfo
->btn
= nmtb
.tbButton
;
2422 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2424 if (lstrlenW(nmtb
.pszText
))
2425 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2426 else if (nmtb
.tbButton
.iString
>= 0 &&
2427 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2429 lstrcpyW(btnInfo
->text
,
2430 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2435 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2438 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2440 /* select first item in the 'available' list */
2441 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2443 /* append 'virtual' separator button to the 'toolbar buttons' list */
2444 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2445 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2446 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2447 btnInfo
->bVirtual
= TRUE
;
2448 btnInfo
->bRemovable
= FALSE
;
2449 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2450 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2451 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2453 /* select last item in the 'toolbar' list */
2454 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2455 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2457 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2458 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2460 /* set focus and disable buttons */
2461 PostMessageW (hwnd
, WM_USER
, 0, 0);
2466 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2467 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2468 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2469 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2473 EndDialog(hwnd
, FALSE
);
2477 switch (LOWORD(wParam
))
2479 case IDC_TOOLBARBTN_LBOX
:
2480 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2482 PCUSTOMBUTTON btnInfo
;
2487 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2488 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2490 /* send TBN_QUERYINSERT notification */
2492 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2494 /* get list box item */
2495 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2497 if (index
== (count
- 1))
2499 /* last item (virtual separator) */
2500 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2501 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2503 else if (index
== (count
- 2))
2505 /* second last item (last non-virtual item) */
2506 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2507 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2509 else if (index
== 0)
2512 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2513 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2517 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2518 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2521 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2525 case IDC_MOVEUP_BTN
:
2527 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2528 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2532 case IDC_MOVEDN_BTN
: /* move down */
2534 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2535 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2539 case IDC_REMOVE_BTN
: /* remove button */
2541 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2543 if (LB_ERR
== index
)
2546 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2550 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2553 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2556 case IDOK
: /* Add button */
2561 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2562 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2564 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2569 EndDialog(hwnd
, FALSE
);
2579 /* delete items from 'toolbar buttons' listbox*/
2580 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2581 for (i
= 0; i
< count
; i
++)
2583 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2585 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2587 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2590 /* delete items from 'available buttons' listbox*/
2591 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2592 for (i
= 0; i
< count
; i
++)
2594 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2596 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2598 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2603 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2605 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2610 COLORREF oldText
= 0;
2614 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, lpdis
->itemID
, 0);
2615 if (btnInfo
== NULL
)
2617 FIXME("btnInfo invalid!\n");
2621 /* set colors and select objects */
2622 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2623 if (btnInfo
->bVirtual
)
2624 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2626 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2627 hPen
= CreatePen( PS_SOLID
, 1,
2628 (lpdis
->itemState
& ODS_SELECTED
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2629 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2630 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2632 /* fill background rectangle */
2633 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2634 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2636 /* calculate button and text rectangles */
2637 CopyRect (&rcButton
, &lpdis
->rcItem
);
2638 InflateRect (&rcButton
, -1, -1);
2639 CopyRect (&rcText
, &rcButton
);
2640 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2641 rcText
.left
= rcButton
.right
+ 2;
2643 /* draw focus rectangle */
2644 if (lpdis
->itemState
& ODS_FOCUS
)
2645 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2648 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2649 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2651 /* draw image and text */
2652 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2653 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2654 btnInfo
->btn
.iBitmap
));
2655 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2656 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2658 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2659 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2661 /* delete objects and reset colors */
2662 SelectObject (lpdis
->hDC
, hOldBrush
);
2663 SelectObject (lpdis
->hDC
, hOldPen
);
2664 SetBkColor (lpdis
->hDC
, oldBk
);
2665 SetTextColor (lpdis
->hDC
, oldText
);
2666 DeleteObject( hPen
);
2671 case WM_MEASUREITEM
:
2672 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2674 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2676 lpmis
->itemHeight
= 15 + 8; /* default height */
2683 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2685 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2687 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2688 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2689 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2692 else if (wParam
== IDC_AVAILBTN_LBOX
)
2694 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2695 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2696 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2705 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2708 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2714 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2715 /* Add bitmaps to the default image list */
2716 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2717 hbmLoad
= CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2718 else if (bitmap
->hInst
== COMCTL32_hModule
)
2719 hbmLoad
= LoadImageW( bitmap
->hInst
, MAKEINTRESOURCEW(bitmap
->nID
),
2720 IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
2722 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2724 /* enlarge the bitmap if needed */
2725 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2726 if (bitmap
->hInst
!= COMCTL32_hModule
)
2727 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2729 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2730 DeleteObject(hbmLoad
);
2734 nCountAfter
= ImageList_GetImageCount(himlDef
);
2735 nAdded
= nCountAfter
- nCountBefore
;
2736 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2738 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2739 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2740 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2741 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2744 infoPtr
->nNumBitmaps
+= nAdded
;
2749 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2756 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2757 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2759 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2761 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2764 TRACE("Update icon size: %dx%d -> %dx%d\n",
2765 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2767 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2768 ILC_COLOR32
|ILC_MASK
, 8, 2);
2769 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2770 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2771 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2772 infoPtr
->himlInt
= himlNew
;
2774 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2775 ImageList_Destroy(himlDef
);
2778 /***********************************************************************
2779 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2783 TOOLBAR_AddBitmap (TOOLBAR_INFO
*infoPtr
, INT count
, const TBADDBITMAP
*lpAddBmp
)
2789 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr
->hwndSelf
, count
, lpAddBmp
);
2793 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2795 info
.hInst
= COMCTL32_hModule
;
2796 switch (lpAddBmp
->nID
)
2798 case IDB_STD_SMALL_COLOR
:
2800 info
.nID
= IDB_STD_SMALL
;
2802 case IDB_STD_LARGE_COLOR
:
2804 info
.nID
= IDB_STD_LARGE
;
2806 case IDB_VIEW_SMALL_COLOR
:
2808 info
.nID
= IDB_VIEW_SMALL
;
2810 case IDB_VIEW_LARGE_COLOR
:
2812 info
.nID
= IDB_VIEW_LARGE
;
2814 case IDB_HIST_SMALL_COLOR
:
2816 info
.nID
= IDB_HIST_SMALL
;
2818 case IDB_HIST_LARGE_COLOR
:
2820 info
.nID
= IDB_HIST_LARGE
;
2826 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2828 /* Windows resize all the buttons to the size of a newly added standard image */
2829 if (lpAddBmp
->nID
& 1)
2831 /* large icons: 24x24. Will make the button 31x30 */
2832 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2836 /* small icons: 16x16. Will make the buttons 23x22 */
2837 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2840 TOOLBAR_CalcToolbar (infoPtr
);
2844 info
.nButtons
= count
;
2845 info
.hInst
= lpAddBmp
->hInst
;
2846 info
.nID
= lpAddBmp
->nID
;
2847 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2850 /* check if the bitmap is already loaded and compute iSumButtons */
2852 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2854 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2855 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2857 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2860 if (!infoPtr
->cimlDef
) {
2861 /* create new default image list */
2862 TRACE ("creating default image list!\n");
2864 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2865 ILC_COLOR32
| ILC_MASK
, info
.nButtons
, 2);
2866 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2867 infoPtr
->himlInt
= himlDef
;
2870 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2874 WARN("No default image list available\n");
2878 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2881 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2882 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2883 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2884 infoPtr
->nNumBitmapInfos
++;
2885 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2887 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2893 TOOLBAR_AddButtonsT(TOOLBAR_INFO
*infoPtr
, INT nAddButtons
, const TBBUTTON
* lpTbb
, BOOL fUnicode
)
2895 TRACE("adding %d buttons (unicode=%d)!\n", nAddButtons
, fUnicode
);
2897 return TOOLBAR_InternalInsertButtonsT(infoPtr
, -1, nAddButtons
, lpTbb
, fUnicode
);
2902 TOOLBAR_AddStringW (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
2904 #define MAX_RESOURCE_STRING_LENGTH 512
2905 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2906 INT nIndex
= infoPtr
->nNumStrings
;
2908 TRACE("%p, %lx\n", hInstance
, lParam
);
2910 if (IS_INTRESOURCE(lParam
)) {
2911 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2918 TRACE("adding string from resource\n");
2920 if (!hInstance
) return -1;
2922 hrsrc
= FindResourceW( hInstance
, MAKEINTRESOURCEW((LOWORD(lParam
) >> 4) + 1),
2923 (LPWSTR
)RT_STRING
);
2926 TRACE("string not found in resources\n");
2930 len
= LoadStringW (hInstance
, (UINT
)lParam
,
2931 szString
, MAX_RESOURCE_STRING_LENGTH
);
2933 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2934 if (len
== 0 || len
== 1)
2937 TRACE("delimiter: 0x%x\n", *szString
);
2938 delimiter
= *szString
;
2941 while ((next_delim
= strchrW(p
, delimiter
)) != NULL
) {
2943 if (next_delim
+ 1 >= szString
+ len
)
2945 /* this may happen if delimiter == '\0' or if the last char is a
2946 * delimiter (then it is ignored like the native does) */
2950 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2951 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2952 infoPtr
->nNumStrings
++;
2958 LPWSTR p
= (LPWSTR
)lParam
;
2963 TRACE("adding string(s) from array\n");
2967 TRACE("len=%d %s\n", len
, debugstr_w(p
));
2968 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2969 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2970 infoPtr
->nNumStrings
++;
2977 TOOLBAR_CalcToolbar(infoPtr
);
2983 TOOLBAR_AddStringA (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
2985 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2990 TRACE("%p, %lx\n", hInstance
, lParam
);
2992 if (IS_INTRESOURCE(lParam
)) /* load from resources */
2993 return TOOLBAR_AddStringW(infoPtr
, hInstance
, lParam
);
2999 TRACE("adding string(s) from array\n");
3000 nIndex
= infoPtr
->nNumStrings
;
3003 TRACE("len=%d \"%s\"\n", len
, p
);
3005 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3006 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3007 infoPtr
->nNumStrings
++;
3013 TOOLBAR_CalcToolbar(infoPtr
);
3019 TOOLBAR_AutoSize (TOOLBAR_INFO
*infoPtr
)
3026 TRACE("auto sizing, style=%x!\n", infoPtr
->dwStyle
);
3028 parent
= GetParent (infoPtr
->hwndSelf
);
3030 if (!parent
|| !infoPtr
->bDoRedraw
)
3033 GetClientRect(parent
, &parent_rect
);
3035 x
= parent_rect
.left
;
3036 y
= parent_rect
.top
;
3038 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3040 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3041 cx
= parent_rect
.right
- parent_rect
.left
;
3043 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
))
3045 TOOLBAR_LayoutToolbar(infoPtr
);
3046 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
3049 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3052 UINT uPosFlags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
3054 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3056 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3057 MapWindowPoints( 0, parent
, (POINT
*)&window_rect
, 2 );
3058 y
= window_rect
.top
;
3060 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3062 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3063 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3066 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3067 uPosFlags
|= SWP_NOMOVE
;
3069 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3070 cy
+= GetSystemMetrics(SM_CYEDGE
);
3072 if (infoPtr
->dwStyle
& WS_BORDER
)
3074 cx
+= 2 * GetSystemMetrics(SM_CXBORDER
);
3075 cy
+= 2 * GetSystemMetrics(SM_CYBORDER
);
3078 SetWindowPos(infoPtr
->hwndSelf
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3085 static inline LRESULT
3086 TOOLBAR_ButtonCount (const TOOLBAR_INFO
*infoPtr
)
3088 return infoPtr
->nNumButtons
;
3092 static inline LRESULT
3093 TOOLBAR_ButtonStructSize (TOOLBAR_INFO
*infoPtr
, DWORD Size
)
3095 infoPtr
->dwStructSize
= Size
;
3102 TOOLBAR_ChangeBitmap (TOOLBAR_INFO
*infoPtr
, INT Id
, INT Index
)
3104 TBUTTON_INFO
*btnPtr
;
3107 TRACE("button %d, iBitmap now %d\n", Id
, Index
);
3109 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3113 btnPtr
= &infoPtr
->buttons
[nIndex
];
3114 btnPtr
->iBitmap
= Index
;
3116 /* we HAVE to erase the background, the new bitmap could be */
3118 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3125 TOOLBAR_CheckButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3127 TBUTTON_INFO
*btnPtr
;
3130 BOOL bChecked
= FALSE
;
3132 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3134 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, nIndex
, lParam
);
3139 btnPtr
= &infoPtr
->buttons
[nIndex
];
3141 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) != 0;
3143 if (LOWORD(lParam
) == FALSE
)
3144 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3146 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3148 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3149 if (nOldIndex
== nIndex
)
3151 if (nOldIndex
!= -1)
3152 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3154 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3157 if( bChecked
!= LOWORD(lParam
) )
3159 if (nOldIndex
!= -1)
3160 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3161 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3164 /* FIXME: Send a WM_NOTIFY?? */
3171 TOOLBAR_CommandToIndex (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3173 return TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3178 TOOLBAR_Customize (TOOLBAR_INFO
*infoPtr
)
3180 CUSTDLG_INFO custInfo
;
3184 custInfo
.tbInfo
= infoPtr
;
3185 custInfo
.tbHwnd
= infoPtr
->hwndSelf
;
3187 /* send TBN_BEGINADJUST notification */
3188 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3190 ret
= DialogBoxParamW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3191 infoPtr
->hwndSelf
, TOOLBAR_CustomizeDialogProc
, (LPARAM
)&custInfo
);
3193 /* send TBN_ENDADJUST notification */
3194 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3201 TOOLBAR_DeleteButton (TOOLBAR_INFO
*infoPtr
, INT nIndex
)
3204 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3206 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3209 memset(&nmtb
, 0, sizeof(nmtb
));
3210 nmtb
.iItem
= btnPtr
->idCommand
;
3211 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3212 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3213 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3214 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3215 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3216 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3217 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3219 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3221 if (infoPtr
->nNumButtons
== 1) {
3222 TRACE(" simple delete!\n");
3223 if (TOOLBAR_ButtonHasString(infoPtr
->buttons
))
3224 Free((LPWSTR
)infoPtr
->buttons
[0].iString
);
3225 Free (infoPtr
->buttons
);
3226 infoPtr
->buttons
= NULL
;
3227 infoPtr
->nNumButtons
= 0;
3230 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3231 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3233 infoPtr
->nNumButtons
--;
3234 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3236 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3237 nIndex
* sizeof(TBUTTON_INFO
));
3240 if (nIndex
< infoPtr
->nNumButtons
) {
3241 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3242 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3245 if (TOOLBAR_ButtonHasString(&oldButtons
[nIndex
]))
3246 Free((LPWSTR
)oldButtons
[nIndex
].iString
);
3250 TOOLBAR_LayoutToolbar(infoPtr
);
3252 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3259 TOOLBAR_EnableButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3261 TBUTTON_INFO
*btnPtr
;
3265 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3267 TRACE("hwnd=%p, btn id=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, Id
, lParam
);
3272 btnPtr
= &infoPtr
->buttons
[nIndex
];
3274 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3276 /* update the toolbar button state */
3277 if(LOWORD(lParam
) == FALSE
) {
3278 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3280 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3283 /* redraw the button only if the state of the button changed */
3284 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3285 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3291 static inline LRESULT
3292 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO
*infoPtr
)
3294 return infoPtr
->bAnchor
;
3299 TOOLBAR_GetBitmap (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3303 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3307 return infoPtr
->buttons
[nIndex
].iBitmap
;
3311 static inline LRESULT
3312 TOOLBAR_GetBitmapFlags (void)
3314 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3319 TOOLBAR_GetButton (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, TBBUTTON
*lpTbb
)
3321 TBUTTON_INFO
*btnPtr
;
3326 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3329 btnPtr
= &infoPtr
->buttons
[nIndex
];
3330 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3331 lpTbb
->idCommand
= btnPtr
->idCommand
;
3332 lpTbb
->fsState
= btnPtr
->fsState
;
3333 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3334 lpTbb
->bReserved
[0] = 0;
3335 lpTbb
->bReserved
[1] = 0;
3336 lpTbb
->dwData
= btnPtr
->dwData
;
3337 lpTbb
->iString
= btnPtr
->iString
;
3344 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO
*infoPtr
, INT Id
, LPTBBUTTONINFOW lpTbInfo
, BOOL bUnicode
)
3346 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3347 TBUTTON_INFO
*btnPtr
;
3350 if (lpTbInfo
== NULL
)
3353 /* MSDN documents an iImageLabel field added in Vista but it is not present in
3354 * the headers and tests shows that even with comctl 6 Vista accepts only the
3355 * original TBBUTTONINFO size
3357 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3359 WARN("Invalid button size\n");
3363 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lpTbInfo
->dwMask
& TBIF_BYINDEX
);
3367 if (!(btnPtr
= &infoPtr
->buttons
[nIndex
])) return -1;
3369 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3370 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3371 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3372 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3373 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3374 lpTbInfo
->lParam
= btnPtr
->dwData
;
3375 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3376 /* tests show that for separators TBIF_SIZE returns not calculated width,
3377 but cx property, that differs from 0 only if application have
3378 specifically set it */
3379 lpTbInfo
->cx
= (btnPtr
->fsStyle
& BTNS_SEP
)
3380 ? btnPtr
->cx
: (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3381 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3382 lpTbInfo
->fsState
= btnPtr
->fsState
;
3383 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3384 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3385 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3386 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3387 can't use TOOLBAR_GetText here */
3388 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3389 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3391 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3393 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3395 lpTbInfo
->pszText
[0] = '\0';
3401 static inline LRESULT
3402 TOOLBAR_GetButtonSize (const TOOLBAR_INFO
*infoPtr
)
3404 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3405 (WORD
)infoPtr
->nButtonHeight
);
3410 TOOLBAR_GetButtonText (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPWSTR lpStr
, BOOL isW
)
3416 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3420 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3426 ret
= strlenW (lpText
);
3427 if (lpStr
) strcpyW (lpStr
, lpText
);
3431 ret
= WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3432 (LPSTR
)lpStr
, lpStr
? 0x7fffffff : 0, NULL
, NULL
) - 1;
3438 TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3440 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3441 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3442 return (LRESULT
)GETDISIMAGELIST(infoPtr
, wParam
);
3446 static inline LRESULT
3447 TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO
*infoPtr
)
3451 return infoPtr
->dwExStyle
;
3456 TOOLBAR_GetHotImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3458 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3459 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3460 return (LRESULT
)GETHOTIMAGELIST(infoPtr
, wParam
);
3465 TOOLBAR_GetHotItem (const TOOLBAR_INFO
*infoPtr
)
3467 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3470 if (infoPtr
->nHotItem
< 0)
3473 return (LRESULT
)infoPtr
->nHotItem
;
3478 TOOLBAR_GetDefImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3480 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3481 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3482 return (LRESULT
) GETDEFIMAGELIST(infoPtr
, wParam
);
3487 TOOLBAR_GetInsertMark (const TOOLBAR_INFO
*infoPtr
, TBINSERTMARK
*lptbim
)
3489 TRACE("hwnd = %p, lptbim = %p\n", infoPtr
->hwndSelf
, lptbim
);
3491 *lptbim
= infoPtr
->tbim
;
3497 static inline LRESULT
3498 TOOLBAR_GetInsertMarkColor (const TOOLBAR_INFO
*infoPtr
)
3500 TRACE("hwnd = %p\n", infoPtr
->hwndSelf
);
3502 return (LRESULT
)infoPtr
->clrInsertMark
;
3507 TOOLBAR_GetItemRect (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, LPRECT lpRect
)
3509 TBUTTON_INFO
*btnPtr
;
3511 btnPtr
= &infoPtr
->buttons
[nIndex
];
3512 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3517 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3520 lpRect
->left
= btnPtr
->rect
.left
;
3521 lpRect
->right
= btnPtr
->rect
.right
;
3522 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3523 lpRect
->top
= btnPtr
->rect
.top
;
3530 TOOLBAR_GetMaxSize (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
3535 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3536 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3538 TRACE("maximum size %d x %d\n",
3539 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3540 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3546 /* << TOOLBAR_GetObject >> */
3549 static inline LRESULT
3550 TOOLBAR_GetPadding (const TOOLBAR_INFO
*infoPtr
)
3552 return MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3557 TOOLBAR_GetRect (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPRECT lpRect
)
3559 TBUTTON_INFO
*btnPtr
;
3562 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3563 btnPtr
= &infoPtr
->buttons
[nIndex
];
3564 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3570 lpRect
->left
= btnPtr
->rect
.left
;
3571 lpRect
->right
= btnPtr
->rect
.right
;
3572 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3573 lpRect
->top
= btnPtr
->rect
.top
;
3579 static inline LRESULT
3580 TOOLBAR_GetRows (const TOOLBAR_INFO
*infoPtr
)
3582 return infoPtr
->nRows
;
3587 TOOLBAR_GetState (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3591 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3595 return infoPtr
->buttons
[nIndex
].fsState
;
3599 static inline LRESULT
3600 TOOLBAR_GetStyle (const TOOLBAR_INFO
*infoPtr
)
3602 return infoPtr
->dwStyle
;
3606 static inline LRESULT
3607 TOOLBAR_GetTextRows (const TOOLBAR_INFO
*infoPtr
)
3609 return infoPtr
->nMaxTextRows
;
3614 TOOLBAR_GetToolTips (TOOLBAR_INFO
*infoPtr
)
3616 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3617 TOOLBAR_TooltipCreateControl(infoPtr
);
3618 return (LRESULT
)infoPtr
->hwndToolTip
;
3623 TOOLBAR_GetUnicodeFormat (const TOOLBAR_INFO
*infoPtr
)
3625 TRACE("%s hwnd=%p\n",
3626 infoPtr
->bUnicode
? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
3628 return infoPtr
->bUnicode
;
3632 static inline LRESULT
3633 TOOLBAR_GetVersion (const TOOLBAR_INFO
*infoPtr
)
3635 return infoPtr
->iVersion
;
3640 TOOLBAR_HideButton (TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fHide
)
3642 TBUTTON_INFO
*btnPtr
;
3648 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3652 btnPtr
= &infoPtr
->buttons
[nIndex
];
3653 oldState
= btnPtr
->fsState
;
3656 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3658 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3660 if (oldState
!= btnPtr
->fsState
) {
3661 TOOLBAR_LayoutToolbar (infoPtr
);
3662 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3669 static inline LRESULT
3670 TOOLBAR_HitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
* lpPt
)
3672 return TOOLBAR_InternalHitTest (infoPtr
, lpPt
, NULL
);
3677 TOOLBAR_Indeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fIndeterminate
)
3679 TBUTTON_INFO
*btnPtr
;
3683 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3687 btnPtr
= &infoPtr
->buttons
[nIndex
];
3688 oldState
= btnPtr
->fsState
;
3691 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3693 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3695 if(oldState
!= btnPtr
->fsState
)
3696 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3703 TOOLBAR_InsertButtonT(TOOLBAR_INFO
*infoPtr
, INT nIndex
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
3709 /* EPP: this seems to be an undocumented call (from my IE4)
3710 * I assume in that case that:
3711 * - index of insertion is at the end of existing buttons
3712 * I only see this happen with nIndex == -1, but it could have a special
3713 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3715 nIndex
= infoPtr
->nNumButtons
;
3717 } else if (nIndex
< 0)
3720 TRACE("inserting button index=%d\n", nIndex
);
3721 if (nIndex
> infoPtr
->nNumButtons
) {
3722 nIndex
= infoPtr
->nNumButtons
;
3723 TRACE("adjust index=%d\n", nIndex
);
3726 return TOOLBAR_InternalInsertButtonsT(infoPtr
, nIndex
, 1, lpTbb
, fUnicode
);
3729 /* << TOOLBAR_InsertMarkHitTest >> */
3733 TOOLBAR_IsButtonChecked (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3737 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3741 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3746 TOOLBAR_IsButtonEnabled (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3750 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3754 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3759 TOOLBAR_IsButtonHidden (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3763 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3767 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3772 TOOLBAR_IsButtonHighlighted (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3776 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3780 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3785 TOOLBAR_IsButtonIndeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3789 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3793 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3798 TOOLBAR_IsButtonPressed (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3802 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3806 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3811 TOOLBAR_LoadImages (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HINSTANCE hInstance
)
3814 tbab
.hInst
= hInstance
;
3817 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", infoPtr
->hwndSelf
, tbab
.hInst
, tbab
.nID
);
3819 return TOOLBAR_AddBitmap(infoPtr
, 0, &tbab
);
3824 TOOLBAR_MapAccelerator (const TOOLBAR_INFO
*infoPtr
, WCHAR wAccel
, UINT
*pIDButton
)
3826 WCHAR wszAccel
[] = {'&',wAccel
,0};
3829 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3830 infoPtr
->hwndSelf
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3832 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3834 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3835 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3836 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3838 int iLen
= strlenW(wszAccel
);
3839 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3846 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3851 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
3853 *pIDButton
= btnPtr
->idCommand
;
3865 TOOLBAR_MarkButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fMark
)
3869 TBUTTON_INFO
*btnPtr
;
3871 TRACE("hwnd = %p, Id = %d, fMark = 0%d\n", infoPtr
->hwndSelf
, Id
, fMark
);
3873 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3877 btnPtr
= &infoPtr
->buttons
[nIndex
];
3878 oldState
= btnPtr
->fsState
;
3881 btnPtr
->fsState
|= TBSTATE_MARKED
;
3883 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
3885 if(oldState
!= btnPtr
->fsState
)
3886 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3892 /* fixes up an index of a button affected by a move */
3893 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
3897 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
3899 else if (*pIndex
== nIndex
)
3900 *pIndex
= nMoveIndex
;
3904 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
3906 else if (*pIndex
== nIndex
)
3907 *pIndex
= nMoveIndex
;
3913 TOOLBAR_MoveButton (TOOLBAR_INFO
*infoPtr
, INT Id
, INT nMoveIndex
)
3917 TBUTTON_INFO button
;
3919 TRACE("hwnd=%p, Id=%d, nMoveIndex=%d\n", infoPtr
->hwndSelf
, Id
, nMoveIndex
);
3921 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, TRUE
);
3922 if ((nIndex
== -1) || (nMoveIndex
< 0))
3925 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
3926 nMoveIndex
= infoPtr
->nNumButtons
- 1;
3928 button
= infoPtr
->buttons
[nIndex
];
3930 /* move button right */
3931 if (nIndex
< nMoveIndex
)
3933 nCount
= nMoveIndex
- nIndex
;
3934 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
3935 infoPtr
->buttons
[nMoveIndex
] = button
;
3937 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
3938 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
3939 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
3940 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
3942 else if (nIndex
> nMoveIndex
) /* move button left */
3944 nCount
= nIndex
- nMoveIndex
;
3945 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
3946 infoPtr
->buttons
[nMoveIndex
] = button
;
3948 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
3949 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
3950 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
3951 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
3954 TOOLBAR_LayoutToolbar(infoPtr
);
3955 TOOLBAR_AutoSize(infoPtr
);
3956 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
3963 TOOLBAR_PressButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fPress
)
3965 TBUTTON_INFO
*btnPtr
;
3969 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3973 btnPtr
= &infoPtr
->buttons
[nIndex
];
3974 oldState
= btnPtr
->fsState
;
3977 btnPtr
->fsState
|= TBSTATE_PRESSED
;
3979 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
3981 if(oldState
!= btnPtr
->fsState
)
3982 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3987 /* FIXME: there might still be some confusion her between number of buttons
3988 * and number of bitmaps */
3990 TOOLBAR_ReplaceBitmap (TOOLBAR_INFO
*infoPtr
, const TBREPLACEBITMAP
*lpReplace
)
3993 int i
= 0, nOldButtons
= 0, pos
= 0;
3994 int nOldBitmaps
, nNewBitmaps
= 0;
3995 HIMAGELIST himlDef
= 0;
3997 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
3998 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
3999 lpReplace
->nButtons
);
4001 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4003 FIXME("changing standard bitmaps not implemented\n");
4006 else if (lpReplace
->hInstOld
!= 0 && lpReplace
->hInstOld
!= lpReplace
->hInstNew
)
4007 FIXME("resources not in the current module not implemented\n");
4009 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4010 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4011 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4012 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4013 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4015 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4016 nOldButtons
= tbi
->nButtons
;
4017 tbi
->nButtons
= lpReplace
->nButtons
;
4018 tbi
->hInst
= lpReplace
->hInstNew
;
4019 tbi
->nID
= lpReplace
->nIDNew
;
4020 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4023 pos
+= tbi
->nButtons
;
4026 if (nOldButtons
== 0)
4028 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4032 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4035 if (lpReplace
->hInstNew
)
4036 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4038 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4040 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4041 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4043 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4045 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4046 ImageList_Remove(himlDef
, i
);
4050 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4051 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4052 DeleteObject(hBitmap
);
4055 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4057 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4058 pos
, nOldBitmaps
, nNewBitmaps
);
4060 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4065 /* helper for TOOLBAR_SaveRestoreW */
4067 TOOLBAR_Save(const TBSAVEPARAMSW
*lpSave
)
4069 FIXME("save to %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4070 debugstr_w(lpSave
->pszValueName
));
4076 /* helper for TOOLBAR_Restore */
4078 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4082 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4084 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4087 Free(infoPtr
->buttons
);
4088 infoPtr
->buttons
= NULL
;
4089 infoPtr
->nNumButtons
= 0;
4093 /* helper for TOOLBAR_SaveRestoreW */
4095 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4104 /* restore toolbar information */
4105 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4106 debugstr_w(lpSave
->pszValueName
));
4108 memset(&nmtbr
, 0, sizeof(nmtbr
));
4110 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4111 KEY_QUERY_VALUE
, &hkey
);
4113 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4115 if (!res
&& dwType
!= REG_BINARY
)
4116 res
= ERROR_FILE_NOT_FOUND
;
4119 nmtbr
.pData
= Alloc(dwSize
);
4120 nmtbr
.cbData
= dwSize
;
4121 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4124 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4125 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4128 nmtbr
.pCurrent
= nmtbr
.pData
;
4130 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4131 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4133 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4137 /* remove all existing buttons as this function is designed to
4138 * restore the toolbar to a previously saved state */
4139 TOOLBAR_DeleteAllButtons(infoPtr
);
4141 for (i
= 0; i
< nmtbr
.cButtons
; i
++)
4144 nmtbr
.tbButton
.iBitmap
= -1;
4145 nmtbr
.tbButton
.fsState
= 0;
4146 nmtbr
.tbButton
.fsStyle
= 0;
4147 nmtbr
.tbButton
.idCommand
= 0;
4148 if (*nmtbr
.pCurrent
== (DWORD
)-1)
4151 nmtbr
.tbButton
.fsStyle
= TBSTYLE_SEP
;
4152 /* when inserting separators, iBitmap controls its size.
4153 0 sets default size (width) */
4154 nmtbr
.tbButton
.iBitmap
= 0;
4156 else if (*nmtbr
.pCurrent
== (DWORD
)-2)
4158 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4160 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4164 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4166 /* can't contain real string as we don't know whether
4167 * the client put an ANSI or Unicode string in there */
4168 if (!IS_INTRESOURCE(nmtbr
.tbButton
.iString
))
4169 nmtbr
.tbButton
.iString
= 0;
4171 TOOLBAR_InsertButtonT(infoPtr
, -1, &nmtbr
.tbButton
, TRUE
);
4174 /* do legacy notifications */
4175 if (infoPtr
->iVersion
< 5)
4177 /* FIXME: send TBN_BEGINADJUST */
4178 FIXME("send TBN_GETBUTTONINFO for each button\n");
4179 /* FIXME: send TBN_ENDADJUST */
4182 /* remove all uninitialised buttons
4183 * note: loop backwards to avoid having to fixup i on a
4185 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4186 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4187 TOOLBAR_DeleteButton(infoPtr
, i
);
4189 /* only indicate success if at least one button survived */
4190 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4201 TOOLBAR_SaveRestoreW (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4203 if (lpSave
== NULL
) return 0;
4206 return TOOLBAR_Save(lpSave
);
4208 return TOOLBAR_Restore(infoPtr
, lpSave
);
4213 TOOLBAR_SaveRestoreA (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4215 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4216 TBSAVEPARAMSW SaveW
;
4220 if (lpSave
== NULL
) return 0;
4222 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4223 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4224 if (pszSubKey
) goto exit
;
4225 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4227 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4228 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4229 if (!pszValueName
) goto exit
;
4230 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4232 SaveW
.pszValueName
= pszValueName
;
4233 SaveW
.pszSubKey
= pszSubKey
;
4234 SaveW
.hkr
= lpSave
->hkr
;
4235 result
= TOOLBAR_SaveRestoreW(infoPtr
, wParam
, &SaveW
);
4238 Free (pszValueName
);
4246 TOOLBAR_SetAnchorHighlight (TOOLBAR_INFO
*infoPtr
, BOOL bAnchor
)
4248 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4250 TRACE("hwnd=%p, bAnchor = %s\n", infoPtr
->hwndSelf
, bAnchor
? "TRUE" : "FALSE");
4252 infoPtr
->bAnchor
= bAnchor
;
4254 /* Native does not remove the hot effect from an already hot button */
4256 return (LRESULT
)bOldAnchor
;
4261 TOOLBAR_SetBitmapSize (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4263 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4264 short width
= (short)LOWORD(lParam
);
4265 short height
= (short)HIWORD(lParam
);
4267 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", infoPtr
->hwndSelf
, wParam
, lParam
);
4270 FIXME("wParam is %ld. Perhaps image list index?\n", wParam
);
4272 /* 0 width or height is changed to 1 */
4278 if (infoPtr
->nNumButtons
> 0)
4279 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4280 infoPtr
->nNumButtons
,
4281 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
, width
, height
);
4283 if (width
< -1 || height
< -1)
4285 /* Windows destroys the imagelist and seems to actually use negative
4286 * values to compute button sizes */
4287 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width
, height
);
4291 /* width or height of -1 means no change */
4293 infoPtr
->nBitmapWidth
= width
;
4295 infoPtr
->nBitmapHeight
= height
;
4297 if ((himlDef
== infoPtr
->himlInt
) &&
4298 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4300 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4301 infoPtr
->nBitmapHeight
);
4304 TOOLBAR_CalcToolbar(infoPtr
);
4305 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4311 TOOLBAR_SetButtonInfo (TOOLBAR_INFO
*infoPtr
, INT Id
,
4312 const TBBUTTONINFOW
*lptbbi
, BOOL isW
)
4314 TBUTTON_INFO
*btnPtr
;
4320 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4323 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lptbbi
->dwMask
& TBIF_BYINDEX
);
4327 btnPtr
= &infoPtr
->buttons
[nIndex
];
4328 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4329 btnPtr
->idCommand
= lptbbi
->idCommand
;
4330 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4331 btnPtr
->iBitmap
= lptbbi
->iImage
;
4332 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4333 btnPtr
->dwData
= lptbbi
->lParam
;
4334 if (lptbbi
->dwMask
& TBIF_SIZE
)
4335 btnPtr
->cx
= lptbbi
->cx
;
4336 if (lptbbi
->dwMask
& TBIF_STATE
)
4337 btnPtr
->fsState
= lptbbi
->fsState
;
4338 if (lptbbi
->dwMask
& TBIF_STYLE
)
4339 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4341 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4342 /* iString is index, zero it to make Str_SetPtr succeed */
4343 if (!TOOLBAR_ButtonHasString(btnPtr
)) btnPtr
->iString
= 0;
4346 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4348 Str_SetPtrAtoW ((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lptbbi
->pszText
);
4351 /* save the button rect to see if we need to redraw the whole toolbar */
4352 oldBtnRect
= btnPtr
->rect
;
4353 TOOLBAR_LayoutToolbar(infoPtr
);
4355 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4356 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4358 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4365 TOOLBAR_SetButtonSize (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4367 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4369 if ((cx
< 0) || (cy
< 0))
4371 ERR("invalid parameter 0x%08x\n", (DWORD
)lParam
);
4375 TRACE("%p, cx = %d, cy = %d\n", infoPtr
->hwndSelf
, cx
, cy
);
4377 /* The documentation claims you can only change the button size before
4378 * any button has been added. But this is wrong.
4379 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4380 * it to the toolbar, and it checks that the return value is nonzero - mjm
4381 * Further testing shows that we must actually perform the change too.
4384 * The documentation also does not mention that if 0 is supplied for
4385 * either size, the system changes it to the default of 24 wide and
4386 * 22 high. Demonstrated in ControlSpy Toolbar. GLA 3/02
4388 if (cx
== 0) cx
= 24;
4389 if (cy
== 0) cy
= 22;
4391 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4392 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4394 infoPtr
->nButtonWidth
= cx
;
4395 infoPtr
->nButtonHeight
= cy
;
4397 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
4398 TOOLBAR_LayoutToolbar(infoPtr
);
4404 TOOLBAR_SetButtonWidth (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4406 /* if setting to current values, ignore */
4407 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4408 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4409 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4410 infoPtr
->cxMin
, infoPtr
->cxMax
);
4414 /* save new values */
4415 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4416 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4418 /* otherwise we need to recalc the toolbar and in some cases
4419 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4420 which doesn't actually draw - GA). */
4421 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4422 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4424 TOOLBAR_CalcToolbar (infoPtr
);
4426 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
4433 TOOLBAR_SetCmdId (TOOLBAR_INFO
*infoPtr
, INT nIndex
, INT nId
)
4435 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4438 infoPtr
->buttons
[nIndex
].idCommand
= nId
;
4440 if (infoPtr
->hwndToolTip
) {
4442 FIXME("change tool tip!\n");
4451 TOOLBAR_SetDisabledImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4453 HIMAGELIST himlTemp
;
4456 if (infoPtr
->iVersion
>= 5)
4459 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4460 &infoPtr
->cimlDis
, himl
, id
);
4462 /* FIXME: redraw ? */
4464 return (LRESULT
)himlTemp
;
4469 TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4473 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", infoPtr
->hwndSelf
, (DWORD
)wParam
, (DWORD
)lParam
);
4475 dwTemp
= infoPtr
->dwDTFlags
;
4476 infoPtr
->dwDTFlags
=
4477 (infoPtr
->dwDTFlags
& (DWORD
)wParam
) | (DWORD
)lParam
;
4479 return (LRESULT
)dwTemp
;
4482 /* This function differs a bit from what MSDN says it does:
4483 * 1. lParam contains extended style flags to OR with current style
4484 * (MSDN isn't clear on the OR bit)
4485 * 2. wParam appears to contain extended style flags to be reset
4486 * (MSDN says that this parameter is reserved)
4489 TOOLBAR_SetExtendedStyle (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD style
)
4491 DWORD old_style
= infoPtr
->dwExStyle
;
4493 TRACE("mask=0x%08x, style=0x%08x\n", mask
, style
);
4496 infoPtr
->dwExStyle
= (old_style
& ~mask
) | (style
& mask
);
4498 infoPtr
->dwExStyle
= style
;
4500 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4501 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4502 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4504 if ((old_style
^ infoPtr
->dwExStyle
) & TBSTYLE_EX_MIXEDBUTTONS
)
4505 TOOLBAR_CalcToolbar(infoPtr
);
4507 TOOLBAR_LayoutToolbar(infoPtr
);
4509 TOOLBAR_AutoSize(infoPtr
);
4510 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4517 TOOLBAR_SetHotImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4519 HIMAGELIST himlTemp
;
4522 if (infoPtr
->iVersion
>= 5)
4525 TRACE("hwnd = %p, himl = %p, id = %d\n", infoPtr
->hwndSelf
, himl
, id
);
4527 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4528 &infoPtr
->cimlHot
, himl
, id
);
4530 /* FIXME: redraw ? */
4532 return (LRESULT
)himlTemp
;
4536 /* Makes previous hot button no longer hot, makes the specified
4537 * button hot and sends appropriate notifications. dwReason is one or
4538 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4539 * NOTE 1: this function does not validate nHit
4540 * NOTE 2: the name of this function is completely made up and
4541 * not based on any documentation from Microsoft. */
4543 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4545 if (infoPtr
->nHotItem
!= nHit
)
4547 NMTBHOTITEM nmhotitem
;
4548 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4550 nmhotitem
.dwFlags
= dwReason
;
4551 if(infoPtr
->nHotItem
>= 0)
4553 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4554 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4558 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4559 nmhotitem
.idOld
= 0;
4564 btnPtr
= &infoPtr
->buttons
[nHit
];
4565 nmhotitem
.idNew
= btnPtr
->idCommand
;
4569 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4570 nmhotitem
.idNew
= 0;
4573 /* now change the hot and invalidate the old and new buttons - if the
4575 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4578 oldBtnPtr
->bHot
= FALSE
;
4579 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4581 /* setting disabled buttons as hot fails even if the notify contains the button id */
4582 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4583 btnPtr
->bHot
= TRUE
;
4584 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4585 infoPtr
->nHotItem
= nHit
;
4588 infoPtr
->nHotItem
= -1;
4594 TOOLBAR_SetHotItem (TOOLBAR_INFO
*infoPtr
, INT nHotItem
)
4596 INT nOldHotItem
= infoPtr
->nHotItem
;
4598 TRACE("hwnd = %p, nHotItem = %d\n", infoPtr
->hwndSelf
, nHotItem
);
4600 if (nHotItem
>= infoPtr
->nNumButtons
)
4601 return infoPtr
->nHotItem
;
4606 /* NOTE: an application can still remove the hot item even if anchor
4607 * highlighting is enabled */
4609 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, HICF_OTHER
);
4611 if (nOldHotItem
< 0)
4614 return (LRESULT
)nOldHotItem
;
4619 TOOLBAR_SetImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4621 HIMAGELIST himlTemp
;
4622 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4623 INT oldBitmapWidth
= infoPtr
->nBitmapWidth
;
4624 INT oldBitmapHeight
= infoPtr
->nBitmapHeight
;
4627 if (infoPtr
->iVersion
>= 5)
4630 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4631 &infoPtr
->cimlDef
, himl
, id
);
4633 infoPtr
->nNumBitmaps
= 0;
4634 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4635 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4637 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4638 &infoPtr
->nBitmapHeight
))
4640 infoPtr
->nBitmapWidth
= 1;
4641 infoPtr
->nBitmapHeight
= 1;
4643 if ((oldBitmapWidth
!= infoPtr
->nBitmapWidth
) || (oldBitmapHeight
!= infoPtr
->nBitmapHeight
))
4645 TOOLBAR_CalcToolbar(infoPtr
);
4646 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4647 TOOLBAR_SetButtonSize(infoPtr
, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4650 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4651 infoPtr
->hwndSelf
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4652 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4654 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4656 return (LRESULT
)himlTemp
;
4661 TOOLBAR_SetIndent (TOOLBAR_INFO
*infoPtr
, INT nIndent
)
4663 infoPtr
->nIndent
= nIndent
;
4667 /* process only on indent changing */
4668 if(infoPtr
->nIndent
!= nIndent
)
4670 infoPtr
->nIndent
= nIndent
;
4671 TOOLBAR_CalcToolbar (infoPtr
);
4672 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4680 TOOLBAR_SetInsertMark (TOOLBAR_INFO
*infoPtr
, const TBINSERTMARK
*lptbim
)
4682 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", infoPtr
->hwndSelf
, lptbim
->iButton
, lptbim
->dwFlags
);
4684 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4686 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4690 if ((lptbim
->iButton
== -1) ||
4691 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4692 (lptbim
->iButton
>= 0)))
4694 infoPtr
->tbim
= *lptbim
;
4695 /* FIXME: don't need to update entire toolbar */
4696 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4699 ERR("Invalid button index %d\n", lptbim
->iButton
);
4706 TOOLBAR_SetInsertMarkColor (TOOLBAR_INFO
*infoPtr
, COLORREF clr
)
4708 infoPtr
->clrInsertMark
= clr
;
4710 /* FIXME: don't need to update entire toolbar */
4711 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4718 TOOLBAR_SetMaxTextRows (TOOLBAR_INFO
*infoPtr
, INT nMaxRows
)
4720 infoPtr
->nMaxTextRows
= nMaxRows
;
4722 TOOLBAR_CalcToolbar(infoPtr
);
4727 /* MSDN gives slightly wrong info on padding.
4728 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4729 * 2. It is not used to create a blank area between the edge of the button
4730 * and the text or image if TBSTYLE_LIST is set. It is used to control
4731 * the gap between the image and text.
4732 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4733 * to control the bottom and right borders [with the border being
4734 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4735 * is shared evenly on both sides of the button.
4736 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4739 TOOLBAR_SetPadding (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4743 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4744 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4745 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4746 TRACE("cx=%d, cy=%d\n",
4747 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4748 return (LRESULT
) oldPad
;
4753 TOOLBAR_SetParent (TOOLBAR_INFO
*infoPtr
, HWND hParent
)
4759 hwndOldNotify
= infoPtr
->hwndNotify
;
4760 infoPtr
->hwndNotify
= hParent
;
4762 return (LRESULT
)hwndOldNotify
;
4767 TOOLBAR_SetRows (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPRECT lprc
)
4769 int rows
= LOWORD(wParam
);
4770 BOOL bLarger
= HIWORD(wParam
);
4774 TRACE("Setting rows to %d (%d)\n", rows
, bLarger
);
4776 if(infoPtr
->nRows
!= rows
)
4778 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
;
4779 int curColumn
= 0; /* Current column */
4780 int curRow
= 0; /* Current row */
4781 int hidden
= 0; /* Number of hidden buttons */
4782 int seps
= 0; /* Number of separators */
4783 int idealWrap
= 0; /* Ideal wrap point */
4788 Calculate new size and wrap points - Under windows, setrows will
4789 change the dimensions if needed to show the number of requested
4790 rows (if CCS_NORESIZE is set), or will take up the whole window
4791 (if no CCS_NORESIZE).
4793 Basic algorithm - If N buttons, and y rows requested, each row
4794 contains N/y buttons.
4796 FIXME: Handling of separators not obvious from testing results
4797 FIXME: Take width of window into account?
4800 /* Loop through the buttons one by one counting key items */
4801 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4803 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
4804 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4806 else if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
4810 /* FIXME: Separators make this quite complex */
4811 if (seps
) FIXME("Separators unhandled\n");
4813 /* Round up so more per line, i.e., less rows */
4814 idealWrap
= (infoPtr
->nNumButtons
- hidden
+ (rows
-1)) / (rows
? rows
: 1);
4816 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4817 achieve the requested number of rows. */
4818 if (bLarger
&& idealWrap
> 1)
4820 int resRows
= (infoPtr
->nNumButtons
+ (idealWrap
-1)) / idealWrap
;
4821 int moreRows
= (infoPtr
->nNumButtons
+ (idealWrap
-2)) / (idealWrap
-1);
4823 if (resRows
< rows
&& moreRows
> rows
)
4826 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap
);
4830 curColumn
= curRow
= 0;
4832 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap
,
4833 infoPtr
->nNumButtons
, hidden
, rows
);
4835 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4837 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4840 /* Step on, wrap if necessary or flag next to wrap */
4849 if (curColumn
> (idealWrap
-1)) {
4851 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
4855 TRACE("Result - %d rows\n", curRow
+ 1);
4857 /* recalculate toolbar */
4858 TOOLBAR_CalcToolbar (infoPtr
);
4860 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
4861 if NORESIZE is NOT set, then the toolbar will always be resized to
4862 take up the whole window. With it set, sizing needs to be manual. */
4863 if (infoPtr
->dwStyle
& CCS_NORESIZE
) {
4864 SetWindowPos(infoPtr
->hwndSelf
, NULL
, 0, 0,
4865 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
4866 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
,
4867 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
4870 /* repaint toolbar */
4871 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4874 /* return bounding rectangle */
4876 lprc
->left
= infoPtr
->rcBound
.left
;
4877 lprc
->right
= infoPtr
->rcBound
.right
;
4878 lprc
->top
= infoPtr
->rcBound
.top
;
4879 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
4887 TOOLBAR_SetState (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
4889 TBUTTON_INFO
*btnPtr
;
4892 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
4896 btnPtr
= &infoPtr
->buttons
[nIndex
];
4898 /* if hidden state has changed the invalidate entire window and recalc */
4899 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
4900 btnPtr
->fsState
= LOWORD(lParam
);
4901 TOOLBAR_CalcToolbar (infoPtr
);
4902 InvalidateRect(infoPtr
->hwndSelf
, 0, TRUE
);
4906 /* process state changing if current state doesn't match new state */
4907 if(btnPtr
->fsState
!= LOWORD(lParam
))
4909 btnPtr
->fsState
= LOWORD(lParam
);
4910 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4918 TOOLBAR_SetStyle (TOOLBAR_INFO
*infoPtr
, DWORD style
)
4920 infoPtr
->dwStyle
= style
;
4925 static inline LRESULT
4926 TOOLBAR_SetToolTips (TOOLBAR_INFO
*infoPtr
, HWND hwndTooltip
)
4928 TRACE("hwnd=%p, hwndTooltip=%p\n", infoPtr
->hwndSelf
, hwndTooltip
);
4930 infoPtr
->hwndToolTip
= hwndTooltip
;
4936 TOOLBAR_SetUnicodeFormat (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
4940 TRACE("%s hwnd=%p\n",
4941 ((BOOL
)wParam
) ? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
4943 bTemp
= infoPtr
->bUnicode
;
4944 infoPtr
->bUnicode
= (BOOL
)wParam
;
4951 TOOLBAR_GetColorScheme (const TOOLBAR_INFO
*infoPtr
, LPCOLORSCHEME lParam
)
4953 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
4954 comctl32_color
.clrBtnHighlight
:
4955 infoPtr
->clrBtnHighlight
;
4956 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
4957 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
4963 TOOLBAR_SetColorScheme (TOOLBAR_INFO
*infoPtr
, const COLORSCHEME
*lParam
)
4965 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
4966 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
4967 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
4969 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
4970 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
4971 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4977 TOOLBAR_SetVersion (TOOLBAR_INFO
*infoPtr
, INT iVersion
)
4979 INT iOldVersion
= infoPtr
->iVersion
;
4981 infoPtr
->iVersion
= iVersion
;
4983 if (infoPtr
->iVersion
>= 5)
4984 TOOLBAR_SetUnicodeFormat(infoPtr
, TRUE
);
4991 TOOLBAR_GetStringA (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPSTR str
)
4993 WORD iString
= HIWORD(wParam
);
4994 WORD buffersize
= LOWORD(wParam
);
4997 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, buffersize
, str
);
4999 if (iString
< infoPtr
->nNumStrings
)
5001 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
5004 TRACE("returning %s\n", debugstr_a(str
));
5007 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5014 TOOLBAR_GetStringW (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPWSTR str
)
5016 WORD iString
= HIWORD(wParam
);
5017 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5020 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, LOWORD(wParam
), str
);
5022 if (iString
< infoPtr
->nNumStrings
)
5024 len
= min(len
, strlenW(infoPtr
->strings
[iString
]));
5025 ret
= (len
+1)*sizeof(WCHAR
);
5028 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5033 TRACE("returning %s\n", debugstr_w(str
));
5036 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5041 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5042 * is the maximum size of the toolbar? */
5043 static LRESULT
TOOLBAR_Unkwn45D(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5045 SIZE
* pSize
= (SIZE
*)lParam
;
5046 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5051 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5052 * caller to specify a reason why the hot item changed (rather than just the
5053 * HICF_OTHER that TB_SETHOTITEM sends). */
5055 TOOLBAR_SetHotItem2 (TOOLBAR_INFO
*infoPtr
, INT nHotItem
, LPARAM lParam
)
5057 INT nOldHotItem
= infoPtr
->nHotItem
;
5059 TRACE("old item=%d, new item=%d, flags=%08x\n",
5060 nOldHotItem
, nHotItem
, (DWORD
)lParam
);
5062 if (nHotItem
< 0 || nHotItem
> infoPtr
->nNumButtons
)
5065 /* NOTE: an application can still remove the hot item even if anchor
5066 * highlighting is enabled */
5068 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, lParam
);
5072 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5075 /* Sets the toolbar global iListGap parameter which controls the amount of
5076 * spacing between the image and the text of buttons for TBSTYLE_LIST
5078 static LRESULT
TOOLBAR_SetListGap(TOOLBAR_INFO
*infoPtr
, INT iListGap
)
5080 TRACE("hwnd=%p iListGap=%d\n", infoPtr
->hwndSelf
, iListGap
);
5082 infoPtr
->iListGap
= iListGap
;
5084 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5089 /* Returns the number of maximum number of image lists associated with the
5090 * various states. */
5091 static LRESULT
TOOLBAR_GetImageListCount(const TOOLBAR_INFO
*infoPtr
)
5093 TRACE("hwnd=%p\n", infoPtr
->hwndSelf
);
5095 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5099 TOOLBAR_GetIdealSize (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5101 LPSIZE lpsize
= (LPSIZE
)lParam
;
5107 * Testing shows the following:
5108 * wParam = 0 adjust cx value
5109 * = 1 set cy value to max size.
5110 * lParam pointer to SIZE structure
5113 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5114 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5118 if (lpsize
->cx
== -1) {
5119 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5121 else if(HIWORD(lpsize
->cx
)) {
5123 HWND hwndParent
= GetParent(infoPtr
->hwndSelf
);
5125 GetWindowRect(infoPtr
->hwndSelf
, &rc
);
5126 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5127 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc
));
5128 lpsize
->cx
= max(rc
.right
-rc
.left
,
5129 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5132 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5136 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5139 FIXME("Unknown wParam %ld\n", wParam
);
5142 TRACE("set to -> 0x%08x 0x%08x\n",
5143 lpsize
->cx
, lpsize
->cy
);
5147 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5149 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5151 InvalidateRect(hwnd
, NULL
, TRUE
);
5157 TOOLBAR_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
5159 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
5162 TRACE("hwnd = %p, style=0x%08x\n", hwnd
, lpcs
->style
);
5164 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5165 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5166 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5167 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_REQUERY
));
5168 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5170 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5171 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5173 OpenThemeData (hwnd
, themeClass
);
5175 TOOLBAR_CheckStyle (infoPtr
);
5182 TOOLBAR_Destroy (TOOLBAR_INFO
*infoPtr
)
5186 /* delete tooltip control */
5187 if (infoPtr
->hwndToolTip
)
5188 DestroyWindow (infoPtr
->hwndToolTip
);
5190 /* delete temporary buffer for tooltip text */
5191 Free (infoPtr
->pszTooltipText
);
5192 Free (infoPtr
->bitmaps
); /* bitmaps list */
5194 /* delete button data */
5195 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5196 if (TOOLBAR_ButtonHasString(&infoPtr
->buttons
[i
]))
5197 Free ((LPWSTR
)infoPtr
->buttons
[i
].iString
);
5198 Free (infoPtr
->buttons
);
5200 /* delete strings */
5201 if (infoPtr
->strings
) {
5202 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5203 Free (infoPtr
->strings
[i
]);
5205 Free (infoPtr
->strings
);
5208 /* destroy internal image list */
5209 if (infoPtr
->himlInt
)
5210 ImageList_Destroy (infoPtr
->himlInt
);
5212 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5213 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5214 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5216 /* delete default font */
5217 DeleteObject (infoPtr
->hDefaultFont
);
5219 CloseThemeData (GetWindowTheme (infoPtr
->hwndSelf
));
5221 /* free toolbar info data */
5222 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
5230 TOOLBAR_EraseBackground (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5232 NMTBCUSTOMDRAW tbcd
;
5235 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
5236 DWORD dwEraseCustDraw
= 0;
5238 /* the app has told us not to redraw the toolbar */
5239 if (!infoPtr
->bDoRedraw
)
5242 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5243 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5244 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5245 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5246 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5247 dwEraseCustDraw
= ntfret
& 0xffff;
5249 /* FIXME: in general the return flags *can* be or'ed together */
5250 switch (dwEraseCustDraw
)
5252 case CDRF_DODEFAULT
:
5254 case CDRF_SKIPDEFAULT
:
5257 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5258 infoPtr
->hwndSelf
, ntfret
);
5262 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5263 * to my parent for processing.
5265 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5267 HDC hdc
= (HDC
)wParam
;
5272 parent
= GetParent(infoPtr
->hwndSelf
);
5273 MapWindowPoints(infoPtr
->hwndSelf
, parent
, &pt
, 1);
5274 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5275 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5276 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5279 ret
= DefWindowProcW (infoPtr
->hwndSelf
, WM_ERASEBKGND
, wParam
, lParam
);
5281 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5282 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5283 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5284 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5285 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5286 dwEraseCustDraw
= ntfret
& 0xffff;
5287 switch (dwEraseCustDraw
)
5289 case CDRF_DODEFAULT
:
5291 case CDRF_SKIPDEFAULT
:
5294 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5295 infoPtr
->hwndSelf
, ntfret
);
5302 static inline LRESULT
5303 TOOLBAR_GetFont (const TOOLBAR_INFO
*infoPtr
)
5305 return (LRESULT
)infoPtr
->hFont
;
5310 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5313 INT nNewHotItem
= infoPtr
->nHotItem
;
5315 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5318 if ((nNewHotItem
+ iDirection
< 0) ||
5319 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5321 NMTBWRAPHOTITEM nmtbwhi
;
5322 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5323 nmtbwhi
.iDirection
= iDirection
;
5324 nmtbwhi
.dwReason
= dwReason
;
5326 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5330 nNewHotItem
+= iDirection
;
5331 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5333 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5334 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5336 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5343 TOOLBAR_KeyDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5347 nmkey
.nVKey
= (UINT
)wParam
;
5348 nmkey
.uFlags
= HIWORD(lParam
);
5350 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5351 return DefWindowProcW(infoPtr
->hwndSelf
, WM_KEYDOWN
, wParam
, lParam
);
5353 switch ((UINT
)wParam
)
5357 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5361 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5365 if ((infoPtr
->nHotItem
>= 0) &&
5366 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5368 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5369 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5370 (LPARAM
)infoPtr
->hwndSelf
);
5380 TOOLBAR_LButtonDblClk (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5385 pt
.x
= (short)LOWORD(lParam
);
5386 pt
.y
= (short)HIWORD(lParam
);
5387 TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5390 TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
5391 else if (infoPtr
->dwStyle
& CCS_ADJUSTABLE
)
5392 TOOLBAR_Customize (infoPtr
);
5399 TOOLBAR_LButtonDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5401 TBUTTON_INFO
*btnPtr
;
5406 BOOL bDragKeyPressed
;
5411 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5412 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5414 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5416 if (infoPtr
->hwndToolTip
)
5417 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5418 WM_LBUTTONDOWN
, wParam
, lParam
);
5420 pt
.x
= (short)LOWORD(lParam
);
5421 pt
.y
= (short)HIWORD(lParam
);
5422 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5425 btnPtr
= &infoPtr
->buttons
[nHit
];
5427 if (button
&& bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5429 infoPtr
->nButtonDrag
= nHit
;
5430 SetCapture (infoPtr
->hwndSelf
);
5432 /* If drag cursor has not been loaded, load it.
5433 * Note: it doesn't need to be freed */
5435 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5436 SetCursor(hCursorDrag
);
5441 infoPtr
->nOldHit
= nHit
;
5443 CopyRect(&arrowRect
, &btnPtr
->rect
);
5444 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5446 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5447 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5448 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5449 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5450 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5451 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5455 /* draw in pressed state */
5456 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5457 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5459 btnPtr
->bDropDownPressed
= TRUE
;
5460 RedrawWindow(infoPtr
->hwndSelf
,&btnPtr
->rect
,0,
5461 RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5463 memset(&nmtb
, 0, sizeof(nmtb
));
5464 nmtb
.iItem
= btnPtr
->idCommand
;
5465 nmtb
.rcButton
= btnPtr
->rect
;
5466 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5468 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5470 if (res
!= TBDDRET_TREATPRESSED
)
5474 /* redraw button in unpressed state */
5475 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5476 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5478 btnPtr
->bDropDownPressed
= FALSE
;
5479 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5481 /* find and set hot item */
5483 ScreenToClient(infoPtr
->hwndSelf
, &pt
);
5484 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5485 if (!infoPtr
->bAnchor
|| button
)
5486 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5488 /* remove any left mouse button down or double-click messages
5489 * so that we can get a toggle effect on the button */
5490 while (PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5491 PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5496 /* otherwise drop through and process as pushed */
5498 infoPtr
->bCaptured
= TRUE
;
5499 infoPtr
->nButtonDown
= nHit
;
5500 infoPtr
->bDragOutSent
= FALSE
;
5502 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5504 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5506 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5507 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5508 UpdateWindow(infoPtr
->hwndSelf
);
5509 SetCapture (infoPtr
->hwndSelf
);
5514 memset(&nmtb
, 0, sizeof(nmtb
));
5515 nmtb
.iItem
= btnPtr
->idCommand
;
5516 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5519 nmmouse
.dwHitInfo
= nHit
;
5521 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5523 nmmouse
.dwItemSpec
= -1;
5526 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5527 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5530 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5533 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5534 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, wParam
, lParam
);
5540 TOOLBAR_LButtonUp (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5542 TBUTTON_INFO
*btnPtr
;
5551 if (infoPtr
->hwndToolTip
)
5552 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5553 WM_LBUTTONUP
, wParam
, lParam
);
5555 pt
.x
= (short)LOWORD(lParam
);
5556 pt
.y
= (short)HIWORD(lParam
);
5557 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5559 if (!infoPtr
->bAnchor
|| button
)
5560 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5562 if (infoPtr
->nButtonDrag
>= 0) {
5566 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5569 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5571 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5572 if (PtInRect(&rcClient
, pt
))
5579 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5582 if (nButton
== infoPtr
->nButtonDrag
)
5584 /* if the button is moved sightly left and we have a
5585 * separator there then remove it */
5586 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5588 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5589 TOOLBAR_DeleteButton(infoPtr
, nButton
- 1);
5591 else /* else insert a separator before the dragged button */
5594 memset(&tbb
, 0, sizeof(tbb
));
5595 tbb
.fsStyle
= BTNS_SEP
;
5597 TOOLBAR_InsertButtonT(infoPtr
, nButton
, &tbb
, TRUE
);
5604 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5605 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, 0);
5607 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5610 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, nButton
);
5615 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5616 TOOLBAR_DeleteButton(infoPtr
, infoPtr
->nButtonDrag
);
5619 /* button under cursor changed so need to re-set hot item */
5620 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5621 infoPtr
->nButtonDrag
= -1;
5623 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5625 else if (infoPtr
->nButtonDown
>= 0) {
5626 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5627 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5629 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5630 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5631 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5633 if ((nOldIndex
!= nHit
) &&
5635 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5636 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5639 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5640 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5642 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5646 if (nOldIndex
!= -1)
5647 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5650 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5651 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5652 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5654 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5656 infoPtr
->nButtonDown
= -1;
5658 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5659 TOOLBAR_SendNotify (&hdr
, infoPtr
,
5660 NM_RELEASEDCAPTURE
);
5662 memset(&nmtb
, 0, sizeof(nmtb
));
5663 nmtb
.iItem
= btnPtr
->idCommand
;
5664 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5667 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5669 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5670 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)infoPtr
->hwndSelf
);
5672 /* In case we have just been destroyed... */
5673 if(!IsWindow(infoPtr
->hwndSelf
))
5678 /* !!! Undocumented - toolbar at 4.71 level and above sends
5679 * NM_CLICK with the NMMOUSE structure. */
5680 nmmouse
.dwHitInfo
= nHit
;
5683 nmmouse
.dwItemSpec
= -1;
5686 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5687 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5690 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5693 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5694 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONUP
, wParam
, lParam
);
5700 TOOLBAR_RButtonUp(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5707 pt
.x
= (short)LOWORD(lParam
);
5708 pt
.y
= (short)HIWORD(lParam
);
5710 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5711 nmmouse
.dwHitInfo
= nHit
;
5714 nmmouse
.dwItemSpec
= -1;
5716 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5717 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5720 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5723 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5724 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONUP
, wParam
, lParam
);
5730 TOOLBAR_RButtonDblClk( TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5734 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5735 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
5741 TOOLBAR_CaptureChanged(TOOLBAR_INFO
*infoPtr
)
5743 TBUTTON_INFO
*btnPtr
;
5745 infoPtr
->bCaptured
= FALSE
;
5747 if (infoPtr
->nButtonDown
>= 0)
5749 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5750 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5752 infoPtr
->nOldHit
= -1;
5754 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5755 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5761 TOOLBAR_MouseLeave (TOOLBAR_INFO
*infoPtr
)
5763 /* don't remove hot effects when in anchor highlighting mode or when a
5764 * drop-down button is pressed */
5765 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
5767 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
5768 if (!hotBtnPtr
->bDropDownPressed
)
5769 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
5772 if (infoPtr
->nOldHit
< 0)
5775 /* If the last button we were over is depressed then make it not */
5776 /* depressed and redraw it */
5777 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
5779 TBUTTON_INFO
*btnPtr
;
5782 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5784 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5787 InflateRect (&rc1
, 1, 1);
5788 InvalidateRect (infoPtr
->hwndSelf
, &rc1
, TRUE
);
5791 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
5794 ZeroMemory(&nmt
, sizeof(nmt
));
5795 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5796 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5797 infoPtr
->bDragOutSent
= TRUE
;
5800 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
5806 TOOLBAR_MouseMove (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5809 TRACKMOUSEEVENT trackinfo
;
5811 TBUTTON_INFO
*btnPtr
;
5814 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
5815 TOOLBAR_TooltipCreateControl(infoPtr
);
5817 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
5818 /* fill in the TRACKMOUSEEVENT struct */
5819 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5820 trackinfo
.dwFlags
= TME_QUERY
;
5822 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5823 _TrackMouseEvent(&trackinfo
);
5825 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5826 if(trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
5827 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5828 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
5830 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5831 /* and can properly deactivate the hot toolbar button */
5832 _TrackMouseEvent(&trackinfo
);
5836 if (infoPtr
->hwndToolTip
)
5837 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5838 WM_MOUSEMOVE
, wParam
, lParam
);
5840 pt
.x
= (short)LOWORD(lParam
);
5841 pt
.y
= (short)HIWORD(lParam
);
5843 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5845 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
5846 && (!infoPtr
->bAnchor
|| button
))
5847 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
);
5849 if (infoPtr
->nOldHit
!= nHit
)
5851 if (infoPtr
->bCaptured
)
5853 if (!infoPtr
->bDragOutSent
)
5856 ZeroMemory(&nmt
, sizeof(nmt
));
5857 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5858 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5859 infoPtr
->bDragOutSent
= TRUE
;
5862 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5863 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
5864 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5865 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5867 else if (nHit
== infoPtr
->nButtonDown
) {
5868 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5869 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5871 infoPtr
->nOldHit
= nHit
;
5879 static inline LRESULT
5880 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5882 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5883 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
5885 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5889 static inline LRESULT
5890 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5892 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
5893 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
5895 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
5900 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
5902 TOOLBAR_INFO
*infoPtr
;
5905 /* allocate memory for info structure */
5906 infoPtr
= Alloc (sizeof(TOOLBAR_INFO
));
5907 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
5910 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
5912 infoPtr
->nWidth
= 0;
5914 /* initialize info structure */
5915 infoPtr
->nButtonWidth
= 23;
5916 infoPtr
->nButtonHeight
= 22;
5917 infoPtr
->nBitmapHeight
= 16;
5918 infoPtr
->nBitmapWidth
= 16;
5920 infoPtr
->nMaxTextRows
= 1;
5921 infoPtr
->cxMin
= -1;
5922 infoPtr
->cxMax
= -1;
5923 infoPtr
->nNumBitmaps
= 0;
5924 infoPtr
->nNumStrings
= 0;
5926 infoPtr
->bCaptured
= FALSE
;
5927 infoPtr
->nButtonDown
= -1;
5928 infoPtr
->nButtonDrag
= -1;
5929 infoPtr
->nOldHit
= -1;
5930 infoPtr
->nHotItem
= -1;
5931 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
5932 infoPtr
->dwDTFlags
= (lpcs
->style
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
5933 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
5934 infoPtr
->bDragOutSent
= FALSE
;
5935 infoPtr
->iVersion
= 0;
5936 infoPtr
->hwndSelf
= hwnd
;
5937 infoPtr
->bDoRedraw
= TRUE
;
5938 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
5939 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
5940 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
5941 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
5942 infoPtr
->iListGap
= DEFLISTGAP
;
5943 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
5944 infoPtr
->dwStyle
= lpcs
->style
;
5945 infoPtr
->tbim
.iButton
= -1;
5947 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5948 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
5949 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
5950 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
5953 /* I think the code below is a bug, but it is the way that the native
5954 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5955 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5956 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5957 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5958 * Somehow, the only cases of this seem to be MFC programs.
5960 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5961 * does not occur in the WM_STYLECHANGING routine.
5962 * (Guy Albertelli 9/2001)
5965 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
5966 && !(lpcs
->style
& TBSTYLE_TRANSPARENT
))
5967 styleadd
|= TBSTYLE_TRANSPARENT
;
5968 if (!(lpcs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
5969 styleadd
|= CCS_TOP
; /* default to top */
5970 SetWindowLongW (hwnd
, GWL_STYLE
, lpcs
->style
| styleadd
);
5973 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
5978 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5980 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5984 if (dwStyle
& WS_MINIMIZE
)
5985 return 0; /* Nothing to do */
5987 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
5989 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
5992 if (!(dwStyle
& CCS_NODIVIDER
))
5994 GetWindowRect (hwnd
, &rcWindow
);
5995 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
5996 if( dwStyle
& WS_BORDER
)
5997 InflateRect (&rcWindow
, -1, -1);
5998 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6001 ReleaseDC( hwnd
, hdc
);
6007 /* handles requests from the tooltip control on what text to display */
6008 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6010 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6012 TRACE("button index = %d\n", index
);
6014 Free (infoPtr
->pszTooltipText
);
6015 infoPtr
->pszTooltipText
= NULL
;
6020 if (infoPtr
->bUnicode
)
6022 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6023 NMTBGETINFOTIPW tbgit
;
6024 unsigned int len
; /* in chars */
6026 wszBuffer
[0] = '\0';
6027 wszBuffer
[INFOTIPSIZE
] = '\0';
6029 tbgit
.pszText
= wszBuffer
;
6030 tbgit
.cchTextMax
= INFOTIPSIZE
;
6031 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6032 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6034 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6036 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6038 len
= strlenW(tbgit
.pszText
);
6039 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6041 /* need to allocate temporary buffer in infoPtr as there
6042 * isn't enough space in buffer passed to us by the
6043 * tooltip control */
6044 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6045 if (infoPtr
->pszTooltipText
)
6047 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6048 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6054 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6060 CHAR szBuffer
[INFOTIPSIZE
+1];
6061 NMTBGETINFOTIPA tbgit
;
6062 unsigned int len
; /* in chars */
6065 szBuffer
[INFOTIPSIZE
] = '\0';
6067 tbgit
.pszText
= szBuffer
;
6068 tbgit
.cchTextMax
= INFOTIPSIZE
;
6069 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6070 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6072 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6074 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6076 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6077 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]))
6079 /* need to allocate temporary buffer in infoPtr as there
6080 * isn't enough space in buffer passed to us by the
6081 * tooltip control */
6082 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6083 if (infoPtr
->pszTooltipText
)
6085 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6086 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6090 else if (tbgit
.pszText
&& tbgit
.pszText
[0])
6092 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1,
6093 lpnmtdi
->lpszText
, sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]));
6098 /* if button has text, but it is not shown then automatically
6099 * use that text as tooltip */
6100 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6101 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6103 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6104 unsigned int len
= pszText
? strlenW(pszText
) : 0;
6106 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6108 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6110 /* need to allocate temporary buffer in infoPtr as there
6111 * isn't enough space in buffer passed to us by the
6112 * tooltip control */
6113 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6114 if (infoPtr
->pszTooltipText
)
6116 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6117 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6123 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6128 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6130 /* last resort: send notification on to app */
6131 /* FIXME: find out what is really used here */
6132 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmtdi
->hdr
.idFrom
, (LPARAM
)lpnmtdi
);
6136 static inline LRESULT
6137 TOOLBAR_Notify (TOOLBAR_INFO
*infoPtr
, LPNMHDR lpnmh
)
6139 switch (lpnmh
->code
)
6143 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lpnmh
;
6145 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6146 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6147 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6151 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6152 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6160 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lpnmh
;
6162 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6163 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6164 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6165 lppgs
->iScroll
, lppgs
->iDir
);
6169 case TTN_GETDISPINFOW
:
6170 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lpnmh
);
6172 case TTN_GETDISPINFOA
:
6173 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6183 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6187 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam
, lParam
);
6189 if (lParam
== NF_QUERY
)
6192 if (lParam
== NF_REQUERY
) {
6193 format
= SendMessageW(infoPtr
->hwndNotify
,
6194 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6195 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6196 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6207 TOOLBAR_Paint (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6212 /* fill ps.rcPaint with a default rect */
6213 ps
.rcPaint
= infoPtr
->rcBound
;
6215 hdc
= wParam
==0 ? BeginPaint(infoPtr
->hwndSelf
, &ps
) : (HDC
)wParam
;
6217 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps
.rcPaint
));
6219 TOOLBAR_Refresh (infoPtr
, hdc
, &ps
);
6220 if (!wParam
) EndPaint (infoPtr
->hwndSelf
, &ps
);
6227 TOOLBAR_SetFocus (TOOLBAR_INFO
*infoPtr
)
6229 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6231 /* make first item hot */
6232 if (infoPtr
->nNumButtons
> 0)
6233 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6239 TOOLBAR_SetFont(TOOLBAR_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
6241 TRACE("font=%p redraw=%d\n", hFont
, Redraw
);
6244 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6246 infoPtr
->hFont
= hFont
;
6248 TOOLBAR_CalcToolbar(infoPtr
);
6251 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6256 TOOLBAR_SetRedraw (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6257 /*****************************************************
6260 * Handles the WM_SETREDRAW message.
6263 * According to testing V4.71 of COMCTL32 returns the
6264 * *previous* status of the redraw flag (either 0 or 1)
6265 * instead of the MSDN documented value of 0 if handled.
6266 * (For laughs see the "consistency" with same function
6269 *****************************************************/
6271 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6273 TRACE("set to %s\n",
6274 (wParam
) ? "TRUE" : "FALSE");
6275 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6277 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6279 return (oldredraw
) ? 1 : 0;
6284 TOOLBAR_Size (TOOLBAR_INFO
*infoPtr
)
6286 TRACE("sizing toolbar!\n");
6288 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6290 RECT delta_width
, delta_height
, client
, dummy
;
6291 DWORD min_x
, max_x
, min_y
, max_y
;
6292 TBUTTON_INFO
*btnPtr
;
6295 GetClientRect(infoPtr
->hwndSelf
, &client
);
6296 if(client
.right
> infoPtr
->client_rect
.right
)
6298 min_x
= infoPtr
->client_rect
.right
;
6299 max_x
= client
.right
;
6303 max_x
= infoPtr
->client_rect
.right
;
6304 min_x
= client
.right
;
6306 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6308 min_y
= infoPtr
->client_rect
.bottom
;
6309 max_y
= client
.bottom
;
6313 max_y
= infoPtr
->client_rect
.bottom
;
6314 min_y
= client
.bottom
;
6317 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6318 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6320 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6321 btnPtr
= infoPtr
->buttons
;
6322 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6323 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6324 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6325 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6327 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->client_rect
);
6328 TOOLBAR_AutoSize(infoPtr
);
6334 TOOLBAR_StyleChanged (TOOLBAR_INFO
*infoPtr
, INT nType
, const STYLESTRUCT
*lpStyle
)
6336 if (nType
== GWL_STYLE
)
6338 DWORD dwOldStyle
= infoPtr
->dwStyle
;
6340 if (lpStyle
->styleNew
& TBSTYLE_LIST
)
6341 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
6343 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
6345 TRACE("new style 0x%08x\n", lpStyle
->styleNew
);
6347 infoPtr
->dwStyle
= lpStyle
->styleNew
;
6348 TOOLBAR_CheckStyle (infoPtr
);
6350 if ((dwOldStyle
^ lpStyle
->styleNew
) & (TBSTYLE_WRAPABLE
| CCS_VERT
))
6351 TOOLBAR_LayoutToolbar(infoPtr
);
6353 /* only resize if one of the CCS_* styles was changed */
6354 if ((dwOldStyle
^ lpStyle
->styleNew
) & COMMON_STYLES
)
6356 TOOLBAR_AutoSize (infoPtr
);
6358 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6367 TOOLBAR_SysColorChange (void)
6369 COMCTL32_RefreshSysColors();
6375 /* update theme after a WM_THEMECHANGED message */
6376 static LRESULT
theme_changed (HWND hwnd
)
6378 HTHEME theme
= GetWindowTheme (hwnd
);
6379 CloseThemeData (theme
);
6380 OpenThemeData (hwnd
, themeClass
);
6385 static LRESULT WINAPI
6386 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6388 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
6390 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6391 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6393 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6394 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6399 return TOOLBAR_AddBitmap (infoPtr
, (INT
)wParam
, (TBADDBITMAP
*)lParam
);
6401 case TB_ADDBUTTONSA
:
6402 case TB_ADDBUTTONSW
:
6403 return TOOLBAR_AddButtonsT (infoPtr
, wParam
, (LPTBBUTTON
)lParam
,
6404 uMsg
== TB_ADDBUTTONSW
);
6406 return TOOLBAR_AddStringA (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6409 return TOOLBAR_AddStringW (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6412 return TOOLBAR_AutoSize (infoPtr
);
6414 case TB_BUTTONCOUNT
:
6415 return TOOLBAR_ButtonCount (infoPtr
);
6417 case TB_BUTTONSTRUCTSIZE
:
6418 return TOOLBAR_ButtonStructSize (infoPtr
, wParam
);
6420 case TB_CHANGEBITMAP
:
6421 return TOOLBAR_ChangeBitmap (infoPtr
, wParam
, LOWORD(lParam
));
6423 case TB_CHECKBUTTON
:
6424 return TOOLBAR_CheckButton (infoPtr
, wParam
, lParam
);
6426 case TB_COMMANDTOINDEX
:
6427 return TOOLBAR_CommandToIndex (infoPtr
, wParam
);
6430 return TOOLBAR_Customize (infoPtr
);
6432 case TB_DELETEBUTTON
:
6433 return TOOLBAR_DeleteButton (infoPtr
, wParam
);
6435 case TB_ENABLEBUTTON
:
6436 return TOOLBAR_EnableButton (infoPtr
, wParam
, lParam
);
6438 case TB_GETANCHORHIGHLIGHT
:
6439 return TOOLBAR_GetAnchorHighlight (infoPtr
);
6442 return TOOLBAR_GetBitmap (infoPtr
, wParam
);
6444 case TB_GETBITMAPFLAGS
:
6445 return TOOLBAR_GetBitmapFlags ();
6448 return TOOLBAR_GetButton (infoPtr
, wParam
, (TBBUTTON
*)lParam
);
6450 case TB_GETBUTTONINFOA
:
6451 case TB_GETBUTTONINFOW
:
6452 return TOOLBAR_GetButtonInfoT (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6453 uMsg
== TB_GETBUTTONINFOW
);
6454 case TB_GETBUTTONSIZE
:
6455 return TOOLBAR_GetButtonSize (infoPtr
);
6457 case TB_GETBUTTONTEXTA
:
6458 case TB_GETBUTTONTEXTW
:
6459 return TOOLBAR_GetButtonText (infoPtr
, wParam
, (LPWSTR
)lParam
,
6460 uMsg
== TB_GETBUTTONTEXTW
);
6462 case TB_GETDISABLEDIMAGELIST
:
6463 return TOOLBAR_GetDisabledImageList (infoPtr
, wParam
);
6465 case TB_GETEXTENDEDSTYLE
:
6466 return TOOLBAR_GetExtendedStyle (infoPtr
);
6468 case TB_GETHOTIMAGELIST
:
6469 return TOOLBAR_GetHotImageList (infoPtr
, wParam
);
6472 return TOOLBAR_GetHotItem (infoPtr
);
6474 case TB_GETIMAGELIST
:
6475 return TOOLBAR_GetDefImageList (infoPtr
, wParam
);
6477 case TB_GETINSERTMARK
:
6478 return TOOLBAR_GetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6480 case TB_GETINSERTMARKCOLOR
:
6481 return TOOLBAR_GetInsertMarkColor (infoPtr
);
6483 case TB_GETITEMRECT
:
6484 return TOOLBAR_GetItemRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6487 return TOOLBAR_GetMaxSize (infoPtr
, (LPSIZE
)lParam
);
6489 /* case TB_GETOBJECT: */ /* 4.71 */
6492 return TOOLBAR_GetPadding (infoPtr
);
6495 return TOOLBAR_GetRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6498 return TOOLBAR_GetRows (infoPtr
);
6501 return TOOLBAR_GetState (infoPtr
, wParam
);
6504 return TOOLBAR_GetStringA (infoPtr
, wParam
, (LPSTR
)lParam
);
6507 return TOOLBAR_GetStringW (infoPtr
, wParam
, (LPWSTR
)lParam
);
6510 return TOOLBAR_GetStyle (infoPtr
);
6512 case TB_GETTEXTROWS
:
6513 return TOOLBAR_GetTextRows (infoPtr
);
6515 case TB_GETTOOLTIPS
:
6516 return TOOLBAR_GetToolTips (infoPtr
);
6518 case TB_GETUNICODEFORMAT
:
6519 return TOOLBAR_GetUnicodeFormat (infoPtr
);
6522 return TOOLBAR_HideButton (infoPtr
, wParam
, LOWORD(lParam
));
6525 return TOOLBAR_HitTest (infoPtr
, (LPPOINT
)lParam
);
6527 case TB_INDETERMINATE
:
6528 return TOOLBAR_Indeterminate (infoPtr
, wParam
, LOWORD(lParam
));
6530 case TB_INSERTBUTTONA
:
6531 case TB_INSERTBUTTONW
:
6532 return TOOLBAR_InsertButtonT(infoPtr
, wParam
, (TBBUTTON
*)lParam
,
6533 uMsg
== TB_INSERTBUTTONW
);
6535 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6537 case TB_ISBUTTONCHECKED
:
6538 return TOOLBAR_IsButtonChecked (infoPtr
, wParam
);
6540 case TB_ISBUTTONENABLED
:
6541 return TOOLBAR_IsButtonEnabled (infoPtr
, wParam
);
6543 case TB_ISBUTTONHIDDEN
:
6544 return TOOLBAR_IsButtonHidden (infoPtr
, wParam
);
6546 case TB_ISBUTTONHIGHLIGHTED
:
6547 return TOOLBAR_IsButtonHighlighted (infoPtr
, wParam
);
6549 case TB_ISBUTTONINDETERMINATE
:
6550 return TOOLBAR_IsButtonIndeterminate (infoPtr
, wParam
);
6552 case TB_ISBUTTONPRESSED
:
6553 return TOOLBAR_IsButtonPressed (infoPtr
, wParam
);
6556 return TOOLBAR_LoadImages (infoPtr
, wParam
, (HINSTANCE
)lParam
);
6558 case TB_MAPACCELERATORA
:
6559 case TB_MAPACCELERATORW
:
6560 return TOOLBAR_MapAccelerator (infoPtr
, wParam
, (UINT
*)lParam
);
6563 return TOOLBAR_MarkButton (infoPtr
, wParam
, LOWORD(lParam
));
6566 return TOOLBAR_MoveButton (infoPtr
, wParam
, lParam
);
6568 case TB_PRESSBUTTON
:
6569 return TOOLBAR_PressButton (infoPtr
, wParam
, LOWORD(lParam
));
6571 case TB_REPLACEBITMAP
:
6572 return TOOLBAR_ReplaceBitmap (infoPtr
, (LPTBREPLACEBITMAP
)lParam
);
6574 case TB_SAVERESTOREA
:
6575 return TOOLBAR_SaveRestoreA (infoPtr
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6577 case TB_SAVERESTOREW
:
6578 return TOOLBAR_SaveRestoreW (infoPtr
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6580 case TB_SETANCHORHIGHLIGHT
:
6581 return TOOLBAR_SetAnchorHighlight (infoPtr
, (BOOL
)wParam
);
6583 case TB_SETBITMAPSIZE
:
6584 return TOOLBAR_SetBitmapSize (infoPtr
, wParam
, lParam
);
6586 case TB_SETBUTTONINFOA
:
6587 case TB_SETBUTTONINFOW
:
6588 return TOOLBAR_SetButtonInfo (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6589 uMsg
== TB_SETBUTTONINFOW
);
6590 case TB_SETBUTTONSIZE
:
6591 return TOOLBAR_SetButtonSize (infoPtr
, lParam
);
6593 case TB_SETBUTTONWIDTH
:
6594 return TOOLBAR_SetButtonWidth (infoPtr
, lParam
);
6597 return TOOLBAR_SetCmdId (infoPtr
, wParam
, lParam
);
6599 case TB_SETDISABLEDIMAGELIST
:
6600 return TOOLBAR_SetDisabledImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6602 case TB_SETDRAWTEXTFLAGS
:
6603 return TOOLBAR_SetDrawTextFlags (infoPtr
, wParam
, lParam
);
6605 case TB_SETEXTENDEDSTYLE
:
6606 return TOOLBAR_SetExtendedStyle (infoPtr
, wParam
, lParam
);
6608 case TB_SETHOTIMAGELIST
:
6609 return TOOLBAR_SetHotImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6612 return TOOLBAR_SetHotItem (infoPtr
, wParam
);
6614 case TB_SETIMAGELIST
:
6615 return TOOLBAR_SetImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6618 return TOOLBAR_SetIndent (infoPtr
, wParam
);
6620 case TB_SETINSERTMARK
:
6621 return TOOLBAR_SetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6623 case TB_SETINSERTMARKCOLOR
:
6624 return TOOLBAR_SetInsertMarkColor (infoPtr
, lParam
);
6626 case TB_SETMAXTEXTROWS
:
6627 return TOOLBAR_SetMaxTextRows (infoPtr
, wParam
);
6630 return TOOLBAR_SetPadding (infoPtr
, lParam
);
6633 return TOOLBAR_SetParent (infoPtr
, (HWND
)wParam
);
6636 return TOOLBAR_SetRows (infoPtr
, wParam
, (LPRECT
)lParam
);
6639 return TOOLBAR_SetState (infoPtr
, wParam
, lParam
);
6642 return TOOLBAR_SetStyle (infoPtr
, lParam
);
6644 case TB_SETTOOLTIPS
:
6645 return TOOLBAR_SetToolTips (infoPtr
, (HWND
)wParam
);
6647 case TB_SETUNICODEFORMAT
:
6648 return TOOLBAR_SetUnicodeFormat (infoPtr
, wParam
);
6651 return TOOLBAR_Unkwn45D(hwnd
, wParam
, lParam
);
6653 case TB_SETHOTITEM2
:
6654 return TOOLBAR_SetHotItem2 (infoPtr
, wParam
, lParam
);
6657 return TOOLBAR_SetListGap(infoPtr
, wParam
);
6659 case TB_GETIMAGELISTCOUNT
:
6660 return TOOLBAR_GetImageListCount(infoPtr
);
6662 case TB_GETIDEALSIZE
:
6663 return TOOLBAR_GetIdealSize (infoPtr
, wParam
, lParam
);
6666 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6668 /* Common Control Messages */
6670 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6671 case CCM_GETCOLORSCHEME
:
6672 return TOOLBAR_GetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6674 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6675 case CCM_SETCOLORSCHEME
:
6676 return TOOLBAR_SetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6678 case CCM_GETVERSION
:
6679 return TOOLBAR_GetVersion (infoPtr
);
6681 case CCM_SETVERSION
:
6682 return TOOLBAR_SetVersion (infoPtr
, (INT
)wParam
);
6688 return TOOLBAR_Create (hwnd
, (CREATESTRUCTW
*)lParam
);
6691 return TOOLBAR_Destroy (infoPtr
);
6694 return TOOLBAR_EraseBackground (infoPtr
, wParam
, lParam
);
6697 return TOOLBAR_GetFont (infoPtr
);
6700 return TOOLBAR_KeyDown (infoPtr
, wParam
, lParam
);
6702 /* case WM_KILLFOCUS: */
6704 case WM_LBUTTONDBLCLK
:
6705 return TOOLBAR_LButtonDblClk (infoPtr
, wParam
, lParam
);
6707 case WM_LBUTTONDOWN
:
6708 return TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
6711 return TOOLBAR_LButtonUp (infoPtr
, wParam
, lParam
);
6714 return TOOLBAR_RButtonUp (infoPtr
, wParam
, lParam
);
6716 case WM_RBUTTONDBLCLK
:
6717 return TOOLBAR_RButtonDblClk (infoPtr
, wParam
, lParam
);
6720 return TOOLBAR_MouseMove (infoPtr
, wParam
, lParam
);
6723 return TOOLBAR_MouseLeave (infoPtr
);
6725 case WM_CAPTURECHANGED
:
6726 return TOOLBAR_CaptureChanged(infoPtr
);
6729 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6732 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6735 return TOOLBAR_NCCreate (hwnd
, wParam
, (CREATESTRUCTW
*)lParam
);
6738 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
6741 return TOOLBAR_Notify (infoPtr
, (LPNMHDR
)lParam
);
6743 case WM_NOTIFYFORMAT
:
6744 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
6746 case WM_PRINTCLIENT
:
6748 return TOOLBAR_Paint (infoPtr
, wParam
);
6751 return TOOLBAR_SetFocus (infoPtr
);
6754 return TOOLBAR_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
6757 return TOOLBAR_SetRedraw (infoPtr
, wParam
);
6760 return TOOLBAR_Size (infoPtr
);
6762 case WM_STYLECHANGED
:
6763 return TOOLBAR_StyleChanged (infoPtr
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
6765 case WM_SYSCOLORCHANGE
:
6766 return TOOLBAR_SysColorChange ();
6768 case WM_THEMECHANGED
:
6769 return theme_changed (hwnd
);
6771 /* case WM_WININICHANGE: */
6776 case WM_MEASUREITEM
:
6778 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
6780 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6781 case PGM_FORWARDMOUSE
:
6782 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6785 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
6786 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
6787 uMsg
, wParam
, lParam
);
6788 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6794 TOOLBAR_Register (void)
6798 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
6799 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
6800 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
6801 wndClass
.cbClsExtra
= 0;
6802 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
6803 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
6804 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
6805 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
6807 RegisterClassW (&wndClass
);
6812 TOOLBAR_Unregister (void)
6814 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
6817 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
6822 /* Check if the entry already exists */
6823 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
6825 /* If this is a new entry we must create it and insert into the array */
6830 c
= Alloc(sizeof(IMLENTRY
));
6833 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
6834 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
6849 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
6853 for (i
= 0; i
< *cies
; i
++)
6863 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
6871 for (i
= 0; i
< cies
; i
++)
6873 if (pies
[i
]->id
== id
)
6885 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
6887 HIMAGELIST himlDef
= 0;
6888 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
6891 himlDef
= pie
->himl
;
6897 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
6899 if (infoPtr
->bUnicode
)
6900 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
6907 nmtba
.iItem
= nmtb
->iItem
;
6908 nmtba
.pszText
= Buffer
;
6909 nmtba
.cchText
= 256;
6910 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
6912 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
6914 int ccht
= strlen(nmtba
.pszText
);
6916 MultiByteToWideChar(CP_ACP
, 0, nmtba
.pszText
, -1,
6917 nmtb
->pszText
, nmtb
->cchText
);
6919 nmtb
->tbButton
= nmtba
.tbButton
;
6928 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
)
6932 /* MSDN states that iItem is the index of the button, rather than the
6933 * command ID as used by every other NMTOOLBAR notification */
6935 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
6937 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);