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
);
854 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
855 FIXME("Draw some kind of separator: fsStyle=%x\n",
861 /* get a pointer to the text */
862 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
864 if (hasDropDownArrow
)
868 if (dwStyle
& TBSTYLE_FLAT
)
869 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
871 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
873 if (drawSepDropDownArrow
)
876 rcArrow
.left
= right
;
879 /* copy text & bitmap rects after adjusting for drop-down arrow
880 * so that text & bitmap is centered in the rectangle not containing
882 CopyRect(&rcText
, &rc
);
883 CopyRect(&rcBitmap
, &rc
);
885 /* Center the bitmap horizontally and vertically */
886 if (dwStyle
& TBSTYLE_LIST
)
889 infoPtr
->nMaxTextRows
> 0 &&
890 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
891 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
892 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
894 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
897 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
899 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
901 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
902 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
903 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
904 TRACE("Text=%s\n", debugstr_w(lpText
));
905 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
907 /* calculate text position */
910 rcText
.left
+= GetSystemMetrics(SM_CXEDGE
);
911 rcText
.right
-= GetSystemMetrics(SM_CXEDGE
);
912 if (dwStyle
& TBSTYLE_LIST
)
914 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
918 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
919 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
921 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
925 /* Initialize fields in all cases, because we use these later
926 * NOTE: applications can and do alter these to customize their
928 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
929 tbcd
.clrText
= comctl32_color
.clrBtnText
;
930 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
931 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
932 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
933 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
934 tbcd
.clrHighlightHotTrack
= 0;
935 tbcd
.nStringBkMode
= TRANSPARENT
;
936 tbcd
.nHLStringBkMode
= OPAQUE
;
937 tbcd
.rcText
.left
= 0;
939 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
940 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
941 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
943 tbcd
.nmcd
.rc
= btnPtr
->rect
;
944 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
946 /* FIXME: what are these used for? */
950 /* Issue Item Prepaint notify */
953 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
955 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
956 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
957 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
958 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
959 /* reset these fields so the user can't alter the behaviour like native */
961 tbcd
.nmcd
.rc
= btnPtr
->rect
;
963 dwItemCustDraw
= ntfret
& 0xffff;
964 dwItemCDFlag
= ntfret
& 0xffff0000;
965 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
967 /* save the only part of the rect that the user can change */
968 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
969 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
972 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
973 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
974 OffsetRect(&rcText
, 1, 1);
976 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
977 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
978 TOOLBAR_DrawPattern (&rc
, &tbcd
);
980 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
981 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
983 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
987 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
988 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
989 if (hasDropDownArrow
)
990 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
991 SetBkColor(hdc
, oldclr
);
997 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
998 int stateId
= TS_NORMAL
;
1000 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1001 stateId
= TS_DISABLED
;
1002 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1003 stateId
= TS_PRESSED
;
1004 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1005 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1006 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1007 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1010 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &rc
, NULL
);
1013 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, &rc
, dwItemCDFlag
);
1015 if (drawSepDropDownArrow
)
1019 int stateId
= TS_NORMAL
;
1021 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1022 stateId
= TS_DISABLED
;
1023 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1024 stateId
= TS_PRESSED
;
1025 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1026 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1027 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1030 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1031 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1034 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1037 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1038 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1039 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1040 SetBkMode (hdc
, oldBkMode
);
1042 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1044 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1046 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1048 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1049 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1051 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1053 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1054 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1057 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1060 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1062 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1063 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1070 TOOLBAR_Refresh (TOOLBAR_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
1072 TBUTTON_INFO
*btnPtr
;
1074 RECT rcTemp
, rcClient
;
1075 NMTBCUSTOMDRAW tbcd
;
1077 DWORD dwBaseCustDraw
;
1079 /* the app has told us not to redraw the toolbar */
1080 if (!infoPtr
->bDoRedraw
)
1083 /* if imagelist belongs to the app, it can be changed
1084 by the app after setting it */
1085 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1087 infoPtr
->nNumBitmaps
= 0;
1088 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1089 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1092 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1094 /* change the imagelist icon size if we manage the list and it is necessary */
1095 TOOLBAR_CheckImageListIconSize(infoPtr
);
1097 /* Send initial notify */
1098 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1099 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1100 tbcd
.nmcd
.hdc
= hdc
;
1101 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1102 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1103 dwBaseCustDraw
= ntfret
& 0xffff;
1105 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1107 /* redraw necessary buttons */
1108 btnPtr
= infoPtr
->buttons
;
1109 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1112 if (!RectVisible(hdc
, &btnPtr
->rect
))
1114 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1116 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1117 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1121 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1122 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1124 TOOLBAR_DrawButton(infoPtr
, btnPtr
, hdc
, dwBaseCustDraw
);
1127 /* draw insert mark if required */
1128 if (infoPtr
->tbim
.iButton
!= -1)
1130 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1132 rcInsertMark
.top
= rcButton
.top
;
1133 rcInsertMark
.bottom
= rcButton
.bottom
;
1134 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1135 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1137 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1138 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1141 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1143 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1144 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1145 tbcd
.nmcd
.hdc
= hdc
;
1146 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1147 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1151 /***********************************************************************
1152 * TOOLBAR_MeasureString
1154 * This function gets the width and height of a string in pixels. This
1155 * is done first by using GetTextExtentPoint to get the basic width
1156 * and height. The DrawText is called with DT_CALCRECT to get the exact
1157 * width. The reason is because the text may have more than one "&" (or
1158 * prefix characters as M$ likes to call them). The prefix character
1159 * indicates where the underline goes, except for the string "&&" which
1160 * is reduced to a single "&". GetTextExtentPoint does not process these
1161 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1164 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1165 HDC hdc
, LPSIZE lpSize
)
1172 if (infoPtr
->nMaxTextRows
> 0 &&
1173 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1174 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1175 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1177 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1179 if(lpText
!= NULL
) {
1180 /* first get size of all the text */
1181 GetTextExtentPoint32W (hdc
, lpText
, strlenW (lpText
), lpSize
);
1183 /* feed above size into the rectangle for DrawText */
1184 myrect
.left
= myrect
.top
= 0;
1185 myrect
.right
= lpSize
->cx
;
1186 myrect
.bottom
= lpSize
->cy
;
1188 /* Use DrawText to get true size as drawn (less pesky "&") */
1189 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1190 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1193 /* feed back to caller */
1194 lpSize
->cx
= myrect
.right
;
1195 lpSize
->cy
= myrect
.bottom
;
1199 TRACE("string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1202 /***********************************************************************
1203 * TOOLBAR_CalcStrings
1205 * This function walks through each string and measures it and returns
1206 * the largest height and width to caller.
1209 TOOLBAR_CalcStrings (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
1211 TBUTTON_INFO
*btnPtr
;
1220 if (infoPtr
->nMaxTextRows
== 0)
1223 hdc
= GetDC (infoPtr
->hwndSelf
);
1224 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1226 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1230 GetTextMetricsW(hdc
, &tm
);
1231 lpSize
->cy
= tm
.tmHeight
;
1234 btnPtr
= infoPtr
->buttons
;
1235 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1236 if(TOOLBAR_GetText(infoPtr
, btnPtr
))
1238 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1239 if (sz
.cx
> lpSize
->cx
)
1241 if (sz
.cy
> lpSize
->cy
)
1246 SelectObject (hdc
, hOldFont
);
1247 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1249 TRACE("max string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1252 /***********************************************************************
1253 * TOOLBAR_WrapToolbar
1255 * This function walks through the buttons and separators in the
1256 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1257 * wrapping should occur based on the width of the toolbar window.
1258 * It does *not* calculate button placement itself. That task
1259 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1260 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1261 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1263 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_VERTICAL can be used also to allow
1264 * vertical toolbar lists.
1268 TOOLBAR_WrapToolbar(TOOLBAR_INFO
*infoPtr
)
1270 TBUTTON_INFO
*btnPtr
;
1275 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1276 /* no layout is necessary. Applications may use this style */
1277 /* to perform their own layout on the toolbar. */
1278 if( !(infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) &&
1279 !(infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
) ) return;
1281 btnPtr
= infoPtr
->buttons
;
1282 x
= infoPtr
->nIndent
;
1284 if (GetParent(infoPtr
->hwndSelf
))
1286 /* this can get the parents width, to know how far we can extend
1287 * this toolbar. We cannot use its height, as there may be multiple
1288 * toolbars in a rebar control
1290 GetClientRect( GetParent(infoPtr
->hwndSelf
), &rc
);
1291 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1295 GetWindowRect( infoPtr
->hwndSelf
, &rc
);
1296 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1299 bButtonWrap
= FALSE
;
1301 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1302 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, infoPtr
->nWidth
,
1305 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1307 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1309 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1312 if (btnPtr
[i
].cx
> 0)
1314 /* horizontal separators are treated as buttons for width */
1315 else if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1316 !(infoPtr
->dwStyle
& CCS_VERT
))
1317 cx
= (btnPtr
[i
].iBitmap
> 0) ? btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1319 cx
= infoPtr
->nButtonWidth
;
1321 /* Two or more adjacent separators form a separator group. */
1322 /* The first separator in a group should be wrapped to the */
1323 /* next row if the previous wrapping is on a button. */
1325 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1326 (i
+ 1 < infoPtr
->nNumButtons
) &&
1327 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1329 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1330 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1331 x
= infoPtr
->nIndent
;
1333 bButtonWrap
= FALSE
;
1337 /* The layout makes sure the bitmap is visible, but not the button. */
1338 /* Test added to also wrap after a button that starts a row but */
1339 /* is bigger than the area. - GA 8/01 */
1340 if (( x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2
1341 > infoPtr
->nWidth
) ||
1342 ((x
== infoPtr
->nIndent
) && (cx
> infoPtr
->nWidth
)))
1344 BOOL bFound
= FALSE
;
1346 /* If the current button is a separator and not hidden, */
1347 /* go to the next until it reaches a non separator. */
1348 /* Wrap the last separator if it is before a button. */
1349 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1350 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1351 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1352 i
< infoPtr
->nNumButtons
)
1358 if( bFound
&& i
< infoPtr
->nNumButtons
)
1361 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1362 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1363 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1364 x
= infoPtr
->nIndent
;
1365 bButtonWrap
= FALSE
;
1368 else if ( i
>= infoPtr
->nNumButtons
)
1371 /* If the current button is not a separator, find the last */
1372 /* separator and wrap it. */
1373 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1375 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1376 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1380 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1381 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1382 x
= infoPtr
->nIndent
;
1383 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1384 bButtonWrap
= FALSE
;
1389 /* If no separator available for wrapping, wrap one of */
1390 /* non-hidden previous button. */
1394 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1396 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1401 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1402 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1403 x
= infoPtr
->nIndent
;
1404 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1410 /* If all above failed, wrap the current button. */
1413 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1414 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1415 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1416 x
= infoPtr
->nIndent
;
1417 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1418 bButtonWrap
= FALSE
;
1424 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1425 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1432 /***********************************************************************
1433 * TOOLBAR_MeasureButton
1435 * Calculates the width and height required for a button. Used in
1436 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1437 * the width of buttons that are autosized.
1439 * Note that it would have been rather elegant to use one piece of code for
1440 * both the laying out of the toolbar and for controlling where button parts
1441 * are drawn, but the native control has inconsistencies between the two that
1442 * prevent this from being effectively. These inconsistencies can be seen as
1443 * artefacts where parts of the button appear outside of the bounding button
1446 * There are several cases for the calculation of the button dimensions and
1447 * button part positioning:
1454 * +--------------------------------------------------------+ ^
1456 * | | pad.cy / 2 | centered | |
1457 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1458 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1459 * | |<------------>| | | | |
1460 * | +--------------+ +------------+ | |
1461 * |<-------------------------------------->| | |
1462 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1464 * +--------------------------------------------------------+ -
1465 * <-------------------------------------------------------->
1466 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1468 * Without Bitmap (I_IMAGENONE):
1470 * +-----------------------------------+ ^
1472 * | | centered | | LISTPAD_CY +
1473 * | +------------+ | | szText.cy
1476 * | +------------+ | |
1477 * |<----------------->| | |
1478 * | cxedge |<-----------> | |
1480 * +-----------------------------------+ -
1481 * <----------------------------------->
1482 * szText.cx + pad.cx
1486 * +--------------------------------------+ ^
1488 * | | padding.cy/2 | | DEFPAD_CY +
1489 * | +------------+ | | nBitmapHeight
1492 * | +------------+ | |
1493 * |<------------------->| | |
1494 * | cxedge + iListGap/2 |<-----------> | |
1495 * | nBitmapWidth | |
1496 * +--------------------------------------+ -
1497 * <-------------------------------------->
1498 * 2*cxedge + nBitmapWidth + iListGap
1505 * +-----------------------------------+ ^
1507 * | | pad.cy / 2 | | nBitmapHeight +
1508 * | - | | szText.cy +
1509 * | +------------+ | | DEFPAD_CY + 1
1510 * | centered | Bitmap | | |
1511 * |<----------------->| | | |
1512 * | +------------+ | |
1516 * | centered +---------------+ | |
1517 * |<--------------->| Text | | |
1518 * | +---------------+ | |
1519 * +-----------------------------------+ -
1520 * <----------------------------------->
1521 * pad.cx + max(nBitmapWidth, szText.cx)
1523 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1525 * +---------------------------------------+ ^
1527 * | | 2 + pad.cy / 2 | |
1528 * | - | | szText.cy +
1529 * | centered +-----------------+ | | pad.cy + 2
1530 * |<--------------->| Text | | |
1531 * | +-----------------+ | |
1533 * +---------------------------------------+ -
1534 * <--------------------------------------->
1535 * 2*cxedge + pad.cx + szText.cx
1538 * As for with bitmaps, but with szText.cx zero.
1540 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1541 BOOL bHasBitmap
, BOOL bValidImageList
)
1544 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1546 /* set button height from bitmap / text height... */
1547 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1550 /* ... add on the necessary padding */
1551 if (bValidImageList
)
1554 sizeButton
.cy
+= DEFPAD_CY
;
1556 sizeButton
.cy
+= LISTPAD_CY
;
1559 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1561 /* calculate button width */
1562 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1563 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1564 if (sizeString
.cx
> 0)
1565 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1572 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1573 if (sizeString
.cy
> 0)
1574 sizeButton
.cy
+= 1 + sizeString
.cy
;
1575 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1576 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1580 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1581 NONLIST_NOTEXT_OFFSET
;
1582 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1583 max(2*GetSystemMetrics(SM_CXEDGE
) + sizeString
.cx
, infoPtr
->nBitmapWidth
);
1590 /***********************************************************************
1591 * TOOLBAR_CalcToolbar
1593 * This function calculates button and separator placement. It first
1594 * calculates the button sizes, gets the toolbar window width and then
1595 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1596 * on. It assigns a new location to each item and sends this location to
1597 * the tooltip window if appropriate. Finally, it updates the rcBound
1598 * rect and calculates the new required toolbar window height.
1601 TOOLBAR_CalcToolbar (TOOLBAR_INFO
*infoPtr
)
1603 SIZE sizeString
, sizeButton
;
1604 BOOL validImageList
= FALSE
;
1606 TOOLBAR_CalcStrings (infoPtr
, &sizeString
);
1608 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1610 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1611 validImageList
= TRUE
;
1612 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1613 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1614 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1615 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1617 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1618 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1619 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1620 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1622 TOOLBAR_LayoutToolbar(infoPtr
);
1626 TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
)
1628 TBUTTON_INFO
*btnPtr
;
1630 INT i
, nRows
, nSepRows
;
1633 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1634 BOOL hasDropDownArrows
= TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
);
1636 TOOLBAR_WrapToolbar(infoPtr
);
1638 x
= infoPtr
->nIndent
;
1639 y
= infoPtr
->iTopMargin
;
1640 cx
= infoPtr
->nButtonWidth
;
1641 cy
= infoPtr
->nButtonHeight
;
1643 nRows
= nSepRows
= 0;
1645 infoPtr
->rcBound
.top
= y
;
1646 infoPtr
->rcBound
.left
= x
;
1647 infoPtr
->rcBound
.bottom
= y
+ cy
;
1648 infoPtr
->rcBound
.right
= x
;
1650 btnPtr
= infoPtr
->buttons
;
1652 TRACE("cy=%d\n", cy
);
1654 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1657 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1659 SetRectEmpty (&btnPtr
->rect
);
1663 cy
= infoPtr
->nButtonHeight
;
1665 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1666 if (infoPtr
->dwStyle
& CCS_VERT
) {
1667 cy
= (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1668 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
: infoPtr
->nButtonWidth
;
1671 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
:
1672 (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1678 else if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1679 (btnPtr
->fsStyle
& BTNS_AUTOSIZE
))
1685 hdc
= GetDC (infoPtr
->hwndSelf
);
1686 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1688 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1690 SelectObject (hdc
, hOldFont
);
1691 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1693 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1694 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1699 cx
= infoPtr
->nButtonWidth
;
1701 /* if size has been set manually then don't add on extra space
1702 * for the drop down arrow */
1703 if (!btnPtr
->cx
&& hasDropDownArrows
&&
1704 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) || (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)))
1705 cx
+= DDARROW_WIDTH
;
1707 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1710 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1712 if (infoPtr
->rcBound
.left
> x
)
1713 infoPtr
->rcBound
.left
= x
;
1714 if (infoPtr
->rcBound
.right
< x
+ cx
)
1715 infoPtr
->rcBound
.right
= x
+ cx
;
1716 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1717 infoPtr
->rcBound
.bottom
= y
+ cy
;
1719 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1721 /* btnPtr->nRow is zero based. The space between the rows is */
1722 /* also considered as a row. */
1723 btnPtr
->nRow
= nRows
+ nSepRows
;
1725 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1726 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1731 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1735 if ( !(infoPtr
->dwStyle
& CCS_VERT
))
1736 y
+= cy
+ ( (btnPtr
->cx
> 0 ) ?
1737 btnPtr
->cx
: SEPARATOR_WIDTH
) * 2 /3;
1741 /* nSepRows is used to calculate the extra height following */
1745 x
= infoPtr
->nIndent
;
1747 /* Increment row number unless this is the last button */
1748 /* and it has Wrap set. */
1749 if (i
!= infoPtr
->nNumButtons
-1)
1756 /* infoPtr->nRows is the number of rows on the toolbar */
1757 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1759 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1764 TOOLBAR_InternalHitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
*lpPt
, BOOL
*button
)
1766 TBUTTON_INFO
*btnPtr
;
1772 btnPtr
= infoPtr
->buttons
;
1773 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1774 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1777 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1778 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1779 TRACE(" ON SEPARATOR %d!\n", i
);
1784 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1785 TRACE(" ON BUTTON %d!\n", i
);
1793 TRACE(" NOWHERE!\n");
1794 return TOOLBAR_NOWHERE
;
1798 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1800 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO
*infoPtr
, INT iIndex
, UINT nAddButtons
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
1802 INT nOldButtons
, nNewButtons
, iButton
;
1803 BOOL fHasString
= FALSE
;
1805 if (iIndex
< 0) /* iIndex can be negative, what means adding at the end */
1806 iIndex
= infoPtr
->nNumButtons
;
1808 nOldButtons
= infoPtr
->nNumButtons
;
1809 nNewButtons
= nOldButtons
+ nAddButtons
;
1811 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
1812 memmove(&infoPtr
->buttons
[iIndex
+ nAddButtons
], &infoPtr
->buttons
[iIndex
],
1813 (nOldButtons
- iIndex
) * sizeof(TBUTTON_INFO
));
1814 infoPtr
->nNumButtons
+= nAddButtons
;
1816 /* insert new buttons data */
1817 for (iButton
= 0; iButton
< nAddButtons
; iButton
++) {
1818 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[iIndex
+ iButton
];
1820 TOOLBAR_DumpTBButton(lpTbb
+ iButton
, fUnicode
);
1822 ZeroMemory(btnPtr
, sizeof(*btnPtr
));
1824 btnPtr
->iBitmap
= lpTbb
[iButton
].iBitmap
;
1825 btnPtr
->idCommand
= lpTbb
[iButton
].idCommand
;
1826 btnPtr
->fsState
= lpTbb
[iButton
].fsState
;
1827 btnPtr
->fsStyle
= lpTbb
[iButton
].fsStyle
;
1828 btnPtr
->dwData
= lpTbb
[iButton
].dwData
;
1829 if (btnPtr
->fsStyle
& BTNS_SEP
)
1830 btnPtr
->iString
= -1;
1831 else if(!IS_INTRESOURCE(lpTbb
[iButton
].iString
) && lpTbb
[iButton
].iString
!= -1)
1834 Str_SetPtrW((LPWSTR
*)&btnPtr
->iString
, (LPWSTR
)lpTbb
[iButton
].iString
);
1836 Str_SetPtrAtoW((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lpTbb
[iButton
].iString
);
1840 btnPtr
->iString
= lpTbb
[iButton
].iString
;
1842 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
1845 if (infoPtr
->nNumStrings
> 0 || fHasString
)
1846 TOOLBAR_CalcToolbar(infoPtr
);
1848 TOOLBAR_LayoutToolbar(infoPtr
);
1849 TOOLBAR_AutoSize(infoPtr
);
1851 TOOLBAR_DumpToolbar(infoPtr
, __LINE__
);
1852 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1858 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1860 TBUTTON_INFO
*btnPtr
;
1863 if (CommandIsIndex
) {
1864 TRACE("command is really index command=%d\n", idCommand
);
1865 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1868 btnPtr
= infoPtr
->buttons
;
1869 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1870 if (btnPtr
->idCommand
== idCommand
) {
1871 TRACE("command=%d index=%d\n", idCommand
, i
);
1875 TRACE("no index found for command=%d\n", idCommand
);
1881 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1883 TBUTTON_INFO
*btnPtr
;
1886 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1889 /* check index button */
1890 btnPtr
= &infoPtr
->buttons
[nIndex
];
1891 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1892 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1896 /* check previous buttons */
1897 nRunIndex
= nIndex
- 1;
1898 while (nRunIndex
>= 0) {
1899 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1900 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1901 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1909 /* check next buttons */
1910 nRunIndex
= nIndex
+ 1;
1911 while (nRunIndex
< infoPtr
->nNumButtons
) {
1912 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1913 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1914 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1927 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1928 WPARAM wParam
, LPARAM lParam
)
1934 msg
.wParam
= wParam
;
1935 msg
.lParam
= lParam
;
1936 msg
.time
= GetMessageTime ();
1937 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
1938 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
1940 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1944 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1946 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
1949 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
1950 ti
.cbSize
= sizeof (TTTOOLINFOW
);
1951 ti
.hwnd
= infoPtr
->hwndSelf
;
1952 ti
.uId
= button
->idCommand
;
1954 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
1955 /* ti.lParam = random value from the stack? */
1957 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
1963 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1965 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
1968 ZeroMemory(&ti
, sizeof(ti
));
1969 ti
.cbSize
= sizeof(ti
);
1970 ti
.hwnd
= infoPtr
->hwndSelf
;
1971 ti
.uId
= button
->idCommand
;
1973 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
1977 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1979 /* Set the toolTip only for non-hidden, non-separator button */
1980 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
1984 ZeroMemory(&ti
, sizeof(ti
));
1985 ti
.cbSize
= sizeof(ti
);
1986 ti
.hwnd
= infoPtr
->hwndSelf
;
1987 ti
.uId
= button
->idCommand
;
1988 ti
.rect
= button
->rect
;
1989 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
1993 /* Creates the tooltip control */
1995 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
1998 NMTOOLTIPSCREATED nmttc
;
2000 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
2001 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2002 infoPtr
->hwndSelf
, 0, 0, 0);
2004 if (!infoPtr
->hwndToolTip
)
2007 /* Send NM_TOOLTIPSCREATED notification */
2008 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
2009 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
2011 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
2013 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
2014 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
2018 /* keeps available button list box sorted by button id */
2019 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
2023 PCUSTOMBUTTON btnInfo
;
2024 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2026 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
2028 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2030 /* position 0 is always separator */
2031 for (i
= 1; i
< count
; i
++)
2033 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2034 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2036 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2037 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2041 /* id higher than all others add to end */
2042 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2043 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2046 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2050 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2052 if (nIndexFrom
== nIndexTo
)
2055 /* MSDN states that iItem is the index of the button, rather than the
2056 * command ID as used by every other NMTOOLBAR notification */
2057 nmtb
.iItem
= nIndexFrom
;
2058 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2060 PCUSTOMBUTTON btnInfo
;
2062 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2063 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2065 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2067 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2068 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2069 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2070 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2073 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2075 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2077 /* last item is always separator, so -2 instead of -1 */
2078 if (nIndexTo
>= (count
- 2))
2079 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2081 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2083 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2084 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2086 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2090 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2094 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2096 /* MSDN states that iItem is the index of the button, rather than the
2097 * command ID as used by every other NMTOOLBAR notification */
2098 nmtb
.iItem
= nIndexAvail
;
2099 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2101 PCUSTOMBUTTON btnInfo
;
2103 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2104 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2105 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2107 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2109 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2111 /* remove from 'available buttons' list */
2112 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2113 if (nIndexAvail
== count
-1)
2114 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2116 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2120 PCUSTOMBUTTON btnNew
;
2122 /* duplicate 'separator' button */
2123 btnNew
= Alloc(sizeof(CUSTOMBUTTON
));
2128 /* insert into 'toolbar button' list */
2129 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2130 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2132 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2134 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2138 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2140 PCUSTOMBUTTON btnInfo
;
2141 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2143 TRACE("Remove: index %d\n", index
);
2145 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2147 /* send TBN_QUERYDELETE notification */
2148 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2152 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2153 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2155 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2157 /* insert into 'available button' list */
2158 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2159 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2163 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2167 /* drag list notification function for toolbar buttons list box */
2168 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2169 const DRAGLISTINFO
*pDLI
)
2171 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2172 switch (pDLI
->uNotification
)
2176 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2177 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2178 /* no dragging for last item (separator) */
2179 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2184 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2185 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2186 /* no dragging past last item (separator) */
2187 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2189 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2190 /* FIXME: native uses "move button" cursor */
2191 return DL_COPYCURSOR
;
2194 /* not over toolbar buttons list */
2195 if (nCurrentItem
< 0)
2197 POINT ptWindow
= pDLI
->ptCursor
;
2198 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2199 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2200 /* over available buttons list? */
2201 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2202 /* FIXME: native uses "move button" cursor */
2203 return DL_COPYCURSOR
;
2205 /* clear drag arrow */
2206 DrawInsert(hwnd
, hwndList
, -1);
2207 return DL_STOPCURSOR
;
2211 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2212 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2213 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2214 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2216 /* clear drag arrow */
2217 DrawInsert(hwnd
, hwndList
, -1);
2219 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2221 /* not over toolbar buttons list */
2224 POINT ptWindow
= pDLI
->ptCursor
;
2225 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2226 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2227 /* over available buttons list? */
2228 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2229 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2234 /* Clear drag arrow */
2235 DrawInsert(hwnd
, hwndList
, -1);
2242 /* drag list notification function for available buttons list box */
2243 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2244 const DRAGLISTINFO
*pDLI
)
2246 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2247 switch (pDLI
->uNotification
)
2253 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2254 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2255 /* no dragging past last item (separator) */
2256 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2258 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2259 /* FIXME: native uses "move button" cursor */
2260 return DL_COPYCURSOR
;
2263 /* not over toolbar buttons list */
2264 if (nCurrentItem
< 0)
2266 POINT ptWindow
= pDLI
->ptCursor
;
2267 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2268 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2269 /* over available buttons list? */
2270 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2271 /* FIXME: native uses "move button" cursor */
2272 return DL_COPYCURSOR
;
2274 /* clear drag arrow */
2275 DrawInsert(hwnd
, hwndList
, -1);
2276 return DL_STOPCURSOR
;
2280 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2281 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2282 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2283 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2285 /* clear drag arrow */
2286 DrawInsert(hwnd
, hwndList
, -1);
2288 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2292 /* Clear drag arrow */
2293 DrawInsert(hwnd
, hwndList
, -1);
2299 extern UINT uDragListMessage DECLSPEC_HIDDEN
;
2301 /***********************************************************************
2302 * TOOLBAR_CustomizeDialogProc
2303 * This function implements the toolbar customization dialog.
2305 static INT_PTR CALLBACK
2306 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2308 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2309 PCUSTOMBUTTON btnInfo
;
2311 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2316 custInfo
= (PCUSTDLG_INFO
)lParam
;
2317 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2324 NMTBINITCUSTOMIZE nmtbic
;
2326 infoPtr
= custInfo
->tbInfo
;
2328 /* send TBN_QUERYINSERT notification */
2329 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2331 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2334 nmtbic
.hwndDialog
= hwnd
;
2335 /* Send TBN_INITCUSTOMIZE notification */
2336 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2339 TRACE("TBNRF_HIDEHELP requested\n");
2340 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2343 /* add items to 'toolbar buttons' list and check if removable */
2344 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2346 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2347 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2348 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2349 btnInfo
->bVirtual
= FALSE
;
2350 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2352 /* send TBN_QUERYDELETE notification */
2353 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2355 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2356 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2359 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2361 /* insert separator button into 'available buttons' list */
2362 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2363 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2364 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2365 btnInfo
->bVirtual
= FALSE
;
2366 btnInfo
->bRemovable
= TRUE
;
2367 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2368 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2369 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2371 /* insert all buttons into dsa */
2374 /* send TBN_GETBUTTONINFO notification */
2377 nmtb
.pszText
= Buffer
;
2380 /* Clear previous button's text */
2381 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2383 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2386 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2387 nmtb
.tbButton
.fsStyle
, i
,
2388 nmtb
.tbButton
.idCommand
,
2389 nmtb
.tbButton
.iString
,
2390 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2393 /* insert button into the appropriate list */
2394 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2397 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2398 btnInfo
->bVirtual
= FALSE
;
2399 btnInfo
->bRemovable
= TRUE
;
2403 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2404 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2407 btnInfo
->btn
= nmtb
.tbButton
;
2408 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2410 if (lstrlenW(nmtb
.pszText
))
2411 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2412 else if (nmtb
.tbButton
.iString
>= 0 &&
2413 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2415 lstrcpyW(btnInfo
->text
,
2416 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2421 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2424 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2426 /* select first item in the 'available' list */
2427 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2429 /* append 'virtual' separator button to the 'toolbar buttons' list */
2430 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2431 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2432 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2433 btnInfo
->bVirtual
= TRUE
;
2434 btnInfo
->bRemovable
= FALSE
;
2435 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2436 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2437 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2439 /* select last item in the 'toolbar' list */
2440 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2441 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2443 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2444 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2446 /* set focus and disable buttons */
2447 PostMessageW (hwnd
, WM_USER
, 0, 0);
2452 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2453 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2454 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2455 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2459 EndDialog(hwnd
, FALSE
);
2463 switch (LOWORD(wParam
))
2465 case IDC_TOOLBARBTN_LBOX
:
2466 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2468 PCUSTOMBUTTON btnInfo
;
2473 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2474 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2476 /* send TBN_QUERYINSERT notification */
2478 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2480 /* get list box item */
2481 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2483 if (index
== (count
- 1))
2485 /* last item (virtual separator) */
2486 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2487 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2489 else if (index
== (count
- 2))
2491 /* second last item (last non-virtual item) */
2492 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2493 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2495 else if (index
== 0)
2498 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2499 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2503 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2504 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2507 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2511 case IDC_MOVEUP_BTN
:
2513 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2514 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2518 case IDC_MOVEDN_BTN
: /* move down */
2520 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2521 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2525 case IDC_REMOVE_BTN
: /* remove button */
2527 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2529 if (LB_ERR
== index
)
2532 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2536 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2539 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2542 case IDOK
: /* Add button */
2547 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2548 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2550 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2555 EndDialog(hwnd
, FALSE
);
2565 /* delete items from 'toolbar buttons' listbox*/
2566 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2567 for (i
= 0; i
< count
; i
++)
2569 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2571 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2573 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2576 /* delete items from 'available buttons' listbox*/
2577 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2578 for (i
= 0; i
< count
; i
++)
2580 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2582 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2584 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2589 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2591 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2596 COLORREF oldText
= 0;
2600 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, lpdis
->itemID
, 0);
2601 if (btnInfo
== NULL
)
2603 FIXME("btnInfo invalid!\n");
2607 /* set colors and select objects */
2608 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2609 if (btnInfo
->bVirtual
)
2610 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2612 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2613 hPen
= CreatePen( PS_SOLID
, 1,
2614 (lpdis
->itemState
& ODS_SELECTED
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2615 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2616 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2618 /* fill background rectangle */
2619 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2620 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2622 /* calculate button and text rectangles */
2623 CopyRect (&rcButton
, &lpdis
->rcItem
);
2624 InflateRect (&rcButton
, -1, -1);
2625 CopyRect (&rcText
, &rcButton
);
2626 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2627 rcText
.left
= rcButton
.right
+ 2;
2629 /* draw focus rectangle */
2630 if (lpdis
->itemState
& ODS_FOCUS
)
2631 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2634 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2635 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2637 /* draw image and text */
2638 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2639 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2640 btnInfo
->btn
.iBitmap
));
2641 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2642 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2644 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2645 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2647 /* delete objects and reset colors */
2648 SelectObject (lpdis
->hDC
, hOldBrush
);
2649 SelectObject (lpdis
->hDC
, hOldPen
);
2650 SetBkColor (lpdis
->hDC
, oldBk
);
2651 SetTextColor (lpdis
->hDC
, oldText
);
2652 DeleteObject( hPen
);
2657 case WM_MEASUREITEM
:
2658 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2660 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2662 lpmis
->itemHeight
= 15 + 8; /* default height */
2669 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2671 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2673 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2674 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2675 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2678 else if (wParam
== IDC_AVAILBTN_LBOX
)
2680 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2681 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2682 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2691 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2694 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2700 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2701 /* Add bitmaps to the default image list */
2702 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2703 hbmLoad
= CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2704 else if (bitmap
->hInst
== COMCTL32_hModule
)
2705 hbmLoad
= LoadImageW( bitmap
->hInst
, MAKEINTRESOURCEW(bitmap
->nID
),
2706 IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
2708 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2710 /* enlarge the bitmap if needed */
2711 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2712 if (bitmap
->hInst
!= COMCTL32_hModule
)
2713 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2715 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2716 DeleteObject(hbmLoad
);
2720 nCountAfter
= ImageList_GetImageCount(himlDef
);
2721 nAdded
= nCountAfter
- nCountBefore
;
2722 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2724 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2725 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2726 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2727 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2730 infoPtr
->nNumBitmaps
+= nAdded
;
2735 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2742 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2743 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2745 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2747 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2750 TRACE("Update icon size: %dx%d -> %dx%d\n",
2751 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2753 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2754 ILC_COLOR32
|ILC_MASK
, 8, 2);
2755 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2756 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2757 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2758 infoPtr
->himlInt
= himlNew
;
2760 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2761 ImageList_Destroy(himlDef
);
2764 /***********************************************************************
2765 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2769 TOOLBAR_AddBitmap (TOOLBAR_INFO
*infoPtr
, INT count
, const TBADDBITMAP
*lpAddBmp
)
2775 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr
->hwndSelf
, count
, lpAddBmp
);
2779 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2781 info
.hInst
= COMCTL32_hModule
;
2782 switch (lpAddBmp
->nID
)
2784 case IDB_STD_SMALL_COLOR
:
2786 info
.nID
= IDB_STD_SMALL
;
2788 case IDB_STD_LARGE_COLOR
:
2790 info
.nID
= IDB_STD_LARGE
;
2792 case IDB_VIEW_SMALL_COLOR
:
2794 info
.nID
= IDB_VIEW_SMALL
;
2796 case IDB_VIEW_LARGE_COLOR
:
2798 info
.nID
= IDB_VIEW_LARGE
;
2800 case IDB_HIST_SMALL_COLOR
:
2802 info
.nID
= IDB_HIST_SMALL
;
2804 case IDB_HIST_LARGE_COLOR
:
2806 info
.nID
= IDB_HIST_LARGE
;
2812 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2814 /* Windows resize all the buttons to the size of a newly added standard image */
2815 if (lpAddBmp
->nID
& 1)
2817 /* large icons: 24x24. Will make the button 31x30 */
2818 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2822 /* small icons: 16x16. Will make the buttons 23x22 */
2823 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2826 TOOLBAR_CalcToolbar (infoPtr
);
2830 info
.nButtons
= count
;
2831 info
.hInst
= lpAddBmp
->hInst
;
2832 info
.nID
= lpAddBmp
->nID
;
2833 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2836 /* check if the bitmap is already loaded and compute iSumButtons */
2838 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2840 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2841 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2843 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2846 if (!infoPtr
->cimlDef
) {
2847 /* create new default image list */
2848 TRACE ("creating default image list!\n");
2850 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2851 ILC_COLOR32
| ILC_MASK
, info
.nButtons
, 2);
2852 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2853 infoPtr
->himlInt
= himlDef
;
2856 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2860 WARN("No default image list available\n");
2864 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2867 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2868 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2869 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2870 infoPtr
->nNumBitmapInfos
++;
2871 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2873 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2879 TOOLBAR_AddButtonsT(TOOLBAR_INFO
*infoPtr
, INT nAddButtons
, const TBBUTTON
* lpTbb
, BOOL fUnicode
)
2881 TRACE("adding %d buttons (unicode=%d)!\n", nAddButtons
, fUnicode
);
2883 return TOOLBAR_InternalInsertButtonsT(infoPtr
, -1, nAddButtons
, lpTbb
, fUnicode
);
2888 TOOLBAR_AddStringW (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
2890 #define MAX_RESOURCE_STRING_LENGTH 512
2891 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2892 INT nIndex
= infoPtr
->nNumStrings
;
2894 TRACE("%p, %lx\n", hInstance
, lParam
);
2896 if (IS_INTRESOURCE(lParam
)) {
2897 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2904 TRACE("adding string from resource\n");
2906 if (!hInstance
) return -1;
2908 hrsrc
= FindResourceW( hInstance
, MAKEINTRESOURCEW((LOWORD(lParam
) >> 4) + 1),
2909 (LPWSTR
)RT_STRING
);
2912 TRACE("string not found in resources\n");
2916 len
= LoadStringW (hInstance
, (UINT
)lParam
,
2917 szString
, MAX_RESOURCE_STRING_LENGTH
);
2919 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2920 if (len
== 0 || len
== 1)
2923 TRACE("delimiter: 0x%x\n", *szString
);
2924 delimiter
= *szString
;
2927 while ((next_delim
= strchrW(p
, delimiter
)) != NULL
) {
2929 if (next_delim
+ 1 >= szString
+ len
)
2931 /* this may happen if delimiter == '\0' or if the last char is a
2932 * delimiter (then it is ignored like the native does) */
2936 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2937 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2938 infoPtr
->nNumStrings
++;
2944 LPWSTR p
= (LPWSTR
)lParam
;
2949 TRACE("adding string(s) from array\n");
2953 TRACE("len=%d %s\n", len
, debugstr_w(p
));
2954 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2955 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2956 infoPtr
->nNumStrings
++;
2963 TOOLBAR_CalcToolbar(infoPtr
);
2969 TOOLBAR_AddStringA (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
2971 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2976 TRACE("%p, %lx\n", hInstance
, lParam
);
2978 if (IS_INTRESOURCE(lParam
)) /* load from resources */
2979 return TOOLBAR_AddStringW(infoPtr
, hInstance
, lParam
);
2985 TRACE("adding string(s) from array\n");
2986 nIndex
= infoPtr
->nNumStrings
;
2989 TRACE("len=%d \"%s\"\n", len
, p
);
2991 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2992 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2993 infoPtr
->nNumStrings
++;
2999 TOOLBAR_CalcToolbar(infoPtr
);
3005 TOOLBAR_AutoSize (TOOLBAR_INFO
*infoPtr
)
3012 TRACE("auto sizing, style=%x!\n", infoPtr
->dwStyle
);
3014 parent
= GetParent (infoPtr
->hwndSelf
);
3016 if (!parent
|| !infoPtr
->bDoRedraw
)
3019 GetClientRect(parent
, &parent_rect
);
3021 x
= parent_rect
.left
;
3022 y
= parent_rect
.top
;
3024 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3026 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3027 cx
= parent_rect
.right
- parent_rect
.left
;
3029 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_VERTICAL
))
3031 TOOLBAR_LayoutToolbar(infoPtr
);
3032 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
3035 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3038 UINT uPosFlags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
3040 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3042 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3043 MapWindowPoints( 0, parent
, (POINT
*)&window_rect
, 2 );
3044 y
= window_rect
.top
;
3046 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3048 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3049 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3052 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3053 uPosFlags
|= SWP_NOMOVE
;
3055 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3056 cy
+= GetSystemMetrics(SM_CYEDGE
);
3058 if (infoPtr
->dwStyle
& WS_BORDER
)
3060 cx
+= 2 * GetSystemMetrics(SM_CXBORDER
);
3061 cy
+= 2 * GetSystemMetrics(SM_CYBORDER
);
3064 SetWindowPos(infoPtr
->hwndSelf
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3071 static inline LRESULT
3072 TOOLBAR_ButtonCount (const TOOLBAR_INFO
*infoPtr
)
3074 return infoPtr
->nNumButtons
;
3078 static inline LRESULT
3079 TOOLBAR_ButtonStructSize (TOOLBAR_INFO
*infoPtr
, DWORD Size
)
3081 infoPtr
->dwStructSize
= Size
;
3088 TOOLBAR_ChangeBitmap (TOOLBAR_INFO
*infoPtr
, INT Id
, INT Index
)
3090 TBUTTON_INFO
*btnPtr
;
3093 TRACE("button %d, iBitmap now %d\n", Id
, Index
);
3095 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3099 btnPtr
= &infoPtr
->buttons
[nIndex
];
3100 btnPtr
->iBitmap
= Index
;
3102 /* we HAVE to erase the background, the new bitmap could be */
3104 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3111 TOOLBAR_CheckButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3113 TBUTTON_INFO
*btnPtr
;
3116 BOOL bChecked
= FALSE
;
3118 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3120 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, nIndex
, lParam
);
3125 btnPtr
= &infoPtr
->buttons
[nIndex
];
3127 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) != 0;
3129 if (LOWORD(lParam
) == FALSE
)
3130 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3132 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3134 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3135 if (nOldIndex
== nIndex
)
3137 if (nOldIndex
!= -1)
3138 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3140 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3143 if( bChecked
!= LOWORD(lParam
) )
3145 if (nOldIndex
!= -1)
3146 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3147 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3150 /* FIXME: Send a WM_NOTIFY?? */
3157 TOOLBAR_CommandToIndex (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3159 return TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3164 TOOLBAR_Customize (TOOLBAR_INFO
*infoPtr
)
3166 CUSTDLG_INFO custInfo
;
3170 custInfo
.tbInfo
= infoPtr
;
3171 custInfo
.tbHwnd
= infoPtr
->hwndSelf
;
3173 /* send TBN_BEGINADJUST notification */
3174 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3176 ret
= DialogBoxParamW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3177 infoPtr
->hwndSelf
, TOOLBAR_CustomizeDialogProc
, (LPARAM
)&custInfo
);
3179 /* send TBN_ENDADJUST notification */
3180 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3187 TOOLBAR_DeleteButton (TOOLBAR_INFO
*infoPtr
, INT nIndex
)
3190 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3192 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3195 memset(&nmtb
, 0, sizeof(nmtb
));
3196 nmtb
.iItem
= btnPtr
->idCommand
;
3197 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3198 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3199 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3200 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3201 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3202 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3203 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3205 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3207 if (infoPtr
->nNumButtons
== 1) {
3208 TRACE(" simple delete!\n");
3209 if (TOOLBAR_ButtonHasString(infoPtr
->buttons
))
3210 Free((LPWSTR
)infoPtr
->buttons
[0].iString
);
3211 Free (infoPtr
->buttons
);
3212 infoPtr
->buttons
= NULL
;
3213 infoPtr
->nNumButtons
= 0;
3216 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3217 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3219 infoPtr
->nNumButtons
--;
3220 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3222 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3223 nIndex
* sizeof(TBUTTON_INFO
));
3226 if (nIndex
< infoPtr
->nNumButtons
) {
3227 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3228 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3231 if (TOOLBAR_ButtonHasString(&oldButtons
[nIndex
]))
3232 Free((LPWSTR
)oldButtons
[nIndex
].iString
);
3236 TOOLBAR_LayoutToolbar(infoPtr
);
3238 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3245 TOOLBAR_EnableButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3247 TBUTTON_INFO
*btnPtr
;
3251 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3253 TRACE("hwnd=%p, btn id=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, Id
, lParam
);
3258 btnPtr
= &infoPtr
->buttons
[nIndex
];
3260 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3262 /* update the toolbar button state */
3263 if(LOWORD(lParam
) == FALSE
) {
3264 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3266 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3269 /* redraw the button only if the state of the button changed */
3270 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3271 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3277 static inline LRESULT
3278 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO
*infoPtr
)
3280 return infoPtr
->bAnchor
;
3285 TOOLBAR_GetBitmap (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3289 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3293 return infoPtr
->buttons
[nIndex
].iBitmap
;
3297 static inline LRESULT
3298 TOOLBAR_GetBitmapFlags (void)
3300 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3305 TOOLBAR_GetButton (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, TBBUTTON
*lpTbb
)
3307 TBUTTON_INFO
*btnPtr
;
3312 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3315 btnPtr
= &infoPtr
->buttons
[nIndex
];
3316 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3317 lpTbb
->idCommand
= btnPtr
->idCommand
;
3318 lpTbb
->fsState
= btnPtr
->fsState
;
3319 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3320 lpTbb
->bReserved
[0] = 0;
3321 lpTbb
->bReserved
[1] = 0;
3322 lpTbb
->dwData
= btnPtr
->dwData
;
3323 lpTbb
->iString
= btnPtr
->iString
;
3330 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO
*infoPtr
, INT Id
, LPTBBUTTONINFOW lpTbInfo
, BOOL bUnicode
)
3332 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3333 TBUTTON_INFO
*btnPtr
;
3336 if (lpTbInfo
== NULL
)
3339 /* MSDN documents an iImageLabel field added in Vista but it is not present in
3340 * the headers and tests shows that even with comctl 6 Vista accepts only the
3341 * original TBBUTTONINFO size
3343 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3345 WARN("Invalid button size\n");
3349 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lpTbInfo
->dwMask
& TBIF_BYINDEX
);
3353 if (!(btnPtr
= &infoPtr
->buttons
[nIndex
])) return -1;
3355 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3356 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3357 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3358 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3359 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3360 lpTbInfo
->lParam
= btnPtr
->dwData
;
3361 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3362 /* tests show that for separators TBIF_SIZE returns not calculated width,
3363 but cx property, that differs from 0 only if application have
3364 specifically set it */
3365 lpTbInfo
->cx
= (btnPtr
->fsStyle
& BTNS_SEP
)
3366 ? btnPtr
->cx
: (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3367 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3368 lpTbInfo
->fsState
= btnPtr
->fsState
;
3369 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3370 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3371 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3372 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3373 can't use TOOLBAR_GetText here */
3374 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3375 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3377 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3379 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3381 lpTbInfo
->pszText
[0] = '\0';
3387 static inline LRESULT
3388 TOOLBAR_GetButtonSize (const TOOLBAR_INFO
*infoPtr
)
3390 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3391 (WORD
)infoPtr
->nButtonHeight
);
3396 TOOLBAR_GetButtonText (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPWSTR lpStr
, BOOL isW
)
3402 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3406 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3412 ret
= strlenW (lpText
);
3413 if (lpStr
) strcpyW (lpStr
, lpText
);
3417 ret
= WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3418 (LPSTR
)lpStr
, lpStr
? 0x7fffffff : 0, NULL
, NULL
) - 1;
3424 TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3426 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3427 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3428 return (LRESULT
)GETDISIMAGELIST(infoPtr
, wParam
);
3432 static inline LRESULT
3433 TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO
*infoPtr
)
3437 return infoPtr
->dwExStyle
;
3442 TOOLBAR_GetHotImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3444 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3445 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3446 return (LRESULT
)GETHOTIMAGELIST(infoPtr
, wParam
);
3451 TOOLBAR_GetHotItem (const TOOLBAR_INFO
*infoPtr
)
3453 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3456 if (infoPtr
->nHotItem
< 0)
3459 return (LRESULT
)infoPtr
->nHotItem
;
3464 TOOLBAR_GetDefImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3466 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3467 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3468 return (LRESULT
) GETDEFIMAGELIST(infoPtr
, wParam
);
3473 TOOLBAR_GetInsertMark (const TOOLBAR_INFO
*infoPtr
, TBINSERTMARK
*lptbim
)
3475 TRACE("hwnd = %p, lptbim = %p\n", infoPtr
->hwndSelf
, lptbim
);
3477 *lptbim
= infoPtr
->tbim
;
3483 static inline LRESULT
3484 TOOLBAR_GetInsertMarkColor (const TOOLBAR_INFO
*infoPtr
)
3486 TRACE("hwnd = %p\n", infoPtr
->hwndSelf
);
3488 return (LRESULT
)infoPtr
->clrInsertMark
;
3493 TOOLBAR_GetItemRect (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, LPRECT lpRect
)
3495 TBUTTON_INFO
*btnPtr
;
3497 btnPtr
= &infoPtr
->buttons
[nIndex
];
3498 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3503 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3506 lpRect
->left
= btnPtr
->rect
.left
;
3507 lpRect
->right
= btnPtr
->rect
.right
;
3508 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3509 lpRect
->top
= btnPtr
->rect
.top
;
3516 TOOLBAR_GetMaxSize (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
3521 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3522 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3524 TRACE("maximum size %d x %d\n",
3525 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3526 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3532 /* << TOOLBAR_GetObject >> */
3535 static inline LRESULT
3536 TOOLBAR_GetPadding (const TOOLBAR_INFO
*infoPtr
)
3538 return MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3543 TOOLBAR_GetRect (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPRECT lpRect
)
3545 TBUTTON_INFO
*btnPtr
;
3548 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3549 btnPtr
= &infoPtr
->buttons
[nIndex
];
3550 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3556 lpRect
->left
= btnPtr
->rect
.left
;
3557 lpRect
->right
= btnPtr
->rect
.right
;
3558 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3559 lpRect
->top
= btnPtr
->rect
.top
;
3565 static inline LRESULT
3566 TOOLBAR_GetRows (const TOOLBAR_INFO
*infoPtr
)
3568 return infoPtr
->nRows
;
3573 TOOLBAR_GetState (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3577 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3581 return infoPtr
->buttons
[nIndex
].fsState
;
3585 static inline LRESULT
3586 TOOLBAR_GetStyle (const TOOLBAR_INFO
*infoPtr
)
3588 return infoPtr
->dwStyle
;
3592 static inline LRESULT
3593 TOOLBAR_GetTextRows (const TOOLBAR_INFO
*infoPtr
)
3595 return infoPtr
->nMaxTextRows
;
3600 TOOLBAR_GetToolTips (TOOLBAR_INFO
*infoPtr
)
3602 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3603 TOOLBAR_TooltipCreateControl(infoPtr
);
3604 return (LRESULT
)infoPtr
->hwndToolTip
;
3609 TOOLBAR_GetUnicodeFormat (const TOOLBAR_INFO
*infoPtr
)
3611 TRACE("%s hwnd=%p\n",
3612 infoPtr
->bUnicode
? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
3614 return infoPtr
->bUnicode
;
3618 static inline LRESULT
3619 TOOLBAR_GetVersion (const TOOLBAR_INFO
*infoPtr
)
3621 return infoPtr
->iVersion
;
3626 TOOLBAR_HideButton (TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fHide
)
3628 TBUTTON_INFO
*btnPtr
;
3634 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3638 btnPtr
= &infoPtr
->buttons
[nIndex
];
3639 oldState
= btnPtr
->fsState
;
3642 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3644 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3646 if (oldState
!= btnPtr
->fsState
) {
3647 TOOLBAR_LayoutToolbar (infoPtr
);
3648 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3655 static inline LRESULT
3656 TOOLBAR_HitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
* lpPt
)
3658 return TOOLBAR_InternalHitTest (infoPtr
, lpPt
, NULL
);
3663 TOOLBAR_Indeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fIndeterminate
)
3665 TBUTTON_INFO
*btnPtr
;
3669 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3673 btnPtr
= &infoPtr
->buttons
[nIndex
];
3674 oldState
= btnPtr
->fsState
;
3677 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3679 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3681 if(oldState
!= btnPtr
->fsState
)
3682 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3689 TOOLBAR_InsertButtonT(TOOLBAR_INFO
*infoPtr
, INT nIndex
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
3695 /* EPP: this seems to be an undocumented call (from my IE4)
3696 * I assume in that case that:
3697 * - index of insertion is at the end of existing buttons
3698 * I only see this happen with nIndex == -1, but it could have a special
3699 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3701 nIndex
= infoPtr
->nNumButtons
;
3703 } else if (nIndex
< 0)
3706 TRACE("inserting button index=%d\n", nIndex
);
3707 if (nIndex
> infoPtr
->nNumButtons
) {
3708 nIndex
= infoPtr
->nNumButtons
;
3709 TRACE("adjust index=%d\n", nIndex
);
3712 return TOOLBAR_InternalInsertButtonsT(infoPtr
, nIndex
, 1, lpTbb
, fUnicode
);
3715 /* << TOOLBAR_InsertMarkHitTest >> */
3719 TOOLBAR_IsButtonChecked (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3723 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3727 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3732 TOOLBAR_IsButtonEnabled (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3736 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3740 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3745 TOOLBAR_IsButtonHidden (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3749 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3753 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3758 TOOLBAR_IsButtonHighlighted (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3762 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3766 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3771 TOOLBAR_IsButtonIndeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3775 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3779 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3784 TOOLBAR_IsButtonPressed (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3788 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3792 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3797 TOOLBAR_LoadImages (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HINSTANCE hInstance
)
3800 tbab
.hInst
= hInstance
;
3803 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", infoPtr
->hwndSelf
, tbab
.hInst
, tbab
.nID
);
3805 return TOOLBAR_AddBitmap(infoPtr
, 0, &tbab
);
3810 TOOLBAR_MapAccelerator (const TOOLBAR_INFO
*infoPtr
, WCHAR wAccel
, UINT
*pIDButton
)
3812 WCHAR wszAccel
[] = {'&',wAccel
,0};
3815 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3816 infoPtr
->hwndSelf
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3818 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3820 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3821 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3822 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3824 int iLen
= strlenW(wszAccel
);
3825 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3832 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3837 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
3839 *pIDButton
= btnPtr
->idCommand
;
3851 TOOLBAR_MarkButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fMark
)
3855 TBUTTON_INFO
*btnPtr
;
3857 TRACE("hwnd = %p, Id = %d, fMark = 0%d\n", infoPtr
->hwndSelf
, Id
, fMark
);
3859 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3863 btnPtr
= &infoPtr
->buttons
[nIndex
];
3864 oldState
= btnPtr
->fsState
;
3867 btnPtr
->fsState
|= TBSTATE_MARKED
;
3869 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
3871 if(oldState
!= btnPtr
->fsState
)
3872 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3878 /* fixes up an index of a button affected by a move */
3879 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
3883 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
3885 else if (*pIndex
== nIndex
)
3886 *pIndex
= nMoveIndex
;
3890 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
3892 else if (*pIndex
== nIndex
)
3893 *pIndex
= nMoveIndex
;
3899 TOOLBAR_MoveButton (TOOLBAR_INFO
*infoPtr
, INT Id
, INT nMoveIndex
)
3903 TBUTTON_INFO button
;
3905 TRACE("hwnd=%p, Id=%d, nMoveIndex=%d\n", infoPtr
->hwndSelf
, Id
, nMoveIndex
);
3907 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, TRUE
);
3908 if ((nIndex
== -1) || (nMoveIndex
< 0))
3911 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
3912 nMoveIndex
= infoPtr
->nNumButtons
- 1;
3914 button
= infoPtr
->buttons
[nIndex
];
3916 /* move button right */
3917 if (nIndex
< nMoveIndex
)
3919 nCount
= nMoveIndex
- nIndex
;
3920 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
3921 infoPtr
->buttons
[nMoveIndex
] = button
;
3923 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
3924 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
3925 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
3926 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
3928 else if (nIndex
> nMoveIndex
) /* move button left */
3930 nCount
= nIndex
- nMoveIndex
;
3931 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
3932 infoPtr
->buttons
[nMoveIndex
] = button
;
3934 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
3935 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
3936 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
3937 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
3940 TOOLBAR_LayoutToolbar(infoPtr
);
3941 TOOLBAR_AutoSize(infoPtr
);
3942 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
3949 TOOLBAR_PressButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fPress
)
3951 TBUTTON_INFO
*btnPtr
;
3955 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3959 btnPtr
= &infoPtr
->buttons
[nIndex
];
3960 oldState
= btnPtr
->fsState
;
3963 btnPtr
->fsState
|= TBSTATE_PRESSED
;
3965 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
3967 if(oldState
!= btnPtr
->fsState
)
3968 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3973 /* FIXME: there might still be some confusion her between number of buttons
3974 * and number of bitmaps */
3976 TOOLBAR_ReplaceBitmap (TOOLBAR_INFO
*infoPtr
, const TBREPLACEBITMAP
*lpReplace
)
3979 int i
= 0, nOldButtons
= 0, pos
= 0;
3980 int nOldBitmaps
, nNewBitmaps
= 0;
3981 HIMAGELIST himlDef
= 0;
3983 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
3984 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
3985 lpReplace
->nButtons
);
3987 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
3989 FIXME("changing standard bitmaps not implemented\n");
3992 else if (lpReplace
->hInstOld
!= 0 && lpReplace
->hInstOld
!= lpReplace
->hInstNew
)
3993 FIXME("resources not in the current module not implemented\n");
3995 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
3996 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
3997 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
3998 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
3999 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4001 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4002 nOldButtons
= tbi
->nButtons
;
4003 tbi
->nButtons
= lpReplace
->nButtons
;
4004 tbi
->hInst
= lpReplace
->hInstNew
;
4005 tbi
->nID
= lpReplace
->nIDNew
;
4006 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4009 pos
+= tbi
->nButtons
;
4012 if (nOldButtons
== 0)
4014 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4018 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4021 if (lpReplace
->hInstNew
)
4022 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4024 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4026 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4027 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4029 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4031 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4032 ImageList_Remove(himlDef
, i
);
4036 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4037 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4038 DeleteObject(hBitmap
);
4041 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4043 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4044 pos
, nOldBitmaps
, nNewBitmaps
);
4046 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4051 /* helper for TOOLBAR_SaveRestoreW */
4053 TOOLBAR_Save(const TBSAVEPARAMSW
*lpSave
)
4055 FIXME("save to %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4056 debugstr_w(lpSave
->pszValueName
));
4062 /* helper for TOOLBAR_Restore */
4064 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4068 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4070 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4073 Free(infoPtr
->buttons
);
4074 infoPtr
->buttons
= NULL
;
4075 infoPtr
->nNumButtons
= 0;
4079 /* helper for TOOLBAR_SaveRestoreW */
4081 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4090 /* restore toolbar information */
4091 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4092 debugstr_w(lpSave
->pszValueName
));
4094 memset(&nmtbr
, 0, sizeof(nmtbr
));
4096 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4097 KEY_QUERY_VALUE
, &hkey
);
4099 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4101 if (!res
&& dwType
!= REG_BINARY
)
4102 res
= ERROR_FILE_NOT_FOUND
;
4105 nmtbr
.pData
= Alloc(dwSize
);
4106 nmtbr
.cbData
= dwSize
;
4107 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4110 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4111 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4114 nmtbr
.pCurrent
= nmtbr
.pData
;
4116 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4117 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4119 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4123 /* remove all existing buttons as this function is designed to
4124 * restore the toolbar to a previously saved state */
4125 TOOLBAR_DeleteAllButtons(infoPtr
);
4127 for (i
= 0; i
< nmtbr
.cButtons
; i
++)
4130 nmtbr
.tbButton
.iBitmap
= -1;
4131 nmtbr
.tbButton
.fsState
= 0;
4132 nmtbr
.tbButton
.fsStyle
= 0;
4133 nmtbr
.tbButton
.idCommand
= 0;
4134 if (*nmtbr
.pCurrent
== (DWORD
)-1)
4137 nmtbr
.tbButton
.fsStyle
= TBSTYLE_SEP
;
4138 /* when inserting separators, iBitmap controls its size.
4139 0 sets default size (width) */
4140 nmtbr
.tbButton
.iBitmap
= 0;
4142 else if (*nmtbr
.pCurrent
== (DWORD
)-2)
4144 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4146 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4150 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4152 /* can't contain real string as we don't know whether
4153 * the client put an ANSI or Unicode string in there */
4154 if (!IS_INTRESOURCE(nmtbr
.tbButton
.iString
))
4155 nmtbr
.tbButton
.iString
= 0;
4157 TOOLBAR_InsertButtonT(infoPtr
, -1, &nmtbr
.tbButton
, TRUE
);
4160 /* do legacy notifications */
4161 if (infoPtr
->iVersion
< 5)
4163 /* FIXME: send TBN_BEGINADJUST */
4164 FIXME("send TBN_GETBUTTONINFO for each button\n");
4165 /* FIXME: send TBN_ENDADJUST */
4168 /* remove all uninitialised buttons
4169 * note: loop backwards to avoid having to fixup i on a
4171 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4172 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4173 TOOLBAR_DeleteButton(infoPtr
, i
);
4175 /* only indicate success if at least one button survived */
4176 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4187 TOOLBAR_SaveRestoreW (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4189 if (lpSave
== NULL
) return 0;
4192 return TOOLBAR_Save(lpSave
);
4194 return TOOLBAR_Restore(infoPtr
, lpSave
);
4199 TOOLBAR_SaveRestoreA (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4201 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4202 TBSAVEPARAMSW SaveW
;
4206 if (lpSave
== NULL
) return 0;
4208 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4209 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4210 if (pszSubKey
) goto exit
;
4211 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4213 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4214 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4215 if (!pszValueName
) goto exit
;
4216 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4218 SaveW
.pszValueName
= pszValueName
;
4219 SaveW
.pszSubKey
= pszSubKey
;
4220 SaveW
.hkr
= lpSave
->hkr
;
4221 result
= TOOLBAR_SaveRestoreW(infoPtr
, wParam
, &SaveW
);
4224 Free (pszValueName
);
4232 TOOLBAR_SetAnchorHighlight (TOOLBAR_INFO
*infoPtr
, BOOL bAnchor
)
4234 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4236 TRACE("hwnd=%p, bAnchor = %s\n", infoPtr
->hwndSelf
, bAnchor
? "TRUE" : "FALSE");
4238 infoPtr
->bAnchor
= bAnchor
;
4240 /* Native does not remove the hot effect from an already hot button */
4242 return (LRESULT
)bOldAnchor
;
4247 TOOLBAR_SetBitmapSize (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4249 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4250 short width
= (short)LOWORD(lParam
);
4251 short height
= (short)HIWORD(lParam
);
4253 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", infoPtr
->hwndSelf
, wParam
, lParam
);
4256 FIXME("wParam is %ld. Perhaps image list index?\n", wParam
);
4258 /* 0 width or height is changed to 1 */
4264 if (infoPtr
->nNumButtons
> 0)
4265 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4266 infoPtr
->nNumButtons
,
4267 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
, width
, height
);
4269 if (width
< -1 || height
< -1)
4271 /* Windows destroys the imagelist and seems to actually use negative
4272 * values to compute button sizes */
4273 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width
, height
);
4277 /* width or height of -1 means no change */
4279 infoPtr
->nBitmapWidth
= width
;
4281 infoPtr
->nBitmapHeight
= height
;
4283 if ((himlDef
== infoPtr
->himlInt
) &&
4284 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4286 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4287 infoPtr
->nBitmapHeight
);
4290 TOOLBAR_CalcToolbar(infoPtr
);
4291 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4297 TOOLBAR_SetButtonInfo (TOOLBAR_INFO
*infoPtr
, INT Id
,
4298 const TBBUTTONINFOW
*lptbbi
, BOOL isW
)
4300 TBUTTON_INFO
*btnPtr
;
4306 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4309 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lptbbi
->dwMask
& TBIF_BYINDEX
);
4313 btnPtr
= &infoPtr
->buttons
[nIndex
];
4314 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4315 btnPtr
->idCommand
= lptbbi
->idCommand
;
4316 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4317 btnPtr
->iBitmap
= lptbbi
->iImage
;
4318 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4319 btnPtr
->dwData
= lptbbi
->lParam
;
4320 if (lptbbi
->dwMask
& TBIF_SIZE
)
4321 btnPtr
->cx
= lptbbi
->cx
;
4322 if (lptbbi
->dwMask
& TBIF_STATE
)
4323 btnPtr
->fsState
= lptbbi
->fsState
;
4324 if (lptbbi
->dwMask
& TBIF_STYLE
)
4325 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4327 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4328 /* iString is index, zero it to make Str_SetPtr succeed */
4329 if (!TOOLBAR_ButtonHasString(btnPtr
)) btnPtr
->iString
= 0;
4332 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4334 Str_SetPtrAtoW ((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lptbbi
->pszText
);
4337 /* save the button rect to see if we need to redraw the whole toolbar */
4338 oldBtnRect
= btnPtr
->rect
;
4339 TOOLBAR_LayoutToolbar(infoPtr
);
4341 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4342 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4344 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4351 TOOLBAR_SetButtonSize (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4353 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4355 if ((cx
< 0) || (cy
< 0))
4357 ERR("invalid parameter 0x%08x\n", (DWORD
)lParam
);
4361 TRACE("%p, cx = %d, cy = %d\n", infoPtr
->hwndSelf
, cx
, cy
);
4363 /* The documentation claims you can only change the button size before
4364 * any button has been added. But this is wrong.
4365 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4366 * it to the toolbar, and it checks that the return value is nonzero - mjm
4367 * Further testing shows that we must actually perform the change too.
4370 * The documentation also does not mention that if 0 is supplied for
4371 * either size, the system changes it to the default of 24 wide and
4372 * 22 high. Demonstrated in ControlSpy Toolbar. GLA 3/02
4374 if (cx
== 0) cx
= 24;
4375 if (cy
== 0) cy
= 22;
4377 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4378 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4380 infoPtr
->nButtonWidth
= cx
;
4381 infoPtr
->nButtonHeight
= cy
;
4383 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
4384 TOOLBAR_LayoutToolbar(infoPtr
);
4390 TOOLBAR_SetButtonWidth (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4392 /* if setting to current values, ignore */
4393 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4394 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4395 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4396 infoPtr
->cxMin
, infoPtr
->cxMax
);
4400 /* save new values */
4401 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4402 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4404 /* otherwise we need to recalc the toolbar and in some cases
4405 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4406 which doesn't actually draw - GA). */
4407 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4408 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4410 TOOLBAR_CalcToolbar (infoPtr
);
4412 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
4419 TOOLBAR_SetCmdId (TOOLBAR_INFO
*infoPtr
, INT nIndex
, INT nId
)
4421 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4424 infoPtr
->buttons
[nIndex
].idCommand
= nId
;
4426 if (infoPtr
->hwndToolTip
) {
4428 FIXME("change tool tip!\n");
4437 TOOLBAR_SetDisabledImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4439 HIMAGELIST himlTemp
;
4442 if (infoPtr
->iVersion
>= 5)
4445 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4446 &infoPtr
->cimlDis
, himl
, id
);
4448 /* FIXME: redraw ? */
4450 return (LRESULT
)himlTemp
;
4455 TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4459 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", infoPtr
->hwndSelf
, (DWORD
)wParam
, (DWORD
)lParam
);
4461 dwTemp
= infoPtr
->dwDTFlags
;
4462 infoPtr
->dwDTFlags
=
4463 (infoPtr
->dwDTFlags
& (DWORD
)wParam
) | (DWORD
)lParam
;
4465 return (LRESULT
)dwTemp
;
4468 /* This function differs a bit from what MSDN says it does:
4469 * 1. lParam contains extended style flags to OR with current style
4470 * (MSDN isn't clear on the OR bit)
4471 * 2. wParam appears to contain extended style flags to be reset
4472 * (MSDN says that this parameter is reserved)
4475 TOOLBAR_SetExtendedStyle (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD style
)
4477 DWORD old_style
= infoPtr
->dwExStyle
;
4479 TRACE("mask=0x%08x, style=0x%08x\n", mask
, style
);
4482 infoPtr
->dwExStyle
= (old_style
& ~mask
) | (style
& mask
);
4484 infoPtr
->dwExStyle
= style
;
4486 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4487 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4488 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4490 if ((old_style
^ infoPtr
->dwExStyle
) & TBSTYLE_EX_MIXEDBUTTONS
)
4491 TOOLBAR_CalcToolbar(infoPtr
);
4493 TOOLBAR_LayoutToolbar(infoPtr
);
4495 TOOLBAR_AutoSize(infoPtr
);
4496 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4503 TOOLBAR_SetHotImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4505 HIMAGELIST himlTemp
;
4508 if (infoPtr
->iVersion
>= 5)
4511 TRACE("hwnd = %p, himl = %p, id = %d\n", infoPtr
->hwndSelf
, himl
, id
);
4513 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4514 &infoPtr
->cimlHot
, himl
, id
);
4516 /* FIXME: redraw ? */
4518 return (LRESULT
)himlTemp
;
4522 /* Makes previous hot button no longer hot, makes the specified
4523 * button hot and sends appropriate notifications. dwReason is one or
4524 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4525 * NOTE 1: this function does not validate nHit
4526 * NOTE 2: the name of this function is completely made up and
4527 * not based on any documentation from Microsoft. */
4529 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4531 if (infoPtr
->nHotItem
!= nHit
)
4533 NMTBHOTITEM nmhotitem
;
4534 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4536 nmhotitem
.dwFlags
= dwReason
;
4537 if(infoPtr
->nHotItem
>= 0)
4539 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4540 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4544 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4545 nmhotitem
.idOld
= 0;
4550 btnPtr
= &infoPtr
->buttons
[nHit
];
4551 nmhotitem
.idNew
= btnPtr
->idCommand
;
4555 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4556 nmhotitem
.idNew
= 0;
4559 /* now change the hot and invalidate the old and new buttons - if the
4561 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4564 oldBtnPtr
->bHot
= FALSE
;
4565 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4567 /* setting disabled buttons as hot fails even if the notify contains the button id */
4568 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4569 btnPtr
->bHot
= TRUE
;
4570 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4571 infoPtr
->nHotItem
= nHit
;
4574 infoPtr
->nHotItem
= -1;
4580 TOOLBAR_SetHotItem (TOOLBAR_INFO
*infoPtr
, INT nHotItem
)
4582 INT nOldHotItem
= infoPtr
->nHotItem
;
4584 TRACE("hwnd = %p, nHotItem = %d\n", infoPtr
->hwndSelf
, nHotItem
);
4586 if (nHotItem
>= infoPtr
->nNumButtons
)
4587 return infoPtr
->nHotItem
;
4592 /* NOTE: an application can still remove the hot item even if anchor
4593 * highlighting is enabled */
4595 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, HICF_OTHER
);
4597 if (nOldHotItem
< 0)
4600 return (LRESULT
)nOldHotItem
;
4605 TOOLBAR_SetImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4607 HIMAGELIST himlTemp
;
4608 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4609 INT oldBitmapWidth
= infoPtr
->nBitmapWidth
;
4610 INT oldBitmapHeight
= infoPtr
->nBitmapHeight
;
4613 if (infoPtr
->iVersion
>= 5)
4616 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4617 &infoPtr
->cimlDef
, himl
, id
);
4619 infoPtr
->nNumBitmaps
= 0;
4620 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4621 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4623 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4624 &infoPtr
->nBitmapHeight
))
4626 infoPtr
->nBitmapWidth
= 1;
4627 infoPtr
->nBitmapHeight
= 1;
4629 if ((oldBitmapWidth
!= infoPtr
->nBitmapWidth
) || (oldBitmapHeight
!= infoPtr
->nBitmapHeight
))
4631 TOOLBAR_CalcToolbar(infoPtr
);
4632 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4633 TOOLBAR_SetButtonSize(infoPtr
, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4636 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4637 infoPtr
->hwndSelf
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4638 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4640 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4642 return (LRESULT
)himlTemp
;
4647 TOOLBAR_SetIndent (TOOLBAR_INFO
*infoPtr
, INT nIndent
)
4649 infoPtr
->nIndent
= nIndent
;
4653 /* process only on indent changing */
4654 if(infoPtr
->nIndent
!= nIndent
)
4656 infoPtr
->nIndent
= nIndent
;
4657 TOOLBAR_CalcToolbar (infoPtr
);
4658 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4666 TOOLBAR_SetInsertMark (TOOLBAR_INFO
*infoPtr
, const TBINSERTMARK
*lptbim
)
4668 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", infoPtr
->hwndSelf
, lptbim
->iButton
, lptbim
->dwFlags
);
4670 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4672 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4676 if ((lptbim
->iButton
== -1) ||
4677 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4678 (lptbim
->iButton
>= 0)))
4680 infoPtr
->tbim
= *lptbim
;
4681 /* FIXME: don't need to update entire toolbar */
4682 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4685 ERR("Invalid button index %d\n", lptbim
->iButton
);
4692 TOOLBAR_SetInsertMarkColor (TOOLBAR_INFO
*infoPtr
, COLORREF clr
)
4694 infoPtr
->clrInsertMark
= clr
;
4696 /* FIXME: don't need to update entire toolbar */
4697 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4704 TOOLBAR_SetMaxTextRows (TOOLBAR_INFO
*infoPtr
, INT nMaxRows
)
4706 infoPtr
->nMaxTextRows
= nMaxRows
;
4708 TOOLBAR_CalcToolbar(infoPtr
);
4713 /* MSDN gives slightly wrong info on padding.
4714 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4715 * 2. It is not used to create a blank area between the edge of the button
4716 * and the text or image if TBSTYLE_LIST is set. It is used to control
4717 * the gap between the image and text.
4718 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4719 * to control the bottom and right borders [with the border being
4720 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4721 * is shared evenly on both sides of the button.
4722 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4725 TOOLBAR_SetPadding (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4729 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4730 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4731 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4732 TRACE("cx=%d, cy=%d\n",
4733 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4734 return (LRESULT
) oldPad
;
4739 TOOLBAR_SetParent (TOOLBAR_INFO
*infoPtr
, HWND hParent
)
4745 hwndOldNotify
= infoPtr
->hwndNotify
;
4746 infoPtr
->hwndNotify
= hParent
;
4748 return (LRESULT
)hwndOldNotify
;
4753 TOOLBAR_SetRows (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPRECT lprc
)
4755 int rows
= LOWORD(wParam
);
4756 BOOL bLarger
= HIWORD(wParam
);
4760 TRACE("Setting rows to %d (%d)\n", rows
, bLarger
);
4762 if(infoPtr
->nRows
!= rows
)
4764 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
;
4765 int curColumn
= 0; /* Current column */
4766 int curRow
= 0; /* Current row */
4767 int hidden
= 0; /* Number of hidden buttons */
4768 int seps
= 0; /* Number of separators */
4769 int idealWrap
= 0; /* Ideal wrap point */
4774 Calculate new size and wrap points - Under windows, setrows will
4775 change the dimensions if needed to show the number of requested
4776 rows (if CCS_NORESIZE is set), or will take up the whole window
4777 (if no CCS_NORESIZE).
4779 Basic algorithm - If N buttons, and y rows requested, each row
4780 contains N/y buttons.
4782 FIXME: Handling of separators not obvious from testing results
4783 FIXME: Take width of window into account?
4786 /* Loop through the buttons one by one counting key items */
4787 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4789 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
4790 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4792 else if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
4796 /* FIXME: Separators make this quite complex */
4797 if (seps
) FIXME("Separators unhandled\n");
4799 /* Round up so more per line, i.e., less rows */
4800 idealWrap
= (infoPtr
->nNumButtons
- hidden
+ (rows
-1)) / (rows
? rows
: 1);
4802 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4803 achieve the requested number of rows. */
4804 if (bLarger
&& idealWrap
> 1)
4806 int resRows
= (infoPtr
->nNumButtons
+ (idealWrap
-1)) / idealWrap
;
4807 int moreRows
= (infoPtr
->nNumButtons
+ (idealWrap
-2)) / (idealWrap
-1);
4809 if (resRows
< rows
&& moreRows
> rows
)
4812 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap
);
4816 curColumn
= curRow
= 0;
4818 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap
,
4819 infoPtr
->nNumButtons
, hidden
, rows
);
4821 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4823 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4826 /* Step on, wrap if necessary or flag next to wrap */
4835 if (curColumn
> (idealWrap
-1)) {
4837 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
4841 TRACE("Result - %d rows\n", curRow
+ 1);
4843 /* recalculate toolbar */
4844 TOOLBAR_CalcToolbar (infoPtr
);
4846 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
4847 if NORESIZE is NOT set, then the toolbar will always be resized to
4848 take up the whole window. With it set, sizing needs to be manual. */
4849 if (infoPtr
->dwStyle
& CCS_NORESIZE
) {
4850 SetWindowPos(infoPtr
->hwndSelf
, NULL
, 0, 0,
4851 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
4852 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
,
4853 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
4856 /* repaint toolbar */
4857 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4860 /* return bounding rectangle */
4862 lprc
->left
= infoPtr
->rcBound
.left
;
4863 lprc
->right
= infoPtr
->rcBound
.right
;
4864 lprc
->top
= infoPtr
->rcBound
.top
;
4865 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
4873 TOOLBAR_SetState (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
4875 TBUTTON_INFO
*btnPtr
;
4878 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
4882 btnPtr
= &infoPtr
->buttons
[nIndex
];
4884 /* if hidden state has changed the invalidate entire window and recalc */
4885 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
4886 btnPtr
->fsState
= LOWORD(lParam
);
4887 TOOLBAR_CalcToolbar (infoPtr
);
4888 InvalidateRect(infoPtr
->hwndSelf
, 0, TRUE
);
4892 /* process state changing if current state doesn't match new state */
4893 if(btnPtr
->fsState
!= LOWORD(lParam
))
4895 btnPtr
->fsState
= LOWORD(lParam
);
4896 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4904 TOOLBAR_SetStyle (TOOLBAR_INFO
*infoPtr
, DWORD style
)
4906 infoPtr
->dwStyle
= style
;
4911 static inline LRESULT
4912 TOOLBAR_SetToolTips (TOOLBAR_INFO
*infoPtr
, HWND hwndTooltip
)
4914 TRACE("hwnd=%p, hwndTooltip=%p\n", infoPtr
->hwndSelf
, hwndTooltip
);
4916 infoPtr
->hwndToolTip
= hwndTooltip
;
4922 TOOLBAR_SetUnicodeFormat (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
4926 TRACE("%s hwnd=%p\n",
4927 ((BOOL
)wParam
) ? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
4929 bTemp
= infoPtr
->bUnicode
;
4930 infoPtr
->bUnicode
= (BOOL
)wParam
;
4937 TOOLBAR_GetColorScheme (const TOOLBAR_INFO
*infoPtr
, LPCOLORSCHEME lParam
)
4939 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
4940 comctl32_color
.clrBtnHighlight
:
4941 infoPtr
->clrBtnHighlight
;
4942 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
4943 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
4949 TOOLBAR_SetColorScheme (TOOLBAR_INFO
*infoPtr
, const COLORSCHEME
*lParam
)
4951 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
4952 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
4953 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
4955 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
4956 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
4957 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4963 TOOLBAR_SetVersion (TOOLBAR_INFO
*infoPtr
, INT iVersion
)
4965 INT iOldVersion
= infoPtr
->iVersion
;
4967 infoPtr
->iVersion
= iVersion
;
4969 if (infoPtr
->iVersion
>= 5)
4970 TOOLBAR_SetUnicodeFormat(infoPtr
, TRUE
);
4977 TOOLBAR_GetStringA (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPSTR str
)
4979 WORD iString
= HIWORD(wParam
);
4980 WORD buffersize
= LOWORD(wParam
);
4983 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, buffersize
, str
);
4985 if (iString
< infoPtr
->nNumStrings
)
4987 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
4990 TRACE("returning %s\n", debugstr_a(str
));
4993 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5000 TOOLBAR_GetStringW (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPWSTR str
)
5002 WORD iString
= HIWORD(wParam
);
5003 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5006 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, LOWORD(wParam
), str
);
5008 if (iString
< infoPtr
->nNumStrings
)
5010 len
= min(len
, strlenW(infoPtr
->strings
[iString
]));
5011 ret
= (len
+1)*sizeof(WCHAR
);
5014 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5019 TRACE("returning %s\n", debugstr_w(str
));
5022 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5027 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5028 * is the maximum size of the toolbar? */
5029 static LRESULT
TOOLBAR_Unkwn45D(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5031 SIZE
* pSize
= (SIZE
*)lParam
;
5032 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5037 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5038 * caller to specify a reason why the hot item changed (rather than just the
5039 * HICF_OTHER that TB_SETHOTITEM sends). */
5041 TOOLBAR_SetHotItem2 (TOOLBAR_INFO
*infoPtr
, INT nHotItem
, LPARAM lParam
)
5043 INT nOldHotItem
= infoPtr
->nHotItem
;
5045 TRACE("old item=%d, new item=%d, flags=%08x\n",
5046 nOldHotItem
, nHotItem
, (DWORD
)lParam
);
5048 if (nHotItem
< 0 || nHotItem
> infoPtr
->nNumButtons
)
5051 /* NOTE: an application can still remove the hot item even if anchor
5052 * highlighting is enabled */
5054 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, lParam
);
5058 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5061 /* Sets the toolbar global iListGap parameter which controls the amount of
5062 * spacing between the image and the text of buttons for TBSTYLE_LIST
5064 static LRESULT
TOOLBAR_SetListGap(TOOLBAR_INFO
*infoPtr
, INT iListGap
)
5066 TRACE("hwnd=%p iListGap=%d\n", infoPtr
->hwndSelf
, iListGap
);
5068 infoPtr
->iListGap
= iListGap
;
5070 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5075 /* Returns the number of maximum number of image lists associated with the
5076 * various states. */
5077 static LRESULT
TOOLBAR_GetImageListCount(const TOOLBAR_INFO
*infoPtr
)
5079 TRACE("hwnd=%p\n", infoPtr
->hwndSelf
);
5081 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5085 TOOLBAR_GetIdealSize (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5087 LPSIZE lpsize
= (LPSIZE
)lParam
;
5093 * Testing shows the following:
5094 * wParam = 0 adjust cx value
5095 * = 1 set cy value to max size.
5096 * lParam pointer to SIZE structure
5099 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5100 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5104 if (lpsize
->cx
== -1) {
5105 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5107 else if(HIWORD(lpsize
->cx
)) {
5109 HWND hwndParent
= GetParent(infoPtr
->hwndSelf
);
5111 GetWindowRect(infoPtr
->hwndSelf
, &rc
);
5112 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5113 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc
));
5114 lpsize
->cx
= max(rc
.right
-rc
.left
,
5115 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5118 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5122 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5125 FIXME("Unknown wParam %ld\n", wParam
);
5128 TRACE("set to -> 0x%08x 0x%08x\n",
5129 lpsize
->cx
, lpsize
->cy
);
5133 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5135 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5137 InvalidateRect(hwnd
, NULL
, TRUE
);
5143 TOOLBAR_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
5145 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
5148 TRACE("hwnd = %p, style=0x%08x\n", hwnd
, lpcs
->style
);
5150 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5151 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5152 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5153 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_REQUERY
));
5154 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5156 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5157 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5159 OpenThemeData (hwnd
, themeClass
);
5161 TOOLBAR_CheckStyle (infoPtr
);
5168 TOOLBAR_Destroy (TOOLBAR_INFO
*infoPtr
)
5172 /* delete tooltip control */
5173 if (infoPtr
->hwndToolTip
)
5174 DestroyWindow (infoPtr
->hwndToolTip
);
5176 /* delete temporary buffer for tooltip text */
5177 Free (infoPtr
->pszTooltipText
);
5178 Free (infoPtr
->bitmaps
); /* bitmaps list */
5180 /* delete button data */
5181 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5182 if (TOOLBAR_ButtonHasString(&infoPtr
->buttons
[i
]))
5183 Free ((LPWSTR
)infoPtr
->buttons
[i
].iString
);
5184 Free (infoPtr
->buttons
);
5186 /* delete strings */
5187 if (infoPtr
->strings
) {
5188 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5189 Free (infoPtr
->strings
[i
]);
5191 Free (infoPtr
->strings
);
5194 /* destroy internal image list */
5195 if (infoPtr
->himlInt
)
5196 ImageList_Destroy (infoPtr
->himlInt
);
5198 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5199 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5200 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5202 /* delete default font */
5203 DeleteObject (infoPtr
->hDefaultFont
);
5205 CloseThemeData (GetWindowTheme (infoPtr
->hwndSelf
));
5207 /* free toolbar info data */
5208 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
5216 TOOLBAR_EraseBackground (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5218 NMTBCUSTOMDRAW tbcd
;
5221 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
5222 DWORD dwEraseCustDraw
= 0;
5224 /* the app has told us not to redraw the toolbar */
5225 if (!infoPtr
->bDoRedraw
)
5228 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5229 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5230 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5231 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5232 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5233 dwEraseCustDraw
= ntfret
& 0xffff;
5235 /* FIXME: in general the return flags *can* be or'ed together */
5236 switch (dwEraseCustDraw
)
5238 case CDRF_DODEFAULT
:
5240 case CDRF_SKIPDEFAULT
:
5243 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5244 infoPtr
->hwndSelf
, ntfret
);
5248 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5249 * to my parent for processing.
5251 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5253 HDC hdc
= (HDC
)wParam
;
5258 parent
= GetParent(infoPtr
->hwndSelf
);
5259 MapWindowPoints(infoPtr
->hwndSelf
, parent
, &pt
, 1);
5260 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5261 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5262 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5265 ret
= DefWindowProcW (infoPtr
->hwndSelf
, WM_ERASEBKGND
, wParam
, lParam
);
5267 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5268 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5269 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5270 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5271 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5272 dwEraseCustDraw
= ntfret
& 0xffff;
5273 switch (dwEraseCustDraw
)
5275 case CDRF_DODEFAULT
:
5277 case CDRF_SKIPDEFAULT
:
5280 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5281 infoPtr
->hwndSelf
, ntfret
);
5288 static inline LRESULT
5289 TOOLBAR_GetFont (const TOOLBAR_INFO
*infoPtr
)
5291 return (LRESULT
)infoPtr
->hFont
;
5296 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5299 INT nNewHotItem
= infoPtr
->nHotItem
;
5301 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5304 if ((nNewHotItem
+ iDirection
< 0) ||
5305 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5307 NMTBWRAPHOTITEM nmtbwhi
;
5308 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5309 nmtbwhi
.iDirection
= iDirection
;
5310 nmtbwhi
.dwReason
= dwReason
;
5312 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5316 nNewHotItem
+= iDirection
;
5317 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5319 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5320 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5322 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5329 TOOLBAR_KeyDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5333 nmkey
.nVKey
= (UINT
)wParam
;
5334 nmkey
.uFlags
= HIWORD(lParam
);
5336 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5337 return DefWindowProcW(infoPtr
->hwndSelf
, WM_KEYDOWN
, wParam
, lParam
);
5339 switch ((UINT
)wParam
)
5343 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5347 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5351 if ((infoPtr
->nHotItem
>= 0) &&
5352 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5354 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5355 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5356 (LPARAM
)infoPtr
->hwndSelf
);
5366 TOOLBAR_LButtonDblClk (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5371 pt
.x
= (short)LOWORD(lParam
);
5372 pt
.y
= (short)HIWORD(lParam
);
5373 TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5376 TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
5377 else if (infoPtr
->dwStyle
& CCS_ADJUSTABLE
)
5378 TOOLBAR_Customize (infoPtr
);
5385 TOOLBAR_LButtonDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5387 TBUTTON_INFO
*btnPtr
;
5392 BOOL bDragKeyPressed
;
5397 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5398 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5400 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5402 if (infoPtr
->hwndToolTip
)
5403 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5404 WM_LBUTTONDOWN
, wParam
, lParam
);
5406 pt
.x
= (short)LOWORD(lParam
);
5407 pt
.y
= (short)HIWORD(lParam
);
5408 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5411 btnPtr
= &infoPtr
->buttons
[nHit
];
5413 if (button
&& bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5415 infoPtr
->nButtonDrag
= nHit
;
5416 SetCapture (infoPtr
->hwndSelf
);
5418 /* If drag cursor has not been loaded, load it.
5419 * Note: it doesn't need to be freed */
5421 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5422 SetCursor(hCursorDrag
);
5427 infoPtr
->nOldHit
= nHit
;
5429 CopyRect(&arrowRect
, &btnPtr
->rect
);
5430 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5432 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5433 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5434 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5435 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5436 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5437 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5441 /* draw in pressed state */
5442 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5443 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5445 btnPtr
->bDropDownPressed
= TRUE
;
5446 RedrawWindow(infoPtr
->hwndSelf
,&btnPtr
->rect
,0,
5447 RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5449 memset(&nmtb
, 0, sizeof(nmtb
));
5450 nmtb
.iItem
= btnPtr
->idCommand
;
5451 nmtb
.rcButton
= btnPtr
->rect
;
5452 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5454 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5456 if (res
!= TBDDRET_TREATPRESSED
)
5460 /* redraw button in unpressed state */
5461 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5462 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5464 btnPtr
->bDropDownPressed
= FALSE
;
5465 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5467 /* find and set hot item */
5469 ScreenToClient(infoPtr
->hwndSelf
, &pt
);
5470 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5471 if (!infoPtr
->bAnchor
|| button
)
5472 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5474 /* remove any left mouse button down or double-click messages
5475 * so that we can get a toggle effect on the button */
5476 while (PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5477 PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5482 /* otherwise drop through and process as pushed */
5484 infoPtr
->bCaptured
= TRUE
;
5485 infoPtr
->nButtonDown
= nHit
;
5486 infoPtr
->bDragOutSent
= FALSE
;
5488 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5490 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5492 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5493 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5494 UpdateWindow(infoPtr
->hwndSelf
);
5495 SetCapture (infoPtr
->hwndSelf
);
5500 memset(&nmtb
, 0, sizeof(nmtb
));
5501 nmtb
.iItem
= btnPtr
->idCommand
;
5502 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5505 nmmouse
.dwHitInfo
= nHit
;
5507 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5509 nmmouse
.dwItemSpec
= -1;
5512 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5513 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5516 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5519 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5520 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, wParam
, lParam
);
5526 TOOLBAR_LButtonUp (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5528 TBUTTON_INFO
*btnPtr
;
5537 if (infoPtr
->hwndToolTip
)
5538 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5539 WM_LBUTTONUP
, wParam
, lParam
);
5541 pt
.x
= (short)LOWORD(lParam
);
5542 pt
.y
= (short)HIWORD(lParam
);
5543 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5545 if (!infoPtr
->bAnchor
|| button
)
5546 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5548 if (infoPtr
->nButtonDrag
>= 0) {
5552 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5555 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5557 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5558 if (PtInRect(&rcClient
, pt
))
5565 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5568 if (nButton
== infoPtr
->nButtonDrag
)
5570 /* if the button is moved sightly left and we have a
5571 * separator there then remove it */
5572 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5574 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5575 TOOLBAR_DeleteButton(infoPtr
, nButton
- 1);
5577 else /* else insert a separator before the dragged button */
5580 memset(&tbb
, 0, sizeof(tbb
));
5581 tbb
.fsStyle
= BTNS_SEP
;
5583 TOOLBAR_InsertButtonT(infoPtr
, nButton
, &tbb
, TRUE
);
5590 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5591 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, 0);
5593 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5596 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, nButton
);
5601 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5602 TOOLBAR_DeleteButton(infoPtr
, infoPtr
->nButtonDrag
);
5605 /* button under cursor changed so need to re-set hot item */
5606 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5607 infoPtr
->nButtonDrag
= -1;
5609 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5611 else if (infoPtr
->nButtonDown
>= 0) {
5612 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5613 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5615 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5616 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5617 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5619 if ((nOldIndex
!= nHit
) &&
5621 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5622 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5625 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5626 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5628 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5632 if (nOldIndex
!= -1)
5633 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5636 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5637 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5638 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5640 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5642 infoPtr
->nButtonDown
= -1;
5644 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5645 TOOLBAR_SendNotify (&hdr
, infoPtr
,
5646 NM_RELEASEDCAPTURE
);
5648 memset(&nmtb
, 0, sizeof(nmtb
));
5649 nmtb
.iItem
= btnPtr
->idCommand
;
5650 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5653 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5655 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5656 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)infoPtr
->hwndSelf
);
5658 /* In case we have just been destroyed... */
5659 if(!IsWindow(infoPtr
->hwndSelf
))
5664 /* !!! Undocumented - toolbar at 4.71 level and above sends
5665 * NM_CLICK with the NMMOUSE structure. */
5666 nmmouse
.dwHitInfo
= nHit
;
5669 nmmouse
.dwItemSpec
= -1;
5672 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5673 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5676 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5679 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5680 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONUP
, wParam
, lParam
);
5686 TOOLBAR_RButtonUp(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5693 pt
.x
= (short)LOWORD(lParam
);
5694 pt
.y
= (short)HIWORD(lParam
);
5696 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5697 nmmouse
.dwHitInfo
= nHit
;
5700 nmmouse
.dwItemSpec
= -1;
5702 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5703 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5706 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5709 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5710 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONUP
, wParam
, lParam
);
5716 TOOLBAR_RButtonDblClk( TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5720 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5721 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
5727 TOOLBAR_CaptureChanged(TOOLBAR_INFO
*infoPtr
)
5729 TBUTTON_INFO
*btnPtr
;
5731 infoPtr
->bCaptured
= FALSE
;
5733 if (infoPtr
->nButtonDown
>= 0)
5735 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5736 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5738 infoPtr
->nOldHit
= -1;
5740 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5741 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5747 TOOLBAR_MouseLeave (TOOLBAR_INFO
*infoPtr
)
5749 /* don't remove hot effects when in anchor highlighting mode or when a
5750 * drop-down button is pressed */
5751 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
5753 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
5754 if (!hotBtnPtr
->bDropDownPressed
)
5755 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
5758 if (infoPtr
->nOldHit
< 0)
5761 /* If the last button we were over is depressed then make it not */
5762 /* depressed and redraw it */
5763 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
5765 TBUTTON_INFO
*btnPtr
;
5768 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5770 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5773 InflateRect (&rc1
, 1, 1);
5774 InvalidateRect (infoPtr
->hwndSelf
, &rc1
, TRUE
);
5777 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
5780 ZeroMemory(&nmt
, sizeof(nmt
));
5781 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5782 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5783 infoPtr
->bDragOutSent
= TRUE
;
5786 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
5792 TOOLBAR_MouseMove (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5795 TRACKMOUSEEVENT trackinfo
;
5797 TBUTTON_INFO
*btnPtr
;
5800 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
5801 TOOLBAR_TooltipCreateControl(infoPtr
);
5803 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
5804 /* fill in the TRACKMOUSEEVENT struct */
5805 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5806 trackinfo
.dwFlags
= TME_QUERY
;
5808 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5809 _TrackMouseEvent(&trackinfo
);
5811 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5812 if(trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
5813 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5814 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
5816 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5817 /* and can properly deactivate the hot toolbar button */
5818 _TrackMouseEvent(&trackinfo
);
5822 if (infoPtr
->hwndToolTip
)
5823 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5824 WM_MOUSEMOVE
, wParam
, lParam
);
5826 pt
.x
= (short)LOWORD(lParam
);
5827 pt
.y
= (short)HIWORD(lParam
);
5829 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5831 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
5832 && (!infoPtr
->bAnchor
|| button
))
5833 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
);
5835 if (infoPtr
->nOldHit
!= nHit
)
5837 if (infoPtr
->bCaptured
)
5839 if (!infoPtr
->bDragOutSent
)
5842 ZeroMemory(&nmt
, sizeof(nmt
));
5843 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5844 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5845 infoPtr
->bDragOutSent
= TRUE
;
5848 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5849 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
5850 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5851 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5853 else if (nHit
== infoPtr
->nButtonDown
) {
5854 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5855 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5857 infoPtr
->nOldHit
= nHit
;
5865 static inline LRESULT
5866 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5868 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5869 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
5871 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5875 static inline LRESULT
5876 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5878 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
5879 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
5881 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
5886 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
5888 TOOLBAR_INFO
*infoPtr
;
5891 /* allocate memory for info structure */
5892 infoPtr
= Alloc (sizeof(TOOLBAR_INFO
));
5893 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
5896 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
5898 infoPtr
->nWidth
= 0;
5900 /* initialize info structure */
5901 infoPtr
->nButtonWidth
= 23;
5902 infoPtr
->nButtonHeight
= 22;
5903 infoPtr
->nBitmapHeight
= 16;
5904 infoPtr
->nBitmapWidth
= 16;
5906 infoPtr
->nMaxTextRows
= 1;
5907 infoPtr
->cxMin
= -1;
5908 infoPtr
->cxMax
= -1;
5909 infoPtr
->nNumBitmaps
= 0;
5910 infoPtr
->nNumStrings
= 0;
5912 infoPtr
->bCaptured
= FALSE
;
5913 infoPtr
->nButtonDown
= -1;
5914 infoPtr
->nButtonDrag
= -1;
5915 infoPtr
->nOldHit
= -1;
5916 infoPtr
->nHotItem
= -1;
5917 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
5918 infoPtr
->dwDTFlags
= (lpcs
->style
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
5919 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
5920 infoPtr
->bDragOutSent
= FALSE
;
5921 infoPtr
->iVersion
= 0;
5922 infoPtr
->hwndSelf
= hwnd
;
5923 infoPtr
->bDoRedraw
= TRUE
;
5924 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
5925 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
5926 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
5927 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
5928 infoPtr
->iListGap
= DEFLISTGAP
;
5929 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
5930 infoPtr
->dwStyle
= lpcs
->style
;
5931 infoPtr
->tbim
.iButton
= -1;
5933 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5934 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
5935 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
5936 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
5939 /* I think the code below is a bug, but it is the way that the native
5940 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5941 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5942 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5943 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5944 * Somehow, the only cases of this seem to be MFC programs.
5946 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5947 * does not occur in the WM_STYLECHANGING routine.
5948 * (Guy Albertelli 9/2001)
5951 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
5952 && !(lpcs
->style
& TBSTYLE_TRANSPARENT
))
5953 styleadd
|= TBSTYLE_TRANSPARENT
;
5954 if (!(lpcs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
5955 styleadd
|= CCS_TOP
; /* default to top */
5956 SetWindowLongW (hwnd
, GWL_STYLE
, lpcs
->style
| styleadd
);
5959 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
5964 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5966 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5970 if (dwStyle
& WS_MINIMIZE
)
5971 return 0; /* Nothing to do */
5973 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
5975 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
5978 if (!(dwStyle
& CCS_NODIVIDER
))
5980 GetWindowRect (hwnd
, &rcWindow
);
5981 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
5982 if( dwStyle
& WS_BORDER
)
5983 InflateRect (&rcWindow
, -1, -1);
5984 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
5987 ReleaseDC( hwnd
, hdc
);
5993 /* handles requests from the tooltip control on what text to display */
5994 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
5996 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
5998 TRACE("button index = %d\n", index
);
6000 Free (infoPtr
->pszTooltipText
);
6001 infoPtr
->pszTooltipText
= NULL
;
6006 if (infoPtr
->bUnicode
)
6008 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6009 NMTBGETINFOTIPW tbgit
;
6010 unsigned int len
; /* in chars */
6012 wszBuffer
[0] = '\0';
6013 wszBuffer
[INFOTIPSIZE
] = '\0';
6015 tbgit
.pszText
= wszBuffer
;
6016 tbgit
.cchTextMax
= INFOTIPSIZE
;
6017 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6018 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6020 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6022 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6024 len
= strlenW(tbgit
.pszText
);
6025 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6027 /* need to allocate temporary buffer in infoPtr as there
6028 * isn't enough space in buffer passed to us by the
6029 * tooltip control */
6030 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6031 if (infoPtr
->pszTooltipText
)
6033 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6034 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6040 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6046 CHAR szBuffer
[INFOTIPSIZE
+1];
6047 NMTBGETINFOTIPA tbgit
;
6048 unsigned int len
; /* in chars */
6051 szBuffer
[INFOTIPSIZE
] = '\0';
6053 tbgit
.pszText
= szBuffer
;
6054 tbgit
.cchTextMax
= INFOTIPSIZE
;
6055 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6056 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6058 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6060 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6062 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6063 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]))
6065 /* need to allocate temporary buffer in infoPtr as there
6066 * isn't enough space in buffer passed to us by the
6067 * tooltip control */
6068 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6069 if (infoPtr
->pszTooltipText
)
6071 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6072 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6076 else if (tbgit
.pszText
&& tbgit
.pszText
[0])
6078 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1,
6079 lpnmtdi
->lpszText
, sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]));
6084 /* if button has text, but it is not shown then automatically
6085 * use that text as tooltip */
6086 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6087 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6089 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6090 unsigned int len
= pszText
? strlenW(pszText
) : 0;
6092 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6094 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6096 /* need to allocate temporary buffer in infoPtr as there
6097 * isn't enough space in buffer passed to us by the
6098 * tooltip control */
6099 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6100 if (infoPtr
->pszTooltipText
)
6102 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6103 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6109 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6114 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6116 /* last resort: send notification on to app */
6117 /* FIXME: find out what is really used here */
6118 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmtdi
->hdr
.idFrom
, (LPARAM
)lpnmtdi
);
6122 static inline LRESULT
6123 TOOLBAR_Notify (TOOLBAR_INFO
*infoPtr
, LPNMHDR lpnmh
)
6125 switch (lpnmh
->code
)
6129 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lpnmh
;
6131 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6132 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6133 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6137 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6138 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6146 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lpnmh
;
6148 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6149 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6150 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6151 lppgs
->iScroll
, lppgs
->iDir
);
6155 case TTN_GETDISPINFOW
:
6156 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lpnmh
);
6158 case TTN_GETDISPINFOA
:
6159 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6169 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6173 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam
, lParam
);
6175 if (lParam
== NF_QUERY
)
6178 if (lParam
== NF_REQUERY
) {
6179 format
= SendMessageW(infoPtr
->hwndNotify
,
6180 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6181 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6182 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6193 TOOLBAR_Paint (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6198 /* fill ps.rcPaint with a default rect */
6199 ps
.rcPaint
= infoPtr
->rcBound
;
6201 hdc
= wParam
==0 ? BeginPaint(infoPtr
->hwndSelf
, &ps
) : (HDC
)wParam
;
6203 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps
.rcPaint
));
6205 TOOLBAR_Refresh (infoPtr
, hdc
, &ps
);
6206 if (!wParam
) EndPaint (infoPtr
->hwndSelf
, &ps
);
6213 TOOLBAR_SetFocus (TOOLBAR_INFO
*infoPtr
)
6215 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6217 /* make first item hot */
6218 if (infoPtr
->nNumButtons
> 0)
6219 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6225 TOOLBAR_SetFont(TOOLBAR_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
6227 TRACE("font=%p redraw=%d\n", hFont
, Redraw
);
6230 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6232 infoPtr
->hFont
= hFont
;
6234 TOOLBAR_CalcToolbar(infoPtr
);
6237 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6242 TOOLBAR_SetRedraw (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6243 /*****************************************************
6246 * Handles the WM_SETREDRAW message.
6249 * According to testing V4.71 of COMCTL32 returns the
6250 * *previous* status of the redraw flag (either 0 or 1)
6251 * instead of the MSDN documented value of 0 if handled.
6252 * (For laughs see the "consistency" with same function
6255 *****************************************************/
6257 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6259 TRACE("set to %s\n",
6260 (wParam
) ? "TRUE" : "FALSE");
6261 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6263 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6265 return (oldredraw
) ? 1 : 0;
6270 TOOLBAR_Size (TOOLBAR_INFO
*infoPtr
)
6272 TRACE("sizing toolbar!\n");
6274 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6276 RECT delta_width
, delta_height
, client
, dummy
;
6277 DWORD min_x
, max_x
, min_y
, max_y
;
6278 TBUTTON_INFO
*btnPtr
;
6281 GetClientRect(infoPtr
->hwndSelf
, &client
);
6282 if(client
.right
> infoPtr
->client_rect
.right
)
6284 min_x
= infoPtr
->client_rect
.right
;
6285 max_x
= client
.right
;
6289 max_x
= infoPtr
->client_rect
.right
;
6290 min_x
= client
.right
;
6292 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6294 min_y
= infoPtr
->client_rect
.bottom
;
6295 max_y
= client
.bottom
;
6299 max_y
= infoPtr
->client_rect
.bottom
;
6300 min_y
= client
.bottom
;
6303 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6304 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6306 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6307 btnPtr
= infoPtr
->buttons
;
6308 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6309 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6310 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6311 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6313 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->client_rect
);
6314 TOOLBAR_AutoSize(infoPtr
);
6320 TOOLBAR_StyleChanged (TOOLBAR_INFO
*infoPtr
, INT nType
, const STYLESTRUCT
*lpStyle
)
6322 if (nType
== GWL_STYLE
)
6324 DWORD dwOldStyle
= infoPtr
->dwStyle
;
6326 if (lpStyle
->styleNew
& TBSTYLE_LIST
)
6327 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
6329 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
6331 TRACE("new style 0x%08x\n", lpStyle
->styleNew
);
6333 infoPtr
->dwStyle
= lpStyle
->styleNew
;
6334 TOOLBAR_CheckStyle (infoPtr
);
6336 if ((dwOldStyle
^ lpStyle
->styleNew
) & (TBSTYLE_WRAPABLE
| CCS_VERT
))
6337 TOOLBAR_LayoutToolbar(infoPtr
);
6339 /* only resize if one of the CCS_* styles was changed */
6340 if ((dwOldStyle
^ lpStyle
->styleNew
) & COMMON_STYLES
)
6342 TOOLBAR_AutoSize (infoPtr
);
6344 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6353 TOOLBAR_SysColorChange (void)
6355 COMCTL32_RefreshSysColors();
6361 /* update theme after a WM_THEMECHANGED message */
6362 static LRESULT
theme_changed (HWND hwnd
)
6364 HTHEME theme
= GetWindowTheme (hwnd
);
6365 CloseThemeData (theme
);
6366 OpenThemeData (hwnd
, themeClass
);
6371 static LRESULT WINAPI
6372 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6374 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
6376 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6377 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6379 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6380 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6385 return TOOLBAR_AddBitmap (infoPtr
, (INT
)wParam
, (TBADDBITMAP
*)lParam
);
6387 case TB_ADDBUTTONSA
:
6388 case TB_ADDBUTTONSW
:
6389 return TOOLBAR_AddButtonsT (infoPtr
, wParam
, (LPTBBUTTON
)lParam
,
6390 uMsg
== TB_ADDBUTTONSW
);
6392 return TOOLBAR_AddStringA (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6395 return TOOLBAR_AddStringW (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6398 return TOOLBAR_AutoSize (infoPtr
);
6400 case TB_BUTTONCOUNT
:
6401 return TOOLBAR_ButtonCount (infoPtr
);
6403 case TB_BUTTONSTRUCTSIZE
:
6404 return TOOLBAR_ButtonStructSize (infoPtr
, wParam
);
6406 case TB_CHANGEBITMAP
:
6407 return TOOLBAR_ChangeBitmap (infoPtr
, wParam
, LOWORD(lParam
));
6409 case TB_CHECKBUTTON
:
6410 return TOOLBAR_CheckButton (infoPtr
, wParam
, lParam
);
6412 case TB_COMMANDTOINDEX
:
6413 return TOOLBAR_CommandToIndex (infoPtr
, wParam
);
6416 return TOOLBAR_Customize (infoPtr
);
6418 case TB_DELETEBUTTON
:
6419 return TOOLBAR_DeleteButton (infoPtr
, wParam
);
6421 case TB_ENABLEBUTTON
:
6422 return TOOLBAR_EnableButton (infoPtr
, wParam
, lParam
);
6424 case TB_GETANCHORHIGHLIGHT
:
6425 return TOOLBAR_GetAnchorHighlight (infoPtr
);
6428 return TOOLBAR_GetBitmap (infoPtr
, wParam
);
6430 case TB_GETBITMAPFLAGS
:
6431 return TOOLBAR_GetBitmapFlags ();
6434 return TOOLBAR_GetButton (infoPtr
, wParam
, (TBBUTTON
*)lParam
);
6436 case TB_GETBUTTONINFOA
:
6437 case TB_GETBUTTONINFOW
:
6438 return TOOLBAR_GetButtonInfoT (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6439 uMsg
== TB_GETBUTTONINFOW
);
6440 case TB_GETBUTTONSIZE
:
6441 return TOOLBAR_GetButtonSize (infoPtr
);
6443 case TB_GETBUTTONTEXTA
:
6444 case TB_GETBUTTONTEXTW
:
6445 return TOOLBAR_GetButtonText (infoPtr
, wParam
, (LPWSTR
)lParam
,
6446 uMsg
== TB_GETBUTTONTEXTW
);
6448 case TB_GETDISABLEDIMAGELIST
:
6449 return TOOLBAR_GetDisabledImageList (infoPtr
, wParam
);
6451 case TB_GETEXTENDEDSTYLE
:
6452 return TOOLBAR_GetExtendedStyle (infoPtr
);
6454 case TB_GETHOTIMAGELIST
:
6455 return TOOLBAR_GetHotImageList (infoPtr
, wParam
);
6458 return TOOLBAR_GetHotItem (infoPtr
);
6460 case TB_GETIMAGELIST
:
6461 return TOOLBAR_GetDefImageList (infoPtr
, wParam
);
6463 case TB_GETINSERTMARK
:
6464 return TOOLBAR_GetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6466 case TB_GETINSERTMARKCOLOR
:
6467 return TOOLBAR_GetInsertMarkColor (infoPtr
);
6469 case TB_GETITEMRECT
:
6470 return TOOLBAR_GetItemRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6473 return TOOLBAR_GetMaxSize (infoPtr
, (LPSIZE
)lParam
);
6475 /* case TB_GETOBJECT: */ /* 4.71 */
6478 return TOOLBAR_GetPadding (infoPtr
);
6481 return TOOLBAR_GetRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6484 return TOOLBAR_GetRows (infoPtr
);
6487 return TOOLBAR_GetState (infoPtr
, wParam
);
6490 return TOOLBAR_GetStringA (infoPtr
, wParam
, (LPSTR
)lParam
);
6493 return TOOLBAR_GetStringW (infoPtr
, wParam
, (LPWSTR
)lParam
);
6496 return TOOLBAR_GetStyle (infoPtr
);
6498 case TB_GETTEXTROWS
:
6499 return TOOLBAR_GetTextRows (infoPtr
);
6501 case TB_GETTOOLTIPS
:
6502 return TOOLBAR_GetToolTips (infoPtr
);
6504 case TB_GETUNICODEFORMAT
:
6505 return TOOLBAR_GetUnicodeFormat (infoPtr
);
6508 return TOOLBAR_HideButton (infoPtr
, wParam
, LOWORD(lParam
));
6511 return TOOLBAR_HitTest (infoPtr
, (LPPOINT
)lParam
);
6513 case TB_INDETERMINATE
:
6514 return TOOLBAR_Indeterminate (infoPtr
, wParam
, LOWORD(lParam
));
6516 case TB_INSERTBUTTONA
:
6517 case TB_INSERTBUTTONW
:
6518 return TOOLBAR_InsertButtonT(infoPtr
, wParam
, (TBBUTTON
*)lParam
,
6519 uMsg
== TB_INSERTBUTTONW
);
6521 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6523 case TB_ISBUTTONCHECKED
:
6524 return TOOLBAR_IsButtonChecked (infoPtr
, wParam
);
6526 case TB_ISBUTTONENABLED
:
6527 return TOOLBAR_IsButtonEnabled (infoPtr
, wParam
);
6529 case TB_ISBUTTONHIDDEN
:
6530 return TOOLBAR_IsButtonHidden (infoPtr
, wParam
);
6532 case TB_ISBUTTONHIGHLIGHTED
:
6533 return TOOLBAR_IsButtonHighlighted (infoPtr
, wParam
);
6535 case TB_ISBUTTONINDETERMINATE
:
6536 return TOOLBAR_IsButtonIndeterminate (infoPtr
, wParam
);
6538 case TB_ISBUTTONPRESSED
:
6539 return TOOLBAR_IsButtonPressed (infoPtr
, wParam
);
6542 return TOOLBAR_LoadImages (infoPtr
, wParam
, (HINSTANCE
)lParam
);
6544 case TB_MAPACCELERATORA
:
6545 case TB_MAPACCELERATORW
:
6546 return TOOLBAR_MapAccelerator (infoPtr
, wParam
, (UINT
*)lParam
);
6549 return TOOLBAR_MarkButton (infoPtr
, wParam
, LOWORD(lParam
));
6552 return TOOLBAR_MoveButton (infoPtr
, wParam
, lParam
);
6554 case TB_PRESSBUTTON
:
6555 return TOOLBAR_PressButton (infoPtr
, wParam
, LOWORD(lParam
));
6557 case TB_REPLACEBITMAP
:
6558 return TOOLBAR_ReplaceBitmap (infoPtr
, (LPTBREPLACEBITMAP
)lParam
);
6560 case TB_SAVERESTOREA
:
6561 return TOOLBAR_SaveRestoreA (infoPtr
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6563 case TB_SAVERESTOREW
:
6564 return TOOLBAR_SaveRestoreW (infoPtr
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6566 case TB_SETANCHORHIGHLIGHT
:
6567 return TOOLBAR_SetAnchorHighlight (infoPtr
, (BOOL
)wParam
);
6569 case TB_SETBITMAPSIZE
:
6570 return TOOLBAR_SetBitmapSize (infoPtr
, wParam
, lParam
);
6572 case TB_SETBUTTONINFOA
:
6573 case TB_SETBUTTONINFOW
:
6574 return TOOLBAR_SetButtonInfo (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6575 uMsg
== TB_SETBUTTONINFOW
);
6576 case TB_SETBUTTONSIZE
:
6577 return TOOLBAR_SetButtonSize (infoPtr
, lParam
);
6579 case TB_SETBUTTONWIDTH
:
6580 return TOOLBAR_SetButtonWidth (infoPtr
, lParam
);
6583 return TOOLBAR_SetCmdId (infoPtr
, wParam
, lParam
);
6585 case TB_SETDISABLEDIMAGELIST
:
6586 return TOOLBAR_SetDisabledImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6588 case TB_SETDRAWTEXTFLAGS
:
6589 return TOOLBAR_SetDrawTextFlags (infoPtr
, wParam
, lParam
);
6591 case TB_SETEXTENDEDSTYLE
:
6592 return TOOLBAR_SetExtendedStyle (infoPtr
, wParam
, lParam
);
6594 case TB_SETHOTIMAGELIST
:
6595 return TOOLBAR_SetHotImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6598 return TOOLBAR_SetHotItem (infoPtr
, wParam
);
6600 case TB_SETIMAGELIST
:
6601 return TOOLBAR_SetImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6604 return TOOLBAR_SetIndent (infoPtr
, wParam
);
6606 case TB_SETINSERTMARK
:
6607 return TOOLBAR_SetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6609 case TB_SETINSERTMARKCOLOR
:
6610 return TOOLBAR_SetInsertMarkColor (infoPtr
, lParam
);
6612 case TB_SETMAXTEXTROWS
:
6613 return TOOLBAR_SetMaxTextRows (infoPtr
, wParam
);
6616 return TOOLBAR_SetPadding (infoPtr
, lParam
);
6619 return TOOLBAR_SetParent (infoPtr
, (HWND
)wParam
);
6622 return TOOLBAR_SetRows (infoPtr
, wParam
, (LPRECT
)lParam
);
6625 return TOOLBAR_SetState (infoPtr
, wParam
, lParam
);
6628 return TOOLBAR_SetStyle (infoPtr
, lParam
);
6630 case TB_SETTOOLTIPS
:
6631 return TOOLBAR_SetToolTips (infoPtr
, (HWND
)wParam
);
6633 case TB_SETUNICODEFORMAT
:
6634 return TOOLBAR_SetUnicodeFormat (infoPtr
, wParam
);
6637 return TOOLBAR_Unkwn45D(hwnd
, wParam
, lParam
);
6639 case TB_SETHOTITEM2
:
6640 return TOOLBAR_SetHotItem2 (infoPtr
, wParam
, lParam
);
6643 return TOOLBAR_SetListGap(infoPtr
, wParam
);
6645 case TB_GETIMAGELISTCOUNT
:
6646 return TOOLBAR_GetImageListCount(infoPtr
);
6648 case TB_GETIDEALSIZE
:
6649 return TOOLBAR_GetIdealSize (infoPtr
, wParam
, lParam
);
6652 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6654 /* Common Control Messages */
6656 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6657 case CCM_GETCOLORSCHEME
:
6658 return TOOLBAR_GetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6660 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6661 case CCM_SETCOLORSCHEME
:
6662 return TOOLBAR_SetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6664 case CCM_GETVERSION
:
6665 return TOOLBAR_GetVersion (infoPtr
);
6667 case CCM_SETVERSION
:
6668 return TOOLBAR_SetVersion (infoPtr
, (INT
)wParam
);
6674 return TOOLBAR_Create (hwnd
, (CREATESTRUCTW
*)lParam
);
6677 return TOOLBAR_Destroy (infoPtr
);
6680 return TOOLBAR_EraseBackground (infoPtr
, wParam
, lParam
);
6683 return TOOLBAR_GetFont (infoPtr
);
6686 return TOOLBAR_KeyDown (infoPtr
, wParam
, lParam
);
6688 /* case WM_KILLFOCUS: */
6690 case WM_LBUTTONDBLCLK
:
6691 return TOOLBAR_LButtonDblClk (infoPtr
, wParam
, lParam
);
6693 case WM_LBUTTONDOWN
:
6694 return TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
6697 return TOOLBAR_LButtonUp (infoPtr
, wParam
, lParam
);
6700 return TOOLBAR_RButtonUp (infoPtr
, wParam
, lParam
);
6702 case WM_RBUTTONDBLCLK
:
6703 return TOOLBAR_RButtonDblClk (infoPtr
, wParam
, lParam
);
6706 return TOOLBAR_MouseMove (infoPtr
, wParam
, lParam
);
6709 return TOOLBAR_MouseLeave (infoPtr
);
6711 case WM_CAPTURECHANGED
:
6712 return TOOLBAR_CaptureChanged(infoPtr
);
6715 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6718 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6721 return TOOLBAR_NCCreate (hwnd
, wParam
, (CREATESTRUCTW
*)lParam
);
6724 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
6727 return TOOLBAR_Notify (infoPtr
, (LPNMHDR
)lParam
);
6729 case WM_NOTIFYFORMAT
:
6730 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
6732 case WM_PRINTCLIENT
:
6734 return TOOLBAR_Paint (infoPtr
, wParam
);
6737 return TOOLBAR_SetFocus (infoPtr
);
6740 return TOOLBAR_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
6743 return TOOLBAR_SetRedraw (infoPtr
, wParam
);
6746 return TOOLBAR_Size (infoPtr
);
6748 case WM_STYLECHANGED
:
6749 return TOOLBAR_StyleChanged (infoPtr
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
6751 case WM_SYSCOLORCHANGE
:
6752 return TOOLBAR_SysColorChange ();
6754 case WM_THEMECHANGED
:
6755 return theme_changed (hwnd
);
6757 /* case WM_WININICHANGE: */
6762 case WM_MEASUREITEM
:
6764 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
6766 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6767 case PGM_FORWARDMOUSE
:
6768 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6771 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
6772 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
6773 uMsg
, wParam
, lParam
);
6774 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6780 TOOLBAR_Register (void)
6784 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
6785 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
6786 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
6787 wndClass
.cbClsExtra
= 0;
6788 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
6789 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
6790 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
6791 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
6793 RegisterClassW (&wndClass
);
6798 TOOLBAR_Unregister (void)
6800 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
6803 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
6808 /* Check if the entry already exists */
6809 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
6811 /* If this is a new entry we must create it and insert into the array */
6816 c
= Alloc(sizeof(IMLENTRY
));
6819 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
6820 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
6835 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
6839 for (i
= 0; i
< *cies
; i
++)
6849 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
6857 for (i
= 0; i
< cies
; i
++)
6859 if (pies
[i
]->id
== id
)
6871 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
6873 HIMAGELIST himlDef
= 0;
6874 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
6877 himlDef
= pie
->himl
;
6883 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
6885 if (infoPtr
->bUnicode
)
6886 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
6893 nmtba
.iItem
= nmtb
->iItem
;
6894 nmtba
.pszText
= Buffer
;
6895 nmtba
.cchText
= 256;
6896 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
6898 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
6900 int ccht
= strlen(nmtba
.pszText
);
6902 MultiByteToWideChar(CP_ACP
, 0, nmtba
.pszText
, -1,
6903 nmtb
->pszText
, nmtb
->cchText
);
6905 nmtb
->tbButton
= nmtba
.tbButton
;
6914 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
)
6918 /* MSDN states that iItem is the index of the button, rather than the
6919 * command ID as used by every other NMTOOLBAR notification */
6921 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
6923 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);