4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
38 * - TB_INSERTMARKHITTEST
46 * - Button wrapping (under construction).
47 * - Fix TB_SETROWS and Separators.
48 * - iListGap custom draw support.
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
79 #include "wine/unicode.h"
85 #include "wine/debug.h"
87 WINE_DEFAULT_DEBUG_CHANNEL(toolbar
);
89 static HCURSOR hCursorDrag
= NULL
;
98 BYTE bDropDownPressed
;
103 INT cx
; /* manually set size */
117 } IMLENTRY
, *PIMLENTRY
;
121 DWORD dwStructSize
; /* size of TBBUTTON struct */
122 INT nWidth
; /* width of the toolbar */
124 RECT rcBound
; /* bounding rectangle */
130 INT nRows
; /* number of button rows */
131 INT nMaxTextRows
; /* maximum number of text rows */
132 INT cxMin
; /* minimum button width */
133 INT cxMax
; /* maximum button width */
134 INT nNumButtons
; /* number of buttons */
135 INT nNumBitmaps
; /* number of bitmaps */
136 INT nNumStrings
; /* number of strings */
138 INT nButtonDown
; /* toolbar button being pressed or -1 if none */
139 INT nButtonDrag
; /* toolbar button being dragged or -1 if none */
141 INT nHotItem
; /* index of the "hot" item */
142 SIZE szPadding
; /* padding values around button */
143 INT iTopMargin
; /* the top margin */
144 INT iListGap
; /* default gap between text and image for toolbar with list style */
146 HFONT hFont
; /* text font */
147 HIMAGELIST himlInt
; /* image list created internally */
148 PIMLENTRY
*himlDef
; /* default image list array */
149 INT cimlDef
; /* default image list array count */
150 PIMLENTRY
*himlHot
; /* hot image list array */
151 INT cimlHot
; /* hot image list array count */
152 PIMLENTRY
*himlDis
; /* disabled image list array */
153 INT cimlDis
; /* disabled image list array count */
154 HWND hwndToolTip
; /* handle to tool tip control */
155 HWND hwndNotify
; /* handle to the window that gets notifications */
156 HWND hwndSelf
; /* my own handle */
157 BOOL bAnchor
; /* anchor highlight enabled */
158 BOOL bDoRedraw
; /* Redraw status */
159 BOOL bDragOutSent
; /* has TBN_DRAGOUT notification been sent for this drag? */
160 BOOL bUnicode
; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
161 BOOL bCaptured
; /* mouse captured? */
162 DWORD dwStyle
; /* regular toolbar style */
163 DWORD dwExStyle
; /* extended toolbar style */
164 DWORD dwDTFlags
; /* DrawText flags */
166 COLORREF clrInsertMark
; /* insert mark color */
167 COLORREF clrBtnHighlight
; /* color for Flat Separator */
168 COLORREF clrBtnShadow
; /* color for Flag Separator */
170 LPWSTR pszTooltipText
; /* temporary store for a string > 80 characters
171 * for TTN_GETDISPINFOW notification */
172 TBINSERTMARK tbim
; /* info on insertion mark */
173 TBUTTON_INFO
*buttons
; /* pointer to button array */
174 LPWSTR
*strings
; /* pointer to string array */
175 TBITMAP_INFO
*bitmaps
;
176 } TOOLBAR_INFO
, *PTOOLBAR_INFO
;
179 /* used by customization dialog */
182 PTOOLBAR_INFO tbInfo
;
184 } CUSTDLG_INFO
, *PCUSTDLG_INFO
;
192 } CUSTOMBUTTON
, *PCUSTOMBUTTON
;
201 #define SEPARATOR_WIDTH 8
203 #define BOTTOM_BORDER 2
204 #define DDARROW_WIDTH 11
205 #define ARROW_HEIGHT 3
206 #define INSERTMARK_WIDTH 2
212 /* vertical padding used in list mode when image is present */
215 /* how wide to treat the bitmap if it isn't present */
216 #define NONLIST_NOTEXT_OFFSET 2
218 #define TOOLBAR_NOWHERE (-1)
220 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
221 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
222 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
224 /* Used to find undocumented extended styles */
225 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
226 TBSTYLE_EX_UNDOC1 | \
227 TBSTYLE_EX_MIXEDBUTTONS | \
228 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
230 /* all of the CCS_ styles */
231 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
232 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
234 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
235 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
236 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
237 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
238 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
240 static const WCHAR themeClass
[] = { 'T','o','o','l','b','a','r',0 };
242 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
);
243 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, PCUSTOMBUTTON btnInfo
);
244 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
);
245 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
);
246 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
);
247 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
);
248 static LRESULT
TOOLBAR_LButtonDown(HWND hwnd
, WPARAM wParam
, LPARAM lParam
);
249 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
);
250 static void TOOLBAR_LayoutToolbar(HWND hwnd
);
251 static LRESULT
TOOLBAR_AutoSize(HWND hwnd
);
252 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
);
253 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
256 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
);
258 static inline int default_top_margin(const TOOLBAR_INFO
*infoPtr
)
260 return (infoPtr
->dwStyle
& TBSTYLE_FLAT
? 0 : TOP_BORDER
);
264 TOOLBAR_GetText(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
266 LPWSTR lpText
= NULL
;
268 /* NOTE: iString == -1 is undocumented */
269 if ((HIWORD(btnPtr
->iString
) != 0) && (btnPtr
->iString
!= -1))
270 lpText
= (LPWSTR
)btnPtr
->iString
;
271 else if ((btnPtr
->iString
>= 0) && (btnPtr
->iString
< infoPtr
->nNumStrings
))
272 lpText
= infoPtr
->strings
[btnPtr
->iString
];
278 TOOLBAR_DumpButton(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*bP
, INT btn_num
, BOOL internal
)
280 if (TRACE_ON(toolbar
)){
281 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
282 btn_num
, bP
->idCommand
, GETIBITMAP(infoPtr
, bP
->iBitmap
),
283 bP
->fsState
, bP
->fsStyle
, bP
->dwData
, bP
->iString
);
284 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr
,bP
)));
286 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n",
287 btn_num
, bP
->idCommand
,
288 (bP
->bHot
) ? "TRUE":"FALSE", bP
->nRow
,
289 wine_dbgstr_rect(&bP
->rect
));
295 TOOLBAR_DumpToolbar(const TOOLBAR_INFO
*iP
, INT line
)
297 if (TRACE_ON(toolbar
)) {
300 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
302 iP
->dwExStyle
, iP
->nNumButtons
, iP
->nNumBitmaps
,
303 iP
->nNumStrings
, iP
->dwStyle
);
304 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
306 iP
->himlInt
, iP
->himlDef
, iP
->himlHot
, iP
->himlDis
,
307 (iP
->bDoRedraw
) ? "TRUE" : "FALSE");
308 for(i
=0; i
<iP
->nNumButtons
; i
++) {
309 TOOLBAR_DumpButton(iP
, &iP
->buttons
[i
], i
, TRUE
);
315 /***********************************************************************
318 * This function validates that the styles set are implemented and
319 * issues FIXME's warning of possible problems. In a perfect world this
320 * function should be null.
323 TOOLBAR_CheckStyle (HWND hwnd
, DWORD dwStyle
)
325 if (dwStyle
& TBSTYLE_REGISTERDROP
)
326 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd
);
331 TOOLBAR_SendNotify (NMHDR
*nmhdr
, const TOOLBAR_INFO
*infoPtr
, UINT code
)
333 if(!IsWindow(infoPtr
->hwndSelf
))
334 return 0; /* we have just been destroyed */
336 nmhdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
337 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
340 TRACE("to window %p, code=%08x, %s\n", infoPtr
->hwndNotify
, code
,
341 (infoPtr
->bUnicode
) ? "via Unicode" : "via ANSI");
343 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhdr
->idFrom
, (LPARAM
)nmhdr
);
346 /***********************************************************************
347 * TOOLBAR_GetBitmapIndex
349 * This function returns the bitmap index associated with a button.
350 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
351 * is issued to retrieve the index.
354 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
356 INT ret
= btnPtr
->iBitmap
;
358 if (ret
== I_IMAGECALLBACK
)
360 /* issue TBN_GETDISPINFO */
363 memset(&nmgd
, 0, sizeof(nmgd
));
364 nmgd
.idCommand
= btnPtr
->idCommand
;
365 nmgd
.lParam
= btnPtr
->dwData
;
366 nmgd
.dwMask
= TBNF_IMAGE
;
368 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
369 TOOLBAR_SendNotify(&nmgd
.hdr
, infoPtr
, TBN_GETDISPINFOW
);
370 if (nmgd
.dwMask
& TBNF_DI_SETITEM
)
371 btnPtr
->iBitmap
= nmgd
.iImage
;
373 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
374 ret
, nmgd
.dwMask
, infoPtr
->nNumBitmaps
);
377 if (ret
!= I_IMAGENONE
)
378 ret
= GETIBITMAP(infoPtr
, ret
);
385 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO
*infoPtr
, INT index
)
388 INT id
= GETHIMLID(infoPtr
, index
);
389 INT iBitmap
= GETIBITMAP(infoPtr
, index
);
391 if (((himl
= GETDEFIMAGELIST(infoPtr
, id
)) &&
392 iBitmap
>= 0 && iBitmap
< ImageList_GetImageCount(himl
)) ||
393 (index
== I_IMAGECALLBACK
))
401 TOOLBAR_IsValidImageList(const TOOLBAR_INFO
*infoPtr
, INT index
)
403 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, index
));
404 return (himl
!= NULL
) && (ImageList_GetImageCount(himl
) > 0);
408 /***********************************************************************
409 * TOOLBAR_GetImageListForDrawing
411 * This function validates the bitmap index (including I_IMAGECALLBACK
412 * functionality) and returns the corresponding image list.
415 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
,
416 IMAGE_LIST_TYPE imagelist
, INT
* index
)
420 if (!TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
)) {
421 if (btnPtr
->iBitmap
== I_IMAGENONE
) return NULL
;
422 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
423 HIWORD(btnPtr
->iBitmap
), LOWORD(btnPtr
->iBitmap
), infoPtr
->nNumBitmaps
);
427 if ((*index
= TOOLBAR_GetBitmapIndex(infoPtr
, btnPtr
)) < 0) {
428 if ((*index
== I_IMAGECALLBACK
) ||
429 (*index
== I_IMAGENONE
)) return NULL
;
430 ERR("TBN_GETDISPINFO returned invalid index %d\n",
437 case IMAGE_LIST_DEFAULT
:
438 himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
441 himl
= GETHOTIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
443 case IMAGE_LIST_DISABLED
:
444 himl
= GETDISIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
448 FIXME("Shouldn't reach here\n");
452 TRACE("no image list\n");
459 TOOLBAR_DrawFlatSeparator (const RECT
*lpRect
, HDC hdc
, const TOOLBAR_INFO
*infoPtr
)
462 COLORREF oldcolor
, newcolor
;
464 myrect
.left
= (lpRect
->left
+ lpRect
->right
) / 2 - 1;
465 myrect
.right
= myrect
.left
+ 1;
466 myrect
.top
= lpRect
->top
+ 2;
467 myrect
.bottom
= lpRect
->bottom
- 2;
469 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
470 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
471 oldcolor
= SetBkColor (hdc
, newcolor
);
472 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
474 myrect
.left
= myrect
.right
;
475 myrect
.right
= myrect
.left
+ 1;
477 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
478 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
479 SetBkColor (hdc
, newcolor
);
480 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
482 SetBkColor (hdc
, oldcolor
);
486 /***********************************************************************
487 * TOOLBAR_DrawDDFlatSeparator
489 * This function draws the separator that was flagged as BTNS_DROPDOWN.
490 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
491 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
492 * are horizontal as opposed to the vertical separators for not dropdown
495 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
498 TOOLBAR_DrawDDFlatSeparator (const RECT
*lpRect
, HDC hdc
, const TBUTTON_INFO
*btnPtr
,
499 const TOOLBAR_INFO
*infoPtr
)
502 COLORREF oldcolor
, newcolor
;
504 myrect
.left
= lpRect
->left
;
505 myrect
.right
= lpRect
->right
;
506 myrect
.top
= lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
- 2)/2;
507 myrect
.bottom
= myrect
.top
+ 1;
509 InflateRect (&myrect
, -2, 0);
511 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect
));
513 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
514 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
515 oldcolor
= SetBkColor (hdc
, newcolor
);
516 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
518 myrect
.top
= myrect
.bottom
;
519 myrect
.bottom
= myrect
.top
+ 1;
521 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
522 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
523 SetBkColor (hdc
, newcolor
);
524 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
526 SetBkColor (hdc
, oldcolor
);
531 TOOLBAR_DrawArrow (HDC hdc
, INT left
, INT top
, COLORREF clr
)
536 if (!(hPen
= CreatePen( PS_SOLID
, 1, clr
))) return;
537 hOldPen
= SelectObject ( hdc
, hPen
);
540 MoveToEx (hdc
, x
, y
, NULL
);
541 LineTo (hdc
, x
+5, y
++); x
++;
542 MoveToEx (hdc
, x
, y
, NULL
);
543 LineTo (hdc
, x
+3, y
++); x
++;
544 MoveToEx (hdc
, x
, y
, NULL
);
545 LineTo (hdc
, x
+1, y
++);
546 SelectObject( hdc
, hOldPen
);
547 DeleteObject( hPen
);
551 * Draw the text string for this button.
552 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
553 * is non-zero, so we can simply check himlDef to see if we have
557 TOOLBAR_DrawString (const TOOLBAR_INFO
*infoPtr
, RECT
*rcText
, LPCWSTR lpText
,
558 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
560 HDC hdc
= tbcd
->nmcd
.hdc
;
563 COLORREF clrOldBk
= 0;
565 UINT state
= tbcd
->nmcd
.uItemState
;
569 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText
),
570 wine_dbgstr_rect(rcText
));
572 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
573 if ((state
& CDIS_HOT
) && (dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)) {
574 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
576 else if (state
& CDIS_DISABLED
) {
577 clrOld
= SetTextColor (hdc
, tbcd
->clrBtnHighlight
);
578 OffsetRect (rcText
, 1, 1);
579 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
580 SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
581 OffsetRect (rcText
, -1, -1);
583 else if (state
& CDIS_INDETERMINATE
) {
584 clrOld
= SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
586 else if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
)) {
587 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
588 clrOldBk
= SetBkColor (hdc
, tbcd
->clrMark
);
589 oldBkMode
= SetBkMode (hdc
, tbcd
->nHLStringBkMode
);
592 clrOld
= SetTextColor (hdc
, tbcd
->clrText
);
595 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
596 SetTextColor (hdc
, clrOld
);
597 if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
))
599 SetBkColor (hdc
, clrOldBk
);
600 SetBkMode (hdc
, oldBkMode
);
602 SelectObject (hdc
, hOldFont
);
608 TOOLBAR_DrawPattern (const RECT
*lpRect
, const NMTBCUSTOMDRAW
*tbcd
)
610 HDC hdc
= tbcd
->nmcd
.hdc
;
611 HBRUSH hbr
= SelectObject (hdc
, tbcd
->hbrMonoDither
);
614 INT cx
= lpRect
->right
- lpRect
->left
;
615 INT cy
= lpRect
->bottom
- lpRect
->top
;
616 INT cxEdge
= GetSystemMetrics(SM_CXEDGE
);
617 INT cyEdge
= GetSystemMetrics(SM_CYEDGE
);
618 clrTextOld
= SetTextColor(hdc
, tbcd
->clrBtnHighlight
);
619 clrBkOld
= SetBkColor(hdc
, tbcd
->clrBtnFace
);
620 PatBlt (hdc
, lpRect
->left
+ cxEdge
, lpRect
->top
+ cyEdge
,
621 cx
- (2 * cxEdge
), cy
- (2 * cyEdge
), PATCOPY
);
622 SetBkColor(hdc
, clrBkOld
);
623 SetTextColor(hdc
, clrTextOld
);
624 SelectObject (hdc
, hbr
);
628 static void TOOLBAR_DrawMasked(HIMAGELIST himl
, int index
, HDC hdc
, INT x
, INT y
, UINT draw_flags
)
631 HBITMAP hbmMask
, hbmImage
;
632 HDC hdcMask
, hdcImage
;
634 ImageList_GetIconSize(himl
, &cx
, &cy
);
636 /* Create src image */
637 hdcImage
= CreateCompatibleDC(hdc
);
638 hbmImage
= CreateCompatibleBitmap(hdc
, cx
, cy
);
639 SelectObject(hdcImage
, hbmImage
);
640 ImageList_DrawEx(himl
, index
, hdcImage
, 0, 0, cx
, cy
,
641 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags
);
644 hdcMask
= CreateCompatibleDC(0);
645 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
646 SelectObject(hdcMask
, hbmMask
);
648 /* Remove the background and all white pixels */
649 ImageList_DrawEx(himl
, index
, hdcMask
, 0, 0, cx
, cy
,
650 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK
);
651 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
652 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
654 /* draw the new mask 'etched' to hdc */
655 SetBkColor(hdc
, RGB(255, 255, 255));
656 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
657 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
658 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
659 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
660 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
663 DeleteObject(hbmImage
);
665 DeleteObject (hbmMask
);
671 TOOLBAR_TranslateState(const TBUTTON_INFO
*btnPtr
)
675 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
676 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
677 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
678 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
679 retstate
|= (btnPtr
->bHot
) ? CDIS_HOT
: 0;
680 retstate
|= ((btnPtr
->fsState
& (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) == (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) ? CDIS_INDETERMINATE
: 0;
681 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
685 /* draws the image on a toolbar button */
687 TOOLBAR_DrawImage(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
,
688 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
690 HIMAGELIST himl
= NULL
;
691 BOOL draw_masked
= FALSE
;
694 UINT draw_flags
= ILD_TRANSPARENT
;
696 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
698 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
701 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
705 else if (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
||
706 ((tbcd
->nmcd
.uItemState
& CDIS_HOT
)
707 && ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))))
709 /* if hot, attempt to draw with hot image list, if fails,
710 use default image list */
711 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
713 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
716 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
721 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
722 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
725 if (!(dwItemCDFlag
& TBCDRF_NOMARK
) &&
726 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
727 draw_flags
|= ILD_BLEND50
;
729 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
730 index
, himl
, left
, top
, offset
);
733 TOOLBAR_DrawMasked (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
735 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
738 /* draws a blank frame for a toolbar button */
740 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
742 HDC hdc
= tbcd
->nmcd
.hdc
;
743 RECT rc
= tbcd
->nmcd
.rc
;
744 /* if the state is disabled or indeterminate then the button
745 * cannot have an interactive look like pressed or hot */
746 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
747 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
748 BOOL pressed_look
= !non_interactive_state
&&
749 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
750 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
752 /* app don't want us to draw any edges */
753 if (dwItemCDFlag
& TBCDRF_NOEDGES
)
756 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
759 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
760 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
761 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
766 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
768 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
769 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
774 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
, BOOL bDropDownPressed
, DWORD dwItemCDFlag
)
776 HDC hdc
= tbcd
->nmcd
.hdc
;
778 BOOL pressed
= bDropDownPressed
||
779 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
));
781 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
784 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
);
785 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
786 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
787 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
788 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
793 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
795 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
796 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
800 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
802 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
804 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
805 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
808 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
811 /* draws a complete toolbar button */
813 TOOLBAR_DrawButton (HWND hwnd
, TBUTTON_INFO
*btnPtr
, HDC hdc
, DWORD dwBaseCustDraw
)
815 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
816 DWORD dwStyle
= infoPtr
->dwStyle
;
817 BOOL hasDropDownArrow
= (TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) &&
818 (btnPtr
->fsStyle
& BTNS_DROPDOWN
)) ||
819 (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
820 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
821 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
822 RECT rc
, rcArrow
, rcBitmap
, rcText
;
823 LPWSTR lpText
= NULL
;
828 DWORD dwItemCustDraw
;
830 HTHEME theme
= GetWindowTheme (hwnd
);
833 CopyRect (&rcArrow
, &rc
);
835 /* separator - doesn't send NM_CUSTOMDRAW */
836 if (btnPtr
->fsStyle
& BTNS_SEP
) {
839 DrawThemeBackground (theme
, hdc
,
840 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
844 /* with the FLAT style, iBitmap is the width and has already */
845 /* been taken into consideration in calculating the width */
846 /* so now we need to draw the vertical separator */
847 /* empirical tests show that iBitmap can/will be non-zero */
848 /* when drawing the vertical bar... */
849 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
850 if (btnPtr
->fsStyle
& BTNS_DROPDOWN
)
851 TOOLBAR_DrawDDFlatSeparator (&rc
, hdc
, btnPtr
, infoPtr
);
853 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
855 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
856 FIXME("Draw some kind of separator: fsStyle=%x\n",
862 /* get a pointer to the text */
863 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
865 if (hasDropDownArrow
)
869 if (dwStyle
& TBSTYLE_FLAT
)
870 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
872 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
874 if (drawSepDropDownArrow
)
877 rcArrow
.left
= right
;
880 /* copy text & bitmap rects after adjusting for drop-down arrow
881 * so that text & bitmap is centered in the rectangle not containing
883 CopyRect(&rcText
, &rc
);
884 CopyRect(&rcBitmap
, &rc
);
886 /* Center the bitmap horizontally and vertically */
887 if (dwStyle
& TBSTYLE_LIST
)
890 infoPtr
->nMaxTextRows
> 0 &&
891 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
892 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
893 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
895 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
898 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
900 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
902 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
903 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
904 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
905 TRACE("Text=%s\n", debugstr_w(lpText
));
906 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
908 /* calculate text position */
911 rcText
.left
+= GetSystemMetrics(SM_CXEDGE
);
912 rcText
.right
-= GetSystemMetrics(SM_CXEDGE
);
913 if (dwStyle
& TBSTYLE_LIST
)
915 if (TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
))
916 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
920 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
921 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
923 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
927 /* Initialize fields in all cases, because we use these later
928 * NOTE: applications can and do alter these to customize their
930 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
931 tbcd
.clrText
= comctl32_color
.clrBtnText
;
932 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
933 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
934 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
935 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
936 tbcd
.clrHighlightHotTrack
= 0;
937 tbcd
.nStringBkMode
= TRANSPARENT
;
938 tbcd
.nHLStringBkMode
= OPAQUE
;
939 /* MSDN says that this is the text rectangle.
940 * But (why always a but) tracing of v5.7 of native shows
941 * that this is really a *relative* rectangle based on the
942 * the nmcd.rc. Also the left and top are always 0 ignoring
943 * any bitmap that might be present. */
944 tbcd
.rcText
.left
= 0;
946 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
947 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
948 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
951 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
953 /* FIXME: what are these used for? */
957 /* Issue Item Prepaint notify */
960 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
962 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
963 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
964 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
965 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
966 /* reset these fields so the user can't alter the behaviour like native */
970 dwItemCustDraw
= ntfret
& 0xffff;
971 dwItemCDFlag
= ntfret
& 0xffff0000;
972 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
974 /* save the only part of the rect that the user can change */
975 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
976 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
979 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
980 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
981 OffsetRect(&rcText
, 1, 1);
983 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
984 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
985 TOOLBAR_DrawPattern (&rc
, &tbcd
);
987 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
988 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
990 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
994 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
995 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
996 if (hasDropDownArrow
)
997 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
998 SetBkColor(hdc
, oldclr
);
1004 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
1005 int stateId
= TS_NORMAL
;
1007 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1008 stateId
= TS_DISABLED
;
1009 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1010 stateId
= TS_PRESSED
;
1011 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1012 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1013 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1014 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1017 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &tbcd
.nmcd
.rc
, NULL
);
1020 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, dwItemCDFlag
);
1022 if (drawSepDropDownArrow
)
1026 int stateId
= TS_NORMAL
;
1028 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1029 stateId
= TS_DISABLED
;
1030 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1031 stateId
= TS_PRESSED
;
1032 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1033 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1034 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1037 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1038 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1041 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1044 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1045 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1046 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1047 SetBkMode (hdc
, oldBkMode
);
1049 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1051 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1053 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1055 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1056 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1058 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1060 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1061 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1064 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1067 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1069 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1070 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1077 TOOLBAR_Refresh (HWND hwnd
, HDC hdc
, const PAINTSTRUCT
*ps
)
1079 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1080 TBUTTON_INFO
*btnPtr
;
1082 RECT rcTemp
, rcClient
;
1083 NMTBCUSTOMDRAW tbcd
;
1085 DWORD dwBaseCustDraw
;
1087 /* the app has told us not to redraw the toolbar */
1088 if (!infoPtr
->bDoRedraw
)
1091 /* if imagelist belongs to the app, it can be changed
1092 by the app after setting it */
1093 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1095 infoPtr
->nNumBitmaps
= 0;
1096 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1097 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1100 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1102 /* change the imagelist icon size if we manage the list and it is necessary */
1103 TOOLBAR_CheckImageListIconSize(infoPtr
);
1105 /* Send initial notify */
1106 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1107 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1108 tbcd
.nmcd
.hdc
= hdc
;
1109 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1110 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1111 dwBaseCustDraw
= ntfret
& 0xffff;
1113 GetClientRect(hwnd
, &rcClient
);
1115 /* redraw necessary buttons */
1116 btnPtr
= infoPtr
->buttons
;
1117 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1120 if (!RectVisible(hdc
, &btnPtr
->rect
))
1122 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1124 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1125 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1129 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1130 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1132 TOOLBAR_DrawButton(hwnd
, btnPtr
, hdc
, dwBaseCustDraw
);
1135 /* draw insert mark if required */
1136 if (infoPtr
->tbim
.iButton
!= -1)
1138 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1140 rcInsertMark
.top
= rcButton
.top
;
1141 rcInsertMark
.bottom
= rcButton
.bottom
;
1142 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1143 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1145 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1146 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1149 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1151 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1152 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1153 tbcd
.nmcd
.hdc
= hdc
;
1154 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1155 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1159 /***********************************************************************
1160 * TOOLBAR_MeasureString
1162 * This function gets the width and height of a string in pixels. This
1163 * is done first by using GetTextExtentPoint to get the basic width
1164 * and height. The DrawText is called with DT_CALCRECT to get the exact
1165 * width. The reason is because the text may have more than one "&" (or
1166 * prefix characters as M$ likes to call them). The prefix character
1167 * indicates where the underline goes, except for the string "&&" which
1168 * is reduced to a single "&". GetTextExtentPoint does not process these
1169 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1172 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1173 HDC hdc
, LPSIZE lpSize
)
1180 if (infoPtr
->nMaxTextRows
> 0 &&
1181 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1182 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1183 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1185 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1187 if(lpText
!= NULL
) {
1188 /* first get size of all the text */
1189 GetTextExtentPoint32W (hdc
, lpText
, strlenW (lpText
), lpSize
);
1191 /* feed above size into the rectangle for DrawText */
1192 myrect
.left
= myrect
.top
= 0;
1193 myrect
.right
= lpSize
->cx
;
1194 myrect
.bottom
= lpSize
->cy
;
1196 /* Use DrawText to get true size as drawn (less pesky "&") */
1197 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1198 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1201 /* feed back to caller */
1202 lpSize
->cx
= myrect
.right
;
1203 lpSize
->cy
= myrect
.bottom
;
1207 TRACE("string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1210 /***********************************************************************
1211 * TOOLBAR_CalcStrings
1213 * This function walks through each string and measures it and returns
1214 * the largest height and width to caller.
1217 TOOLBAR_CalcStrings (HWND hwnd
, LPSIZE lpSize
)
1219 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1220 TBUTTON_INFO
*btnPtr
;
1229 if (infoPtr
->nMaxTextRows
== 0)
1233 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1235 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1239 GetTextMetricsW(hdc
, &tm
);
1240 lpSize
->cy
= tm
.tmHeight
;
1243 btnPtr
= infoPtr
->buttons
;
1244 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1245 if(TOOLBAR_HasText(infoPtr
, btnPtr
))
1247 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1248 if (sz
.cx
> lpSize
->cx
)
1250 if (sz
.cy
> lpSize
->cy
)
1255 SelectObject (hdc
, hOldFont
);
1256 ReleaseDC (hwnd
, hdc
);
1258 TRACE("max string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1261 /***********************************************************************
1262 * TOOLBAR_WrapToolbar
1264 * This function walks through the buttons and separators in the
1265 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1266 * wrapping should occur based on the width of the toolbar window.
1267 * It does *not* calculate button placement itself. That task
1268 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1269 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1270 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1272 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1273 * vertical toolbar lists.
1277 TOOLBAR_WrapToolbar( HWND hwnd
, DWORD dwStyle
)
1279 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1280 TBUTTON_INFO
*btnPtr
;
1283 BOOL bWrap
, bButtonWrap
;
1285 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1286 /* no layout is necessary. Applications may use this style */
1287 /* to perform their own layout on the toolbar. */
1288 if( !(dwStyle
& TBSTYLE_WRAPABLE
) &&
1289 !(infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
) ) return;
1291 btnPtr
= infoPtr
->buttons
;
1292 x
= infoPtr
->nIndent
;
1294 if (GetParent(hwnd
))
1296 /* this can get the parents width, to know how far we can extend
1297 * this toolbar. We cannot use its height, as there may be multiple
1298 * toolbars in a rebar control
1300 GetClientRect( GetParent(hwnd
), &rc
);
1301 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1305 GetWindowRect( hwnd
, &rc
);
1306 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1309 bButtonWrap
= FALSE
;
1311 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1312 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, infoPtr
->nWidth
,
1315 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1318 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1320 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1323 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1324 /* it is the actual width of the separator. This is used for */
1325 /* custom controls in toolbars. */
1327 /* BTNS_DROPDOWN separators are treated as buttons for */
1328 /* width. - GA 8/01 */
1329 if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1330 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
))
1331 cx
= (btnPtr
[i
].iBitmap
> 0) ?
1332 btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1334 cx
= infoPtr
->nButtonWidth
;
1336 /* Two or more adjacent separators form a separator group. */
1337 /* The first separator in a group should be wrapped to the */
1338 /* next row if the previous wrapping is on a button. */
1340 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1341 (i
+ 1 < infoPtr
->nNumButtons
) &&
1342 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1344 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1345 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1346 x
= infoPtr
->nIndent
;
1348 bButtonWrap
= FALSE
;
1352 /* The layout makes sure the bitmap is visible, but not the button. */
1353 /* Test added to also wrap after a button that starts a row but */
1354 /* is bigger than the area. - GA 8/01 */
1355 if (( x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2
1356 > infoPtr
->nWidth
) ||
1357 ((x
== infoPtr
->nIndent
) && (cx
> infoPtr
->nWidth
)))
1359 BOOL bFound
= FALSE
;
1361 /* If the current button is a separator and not hidden, */
1362 /* go to the next until it reaches a non separator. */
1363 /* Wrap the last separator if it is before a button. */
1364 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1365 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1366 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1367 i
< infoPtr
->nNumButtons
)
1373 if( bFound
&& i
< infoPtr
->nNumButtons
)
1376 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1377 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1378 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1379 x
= infoPtr
->nIndent
;
1380 bButtonWrap
= FALSE
;
1383 else if ( i
>= infoPtr
->nNumButtons
)
1386 /* If the current button is not a separator, find the last */
1387 /* separator and wrap it. */
1388 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1390 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1391 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1395 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1396 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1397 x
= infoPtr
->nIndent
;
1398 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1399 bButtonWrap
= FALSE
;
1404 /* If no separator available for wrapping, wrap one of */
1405 /* non-hidden previous button. */
1409 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1411 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1416 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1417 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1418 x
= infoPtr
->nIndent
;
1419 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1425 /* If all above failed, wrap the current button. */
1428 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1429 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1430 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1432 x
= infoPtr
->nIndent
;
1433 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1434 bButtonWrap
= FALSE
;
1440 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1441 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1448 /***********************************************************************
1449 * TOOLBAR_MeasureButton
1451 * Calculates the width and height required for a button. Used in
1452 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1453 * the width of buttons that are autosized.
1455 * Note that it would have been rather elegant to use one piece of code for
1456 * both the laying out of the toolbar and for controlling where button parts
1457 * are drawn, but the native control has inconsistencies between the two that
1458 * prevent this from being effectively. These inconsistencies can be seen as
1459 * artefacts where parts of the button appear outside of the bounding button
1462 * There are several cases for the calculation of the button dimensions and
1463 * button part positioning:
1470 * +--------------------------------------------------------+ ^
1472 * | | pad.cy / 2 | centred | |
1473 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1474 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1475 * | |<------------>| | | | |
1476 * | +--------------+ +------------+ | |
1477 * |<-------------------------------------->| | |
1478 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1480 * +--------------------------------------------------------+ -
1481 * <-------------------------------------------------------->
1482 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1484 * Without Bitmap (I_IMAGENONE):
1486 * +-----------------------------------+ ^
1488 * | | centred | | LISTPAD_CY +
1489 * | +------------+ | | szText.cy
1492 * | +------------+ | |
1493 * |<----------------->| | |
1494 * | cxedge |<-----------> | |
1496 * +-----------------------------------+ -
1497 * <----------------------------------->
1498 * szText.cx + pad.cx
1502 * +--------------------------------------+ ^
1504 * | | padding.cy/2 | | DEFPAD_CY +
1505 * | +------------+ | | nBitmapHeight
1508 * | +------------+ | |
1509 * |<------------------->| | |
1510 * | cxedge + iListGap/2 |<-----------> | |
1511 * | nBitmapWidth | |
1512 * +--------------------------------------+ -
1513 * <-------------------------------------->
1514 * 2*cxedge + nBitmapWidth + iListGap
1521 * +-----------------------------------+ ^
1523 * | | pad.cy / 2 | | nBitmapHeight +
1524 * | - | | szText.cy +
1525 * | +------------+ | | DEFPAD_CY + 1
1526 * | centred | Bitmap | | |
1527 * |<----------------->| | | |
1528 * | +------------+ | |
1532 * | centred +---------------+ | |
1533 * |<--------------->| Text | | |
1534 * | +---------------+ | |
1535 * +-----------------------------------+ -
1536 * <----------------------------------->
1537 * pad.cx + max(nBitmapWidth, szText.cx)
1539 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1541 * +---------------------------------------+ ^
1543 * | | 2 + pad.cy / 2 | |
1544 * | - | | szText.cy +
1545 * | centred +-----------------+ | | pad.cy + 2
1546 * |<--------------->| Text | | |
1547 * | +-----------------+ | |
1549 * +---------------------------------------+ -
1550 * <--------------------------------------->
1551 * 2*cxedge + pad.cx + szText.cx
1554 * As for with bitmaps, but with szText.cx zero.
1556 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1557 BOOL bHasBitmap
, BOOL bValidImageList
)
1560 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1562 /* set button height from bitmap / text height... */
1563 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1566 /* ... add on the necessary padding */
1567 if (bValidImageList
)
1570 sizeButton
.cy
+= DEFPAD_CY
;
1572 sizeButton
.cy
+= LISTPAD_CY
;
1575 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1577 /* calculate button width */
1580 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1581 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1582 if (sizeString
.cx
> 0)
1583 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1586 sizeButton
.cx
= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1592 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1593 if (sizeString
.cy
> 0)
1594 sizeButton
.cy
+= 1 + sizeString
.cy
;
1595 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1596 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1600 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1601 NONLIST_NOTEXT_OFFSET
;
1602 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1603 infoPtr
->szPadding
.cx
+ sizeString
.cx
;
1610 /***********************************************************************
1611 * TOOLBAR_CalcToolbar
1613 * This function calculates button and separator placement. It first
1614 * calculates the button sizes, gets the toolbar window width and then
1615 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1616 * on. It assigns a new location to each item and sends this location to
1617 * the tooltip window if appropriate. Finally, it updates the rcBound
1618 * rect and calculates the new required toolbar window height.
1621 TOOLBAR_CalcToolbar (HWND hwnd
)
1623 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
1624 SIZE sizeString
, sizeButton
;
1625 BOOL validImageList
= FALSE
;
1627 TOOLBAR_CalcStrings (hwnd
, &sizeString
);
1629 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1631 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1632 validImageList
= TRUE
;
1633 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1634 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1635 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1636 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1638 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1639 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1640 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1641 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1643 TOOLBAR_LayoutToolbar(hwnd
);
1647 TOOLBAR_LayoutToolbar(HWND hwnd
)
1649 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
1650 TBUTTON_INFO
*btnPtr
;
1652 INT i
, nRows
, nSepRows
;
1655 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1656 BOOL hasDropDownArrows
= TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
);
1658 TOOLBAR_WrapToolbar(hwnd
, infoPtr
->dwStyle
);
1660 x
= infoPtr
->nIndent
;
1661 y
= infoPtr
->iTopMargin
;
1662 cx
= infoPtr
->nButtonWidth
;
1663 cy
= infoPtr
->nButtonHeight
;
1665 nRows
= nSepRows
= 0;
1667 infoPtr
->rcBound
.top
= y
;
1668 infoPtr
->rcBound
.left
= x
;
1669 infoPtr
->rcBound
.bottom
= y
+ cy
;
1670 infoPtr
->rcBound
.right
= x
;
1672 btnPtr
= infoPtr
->buttons
;
1674 TRACE("cy=%d\n", cy
);
1676 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1679 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1681 SetRectEmpty (&btnPtr
->rect
);
1685 cy
= infoPtr
->nButtonHeight
;
1687 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1688 /* it is the actual width of the separator. This is used for */
1689 /* custom controls in toolbars. */
1690 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1691 if (btnPtr
->fsStyle
& BTNS_DROPDOWN
) {
1692 cy
= (btnPtr
->iBitmap
> 0) ?
1693 btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1694 cx
= infoPtr
->nButtonWidth
;
1697 cx
= (btnPtr
->iBitmap
> 0) ?
1698 btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1704 else if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1705 (btnPtr
->fsStyle
& BTNS_AUTOSIZE
))
1712 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1714 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1716 SelectObject (hdc
, hOldFont
);
1717 ReleaseDC (hwnd
, hdc
);
1719 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1720 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1725 cx
= infoPtr
->nButtonWidth
;
1727 /* if size has been set manually then don't add on extra space
1728 * for the drop down arrow */
1729 if (!btnPtr
->cx
&& hasDropDownArrows
&&
1730 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) || (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)))
1731 cx
+= DDARROW_WIDTH
;
1733 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1736 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1738 if (infoPtr
->rcBound
.left
> x
)
1739 infoPtr
->rcBound
.left
= x
;
1740 if (infoPtr
->rcBound
.right
< x
+ cx
)
1741 infoPtr
->rcBound
.right
= x
+ cx
;
1742 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1743 infoPtr
->rcBound
.bottom
= y
+ cy
;
1745 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1747 /* btnPtr->nRow is zero based. The space between the rows is */
1748 /* also considered as a row. */
1749 btnPtr
->nRow
= nRows
+ nSepRows
;
1751 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1752 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1757 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1761 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1762 /* it is the actual width of the separator. This is used for */
1763 /* custom controls in toolbars. */
1764 if ( !(btnPtr
->fsStyle
& BTNS_DROPDOWN
))
1765 y
+= cy
+ ( (btnPtr
->iBitmap
> 0 ) ?
1766 btnPtr
->iBitmap
: SEPARATOR_WIDTH
) * 2 /3;
1770 /* nSepRows is used to calculate the extra height following */
1774 x
= infoPtr
->nIndent
;
1776 /* Increment row number unless this is the last button */
1777 /* and it has Wrap set. */
1778 if (i
!= infoPtr
->nNumButtons
-1)
1785 /* infoPtr->nRows is the number of rows on the toolbar */
1786 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1788 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1793 TOOLBAR_InternalHitTest (HWND hwnd
, const POINT
*lpPt
)
1795 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1796 TBUTTON_INFO
*btnPtr
;
1799 btnPtr
= infoPtr
->buttons
;
1800 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1801 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1804 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1805 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1806 TRACE(" ON SEPARATOR %d!\n", i
);
1811 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1812 TRACE(" ON BUTTON %d!\n", i
);
1818 TRACE(" NOWHERE!\n");
1819 return TOOLBAR_NOWHERE
;
1824 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1826 TBUTTON_INFO
*btnPtr
;
1829 if (CommandIsIndex
) {
1830 TRACE("command is really index command=%d\n", idCommand
);
1831 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1834 btnPtr
= infoPtr
->buttons
;
1835 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1836 if (btnPtr
->idCommand
== idCommand
) {
1837 TRACE("command=%d index=%d\n", idCommand
, i
);
1841 TRACE("no index found for command=%d\n", idCommand
);
1847 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1849 TBUTTON_INFO
*btnPtr
;
1852 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1855 /* check index button */
1856 btnPtr
= &infoPtr
->buttons
[nIndex
];
1857 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1858 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1862 /* check previous buttons */
1863 nRunIndex
= nIndex
- 1;
1864 while (nRunIndex
>= 0) {
1865 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1866 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1867 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1875 /* check next buttons */
1876 nRunIndex
= nIndex
+ 1;
1877 while (nRunIndex
< infoPtr
->nNumButtons
) {
1878 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1879 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1880 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1893 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1894 WPARAM wParam
, LPARAM lParam
)
1900 msg
.wParam
= wParam
;
1901 msg
.lParam
= lParam
;
1902 msg
.time
= GetMessageTime ();
1903 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
1904 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
1906 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1910 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1912 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
1915 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
1916 ti
.cbSize
= sizeof (TTTOOLINFOW
);
1917 ti
.hwnd
= infoPtr
->hwndSelf
;
1918 ti
.uId
= button
->idCommand
;
1920 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
1921 /* ti.lParam = random value from the stack? */
1923 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
1929 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1931 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
1934 ZeroMemory(&ti
, sizeof(ti
));
1935 ti
.cbSize
= sizeof(ti
);
1936 ti
.hwnd
= infoPtr
->hwndSelf
;
1937 ti
.uId
= button
->idCommand
;
1939 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
1943 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1945 /* Set the toolTip only for non-hidden, non-separator button */
1946 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
1950 ZeroMemory(&ti
, sizeof(ti
));
1951 ti
.cbSize
= sizeof(ti
);
1952 ti
.hwnd
= infoPtr
->hwndSelf
;
1953 ti
.uId
= button
->idCommand
;
1954 ti
.rect
= button
->rect
;
1955 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
1959 /* Creates the tooltip control */
1961 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
1964 NMTOOLTIPSCREATED nmttc
;
1966 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
1967 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1968 infoPtr
->hwndSelf
, 0, 0, 0);
1970 if (!infoPtr
->hwndToolTip
)
1973 /* Send NM_TOOLTIPSCREATED notification */
1974 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
1975 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
1977 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
1979 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
1980 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
1984 /* keeps available button list box sorted by button id */
1985 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
1989 PCUSTOMBUTTON btnInfo
;
1990 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
1992 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
1994 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
1996 /* position 0 is always separator */
1997 for (i
= 1; i
< count
; i
++)
1999 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2000 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2002 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2003 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2007 /* id higher than all others add to end */
2008 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2009 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2012 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2016 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2018 if (nIndexFrom
== nIndexTo
)
2021 /* MSDN states that iItem is the index of the button, rather than the
2022 * command ID as used by every other NMTOOLBAR notification */
2023 nmtb
.iItem
= nIndexFrom
;
2024 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2026 PCUSTOMBUTTON btnInfo
;
2028 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2029 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2031 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2033 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2034 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2035 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2036 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2039 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2041 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2043 /* last item is always separator, so -2 instead of -1 */
2044 if (nIndexTo
>= (count
- 2))
2045 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2047 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2049 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2050 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2052 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2056 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2060 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2062 /* MSDN states that iItem is the index of the button, rather than the
2063 * command ID as used by every other NMTOOLBAR notification */
2064 nmtb
.iItem
= nIndexAvail
;
2065 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2067 PCUSTOMBUTTON btnInfo
;
2069 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2070 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2071 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2073 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2075 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2077 /* remove from 'available buttons' list */
2078 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2079 if (nIndexAvail
== count
-1)
2080 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2082 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2086 PCUSTOMBUTTON btnNew
;
2088 /* duplicate 'separator' button */
2089 btnNew
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2090 memcpy(btnNew
, btnInfo
, sizeof(CUSTOMBUTTON
));
2094 /* insert into 'toolbar button' list */
2095 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2096 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2098 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2100 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2104 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2106 PCUSTOMBUTTON btnInfo
;
2107 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2109 TRACE("Remove: index %d\n", index
);
2111 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2113 /* send TBN_QUERYDELETE notification */
2114 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2118 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2119 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2121 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2123 /* insert into 'available button' list */
2124 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2125 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2129 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2133 /* drag list notification function for toolbar buttons list box */
2134 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2135 const DRAGLISTINFO
*pDLI
)
2137 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2138 switch (pDLI
->uNotification
)
2142 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2143 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2144 /* no dragging for last item (separator) */
2145 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2150 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2151 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2152 /* no dragging past last item (separator) */
2153 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2155 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2156 /* FIXME: native uses "move button" cursor */
2157 return DL_COPYCURSOR
;
2160 /* not over toolbar buttons list */
2161 if (nCurrentItem
< 0)
2163 POINT ptWindow
= pDLI
->ptCursor
;
2164 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2165 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2166 /* over available buttons list? */
2167 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2168 /* FIXME: native uses "move button" cursor */
2169 return DL_COPYCURSOR
;
2171 /* clear drag arrow */
2172 DrawInsert(hwnd
, hwndList
, -1);
2173 return DL_STOPCURSOR
;
2177 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2178 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2179 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2180 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2182 /* clear drag arrow */
2183 DrawInsert(hwnd
, hwndList
, -1);
2185 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2187 /* not over toolbar buttons list */
2190 POINT ptWindow
= pDLI
->ptCursor
;
2191 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2192 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2193 /* over available buttons list? */
2194 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2195 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2200 /* Clear drag arrow */
2201 DrawInsert(hwnd
, hwndList
, -1);
2208 /* drag list notification function for available buttons list box */
2209 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2210 const DRAGLISTINFO
*pDLI
)
2212 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2213 switch (pDLI
->uNotification
)
2219 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2220 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2221 /* no dragging past last item (separator) */
2222 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2224 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2225 /* FIXME: native uses "move button" cursor */
2226 return DL_COPYCURSOR
;
2229 /* not over toolbar buttons list */
2230 if (nCurrentItem
< 0)
2232 POINT ptWindow
= pDLI
->ptCursor
;
2233 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2234 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2235 /* over available buttons list? */
2236 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2237 /* FIXME: native uses "move button" cursor */
2238 return DL_COPYCURSOR
;
2240 /* clear drag arrow */
2241 DrawInsert(hwnd
, hwndList
, -1);
2242 return DL_STOPCURSOR
;
2246 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2247 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2248 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2249 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2251 /* clear drag arrow */
2252 DrawInsert(hwnd
, hwndList
, -1);
2254 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2258 /* Clear drag arrow */
2259 DrawInsert(hwnd
, hwndList
, -1);
2265 extern UINT uDragListMessage
;
2267 /***********************************************************************
2268 * TOOLBAR_CustomizeDialogProc
2269 * This function implements the toolbar customization dialog.
2271 static INT_PTR CALLBACK
2272 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2274 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2275 PCUSTOMBUTTON btnInfo
;
2277 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2282 custInfo
= (PCUSTDLG_INFO
)lParam
;
2283 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2290 NMTBINITCUSTOMIZE nmtbic
;
2292 infoPtr
= custInfo
->tbInfo
;
2294 /* send TBN_QUERYINSERT notification */
2295 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2297 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2300 nmtbic
.hwndDialog
= hwnd
;
2301 /* Send TBN_INITCUSTOMIZE notification */
2302 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2305 TRACE("TBNRF_HIDEHELP requested\n");
2306 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2309 /* add items to 'toolbar buttons' list and check if removable */
2310 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2312 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2313 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2314 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2315 btnInfo
->bVirtual
= FALSE
;
2316 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2318 /* send TBN_QUERYDELETE notification */
2319 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2321 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2322 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2325 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2327 /* insert separator button into 'available buttons' list */
2328 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2329 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2330 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2331 btnInfo
->bVirtual
= FALSE
;
2332 btnInfo
->bRemovable
= TRUE
;
2333 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2334 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2335 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2337 /* insert all buttons into dsa */
2340 /* send TBN_GETBUTTONINFO notification */
2343 nmtb
.pszText
= Buffer
;
2346 /* Clear previous button's text */
2347 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2349 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2352 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2353 nmtb
.tbButton
.fsStyle
, i
,
2354 nmtb
.tbButton
.idCommand
,
2355 nmtb
.tbButton
.iString
,
2356 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2359 /* insert button into the apropriate list */
2360 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2363 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2364 btnInfo
->bVirtual
= FALSE
;
2365 btnInfo
->bRemovable
= TRUE
;
2369 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2370 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2373 memcpy (&btnInfo
->btn
, &nmtb
.tbButton
, sizeof(TBBUTTON
));
2374 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2376 if (lstrlenW(nmtb
.pszText
))
2377 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2378 else if (nmtb
.tbButton
.iString
>= 0 &&
2379 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2381 lstrcpyW(btnInfo
->text
,
2382 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2387 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2390 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2392 /* select first item in the 'available' list */
2393 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2395 /* append 'virtual' separator button to the 'toolbar buttons' list */
2396 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2397 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2398 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2399 btnInfo
->bVirtual
= TRUE
;
2400 btnInfo
->bRemovable
= FALSE
;
2401 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2402 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2403 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2405 /* select last item in the 'toolbar' list */
2406 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2407 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2409 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2410 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2412 /* set focus and disable buttons */
2413 PostMessageW (hwnd
, WM_USER
, 0, 0);
2418 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2419 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2420 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2421 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2425 EndDialog(hwnd
, FALSE
);
2429 switch (LOWORD(wParam
))
2431 case IDC_TOOLBARBTN_LBOX
:
2432 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2434 PCUSTOMBUTTON btnInfo
;
2439 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2440 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2442 /* send TBN_QUERYINSERT notification */
2444 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2446 /* get list box item */
2447 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2449 if (index
== (count
- 1))
2451 /* last item (virtual separator) */
2452 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2453 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2455 else if (index
== (count
- 2))
2457 /* second last item (last non-virtual item) */
2458 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2459 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2461 else if (index
== 0)
2464 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2465 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2469 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2470 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2473 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2477 case IDC_MOVEUP_BTN
:
2479 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2480 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2484 case IDC_MOVEDN_BTN
: /* move down */
2486 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2487 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2491 case IDC_REMOVE_BTN
: /* remove button */
2493 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2495 if (LB_ERR
== index
)
2498 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2502 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2505 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2508 case IDOK
: /* Add button */
2513 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2514 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2516 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2521 EndDialog(hwnd
, FALSE
);
2531 /* delete items from 'toolbar buttons' listbox*/
2532 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2533 for (i
= 0; i
< count
; i
++)
2535 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2537 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2539 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2542 /* delete items from 'available buttons' listbox*/
2543 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2544 for (i
= 0; i
< count
; i
++)
2546 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2548 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2550 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2555 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2557 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2562 COLORREF oldText
= 0;
2566 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, (WPARAM
)lpdis
->itemID
, 0);
2567 if (btnInfo
== NULL
)
2569 FIXME("btnInfo invalid!\n");
2573 /* set colors and select objects */
2574 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2575 if (btnInfo
->bVirtual
)
2576 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2578 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2579 hPen
= CreatePen( PS_SOLID
, 1,
2580 GetSysColor( (lpdis
->itemState
& ODS_SELECTED
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2581 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2582 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2584 /* fill background rectangle */
2585 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2586 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2588 /* calculate button and text rectangles */
2589 CopyRect (&rcButton
, &lpdis
->rcItem
);
2590 InflateRect (&rcButton
, -1, -1);
2591 CopyRect (&rcText
, &rcButton
);
2592 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2593 rcText
.left
= rcButton
.right
+ 2;
2595 /* draw focus rectangle */
2596 if (lpdis
->itemState
& ODS_FOCUS
)
2597 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2600 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2601 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2603 /* draw image and text */
2604 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2605 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2606 btnInfo
->btn
.iBitmap
));
2607 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2608 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2610 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2611 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2613 /* delete objects and reset colors */
2614 SelectObject (lpdis
->hDC
, hOldBrush
);
2615 SelectObject (lpdis
->hDC
, hOldPen
);
2616 SetBkColor (lpdis
->hDC
, oldBk
);
2617 SetTextColor (lpdis
->hDC
, oldText
);
2618 DeleteObject( hPen
);
2623 case WM_MEASUREITEM
:
2624 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2626 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2628 lpmis
->itemHeight
= 15 + 8; /* default height */
2635 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2637 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2639 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2640 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2641 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2644 else if (wParam
== IDC_AVAILBTN_LBOX
)
2646 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2647 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2648 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2657 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2660 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2666 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2667 /* Add bitmaps to the default image list */
2668 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2669 hbmLoad
= (HBITMAP
)CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2671 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2673 /* enlarge the bitmap if needed */
2674 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2675 if (bitmap
->hInst
!= COMCTL32_hModule
)
2676 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2678 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2679 DeleteObject(hbmLoad
);
2683 nCountAfter
= ImageList_GetImageCount(himlDef
);
2684 nAdded
= nCountAfter
- nCountBefore
;
2685 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2687 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2688 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2689 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2690 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2693 infoPtr
->nNumBitmaps
+= nAdded
;
2698 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2705 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2706 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2708 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2710 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2713 TRACE("Update icon size: %dx%d -> %dx%d\n",
2714 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2716 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2717 ILC_COLORDDB
|ILC_MASK
, 8, 2);
2718 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2719 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2720 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2721 infoPtr
->himlInt
= himlNew
;
2723 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2724 ImageList_Destroy(himlDef
);
2727 /***********************************************************************
2728 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2732 TOOLBAR_AddBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2734 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2735 LPTBADDBITMAP lpAddBmp
= (LPTBADDBITMAP
)lParam
;
2740 TRACE("hwnd=%p wParam=%lx lParam=%lx\n", hwnd
, wParam
, lParam
);
2744 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2746 info
.hInst
= COMCTL32_hModule
;
2747 switch (lpAddBmp
->nID
)
2749 case IDB_STD_SMALL_COLOR
:
2751 info
.nID
= IDB_STD_SMALL
;
2753 case IDB_STD_LARGE_COLOR
:
2755 info
.nID
= IDB_STD_LARGE
;
2757 case IDB_VIEW_SMALL_COLOR
:
2759 info
.nID
= IDB_VIEW_SMALL
;
2761 case IDB_VIEW_LARGE_COLOR
:
2763 info
.nID
= IDB_VIEW_LARGE
;
2765 case IDB_HIST_SMALL_COLOR
:
2767 info
.nID
= IDB_HIST_SMALL
;
2769 case IDB_HIST_LARGE_COLOR
:
2771 info
.nID
= IDB_HIST_LARGE
;
2777 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2779 /* Windows resize all the buttons to the size of a newly added standard image */
2780 if (lpAddBmp
->nID
& 1)
2782 /* large icons: 24x24. Will make the button 31x30 */
2783 SendMessageW (hwnd
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2787 /* small icons: 16x16. Will make the buttons 23x22 */
2788 SendMessageW (hwnd
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2791 TOOLBAR_CalcToolbar (hwnd
);
2795 info
.nButtons
= (INT
)wParam
;
2796 info
.hInst
= lpAddBmp
->hInst
;
2797 info
.nID
= lpAddBmp
->nID
;
2798 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2801 /* check if the bitmap is already loaded and compute iSumButtons */
2803 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2805 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2806 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2808 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2811 if (!infoPtr
->cimlDef
) {
2812 /* create new default image list */
2813 TRACE ("creating default image list!\n");
2815 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2816 ILC_COLORDDB
| ILC_MASK
, info
.nButtons
, 2);
2817 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2818 infoPtr
->himlInt
= himlDef
;
2821 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2825 WARN("No default image list available\n");
2829 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2832 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2833 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2834 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2835 infoPtr
->nNumBitmapInfos
++;
2836 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2838 InvalidateRect(hwnd
, NULL
, TRUE
);
2844 TOOLBAR_AddButtonsT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL fUnicode
)
2846 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2847 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
2848 INT nOldButtons
, nNewButtons
, nAddButtons
, nCount
;
2849 BOOL fHasString
= FALSE
;
2851 TRACE("adding %ld buttons (unicode=%d)!\n", wParam
, fUnicode
);
2853 nAddButtons
= (UINT
)wParam
;
2854 nOldButtons
= infoPtr
->nNumButtons
;
2855 nNewButtons
= nOldButtons
+ nAddButtons
;
2857 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
2858 infoPtr
->nNumButtons
= nNewButtons
;
2860 /* insert new button data */
2861 for (nCount
= 0; nCount
< nAddButtons
; nCount
++) {
2862 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nOldButtons
+nCount
];
2863 btnPtr
->iBitmap
= lpTbb
[nCount
].iBitmap
;
2864 btnPtr
->idCommand
= lpTbb
[nCount
].idCommand
;
2865 btnPtr
->fsState
= lpTbb
[nCount
].fsState
;
2866 btnPtr
->fsStyle
= lpTbb
[nCount
].fsStyle
;
2867 btnPtr
->dwData
= lpTbb
[nCount
].dwData
;
2868 btnPtr
->bHot
= FALSE
;
2869 if(HIWORD(lpTbb
[nCount
].iString
) && lpTbb
[nCount
].iString
!= -1)
2872 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, (LPWSTR
)lpTbb
[nCount
].iString
);
2874 Str_SetPtrAtoW((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lpTbb
[nCount
].iString
);
2878 btnPtr
->iString
= lpTbb
[nCount
].iString
;
2880 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
2883 if (infoPtr
->nNumStrings
> 0 || fHasString
)
2884 TOOLBAR_CalcToolbar(hwnd
);
2886 TOOLBAR_LayoutToolbar(hwnd
);
2887 TOOLBAR_AutoSize (hwnd
);
2889 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
2891 InvalidateRect(hwnd
, NULL
, TRUE
);
2898 TOOLBAR_AddStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2900 #define MAX_RESOURCE_STRING_LENGTH 512
2901 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2902 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2903 INT nIndex
= infoPtr
->nNumStrings
;
2905 if ((wParam
) && (HIWORD(lParam
) == 0)) {
2906 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2911 TRACE("adding string from resource!\n");
2913 len
= LoadStringW ((HINSTANCE
)wParam
, (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(hwnd
);
2966 TOOLBAR_AddStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2968 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2969 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2974 if ((wParam
) && (HIWORD(lParam
) == 0)) /* load from resources */
2975 return TOOLBAR_AddStringW(hwnd
, wParam
, lParam
);
2981 TRACE("adding string(s) from array!\n");
2982 nIndex
= infoPtr
->nNumStrings
;
2985 TRACE("len=%d \"%s\"\n", len
, p
);
2987 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2988 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2989 infoPtr
->nNumStrings
++;
2995 TOOLBAR_CalcToolbar(hwnd
);
3001 TOOLBAR_AutoSize (HWND hwnd
)
3003 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3009 TRACE("auto sizing, style=%x!\n", infoPtr
->dwStyle
);
3011 parent
= GetParent (hwnd
);
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(hwnd
);
3029 InvalidateRect( hwnd
, NULL
, TRUE
);
3032 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3035 UINT uPosFlags
= SWP_NOZORDER
;
3037 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3039 GetWindowRect(hwnd
, &window_rect
);
3040 ScreenToClient(parent
, (LPPOINT
)&window_rect
.left
);
3041 y
= window_rect
.top
;
3043 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3045 GetWindowRect(hwnd
, &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 x
= y
= 1; /* FIXME: this looks wrong */
3058 cy
+= GetSystemMetrics(SM_CYEDGE
);
3059 cx
+= GetSystemMetrics(SM_CXEDGE
);
3062 SetWindowPos(hwnd
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3070 TOOLBAR_ButtonCount (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3072 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3074 return infoPtr
->nNumButtons
;
3079 TOOLBAR_ButtonStructSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3081 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3083 infoPtr
->dwStructSize
= (DWORD
)wParam
;
3090 TOOLBAR_ChangeBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3092 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3093 TBUTTON_INFO
*btnPtr
;
3096 TRACE("button %ld, iBitmap now %d\n", wParam
, LOWORD(lParam
));
3098 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3102 btnPtr
= &infoPtr
->buttons
[nIndex
];
3103 btnPtr
->iBitmap
= LOWORD(lParam
);
3105 /* we HAVE to erase the background, the new bitmap could be */
3107 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3114 TOOLBAR_CheckButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3116 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3117 TBUTTON_INFO
*btnPtr
;
3120 BOOL bChecked
= FALSE
;
3122 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3124 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd
, nIndex
, lParam
);
3129 btnPtr
= &infoPtr
->buttons
[nIndex
];
3131 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? TRUE
: FALSE
;
3133 if (LOWORD(lParam
) == FALSE
)
3134 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3136 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3138 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3139 if (nOldIndex
== nIndex
)
3141 if (nOldIndex
!= -1)
3142 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3144 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3147 if( bChecked
!= LOWORD(lParam
) )
3149 if (nOldIndex
!= -1)
3150 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3151 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3154 /* FIXME: Send a WM_NOTIFY?? */
3161 TOOLBAR_CommandToIndex (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3163 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3165 return TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3170 TOOLBAR_Customize (HWND hwnd
)
3172 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3173 CUSTDLG_INFO custInfo
;
3179 custInfo
.tbInfo
= infoPtr
;
3180 custInfo
.tbHwnd
= hwnd
;
3182 /* send TBN_BEGINADJUST notification */
3183 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3185 if (!(hRes
= FindResourceW (COMCTL32_hModule
,
3186 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3187 (LPWSTR
)RT_DIALOG
)))
3190 if(!(template = LoadResource (COMCTL32_hModule
, hRes
)))
3193 ret
= DialogBoxIndirectParamW ((HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
),
3194 (LPCDLGTEMPLATEW
)template,
3196 TOOLBAR_CustomizeDialogProc
,
3199 /* send TBN_ENDADJUST notification */
3200 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3207 TOOLBAR_DeleteButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3209 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3210 INT nIndex
= (INT
)wParam
;
3212 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3214 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3217 memset(&nmtb
, 0, sizeof(nmtb
));
3218 nmtb
.iItem
= btnPtr
->idCommand
;
3219 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3220 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3221 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3222 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3223 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3224 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3225 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3227 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3229 if (infoPtr
->nNumButtons
== 1) {
3230 TRACE(" simple delete!\n");
3231 Free (infoPtr
->buttons
);
3232 infoPtr
->buttons
= NULL
;
3233 infoPtr
->nNumButtons
= 0;
3236 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3237 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3239 infoPtr
->nNumButtons
--;
3240 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3242 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3243 nIndex
* sizeof(TBUTTON_INFO
));
3246 if (nIndex
< infoPtr
->nNumButtons
) {
3247 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3248 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3254 TOOLBAR_LayoutToolbar(hwnd
);
3256 InvalidateRect (hwnd
, NULL
, TRUE
);
3263 TOOLBAR_EnableButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3265 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3266 TBUTTON_INFO
*btnPtr
;
3270 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3272 TRACE("hwnd=%p, btn index=%ld, lParam=0x%08lx\n", hwnd
, wParam
, lParam
);
3277 btnPtr
= &infoPtr
->buttons
[nIndex
];
3279 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3281 /* update the toolbar button state */
3282 if(LOWORD(lParam
) == FALSE
) {
3283 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3285 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3288 /* redraw the button only if the state of the button changed */
3289 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3290 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3296 static inline LRESULT
3297 TOOLBAR_GetAnchorHighlight (HWND hwnd
)
3299 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3301 return infoPtr
->bAnchor
;
3306 TOOLBAR_GetBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3308 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3311 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3315 return infoPtr
->buttons
[nIndex
].iBitmap
;
3319 static inline LRESULT
3320 TOOLBAR_GetBitmapFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3322 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3327 TOOLBAR_GetButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3329 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3330 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3331 INT nIndex
= (INT
)wParam
;
3332 TBUTTON_INFO
*btnPtr
;
3337 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3340 btnPtr
= &infoPtr
->buttons
[nIndex
];
3341 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3342 lpTbb
->idCommand
= btnPtr
->idCommand
;
3343 lpTbb
->fsState
= btnPtr
->fsState
;
3344 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3345 lpTbb
->bReserved
[0] = 0;
3346 lpTbb
->bReserved
[1] = 0;
3347 lpTbb
->dwData
= btnPtr
->dwData
;
3348 lpTbb
->iString
= btnPtr
->iString
;
3355 TOOLBAR_GetButtonInfoT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL bUnicode
)
3357 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3358 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3359 LPTBBUTTONINFOW lpTbInfo
= (LPTBBUTTONINFOW
)lParam
;
3360 TBUTTON_INFO
*btnPtr
;
3363 if (lpTbInfo
== NULL
)
3366 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3367 * the headers and tests shows that even with comctl 6 Vista accepts only the
3368 * original TBBUTTONINFO size
3370 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3372 WARN("Invalid button size\n");
3376 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
3377 lpTbInfo
->dwMask
& 0x80000000);
3381 if (!(btnPtr
= &infoPtr
->buttons
[nIndex
])) return -1;
3383 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3384 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3385 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3386 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3387 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3388 lpTbInfo
->lParam
= btnPtr
->dwData
;
3389 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3390 lpTbInfo
->cx
= (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3391 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3392 lpTbInfo
->fsState
= btnPtr
->fsState
;
3393 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3394 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3395 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3396 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3397 can't use TOOLBAR_GetText here */
3398 if (HIWORD(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3399 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3401 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3403 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3405 lpTbInfo
->pszText
[0] = '\0';
3412 TOOLBAR_GetButtonSize (HWND hwnd
)
3414 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3416 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3417 (WORD
)infoPtr
->nButtonHeight
);
3422 TOOLBAR_GetButtonTextA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3424 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3431 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3435 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3437 return WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3438 (LPSTR
)lParam
, 0x7fffffff, NULL
, NULL
) - 1;
3443 TOOLBAR_GetButtonTextW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3445 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3450 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3454 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3458 ret
= strlenW (lpText
);
3461 strcpyW ((LPWSTR
)lParam
, lpText
);
3469 TOOLBAR_GetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3471 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3472 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3473 return (LRESULT
)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3477 static inline LRESULT
3478 TOOLBAR_GetExtendedStyle (HWND hwnd
)
3480 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3484 return infoPtr
->dwExStyle
;
3489 TOOLBAR_GetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3491 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3492 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3493 return (LRESULT
)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3498 TOOLBAR_GetHotItem (HWND hwnd
)
3500 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3502 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3505 if (infoPtr
->nHotItem
< 0)
3508 return (LRESULT
)infoPtr
->nHotItem
;
3513 TOOLBAR_GetDefImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3515 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3516 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3517 return (LRESULT
) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd
), wParam
);
3522 TOOLBAR_GetInsertMark (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3524 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3525 TBINSERTMARK
*lptbim
= (TBINSERTMARK
*)lParam
;
3527 TRACE("hwnd = %p, lptbim = %p\n", hwnd
, lptbim
);
3529 *lptbim
= infoPtr
->tbim
;
3536 TOOLBAR_GetInsertMarkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3538 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3540 TRACE("hwnd = %p\n", hwnd
);
3542 return (LRESULT
)infoPtr
->clrInsertMark
;
3547 TOOLBAR_GetItemRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3549 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3550 TBUTTON_INFO
*btnPtr
;
3554 nIndex
= (INT
)wParam
;
3555 btnPtr
= &infoPtr
->buttons
[nIndex
];
3556 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3558 lpRect
= (LPRECT
)lParam
;
3561 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3564 lpRect
->left
= btnPtr
->rect
.left
;
3565 lpRect
->right
= btnPtr
->rect
.right
;
3566 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3567 lpRect
->top
= btnPtr
->rect
.top
;
3574 TOOLBAR_GetMaxSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3576 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3577 LPSIZE lpSize
= (LPSIZE
)lParam
;
3582 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3583 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3585 TRACE("maximum size %d x %d\n",
3586 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3587 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3593 /* << TOOLBAR_GetObject >> */
3597 TOOLBAR_GetPadding (HWND hwnd
)
3599 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3602 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3603 return (LRESULT
) oldPad
;
3608 TOOLBAR_GetRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3610 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3611 TBUTTON_INFO
*btnPtr
;
3615 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3616 btnPtr
= &infoPtr
->buttons
[nIndex
];
3617 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3619 lpRect
= (LPRECT
)lParam
;
3623 lpRect
->left
= btnPtr
->rect
.left
;
3624 lpRect
->right
= btnPtr
->rect
.right
;
3625 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3626 lpRect
->top
= btnPtr
->rect
.top
;
3633 TOOLBAR_GetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3635 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3637 return infoPtr
->nRows
;
3642 TOOLBAR_GetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3644 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3647 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3651 return infoPtr
->buttons
[nIndex
].fsState
;
3656 TOOLBAR_GetStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3658 return GetWindowLongW(hwnd
, GWL_STYLE
);
3663 TOOLBAR_GetTextRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3665 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3667 return infoPtr
->nMaxTextRows
;
3672 TOOLBAR_GetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3674 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3676 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3677 TOOLBAR_TooltipCreateControl(infoPtr
);
3678 return (LRESULT
)infoPtr
->hwndToolTip
;
3683 TOOLBAR_GetUnicodeFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3685 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3687 TRACE("%s hwnd=%p\n",
3688 infoPtr
->bUnicode
? "TRUE" : "FALSE", hwnd
);
3690 return infoPtr
->bUnicode
;
3694 static inline LRESULT
3695 TOOLBAR_GetVersion (HWND hwnd
)
3697 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3698 return infoPtr
->iVersion
;
3703 TOOLBAR_HideButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3705 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3706 TBUTTON_INFO
*btnPtr
;
3711 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3715 btnPtr
= &infoPtr
->buttons
[nIndex
];
3716 if (LOWORD(lParam
) == FALSE
)
3717 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3719 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3721 TOOLBAR_LayoutToolbar (hwnd
);
3723 InvalidateRect (hwnd
, NULL
, TRUE
);
3729 static inline LRESULT
3730 TOOLBAR_HitTest (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3732 return TOOLBAR_InternalHitTest (hwnd
, (LPPOINT
)lParam
);
3737 TOOLBAR_Indeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3739 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3740 TBUTTON_INFO
*btnPtr
;
3744 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3748 btnPtr
= &infoPtr
->buttons
[nIndex
];
3749 oldState
= btnPtr
->fsState
;
3750 if (LOWORD(lParam
) == FALSE
)
3751 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3753 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3755 if(oldState
!= btnPtr
->fsState
)
3756 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3763 TOOLBAR_InsertButtonT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL fUnicode
)
3765 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3766 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3767 INT nIndex
= (INT
)wParam
;
3772 TOOLBAR_DumpButton(infoPtr
, (TBUTTON_INFO
*)lpTbb
, nIndex
, FALSE
);
3775 /* EPP: this seems to be an undocumented call (from my IE4)
3776 * I assume in that case that:
3777 * - index of insertion is at the end of existing buttons
3778 * I only see this happen with nIndex == -1, but it could have a special
3779 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3781 nIndex
= infoPtr
->nNumButtons
;
3783 } else if (nIndex
< 0)
3786 TRACE("inserting button index=%d\n", nIndex
);
3787 if (nIndex
> infoPtr
->nNumButtons
) {
3788 nIndex
= infoPtr
->nNumButtons
;
3789 TRACE("adjust index=%d\n", nIndex
);
3792 infoPtr
->nNumButtons
++;
3793 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3794 memmove(&infoPtr
->buttons
[nIndex
+1], &infoPtr
->buttons
[nIndex
],
3795 (infoPtr
->nNumButtons
- nIndex
- 1) * sizeof(TBUTTON_INFO
));
3797 /* insert new button */
3798 infoPtr
->buttons
[nIndex
].iBitmap
= lpTbb
->iBitmap
;
3799 infoPtr
->buttons
[nIndex
].idCommand
= lpTbb
->idCommand
;
3800 infoPtr
->buttons
[nIndex
].fsState
= lpTbb
->fsState
;
3801 infoPtr
->buttons
[nIndex
].fsStyle
= lpTbb
->fsStyle
;
3802 infoPtr
->buttons
[nIndex
].dwData
= lpTbb
->dwData
;
3803 /* if passed string and not index, then add string */
3804 if(HIWORD(lpTbb
->iString
) && lpTbb
->iString
!=-1) {
3806 Str_SetPtrW((LPWSTR
*)&infoPtr
->buttons
[nIndex
].iString
, (LPWSTR
)lpTbb
->iString
);
3808 Str_SetPtrAtoW((LPWSTR
*)&infoPtr
->buttons
[nIndex
].iString
, (LPCSTR
)lpTbb
->iString
);
3811 infoPtr
->buttons
[nIndex
].iString
= lpTbb
->iString
;
3813 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3815 if (infoPtr
->nNumStrings
> 0)
3816 TOOLBAR_CalcToolbar(hwnd
);
3818 TOOLBAR_LayoutToolbar(hwnd
);
3819 TOOLBAR_AutoSize (hwnd
);
3821 InvalidateRect (hwnd
, NULL
, TRUE
);
3826 /* << TOOLBAR_InsertMarkHitTest >> */
3830 TOOLBAR_IsButtonChecked (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3832 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3835 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3839 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3844 TOOLBAR_IsButtonEnabled (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3846 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3849 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3853 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3858 TOOLBAR_IsButtonHidden (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3860 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3863 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3867 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3872 TOOLBAR_IsButtonHighlighted (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3874 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3877 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3881 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3886 TOOLBAR_IsButtonIndeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3888 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3891 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3895 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3900 TOOLBAR_IsButtonPressed (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3902 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3905 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3909 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3914 TOOLBAR_LoadImages (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3917 tbab
.hInst
= (HINSTANCE
)lParam
;
3920 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", hwnd
, tbab
.hInst
, tbab
.nID
);
3922 return TOOLBAR_AddBitmap(hwnd
, 0, (LPARAM
)&tbab
);
3927 TOOLBAR_MapAccelerator (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3929 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3930 WCHAR wAccel
= (WCHAR
)wParam
;
3931 UINT
* pIDButton
= (UINT
*)lParam
;
3932 WCHAR wszAccel
[] = {'&',wAccel
,0};
3935 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3936 hwnd
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3938 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3940 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3941 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3942 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3944 int iLen
= strlenW(wszAccel
);
3945 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3952 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3957 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
3959 *pIDButton
= btnPtr
->idCommand
;
3971 TOOLBAR_MarkButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3973 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3976 TBUTTON_INFO
*btnPtr
;
3978 TRACE("hwnd = %p, wParam = %ld, lParam = 0x%08lx\n", hwnd
, wParam
, lParam
);
3980 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3984 btnPtr
= &infoPtr
->buttons
[nIndex
];
3985 oldState
= btnPtr
->fsState
;
3988 btnPtr
->fsState
|= TBSTATE_MARKED
;
3990 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
3992 if(oldState
!= btnPtr
->fsState
)
3993 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3999 /* fixes up an index of a button affected by a move */
4000 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
4004 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
4006 else if (*pIndex
== nIndex
)
4007 *pIndex
= nMoveIndex
;
4011 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
4013 else if (*pIndex
== nIndex
)
4014 *pIndex
= nMoveIndex
;
4020 TOOLBAR_MoveButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4022 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4025 INT nMoveIndex
= (INT
)lParam
;
4026 TBUTTON_INFO button
;
4028 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd
, wParam
, lParam
);
4030 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, TRUE
);
4031 if ((nIndex
== -1) || (nMoveIndex
< 0))
4034 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
4035 nMoveIndex
= infoPtr
->nNumButtons
- 1;
4037 button
= infoPtr
->buttons
[nIndex
];
4039 /* move button right */
4040 if (nIndex
< nMoveIndex
)
4042 nCount
= nMoveIndex
- nIndex
;
4043 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
4044 infoPtr
->buttons
[nMoveIndex
] = button
;
4046 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
4047 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
4048 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
4049 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
4051 else if (nIndex
> nMoveIndex
) /* move button left */
4053 nCount
= nIndex
- nMoveIndex
;
4054 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
4055 infoPtr
->buttons
[nMoveIndex
] = button
;
4057 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
4058 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
4059 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
4060 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
4063 TOOLBAR_LayoutToolbar(hwnd
);
4064 TOOLBAR_AutoSize(hwnd
);
4065 InvalidateRect(hwnd
, NULL
, TRUE
);
4072 TOOLBAR_PressButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4074 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4075 TBUTTON_INFO
*btnPtr
;
4079 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4083 btnPtr
= &infoPtr
->buttons
[nIndex
];
4084 oldState
= btnPtr
->fsState
;
4085 if (LOWORD(lParam
) == FALSE
)
4086 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
4088 btnPtr
->fsState
|= TBSTATE_PRESSED
;
4090 if(oldState
!= btnPtr
->fsState
)
4091 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4096 /* FIXME: there might still be some confusion her between number of buttons
4097 * and number of bitmaps */
4099 TOOLBAR_ReplaceBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4101 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4102 LPTBREPLACEBITMAP lpReplace
= (LPTBREPLACEBITMAP
) lParam
;
4104 int i
= 0, nOldButtons
= 0, pos
= 0;
4105 int nOldBitmaps
, nNewBitmaps
= 0;
4106 HIMAGELIST himlDef
= 0;
4108 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4109 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
4110 lpReplace
->nButtons
);
4112 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4114 FIXME("changing standard bitmaps not implemented\n");
4117 else if (lpReplace
->hInstOld
!= 0)
4118 FIXME("resources not in the current module not implemented\n");
4120 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4121 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4122 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4123 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4124 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4126 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4127 nOldButtons
= tbi
->nButtons
;
4128 tbi
->nButtons
= lpReplace
->nButtons
;
4129 tbi
->hInst
= lpReplace
->hInstNew
;
4130 tbi
->nID
= lpReplace
->nIDNew
;
4131 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4134 pos
+= tbi
->nButtons
;
4137 if (nOldButtons
== 0)
4139 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4143 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4146 if (lpReplace
->hInstNew
)
4147 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4149 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4151 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4152 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4154 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4156 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4157 ImageList_Remove(himlDef
, i
);
4161 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4162 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4163 DeleteObject(hBitmap
);
4166 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4168 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4169 pos
, nOldBitmaps
, nNewBitmaps
);
4171 InvalidateRect(hwnd
, NULL
, TRUE
);
4176 /* helper for TOOLBAR_SaveRestoreW */
4178 TOOLBAR_Save(const TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4180 FIXME("save to %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4181 debugstr_w(lpSave
->pszValueName
));
4187 /* helper for TOOLBAR_Restore */
4189 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4193 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4195 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4198 Free(infoPtr
->buttons
);
4199 infoPtr
->buttons
= NULL
;
4200 infoPtr
->nNumButtons
= 0;
4204 /* helper for TOOLBAR_SaveRestoreW */
4206 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4215 /* restore toolbar information */
4216 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4217 debugstr_w(lpSave
->pszValueName
));
4219 memset(&nmtbr
, 0, sizeof(nmtbr
));
4221 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4222 KEY_QUERY_VALUE
, &hkey
);
4224 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4226 if (!res
&& dwType
!= REG_BINARY
)
4227 res
= ERROR_FILE_NOT_FOUND
;
4230 nmtbr
.pData
= Alloc(dwSize
);
4231 nmtbr
.cbData
= dwSize
;
4232 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4235 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4236 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4239 nmtbr
.pCurrent
= nmtbr
.pData
;
4241 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4242 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4244 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4248 /* remove all existing buttons as this function is designed to
4249 * restore the toolbar to a previously saved state */
4250 TOOLBAR_DeleteAllButtons(infoPtr
);
4252 for (i
= 0; i
< nmtbr
.cButtons
; i
++)
4255 nmtbr
.tbButton
.iBitmap
= -1;
4256 nmtbr
.tbButton
.fsState
= 0;
4257 nmtbr
.tbButton
.fsStyle
= 0;
4258 nmtbr
.tbButton
.idCommand
= 0;
4259 if (*nmtbr
.pCurrent
== (DWORD
)-1)
4262 nmtbr
.tbButton
.fsStyle
= TBSTYLE_SEP
;
4263 nmtbr
.tbButton
.iBitmap
= SEPARATOR_WIDTH
;
4265 else if (*nmtbr
.pCurrent
== (DWORD
)-2)
4267 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4269 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4273 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4275 /* can't contain real string as we don't know whether
4276 * the client put an ANSI or Unicode string in there */
4277 if (HIWORD(nmtbr
.tbButton
.iString
))
4278 nmtbr
.tbButton
.iString
= 0;
4280 TOOLBAR_InsertButtonT(infoPtr
->hwndSelf
, -1,
4281 (LPARAM
)&nmtbr
.tbButton
, TRUE
);
4284 /* do legacy notifications */
4285 if (infoPtr
->iVersion
< 5)
4287 /* FIXME: send TBN_BEGINADJUST */
4288 FIXME("send TBN_GETBUTTONINFO for each button\n");
4289 /* FIXME: send TBN_ENDADJUST */
4292 /* remove all uninitialised buttons
4293 * note: loop backwards to avoid having to fixup i on a
4295 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4296 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4297 TOOLBAR_DeleteButton(infoPtr
->hwndSelf
, i
, 0);
4299 /* only indicate success if at least one button survived */
4300 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4311 TOOLBAR_SaveRestoreW (HWND hwnd
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4313 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4315 if (lpSave
== NULL
) return 0;
4318 return TOOLBAR_Save(infoPtr
, lpSave
);
4320 return TOOLBAR_Restore(infoPtr
, lpSave
);
4325 TOOLBAR_SaveRestoreA (HWND hwnd
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4327 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4328 TBSAVEPARAMSW SaveW
;
4332 if (lpSave
== NULL
) return 0;
4334 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4335 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4336 if (pszSubKey
) goto exit
;
4337 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4339 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4340 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4341 if (!pszValueName
) goto exit
;
4342 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4344 SaveW
.pszValueName
= pszValueName
;
4345 SaveW
.pszSubKey
= pszSubKey
;
4346 SaveW
.hkr
= lpSave
->hkr
;
4347 result
= TOOLBAR_SaveRestoreW(hwnd
, wParam
, &SaveW
);
4350 Free (pszValueName
);
4358 TOOLBAR_SetAnchorHighlight (HWND hwnd
, WPARAM wParam
)
4360 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4361 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4363 TRACE("hwnd=%p, bAnchor = %s\n", hwnd
, wParam
? "TRUE" : "FALSE");
4365 infoPtr
->bAnchor
= (BOOL
)wParam
;
4367 /* Native does not remove the hot effect from an already hot button */
4369 return (LRESULT
)bOldAnchor
;
4374 TOOLBAR_SetBitmapSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4376 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4377 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4379 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd
, wParam
, lParam
);
4382 FIXME("wParam is %ld. Perhaps image list index?\n", wParam
);
4384 if (LOWORD(lParam
) == 0)
4385 lParam
= MAKELPARAM(1, HIWORD(lParam
));
4387 if (HIWORD(lParam
)==0)
4388 lParam
= MAKELPARAM(LOWORD(lParam
), 1);
4390 if (infoPtr
->nNumButtons
> 0)
4391 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4392 infoPtr
->nNumButtons
,
4393 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
4394 LOWORD(lParam
), HIWORD(lParam
));
4396 infoPtr
->nBitmapWidth
= (INT
)LOWORD(lParam
);
4397 infoPtr
->nBitmapHeight
= (INT
)HIWORD(lParam
);
4399 if ((himlDef
== infoPtr
->himlInt
) &&
4400 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4402 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4403 infoPtr
->nBitmapHeight
);
4406 TOOLBAR_CalcToolbar(hwnd
);
4407 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4413 TOOLBAR_SetButtonInfoA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4415 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4416 LPTBBUTTONINFOA lptbbi
= (LPTBBUTTONINFOA
)lParam
;
4417 TBUTTON_INFO
*btnPtr
;
4423 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOA
))
4426 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4427 lptbbi
->dwMask
& 0x80000000);
4431 btnPtr
= &infoPtr
->buttons
[nIndex
];
4432 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4433 btnPtr
->idCommand
= lptbbi
->idCommand
;
4434 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4435 btnPtr
->iBitmap
= lptbbi
->iImage
;
4436 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4437 btnPtr
->dwData
= lptbbi
->lParam
;
4438 if (lptbbi
->dwMask
& TBIF_SIZE
)
4439 btnPtr
->cx
= lptbbi
->cx
;
4440 if (lptbbi
->dwMask
& TBIF_STATE
)
4441 btnPtr
->fsState
= lptbbi
->fsState
;
4442 if (lptbbi
->dwMask
& TBIF_STYLE
)
4443 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4445 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4446 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4447 /* iString is index, zero it to make Str_SetPtr succeed */
4450 Str_SetPtrAtoW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4453 /* save the button rect to see if we need to redraw the whole toolbar */
4454 oldBtnRect
= btnPtr
->rect
;
4455 TOOLBAR_CalcToolbar(hwnd
);
4457 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4458 InvalidateRect(hwnd
, NULL
, TRUE
);
4460 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4467 TOOLBAR_SetButtonInfoW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4469 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4470 LPTBBUTTONINFOW lptbbi
= (LPTBBUTTONINFOW
)lParam
;
4471 TBUTTON_INFO
*btnPtr
;
4477 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4480 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4481 lptbbi
->dwMask
& 0x80000000);
4485 btnPtr
= &infoPtr
->buttons
[nIndex
];
4486 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4487 btnPtr
->idCommand
= lptbbi
->idCommand
;
4488 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4489 btnPtr
->iBitmap
= lptbbi
->iImage
;
4490 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4491 btnPtr
->dwData
= lptbbi
->lParam
;
4492 if (lptbbi
->dwMask
& TBIF_SIZE
)
4493 btnPtr
->cx
= lptbbi
->cx
;
4494 if (lptbbi
->dwMask
& TBIF_STATE
)
4495 btnPtr
->fsState
= lptbbi
->fsState
;
4496 if (lptbbi
->dwMask
& TBIF_STYLE
)
4497 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4499 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4500 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4501 /* iString is index, zero it to make Str_SetPtr succeed */
4503 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4506 /* save the button rect to see if we need to redraw the whole toolbar */
4507 oldBtnRect
= btnPtr
->rect
;
4508 TOOLBAR_CalcToolbar(hwnd
);
4510 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4511 InvalidateRect(hwnd
, NULL
, TRUE
);
4513 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4520 TOOLBAR_SetButtonSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4522 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4523 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4525 if ((cx
< 0) || (cy
< 0))
4527 ERR("invalid parameter 0x%08x\n", (DWORD
)lParam
);
4531 TRACE("%p, cx = %d, cy = %d\n", hwnd
, cx
, cy
);
4533 /* The documentation claims you can only change the button size before
4534 * any button has been added. But this is wrong.
4535 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4536 * it to the toolbar, and it checks that the return value is nonzero - mjm
4537 * Further testing shows that we must actually perform the change too.
4540 * The documentation also does not mention that if 0 is supplied for
4541 * either size, the system changes it to the default of 24 wide and
4542 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4544 if (cx
== 0) cx
= 24;
4545 if (cy
== 0) cx
= 22;
4547 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4548 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4550 infoPtr
->nButtonWidth
= cx
;
4551 infoPtr
->nButtonHeight
= cy
;
4553 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
4554 TOOLBAR_LayoutToolbar(hwnd
);
4560 TOOLBAR_SetButtonWidth (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4562 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4564 /* if setting to current values, ignore */
4565 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4566 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4567 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4568 infoPtr
->cxMin
, infoPtr
->cxMax
);
4572 /* save new values */
4573 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4574 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4576 /* otherwise we need to recalc the toolbar and in some cases
4577 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4578 which doesn't actually draw - GA). */
4579 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4580 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4582 TOOLBAR_CalcToolbar (hwnd
);
4584 InvalidateRect (hwnd
, NULL
, TRUE
);
4591 TOOLBAR_SetCmdId (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4593 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4594 INT nIndex
= (INT
)wParam
;
4596 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4599 infoPtr
->buttons
[nIndex
].idCommand
= (INT
)lParam
;
4601 if (infoPtr
->hwndToolTip
) {
4603 FIXME("change tool tip!\n");
4612 TOOLBAR_SetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4614 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4615 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4616 HIMAGELIST himlTemp
;
4619 if (infoPtr
->iVersion
>= 5)
4622 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4623 &infoPtr
->cimlDis
, himl
, id
);
4625 /* FIXME: redraw ? */
4627 return (LRESULT
)himlTemp
;
4632 TOOLBAR_SetDrawTextFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4634 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4637 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd
, (DWORD
)wParam
, (DWORD
)lParam
);
4639 dwTemp
= infoPtr
->dwDTFlags
;
4640 infoPtr
->dwDTFlags
=
4641 (infoPtr
->dwDTFlags
& (DWORD
)wParam
) | (DWORD
)lParam
;
4643 return (LRESULT
)dwTemp
;
4646 /* This function differs a bit from what MSDN says it does:
4647 * 1. lParam contains extended style flags to OR with current style
4648 * (MSDN isn't clear on the OR bit)
4649 * 2. wParam appears to contain extended style flags to be reset
4650 * (MSDN says that this parameter is reserved)
4653 TOOLBAR_SetExtendedStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4655 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4658 dwTemp
= infoPtr
->dwExStyle
;
4659 infoPtr
->dwExStyle
&= ~wParam
;
4660 infoPtr
->dwExStyle
|= (DWORD
)lParam
;
4662 TRACE("new style 0x%08x\n", infoPtr
->dwExStyle
);
4664 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4665 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4666 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4668 TOOLBAR_CalcToolbar (hwnd
);
4670 TOOLBAR_AutoSize(hwnd
);
4672 InvalidateRect(hwnd
, NULL
, TRUE
);
4674 return (LRESULT
)dwTemp
;
4679 TOOLBAR_SetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4681 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4682 HIMAGELIST himlTemp
;
4683 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4686 if (infoPtr
->iVersion
>= 5)
4689 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd
, himl
, id
);
4691 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4692 &infoPtr
->cimlHot
, himl
, id
);
4694 /* FIXME: redraw ? */
4696 return (LRESULT
)himlTemp
;
4700 /* Makes previous hot button no longer hot, makes the specified
4701 * button hot and sends appropriate notifications. dwReason is one or
4702 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4703 * NOTE 1: this function does not validate nHit
4704 * NOTE 2: the name of this function is completely made up and
4705 * not based on any documentation from Microsoft. */
4707 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4709 if (infoPtr
->nHotItem
!= nHit
)
4711 NMTBHOTITEM nmhotitem
;
4712 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4714 nmhotitem
.dwFlags
= dwReason
;
4715 if(infoPtr
->nHotItem
>= 0)
4717 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4718 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4722 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4723 nmhotitem
.idOld
= 0;
4728 btnPtr
= &infoPtr
->buttons
[nHit
];
4729 nmhotitem
.idNew
= btnPtr
->idCommand
;
4733 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4734 nmhotitem
.idNew
= 0;
4737 /* now change the hot and invalidate the old and new buttons - if the
4739 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4742 oldBtnPtr
->bHot
= FALSE
;
4743 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4745 /* setting disabled buttons as hot fails even if the notify contains the button id */
4746 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4747 btnPtr
->bHot
= TRUE
;
4748 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4749 infoPtr
->nHotItem
= nHit
;
4752 infoPtr
->nHotItem
= -1;
4758 TOOLBAR_SetHotItem (HWND hwnd
, WPARAM wParam
)
4760 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4761 INT nOldHotItem
= infoPtr
->nHotItem
;
4763 TRACE("hwnd = %p, nHit = %d\n", hwnd
, (INT
)wParam
);
4765 if ((INT
)wParam
> infoPtr
->nNumButtons
)
4766 return infoPtr
->nHotItem
;
4768 if ((INT
)wParam
< 0)
4771 /* NOTE: an application can still remove the hot item even if anchor
4772 * highlighting is enabled */
4774 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, HICF_OTHER
);
4776 if (nOldHotItem
< 0)
4779 return (LRESULT
)nOldHotItem
;
4784 TOOLBAR_SetImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4786 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4787 HIMAGELIST himlTemp
;
4788 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4789 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4792 if (infoPtr
->iVersion
>= 5)
4795 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4796 &infoPtr
->cimlDef
, himl
, id
);
4798 infoPtr
->nNumBitmaps
= 0;
4799 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4800 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4802 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4803 &infoPtr
->nBitmapHeight
))
4805 infoPtr
->nBitmapWidth
= 1;
4806 infoPtr
->nBitmapHeight
= 1;
4808 TOOLBAR_CalcToolbar(hwnd
);
4809 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4810 TOOLBAR_SetButtonSize(hwnd
, 0, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4812 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4813 hwnd
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4814 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4816 InvalidateRect(hwnd
, NULL
, TRUE
);
4818 return (LRESULT
)himlTemp
;
4823 TOOLBAR_SetIndent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4825 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4827 infoPtr
->nIndent
= (INT
)wParam
;
4831 /* process only on indent changing */
4832 if(infoPtr
->nIndent
!= (INT
)wParam
)
4834 infoPtr
->nIndent
= (INT
)wParam
;
4835 TOOLBAR_CalcToolbar (hwnd
);
4836 InvalidateRect(hwnd
, NULL
, FALSE
);
4844 TOOLBAR_SetInsertMark (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4846 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4847 TBINSERTMARK
*lptbim
= (TBINSERTMARK
*)lParam
;
4849 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd
, lptbim
->iButton
, lptbim
->dwFlags
);
4851 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4853 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4857 if ((lptbim
->iButton
== -1) ||
4858 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4859 (lptbim
->iButton
>= 0)))
4861 infoPtr
->tbim
= *lptbim
;
4862 /* FIXME: don't need to update entire toolbar */
4863 InvalidateRect(hwnd
, NULL
, TRUE
);
4866 ERR("Invalid button index %d\n", lptbim
->iButton
);
4873 TOOLBAR_SetInsertMarkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4875 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4877 infoPtr
->clrInsertMark
= (COLORREF
)lParam
;
4879 /* FIXME: don't need to update entire toolbar */
4880 InvalidateRect(hwnd
, NULL
, TRUE
);
4887 TOOLBAR_SetMaxTextRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4889 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4891 infoPtr
->nMaxTextRows
= (INT
)wParam
;
4893 TOOLBAR_CalcToolbar(hwnd
);
4898 /* MSDN gives slightly wrong info on padding.
4899 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4900 * 2. It is not used to create a blank area between the edge of the button
4901 * and the text or image if TBSTYLE_LIST is set. It is used to control
4902 * the gap between the image and text.
4903 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4904 * to control the bottom and right borders [with the border being
4905 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4906 * is shared evenly on both sides of the button.
4907 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4910 TOOLBAR_SetPadding (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4912 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4915 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4916 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4917 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4918 TRACE("cx=%d, cy=%d\n",
4919 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4920 return (LRESULT
) oldPad
;
4925 TOOLBAR_SetParent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4927 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4932 hwndOldNotify
= infoPtr
->hwndNotify
;
4933 infoPtr
->hwndNotify
= (HWND
)wParam
;
4935 return (LRESULT
)hwndOldNotify
;
4940 TOOLBAR_SetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4942 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4943 LPRECT lprc
= (LPRECT
)lParam
;
4944 int rows
= LOWORD(wParam
);
4945 BOOL bLarger
= HIWORD(wParam
);
4949 TRACE("Setting rows to %d (%d)\n", rows
, bLarger
);
4951 if(infoPtr
->nRows
!= rows
)
4953 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
;
4954 int curColumn
= 0; /* Current column */
4955 int curRow
= 0; /* Current row */
4956 int hidden
= 0; /* Number of hidden buttons */
4957 int seps
= 0; /* Number of separators */
4958 int idealWrap
= 0; /* Ideal wrap point */
4963 Calculate new size and wrap points - Under windows, setrows will
4964 change the dimensions if needed to show the number of requested
4965 rows (if CCS_NORESIZE is set), or will take up the whole window
4966 (if no CCS_NORESIZE).
4968 Basic algorithm - If N buttons, and y rows requested, each row
4969 contains N/y buttons.
4971 FIXME: Handling of separators not obvious from testing results
4972 FIXME: Take width of window into account?
4975 /* Loop through the buttons one by one counting key items */
4976 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4978 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
4979 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4981 else if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
4985 /* FIXME: Separators make this quite complex */
4986 if (seps
) FIXME("Separators unhandled\n");
4988 /* Round up so more per line, ie less rows */
4989 idealWrap
= (infoPtr
->nNumButtons
- hidden
+ (rows
-1)) / rows
;
4991 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4992 achieve the requested number of rows. */
4993 if (bLarger
&& idealWrap
> 1)
4995 int resRows
= (infoPtr
->nNumButtons
+ (idealWrap
-1)) / idealWrap
;
4996 int moreRows
= (infoPtr
->nNumButtons
+ (idealWrap
-2)) / (idealWrap
-1);
4998 if (resRows
< rows
&& moreRows
> rows
)
5001 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap
);
5005 curColumn
= curRow
= 0;
5007 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap
,
5008 infoPtr
->nNumButtons
, hidden
, rows
);
5010 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
5012 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
5015 /* Step on, wrap if necessary or flag next to wrap */
5024 if (curColumn
> (idealWrap
-1)) {
5026 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
5030 TRACE("Result - %d rows\n", curRow
+ 1);
5032 /* recalculate toolbar */
5033 TOOLBAR_CalcToolbar (hwnd
);
5035 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
5036 if NORESIZE is NOT set, then the toolbar will always be resized to
5037 take up the whole window. With it set, sizing needs to be manual. */
5038 if (infoPtr
->dwStyle
& CCS_NORESIZE
) {
5039 SetWindowPos(hwnd
, NULL
, 0, 0,
5040 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
5041 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
,
5045 /* repaint toolbar */
5046 InvalidateRect(hwnd
, NULL
, TRUE
);
5049 /* return bounding rectangle */
5051 lprc
->left
= infoPtr
->rcBound
.left
;
5052 lprc
->right
= infoPtr
->rcBound
.right
;
5053 lprc
->top
= infoPtr
->rcBound
.top
;
5054 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
5062 TOOLBAR_SetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5064 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5065 TBUTTON_INFO
*btnPtr
;
5068 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
5072 btnPtr
= &infoPtr
->buttons
[nIndex
];
5074 /* if hidden state has changed the invalidate entire window and recalc */
5075 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
5076 btnPtr
->fsState
= LOWORD(lParam
);
5077 TOOLBAR_CalcToolbar (hwnd
);
5078 InvalidateRect(hwnd
, 0, TRUE
);
5082 /* process state changing if current state doesn't match new state */
5083 if(btnPtr
->fsState
!= LOWORD(lParam
))
5085 btnPtr
->fsState
= LOWORD(lParam
);
5086 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5094 TOOLBAR_SetStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5096 SetWindowLongW(hwnd
, GWL_STYLE
, lParam
);
5102 static inline LRESULT
5103 TOOLBAR_SetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5105 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5107 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd
, (HWND
)wParam
, lParam
);
5109 infoPtr
->hwndToolTip
= (HWND
)wParam
;
5115 TOOLBAR_SetUnicodeFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5117 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5120 TRACE("%s hwnd=%p\n",
5121 ((BOOL
)wParam
) ? "TRUE" : "FALSE", hwnd
);
5123 bTemp
= infoPtr
->bUnicode
;
5124 infoPtr
->bUnicode
= (BOOL
)wParam
;
5131 TOOLBAR_GetColorScheme (HWND hwnd
, LPCOLORSCHEME lParam
)
5133 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5135 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
5136 comctl32_color
.clrBtnHighlight
:
5137 infoPtr
->clrBtnHighlight
;
5138 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
5139 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
5145 TOOLBAR_SetColorScheme (HWND hwnd
, const COLORSCHEME
*lParam
)
5147 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5149 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5150 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
5151 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
5153 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
5154 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
5155 InvalidateRect(hwnd
, NULL
, TRUE
);
5161 TOOLBAR_SetVersion (HWND hwnd
, INT iVersion
)
5163 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5164 INT iOldVersion
= infoPtr
->iVersion
;
5166 infoPtr
->iVersion
= iVersion
;
5168 if (infoPtr
->iVersion
>= 5)
5169 TOOLBAR_SetUnicodeFormat(hwnd
, (WPARAM
)TRUE
, (LPARAM
)0);
5176 TOOLBAR_GetStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5178 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5179 WORD iString
= HIWORD(wParam
);
5180 WORD buffersize
= LOWORD(wParam
);
5181 LPSTR str
= (LPSTR
)lParam
;
5184 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, buffersize
, str
);
5186 if (iString
< infoPtr
->nNumStrings
)
5188 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
5190 TRACE("returning %s\n", debugstr_a(str
));
5193 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5200 TOOLBAR_GetStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5202 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5203 WORD iString
= HIWORD(wParam
);
5204 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5205 LPWSTR str
= (LPWSTR
)lParam
;
5208 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, LOWORD(wParam
), str
);
5210 if (iString
< infoPtr
->nNumStrings
)
5212 len
= min(len
, strlenW(infoPtr
->strings
[iString
]));
5213 ret
= (len
+1)*sizeof(WCHAR
);
5214 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5217 TRACE("returning %s\n", debugstr_w(str
));
5220 ERR("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5225 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5226 * is the maximum size of the toolbar? */
5227 static LRESULT
TOOLBAR_Unkwn45D(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5229 SIZE
* pSize
= (SIZE
*)lParam
;
5230 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5235 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5236 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5237 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5240 TOOLBAR_Unkwn45E (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5242 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5243 INT nOldHotItem
= infoPtr
->nHotItem
;
5245 TRACE("old item=%d, new item=%d, flags=%08x\n",
5246 nOldHotItem
, infoPtr
->nHotItem
, (DWORD
)lParam
);
5248 if ((INT
) wParam
< 0 || (INT
)wParam
> infoPtr
->nNumButtons
)
5251 /* NOTE: an application can still remove the hot item even if anchor
5252 * highlighting is enabled */
5254 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, lParam
);
5258 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5261 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5262 * which controls the amount of spacing between the image and the text
5263 * of buttons for TBSTYLE_LIST toolbars. */
5264 static LRESULT
TOOLBAR_Unkwn460(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5266 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5268 TRACE("hwnd=%p iListGap=%ld\n", hwnd
, wParam
);
5271 FIXME("lParam = 0x%08lx. Please report\n", lParam
);
5273 infoPtr
->iListGap
= (INT
)wParam
;
5275 InvalidateRect(hwnd
, NULL
, TRUE
);
5280 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5281 * of image lists associated with the various states. */
5282 static LRESULT
TOOLBAR_Unkwn462(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5284 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5286 TRACE("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5288 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5292 TOOLBAR_Unkwn463 (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5294 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5295 LPSIZE lpsize
= (LPSIZE
)lParam
;
5301 * Testing shows the following:
5302 * wParam = 0 adjust cx value
5303 * = 1 set cy value to max size.
5304 * lParam pointer to SIZE structure
5307 TRACE("[0463] wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5308 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5312 if (lpsize
->cx
== -1) {
5313 /* **** this is wrong, native measures each button and sets it */
5314 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5316 else if(HIWORD(lpsize
->cx
)) {
5318 HWND hwndParent
= GetParent(hwnd
);
5320 GetWindowRect(hwnd
, &rc
);
5321 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5322 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc
));
5323 lpsize
->cx
= max(rc
.right
-rc
.left
,
5324 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5327 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5331 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5334 ERR("Unknown wParam %ld for Toolbar message [0463]. Please report\n",
5338 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5339 lpsize
->cx
, lpsize
->cy
);
5343 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5345 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5347 InvalidateRect(hwnd
, NULL
, TRUE
);
5353 TOOLBAR_Create (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5355 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5356 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
5359 TRACE("hwnd = %p\n", hwnd
);
5361 /* initialize info structure */
5362 infoPtr
->nButtonWidth
= 23;
5363 infoPtr
->nButtonHeight
= 22;
5364 infoPtr
->nBitmapHeight
= 16;
5365 infoPtr
->nBitmapWidth
= 16;
5367 infoPtr
->nMaxTextRows
= 1;
5368 infoPtr
->cxMin
= -1;
5369 infoPtr
->cxMax
= -1;
5370 infoPtr
->nNumBitmaps
= 0;
5371 infoPtr
->nNumStrings
= 0;
5373 infoPtr
->bCaptured
= FALSE
;
5374 infoPtr
->nButtonDown
= -1;
5375 infoPtr
->nButtonDrag
= -1;
5376 infoPtr
->nOldHit
= -1;
5377 infoPtr
->nHotItem
= -1;
5378 infoPtr
->hwndNotify
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
5379 infoPtr
->dwDTFlags
= (dwStyle
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
5380 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
5381 infoPtr
->bDragOutSent
= FALSE
;
5382 infoPtr
->iVersion
= 0;
5383 infoPtr
->hwndSelf
= hwnd
;
5384 infoPtr
->bDoRedraw
= TRUE
;
5385 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
5386 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
5387 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
5388 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
5389 infoPtr
->iListGap
= DEFLISTGAP
;
5390 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
5391 infoPtr
->dwStyle
= dwStyle
;
5392 infoPtr
->tbim
.iButton
= -1;
5393 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5394 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5395 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, (LPARAM
)NF_REQUERY
));
5396 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5398 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5399 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5401 OpenThemeData (hwnd
, themeClass
);
5403 TOOLBAR_CheckStyle (hwnd
, dwStyle
);
5410 TOOLBAR_Destroy (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5412 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5414 /* delete tooltip control */
5415 if (infoPtr
->hwndToolTip
)
5416 DestroyWindow (infoPtr
->hwndToolTip
);
5418 /* delete temporary buffer for tooltip text */
5419 Free (infoPtr
->pszTooltipText
);
5420 Free (infoPtr
->bitmaps
); /* bitmaps list */
5422 /* delete button data */
5423 Free (infoPtr
->buttons
);
5425 /* delete strings */
5426 if (infoPtr
->strings
) {
5428 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5429 Free (infoPtr
->strings
[i
]);
5431 Free (infoPtr
->strings
);
5434 /* destroy internal image list */
5435 if (infoPtr
->himlInt
)
5436 ImageList_Destroy (infoPtr
->himlInt
);
5438 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5439 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5440 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5442 /* delete default font */
5443 DeleteObject (infoPtr
->hDefaultFont
);
5445 CloseThemeData (GetWindowTheme (hwnd
));
5447 /* free toolbar info data */
5449 SetWindowLongPtrW (hwnd
, 0, 0);
5456 TOOLBAR_EraseBackground (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5458 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5459 NMTBCUSTOMDRAW tbcd
;
5462 HTHEME theme
= GetWindowTheme (hwnd
);
5463 DWORD dwEraseCustDraw
= 0;
5465 /* the app has told us not to redraw the toolbar */
5466 if (!infoPtr
->bDoRedraw
)
5469 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5470 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5471 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5472 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5473 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5474 dwEraseCustDraw
= ntfret
& 0xffff;
5476 /* FIXME: in general the return flags *can* be or'ed together */
5477 switch (dwEraseCustDraw
)
5479 case CDRF_DODEFAULT
:
5481 case CDRF_SKIPDEFAULT
:
5484 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5489 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5490 * to my parent for processing.
5492 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5494 HDC hdc
= (HDC
)wParam
;
5499 parent
= GetParent(hwnd
);
5500 MapWindowPoints(hwnd
, parent
, &pt
, 1);
5501 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5502 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5503 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5506 ret
= DefWindowProcW (hwnd
, WM_ERASEBKGND
, wParam
, lParam
);
5508 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5509 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5510 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5511 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5512 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5513 dwEraseCustDraw
= ntfret
& 0xffff;
5514 switch (dwEraseCustDraw
)
5516 case CDRF_DODEFAULT
:
5518 case CDRF_SKIPDEFAULT
:
5521 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5530 TOOLBAR_GetFont (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5532 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5534 return (LRESULT
)infoPtr
->hFont
;
5539 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5542 INT nNewHotItem
= infoPtr
->nHotItem
;
5544 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5547 if ((nNewHotItem
+ iDirection
< 0) ||
5548 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5550 NMTBWRAPHOTITEM nmtbwhi
;
5551 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5552 nmtbwhi
.iDirection
= iDirection
;
5553 nmtbwhi
.dwReason
= dwReason
;
5555 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5559 nNewHotItem
+= iDirection
;
5560 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5562 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5563 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5565 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5572 TOOLBAR_KeyDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5574 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5577 nmkey
.nVKey
= (UINT
)wParam
;
5578 nmkey
.uFlags
= HIWORD(lParam
);
5580 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5581 return DefWindowProcW(hwnd
, WM_KEYDOWN
, wParam
, lParam
);
5583 switch ((UINT
)wParam
)
5587 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5591 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5595 if ((infoPtr
->nHotItem
>= 0) &&
5596 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5598 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5599 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5610 TOOLBAR_LButtonDblClk (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5615 pt
.x
= (short)LOWORD(lParam
);
5616 pt
.y
= (short)HIWORD(lParam
);
5617 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5620 TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
5621 else if (GetWindowLongW (hwnd
, GWL_STYLE
) & CCS_ADJUSTABLE
)
5622 TOOLBAR_Customize (hwnd
);
5629 TOOLBAR_LButtonDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5631 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5632 TBUTTON_INFO
*btnPtr
;
5637 BOOL bDragKeyPressed
;
5641 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5642 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5644 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5646 if (infoPtr
->hwndToolTip
)
5647 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5648 WM_LBUTTONDOWN
, wParam
, lParam
);
5650 pt
.x
= (short)LOWORD(lParam
);
5651 pt
.y
= (short)HIWORD(lParam
);
5652 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5654 btnPtr
= &infoPtr
->buttons
[nHit
];
5656 if ((nHit
>= 0) && bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5658 infoPtr
->nButtonDrag
= nHit
;
5661 /* If drag cursor has not been loaded, load it.
5662 * Note: it doesn't need to be freed */
5664 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5665 SetCursor(hCursorDrag
);
5670 infoPtr
->nOldHit
= nHit
;
5672 CopyRect(&arrowRect
, &btnPtr
->rect
);
5673 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5675 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5676 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5677 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5678 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5679 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5680 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5684 /* draw in pressed state */
5685 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5686 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5688 btnPtr
->bDropDownPressed
= TRUE
;
5689 RedrawWindow(hwnd
,&btnPtr
->rect
,0,
5690 RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5692 memset(&nmtb
, 0, sizeof(nmtb
));
5693 nmtb
.iItem
= btnPtr
->idCommand
;
5694 nmtb
.rcButton
= btnPtr
->rect
;
5695 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5697 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5699 if (res
!= TBDDRET_TREATPRESSED
)
5703 /* redraw button in unpressed state */
5704 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5705 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5707 btnPtr
->bDropDownPressed
= FALSE
;
5708 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5710 /* find and set hot item
5711 * NOTE: native doesn't do this, but that is a bug */
5713 ScreenToClient(hwnd
, &pt
);
5714 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
5715 if (!infoPtr
->bAnchor
|| (nHit
>= 0))
5716 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5718 /* remove any left mouse button down or double-click messages
5719 * so that we can get a toggle effect on the button */
5720 while (PeekMessageW(&msg
, hwnd
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5721 PeekMessageW(&msg
, hwnd
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5726 /* otherwise drop through and process as pushed */
5728 infoPtr
->bCaptured
= TRUE
;
5729 infoPtr
->nButtonDown
= nHit
;
5730 infoPtr
->bDragOutSent
= FALSE
;
5732 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5734 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5736 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5737 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5744 memset(&nmtb
, 0, sizeof(nmtb
));
5745 nmtb
.iItem
= btnPtr
->idCommand
;
5746 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5749 nmmouse
.dwHitInfo
= nHit
;
5751 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5753 nmmouse
.dwItemSpec
= -1;
5756 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5757 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5760 ClientToScreen(hwnd
, &pt
);
5763 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5764 return DefWindowProcW(hwnd
, WM_LBUTTONDOWN
, wParam
, lParam
);
5770 TOOLBAR_LButtonUp (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5772 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5773 TBUTTON_INFO
*btnPtr
;
5777 BOOL bSendMessage
= TRUE
;
5782 if (infoPtr
->hwndToolTip
)
5783 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5784 WM_LBUTTONUP
, wParam
, lParam
);
5786 pt
.x
= (short)LOWORD(lParam
);
5787 pt
.y
= (short)HIWORD(lParam
);
5788 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5790 if (!infoPtr
->bAnchor
|| (nHit
>= 0))
5791 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5793 if (infoPtr
->nButtonDrag
>= 0) {
5797 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5800 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5802 GetClientRect(hwnd
, &rcClient
);
5803 if (PtInRect(&rcClient
, pt
))
5810 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5813 if (nButton
== infoPtr
->nButtonDrag
)
5815 /* if the button is moved sightly left and we have a
5816 * separator there then remove it */
5817 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5819 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5820 TOOLBAR_DeleteButton(hwnd
, nButton
- 1, 0);
5822 else /* else insert a separator before the dragged button */
5825 memset(&tbb
, 0, sizeof(tbb
));
5826 tbb
.fsStyle
= BTNS_SEP
;
5828 TOOLBAR_InsertButtonT(hwnd
, nButton
, (LPARAM
)&tbb
, TRUE
);
5835 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5836 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, 0);
5838 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5841 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, nButton
);
5846 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5847 TOOLBAR_DeleteButton(hwnd
, (WPARAM
)infoPtr
->nButtonDrag
, 0);
5850 /* button under cursor changed so need to re-set hot item */
5851 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5852 infoPtr
->nButtonDrag
= -1;
5854 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5856 else if (infoPtr
->nButtonDown
>= 0) {
5857 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5858 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5860 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5861 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5862 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5864 if (nOldIndex
== nHit
)
5865 bSendMessage
= FALSE
;
5866 if ((nOldIndex
!= nHit
) &&
5868 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5869 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5872 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5873 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5875 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5879 if (nOldIndex
!= -1)
5880 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5883 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5884 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5885 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5887 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5889 infoPtr
->nButtonDown
= -1;
5891 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5892 TOOLBAR_SendNotify (&hdr
, infoPtr
,
5893 NM_RELEASEDCAPTURE
);
5895 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5898 memset(&nmtb
, 0, sizeof(nmtb
));
5899 nmtb
.iItem
= btnPtr
->idCommand
;
5900 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5903 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5905 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5906 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)hwnd
);
5908 /* In case we have just been destroyed... */
5914 /* !!! Undocumented - toolbar at 4.71 level and above sends
5915 * NM_CLICK with the NMMOUSE structure. */
5916 nmmouse
.dwHitInfo
= nHit
;
5919 nmmouse
.dwItemSpec
= -1;
5922 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5923 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5926 ClientToScreen(hwnd
, &pt
);
5929 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5930 return DefWindowProcW(hwnd
, WM_LBUTTONUP
, wParam
, lParam
);
5936 TOOLBAR_RButtonUp( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5938 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5943 pt
.x
= (short)LOWORD(lParam
);
5944 pt
.y
= (short)HIWORD(lParam
);
5946 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
5947 nmmouse
.dwHitInfo
= nHit
;
5950 nmmouse
.dwItemSpec
= -1;
5952 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5953 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5956 ClientToScreen(hwnd
, &pt
);
5959 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5960 return DefWindowProcW(hwnd
, WM_RBUTTONUP
, wParam
, lParam
);
5966 TOOLBAR_RButtonDblClk( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5968 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5971 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5972 return DefWindowProcW(hwnd
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
5978 TOOLBAR_CaptureChanged(HWND hwnd
)
5980 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5981 TBUTTON_INFO
*btnPtr
;
5983 infoPtr
->bCaptured
= FALSE
;
5985 if (infoPtr
->nButtonDown
>= 0)
5987 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5988 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5990 infoPtr
->nOldHit
= -1;
5992 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5993 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5999 TOOLBAR_MouseLeave (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6001 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6003 /* don't remove hot effects when in anchor highlighting mode or when a
6004 * drop-down button is pressed */
6005 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
6007 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
6008 if (!hotBtnPtr
->bDropDownPressed
)
6009 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
6012 if (infoPtr
->nOldHit
< 0)
6015 /* If the last button we were over is depressed then make it not */
6016 /* depressed and redraw it */
6017 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
6019 TBUTTON_INFO
*btnPtr
;
6022 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6024 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6027 InflateRect (&rc1
, 1, 1);
6028 InvalidateRect (hwnd
, &rc1
, TRUE
);
6031 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
6034 ZeroMemory(&nmt
, sizeof(nmt
));
6035 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6036 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6037 infoPtr
->bDragOutSent
= TRUE
;
6040 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
6046 TOOLBAR_MouseMove (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6048 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6050 TRACKMOUSEEVENT trackinfo
;
6052 TBUTTON_INFO
*btnPtr
;
6054 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
6055 TOOLBAR_TooltipCreateControl(infoPtr
);
6057 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
6058 /* fill in the TRACKMOUSEEVENT struct */
6059 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
6060 trackinfo
.dwFlags
= TME_QUERY
;
6062 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6063 _TrackMouseEvent(&trackinfo
);
6065 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6066 if(trackinfo
.hwndTrack
!= hwnd
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
6067 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
6068 trackinfo
.hwndTrack
= hwnd
;
6070 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6071 /* and can properly deactivate the hot toolbar button */
6072 _TrackMouseEvent(&trackinfo
);
6076 if (infoPtr
->hwndToolTip
)
6077 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
6078 WM_MOUSEMOVE
, wParam
, lParam
);
6080 pt
.x
= (short)LOWORD(lParam
);
6081 pt
.y
= (short)HIWORD(lParam
);
6083 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
6085 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6086 && (!infoPtr
->bAnchor
|| (nHit
>= 0)))
6087 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
);
6089 if (infoPtr
->nOldHit
!= nHit
)
6091 if (infoPtr
->bCaptured
)
6093 if (!infoPtr
->bDragOutSent
)
6096 ZeroMemory(&nmt
, sizeof(nmt
));
6097 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6098 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6099 infoPtr
->bDragOutSent
= TRUE
;
6102 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6103 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
6104 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6105 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6107 else if (nHit
== infoPtr
->nButtonDown
) {
6108 btnPtr
->fsState
|= TBSTATE_PRESSED
;
6109 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6111 infoPtr
->nOldHit
= nHit
;
6119 static inline LRESULT
6120 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6122 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6123 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
6125 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6129 static inline LRESULT
6130 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6132 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
6133 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
6135 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
6140 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6142 TOOLBAR_INFO
*infoPtr
;
6143 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
6146 /* allocate memory for info structure */
6147 infoPtr
= (TOOLBAR_INFO
*)Alloc (sizeof(TOOLBAR_INFO
));
6148 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
6151 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
6153 infoPtr
->nWidth
= 0;
6155 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6156 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
6157 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
6158 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
6161 /* native control does:
6162 * Get a lot of colors and brushes
6164 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6165 * CreateFontIndirectW(adr1)
6166 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6167 * hdc = GetDC(toolbar)
6168 * GetSystemMetrics(0x48)
6169 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6170 * 0, 0, 0, 0, "MARLETT")
6171 * oldfnt = SelectObject(hdc, fnt2)
6172 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6173 * GetTextMetricsW(hdc, adr3)
6174 * SelectObject(hdc, oldfnt)
6175 * DeleteObject(fnt2)
6177 * InvalidateRect(toolbar, 0, 1)
6178 * SetWindowLongW(toolbar, 0, addr)
6179 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6182 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6183 * ie 2 0x4600094c 0x4600094c 0x4600894d
6184 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6185 * rebar 0x50008844 0x40008844 0x50008845
6186 * pager 0x50000844 0x40000844 0x50008845
6187 * IC35mgr 0x5400084e **nochange**
6188 * on entry to _NCCREATE 0x5400084e
6189 * rowlist 0x5400004e **nochange**
6190 * on entry to _NCCREATE 0x5400004e
6194 /* I think the code below is a bug, but it is the way that the native
6195 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6196 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6197 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6198 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6199 * Somehow, the only cases of this seem to be MFC programs.
6201 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6202 * does not occur in the WM_STYLECHANGING routine.
6203 * (Guy Albertelli 9/2001)
6206 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6207 && !(cs
->style
& TBSTYLE_TRANSPARENT
))
6208 styleadd
|= TBSTYLE_TRANSPARENT
;
6209 if (!(cs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
6210 styleadd
|= CCS_TOP
; /* default to top */
6211 SetWindowLongW (hwnd
, GWL_STYLE
, cs
->style
| styleadd
);
6214 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, lParam
);
6219 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6221 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
6225 if (dwStyle
& WS_MINIMIZE
)
6226 return 0; /* Nothing to do */
6228 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
6230 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
6233 if (!(dwStyle
& CCS_NODIVIDER
))
6235 GetWindowRect (hwnd
, &rcWindow
);
6236 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
6237 if( dwStyle
& WS_BORDER
)
6238 OffsetRect (&rcWindow
, 1, 1);
6239 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6242 ReleaseDC( hwnd
, hdc
);
6248 /* handles requests from the tooltip control on what text to display */
6249 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6251 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6253 TRACE("button index = %d\n", index
);
6255 Free (infoPtr
->pszTooltipText
);
6256 infoPtr
->pszTooltipText
= NULL
;
6261 if (infoPtr
->bUnicode
)
6263 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6264 NMTBGETINFOTIPW tbgit
;
6265 unsigned int len
; /* in chars */
6267 wszBuffer
[0] = '\0';
6268 wszBuffer
[INFOTIPSIZE
] = '\0';
6270 tbgit
.pszText
= wszBuffer
;
6271 tbgit
.cchTextMax
= INFOTIPSIZE
;
6272 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6273 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6275 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6277 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6279 len
= strlenW(tbgit
.pszText
);
6280 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6282 /* need to allocate temporary buffer in infoPtr as there
6283 * isn't enough space in buffer passed to us by the
6284 * tooltip control */
6285 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6286 if (infoPtr
->pszTooltipText
)
6288 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6289 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6295 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6301 CHAR szBuffer
[INFOTIPSIZE
+1];
6302 NMTBGETINFOTIPA tbgit
;
6303 unsigned int len
; /* in chars */
6306 szBuffer
[INFOTIPSIZE
] = '\0';
6308 tbgit
.pszText
= szBuffer
;
6309 tbgit
.cchTextMax
= INFOTIPSIZE
;
6310 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6311 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6313 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6315 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6317 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6318 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]))
6320 /* need to allocate temporary buffer in infoPtr as there
6321 * isn't enough space in buffer passed to us by the
6322 * tooltip control */
6323 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6324 if (infoPtr
->pszTooltipText
)
6326 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6327 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6331 else if (tbgit
.pszText
[0])
6333 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1,
6334 lpnmtdi
->lpszText
, sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]));
6339 /* if button has text, but it is not shown then automatically
6340 * use that text as tooltip */
6341 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6342 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6344 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6345 unsigned int len
= pszText
? strlenW(pszText
) : 0;
6347 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6349 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6351 /* need to allocate temporary buffer in infoPtr as there
6352 * isn't enough space in buffer passed to us by the
6353 * tooltip control */
6354 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6355 if (infoPtr
->pszTooltipText
)
6357 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6358 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6364 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6369 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6371 /* last resort: send notification on to app */
6372 /* FIXME: find out what is really used here */
6373 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmtdi
->hdr
.idFrom
, (LPARAM
)lpnmtdi
);
6377 static inline LRESULT
6378 TOOLBAR_Notify (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6380 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6381 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
6383 switch (lpnmh
->code
)
6387 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
6389 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6390 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6391 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6395 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6396 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6404 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lParam
;
6406 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6407 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6408 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6409 lppgs
->iScroll
, lppgs
->iDir
);
6413 case TTN_GETDISPINFOW
:
6414 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lParam
);
6416 case TTN_GETDISPINFOA
:
6417 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6427 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6431 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam
, lParam
);
6433 if (lParam
== NF_QUERY
)
6436 if (lParam
== NF_REQUERY
) {
6437 format
= SendMessageW(infoPtr
->hwndNotify
,
6438 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6439 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6440 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6451 TOOLBAR_Paint (HWND hwnd
, WPARAM wParam
)
6453 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
6457 /* fill ps.rcPaint with a default rect */
6458 memcpy(&(ps
.rcPaint
), &(infoPtr
->rcBound
), sizeof(infoPtr
->rcBound
));
6460 hdc
= wParam
==0 ? BeginPaint(hwnd
, &ps
) : (HDC
)wParam
;
6462 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps
.rcPaint
));
6464 TOOLBAR_Refresh (hwnd
, hdc
, &ps
);
6465 if (!wParam
) EndPaint (hwnd
, &ps
);
6472 TOOLBAR_SetFocus (HWND hwnd
, WPARAM wParam
)
6474 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6476 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6478 /* make first item hot */
6479 if (infoPtr
->nNumButtons
> 0)
6480 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6486 TOOLBAR_SetFont(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6488 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
6490 TRACE("font=%p redraw=%ld\n", (HFONT
)wParam
, lParam
);
6493 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6495 infoPtr
->hFont
= (HFONT
)wParam
;
6497 TOOLBAR_CalcToolbar(hwnd
);
6500 InvalidateRect(hwnd
, NULL
, TRUE
);
6505 TOOLBAR_SetRedraw (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6506 /*****************************************************
6509 * Handles the WM_SETREDRAW message.
6512 * According to testing V4.71 of COMCTL32 returns the
6513 * *previous* status of the redraw flag (either 0 or 1)
6514 * instead of the MSDN documented value of 0 if handled.
6515 * (For laughs see the "consistency" with same function
6518 *****************************************************/
6520 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6521 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6523 TRACE("set to %s\n",
6524 (wParam
) ? "TRUE" : "FALSE");
6525 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6527 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6529 return (oldredraw
) ? 1 : 0;
6534 TOOLBAR_Size (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6536 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6538 TRACE("sizing toolbar!\n");
6540 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6542 RECT delta_width
, delta_height
, client
, dummy
;
6543 DWORD min_x
, max_x
, min_y
, max_y
;
6544 TBUTTON_INFO
*btnPtr
;
6547 GetClientRect(hwnd
, &client
);
6548 if(client
.right
> infoPtr
->client_rect
.right
)
6550 min_x
= infoPtr
->client_rect
.right
;
6551 max_x
= client
.right
;
6555 max_x
= infoPtr
->client_rect
.right
;
6556 min_x
= client
.right
;
6558 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6560 min_y
= infoPtr
->client_rect
.bottom
;
6561 max_y
= client
.bottom
;
6565 max_y
= infoPtr
->client_rect
.bottom
;
6566 min_y
= client
.bottom
;
6569 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6570 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6572 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6573 btnPtr
= infoPtr
->buttons
;
6574 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6575 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6576 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6577 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6579 GetClientRect(hwnd
, &infoPtr
->client_rect
);
6580 TOOLBAR_AutoSize(hwnd
);
6586 TOOLBAR_StyleChanged (HWND hwnd
, INT nType
, const STYLESTRUCT
*lpStyle
)
6588 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6590 if (nType
== GWL_STYLE
)
6592 DWORD dwOldStyle
= infoPtr
->dwStyle
;
6594 if (lpStyle
->styleNew
& TBSTYLE_LIST
)
6595 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
6597 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
6599 TOOLBAR_CheckStyle (hwnd
, lpStyle
->styleNew
);
6601 TRACE("new style 0x%08x\n", lpStyle
->styleNew
);
6603 infoPtr
->dwStyle
= lpStyle
->styleNew
;
6605 if ((dwOldStyle
^ lpStyle
->styleNew
) & (TBSTYLE_WRAPABLE
| CCS_VERT
))
6606 TOOLBAR_LayoutToolbar(hwnd
);
6608 /* only resize if one of the CCS_* styles was changed */
6609 if ((dwOldStyle
^ lpStyle
->styleNew
) & COMMON_STYLES
)
6611 TOOLBAR_AutoSize (hwnd
);
6613 InvalidateRect(hwnd
, NULL
, TRUE
);
6622 TOOLBAR_SysColorChange (HWND hwnd
)
6624 COMCTL32_RefreshSysColors();
6630 /* update theme after a WM_THEMECHANGED message */
6631 static LRESULT
theme_changed (HWND hwnd
)
6633 HTHEME theme
= GetWindowTheme (hwnd
);
6634 CloseThemeData (theme
);
6635 OpenThemeData (hwnd
, themeClass
);
6640 static LRESULT WINAPI
6641 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6643 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6645 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6646 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6648 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6649 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6654 return TOOLBAR_AddBitmap (hwnd
, wParam
, lParam
);
6656 case TB_ADDBUTTONSA
:
6657 return TOOLBAR_AddButtonsT(hwnd
, wParam
, lParam
, FALSE
);
6659 case TB_ADDBUTTONSW
:
6660 return TOOLBAR_AddButtonsT(hwnd
, wParam
, lParam
, TRUE
);
6663 return TOOLBAR_AddStringA (hwnd
, wParam
, lParam
);
6666 return TOOLBAR_AddStringW (hwnd
, wParam
, lParam
);
6669 return TOOLBAR_AutoSize (hwnd
);
6671 case TB_BUTTONCOUNT
:
6672 return TOOLBAR_ButtonCount (hwnd
, wParam
, lParam
);
6674 case TB_BUTTONSTRUCTSIZE
:
6675 return TOOLBAR_ButtonStructSize (hwnd
, wParam
, lParam
);
6677 case TB_CHANGEBITMAP
:
6678 return TOOLBAR_ChangeBitmap (hwnd
, wParam
, lParam
);
6680 case TB_CHECKBUTTON
:
6681 return TOOLBAR_CheckButton (hwnd
, wParam
, lParam
);
6683 case TB_COMMANDTOINDEX
:
6684 return TOOLBAR_CommandToIndex (hwnd
, wParam
, lParam
);
6687 return TOOLBAR_Customize (hwnd
);
6689 case TB_DELETEBUTTON
:
6690 return TOOLBAR_DeleteButton (hwnd
, wParam
, lParam
);
6692 case TB_ENABLEBUTTON
:
6693 return TOOLBAR_EnableButton (hwnd
, wParam
, lParam
);
6695 case TB_GETANCHORHIGHLIGHT
:
6696 return TOOLBAR_GetAnchorHighlight (hwnd
);
6699 return TOOLBAR_GetBitmap (hwnd
, wParam
, lParam
);
6701 case TB_GETBITMAPFLAGS
:
6702 return TOOLBAR_GetBitmapFlags (hwnd
, wParam
, lParam
);
6705 return TOOLBAR_GetButton (hwnd
, wParam
, lParam
);
6707 case TB_GETBUTTONINFOA
:
6708 return TOOLBAR_GetButtonInfoT(hwnd
, wParam
, lParam
, FALSE
);
6710 case TB_GETBUTTONINFOW
:
6711 return TOOLBAR_GetButtonInfoT(hwnd
, wParam
, lParam
, TRUE
);
6713 case TB_GETBUTTONSIZE
:
6714 return TOOLBAR_GetButtonSize (hwnd
);
6716 case TB_GETBUTTONTEXTA
:
6717 return TOOLBAR_GetButtonTextA (hwnd
, wParam
, lParam
);
6719 case TB_GETBUTTONTEXTW
:
6720 return TOOLBAR_GetButtonTextW (hwnd
, wParam
, lParam
);
6722 case TB_GETDISABLEDIMAGELIST
:
6723 return TOOLBAR_GetDisabledImageList (hwnd
, wParam
, lParam
);
6725 case TB_GETEXTENDEDSTYLE
:
6726 return TOOLBAR_GetExtendedStyle (hwnd
);
6728 case TB_GETHOTIMAGELIST
:
6729 return TOOLBAR_GetHotImageList (hwnd
, wParam
, lParam
);
6732 return TOOLBAR_GetHotItem (hwnd
);
6734 case TB_GETIMAGELIST
:
6735 return TOOLBAR_GetDefImageList (hwnd
, wParam
, lParam
);
6737 case TB_GETINSERTMARK
:
6738 return TOOLBAR_GetInsertMark (hwnd
, wParam
, lParam
);
6740 case TB_GETINSERTMARKCOLOR
:
6741 return TOOLBAR_GetInsertMarkColor (hwnd
, wParam
, lParam
);
6743 case TB_GETITEMRECT
:
6744 return TOOLBAR_GetItemRect (hwnd
, wParam
, lParam
);
6747 return TOOLBAR_GetMaxSize (hwnd
, wParam
, lParam
);
6749 /* case TB_GETOBJECT: */ /* 4.71 */
6752 return TOOLBAR_GetPadding (hwnd
);
6755 return TOOLBAR_GetRect (hwnd
, wParam
, lParam
);
6758 return TOOLBAR_GetRows (hwnd
, wParam
, lParam
);
6761 return TOOLBAR_GetState (hwnd
, wParam
, lParam
);
6764 return TOOLBAR_GetStringA (hwnd
, wParam
, lParam
);
6767 return TOOLBAR_GetStringW (hwnd
, wParam
, lParam
);
6770 return TOOLBAR_GetStyle (hwnd
, wParam
, lParam
);
6772 case TB_GETTEXTROWS
:
6773 return TOOLBAR_GetTextRows (hwnd
, wParam
, lParam
);
6775 case TB_GETTOOLTIPS
:
6776 return TOOLBAR_GetToolTips (hwnd
, wParam
, lParam
);
6778 case TB_GETUNICODEFORMAT
:
6779 return TOOLBAR_GetUnicodeFormat (hwnd
, wParam
, lParam
);
6782 return TOOLBAR_HideButton (hwnd
, wParam
, lParam
);
6785 return TOOLBAR_HitTest (hwnd
, wParam
, lParam
);
6787 case TB_INDETERMINATE
:
6788 return TOOLBAR_Indeterminate (hwnd
, wParam
, lParam
);
6790 case TB_INSERTBUTTONA
:
6791 return TOOLBAR_InsertButtonT(hwnd
, wParam
, lParam
, FALSE
);
6793 case TB_INSERTBUTTONW
:
6794 return TOOLBAR_InsertButtonT(hwnd
, wParam
, lParam
, TRUE
);
6796 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6798 case TB_ISBUTTONCHECKED
:
6799 return TOOLBAR_IsButtonChecked (hwnd
, wParam
, lParam
);
6801 case TB_ISBUTTONENABLED
:
6802 return TOOLBAR_IsButtonEnabled (hwnd
, wParam
, lParam
);
6804 case TB_ISBUTTONHIDDEN
:
6805 return TOOLBAR_IsButtonHidden (hwnd
, wParam
, lParam
);
6807 case TB_ISBUTTONHIGHLIGHTED
:
6808 return TOOLBAR_IsButtonHighlighted (hwnd
, wParam
, lParam
);
6810 case TB_ISBUTTONINDETERMINATE
:
6811 return TOOLBAR_IsButtonIndeterminate (hwnd
, wParam
, lParam
);
6813 case TB_ISBUTTONPRESSED
:
6814 return TOOLBAR_IsButtonPressed (hwnd
, wParam
, lParam
);
6817 return TOOLBAR_LoadImages (hwnd
, wParam
, lParam
);
6819 case TB_MAPACCELERATORA
:
6820 case TB_MAPACCELERATORW
:
6821 return TOOLBAR_MapAccelerator (hwnd
, wParam
, lParam
);
6824 return TOOLBAR_MarkButton (hwnd
, wParam
, lParam
);
6827 return TOOLBAR_MoveButton (hwnd
, wParam
, lParam
);
6829 case TB_PRESSBUTTON
:
6830 return TOOLBAR_PressButton (hwnd
, wParam
, lParam
);
6832 case TB_REPLACEBITMAP
:
6833 return TOOLBAR_ReplaceBitmap (hwnd
, wParam
, lParam
);
6835 case TB_SAVERESTOREA
:
6836 return TOOLBAR_SaveRestoreA (hwnd
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6838 case TB_SAVERESTOREW
:
6839 return TOOLBAR_SaveRestoreW (hwnd
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6841 case TB_SETANCHORHIGHLIGHT
:
6842 return TOOLBAR_SetAnchorHighlight (hwnd
, wParam
);
6844 case TB_SETBITMAPSIZE
:
6845 return TOOLBAR_SetBitmapSize (hwnd
, wParam
, lParam
);
6847 case TB_SETBUTTONINFOA
:
6848 return TOOLBAR_SetButtonInfoA (hwnd
, wParam
, lParam
);
6850 case TB_SETBUTTONINFOW
:
6851 return TOOLBAR_SetButtonInfoW (hwnd
, wParam
, lParam
);
6853 case TB_SETBUTTONSIZE
:
6854 return TOOLBAR_SetButtonSize (hwnd
, wParam
, lParam
);
6856 case TB_SETBUTTONWIDTH
:
6857 return TOOLBAR_SetButtonWidth (hwnd
, wParam
, lParam
);
6860 return TOOLBAR_SetCmdId (hwnd
, wParam
, lParam
);
6862 case TB_SETDISABLEDIMAGELIST
:
6863 return TOOLBAR_SetDisabledImageList (hwnd
, wParam
, lParam
);
6865 case TB_SETDRAWTEXTFLAGS
:
6866 return TOOLBAR_SetDrawTextFlags (hwnd
, wParam
, lParam
);
6868 case TB_SETEXTENDEDSTYLE
:
6869 return TOOLBAR_SetExtendedStyle (hwnd
, wParam
, lParam
);
6871 case TB_SETHOTIMAGELIST
:
6872 return TOOLBAR_SetHotImageList (hwnd
, wParam
, lParam
);
6875 return TOOLBAR_SetHotItem (hwnd
, wParam
);
6877 case TB_SETIMAGELIST
:
6878 return TOOLBAR_SetImageList (hwnd
, wParam
, lParam
);
6881 return TOOLBAR_SetIndent (hwnd
, wParam
, lParam
);
6883 case TB_SETINSERTMARK
:
6884 return TOOLBAR_SetInsertMark (hwnd
, wParam
, lParam
);
6886 case TB_SETINSERTMARKCOLOR
:
6887 return TOOLBAR_SetInsertMarkColor (hwnd
, wParam
, lParam
);
6889 case TB_SETMAXTEXTROWS
:
6890 return TOOLBAR_SetMaxTextRows (hwnd
, wParam
, lParam
);
6893 return TOOLBAR_SetPadding (hwnd
, wParam
, lParam
);
6896 return TOOLBAR_SetParent (hwnd
, wParam
, lParam
);
6899 return TOOLBAR_SetRows (hwnd
, wParam
, lParam
);
6902 return TOOLBAR_SetState (hwnd
, wParam
, lParam
);
6905 return TOOLBAR_SetStyle (hwnd
, wParam
, lParam
);
6907 case TB_SETTOOLTIPS
:
6908 return TOOLBAR_SetToolTips (hwnd
, wParam
, lParam
);
6910 case TB_SETUNICODEFORMAT
:
6911 return TOOLBAR_SetUnicodeFormat (hwnd
, wParam
, lParam
);
6914 return TOOLBAR_Unkwn45D(hwnd
, wParam
, lParam
);
6917 return TOOLBAR_Unkwn45E (hwnd
, wParam
, lParam
);
6920 return TOOLBAR_Unkwn460(hwnd
, wParam
, lParam
);
6923 return TOOLBAR_Unkwn462(hwnd
, wParam
, lParam
);
6926 return TOOLBAR_Unkwn463 (hwnd
, wParam
, lParam
);
6929 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6931 /* Common Control Messages */
6933 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6934 case CCM_GETCOLORSCHEME
:
6935 return TOOLBAR_GetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
6937 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6938 case CCM_SETCOLORSCHEME
:
6939 return TOOLBAR_SetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
6941 case CCM_GETVERSION
:
6942 return TOOLBAR_GetVersion (hwnd
);
6944 case CCM_SETVERSION
:
6945 return TOOLBAR_SetVersion (hwnd
, (INT
)wParam
);
6951 return TOOLBAR_Create (hwnd
, wParam
, lParam
);
6954 return TOOLBAR_Destroy (hwnd
, wParam
, lParam
);
6957 return TOOLBAR_EraseBackground (hwnd
, wParam
, lParam
);
6960 return TOOLBAR_GetFont (hwnd
, wParam
, lParam
);
6963 return TOOLBAR_KeyDown (hwnd
, wParam
, lParam
);
6965 /* case WM_KILLFOCUS: */
6967 case WM_LBUTTONDBLCLK
:
6968 return TOOLBAR_LButtonDblClk (hwnd
, wParam
, lParam
);
6970 case WM_LBUTTONDOWN
:
6971 return TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
6974 return TOOLBAR_LButtonUp (hwnd
, wParam
, lParam
);
6977 return TOOLBAR_RButtonUp (hwnd
, wParam
, lParam
);
6979 case WM_RBUTTONDBLCLK
:
6980 return TOOLBAR_RButtonDblClk (hwnd
, wParam
, lParam
);
6983 return TOOLBAR_MouseMove (hwnd
, wParam
, lParam
);
6986 return TOOLBAR_MouseLeave (hwnd
, wParam
, lParam
);
6988 case WM_CAPTURECHANGED
:
6989 return TOOLBAR_CaptureChanged(hwnd
);
6992 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6995 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6998 return TOOLBAR_NCCreate (hwnd
, wParam
, lParam
);
7001 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
7004 return TOOLBAR_Notify (hwnd
, wParam
, lParam
);
7006 case WM_NOTIFYFORMAT
:
7007 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
7009 case WM_PRINTCLIENT
:
7011 return TOOLBAR_Paint (hwnd
, wParam
);
7014 return TOOLBAR_SetFocus (hwnd
, wParam
);
7017 return TOOLBAR_SetFont(hwnd
, wParam
, lParam
);
7020 return TOOLBAR_SetRedraw (hwnd
, wParam
, lParam
);
7023 return TOOLBAR_Size (hwnd
, wParam
, lParam
);
7025 case WM_STYLECHANGED
:
7026 return TOOLBAR_StyleChanged (hwnd
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
7028 case WM_SYSCOLORCHANGE
:
7029 return TOOLBAR_SysColorChange (hwnd
);
7031 case WM_THEMECHANGED
:
7032 return theme_changed (hwnd
);
7034 /* case WM_WININICHANGE: */
7039 case WM_MEASUREITEM
:
7041 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
7043 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7044 case PGM_FORWARDMOUSE
:
7045 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7048 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
7049 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
7050 uMsg
, wParam
, lParam
);
7051 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7057 TOOLBAR_Register (void)
7061 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
7062 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
7063 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
7064 wndClass
.cbClsExtra
= 0;
7065 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
7066 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
7067 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
7068 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
7070 RegisterClassW (&wndClass
);
7075 TOOLBAR_Unregister (void)
7077 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
7080 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
7085 /* Check if the entry already exists */
7086 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
7088 /* If this is a new entry we must create it and insert into the array */
7093 c
= (PIMLENTRY
) Alloc(sizeof(IMLENTRY
));
7096 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
7097 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
7112 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
7116 for (i
= 0; i
< *cies
; i
++)
7126 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
7134 for (i
= 0; i
< cies
; i
++)
7136 if (pies
[i
]->id
== id
)
7148 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
7150 HIMAGELIST himlDef
= 0;
7151 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
7154 himlDef
= pie
->himl
;
7160 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
7162 if (infoPtr
->bUnicode
)
7163 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
7170 nmtba
.iItem
= nmtb
->iItem
;
7171 nmtba
.pszText
= Buffer
;
7172 nmtba
.cchText
= 256;
7173 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
7175 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
7177 int ccht
= strlen(nmtba
.pszText
);
7179 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)nmtba
.pszText
, -1,
7180 nmtb
->pszText
, nmtb
->cchText
);
7182 memcpy(&nmtb
->tbButton
, &nmtba
.tbButton
, sizeof(TBBUTTON
));
7191 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, PCUSTOMBUTTON btnInfo
)
7195 /* MSDN states that iItem is the index of the button, rather than the
7196 * command ID as used by every other NMTOOLBAR notification */
7198 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
7200 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);