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)
73 WINE_DEFAULT_DEBUG_CHANNEL(toolbar
);
75 static HCURSOR hCursorDrag
= NULL
;
84 BOOL bDropDownPressed
;
89 INT cx
; /* manually set size */
103 } IMLENTRY
, *PIMLENTRY
;
107 DWORD dwStructSize
; /* size of TBBUTTON struct */
108 INT nWidth
; /* width of the toolbar */
110 RECT rcBound
; /* bounding rectangle */
116 INT nRows
; /* number of button rows */
117 INT nMaxTextRows
; /* maximum number of text rows */
118 INT cxMin
; /* minimum button width */
119 INT cxMax
; /* maximum button width */
120 INT nNumButtons
; /* number of buttons */
121 INT nNumBitmaps
; /* number of bitmaps */
122 INT nNumStrings
; /* number of strings */
124 INT nButtonDown
; /* toolbar button being pressed or -1 if none */
125 INT nButtonDrag
; /* toolbar button being dragged or -1 if none */
127 INT nHotItem
; /* index of the "hot" item */
128 SIZE szPadding
; /* padding values around button */
129 INT iTopMargin
; /* the top margin */
130 INT iListGap
; /* default gap between text and image for toolbar with list style */
132 HFONT hFont
; /* text font */
133 HIMAGELIST himlInt
; /* image list created internally */
134 PIMLENTRY
*himlDef
; /* default image list array */
135 INT cimlDef
; /* default image list array count */
136 PIMLENTRY
*himlHot
; /* hot image list array */
137 INT cimlHot
; /* hot image list array count */
138 PIMLENTRY
*himlDis
; /* disabled image list array */
139 INT cimlDis
; /* disabled image list array count */
140 HWND hwndToolTip
; /* handle to tool tip control */
141 HWND hwndNotify
; /* handle to the window that gets notifications */
142 HWND hwndSelf
; /* my own handle */
143 BOOL bAnchor
; /* anchor highlight enabled */
144 BOOL bDoRedraw
; /* Redraw status */
145 BOOL bDragOutSent
; /* has TBN_DRAGOUT notification been sent for this drag? */
146 BOOL bUnicode
; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
147 BOOL bCaptured
; /* mouse captured? */
148 DWORD dwStyle
; /* regular toolbar style */
149 DWORD dwExStyle
; /* extended toolbar style */
150 DWORD dwDTFlags
; /* DrawText flags */
152 COLORREF clrInsertMark
; /* insert mark color */
153 COLORREF clrBtnHighlight
; /* color for Flat Separator */
154 COLORREF clrBtnShadow
; /* color for Flag Separator */
156 LPWSTR pszTooltipText
; /* temporary store for a string > 80 characters
157 * for TTN_GETDISPINFOW notification */
158 TBINSERTMARK tbim
; /* info on insertion mark */
159 TBUTTON_INFO
*buttons
; /* pointer to button array */
160 LPWSTR
*strings
; /* pointer to string array */
161 TBITMAP_INFO
*bitmaps
;
162 } TOOLBAR_INFO
, *PTOOLBAR_INFO
;
165 /* used by customization dialog */
168 PTOOLBAR_INFO tbInfo
;
170 } CUSTDLG_INFO
, *PCUSTDLG_INFO
;
178 } CUSTOMBUTTON
, *PCUSTOMBUTTON
;
187 #define SEPARATOR_WIDTH 8
189 #define BOTTOM_BORDER 2
190 #define DDARROW_WIDTH 11
191 #define ARROW_HEIGHT 3
192 #define INSERTMARK_WIDTH 2
198 /* vertical padding used in list mode when image is present */
201 /* how wide to treat the bitmap if it isn't present */
202 #define NONLIST_NOTEXT_OFFSET 2
204 #define TOOLBAR_NOWHERE (-1)
206 /* Used to find undocumented extended styles */
207 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
208 TBSTYLE_EX_VERTICAL | \
209 TBSTYLE_EX_MIXEDBUTTONS | \
210 TBSTYLE_EX_DOUBLEBUFFER | \
211 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
213 /* all of the CCS_ styles */
214 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
215 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
217 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
218 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
219 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
220 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
221 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
223 static const WCHAR themeClass
[] = { 'T','o','o','l','b','a','r',0 };
225 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
);
226 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
);
227 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
);
228 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
);
229 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
);
230 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
);
231 static LRESULT
TOOLBAR_LButtonDown(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
);
232 static void TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
);
233 static LRESULT
TOOLBAR_AutoSize(TOOLBAR_INFO
*infoPtr
);
234 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
);
235 static void TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
236 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
239 static inline int default_top_margin(const TOOLBAR_INFO
*infoPtr
)
241 return (infoPtr
->dwStyle
& TBSTYLE_FLAT
? 0 : TOP_BORDER
);
244 static inline BOOL
TOOLBAR_HasDropDownArrows(DWORD exStyle
)
246 return (exStyle
& TBSTYLE_EX_DRAWDDARROWS
) != 0;
250 TOOLBAR_GetText(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
252 LPWSTR lpText
= NULL
;
254 /* NOTE: iString == -1 is undocumented */
255 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1))
256 lpText
= (LPWSTR
)btnPtr
->iString
;
257 else if ((btnPtr
->iString
>= 0) && (btnPtr
->iString
< infoPtr
->nNumStrings
))
258 lpText
= infoPtr
->strings
[btnPtr
->iString
];
264 TOOLBAR_DumpTBButton(const TBBUTTON
*tbb
, BOOL fUnicode
)
266 TRACE("TBBUTTON: id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx (%s)\n",
267 tbb
->idCommand
,tbb
->iBitmap
, tbb
->fsState
, tbb
->fsStyle
, tbb
->dwData
, tbb
->iString
,
268 (fUnicode
? wine_dbgstr_w((LPWSTR
)tbb
->iString
) : wine_dbgstr_a((LPSTR
)tbb
->iString
)));
272 TOOLBAR_DumpButton(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*bP
, INT btn_num
)
274 if (TRACE_ON(toolbar
)){
275 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
276 btn_num
, bP
->idCommand
, GETIBITMAP(infoPtr
, bP
->iBitmap
),
277 bP
->fsState
, bP
->fsStyle
, bP
->dwData
, bP
->iString
);
278 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr
,bP
)));
279 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n",
280 btn_num
, bP
->idCommand
, (bP
->bHot
) ? "TRUE":"FALSE", bP
->nRow
,
281 wine_dbgstr_rect(&bP
->rect
));
287 TOOLBAR_DumpToolbar(const TOOLBAR_INFO
*iP
, INT line
)
289 if (TRACE_ON(toolbar
)) {
292 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
294 iP
->dwExStyle
, iP
->nNumButtons
, iP
->nNumBitmaps
,
295 iP
->nNumStrings
, iP
->dwStyle
);
296 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
298 iP
->himlInt
, iP
->himlDef
, iP
->himlHot
, iP
->himlDis
,
299 (iP
->bDoRedraw
) ? "TRUE" : "FALSE");
300 for(i
=0; i
<iP
->nNumButtons
; i
++) {
301 TOOLBAR_DumpButton(iP
, &iP
->buttons
[i
], i
);
307 TOOLBAR_ButtonHasString(const TBUTTON_INFO
*btnPtr
)
309 return HIWORD(btnPtr
->iString
) && btnPtr
->iString
!= -1;
312 /***********************************************************************
315 * This function validates that the styles set are implemented and
316 * issues FIXMEs warning of possible problems. In a perfect world this
317 * function should be null.
320 TOOLBAR_CheckStyle (const TOOLBAR_INFO
*infoPtr
)
322 if (infoPtr
->dwStyle
& TBSTYLE_REGISTERDROP
)
323 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", infoPtr
->hwndSelf
);
328 TOOLBAR_SendNotify (NMHDR
*nmhdr
, const TOOLBAR_INFO
*infoPtr
, UINT code
)
330 if(!IsWindow(infoPtr
->hwndSelf
))
331 return 0; /* we have just been destroyed */
333 nmhdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
334 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
337 TRACE("to window %p, code=%08x, %s\n", infoPtr
->hwndNotify
, code
,
338 (infoPtr
->bUnicode
) ? "via Unicode" : "via ANSI");
340 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhdr
->idFrom
, (LPARAM
)nmhdr
);
343 /***********************************************************************
344 * TOOLBAR_GetBitmapIndex
346 * This function returns the bitmap index associated with a button.
347 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
348 * is issued to retrieve the index.
351 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
353 INT ret
= btnPtr
->iBitmap
;
355 if (ret
== I_IMAGECALLBACK
)
357 /* issue TBN_GETDISPINFO */
360 memset(&nmgd
, 0, sizeof(nmgd
));
361 nmgd
.idCommand
= btnPtr
->idCommand
;
362 nmgd
.lParam
= btnPtr
->dwData
;
363 nmgd
.dwMask
= TBNF_IMAGE
;
365 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
366 TOOLBAR_SendNotify(&nmgd
.hdr
, infoPtr
, TBN_GETDISPINFOW
);
367 if (nmgd
.dwMask
& TBNF_DI_SETITEM
)
368 btnPtr
->iBitmap
= nmgd
.iImage
;
370 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
371 ret
, nmgd
.dwMask
, infoPtr
->nNumBitmaps
);
374 if (ret
!= I_IMAGENONE
)
375 ret
= GETIBITMAP(infoPtr
, ret
);
382 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO
*infoPtr
, INT index
)
385 INT id
= GETHIMLID(infoPtr
, index
);
386 INT iBitmap
= GETIBITMAP(infoPtr
, index
);
388 if (((himl
= GETDEFIMAGELIST(infoPtr
, id
)) &&
389 iBitmap
>= 0 && iBitmap
< ImageList_GetImageCount(himl
)) ||
390 (index
== I_IMAGECALLBACK
))
398 TOOLBAR_IsValidImageList(const TOOLBAR_INFO
*infoPtr
, INT index
)
400 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, index
));
401 return (himl
!= NULL
) && (ImageList_GetImageCount(himl
) > 0);
405 /***********************************************************************
406 * TOOLBAR_GetImageListForDrawing
408 * This function validates the bitmap index (including I_IMAGECALLBACK
409 * functionality) and returns the corresponding image list.
412 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
,
413 IMAGE_LIST_TYPE imagelist
, INT
* index
)
417 if (!TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
)) {
418 if (btnPtr
->iBitmap
== I_IMAGENONE
) return NULL
;
419 WARN("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
420 HIWORD(btnPtr
->iBitmap
), LOWORD(btnPtr
->iBitmap
), infoPtr
->nNumBitmaps
);
424 if ((*index
= TOOLBAR_GetBitmapIndex(infoPtr
, btnPtr
)) < 0) {
425 if ((*index
== I_IMAGECALLBACK
) ||
426 (*index
== I_IMAGENONE
)) return NULL
;
427 ERR("TBN_GETDISPINFO returned invalid index %d\n",
434 case IMAGE_LIST_DEFAULT
:
435 himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
438 himl
= GETHOTIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
440 case IMAGE_LIST_DISABLED
:
441 himl
= GETDISIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
445 FIXME("Shouldn't reach here\n");
449 TRACE("no image list\n");
456 TOOLBAR_DrawFlatSeparator (const RECT
*lpRect
, HDC hdc
, const TOOLBAR_INFO
*infoPtr
)
459 COLORREF oldcolor
, newcolor
;
461 myrect
.left
= (lpRect
->left
+ lpRect
->right
) / 2 - 1;
462 myrect
.right
= myrect
.left
+ 1;
463 myrect
.top
= lpRect
->top
+ 2;
464 myrect
.bottom
= lpRect
->bottom
- 2;
466 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
467 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
468 oldcolor
= SetBkColor (hdc
, newcolor
);
469 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
471 myrect
.left
= myrect
.right
;
472 myrect
.right
= myrect
.left
+ 1;
474 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
475 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
476 SetBkColor (hdc
, newcolor
);
477 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
479 SetBkColor (hdc
, oldcolor
);
483 /***********************************************************************
484 * TOOLBAR_DrawFlatHorizontalSeparator
486 * This function draws horizontal separator for toolbars having CCS_VERT style.
487 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
488 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
489 * are horizontal as opposed to the vertical separators for not dropdown
492 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
495 TOOLBAR_DrawFlatHorizontalSeparator (const RECT
*lpRect
, HDC hdc
,
496 const TOOLBAR_INFO
*infoPtr
)
499 COLORREF oldcolor
, newcolor
;
501 myrect
.left
= lpRect
->left
;
502 myrect
.right
= lpRect
->right
;
503 myrect
.top
= lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
- 2)/2;
504 myrect
.bottom
= myrect
.top
+ 1;
506 InflateRect (&myrect
, -2, 0);
508 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect
));
510 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
511 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
512 oldcolor
= SetBkColor (hdc
, newcolor
);
513 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
515 myrect
.top
= myrect
.bottom
;
516 myrect
.bottom
= myrect
.top
+ 1;
518 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
519 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
520 SetBkColor (hdc
, newcolor
);
521 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
523 SetBkColor (hdc
, oldcolor
);
528 TOOLBAR_DrawArrow (HDC hdc
, INT left
, INT top
, COLORREF clr
)
533 if (!(hPen
= CreatePen( PS_SOLID
, 1, clr
))) return;
534 hOldPen
= SelectObject ( hdc
, hPen
);
537 MoveToEx (hdc
, x
, y
, NULL
);
538 LineTo (hdc
, x
+5, y
++); x
++;
539 MoveToEx (hdc
, x
, y
, NULL
);
540 LineTo (hdc
, x
+3, y
++); x
++;
541 MoveToEx (hdc
, x
, y
, NULL
);
542 LineTo (hdc
, x
+1, y
);
543 SelectObject( hdc
, hOldPen
);
544 DeleteObject( hPen
);
548 * Draw the text string for this button.
549 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
550 * is non-zero, so we can simply check himlDef to see if we have
554 TOOLBAR_DrawString (const TOOLBAR_INFO
*infoPtr
, RECT
*rcText
, LPCWSTR lpText
,
555 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
557 HDC hdc
= tbcd
->nmcd
.hdc
;
560 COLORREF clrOldBk
= 0;
562 UINT state
= tbcd
->nmcd
.uItemState
;
565 if (lpText
&& infoPtr
->nMaxTextRows
> 0) {
566 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText
),
567 wine_dbgstr_rect(rcText
));
569 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
570 if ((state
& CDIS_HOT
) && (dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)) {
571 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
573 else if (state
& CDIS_DISABLED
) {
574 clrOld
= SetTextColor (hdc
, tbcd
->clrBtnHighlight
);
575 OffsetRect (rcText
, 1, 1);
576 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
577 SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
578 OffsetRect (rcText
, -1, -1);
580 else if (state
& CDIS_INDETERMINATE
) {
581 clrOld
= SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
583 else if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
)) {
584 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
585 clrOldBk
= SetBkColor (hdc
, tbcd
->clrMark
);
586 oldBkMode
= SetBkMode (hdc
, tbcd
->nHLStringBkMode
);
589 clrOld
= SetTextColor (hdc
, tbcd
->clrText
);
592 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
593 SetTextColor (hdc
, clrOld
);
594 if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
))
596 SetBkColor (hdc
, clrOldBk
);
597 SetBkMode (hdc
, oldBkMode
);
599 SelectObject (hdc
, hOldFont
);
605 TOOLBAR_DrawPattern (const RECT
*lpRect
, const NMTBCUSTOMDRAW
*tbcd
)
607 HDC hdc
= tbcd
->nmcd
.hdc
;
608 HBRUSH hbr
= SelectObject (hdc
, tbcd
->hbrMonoDither
);
611 INT cx
= lpRect
->right
- lpRect
->left
;
612 INT cy
= lpRect
->bottom
- lpRect
->top
;
613 INT cxEdge
= GetSystemMetrics(SM_CXEDGE
);
614 INT cyEdge
= GetSystemMetrics(SM_CYEDGE
);
615 clrTextOld
= SetTextColor(hdc
, tbcd
->clrBtnHighlight
);
616 clrBkOld
= SetBkColor(hdc
, tbcd
->clrBtnFace
);
617 PatBlt (hdc
, lpRect
->left
+ cxEdge
, lpRect
->top
+ cyEdge
,
618 cx
- (2 * cxEdge
), cy
- (2 * cyEdge
), PATCOPY
);
619 SetBkColor(hdc
, clrBkOld
);
620 SetTextColor(hdc
, clrTextOld
);
621 SelectObject (hdc
, hbr
);
625 static void TOOLBAR_DrawMasked(HIMAGELIST himl
, int index
, HDC hdc
, INT x
, INT y
, UINT draw_flags
)
628 HBITMAP hbmMask
, hbmImage
;
629 HDC hdcMask
, hdcImage
;
631 ImageList_GetIconSize(himl
, &cx
, &cy
);
633 /* Create src image */
634 hdcImage
= CreateCompatibleDC(hdc
);
635 hbmImage
= CreateCompatibleBitmap(hdc
, cx
, cy
);
636 SelectObject(hdcImage
, hbmImage
);
637 ImageList_DrawEx(himl
, index
, hdcImage
, 0, 0, cx
, cy
,
638 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags
);
641 hdcMask
= CreateCompatibleDC(0);
642 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
643 SelectObject(hdcMask
, hbmMask
);
645 /* Remove the background and all white pixels */
646 ImageList_DrawEx(himl
, index
, hdcMask
, 0, 0, cx
, cy
,
647 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK
);
648 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
649 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
651 /* draw the new mask 'etched' to hdc */
652 SetBkColor(hdc
, RGB(255, 255, 255));
653 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
654 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
655 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
656 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
657 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
660 DeleteObject(hbmImage
);
662 DeleteObject (hbmMask
);
668 TOOLBAR_TranslateState(const TBUTTON_INFO
*btnPtr
)
672 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
673 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
674 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
675 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
676 retstate
|= (btnPtr
->bHot
) ? CDIS_HOT
: 0;
677 retstate
|= ((btnPtr
->fsState
& (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) == (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) ? CDIS_INDETERMINATE
: 0;
678 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
682 /* draws the image on a toolbar button */
684 TOOLBAR_DrawImage(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
,
685 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
687 HIMAGELIST himl
= NULL
;
688 BOOL draw_masked
= FALSE
;
691 UINT draw_flags
= ILD_TRANSPARENT
;
693 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
695 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
698 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
702 else if (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
||
703 ((tbcd
->nmcd
.uItemState
& CDIS_HOT
)
704 && ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))))
706 /* if hot, attempt to draw with hot image list, if fails,
707 use default image list */
708 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
710 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
713 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
718 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
719 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
722 if (!(dwItemCDFlag
& TBCDRF_NOMARK
) &&
723 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
724 draw_flags
|= ILD_BLEND50
;
726 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
727 index
, himl
, left
, top
, offset
);
730 TOOLBAR_DrawMasked (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
732 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
735 /* draws a blank frame for a toolbar button */
737 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, const RECT
*rect
, DWORD dwItemCDFlag
)
739 HDC hdc
= tbcd
->nmcd
.hdc
;
741 /* if the state is disabled or indeterminate then the button
742 * cannot have an interactive look like pressed or hot */
743 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
744 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
745 BOOL pressed_look
= !non_interactive_state
&&
746 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
747 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
749 /* app don't want us to draw any edges */
750 if (dwItemCDFlag
& TBCDRF_NOEDGES
)
753 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
756 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
757 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
758 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
763 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
765 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
766 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
771 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
, BOOL bDropDownPressed
, DWORD dwItemCDFlag
)
773 HDC hdc
= tbcd
->nmcd
.hdc
;
775 BOOL pressed
= bDropDownPressed
||
776 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
));
778 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
781 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
);
782 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
783 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
784 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
785 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
790 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
792 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
793 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
797 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
799 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
801 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
802 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
805 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
808 /* draws a complete toolbar button */
810 TOOLBAR_DrawButton (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, HDC hdc
, DWORD dwBaseCustDraw
)
812 DWORD dwStyle
= infoPtr
->dwStyle
;
813 BOOL hasDropDownArrow
= (TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) &&
814 (btnPtr
->fsStyle
& BTNS_DROPDOWN
)) ||
815 (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
816 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
817 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
818 RECT rc
, rcArrow
, rcBitmap
, rcText
;
819 LPWSTR lpText
= NULL
;
824 DWORD dwItemCustDraw
;
826 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
829 CopyRect (&rcArrow
, &rc
);
831 /* separator - doesn't send NM_CUSTOMDRAW */
832 if (btnPtr
->fsStyle
& BTNS_SEP
) {
835 DrawThemeBackground (theme
, hdc
,
836 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
840 /* with the FLAT style, iBitmap is the width and has already */
841 /* been taken into consideration in calculating the width */
842 /* so now we need to draw the vertical separator */
843 /* empirical tests show that iBitmap can/will be non-zero */
844 /* when drawing the vertical bar... */
845 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
846 if (dwStyle
& CCS_VERT
) {
848 InflateRect(&rcsep
, -infoPtr
->szPadding
.cx
, -infoPtr
->szPadding
.cy
);
849 TOOLBAR_DrawFlatHorizontalSeparator (&rcsep
, hdc
, infoPtr
);
852 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
855 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
856 FIXME("Draw some kind of separator: fsStyle=%x\n",
862 /* get a pointer to the text */
863 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
865 if (hasDropDownArrow
)
869 if (dwStyle
& TBSTYLE_FLAT
)
870 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
872 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
874 if (drawSepDropDownArrow
)
877 rcArrow
.left
= right
;
880 /* copy text & bitmap rects after adjusting for drop-down arrow
881 * so that text & bitmap is centered in the rectangle not containing
883 CopyRect(&rcText
, &rc
);
884 CopyRect(&rcBitmap
, &rc
);
886 /* Center the bitmap horizontally and vertically */
887 if (dwStyle
& TBSTYLE_LIST
)
890 infoPtr
->nMaxTextRows
> 0 &&
891 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
892 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
893 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
895 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
898 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
900 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
902 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
903 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
904 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
905 TRACE("Text=%s\n", debugstr_w(lpText
));
906 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
908 /* calculate text position */
911 rcText
.left
+= GetSystemMetrics(SM_CXEDGE
);
912 rcText
.right
-= GetSystemMetrics(SM_CXEDGE
);
913 if (dwStyle
& TBSTYLE_LIST
)
915 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
919 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
920 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
922 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
926 /* Initialize fields in all cases, because we use these later
927 * NOTE: applications can and do alter these to customize their
929 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
930 tbcd
.clrText
= comctl32_color
.clrBtnText
;
931 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
932 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
933 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
934 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
935 tbcd
.clrHighlightHotTrack
= 0;
936 tbcd
.nStringBkMode
= TRANSPARENT
;
937 tbcd
.nHLStringBkMode
= OPAQUE
;
938 tbcd
.rcText
.left
= 0;
940 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
941 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
942 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
944 tbcd
.nmcd
.rc
= btnPtr
->rect
;
945 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
947 /* FIXME: what are these used for? */
951 /* Issue Item Prepaint notify */
954 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
956 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
957 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
958 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
959 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
960 /* reset these fields so the user can't alter the behaviour like native */
962 tbcd
.nmcd
.rc
= btnPtr
->rect
;
964 dwItemCustDraw
= ntfret
& 0xffff;
965 dwItemCDFlag
= ntfret
& 0xffff0000;
966 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
968 /* save the only part of the rect that the user can change */
969 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
970 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
973 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
974 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
975 OffsetRect(&rcText
, 1, 1);
977 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
978 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
979 TOOLBAR_DrawPattern (&rc
, &tbcd
);
981 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
982 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
984 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
988 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
989 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
990 if (hasDropDownArrow
)
991 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
992 SetBkColor(hdc
, oldclr
);
998 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
999 int stateId
= TS_NORMAL
;
1001 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1002 stateId
= TS_DISABLED
;
1003 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1004 stateId
= TS_PRESSED
;
1005 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1006 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1007 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1008 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1011 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &rc
, NULL
);
1014 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, &rc
, dwItemCDFlag
);
1016 if (drawSepDropDownArrow
)
1020 int stateId
= TS_NORMAL
;
1022 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1023 stateId
= TS_DISABLED
;
1024 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1025 stateId
= TS_PRESSED
;
1026 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1027 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1028 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1031 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1032 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1035 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1038 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1039 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1040 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1041 SetBkMode (hdc
, oldBkMode
);
1043 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1045 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1047 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1049 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1050 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1052 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1054 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1055 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1058 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1061 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1063 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1064 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1071 TOOLBAR_Refresh (TOOLBAR_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
1073 TBUTTON_INFO
*btnPtr
;
1075 RECT rcTemp
, rcClient
;
1076 NMTBCUSTOMDRAW tbcd
;
1078 DWORD dwBaseCustDraw
;
1080 /* the app has told us not to redraw the toolbar */
1081 if (!infoPtr
->bDoRedraw
)
1084 /* if imagelist belongs to the app, it can be changed
1085 by the app after setting it */
1086 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1088 infoPtr
->nNumBitmaps
= 0;
1089 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1090 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1093 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1095 /* change the imagelist icon size if we manage the list and it is necessary */
1096 TOOLBAR_CheckImageListIconSize(infoPtr
);
1098 /* Send initial notify */
1099 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1100 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1101 tbcd
.nmcd
.hdc
= hdc
;
1102 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1103 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1104 dwBaseCustDraw
= ntfret
& 0xffff;
1106 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1108 /* redraw necessary buttons */
1109 btnPtr
= infoPtr
->buttons
;
1110 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1113 if (!RectVisible(hdc
, &btnPtr
->rect
))
1115 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1117 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1118 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1122 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1123 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1125 TOOLBAR_DrawButton(infoPtr
, btnPtr
, hdc
, dwBaseCustDraw
);
1128 /* draw insert mark if required */
1129 if (infoPtr
->tbim
.iButton
!= -1)
1131 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1133 rcInsertMark
.top
= rcButton
.top
;
1134 rcInsertMark
.bottom
= rcButton
.bottom
;
1135 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1136 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1138 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1139 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1142 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1144 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1145 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1146 tbcd
.nmcd
.hdc
= hdc
;
1147 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1148 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1152 /***********************************************************************
1153 * TOOLBAR_MeasureString
1155 * This function gets the width and height of a string in pixels. This
1156 * is done first by using GetTextExtentPoint to get the basic width
1157 * and height. The DrawText is called with DT_CALCRECT to get the exact
1158 * width. The reason is because the text may have more than one "&" (or
1159 * prefix characters as M$ likes to call them). The prefix character
1160 * indicates where the underline goes, except for the string "&&" which
1161 * is reduced to a single "&". GetTextExtentPoint does not process these
1162 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1165 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1166 HDC hdc
, LPSIZE lpSize
)
1173 if (infoPtr
->nMaxTextRows
> 0 &&
1174 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1175 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1176 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1178 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1180 if(lpText
!= NULL
) {
1181 /* first get size of all the text */
1182 GetTextExtentPoint32W (hdc
, lpText
, strlenW (lpText
), lpSize
);
1184 /* feed above size into the rectangle for DrawText */
1185 myrect
.left
= myrect
.top
= 0;
1186 myrect
.right
= lpSize
->cx
;
1187 myrect
.bottom
= lpSize
->cy
;
1189 /* Use DrawText to get true size as drawn (less pesky "&") */
1190 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1191 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1194 /* feed back to caller */
1195 lpSize
->cx
= myrect
.right
;
1196 lpSize
->cy
= myrect
.bottom
;
1200 TRACE("string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1203 /***********************************************************************
1204 * TOOLBAR_CalcStrings
1206 * This function walks through each string and measures it and returns
1207 * the largest height and width to caller.
1210 TOOLBAR_CalcStrings (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
1212 TBUTTON_INFO
*btnPtr
;
1221 if (infoPtr
->nMaxTextRows
== 0)
1224 hdc
= GetDC (infoPtr
->hwndSelf
);
1225 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1227 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1231 GetTextMetricsW(hdc
, &tm
);
1232 lpSize
->cy
= tm
.tmHeight
;
1235 btnPtr
= infoPtr
->buttons
;
1236 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1237 if(TOOLBAR_GetText(infoPtr
, btnPtr
))
1239 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1240 if (sz
.cx
> lpSize
->cx
)
1242 if (sz
.cy
> lpSize
->cy
)
1247 SelectObject (hdc
, hOldFont
);
1248 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1250 TRACE("max string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1253 /***********************************************************************
1254 * TOOLBAR_WrapToolbar
1256 * This function walks through the buttons and separators in the
1257 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1258 * wrapping should occur based on the width of the toolbar window.
1259 * It does *not* calculate button placement itself. That task
1260 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1261 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1262 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1264 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_VERTICAL can be used also to allow
1265 * vertical toolbar lists.
1269 TOOLBAR_WrapToolbar(TOOLBAR_INFO
*infoPtr
)
1271 TBUTTON_INFO
*btnPtr
;
1276 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1277 /* no layout is necessary. Applications may use this style */
1278 /* to perform their own layout on the toolbar. */
1279 if( !(infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) &&
1280 !(infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
) ) return;
1282 btnPtr
= infoPtr
->buttons
;
1283 x
= infoPtr
->nIndent
;
1285 if (GetParent(infoPtr
->hwndSelf
))
1287 /* this can get the parents width, to know how far we can extend
1288 * this toolbar. We cannot use its height, as there may be multiple
1289 * toolbars in a rebar control
1291 GetClientRect( GetParent(infoPtr
->hwndSelf
), &rc
);
1292 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1296 GetWindowRect( infoPtr
->hwndSelf
, &rc
);
1297 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1300 bButtonWrap
= FALSE
;
1302 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1303 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, infoPtr
->nWidth
,
1306 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1308 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1310 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1313 if (btnPtr
[i
].cx
> 0)
1315 /* horizontal separators are treated as buttons for width */
1316 else if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1317 !(infoPtr
->dwStyle
& CCS_VERT
))
1318 cx
= (btnPtr
[i
].iBitmap
> 0) ? btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1320 cx
= infoPtr
->nButtonWidth
;
1322 /* Two or more adjacent separators form a separator group. */
1323 /* The first separator in a group should be wrapped to the */
1324 /* next row if the previous wrapping is on a button. */
1326 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1327 (i
+ 1 < infoPtr
->nNumButtons
) &&
1328 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1330 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1331 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1332 x
= infoPtr
->nIndent
;
1334 bButtonWrap
= FALSE
;
1338 /* The layout makes sure the bitmap is visible, but not the button. */
1339 /* Test added to also wrap after a button that starts a row but */
1340 /* is bigger than the area. - GA 8/01 */
1341 if (( x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2
1342 > infoPtr
->nWidth
) ||
1343 ((x
== infoPtr
->nIndent
) && (cx
> infoPtr
->nWidth
)))
1345 BOOL bFound
= FALSE
;
1347 /* If the current button is a separator and not hidden, */
1348 /* go to the next until it reaches a non separator. */
1349 /* Wrap the last separator if it is before a button. */
1350 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1351 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1352 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1353 i
< infoPtr
->nNumButtons
)
1359 if( bFound
&& i
< infoPtr
->nNumButtons
)
1362 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1363 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1364 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1365 x
= infoPtr
->nIndent
;
1366 bButtonWrap
= FALSE
;
1369 else if ( i
>= infoPtr
->nNumButtons
)
1372 /* If the current button is not a separator, find the last */
1373 /* separator and wrap it. */
1374 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1376 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1377 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1381 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1382 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1383 x
= infoPtr
->nIndent
;
1384 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1385 bButtonWrap
= FALSE
;
1390 /* If no separator available for wrapping, wrap one of */
1391 /* non-hidden previous button. */
1395 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1397 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1402 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1403 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1404 x
= infoPtr
->nIndent
;
1405 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1411 /* If all above failed, wrap the current button. */
1414 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1415 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1416 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1417 x
= infoPtr
->nIndent
;
1418 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1419 bButtonWrap
= FALSE
;
1425 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1426 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1433 /***********************************************************************
1434 * TOOLBAR_MeasureButton
1436 * Calculates the width and height required for a button. Used in
1437 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1438 * the width of buttons that are autosized.
1440 * Note that it would have been rather elegant to use one piece of code for
1441 * both the laying out of the toolbar and for controlling where button parts
1442 * are drawn, but the native control has inconsistencies between the two that
1443 * prevent this from being effectively. These inconsistencies can be seen as
1444 * artefacts where parts of the button appear outside of the bounding button
1447 * There are several cases for the calculation of the button dimensions and
1448 * button part positioning:
1455 * +--------------------------------------------------------+ ^
1457 * | | pad.cy / 2 | centered | |
1458 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1459 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1460 * | |<------------>| | | | |
1461 * | +--------------+ +------------+ | |
1462 * |<-------------------------------------->| | |
1463 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1465 * +--------------------------------------------------------+ -
1466 * <-------------------------------------------------------->
1467 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1469 * Without Bitmap (I_IMAGENONE):
1471 * +-----------------------------------+ ^
1473 * | | centered | | LISTPAD_CY +
1474 * | +------------+ | | szText.cy
1477 * | +------------+ | |
1478 * |<----------------->| | |
1479 * | cxedge |<-----------> | |
1481 * +-----------------------------------+ -
1482 * <----------------------------------->
1483 * szText.cx + pad.cx
1487 * +--------------------------------------+ ^
1489 * | | padding.cy/2 | | DEFPAD_CY +
1490 * | +------------+ | | nBitmapHeight
1493 * | +------------+ | |
1494 * |<------------------->| | |
1495 * | cxedge + iListGap/2 |<-----------> | |
1496 * | nBitmapWidth | |
1497 * +--------------------------------------+ -
1498 * <-------------------------------------->
1499 * 2*cxedge + nBitmapWidth + iListGap
1506 * +-----------------------------------+ ^
1508 * | | pad.cy / 2 | | nBitmapHeight +
1509 * | - | | szText.cy +
1510 * | +------------+ | | DEFPAD_CY + 1
1511 * | centered | Bitmap | | |
1512 * |<----------------->| | | |
1513 * | +------------+ | |
1517 * | centered +---------------+ | |
1518 * |<--------------->| Text | | |
1519 * | +---------------+ | |
1520 * +-----------------------------------+ -
1521 * <----------------------------------->
1522 * pad.cx + max(nBitmapWidth, szText.cx)
1524 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1526 * +---------------------------------------+ ^
1528 * | | 2 + pad.cy / 2 | |
1529 * | - | | szText.cy +
1530 * | centered +-----------------+ | | pad.cy + 2
1531 * |<--------------->| Text | | |
1532 * | +-----------------+ | |
1534 * +---------------------------------------+ -
1535 * <--------------------------------------->
1536 * 2*cxedge + pad.cx + szText.cx
1539 * As for with bitmaps, but with szText.cx zero.
1541 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1542 BOOL bHasBitmap
, BOOL bValidImageList
)
1545 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1547 /* set button height from bitmap / text height... */
1548 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1551 /* ... add on the necessary padding */
1552 if (bValidImageList
)
1555 sizeButton
.cy
+= DEFPAD_CY
;
1557 sizeButton
.cy
+= LISTPAD_CY
;
1560 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1562 /* calculate button width */
1563 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1564 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1565 if (sizeString
.cx
> 0)
1566 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1573 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1574 if (sizeString
.cy
> 0)
1575 sizeButton
.cy
+= 1 + sizeString
.cy
;
1576 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1577 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1581 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1582 NONLIST_NOTEXT_OFFSET
;
1583 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1584 max(2*GetSystemMetrics(SM_CXEDGE
) + sizeString
.cx
, infoPtr
->nBitmapWidth
);
1591 /***********************************************************************
1592 * TOOLBAR_CalcToolbar
1594 * This function calculates button and separator placement. It first
1595 * calculates the button sizes, gets the toolbar window width and then
1596 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1597 * on. It assigns a new location to each item and sends this location to
1598 * the tooltip window if appropriate. Finally, it updates the rcBound
1599 * rect and calculates the new required toolbar window height.
1602 TOOLBAR_CalcToolbar (TOOLBAR_INFO
*infoPtr
)
1604 SIZE sizeString
, sizeButton
;
1605 BOOL validImageList
= FALSE
;
1607 TOOLBAR_CalcStrings (infoPtr
, &sizeString
);
1609 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1611 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1612 validImageList
= TRUE
;
1613 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1614 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1615 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1616 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1618 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1619 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1620 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1621 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1623 TOOLBAR_LayoutToolbar(infoPtr
);
1627 TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
)
1629 TBUTTON_INFO
*btnPtr
;
1631 INT i
, nRows
, nSepRows
;
1634 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1635 BOOL hasDropDownArrows
= TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
);
1637 TOOLBAR_WrapToolbar(infoPtr
);
1639 x
= infoPtr
->nIndent
;
1640 y
= infoPtr
->iTopMargin
;
1641 cx
= infoPtr
->nButtonWidth
;
1642 cy
= infoPtr
->nButtonHeight
;
1644 nRows
= nSepRows
= 0;
1646 infoPtr
->rcBound
.top
= y
;
1647 infoPtr
->rcBound
.left
= x
;
1648 infoPtr
->rcBound
.bottom
= y
+ cy
;
1649 infoPtr
->rcBound
.right
= x
;
1651 btnPtr
= infoPtr
->buttons
;
1653 TRACE("cy=%d\n", cy
);
1655 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1658 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1660 SetRectEmpty (&btnPtr
->rect
);
1664 cy
= infoPtr
->nButtonHeight
;
1666 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1667 if (infoPtr
->dwStyle
& CCS_VERT
) {
1668 cy
= (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1669 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
: infoPtr
->nButtonWidth
;
1672 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
:
1673 (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1679 else if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1680 (btnPtr
->fsStyle
& BTNS_AUTOSIZE
))
1686 hdc
= GetDC (infoPtr
->hwndSelf
);
1687 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1689 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1691 SelectObject (hdc
, hOldFont
);
1692 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1694 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1695 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1700 cx
= infoPtr
->nButtonWidth
;
1702 /* if size has been set manually then don't add on extra space
1703 * for the drop down arrow */
1704 if (!btnPtr
->cx
&& hasDropDownArrows
&&
1705 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) || (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)))
1706 cx
+= DDARROW_WIDTH
;
1708 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1711 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1713 if (infoPtr
->rcBound
.left
> x
)
1714 infoPtr
->rcBound
.left
= x
;
1715 if (infoPtr
->rcBound
.right
< x
+ cx
)
1716 infoPtr
->rcBound
.right
= x
+ cx
;
1717 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1718 infoPtr
->rcBound
.bottom
= y
+ cy
;
1720 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1722 /* btnPtr->nRow is zero based. The space between the rows is */
1723 /* also considered as a row. */
1724 btnPtr
->nRow
= nRows
+ nSepRows
;
1726 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1727 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1732 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1736 if ( !(infoPtr
->dwStyle
& CCS_VERT
))
1737 y
+= cy
+ ( (btnPtr
->cx
> 0 ) ?
1738 btnPtr
->cx
: SEPARATOR_WIDTH
) * 2 /3;
1742 /* nSepRows is used to calculate the extra height following */
1746 x
= infoPtr
->nIndent
;
1748 /* Increment row number unless this is the last button */
1749 /* and it has Wrap set. */
1750 if (i
!= infoPtr
->nNumButtons
-1)
1757 /* infoPtr->nRows is the number of rows on the toolbar */
1758 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1760 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1765 TOOLBAR_InternalHitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
*lpPt
, BOOL
*button
)
1767 TBUTTON_INFO
*btnPtr
;
1773 btnPtr
= infoPtr
->buttons
;
1774 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1775 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1778 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1779 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1780 TRACE(" ON SEPARATOR %d!\n", i
);
1785 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1786 TRACE(" ON BUTTON %d!\n", i
);
1794 TRACE(" NOWHERE!\n");
1795 return TOOLBAR_NOWHERE
;
1799 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1801 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO
*infoPtr
, INT iIndex
, UINT nAddButtons
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
1803 INT nOldButtons
, nNewButtons
, iButton
;
1804 BOOL fHasString
= FALSE
;
1806 if (iIndex
< 0) /* iIndex can be negative, what means adding at the end */
1807 iIndex
= infoPtr
->nNumButtons
;
1809 nOldButtons
= infoPtr
->nNumButtons
;
1810 nNewButtons
= nOldButtons
+ nAddButtons
;
1812 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
1813 memmove(&infoPtr
->buttons
[iIndex
+ nAddButtons
], &infoPtr
->buttons
[iIndex
],
1814 (nOldButtons
- iIndex
) * sizeof(TBUTTON_INFO
));
1815 infoPtr
->nNumButtons
+= nAddButtons
;
1817 /* insert new buttons data */
1818 for (iButton
= 0; iButton
< nAddButtons
; iButton
++) {
1819 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[iIndex
+ iButton
];
1821 TOOLBAR_DumpTBButton(lpTbb
+ iButton
, fUnicode
);
1823 ZeroMemory(btnPtr
, sizeof(*btnPtr
));
1825 btnPtr
->iBitmap
= lpTbb
[iButton
].iBitmap
;
1826 btnPtr
->idCommand
= lpTbb
[iButton
].idCommand
;
1827 btnPtr
->fsState
= lpTbb
[iButton
].fsState
;
1828 btnPtr
->fsStyle
= lpTbb
[iButton
].fsStyle
;
1829 btnPtr
->dwData
= lpTbb
[iButton
].dwData
;
1830 if (btnPtr
->fsStyle
& BTNS_SEP
)
1831 btnPtr
->iString
= -1;
1832 else if(!IS_INTRESOURCE(lpTbb
[iButton
].iString
) && lpTbb
[iButton
].iString
!= -1)
1835 Str_SetPtrW((LPWSTR
*)&btnPtr
->iString
, (LPWSTR
)lpTbb
[iButton
].iString
);
1837 Str_SetPtrAtoW((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lpTbb
[iButton
].iString
);
1841 btnPtr
->iString
= lpTbb
[iButton
].iString
;
1843 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
1846 if (infoPtr
->nNumStrings
> 0 || fHasString
)
1847 TOOLBAR_CalcToolbar(infoPtr
);
1849 TOOLBAR_LayoutToolbar(infoPtr
);
1850 TOOLBAR_AutoSize(infoPtr
);
1852 TOOLBAR_DumpToolbar(infoPtr
, __LINE__
);
1853 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1859 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1861 TBUTTON_INFO
*btnPtr
;
1864 if (CommandIsIndex
) {
1865 TRACE("command is really index command=%d\n", idCommand
);
1866 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1869 btnPtr
= infoPtr
->buttons
;
1870 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1871 if (btnPtr
->idCommand
== idCommand
) {
1872 TRACE("command=%d index=%d\n", idCommand
, i
);
1876 TRACE("no index found for command=%d\n", idCommand
);
1882 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1884 TBUTTON_INFO
*btnPtr
;
1887 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1890 /* check index button */
1891 btnPtr
= &infoPtr
->buttons
[nIndex
];
1892 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1893 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1897 /* check previous buttons */
1898 nRunIndex
= nIndex
- 1;
1899 while (nRunIndex
>= 0) {
1900 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1901 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1902 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1910 /* check next buttons */
1911 nRunIndex
= nIndex
+ 1;
1912 while (nRunIndex
< infoPtr
->nNumButtons
) {
1913 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1914 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1915 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1928 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1929 WPARAM wParam
, LPARAM lParam
)
1935 msg
.wParam
= wParam
;
1936 msg
.lParam
= lParam
;
1937 msg
.time
= GetMessageTime ();
1938 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
1939 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
1941 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1945 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1947 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
1950 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
1951 ti
.cbSize
= sizeof (TTTOOLINFOW
);
1952 ti
.hwnd
= infoPtr
->hwndSelf
;
1953 ti
.uId
= button
->idCommand
;
1955 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
1956 /* ti.lParam = random value from the stack? */
1958 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
1964 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1966 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
1969 ZeroMemory(&ti
, sizeof(ti
));
1970 ti
.cbSize
= sizeof(ti
);
1971 ti
.hwnd
= infoPtr
->hwndSelf
;
1972 ti
.uId
= button
->idCommand
;
1974 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
1978 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1980 /* Set the toolTip only for non-hidden, non-separator button */
1981 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
1985 ZeroMemory(&ti
, sizeof(ti
));
1986 ti
.cbSize
= sizeof(ti
);
1987 ti
.hwnd
= infoPtr
->hwndSelf
;
1988 ti
.uId
= button
->idCommand
;
1989 ti
.rect
= button
->rect
;
1990 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
1994 /* Creates the tooltip control */
1996 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
1999 NMTOOLTIPSCREATED nmttc
;
2001 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
2002 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2003 infoPtr
->hwndSelf
, 0, 0, 0);
2005 if (!infoPtr
->hwndToolTip
)
2008 /* Send NM_TOOLTIPSCREATED notification */
2009 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
2010 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
2012 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
2014 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
2015 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
2019 /* keeps available button list box sorted by button id */
2020 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
2024 PCUSTOMBUTTON btnInfo
;
2025 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2027 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
2029 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2031 /* position 0 is always separator */
2032 for (i
= 1; i
< count
; i
++)
2034 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2035 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2037 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2038 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2042 /* id higher than all others add to end */
2043 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2044 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2047 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2051 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2053 if (nIndexFrom
== nIndexTo
)
2056 /* MSDN states that iItem is the index of the button, rather than the
2057 * command ID as used by every other NMTOOLBAR notification */
2058 nmtb
.iItem
= nIndexFrom
;
2059 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2061 PCUSTOMBUTTON btnInfo
;
2063 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2064 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2066 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2068 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2069 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2070 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2071 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2074 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2076 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2078 /* last item is always separator, so -2 instead of -1 */
2079 if (nIndexTo
>= (count
- 2))
2080 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2082 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2084 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2085 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2087 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2091 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2095 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2097 /* MSDN states that iItem is the index of the button, rather than the
2098 * command ID as used by every other NMTOOLBAR notification */
2099 nmtb
.iItem
= nIndexAvail
;
2100 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2102 PCUSTOMBUTTON btnInfo
;
2104 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2105 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2106 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2108 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2110 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2112 /* remove from 'available buttons' list */
2113 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2114 if (nIndexAvail
== count
-1)
2115 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2117 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2121 PCUSTOMBUTTON btnNew
;
2123 /* duplicate 'separator' button */
2124 btnNew
= Alloc(sizeof(CUSTOMBUTTON
));
2129 /* insert into 'toolbar button' list */
2130 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2131 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2133 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2135 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2139 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2141 PCUSTOMBUTTON btnInfo
;
2142 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2144 TRACE("Remove: index %d\n", index
);
2146 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2148 /* send TBN_QUERYDELETE notification */
2149 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2153 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2154 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2156 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2158 /* insert into 'available button' list */
2159 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2160 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2164 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2168 /* drag list notification function for toolbar buttons list box */
2169 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2170 const DRAGLISTINFO
*pDLI
)
2172 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2173 switch (pDLI
->uNotification
)
2177 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2178 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2179 /* no dragging for last item (separator) */
2180 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2185 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2186 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2187 /* no dragging past last item (separator) */
2188 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2190 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2191 /* FIXME: native uses "move button" cursor */
2192 return DL_COPYCURSOR
;
2195 /* not over toolbar buttons list */
2196 if (nCurrentItem
< 0)
2198 POINT ptWindow
= pDLI
->ptCursor
;
2199 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2200 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2201 /* over available buttons list? */
2202 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2203 /* FIXME: native uses "move button" cursor */
2204 return DL_COPYCURSOR
;
2206 /* clear drag arrow */
2207 DrawInsert(hwnd
, hwndList
, -1);
2208 return DL_STOPCURSOR
;
2212 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2213 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2214 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2215 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2217 /* clear drag arrow */
2218 DrawInsert(hwnd
, hwndList
, -1);
2220 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2222 /* not over toolbar buttons list */
2225 POINT ptWindow
= pDLI
->ptCursor
;
2226 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2227 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2228 /* over available buttons list? */
2229 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2230 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2235 /* Clear drag arrow */
2236 DrawInsert(hwnd
, hwndList
, -1);
2243 /* drag list notification function for available buttons list box */
2244 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2245 const DRAGLISTINFO
*pDLI
)
2247 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2248 switch (pDLI
->uNotification
)
2254 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2255 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2256 /* no dragging past last item (separator) */
2257 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2259 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2260 /* FIXME: native uses "move button" cursor */
2261 return DL_COPYCURSOR
;
2264 /* not over toolbar buttons list */
2265 if (nCurrentItem
< 0)
2267 POINT ptWindow
= pDLI
->ptCursor
;
2268 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2269 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2270 /* over available buttons list? */
2271 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2272 /* FIXME: native uses "move button" cursor */
2273 return DL_COPYCURSOR
;
2275 /* clear drag arrow */
2276 DrawInsert(hwnd
, hwndList
, -1);
2277 return DL_STOPCURSOR
;
2281 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2282 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2283 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2284 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2286 /* clear drag arrow */
2287 DrawInsert(hwnd
, hwndList
, -1);
2289 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2293 /* Clear drag arrow */
2294 DrawInsert(hwnd
, hwndList
, -1);
2300 extern UINT uDragListMessage DECLSPEC_HIDDEN
;
2302 /***********************************************************************
2303 * TOOLBAR_CustomizeDialogProc
2304 * This function implements the toolbar customization dialog.
2306 static INT_PTR CALLBACK
2307 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2309 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2310 PCUSTOMBUTTON btnInfo
;
2312 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2317 custInfo
= (PCUSTDLG_INFO
)lParam
;
2318 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2325 NMTBINITCUSTOMIZE nmtbic
;
2327 infoPtr
= custInfo
->tbInfo
;
2329 /* send TBN_QUERYINSERT notification */
2330 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2332 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2335 nmtbic
.hwndDialog
= hwnd
;
2336 /* Send TBN_INITCUSTOMIZE notification */
2337 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2340 TRACE("TBNRF_HIDEHELP requested\n");
2341 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2344 /* add items to 'toolbar buttons' list and check if removable */
2345 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2347 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2348 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2349 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2350 btnInfo
->bVirtual
= FALSE
;
2351 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2353 /* send TBN_QUERYDELETE notification */
2354 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2356 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2357 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2360 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2362 /* insert separator button into 'available buttons' list */
2363 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2364 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2365 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2366 btnInfo
->bVirtual
= FALSE
;
2367 btnInfo
->bRemovable
= TRUE
;
2368 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2369 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2370 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2372 /* insert all buttons into dsa */
2375 /* send TBN_GETBUTTONINFO notification */
2378 nmtb
.pszText
= Buffer
;
2381 /* Clear previous button's text */
2382 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2384 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2387 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2388 nmtb
.tbButton
.fsStyle
, i
,
2389 nmtb
.tbButton
.idCommand
,
2390 nmtb
.tbButton
.iString
,
2391 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2394 /* insert button into the appropriate list */
2395 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2398 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2399 btnInfo
->bVirtual
= FALSE
;
2400 btnInfo
->bRemovable
= TRUE
;
2404 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2405 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2408 btnInfo
->btn
= nmtb
.tbButton
;
2409 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2411 if (lstrlenW(nmtb
.pszText
))
2412 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2413 else if (nmtb
.tbButton
.iString
>= 0 &&
2414 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2416 lstrcpyW(btnInfo
->text
,
2417 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2422 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2425 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2427 /* select first item in the 'available' list */
2428 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2430 /* append 'virtual' separator button to the 'toolbar buttons' list */
2431 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2432 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2433 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2434 btnInfo
->bVirtual
= TRUE
;
2435 btnInfo
->bRemovable
= FALSE
;
2436 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2437 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2438 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2440 /* select last item in the 'toolbar' list */
2441 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2442 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2444 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2445 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2447 /* set focus and disable buttons */
2448 PostMessageW (hwnd
, WM_USER
, 0, 0);
2453 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2454 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2455 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2456 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2460 EndDialog(hwnd
, FALSE
);
2464 switch (LOWORD(wParam
))
2466 case IDC_TOOLBARBTN_LBOX
:
2467 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2469 PCUSTOMBUTTON btnInfo
;
2474 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2475 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2477 /* send TBN_QUERYINSERT notification */
2479 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2481 /* get list box item */
2482 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2484 if (index
== (count
- 1))
2486 /* last item (virtual separator) */
2487 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2488 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2490 else if (index
== (count
- 2))
2492 /* second last item (last non-virtual item) */
2493 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2494 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2496 else if (index
== 0)
2499 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2500 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2504 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2505 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2508 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2512 case IDC_MOVEUP_BTN
:
2514 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2515 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2519 case IDC_MOVEDN_BTN
: /* move down */
2521 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2522 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2526 case IDC_REMOVE_BTN
: /* remove button */
2528 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2530 if (LB_ERR
== index
)
2533 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2537 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2540 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2543 case IDOK
: /* Add button */
2548 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2549 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2551 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2556 EndDialog(hwnd
, FALSE
);
2566 /* delete items from 'toolbar buttons' listbox*/
2567 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2568 for (i
= 0; i
< count
; i
++)
2570 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2572 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2574 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2577 /* delete items from 'available buttons' listbox*/
2578 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2579 for (i
= 0; i
< count
; i
++)
2581 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2583 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2585 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2590 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2592 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2597 COLORREF oldText
= 0;
2601 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, lpdis
->itemID
, 0);
2602 if (btnInfo
== NULL
)
2604 FIXME("btnInfo invalid!\n");
2608 /* set colors and select objects */
2609 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2610 if (btnInfo
->bVirtual
)
2611 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2613 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2614 hPen
= CreatePen( PS_SOLID
, 1,
2615 (lpdis
->itemState
& ODS_SELECTED
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2616 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2617 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2619 /* fill background rectangle */
2620 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2621 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2623 /* calculate button and text rectangles */
2624 CopyRect (&rcButton
, &lpdis
->rcItem
);
2625 InflateRect (&rcButton
, -1, -1);
2626 CopyRect (&rcText
, &rcButton
);
2627 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2628 rcText
.left
= rcButton
.right
+ 2;
2630 /* draw focus rectangle */
2631 if (lpdis
->itemState
& ODS_FOCUS
)
2632 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2635 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2636 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2638 /* draw image and text */
2639 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2640 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2641 btnInfo
->btn
.iBitmap
));
2642 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2643 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2645 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2646 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2648 /* delete objects and reset colors */
2649 SelectObject (lpdis
->hDC
, hOldBrush
);
2650 SelectObject (lpdis
->hDC
, hOldPen
);
2651 SetBkColor (lpdis
->hDC
, oldBk
);
2652 SetTextColor (lpdis
->hDC
, oldText
);
2653 DeleteObject( hPen
);
2658 case WM_MEASUREITEM
:
2659 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2661 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2663 lpmis
->itemHeight
= 15 + 8; /* default height */
2670 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2672 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2674 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2675 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2676 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2679 else if (wParam
== IDC_AVAILBTN_LBOX
)
2681 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2682 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2683 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2692 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2695 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2701 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2702 /* Add bitmaps to the default image list */
2703 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2704 hbmLoad
= CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2705 else if (bitmap
->hInst
== COMCTL32_hModule
)
2706 hbmLoad
= LoadImageW( bitmap
->hInst
, MAKEINTRESOURCEW(bitmap
->nID
),
2707 IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
2709 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2711 /* enlarge the bitmap if needed */
2712 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2713 if (bitmap
->hInst
!= COMCTL32_hModule
)
2714 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2716 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2717 DeleteObject(hbmLoad
);
2721 nCountAfter
= ImageList_GetImageCount(himlDef
);
2722 nAdded
= nCountAfter
- nCountBefore
;
2723 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2725 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2726 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2727 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2728 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2731 infoPtr
->nNumBitmaps
+= nAdded
;
2736 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2743 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2744 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2746 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2748 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2751 TRACE("Update icon size: %dx%d -> %dx%d\n",
2752 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2754 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2755 ILC_COLOR32
|ILC_MASK
, 8, 2);
2756 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2757 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2758 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2759 infoPtr
->himlInt
= himlNew
;
2761 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2762 ImageList_Destroy(himlDef
);
2765 /***********************************************************************
2766 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2770 TOOLBAR_AddBitmap (TOOLBAR_INFO
*infoPtr
, INT count
, const TBADDBITMAP
*lpAddBmp
)
2776 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr
->hwndSelf
, count
, lpAddBmp
);
2780 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2782 info
.hInst
= COMCTL32_hModule
;
2783 switch (lpAddBmp
->nID
)
2785 case IDB_STD_SMALL_COLOR
:
2787 info
.nID
= IDB_STD_SMALL
;
2789 case IDB_STD_LARGE_COLOR
:
2791 info
.nID
= IDB_STD_LARGE
;
2793 case IDB_VIEW_SMALL_COLOR
:
2795 info
.nID
= IDB_VIEW_SMALL
;
2797 case IDB_VIEW_LARGE_COLOR
:
2799 info
.nID
= IDB_VIEW_LARGE
;
2801 case IDB_HIST_SMALL_COLOR
:
2803 info
.nID
= IDB_HIST_SMALL
;
2805 case IDB_HIST_LARGE_COLOR
:
2807 info
.nID
= IDB_HIST_LARGE
;
2813 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2815 /* Windows resize all the buttons to the size of a newly added standard image */
2816 if (lpAddBmp
->nID
& 1)
2818 /* large icons: 24x24. Will make the button 31x30 */
2819 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2823 /* small icons: 16x16. Will make the buttons 23x22 */
2824 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2827 TOOLBAR_CalcToolbar (infoPtr
);
2831 info
.nButtons
= count
;
2832 info
.hInst
= lpAddBmp
->hInst
;
2833 info
.nID
= lpAddBmp
->nID
;
2834 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2837 /* check if the bitmap is already loaded and compute iSumButtons */
2839 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2841 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2842 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2844 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2847 if (!infoPtr
->cimlDef
) {
2848 /* create new default image list */
2849 TRACE ("creating default image list!\n");
2851 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2852 ILC_COLOR32
| ILC_MASK
, info
.nButtons
, 2);
2853 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2854 infoPtr
->himlInt
= himlDef
;
2857 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2861 WARN("No default image list available\n");
2865 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2868 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2869 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2870 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2871 infoPtr
->nNumBitmapInfos
++;
2872 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2874 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2880 TOOLBAR_AddButtonsT(TOOLBAR_INFO
*infoPtr
, INT nAddButtons
, const TBBUTTON
* lpTbb
, BOOL fUnicode
)
2882 TRACE("adding %d buttons (unicode=%d)!\n", nAddButtons
, fUnicode
);
2884 return TOOLBAR_InternalInsertButtonsT(infoPtr
, -1, nAddButtons
, lpTbb
, fUnicode
);
2889 TOOLBAR_AddStringW (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
2891 #define MAX_RESOURCE_STRING_LENGTH 512
2892 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2893 INT nIndex
= infoPtr
->nNumStrings
;
2895 TRACE("%p, %lx\n", hInstance
, lParam
);
2897 if (IS_INTRESOURCE(lParam
)) {
2898 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2905 TRACE("adding string from resource\n");
2907 if (!hInstance
) return -1;
2909 hrsrc
= FindResourceW( hInstance
, MAKEINTRESOURCEW((LOWORD(lParam
) >> 4) + 1),
2910 (LPWSTR
)RT_STRING
);
2913 TRACE("string not found in resources\n");
2917 len
= LoadStringW (hInstance
, (UINT
)lParam
,
2918 szString
, MAX_RESOURCE_STRING_LENGTH
);
2920 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2921 if (len
== 0 || len
== 1)
2924 TRACE("delimiter: 0x%x\n", *szString
);
2925 delimiter
= *szString
;
2928 while ((next_delim
= strchrW(p
, delimiter
)) != NULL
) {
2930 if (next_delim
+ 1 >= szString
+ len
)
2932 /* this may happen if delimiter == '\0' or if the last char is a
2933 * delimiter (then it is ignored like the native does) */
2937 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2938 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2939 infoPtr
->nNumStrings
++;
2945 LPWSTR p
= (LPWSTR
)lParam
;
2950 TRACE("adding string(s) from array\n");
2954 TRACE("len=%d %s\n", len
, debugstr_w(p
));
2955 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2956 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2957 infoPtr
->nNumStrings
++;
2964 TOOLBAR_CalcToolbar(infoPtr
);
2970 TOOLBAR_AddStringA (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
2972 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2977 TRACE("%p, %lx\n", hInstance
, lParam
);
2979 if (IS_INTRESOURCE(lParam
)) /* load from resources */
2980 return TOOLBAR_AddStringW(infoPtr
, hInstance
, lParam
);
2986 TRACE("adding string(s) from array\n");
2987 nIndex
= infoPtr
->nNumStrings
;
2990 TRACE("len=%d \"%s\"\n", len
, p
);
2992 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2993 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2994 infoPtr
->nNumStrings
++;
3000 TOOLBAR_CalcToolbar(infoPtr
);
3006 TOOLBAR_AutoSize (TOOLBAR_INFO
*infoPtr
)
3013 TRACE("auto sizing, style=%x!\n", infoPtr
->dwStyle
);
3015 parent
= GetParent (infoPtr
->hwndSelf
);
3017 if (!parent
|| !infoPtr
->bDoRedraw
)
3020 GetClientRect(parent
, &parent_rect
);
3022 x
= parent_rect
.left
;
3023 y
= parent_rect
.top
;
3025 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3027 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3028 cx
= parent_rect
.right
- parent_rect
.left
;
3030 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
))
3032 TOOLBAR_LayoutToolbar(infoPtr
);
3033 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
3036 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3039 UINT uPosFlags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
3041 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3043 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3044 MapWindowPoints( 0, parent
, (POINT
*)&window_rect
, 2 );
3045 y
= window_rect
.top
;
3047 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3049 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3050 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3053 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3054 uPosFlags
|= SWP_NOMOVE
;
3056 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3057 cy
+= GetSystemMetrics(SM_CYEDGE
);
3059 if (infoPtr
->dwStyle
& WS_BORDER
)
3061 cx
+= 2 * GetSystemMetrics(SM_CXBORDER
);
3062 cy
+= 2 * GetSystemMetrics(SM_CYBORDER
);
3065 SetWindowPos(infoPtr
->hwndSelf
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3072 static inline LRESULT
3073 TOOLBAR_ButtonCount (const TOOLBAR_INFO
*infoPtr
)
3075 return infoPtr
->nNumButtons
;
3079 static inline LRESULT
3080 TOOLBAR_ButtonStructSize (TOOLBAR_INFO
*infoPtr
, DWORD Size
)
3082 infoPtr
->dwStructSize
= Size
;
3089 TOOLBAR_ChangeBitmap (TOOLBAR_INFO
*infoPtr
, INT Id
, INT Index
)
3091 TBUTTON_INFO
*btnPtr
;
3094 TRACE("button %d, iBitmap now %d\n", Id
, Index
);
3096 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3100 btnPtr
= &infoPtr
->buttons
[nIndex
];
3101 btnPtr
->iBitmap
= Index
;
3103 /* we HAVE to erase the background, the new bitmap could be */
3105 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3112 TOOLBAR_CheckButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3114 TBUTTON_INFO
*btnPtr
;
3117 BOOL bChecked
= FALSE
;
3119 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3121 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, nIndex
, lParam
);
3126 btnPtr
= &infoPtr
->buttons
[nIndex
];
3128 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) != 0;
3130 if (LOWORD(lParam
) == FALSE
)
3131 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3133 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3135 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3136 if (nOldIndex
== nIndex
)
3138 if (nOldIndex
!= -1)
3139 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3141 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3144 if( bChecked
!= LOWORD(lParam
) )
3146 if (nOldIndex
!= -1)
3147 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3148 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3151 /* FIXME: Send a WM_NOTIFY?? */
3158 TOOLBAR_CommandToIndex (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3160 return TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3165 TOOLBAR_Customize (TOOLBAR_INFO
*infoPtr
)
3167 CUSTDLG_INFO custInfo
;
3171 custInfo
.tbInfo
= infoPtr
;
3172 custInfo
.tbHwnd
= infoPtr
->hwndSelf
;
3174 /* send TBN_BEGINADJUST notification */
3175 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3177 ret
= DialogBoxParamW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3178 infoPtr
->hwndSelf
, TOOLBAR_CustomizeDialogProc
, (LPARAM
)&custInfo
);
3180 /* send TBN_ENDADJUST notification */
3181 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3188 TOOLBAR_DeleteButton (TOOLBAR_INFO
*infoPtr
, INT nIndex
)
3191 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3193 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3196 memset(&nmtb
, 0, sizeof(nmtb
));
3197 nmtb
.iItem
= btnPtr
->idCommand
;
3198 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3199 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3200 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3201 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3202 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3203 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3204 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3206 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3208 if (infoPtr
->nNumButtons
== 1) {
3209 TRACE(" simple delete!\n");
3210 if (TOOLBAR_ButtonHasString(infoPtr
->buttons
))
3211 Free((LPWSTR
)infoPtr
->buttons
[0].iString
);
3212 Free (infoPtr
->buttons
);
3213 infoPtr
->buttons
= NULL
;
3214 infoPtr
->nNumButtons
= 0;
3217 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3218 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3220 infoPtr
->nNumButtons
--;
3221 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3223 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3224 nIndex
* sizeof(TBUTTON_INFO
));
3227 if (nIndex
< infoPtr
->nNumButtons
) {
3228 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3229 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3232 if (TOOLBAR_ButtonHasString(&oldButtons
[nIndex
]))
3233 Free((LPWSTR
)oldButtons
[nIndex
].iString
);
3237 TOOLBAR_LayoutToolbar(infoPtr
);
3239 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3246 TOOLBAR_EnableButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3248 TBUTTON_INFO
*btnPtr
;
3252 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3254 TRACE("hwnd=%p, btn id=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, Id
, lParam
);
3259 btnPtr
= &infoPtr
->buttons
[nIndex
];
3261 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3263 /* update the toolbar button state */
3264 if(LOWORD(lParam
) == FALSE
) {
3265 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3267 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3270 /* redraw the button only if the state of the button changed */
3271 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3272 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3278 static inline LRESULT
3279 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO
*infoPtr
)
3281 return infoPtr
->bAnchor
;
3286 TOOLBAR_GetBitmap (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3290 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3294 return infoPtr
->buttons
[nIndex
].iBitmap
;
3298 static inline LRESULT
3299 TOOLBAR_GetBitmapFlags (void)
3301 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3306 TOOLBAR_GetButton (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, TBBUTTON
*lpTbb
)
3308 TBUTTON_INFO
*btnPtr
;
3313 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3316 btnPtr
= &infoPtr
->buttons
[nIndex
];
3317 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3318 lpTbb
->idCommand
= btnPtr
->idCommand
;
3319 lpTbb
->fsState
= btnPtr
->fsState
;
3320 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3321 lpTbb
->bReserved
[0] = 0;
3322 lpTbb
->bReserved
[1] = 0;
3323 lpTbb
->dwData
= btnPtr
->dwData
;
3324 lpTbb
->iString
= btnPtr
->iString
;
3331 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO
*infoPtr
, INT Id
, LPTBBUTTONINFOW lpTbInfo
, BOOL bUnicode
)
3333 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3334 TBUTTON_INFO
*btnPtr
;
3337 if (lpTbInfo
== NULL
)
3340 /* MSDN documents an iImageLabel field added in Vista but it is not present in
3341 * the headers and tests shows that even with comctl 6 Vista accepts only the
3342 * original TBBUTTONINFO size
3344 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3346 WARN("Invalid button size\n");
3350 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lpTbInfo
->dwMask
& TBIF_BYINDEX
);
3354 if (!(btnPtr
= &infoPtr
->buttons
[nIndex
])) return -1;
3356 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3357 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3358 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3359 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3360 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3361 lpTbInfo
->lParam
= btnPtr
->dwData
;
3362 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3363 /* tests show that for separators TBIF_SIZE returns not calculated width,
3364 but cx property, that differs from 0 only if application have
3365 specifically set it */
3366 lpTbInfo
->cx
= (btnPtr
->fsStyle
& BTNS_SEP
)
3367 ? btnPtr
->cx
: (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3368 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3369 lpTbInfo
->fsState
= btnPtr
->fsState
;
3370 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3371 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3372 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3373 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3374 can't use TOOLBAR_GetText here */
3375 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3376 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3378 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3380 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3382 lpTbInfo
->pszText
[0] = '\0';
3388 static inline LRESULT
3389 TOOLBAR_GetButtonSize (const TOOLBAR_INFO
*infoPtr
)
3391 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3392 (WORD
)infoPtr
->nButtonHeight
);
3397 TOOLBAR_GetButtonText (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPWSTR lpStr
, BOOL isW
)
3403 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3407 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3413 ret
= strlenW (lpText
);
3414 if (lpStr
) strcpyW (lpStr
, lpText
);
3418 ret
= WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3419 (LPSTR
)lpStr
, lpStr
? 0x7fffffff : 0, NULL
, NULL
) - 1;
3425 TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3427 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3428 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3429 return (LRESULT
)GETDISIMAGELIST(infoPtr
, wParam
);
3433 static inline LRESULT
3434 TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO
*infoPtr
)
3438 return infoPtr
->dwExStyle
;
3443 TOOLBAR_GetHotImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3445 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3446 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3447 return (LRESULT
)GETHOTIMAGELIST(infoPtr
, wParam
);
3452 TOOLBAR_GetHotItem (const TOOLBAR_INFO
*infoPtr
)
3454 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3457 if (infoPtr
->nHotItem
< 0)
3460 return (LRESULT
)infoPtr
->nHotItem
;
3465 TOOLBAR_GetDefImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3467 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3468 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3469 return (LRESULT
) GETDEFIMAGELIST(infoPtr
, wParam
);
3474 TOOLBAR_GetInsertMark (const TOOLBAR_INFO
*infoPtr
, TBINSERTMARK
*lptbim
)
3476 TRACE("hwnd = %p, lptbim = %p\n", infoPtr
->hwndSelf
, lptbim
);
3478 *lptbim
= infoPtr
->tbim
;
3484 static inline LRESULT
3485 TOOLBAR_GetInsertMarkColor (const TOOLBAR_INFO
*infoPtr
)
3487 TRACE("hwnd = %p\n", infoPtr
->hwndSelf
);
3489 return (LRESULT
)infoPtr
->clrInsertMark
;
3494 TOOLBAR_GetItemRect (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, LPRECT lpRect
)
3496 TBUTTON_INFO
*btnPtr
;
3498 btnPtr
= &infoPtr
->buttons
[nIndex
];
3499 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3504 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3507 lpRect
->left
= btnPtr
->rect
.left
;
3508 lpRect
->right
= btnPtr
->rect
.right
;
3509 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3510 lpRect
->top
= btnPtr
->rect
.top
;
3517 TOOLBAR_GetMaxSize (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
3522 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3523 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3525 TRACE("maximum size %d x %d\n",
3526 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3527 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3533 /* << TOOLBAR_GetObject >> */
3536 static inline LRESULT
3537 TOOLBAR_GetPadding (const TOOLBAR_INFO
*infoPtr
)
3539 return MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3544 TOOLBAR_GetRect (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPRECT lpRect
)
3546 TBUTTON_INFO
*btnPtr
;
3549 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3550 btnPtr
= &infoPtr
->buttons
[nIndex
];
3551 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3557 lpRect
->left
= btnPtr
->rect
.left
;
3558 lpRect
->right
= btnPtr
->rect
.right
;
3559 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3560 lpRect
->top
= btnPtr
->rect
.top
;
3566 static inline LRESULT
3567 TOOLBAR_GetRows (const TOOLBAR_INFO
*infoPtr
)
3569 return infoPtr
->nRows
;
3574 TOOLBAR_GetState (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3578 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3582 return infoPtr
->buttons
[nIndex
].fsState
;
3586 static inline LRESULT
3587 TOOLBAR_GetStyle (const TOOLBAR_INFO
*infoPtr
)
3589 return infoPtr
->dwStyle
;
3593 static inline LRESULT
3594 TOOLBAR_GetTextRows (const TOOLBAR_INFO
*infoPtr
)
3596 return infoPtr
->nMaxTextRows
;
3601 TOOLBAR_GetToolTips (TOOLBAR_INFO
*infoPtr
)
3603 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3604 TOOLBAR_TooltipCreateControl(infoPtr
);
3605 return (LRESULT
)infoPtr
->hwndToolTip
;
3610 TOOLBAR_GetUnicodeFormat (const TOOLBAR_INFO
*infoPtr
)
3612 TRACE("%s hwnd=%p\n",
3613 infoPtr
->bUnicode
? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
3615 return infoPtr
->bUnicode
;
3619 static inline LRESULT
3620 TOOLBAR_GetVersion (const TOOLBAR_INFO
*infoPtr
)
3622 return infoPtr
->iVersion
;
3627 TOOLBAR_HideButton (TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fHide
)
3629 TBUTTON_INFO
*btnPtr
;
3635 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3639 btnPtr
= &infoPtr
->buttons
[nIndex
];
3640 oldState
= btnPtr
->fsState
;
3643 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3645 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3647 if (oldState
!= btnPtr
->fsState
) {
3648 TOOLBAR_LayoutToolbar (infoPtr
);
3649 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3656 static inline LRESULT
3657 TOOLBAR_HitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
* lpPt
)
3659 return TOOLBAR_InternalHitTest (infoPtr
, lpPt
, NULL
);
3664 TOOLBAR_Indeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fIndeterminate
)
3666 TBUTTON_INFO
*btnPtr
;
3670 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3674 btnPtr
= &infoPtr
->buttons
[nIndex
];
3675 oldState
= btnPtr
->fsState
;
3678 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3680 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3682 if(oldState
!= btnPtr
->fsState
)
3683 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3690 TOOLBAR_InsertButtonT(TOOLBAR_INFO
*infoPtr
, INT nIndex
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
3696 /* EPP: this seems to be an undocumented call (from my IE4)
3697 * I assume in that case that:
3698 * - index of insertion is at the end of existing buttons
3699 * I only see this happen with nIndex == -1, but it could have a special
3700 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3702 nIndex
= infoPtr
->nNumButtons
;
3704 } else if (nIndex
< 0)
3707 TRACE("inserting button index=%d\n", nIndex
);
3708 if (nIndex
> infoPtr
->nNumButtons
) {
3709 nIndex
= infoPtr
->nNumButtons
;
3710 TRACE("adjust index=%d\n", nIndex
);
3713 return TOOLBAR_InternalInsertButtonsT(infoPtr
, nIndex
, 1, lpTbb
, fUnicode
);
3716 /* << TOOLBAR_InsertMarkHitTest >> */
3720 TOOLBAR_IsButtonChecked (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3724 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3728 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3733 TOOLBAR_IsButtonEnabled (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3737 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3741 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3746 TOOLBAR_IsButtonHidden (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3750 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3754 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3759 TOOLBAR_IsButtonHighlighted (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3763 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3767 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3772 TOOLBAR_IsButtonIndeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3776 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3780 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3785 TOOLBAR_IsButtonPressed (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3789 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3793 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3798 TOOLBAR_LoadImages (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HINSTANCE hInstance
)
3801 tbab
.hInst
= hInstance
;
3804 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", infoPtr
->hwndSelf
, tbab
.hInst
, tbab
.nID
);
3806 return TOOLBAR_AddBitmap(infoPtr
, 0, &tbab
);
3811 TOOLBAR_MapAccelerator (const TOOLBAR_INFO
*infoPtr
, WCHAR wAccel
, UINT
*pIDButton
)
3813 WCHAR wszAccel
[] = {'&',wAccel
,0};
3816 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3817 infoPtr
->hwndSelf
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3819 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3821 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3822 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3823 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3825 int iLen
= strlenW(wszAccel
);
3826 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3833 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3838 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
3840 *pIDButton
= btnPtr
->idCommand
;
3852 TOOLBAR_MarkButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fMark
)
3856 TBUTTON_INFO
*btnPtr
;
3858 TRACE("hwnd = %p, Id = %d, fMark = 0%d\n", infoPtr
->hwndSelf
, Id
, fMark
);
3860 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3864 btnPtr
= &infoPtr
->buttons
[nIndex
];
3865 oldState
= btnPtr
->fsState
;
3868 btnPtr
->fsState
|= TBSTATE_MARKED
;
3870 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
3872 if(oldState
!= btnPtr
->fsState
)
3873 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3879 /* fixes up an index of a button affected by a move */
3880 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
3884 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
3886 else if (*pIndex
== nIndex
)
3887 *pIndex
= nMoveIndex
;
3891 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
3893 else if (*pIndex
== nIndex
)
3894 *pIndex
= nMoveIndex
;
3900 TOOLBAR_MoveButton (TOOLBAR_INFO
*infoPtr
, INT Id
, INT nMoveIndex
)
3904 TBUTTON_INFO button
;
3906 TRACE("hwnd=%p, Id=%d, nMoveIndex=%d\n", infoPtr
->hwndSelf
, Id
, nMoveIndex
);
3908 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, TRUE
);
3909 if ((nIndex
== -1) || (nMoveIndex
< 0))
3912 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
3913 nMoveIndex
= infoPtr
->nNumButtons
- 1;
3915 button
= infoPtr
->buttons
[nIndex
];
3917 /* move button right */
3918 if (nIndex
< nMoveIndex
)
3920 nCount
= nMoveIndex
- nIndex
;
3921 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
3922 infoPtr
->buttons
[nMoveIndex
] = button
;
3924 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
3925 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
3926 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
3927 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
3929 else if (nIndex
> nMoveIndex
) /* move button left */
3931 nCount
= nIndex
- nMoveIndex
;
3932 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
3933 infoPtr
->buttons
[nMoveIndex
] = button
;
3935 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
3936 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
3937 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
3938 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
3941 TOOLBAR_LayoutToolbar(infoPtr
);
3942 TOOLBAR_AutoSize(infoPtr
);
3943 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
3950 TOOLBAR_PressButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fPress
)
3952 TBUTTON_INFO
*btnPtr
;
3956 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3960 btnPtr
= &infoPtr
->buttons
[nIndex
];
3961 oldState
= btnPtr
->fsState
;
3964 btnPtr
->fsState
|= TBSTATE_PRESSED
;
3966 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
3968 if(oldState
!= btnPtr
->fsState
)
3969 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3974 /* FIXME: there might still be some confusion her between number of buttons
3975 * and number of bitmaps */
3977 TOOLBAR_ReplaceBitmap (TOOLBAR_INFO
*infoPtr
, const TBREPLACEBITMAP
*lpReplace
)
3980 int i
= 0, nOldButtons
= 0, pos
= 0;
3981 int nOldBitmaps
, nNewBitmaps
= 0;
3982 HIMAGELIST himlDef
= 0;
3984 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
3985 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
3986 lpReplace
->nButtons
);
3988 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
3990 FIXME("changing standard bitmaps not implemented\n");
3993 else if (lpReplace
->hInstOld
!= 0 && lpReplace
->hInstOld
!= lpReplace
->hInstNew
)
3994 FIXME("resources not in the current module not implemented\n");
3996 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
3997 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
3998 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
3999 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4000 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4002 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4003 nOldButtons
= tbi
->nButtons
;
4004 tbi
->nButtons
= lpReplace
->nButtons
;
4005 tbi
->hInst
= lpReplace
->hInstNew
;
4006 tbi
->nID
= lpReplace
->nIDNew
;
4007 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4010 pos
+= tbi
->nButtons
;
4013 if (nOldButtons
== 0)
4015 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4019 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4022 if (lpReplace
->hInstNew
)
4023 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4025 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4027 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4028 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4030 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4032 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4033 ImageList_Remove(himlDef
, i
);
4037 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4038 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4039 DeleteObject(hBitmap
);
4042 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4044 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4045 pos
, nOldBitmaps
, nNewBitmaps
);
4047 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4052 /* helper for TOOLBAR_SaveRestoreW */
4054 TOOLBAR_Save(const TBSAVEPARAMSW
*lpSave
)
4056 FIXME("save to %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4057 debugstr_w(lpSave
->pszValueName
));
4063 /* helper for TOOLBAR_Restore */
4065 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4069 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4071 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4074 Free(infoPtr
->buttons
);
4075 infoPtr
->buttons
= NULL
;
4076 infoPtr
->nNumButtons
= 0;
4080 /* helper for TOOLBAR_SaveRestoreW */
4082 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4091 /* restore toolbar information */
4092 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4093 debugstr_w(lpSave
->pszValueName
));
4095 memset(&nmtbr
, 0, sizeof(nmtbr
));
4097 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4098 KEY_QUERY_VALUE
, &hkey
);
4100 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4102 if (!res
&& dwType
!= REG_BINARY
)
4103 res
= ERROR_FILE_NOT_FOUND
;
4106 nmtbr
.pData
= Alloc(dwSize
);
4107 nmtbr
.cbData
= dwSize
;
4108 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4111 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4112 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4115 nmtbr
.pCurrent
= nmtbr
.pData
;
4117 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4118 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4120 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4124 /* remove all existing buttons as this function is designed to
4125 * restore the toolbar to a previously saved state */
4126 TOOLBAR_DeleteAllButtons(infoPtr
);
4128 for (i
= 0; i
< nmtbr
.cButtons
; i
++)
4131 nmtbr
.tbButton
.iBitmap
= -1;
4132 nmtbr
.tbButton
.fsState
= 0;
4133 nmtbr
.tbButton
.fsStyle
= 0;
4134 nmtbr
.tbButton
.idCommand
= 0;
4135 if (*nmtbr
.pCurrent
== (DWORD
)-1)
4138 nmtbr
.tbButton
.fsStyle
= TBSTYLE_SEP
;
4139 /* when inserting separators, iBitmap controls its size.
4140 0 sets default size (width) */
4141 nmtbr
.tbButton
.iBitmap
= 0;
4143 else if (*nmtbr
.pCurrent
== (DWORD
)-2)
4145 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4147 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4151 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4153 /* can't contain real string as we don't know whether
4154 * the client put an ANSI or Unicode string in there */
4155 if (!IS_INTRESOURCE(nmtbr
.tbButton
.iString
))
4156 nmtbr
.tbButton
.iString
= 0;
4158 TOOLBAR_InsertButtonT(infoPtr
, -1, &nmtbr
.tbButton
, TRUE
);
4161 /* do legacy notifications */
4162 if (infoPtr
->iVersion
< 5)
4164 /* FIXME: send TBN_BEGINADJUST */
4165 FIXME("send TBN_GETBUTTONINFO for each button\n");
4166 /* FIXME: send TBN_ENDADJUST */
4169 /* remove all uninitialised buttons
4170 * note: loop backwards to avoid having to fixup i on a
4172 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4173 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4174 TOOLBAR_DeleteButton(infoPtr
, i
);
4176 /* only indicate success if at least one button survived */
4177 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4188 TOOLBAR_SaveRestoreW (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4190 if (lpSave
== NULL
) return 0;
4193 return TOOLBAR_Save(lpSave
);
4195 return TOOLBAR_Restore(infoPtr
, lpSave
);
4200 TOOLBAR_SaveRestoreA (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4202 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4203 TBSAVEPARAMSW SaveW
;
4207 if (lpSave
== NULL
) return 0;
4209 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4210 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4211 if (pszSubKey
) goto exit
;
4212 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4214 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4215 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4216 if (!pszValueName
) goto exit
;
4217 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4219 SaveW
.pszValueName
= pszValueName
;
4220 SaveW
.pszSubKey
= pszSubKey
;
4221 SaveW
.hkr
= lpSave
->hkr
;
4222 result
= TOOLBAR_SaveRestoreW(infoPtr
, wParam
, &SaveW
);
4225 Free (pszValueName
);
4233 TOOLBAR_SetAnchorHighlight (TOOLBAR_INFO
*infoPtr
, BOOL bAnchor
)
4235 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4237 TRACE("hwnd=%p, bAnchor = %s\n", infoPtr
->hwndSelf
, bAnchor
? "TRUE" : "FALSE");
4239 infoPtr
->bAnchor
= bAnchor
;
4241 /* Native does not remove the hot effect from an already hot button */
4243 return (LRESULT
)bOldAnchor
;
4248 TOOLBAR_SetBitmapSize (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4250 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4251 short width
= (short)LOWORD(lParam
);
4252 short height
= (short)HIWORD(lParam
);
4254 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", infoPtr
->hwndSelf
, wParam
, lParam
);
4257 FIXME("wParam is %ld. Perhaps image list index?\n", wParam
);
4259 /* 0 width or height is changed to 1 */
4265 if (infoPtr
->nNumButtons
> 0)
4266 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4267 infoPtr
->nNumButtons
,
4268 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
, width
, height
);
4270 if (width
< -1 || height
< -1)
4272 /* Windows destroys the imagelist and seems to actually use negative
4273 * values to compute button sizes */
4274 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width
, height
);
4278 /* width or height of -1 means no change */
4280 infoPtr
->nBitmapWidth
= width
;
4282 infoPtr
->nBitmapHeight
= height
;
4284 if ((himlDef
== infoPtr
->himlInt
) &&
4285 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4287 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4288 infoPtr
->nBitmapHeight
);
4291 TOOLBAR_CalcToolbar(infoPtr
);
4292 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4298 TOOLBAR_SetButtonInfo (TOOLBAR_INFO
*infoPtr
, INT Id
,
4299 const TBBUTTONINFOW
*lptbbi
, BOOL isW
)
4301 TBUTTON_INFO
*btnPtr
;
4307 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4310 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lptbbi
->dwMask
& TBIF_BYINDEX
);
4314 btnPtr
= &infoPtr
->buttons
[nIndex
];
4315 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4316 btnPtr
->idCommand
= lptbbi
->idCommand
;
4317 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4318 btnPtr
->iBitmap
= lptbbi
->iImage
;
4319 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4320 btnPtr
->dwData
= lptbbi
->lParam
;
4321 if (lptbbi
->dwMask
& TBIF_SIZE
)
4322 btnPtr
->cx
= lptbbi
->cx
;
4323 if (lptbbi
->dwMask
& TBIF_STATE
)
4324 btnPtr
->fsState
= lptbbi
->fsState
;
4325 if (lptbbi
->dwMask
& TBIF_STYLE
)
4326 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4328 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4329 /* iString is index, zero it to make Str_SetPtr succeed */
4330 if (!TOOLBAR_ButtonHasString(btnPtr
)) btnPtr
->iString
= 0;
4333 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4335 Str_SetPtrAtoW ((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lptbbi
->pszText
);
4338 /* save the button rect to see if we need to redraw the whole toolbar */
4339 oldBtnRect
= btnPtr
->rect
;
4340 TOOLBAR_LayoutToolbar(infoPtr
);
4342 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4343 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4345 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4352 TOOLBAR_SetButtonSize (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4354 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4356 if ((cx
< 0) || (cy
< 0))
4358 ERR("invalid parameter 0x%08x\n", (DWORD
)lParam
);
4362 TRACE("%p, cx = %d, cy = %d\n", infoPtr
->hwndSelf
, cx
, cy
);
4364 /* The documentation claims you can only change the button size before
4365 * any button has been added. But this is wrong.
4366 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4367 * it to the toolbar, and it checks that the return value is nonzero - mjm
4368 * Further testing shows that we must actually perform the change too.
4371 * The documentation also does not mention that if 0 is supplied for
4372 * either size, the system changes it to the default of 24 wide and
4373 * 22 high. Demonstrated in ControlSpy Toolbar. GLA 3/02
4375 if (cx
== 0) cx
= 24;
4376 if (cy
== 0) cy
= 22;
4378 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4379 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4381 infoPtr
->nButtonWidth
= cx
;
4382 infoPtr
->nButtonHeight
= cy
;
4384 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
4385 TOOLBAR_LayoutToolbar(infoPtr
);
4391 TOOLBAR_SetButtonWidth (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4393 /* if setting to current values, ignore */
4394 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4395 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4396 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4397 infoPtr
->cxMin
, infoPtr
->cxMax
);
4401 /* save new values */
4402 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4403 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4405 /* otherwise we need to recalc the toolbar and in some cases
4406 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4407 which doesn't actually draw - GA). */
4408 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4409 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4411 TOOLBAR_CalcToolbar (infoPtr
);
4413 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
4420 TOOLBAR_SetCmdId (TOOLBAR_INFO
*infoPtr
, INT nIndex
, INT nId
)
4422 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4425 infoPtr
->buttons
[nIndex
].idCommand
= nId
;
4427 if (infoPtr
->hwndToolTip
) {
4429 FIXME("change tool tip!\n");
4438 TOOLBAR_SetDisabledImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4440 HIMAGELIST himlTemp
;
4443 if (infoPtr
->iVersion
>= 5)
4446 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4447 &infoPtr
->cimlDis
, himl
, id
);
4449 /* FIXME: redraw ? */
4451 return (LRESULT
)himlTemp
;
4456 TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4460 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", infoPtr
->hwndSelf
, (DWORD
)wParam
, (DWORD
)lParam
);
4462 dwTemp
= infoPtr
->dwDTFlags
;
4463 infoPtr
->dwDTFlags
=
4464 (infoPtr
->dwDTFlags
& (DWORD
)wParam
) | (DWORD
)lParam
;
4466 return (LRESULT
)dwTemp
;
4469 /* This function differs a bit from what MSDN says it does:
4470 * 1. lParam contains extended style flags to OR with current style
4471 * (MSDN isn't clear on the OR bit)
4472 * 2. wParam appears to contain extended style flags to be reset
4473 * (MSDN says that this parameter is reserved)
4476 TOOLBAR_SetExtendedStyle (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD style
)
4478 DWORD old_style
= infoPtr
->dwExStyle
;
4480 TRACE("mask=0x%08x, style=0x%08x\n", mask
, style
);
4483 infoPtr
->dwExStyle
= (old_style
& ~mask
) | (style
& mask
);
4485 infoPtr
->dwExStyle
= style
;
4487 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4488 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4489 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4491 if ((old_style
^ infoPtr
->dwExStyle
) & TBSTYLE_EX_MIXEDBUTTONS
)
4492 TOOLBAR_CalcToolbar(infoPtr
);
4494 TOOLBAR_LayoutToolbar(infoPtr
);
4496 TOOLBAR_AutoSize(infoPtr
);
4497 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4504 TOOLBAR_SetHotImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4506 HIMAGELIST himlTemp
;
4509 if (infoPtr
->iVersion
>= 5)
4512 TRACE("hwnd = %p, himl = %p, id = %d\n", infoPtr
->hwndSelf
, himl
, id
);
4514 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4515 &infoPtr
->cimlHot
, himl
, id
);
4517 /* FIXME: redraw ? */
4519 return (LRESULT
)himlTemp
;
4523 /* Makes previous hot button no longer hot, makes the specified
4524 * button hot and sends appropriate notifications. dwReason is one or
4525 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4526 * NOTE 1: this function does not validate nHit
4527 * NOTE 2: the name of this function is completely made up and
4528 * not based on any documentation from Microsoft. */
4530 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4532 if (infoPtr
->nHotItem
!= nHit
)
4534 NMTBHOTITEM nmhotitem
;
4535 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4537 nmhotitem
.dwFlags
= dwReason
;
4538 if(infoPtr
->nHotItem
>= 0)
4540 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4541 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4545 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4546 nmhotitem
.idOld
= 0;
4551 btnPtr
= &infoPtr
->buttons
[nHit
];
4552 nmhotitem
.idNew
= btnPtr
->idCommand
;
4556 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4557 nmhotitem
.idNew
= 0;
4560 /* now change the hot and invalidate the old and new buttons - if the
4562 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4565 oldBtnPtr
->bHot
= FALSE
;
4566 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4568 /* setting disabled buttons as hot fails even if the notify contains the button id */
4569 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4570 btnPtr
->bHot
= TRUE
;
4571 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4572 infoPtr
->nHotItem
= nHit
;
4575 infoPtr
->nHotItem
= -1;
4581 TOOLBAR_SetHotItem (TOOLBAR_INFO
*infoPtr
, INT nHotItem
)
4583 INT nOldHotItem
= infoPtr
->nHotItem
;
4585 TRACE("hwnd = %p, nHotItem = %d\n", infoPtr
->hwndSelf
, nHotItem
);
4587 if (nHotItem
>= infoPtr
->nNumButtons
)
4588 return infoPtr
->nHotItem
;
4593 /* NOTE: an application can still remove the hot item even if anchor
4594 * highlighting is enabled */
4596 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, HICF_OTHER
);
4598 if (nOldHotItem
< 0)
4601 return (LRESULT
)nOldHotItem
;
4606 TOOLBAR_SetImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4608 HIMAGELIST himlTemp
;
4609 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4610 INT oldBitmapWidth
= infoPtr
->nBitmapWidth
;
4611 INT oldBitmapHeight
= infoPtr
->nBitmapHeight
;
4614 if (infoPtr
->iVersion
>= 5)
4617 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4618 &infoPtr
->cimlDef
, himl
, id
);
4620 infoPtr
->nNumBitmaps
= 0;
4621 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4622 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4624 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4625 &infoPtr
->nBitmapHeight
))
4627 infoPtr
->nBitmapWidth
= 1;
4628 infoPtr
->nBitmapHeight
= 1;
4630 if ((oldBitmapWidth
!= infoPtr
->nBitmapWidth
) || (oldBitmapHeight
!= infoPtr
->nBitmapHeight
))
4632 TOOLBAR_CalcToolbar(infoPtr
);
4633 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4634 TOOLBAR_SetButtonSize(infoPtr
, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4637 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4638 infoPtr
->hwndSelf
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4639 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4641 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4643 return (LRESULT
)himlTemp
;
4648 TOOLBAR_SetIndent (TOOLBAR_INFO
*infoPtr
, INT nIndent
)
4650 infoPtr
->nIndent
= nIndent
;
4654 /* process only on indent changing */
4655 if(infoPtr
->nIndent
!= nIndent
)
4657 infoPtr
->nIndent
= nIndent
;
4658 TOOLBAR_CalcToolbar (infoPtr
);
4659 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4667 TOOLBAR_SetInsertMark (TOOLBAR_INFO
*infoPtr
, const TBINSERTMARK
*lptbim
)
4669 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", infoPtr
->hwndSelf
, lptbim
->iButton
, lptbim
->dwFlags
);
4671 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4673 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4677 if ((lptbim
->iButton
== -1) ||
4678 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4679 (lptbim
->iButton
>= 0)))
4681 infoPtr
->tbim
= *lptbim
;
4682 /* FIXME: don't need to update entire toolbar */
4683 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4686 ERR("Invalid button index %d\n", lptbim
->iButton
);
4693 TOOLBAR_SetInsertMarkColor (TOOLBAR_INFO
*infoPtr
, COLORREF clr
)
4695 infoPtr
->clrInsertMark
= clr
;
4697 /* FIXME: don't need to update entire toolbar */
4698 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4705 TOOLBAR_SetMaxTextRows (TOOLBAR_INFO
*infoPtr
, INT nMaxRows
)
4707 infoPtr
->nMaxTextRows
= nMaxRows
;
4709 TOOLBAR_CalcToolbar(infoPtr
);
4714 /* MSDN gives slightly wrong info on padding.
4715 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4716 * 2. It is not used to create a blank area between the edge of the button
4717 * and the text or image if TBSTYLE_LIST is set. It is used to control
4718 * the gap between the image and text.
4719 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4720 * to control the bottom and right borders [with the border being
4721 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4722 * is shared evenly on both sides of the button.
4723 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4726 TOOLBAR_SetPadding (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4730 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4731 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4732 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4733 TRACE("cx=%d, cy=%d\n",
4734 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4735 return (LRESULT
) oldPad
;
4740 TOOLBAR_SetParent (TOOLBAR_INFO
*infoPtr
, HWND hParent
)
4746 hwndOldNotify
= infoPtr
->hwndNotify
;
4747 infoPtr
->hwndNotify
= hParent
;
4749 return (LRESULT
)hwndOldNotify
;
4754 TOOLBAR_SetRows (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPRECT lprc
)
4756 int rows
= LOWORD(wParam
);
4757 BOOL bLarger
= HIWORD(wParam
);
4761 TRACE("Setting rows to %d (%d)\n", rows
, bLarger
);
4763 if(infoPtr
->nRows
!= rows
)
4765 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
;
4766 int curColumn
= 0; /* Current column */
4767 int curRow
= 0; /* Current row */
4768 int hidden
= 0; /* Number of hidden buttons */
4769 int seps
= 0; /* Number of separators */
4770 int idealWrap
= 0; /* Ideal wrap point */
4775 Calculate new size and wrap points - Under windows, setrows will
4776 change the dimensions if needed to show the number of requested
4777 rows (if CCS_NORESIZE is set), or will take up the whole window
4778 (if no CCS_NORESIZE).
4780 Basic algorithm - If N buttons, and y rows requested, each row
4781 contains N/y buttons.
4783 FIXME: Handling of separators not obvious from testing results
4784 FIXME: Take width of window into account?
4787 /* Loop through the buttons one by one counting key items */
4788 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4790 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
4791 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4793 else if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
4797 /* FIXME: Separators make this quite complex */
4798 if (seps
) FIXME("Separators unhandled\n");
4800 /* Round up so more per line, i.e., less rows */
4801 idealWrap
= (infoPtr
->nNumButtons
- hidden
+ (rows
-1)) / (rows
? rows
: 1);
4803 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4804 achieve the requested number of rows. */
4805 if (bLarger
&& idealWrap
> 1)
4807 int resRows
= (infoPtr
->nNumButtons
+ (idealWrap
-1)) / idealWrap
;
4808 int moreRows
= (infoPtr
->nNumButtons
+ (idealWrap
-2)) / (idealWrap
-1);
4810 if (resRows
< rows
&& moreRows
> rows
)
4813 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap
);
4817 curColumn
= curRow
= 0;
4819 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap
,
4820 infoPtr
->nNumButtons
, hidden
, rows
);
4822 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4824 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4827 /* Step on, wrap if necessary or flag next to wrap */
4836 if (curColumn
> (idealWrap
-1)) {
4838 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
4842 TRACE("Result - %d rows\n", curRow
+ 1);
4844 /* recalculate toolbar */
4845 TOOLBAR_CalcToolbar (infoPtr
);
4847 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
4848 if NORESIZE is NOT set, then the toolbar will always be resized to
4849 take up the whole window. With it set, sizing needs to be manual. */
4850 if (infoPtr
->dwStyle
& CCS_NORESIZE
) {
4851 SetWindowPos(infoPtr
->hwndSelf
, NULL
, 0, 0,
4852 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
4853 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
,
4854 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
4857 /* repaint toolbar */
4858 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4861 /* return bounding rectangle */
4863 lprc
->left
= infoPtr
->rcBound
.left
;
4864 lprc
->right
= infoPtr
->rcBound
.right
;
4865 lprc
->top
= infoPtr
->rcBound
.top
;
4866 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
4874 TOOLBAR_SetState (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
4876 TBUTTON_INFO
*btnPtr
;
4879 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
4883 btnPtr
= &infoPtr
->buttons
[nIndex
];
4885 /* if hidden state has changed the invalidate entire window and recalc */
4886 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
4887 btnPtr
->fsState
= LOWORD(lParam
);
4888 TOOLBAR_CalcToolbar (infoPtr
);
4889 InvalidateRect(infoPtr
->hwndSelf
, 0, TRUE
);
4893 /* process state changing if current state doesn't match new state */
4894 if(btnPtr
->fsState
!= LOWORD(lParam
))
4896 btnPtr
->fsState
= LOWORD(lParam
);
4897 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4905 TOOLBAR_SetStyle (TOOLBAR_INFO
*infoPtr
, DWORD style
)
4907 infoPtr
->dwStyle
= style
;
4912 static inline LRESULT
4913 TOOLBAR_SetToolTips (TOOLBAR_INFO
*infoPtr
, HWND hwndTooltip
)
4915 TRACE("hwnd=%p, hwndTooltip=%p\n", infoPtr
->hwndSelf
, hwndTooltip
);
4917 infoPtr
->hwndToolTip
= hwndTooltip
;
4923 TOOLBAR_SetUnicodeFormat (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
4927 TRACE("%s hwnd=%p\n",
4928 ((BOOL
)wParam
) ? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
4930 bTemp
= infoPtr
->bUnicode
;
4931 infoPtr
->bUnicode
= (BOOL
)wParam
;
4938 TOOLBAR_GetColorScheme (const TOOLBAR_INFO
*infoPtr
, LPCOLORSCHEME lParam
)
4940 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
4941 comctl32_color
.clrBtnHighlight
:
4942 infoPtr
->clrBtnHighlight
;
4943 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
4944 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
4950 TOOLBAR_SetColorScheme (TOOLBAR_INFO
*infoPtr
, const COLORSCHEME
*lParam
)
4952 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
4953 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
4954 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
4956 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
4957 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
4958 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4964 TOOLBAR_SetVersion (TOOLBAR_INFO
*infoPtr
, INT iVersion
)
4966 INT iOldVersion
= infoPtr
->iVersion
;
4968 infoPtr
->iVersion
= iVersion
;
4970 if (infoPtr
->iVersion
>= 5)
4971 TOOLBAR_SetUnicodeFormat(infoPtr
, TRUE
);
4978 TOOLBAR_GetStringA (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPSTR str
)
4980 WORD iString
= HIWORD(wParam
);
4981 WORD buffersize
= LOWORD(wParam
);
4984 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, buffersize
, str
);
4986 if (iString
< infoPtr
->nNumStrings
)
4988 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
4991 TRACE("returning %s\n", debugstr_a(str
));
4994 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5001 TOOLBAR_GetStringW (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPWSTR str
)
5003 WORD iString
= HIWORD(wParam
);
5004 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5007 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, LOWORD(wParam
), str
);
5009 if (iString
< infoPtr
->nNumStrings
)
5011 len
= min(len
, strlenW(infoPtr
->strings
[iString
]));
5012 ret
= (len
+1)*sizeof(WCHAR
);
5015 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5020 TRACE("returning %s\n", debugstr_w(str
));
5023 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5028 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5029 * is the maximum size of the toolbar? */
5030 static LRESULT
TOOLBAR_Unkwn45D(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5032 SIZE
* pSize
= (SIZE
*)lParam
;
5033 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5038 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5039 * caller to specify a reason why the hot item changed (rather than just the
5040 * HICF_OTHER that TB_SETHOTITEM sends). */
5042 TOOLBAR_SetHotItem2 (TOOLBAR_INFO
*infoPtr
, INT nHotItem
, LPARAM lParam
)
5044 INT nOldHotItem
= infoPtr
->nHotItem
;
5046 TRACE("old item=%d, new item=%d, flags=%08x\n",
5047 nOldHotItem
, nHotItem
, (DWORD
)lParam
);
5049 if (nHotItem
< 0 || nHotItem
> infoPtr
->nNumButtons
)
5052 /* NOTE: an application can still remove the hot item even if anchor
5053 * highlighting is enabled */
5055 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, lParam
);
5059 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5062 /* Sets the toolbar global iListGap parameter which controls the amount of
5063 * spacing between the image and the text of buttons for TBSTYLE_LIST
5065 static LRESULT
TOOLBAR_SetListGap(TOOLBAR_INFO
*infoPtr
, INT iListGap
)
5067 TRACE("hwnd=%p iListGap=%d\n", infoPtr
->hwndSelf
, iListGap
);
5069 infoPtr
->iListGap
= iListGap
;
5071 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5076 /* Returns the number of maximum number of image lists associated with the
5077 * various states. */
5078 static LRESULT
TOOLBAR_GetImageListCount(const TOOLBAR_INFO
*infoPtr
)
5080 TRACE("hwnd=%p\n", infoPtr
->hwndSelf
);
5082 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5086 TOOLBAR_GetIdealSize (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5088 LPSIZE lpsize
= (LPSIZE
)lParam
;
5094 * Testing shows the following:
5095 * wParam = 0 adjust cx value
5096 * = 1 set cy value to max size.
5097 * lParam pointer to SIZE structure
5100 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5101 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5105 if (lpsize
->cx
== -1) {
5106 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5108 else if(HIWORD(lpsize
->cx
)) {
5110 HWND hwndParent
= GetParent(infoPtr
->hwndSelf
);
5112 GetWindowRect(infoPtr
->hwndSelf
, &rc
);
5113 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5114 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc
));
5115 lpsize
->cx
= max(rc
.right
-rc
.left
,
5116 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5119 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5123 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5126 FIXME("Unknown wParam %ld\n", wParam
);
5129 TRACE("set to -> 0x%08x 0x%08x\n",
5130 lpsize
->cx
, lpsize
->cy
);
5134 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5136 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5138 InvalidateRect(hwnd
, NULL
, TRUE
);
5144 TOOLBAR_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
5146 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
5149 TRACE("hwnd = %p, style=0x%08x\n", hwnd
, lpcs
->style
);
5151 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5152 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5153 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5154 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_REQUERY
));
5155 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5157 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5158 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5160 OpenThemeData (hwnd
, themeClass
);
5162 TOOLBAR_CheckStyle (infoPtr
);
5169 TOOLBAR_Destroy (TOOLBAR_INFO
*infoPtr
)
5173 /* delete tooltip control */
5174 if (infoPtr
->hwndToolTip
)
5175 DestroyWindow (infoPtr
->hwndToolTip
);
5177 /* delete temporary buffer for tooltip text */
5178 Free (infoPtr
->pszTooltipText
);
5179 Free (infoPtr
->bitmaps
); /* bitmaps list */
5181 /* delete button data */
5182 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5183 if (TOOLBAR_ButtonHasString(&infoPtr
->buttons
[i
]))
5184 Free ((LPWSTR
)infoPtr
->buttons
[i
].iString
);
5185 Free (infoPtr
->buttons
);
5187 /* delete strings */
5188 if (infoPtr
->strings
) {
5189 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5190 Free (infoPtr
->strings
[i
]);
5192 Free (infoPtr
->strings
);
5195 /* destroy internal image list */
5196 if (infoPtr
->himlInt
)
5197 ImageList_Destroy (infoPtr
->himlInt
);
5199 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5200 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5201 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5203 /* delete default font */
5204 DeleteObject (infoPtr
->hDefaultFont
);
5206 CloseThemeData (GetWindowTheme (infoPtr
->hwndSelf
));
5208 /* free toolbar info data */
5209 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
5217 TOOLBAR_EraseBackground (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5219 NMTBCUSTOMDRAW tbcd
;
5222 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
5223 DWORD dwEraseCustDraw
= 0;
5225 /* the app has told us not to redraw the toolbar */
5226 if (!infoPtr
->bDoRedraw
)
5229 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5230 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5231 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5232 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5233 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5234 dwEraseCustDraw
= ntfret
& 0xffff;
5236 /* FIXME: in general the return flags *can* be or'ed together */
5237 switch (dwEraseCustDraw
)
5239 case CDRF_DODEFAULT
:
5241 case CDRF_SKIPDEFAULT
:
5244 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5245 infoPtr
->hwndSelf
, ntfret
);
5249 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5250 * to my parent for processing.
5252 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5254 HDC hdc
= (HDC
)wParam
;
5259 parent
= GetParent(infoPtr
->hwndSelf
);
5260 MapWindowPoints(infoPtr
->hwndSelf
, parent
, &pt
, 1);
5261 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5262 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5263 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5266 ret
= DefWindowProcW (infoPtr
->hwndSelf
, WM_ERASEBKGND
, wParam
, lParam
);
5268 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5269 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5270 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5271 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5272 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5273 dwEraseCustDraw
= ntfret
& 0xffff;
5274 switch (dwEraseCustDraw
)
5276 case CDRF_DODEFAULT
:
5278 case CDRF_SKIPDEFAULT
:
5281 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5282 infoPtr
->hwndSelf
, ntfret
);
5289 static inline LRESULT
5290 TOOLBAR_GetFont (const TOOLBAR_INFO
*infoPtr
)
5292 return (LRESULT
)infoPtr
->hFont
;
5297 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5300 INT nNewHotItem
= infoPtr
->nHotItem
;
5302 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5305 if ((nNewHotItem
+ iDirection
< 0) ||
5306 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5308 NMTBWRAPHOTITEM nmtbwhi
;
5309 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5310 nmtbwhi
.iDirection
= iDirection
;
5311 nmtbwhi
.dwReason
= dwReason
;
5313 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5317 nNewHotItem
+= iDirection
;
5318 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5320 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5321 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5323 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5330 TOOLBAR_KeyDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5334 nmkey
.nVKey
= (UINT
)wParam
;
5335 nmkey
.uFlags
= HIWORD(lParam
);
5337 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5338 return DefWindowProcW(infoPtr
->hwndSelf
, WM_KEYDOWN
, wParam
, lParam
);
5340 switch ((UINT
)wParam
)
5344 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5348 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5352 if ((infoPtr
->nHotItem
>= 0) &&
5353 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5355 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5356 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5357 (LPARAM
)infoPtr
->hwndSelf
);
5367 TOOLBAR_LButtonDblClk (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5372 pt
.x
= (short)LOWORD(lParam
);
5373 pt
.y
= (short)HIWORD(lParam
);
5374 TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5377 TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
5378 else if (infoPtr
->dwStyle
& CCS_ADJUSTABLE
)
5379 TOOLBAR_Customize (infoPtr
);
5386 TOOLBAR_LButtonDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5388 TBUTTON_INFO
*btnPtr
;
5393 BOOL bDragKeyPressed
;
5398 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5399 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5401 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5403 if (infoPtr
->hwndToolTip
)
5404 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5405 WM_LBUTTONDOWN
, wParam
, lParam
);
5407 pt
.x
= (short)LOWORD(lParam
);
5408 pt
.y
= (short)HIWORD(lParam
);
5409 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5412 btnPtr
= &infoPtr
->buttons
[nHit
];
5414 if (button
&& bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5416 infoPtr
->nButtonDrag
= nHit
;
5417 SetCapture (infoPtr
->hwndSelf
);
5419 /* If drag cursor has not been loaded, load it.
5420 * Note: it doesn't need to be freed */
5422 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5423 SetCursor(hCursorDrag
);
5428 infoPtr
->nOldHit
= nHit
;
5430 CopyRect(&arrowRect
, &btnPtr
->rect
);
5431 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5433 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5434 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5435 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5436 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5437 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5438 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5442 /* draw in pressed state */
5443 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5444 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5446 btnPtr
->bDropDownPressed
= TRUE
;
5447 RedrawWindow(infoPtr
->hwndSelf
,&btnPtr
->rect
,0,
5448 RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5450 memset(&nmtb
, 0, sizeof(nmtb
));
5451 nmtb
.iItem
= btnPtr
->idCommand
;
5452 nmtb
.rcButton
= btnPtr
->rect
;
5453 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5455 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5457 if (res
!= TBDDRET_TREATPRESSED
)
5461 /* redraw button in unpressed state */
5462 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5463 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5465 btnPtr
->bDropDownPressed
= FALSE
;
5466 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5468 /* find and set hot item */
5470 ScreenToClient(infoPtr
->hwndSelf
, &pt
);
5471 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5472 if (!infoPtr
->bAnchor
|| button
)
5473 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5475 /* remove any left mouse button down or double-click messages
5476 * so that we can get a toggle effect on the button */
5477 while (PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5478 PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5483 /* otherwise drop through and process as pushed */
5485 infoPtr
->bCaptured
= TRUE
;
5486 infoPtr
->nButtonDown
= nHit
;
5487 infoPtr
->bDragOutSent
= FALSE
;
5489 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5491 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5493 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5494 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5495 UpdateWindow(infoPtr
->hwndSelf
);
5496 SetCapture (infoPtr
->hwndSelf
);
5501 memset(&nmtb
, 0, sizeof(nmtb
));
5502 nmtb
.iItem
= btnPtr
->idCommand
;
5503 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5506 nmmouse
.dwHitInfo
= nHit
;
5508 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5510 nmmouse
.dwItemSpec
= -1;
5513 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5514 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5517 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5520 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5521 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, wParam
, lParam
);
5527 TOOLBAR_LButtonUp (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5529 TBUTTON_INFO
*btnPtr
;
5538 if (infoPtr
->hwndToolTip
)
5539 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5540 WM_LBUTTONUP
, wParam
, lParam
);
5542 pt
.x
= (short)LOWORD(lParam
);
5543 pt
.y
= (short)HIWORD(lParam
);
5544 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5546 if (!infoPtr
->bAnchor
|| button
)
5547 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5549 if (infoPtr
->nButtonDrag
>= 0) {
5553 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5556 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5558 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5559 if (PtInRect(&rcClient
, pt
))
5566 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5569 if (nButton
== infoPtr
->nButtonDrag
)
5571 /* if the button is moved sightly left and we have a
5572 * separator there then remove it */
5573 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5575 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5576 TOOLBAR_DeleteButton(infoPtr
, nButton
- 1);
5578 else /* else insert a separator before the dragged button */
5581 memset(&tbb
, 0, sizeof(tbb
));
5582 tbb
.fsStyle
= BTNS_SEP
;
5584 TOOLBAR_InsertButtonT(infoPtr
, nButton
, &tbb
, TRUE
);
5591 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5592 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, 0);
5594 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5597 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, nButton
);
5602 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5603 TOOLBAR_DeleteButton(infoPtr
, infoPtr
->nButtonDrag
);
5606 /* button under cursor changed so need to re-set hot item */
5607 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5608 infoPtr
->nButtonDrag
= -1;
5610 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5612 else if (infoPtr
->nButtonDown
>= 0) {
5613 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5614 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5616 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5617 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5618 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5620 if ((nOldIndex
!= nHit
) &&
5622 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5623 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5626 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5627 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5629 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5633 if (nOldIndex
!= -1)
5634 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5637 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5638 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5639 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5641 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5643 infoPtr
->nButtonDown
= -1;
5645 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5646 TOOLBAR_SendNotify (&hdr
, infoPtr
,
5647 NM_RELEASEDCAPTURE
);
5649 memset(&nmtb
, 0, sizeof(nmtb
));
5650 nmtb
.iItem
= btnPtr
->idCommand
;
5651 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5654 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5656 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5657 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)infoPtr
->hwndSelf
);
5659 /* In case we have just been destroyed... */
5660 if(!IsWindow(infoPtr
->hwndSelf
))
5665 /* !!! Undocumented - toolbar at 4.71 level and above sends
5666 * NM_CLICK with the NMMOUSE structure. */
5667 nmmouse
.dwHitInfo
= nHit
;
5670 nmmouse
.dwItemSpec
= -1;
5673 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5674 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5677 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5680 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5681 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONUP
, wParam
, lParam
);
5687 TOOLBAR_RButtonUp(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5694 pt
.x
= (short)LOWORD(lParam
);
5695 pt
.y
= (short)HIWORD(lParam
);
5697 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5698 nmmouse
.dwHitInfo
= nHit
;
5701 nmmouse
.dwItemSpec
= -1;
5703 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5704 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5707 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5710 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5711 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONUP
, wParam
, lParam
);
5717 TOOLBAR_RButtonDblClk( TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5721 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5722 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
5728 TOOLBAR_CaptureChanged(TOOLBAR_INFO
*infoPtr
)
5730 TBUTTON_INFO
*btnPtr
;
5732 infoPtr
->bCaptured
= FALSE
;
5734 if (infoPtr
->nButtonDown
>= 0)
5736 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5737 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5739 infoPtr
->nOldHit
= -1;
5741 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5742 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5748 TOOLBAR_MouseLeave (TOOLBAR_INFO
*infoPtr
)
5750 /* don't remove hot effects when in anchor highlighting mode or when a
5751 * drop-down button is pressed */
5752 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
5754 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
5755 if (!hotBtnPtr
->bDropDownPressed
)
5756 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
5759 if (infoPtr
->nOldHit
< 0)
5762 /* If the last button we were over is depressed then make it not */
5763 /* depressed and redraw it */
5764 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
5766 TBUTTON_INFO
*btnPtr
;
5769 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5771 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5774 InflateRect (&rc1
, 1, 1);
5775 InvalidateRect (infoPtr
->hwndSelf
, &rc1
, TRUE
);
5778 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
5781 ZeroMemory(&nmt
, sizeof(nmt
));
5782 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5783 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5784 infoPtr
->bDragOutSent
= TRUE
;
5787 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
5793 TOOLBAR_MouseMove (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5796 TRACKMOUSEEVENT trackinfo
;
5798 TBUTTON_INFO
*btnPtr
;
5801 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
5802 TOOLBAR_TooltipCreateControl(infoPtr
);
5804 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
5805 /* fill in the TRACKMOUSEEVENT struct */
5806 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5807 trackinfo
.dwFlags
= TME_QUERY
;
5809 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5810 _TrackMouseEvent(&trackinfo
);
5812 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5813 if(trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
5814 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5815 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
5817 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5818 /* and can properly deactivate the hot toolbar button */
5819 _TrackMouseEvent(&trackinfo
);
5823 if (infoPtr
->hwndToolTip
)
5824 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5825 WM_MOUSEMOVE
, wParam
, lParam
);
5827 pt
.x
= (short)LOWORD(lParam
);
5828 pt
.y
= (short)HIWORD(lParam
);
5830 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5832 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
5833 && (!infoPtr
->bAnchor
|| button
))
5834 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
);
5836 if (infoPtr
->nOldHit
!= nHit
)
5838 if (infoPtr
->bCaptured
)
5840 if (!infoPtr
->bDragOutSent
)
5843 ZeroMemory(&nmt
, sizeof(nmt
));
5844 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5845 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5846 infoPtr
->bDragOutSent
= TRUE
;
5849 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5850 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
5851 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5852 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5854 else if (nHit
== infoPtr
->nButtonDown
) {
5855 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5856 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5858 infoPtr
->nOldHit
= nHit
;
5866 static inline LRESULT
5867 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5869 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5870 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
5872 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5876 static inline LRESULT
5877 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5879 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
5880 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
5882 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
5887 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
5889 TOOLBAR_INFO
*infoPtr
;
5892 /* allocate memory for info structure */
5893 infoPtr
= Alloc (sizeof(TOOLBAR_INFO
));
5894 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
5897 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
5899 infoPtr
->nWidth
= 0;
5901 /* initialize info structure */
5902 infoPtr
->nButtonWidth
= 23;
5903 infoPtr
->nButtonHeight
= 22;
5904 infoPtr
->nBitmapHeight
= 16;
5905 infoPtr
->nBitmapWidth
= 16;
5907 infoPtr
->nMaxTextRows
= 1;
5908 infoPtr
->cxMin
= -1;
5909 infoPtr
->cxMax
= -1;
5910 infoPtr
->nNumBitmaps
= 0;
5911 infoPtr
->nNumStrings
= 0;
5913 infoPtr
->bCaptured
= FALSE
;
5914 infoPtr
->nButtonDown
= -1;
5915 infoPtr
->nButtonDrag
= -1;
5916 infoPtr
->nOldHit
= -1;
5917 infoPtr
->nHotItem
= -1;
5918 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
5919 infoPtr
->dwDTFlags
= (lpcs
->style
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
5920 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
5921 infoPtr
->bDragOutSent
= FALSE
;
5922 infoPtr
->iVersion
= 0;
5923 infoPtr
->hwndSelf
= hwnd
;
5924 infoPtr
->bDoRedraw
= TRUE
;
5925 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
5926 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
5927 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
5928 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
5929 infoPtr
->iListGap
= DEFLISTGAP
;
5930 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
5931 infoPtr
->dwStyle
= lpcs
->style
;
5932 infoPtr
->tbim
.iButton
= -1;
5934 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5935 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
5936 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
5937 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
5940 /* I think the code below is a bug, but it is the way that the native
5941 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5942 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5943 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5944 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5945 * Somehow, the only cases of this seem to be MFC programs.
5947 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5948 * does not occur in the WM_STYLECHANGING routine.
5949 * (Guy Albertelli 9/2001)
5952 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
5953 && !(lpcs
->style
& TBSTYLE_TRANSPARENT
))
5954 styleadd
|= TBSTYLE_TRANSPARENT
;
5955 if (!(lpcs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
5956 styleadd
|= CCS_TOP
; /* default to top */
5957 SetWindowLongW (hwnd
, GWL_STYLE
, lpcs
->style
| styleadd
);
5960 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
5965 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5967 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5971 if (dwStyle
& WS_MINIMIZE
)
5972 return 0; /* Nothing to do */
5974 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
5976 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
5979 if (!(dwStyle
& CCS_NODIVIDER
))
5981 GetWindowRect (hwnd
, &rcWindow
);
5982 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
5983 if( dwStyle
& WS_BORDER
)
5984 InflateRect (&rcWindow
, -1, -1);
5985 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
5988 ReleaseDC( hwnd
, hdc
);
5994 /* handles requests from the tooltip control on what text to display */
5995 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
5997 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
5999 TRACE("button index = %d\n", index
);
6001 Free (infoPtr
->pszTooltipText
);
6002 infoPtr
->pszTooltipText
= NULL
;
6007 if (infoPtr
->bUnicode
)
6009 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6010 NMTBGETINFOTIPW tbgit
;
6011 unsigned int len
; /* in chars */
6013 wszBuffer
[0] = '\0';
6014 wszBuffer
[INFOTIPSIZE
] = '\0';
6016 tbgit
.pszText
= wszBuffer
;
6017 tbgit
.cchTextMax
= INFOTIPSIZE
;
6018 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6019 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6021 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6023 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6025 len
= strlenW(tbgit
.pszText
);
6026 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6028 /* need to allocate temporary buffer in infoPtr as there
6029 * isn't enough space in buffer passed to us by the
6030 * tooltip control */
6031 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6032 if (infoPtr
->pszTooltipText
)
6034 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6035 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6041 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6047 CHAR szBuffer
[INFOTIPSIZE
+1];
6048 NMTBGETINFOTIPA tbgit
;
6049 unsigned int len
; /* in chars */
6052 szBuffer
[INFOTIPSIZE
] = '\0';
6054 tbgit
.pszText
= szBuffer
;
6055 tbgit
.cchTextMax
= INFOTIPSIZE
;
6056 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6057 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6059 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6061 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6063 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6064 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]))
6066 /* need to allocate temporary buffer in infoPtr as there
6067 * isn't enough space in buffer passed to us by the
6068 * tooltip control */
6069 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6070 if (infoPtr
->pszTooltipText
)
6072 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6073 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6077 else if (tbgit
.pszText
&& tbgit
.pszText
[0])
6079 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1,
6080 lpnmtdi
->lpszText
, sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]));
6085 /* if button has text, but it is not shown then automatically
6086 * use that text as tooltip */
6087 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6088 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6090 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6091 unsigned int len
= pszText
? strlenW(pszText
) : 0;
6093 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6095 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6097 /* need to allocate temporary buffer in infoPtr as there
6098 * isn't enough space in buffer passed to us by the
6099 * tooltip control */
6100 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6101 if (infoPtr
->pszTooltipText
)
6103 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6104 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6110 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6115 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6117 /* last resort: send notification on to app */
6118 /* FIXME: find out what is really used here */
6119 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmtdi
->hdr
.idFrom
, (LPARAM
)lpnmtdi
);
6123 static inline LRESULT
6124 TOOLBAR_Notify (TOOLBAR_INFO
*infoPtr
, LPNMHDR lpnmh
)
6126 switch (lpnmh
->code
)
6130 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lpnmh
;
6132 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6133 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6134 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6138 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6139 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6147 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lpnmh
;
6149 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6150 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6151 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6152 lppgs
->iScroll
, lppgs
->iDir
);
6156 case TTN_GETDISPINFOW
:
6157 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lpnmh
);
6159 case TTN_GETDISPINFOA
:
6160 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6170 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6174 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam
, lParam
);
6176 if (lParam
== NF_QUERY
)
6179 if (lParam
== NF_REQUERY
) {
6180 format
= SendMessageW(infoPtr
->hwndNotify
,
6181 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6182 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6183 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6194 TOOLBAR_Paint (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6199 /* fill ps.rcPaint with a default rect */
6200 ps
.rcPaint
= infoPtr
->rcBound
;
6202 hdc
= wParam
==0 ? BeginPaint(infoPtr
->hwndSelf
, &ps
) : (HDC
)wParam
;
6204 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps
.rcPaint
));
6206 TOOLBAR_Refresh (infoPtr
, hdc
, &ps
);
6207 if (!wParam
) EndPaint (infoPtr
->hwndSelf
, &ps
);
6214 TOOLBAR_SetFocus (TOOLBAR_INFO
*infoPtr
)
6216 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6218 /* make first item hot */
6219 if (infoPtr
->nNumButtons
> 0)
6220 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6226 TOOLBAR_SetFont(TOOLBAR_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
6228 TRACE("font=%p redraw=%d\n", hFont
, Redraw
);
6231 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6233 infoPtr
->hFont
= hFont
;
6235 TOOLBAR_CalcToolbar(infoPtr
);
6238 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6243 TOOLBAR_SetRedraw (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6244 /*****************************************************
6247 * Handles the WM_SETREDRAW message.
6250 * According to testing V4.71 of COMCTL32 returns the
6251 * *previous* status of the redraw flag (either 0 or 1)
6252 * instead of the MSDN documented value of 0 if handled.
6253 * (For laughs see the "consistency" with same function
6256 *****************************************************/
6258 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6260 TRACE("set to %s\n",
6261 (wParam
) ? "TRUE" : "FALSE");
6262 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6264 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6266 return (oldredraw
) ? 1 : 0;
6271 TOOLBAR_Size (TOOLBAR_INFO
*infoPtr
)
6273 TRACE("sizing toolbar!\n");
6275 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6277 RECT delta_width
, delta_height
, client
, dummy
;
6278 DWORD min_x
, max_x
, min_y
, max_y
;
6279 TBUTTON_INFO
*btnPtr
;
6282 GetClientRect(infoPtr
->hwndSelf
, &client
);
6283 if(client
.right
> infoPtr
->client_rect
.right
)
6285 min_x
= infoPtr
->client_rect
.right
;
6286 max_x
= client
.right
;
6290 max_x
= infoPtr
->client_rect
.right
;
6291 min_x
= client
.right
;
6293 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6295 min_y
= infoPtr
->client_rect
.bottom
;
6296 max_y
= client
.bottom
;
6300 max_y
= infoPtr
->client_rect
.bottom
;
6301 min_y
= client
.bottom
;
6304 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6305 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6307 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6308 btnPtr
= infoPtr
->buttons
;
6309 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6310 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6311 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6312 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6314 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->client_rect
);
6315 TOOLBAR_AutoSize(infoPtr
);
6321 TOOLBAR_StyleChanged (TOOLBAR_INFO
*infoPtr
, INT nType
, const STYLESTRUCT
*lpStyle
)
6323 if (nType
== GWL_STYLE
)
6325 DWORD dwOldStyle
= infoPtr
->dwStyle
;
6327 if (lpStyle
->styleNew
& TBSTYLE_LIST
)
6328 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
6330 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
6332 TRACE("new style 0x%08x\n", lpStyle
->styleNew
);
6334 infoPtr
->dwStyle
= lpStyle
->styleNew
;
6335 TOOLBAR_CheckStyle (infoPtr
);
6337 if ((dwOldStyle
^ lpStyle
->styleNew
) & (TBSTYLE_WRAPABLE
| CCS_VERT
))
6338 TOOLBAR_LayoutToolbar(infoPtr
);
6340 /* only resize if one of the CCS_* styles was changed */
6341 if ((dwOldStyle
^ lpStyle
->styleNew
) & COMMON_STYLES
)
6343 TOOLBAR_AutoSize (infoPtr
);
6345 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6354 TOOLBAR_SysColorChange (void)
6356 COMCTL32_RefreshSysColors();
6362 /* update theme after a WM_THEMECHANGED message */
6363 static LRESULT
theme_changed (HWND hwnd
)
6365 HTHEME theme
= GetWindowTheme (hwnd
);
6366 CloseThemeData (theme
);
6367 OpenThemeData (hwnd
, themeClass
);
6372 static LRESULT WINAPI
6373 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6375 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
6377 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6378 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6380 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6381 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6386 return TOOLBAR_AddBitmap (infoPtr
, (INT
)wParam
, (TBADDBITMAP
*)lParam
);
6388 case TB_ADDBUTTONSA
:
6389 case TB_ADDBUTTONSW
:
6390 return TOOLBAR_AddButtonsT (infoPtr
, wParam
, (LPTBBUTTON
)lParam
,
6391 uMsg
== TB_ADDBUTTONSW
);
6393 return TOOLBAR_AddStringA (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6396 return TOOLBAR_AddStringW (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6399 return TOOLBAR_AutoSize (infoPtr
);
6401 case TB_BUTTONCOUNT
:
6402 return TOOLBAR_ButtonCount (infoPtr
);
6404 case TB_BUTTONSTRUCTSIZE
:
6405 return TOOLBAR_ButtonStructSize (infoPtr
, wParam
);
6407 case TB_CHANGEBITMAP
:
6408 return TOOLBAR_ChangeBitmap (infoPtr
, wParam
, LOWORD(lParam
));
6410 case TB_CHECKBUTTON
:
6411 return TOOLBAR_CheckButton (infoPtr
, wParam
, lParam
);
6413 case TB_COMMANDTOINDEX
:
6414 return TOOLBAR_CommandToIndex (infoPtr
, wParam
);
6417 return TOOLBAR_Customize (infoPtr
);
6419 case TB_DELETEBUTTON
:
6420 return TOOLBAR_DeleteButton (infoPtr
, wParam
);
6422 case TB_ENABLEBUTTON
:
6423 return TOOLBAR_EnableButton (infoPtr
, wParam
, lParam
);
6425 case TB_GETANCHORHIGHLIGHT
:
6426 return TOOLBAR_GetAnchorHighlight (infoPtr
);
6429 return TOOLBAR_GetBitmap (infoPtr
, wParam
);
6431 case TB_GETBITMAPFLAGS
:
6432 return TOOLBAR_GetBitmapFlags ();
6435 return TOOLBAR_GetButton (infoPtr
, wParam
, (TBBUTTON
*)lParam
);
6437 case TB_GETBUTTONINFOA
:
6438 case TB_GETBUTTONINFOW
:
6439 return TOOLBAR_GetButtonInfoT (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6440 uMsg
== TB_GETBUTTONINFOW
);
6441 case TB_GETBUTTONSIZE
:
6442 return TOOLBAR_GetButtonSize (infoPtr
);
6444 case TB_GETBUTTONTEXTA
:
6445 case TB_GETBUTTONTEXTW
:
6446 return TOOLBAR_GetButtonText (infoPtr
, wParam
, (LPWSTR
)lParam
,
6447 uMsg
== TB_GETBUTTONTEXTW
);
6449 case TB_GETDISABLEDIMAGELIST
:
6450 return TOOLBAR_GetDisabledImageList (infoPtr
, wParam
);
6452 case TB_GETEXTENDEDSTYLE
:
6453 return TOOLBAR_GetExtendedStyle (infoPtr
);
6455 case TB_GETHOTIMAGELIST
:
6456 return TOOLBAR_GetHotImageList (infoPtr
, wParam
);
6459 return TOOLBAR_GetHotItem (infoPtr
);
6461 case TB_GETIMAGELIST
:
6462 return TOOLBAR_GetDefImageList (infoPtr
, wParam
);
6464 case TB_GETINSERTMARK
:
6465 return TOOLBAR_GetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6467 case TB_GETINSERTMARKCOLOR
:
6468 return TOOLBAR_GetInsertMarkColor (infoPtr
);
6470 case TB_GETITEMRECT
:
6471 return TOOLBAR_GetItemRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6474 return TOOLBAR_GetMaxSize (infoPtr
, (LPSIZE
)lParam
);
6476 /* case TB_GETOBJECT: */ /* 4.71 */
6479 return TOOLBAR_GetPadding (infoPtr
);
6482 return TOOLBAR_GetRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6485 return TOOLBAR_GetRows (infoPtr
);
6488 return TOOLBAR_GetState (infoPtr
, wParam
);
6491 return TOOLBAR_GetStringA (infoPtr
, wParam
, (LPSTR
)lParam
);
6494 return TOOLBAR_GetStringW (infoPtr
, wParam
, (LPWSTR
)lParam
);
6497 return TOOLBAR_GetStyle (infoPtr
);
6499 case TB_GETTEXTROWS
:
6500 return TOOLBAR_GetTextRows (infoPtr
);
6502 case TB_GETTOOLTIPS
:
6503 return TOOLBAR_GetToolTips (infoPtr
);
6505 case TB_GETUNICODEFORMAT
:
6506 return TOOLBAR_GetUnicodeFormat (infoPtr
);
6509 return TOOLBAR_HideButton (infoPtr
, wParam
, LOWORD(lParam
));
6512 return TOOLBAR_HitTest (infoPtr
, (LPPOINT
)lParam
);
6514 case TB_INDETERMINATE
:
6515 return TOOLBAR_Indeterminate (infoPtr
, wParam
, LOWORD(lParam
));
6517 case TB_INSERTBUTTONA
:
6518 case TB_INSERTBUTTONW
:
6519 return TOOLBAR_InsertButtonT(infoPtr
, wParam
, (TBBUTTON
*)lParam
,
6520 uMsg
== TB_INSERTBUTTONW
);
6522 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6524 case TB_ISBUTTONCHECKED
:
6525 return TOOLBAR_IsButtonChecked (infoPtr
, wParam
);
6527 case TB_ISBUTTONENABLED
:
6528 return TOOLBAR_IsButtonEnabled (infoPtr
, wParam
);
6530 case TB_ISBUTTONHIDDEN
:
6531 return TOOLBAR_IsButtonHidden (infoPtr
, wParam
);
6533 case TB_ISBUTTONHIGHLIGHTED
:
6534 return TOOLBAR_IsButtonHighlighted (infoPtr
, wParam
);
6536 case TB_ISBUTTONINDETERMINATE
:
6537 return TOOLBAR_IsButtonIndeterminate (infoPtr
, wParam
);
6539 case TB_ISBUTTONPRESSED
:
6540 return TOOLBAR_IsButtonPressed (infoPtr
, wParam
);
6543 return TOOLBAR_LoadImages (infoPtr
, wParam
, (HINSTANCE
)lParam
);
6545 case TB_MAPACCELERATORA
:
6546 case TB_MAPACCELERATORW
:
6547 return TOOLBAR_MapAccelerator (infoPtr
, wParam
, (UINT
*)lParam
);
6550 return TOOLBAR_MarkButton (infoPtr
, wParam
, LOWORD(lParam
));
6553 return TOOLBAR_MoveButton (infoPtr
, wParam
, lParam
);
6555 case TB_PRESSBUTTON
:
6556 return TOOLBAR_PressButton (infoPtr
, wParam
, LOWORD(lParam
));
6558 case TB_REPLACEBITMAP
:
6559 return TOOLBAR_ReplaceBitmap (infoPtr
, (LPTBREPLACEBITMAP
)lParam
);
6561 case TB_SAVERESTOREA
:
6562 return TOOLBAR_SaveRestoreA (infoPtr
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6564 case TB_SAVERESTOREW
:
6565 return TOOLBAR_SaveRestoreW (infoPtr
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6567 case TB_SETANCHORHIGHLIGHT
:
6568 return TOOLBAR_SetAnchorHighlight (infoPtr
, (BOOL
)wParam
);
6570 case TB_SETBITMAPSIZE
:
6571 return TOOLBAR_SetBitmapSize (infoPtr
, wParam
, lParam
);
6573 case TB_SETBUTTONINFOA
:
6574 case TB_SETBUTTONINFOW
:
6575 return TOOLBAR_SetButtonInfo (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6576 uMsg
== TB_SETBUTTONINFOW
);
6577 case TB_SETBUTTONSIZE
:
6578 return TOOLBAR_SetButtonSize (infoPtr
, lParam
);
6580 case TB_SETBUTTONWIDTH
:
6581 return TOOLBAR_SetButtonWidth (infoPtr
, lParam
);
6584 return TOOLBAR_SetCmdId (infoPtr
, wParam
, lParam
);
6586 case TB_SETDISABLEDIMAGELIST
:
6587 return TOOLBAR_SetDisabledImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6589 case TB_SETDRAWTEXTFLAGS
:
6590 return TOOLBAR_SetDrawTextFlags (infoPtr
, wParam
, lParam
);
6592 case TB_SETEXTENDEDSTYLE
:
6593 return TOOLBAR_SetExtendedStyle (infoPtr
, wParam
, lParam
);
6595 case TB_SETHOTIMAGELIST
:
6596 return TOOLBAR_SetHotImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6599 return TOOLBAR_SetHotItem (infoPtr
, wParam
);
6601 case TB_SETIMAGELIST
:
6602 return TOOLBAR_SetImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6605 return TOOLBAR_SetIndent (infoPtr
, wParam
);
6607 case TB_SETINSERTMARK
:
6608 return TOOLBAR_SetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6610 case TB_SETINSERTMARKCOLOR
:
6611 return TOOLBAR_SetInsertMarkColor (infoPtr
, lParam
);
6613 case TB_SETMAXTEXTROWS
:
6614 return TOOLBAR_SetMaxTextRows (infoPtr
, wParam
);
6617 return TOOLBAR_SetPadding (infoPtr
, lParam
);
6620 return TOOLBAR_SetParent (infoPtr
, (HWND
)wParam
);
6623 return TOOLBAR_SetRows (infoPtr
, wParam
, (LPRECT
)lParam
);
6626 return TOOLBAR_SetState (infoPtr
, wParam
, lParam
);
6629 return TOOLBAR_SetStyle (infoPtr
, lParam
);
6631 case TB_SETTOOLTIPS
:
6632 return TOOLBAR_SetToolTips (infoPtr
, (HWND
)wParam
);
6634 case TB_SETUNICODEFORMAT
:
6635 return TOOLBAR_SetUnicodeFormat (infoPtr
, wParam
);
6638 return TOOLBAR_Unkwn45D(hwnd
, wParam
, lParam
);
6640 case TB_SETHOTITEM2
:
6641 return TOOLBAR_SetHotItem2 (infoPtr
, wParam
, lParam
);
6644 return TOOLBAR_SetListGap(infoPtr
, wParam
);
6646 case TB_GETIMAGELISTCOUNT
:
6647 return TOOLBAR_GetImageListCount(infoPtr
);
6649 case TB_GETIDEALSIZE
:
6650 return TOOLBAR_GetIdealSize (infoPtr
, wParam
, lParam
);
6653 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6655 /* Common Control Messages */
6657 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6658 case CCM_GETCOLORSCHEME
:
6659 return TOOLBAR_GetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6661 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6662 case CCM_SETCOLORSCHEME
:
6663 return TOOLBAR_SetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6665 case CCM_GETVERSION
:
6666 return TOOLBAR_GetVersion (infoPtr
);
6668 case CCM_SETVERSION
:
6669 return TOOLBAR_SetVersion (infoPtr
, (INT
)wParam
);
6675 return TOOLBAR_Create (hwnd
, (CREATESTRUCTW
*)lParam
);
6678 return TOOLBAR_Destroy (infoPtr
);
6681 return TOOLBAR_EraseBackground (infoPtr
, wParam
, lParam
);
6684 return TOOLBAR_GetFont (infoPtr
);
6687 return TOOLBAR_KeyDown (infoPtr
, wParam
, lParam
);
6689 /* case WM_KILLFOCUS: */
6691 case WM_LBUTTONDBLCLK
:
6692 return TOOLBAR_LButtonDblClk (infoPtr
, wParam
, lParam
);
6694 case WM_LBUTTONDOWN
:
6695 return TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
6698 return TOOLBAR_LButtonUp (infoPtr
, wParam
, lParam
);
6701 return TOOLBAR_RButtonUp (infoPtr
, wParam
, lParam
);
6703 case WM_RBUTTONDBLCLK
:
6704 return TOOLBAR_RButtonDblClk (infoPtr
, wParam
, lParam
);
6707 return TOOLBAR_MouseMove (infoPtr
, wParam
, lParam
);
6710 return TOOLBAR_MouseLeave (infoPtr
);
6712 case WM_CAPTURECHANGED
:
6713 return TOOLBAR_CaptureChanged(infoPtr
);
6716 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6719 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6722 return TOOLBAR_NCCreate (hwnd
, wParam
, (CREATESTRUCTW
*)lParam
);
6725 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
6728 return TOOLBAR_Notify (infoPtr
, (LPNMHDR
)lParam
);
6730 case WM_NOTIFYFORMAT
:
6731 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
6733 case WM_PRINTCLIENT
:
6735 return TOOLBAR_Paint (infoPtr
, wParam
);
6738 return TOOLBAR_SetFocus (infoPtr
);
6741 return TOOLBAR_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
6744 return TOOLBAR_SetRedraw (infoPtr
, wParam
);
6747 return TOOLBAR_Size (infoPtr
);
6749 case WM_STYLECHANGED
:
6750 return TOOLBAR_StyleChanged (infoPtr
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
6752 case WM_SYSCOLORCHANGE
:
6753 return TOOLBAR_SysColorChange ();
6755 case WM_THEMECHANGED
:
6756 return theme_changed (hwnd
);
6758 /* case WM_WININICHANGE: */
6763 case WM_MEASUREITEM
:
6765 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
6767 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6768 case PGM_FORWARDMOUSE
:
6769 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6772 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
6773 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
6774 uMsg
, wParam
, lParam
);
6775 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6781 TOOLBAR_Register (void)
6785 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
6786 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
6787 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
6788 wndClass
.cbClsExtra
= 0;
6789 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
6790 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
6791 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
6792 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
6794 RegisterClassW (&wndClass
);
6799 TOOLBAR_Unregister (void)
6801 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
6804 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
6809 /* Check if the entry already exists */
6810 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
6812 /* If this is a new entry we must create it and insert into the array */
6817 c
= Alloc(sizeof(IMLENTRY
));
6820 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
6821 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
6836 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
6840 for (i
= 0; i
< *cies
; i
++)
6850 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
6858 for (i
= 0; i
< cies
; i
++)
6860 if (pies
[i
]->id
== id
)
6872 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
6874 HIMAGELIST himlDef
= 0;
6875 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
6878 himlDef
= pie
->himl
;
6884 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
6886 if (infoPtr
->bUnicode
)
6887 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
6894 nmtba
.iItem
= nmtb
->iItem
;
6895 nmtba
.pszText
= Buffer
;
6896 nmtba
.cchText
= 256;
6897 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
6899 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
6901 int ccht
= strlen(nmtba
.pszText
);
6903 MultiByteToWideChar(CP_ACP
, 0, nmtba
.pszText
, -1,
6904 nmtb
->pszText
, nmtb
->cchText
);
6906 nmtb
->tbButton
= nmtba
.tbButton
;
6915 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
)
6919 /* MSDN states that iItem is the index of the button, rather than the
6920 * command ID as used by every other NMTOOLBAR notification */
6922 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
6924 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);