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 BYTE 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_UNDOC1 | \
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
)
861 TOOLBAR_DrawFlatHorizontalSeparator (&rc
, hdc
, infoPtr
);
863 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
865 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
866 FIXME("Draw some kind of separator: fsStyle=%x\n",
872 /* get a pointer to the text */
873 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
875 if (hasDropDownArrow
)
879 if (dwStyle
& TBSTYLE_FLAT
)
880 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
882 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
884 if (drawSepDropDownArrow
)
887 rcArrow
.left
= right
;
890 /* copy text & bitmap rects after adjusting for drop-down arrow
891 * so that text & bitmap is centered in the rectangle not containing
893 CopyRect(&rcText
, &rc
);
894 CopyRect(&rcBitmap
, &rc
);
896 /* Center the bitmap horizontally and vertically */
897 if (dwStyle
& TBSTYLE_LIST
)
900 infoPtr
->nMaxTextRows
> 0 &&
901 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
902 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
903 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
905 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
908 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
910 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
912 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
913 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
914 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
915 TRACE("Text=%s\n", debugstr_w(lpText
));
916 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
918 /* calculate text position */
921 rcText
.left
+= GetSystemMetrics(SM_CXEDGE
);
922 rcText
.right
-= GetSystemMetrics(SM_CXEDGE
);
923 if (dwStyle
& TBSTYLE_LIST
)
925 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
929 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
930 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
932 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
936 /* Initialize fields in all cases, because we use these later
937 * NOTE: applications can and do alter these to customize their
939 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
940 tbcd
.clrText
= comctl32_color
.clrBtnText
;
941 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
942 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
943 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
944 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
945 tbcd
.clrHighlightHotTrack
= 0;
946 tbcd
.nStringBkMode
= TRANSPARENT
;
947 tbcd
.nHLStringBkMode
= OPAQUE
;
948 /* MSDN says that this is the text rectangle.
949 * But (why always a but) tracing of v5.7 of native shows
950 * that this is really a *relative* rectangle based on the
951 * the nmcd.rc. Also the left and top are always 0 ignoring
952 * any bitmap that might be present. */
953 tbcd
.rcText
.left
= 0;
955 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
956 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
957 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
960 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
962 /* FIXME: what are these used for? */
966 /* Issue Item Prepaint notify */
969 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
971 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
972 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
973 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
974 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
975 /* reset these fields so the user can't alter the behaviour like native */
979 dwItemCustDraw
= ntfret
& 0xffff;
980 dwItemCDFlag
= ntfret
& 0xffff0000;
981 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
983 /* save the only part of the rect that the user can change */
984 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
985 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
988 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
989 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
990 OffsetRect(&rcText
, 1, 1);
992 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
993 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
994 TOOLBAR_DrawPattern (&rc
, &tbcd
);
996 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
997 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
999 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
1003 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
1004 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
1005 if (hasDropDownArrow
)
1006 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
1007 SetBkColor(hdc
, oldclr
);
1013 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
1014 int stateId
= TS_NORMAL
;
1016 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1017 stateId
= TS_DISABLED
;
1018 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1019 stateId
= TS_PRESSED
;
1020 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1021 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1022 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1023 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1026 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &tbcd
.nmcd
.rc
, NULL
);
1029 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, dwItemCDFlag
);
1031 if (drawSepDropDownArrow
)
1035 int stateId
= TS_NORMAL
;
1037 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1038 stateId
= TS_DISABLED
;
1039 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1040 stateId
= TS_PRESSED
;
1041 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1042 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1043 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1046 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1047 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1050 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1053 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1054 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1055 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1056 SetBkMode (hdc
, oldBkMode
);
1058 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1060 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1062 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1064 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1065 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1067 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1069 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1070 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1073 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1076 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1078 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1079 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1086 TOOLBAR_Refresh (TOOLBAR_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
1088 TBUTTON_INFO
*btnPtr
;
1090 RECT rcTemp
, rcClient
;
1091 NMTBCUSTOMDRAW tbcd
;
1093 DWORD dwBaseCustDraw
;
1095 /* the app has told us not to redraw the toolbar */
1096 if (!infoPtr
->bDoRedraw
)
1099 /* if imagelist belongs to the app, it can be changed
1100 by the app after setting it */
1101 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1103 infoPtr
->nNumBitmaps
= 0;
1104 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1105 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1108 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1110 /* change the imagelist icon size if we manage the list and it is necessary */
1111 TOOLBAR_CheckImageListIconSize(infoPtr
);
1113 /* Send initial notify */
1114 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1115 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1116 tbcd
.nmcd
.hdc
= hdc
;
1117 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1118 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1119 dwBaseCustDraw
= ntfret
& 0xffff;
1121 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1123 /* redraw necessary buttons */
1124 btnPtr
= infoPtr
->buttons
;
1125 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1128 if (!RectVisible(hdc
, &btnPtr
->rect
))
1130 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1132 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1133 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1137 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1138 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1140 TOOLBAR_DrawButton(infoPtr
, btnPtr
, hdc
, dwBaseCustDraw
);
1143 /* draw insert mark if required */
1144 if (infoPtr
->tbim
.iButton
!= -1)
1146 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1148 rcInsertMark
.top
= rcButton
.top
;
1149 rcInsertMark
.bottom
= rcButton
.bottom
;
1150 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1151 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1153 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1154 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1157 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1159 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1160 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1161 tbcd
.nmcd
.hdc
= hdc
;
1162 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1163 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1167 /***********************************************************************
1168 * TOOLBAR_MeasureString
1170 * This function gets the width and height of a string in pixels. This
1171 * is done first by using GetTextExtentPoint to get the basic width
1172 * and height. The DrawText is called with DT_CALCRECT to get the exact
1173 * width. The reason is because the text may have more than one "&" (or
1174 * prefix characters as M$ likes to call them). The prefix character
1175 * indicates where the underline goes, except for the string "&&" which
1176 * is reduced to a single "&". GetTextExtentPoint does not process these
1177 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1180 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1181 HDC hdc
, LPSIZE lpSize
)
1188 if (infoPtr
->nMaxTextRows
> 0 &&
1189 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1190 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1191 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1193 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1195 if(lpText
!= NULL
) {
1196 /* first get size of all the text */
1197 GetTextExtentPoint32W (hdc
, lpText
, strlenW (lpText
), lpSize
);
1199 /* feed above size into the rectangle for DrawText */
1200 myrect
.left
= myrect
.top
= 0;
1201 myrect
.right
= lpSize
->cx
;
1202 myrect
.bottom
= lpSize
->cy
;
1204 /* Use DrawText to get true size as drawn (less pesky "&") */
1205 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1206 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1209 /* feed back to caller */
1210 lpSize
->cx
= myrect
.right
;
1211 lpSize
->cy
= myrect
.bottom
;
1215 TRACE("string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1218 /***********************************************************************
1219 * TOOLBAR_CalcStrings
1221 * This function walks through each string and measures it and returns
1222 * the largest height and width to caller.
1225 TOOLBAR_CalcStrings (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
1227 TBUTTON_INFO
*btnPtr
;
1236 if (infoPtr
->nMaxTextRows
== 0)
1239 hdc
= GetDC (infoPtr
->hwndSelf
);
1240 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1242 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1246 GetTextMetricsW(hdc
, &tm
);
1247 lpSize
->cy
= tm
.tmHeight
;
1250 btnPtr
= infoPtr
->buttons
;
1251 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1252 if(TOOLBAR_GetText(infoPtr
, btnPtr
))
1254 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1255 if (sz
.cx
> lpSize
->cx
)
1257 if (sz
.cy
> lpSize
->cy
)
1262 SelectObject (hdc
, hOldFont
);
1263 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1265 TRACE("max string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1268 /***********************************************************************
1269 * TOOLBAR_WrapToolbar
1271 * This function walks through the buttons and separators in the
1272 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1273 * wrapping should occur based on the width of the toolbar window.
1274 * It does *not* calculate button placement itself. That task
1275 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1276 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1277 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1279 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1280 * vertical toolbar lists.
1284 TOOLBAR_WrapToolbar(TOOLBAR_INFO
*infoPtr
)
1286 TBUTTON_INFO
*btnPtr
;
1291 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1292 /* no layout is necessary. Applications may use this style */
1293 /* to perform their own layout on the toolbar. */
1294 if( !(infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) &&
1295 !(infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
) ) return;
1297 btnPtr
= infoPtr
->buttons
;
1298 x
= infoPtr
->nIndent
;
1300 if (GetParent(infoPtr
->hwndSelf
))
1302 /* this can get the parents width, to know how far we can extend
1303 * this toolbar. We cannot use its height, as there may be multiple
1304 * toolbars in a rebar control
1306 GetClientRect( GetParent(infoPtr
->hwndSelf
), &rc
);
1307 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1311 GetWindowRect( infoPtr
->hwndSelf
, &rc
);
1312 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1315 bButtonWrap
= FALSE
;
1317 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1318 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, infoPtr
->nWidth
,
1321 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1323 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1325 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1328 if (btnPtr
[i
].cx
> 0)
1330 /* horizontal separators are treated as buttons for width */
1331 else if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1332 !(infoPtr
->dwStyle
& CCS_VERT
))
1333 cx
= (btnPtr
[i
].iBitmap
> 0) ? btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1335 cx
= infoPtr
->nButtonWidth
;
1337 /* Two or more adjacent separators form a separator group. */
1338 /* The first separator in a group should be wrapped to the */
1339 /* next row if the previous wrapping is on a button. */
1341 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1342 (i
+ 1 < infoPtr
->nNumButtons
) &&
1343 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1345 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1346 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1347 x
= infoPtr
->nIndent
;
1349 bButtonWrap
= FALSE
;
1353 /* The layout makes sure the bitmap is visible, but not the button. */
1354 /* Test added to also wrap after a button that starts a row but */
1355 /* is bigger than the area. - GA 8/01 */
1356 if (( x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2
1357 > infoPtr
->nWidth
) ||
1358 ((x
== infoPtr
->nIndent
) && (cx
> infoPtr
->nWidth
)))
1360 BOOL bFound
= FALSE
;
1362 /* If the current button is a separator and not hidden, */
1363 /* go to the next until it reaches a non separator. */
1364 /* Wrap the last separator if it is before a button. */
1365 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1366 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1367 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1368 i
< infoPtr
->nNumButtons
)
1374 if( bFound
&& i
< infoPtr
->nNumButtons
)
1377 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1378 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1379 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1380 x
= infoPtr
->nIndent
;
1381 bButtonWrap
= FALSE
;
1384 else if ( i
>= infoPtr
->nNumButtons
)
1387 /* If the current button is not a separator, find the last */
1388 /* separator and wrap it. */
1389 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1391 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1392 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1396 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1397 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1398 x
= infoPtr
->nIndent
;
1399 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1400 bButtonWrap
= FALSE
;
1405 /* If no separator available for wrapping, wrap one of */
1406 /* non-hidden previous button. */
1410 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1412 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1417 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1418 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1419 x
= infoPtr
->nIndent
;
1420 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1426 /* If all above failed, wrap the current button. */
1429 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1430 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1431 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1432 x
= infoPtr
->nIndent
;
1433 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1434 bButtonWrap
= FALSE
;
1440 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1441 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1448 /***********************************************************************
1449 * TOOLBAR_MeasureButton
1451 * Calculates the width and height required for a button. Used in
1452 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1453 * the width of buttons that are autosized.
1455 * Note that it would have been rather elegant to use one piece of code for
1456 * both the laying out of the toolbar and for controlling where button parts
1457 * are drawn, but the native control has inconsistencies between the two that
1458 * prevent this from being effectively. These inconsistencies can be seen as
1459 * artefacts where parts of the button appear outside of the bounding button
1462 * There are several cases for the calculation of the button dimensions and
1463 * button part positioning:
1470 * +--------------------------------------------------------+ ^
1472 * | | pad.cy / 2 | centered | |
1473 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1474 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1475 * | |<------------>| | | | |
1476 * | +--------------+ +------------+ | |
1477 * |<-------------------------------------->| | |
1478 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1480 * +--------------------------------------------------------+ -
1481 * <-------------------------------------------------------->
1482 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1484 * Without Bitmap (I_IMAGENONE):
1486 * +-----------------------------------+ ^
1488 * | | centered | | LISTPAD_CY +
1489 * | +------------+ | | szText.cy
1492 * | +------------+ | |
1493 * |<----------------->| | |
1494 * | cxedge |<-----------> | |
1496 * +-----------------------------------+ -
1497 * <----------------------------------->
1498 * szText.cx + pad.cx
1502 * +--------------------------------------+ ^
1504 * | | padding.cy/2 | | DEFPAD_CY +
1505 * | +------------+ | | nBitmapHeight
1508 * | +------------+ | |
1509 * |<------------------->| | |
1510 * | cxedge + iListGap/2 |<-----------> | |
1511 * | nBitmapWidth | |
1512 * +--------------------------------------+ -
1513 * <-------------------------------------->
1514 * 2*cxedge + nBitmapWidth + iListGap
1521 * +-----------------------------------+ ^
1523 * | | pad.cy / 2 | | nBitmapHeight +
1524 * | - | | szText.cy +
1525 * | +------------+ | | DEFPAD_CY + 1
1526 * | centered | Bitmap | | |
1527 * |<----------------->| | | |
1528 * | +------------+ | |
1532 * | centered +---------------+ | |
1533 * |<--------------->| Text | | |
1534 * | +---------------+ | |
1535 * +-----------------------------------+ -
1536 * <----------------------------------->
1537 * pad.cx + max(nBitmapWidth, szText.cx)
1539 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1541 * +---------------------------------------+ ^
1543 * | | 2 + pad.cy / 2 | |
1544 * | - | | szText.cy +
1545 * | centered +-----------------+ | | pad.cy + 2
1546 * |<--------------->| Text | | |
1547 * | +-----------------+ | |
1549 * +---------------------------------------+ -
1550 * <--------------------------------------->
1551 * 2*cxedge + pad.cx + szText.cx
1554 * As for with bitmaps, but with szText.cx zero.
1556 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1557 BOOL bHasBitmap
, BOOL bValidImageList
)
1560 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1562 /* set button height from bitmap / text height... */
1563 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1566 /* ... add on the necessary padding */
1567 if (bValidImageList
)
1570 sizeButton
.cy
+= DEFPAD_CY
;
1572 sizeButton
.cy
+= LISTPAD_CY
;
1575 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1577 /* calculate button width */
1578 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1579 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1580 if (sizeString
.cx
> 0)
1581 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1588 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1589 if (sizeString
.cy
> 0)
1590 sizeButton
.cy
+= 1 + sizeString
.cy
;
1591 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1592 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1596 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1597 NONLIST_NOTEXT_OFFSET
;
1598 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1599 max(2*GetSystemMetrics(SM_CXEDGE
) + sizeString
.cx
, infoPtr
->nBitmapWidth
);
1606 /***********************************************************************
1607 * TOOLBAR_CalcToolbar
1609 * This function calculates button and separator placement. It first
1610 * calculates the button sizes, gets the toolbar window width and then
1611 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1612 * on. It assigns a new location to each item and sends this location to
1613 * the tooltip window if appropriate. Finally, it updates the rcBound
1614 * rect and calculates the new required toolbar window height.
1617 TOOLBAR_CalcToolbar (TOOLBAR_INFO
*infoPtr
)
1619 SIZE sizeString
, sizeButton
;
1620 BOOL validImageList
= FALSE
;
1622 TOOLBAR_CalcStrings (infoPtr
, &sizeString
);
1624 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1626 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1627 validImageList
= TRUE
;
1628 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1629 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1630 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1631 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1633 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1634 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1635 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1636 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1638 TOOLBAR_LayoutToolbar(infoPtr
);
1642 TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
)
1644 TBUTTON_INFO
*btnPtr
;
1646 INT i
, nRows
, nSepRows
;
1649 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1650 BOOL hasDropDownArrows
= TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
);
1652 TOOLBAR_WrapToolbar(infoPtr
);
1654 x
= infoPtr
->nIndent
;
1655 y
= infoPtr
->iTopMargin
;
1656 cx
= infoPtr
->nButtonWidth
;
1657 cy
= infoPtr
->nButtonHeight
;
1659 nRows
= nSepRows
= 0;
1661 infoPtr
->rcBound
.top
= y
;
1662 infoPtr
->rcBound
.left
= x
;
1663 infoPtr
->rcBound
.bottom
= y
+ cy
;
1664 infoPtr
->rcBound
.right
= x
;
1666 btnPtr
= infoPtr
->buttons
;
1668 TRACE("cy=%d\n", cy
);
1670 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1673 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1675 SetRectEmpty (&btnPtr
->rect
);
1679 cy
= infoPtr
->nButtonHeight
;
1681 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1682 if (infoPtr
->dwStyle
& CCS_VERT
) {
1683 cy
= (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1684 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
: infoPtr
->nWidth
;
1687 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
:
1688 (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1694 else if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1695 (btnPtr
->fsStyle
& BTNS_AUTOSIZE
))
1701 hdc
= GetDC (infoPtr
->hwndSelf
);
1702 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1704 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1706 SelectObject (hdc
, hOldFont
);
1707 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1709 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1710 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1715 cx
= infoPtr
->nButtonWidth
;
1717 /* if size has been set manually then don't add on extra space
1718 * for the drop down arrow */
1719 if (!btnPtr
->cx
&& hasDropDownArrows
&&
1720 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) || (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)))
1721 cx
+= DDARROW_WIDTH
;
1723 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1726 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1728 if (infoPtr
->rcBound
.left
> x
)
1729 infoPtr
->rcBound
.left
= x
;
1730 if (infoPtr
->rcBound
.right
< x
+ cx
)
1731 infoPtr
->rcBound
.right
= x
+ cx
;
1732 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1733 infoPtr
->rcBound
.bottom
= y
+ cy
;
1735 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1737 /* btnPtr->nRow is zero based. The space between the rows is */
1738 /* also considered as a row. */
1739 btnPtr
->nRow
= nRows
+ nSepRows
;
1741 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1742 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1747 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1751 if ( !(infoPtr
->dwStyle
& CCS_VERT
))
1752 y
+= cy
+ ( (btnPtr
->cx
> 0 ) ?
1753 btnPtr
->cx
: SEPARATOR_WIDTH
) * 2 /3;
1757 /* nSepRows is used to calculate the extra height following */
1761 x
= infoPtr
->nIndent
;
1763 /* Increment row number unless this is the last button */
1764 /* and it has Wrap set. */
1765 if (i
!= infoPtr
->nNumButtons
-1)
1772 /* infoPtr->nRows is the number of rows on the toolbar */
1773 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1775 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1780 TOOLBAR_InternalHitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
*lpPt
, BOOL
*button
)
1782 TBUTTON_INFO
*btnPtr
;
1788 btnPtr
= infoPtr
->buttons
;
1789 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1790 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1793 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1794 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1795 TRACE(" ON SEPARATOR %d!\n", i
);
1800 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1801 TRACE(" ON BUTTON %d!\n", i
);
1809 TRACE(" NOWHERE!\n");
1810 return TOOLBAR_NOWHERE
;
1814 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1816 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO
*infoPtr
, INT iIndex
, UINT nAddButtons
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
1818 INT nOldButtons
, nNewButtons
, iButton
;
1819 BOOL fHasString
= FALSE
;
1821 if (iIndex
< 0) /* iIndex can be negative, what means adding at the end */
1822 iIndex
= infoPtr
->nNumButtons
;
1824 nOldButtons
= infoPtr
->nNumButtons
;
1825 nNewButtons
= nOldButtons
+ nAddButtons
;
1827 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
1828 memmove(&infoPtr
->buttons
[iIndex
+ nAddButtons
], &infoPtr
->buttons
[iIndex
],
1829 (nOldButtons
- iIndex
) * sizeof(TBUTTON_INFO
));
1830 infoPtr
->nNumButtons
+= nAddButtons
;
1832 /* insert new buttons data */
1833 for (iButton
= 0; iButton
< nAddButtons
; iButton
++) {
1834 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[iIndex
+ iButton
];
1836 TOOLBAR_DumpTBButton(lpTbb
+ iButton
, fUnicode
);
1838 ZeroMemory(btnPtr
, sizeof(*btnPtr
));
1840 btnPtr
->iBitmap
= lpTbb
[iButton
].iBitmap
;
1841 btnPtr
->idCommand
= lpTbb
[iButton
].idCommand
;
1842 btnPtr
->fsState
= lpTbb
[iButton
].fsState
;
1843 btnPtr
->fsStyle
= lpTbb
[iButton
].fsStyle
;
1844 btnPtr
->dwData
= lpTbb
[iButton
].dwData
;
1845 if (btnPtr
->fsStyle
& BTNS_SEP
)
1846 btnPtr
->iString
= -1;
1847 else if(!IS_INTRESOURCE(lpTbb
[iButton
].iString
) && lpTbb
[iButton
].iString
!= -1)
1850 Str_SetPtrW((LPWSTR
*)&btnPtr
->iString
, (LPWSTR
)lpTbb
[iButton
].iString
);
1852 Str_SetPtrAtoW((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lpTbb
[iButton
].iString
);
1856 btnPtr
->iString
= lpTbb
[iButton
].iString
;
1858 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
1861 if (infoPtr
->nNumStrings
> 0 || fHasString
)
1862 TOOLBAR_CalcToolbar(infoPtr
);
1864 TOOLBAR_LayoutToolbar(infoPtr
);
1865 TOOLBAR_AutoSize(infoPtr
);
1867 TOOLBAR_DumpToolbar(infoPtr
, __LINE__
);
1868 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1874 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1876 TBUTTON_INFO
*btnPtr
;
1879 if (CommandIsIndex
) {
1880 TRACE("command is really index command=%d\n", idCommand
);
1881 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1884 btnPtr
= infoPtr
->buttons
;
1885 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1886 if (btnPtr
->idCommand
== idCommand
) {
1887 TRACE("command=%d index=%d\n", idCommand
, i
);
1891 TRACE("no index found for command=%d\n", idCommand
);
1897 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1899 TBUTTON_INFO
*btnPtr
;
1902 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1905 /* check index button */
1906 btnPtr
= &infoPtr
->buttons
[nIndex
];
1907 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1908 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1912 /* check previous buttons */
1913 nRunIndex
= nIndex
- 1;
1914 while (nRunIndex
>= 0) {
1915 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1916 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1917 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1925 /* check next buttons */
1926 nRunIndex
= nIndex
+ 1;
1927 while (nRunIndex
< infoPtr
->nNumButtons
) {
1928 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1929 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1930 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1943 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1944 WPARAM wParam
, LPARAM lParam
)
1950 msg
.wParam
= wParam
;
1951 msg
.lParam
= lParam
;
1952 msg
.time
= GetMessageTime ();
1953 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
1954 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
1956 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1960 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1962 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
1965 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
1966 ti
.cbSize
= sizeof (TTTOOLINFOW
);
1967 ti
.hwnd
= infoPtr
->hwndSelf
;
1968 ti
.uId
= button
->idCommand
;
1970 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
1971 /* ti.lParam = random value from the stack? */
1973 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
1979 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1981 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
1984 ZeroMemory(&ti
, sizeof(ti
));
1985 ti
.cbSize
= sizeof(ti
);
1986 ti
.hwnd
= infoPtr
->hwndSelf
;
1987 ti
.uId
= button
->idCommand
;
1989 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
1993 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1995 /* Set the toolTip only for non-hidden, non-separator button */
1996 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
2000 ZeroMemory(&ti
, sizeof(ti
));
2001 ti
.cbSize
= sizeof(ti
);
2002 ti
.hwnd
= infoPtr
->hwndSelf
;
2003 ti
.uId
= button
->idCommand
;
2004 ti
.rect
= button
->rect
;
2005 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
2009 /* Creates the tooltip control */
2011 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
2014 NMTOOLTIPSCREATED nmttc
;
2016 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
2017 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2018 infoPtr
->hwndSelf
, 0, 0, 0);
2020 if (!infoPtr
->hwndToolTip
)
2023 /* Send NM_TOOLTIPSCREATED notification */
2024 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
2025 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
2027 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
2029 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
2030 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
2034 /* keeps available button list box sorted by button id */
2035 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
2039 PCUSTOMBUTTON btnInfo
;
2040 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2042 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
2044 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2046 /* position 0 is always separator */
2047 for (i
= 1; i
< count
; i
++)
2049 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2050 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2052 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2053 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2057 /* id higher than all others add to end */
2058 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2059 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2062 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2066 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2068 if (nIndexFrom
== nIndexTo
)
2071 /* MSDN states that iItem is the index of the button, rather than the
2072 * command ID as used by every other NMTOOLBAR notification */
2073 nmtb
.iItem
= nIndexFrom
;
2074 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2076 PCUSTOMBUTTON btnInfo
;
2078 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2079 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2081 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2083 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2084 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2085 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2086 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2089 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2091 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2093 /* last item is always separator, so -2 instead of -1 */
2094 if (nIndexTo
>= (count
- 2))
2095 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2097 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2099 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2100 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2102 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2106 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2110 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2112 /* MSDN states that iItem is the index of the button, rather than the
2113 * command ID as used by every other NMTOOLBAR notification */
2114 nmtb
.iItem
= nIndexAvail
;
2115 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2117 PCUSTOMBUTTON btnInfo
;
2119 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2120 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2121 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2123 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2125 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2127 /* remove from 'available buttons' list */
2128 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2129 if (nIndexAvail
== count
-1)
2130 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2132 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2136 PCUSTOMBUTTON btnNew
;
2138 /* duplicate 'separator' button */
2139 btnNew
= Alloc(sizeof(CUSTOMBUTTON
));
2144 /* insert into 'toolbar button' list */
2145 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2146 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2148 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2150 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2154 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2156 PCUSTOMBUTTON btnInfo
;
2157 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2159 TRACE("Remove: index %d\n", index
);
2161 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2163 /* send TBN_QUERYDELETE notification */
2164 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2168 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2169 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2171 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2173 /* insert into 'available button' list */
2174 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2175 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2179 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2183 /* drag list notification function for toolbar buttons list box */
2184 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2185 const DRAGLISTINFO
*pDLI
)
2187 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2188 switch (pDLI
->uNotification
)
2192 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2193 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2194 /* no dragging for last item (separator) */
2195 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2200 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2201 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2202 /* no dragging past last item (separator) */
2203 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2205 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2206 /* FIXME: native uses "move button" cursor */
2207 return DL_COPYCURSOR
;
2210 /* not over toolbar buttons list */
2211 if (nCurrentItem
< 0)
2213 POINT ptWindow
= pDLI
->ptCursor
;
2214 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2215 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2216 /* over available buttons list? */
2217 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2218 /* FIXME: native uses "move button" cursor */
2219 return DL_COPYCURSOR
;
2221 /* clear drag arrow */
2222 DrawInsert(hwnd
, hwndList
, -1);
2223 return DL_STOPCURSOR
;
2227 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2228 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2229 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2230 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2232 /* clear drag arrow */
2233 DrawInsert(hwnd
, hwndList
, -1);
2235 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2237 /* not over toolbar buttons list */
2240 POINT ptWindow
= pDLI
->ptCursor
;
2241 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2242 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2243 /* over available buttons list? */
2244 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2245 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2250 /* Clear drag arrow */
2251 DrawInsert(hwnd
, hwndList
, -1);
2258 /* drag list notification function for available buttons list box */
2259 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2260 const DRAGLISTINFO
*pDLI
)
2262 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2263 switch (pDLI
->uNotification
)
2269 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2270 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2271 /* no dragging past last item (separator) */
2272 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2274 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2275 /* FIXME: native uses "move button" cursor */
2276 return DL_COPYCURSOR
;
2279 /* not over toolbar buttons list */
2280 if (nCurrentItem
< 0)
2282 POINT ptWindow
= pDLI
->ptCursor
;
2283 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2284 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2285 /* over available buttons list? */
2286 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2287 /* FIXME: native uses "move button" cursor */
2288 return DL_COPYCURSOR
;
2290 /* clear drag arrow */
2291 DrawInsert(hwnd
, hwndList
, -1);
2292 return DL_STOPCURSOR
;
2296 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2297 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2298 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2299 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2301 /* clear drag arrow */
2302 DrawInsert(hwnd
, hwndList
, -1);
2304 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2308 /* Clear drag arrow */
2309 DrawInsert(hwnd
, hwndList
, -1);
2315 extern UINT uDragListMessage DECLSPEC_HIDDEN
;
2317 /***********************************************************************
2318 * TOOLBAR_CustomizeDialogProc
2319 * This function implements the toolbar customization dialog.
2321 static INT_PTR CALLBACK
2322 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2324 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2325 PCUSTOMBUTTON btnInfo
;
2327 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2332 custInfo
= (PCUSTDLG_INFO
)lParam
;
2333 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2340 NMTBINITCUSTOMIZE nmtbic
;
2342 infoPtr
= custInfo
->tbInfo
;
2344 /* send TBN_QUERYINSERT notification */
2345 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2347 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2350 nmtbic
.hwndDialog
= hwnd
;
2351 /* Send TBN_INITCUSTOMIZE notification */
2352 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2355 TRACE("TBNRF_HIDEHELP requested\n");
2356 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2359 /* add items to 'toolbar buttons' list and check if removable */
2360 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2362 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2363 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2364 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2365 btnInfo
->bVirtual
= FALSE
;
2366 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2368 /* send TBN_QUERYDELETE notification */
2369 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2371 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2372 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2375 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2377 /* insert separator button into 'available buttons' list */
2378 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2379 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2380 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2381 btnInfo
->bVirtual
= FALSE
;
2382 btnInfo
->bRemovable
= TRUE
;
2383 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2384 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2385 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2387 /* insert all buttons into dsa */
2390 /* send TBN_GETBUTTONINFO notification */
2393 nmtb
.pszText
= Buffer
;
2396 /* Clear previous button's text */
2397 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2399 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2402 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2403 nmtb
.tbButton
.fsStyle
, i
,
2404 nmtb
.tbButton
.idCommand
,
2405 nmtb
.tbButton
.iString
,
2406 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2409 /* insert button into the appropriate list */
2410 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2413 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2414 btnInfo
->bVirtual
= FALSE
;
2415 btnInfo
->bRemovable
= TRUE
;
2419 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2420 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2423 btnInfo
->btn
= nmtb
.tbButton
;
2424 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2426 if (lstrlenW(nmtb
.pszText
))
2427 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2428 else if (nmtb
.tbButton
.iString
>= 0 &&
2429 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2431 lstrcpyW(btnInfo
->text
,
2432 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2437 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2440 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2442 /* select first item in the 'available' list */
2443 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2445 /* append 'virtual' separator button to the 'toolbar buttons' list */
2446 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2447 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2448 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2449 btnInfo
->bVirtual
= TRUE
;
2450 btnInfo
->bRemovable
= FALSE
;
2451 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2452 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2453 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2455 /* select last item in the 'toolbar' list */
2456 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2457 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2459 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2460 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2462 /* set focus and disable buttons */
2463 PostMessageW (hwnd
, WM_USER
, 0, 0);
2468 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2469 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2470 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2471 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2475 EndDialog(hwnd
, FALSE
);
2479 switch (LOWORD(wParam
))
2481 case IDC_TOOLBARBTN_LBOX
:
2482 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2484 PCUSTOMBUTTON btnInfo
;
2489 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2490 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2492 /* send TBN_QUERYINSERT notification */
2494 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2496 /* get list box item */
2497 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2499 if (index
== (count
- 1))
2501 /* last item (virtual separator) */
2502 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2503 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2505 else if (index
== (count
- 2))
2507 /* second last item (last non-virtual item) */
2508 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2509 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2511 else if (index
== 0)
2514 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2515 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2519 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2520 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2523 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2527 case IDC_MOVEUP_BTN
:
2529 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2530 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2534 case IDC_MOVEDN_BTN
: /* move down */
2536 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2537 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2541 case IDC_REMOVE_BTN
: /* remove button */
2543 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2545 if (LB_ERR
== index
)
2548 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2552 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2555 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2558 case IDOK
: /* Add button */
2563 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2564 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2566 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2571 EndDialog(hwnd
, FALSE
);
2581 /* delete items from 'toolbar buttons' listbox*/
2582 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2583 for (i
= 0; i
< count
; i
++)
2585 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2587 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2589 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2592 /* delete items from 'available buttons' listbox*/
2593 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2594 for (i
= 0; i
< count
; i
++)
2596 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2598 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2600 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2605 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2607 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2612 COLORREF oldText
= 0;
2616 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, lpdis
->itemID
, 0);
2617 if (btnInfo
== NULL
)
2619 FIXME("btnInfo invalid!\n");
2623 /* set colors and select objects */
2624 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2625 if (btnInfo
->bVirtual
)
2626 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2628 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2629 hPen
= CreatePen( PS_SOLID
, 1,
2630 (lpdis
->itemState
& ODS_SELECTED
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2631 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2632 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2634 /* fill background rectangle */
2635 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2636 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2638 /* calculate button and text rectangles */
2639 CopyRect (&rcButton
, &lpdis
->rcItem
);
2640 InflateRect (&rcButton
, -1, -1);
2641 CopyRect (&rcText
, &rcButton
);
2642 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2643 rcText
.left
= rcButton
.right
+ 2;
2645 /* draw focus rectangle */
2646 if (lpdis
->itemState
& ODS_FOCUS
)
2647 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2650 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2651 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2653 /* draw image and text */
2654 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2655 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2656 btnInfo
->btn
.iBitmap
));
2657 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2658 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2660 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2661 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2663 /* delete objects and reset colors */
2664 SelectObject (lpdis
->hDC
, hOldBrush
);
2665 SelectObject (lpdis
->hDC
, hOldPen
);
2666 SetBkColor (lpdis
->hDC
, oldBk
);
2667 SetTextColor (lpdis
->hDC
, oldText
);
2668 DeleteObject( hPen
);
2673 case WM_MEASUREITEM
:
2674 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2676 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2678 lpmis
->itemHeight
= 15 + 8; /* default height */
2685 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2687 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2689 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2690 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2691 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2694 else if (wParam
== IDC_AVAILBTN_LBOX
)
2696 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2697 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2698 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2707 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2710 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2716 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2717 /* Add bitmaps to the default image list */
2718 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2719 hbmLoad
= CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2720 else if (bitmap
->hInst
== COMCTL32_hModule
)
2721 hbmLoad
= LoadImageW( bitmap
->hInst
, MAKEINTRESOURCEW(bitmap
->nID
),
2722 IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
2724 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2726 /* enlarge the bitmap if needed */
2727 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2728 if (bitmap
->hInst
!= COMCTL32_hModule
)
2729 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2731 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2732 DeleteObject(hbmLoad
);
2736 nCountAfter
= ImageList_GetImageCount(himlDef
);
2737 nAdded
= nCountAfter
- nCountBefore
;
2738 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2740 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2741 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2742 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2743 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2746 infoPtr
->nNumBitmaps
+= nAdded
;
2751 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2758 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2759 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2761 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2763 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2766 TRACE("Update icon size: %dx%d -> %dx%d\n",
2767 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2769 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2770 ILC_COLOR32
|ILC_MASK
, 8, 2);
2771 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2772 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2773 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2774 infoPtr
->himlInt
= himlNew
;
2776 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2777 ImageList_Destroy(himlDef
);
2780 /***********************************************************************
2781 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2785 TOOLBAR_AddBitmap (TOOLBAR_INFO
*infoPtr
, INT count
, const TBADDBITMAP
*lpAddBmp
)
2791 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr
->hwndSelf
, count
, lpAddBmp
);
2795 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2797 info
.hInst
= COMCTL32_hModule
;
2798 switch (lpAddBmp
->nID
)
2800 case IDB_STD_SMALL_COLOR
:
2802 info
.nID
= IDB_STD_SMALL
;
2804 case IDB_STD_LARGE_COLOR
:
2806 info
.nID
= IDB_STD_LARGE
;
2808 case IDB_VIEW_SMALL_COLOR
:
2810 info
.nID
= IDB_VIEW_SMALL
;
2812 case IDB_VIEW_LARGE_COLOR
:
2814 info
.nID
= IDB_VIEW_LARGE
;
2816 case IDB_HIST_SMALL_COLOR
:
2818 info
.nID
= IDB_HIST_SMALL
;
2820 case IDB_HIST_LARGE_COLOR
:
2822 info
.nID
= IDB_HIST_LARGE
;
2828 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2830 /* Windows resize all the buttons to the size of a newly added standard image */
2831 if (lpAddBmp
->nID
& 1)
2833 /* large icons: 24x24. Will make the button 31x30 */
2834 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2838 /* small icons: 16x16. Will make the buttons 23x22 */
2839 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2842 TOOLBAR_CalcToolbar (infoPtr
);
2846 info
.nButtons
= count
;
2847 info
.hInst
= lpAddBmp
->hInst
;
2848 info
.nID
= lpAddBmp
->nID
;
2849 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2852 /* check if the bitmap is already loaded and compute iSumButtons */
2854 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2856 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2857 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2859 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2862 if (!infoPtr
->cimlDef
) {
2863 /* create new default image list */
2864 TRACE ("creating default image list!\n");
2866 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2867 ILC_COLOR32
| ILC_MASK
, info
.nButtons
, 2);
2868 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2869 infoPtr
->himlInt
= himlDef
;
2872 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2876 WARN("No default image list available\n");
2880 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2883 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2884 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2885 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2886 infoPtr
->nNumBitmapInfos
++;
2887 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2889 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2895 TOOLBAR_AddButtonsT(TOOLBAR_INFO
*infoPtr
, INT nAddButtons
, const TBBUTTON
* lpTbb
, BOOL fUnicode
)
2897 TRACE("adding %d buttons (unicode=%d)!\n", nAddButtons
, fUnicode
);
2899 return TOOLBAR_InternalInsertButtonsT(infoPtr
, -1, nAddButtons
, lpTbb
, fUnicode
);
2904 TOOLBAR_AddStringW (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
2906 #define MAX_RESOURCE_STRING_LENGTH 512
2907 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2908 INT nIndex
= infoPtr
->nNumStrings
;
2910 TRACE("%p, %lx\n", hInstance
, lParam
);
2912 if (IS_INTRESOURCE(lParam
)) {
2913 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2920 TRACE("adding string from resource\n");
2922 if (!hInstance
) return -1;
2924 hrsrc
= FindResourceW( hInstance
, MAKEINTRESOURCEW((LOWORD(lParam
) >> 4) + 1),
2925 (LPWSTR
)RT_STRING
);
2928 TRACE("string not found in resources\n");
2932 len
= LoadStringW (hInstance
, (UINT
)lParam
,
2933 szString
, MAX_RESOURCE_STRING_LENGTH
);
2935 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2936 if (len
== 0 || len
== 1)
2939 TRACE("delimiter: 0x%x\n", *szString
);
2940 delimiter
= *szString
;
2943 while ((next_delim
= strchrW(p
, delimiter
)) != NULL
) {
2945 if (next_delim
+ 1 >= szString
+ len
)
2947 /* this may happen if delimiter == '\0' or if the last char is a
2948 * delimiter (then it is ignored like the native does) */
2952 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2953 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2954 infoPtr
->nNumStrings
++;
2960 LPWSTR p
= (LPWSTR
)lParam
;
2965 TRACE("adding string(s) from array\n");
2969 TRACE("len=%d %s\n", len
, debugstr_w(p
));
2970 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2971 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2972 infoPtr
->nNumStrings
++;
2979 TOOLBAR_CalcToolbar(infoPtr
);
2985 TOOLBAR_AddStringA (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
2987 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2992 TRACE("%p, %lx\n", hInstance
, lParam
);
2994 if (IS_INTRESOURCE(lParam
)) /* load from resources */
2995 return TOOLBAR_AddStringW(infoPtr
, hInstance
, lParam
);
3001 TRACE("adding string(s) from array\n");
3002 nIndex
= infoPtr
->nNumStrings
;
3005 TRACE("len=%d \"%s\"\n", len
, p
);
3007 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3008 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3009 infoPtr
->nNumStrings
++;
3015 TOOLBAR_CalcToolbar(infoPtr
);
3021 TOOLBAR_AutoSize (TOOLBAR_INFO
*infoPtr
)
3028 TRACE("auto sizing, style=%x!\n", infoPtr
->dwStyle
);
3030 parent
= GetParent (infoPtr
->hwndSelf
);
3032 if (!parent
|| !infoPtr
->bDoRedraw
)
3035 GetClientRect(parent
, &parent_rect
);
3037 x
= parent_rect
.left
;
3038 y
= parent_rect
.top
;
3040 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3042 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3043 cx
= parent_rect
.right
- parent_rect
.left
;
3045 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
))
3047 TOOLBAR_LayoutToolbar(infoPtr
);
3048 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
3051 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3054 UINT uPosFlags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
3056 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3058 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3059 MapWindowPoints( 0, parent
, (POINT
*)&window_rect
, 2 );
3060 y
= window_rect
.top
;
3062 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3064 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3065 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3068 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3069 uPosFlags
|= SWP_NOMOVE
;
3071 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3072 cy
+= GetSystemMetrics(SM_CYEDGE
);
3074 if (infoPtr
->dwStyle
& WS_BORDER
)
3076 cx
+= 2 * GetSystemMetrics(SM_CXBORDER
);
3077 cy
+= 2 * GetSystemMetrics(SM_CYBORDER
);
3080 SetWindowPos(infoPtr
->hwndSelf
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3087 static inline LRESULT
3088 TOOLBAR_ButtonCount (const TOOLBAR_INFO
*infoPtr
)
3090 return infoPtr
->nNumButtons
;
3094 static inline LRESULT
3095 TOOLBAR_ButtonStructSize (TOOLBAR_INFO
*infoPtr
, DWORD Size
)
3097 infoPtr
->dwStructSize
= Size
;
3104 TOOLBAR_ChangeBitmap (TOOLBAR_INFO
*infoPtr
, INT Id
, INT Index
)
3106 TBUTTON_INFO
*btnPtr
;
3109 TRACE("button %d, iBitmap now %d\n", Id
, Index
);
3111 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3115 btnPtr
= &infoPtr
->buttons
[nIndex
];
3116 btnPtr
->iBitmap
= Index
;
3118 /* we HAVE to erase the background, the new bitmap could be */
3120 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3127 TOOLBAR_CheckButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3129 TBUTTON_INFO
*btnPtr
;
3132 BOOL bChecked
= FALSE
;
3134 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3136 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, nIndex
, lParam
);
3141 btnPtr
= &infoPtr
->buttons
[nIndex
];
3143 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) != 0;
3145 if (LOWORD(lParam
) == FALSE
)
3146 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3148 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3150 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3151 if (nOldIndex
== nIndex
)
3153 if (nOldIndex
!= -1)
3154 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3156 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3159 if( bChecked
!= LOWORD(lParam
) )
3161 if (nOldIndex
!= -1)
3162 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3163 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3166 /* FIXME: Send a WM_NOTIFY?? */
3173 TOOLBAR_CommandToIndex (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3175 return TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3180 TOOLBAR_Customize (TOOLBAR_INFO
*infoPtr
)
3182 CUSTDLG_INFO custInfo
;
3186 custInfo
.tbInfo
= infoPtr
;
3187 custInfo
.tbHwnd
= infoPtr
->hwndSelf
;
3189 /* send TBN_BEGINADJUST notification */
3190 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3192 ret
= DialogBoxParamW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3193 infoPtr
->hwndSelf
, TOOLBAR_CustomizeDialogProc
, (LPARAM
)&custInfo
);
3195 /* send TBN_ENDADJUST notification */
3196 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3203 TOOLBAR_DeleteButton (TOOLBAR_INFO
*infoPtr
, INT nIndex
)
3206 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3208 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3211 memset(&nmtb
, 0, sizeof(nmtb
));
3212 nmtb
.iItem
= btnPtr
->idCommand
;
3213 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3214 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3215 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3216 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3217 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3218 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3219 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3221 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3223 if (infoPtr
->nNumButtons
== 1) {
3224 TRACE(" simple delete!\n");
3225 if (TOOLBAR_ButtonHasString(infoPtr
->buttons
))
3226 Free((LPWSTR
)infoPtr
->buttons
[0].iString
);
3227 Free (infoPtr
->buttons
);
3228 infoPtr
->buttons
= NULL
;
3229 infoPtr
->nNumButtons
= 0;
3232 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3233 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3235 infoPtr
->nNumButtons
--;
3236 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3238 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3239 nIndex
* sizeof(TBUTTON_INFO
));
3242 if (nIndex
< infoPtr
->nNumButtons
) {
3243 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3244 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3247 if (TOOLBAR_ButtonHasString(&oldButtons
[nIndex
]))
3248 Free((LPWSTR
)oldButtons
[nIndex
].iString
);
3252 TOOLBAR_LayoutToolbar(infoPtr
);
3254 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3261 TOOLBAR_EnableButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3263 TBUTTON_INFO
*btnPtr
;
3267 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3269 TRACE("hwnd=%p, btn id=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, Id
, lParam
);
3274 btnPtr
= &infoPtr
->buttons
[nIndex
];
3276 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3278 /* update the toolbar button state */
3279 if(LOWORD(lParam
) == FALSE
) {
3280 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3282 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3285 /* redraw the button only if the state of the button changed */
3286 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3287 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3293 static inline LRESULT
3294 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO
*infoPtr
)
3296 return infoPtr
->bAnchor
;
3301 TOOLBAR_GetBitmap (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3305 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3309 return infoPtr
->buttons
[nIndex
].iBitmap
;
3313 static inline LRESULT
3314 TOOLBAR_GetBitmapFlags (void)
3316 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3321 TOOLBAR_GetButton (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, TBBUTTON
*lpTbb
)
3323 TBUTTON_INFO
*btnPtr
;
3328 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3331 btnPtr
= &infoPtr
->buttons
[nIndex
];
3332 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3333 lpTbb
->idCommand
= btnPtr
->idCommand
;
3334 lpTbb
->fsState
= btnPtr
->fsState
;
3335 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3336 lpTbb
->bReserved
[0] = 0;
3337 lpTbb
->bReserved
[1] = 0;
3338 lpTbb
->dwData
= btnPtr
->dwData
;
3339 lpTbb
->iString
= btnPtr
->iString
;
3346 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO
*infoPtr
, INT Id
, LPTBBUTTONINFOW lpTbInfo
, BOOL bUnicode
)
3348 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3349 TBUTTON_INFO
*btnPtr
;
3352 if (lpTbInfo
== NULL
)
3355 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3356 * the headers and tests shows that even with comctl 6 Vista accepts only the
3357 * original TBBUTTONINFO size
3359 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3361 WARN("Invalid button size\n");
3365 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lpTbInfo
->dwMask
& TBIF_BYINDEX
);
3369 if (!(btnPtr
= &infoPtr
->buttons
[nIndex
])) return -1;
3371 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3372 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3373 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3374 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3375 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3376 lpTbInfo
->lParam
= btnPtr
->dwData
;
3377 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3378 /* tests show that for separators TBIF_SIZE returns not calculated width,
3379 but cx property, that differs from 0 only if application have
3380 specifically set it */
3381 lpTbInfo
->cx
= (btnPtr
->fsStyle
& BTNS_SEP
)
3382 ? btnPtr
->cx
: (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3383 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3384 lpTbInfo
->fsState
= btnPtr
->fsState
;
3385 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3386 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3387 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3388 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3389 can't use TOOLBAR_GetText here */
3390 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3391 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3393 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3395 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3397 lpTbInfo
->pszText
[0] = '\0';
3403 static inline LRESULT
3404 TOOLBAR_GetButtonSize (const TOOLBAR_INFO
*infoPtr
)
3406 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3407 (WORD
)infoPtr
->nButtonHeight
);
3412 TOOLBAR_GetButtonText (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPWSTR lpStr
, BOOL isW
)
3418 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3422 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3428 ret
= strlenW (lpText
);
3429 if (lpStr
) strcpyW (lpStr
, lpText
);
3433 ret
= WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3434 (LPSTR
)lpStr
, lpStr
? 0x7fffffff : 0, NULL
, NULL
) - 1;
3440 TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3442 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3443 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3444 return (LRESULT
)GETDISIMAGELIST(infoPtr
, wParam
);
3448 static inline LRESULT
3449 TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO
*infoPtr
)
3453 return infoPtr
->dwExStyle
;
3458 TOOLBAR_GetHotImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3460 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3461 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3462 return (LRESULT
)GETHOTIMAGELIST(infoPtr
, wParam
);
3467 TOOLBAR_GetHotItem (const TOOLBAR_INFO
*infoPtr
)
3469 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3472 if (infoPtr
->nHotItem
< 0)
3475 return (LRESULT
)infoPtr
->nHotItem
;
3480 TOOLBAR_GetDefImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3482 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3483 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3484 return (LRESULT
) GETDEFIMAGELIST(infoPtr
, wParam
);
3489 TOOLBAR_GetInsertMark (const TOOLBAR_INFO
*infoPtr
, TBINSERTMARK
*lptbim
)
3491 TRACE("hwnd = %p, lptbim = %p\n", infoPtr
->hwndSelf
, lptbim
);
3493 *lptbim
= infoPtr
->tbim
;
3499 static inline LRESULT
3500 TOOLBAR_GetInsertMarkColor (const TOOLBAR_INFO
*infoPtr
)
3502 TRACE("hwnd = %p\n", infoPtr
->hwndSelf
);
3504 return (LRESULT
)infoPtr
->clrInsertMark
;
3509 TOOLBAR_GetItemRect (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, LPRECT lpRect
)
3511 TBUTTON_INFO
*btnPtr
;
3513 btnPtr
= &infoPtr
->buttons
[nIndex
];
3514 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3519 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3522 lpRect
->left
= btnPtr
->rect
.left
;
3523 lpRect
->right
= btnPtr
->rect
.right
;
3524 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3525 lpRect
->top
= btnPtr
->rect
.top
;
3532 TOOLBAR_GetMaxSize (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
3537 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3538 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3540 TRACE("maximum size %d x %d\n",
3541 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3542 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3548 /* << TOOLBAR_GetObject >> */
3551 static inline LRESULT
3552 TOOLBAR_GetPadding (const TOOLBAR_INFO
*infoPtr
)
3554 return MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3559 TOOLBAR_GetRect (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPRECT lpRect
)
3561 TBUTTON_INFO
*btnPtr
;
3564 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3565 btnPtr
= &infoPtr
->buttons
[nIndex
];
3566 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3572 lpRect
->left
= btnPtr
->rect
.left
;
3573 lpRect
->right
= btnPtr
->rect
.right
;
3574 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3575 lpRect
->top
= btnPtr
->rect
.top
;
3581 static inline LRESULT
3582 TOOLBAR_GetRows (const TOOLBAR_INFO
*infoPtr
)
3584 return infoPtr
->nRows
;
3589 TOOLBAR_GetState (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3593 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3597 return infoPtr
->buttons
[nIndex
].fsState
;
3601 static inline LRESULT
3602 TOOLBAR_GetStyle (const TOOLBAR_INFO
*infoPtr
)
3604 return infoPtr
->dwStyle
;
3608 static inline LRESULT
3609 TOOLBAR_GetTextRows (const TOOLBAR_INFO
*infoPtr
)
3611 return infoPtr
->nMaxTextRows
;
3616 TOOLBAR_GetToolTips (TOOLBAR_INFO
*infoPtr
)
3618 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3619 TOOLBAR_TooltipCreateControl(infoPtr
);
3620 return (LRESULT
)infoPtr
->hwndToolTip
;
3625 TOOLBAR_GetUnicodeFormat (const TOOLBAR_INFO
*infoPtr
)
3627 TRACE("%s hwnd=%p\n",
3628 infoPtr
->bUnicode
? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
3630 return infoPtr
->bUnicode
;
3634 static inline LRESULT
3635 TOOLBAR_GetVersion (const TOOLBAR_INFO
*infoPtr
)
3637 return infoPtr
->iVersion
;
3642 TOOLBAR_HideButton (TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fHide
)
3644 TBUTTON_INFO
*btnPtr
;
3650 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3654 btnPtr
= &infoPtr
->buttons
[nIndex
];
3655 oldState
= btnPtr
->fsState
;
3658 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3660 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3662 if (oldState
!= btnPtr
->fsState
) {
3663 TOOLBAR_LayoutToolbar (infoPtr
);
3664 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3671 static inline LRESULT
3672 TOOLBAR_HitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
* lpPt
)
3674 return TOOLBAR_InternalHitTest (infoPtr
, lpPt
, NULL
);
3679 TOOLBAR_Indeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fIndeterminate
)
3681 TBUTTON_INFO
*btnPtr
;
3685 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3689 btnPtr
= &infoPtr
->buttons
[nIndex
];
3690 oldState
= btnPtr
->fsState
;
3693 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3695 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3697 if(oldState
!= btnPtr
->fsState
)
3698 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3705 TOOLBAR_InsertButtonT(TOOLBAR_INFO
*infoPtr
, INT nIndex
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
3711 /* EPP: this seems to be an undocumented call (from my IE4)
3712 * I assume in that case that:
3713 * - index of insertion is at the end of existing buttons
3714 * I only see this happen with nIndex == -1, but it could have a special
3715 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3717 nIndex
= infoPtr
->nNumButtons
;
3719 } else if (nIndex
< 0)
3722 TRACE("inserting button index=%d\n", nIndex
);
3723 if (nIndex
> infoPtr
->nNumButtons
) {
3724 nIndex
= infoPtr
->nNumButtons
;
3725 TRACE("adjust index=%d\n", nIndex
);
3728 return TOOLBAR_InternalInsertButtonsT(infoPtr
, nIndex
, 1, lpTbb
, fUnicode
);
3731 /* << TOOLBAR_InsertMarkHitTest >> */
3735 TOOLBAR_IsButtonChecked (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3739 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3743 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3748 TOOLBAR_IsButtonEnabled (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3752 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3756 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3761 TOOLBAR_IsButtonHidden (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3765 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3769 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3774 TOOLBAR_IsButtonHighlighted (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3778 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3782 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3787 TOOLBAR_IsButtonIndeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3791 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3795 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3800 TOOLBAR_IsButtonPressed (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3804 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3808 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3813 TOOLBAR_LoadImages (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HINSTANCE hInstance
)
3816 tbab
.hInst
= hInstance
;
3819 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", infoPtr
->hwndSelf
, tbab
.hInst
, tbab
.nID
);
3821 return TOOLBAR_AddBitmap(infoPtr
, 0, &tbab
);
3826 TOOLBAR_MapAccelerator (const TOOLBAR_INFO
*infoPtr
, WCHAR wAccel
, UINT
*pIDButton
)
3828 WCHAR wszAccel
[] = {'&',wAccel
,0};
3831 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3832 infoPtr
->hwndSelf
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3834 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3836 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3837 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3838 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3840 int iLen
= strlenW(wszAccel
);
3841 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3848 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3853 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
3855 *pIDButton
= btnPtr
->idCommand
;
3867 TOOLBAR_MarkButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fMark
)
3871 TBUTTON_INFO
*btnPtr
;
3873 TRACE("hwnd = %p, Id = %d, fMark = 0%d\n", infoPtr
->hwndSelf
, Id
, fMark
);
3875 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3879 btnPtr
= &infoPtr
->buttons
[nIndex
];
3880 oldState
= btnPtr
->fsState
;
3883 btnPtr
->fsState
|= TBSTATE_MARKED
;
3885 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
3887 if(oldState
!= btnPtr
->fsState
)
3888 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3894 /* fixes up an index of a button affected by a move */
3895 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
3899 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
3901 else if (*pIndex
== nIndex
)
3902 *pIndex
= nMoveIndex
;
3906 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
3908 else if (*pIndex
== nIndex
)
3909 *pIndex
= nMoveIndex
;
3915 TOOLBAR_MoveButton (TOOLBAR_INFO
*infoPtr
, INT Id
, INT nMoveIndex
)
3919 TBUTTON_INFO button
;
3921 TRACE("hwnd=%p, Id=%d, nMoveIndex=%d\n", infoPtr
->hwndSelf
, Id
, nMoveIndex
);
3923 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, TRUE
);
3924 if ((nIndex
== -1) || (nMoveIndex
< 0))
3927 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
3928 nMoveIndex
= infoPtr
->nNumButtons
- 1;
3930 button
= infoPtr
->buttons
[nIndex
];
3932 /* move button right */
3933 if (nIndex
< nMoveIndex
)
3935 nCount
= nMoveIndex
- nIndex
;
3936 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
3937 infoPtr
->buttons
[nMoveIndex
] = button
;
3939 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
3940 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
3941 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
3942 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
3944 else if (nIndex
> nMoveIndex
) /* move button left */
3946 nCount
= nIndex
- nMoveIndex
;
3947 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
3948 infoPtr
->buttons
[nMoveIndex
] = button
;
3950 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
3951 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
3952 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
3953 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
3956 TOOLBAR_LayoutToolbar(infoPtr
);
3957 TOOLBAR_AutoSize(infoPtr
);
3958 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
3965 TOOLBAR_PressButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fPress
)
3967 TBUTTON_INFO
*btnPtr
;
3971 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3975 btnPtr
= &infoPtr
->buttons
[nIndex
];
3976 oldState
= btnPtr
->fsState
;
3979 btnPtr
->fsState
|= TBSTATE_PRESSED
;
3981 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
3983 if(oldState
!= btnPtr
->fsState
)
3984 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3989 /* FIXME: there might still be some confusion her between number of buttons
3990 * and number of bitmaps */
3992 TOOLBAR_ReplaceBitmap (TOOLBAR_INFO
*infoPtr
, const TBREPLACEBITMAP
*lpReplace
)
3995 int i
= 0, nOldButtons
= 0, pos
= 0;
3996 int nOldBitmaps
, nNewBitmaps
= 0;
3997 HIMAGELIST himlDef
= 0;
3999 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4000 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
4001 lpReplace
->nButtons
);
4003 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4005 FIXME("changing standard bitmaps not implemented\n");
4008 else if (lpReplace
->hInstOld
!= 0 && lpReplace
->hInstOld
!= lpReplace
->hInstNew
)
4009 FIXME("resources not in the current module not implemented\n");
4011 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4012 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4013 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4014 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4015 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4017 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4018 nOldButtons
= tbi
->nButtons
;
4019 tbi
->nButtons
= lpReplace
->nButtons
;
4020 tbi
->hInst
= lpReplace
->hInstNew
;
4021 tbi
->nID
= lpReplace
->nIDNew
;
4022 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4025 pos
+= tbi
->nButtons
;
4028 if (nOldButtons
== 0)
4030 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4034 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4037 if (lpReplace
->hInstNew
)
4038 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4040 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4042 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4043 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4045 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4047 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4048 ImageList_Remove(himlDef
, i
);
4052 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4053 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4054 DeleteObject(hBitmap
);
4057 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4059 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4060 pos
, nOldBitmaps
, nNewBitmaps
);
4062 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4067 /* helper for TOOLBAR_SaveRestoreW */
4069 TOOLBAR_Save(const TBSAVEPARAMSW
*lpSave
)
4071 FIXME("save to %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4072 debugstr_w(lpSave
->pszValueName
));
4078 /* helper for TOOLBAR_Restore */
4080 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4084 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4086 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4089 Free(infoPtr
->buttons
);
4090 infoPtr
->buttons
= NULL
;
4091 infoPtr
->nNumButtons
= 0;
4095 /* helper for TOOLBAR_SaveRestoreW */
4097 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4106 /* restore toolbar information */
4107 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4108 debugstr_w(lpSave
->pszValueName
));
4110 memset(&nmtbr
, 0, sizeof(nmtbr
));
4112 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4113 KEY_QUERY_VALUE
, &hkey
);
4115 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4117 if (!res
&& dwType
!= REG_BINARY
)
4118 res
= ERROR_FILE_NOT_FOUND
;
4121 nmtbr
.pData
= Alloc(dwSize
);
4122 nmtbr
.cbData
= dwSize
;
4123 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4126 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4127 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4130 nmtbr
.pCurrent
= nmtbr
.pData
;
4132 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4133 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4135 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4139 /* remove all existing buttons as this function is designed to
4140 * restore the toolbar to a previously saved state */
4141 TOOLBAR_DeleteAllButtons(infoPtr
);
4143 for (i
= 0; i
< nmtbr
.cButtons
; i
++)
4146 nmtbr
.tbButton
.iBitmap
= -1;
4147 nmtbr
.tbButton
.fsState
= 0;
4148 nmtbr
.tbButton
.fsStyle
= 0;
4149 nmtbr
.tbButton
.idCommand
= 0;
4150 if (*nmtbr
.pCurrent
== (DWORD
)-1)
4153 nmtbr
.tbButton
.fsStyle
= TBSTYLE_SEP
;
4154 /* when inserting separators, iBitmap controls it's size.
4155 0 sets default size (width) */
4156 nmtbr
.tbButton
.iBitmap
= 0;
4158 else if (*nmtbr
.pCurrent
== (DWORD
)-2)
4160 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4162 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4166 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4168 /* can't contain real string as we don't know whether
4169 * the client put an ANSI or Unicode string in there */
4170 if (!IS_INTRESOURCE(nmtbr
.tbButton
.iString
))
4171 nmtbr
.tbButton
.iString
= 0;
4173 TOOLBAR_InsertButtonT(infoPtr
, -1, &nmtbr
.tbButton
, TRUE
);
4176 /* do legacy notifications */
4177 if (infoPtr
->iVersion
< 5)
4179 /* FIXME: send TBN_BEGINADJUST */
4180 FIXME("send TBN_GETBUTTONINFO for each button\n");
4181 /* FIXME: send TBN_ENDADJUST */
4184 /* remove all uninitialised buttons
4185 * note: loop backwards to avoid having to fixup i on a
4187 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4188 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4189 TOOLBAR_DeleteButton(infoPtr
, i
);
4191 /* only indicate success if at least one button survived */
4192 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4203 TOOLBAR_SaveRestoreW (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4205 if (lpSave
== NULL
) return 0;
4208 return TOOLBAR_Save(lpSave
);
4210 return TOOLBAR_Restore(infoPtr
, lpSave
);
4215 TOOLBAR_SaveRestoreA (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4217 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4218 TBSAVEPARAMSW SaveW
;
4222 if (lpSave
== NULL
) return 0;
4224 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4225 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4226 if (pszSubKey
) goto exit
;
4227 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4229 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4230 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4231 if (!pszValueName
) goto exit
;
4232 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4234 SaveW
.pszValueName
= pszValueName
;
4235 SaveW
.pszSubKey
= pszSubKey
;
4236 SaveW
.hkr
= lpSave
->hkr
;
4237 result
= TOOLBAR_SaveRestoreW(infoPtr
, wParam
, &SaveW
);
4240 Free (pszValueName
);
4248 TOOLBAR_SetAnchorHighlight (TOOLBAR_INFO
*infoPtr
, BOOL bAnchor
)
4250 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4252 TRACE("hwnd=%p, bAnchor = %s\n", infoPtr
->hwndSelf
, bAnchor
? "TRUE" : "FALSE");
4254 infoPtr
->bAnchor
= bAnchor
;
4256 /* Native does not remove the hot effect from an already hot button */
4258 return (LRESULT
)bOldAnchor
;
4263 TOOLBAR_SetBitmapSize (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4265 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4266 short width
= (short)LOWORD(lParam
);
4267 short height
= (short)HIWORD(lParam
);
4269 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", infoPtr
->hwndSelf
, wParam
, lParam
);
4272 FIXME("wParam is %ld. Perhaps image list index?\n", wParam
);
4274 /* 0 width or height is changed to 1 */
4280 if (infoPtr
->nNumButtons
> 0)
4281 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4282 infoPtr
->nNumButtons
,
4283 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
, width
, height
);
4285 if (width
< -1 || height
< -1)
4287 /* Windows destroys the imagelist and seems to actually use negative
4288 * values to compute button sizes */
4289 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width
, height
);
4293 /* width or height of -1 means no change */
4295 infoPtr
->nBitmapWidth
= width
;
4297 infoPtr
->nBitmapHeight
= height
;
4299 if ((himlDef
== infoPtr
->himlInt
) &&
4300 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4302 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4303 infoPtr
->nBitmapHeight
);
4306 TOOLBAR_CalcToolbar(infoPtr
);
4307 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4313 TOOLBAR_SetButtonInfo (TOOLBAR_INFO
*infoPtr
, INT Id
,
4314 const TBBUTTONINFOW
*lptbbi
, BOOL isW
)
4316 TBUTTON_INFO
*btnPtr
;
4322 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4325 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lptbbi
->dwMask
& TBIF_BYINDEX
);
4329 btnPtr
= &infoPtr
->buttons
[nIndex
];
4330 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4331 btnPtr
->idCommand
= lptbbi
->idCommand
;
4332 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4333 btnPtr
->iBitmap
= lptbbi
->iImage
;
4334 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4335 btnPtr
->dwData
= lptbbi
->lParam
;
4336 if (lptbbi
->dwMask
& TBIF_SIZE
)
4337 btnPtr
->cx
= lptbbi
->cx
;
4338 if (lptbbi
->dwMask
& TBIF_STATE
)
4339 btnPtr
->fsState
= lptbbi
->fsState
;
4340 if (lptbbi
->dwMask
& TBIF_STYLE
)
4341 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4343 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4344 /* iString is index, zero it to make Str_SetPtr succeed */
4345 if (!TOOLBAR_ButtonHasString(btnPtr
)) btnPtr
->iString
= 0;
4348 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4350 Str_SetPtrAtoW ((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lptbbi
->pszText
);
4353 /* save the button rect to see if we need to redraw the whole toolbar */
4354 oldBtnRect
= btnPtr
->rect
;
4355 TOOLBAR_LayoutToolbar(infoPtr
);
4357 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4358 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4360 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4367 TOOLBAR_SetButtonSize (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4369 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4371 if ((cx
< 0) || (cy
< 0))
4373 ERR("invalid parameter 0x%08x\n", (DWORD
)lParam
);
4377 TRACE("%p, cx = %d, cy = %d\n", infoPtr
->hwndSelf
, cx
, cy
);
4379 /* The documentation claims you can only change the button size before
4380 * any button has been added. But this is wrong.
4381 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4382 * it to the toolbar, and it checks that the return value is nonzero - mjm
4383 * Further testing shows that we must actually perform the change too.
4386 * The documentation also does not mention that if 0 is supplied for
4387 * either size, the system changes it to the default of 24 wide and
4388 * 22 high. Demonstrated in ControlSpy Toolbar. GLA 3/02
4390 if (cx
== 0) cx
= 24;
4391 if (cy
== 0) cy
= 22;
4393 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4394 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4396 infoPtr
->nButtonWidth
= cx
;
4397 infoPtr
->nButtonHeight
= cy
;
4399 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
4400 TOOLBAR_LayoutToolbar(infoPtr
);
4406 TOOLBAR_SetButtonWidth (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4408 /* if setting to current values, ignore */
4409 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4410 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4411 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4412 infoPtr
->cxMin
, infoPtr
->cxMax
);
4416 /* save new values */
4417 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4418 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4420 /* otherwise we need to recalc the toolbar and in some cases
4421 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4422 which doesn't actually draw - GA). */
4423 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4424 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4426 TOOLBAR_CalcToolbar (infoPtr
);
4428 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
4435 TOOLBAR_SetCmdId (TOOLBAR_INFO
*infoPtr
, INT nIndex
, INT nId
)
4437 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4440 infoPtr
->buttons
[nIndex
].idCommand
= nId
;
4442 if (infoPtr
->hwndToolTip
) {
4444 FIXME("change tool tip!\n");
4453 TOOLBAR_SetDisabledImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4455 HIMAGELIST himlTemp
;
4458 if (infoPtr
->iVersion
>= 5)
4461 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4462 &infoPtr
->cimlDis
, himl
, id
);
4464 /* FIXME: redraw ? */
4466 return (LRESULT
)himlTemp
;
4471 TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4475 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", infoPtr
->hwndSelf
, (DWORD
)wParam
, (DWORD
)lParam
);
4477 dwTemp
= infoPtr
->dwDTFlags
;
4478 infoPtr
->dwDTFlags
=
4479 (infoPtr
->dwDTFlags
& (DWORD
)wParam
) | (DWORD
)lParam
;
4481 return (LRESULT
)dwTemp
;
4484 /* This function differs a bit from what MSDN says it does:
4485 * 1. lParam contains extended style flags to OR with current style
4486 * (MSDN isn't clear on the OR bit)
4487 * 2. wParam appears to contain extended style flags to be reset
4488 * (MSDN says that this parameter is reserved)
4491 TOOLBAR_SetExtendedStyle (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD style
)
4493 DWORD old_style
= infoPtr
->dwExStyle
;
4495 TRACE("mask=0x%08x, style=0x%08x\n", mask
, style
);
4498 infoPtr
->dwExStyle
= (old_style
& ~mask
) | (style
& mask
);
4500 infoPtr
->dwExStyle
= style
;
4502 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4503 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4504 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4506 if ((old_style
^ infoPtr
->dwExStyle
) & TBSTYLE_EX_MIXEDBUTTONS
)
4507 TOOLBAR_CalcToolbar(infoPtr
);
4509 TOOLBAR_LayoutToolbar(infoPtr
);
4511 TOOLBAR_AutoSize(infoPtr
);
4512 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4519 TOOLBAR_SetHotImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4521 HIMAGELIST himlTemp
;
4524 if (infoPtr
->iVersion
>= 5)
4527 TRACE("hwnd = %p, himl = %p, id = %d\n", infoPtr
->hwndSelf
, himl
, id
);
4529 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4530 &infoPtr
->cimlHot
, himl
, id
);
4532 /* FIXME: redraw ? */
4534 return (LRESULT
)himlTemp
;
4538 /* Makes previous hot button no longer hot, makes the specified
4539 * button hot and sends appropriate notifications. dwReason is one or
4540 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4541 * NOTE 1: this function does not validate nHit
4542 * NOTE 2: the name of this function is completely made up and
4543 * not based on any documentation from Microsoft. */
4545 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4547 if (infoPtr
->nHotItem
!= nHit
)
4549 NMTBHOTITEM nmhotitem
;
4550 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4552 nmhotitem
.dwFlags
= dwReason
;
4553 if(infoPtr
->nHotItem
>= 0)
4555 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4556 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4560 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4561 nmhotitem
.idOld
= 0;
4566 btnPtr
= &infoPtr
->buttons
[nHit
];
4567 nmhotitem
.idNew
= btnPtr
->idCommand
;
4571 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4572 nmhotitem
.idNew
= 0;
4575 /* now change the hot and invalidate the old and new buttons - if the
4577 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4580 oldBtnPtr
->bHot
= FALSE
;
4581 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4583 /* setting disabled buttons as hot fails even if the notify contains the button id */
4584 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4585 btnPtr
->bHot
= TRUE
;
4586 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4587 infoPtr
->nHotItem
= nHit
;
4590 infoPtr
->nHotItem
= -1;
4596 TOOLBAR_SetHotItem (TOOLBAR_INFO
*infoPtr
, INT nHotItem
)
4598 INT nOldHotItem
= infoPtr
->nHotItem
;
4600 TRACE("hwnd = %p, nHotItem = %d\n", infoPtr
->hwndSelf
, nHotItem
);
4602 if (nHotItem
>= infoPtr
->nNumButtons
)
4603 return infoPtr
->nHotItem
;
4608 /* NOTE: an application can still remove the hot item even if anchor
4609 * highlighting is enabled */
4611 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, HICF_OTHER
);
4613 if (nOldHotItem
< 0)
4616 return (LRESULT
)nOldHotItem
;
4621 TOOLBAR_SetImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4623 HIMAGELIST himlTemp
;
4624 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4625 INT oldBitmapWidth
= infoPtr
->nBitmapWidth
;
4626 INT oldBitmapHeight
= infoPtr
->nBitmapHeight
;
4629 if (infoPtr
->iVersion
>= 5)
4632 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4633 &infoPtr
->cimlDef
, himl
, id
);
4635 infoPtr
->nNumBitmaps
= 0;
4636 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4637 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4639 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4640 &infoPtr
->nBitmapHeight
))
4642 infoPtr
->nBitmapWidth
= 1;
4643 infoPtr
->nBitmapHeight
= 1;
4645 if ((oldBitmapWidth
!= infoPtr
->nBitmapWidth
) || (oldBitmapHeight
!= infoPtr
->nBitmapHeight
))
4647 TOOLBAR_CalcToolbar(infoPtr
);
4648 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4649 TOOLBAR_SetButtonSize(infoPtr
, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4652 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4653 infoPtr
->hwndSelf
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4654 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4656 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4658 return (LRESULT
)himlTemp
;
4663 TOOLBAR_SetIndent (TOOLBAR_INFO
*infoPtr
, INT nIndent
)
4665 infoPtr
->nIndent
= nIndent
;
4669 /* process only on indent changing */
4670 if(infoPtr
->nIndent
!= nIndent
)
4672 infoPtr
->nIndent
= nIndent
;
4673 TOOLBAR_CalcToolbar (infoPtr
);
4674 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4682 TOOLBAR_SetInsertMark (TOOLBAR_INFO
*infoPtr
, const TBINSERTMARK
*lptbim
)
4684 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", infoPtr
->hwndSelf
, lptbim
->iButton
, lptbim
->dwFlags
);
4686 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4688 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4692 if ((lptbim
->iButton
== -1) ||
4693 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4694 (lptbim
->iButton
>= 0)))
4696 infoPtr
->tbim
= *lptbim
;
4697 /* FIXME: don't need to update entire toolbar */
4698 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4701 ERR("Invalid button index %d\n", lptbim
->iButton
);
4708 TOOLBAR_SetInsertMarkColor (TOOLBAR_INFO
*infoPtr
, COLORREF clr
)
4710 infoPtr
->clrInsertMark
= clr
;
4712 /* FIXME: don't need to update entire toolbar */
4713 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4720 TOOLBAR_SetMaxTextRows (TOOLBAR_INFO
*infoPtr
, INT nMaxRows
)
4722 infoPtr
->nMaxTextRows
= nMaxRows
;
4724 TOOLBAR_CalcToolbar(infoPtr
);
4729 /* MSDN gives slightly wrong info on padding.
4730 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4731 * 2. It is not used to create a blank area between the edge of the button
4732 * and the text or image if TBSTYLE_LIST is set. It is used to control
4733 * the gap between the image and text.
4734 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4735 * to control the bottom and right borders [with the border being
4736 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4737 * is shared evenly on both sides of the button.
4738 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4741 TOOLBAR_SetPadding (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4745 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4746 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4747 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4748 TRACE("cx=%d, cy=%d\n",
4749 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4750 return (LRESULT
) oldPad
;
4755 TOOLBAR_SetParent (TOOLBAR_INFO
*infoPtr
, HWND hParent
)
4761 hwndOldNotify
= infoPtr
->hwndNotify
;
4762 infoPtr
->hwndNotify
= hParent
;
4764 return (LRESULT
)hwndOldNotify
;
4769 TOOLBAR_SetRows (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPRECT lprc
)
4771 int rows
= LOWORD(wParam
);
4772 BOOL bLarger
= HIWORD(wParam
);
4776 TRACE("Setting rows to %d (%d)\n", rows
, bLarger
);
4778 if(infoPtr
->nRows
!= rows
)
4780 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
;
4781 int curColumn
= 0; /* Current column */
4782 int curRow
= 0; /* Current row */
4783 int hidden
= 0; /* Number of hidden buttons */
4784 int seps
= 0; /* Number of separators */
4785 int idealWrap
= 0; /* Ideal wrap point */
4790 Calculate new size and wrap points - Under windows, setrows will
4791 change the dimensions if needed to show the number of requested
4792 rows (if CCS_NORESIZE is set), or will take up the whole window
4793 (if no CCS_NORESIZE).
4795 Basic algorithm - If N buttons, and y rows requested, each row
4796 contains N/y buttons.
4798 FIXME: Handling of separators not obvious from testing results
4799 FIXME: Take width of window into account?
4802 /* Loop through the buttons one by one counting key items */
4803 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4805 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
4806 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4808 else if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
4812 /* FIXME: Separators make this quite complex */
4813 if (seps
) FIXME("Separators unhandled\n");
4815 /* Round up so more per line, i.e., less rows */
4816 idealWrap
= (infoPtr
->nNumButtons
- hidden
+ (rows
-1)) / (rows
? rows
: 1);
4818 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4819 achieve the requested number of rows. */
4820 if (bLarger
&& idealWrap
> 1)
4822 int resRows
= (infoPtr
->nNumButtons
+ (idealWrap
-1)) / idealWrap
;
4823 int moreRows
= (infoPtr
->nNumButtons
+ (idealWrap
-2)) / (idealWrap
-1);
4825 if (resRows
< rows
&& moreRows
> rows
)
4828 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap
);
4832 curColumn
= curRow
= 0;
4834 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap
,
4835 infoPtr
->nNumButtons
, hidden
, rows
);
4837 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4839 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4842 /* Step on, wrap if necessary or flag next to wrap */
4851 if (curColumn
> (idealWrap
-1)) {
4853 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
4857 TRACE("Result - %d rows\n", curRow
+ 1);
4859 /* recalculate toolbar */
4860 TOOLBAR_CalcToolbar (infoPtr
);
4862 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
4863 if NORESIZE is NOT set, then the toolbar will always be resized to
4864 take up the whole window. With it set, sizing needs to be manual. */
4865 if (infoPtr
->dwStyle
& CCS_NORESIZE
) {
4866 SetWindowPos(infoPtr
->hwndSelf
, NULL
, 0, 0,
4867 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
4868 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
,
4869 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
4872 /* repaint toolbar */
4873 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4876 /* return bounding rectangle */
4878 lprc
->left
= infoPtr
->rcBound
.left
;
4879 lprc
->right
= infoPtr
->rcBound
.right
;
4880 lprc
->top
= infoPtr
->rcBound
.top
;
4881 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
4889 TOOLBAR_SetState (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
4891 TBUTTON_INFO
*btnPtr
;
4894 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
4898 btnPtr
= &infoPtr
->buttons
[nIndex
];
4900 /* if hidden state has changed the invalidate entire window and recalc */
4901 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
4902 btnPtr
->fsState
= LOWORD(lParam
);
4903 TOOLBAR_CalcToolbar (infoPtr
);
4904 InvalidateRect(infoPtr
->hwndSelf
, 0, TRUE
);
4908 /* process state changing if current state doesn't match new state */
4909 if(btnPtr
->fsState
!= LOWORD(lParam
))
4911 btnPtr
->fsState
= LOWORD(lParam
);
4912 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4920 TOOLBAR_SetStyle (TOOLBAR_INFO
*infoPtr
, DWORD style
)
4922 infoPtr
->dwStyle
= style
;
4927 static inline LRESULT
4928 TOOLBAR_SetToolTips (TOOLBAR_INFO
*infoPtr
, HWND hwndTooltip
)
4930 TRACE("hwnd=%p, hwndTooltip=%p\n", infoPtr
->hwndSelf
, hwndTooltip
);
4932 infoPtr
->hwndToolTip
= hwndTooltip
;
4938 TOOLBAR_SetUnicodeFormat (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
4942 TRACE("%s hwnd=%p\n",
4943 ((BOOL
)wParam
) ? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
4945 bTemp
= infoPtr
->bUnicode
;
4946 infoPtr
->bUnicode
= (BOOL
)wParam
;
4953 TOOLBAR_GetColorScheme (const TOOLBAR_INFO
*infoPtr
, LPCOLORSCHEME lParam
)
4955 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
4956 comctl32_color
.clrBtnHighlight
:
4957 infoPtr
->clrBtnHighlight
;
4958 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
4959 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
4965 TOOLBAR_SetColorScheme (TOOLBAR_INFO
*infoPtr
, const COLORSCHEME
*lParam
)
4967 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
4968 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
4969 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
4971 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
4972 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
4973 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4979 TOOLBAR_SetVersion (TOOLBAR_INFO
*infoPtr
, INT iVersion
)
4981 INT iOldVersion
= infoPtr
->iVersion
;
4983 infoPtr
->iVersion
= iVersion
;
4985 if (infoPtr
->iVersion
>= 5)
4986 TOOLBAR_SetUnicodeFormat(infoPtr
, TRUE
);
4993 TOOLBAR_GetStringA (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPSTR str
)
4995 WORD iString
= HIWORD(wParam
);
4996 WORD buffersize
= LOWORD(wParam
);
4999 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, buffersize
, str
);
5001 if (iString
< infoPtr
->nNumStrings
)
5003 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
5006 TRACE("returning %s\n", debugstr_a(str
));
5009 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5016 TOOLBAR_GetStringW (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPWSTR str
)
5018 WORD iString
= HIWORD(wParam
);
5019 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5022 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, LOWORD(wParam
), str
);
5024 if (iString
< infoPtr
->nNumStrings
)
5026 len
= min(len
, strlenW(infoPtr
->strings
[iString
]));
5027 ret
= (len
+1)*sizeof(WCHAR
);
5030 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5035 TRACE("returning %s\n", debugstr_w(str
));
5038 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5043 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5044 * is the maximum size of the toolbar? */
5045 static LRESULT
TOOLBAR_Unkwn45D(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5047 SIZE
* pSize
= (SIZE
*)lParam
;
5048 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5053 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5054 * caller to specify a reason why the hot item changed (rather than just the
5055 * HICF_OTHER that TB_SETHOTITEM sends). */
5057 TOOLBAR_SetHotItem2 (TOOLBAR_INFO
*infoPtr
, INT nHotItem
, LPARAM lParam
)
5059 INT nOldHotItem
= infoPtr
->nHotItem
;
5061 TRACE("old item=%d, new item=%d, flags=%08x\n",
5062 nOldHotItem
, nHotItem
, (DWORD
)lParam
);
5064 if (nHotItem
< 0 || nHotItem
> infoPtr
->nNumButtons
)
5067 /* NOTE: an application can still remove the hot item even if anchor
5068 * highlighting is enabled */
5070 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, lParam
);
5074 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5077 /* Sets the toolbar global iListGap parameter which controls the amount of
5078 * spacing between the image and the text of buttons for TBSTYLE_LIST
5080 static LRESULT
TOOLBAR_SetListGap(TOOLBAR_INFO
*infoPtr
, INT iListGap
)
5082 TRACE("hwnd=%p iListGap=%d\n", infoPtr
->hwndSelf
, iListGap
);
5084 infoPtr
->iListGap
= iListGap
;
5086 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5091 /* Returns the number of maximum number of image lists associated with the
5092 * various states. */
5093 static LRESULT
TOOLBAR_GetImageListCount(const TOOLBAR_INFO
*infoPtr
)
5095 TRACE("hwnd=%p\n", infoPtr
->hwndSelf
);
5097 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5101 TOOLBAR_GetIdealSize (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5103 LPSIZE lpsize
= (LPSIZE
)lParam
;
5109 * Testing shows the following:
5110 * wParam = 0 adjust cx value
5111 * = 1 set cy value to max size.
5112 * lParam pointer to SIZE structure
5115 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5116 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5120 if (lpsize
->cx
== -1) {
5121 /* **** this is wrong, native measures each button and sets it */
5122 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5124 else if(HIWORD(lpsize
->cx
)) {
5126 HWND hwndParent
= GetParent(infoPtr
->hwndSelf
);
5128 GetWindowRect(infoPtr
->hwndSelf
, &rc
);
5129 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5130 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc
));
5131 lpsize
->cx
= max(rc
.right
-rc
.left
,
5132 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5135 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5139 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5142 FIXME("Unknown wParam %ld\n", wParam
);
5145 TRACE("set to -> 0x%08x 0x%08x\n",
5146 lpsize
->cx
, lpsize
->cy
);
5150 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5152 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5154 InvalidateRect(hwnd
, NULL
, TRUE
);
5160 TOOLBAR_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
5162 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
5165 TRACE("hwnd = %p, style=0x%08x\n", hwnd
, lpcs
->style
);
5167 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5168 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5169 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5170 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_REQUERY
));
5171 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5173 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5174 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5176 OpenThemeData (hwnd
, themeClass
);
5178 TOOLBAR_CheckStyle (infoPtr
);
5185 TOOLBAR_Destroy (TOOLBAR_INFO
*infoPtr
)
5189 /* delete tooltip control */
5190 if (infoPtr
->hwndToolTip
)
5191 DestroyWindow (infoPtr
->hwndToolTip
);
5193 /* delete temporary buffer for tooltip text */
5194 Free (infoPtr
->pszTooltipText
);
5195 Free (infoPtr
->bitmaps
); /* bitmaps list */
5197 /* delete button data */
5198 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5199 if (TOOLBAR_ButtonHasString(&infoPtr
->buttons
[i
]))
5200 Free ((LPWSTR
)infoPtr
->buttons
[i
].iString
);
5201 Free (infoPtr
->buttons
);
5203 /* delete strings */
5204 if (infoPtr
->strings
) {
5205 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5206 Free (infoPtr
->strings
[i
]);
5208 Free (infoPtr
->strings
);
5211 /* destroy internal image list */
5212 if (infoPtr
->himlInt
)
5213 ImageList_Destroy (infoPtr
->himlInt
);
5215 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5216 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5217 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5219 /* delete default font */
5220 DeleteObject (infoPtr
->hDefaultFont
);
5222 CloseThemeData (GetWindowTheme (infoPtr
->hwndSelf
));
5224 /* free toolbar info data */
5225 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
5233 TOOLBAR_EraseBackground (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5235 NMTBCUSTOMDRAW tbcd
;
5238 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
5239 DWORD dwEraseCustDraw
= 0;
5241 /* the app has told us not to redraw the toolbar */
5242 if (!infoPtr
->bDoRedraw
)
5245 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5246 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5247 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5248 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5249 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5250 dwEraseCustDraw
= ntfret
& 0xffff;
5252 /* FIXME: in general the return flags *can* be or'ed together */
5253 switch (dwEraseCustDraw
)
5255 case CDRF_DODEFAULT
:
5257 case CDRF_SKIPDEFAULT
:
5260 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5261 infoPtr
->hwndSelf
, ntfret
);
5265 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5266 * to my parent for processing.
5268 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5270 HDC hdc
= (HDC
)wParam
;
5275 parent
= GetParent(infoPtr
->hwndSelf
);
5276 MapWindowPoints(infoPtr
->hwndSelf
, parent
, &pt
, 1);
5277 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5278 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5279 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5282 ret
= DefWindowProcW (infoPtr
->hwndSelf
, WM_ERASEBKGND
, wParam
, lParam
);
5284 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5285 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5286 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5287 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5288 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5289 dwEraseCustDraw
= ntfret
& 0xffff;
5290 switch (dwEraseCustDraw
)
5292 case CDRF_DODEFAULT
:
5294 case CDRF_SKIPDEFAULT
:
5297 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5298 infoPtr
->hwndSelf
, ntfret
);
5305 static inline LRESULT
5306 TOOLBAR_GetFont (const TOOLBAR_INFO
*infoPtr
)
5308 return (LRESULT
)infoPtr
->hFont
;
5313 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5316 INT nNewHotItem
= infoPtr
->nHotItem
;
5318 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5321 if ((nNewHotItem
+ iDirection
< 0) ||
5322 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5324 NMTBWRAPHOTITEM nmtbwhi
;
5325 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5326 nmtbwhi
.iDirection
= iDirection
;
5327 nmtbwhi
.dwReason
= dwReason
;
5329 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5333 nNewHotItem
+= iDirection
;
5334 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5336 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5337 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5339 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5346 TOOLBAR_KeyDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5350 nmkey
.nVKey
= (UINT
)wParam
;
5351 nmkey
.uFlags
= HIWORD(lParam
);
5353 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5354 return DefWindowProcW(infoPtr
->hwndSelf
, WM_KEYDOWN
, wParam
, lParam
);
5356 switch ((UINT
)wParam
)
5360 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5364 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5368 if ((infoPtr
->nHotItem
>= 0) &&
5369 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5371 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5372 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5373 (LPARAM
)infoPtr
->hwndSelf
);
5383 TOOLBAR_LButtonDblClk (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5388 pt
.x
= (short)LOWORD(lParam
);
5389 pt
.y
= (short)HIWORD(lParam
);
5390 TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5393 TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
5394 else if (infoPtr
->dwStyle
& CCS_ADJUSTABLE
)
5395 TOOLBAR_Customize (infoPtr
);
5402 TOOLBAR_LButtonDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5404 TBUTTON_INFO
*btnPtr
;
5409 BOOL bDragKeyPressed
;
5414 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5415 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5417 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5419 if (infoPtr
->hwndToolTip
)
5420 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5421 WM_LBUTTONDOWN
, wParam
, lParam
);
5423 pt
.x
= (short)LOWORD(lParam
);
5424 pt
.y
= (short)HIWORD(lParam
);
5425 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5428 btnPtr
= &infoPtr
->buttons
[nHit
];
5430 if (button
&& bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5432 infoPtr
->nButtonDrag
= nHit
;
5433 SetCapture (infoPtr
->hwndSelf
);
5435 /* If drag cursor has not been loaded, load it.
5436 * Note: it doesn't need to be freed */
5438 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5439 SetCursor(hCursorDrag
);
5444 infoPtr
->nOldHit
= nHit
;
5446 CopyRect(&arrowRect
, &btnPtr
->rect
);
5447 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5449 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5450 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5451 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5452 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5453 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5454 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5458 /* draw in pressed state */
5459 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5460 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5462 btnPtr
->bDropDownPressed
= TRUE
;
5463 RedrawWindow(infoPtr
->hwndSelf
,&btnPtr
->rect
,0,
5464 RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5466 memset(&nmtb
, 0, sizeof(nmtb
));
5467 nmtb
.iItem
= btnPtr
->idCommand
;
5468 nmtb
.rcButton
= btnPtr
->rect
;
5469 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5471 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5473 if (res
!= TBDDRET_TREATPRESSED
)
5477 /* redraw button in unpressed state */
5478 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5479 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5481 btnPtr
->bDropDownPressed
= FALSE
;
5482 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5484 /* find and set hot item
5485 * NOTE: native doesn't do this, but that is a bug */
5487 ScreenToClient(infoPtr
->hwndSelf
, &pt
);
5488 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5489 if (!infoPtr
->bAnchor
|| button
)
5490 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5492 /* remove any left mouse button down or double-click messages
5493 * so that we can get a toggle effect on the button */
5494 while (PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5495 PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5500 /* otherwise drop through and process as pushed */
5502 infoPtr
->bCaptured
= TRUE
;
5503 infoPtr
->nButtonDown
= nHit
;
5504 infoPtr
->bDragOutSent
= FALSE
;
5506 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5508 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5510 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5511 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5512 UpdateWindow(infoPtr
->hwndSelf
);
5513 SetCapture (infoPtr
->hwndSelf
);
5518 memset(&nmtb
, 0, sizeof(nmtb
));
5519 nmtb
.iItem
= btnPtr
->idCommand
;
5520 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5523 nmmouse
.dwHitInfo
= nHit
;
5525 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5527 nmmouse
.dwItemSpec
= -1;
5530 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5531 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5534 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5537 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5538 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, wParam
, lParam
);
5544 TOOLBAR_LButtonUp (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5546 TBUTTON_INFO
*btnPtr
;
5555 if (infoPtr
->hwndToolTip
)
5556 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5557 WM_LBUTTONUP
, wParam
, lParam
);
5559 pt
.x
= (short)LOWORD(lParam
);
5560 pt
.y
= (short)HIWORD(lParam
);
5561 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5563 if (!infoPtr
->bAnchor
|| button
)
5564 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5566 if (infoPtr
->nButtonDrag
>= 0) {
5570 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5573 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5575 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5576 if (PtInRect(&rcClient
, pt
))
5583 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5586 if (nButton
== infoPtr
->nButtonDrag
)
5588 /* if the button is moved sightly left and we have a
5589 * separator there then remove it */
5590 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5592 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5593 TOOLBAR_DeleteButton(infoPtr
, nButton
- 1);
5595 else /* else insert a separator before the dragged button */
5598 memset(&tbb
, 0, sizeof(tbb
));
5599 tbb
.fsStyle
= BTNS_SEP
;
5601 TOOLBAR_InsertButtonT(infoPtr
, nButton
, &tbb
, TRUE
);
5608 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5609 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, 0);
5611 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5614 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, nButton
);
5619 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5620 TOOLBAR_DeleteButton(infoPtr
, infoPtr
->nButtonDrag
);
5623 /* button under cursor changed so need to re-set hot item */
5624 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5625 infoPtr
->nButtonDrag
= -1;
5627 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5629 else if (infoPtr
->nButtonDown
>= 0) {
5630 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5631 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5633 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5634 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5635 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5637 if ((nOldIndex
!= nHit
) &&
5639 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5640 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5643 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5644 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5646 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5650 if (nOldIndex
!= -1)
5651 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5654 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5655 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5656 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5658 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5660 infoPtr
->nButtonDown
= -1;
5662 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5663 TOOLBAR_SendNotify (&hdr
, infoPtr
,
5664 NM_RELEASEDCAPTURE
);
5666 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5669 memset(&nmtb
, 0, sizeof(nmtb
));
5670 nmtb
.iItem
= btnPtr
->idCommand
;
5671 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5674 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5676 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5677 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)infoPtr
->hwndSelf
);
5679 /* In case we have just been destroyed... */
5680 if(!IsWindow(infoPtr
->hwndSelf
))
5685 /* !!! Undocumented - toolbar at 4.71 level and above sends
5686 * NM_CLICK with the NMMOUSE structure. */
5687 nmmouse
.dwHitInfo
= nHit
;
5690 nmmouse
.dwItemSpec
= -1;
5693 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5694 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5697 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5700 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5701 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONUP
, wParam
, lParam
);
5707 TOOLBAR_RButtonUp(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5714 pt
.x
= (short)LOWORD(lParam
);
5715 pt
.y
= (short)HIWORD(lParam
);
5717 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5718 nmmouse
.dwHitInfo
= nHit
;
5721 nmmouse
.dwItemSpec
= -1;
5723 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5724 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5727 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5730 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5731 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONUP
, wParam
, lParam
);
5737 TOOLBAR_RButtonDblClk( TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5741 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5742 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
5748 TOOLBAR_CaptureChanged(TOOLBAR_INFO
*infoPtr
)
5750 TBUTTON_INFO
*btnPtr
;
5752 infoPtr
->bCaptured
= FALSE
;
5754 if (infoPtr
->nButtonDown
>= 0)
5756 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5757 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5759 infoPtr
->nOldHit
= -1;
5761 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5762 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5768 TOOLBAR_MouseLeave (TOOLBAR_INFO
*infoPtr
)
5770 /* don't remove hot effects when in anchor highlighting mode or when a
5771 * drop-down button is pressed */
5772 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
5774 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
5775 if (!hotBtnPtr
->bDropDownPressed
)
5776 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
5779 if (infoPtr
->nOldHit
< 0)
5782 /* If the last button we were over is depressed then make it not */
5783 /* depressed and redraw it */
5784 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
5786 TBUTTON_INFO
*btnPtr
;
5789 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5791 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5794 InflateRect (&rc1
, 1, 1);
5795 InvalidateRect (infoPtr
->hwndSelf
, &rc1
, TRUE
);
5798 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
5801 ZeroMemory(&nmt
, sizeof(nmt
));
5802 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5803 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5804 infoPtr
->bDragOutSent
= TRUE
;
5807 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
5813 TOOLBAR_MouseMove (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5816 TRACKMOUSEEVENT trackinfo
;
5818 TBUTTON_INFO
*btnPtr
;
5821 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
5822 TOOLBAR_TooltipCreateControl(infoPtr
);
5824 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
5825 /* fill in the TRACKMOUSEEVENT struct */
5826 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5827 trackinfo
.dwFlags
= TME_QUERY
;
5829 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5830 _TrackMouseEvent(&trackinfo
);
5832 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5833 if(trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
5834 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5835 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
5837 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5838 /* and can properly deactivate the hot toolbar button */
5839 _TrackMouseEvent(&trackinfo
);
5843 if (infoPtr
->hwndToolTip
)
5844 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5845 WM_MOUSEMOVE
, wParam
, lParam
);
5847 pt
.x
= (short)LOWORD(lParam
);
5848 pt
.y
= (short)HIWORD(lParam
);
5850 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5852 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
5853 && (!infoPtr
->bAnchor
|| button
))
5854 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
);
5856 if (infoPtr
->nOldHit
!= nHit
)
5858 if (infoPtr
->bCaptured
)
5860 if (!infoPtr
->bDragOutSent
)
5863 ZeroMemory(&nmt
, sizeof(nmt
));
5864 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5865 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5866 infoPtr
->bDragOutSent
= TRUE
;
5869 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5870 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
5871 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5872 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5874 else if (nHit
== infoPtr
->nButtonDown
) {
5875 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5876 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5878 infoPtr
->nOldHit
= nHit
;
5886 static inline LRESULT
5887 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5889 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5890 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
5892 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5896 static inline LRESULT
5897 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5899 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
5900 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
5902 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
5907 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
5909 TOOLBAR_INFO
*infoPtr
;
5912 /* allocate memory for info structure */
5913 infoPtr
= Alloc (sizeof(TOOLBAR_INFO
));
5914 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
5917 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
5919 infoPtr
->nWidth
= 0;
5921 /* initialize info structure */
5922 infoPtr
->nButtonWidth
= 23;
5923 infoPtr
->nButtonHeight
= 22;
5924 infoPtr
->nBitmapHeight
= 16;
5925 infoPtr
->nBitmapWidth
= 16;
5927 infoPtr
->nMaxTextRows
= 1;
5928 infoPtr
->cxMin
= -1;
5929 infoPtr
->cxMax
= -1;
5930 infoPtr
->nNumBitmaps
= 0;
5931 infoPtr
->nNumStrings
= 0;
5933 infoPtr
->bCaptured
= FALSE
;
5934 infoPtr
->nButtonDown
= -1;
5935 infoPtr
->nButtonDrag
= -1;
5936 infoPtr
->nOldHit
= -1;
5937 infoPtr
->nHotItem
= -1;
5938 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
5939 infoPtr
->dwDTFlags
= (lpcs
->style
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
5940 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
5941 infoPtr
->bDragOutSent
= FALSE
;
5942 infoPtr
->iVersion
= 0;
5943 infoPtr
->hwndSelf
= hwnd
;
5944 infoPtr
->bDoRedraw
= TRUE
;
5945 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
5946 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
5947 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
5948 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
5949 infoPtr
->iListGap
= DEFLISTGAP
;
5950 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
5951 infoPtr
->dwStyle
= lpcs
->style
;
5952 infoPtr
->tbim
.iButton
= -1;
5954 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5955 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
5956 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
5957 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
5960 /* native control does:
5961 * Get a lot of colors and brushes
5963 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
5964 * CreateFontIndirectW(adr1)
5965 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5966 * hdc = GetDC(toolbar)
5967 * GetSystemMetrics(0x48)
5968 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5969 * 0, 0, 0, 0, "MARLETT")
5970 * oldfnt = SelectObject(hdc, fnt2)
5971 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
5972 * GetTextMetricsW(hdc, adr3)
5973 * SelectObject(hdc, oldfnt)
5974 * DeleteObject(fnt2)
5976 * InvalidateRect(toolbar, 0, 1)
5977 * SetWindowLongW(toolbar, 0, addr)
5978 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
5981 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5982 * ie 2 0x4600094c 0x4600094c 0x4600894d
5983 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5984 * rebar 0x50008844 0x40008844 0x50008845
5985 * pager 0x50000844 0x40000844 0x50008845
5986 * IC35mgr 0x5400084e **nochange**
5987 * on entry to _NCCREATE 0x5400084e
5988 * rowlist 0x5400004e **nochange**
5989 * on entry to _NCCREATE 0x5400004e
5993 /* I think the code below is a bug, but it is the way that the native
5994 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5995 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5996 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5997 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5998 * Somehow, the only cases of this seem to be MFC programs.
6000 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6001 * does not occur in the WM_STYLECHANGING routine.
6002 * (Guy Albertelli 9/2001)
6005 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6006 && !(lpcs
->style
& TBSTYLE_TRANSPARENT
))
6007 styleadd
|= TBSTYLE_TRANSPARENT
;
6008 if (!(lpcs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
6009 styleadd
|= CCS_TOP
; /* default to top */
6010 SetWindowLongW (hwnd
, GWL_STYLE
, lpcs
->style
| styleadd
);
6013 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
6018 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6020 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
6024 if (dwStyle
& WS_MINIMIZE
)
6025 return 0; /* Nothing to do */
6027 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
6029 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
6032 if (!(dwStyle
& CCS_NODIVIDER
))
6034 GetWindowRect (hwnd
, &rcWindow
);
6035 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
6036 if( dwStyle
& WS_BORDER
)
6037 InflateRect (&rcWindow
, -1, -1);
6038 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6041 ReleaseDC( hwnd
, hdc
);
6047 /* handles requests from the tooltip control on what text to display */
6048 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6050 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6052 TRACE("button index = %d\n", index
);
6054 Free (infoPtr
->pszTooltipText
);
6055 infoPtr
->pszTooltipText
= NULL
;
6060 if (infoPtr
->bUnicode
)
6062 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6063 NMTBGETINFOTIPW tbgit
;
6064 unsigned int len
; /* in chars */
6066 wszBuffer
[0] = '\0';
6067 wszBuffer
[INFOTIPSIZE
] = '\0';
6069 tbgit
.pszText
= wszBuffer
;
6070 tbgit
.cchTextMax
= INFOTIPSIZE
;
6071 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6072 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6074 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6076 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6078 len
= strlenW(tbgit
.pszText
);
6079 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6081 /* need to allocate temporary buffer in infoPtr as there
6082 * isn't enough space in buffer passed to us by the
6083 * tooltip control */
6084 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6085 if (infoPtr
->pszTooltipText
)
6087 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6088 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6094 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6100 CHAR szBuffer
[INFOTIPSIZE
+1];
6101 NMTBGETINFOTIPA tbgit
;
6102 unsigned int len
; /* in chars */
6105 szBuffer
[INFOTIPSIZE
] = '\0';
6107 tbgit
.pszText
= szBuffer
;
6108 tbgit
.cchTextMax
= INFOTIPSIZE
;
6109 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6110 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6112 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6114 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6116 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6117 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]))
6119 /* need to allocate temporary buffer in infoPtr as there
6120 * isn't enough space in buffer passed to us by the
6121 * tooltip control */
6122 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6123 if (infoPtr
->pszTooltipText
)
6125 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6126 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6130 else if (tbgit
.pszText
&& tbgit
.pszText
[0])
6132 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1,
6133 lpnmtdi
->lpszText
, sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]));
6138 /* if button has text, but it is not shown then automatically
6139 * use that text as tooltip */
6140 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6141 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6143 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6144 unsigned int len
= pszText
? strlenW(pszText
) : 0;
6146 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6148 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6150 /* need to allocate temporary buffer in infoPtr as there
6151 * isn't enough space in buffer passed to us by the
6152 * tooltip control */
6153 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6154 if (infoPtr
->pszTooltipText
)
6156 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6157 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6163 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6168 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6170 /* last resort: send notification on to app */
6171 /* FIXME: find out what is really used here */
6172 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmtdi
->hdr
.idFrom
, (LPARAM
)lpnmtdi
);
6176 static inline LRESULT
6177 TOOLBAR_Notify (TOOLBAR_INFO
*infoPtr
, LPNMHDR lpnmh
)
6179 switch (lpnmh
->code
)
6183 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lpnmh
;
6185 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6186 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6187 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6191 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6192 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6200 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lpnmh
;
6202 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6203 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6204 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6205 lppgs
->iScroll
, lppgs
->iDir
);
6209 case TTN_GETDISPINFOW
:
6210 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lpnmh
);
6212 case TTN_GETDISPINFOA
:
6213 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6223 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6227 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam
, lParam
);
6229 if (lParam
== NF_QUERY
)
6232 if (lParam
== NF_REQUERY
) {
6233 format
= SendMessageW(infoPtr
->hwndNotify
,
6234 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6235 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6236 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6247 TOOLBAR_Paint (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6252 /* fill ps.rcPaint with a default rect */
6253 ps
.rcPaint
= infoPtr
->rcBound
;
6255 hdc
= wParam
==0 ? BeginPaint(infoPtr
->hwndSelf
, &ps
) : (HDC
)wParam
;
6257 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps
.rcPaint
));
6259 TOOLBAR_Refresh (infoPtr
, hdc
, &ps
);
6260 if (!wParam
) EndPaint (infoPtr
->hwndSelf
, &ps
);
6267 TOOLBAR_SetFocus (TOOLBAR_INFO
*infoPtr
)
6269 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6271 /* make first item hot */
6272 if (infoPtr
->nNumButtons
> 0)
6273 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6279 TOOLBAR_SetFont(TOOLBAR_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
6281 TRACE("font=%p redraw=%d\n", hFont
, Redraw
);
6284 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6286 infoPtr
->hFont
= hFont
;
6288 TOOLBAR_CalcToolbar(infoPtr
);
6291 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6296 TOOLBAR_SetRedraw (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6297 /*****************************************************
6300 * Handles the WM_SETREDRAW message.
6303 * According to testing V4.71 of COMCTL32 returns the
6304 * *previous* status of the redraw flag (either 0 or 1)
6305 * instead of the MSDN documented value of 0 if handled.
6306 * (For laughs see the "consistency" with same function
6309 *****************************************************/
6311 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6313 TRACE("set to %s\n",
6314 (wParam
) ? "TRUE" : "FALSE");
6315 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6317 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6319 return (oldredraw
) ? 1 : 0;
6324 TOOLBAR_Size (TOOLBAR_INFO
*infoPtr
)
6326 TRACE("sizing toolbar!\n");
6328 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6330 RECT delta_width
, delta_height
, client
, dummy
;
6331 DWORD min_x
, max_x
, min_y
, max_y
;
6332 TBUTTON_INFO
*btnPtr
;
6335 GetClientRect(infoPtr
->hwndSelf
, &client
);
6336 if(client
.right
> infoPtr
->client_rect
.right
)
6338 min_x
= infoPtr
->client_rect
.right
;
6339 max_x
= client
.right
;
6343 max_x
= infoPtr
->client_rect
.right
;
6344 min_x
= client
.right
;
6346 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6348 min_y
= infoPtr
->client_rect
.bottom
;
6349 max_y
= client
.bottom
;
6353 max_y
= infoPtr
->client_rect
.bottom
;
6354 min_y
= client
.bottom
;
6357 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6358 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6360 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6361 btnPtr
= infoPtr
->buttons
;
6362 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6363 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6364 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6365 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6367 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->client_rect
);
6368 TOOLBAR_AutoSize(infoPtr
);
6374 TOOLBAR_StyleChanged (TOOLBAR_INFO
*infoPtr
, INT nType
, const STYLESTRUCT
*lpStyle
)
6376 if (nType
== GWL_STYLE
)
6378 DWORD dwOldStyle
= infoPtr
->dwStyle
;
6380 if (lpStyle
->styleNew
& TBSTYLE_LIST
)
6381 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
6383 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
6385 TRACE("new style 0x%08x\n", lpStyle
->styleNew
);
6387 infoPtr
->dwStyle
= lpStyle
->styleNew
;
6388 TOOLBAR_CheckStyle (infoPtr
);
6390 if ((dwOldStyle
^ lpStyle
->styleNew
) & (TBSTYLE_WRAPABLE
| CCS_VERT
))
6391 TOOLBAR_LayoutToolbar(infoPtr
);
6393 /* only resize if one of the CCS_* styles was changed */
6394 if ((dwOldStyle
^ lpStyle
->styleNew
) & COMMON_STYLES
)
6396 TOOLBAR_AutoSize (infoPtr
);
6398 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6407 TOOLBAR_SysColorChange (void)
6409 COMCTL32_RefreshSysColors();
6415 /* update theme after a WM_THEMECHANGED message */
6416 static LRESULT
theme_changed (HWND hwnd
)
6418 HTHEME theme
= GetWindowTheme (hwnd
);
6419 CloseThemeData (theme
);
6420 OpenThemeData (hwnd
, themeClass
);
6425 static LRESULT WINAPI
6426 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6428 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
6430 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6431 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6433 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6434 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6439 return TOOLBAR_AddBitmap (infoPtr
, (INT
)wParam
, (TBADDBITMAP
*)lParam
);
6441 case TB_ADDBUTTONSA
:
6442 case TB_ADDBUTTONSW
:
6443 return TOOLBAR_AddButtonsT (infoPtr
, wParam
, (LPTBBUTTON
)lParam
,
6444 uMsg
== TB_ADDBUTTONSW
);
6446 return TOOLBAR_AddStringA (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6449 return TOOLBAR_AddStringW (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6452 return TOOLBAR_AutoSize (infoPtr
);
6454 case TB_BUTTONCOUNT
:
6455 return TOOLBAR_ButtonCount (infoPtr
);
6457 case TB_BUTTONSTRUCTSIZE
:
6458 return TOOLBAR_ButtonStructSize (infoPtr
, wParam
);
6460 case TB_CHANGEBITMAP
:
6461 return TOOLBAR_ChangeBitmap (infoPtr
, wParam
, LOWORD(lParam
));
6463 case TB_CHECKBUTTON
:
6464 return TOOLBAR_CheckButton (infoPtr
, wParam
, lParam
);
6466 case TB_COMMANDTOINDEX
:
6467 return TOOLBAR_CommandToIndex (infoPtr
, wParam
);
6470 return TOOLBAR_Customize (infoPtr
);
6472 case TB_DELETEBUTTON
:
6473 return TOOLBAR_DeleteButton (infoPtr
, wParam
);
6475 case TB_ENABLEBUTTON
:
6476 return TOOLBAR_EnableButton (infoPtr
, wParam
, lParam
);
6478 case TB_GETANCHORHIGHLIGHT
:
6479 return TOOLBAR_GetAnchorHighlight (infoPtr
);
6482 return TOOLBAR_GetBitmap (infoPtr
, wParam
);
6484 case TB_GETBITMAPFLAGS
:
6485 return TOOLBAR_GetBitmapFlags ();
6488 return TOOLBAR_GetButton (infoPtr
, wParam
, (TBBUTTON
*)lParam
);
6490 case TB_GETBUTTONINFOA
:
6491 case TB_GETBUTTONINFOW
:
6492 return TOOLBAR_GetButtonInfoT (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6493 uMsg
== TB_GETBUTTONINFOW
);
6494 case TB_GETBUTTONSIZE
:
6495 return TOOLBAR_GetButtonSize (infoPtr
);
6497 case TB_GETBUTTONTEXTA
:
6498 case TB_GETBUTTONTEXTW
:
6499 return TOOLBAR_GetButtonText (infoPtr
, wParam
, (LPWSTR
)lParam
,
6500 uMsg
== TB_GETBUTTONTEXTW
);
6502 case TB_GETDISABLEDIMAGELIST
:
6503 return TOOLBAR_GetDisabledImageList (infoPtr
, wParam
);
6505 case TB_GETEXTENDEDSTYLE
:
6506 return TOOLBAR_GetExtendedStyle (infoPtr
);
6508 case TB_GETHOTIMAGELIST
:
6509 return TOOLBAR_GetHotImageList (infoPtr
, wParam
);
6512 return TOOLBAR_GetHotItem (infoPtr
);
6514 case TB_GETIMAGELIST
:
6515 return TOOLBAR_GetDefImageList (infoPtr
, wParam
);
6517 case TB_GETINSERTMARK
:
6518 return TOOLBAR_GetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6520 case TB_GETINSERTMARKCOLOR
:
6521 return TOOLBAR_GetInsertMarkColor (infoPtr
);
6523 case TB_GETITEMRECT
:
6524 return TOOLBAR_GetItemRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6527 return TOOLBAR_GetMaxSize (infoPtr
, (LPSIZE
)lParam
);
6529 /* case TB_GETOBJECT: */ /* 4.71 */
6532 return TOOLBAR_GetPadding (infoPtr
);
6535 return TOOLBAR_GetRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6538 return TOOLBAR_GetRows (infoPtr
);
6541 return TOOLBAR_GetState (infoPtr
, wParam
);
6544 return TOOLBAR_GetStringA (infoPtr
, wParam
, (LPSTR
)lParam
);
6547 return TOOLBAR_GetStringW (infoPtr
, wParam
, (LPWSTR
)lParam
);
6550 return TOOLBAR_GetStyle (infoPtr
);
6552 case TB_GETTEXTROWS
:
6553 return TOOLBAR_GetTextRows (infoPtr
);
6555 case TB_GETTOOLTIPS
:
6556 return TOOLBAR_GetToolTips (infoPtr
);
6558 case TB_GETUNICODEFORMAT
:
6559 return TOOLBAR_GetUnicodeFormat (infoPtr
);
6562 return TOOLBAR_HideButton (infoPtr
, wParam
, LOWORD(lParam
));
6565 return TOOLBAR_HitTest (infoPtr
, (LPPOINT
)lParam
);
6567 case TB_INDETERMINATE
:
6568 return TOOLBAR_Indeterminate (infoPtr
, wParam
, LOWORD(lParam
));
6570 case TB_INSERTBUTTONA
:
6571 case TB_INSERTBUTTONW
:
6572 return TOOLBAR_InsertButtonT(infoPtr
, wParam
, (TBBUTTON
*)lParam
,
6573 uMsg
== TB_INSERTBUTTONW
);
6575 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6577 case TB_ISBUTTONCHECKED
:
6578 return TOOLBAR_IsButtonChecked (infoPtr
, wParam
);
6580 case TB_ISBUTTONENABLED
:
6581 return TOOLBAR_IsButtonEnabled (infoPtr
, wParam
);
6583 case TB_ISBUTTONHIDDEN
:
6584 return TOOLBAR_IsButtonHidden (infoPtr
, wParam
);
6586 case TB_ISBUTTONHIGHLIGHTED
:
6587 return TOOLBAR_IsButtonHighlighted (infoPtr
, wParam
);
6589 case TB_ISBUTTONINDETERMINATE
:
6590 return TOOLBAR_IsButtonIndeterminate (infoPtr
, wParam
);
6592 case TB_ISBUTTONPRESSED
:
6593 return TOOLBAR_IsButtonPressed (infoPtr
, wParam
);
6596 return TOOLBAR_LoadImages (infoPtr
, wParam
, (HINSTANCE
)lParam
);
6598 case TB_MAPACCELERATORA
:
6599 case TB_MAPACCELERATORW
:
6600 return TOOLBAR_MapAccelerator (infoPtr
, wParam
, (UINT
*)lParam
);
6603 return TOOLBAR_MarkButton (infoPtr
, wParam
, LOWORD(lParam
));
6606 return TOOLBAR_MoveButton (infoPtr
, wParam
, lParam
);
6608 case TB_PRESSBUTTON
:
6609 return TOOLBAR_PressButton (infoPtr
, wParam
, LOWORD(lParam
));
6611 case TB_REPLACEBITMAP
:
6612 return TOOLBAR_ReplaceBitmap (infoPtr
, (LPTBREPLACEBITMAP
)lParam
);
6614 case TB_SAVERESTOREA
:
6615 return TOOLBAR_SaveRestoreA (infoPtr
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6617 case TB_SAVERESTOREW
:
6618 return TOOLBAR_SaveRestoreW (infoPtr
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6620 case TB_SETANCHORHIGHLIGHT
:
6621 return TOOLBAR_SetAnchorHighlight (infoPtr
, (BOOL
)wParam
);
6623 case TB_SETBITMAPSIZE
:
6624 return TOOLBAR_SetBitmapSize (infoPtr
, wParam
, lParam
);
6626 case TB_SETBUTTONINFOA
:
6627 case TB_SETBUTTONINFOW
:
6628 return TOOLBAR_SetButtonInfo (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6629 uMsg
== TB_SETBUTTONINFOW
);
6630 case TB_SETBUTTONSIZE
:
6631 return TOOLBAR_SetButtonSize (infoPtr
, lParam
);
6633 case TB_SETBUTTONWIDTH
:
6634 return TOOLBAR_SetButtonWidth (infoPtr
, lParam
);
6637 return TOOLBAR_SetCmdId (infoPtr
, wParam
, lParam
);
6639 case TB_SETDISABLEDIMAGELIST
:
6640 return TOOLBAR_SetDisabledImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6642 case TB_SETDRAWTEXTFLAGS
:
6643 return TOOLBAR_SetDrawTextFlags (infoPtr
, wParam
, lParam
);
6645 case TB_SETEXTENDEDSTYLE
:
6646 return TOOLBAR_SetExtendedStyle (infoPtr
, wParam
, lParam
);
6648 case TB_SETHOTIMAGELIST
:
6649 return TOOLBAR_SetHotImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6652 return TOOLBAR_SetHotItem (infoPtr
, wParam
);
6654 case TB_SETIMAGELIST
:
6655 return TOOLBAR_SetImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6658 return TOOLBAR_SetIndent (infoPtr
, wParam
);
6660 case TB_SETINSERTMARK
:
6661 return TOOLBAR_SetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6663 case TB_SETINSERTMARKCOLOR
:
6664 return TOOLBAR_SetInsertMarkColor (infoPtr
, lParam
);
6666 case TB_SETMAXTEXTROWS
:
6667 return TOOLBAR_SetMaxTextRows (infoPtr
, wParam
);
6670 return TOOLBAR_SetPadding (infoPtr
, lParam
);
6673 return TOOLBAR_SetParent (infoPtr
, (HWND
)wParam
);
6676 return TOOLBAR_SetRows (infoPtr
, wParam
, (LPRECT
)lParam
);
6679 return TOOLBAR_SetState (infoPtr
, wParam
, lParam
);
6682 return TOOLBAR_SetStyle (infoPtr
, lParam
);
6684 case TB_SETTOOLTIPS
:
6685 return TOOLBAR_SetToolTips (infoPtr
, (HWND
)wParam
);
6687 case TB_SETUNICODEFORMAT
:
6688 return TOOLBAR_SetUnicodeFormat (infoPtr
, wParam
);
6691 return TOOLBAR_Unkwn45D(hwnd
, wParam
, lParam
);
6693 case TB_SETHOTITEM2
:
6694 return TOOLBAR_SetHotItem2 (infoPtr
, wParam
, lParam
);
6697 return TOOLBAR_SetListGap(infoPtr
, wParam
);
6699 case TB_GETIMAGELISTCOUNT
:
6700 return TOOLBAR_GetImageListCount(infoPtr
);
6702 case TB_GETIDEALSIZE
:
6703 return TOOLBAR_GetIdealSize (infoPtr
, wParam
, lParam
);
6706 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6708 /* Common Control Messages */
6710 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6711 case CCM_GETCOLORSCHEME
:
6712 return TOOLBAR_GetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6714 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6715 case CCM_SETCOLORSCHEME
:
6716 return TOOLBAR_SetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6718 case CCM_GETVERSION
:
6719 return TOOLBAR_GetVersion (infoPtr
);
6721 case CCM_SETVERSION
:
6722 return TOOLBAR_SetVersion (infoPtr
, (INT
)wParam
);
6728 return TOOLBAR_Create (hwnd
, (CREATESTRUCTW
*)lParam
);
6731 return TOOLBAR_Destroy (infoPtr
);
6734 return TOOLBAR_EraseBackground (infoPtr
, wParam
, lParam
);
6737 return TOOLBAR_GetFont (infoPtr
);
6740 return TOOLBAR_KeyDown (infoPtr
, wParam
, lParam
);
6742 /* case WM_KILLFOCUS: */
6744 case WM_LBUTTONDBLCLK
:
6745 return TOOLBAR_LButtonDblClk (infoPtr
, wParam
, lParam
);
6747 case WM_LBUTTONDOWN
:
6748 return TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
6751 return TOOLBAR_LButtonUp (infoPtr
, wParam
, lParam
);
6754 return TOOLBAR_RButtonUp (infoPtr
, wParam
, lParam
);
6756 case WM_RBUTTONDBLCLK
:
6757 return TOOLBAR_RButtonDblClk (infoPtr
, wParam
, lParam
);
6760 return TOOLBAR_MouseMove (infoPtr
, wParam
, lParam
);
6763 return TOOLBAR_MouseLeave (infoPtr
);
6765 case WM_CAPTURECHANGED
:
6766 return TOOLBAR_CaptureChanged(infoPtr
);
6769 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6772 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6775 return TOOLBAR_NCCreate (hwnd
, wParam
, (CREATESTRUCTW
*)lParam
);
6778 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
6781 return TOOLBAR_Notify (infoPtr
, (LPNMHDR
)lParam
);
6783 case WM_NOTIFYFORMAT
:
6784 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
6786 case WM_PRINTCLIENT
:
6788 return TOOLBAR_Paint (infoPtr
, wParam
);
6791 return TOOLBAR_SetFocus (infoPtr
);
6794 return TOOLBAR_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
6797 return TOOLBAR_SetRedraw (infoPtr
, wParam
);
6800 return TOOLBAR_Size (infoPtr
);
6802 case WM_STYLECHANGED
:
6803 return TOOLBAR_StyleChanged (infoPtr
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
6805 case WM_SYSCOLORCHANGE
:
6806 return TOOLBAR_SysColorChange ();
6808 case WM_THEMECHANGED
:
6809 return theme_changed (hwnd
);
6811 /* case WM_WININICHANGE: */
6816 case WM_MEASUREITEM
:
6818 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
6820 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6821 case PGM_FORWARDMOUSE
:
6822 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6825 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
6826 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
6827 uMsg
, wParam
, lParam
);
6828 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6834 TOOLBAR_Register (void)
6838 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
6839 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
6840 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
6841 wndClass
.cbClsExtra
= 0;
6842 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
6843 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
6844 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
6845 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
6847 RegisterClassW (&wndClass
);
6852 TOOLBAR_Unregister (void)
6854 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
6857 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
6862 /* Check if the entry already exists */
6863 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
6865 /* If this is a new entry we must create it and insert into the array */
6870 c
= Alloc(sizeof(IMLENTRY
));
6873 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
6874 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
6889 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
6893 for (i
= 0; i
< *cies
; i
++)
6903 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
6911 for (i
= 0; i
< cies
; i
++)
6913 if (pies
[i
]->id
== id
)
6925 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
6927 HIMAGELIST himlDef
= 0;
6928 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
6931 himlDef
= pie
->himl
;
6937 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
6939 if (infoPtr
->bUnicode
)
6940 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
6947 nmtba
.iItem
= nmtb
->iItem
;
6948 nmtba
.pszText
= Buffer
;
6949 nmtba
.cchText
= 256;
6950 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
6952 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
6954 int ccht
= strlen(nmtba
.pszText
);
6956 MultiByteToWideChar(CP_ACP
, 0, nmtba
.pszText
, -1,
6957 nmtb
->pszText
, nmtb
->cchText
);
6959 nmtb
->tbButton
= nmtba
.tbButton
;
6968 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
)
6972 /* MSDN states that iItem is the index of the button, rather than the
6973 * command ID as used by every other NMTOOLBAR notification */
6975 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
6977 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);