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 BYTE 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_UNDOC1 | \
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
, DWORD dwItemCDFlag
)
739 HDC hdc
= tbcd
->nmcd
.hdc
;
740 RECT rc
= tbcd
->nmcd
.rc
;
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
)
847 TOOLBAR_DrawFlatHorizontalSeparator (&rc
, hdc
, infoPtr
);
849 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
851 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
852 FIXME("Draw some kind of separator: fsStyle=%x\n",
858 /* get a pointer to the text */
859 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
861 if (hasDropDownArrow
)
865 if (dwStyle
& TBSTYLE_FLAT
)
866 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
868 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
870 if (drawSepDropDownArrow
)
873 rcArrow
.left
= right
;
876 /* copy text & bitmap rects after adjusting for drop-down arrow
877 * so that text & bitmap is centered in the rectangle not containing
879 CopyRect(&rcText
, &rc
);
880 CopyRect(&rcBitmap
, &rc
);
882 /* Center the bitmap horizontally and vertically */
883 if (dwStyle
& TBSTYLE_LIST
)
886 infoPtr
->nMaxTextRows
> 0 &&
887 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
888 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
889 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
891 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
894 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
896 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
898 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
899 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
900 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
901 TRACE("Text=%s\n", debugstr_w(lpText
));
902 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
904 /* calculate text position */
907 rcText
.left
+= GetSystemMetrics(SM_CXEDGE
);
908 rcText
.right
-= GetSystemMetrics(SM_CXEDGE
);
909 if (dwStyle
& TBSTYLE_LIST
)
911 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
915 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
916 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
918 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
922 /* Initialize fields in all cases, because we use these later
923 * NOTE: applications can and do alter these to customize their
925 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
926 tbcd
.clrText
= comctl32_color
.clrBtnText
;
927 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
928 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
929 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
930 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
931 tbcd
.clrHighlightHotTrack
= 0;
932 tbcd
.nStringBkMode
= TRANSPARENT
;
933 tbcd
.nHLStringBkMode
= OPAQUE
;
934 tbcd
.rcText
.left
= 0;
936 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
937 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
938 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
941 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
943 /* FIXME: what are these used for? */
947 /* Issue Item Prepaint notify */
950 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
952 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
953 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
954 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
955 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
956 /* reset these fields so the user can't alter the behaviour like native */
960 dwItemCustDraw
= ntfret
& 0xffff;
961 dwItemCDFlag
= ntfret
& 0xffff0000;
962 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
964 /* save the only part of the rect that the user can change */
965 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
966 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
969 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
970 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
971 OffsetRect(&rcText
, 1, 1);
973 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
974 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
975 TOOLBAR_DrawPattern (&rc
, &tbcd
);
977 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
978 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
980 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
984 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
985 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
986 if (hasDropDownArrow
)
987 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
988 SetBkColor(hdc
, oldclr
);
994 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
995 int stateId
= TS_NORMAL
;
997 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
998 stateId
= TS_DISABLED
;
999 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1000 stateId
= TS_PRESSED
;
1001 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1002 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1003 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1004 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1007 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &tbcd
.nmcd
.rc
, NULL
);
1010 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, dwItemCDFlag
);
1012 if (drawSepDropDownArrow
)
1016 int stateId
= TS_NORMAL
;
1018 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1019 stateId
= TS_DISABLED
;
1020 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1021 stateId
= TS_PRESSED
;
1022 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1023 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1024 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1027 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1028 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1031 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1034 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1035 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1036 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1037 SetBkMode (hdc
, oldBkMode
);
1039 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1041 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1043 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1045 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1046 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1048 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1050 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1051 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1054 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1057 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1059 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1060 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1067 TOOLBAR_Refresh (TOOLBAR_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
1069 TBUTTON_INFO
*btnPtr
;
1071 RECT rcTemp
, rcClient
;
1072 NMTBCUSTOMDRAW tbcd
;
1074 DWORD dwBaseCustDraw
;
1076 /* the app has told us not to redraw the toolbar */
1077 if (!infoPtr
->bDoRedraw
)
1080 /* if imagelist belongs to the app, it can be changed
1081 by the app after setting it */
1082 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1084 infoPtr
->nNumBitmaps
= 0;
1085 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1086 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1089 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1091 /* change the imagelist icon size if we manage the list and it is necessary */
1092 TOOLBAR_CheckImageListIconSize(infoPtr
);
1094 /* Send initial notify */
1095 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1096 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1097 tbcd
.nmcd
.hdc
= hdc
;
1098 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1099 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1100 dwBaseCustDraw
= ntfret
& 0xffff;
1102 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1104 /* redraw necessary buttons */
1105 btnPtr
= infoPtr
->buttons
;
1106 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1109 if (!RectVisible(hdc
, &btnPtr
->rect
))
1111 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1113 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1114 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1118 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1119 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1121 TOOLBAR_DrawButton(infoPtr
, btnPtr
, hdc
, dwBaseCustDraw
);
1124 /* draw insert mark if required */
1125 if (infoPtr
->tbim
.iButton
!= -1)
1127 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1129 rcInsertMark
.top
= rcButton
.top
;
1130 rcInsertMark
.bottom
= rcButton
.bottom
;
1131 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1132 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1134 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1135 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1138 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1140 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1141 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1142 tbcd
.nmcd
.hdc
= hdc
;
1143 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1144 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1148 /***********************************************************************
1149 * TOOLBAR_MeasureString
1151 * This function gets the width and height of a string in pixels. This
1152 * is done first by using GetTextExtentPoint to get the basic width
1153 * and height. The DrawText is called with DT_CALCRECT to get the exact
1154 * width. The reason is because the text may have more than one "&" (or
1155 * prefix characters as M$ likes to call them). The prefix character
1156 * indicates where the underline goes, except for the string "&&" which
1157 * is reduced to a single "&". GetTextExtentPoint does not process these
1158 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1161 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1162 HDC hdc
, LPSIZE lpSize
)
1169 if (infoPtr
->nMaxTextRows
> 0 &&
1170 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1171 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1172 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1174 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1176 if(lpText
!= NULL
) {
1177 /* first get size of all the text */
1178 GetTextExtentPoint32W (hdc
, lpText
, strlenW (lpText
), lpSize
);
1180 /* feed above size into the rectangle for DrawText */
1181 myrect
.left
= myrect
.top
= 0;
1182 myrect
.right
= lpSize
->cx
;
1183 myrect
.bottom
= lpSize
->cy
;
1185 /* Use DrawText to get true size as drawn (less pesky "&") */
1186 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1187 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1190 /* feed back to caller */
1191 lpSize
->cx
= myrect
.right
;
1192 lpSize
->cy
= myrect
.bottom
;
1196 TRACE("string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1199 /***********************************************************************
1200 * TOOLBAR_CalcStrings
1202 * This function walks through each string and measures it and returns
1203 * the largest height and width to caller.
1206 TOOLBAR_CalcStrings (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
1208 TBUTTON_INFO
*btnPtr
;
1217 if (infoPtr
->nMaxTextRows
== 0)
1220 hdc
= GetDC (infoPtr
->hwndSelf
);
1221 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1223 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1227 GetTextMetricsW(hdc
, &tm
);
1228 lpSize
->cy
= tm
.tmHeight
;
1231 btnPtr
= infoPtr
->buttons
;
1232 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1233 if(TOOLBAR_GetText(infoPtr
, btnPtr
))
1235 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1236 if (sz
.cx
> lpSize
->cx
)
1238 if (sz
.cy
> lpSize
->cy
)
1243 SelectObject (hdc
, hOldFont
);
1244 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1246 TRACE("max string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1249 /***********************************************************************
1250 * TOOLBAR_WrapToolbar
1252 * This function walks through the buttons and separators in the
1253 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1254 * wrapping should occur based on the width of the toolbar window.
1255 * It does *not* calculate button placement itself. That task
1256 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1257 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1258 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1260 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1261 * vertical toolbar lists.
1265 TOOLBAR_WrapToolbar(TOOLBAR_INFO
*infoPtr
)
1267 TBUTTON_INFO
*btnPtr
;
1272 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1273 /* no layout is necessary. Applications may use this style */
1274 /* to perform their own layout on the toolbar. */
1275 if( !(infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) &&
1276 !(infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
) ) return;
1278 btnPtr
= infoPtr
->buttons
;
1279 x
= infoPtr
->nIndent
;
1281 if (GetParent(infoPtr
->hwndSelf
))
1283 /* this can get the parents width, to know how far we can extend
1284 * this toolbar. We cannot use its height, as there may be multiple
1285 * toolbars in a rebar control
1287 GetClientRect( GetParent(infoPtr
->hwndSelf
), &rc
);
1288 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1292 GetWindowRect( infoPtr
->hwndSelf
, &rc
);
1293 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1296 bButtonWrap
= FALSE
;
1298 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1299 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, infoPtr
->nWidth
,
1302 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1304 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1306 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1309 if (btnPtr
[i
].cx
> 0)
1311 /* horizontal separators are treated as buttons for width */
1312 else if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1313 !(infoPtr
->dwStyle
& CCS_VERT
))
1314 cx
= (btnPtr
[i
].iBitmap
> 0) ? btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1316 cx
= infoPtr
->nButtonWidth
;
1318 /* Two or more adjacent separators form a separator group. */
1319 /* The first separator in a group should be wrapped to the */
1320 /* next row if the previous wrapping is on a button. */
1322 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1323 (i
+ 1 < infoPtr
->nNumButtons
) &&
1324 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1326 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1327 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1328 x
= infoPtr
->nIndent
;
1330 bButtonWrap
= FALSE
;
1334 /* The layout makes sure the bitmap is visible, but not the button. */
1335 /* Test added to also wrap after a button that starts a row but */
1336 /* is bigger than the area. - GA 8/01 */
1337 if (( x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2
1338 > infoPtr
->nWidth
) ||
1339 ((x
== infoPtr
->nIndent
) && (cx
> infoPtr
->nWidth
)))
1341 BOOL bFound
= FALSE
;
1343 /* If the current button is a separator and not hidden, */
1344 /* go to the next until it reaches a non separator. */
1345 /* Wrap the last separator if it is before a button. */
1346 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1347 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1348 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1349 i
< infoPtr
->nNumButtons
)
1355 if( bFound
&& i
< infoPtr
->nNumButtons
)
1358 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1359 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1360 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1361 x
= infoPtr
->nIndent
;
1362 bButtonWrap
= FALSE
;
1365 else if ( i
>= infoPtr
->nNumButtons
)
1368 /* If the current button is not a separator, find the last */
1369 /* separator and wrap it. */
1370 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1372 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1373 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1377 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1378 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1379 x
= infoPtr
->nIndent
;
1380 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1381 bButtonWrap
= FALSE
;
1386 /* If no separator available for wrapping, wrap one of */
1387 /* non-hidden previous button. */
1391 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1393 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1398 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1399 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1400 x
= infoPtr
->nIndent
;
1401 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1407 /* If all above failed, wrap the current button. */
1410 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1411 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1412 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1413 x
= infoPtr
->nIndent
;
1414 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1415 bButtonWrap
= FALSE
;
1421 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1422 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1429 /***********************************************************************
1430 * TOOLBAR_MeasureButton
1432 * Calculates the width and height required for a button. Used in
1433 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1434 * the width of buttons that are autosized.
1436 * Note that it would have been rather elegant to use one piece of code for
1437 * both the laying out of the toolbar and for controlling where button parts
1438 * are drawn, but the native control has inconsistencies between the two that
1439 * prevent this from being effectively. These inconsistencies can be seen as
1440 * artefacts where parts of the button appear outside of the bounding button
1443 * There are several cases for the calculation of the button dimensions and
1444 * button part positioning:
1451 * +--------------------------------------------------------+ ^
1453 * | | pad.cy / 2 | centered | |
1454 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1455 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1456 * | |<------------>| | | | |
1457 * | +--------------+ +------------+ | |
1458 * |<-------------------------------------->| | |
1459 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1461 * +--------------------------------------------------------+ -
1462 * <-------------------------------------------------------->
1463 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1465 * Without Bitmap (I_IMAGENONE):
1467 * +-----------------------------------+ ^
1469 * | | centered | | LISTPAD_CY +
1470 * | +------------+ | | szText.cy
1473 * | +------------+ | |
1474 * |<----------------->| | |
1475 * | cxedge |<-----------> | |
1477 * +-----------------------------------+ -
1478 * <----------------------------------->
1479 * szText.cx + pad.cx
1483 * +--------------------------------------+ ^
1485 * | | padding.cy/2 | | DEFPAD_CY +
1486 * | +------------+ | | nBitmapHeight
1489 * | +------------+ | |
1490 * |<------------------->| | |
1491 * | cxedge + iListGap/2 |<-----------> | |
1492 * | nBitmapWidth | |
1493 * +--------------------------------------+ -
1494 * <-------------------------------------->
1495 * 2*cxedge + nBitmapWidth + iListGap
1502 * +-----------------------------------+ ^
1504 * | | pad.cy / 2 | | nBitmapHeight +
1505 * | - | | szText.cy +
1506 * | +------------+ | | DEFPAD_CY + 1
1507 * | centered | Bitmap | | |
1508 * |<----------------->| | | |
1509 * | +------------+ | |
1513 * | centered +---------------+ | |
1514 * |<--------------->| Text | | |
1515 * | +---------------+ | |
1516 * +-----------------------------------+ -
1517 * <----------------------------------->
1518 * pad.cx + max(nBitmapWidth, szText.cx)
1520 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1522 * +---------------------------------------+ ^
1524 * | | 2 + pad.cy / 2 | |
1525 * | - | | szText.cy +
1526 * | centered +-----------------+ | | pad.cy + 2
1527 * |<--------------->| Text | | |
1528 * | +-----------------+ | |
1530 * +---------------------------------------+ -
1531 * <--------------------------------------->
1532 * 2*cxedge + pad.cx + szText.cx
1535 * As for with bitmaps, but with szText.cx zero.
1537 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1538 BOOL bHasBitmap
, BOOL bValidImageList
)
1541 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1543 /* set button height from bitmap / text height... */
1544 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1547 /* ... add on the necessary padding */
1548 if (bValidImageList
)
1551 sizeButton
.cy
+= DEFPAD_CY
;
1553 sizeButton
.cy
+= LISTPAD_CY
;
1556 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1558 /* calculate button width */
1559 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1560 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1561 if (sizeString
.cx
> 0)
1562 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1569 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1570 if (sizeString
.cy
> 0)
1571 sizeButton
.cy
+= 1 + sizeString
.cy
;
1572 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1573 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1577 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1578 NONLIST_NOTEXT_OFFSET
;
1579 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1580 max(2*GetSystemMetrics(SM_CXEDGE
) + sizeString
.cx
, infoPtr
->nBitmapWidth
);
1587 /***********************************************************************
1588 * TOOLBAR_CalcToolbar
1590 * This function calculates button and separator placement. It first
1591 * calculates the button sizes, gets the toolbar window width and then
1592 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1593 * on. It assigns a new location to each item and sends this location to
1594 * the tooltip window if appropriate. Finally, it updates the rcBound
1595 * rect and calculates the new required toolbar window height.
1598 TOOLBAR_CalcToolbar (TOOLBAR_INFO
*infoPtr
)
1600 SIZE sizeString
, sizeButton
;
1601 BOOL validImageList
= FALSE
;
1603 TOOLBAR_CalcStrings (infoPtr
, &sizeString
);
1605 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1607 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1608 validImageList
= TRUE
;
1609 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1610 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1611 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1612 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1614 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1615 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1616 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1617 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1619 TOOLBAR_LayoutToolbar(infoPtr
);
1623 TOOLBAR_LayoutToolbar(TOOLBAR_INFO
*infoPtr
)
1625 TBUTTON_INFO
*btnPtr
;
1627 INT i
, nRows
, nSepRows
;
1630 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1631 BOOL hasDropDownArrows
= TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
);
1633 TOOLBAR_WrapToolbar(infoPtr
);
1635 x
= infoPtr
->nIndent
;
1636 y
= infoPtr
->iTopMargin
;
1637 cx
= infoPtr
->nButtonWidth
;
1638 cy
= infoPtr
->nButtonHeight
;
1640 nRows
= nSepRows
= 0;
1642 infoPtr
->rcBound
.top
= y
;
1643 infoPtr
->rcBound
.left
= x
;
1644 infoPtr
->rcBound
.bottom
= y
+ cy
;
1645 infoPtr
->rcBound
.right
= x
;
1647 btnPtr
= infoPtr
->buttons
;
1649 TRACE("cy=%d\n", cy
);
1651 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1654 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1656 SetRectEmpty (&btnPtr
->rect
);
1660 cy
= infoPtr
->nButtonHeight
;
1662 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1663 if (infoPtr
->dwStyle
& CCS_VERT
) {
1664 cy
= (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1665 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
: infoPtr
->nWidth
;
1668 cx
= (btnPtr
->cx
> 0) ? btnPtr
->cx
:
1669 (btnPtr
->iBitmap
> 0) ? btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1675 else if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1676 (btnPtr
->fsStyle
& BTNS_AUTOSIZE
))
1682 hdc
= GetDC (infoPtr
->hwndSelf
);
1683 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1685 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1687 SelectObject (hdc
, hOldFont
);
1688 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1690 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1691 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1696 cx
= infoPtr
->nButtonWidth
;
1698 /* if size has been set manually then don't add on extra space
1699 * for the drop down arrow */
1700 if (!btnPtr
->cx
&& hasDropDownArrows
&&
1701 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) || (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)))
1702 cx
+= DDARROW_WIDTH
;
1704 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1707 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1709 if (infoPtr
->rcBound
.left
> x
)
1710 infoPtr
->rcBound
.left
= x
;
1711 if (infoPtr
->rcBound
.right
< x
+ cx
)
1712 infoPtr
->rcBound
.right
= x
+ cx
;
1713 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1714 infoPtr
->rcBound
.bottom
= y
+ cy
;
1716 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1718 /* btnPtr->nRow is zero based. The space between the rows is */
1719 /* also considered as a row. */
1720 btnPtr
->nRow
= nRows
+ nSepRows
;
1722 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1723 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1728 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1732 if ( !(infoPtr
->dwStyle
& CCS_VERT
))
1733 y
+= cy
+ ( (btnPtr
->cx
> 0 ) ?
1734 btnPtr
->cx
: SEPARATOR_WIDTH
) * 2 /3;
1738 /* nSepRows is used to calculate the extra height following */
1742 x
= infoPtr
->nIndent
;
1744 /* Increment row number unless this is the last button */
1745 /* and it has Wrap set. */
1746 if (i
!= infoPtr
->nNumButtons
-1)
1753 /* infoPtr->nRows is the number of rows on the toolbar */
1754 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1756 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1761 TOOLBAR_InternalHitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
*lpPt
, BOOL
*button
)
1763 TBUTTON_INFO
*btnPtr
;
1769 btnPtr
= infoPtr
->buttons
;
1770 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1771 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1774 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1775 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1776 TRACE(" ON SEPARATOR %d!\n", i
);
1781 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1782 TRACE(" ON BUTTON %d!\n", i
);
1790 TRACE(" NOWHERE!\n");
1791 return TOOLBAR_NOWHERE
;
1795 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1797 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO
*infoPtr
, INT iIndex
, UINT nAddButtons
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
1799 INT nOldButtons
, nNewButtons
, iButton
;
1800 BOOL fHasString
= FALSE
;
1802 if (iIndex
< 0) /* iIndex can be negative, what means adding at the end */
1803 iIndex
= infoPtr
->nNumButtons
;
1805 nOldButtons
= infoPtr
->nNumButtons
;
1806 nNewButtons
= nOldButtons
+ nAddButtons
;
1808 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
1809 memmove(&infoPtr
->buttons
[iIndex
+ nAddButtons
], &infoPtr
->buttons
[iIndex
],
1810 (nOldButtons
- iIndex
) * sizeof(TBUTTON_INFO
));
1811 infoPtr
->nNumButtons
+= nAddButtons
;
1813 /* insert new buttons data */
1814 for (iButton
= 0; iButton
< nAddButtons
; iButton
++) {
1815 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[iIndex
+ iButton
];
1817 TOOLBAR_DumpTBButton(lpTbb
+ iButton
, fUnicode
);
1819 ZeroMemory(btnPtr
, sizeof(*btnPtr
));
1821 btnPtr
->iBitmap
= lpTbb
[iButton
].iBitmap
;
1822 btnPtr
->idCommand
= lpTbb
[iButton
].idCommand
;
1823 btnPtr
->fsState
= lpTbb
[iButton
].fsState
;
1824 btnPtr
->fsStyle
= lpTbb
[iButton
].fsStyle
;
1825 btnPtr
->dwData
= lpTbb
[iButton
].dwData
;
1826 if (btnPtr
->fsStyle
& BTNS_SEP
)
1827 btnPtr
->iString
= -1;
1828 else if(!IS_INTRESOURCE(lpTbb
[iButton
].iString
) && lpTbb
[iButton
].iString
!= -1)
1831 Str_SetPtrW((LPWSTR
*)&btnPtr
->iString
, (LPWSTR
)lpTbb
[iButton
].iString
);
1833 Str_SetPtrAtoW((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lpTbb
[iButton
].iString
);
1837 btnPtr
->iString
= lpTbb
[iButton
].iString
;
1839 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
1842 if (infoPtr
->nNumStrings
> 0 || fHasString
)
1843 TOOLBAR_CalcToolbar(infoPtr
);
1845 TOOLBAR_LayoutToolbar(infoPtr
);
1846 TOOLBAR_AutoSize(infoPtr
);
1848 TOOLBAR_DumpToolbar(infoPtr
, __LINE__
);
1849 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1855 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1857 TBUTTON_INFO
*btnPtr
;
1860 if (CommandIsIndex
) {
1861 TRACE("command is really index command=%d\n", idCommand
);
1862 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1865 btnPtr
= infoPtr
->buttons
;
1866 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1867 if (btnPtr
->idCommand
== idCommand
) {
1868 TRACE("command=%d index=%d\n", idCommand
, i
);
1872 TRACE("no index found for command=%d\n", idCommand
);
1878 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1880 TBUTTON_INFO
*btnPtr
;
1883 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1886 /* check index button */
1887 btnPtr
= &infoPtr
->buttons
[nIndex
];
1888 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1889 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1893 /* check previous buttons */
1894 nRunIndex
= nIndex
- 1;
1895 while (nRunIndex
>= 0) {
1896 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1897 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1898 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1906 /* check next buttons */
1907 nRunIndex
= nIndex
+ 1;
1908 while (nRunIndex
< infoPtr
->nNumButtons
) {
1909 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1910 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1911 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1924 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1925 WPARAM wParam
, LPARAM lParam
)
1931 msg
.wParam
= wParam
;
1932 msg
.lParam
= lParam
;
1933 msg
.time
= GetMessageTime ();
1934 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
1935 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
1937 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1941 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1943 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
1946 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
1947 ti
.cbSize
= sizeof (TTTOOLINFOW
);
1948 ti
.hwnd
= infoPtr
->hwndSelf
;
1949 ti
.uId
= button
->idCommand
;
1951 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
1952 /* ti.lParam = random value from the stack? */
1954 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
1960 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1962 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
1965 ZeroMemory(&ti
, sizeof(ti
));
1966 ti
.cbSize
= sizeof(ti
);
1967 ti
.hwnd
= infoPtr
->hwndSelf
;
1968 ti
.uId
= button
->idCommand
;
1970 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
1974 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1976 /* Set the toolTip only for non-hidden, non-separator button */
1977 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
1981 ZeroMemory(&ti
, sizeof(ti
));
1982 ti
.cbSize
= sizeof(ti
);
1983 ti
.hwnd
= infoPtr
->hwndSelf
;
1984 ti
.uId
= button
->idCommand
;
1985 ti
.rect
= button
->rect
;
1986 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
1990 /* Creates the tooltip control */
1992 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
1995 NMTOOLTIPSCREATED nmttc
;
1997 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
1998 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1999 infoPtr
->hwndSelf
, 0, 0, 0);
2001 if (!infoPtr
->hwndToolTip
)
2004 /* Send NM_TOOLTIPSCREATED notification */
2005 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
2006 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
2008 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
2010 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
2011 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
2015 /* keeps available button list box sorted by button id */
2016 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
2020 PCUSTOMBUTTON btnInfo
;
2021 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2023 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
2025 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2027 /* position 0 is always separator */
2028 for (i
= 1; i
< count
; i
++)
2030 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2031 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2033 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2034 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2038 /* id higher than all others add to end */
2039 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2040 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2043 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2047 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2049 if (nIndexFrom
== nIndexTo
)
2052 /* MSDN states that iItem is the index of the button, rather than the
2053 * command ID as used by every other NMTOOLBAR notification */
2054 nmtb
.iItem
= nIndexFrom
;
2055 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2057 PCUSTOMBUTTON btnInfo
;
2059 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2060 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2062 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2064 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2065 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2066 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2067 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2070 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2072 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2074 /* last item is always separator, so -2 instead of -1 */
2075 if (nIndexTo
>= (count
- 2))
2076 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2078 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2080 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2081 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2083 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2087 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2091 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2093 /* MSDN states that iItem is the index of the button, rather than the
2094 * command ID as used by every other NMTOOLBAR notification */
2095 nmtb
.iItem
= nIndexAvail
;
2096 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2098 PCUSTOMBUTTON btnInfo
;
2100 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2101 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2102 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2104 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2106 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2108 /* remove from 'available buttons' list */
2109 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2110 if (nIndexAvail
== count
-1)
2111 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2113 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2117 PCUSTOMBUTTON btnNew
;
2119 /* duplicate 'separator' button */
2120 btnNew
= Alloc(sizeof(CUSTOMBUTTON
));
2125 /* insert into 'toolbar button' list */
2126 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2127 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2129 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2131 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2135 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2137 PCUSTOMBUTTON btnInfo
;
2138 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2140 TRACE("Remove: index %d\n", index
);
2142 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2144 /* send TBN_QUERYDELETE notification */
2145 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2149 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2150 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2152 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2154 /* insert into 'available button' list */
2155 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2156 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2160 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2164 /* drag list notification function for toolbar buttons list box */
2165 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2166 const DRAGLISTINFO
*pDLI
)
2168 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2169 switch (pDLI
->uNotification
)
2173 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2174 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2175 /* no dragging for last item (separator) */
2176 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2181 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2182 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2183 /* no dragging past last item (separator) */
2184 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2186 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2187 /* FIXME: native uses "move button" cursor */
2188 return DL_COPYCURSOR
;
2191 /* not over toolbar buttons list */
2192 if (nCurrentItem
< 0)
2194 POINT ptWindow
= pDLI
->ptCursor
;
2195 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2196 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2197 /* over available buttons list? */
2198 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2199 /* FIXME: native uses "move button" cursor */
2200 return DL_COPYCURSOR
;
2202 /* clear drag arrow */
2203 DrawInsert(hwnd
, hwndList
, -1);
2204 return DL_STOPCURSOR
;
2208 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2209 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2210 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2211 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2213 /* clear drag arrow */
2214 DrawInsert(hwnd
, hwndList
, -1);
2216 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2218 /* not over toolbar buttons list */
2221 POINT ptWindow
= pDLI
->ptCursor
;
2222 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2223 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2224 /* over available buttons list? */
2225 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2226 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2231 /* Clear drag arrow */
2232 DrawInsert(hwnd
, hwndList
, -1);
2239 /* drag list notification function for available buttons list box */
2240 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2241 const DRAGLISTINFO
*pDLI
)
2243 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2244 switch (pDLI
->uNotification
)
2250 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2251 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2252 /* no dragging past last item (separator) */
2253 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2255 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2256 /* FIXME: native uses "move button" cursor */
2257 return DL_COPYCURSOR
;
2260 /* not over toolbar buttons list */
2261 if (nCurrentItem
< 0)
2263 POINT ptWindow
= pDLI
->ptCursor
;
2264 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2265 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2266 /* over available buttons list? */
2267 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2268 /* FIXME: native uses "move button" cursor */
2269 return DL_COPYCURSOR
;
2271 /* clear drag arrow */
2272 DrawInsert(hwnd
, hwndList
, -1);
2273 return DL_STOPCURSOR
;
2277 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2278 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2279 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2280 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2282 /* clear drag arrow */
2283 DrawInsert(hwnd
, hwndList
, -1);
2285 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2289 /* Clear drag arrow */
2290 DrawInsert(hwnd
, hwndList
, -1);
2296 extern UINT uDragListMessage DECLSPEC_HIDDEN
;
2298 /***********************************************************************
2299 * TOOLBAR_CustomizeDialogProc
2300 * This function implements the toolbar customization dialog.
2302 static INT_PTR CALLBACK
2303 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2305 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2306 PCUSTOMBUTTON btnInfo
;
2308 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2313 custInfo
= (PCUSTDLG_INFO
)lParam
;
2314 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2321 NMTBINITCUSTOMIZE nmtbic
;
2323 infoPtr
= custInfo
->tbInfo
;
2325 /* send TBN_QUERYINSERT notification */
2326 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2328 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2331 nmtbic
.hwndDialog
= hwnd
;
2332 /* Send TBN_INITCUSTOMIZE notification */
2333 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2336 TRACE("TBNRF_HIDEHELP requested\n");
2337 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2340 /* add items to 'toolbar buttons' list and check if removable */
2341 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2343 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2344 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2345 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2346 btnInfo
->bVirtual
= FALSE
;
2347 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2349 /* send TBN_QUERYDELETE notification */
2350 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2352 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2353 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2356 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2358 /* insert separator button into 'available buttons' list */
2359 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2360 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2361 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2362 btnInfo
->bVirtual
= FALSE
;
2363 btnInfo
->bRemovable
= TRUE
;
2364 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2365 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2366 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2368 /* insert all buttons into dsa */
2371 /* send TBN_GETBUTTONINFO notification */
2374 nmtb
.pszText
= Buffer
;
2377 /* Clear previous button's text */
2378 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2380 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2383 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2384 nmtb
.tbButton
.fsStyle
, i
,
2385 nmtb
.tbButton
.idCommand
,
2386 nmtb
.tbButton
.iString
,
2387 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2390 /* insert button into the appropriate list */
2391 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2394 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2395 btnInfo
->bVirtual
= FALSE
;
2396 btnInfo
->bRemovable
= TRUE
;
2400 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2401 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2404 btnInfo
->btn
= nmtb
.tbButton
;
2405 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2407 if (lstrlenW(nmtb
.pszText
))
2408 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2409 else if (nmtb
.tbButton
.iString
>= 0 &&
2410 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2412 lstrcpyW(btnInfo
->text
,
2413 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2418 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2421 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2423 /* select first item in the 'available' list */
2424 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2426 /* append 'virtual' separator button to the 'toolbar buttons' list */
2427 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2428 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2429 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2430 btnInfo
->bVirtual
= TRUE
;
2431 btnInfo
->bRemovable
= FALSE
;
2432 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2433 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2434 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2436 /* select last item in the 'toolbar' list */
2437 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2438 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2440 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2441 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2443 /* set focus and disable buttons */
2444 PostMessageW (hwnd
, WM_USER
, 0, 0);
2449 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2450 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2451 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2452 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2456 EndDialog(hwnd
, FALSE
);
2460 switch (LOWORD(wParam
))
2462 case IDC_TOOLBARBTN_LBOX
:
2463 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2465 PCUSTOMBUTTON btnInfo
;
2470 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2471 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2473 /* send TBN_QUERYINSERT notification */
2475 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2477 /* get list box item */
2478 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2480 if (index
== (count
- 1))
2482 /* last item (virtual separator) */
2483 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2484 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2486 else if (index
== (count
- 2))
2488 /* second last item (last non-virtual item) */
2489 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2490 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2492 else if (index
== 0)
2495 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2496 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2500 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2501 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2504 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2508 case IDC_MOVEUP_BTN
:
2510 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2511 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2515 case IDC_MOVEDN_BTN
: /* move down */
2517 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2518 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2522 case IDC_REMOVE_BTN
: /* remove button */
2524 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2526 if (LB_ERR
== index
)
2529 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2533 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2536 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2539 case IDOK
: /* Add button */
2544 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2545 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2547 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2552 EndDialog(hwnd
, FALSE
);
2562 /* delete items from 'toolbar buttons' listbox*/
2563 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2564 for (i
= 0; i
< count
; i
++)
2566 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2568 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2570 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2573 /* delete items from 'available buttons' listbox*/
2574 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2575 for (i
= 0; i
< count
; i
++)
2577 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2579 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2581 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2586 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2588 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2593 COLORREF oldText
= 0;
2597 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, lpdis
->itemID
, 0);
2598 if (btnInfo
== NULL
)
2600 FIXME("btnInfo invalid!\n");
2604 /* set colors and select objects */
2605 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2606 if (btnInfo
->bVirtual
)
2607 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2609 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2610 hPen
= CreatePen( PS_SOLID
, 1,
2611 (lpdis
->itemState
& ODS_SELECTED
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2612 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2613 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2615 /* fill background rectangle */
2616 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2617 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2619 /* calculate button and text rectangles */
2620 CopyRect (&rcButton
, &lpdis
->rcItem
);
2621 InflateRect (&rcButton
, -1, -1);
2622 CopyRect (&rcText
, &rcButton
);
2623 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2624 rcText
.left
= rcButton
.right
+ 2;
2626 /* draw focus rectangle */
2627 if (lpdis
->itemState
& ODS_FOCUS
)
2628 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2631 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2632 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2634 /* draw image and text */
2635 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2636 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2637 btnInfo
->btn
.iBitmap
));
2638 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2639 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2641 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2642 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2644 /* delete objects and reset colors */
2645 SelectObject (lpdis
->hDC
, hOldBrush
);
2646 SelectObject (lpdis
->hDC
, hOldPen
);
2647 SetBkColor (lpdis
->hDC
, oldBk
);
2648 SetTextColor (lpdis
->hDC
, oldText
);
2649 DeleteObject( hPen
);
2654 case WM_MEASUREITEM
:
2655 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2657 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2659 lpmis
->itemHeight
= 15 + 8; /* default height */
2666 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2668 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2670 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2671 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2672 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2675 else if (wParam
== IDC_AVAILBTN_LBOX
)
2677 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2678 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2679 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2688 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2691 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2697 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2698 /* Add bitmaps to the default image list */
2699 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2700 hbmLoad
= CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2701 else if (bitmap
->hInst
== COMCTL32_hModule
)
2702 hbmLoad
= LoadImageW( bitmap
->hInst
, MAKEINTRESOURCEW(bitmap
->nID
),
2703 IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
2705 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2707 /* enlarge the bitmap if needed */
2708 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2709 if (bitmap
->hInst
!= COMCTL32_hModule
)
2710 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2712 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2713 DeleteObject(hbmLoad
);
2717 nCountAfter
= ImageList_GetImageCount(himlDef
);
2718 nAdded
= nCountAfter
- nCountBefore
;
2719 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2721 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2722 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2723 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2724 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2727 infoPtr
->nNumBitmaps
+= nAdded
;
2732 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2739 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2740 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2742 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2744 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2747 TRACE("Update icon size: %dx%d -> %dx%d\n",
2748 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2750 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2751 ILC_COLOR32
|ILC_MASK
, 8, 2);
2752 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2753 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2754 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2755 infoPtr
->himlInt
= himlNew
;
2757 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2758 ImageList_Destroy(himlDef
);
2761 /***********************************************************************
2762 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2766 TOOLBAR_AddBitmap (TOOLBAR_INFO
*infoPtr
, INT count
, const TBADDBITMAP
*lpAddBmp
)
2772 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr
->hwndSelf
, count
, lpAddBmp
);
2776 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2778 info
.hInst
= COMCTL32_hModule
;
2779 switch (lpAddBmp
->nID
)
2781 case IDB_STD_SMALL_COLOR
:
2783 info
.nID
= IDB_STD_SMALL
;
2785 case IDB_STD_LARGE_COLOR
:
2787 info
.nID
= IDB_STD_LARGE
;
2789 case IDB_VIEW_SMALL_COLOR
:
2791 info
.nID
= IDB_VIEW_SMALL
;
2793 case IDB_VIEW_LARGE_COLOR
:
2795 info
.nID
= IDB_VIEW_LARGE
;
2797 case IDB_HIST_SMALL_COLOR
:
2799 info
.nID
= IDB_HIST_SMALL
;
2801 case IDB_HIST_LARGE_COLOR
:
2803 info
.nID
= IDB_HIST_LARGE
;
2809 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2811 /* Windows resize all the buttons to the size of a newly added standard image */
2812 if (lpAddBmp
->nID
& 1)
2814 /* large icons: 24x24. Will make the button 31x30 */
2815 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2819 /* small icons: 16x16. Will make the buttons 23x22 */
2820 SendMessageW (infoPtr
->hwndSelf
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2823 TOOLBAR_CalcToolbar (infoPtr
);
2827 info
.nButtons
= count
;
2828 info
.hInst
= lpAddBmp
->hInst
;
2829 info
.nID
= lpAddBmp
->nID
;
2830 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2833 /* check if the bitmap is already loaded and compute iSumButtons */
2835 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2837 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2838 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2840 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2843 if (!infoPtr
->cimlDef
) {
2844 /* create new default image list */
2845 TRACE ("creating default image list!\n");
2847 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2848 ILC_COLOR32
| ILC_MASK
, info
.nButtons
, 2);
2849 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2850 infoPtr
->himlInt
= himlDef
;
2853 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2857 WARN("No default image list available\n");
2861 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2864 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2865 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2866 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2867 infoPtr
->nNumBitmapInfos
++;
2868 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2870 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2876 TOOLBAR_AddButtonsT(TOOLBAR_INFO
*infoPtr
, INT nAddButtons
, const TBBUTTON
* lpTbb
, BOOL fUnicode
)
2878 TRACE("adding %d buttons (unicode=%d)!\n", nAddButtons
, fUnicode
);
2880 return TOOLBAR_InternalInsertButtonsT(infoPtr
, -1, nAddButtons
, lpTbb
, fUnicode
);
2885 TOOLBAR_AddStringW (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
2887 #define MAX_RESOURCE_STRING_LENGTH 512
2888 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2889 INT nIndex
= infoPtr
->nNumStrings
;
2891 TRACE("%p, %lx\n", hInstance
, lParam
);
2893 if (IS_INTRESOURCE(lParam
)) {
2894 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2901 TRACE("adding string from resource\n");
2903 if (!hInstance
) return -1;
2905 hrsrc
= FindResourceW( hInstance
, MAKEINTRESOURCEW((LOWORD(lParam
) >> 4) + 1),
2906 (LPWSTR
)RT_STRING
);
2909 TRACE("string not found in resources\n");
2913 len
= LoadStringW (hInstance
, (UINT
)lParam
,
2914 szString
, MAX_RESOURCE_STRING_LENGTH
);
2916 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2917 if (len
== 0 || len
== 1)
2920 TRACE("delimiter: 0x%x\n", *szString
);
2921 delimiter
= *szString
;
2924 while ((next_delim
= strchrW(p
, delimiter
)) != NULL
) {
2926 if (next_delim
+ 1 >= szString
+ len
)
2928 /* this may happen if delimiter == '\0' or if the last char is a
2929 * delimiter (then it is ignored like the native does) */
2933 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2934 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2935 infoPtr
->nNumStrings
++;
2941 LPWSTR p
= (LPWSTR
)lParam
;
2946 TRACE("adding string(s) from array\n");
2950 TRACE("len=%d %s\n", len
, debugstr_w(p
));
2951 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2952 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2953 infoPtr
->nNumStrings
++;
2960 TOOLBAR_CalcToolbar(infoPtr
);
2966 TOOLBAR_AddStringA (TOOLBAR_INFO
*infoPtr
, HINSTANCE hInstance
, LPARAM lParam
)
2968 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2973 TRACE("%p, %lx\n", hInstance
, lParam
);
2975 if (IS_INTRESOURCE(lParam
)) /* load from resources */
2976 return TOOLBAR_AddStringW(infoPtr
, hInstance
, lParam
);
2982 TRACE("adding string(s) from array\n");
2983 nIndex
= infoPtr
->nNumStrings
;
2986 TRACE("len=%d \"%s\"\n", len
, p
);
2988 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2989 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2990 infoPtr
->nNumStrings
++;
2996 TOOLBAR_CalcToolbar(infoPtr
);
3002 TOOLBAR_AutoSize (TOOLBAR_INFO
*infoPtr
)
3009 TRACE("auto sizing, style=%x!\n", infoPtr
->dwStyle
);
3011 parent
= GetParent (infoPtr
->hwndSelf
);
3013 if (!parent
|| !infoPtr
->bDoRedraw
)
3016 GetClientRect(parent
, &parent_rect
);
3018 x
= parent_rect
.left
;
3019 y
= parent_rect
.top
;
3021 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3023 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3024 cx
= parent_rect
.right
- parent_rect
.left
;
3026 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
))
3028 TOOLBAR_LayoutToolbar(infoPtr
);
3029 InvalidateRect( infoPtr
->hwndSelf
, NULL
, TRUE
);
3032 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3035 UINT uPosFlags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
3037 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3039 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3040 MapWindowPoints( 0, parent
, (POINT
*)&window_rect
, 2 );
3041 y
= window_rect
.top
;
3043 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3045 GetWindowRect(infoPtr
->hwndSelf
, &window_rect
);
3046 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3049 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3050 uPosFlags
|= SWP_NOMOVE
;
3052 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3053 cy
+= GetSystemMetrics(SM_CYEDGE
);
3055 if (infoPtr
->dwStyle
& WS_BORDER
)
3057 cx
+= 2 * GetSystemMetrics(SM_CXBORDER
);
3058 cy
+= 2 * GetSystemMetrics(SM_CYBORDER
);
3061 SetWindowPos(infoPtr
->hwndSelf
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3068 static inline LRESULT
3069 TOOLBAR_ButtonCount (const TOOLBAR_INFO
*infoPtr
)
3071 return infoPtr
->nNumButtons
;
3075 static inline LRESULT
3076 TOOLBAR_ButtonStructSize (TOOLBAR_INFO
*infoPtr
, DWORD Size
)
3078 infoPtr
->dwStructSize
= Size
;
3085 TOOLBAR_ChangeBitmap (TOOLBAR_INFO
*infoPtr
, INT Id
, INT Index
)
3087 TBUTTON_INFO
*btnPtr
;
3090 TRACE("button %d, iBitmap now %d\n", Id
, Index
);
3092 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3096 btnPtr
= &infoPtr
->buttons
[nIndex
];
3097 btnPtr
->iBitmap
= Index
;
3099 /* we HAVE to erase the background, the new bitmap could be */
3101 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3108 TOOLBAR_CheckButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3110 TBUTTON_INFO
*btnPtr
;
3113 BOOL bChecked
= FALSE
;
3115 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3117 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, nIndex
, lParam
);
3122 btnPtr
= &infoPtr
->buttons
[nIndex
];
3124 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) != 0;
3126 if (LOWORD(lParam
) == FALSE
)
3127 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3129 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3131 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3132 if (nOldIndex
== nIndex
)
3134 if (nOldIndex
!= -1)
3135 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3137 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3140 if( bChecked
!= LOWORD(lParam
) )
3142 if (nOldIndex
!= -1)
3143 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3144 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3147 /* FIXME: Send a WM_NOTIFY?? */
3154 TOOLBAR_CommandToIndex (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3156 return TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3161 TOOLBAR_Customize (TOOLBAR_INFO
*infoPtr
)
3163 CUSTDLG_INFO custInfo
;
3167 custInfo
.tbInfo
= infoPtr
;
3168 custInfo
.tbHwnd
= infoPtr
->hwndSelf
;
3170 /* send TBN_BEGINADJUST notification */
3171 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3173 ret
= DialogBoxParamW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3174 infoPtr
->hwndSelf
, TOOLBAR_CustomizeDialogProc
, (LPARAM
)&custInfo
);
3176 /* send TBN_ENDADJUST notification */
3177 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3184 TOOLBAR_DeleteButton (TOOLBAR_INFO
*infoPtr
, INT nIndex
)
3187 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3189 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3192 memset(&nmtb
, 0, sizeof(nmtb
));
3193 nmtb
.iItem
= btnPtr
->idCommand
;
3194 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3195 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3196 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3197 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3198 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3199 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3200 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3202 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3204 if (infoPtr
->nNumButtons
== 1) {
3205 TRACE(" simple delete!\n");
3206 if (TOOLBAR_ButtonHasString(infoPtr
->buttons
))
3207 Free((LPWSTR
)infoPtr
->buttons
[0].iString
);
3208 Free (infoPtr
->buttons
);
3209 infoPtr
->buttons
= NULL
;
3210 infoPtr
->nNumButtons
= 0;
3213 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3214 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3216 infoPtr
->nNumButtons
--;
3217 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3219 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3220 nIndex
* sizeof(TBUTTON_INFO
));
3223 if (nIndex
< infoPtr
->nNumButtons
) {
3224 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3225 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3228 if (TOOLBAR_ButtonHasString(&oldButtons
[nIndex
]))
3229 Free((LPWSTR
)oldButtons
[nIndex
].iString
);
3233 TOOLBAR_LayoutToolbar(infoPtr
);
3235 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3242 TOOLBAR_EnableButton (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
3244 TBUTTON_INFO
*btnPtr
;
3248 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3250 TRACE("hwnd=%p, btn id=%d, lParam=0x%08lx\n", infoPtr
->hwndSelf
, Id
, lParam
);
3255 btnPtr
= &infoPtr
->buttons
[nIndex
];
3257 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3259 /* update the toolbar button state */
3260 if(LOWORD(lParam
) == FALSE
) {
3261 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3263 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3266 /* redraw the button only if the state of the button changed */
3267 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3268 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3274 static inline LRESULT
3275 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO
*infoPtr
)
3277 return infoPtr
->bAnchor
;
3282 TOOLBAR_GetBitmap (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3286 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3290 return infoPtr
->buttons
[nIndex
].iBitmap
;
3294 static inline LRESULT
3295 TOOLBAR_GetBitmapFlags (void)
3297 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3302 TOOLBAR_GetButton (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, TBBUTTON
*lpTbb
)
3304 TBUTTON_INFO
*btnPtr
;
3309 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3312 btnPtr
= &infoPtr
->buttons
[nIndex
];
3313 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3314 lpTbb
->idCommand
= btnPtr
->idCommand
;
3315 lpTbb
->fsState
= btnPtr
->fsState
;
3316 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3317 lpTbb
->bReserved
[0] = 0;
3318 lpTbb
->bReserved
[1] = 0;
3319 lpTbb
->dwData
= btnPtr
->dwData
;
3320 lpTbb
->iString
= btnPtr
->iString
;
3327 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO
*infoPtr
, INT Id
, LPTBBUTTONINFOW lpTbInfo
, BOOL bUnicode
)
3329 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3330 TBUTTON_INFO
*btnPtr
;
3333 if (lpTbInfo
== NULL
)
3336 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3337 * the headers and tests shows that even with comctl 6 Vista accepts only the
3338 * original TBBUTTONINFO size
3340 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3342 WARN("Invalid button size\n");
3346 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lpTbInfo
->dwMask
& TBIF_BYINDEX
);
3350 if (!(btnPtr
= &infoPtr
->buttons
[nIndex
])) return -1;
3352 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3353 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3354 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3355 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3356 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3357 lpTbInfo
->lParam
= btnPtr
->dwData
;
3358 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3359 /* tests show that for separators TBIF_SIZE returns not calculated width,
3360 but cx property, that differs from 0 only if application have
3361 specifically set it */
3362 lpTbInfo
->cx
= (btnPtr
->fsStyle
& BTNS_SEP
)
3363 ? btnPtr
->cx
: (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3364 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3365 lpTbInfo
->fsState
= btnPtr
->fsState
;
3366 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3367 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3368 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3369 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3370 can't use TOOLBAR_GetText here */
3371 if (!IS_INTRESOURCE(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3372 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3374 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3376 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3378 lpTbInfo
->pszText
[0] = '\0';
3384 static inline LRESULT
3385 TOOLBAR_GetButtonSize (const TOOLBAR_INFO
*infoPtr
)
3387 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3388 (WORD
)infoPtr
->nButtonHeight
);
3393 TOOLBAR_GetButtonText (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPWSTR lpStr
, BOOL isW
)
3399 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3403 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3409 ret
= strlenW (lpText
);
3410 if (lpStr
) strcpyW (lpStr
, lpText
);
3414 ret
= WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3415 (LPSTR
)lpStr
, lpStr
? 0x7fffffff : 0, NULL
, NULL
) - 1;
3421 TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3423 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3424 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3425 return (LRESULT
)GETDISIMAGELIST(infoPtr
, wParam
);
3429 static inline LRESULT
3430 TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO
*infoPtr
)
3434 return infoPtr
->dwExStyle
;
3439 TOOLBAR_GetHotImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3441 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3442 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3443 return (LRESULT
)GETHOTIMAGELIST(infoPtr
, wParam
);
3448 TOOLBAR_GetHotItem (const TOOLBAR_INFO
*infoPtr
)
3450 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3453 if (infoPtr
->nHotItem
< 0)
3456 return (LRESULT
)infoPtr
->nHotItem
;
3461 TOOLBAR_GetDefImageList (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
3463 TRACE("hwnd=%p, wParam=%ld\n", infoPtr
->hwndSelf
, wParam
);
3464 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3465 return (LRESULT
) GETDEFIMAGELIST(infoPtr
, wParam
);
3470 TOOLBAR_GetInsertMark (const TOOLBAR_INFO
*infoPtr
, TBINSERTMARK
*lptbim
)
3472 TRACE("hwnd = %p, lptbim = %p\n", infoPtr
->hwndSelf
, lptbim
);
3474 *lptbim
= infoPtr
->tbim
;
3480 static inline LRESULT
3481 TOOLBAR_GetInsertMarkColor (const TOOLBAR_INFO
*infoPtr
)
3483 TRACE("hwnd = %p\n", infoPtr
->hwndSelf
);
3485 return (LRESULT
)infoPtr
->clrInsertMark
;
3490 TOOLBAR_GetItemRect (const TOOLBAR_INFO
*infoPtr
, INT nIndex
, LPRECT lpRect
)
3492 TBUTTON_INFO
*btnPtr
;
3494 btnPtr
= &infoPtr
->buttons
[nIndex
];
3495 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3500 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3503 lpRect
->left
= btnPtr
->rect
.left
;
3504 lpRect
->right
= btnPtr
->rect
.right
;
3505 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3506 lpRect
->top
= btnPtr
->rect
.top
;
3513 TOOLBAR_GetMaxSize (const TOOLBAR_INFO
*infoPtr
, LPSIZE lpSize
)
3518 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3519 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3521 TRACE("maximum size %d x %d\n",
3522 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3523 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3529 /* << TOOLBAR_GetObject >> */
3532 static inline LRESULT
3533 TOOLBAR_GetPadding (const TOOLBAR_INFO
*infoPtr
)
3535 return MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3540 TOOLBAR_GetRect (const TOOLBAR_INFO
*infoPtr
, INT Id
, LPRECT lpRect
)
3542 TBUTTON_INFO
*btnPtr
;
3545 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3546 btnPtr
= &infoPtr
->buttons
[nIndex
];
3547 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3553 lpRect
->left
= btnPtr
->rect
.left
;
3554 lpRect
->right
= btnPtr
->rect
.right
;
3555 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3556 lpRect
->top
= btnPtr
->rect
.top
;
3562 static inline LRESULT
3563 TOOLBAR_GetRows (const TOOLBAR_INFO
*infoPtr
)
3565 return infoPtr
->nRows
;
3570 TOOLBAR_GetState (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3574 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3578 return infoPtr
->buttons
[nIndex
].fsState
;
3582 static inline LRESULT
3583 TOOLBAR_GetStyle (const TOOLBAR_INFO
*infoPtr
)
3585 return infoPtr
->dwStyle
;
3589 static inline LRESULT
3590 TOOLBAR_GetTextRows (const TOOLBAR_INFO
*infoPtr
)
3592 return infoPtr
->nMaxTextRows
;
3597 TOOLBAR_GetToolTips (TOOLBAR_INFO
*infoPtr
)
3599 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3600 TOOLBAR_TooltipCreateControl(infoPtr
);
3601 return (LRESULT
)infoPtr
->hwndToolTip
;
3606 TOOLBAR_GetUnicodeFormat (const TOOLBAR_INFO
*infoPtr
)
3608 TRACE("%s hwnd=%p\n",
3609 infoPtr
->bUnicode
? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
3611 return infoPtr
->bUnicode
;
3615 static inline LRESULT
3616 TOOLBAR_GetVersion (const TOOLBAR_INFO
*infoPtr
)
3618 return infoPtr
->iVersion
;
3623 TOOLBAR_HideButton (TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fHide
)
3625 TBUTTON_INFO
*btnPtr
;
3631 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3635 btnPtr
= &infoPtr
->buttons
[nIndex
];
3636 oldState
= btnPtr
->fsState
;
3639 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3641 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3643 if (oldState
!= btnPtr
->fsState
) {
3644 TOOLBAR_LayoutToolbar (infoPtr
);
3645 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
3652 static inline LRESULT
3653 TOOLBAR_HitTest (const TOOLBAR_INFO
*infoPtr
, const POINT
* lpPt
)
3655 return TOOLBAR_InternalHitTest (infoPtr
, lpPt
, NULL
);
3660 TOOLBAR_Indeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fIndeterminate
)
3662 TBUTTON_INFO
*btnPtr
;
3666 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3670 btnPtr
= &infoPtr
->buttons
[nIndex
];
3671 oldState
= btnPtr
->fsState
;
3674 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3676 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3678 if(oldState
!= btnPtr
->fsState
)
3679 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3686 TOOLBAR_InsertButtonT(TOOLBAR_INFO
*infoPtr
, INT nIndex
, const TBBUTTON
*lpTbb
, BOOL fUnicode
)
3692 /* EPP: this seems to be an undocumented call (from my IE4)
3693 * I assume in that case that:
3694 * - index of insertion is at the end of existing buttons
3695 * I only see this happen with nIndex == -1, but it could have a special
3696 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3698 nIndex
= infoPtr
->nNumButtons
;
3700 } else if (nIndex
< 0)
3703 TRACE("inserting button index=%d\n", nIndex
);
3704 if (nIndex
> infoPtr
->nNumButtons
) {
3705 nIndex
= infoPtr
->nNumButtons
;
3706 TRACE("adjust index=%d\n", nIndex
);
3709 return TOOLBAR_InternalInsertButtonsT(infoPtr
, nIndex
, 1, lpTbb
, fUnicode
);
3712 /* << TOOLBAR_InsertMarkHitTest >> */
3716 TOOLBAR_IsButtonChecked (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3720 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3724 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3729 TOOLBAR_IsButtonEnabled (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3733 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3737 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3742 TOOLBAR_IsButtonHidden (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3746 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3750 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3755 TOOLBAR_IsButtonHighlighted (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3759 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3763 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3768 TOOLBAR_IsButtonIndeterminate (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3772 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3776 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3781 TOOLBAR_IsButtonPressed (const TOOLBAR_INFO
*infoPtr
, INT Id
)
3785 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3789 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3794 TOOLBAR_LoadImages (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HINSTANCE hInstance
)
3797 tbab
.hInst
= hInstance
;
3800 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", infoPtr
->hwndSelf
, tbab
.hInst
, tbab
.nID
);
3802 return TOOLBAR_AddBitmap(infoPtr
, 0, &tbab
);
3807 TOOLBAR_MapAccelerator (const TOOLBAR_INFO
*infoPtr
, WCHAR wAccel
, UINT
*pIDButton
)
3809 WCHAR wszAccel
[] = {'&',wAccel
,0};
3812 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3813 infoPtr
->hwndSelf
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3815 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3817 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3818 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3819 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3821 int iLen
= strlenW(wszAccel
);
3822 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3829 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3834 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
3836 *pIDButton
= btnPtr
->idCommand
;
3848 TOOLBAR_MarkButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fMark
)
3852 TBUTTON_INFO
*btnPtr
;
3854 TRACE("hwnd = %p, Id = %d, fMark = 0%d\n", infoPtr
->hwndSelf
, Id
, fMark
);
3856 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3860 btnPtr
= &infoPtr
->buttons
[nIndex
];
3861 oldState
= btnPtr
->fsState
;
3864 btnPtr
->fsState
|= TBSTATE_MARKED
;
3866 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
3868 if(oldState
!= btnPtr
->fsState
)
3869 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3875 /* fixes up an index of a button affected by a move */
3876 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
3880 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
3882 else if (*pIndex
== nIndex
)
3883 *pIndex
= nMoveIndex
;
3887 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
3889 else if (*pIndex
== nIndex
)
3890 *pIndex
= nMoveIndex
;
3896 TOOLBAR_MoveButton (TOOLBAR_INFO
*infoPtr
, INT Id
, INT nMoveIndex
)
3900 TBUTTON_INFO button
;
3902 TRACE("hwnd=%p, Id=%d, nMoveIndex=%d\n", infoPtr
->hwndSelf
, Id
, nMoveIndex
);
3904 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, TRUE
);
3905 if ((nIndex
== -1) || (nMoveIndex
< 0))
3908 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
3909 nMoveIndex
= infoPtr
->nNumButtons
- 1;
3911 button
= infoPtr
->buttons
[nIndex
];
3913 /* move button right */
3914 if (nIndex
< nMoveIndex
)
3916 nCount
= nMoveIndex
- nIndex
;
3917 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
3918 infoPtr
->buttons
[nMoveIndex
] = button
;
3920 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
3921 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
3922 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
3923 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
3925 else if (nIndex
> nMoveIndex
) /* move button left */
3927 nCount
= nIndex
- nMoveIndex
;
3928 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
3929 infoPtr
->buttons
[nMoveIndex
] = button
;
3931 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
3932 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
3933 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
3934 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
3937 TOOLBAR_LayoutToolbar(infoPtr
);
3938 TOOLBAR_AutoSize(infoPtr
);
3939 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
3946 TOOLBAR_PressButton (const TOOLBAR_INFO
*infoPtr
, INT Id
, BOOL fPress
)
3948 TBUTTON_INFO
*btnPtr
;
3952 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
3956 btnPtr
= &infoPtr
->buttons
[nIndex
];
3957 oldState
= btnPtr
->fsState
;
3960 btnPtr
->fsState
|= TBSTATE_PRESSED
;
3962 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
3964 if(oldState
!= btnPtr
->fsState
)
3965 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
3970 /* FIXME: there might still be some confusion her between number of buttons
3971 * and number of bitmaps */
3973 TOOLBAR_ReplaceBitmap (TOOLBAR_INFO
*infoPtr
, const TBREPLACEBITMAP
*lpReplace
)
3976 int i
= 0, nOldButtons
= 0, pos
= 0;
3977 int nOldBitmaps
, nNewBitmaps
= 0;
3978 HIMAGELIST himlDef
= 0;
3980 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
3981 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
3982 lpReplace
->nButtons
);
3984 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
3986 FIXME("changing standard bitmaps not implemented\n");
3989 else if (lpReplace
->hInstOld
!= 0 && lpReplace
->hInstOld
!= lpReplace
->hInstNew
)
3990 FIXME("resources not in the current module not implemented\n");
3992 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
3993 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
3994 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
3995 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
3996 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
3998 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
3999 nOldButtons
= tbi
->nButtons
;
4000 tbi
->nButtons
= lpReplace
->nButtons
;
4001 tbi
->hInst
= lpReplace
->hInstNew
;
4002 tbi
->nID
= lpReplace
->nIDNew
;
4003 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4006 pos
+= tbi
->nButtons
;
4009 if (nOldButtons
== 0)
4011 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4015 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4018 if (lpReplace
->hInstNew
)
4019 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4021 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4023 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4024 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4026 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4028 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4029 ImageList_Remove(himlDef
, i
);
4033 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4034 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4035 DeleteObject(hBitmap
);
4038 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4040 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4041 pos
, nOldBitmaps
, nNewBitmaps
);
4043 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4048 /* helper for TOOLBAR_SaveRestoreW */
4050 TOOLBAR_Save(const TBSAVEPARAMSW
*lpSave
)
4052 FIXME("save to %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4053 debugstr_w(lpSave
->pszValueName
));
4059 /* helper for TOOLBAR_Restore */
4061 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4065 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4067 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4070 Free(infoPtr
->buttons
);
4071 infoPtr
->buttons
= NULL
;
4072 infoPtr
->nNumButtons
= 0;
4076 /* helper for TOOLBAR_SaveRestoreW */
4078 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4087 /* restore toolbar information */
4088 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4089 debugstr_w(lpSave
->pszValueName
));
4091 memset(&nmtbr
, 0, sizeof(nmtbr
));
4093 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4094 KEY_QUERY_VALUE
, &hkey
);
4096 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4098 if (!res
&& dwType
!= REG_BINARY
)
4099 res
= ERROR_FILE_NOT_FOUND
;
4102 nmtbr
.pData
= Alloc(dwSize
);
4103 nmtbr
.cbData
= dwSize
;
4104 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4107 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4108 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4111 nmtbr
.pCurrent
= nmtbr
.pData
;
4113 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4114 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4116 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4120 /* remove all existing buttons as this function is designed to
4121 * restore the toolbar to a previously saved state */
4122 TOOLBAR_DeleteAllButtons(infoPtr
);
4124 for (i
= 0; i
< nmtbr
.cButtons
; i
++)
4127 nmtbr
.tbButton
.iBitmap
= -1;
4128 nmtbr
.tbButton
.fsState
= 0;
4129 nmtbr
.tbButton
.fsStyle
= 0;
4130 nmtbr
.tbButton
.idCommand
= 0;
4131 if (*nmtbr
.pCurrent
== (DWORD
)-1)
4134 nmtbr
.tbButton
.fsStyle
= TBSTYLE_SEP
;
4135 /* when inserting separators, iBitmap controls it's size.
4136 0 sets default size (width) */
4137 nmtbr
.tbButton
.iBitmap
= 0;
4139 else if (*nmtbr
.pCurrent
== (DWORD
)-2)
4141 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4143 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4147 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4149 /* can't contain real string as we don't know whether
4150 * the client put an ANSI or Unicode string in there */
4151 if (!IS_INTRESOURCE(nmtbr
.tbButton
.iString
))
4152 nmtbr
.tbButton
.iString
= 0;
4154 TOOLBAR_InsertButtonT(infoPtr
, -1, &nmtbr
.tbButton
, TRUE
);
4157 /* do legacy notifications */
4158 if (infoPtr
->iVersion
< 5)
4160 /* FIXME: send TBN_BEGINADJUST */
4161 FIXME("send TBN_GETBUTTONINFO for each button\n");
4162 /* FIXME: send TBN_ENDADJUST */
4165 /* remove all uninitialised buttons
4166 * note: loop backwards to avoid having to fixup i on a
4168 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4169 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4170 TOOLBAR_DeleteButton(infoPtr
, i
);
4172 /* only indicate success if at least one button survived */
4173 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4184 TOOLBAR_SaveRestoreW (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4186 if (lpSave
== NULL
) return 0;
4189 return TOOLBAR_Save(lpSave
);
4191 return TOOLBAR_Restore(infoPtr
, lpSave
);
4196 TOOLBAR_SaveRestoreA (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4198 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4199 TBSAVEPARAMSW SaveW
;
4203 if (lpSave
== NULL
) return 0;
4205 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4206 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4207 if (pszSubKey
) goto exit
;
4208 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4210 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4211 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4212 if (!pszValueName
) goto exit
;
4213 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4215 SaveW
.pszValueName
= pszValueName
;
4216 SaveW
.pszSubKey
= pszSubKey
;
4217 SaveW
.hkr
= lpSave
->hkr
;
4218 result
= TOOLBAR_SaveRestoreW(infoPtr
, wParam
, &SaveW
);
4221 Free (pszValueName
);
4229 TOOLBAR_SetAnchorHighlight (TOOLBAR_INFO
*infoPtr
, BOOL bAnchor
)
4231 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4233 TRACE("hwnd=%p, bAnchor = %s\n", infoPtr
->hwndSelf
, bAnchor
? "TRUE" : "FALSE");
4235 infoPtr
->bAnchor
= bAnchor
;
4237 /* Native does not remove the hot effect from an already hot button */
4239 return (LRESULT
)bOldAnchor
;
4244 TOOLBAR_SetBitmapSize (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4246 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4247 short width
= (short)LOWORD(lParam
);
4248 short height
= (short)HIWORD(lParam
);
4250 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", infoPtr
->hwndSelf
, wParam
, lParam
);
4253 FIXME("wParam is %ld. Perhaps image list index?\n", wParam
);
4255 /* 0 width or height is changed to 1 */
4261 if (infoPtr
->nNumButtons
> 0)
4262 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4263 infoPtr
->nNumButtons
,
4264 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
, width
, height
);
4266 if (width
< -1 || height
< -1)
4268 /* Windows destroys the imagelist and seems to actually use negative
4269 * values to compute button sizes */
4270 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width
, height
);
4274 /* width or height of -1 means no change */
4276 infoPtr
->nBitmapWidth
= width
;
4278 infoPtr
->nBitmapHeight
= height
;
4280 if ((himlDef
== infoPtr
->himlInt
) &&
4281 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4283 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4284 infoPtr
->nBitmapHeight
);
4287 TOOLBAR_CalcToolbar(infoPtr
);
4288 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4294 TOOLBAR_SetButtonInfo (TOOLBAR_INFO
*infoPtr
, INT Id
,
4295 const TBBUTTONINFOW
*lptbbi
, BOOL isW
)
4297 TBUTTON_INFO
*btnPtr
;
4303 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4306 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, lptbbi
->dwMask
& TBIF_BYINDEX
);
4310 btnPtr
= &infoPtr
->buttons
[nIndex
];
4311 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4312 btnPtr
->idCommand
= lptbbi
->idCommand
;
4313 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4314 btnPtr
->iBitmap
= lptbbi
->iImage
;
4315 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4316 btnPtr
->dwData
= lptbbi
->lParam
;
4317 if (lptbbi
->dwMask
& TBIF_SIZE
)
4318 btnPtr
->cx
= lptbbi
->cx
;
4319 if (lptbbi
->dwMask
& TBIF_STATE
)
4320 btnPtr
->fsState
= lptbbi
->fsState
;
4321 if (lptbbi
->dwMask
& TBIF_STYLE
)
4322 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4324 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4325 /* iString is index, zero it to make Str_SetPtr succeed */
4326 if (!TOOLBAR_ButtonHasString(btnPtr
)) btnPtr
->iString
= 0;
4329 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4331 Str_SetPtrAtoW ((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lptbbi
->pszText
);
4334 /* save the button rect to see if we need to redraw the whole toolbar */
4335 oldBtnRect
= btnPtr
->rect
;
4336 TOOLBAR_LayoutToolbar(infoPtr
);
4338 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4339 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4341 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4348 TOOLBAR_SetButtonSize (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4350 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4352 if ((cx
< 0) || (cy
< 0))
4354 ERR("invalid parameter 0x%08x\n", (DWORD
)lParam
);
4358 TRACE("%p, cx = %d, cy = %d\n", infoPtr
->hwndSelf
, cx
, cy
);
4360 /* The documentation claims you can only change the button size before
4361 * any button has been added. But this is wrong.
4362 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4363 * it to the toolbar, and it checks that the return value is nonzero - mjm
4364 * Further testing shows that we must actually perform the change too.
4367 * The documentation also does not mention that if 0 is supplied for
4368 * either size, the system changes it to the default of 24 wide and
4369 * 22 high. Demonstrated in ControlSpy Toolbar. GLA 3/02
4371 if (cx
== 0) cx
= 24;
4372 if (cy
== 0) cy
= 22;
4374 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4375 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4377 infoPtr
->nButtonWidth
= cx
;
4378 infoPtr
->nButtonHeight
= cy
;
4380 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
4381 TOOLBAR_LayoutToolbar(infoPtr
);
4387 TOOLBAR_SetButtonWidth (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4389 /* if setting to current values, ignore */
4390 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4391 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4392 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4393 infoPtr
->cxMin
, infoPtr
->cxMax
);
4397 /* save new values */
4398 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4399 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4401 /* otherwise we need to recalc the toolbar and in some cases
4402 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4403 which doesn't actually draw - GA). */
4404 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4405 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4407 TOOLBAR_CalcToolbar (infoPtr
);
4409 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
4416 TOOLBAR_SetCmdId (TOOLBAR_INFO
*infoPtr
, INT nIndex
, INT nId
)
4418 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4421 infoPtr
->buttons
[nIndex
].idCommand
= nId
;
4423 if (infoPtr
->hwndToolTip
) {
4425 FIXME("change tool tip!\n");
4434 TOOLBAR_SetDisabledImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4436 HIMAGELIST himlTemp
;
4439 if (infoPtr
->iVersion
>= 5)
4442 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4443 &infoPtr
->cimlDis
, himl
, id
);
4445 /* FIXME: redraw ? */
4447 return (LRESULT
)himlTemp
;
4452 TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4456 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", infoPtr
->hwndSelf
, (DWORD
)wParam
, (DWORD
)lParam
);
4458 dwTemp
= infoPtr
->dwDTFlags
;
4459 infoPtr
->dwDTFlags
=
4460 (infoPtr
->dwDTFlags
& (DWORD
)wParam
) | (DWORD
)lParam
;
4462 return (LRESULT
)dwTemp
;
4465 /* This function differs a bit from what MSDN says it does:
4466 * 1. lParam contains extended style flags to OR with current style
4467 * (MSDN isn't clear on the OR bit)
4468 * 2. wParam appears to contain extended style flags to be reset
4469 * (MSDN says that this parameter is reserved)
4472 TOOLBAR_SetExtendedStyle (TOOLBAR_INFO
*infoPtr
, DWORD mask
, DWORD style
)
4474 DWORD old_style
= infoPtr
->dwExStyle
;
4476 TRACE("mask=0x%08x, style=0x%08x\n", mask
, style
);
4479 infoPtr
->dwExStyle
= (old_style
& ~mask
) | (style
& mask
);
4481 infoPtr
->dwExStyle
= style
;
4483 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4484 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4485 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4487 if ((old_style
^ infoPtr
->dwExStyle
) & TBSTYLE_EX_MIXEDBUTTONS
)
4488 TOOLBAR_CalcToolbar(infoPtr
);
4490 TOOLBAR_LayoutToolbar(infoPtr
);
4492 TOOLBAR_AutoSize(infoPtr
);
4493 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4500 TOOLBAR_SetHotImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4502 HIMAGELIST himlTemp
;
4505 if (infoPtr
->iVersion
>= 5)
4508 TRACE("hwnd = %p, himl = %p, id = %d\n", infoPtr
->hwndSelf
, himl
, id
);
4510 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4511 &infoPtr
->cimlHot
, himl
, id
);
4513 /* FIXME: redraw ? */
4515 return (LRESULT
)himlTemp
;
4519 /* Makes previous hot button no longer hot, makes the specified
4520 * button hot and sends appropriate notifications. dwReason is one or
4521 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4522 * NOTE 1: this function does not validate nHit
4523 * NOTE 2: the name of this function is completely made up and
4524 * not based on any documentation from Microsoft. */
4526 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4528 if (infoPtr
->nHotItem
!= nHit
)
4530 NMTBHOTITEM nmhotitem
;
4531 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4533 nmhotitem
.dwFlags
= dwReason
;
4534 if(infoPtr
->nHotItem
>= 0)
4536 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4537 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4541 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4542 nmhotitem
.idOld
= 0;
4547 btnPtr
= &infoPtr
->buttons
[nHit
];
4548 nmhotitem
.idNew
= btnPtr
->idCommand
;
4552 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4553 nmhotitem
.idNew
= 0;
4556 /* now change the hot and invalidate the old and new buttons - if the
4558 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4561 oldBtnPtr
->bHot
= FALSE
;
4562 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4564 /* setting disabled buttons as hot fails even if the notify contains the button id */
4565 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4566 btnPtr
->bHot
= TRUE
;
4567 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4568 infoPtr
->nHotItem
= nHit
;
4571 infoPtr
->nHotItem
= -1;
4577 TOOLBAR_SetHotItem (TOOLBAR_INFO
*infoPtr
, INT nHotItem
)
4579 INT nOldHotItem
= infoPtr
->nHotItem
;
4581 TRACE("hwnd = %p, nHotItem = %d\n", infoPtr
->hwndSelf
, nHotItem
);
4583 if (nHotItem
>= infoPtr
->nNumButtons
)
4584 return infoPtr
->nHotItem
;
4589 /* NOTE: an application can still remove the hot item even if anchor
4590 * highlighting is enabled */
4592 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, HICF_OTHER
);
4594 if (nOldHotItem
< 0)
4597 return (LRESULT
)nOldHotItem
;
4602 TOOLBAR_SetImageList (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himl
)
4604 HIMAGELIST himlTemp
;
4605 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4606 INT oldBitmapWidth
= infoPtr
->nBitmapWidth
;
4607 INT oldBitmapHeight
= infoPtr
->nBitmapHeight
;
4610 if (infoPtr
->iVersion
>= 5)
4613 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4614 &infoPtr
->cimlDef
, himl
, id
);
4616 infoPtr
->nNumBitmaps
= 0;
4617 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4618 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4620 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4621 &infoPtr
->nBitmapHeight
))
4623 infoPtr
->nBitmapWidth
= 1;
4624 infoPtr
->nBitmapHeight
= 1;
4626 if ((oldBitmapWidth
!= infoPtr
->nBitmapWidth
) || (oldBitmapHeight
!= infoPtr
->nBitmapHeight
))
4628 TOOLBAR_CalcToolbar(infoPtr
);
4629 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4630 TOOLBAR_SetButtonSize(infoPtr
, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4633 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4634 infoPtr
->hwndSelf
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4635 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4637 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4639 return (LRESULT
)himlTemp
;
4644 TOOLBAR_SetIndent (TOOLBAR_INFO
*infoPtr
, INT nIndent
)
4646 infoPtr
->nIndent
= nIndent
;
4650 /* process only on indent changing */
4651 if(infoPtr
->nIndent
!= nIndent
)
4653 infoPtr
->nIndent
= nIndent
;
4654 TOOLBAR_CalcToolbar (infoPtr
);
4655 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4663 TOOLBAR_SetInsertMark (TOOLBAR_INFO
*infoPtr
, const TBINSERTMARK
*lptbim
)
4665 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", infoPtr
->hwndSelf
, lptbim
->iButton
, lptbim
->dwFlags
);
4667 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4669 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4673 if ((lptbim
->iButton
== -1) ||
4674 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4675 (lptbim
->iButton
>= 0)))
4677 infoPtr
->tbim
= *lptbim
;
4678 /* FIXME: don't need to update entire toolbar */
4679 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4682 ERR("Invalid button index %d\n", lptbim
->iButton
);
4689 TOOLBAR_SetInsertMarkColor (TOOLBAR_INFO
*infoPtr
, COLORREF clr
)
4691 infoPtr
->clrInsertMark
= clr
;
4693 /* FIXME: don't need to update entire toolbar */
4694 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4701 TOOLBAR_SetMaxTextRows (TOOLBAR_INFO
*infoPtr
, INT nMaxRows
)
4703 infoPtr
->nMaxTextRows
= nMaxRows
;
4705 TOOLBAR_CalcToolbar(infoPtr
);
4710 /* MSDN gives slightly wrong info on padding.
4711 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4712 * 2. It is not used to create a blank area between the edge of the button
4713 * and the text or image if TBSTYLE_LIST is set. It is used to control
4714 * the gap between the image and text.
4715 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4716 * to control the bottom and right borders [with the border being
4717 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4718 * is shared evenly on both sides of the button.
4719 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4722 TOOLBAR_SetPadding (TOOLBAR_INFO
*infoPtr
, LPARAM lParam
)
4726 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4727 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4728 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4729 TRACE("cx=%d, cy=%d\n",
4730 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4731 return (LRESULT
) oldPad
;
4736 TOOLBAR_SetParent (TOOLBAR_INFO
*infoPtr
, HWND hParent
)
4742 hwndOldNotify
= infoPtr
->hwndNotify
;
4743 infoPtr
->hwndNotify
= hParent
;
4745 return (LRESULT
)hwndOldNotify
;
4750 TOOLBAR_SetRows (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPRECT lprc
)
4752 int rows
= LOWORD(wParam
);
4753 BOOL bLarger
= HIWORD(wParam
);
4757 TRACE("Setting rows to %d (%d)\n", rows
, bLarger
);
4759 if(infoPtr
->nRows
!= rows
)
4761 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
;
4762 int curColumn
= 0; /* Current column */
4763 int curRow
= 0; /* Current row */
4764 int hidden
= 0; /* Number of hidden buttons */
4765 int seps
= 0; /* Number of separators */
4766 int idealWrap
= 0; /* Ideal wrap point */
4771 Calculate new size and wrap points - Under windows, setrows will
4772 change the dimensions if needed to show the number of requested
4773 rows (if CCS_NORESIZE is set), or will take up the whole window
4774 (if no CCS_NORESIZE).
4776 Basic algorithm - If N buttons, and y rows requested, each row
4777 contains N/y buttons.
4779 FIXME: Handling of separators not obvious from testing results
4780 FIXME: Take width of window into account?
4783 /* Loop through the buttons one by one counting key items */
4784 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4786 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
4787 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4789 else if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
4793 /* FIXME: Separators make this quite complex */
4794 if (seps
) FIXME("Separators unhandled\n");
4796 /* Round up so more per line, i.e., less rows */
4797 idealWrap
= (infoPtr
->nNumButtons
- hidden
+ (rows
-1)) / (rows
? rows
: 1);
4799 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4800 achieve the requested number of rows. */
4801 if (bLarger
&& idealWrap
> 1)
4803 int resRows
= (infoPtr
->nNumButtons
+ (idealWrap
-1)) / idealWrap
;
4804 int moreRows
= (infoPtr
->nNumButtons
+ (idealWrap
-2)) / (idealWrap
-1);
4806 if (resRows
< rows
&& moreRows
> rows
)
4809 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap
);
4813 curColumn
= curRow
= 0;
4815 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap
,
4816 infoPtr
->nNumButtons
, hidden
, rows
);
4818 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4820 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4823 /* Step on, wrap if necessary or flag next to wrap */
4832 if (curColumn
> (idealWrap
-1)) {
4834 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
4838 TRACE("Result - %d rows\n", curRow
+ 1);
4840 /* recalculate toolbar */
4841 TOOLBAR_CalcToolbar (infoPtr
);
4843 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
4844 if NORESIZE is NOT set, then the toolbar will always be resized to
4845 take up the whole window. With it set, sizing needs to be manual. */
4846 if (infoPtr
->dwStyle
& CCS_NORESIZE
) {
4847 SetWindowPos(infoPtr
->hwndSelf
, NULL
, 0, 0,
4848 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
4849 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
,
4850 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
4853 /* repaint toolbar */
4854 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4857 /* return bounding rectangle */
4859 lprc
->left
= infoPtr
->rcBound
.left
;
4860 lprc
->right
= infoPtr
->rcBound
.right
;
4861 lprc
->top
= infoPtr
->rcBound
.top
;
4862 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
4870 TOOLBAR_SetState (TOOLBAR_INFO
*infoPtr
, INT Id
, LPARAM lParam
)
4872 TBUTTON_INFO
*btnPtr
;
4875 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, Id
, FALSE
);
4879 btnPtr
= &infoPtr
->buttons
[nIndex
];
4881 /* if hidden state has changed the invalidate entire window and recalc */
4882 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
4883 btnPtr
->fsState
= LOWORD(lParam
);
4884 TOOLBAR_CalcToolbar (infoPtr
);
4885 InvalidateRect(infoPtr
->hwndSelf
, 0, TRUE
);
4889 /* process state changing if current state doesn't match new state */
4890 if(btnPtr
->fsState
!= LOWORD(lParam
))
4892 btnPtr
->fsState
= LOWORD(lParam
);
4893 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4901 TOOLBAR_SetStyle (TOOLBAR_INFO
*infoPtr
, DWORD style
)
4903 infoPtr
->dwStyle
= style
;
4908 static inline LRESULT
4909 TOOLBAR_SetToolTips (TOOLBAR_INFO
*infoPtr
, HWND hwndTooltip
)
4911 TRACE("hwnd=%p, hwndTooltip=%p\n", infoPtr
->hwndSelf
, hwndTooltip
);
4913 infoPtr
->hwndToolTip
= hwndTooltip
;
4919 TOOLBAR_SetUnicodeFormat (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
4923 TRACE("%s hwnd=%p\n",
4924 ((BOOL
)wParam
) ? "TRUE" : "FALSE", infoPtr
->hwndSelf
);
4926 bTemp
= infoPtr
->bUnicode
;
4927 infoPtr
->bUnicode
= (BOOL
)wParam
;
4934 TOOLBAR_GetColorScheme (const TOOLBAR_INFO
*infoPtr
, LPCOLORSCHEME lParam
)
4936 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
4937 comctl32_color
.clrBtnHighlight
:
4938 infoPtr
->clrBtnHighlight
;
4939 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
4940 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
4946 TOOLBAR_SetColorScheme (TOOLBAR_INFO
*infoPtr
, const COLORSCHEME
*lParam
)
4948 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
4949 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
4950 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
4952 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
4953 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
4954 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
4960 TOOLBAR_SetVersion (TOOLBAR_INFO
*infoPtr
, INT iVersion
)
4962 INT iOldVersion
= infoPtr
->iVersion
;
4964 infoPtr
->iVersion
= iVersion
;
4966 if (infoPtr
->iVersion
>= 5)
4967 TOOLBAR_SetUnicodeFormat(infoPtr
, TRUE
);
4974 TOOLBAR_GetStringA (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPSTR str
)
4976 WORD iString
= HIWORD(wParam
);
4977 WORD buffersize
= LOWORD(wParam
);
4980 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, buffersize
, str
);
4982 if (iString
< infoPtr
->nNumStrings
)
4984 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
4987 TRACE("returning %s\n", debugstr_a(str
));
4990 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
4997 TOOLBAR_GetStringW (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPWSTR str
)
4999 WORD iString
= HIWORD(wParam
);
5000 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5003 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr
->hwndSelf
, iString
, LOWORD(wParam
), str
);
5005 if (iString
< infoPtr
->nNumStrings
)
5007 len
= min(len
, strlenW(infoPtr
->strings
[iString
]));
5008 ret
= (len
+1)*sizeof(WCHAR
);
5011 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5016 TRACE("returning %s\n", debugstr_w(str
));
5019 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5024 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5025 * is the maximum size of the toolbar? */
5026 static LRESULT
TOOLBAR_Unkwn45D(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5028 SIZE
* pSize
= (SIZE
*)lParam
;
5029 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5034 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5035 * caller to specify a reason why the hot item changed (rather than just the
5036 * HICF_OTHER that TB_SETHOTITEM sends). */
5038 TOOLBAR_SetHotItem2 (TOOLBAR_INFO
*infoPtr
, INT nHotItem
, LPARAM lParam
)
5040 INT nOldHotItem
= infoPtr
->nHotItem
;
5042 TRACE("old item=%d, new item=%d, flags=%08x\n",
5043 nOldHotItem
, nHotItem
, (DWORD
)lParam
);
5045 if (nHotItem
< 0 || nHotItem
> infoPtr
->nNumButtons
)
5048 /* NOTE: an application can still remove the hot item even if anchor
5049 * highlighting is enabled */
5051 TOOLBAR_SetHotItemEx(infoPtr
, nHotItem
, lParam
);
5055 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5058 /* Sets the toolbar global iListGap parameter which controls the amount of
5059 * spacing between the image and the text of buttons for TBSTYLE_LIST
5061 static LRESULT
TOOLBAR_SetListGap(TOOLBAR_INFO
*infoPtr
, INT iListGap
)
5063 TRACE("hwnd=%p iListGap=%d\n", infoPtr
->hwndSelf
, iListGap
);
5065 infoPtr
->iListGap
= iListGap
;
5067 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
5072 /* Returns the number of maximum number of image lists associated with the
5073 * various states. */
5074 static LRESULT
TOOLBAR_GetImageListCount(const TOOLBAR_INFO
*infoPtr
)
5076 TRACE("hwnd=%p\n", infoPtr
->hwndSelf
);
5078 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5082 TOOLBAR_GetIdealSize (const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5084 LPSIZE lpsize
= (LPSIZE
)lParam
;
5090 * Testing shows the following:
5091 * wParam = 0 adjust cx value
5092 * = 1 set cy value to max size.
5093 * lParam pointer to SIZE structure
5096 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5097 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5101 if (lpsize
->cx
== -1) {
5102 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5104 else if(HIWORD(lpsize
->cx
)) {
5106 HWND hwndParent
= GetParent(infoPtr
->hwndSelf
);
5108 GetWindowRect(infoPtr
->hwndSelf
, &rc
);
5109 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5110 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc
));
5111 lpsize
->cx
= max(rc
.right
-rc
.left
,
5112 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5115 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5119 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5122 FIXME("Unknown wParam %ld\n", wParam
);
5125 TRACE("set to -> 0x%08x 0x%08x\n",
5126 lpsize
->cx
, lpsize
->cy
);
5130 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5132 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5134 InvalidateRect(hwnd
, NULL
, TRUE
);
5140 TOOLBAR_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
5142 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
5145 TRACE("hwnd = %p, style=0x%08x\n", hwnd
, lpcs
->style
);
5147 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5148 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5149 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5150 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_REQUERY
));
5151 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5153 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5154 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5156 OpenThemeData (hwnd
, themeClass
);
5158 TOOLBAR_CheckStyle (infoPtr
);
5165 TOOLBAR_Destroy (TOOLBAR_INFO
*infoPtr
)
5169 /* delete tooltip control */
5170 if (infoPtr
->hwndToolTip
)
5171 DestroyWindow (infoPtr
->hwndToolTip
);
5173 /* delete temporary buffer for tooltip text */
5174 Free (infoPtr
->pszTooltipText
);
5175 Free (infoPtr
->bitmaps
); /* bitmaps list */
5177 /* delete button data */
5178 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5179 if (TOOLBAR_ButtonHasString(&infoPtr
->buttons
[i
]))
5180 Free ((LPWSTR
)infoPtr
->buttons
[i
].iString
);
5181 Free (infoPtr
->buttons
);
5183 /* delete strings */
5184 if (infoPtr
->strings
) {
5185 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5186 Free (infoPtr
->strings
[i
]);
5188 Free (infoPtr
->strings
);
5191 /* destroy internal image list */
5192 if (infoPtr
->himlInt
)
5193 ImageList_Destroy (infoPtr
->himlInt
);
5195 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5196 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5197 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5199 /* delete default font */
5200 DeleteObject (infoPtr
->hDefaultFont
);
5202 CloseThemeData (GetWindowTheme (infoPtr
->hwndSelf
));
5204 /* free toolbar info data */
5205 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
5213 TOOLBAR_EraseBackground (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5215 NMTBCUSTOMDRAW tbcd
;
5218 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
5219 DWORD dwEraseCustDraw
= 0;
5221 /* the app has told us not to redraw the toolbar */
5222 if (!infoPtr
->bDoRedraw
)
5225 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5226 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5227 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5228 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5229 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5230 dwEraseCustDraw
= ntfret
& 0xffff;
5232 /* FIXME: in general the return flags *can* be or'ed together */
5233 switch (dwEraseCustDraw
)
5235 case CDRF_DODEFAULT
:
5237 case CDRF_SKIPDEFAULT
:
5240 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5241 infoPtr
->hwndSelf
, ntfret
);
5245 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5246 * to my parent for processing.
5248 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5250 HDC hdc
= (HDC
)wParam
;
5255 parent
= GetParent(infoPtr
->hwndSelf
);
5256 MapWindowPoints(infoPtr
->hwndSelf
, parent
, &pt
, 1);
5257 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5258 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5259 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5262 ret
= DefWindowProcW (infoPtr
->hwndSelf
, WM_ERASEBKGND
, wParam
, lParam
);
5264 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5265 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5266 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5267 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5268 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5269 dwEraseCustDraw
= ntfret
& 0xffff;
5270 switch (dwEraseCustDraw
)
5272 case CDRF_DODEFAULT
:
5274 case CDRF_SKIPDEFAULT
:
5277 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5278 infoPtr
->hwndSelf
, ntfret
);
5285 static inline LRESULT
5286 TOOLBAR_GetFont (const TOOLBAR_INFO
*infoPtr
)
5288 return (LRESULT
)infoPtr
->hFont
;
5293 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5296 INT nNewHotItem
= infoPtr
->nHotItem
;
5298 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5301 if ((nNewHotItem
+ iDirection
< 0) ||
5302 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5304 NMTBWRAPHOTITEM nmtbwhi
;
5305 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5306 nmtbwhi
.iDirection
= iDirection
;
5307 nmtbwhi
.dwReason
= dwReason
;
5309 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5313 nNewHotItem
+= iDirection
;
5314 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5316 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5317 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5319 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5326 TOOLBAR_KeyDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5330 nmkey
.nVKey
= (UINT
)wParam
;
5331 nmkey
.uFlags
= HIWORD(lParam
);
5333 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5334 return DefWindowProcW(infoPtr
->hwndSelf
, WM_KEYDOWN
, wParam
, lParam
);
5336 switch ((UINT
)wParam
)
5340 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5344 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5348 if ((infoPtr
->nHotItem
>= 0) &&
5349 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5351 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5352 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5353 (LPARAM
)infoPtr
->hwndSelf
);
5363 TOOLBAR_LButtonDblClk (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5368 pt
.x
= (short)LOWORD(lParam
);
5369 pt
.y
= (short)HIWORD(lParam
);
5370 TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5373 TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
5374 else if (infoPtr
->dwStyle
& CCS_ADJUSTABLE
)
5375 TOOLBAR_Customize (infoPtr
);
5382 TOOLBAR_LButtonDown (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5384 TBUTTON_INFO
*btnPtr
;
5389 BOOL bDragKeyPressed
;
5394 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5395 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5397 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5399 if (infoPtr
->hwndToolTip
)
5400 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5401 WM_LBUTTONDOWN
, wParam
, lParam
);
5403 pt
.x
= (short)LOWORD(lParam
);
5404 pt
.y
= (short)HIWORD(lParam
);
5405 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5408 btnPtr
= &infoPtr
->buttons
[nHit
];
5410 if (button
&& bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5412 infoPtr
->nButtonDrag
= nHit
;
5413 SetCapture (infoPtr
->hwndSelf
);
5415 /* If drag cursor has not been loaded, load it.
5416 * Note: it doesn't need to be freed */
5418 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5419 SetCursor(hCursorDrag
);
5424 infoPtr
->nOldHit
= nHit
;
5426 CopyRect(&arrowRect
, &btnPtr
->rect
);
5427 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5429 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5430 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5431 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5432 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5433 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5434 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5438 /* draw in pressed state */
5439 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5440 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5442 btnPtr
->bDropDownPressed
= TRUE
;
5443 RedrawWindow(infoPtr
->hwndSelf
,&btnPtr
->rect
,0,
5444 RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5446 memset(&nmtb
, 0, sizeof(nmtb
));
5447 nmtb
.iItem
= btnPtr
->idCommand
;
5448 nmtb
.rcButton
= btnPtr
->rect
;
5449 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5451 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5453 if (res
!= TBDDRET_TREATPRESSED
)
5457 /* redraw button in unpressed state */
5458 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5459 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5461 btnPtr
->bDropDownPressed
= FALSE
;
5462 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5464 /* find and set hot item */
5466 ScreenToClient(infoPtr
->hwndSelf
, &pt
);
5467 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5468 if (!infoPtr
->bAnchor
|| button
)
5469 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5471 /* remove any left mouse button down or double-click messages
5472 * so that we can get a toggle effect on the button */
5473 while (PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5474 PeekMessageW(&msg
, infoPtr
->hwndSelf
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5479 /* otherwise drop through and process as pushed */
5481 infoPtr
->bCaptured
= TRUE
;
5482 infoPtr
->nButtonDown
= nHit
;
5483 infoPtr
->bDragOutSent
= FALSE
;
5485 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5487 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5489 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5490 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5491 UpdateWindow(infoPtr
->hwndSelf
);
5492 SetCapture (infoPtr
->hwndSelf
);
5497 memset(&nmtb
, 0, sizeof(nmtb
));
5498 nmtb
.iItem
= btnPtr
->idCommand
;
5499 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5502 nmmouse
.dwHitInfo
= nHit
;
5504 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5506 nmmouse
.dwItemSpec
= -1;
5509 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5510 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5513 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5516 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5517 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONDOWN
, wParam
, lParam
);
5523 TOOLBAR_LButtonUp (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5525 TBUTTON_INFO
*btnPtr
;
5534 if (infoPtr
->hwndToolTip
)
5535 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5536 WM_LBUTTONUP
, wParam
, lParam
);
5538 pt
.x
= (short)LOWORD(lParam
);
5539 pt
.y
= (short)HIWORD(lParam
);
5540 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5542 if (!infoPtr
->bAnchor
|| button
)
5543 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5545 if (infoPtr
->nButtonDrag
>= 0) {
5549 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5552 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5554 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5555 if (PtInRect(&rcClient
, pt
))
5562 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5565 if (nButton
== infoPtr
->nButtonDrag
)
5567 /* if the button is moved sightly left and we have a
5568 * separator there then remove it */
5569 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5571 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5572 TOOLBAR_DeleteButton(infoPtr
, nButton
- 1);
5574 else /* else insert a separator before the dragged button */
5577 memset(&tbb
, 0, sizeof(tbb
));
5578 tbb
.fsStyle
= BTNS_SEP
;
5580 TOOLBAR_InsertButtonT(infoPtr
, nButton
, &tbb
, TRUE
);
5587 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5588 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, 0);
5590 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5593 TOOLBAR_MoveButton(infoPtr
, infoPtr
->nButtonDrag
, nButton
);
5598 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5599 TOOLBAR_DeleteButton(infoPtr
, infoPtr
->nButtonDrag
);
5602 /* button under cursor changed so need to re-set hot item */
5603 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
| HICF_LMOUSE
);
5604 infoPtr
->nButtonDrag
= -1;
5606 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5608 else if (infoPtr
->nButtonDown
>= 0) {
5609 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5610 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5612 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5613 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5614 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5616 if ((nOldIndex
!= nHit
) &&
5618 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5619 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5622 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5623 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5625 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5629 if (nOldIndex
!= -1)
5630 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5633 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5634 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5635 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5637 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5639 infoPtr
->nButtonDown
= -1;
5641 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5642 TOOLBAR_SendNotify (&hdr
, infoPtr
,
5643 NM_RELEASEDCAPTURE
);
5645 memset(&nmtb
, 0, sizeof(nmtb
));
5646 nmtb
.iItem
= btnPtr
->idCommand
;
5647 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5650 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5652 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5653 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)infoPtr
->hwndSelf
);
5655 /* In case we have just been destroyed... */
5656 if(!IsWindow(infoPtr
->hwndSelf
))
5661 /* !!! Undocumented - toolbar at 4.71 level and above sends
5662 * NM_CLICK with the NMMOUSE structure. */
5663 nmmouse
.dwHitInfo
= nHit
;
5666 nmmouse
.dwItemSpec
= -1;
5669 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5670 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5673 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5676 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5677 return DefWindowProcW(infoPtr
->hwndSelf
, WM_LBUTTONUP
, wParam
, lParam
);
5683 TOOLBAR_RButtonUp(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5690 pt
.x
= (short)LOWORD(lParam
);
5691 pt
.y
= (short)HIWORD(lParam
);
5693 nHit
= TOOLBAR_InternalHitTest(infoPtr
, &pt
, &button
);
5694 nmmouse
.dwHitInfo
= nHit
;
5697 nmmouse
.dwItemSpec
= -1;
5699 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5700 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5703 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
5706 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5707 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONUP
, wParam
, lParam
);
5713 TOOLBAR_RButtonDblClk( TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5717 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5718 return DefWindowProcW(infoPtr
->hwndSelf
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
5724 TOOLBAR_CaptureChanged(TOOLBAR_INFO
*infoPtr
)
5726 TBUTTON_INFO
*btnPtr
;
5728 infoPtr
->bCaptured
= FALSE
;
5730 if (infoPtr
->nButtonDown
>= 0)
5732 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5733 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5735 infoPtr
->nOldHit
= -1;
5737 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5738 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5744 TOOLBAR_MouseLeave (TOOLBAR_INFO
*infoPtr
)
5746 /* don't remove hot effects when in anchor highlighting mode or when a
5747 * drop-down button is pressed */
5748 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
5750 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
5751 if (!hotBtnPtr
->bDropDownPressed
)
5752 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
5755 if (infoPtr
->nOldHit
< 0)
5758 /* If the last button we were over is depressed then make it not */
5759 /* depressed and redraw it */
5760 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
5762 TBUTTON_INFO
*btnPtr
;
5765 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5767 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5770 InflateRect (&rc1
, 1, 1);
5771 InvalidateRect (infoPtr
->hwndSelf
, &rc1
, TRUE
);
5774 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
5777 ZeroMemory(&nmt
, sizeof(nmt
));
5778 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5779 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5780 infoPtr
->bDragOutSent
= TRUE
;
5783 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
5789 TOOLBAR_MouseMove (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5792 TRACKMOUSEEVENT trackinfo
;
5794 TBUTTON_INFO
*btnPtr
;
5797 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
5798 TOOLBAR_TooltipCreateControl(infoPtr
);
5800 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
5801 /* fill in the TRACKMOUSEEVENT struct */
5802 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5803 trackinfo
.dwFlags
= TME_QUERY
;
5805 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5806 _TrackMouseEvent(&trackinfo
);
5808 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5809 if(trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
5810 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5811 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
5813 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5814 /* and can properly deactivate the hot toolbar button */
5815 _TrackMouseEvent(&trackinfo
);
5819 if (infoPtr
->hwndToolTip
)
5820 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, infoPtr
->hwndSelf
,
5821 WM_MOUSEMOVE
, wParam
, lParam
);
5823 pt
.x
= (short)LOWORD(lParam
);
5824 pt
.y
= (short)HIWORD(lParam
);
5826 nHit
= TOOLBAR_InternalHitTest (infoPtr
, &pt
, &button
);
5828 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
5829 && (!infoPtr
->bAnchor
|| button
))
5830 TOOLBAR_SetHotItemEx(infoPtr
, button
? nHit
: TOOLBAR_NOWHERE
, HICF_MOUSE
);
5832 if (infoPtr
->nOldHit
!= nHit
)
5834 if (infoPtr
->bCaptured
)
5836 if (!infoPtr
->bDragOutSent
)
5839 ZeroMemory(&nmt
, sizeof(nmt
));
5840 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5841 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5842 infoPtr
->bDragOutSent
= TRUE
;
5845 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5846 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
5847 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5848 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5850 else if (nHit
== infoPtr
->nButtonDown
) {
5851 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5852 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5854 infoPtr
->nOldHit
= nHit
;
5862 static inline LRESULT
5863 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5865 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5866 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
5868 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5872 static inline LRESULT
5873 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5875 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
5876 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
5878 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
5883 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
5885 TOOLBAR_INFO
*infoPtr
;
5888 /* allocate memory for info structure */
5889 infoPtr
= Alloc (sizeof(TOOLBAR_INFO
));
5890 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
5893 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
5895 infoPtr
->nWidth
= 0;
5897 /* initialize info structure */
5898 infoPtr
->nButtonWidth
= 23;
5899 infoPtr
->nButtonHeight
= 22;
5900 infoPtr
->nBitmapHeight
= 16;
5901 infoPtr
->nBitmapWidth
= 16;
5903 infoPtr
->nMaxTextRows
= 1;
5904 infoPtr
->cxMin
= -1;
5905 infoPtr
->cxMax
= -1;
5906 infoPtr
->nNumBitmaps
= 0;
5907 infoPtr
->nNumStrings
= 0;
5909 infoPtr
->bCaptured
= FALSE
;
5910 infoPtr
->nButtonDown
= -1;
5911 infoPtr
->nButtonDrag
= -1;
5912 infoPtr
->nOldHit
= -1;
5913 infoPtr
->nHotItem
= -1;
5914 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
5915 infoPtr
->dwDTFlags
= (lpcs
->style
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
5916 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
5917 infoPtr
->bDragOutSent
= FALSE
;
5918 infoPtr
->iVersion
= 0;
5919 infoPtr
->hwndSelf
= hwnd
;
5920 infoPtr
->bDoRedraw
= TRUE
;
5921 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
5922 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
5923 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
5924 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
5925 infoPtr
->iListGap
= DEFLISTGAP
;
5926 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
5927 infoPtr
->dwStyle
= lpcs
->style
;
5928 infoPtr
->tbim
.iButton
= -1;
5930 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5931 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
5932 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
5933 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
5936 /* I think the code below is a bug, but it is the way that the native
5937 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5938 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5939 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5940 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5941 * Somehow, the only cases of this seem to be MFC programs.
5943 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5944 * does not occur in the WM_STYLECHANGING routine.
5945 * (Guy Albertelli 9/2001)
5948 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
5949 && !(lpcs
->style
& TBSTYLE_TRANSPARENT
))
5950 styleadd
|= TBSTYLE_TRANSPARENT
;
5951 if (!(lpcs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
5952 styleadd
|= CCS_TOP
; /* default to top */
5953 SetWindowLongW (hwnd
, GWL_STYLE
, lpcs
->style
| styleadd
);
5956 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
5961 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5963 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5967 if (dwStyle
& WS_MINIMIZE
)
5968 return 0; /* Nothing to do */
5970 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
5972 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
5975 if (!(dwStyle
& CCS_NODIVIDER
))
5977 GetWindowRect (hwnd
, &rcWindow
);
5978 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
5979 if( dwStyle
& WS_BORDER
)
5980 InflateRect (&rcWindow
, -1, -1);
5981 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
5984 ReleaseDC( hwnd
, hdc
);
5990 /* handles requests from the tooltip control on what text to display */
5991 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
5993 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
5995 TRACE("button index = %d\n", index
);
5997 Free (infoPtr
->pszTooltipText
);
5998 infoPtr
->pszTooltipText
= NULL
;
6003 if (infoPtr
->bUnicode
)
6005 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6006 NMTBGETINFOTIPW tbgit
;
6007 unsigned int len
; /* in chars */
6009 wszBuffer
[0] = '\0';
6010 wszBuffer
[INFOTIPSIZE
] = '\0';
6012 tbgit
.pszText
= wszBuffer
;
6013 tbgit
.cchTextMax
= INFOTIPSIZE
;
6014 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6015 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6017 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6019 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6021 len
= strlenW(tbgit
.pszText
);
6022 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6024 /* need to allocate temporary buffer in infoPtr as there
6025 * isn't enough space in buffer passed to us by the
6026 * tooltip control */
6027 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6028 if (infoPtr
->pszTooltipText
)
6030 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6031 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6037 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6043 CHAR szBuffer
[INFOTIPSIZE
+1];
6044 NMTBGETINFOTIPA tbgit
;
6045 unsigned int len
; /* in chars */
6048 szBuffer
[INFOTIPSIZE
] = '\0';
6050 tbgit
.pszText
= szBuffer
;
6051 tbgit
.cchTextMax
= INFOTIPSIZE
;
6052 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6053 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6055 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6057 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6059 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6060 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]))
6062 /* need to allocate temporary buffer in infoPtr as there
6063 * isn't enough space in buffer passed to us by the
6064 * tooltip control */
6065 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6066 if (infoPtr
->pszTooltipText
)
6068 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6069 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6073 else if (tbgit
.pszText
&& tbgit
.pszText
[0])
6075 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1,
6076 lpnmtdi
->lpszText
, sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]));
6081 /* if button has text, but it is not shown then automatically
6082 * use that text as tooltip */
6083 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6084 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6086 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6087 unsigned int len
= pszText
? strlenW(pszText
) : 0;
6089 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6091 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6093 /* need to allocate temporary buffer in infoPtr as there
6094 * isn't enough space in buffer passed to us by the
6095 * tooltip control */
6096 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6097 if (infoPtr
->pszTooltipText
)
6099 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6100 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6106 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6111 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6113 /* last resort: send notification on to app */
6114 /* FIXME: find out what is really used here */
6115 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmtdi
->hdr
.idFrom
, (LPARAM
)lpnmtdi
);
6119 static inline LRESULT
6120 TOOLBAR_Notify (TOOLBAR_INFO
*infoPtr
, LPNMHDR lpnmh
)
6122 switch (lpnmh
->code
)
6126 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lpnmh
;
6128 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6129 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6130 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6134 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6135 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6143 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lpnmh
;
6145 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6146 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6147 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6148 lppgs
->iScroll
, lppgs
->iDir
);
6152 case TTN_GETDISPINFOW
:
6153 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lpnmh
);
6155 case TTN_GETDISPINFOA
:
6156 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6166 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6170 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam
, lParam
);
6172 if (lParam
== NF_QUERY
)
6175 if (lParam
== NF_REQUERY
) {
6176 format
= SendMessageW(infoPtr
->hwndNotify
,
6177 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6178 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6179 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6190 TOOLBAR_Paint (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6195 /* fill ps.rcPaint with a default rect */
6196 ps
.rcPaint
= infoPtr
->rcBound
;
6198 hdc
= wParam
==0 ? BeginPaint(infoPtr
->hwndSelf
, &ps
) : (HDC
)wParam
;
6200 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps
.rcPaint
));
6202 TOOLBAR_Refresh (infoPtr
, hdc
, &ps
);
6203 if (!wParam
) EndPaint (infoPtr
->hwndSelf
, &ps
);
6210 TOOLBAR_SetFocus (TOOLBAR_INFO
*infoPtr
)
6212 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6214 /* make first item hot */
6215 if (infoPtr
->nNumButtons
> 0)
6216 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6222 TOOLBAR_SetFont(TOOLBAR_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
6224 TRACE("font=%p redraw=%d\n", hFont
, Redraw
);
6227 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6229 infoPtr
->hFont
= hFont
;
6231 TOOLBAR_CalcToolbar(infoPtr
);
6234 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6239 TOOLBAR_SetRedraw (TOOLBAR_INFO
*infoPtr
, WPARAM wParam
)
6240 /*****************************************************
6243 * Handles the WM_SETREDRAW message.
6246 * According to testing V4.71 of COMCTL32 returns the
6247 * *previous* status of the redraw flag (either 0 or 1)
6248 * instead of the MSDN documented value of 0 if handled.
6249 * (For laughs see the "consistency" with same function
6252 *****************************************************/
6254 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6256 TRACE("set to %s\n",
6257 (wParam
) ? "TRUE" : "FALSE");
6258 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6260 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6262 return (oldredraw
) ? 1 : 0;
6267 TOOLBAR_Size (TOOLBAR_INFO
*infoPtr
)
6269 TRACE("sizing toolbar!\n");
6271 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6273 RECT delta_width
, delta_height
, client
, dummy
;
6274 DWORD min_x
, max_x
, min_y
, max_y
;
6275 TBUTTON_INFO
*btnPtr
;
6278 GetClientRect(infoPtr
->hwndSelf
, &client
);
6279 if(client
.right
> infoPtr
->client_rect
.right
)
6281 min_x
= infoPtr
->client_rect
.right
;
6282 max_x
= client
.right
;
6286 max_x
= infoPtr
->client_rect
.right
;
6287 min_x
= client
.right
;
6289 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6291 min_y
= infoPtr
->client_rect
.bottom
;
6292 max_y
= client
.bottom
;
6296 max_y
= infoPtr
->client_rect
.bottom
;
6297 min_y
= client
.bottom
;
6300 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6301 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6303 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6304 btnPtr
= infoPtr
->buttons
;
6305 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6306 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6307 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6308 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
6310 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->client_rect
);
6311 TOOLBAR_AutoSize(infoPtr
);
6317 TOOLBAR_StyleChanged (TOOLBAR_INFO
*infoPtr
, INT nType
, const STYLESTRUCT
*lpStyle
)
6319 if (nType
== GWL_STYLE
)
6321 DWORD dwOldStyle
= infoPtr
->dwStyle
;
6323 if (lpStyle
->styleNew
& TBSTYLE_LIST
)
6324 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
6326 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
6328 TRACE("new style 0x%08x\n", lpStyle
->styleNew
);
6330 infoPtr
->dwStyle
= lpStyle
->styleNew
;
6331 TOOLBAR_CheckStyle (infoPtr
);
6333 if ((dwOldStyle
^ lpStyle
->styleNew
) & (TBSTYLE_WRAPABLE
| CCS_VERT
))
6334 TOOLBAR_LayoutToolbar(infoPtr
);
6336 /* only resize if one of the CCS_* styles was changed */
6337 if ((dwOldStyle
^ lpStyle
->styleNew
) & COMMON_STYLES
)
6339 TOOLBAR_AutoSize (infoPtr
);
6341 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
6350 TOOLBAR_SysColorChange (void)
6352 COMCTL32_RefreshSysColors();
6358 /* update theme after a WM_THEMECHANGED message */
6359 static LRESULT
theme_changed (HWND hwnd
)
6361 HTHEME theme
= GetWindowTheme (hwnd
);
6362 CloseThemeData (theme
);
6363 OpenThemeData (hwnd
, themeClass
);
6368 static LRESULT WINAPI
6369 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6371 TOOLBAR_INFO
*infoPtr
= (TOOLBAR_INFO
*)GetWindowLongPtrW(hwnd
, 0);
6373 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6374 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6376 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6377 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6382 return TOOLBAR_AddBitmap (infoPtr
, (INT
)wParam
, (TBADDBITMAP
*)lParam
);
6384 case TB_ADDBUTTONSA
:
6385 case TB_ADDBUTTONSW
:
6386 return TOOLBAR_AddButtonsT (infoPtr
, wParam
, (LPTBBUTTON
)lParam
,
6387 uMsg
== TB_ADDBUTTONSW
);
6389 return TOOLBAR_AddStringA (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6392 return TOOLBAR_AddStringW (infoPtr
, (HINSTANCE
)wParam
, lParam
);
6395 return TOOLBAR_AutoSize (infoPtr
);
6397 case TB_BUTTONCOUNT
:
6398 return TOOLBAR_ButtonCount (infoPtr
);
6400 case TB_BUTTONSTRUCTSIZE
:
6401 return TOOLBAR_ButtonStructSize (infoPtr
, wParam
);
6403 case TB_CHANGEBITMAP
:
6404 return TOOLBAR_ChangeBitmap (infoPtr
, wParam
, LOWORD(lParam
));
6406 case TB_CHECKBUTTON
:
6407 return TOOLBAR_CheckButton (infoPtr
, wParam
, lParam
);
6409 case TB_COMMANDTOINDEX
:
6410 return TOOLBAR_CommandToIndex (infoPtr
, wParam
);
6413 return TOOLBAR_Customize (infoPtr
);
6415 case TB_DELETEBUTTON
:
6416 return TOOLBAR_DeleteButton (infoPtr
, wParam
);
6418 case TB_ENABLEBUTTON
:
6419 return TOOLBAR_EnableButton (infoPtr
, wParam
, lParam
);
6421 case TB_GETANCHORHIGHLIGHT
:
6422 return TOOLBAR_GetAnchorHighlight (infoPtr
);
6425 return TOOLBAR_GetBitmap (infoPtr
, wParam
);
6427 case TB_GETBITMAPFLAGS
:
6428 return TOOLBAR_GetBitmapFlags ();
6431 return TOOLBAR_GetButton (infoPtr
, wParam
, (TBBUTTON
*)lParam
);
6433 case TB_GETBUTTONINFOA
:
6434 case TB_GETBUTTONINFOW
:
6435 return TOOLBAR_GetButtonInfoT (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6436 uMsg
== TB_GETBUTTONINFOW
);
6437 case TB_GETBUTTONSIZE
:
6438 return TOOLBAR_GetButtonSize (infoPtr
);
6440 case TB_GETBUTTONTEXTA
:
6441 case TB_GETBUTTONTEXTW
:
6442 return TOOLBAR_GetButtonText (infoPtr
, wParam
, (LPWSTR
)lParam
,
6443 uMsg
== TB_GETBUTTONTEXTW
);
6445 case TB_GETDISABLEDIMAGELIST
:
6446 return TOOLBAR_GetDisabledImageList (infoPtr
, wParam
);
6448 case TB_GETEXTENDEDSTYLE
:
6449 return TOOLBAR_GetExtendedStyle (infoPtr
);
6451 case TB_GETHOTIMAGELIST
:
6452 return TOOLBAR_GetHotImageList (infoPtr
, wParam
);
6455 return TOOLBAR_GetHotItem (infoPtr
);
6457 case TB_GETIMAGELIST
:
6458 return TOOLBAR_GetDefImageList (infoPtr
, wParam
);
6460 case TB_GETINSERTMARK
:
6461 return TOOLBAR_GetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6463 case TB_GETINSERTMARKCOLOR
:
6464 return TOOLBAR_GetInsertMarkColor (infoPtr
);
6466 case TB_GETITEMRECT
:
6467 return TOOLBAR_GetItemRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6470 return TOOLBAR_GetMaxSize (infoPtr
, (LPSIZE
)lParam
);
6472 /* case TB_GETOBJECT: */ /* 4.71 */
6475 return TOOLBAR_GetPadding (infoPtr
);
6478 return TOOLBAR_GetRect (infoPtr
, wParam
, (LPRECT
)lParam
);
6481 return TOOLBAR_GetRows (infoPtr
);
6484 return TOOLBAR_GetState (infoPtr
, wParam
);
6487 return TOOLBAR_GetStringA (infoPtr
, wParam
, (LPSTR
)lParam
);
6490 return TOOLBAR_GetStringW (infoPtr
, wParam
, (LPWSTR
)lParam
);
6493 return TOOLBAR_GetStyle (infoPtr
);
6495 case TB_GETTEXTROWS
:
6496 return TOOLBAR_GetTextRows (infoPtr
);
6498 case TB_GETTOOLTIPS
:
6499 return TOOLBAR_GetToolTips (infoPtr
);
6501 case TB_GETUNICODEFORMAT
:
6502 return TOOLBAR_GetUnicodeFormat (infoPtr
);
6505 return TOOLBAR_HideButton (infoPtr
, wParam
, LOWORD(lParam
));
6508 return TOOLBAR_HitTest (infoPtr
, (LPPOINT
)lParam
);
6510 case TB_INDETERMINATE
:
6511 return TOOLBAR_Indeterminate (infoPtr
, wParam
, LOWORD(lParam
));
6513 case TB_INSERTBUTTONA
:
6514 case TB_INSERTBUTTONW
:
6515 return TOOLBAR_InsertButtonT(infoPtr
, wParam
, (TBBUTTON
*)lParam
,
6516 uMsg
== TB_INSERTBUTTONW
);
6518 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6520 case TB_ISBUTTONCHECKED
:
6521 return TOOLBAR_IsButtonChecked (infoPtr
, wParam
);
6523 case TB_ISBUTTONENABLED
:
6524 return TOOLBAR_IsButtonEnabled (infoPtr
, wParam
);
6526 case TB_ISBUTTONHIDDEN
:
6527 return TOOLBAR_IsButtonHidden (infoPtr
, wParam
);
6529 case TB_ISBUTTONHIGHLIGHTED
:
6530 return TOOLBAR_IsButtonHighlighted (infoPtr
, wParam
);
6532 case TB_ISBUTTONINDETERMINATE
:
6533 return TOOLBAR_IsButtonIndeterminate (infoPtr
, wParam
);
6535 case TB_ISBUTTONPRESSED
:
6536 return TOOLBAR_IsButtonPressed (infoPtr
, wParam
);
6539 return TOOLBAR_LoadImages (infoPtr
, wParam
, (HINSTANCE
)lParam
);
6541 case TB_MAPACCELERATORA
:
6542 case TB_MAPACCELERATORW
:
6543 return TOOLBAR_MapAccelerator (infoPtr
, wParam
, (UINT
*)lParam
);
6546 return TOOLBAR_MarkButton (infoPtr
, wParam
, LOWORD(lParam
));
6549 return TOOLBAR_MoveButton (infoPtr
, wParam
, lParam
);
6551 case TB_PRESSBUTTON
:
6552 return TOOLBAR_PressButton (infoPtr
, wParam
, LOWORD(lParam
));
6554 case TB_REPLACEBITMAP
:
6555 return TOOLBAR_ReplaceBitmap (infoPtr
, (LPTBREPLACEBITMAP
)lParam
);
6557 case TB_SAVERESTOREA
:
6558 return TOOLBAR_SaveRestoreA (infoPtr
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6560 case TB_SAVERESTOREW
:
6561 return TOOLBAR_SaveRestoreW (infoPtr
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6563 case TB_SETANCHORHIGHLIGHT
:
6564 return TOOLBAR_SetAnchorHighlight (infoPtr
, (BOOL
)wParam
);
6566 case TB_SETBITMAPSIZE
:
6567 return TOOLBAR_SetBitmapSize (infoPtr
, wParam
, lParam
);
6569 case TB_SETBUTTONINFOA
:
6570 case TB_SETBUTTONINFOW
:
6571 return TOOLBAR_SetButtonInfo (infoPtr
, wParam
, (LPTBBUTTONINFOW
)lParam
,
6572 uMsg
== TB_SETBUTTONINFOW
);
6573 case TB_SETBUTTONSIZE
:
6574 return TOOLBAR_SetButtonSize (infoPtr
, lParam
);
6576 case TB_SETBUTTONWIDTH
:
6577 return TOOLBAR_SetButtonWidth (infoPtr
, lParam
);
6580 return TOOLBAR_SetCmdId (infoPtr
, wParam
, lParam
);
6582 case TB_SETDISABLEDIMAGELIST
:
6583 return TOOLBAR_SetDisabledImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6585 case TB_SETDRAWTEXTFLAGS
:
6586 return TOOLBAR_SetDrawTextFlags (infoPtr
, wParam
, lParam
);
6588 case TB_SETEXTENDEDSTYLE
:
6589 return TOOLBAR_SetExtendedStyle (infoPtr
, wParam
, lParam
);
6591 case TB_SETHOTIMAGELIST
:
6592 return TOOLBAR_SetHotImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6595 return TOOLBAR_SetHotItem (infoPtr
, wParam
);
6597 case TB_SETIMAGELIST
:
6598 return TOOLBAR_SetImageList (infoPtr
, wParam
, (HIMAGELIST
)lParam
);
6601 return TOOLBAR_SetIndent (infoPtr
, wParam
);
6603 case TB_SETINSERTMARK
:
6604 return TOOLBAR_SetInsertMark (infoPtr
, (TBINSERTMARK
*)lParam
);
6606 case TB_SETINSERTMARKCOLOR
:
6607 return TOOLBAR_SetInsertMarkColor (infoPtr
, lParam
);
6609 case TB_SETMAXTEXTROWS
:
6610 return TOOLBAR_SetMaxTextRows (infoPtr
, wParam
);
6613 return TOOLBAR_SetPadding (infoPtr
, lParam
);
6616 return TOOLBAR_SetParent (infoPtr
, (HWND
)wParam
);
6619 return TOOLBAR_SetRows (infoPtr
, wParam
, (LPRECT
)lParam
);
6622 return TOOLBAR_SetState (infoPtr
, wParam
, lParam
);
6625 return TOOLBAR_SetStyle (infoPtr
, lParam
);
6627 case TB_SETTOOLTIPS
:
6628 return TOOLBAR_SetToolTips (infoPtr
, (HWND
)wParam
);
6630 case TB_SETUNICODEFORMAT
:
6631 return TOOLBAR_SetUnicodeFormat (infoPtr
, wParam
);
6634 return TOOLBAR_Unkwn45D(hwnd
, wParam
, lParam
);
6636 case TB_SETHOTITEM2
:
6637 return TOOLBAR_SetHotItem2 (infoPtr
, wParam
, lParam
);
6640 return TOOLBAR_SetListGap(infoPtr
, wParam
);
6642 case TB_GETIMAGELISTCOUNT
:
6643 return TOOLBAR_GetImageListCount(infoPtr
);
6645 case TB_GETIDEALSIZE
:
6646 return TOOLBAR_GetIdealSize (infoPtr
, wParam
, lParam
);
6649 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6651 /* Common Control Messages */
6653 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6654 case CCM_GETCOLORSCHEME
:
6655 return TOOLBAR_GetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6657 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6658 case CCM_SETCOLORSCHEME
:
6659 return TOOLBAR_SetColorScheme (infoPtr
, (LPCOLORSCHEME
)lParam
);
6661 case CCM_GETVERSION
:
6662 return TOOLBAR_GetVersion (infoPtr
);
6664 case CCM_SETVERSION
:
6665 return TOOLBAR_SetVersion (infoPtr
, (INT
)wParam
);
6671 return TOOLBAR_Create (hwnd
, (CREATESTRUCTW
*)lParam
);
6674 return TOOLBAR_Destroy (infoPtr
);
6677 return TOOLBAR_EraseBackground (infoPtr
, wParam
, lParam
);
6680 return TOOLBAR_GetFont (infoPtr
);
6683 return TOOLBAR_KeyDown (infoPtr
, wParam
, lParam
);
6685 /* case WM_KILLFOCUS: */
6687 case WM_LBUTTONDBLCLK
:
6688 return TOOLBAR_LButtonDblClk (infoPtr
, wParam
, lParam
);
6690 case WM_LBUTTONDOWN
:
6691 return TOOLBAR_LButtonDown (infoPtr
, wParam
, lParam
);
6694 return TOOLBAR_LButtonUp (infoPtr
, wParam
, lParam
);
6697 return TOOLBAR_RButtonUp (infoPtr
, wParam
, lParam
);
6699 case WM_RBUTTONDBLCLK
:
6700 return TOOLBAR_RButtonDblClk (infoPtr
, wParam
, lParam
);
6703 return TOOLBAR_MouseMove (infoPtr
, wParam
, lParam
);
6706 return TOOLBAR_MouseLeave (infoPtr
);
6708 case WM_CAPTURECHANGED
:
6709 return TOOLBAR_CaptureChanged(infoPtr
);
6712 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6715 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6718 return TOOLBAR_NCCreate (hwnd
, wParam
, (CREATESTRUCTW
*)lParam
);
6721 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
6724 return TOOLBAR_Notify (infoPtr
, (LPNMHDR
)lParam
);
6726 case WM_NOTIFYFORMAT
:
6727 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
6729 case WM_PRINTCLIENT
:
6731 return TOOLBAR_Paint (infoPtr
, wParam
);
6734 return TOOLBAR_SetFocus (infoPtr
);
6737 return TOOLBAR_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
6740 return TOOLBAR_SetRedraw (infoPtr
, wParam
);
6743 return TOOLBAR_Size (infoPtr
);
6745 case WM_STYLECHANGED
:
6746 return TOOLBAR_StyleChanged (infoPtr
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
6748 case WM_SYSCOLORCHANGE
:
6749 return TOOLBAR_SysColorChange ();
6751 case WM_THEMECHANGED
:
6752 return theme_changed (hwnd
);
6754 /* case WM_WININICHANGE: */
6759 case WM_MEASUREITEM
:
6761 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
6763 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6764 case PGM_FORWARDMOUSE
:
6765 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6768 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
6769 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
6770 uMsg
, wParam
, lParam
);
6771 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6777 TOOLBAR_Register (void)
6781 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
6782 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
6783 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
6784 wndClass
.cbClsExtra
= 0;
6785 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
6786 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
6787 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
6788 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
6790 RegisterClassW (&wndClass
);
6795 TOOLBAR_Unregister (void)
6797 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
6800 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
6805 /* Check if the entry already exists */
6806 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
6808 /* If this is a new entry we must create it and insert into the array */
6813 c
= Alloc(sizeof(IMLENTRY
));
6816 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
6817 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
6832 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
6836 for (i
= 0; i
< *cies
; i
++)
6846 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
6854 for (i
= 0; i
< cies
; i
++)
6856 if (pies
[i
]->id
== id
)
6868 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
6870 HIMAGELIST himlDef
= 0;
6871 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
6874 himlDef
= pie
->himl
;
6880 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
6882 if (infoPtr
->bUnicode
)
6883 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
6890 nmtba
.iItem
= nmtb
->iItem
;
6891 nmtba
.pszText
= Buffer
;
6892 nmtba
.cchText
= 256;
6893 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
6895 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
6897 int ccht
= strlen(nmtba
.pszText
);
6899 MultiByteToWideChar(CP_ACP
, 0, nmtba
.pszText
, -1,
6900 nmtb
->pszText
, nmtb
->cchText
);
6902 nmtb
->tbButton
= nmtba
.tbButton
;
6911 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, const CUSTOMBUTTON
*btnInfo
)
6915 /* MSDN states that iItem is the index of the button, rather than the
6916 * command ID as used by every other NMTOOLBAR notification */
6918 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
6920 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);