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
;
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
++ )
1317 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1319 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1322 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1323 /* it is the actual width of the separator. This is used for */
1324 /* custom controls in toolbars. */
1326 /* BTNS_DROPDOWN separators are treated as buttons for */
1327 /* width. - GA 8/01 */
1328 if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1329 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
))
1330 cx
= (btnPtr
[i
].iBitmap
> 0) ?
1331 btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1333 cx
= infoPtr
->nButtonWidth
;
1335 /* Two or more adjacent separators form a separator group. */
1336 /* The first separator in a group should be wrapped to the */
1337 /* next row if the previous wrapping is on a button. */
1339 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1340 (i
+ 1 < infoPtr
->nNumButtons
) &&
1341 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1343 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1344 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1345 x
= infoPtr
->nIndent
;
1347 bButtonWrap
= FALSE
;
1351 /* The layout makes sure the bitmap is visible, but not the button. */
1352 /* Test added to also wrap after a button that starts a row but */
1353 /* is bigger than the area. - GA 8/01 */
1354 if (( x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2
1355 > infoPtr
->nWidth
) ||
1356 ((x
== infoPtr
->nIndent
) && (cx
> infoPtr
->nWidth
)))
1358 BOOL bFound
= FALSE
;
1360 /* If the current button is a separator and not hidden, */
1361 /* go to the next until it reaches a non separator. */
1362 /* Wrap the last separator if it is before a button. */
1363 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1364 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1365 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1366 i
< infoPtr
->nNumButtons
)
1372 if( bFound
&& i
< infoPtr
->nNumButtons
)
1375 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1376 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1377 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1378 x
= infoPtr
->nIndent
;
1379 bButtonWrap
= FALSE
;
1382 else if ( i
>= infoPtr
->nNumButtons
)
1385 /* If the current button is not a separator, find the last */
1386 /* separator and wrap it. */
1387 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1389 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1390 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1394 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1395 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1396 x
= infoPtr
->nIndent
;
1397 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1398 bButtonWrap
= FALSE
;
1403 /* If no separator available for wrapping, wrap one of */
1404 /* non-hidden previous button. */
1408 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1410 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1415 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1416 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1417 x
= infoPtr
->nIndent
;
1418 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1424 /* If all above failed, wrap the current button. */
1427 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1428 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1429 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1431 x
= infoPtr
->nIndent
;
1432 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1433 bButtonWrap
= FALSE
;
1439 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1440 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1447 /***********************************************************************
1448 * TOOLBAR_MeasureButton
1450 * Calculates the width and height required for a button. Used in
1451 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1452 * the width of buttons that are autosized.
1454 * Note that it would have been rather elegant to use one piece of code for
1455 * both the laying out of the toolbar and for controlling where button parts
1456 * are drawn, but the native control has inconsistencies between the two that
1457 * prevent this from being effectively. These inconsistencies can be seen as
1458 * artefacts where parts of the button appear outside of the bounding button
1461 * There are several cases for the calculation of the button dimensions and
1462 * button part positioning:
1469 * +--------------------------------------------------------+ ^
1471 * | | pad.cy / 2 | centred | |
1472 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1473 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1474 * | |<------------>| | | | |
1475 * | +--------------+ +------------+ | |
1476 * |<-------------------------------------->| | |
1477 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1479 * +--------------------------------------------------------+ -
1480 * <-------------------------------------------------------->
1481 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1483 * Without Bitmap (I_IMAGENONE):
1485 * +-----------------------------------+ ^
1487 * | | centred | | LISTPAD_CY +
1488 * | +------------+ | | szText.cy
1491 * | +------------+ | |
1492 * |<----------------->| | |
1493 * | cxedge |<-----------> | |
1495 * +-----------------------------------+ -
1496 * <----------------------------------->
1497 * szText.cx + pad.cx
1501 * +--------------------------------------+ ^
1503 * | | padding.cy/2 | | DEFPAD_CY +
1504 * | +------------+ | | nBitmapHeight
1507 * | +------------+ | |
1508 * |<------------------->| | |
1509 * | cxedge + iListGap/2 |<-----------> | |
1510 * | nBitmapWidth | |
1511 * +--------------------------------------+ -
1512 * <-------------------------------------->
1513 * 2*cxedge + nBitmapWidth + iListGap
1520 * +-----------------------------------+ ^
1522 * | | pad.cy / 2 | | nBitmapHeight +
1523 * | - | | szText.cy +
1524 * | +------------+ | | DEFPAD_CY + 1
1525 * | centred | Bitmap | | |
1526 * |<----------------->| | | |
1527 * | +------------+ | |
1531 * | centred +---------------+ | |
1532 * |<--------------->| Text | | |
1533 * | +---------------+ | |
1534 * +-----------------------------------+ -
1535 * <----------------------------------->
1536 * pad.cx + max(nBitmapWidth, szText.cx)
1538 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1540 * +---------------------------------------+ ^
1542 * | | 2 + pad.cy / 2 | |
1543 * | - | | szText.cy +
1544 * | centred +-----------------+ | | pad.cy + 2
1545 * |<--------------->| Text | | |
1546 * | +-----------------+ | |
1548 * +---------------------------------------+ -
1549 * <--------------------------------------->
1550 * 2*cxedge + pad.cx + szText.cx
1553 * As for with bitmaps, but with szText.cx zero.
1555 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1556 BOOL bHasBitmap
, BOOL bValidImageList
)
1559 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1561 /* set button height from bitmap / text height... */
1562 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1565 /* ... add on the necessary padding */
1566 if (bValidImageList
)
1569 sizeButton
.cy
+= DEFPAD_CY
;
1571 sizeButton
.cy
+= LISTPAD_CY
;
1574 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1576 /* calculate button width */
1579 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1580 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1581 if (sizeString
.cx
> 0)
1582 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1585 sizeButton
.cx
= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1591 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1592 if (sizeString
.cy
> 0)
1593 sizeButton
.cy
+= 1 + sizeString
.cy
;
1594 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1595 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1599 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1600 NONLIST_NOTEXT_OFFSET
;
1601 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1602 infoPtr
->szPadding
.cx
+ sizeString
.cx
;
1609 /***********************************************************************
1610 * TOOLBAR_CalcToolbar
1612 * This function calculates button and separator placement. It first
1613 * calculates the button sizes, gets the toolbar window width and then
1614 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1615 * on. It assigns a new location to each item and sends this location to
1616 * the tooltip window if appropriate. Finally, it updates the rcBound
1617 * rect and calculates the new required toolbar window height.
1620 TOOLBAR_CalcToolbar (HWND hwnd
)
1622 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
1623 SIZE sizeString
, sizeButton
;
1624 BOOL validImageList
= FALSE
;
1626 TOOLBAR_CalcStrings (hwnd
, &sizeString
);
1628 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1630 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1631 validImageList
= TRUE
;
1632 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1633 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1634 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1635 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1637 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1638 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1639 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1640 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1642 TOOLBAR_LayoutToolbar(hwnd
);
1646 TOOLBAR_LayoutToolbar(HWND hwnd
)
1648 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
1649 TBUTTON_INFO
*btnPtr
;
1651 INT i
, nRows
, nSepRows
;
1654 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1655 BOOL hasDropDownArrows
= TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
);
1657 TOOLBAR_WrapToolbar(hwnd
, infoPtr
->dwStyle
);
1659 x
= infoPtr
->nIndent
;
1660 y
= infoPtr
->iTopMargin
;
1661 cx
= infoPtr
->nButtonWidth
;
1662 cy
= infoPtr
->nButtonHeight
;
1664 nRows
= nSepRows
= 0;
1666 infoPtr
->rcBound
.top
= y
;
1667 infoPtr
->rcBound
.left
= x
;
1668 infoPtr
->rcBound
.bottom
= y
+ cy
;
1669 infoPtr
->rcBound
.right
= x
;
1671 btnPtr
= infoPtr
->buttons
;
1673 TRACE("cy=%d\n", cy
);
1675 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1678 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1680 SetRectEmpty (&btnPtr
->rect
);
1684 cy
= infoPtr
->nButtonHeight
;
1686 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1687 /* it is the actual width of the separator. This is used for */
1688 /* custom controls in toolbars. */
1689 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1690 if (btnPtr
->fsStyle
& BTNS_DROPDOWN
) {
1691 cy
= (btnPtr
->iBitmap
> 0) ?
1692 btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1693 cx
= infoPtr
->nButtonWidth
;
1696 cx
= (btnPtr
->iBitmap
> 0) ?
1697 btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1703 else if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1704 (btnPtr
->fsStyle
& BTNS_AUTOSIZE
))
1711 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1713 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1715 SelectObject (hdc
, hOldFont
);
1716 ReleaseDC (hwnd
, hdc
);
1718 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1719 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1724 cx
= infoPtr
->nButtonWidth
;
1726 /* if size has been set manually then don't add on extra space
1727 * for the drop down arrow */
1728 if (!btnPtr
->cx
&& hasDropDownArrows
&&
1729 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) || (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)))
1730 cx
+= DDARROW_WIDTH
;
1732 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1735 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1737 if (infoPtr
->rcBound
.left
> x
)
1738 infoPtr
->rcBound
.left
= x
;
1739 if (infoPtr
->rcBound
.right
< x
+ cx
)
1740 infoPtr
->rcBound
.right
= x
+ cx
;
1741 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1742 infoPtr
->rcBound
.bottom
= y
+ cy
;
1744 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1746 /* btnPtr->nRow is zero based. The space between the rows is */
1747 /* also considered as a row. */
1748 btnPtr
->nRow
= nRows
+ nSepRows
;
1750 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1751 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1756 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1760 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1761 /* it is the actual width of the separator. This is used for */
1762 /* custom controls in toolbars. */
1763 if ( !(btnPtr
->fsStyle
& BTNS_DROPDOWN
))
1764 y
+= cy
+ ( (btnPtr
->iBitmap
> 0 ) ?
1765 btnPtr
->iBitmap
: SEPARATOR_WIDTH
) * 2 /3;
1769 /* nSepRows is used to calculate the extra height following */
1773 x
= infoPtr
->nIndent
;
1775 /* Increment row number unless this is the last button */
1776 /* and it has Wrap set. */
1777 if (i
!= infoPtr
->nNumButtons
-1)
1784 /* infoPtr->nRows is the number of rows on the toolbar */
1785 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1787 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1792 TOOLBAR_InternalHitTest (HWND hwnd
, const POINT
*lpPt
)
1794 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1795 TBUTTON_INFO
*btnPtr
;
1798 btnPtr
= infoPtr
->buttons
;
1799 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1800 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1803 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1804 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1805 TRACE(" ON SEPARATOR %d!\n", i
);
1810 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1811 TRACE(" ON BUTTON %d!\n", i
);
1817 TRACE(" NOWHERE!\n");
1818 return TOOLBAR_NOWHERE
;
1823 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1825 TBUTTON_INFO
*btnPtr
;
1828 if (CommandIsIndex
) {
1829 TRACE("command is really index command=%d\n", idCommand
);
1830 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1833 btnPtr
= infoPtr
->buttons
;
1834 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1835 if (btnPtr
->idCommand
== idCommand
) {
1836 TRACE("command=%d index=%d\n", idCommand
, i
);
1840 TRACE("no index found for command=%d\n", idCommand
);
1846 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1848 TBUTTON_INFO
*btnPtr
;
1851 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1854 /* check index button */
1855 btnPtr
= &infoPtr
->buttons
[nIndex
];
1856 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1857 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1861 /* check previous buttons */
1862 nRunIndex
= nIndex
- 1;
1863 while (nRunIndex
>= 0) {
1864 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1865 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1866 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1874 /* check next buttons */
1875 nRunIndex
= nIndex
+ 1;
1876 while (nRunIndex
< infoPtr
->nNumButtons
) {
1877 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1878 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1879 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1892 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1893 WPARAM wParam
, LPARAM lParam
)
1899 msg
.wParam
= wParam
;
1900 msg
.lParam
= lParam
;
1901 msg
.time
= GetMessageTime ();
1902 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
1903 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
1905 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1909 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1911 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
1914 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
1915 ti
.cbSize
= sizeof (TTTOOLINFOW
);
1916 ti
.hwnd
= infoPtr
->hwndSelf
;
1917 ti
.uId
= button
->idCommand
;
1919 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
1920 /* ti.lParam = random value from the stack? */
1922 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
1928 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1930 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
1933 ZeroMemory(&ti
, sizeof(ti
));
1934 ti
.cbSize
= sizeof(ti
);
1935 ti
.hwnd
= infoPtr
->hwndSelf
;
1936 ti
.uId
= button
->idCommand
;
1938 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
1942 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1944 /* Set the toolTip only for non-hidden, non-separator button */
1945 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
1949 ZeroMemory(&ti
, sizeof(ti
));
1950 ti
.cbSize
= sizeof(ti
);
1951 ti
.hwnd
= infoPtr
->hwndSelf
;
1952 ti
.uId
= button
->idCommand
;
1953 ti
.rect
= button
->rect
;
1954 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
1958 /* Creates the tooltip control */
1960 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
1963 NMTOOLTIPSCREATED nmttc
;
1965 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
1966 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1967 infoPtr
->hwndSelf
, 0, 0, 0);
1969 if (!infoPtr
->hwndToolTip
)
1972 /* Send NM_TOOLTIPSCREATED notification */
1973 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
1974 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
1976 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
1978 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
1979 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
1983 /* keeps available button list box sorted by button id */
1984 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
1988 PCUSTOMBUTTON btnInfo
;
1989 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
1991 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
1993 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
1995 /* position 0 is always separator */
1996 for (i
= 1; i
< count
; i
++)
1998 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
1999 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2001 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2002 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2006 /* id higher than all others add to end */
2007 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2008 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2011 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2015 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2017 if (nIndexFrom
== nIndexTo
)
2020 /* MSDN states that iItem is the index of the button, rather than the
2021 * command ID as used by every other NMTOOLBAR notification */
2022 nmtb
.iItem
= nIndexFrom
;
2023 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2025 PCUSTOMBUTTON btnInfo
;
2027 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2028 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2030 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2032 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2033 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2034 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2035 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2038 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2040 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2042 /* last item is always separator, so -2 instead of -1 */
2043 if (nIndexTo
>= (count
- 2))
2044 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2046 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2048 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2049 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2051 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2055 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2059 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2061 /* MSDN states that iItem is the index of the button, rather than the
2062 * command ID as used by every other NMTOOLBAR notification */
2063 nmtb
.iItem
= nIndexAvail
;
2064 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2066 PCUSTOMBUTTON btnInfo
;
2068 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2069 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2070 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2072 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2074 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2076 /* remove from 'available buttons' list */
2077 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2078 if (nIndexAvail
== count
-1)
2079 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2081 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2085 PCUSTOMBUTTON btnNew
;
2087 /* duplicate 'separator' button */
2088 btnNew
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2093 /* insert into 'toolbar button' list */
2094 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2095 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2097 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2099 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2103 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2105 PCUSTOMBUTTON btnInfo
;
2106 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2108 TRACE("Remove: index %d\n", index
);
2110 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2112 /* send TBN_QUERYDELETE notification */
2113 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2117 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2118 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2120 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2122 /* insert into 'available button' list */
2123 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2124 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2128 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2132 /* drag list notification function for toolbar buttons list box */
2133 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2134 const DRAGLISTINFO
*pDLI
)
2136 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2137 switch (pDLI
->uNotification
)
2141 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2142 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2143 /* no dragging for last item (separator) */
2144 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2149 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2150 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2151 /* no dragging past last item (separator) */
2152 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2154 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2155 /* FIXME: native uses "move button" cursor */
2156 return DL_COPYCURSOR
;
2159 /* not over toolbar buttons list */
2160 if (nCurrentItem
< 0)
2162 POINT ptWindow
= pDLI
->ptCursor
;
2163 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2164 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2165 /* over available buttons list? */
2166 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2167 /* FIXME: native uses "move button" cursor */
2168 return DL_COPYCURSOR
;
2170 /* clear drag arrow */
2171 DrawInsert(hwnd
, hwndList
, -1);
2172 return DL_STOPCURSOR
;
2176 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2177 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2178 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2179 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2181 /* clear drag arrow */
2182 DrawInsert(hwnd
, hwndList
, -1);
2184 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2186 /* not over toolbar buttons list */
2189 POINT ptWindow
= pDLI
->ptCursor
;
2190 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2191 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2192 /* over available buttons list? */
2193 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2194 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2199 /* Clear drag arrow */
2200 DrawInsert(hwnd
, hwndList
, -1);
2207 /* drag list notification function for available buttons list box */
2208 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2209 const DRAGLISTINFO
*pDLI
)
2211 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2212 switch (pDLI
->uNotification
)
2218 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2219 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2220 /* no dragging past last item (separator) */
2221 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2223 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2224 /* FIXME: native uses "move button" cursor */
2225 return DL_COPYCURSOR
;
2228 /* not over toolbar buttons list */
2229 if (nCurrentItem
< 0)
2231 POINT ptWindow
= pDLI
->ptCursor
;
2232 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2233 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2234 /* over available buttons list? */
2235 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2236 /* FIXME: native uses "move button" cursor */
2237 return DL_COPYCURSOR
;
2239 /* clear drag arrow */
2240 DrawInsert(hwnd
, hwndList
, -1);
2241 return DL_STOPCURSOR
;
2245 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2246 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2247 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2248 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2250 /* clear drag arrow */
2251 DrawInsert(hwnd
, hwndList
, -1);
2253 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2257 /* Clear drag arrow */
2258 DrawInsert(hwnd
, hwndList
, -1);
2264 extern UINT uDragListMessage
;
2266 /***********************************************************************
2267 * TOOLBAR_CustomizeDialogProc
2268 * This function implements the toolbar customization dialog.
2270 static INT_PTR CALLBACK
2271 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2273 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2274 PCUSTOMBUTTON btnInfo
;
2276 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2281 custInfo
= (PCUSTDLG_INFO
)lParam
;
2282 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2289 NMTBINITCUSTOMIZE nmtbic
;
2291 infoPtr
= custInfo
->tbInfo
;
2293 /* send TBN_QUERYINSERT notification */
2294 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2296 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2299 nmtbic
.hwndDialog
= hwnd
;
2300 /* Send TBN_INITCUSTOMIZE notification */
2301 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2304 TRACE("TBNRF_HIDEHELP requested\n");
2305 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2308 /* add items to 'toolbar buttons' list and check if removable */
2309 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2311 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2312 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2313 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2314 btnInfo
->bVirtual
= FALSE
;
2315 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2317 /* send TBN_QUERYDELETE notification */
2318 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2320 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2321 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2324 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2326 /* insert separator button into 'available buttons' list */
2327 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2328 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2329 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2330 btnInfo
->bVirtual
= FALSE
;
2331 btnInfo
->bRemovable
= TRUE
;
2332 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2333 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2334 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2336 /* insert all buttons into dsa */
2339 /* send TBN_GETBUTTONINFO notification */
2342 nmtb
.pszText
= Buffer
;
2345 /* Clear previous button's text */
2346 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2348 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2351 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2352 nmtb
.tbButton
.fsStyle
, i
,
2353 nmtb
.tbButton
.idCommand
,
2354 nmtb
.tbButton
.iString
,
2355 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2358 /* insert button into the apropriate list */
2359 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2362 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2363 btnInfo
->bVirtual
= FALSE
;
2364 btnInfo
->bRemovable
= TRUE
;
2368 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2369 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2372 btnInfo
->btn
= nmtb
.tbButton
;
2373 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2375 if (lstrlenW(nmtb
.pszText
))
2376 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2377 else if (nmtb
.tbButton
.iString
>= 0 &&
2378 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2380 lstrcpyW(btnInfo
->text
,
2381 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2386 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2389 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2391 /* select first item in the 'available' list */
2392 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2394 /* append 'virtual' separator button to the 'toolbar buttons' list */
2395 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2396 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2397 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2398 btnInfo
->bVirtual
= TRUE
;
2399 btnInfo
->bRemovable
= FALSE
;
2400 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2401 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2402 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2404 /* select last item in the 'toolbar' list */
2405 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2406 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2408 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2409 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2411 /* set focus and disable buttons */
2412 PostMessageW (hwnd
, WM_USER
, 0, 0);
2417 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2418 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2419 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2420 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2424 EndDialog(hwnd
, FALSE
);
2428 switch (LOWORD(wParam
))
2430 case IDC_TOOLBARBTN_LBOX
:
2431 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2433 PCUSTOMBUTTON btnInfo
;
2438 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2439 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2441 /* send TBN_QUERYINSERT notification */
2443 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2445 /* get list box item */
2446 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2448 if (index
== (count
- 1))
2450 /* last item (virtual separator) */
2451 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2452 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2454 else if (index
== (count
- 2))
2456 /* second last item (last non-virtual item) */
2457 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2458 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2460 else if (index
== 0)
2463 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2464 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2468 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2469 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2472 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2476 case IDC_MOVEUP_BTN
:
2478 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2479 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2483 case IDC_MOVEDN_BTN
: /* move down */
2485 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2486 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2490 case IDC_REMOVE_BTN
: /* remove button */
2492 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2494 if (LB_ERR
== index
)
2497 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2501 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2504 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2507 case IDOK
: /* Add button */
2512 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2513 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2515 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2520 EndDialog(hwnd
, FALSE
);
2530 /* delete items from 'toolbar buttons' listbox*/
2531 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2532 for (i
= 0; i
< count
; i
++)
2534 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2536 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2538 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2541 /* delete items from 'available buttons' listbox*/
2542 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2543 for (i
= 0; i
< count
; i
++)
2545 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2547 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2549 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2554 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2556 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2561 COLORREF oldText
= 0;
2565 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, (WPARAM
)lpdis
->itemID
, 0);
2566 if (btnInfo
== NULL
)
2568 FIXME("btnInfo invalid!\n");
2572 /* set colors and select objects */
2573 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2574 if (btnInfo
->bVirtual
)
2575 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2577 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2578 hPen
= CreatePen( PS_SOLID
, 1,
2579 GetSysColor( (lpdis
->itemState
& ODS_SELECTED
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2580 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2581 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2583 /* fill background rectangle */
2584 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2585 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2587 /* calculate button and text rectangles */
2588 CopyRect (&rcButton
, &lpdis
->rcItem
);
2589 InflateRect (&rcButton
, -1, -1);
2590 CopyRect (&rcText
, &rcButton
);
2591 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2592 rcText
.left
= rcButton
.right
+ 2;
2594 /* draw focus rectangle */
2595 if (lpdis
->itemState
& ODS_FOCUS
)
2596 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2599 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2600 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2602 /* draw image and text */
2603 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2604 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2605 btnInfo
->btn
.iBitmap
));
2606 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2607 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2609 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2610 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2612 /* delete objects and reset colors */
2613 SelectObject (lpdis
->hDC
, hOldBrush
);
2614 SelectObject (lpdis
->hDC
, hOldPen
);
2615 SetBkColor (lpdis
->hDC
, oldBk
);
2616 SetTextColor (lpdis
->hDC
, oldText
);
2617 DeleteObject( hPen
);
2622 case WM_MEASUREITEM
:
2623 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2625 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2627 lpmis
->itemHeight
= 15 + 8; /* default height */
2634 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2636 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2638 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2639 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2640 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2643 else if (wParam
== IDC_AVAILBTN_LBOX
)
2645 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2646 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2647 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2656 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2659 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2665 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2666 /* Add bitmaps to the default image list */
2667 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2668 hbmLoad
= (HBITMAP
)CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2670 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2672 /* enlarge the bitmap if needed */
2673 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2674 if (bitmap
->hInst
!= COMCTL32_hModule
)
2675 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2677 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2678 DeleteObject(hbmLoad
);
2682 nCountAfter
= ImageList_GetImageCount(himlDef
);
2683 nAdded
= nCountAfter
- nCountBefore
;
2684 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2686 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2687 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2688 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2689 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2692 infoPtr
->nNumBitmaps
+= nAdded
;
2697 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2704 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2705 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2707 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2709 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2712 TRACE("Update icon size: %dx%d -> %dx%d\n",
2713 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2715 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2716 ILC_COLORDDB
|ILC_MASK
, 8, 2);
2717 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2718 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2719 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2720 infoPtr
->himlInt
= himlNew
;
2722 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2723 ImageList_Destroy(himlDef
);
2726 /***********************************************************************
2727 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2731 TOOLBAR_AddBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2733 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2734 LPTBADDBITMAP lpAddBmp
= (LPTBADDBITMAP
)lParam
;
2739 TRACE("hwnd=%p wParam=%lx lParam=%lx\n", hwnd
, wParam
, lParam
);
2743 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2745 info
.hInst
= COMCTL32_hModule
;
2746 switch (lpAddBmp
->nID
)
2748 case IDB_STD_SMALL_COLOR
:
2750 info
.nID
= IDB_STD_SMALL
;
2752 case IDB_STD_LARGE_COLOR
:
2754 info
.nID
= IDB_STD_LARGE
;
2756 case IDB_VIEW_SMALL_COLOR
:
2758 info
.nID
= IDB_VIEW_SMALL
;
2760 case IDB_VIEW_LARGE_COLOR
:
2762 info
.nID
= IDB_VIEW_LARGE
;
2764 case IDB_HIST_SMALL_COLOR
:
2766 info
.nID
= IDB_HIST_SMALL
;
2768 case IDB_HIST_LARGE_COLOR
:
2770 info
.nID
= IDB_HIST_LARGE
;
2776 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2778 /* Windows resize all the buttons to the size of a newly added standard image */
2779 if (lpAddBmp
->nID
& 1)
2781 /* large icons: 24x24. Will make the button 31x30 */
2782 SendMessageW (hwnd
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2786 /* small icons: 16x16. Will make the buttons 23x22 */
2787 SendMessageW (hwnd
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2790 TOOLBAR_CalcToolbar (hwnd
);
2794 info
.nButtons
= (INT
)wParam
;
2795 info
.hInst
= lpAddBmp
->hInst
;
2796 info
.nID
= lpAddBmp
->nID
;
2797 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2800 /* check if the bitmap is already loaded and compute iSumButtons */
2802 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2804 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2805 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2807 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2810 if (!infoPtr
->cimlDef
) {
2811 /* create new default image list */
2812 TRACE ("creating default image list!\n");
2814 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2815 ILC_COLORDDB
| ILC_MASK
, info
.nButtons
, 2);
2816 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2817 infoPtr
->himlInt
= himlDef
;
2820 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2824 WARN("No default image list available\n");
2828 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2831 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2832 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2833 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2834 infoPtr
->nNumBitmapInfos
++;
2835 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2837 InvalidateRect(hwnd
, NULL
, TRUE
);
2843 TOOLBAR_AddButtonsT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL fUnicode
)
2845 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2846 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
2847 INT nOldButtons
, nNewButtons
, nAddButtons
, nCount
;
2848 BOOL fHasString
= FALSE
;
2850 TRACE("adding %ld buttons (unicode=%d)!\n", wParam
, fUnicode
);
2852 nAddButtons
= (UINT
)wParam
;
2853 nOldButtons
= infoPtr
->nNumButtons
;
2854 nNewButtons
= nOldButtons
+ nAddButtons
;
2856 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
2857 infoPtr
->nNumButtons
= nNewButtons
;
2859 /* insert new button data */
2860 for (nCount
= 0; nCount
< nAddButtons
; nCount
++) {
2861 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nOldButtons
+nCount
];
2862 btnPtr
->iBitmap
= lpTbb
[nCount
].iBitmap
;
2863 btnPtr
->idCommand
= lpTbb
[nCount
].idCommand
;
2864 btnPtr
->fsState
= lpTbb
[nCount
].fsState
;
2865 btnPtr
->fsStyle
= lpTbb
[nCount
].fsStyle
;
2866 btnPtr
->dwData
= lpTbb
[nCount
].dwData
;
2867 btnPtr
->bHot
= FALSE
;
2868 if(HIWORD(lpTbb
[nCount
].iString
) && lpTbb
[nCount
].iString
!= -1)
2871 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, (LPWSTR
)lpTbb
[nCount
].iString
);
2873 Str_SetPtrAtoW((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lpTbb
[nCount
].iString
);
2877 btnPtr
->iString
= lpTbb
[nCount
].iString
;
2879 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
2882 if (infoPtr
->nNumStrings
> 0 || fHasString
)
2883 TOOLBAR_CalcToolbar(hwnd
);
2885 TOOLBAR_LayoutToolbar(hwnd
);
2886 TOOLBAR_AutoSize (hwnd
);
2888 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
2890 InvalidateRect(hwnd
, NULL
, TRUE
);
2897 TOOLBAR_AddStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2899 #define MAX_RESOURCE_STRING_LENGTH 512
2900 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2901 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2902 INT nIndex
= infoPtr
->nNumStrings
;
2904 if ((wParam
) && (HIWORD(lParam
) == 0)) {
2905 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2910 TRACE("adding string from resource!\n");
2912 len
= LoadStringW ((HINSTANCE
)wParam
, (UINT
)lParam
,
2913 szString
, MAX_RESOURCE_STRING_LENGTH
);
2915 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2916 if (len
== 0 || len
== 1)
2919 TRACE("Delimiter: 0x%x\n", *szString
);
2920 delimiter
= *szString
;
2923 while ((next_delim
= strchrW(p
, delimiter
)) != NULL
) {
2925 if (next_delim
+ 1 >= szString
+ len
)
2927 /* this may happen if delimiter == '\0' or if the last char is a
2928 * delimiter (then it is ignored like the native does) */
2932 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2933 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2934 infoPtr
->nNumStrings
++;
2940 LPWSTR p
= (LPWSTR
)lParam
;
2945 TRACE("adding string(s) from array!\n");
2949 TRACE("len=%d %s\n", len
, debugstr_w(p
));
2950 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2951 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2952 infoPtr
->nNumStrings
++;
2959 TOOLBAR_CalcToolbar(hwnd
);
2965 TOOLBAR_AddStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2967 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2968 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2973 if ((wParam
) && (HIWORD(lParam
) == 0)) /* load from resources */
2974 return TOOLBAR_AddStringW(hwnd
, wParam
, lParam
);
2980 TRACE("adding string(s) from array!\n");
2981 nIndex
= infoPtr
->nNumStrings
;
2984 TRACE("len=%d \"%s\"\n", len
, p
);
2986 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2987 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2988 infoPtr
->nNumStrings
++;
2994 TOOLBAR_CalcToolbar(hwnd
);
3000 TOOLBAR_AutoSize (HWND hwnd
)
3002 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3008 TRACE("auto sizing, style=%x!\n", infoPtr
->dwStyle
);
3010 parent
= GetParent (hwnd
);
3012 if (!parent
|| !infoPtr
->bDoRedraw
)
3015 GetClientRect(parent
, &parent_rect
);
3017 x
= parent_rect
.left
;
3018 y
= parent_rect
.top
;
3020 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3022 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3023 cx
= parent_rect
.right
- parent_rect
.left
;
3025 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
))
3027 TOOLBAR_LayoutToolbar(hwnd
);
3028 InvalidateRect( hwnd
, NULL
, TRUE
);
3031 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3034 UINT uPosFlags
= SWP_NOZORDER
;
3036 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3038 GetWindowRect(hwnd
, &window_rect
);
3039 ScreenToClient(parent
, (LPPOINT
)&window_rect
.left
);
3040 y
= window_rect
.top
;
3042 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3044 GetWindowRect(hwnd
, &window_rect
);
3045 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3048 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3049 uPosFlags
|= SWP_NOMOVE
;
3051 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3052 cy
+= GetSystemMetrics(SM_CYEDGE
);
3054 if (infoPtr
->dwStyle
& WS_BORDER
)
3056 x
= y
= 1; /* FIXME: this looks wrong */
3057 cy
+= GetSystemMetrics(SM_CYEDGE
);
3058 cx
+= GetSystemMetrics(SM_CXEDGE
);
3061 SetWindowPos(hwnd
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3069 TOOLBAR_ButtonCount (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3071 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3073 return infoPtr
->nNumButtons
;
3078 TOOLBAR_ButtonStructSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3080 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3082 infoPtr
->dwStructSize
= (DWORD
)wParam
;
3089 TOOLBAR_ChangeBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3091 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3092 TBUTTON_INFO
*btnPtr
;
3095 TRACE("button %ld, iBitmap now %d\n", wParam
, LOWORD(lParam
));
3097 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3101 btnPtr
= &infoPtr
->buttons
[nIndex
];
3102 btnPtr
->iBitmap
= LOWORD(lParam
);
3104 /* we HAVE to erase the background, the new bitmap could be */
3106 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3113 TOOLBAR_CheckButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3115 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3116 TBUTTON_INFO
*btnPtr
;
3119 BOOL bChecked
= FALSE
;
3121 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3123 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd
, nIndex
, lParam
);
3128 btnPtr
= &infoPtr
->buttons
[nIndex
];
3130 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? TRUE
: FALSE
;
3132 if (LOWORD(lParam
) == FALSE
)
3133 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3135 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3137 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3138 if (nOldIndex
== nIndex
)
3140 if (nOldIndex
!= -1)
3141 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3143 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3146 if( bChecked
!= LOWORD(lParam
) )
3148 if (nOldIndex
!= -1)
3149 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3150 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3153 /* FIXME: Send a WM_NOTIFY?? */
3160 TOOLBAR_CommandToIndex (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3162 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3164 return TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3169 TOOLBAR_Customize (HWND hwnd
)
3171 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3172 CUSTDLG_INFO custInfo
;
3178 custInfo
.tbInfo
= infoPtr
;
3179 custInfo
.tbHwnd
= hwnd
;
3181 /* send TBN_BEGINADJUST notification */
3182 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3184 if (!(hRes
= FindResourceW (COMCTL32_hModule
,
3185 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3186 (LPWSTR
)RT_DIALOG
)))
3189 if(!(template = LoadResource (COMCTL32_hModule
, hRes
)))
3192 ret
= DialogBoxIndirectParamW ((HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
),
3193 (LPCDLGTEMPLATEW
)template,
3195 TOOLBAR_CustomizeDialogProc
,
3198 /* send TBN_ENDADJUST notification */
3199 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3206 TOOLBAR_DeleteButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3208 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3209 INT nIndex
= (INT
)wParam
;
3211 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3213 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3216 memset(&nmtb
, 0, sizeof(nmtb
));
3217 nmtb
.iItem
= btnPtr
->idCommand
;
3218 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3219 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3220 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3221 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3222 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3223 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3224 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3226 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3228 if (infoPtr
->nNumButtons
== 1) {
3229 TRACE(" simple delete!\n");
3230 Free (infoPtr
->buttons
);
3231 infoPtr
->buttons
= NULL
;
3232 infoPtr
->nNumButtons
= 0;
3235 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3236 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3238 infoPtr
->nNumButtons
--;
3239 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3241 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3242 nIndex
* sizeof(TBUTTON_INFO
));
3245 if (nIndex
< infoPtr
->nNumButtons
) {
3246 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3247 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3253 TOOLBAR_LayoutToolbar(hwnd
);
3255 InvalidateRect (hwnd
, NULL
, TRUE
);
3262 TOOLBAR_EnableButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3264 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3265 TBUTTON_INFO
*btnPtr
;
3269 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3271 TRACE("hwnd=%p, btn index=%ld, lParam=0x%08lx\n", hwnd
, wParam
, lParam
);
3276 btnPtr
= &infoPtr
->buttons
[nIndex
];
3278 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3280 /* update the toolbar button state */
3281 if(LOWORD(lParam
) == FALSE
) {
3282 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3284 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3287 /* redraw the button only if the state of the button changed */
3288 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3289 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3295 static inline LRESULT
3296 TOOLBAR_GetAnchorHighlight (HWND hwnd
)
3298 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3300 return infoPtr
->bAnchor
;
3305 TOOLBAR_GetBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3307 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3310 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3314 return infoPtr
->buttons
[nIndex
].iBitmap
;
3318 static inline LRESULT
3319 TOOLBAR_GetBitmapFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3321 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3326 TOOLBAR_GetButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3328 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3329 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3330 INT nIndex
= (INT
)wParam
;
3331 TBUTTON_INFO
*btnPtr
;
3336 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3339 btnPtr
= &infoPtr
->buttons
[nIndex
];
3340 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3341 lpTbb
->idCommand
= btnPtr
->idCommand
;
3342 lpTbb
->fsState
= btnPtr
->fsState
;
3343 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3344 lpTbb
->bReserved
[0] = 0;
3345 lpTbb
->bReserved
[1] = 0;
3346 lpTbb
->dwData
= btnPtr
->dwData
;
3347 lpTbb
->iString
= btnPtr
->iString
;
3354 TOOLBAR_GetButtonInfoT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL bUnicode
)
3356 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3357 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3358 LPTBBUTTONINFOW lpTbInfo
= (LPTBBUTTONINFOW
)lParam
;
3359 TBUTTON_INFO
*btnPtr
;
3362 if (lpTbInfo
== NULL
)
3365 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3366 * the headers and tests shows that even with comctl 6 Vista accepts only the
3367 * original TBBUTTONINFO size
3369 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3371 WARN("Invalid button size\n");
3375 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
3376 lpTbInfo
->dwMask
& 0x80000000);
3380 if (!(btnPtr
= &infoPtr
->buttons
[nIndex
])) return -1;
3382 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3383 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3384 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3385 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3386 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3387 lpTbInfo
->lParam
= btnPtr
->dwData
;
3388 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3389 lpTbInfo
->cx
= (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3390 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3391 lpTbInfo
->fsState
= btnPtr
->fsState
;
3392 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3393 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3394 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3395 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3396 can't use TOOLBAR_GetText here */
3397 if (HIWORD(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3398 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3400 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3402 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3404 lpTbInfo
->pszText
[0] = '\0';
3411 TOOLBAR_GetButtonSize (HWND hwnd
)
3413 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3415 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3416 (WORD
)infoPtr
->nButtonHeight
);
3421 TOOLBAR_GetButtonTextA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3423 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3430 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3434 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3436 return WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3437 (LPSTR
)lParam
, 0x7fffffff, NULL
, NULL
) - 1;
3442 TOOLBAR_GetButtonTextW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3444 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3449 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3453 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3457 ret
= strlenW (lpText
);
3460 strcpyW ((LPWSTR
)lParam
, lpText
);
3468 TOOLBAR_GetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3470 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3471 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3472 return (LRESULT
)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3476 static inline LRESULT
3477 TOOLBAR_GetExtendedStyle (HWND hwnd
)
3479 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3483 return infoPtr
->dwExStyle
;
3488 TOOLBAR_GetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3490 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3491 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3492 return (LRESULT
)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3497 TOOLBAR_GetHotItem (HWND hwnd
)
3499 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3501 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3504 if (infoPtr
->nHotItem
< 0)
3507 return (LRESULT
)infoPtr
->nHotItem
;
3512 TOOLBAR_GetDefImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3514 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3515 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3516 return (LRESULT
) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd
), wParam
);
3521 TOOLBAR_GetInsertMark (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3523 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3524 TBINSERTMARK
*lptbim
= (TBINSERTMARK
*)lParam
;
3526 TRACE("hwnd = %p, lptbim = %p\n", hwnd
, lptbim
);
3528 *lptbim
= infoPtr
->tbim
;
3535 TOOLBAR_GetInsertMarkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3537 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3539 TRACE("hwnd = %p\n", hwnd
);
3541 return (LRESULT
)infoPtr
->clrInsertMark
;
3546 TOOLBAR_GetItemRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3548 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3549 TBUTTON_INFO
*btnPtr
;
3553 nIndex
= (INT
)wParam
;
3554 btnPtr
= &infoPtr
->buttons
[nIndex
];
3555 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3557 lpRect
= (LPRECT
)lParam
;
3560 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3563 lpRect
->left
= btnPtr
->rect
.left
;
3564 lpRect
->right
= btnPtr
->rect
.right
;
3565 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3566 lpRect
->top
= btnPtr
->rect
.top
;
3573 TOOLBAR_GetMaxSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3575 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3576 LPSIZE lpSize
= (LPSIZE
)lParam
;
3581 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3582 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3584 TRACE("maximum size %d x %d\n",
3585 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3586 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3592 /* << TOOLBAR_GetObject >> */
3596 TOOLBAR_GetPadding (HWND hwnd
)
3598 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3601 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3602 return (LRESULT
) oldPad
;
3607 TOOLBAR_GetRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3609 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3610 TBUTTON_INFO
*btnPtr
;
3614 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3615 btnPtr
= &infoPtr
->buttons
[nIndex
];
3616 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3618 lpRect
= (LPRECT
)lParam
;
3622 lpRect
->left
= btnPtr
->rect
.left
;
3623 lpRect
->right
= btnPtr
->rect
.right
;
3624 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3625 lpRect
->top
= btnPtr
->rect
.top
;
3632 TOOLBAR_GetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3634 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3636 return infoPtr
->nRows
;
3641 TOOLBAR_GetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3643 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3646 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3650 return infoPtr
->buttons
[nIndex
].fsState
;
3655 TOOLBAR_GetStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3657 return GetWindowLongW(hwnd
, GWL_STYLE
);
3662 TOOLBAR_GetTextRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3664 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3666 return infoPtr
->nMaxTextRows
;
3671 TOOLBAR_GetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3673 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3675 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3676 TOOLBAR_TooltipCreateControl(infoPtr
);
3677 return (LRESULT
)infoPtr
->hwndToolTip
;
3682 TOOLBAR_GetUnicodeFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3684 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3686 TRACE("%s hwnd=%p\n",
3687 infoPtr
->bUnicode
? "TRUE" : "FALSE", hwnd
);
3689 return infoPtr
->bUnicode
;
3693 static inline LRESULT
3694 TOOLBAR_GetVersion (HWND hwnd
)
3696 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3697 return infoPtr
->iVersion
;
3702 TOOLBAR_HideButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3704 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3705 TBUTTON_INFO
*btnPtr
;
3710 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3714 btnPtr
= &infoPtr
->buttons
[nIndex
];
3715 if (LOWORD(lParam
) == FALSE
)
3716 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3718 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3720 TOOLBAR_LayoutToolbar (hwnd
);
3722 InvalidateRect (hwnd
, NULL
, TRUE
);
3728 static inline LRESULT
3729 TOOLBAR_HitTest (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3731 return TOOLBAR_InternalHitTest (hwnd
, (LPPOINT
)lParam
);
3736 TOOLBAR_Indeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3738 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3739 TBUTTON_INFO
*btnPtr
;
3743 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3747 btnPtr
= &infoPtr
->buttons
[nIndex
];
3748 oldState
= btnPtr
->fsState
;
3749 if (LOWORD(lParam
) == FALSE
)
3750 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3752 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3754 if(oldState
!= btnPtr
->fsState
)
3755 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3762 TOOLBAR_InsertButtonT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL fUnicode
)
3764 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3765 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3766 INT nIndex
= (INT
)wParam
;
3771 TOOLBAR_DumpButton(infoPtr
, (TBUTTON_INFO
*)lpTbb
, nIndex
, FALSE
);
3774 /* EPP: this seems to be an undocumented call (from my IE4)
3775 * I assume in that case that:
3776 * - index of insertion is at the end of existing buttons
3777 * I only see this happen with nIndex == -1, but it could have a special
3778 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3780 nIndex
= infoPtr
->nNumButtons
;
3782 } else if (nIndex
< 0)
3785 TRACE("inserting button index=%d\n", nIndex
);
3786 if (nIndex
> infoPtr
->nNumButtons
) {
3787 nIndex
= infoPtr
->nNumButtons
;
3788 TRACE("adjust index=%d\n", nIndex
);
3791 infoPtr
->nNumButtons
++;
3792 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3793 memmove(&infoPtr
->buttons
[nIndex
+1], &infoPtr
->buttons
[nIndex
],
3794 (infoPtr
->nNumButtons
- nIndex
- 1) * sizeof(TBUTTON_INFO
));
3796 /* insert new button */
3797 infoPtr
->buttons
[nIndex
].iBitmap
= lpTbb
->iBitmap
;
3798 infoPtr
->buttons
[nIndex
].idCommand
= lpTbb
->idCommand
;
3799 infoPtr
->buttons
[nIndex
].fsState
= lpTbb
->fsState
;
3800 infoPtr
->buttons
[nIndex
].fsStyle
= lpTbb
->fsStyle
;
3801 infoPtr
->buttons
[nIndex
].dwData
= lpTbb
->dwData
;
3802 /* if passed string and not index, then add string */
3803 if(HIWORD(lpTbb
->iString
) && lpTbb
->iString
!=-1) {
3805 Str_SetPtrW((LPWSTR
*)&infoPtr
->buttons
[nIndex
].iString
, (LPWSTR
)lpTbb
->iString
);
3807 Str_SetPtrAtoW((LPWSTR
*)&infoPtr
->buttons
[nIndex
].iString
, (LPCSTR
)lpTbb
->iString
);
3810 infoPtr
->buttons
[nIndex
].iString
= lpTbb
->iString
;
3812 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3814 if (infoPtr
->nNumStrings
> 0)
3815 TOOLBAR_CalcToolbar(hwnd
);
3817 TOOLBAR_LayoutToolbar(hwnd
);
3818 TOOLBAR_AutoSize (hwnd
);
3820 InvalidateRect (hwnd
, NULL
, TRUE
);
3825 /* << TOOLBAR_InsertMarkHitTest >> */
3829 TOOLBAR_IsButtonChecked (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3831 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3834 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3838 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3843 TOOLBAR_IsButtonEnabled (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3845 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3848 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3852 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3857 TOOLBAR_IsButtonHidden (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3859 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3862 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3866 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3871 TOOLBAR_IsButtonHighlighted (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3873 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3876 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3880 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3885 TOOLBAR_IsButtonIndeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3887 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3890 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3894 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3899 TOOLBAR_IsButtonPressed (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3901 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3904 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3908 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3913 TOOLBAR_LoadImages (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3916 tbab
.hInst
= (HINSTANCE
)lParam
;
3919 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", hwnd
, tbab
.hInst
, tbab
.nID
);
3921 return TOOLBAR_AddBitmap(hwnd
, 0, (LPARAM
)&tbab
);
3926 TOOLBAR_MapAccelerator (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3928 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3929 WCHAR wAccel
= (WCHAR
)wParam
;
3930 UINT
* pIDButton
= (UINT
*)lParam
;
3931 WCHAR wszAccel
[] = {'&',wAccel
,0};
3934 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3935 hwnd
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3937 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3939 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3940 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3941 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3943 int iLen
= strlenW(wszAccel
);
3944 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3951 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3956 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
3958 *pIDButton
= btnPtr
->idCommand
;
3970 TOOLBAR_MarkButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3972 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3975 TBUTTON_INFO
*btnPtr
;
3977 TRACE("hwnd = %p, wParam = %ld, lParam = 0x%08lx\n", hwnd
, wParam
, lParam
);
3979 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3983 btnPtr
= &infoPtr
->buttons
[nIndex
];
3984 oldState
= btnPtr
->fsState
;
3987 btnPtr
->fsState
|= TBSTATE_MARKED
;
3989 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
3991 if(oldState
!= btnPtr
->fsState
)
3992 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3998 /* fixes up an index of a button affected by a move */
3999 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
4003 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
4005 else if (*pIndex
== nIndex
)
4006 *pIndex
= nMoveIndex
;
4010 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
4012 else if (*pIndex
== nIndex
)
4013 *pIndex
= nMoveIndex
;
4019 TOOLBAR_MoveButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4021 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4024 INT nMoveIndex
= (INT
)lParam
;
4025 TBUTTON_INFO button
;
4027 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd
, wParam
, lParam
);
4029 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, TRUE
);
4030 if ((nIndex
== -1) || (nMoveIndex
< 0))
4033 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
4034 nMoveIndex
= infoPtr
->nNumButtons
- 1;
4036 button
= infoPtr
->buttons
[nIndex
];
4038 /* move button right */
4039 if (nIndex
< nMoveIndex
)
4041 nCount
= nMoveIndex
- nIndex
;
4042 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
4043 infoPtr
->buttons
[nMoveIndex
] = button
;
4045 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
4046 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
4047 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
4048 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
4050 else if (nIndex
> nMoveIndex
) /* move button left */
4052 nCount
= nIndex
- nMoveIndex
;
4053 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
4054 infoPtr
->buttons
[nMoveIndex
] = button
;
4056 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
4057 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
4058 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
4059 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
4062 TOOLBAR_LayoutToolbar(hwnd
);
4063 TOOLBAR_AutoSize(hwnd
);
4064 InvalidateRect(hwnd
, NULL
, TRUE
);
4071 TOOLBAR_PressButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4073 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4074 TBUTTON_INFO
*btnPtr
;
4078 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4082 btnPtr
= &infoPtr
->buttons
[nIndex
];
4083 oldState
= btnPtr
->fsState
;
4084 if (LOWORD(lParam
) == FALSE
)
4085 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
4087 btnPtr
->fsState
|= TBSTATE_PRESSED
;
4089 if(oldState
!= btnPtr
->fsState
)
4090 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4095 /* FIXME: there might still be some confusion her between number of buttons
4096 * and number of bitmaps */
4098 TOOLBAR_ReplaceBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4100 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4101 LPTBREPLACEBITMAP lpReplace
= (LPTBREPLACEBITMAP
) lParam
;
4103 int i
= 0, nOldButtons
= 0, pos
= 0;
4104 int nOldBitmaps
, nNewBitmaps
= 0;
4105 HIMAGELIST himlDef
= 0;
4107 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4108 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
4109 lpReplace
->nButtons
);
4111 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4113 FIXME("changing standard bitmaps not implemented\n");
4116 else if (lpReplace
->hInstOld
!= 0)
4117 FIXME("resources not in the current module not implemented\n");
4119 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4120 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4121 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4122 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4123 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4125 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4126 nOldButtons
= tbi
->nButtons
;
4127 tbi
->nButtons
= lpReplace
->nButtons
;
4128 tbi
->hInst
= lpReplace
->hInstNew
;
4129 tbi
->nID
= lpReplace
->nIDNew
;
4130 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4133 pos
+= tbi
->nButtons
;
4136 if (nOldButtons
== 0)
4138 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4142 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4145 if (lpReplace
->hInstNew
)
4146 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4148 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4150 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4151 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4153 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4155 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4156 ImageList_Remove(himlDef
, i
);
4160 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4161 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4162 DeleteObject(hBitmap
);
4165 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4167 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4168 pos
, nOldBitmaps
, nNewBitmaps
);
4170 InvalidateRect(hwnd
, NULL
, TRUE
);
4175 /* helper for TOOLBAR_SaveRestoreW */
4177 TOOLBAR_Save(const TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4179 FIXME("save to %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4180 debugstr_w(lpSave
->pszValueName
));
4186 /* helper for TOOLBAR_Restore */
4188 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4192 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4194 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4197 Free(infoPtr
->buttons
);
4198 infoPtr
->buttons
= NULL
;
4199 infoPtr
->nNumButtons
= 0;
4203 /* helper for TOOLBAR_SaveRestoreW */
4205 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4214 /* restore toolbar information */
4215 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4216 debugstr_w(lpSave
->pszValueName
));
4218 memset(&nmtbr
, 0, sizeof(nmtbr
));
4220 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4221 KEY_QUERY_VALUE
, &hkey
);
4223 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4225 if (!res
&& dwType
!= REG_BINARY
)
4226 res
= ERROR_FILE_NOT_FOUND
;
4229 nmtbr
.pData
= Alloc(dwSize
);
4230 nmtbr
.cbData
= dwSize
;
4231 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4234 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4235 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4238 nmtbr
.pCurrent
= nmtbr
.pData
;
4240 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4241 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4243 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4247 /* remove all existing buttons as this function is designed to
4248 * restore the toolbar to a previously saved state */
4249 TOOLBAR_DeleteAllButtons(infoPtr
);
4251 for (i
= 0; i
< nmtbr
.cButtons
; i
++)
4254 nmtbr
.tbButton
.iBitmap
= -1;
4255 nmtbr
.tbButton
.fsState
= 0;
4256 nmtbr
.tbButton
.fsStyle
= 0;
4257 nmtbr
.tbButton
.idCommand
= 0;
4258 if (*nmtbr
.pCurrent
== (DWORD
)-1)
4261 nmtbr
.tbButton
.fsStyle
= TBSTYLE_SEP
;
4262 nmtbr
.tbButton
.iBitmap
= SEPARATOR_WIDTH
;
4264 else if (*nmtbr
.pCurrent
== (DWORD
)-2)
4266 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4268 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4272 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4274 /* can't contain real string as we don't know whether
4275 * the client put an ANSI or Unicode string in there */
4276 if (HIWORD(nmtbr
.tbButton
.iString
))
4277 nmtbr
.tbButton
.iString
= 0;
4279 TOOLBAR_InsertButtonT(infoPtr
->hwndSelf
, -1,
4280 (LPARAM
)&nmtbr
.tbButton
, TRUE
);
4283 /* do legacy notifications */
4284 if (infoPtr
->iVersion
< 5)
4286 /* FIXME: send TBN_BEGINADJUST */
4287 FIXME("send TBN_GETBUTTONINFO for each button\n");
4288 /* FIXME: send TBN_ENDADJUST */
4291 /* remove all uninitialised buttons
4292 * note: loop backwards to avoid having to fixup i on a
4294 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4295 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4296 TOOLBAR_DeleteButton(infoPtr
->hwndSelf
, i
, 0);
4298 /* only indicate success if at least one button survived */
4299 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4310 TOOLBAR_SaveRestoreW (HWND hwnd
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4312 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4314 if (lpSave
== NULL
) return 0;
4317 return TOOLBAR_Save(infoPtr
, lpSave
);
4319 return TOOLBAR_Restore(infoPtr
, lpSave
);
4324 TOOLBAR_SaveRestoreA (HWND hwnd
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4326 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4327 TBSAVEPARAMSW SaveW
;
4331 if (lpSave
== NULL
) return 0;
4333 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4334 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4335 if (pszSubKey
) goto exit
;
4336 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4338 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4339 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4340 if (!pszValueName
) goto exit
;
4341 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4343 SaveW
.pszValueName
= pszValueName
;
4344 SaveW
.pszSubKey
= pszSubKey
;
4345 SaveW
.hkr
= lpSave
->hkr
;
4346 result
= TOOLBAR_SaveRestoreW(hwnd
, wParam
, &SaveW
);
4349 Free (pszValueName
);
4357 TOOLBAR_SetAnchorHighlight (HWND hwnd
, WPARAM wParam
)
4359 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4360 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4362 TRACE("hwnd=%p, bAnchor = %s\n", hwnd
, wParam
? "TRUE" : "FALSE");
4364 infoPtr
->bAnchor
= (BOOL
)wParam
;
4366 /* Native does not remove the hot effect from an already hot button */
4368 return (LRESULT
)bOldAnchor
;
4373 TOOLBAR_SetBitmapSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4375 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4376 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4378 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd
, wParam
, lParam
);
4381 FIXME("wParam is %ld. Perhaps image list index?\n", wParam
);
4383 if (LOWORD(lParam
) == 0)
4384 lParam
= MAKELPARAM(1, HIWORD(lParam
));
4386 if (HIWORD(lParam
)==0)
4387 lParam
= MAKELPARAM(LOWORD(lParam
), 1);
4389 if (infoPtr
->nNumButtons
> 0)
4390 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4391 infoPtr
->nNumButtons
,
4392 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
4393 LOWORD(lParam
), HIWORD(lParam
));
4395 infoPtr
->nBitmapWidth
= (INT
)LOWORD(lParam
);
4396 infoPtr
->nBitmapHeight
= (INT
)HIWORD(lParam
);
4398 if ((himlDef
== infoPtr
->himlInt
) &&
4399 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4401 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4402 infoPtr
->nBitmapHeight
);
4405 TOOLBAR_CalcToolbar(hwnd
);
4406 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4412 TOOLBAR_SetButtonInfoA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4414 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4415 LPTBBUTTONINFOA lptbbi
= (LPTBBUTTONINFOA
)lParam
;
4416 TBUTTON_INFO
*btnPtr
;
4422 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOA
))
4425 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4426 lptbbi
->dwMask
& 0x80000000);
4430 btnPtr
= &infoPtr
->buttons
[nIndex
];
4431 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4432 btnPtr
->idCommand
= lptbbi
->idCommand
;
4433 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4434 btnPtr
->iBitmap
= lptbbi
->iImage
;
4435 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4436 btnPtr
->dwData
= lptbbi
->lParam
;
4437 if (lptbbi
->dwMask
& TBIF_SIZE
)
4438 btnPtr
->cx
= lptbbi
->cx
;
4439 if (lptbbi
->dwMask
& TBIF_STATE
)
4440 btnPtr
->fsState
= lptbbi
->fsState
;
4441 if (lptbbi
->dwMask
& TBIF_STYLE
)
4442 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4444 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4445 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4446 /* iString is index, zero it to make Str_SetPtr succeed */
4449 Str_SetPtrAtoW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4452 /* save the button rect to see if we need to redraw the whole toolbar */
4453 oldBtnRect
= btnPtr
->rect
;
4454 TOOLBAR_CalcToolbar(hwnd
);
4456 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4457 InvalidateRect(hwnd
, NULL
, TRUE
);
4459 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4466 TOOLBAR_SetButtonInfoW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4468 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4469 LPTBBUTTONINFOW lptbbi
= (LPTBBUTTONINFOW
)lParam
;
4470 TBUTTON_INFO
*btnPtr
;
4476 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4479 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4480 lptbbi
->dwMask
& 0x80000000);
4484 btnPtr
= &infoPtr
->buttons
[nIndex
];
4485 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4486 btnPtr
->idCommand
= lptbbi
->idCommand
;
4487 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4488 btnPtr
->iBitmap
= lptbbi
->iImage
;
4489 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4490 btnPtr
->dwData
= lptbbi
->lParam
;
4491 if (lptbbi
->dwMask
& TBIF_SIZE
)
4492 btnPtr
->cx
= lptbbi
->cx
;
4493 if (lptbbi
->dwMask
& TBIF_STATE
)
4494 btnPtr
->fsState
= lptbbi
->fsState
;
4495 if (lptbbi
->dwMask
& TBIF_STYLE
)
4496 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4498 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4499 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4500 /* iString is index, zero it to make Str_SetPtr succeed */
4502 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4505 /* save the button rect to see if we need to redraw the whole toolbar */
4506 oldBtnRect
= btnPtr
->rect
;
4507 TOOLBAR_CalcToolbar(hwnd
);
4509 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4510 InvalidateRect(hwnd
, NULL
, TRUE
);
4512 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4519 TOOLBAR_SetButtonSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4521 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4522 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4524 if ((cx
< 0) || (cy
< 0))
4526 ERR("invalid parameter 0x%08x\n", (DWORD
)lParam
);
4530 TRACE("%p, cx = %d, cy = %d\n", hwnd
, cx
, cy
);
4532 /* The documentation claims you can only change the button size before
4533 * any button has been added. But this is wrong.
4534 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4535 * it to the toolbar, and it checks that the return value is nonzero - mjm
4536 * Further testing shows that we must actually perform the change too.
4539 * The documentation also does not mention that if 0 is supplied for
4540 * either size, the system changes it to the default of 24 wide and
4541 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4543 if (cx
== 0) cx
= 24;
4544 if (cy
== 0) cx
= 22;
4546 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4547 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4549 infoPtr
->nButtonWidth
= cx
;
4550 infoPtr
->nButtonHeight
= cy
;
4552 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
4553 TOOLBAR_LayoutToolbar(hwnd
);
4559 TOOLBAR_SetButtonWidth (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4561 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4563 /* if setting to current values, ignore */
4564 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4565 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4566 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4567 infoPtr
->cxMin
, infoPtr
->cxMax
);
4571 /* save new values */
4572 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4573 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4575 /* otherwise we need to recalc the toolbar and in some cases
4576 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4577 which doesn't actually draw - GA). */
4578 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4579 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4581 TOOLBAR_CalcToolbar (hwnd
);
4583 InvalidateRect (hwnd
, NULL
, TRUE
);
4590 TOOLBAR_SetCmdId (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4592 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4593 INT nIndex
= (INT
)wParam
;
4595 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4598 infoPtr
->buttons
[nIndex
].idCommand
= (INT
)lParam
;
4600 if (infoPtr
->hwndToolTip
) {
4602 FIXME("change tool tip!\n");
4611 TOOLBAR_SetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4613 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4614 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4615 HIMAGELIST himlTemp
;
4618 if (infoPtr
->iVersion
>= 5)
4621 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4622 &infoPtr
->cimlDis
, himl
, id
);
4624 /* FIXME: redraw ? */
4626 return (LRESULT
)himlTemp
;
4631 TOOLBAR_SetDrawTextFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4633 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4636 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd
, (DWORD
)wParam
, (DWORD
)lParam
);
4638 dwTemp
= infoPtr
->dwDTFlags
;
4639 infoPtr
->dwDTFlags
=
4640 (infoPtr
->dwDTFlags
& (DWORD
)wParam
) | (DWORD
)lParam
;
4642 return (LRESULT
)dwTemp
;
4645 /* This function differs a bit from what MSDN says it does:
4646 * 1. lParam contains extended style flags to OR with current style
4647 * (MSDN isn't clear on the OR bit)
4648 * 2. wParam appears to contain extended style flags to be reset
4649 * (MSDN says that this parameter is reserved)
4652 TOOLBAR_SetExtendedStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4654 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4657 dwTemp
= infoPtr
->dwExStyle
;
4658 infoPtr
->dwExStyle
&= ~wParam
;
4659 infoPtr
->dwExStyle
|= (DWORD
)lParam
;
4661 TRACE("new style 0x%08x\n", infoPtr
->dwExStyle
);
4663 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4664 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4665 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4667 TOOLBAR_CalcToolbar (hwnd
);
4669 TOOLBAR_AutoSize(hwnd
);
4671 InvalidateRect(hwnd
, NULL
, TRUE
);
4673 return (LRESULT
)dwTemp
;
4678 TOOLBAR_SetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4680 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4681 HIMAGELIST himlTemp
;
4682 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4685 if (infoPtr
->iVersion
>= 5)
4688 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd
, himl
, id
);
4690 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4691 &infoPtr
->cimlHot
, himl
, id
);
4693 /* FIXME: redraw ? */
4695 return (LRESULT
)himlTemp
;
4699 /* Makes previous hot button no longer hot, makes the specified
4700 * button hot and sends appropriate notifications. dwReason is one or
4701 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4702 * NOTE 1: this function does not validate nHit
4703 * NOTE 2: the name of this function is completely made up and
4704 * not based on any documentation from Microsoft. */
4706 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4708 if (infoPtr
->nHotItem
!= nHit
)
4710 NMTBHOTITEM nmhotitem
;
4711 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4713 nmhotitem
.dwFlags
= dwReason
;
4714 if(infoPtr
->nHotItem
>= 0)
4716 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4717 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4721 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4722 nmhotitem
.idOld
= 0;
4727 btnPtr
= &infoPtr
->buttons
[nHit
];
4728 nmhotitem
.idNew
= btnPtr
->idCommand
;
4732 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4733 nmhotitem
.idNew
= 0;
4736 /* now change the hot and invalidate the old and new buttons - if the
4738 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4741 oldBtnPtr
->bHot
= FALSE
;
4742 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4744 /* setting disabled buttons as hot fails even if the notify contains the button id */
4745 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4746 btnPtr
->bHot
= TRUE
;
4747 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4748 infoPtr
->nHotItem
= nHit
;
4751 infoPtr
->nHotItem
= -1;
4757 TOOLBAR_SetHotItem (HWND hwnd
, WPARAM wParam
)
4759 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4760 INT nOldHotItem
= infoPtr
->nHotItem
;
4762 TRACE("hwnd = %p, nHit = %d\n", hwnd
, (INT
)wParam
);
4764 if ((INT
)wParam
> infoPtr
->nNumButtons
)
4765 return infoPtr
->nHotItem
;
4767 if ((INT
)wParam
< 0)
4770 /* NOTE: an application can still remove the hot item even if anchor
4771 * highlighting is enabled */
4773 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, HICF_OTHER
);
4775 if (nOldHotItem
< 0)
4778 return (LRESULT
)nOldHotItem
;
4783 TOOLBAR_SetImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4785 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4786 HIMAGELIST himlTemp
;
4787 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4788 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4791 if (infoPtr
->iVersion
>= 5)
4794 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4795 &infoPtr
->cimlDef
, himl
, id
);
4797 infoPtr
->nNumBitmaps
= 0;
4798 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4799 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4801 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4802 &infoPtr
->nBitmapHeight
))
4804 infoPtr
->nBitmapWidth
= 1;
4805 infoPtr
->nBitmapHeight
= 1;
4807 TOOLBAR_CalcToolbar(hwnd
);
4808 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4809 TOOLBAR_SetButtonSize(hwnd
, 0, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4811 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4812 hwnd
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4813 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4815 InvalidateRect(hwnd
, NULL
, TRUE
);
4817 return (LRESULT
)himlTemp
;
4822 TOOLBAR_SetIndent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4824 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4826 infoPtr
->nIndent
= (INT
)wParam
;
4830 /* process only on indent changing */
4831 if(infoPtr
->nIndent
!= (INT
)wParam
)
4833 infoPtr
->nIndent
= (INT
)wParam
;
4834 TOOLBAR_CalcToolbar (hwnd
);
4835 InvalidateRect(hwnd
, NULL
, FALSE
);
4843 TOOLBAR_SetInsertMark (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4845 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4846 TBINSERTMARK
*lptbim
= (TBINSERTMARK
*)lParam
;
4848 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd
, lptbim
->iButton
, lptbim
->dwFlags
);
4850 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4852 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4856 if ((lptbim
->iButton
== -1) ||
4857 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4858 (lptbim
->iButton
>= 0)))
4860 infoPtr
->tbim
= *lptbim
;
4861 /* FIXME: don't need to update entire toolbar */
4862 InvalidateRect(hwnd
, NULL
, TRUE
);
4865 ERR("Invalid button index %d\n", lptbim
->iButton
);
4872 TOOLBAR_SetInsertMarkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4874 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4876 infoPtr
->clrInsertMark
= (COLORREF
)lParam
;
4878 /* FIXME: don't need to update entire toolbar */
4879 InvalidateRect(hwnd
, NULL
, TRUE
);
4886 TOOLBAR_SetMaxTextRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4888 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4890 infoPtr
->nMaxTextRows
= (INT
)wParam
;
4892 TOOLBAR_CalcToolbar(hwnd
);
4897 /* MSDN gives slightly wrong info on padding.
4898 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4899 * 2. It is not used to create a blank area between the edge of the button
4900 * and the text or image if TBSTYLE_LIST is set. It is used to control
4901 * the gap between the image and text.
4902 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4903 * to control the bottom and right borders [with the border being
4904 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4905 * is shared evenly on both sides of the button.
4906 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4909 TOOLBAR_SetPadding (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4911 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4914 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4915 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4916 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4917 TRACE("cx=%d, cy=%d\n",
4918 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4919 return (LRESULT
) oldPad
;
4924 TOOLBAR_SetParent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4926 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4931 hwndOldNotify
= infoPtr
->hwndNotify
;
4932 infoPtr
->hwndNotify
= (HWND
)wParam
;
4934 return (LRESULT
)hwndOldNotify
;
4939 TOOLBAR_SetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4941 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4942 LPRECT lprc
= (LPRECT
)lParam
;
4943 int rows
= LOWORD(wParam
);
4944 BOOL bLarger
= HIWORD(wParam
);
4948 TRACE("Setting rows to %d (%d)\n", rows
, bLarger
);
4950 if(infoPtr
->nRows
!= rows
)
4952 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
;
4953 int curColumn
= 0; /* Current column */
4954 int curRow
= 0; /* Current row */
4955 int hidden
= 0; /* Number of hidden buttons */
4956 int seps
= 0; /* Number of separators */
4957 int idealWrap
= 0; /* Ideal wrap point */
4962 Calculate new size and wrap points - Under windows, setrows will
4963 change the dimensions if needed to show the number of requested
4964 rows (if CCS_NORESIZE is set), or will take up the whole window
4965 (if no CCS_NORESIZE).
4967 Basic algorithm - If N buttons, and y rows requested, each row
4968 contains N/y buttons.
4970 FIXME: Handling of separators not obvious from testing results
4971 FIXME: Take width of window into account?
4974 /* Loop through the buttons one by one counting key items */
4975 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4977 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
4978 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4980 else if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
4984 /* FIXME: Separators make this quite complex */
4985 if (seps
) FIXME("Separators unhandled\n");
4987 /* Round up so more per line, i.e., less rows */
4988 idealWrap
= (infoPtr
->nNumButtons
- hidden
+ (rows
-1)) / rows
;
4990 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4991 achieve the requested number of rows. */
4992 if (bLarger
&& idealWrap
> 1)
4994 int resRows
= (infoPtr
->nNumButtons
+ (idealWrap
-1)) / idealWrap
;
4995 int moreRows
= (infoPtr
->nNumButtons
+ (idealWrap
-2)) / (idealWrap
-1);
4997 if (resRows
< rows
&& moreRows
> rows
)
5000 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap
);
5004 curColumn
= curRow
= 0;
5006 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap
,
5007 infoPtr
->nNumButtons
, hidden
, rows
);
5009 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
5011 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
5014 /* Step on, wrap if necessary or flag next to wrap */
5023 if (curColumn
> (idealWrap
-1)) {
5025 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
5029 TRACE("Result - %d rows\n", curRow
+ 1);
5031 /* recalculate toolbar */
5032 TOOLBAR_CalcToolbar (hwnd
);
5034 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
5035 if NORESIZE is NOT set, then the toolbar will always be resized to
5036 take up the whole window. With it set, sizing needs to be manual. */
5037 if (infoPtr
->dwStyle
& CCS_NORESIZE
) {
5038 SetWindowPos(hwnd
, NULL
, 0, 0,
5039 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
5040 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
,
5044 /* repaint toolbar */
5045 InvalidateRect(hwnd
, NULL
, TRUE
);
5048 /* return bounding rectangle */
5050 lprc
->left
= infoPtr
->rcBound
.left
;
5051 lprc
->right
= infoPtr
->rcBound
.right
;
5052 lprc
->top
= infoPtr
->rcBound
.top
;
5053 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
5061 TOOLBAR_SetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5063 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5064 TBUTTON_INFO
*btnPtr
;
5067 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
5071 btnPtr
= &infoPtr
->buttons
[nIndex
];
5073 /* if hidden state has changed the invalidate entire window and recalc */
5074 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
5075 btnPtr
->fsState
= LOWORD(lParam
);
5076 TOOLBAR_CalcToolbar (hwnd
);
5077 InvalidateRect(hwnd
, 0, TRUE
);
5081 /* process state changing if current state doesn't match new state */
5082 if(btnPtr
->fsState
!= LOWORD(lParam
))
5084 btnPtr
->fsState
= LOWORD(lParam
);
5085 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5093 TOOLBAR_SetStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5095 SetWindowLongW(hwnd
, GWL_STYLE
, lParam
);
5101 static inline LRESULT
5102 TOOLBAR_SetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5104 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5106 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd
, (HWND
)wParam
, lParam
);
5108 infoPtr
->hwndToolTip
= (HWND
)wParam
;
5114 TOOLBAR_SetUnicodeFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5116 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5119 TRACE("%s hwnd=%p\n",
5120 ((BOOL
)wParam
) ? "TRUE" : "FALSE", hwnd
);
5122 bTemp
= infoPtr
->bUnicode
;
5123 infoPtr
->bUnicode
= (BOOL
)wParam
;
5130 TOOLBAR_GetColorScheme (HWND hwnd
, LPCOLORSCHEME lParam
)
5132 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5134 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
5135 comctl32_color
.clrBtnHighlight
:
5136 infoPtr
->clrBtnHighlight
;
5137 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
5138 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
5144 TOOLBAR_SetColorScheme (HWND hwnd
, const COLORSCHEME
*lParam
)
5146 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5148 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5149 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
5150 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
5152 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
5153 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
5154 InvalidateRect(hwnd
, NULL
, TRUE
);
5160 TOOLBAR_SetVersion (HWND hwnd
, INT iVersion
)
5162 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5163 INT iOldVersion
= infoPtr
->iVersion
;
5165 infoPtr
->iVersion
= iVersion
;
5167 if (infoPtr
->iVersion
>= 5)
5168 TOOLBAR_SetUnicodeFormat(hwnd
, (WPARAM
)TRUE
, (LPARAM
)0);
5175 TOOLBAR_GetStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5177 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5178 WORD iString
= HIWORD(wParam
);
5179 WORD buffersize
= LOWORD(wParam
);
5180 LPSTR str
= (LPSTR
)lParam
;
5183 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, buffersize
, str
);
5185 if (iString
< infoPtr
->nNumStrings
)
5187 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
);
5216 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5221 TRACE("returning %s\n", debugstr_w(str
));
5224 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5229 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5230 * is the maximum size of the toolbar? */
5231 static LRESULT
TOOLBAR_Unkwn45D(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5233 SIZE
* pSize
= (SIZE
*)lParam
;
5234 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5239 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5240 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5241 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5244 TOOLBAR_Unkwn45E (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5246 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5247 INT nOldHotItem
= infoPtr
->nHotItem
;
5249 TRACE("old item=%d, new item=%d, flags=%08x\n",
5250 nOldHotItem
, infoPtr
->nHotItem
, (DWORD
)lParam
);
5252 if ((INT
) wParam
< 0 || (INT
)wParam
> infoPtr
->nNumButtons
)
5255 /* NOTE: an application can still remove the hot item even if anchor
5256 * highlighting is enabled */
5258 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, lParam
);
5262 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5265 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5266 * which controls the amount of spacing between the image and the text
5267 * of buttons for TBSTYLE_LIST toolbars. */
5268 static LRESULT
TOOLBAR_Unkwn460(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5270 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5272 TRACE("hwnd=%p iListGap=%ld\n", hwnd
, wParam
);
5275 FIXME("lParam = 0x%08lx. Please report\n", lParam
);
5277 infoPtr
->iListGap
= (INT
)wParam
;
5279 InvalidateRect(hwnd
, NULL
, TRUE
);
5284 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5285 * of image lists associated with the various states. */
5286 static LRESULT
TOOLBAR_Unkwn462(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5288 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5290 TRACE("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5292 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5296 TOOLBAR_Unkwn463 (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5298 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5299 LPSIZE lpsize
= (LPSIZE
)lParam
;
5305 * Testing shows the following:
5306 * wParam = 0 adjust cx value
5307 * = 1 set cy value to max size.
5308 * lParam pointer to SIZE structure
5311 TRACE("[0463] wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5312 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5316 if (lpsize
->cx
== -1) {
5317 /* **** this is wrong, native measures each button and sets it */
5318 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5320 else if(HIWORD(lpsize
->cx
)) {
5322 HWND hwndParent
= GetParent(hwnd
);
5324 GetWindowRect(hwnd
, &rc
);
5325 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5326 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc
));
5327 lpsize
->cx
= max(rc
.right
-rc
.left
,
5328 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5331 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5335 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5338 ERR("Unknown wParam %ld for Toolbar message [0463]. Please report\n",
5342 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5343 lpsize
->cx
, lpsize
->cy
);
5347 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5349 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5351 InvalidateRect(hwnd
, NULL
, TRUE
);
5357 TOOLBAR_Create (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5359 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5360 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
5363 TRACE("hwnd = %p\n", hwnd
);
5365 /* initialize info structure */
5366 infoPtr
->nButtonWidth
= 23;
5367 infoPtr
->nButtonHeight
= 22;
5368 infoPtr
->nBitmapHeight
= 16;
5369 infoPtr
->nBitmapWidth
= 16;
5371 infoPtr
->nMaxTextRows
= 1;
5372 infoPtr
->cxMin
= -1;
5373 infoPtr
->cxMax
= -1;
5374 infoPtr
->nNumBitmaps
= 0;
5375 infoPtr
->nNumStrings
= 0;
5377 infoPtr
->bCaptured
= FALSE
;
5378 infoPtr
->nButtonDown
= -1;
5379 infoPtr
->nButtonDrag
= -1;
5380 infoPtr
->nOldHit
= -1;
5381 infoPtr
->nHotItem
= -1;
5382 infoPtr
->hwndNotify
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
5383 infoPtr
->dwDTFlags
= (dwStyle
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
5384 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
5385 infoPtr
->bDragOutSent
= FALSE
;
5386 infoPtr
->iVersion
= 0;
5387 infoPtr
->hwndSelf
= hwnd
;
5388 infoPtr
->bDoRedraw
= TRUE
;
5389 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
5390 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
5391 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
5392 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
5393 infoPtr
->iListGap
= DEFLISTGAP
;
5394 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
5395 infoPtr
->dwStyle
= dwStyle
;
5396 infoPtr
->tbim
.iButton
= -1;
5397 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5398 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5399 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, (LPARAM
)NF_REQUERY
));
5400 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5402 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5403 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5405 OpenThemeData (hwnd
, themeClass
);
5407 TOOLBAR_CheckStyle (hwnd
, dwStyle
);
5414 TOOLBAR_Destroy (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5416 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5418 /* delete tooltip control */
5419 if (infoPtr
->hwndToolTip
)
5420 DestroyWindow (infoPtr
->hwndToolTip
);
5422 /* delete temporary buffer for tooltip text */
5423 Free (infoPtr
->pszTooltipText
);
5424 Free (infoPtr
->bitmaps
); /* bitmaps list */
5426 /* delete button data */
5427 Free (infoPtr
->buttons
);
5429 /* delete strings */
5430 if (infoPtr
->strings
) {
5432 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5433 Free (infoPtr
->strings
[i
]);
5435 Free (infoPtr
->strings
);
5438 /* destroy internal image list */
5439 if (infoPtr
->himlInt
)
5440 ImageList_Destroy (infoPtr
->himlInt
);
5442 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5443 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5444 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5446 /* delete default font */
5447 DeleteObject (infoPtr
->hDefaultFont
);
5449 CloseThemeData (GetWindowTheme (hwnd
));
5451 /* free toolbar info data */
5453 SetWindowLongPtrW (hwnd
, 0, 0);
5460 TOOLBAR_EraseBackground (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5462 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5463 NMTBCUSTOMDRAW tbcd
;
5466 HTHEME theme
= GetWindowTheme (hwnd
);
5467 DWORD dwEraseCustDraw
= 0;
5469 /* the app has told us not to redraw the toolbar */
5470 if (!infoPtr
->bDoRedraw
)
5473 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5474 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5475 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5476 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5477 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5478 dwEraseCustDraw
= ntfret
& 0xffff;
5480 /* FIXME: in general the return flags *can* be or'ed together */
5481 switch (dwEraseCustDraw
)
5483 case CDRF_DODEFAULT
:
5485 case CDRF_SKIPDEFAULT
:
5488 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5493 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5494 * to my parent for processing.
5496 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5498 HDC hdc
= (HDC
)wParam
;
5503 parent
= GetParent(hwnd
);
5504 MapWindowPoints(hwnd
, parent
, &pt
, 1);
5505 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5506 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5507 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5510 ret
= DefWindowProcW (hwnd
, WM_ERASEBKGND
, wParam
, lParam
);
5512 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5513 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5514 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5515 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5516 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5517 dwEraseCustDraw
= ntfret
& 0xffff;
5518 switch (dwEraseCustDraw
)
5520 case CDRF_DODEFAULT
:
5522 case CDRF_SKIPDEFAULT
:
5525 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5534 TOOLBAR_GetFont (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5536 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5538 return (LRESULT
)infoPtr
->hFont
;
5543 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5546 INT nNewHotItem
= infoPtr
->nHotItem
;
5548 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5551 if ((nNewHotItem
+ iDirection
< 0) ||
5552 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5554 NMTBWRAPHOTITEM nmtbwhi
;
5555 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5556 nmtbwhi
.iDirection
= iDirection
;
5557 nmtbwhi
.dwReason
= dwReason
;
5559 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5563 nNewHotItem
+= iDirection
;
5564 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5566 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5567 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5569 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5576 TOOLBAR_KeyDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5578 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5581 nmkey
.nVKey
= (UINT
)wParam
;
5582 nmkey
.uFlags
= HIWORD(lParam
);
5584 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5585 return DefWindowProcW(hwnd
, WM_KEYDOWN
, wParam
, lParam
);
5587 switch ((UINT
)wParam
)
5591 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5595 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5599 if ((infoPtr
->nHotItem
>= 0) &&
5600 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5602 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5603 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5614 TOOLBAR_LButtonDblClk (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5619 pt
.x
= (short)LOWORD(lParam
);
5620 pt
.y
= (short)HIWORD(lParam
);
5621 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5624 TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
5625 else if (GetWindowLongW (hwnd
, GWL_STYLE
) & CCS_ADJUSTABLE
)
5626 TOOLBAR_Customize (hwnd
);
5633 TOOLBAR_LButtonDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5635 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5636 TBUTTON_INFO
*btnPtr
;
5641 BOOL bDragKeyPressed
;
5645 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5646 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5648 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5650 if (infoPtr
->hwndToolTip
)
5651 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5652 WM_LBUTTONDOWN
, wParam
, lParam
);
5654 pt
.x
= (short)LOWORD(lParam
);
5655 pt
.y
= (short)HIWORD(lParam
);
5656 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5658 btnPtr
= &infoPtr
->buttons
[nHit
];
5660 if ((nHit
>= 0) && bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5662 infoPtr
->nButtonDrag
= nHit
;
5665 /* If drag cursor has not been loaded, load it.
5666 * Note: it doesn't need to be freed */
5668 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5669 SetCursor(hCursorDrag
);
5674 infoPtr
->nOldHit
= nHit
;
5676 CopyRect(&arrowRect
, &btnPtr
->rect
);
5677 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5679 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5680 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5681 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5682 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5683 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5684 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5688 /* draw in pressed state */
5689 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5690 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5692 btnPtr
->bDropDownPressed
= TRUE
;
5693 RedrawWindow(hwnd
,&btnPtr
->rect
,0,
5694 RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5696 memset(&nmtb
, 0, sizeof(nmtb
));
5697 nmtb
.iItem
= btnPtr
->idCommand
;
5698 nmtb
.rcButton
= btnPtr
->rect
;
5699 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5701 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5703 if (res
!= TBDDRET_TREATPRESSED
)
5707 /* redraw button in unpressed state */
5708 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5709 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5711 btnPtr
->bDropDownPressed
= FALSE
;
5712 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5714 /* find and set hot item
5715 * NOTE: native doesn't do this, but that is a bug */
5717 ScreenToClient(hwnd
, &pt
);
5718 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
5719 if (!infoPtr
->bAnchor
|| (nHit
>= 0))
5720 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5722 /* remove any left mouse button down or double-click messages
5723 * so that we can get a toggle effect on the button */
5724 while (PeekMessageW(&msg
, hwnd
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5725 PeekMessageW(&msg
, hwnd
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5730 /* otherwise drop through and process as pushed */
5732 infoPtr
->bCaptured
= TRUE
;
5733 infoPtr
->nButtonDown
= nHit
;
5734 infoPtr
->bDragOutSent
= FALSE
;
5736 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5738 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5740 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5741 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5748 memset(&nmtb
, 0, sizeof(nmtb
));
5749 nmtb
.iItem
= btnPtr
->idCommand
;
5750 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5753 nmmouse
.dwHitInfo
= nHit
;
5755 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5757 nmmouse
.dwItemSpec
= -1;
5760 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5761 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5764 ClientToScreen(hwnd
, &pt
);
5767 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5768 return DefWindowProcW(hwnd
, WM_LBUTTONDOWN
, wParam
, lParam
);
5774 TOOLBAR_LButtonUp (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5776 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5777 TBUTTON_INFO
*btnPtr
;
5785 if (infoPtr
->hwndToolTip
)
5786 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5787 WM_LBUTTONUP
, wParam
, lParam
);
5789 pt
.x
= (short)LOWORD(lParam
);
5790 pt
.y
= (short)HIWORD(lParam
);
5791 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5793 if (!infoPtr
->bAnchor
|| (nHit
>= 0))
5794 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5796 if (infoPtr
->nButtonDrag
>= 0) {
5800 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5803 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5805 GetClientRect(hwnd
, &rcClient
);
5806 if (PtInRect(&rcClient
, pt
))
5813 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5816 if (nButton
== infoPtr
->nButtonDrag
)
5818 /* if the button is moved sightly left and we have a
5819 * separator there then remove it */
5820 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5822 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5823 TOOLBAR_DeleteButton(hwnd
, nButton
- 1, 0);
5825 else /* else insert a separator before the dragged button */
5828 memset(&tbb
, 0, sizeof(tbb
));
5829 tbb
.fsStyle
= BTNS_SEP
;
5831 TOOLBAR_InsertButtonT(hwnd
, nButton
, (LPARAM
)&tbb
, TRUE
);
5838 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5839 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, 0);
5841 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5844 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, nButton
);
5849 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5850 TOOLBAR_DeleteButton(hwnd
, (WPARAM
)infoPtr
->nButtonDrag
, 0);
5853 /* button under cursor changed so need to re-set hot item */
5854 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5855 infoPtr
->nButtonDrag
= -1;
5857 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5859 else if (infoPtr
->nButtonDown
>= 0) {
5860 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5861 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5863 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5864 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5865 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5867 if ((nOldIndex
!= nHit
) &&
5869 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5870 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5873 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5874 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5876 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5880 if (nOldIndex
!= -1)
5881 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5884 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5885 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5886 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5888 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5890 infoPtr
->nButtonDown
= -1;
5892 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5893 TOOLBAR_SendNotify (&hdr
, infoPtr
,
5894 NM_RELEASEDCAPTURE
);
5896 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5899 memset(&nmtb
, 0, sizeof(nmtb
));
5900 nmtb
.iItem
= btnPtr
->idCommand
;
5901 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5904 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5906 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5907 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)hwnd
);
5909 /* In case we have just been destroyed... */
5915 /* !!! Undocumented - toolbar at 4.71 level and above sends
5916 * NM_CLICK with the NMMOUSE structure. */
5917 nmmouse
.dwHitInfo
= nHit
;
5920 nmmouse
.dwItemSpec
= -1;
5923 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5924 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5927 ClientToScreen(hwnd
, &pt
);
5930 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5931 return DefWindowProcW(hwnd
, WM_LBUTTONUP
, wParam
, lParam
);
5937 TOOLBAR_RButtonUp( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5939 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5944 pt
.x
= (short)LOWORD(lParam
);
5945 pt
.y
= (short)HIWORD(lParam
);
5947 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
5948 nmmouse
.dwHitInfo
= nHit
;
5951 nmmouse
.dwItemSpec
= -1;
5953 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5954 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5957 ClientToScreen(hwnd
, &pt
);
5960 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5961 return DefWindowProcW(hwnd
, WM_RBUTTONUP
, wParam
, lParam
);
5967 TOOLBAR_RButtonDblClk( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5969 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5972 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5973 return DefWindowProcW(hwnd
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
5979 TOOLBAR_CaptureChanged(HWND hwnd
)
5981 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5982 TBUTTON_INFO
*btnPtr
;
5984 infoPtr
->bCaptured
= FALSE
;
5986 if (infoPtr
->nButtonDown
>= 0)
5988 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5989 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5991 infoPtr
->nOldHit
= -1;
5993 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5994 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6000 TOOLBAR_MouseLeave (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6002 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6004 /* don't remove hot effects when in anchor highlighting mode or when a
6005 * drop-down button is pressed */
6006 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
6008 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
6009 if (!hotBtnPtr
->bDropDownPressed
)
6010 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
6013 if (infoPtr
->nOldHit
< 0)
6016 /* If the last button we were over is depressed then make it not */
6017 /* depressed and redraw it */
6018 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
6020 TBUTTON_INFO
*btnPtr
;
6023 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6025 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6028 InflateRect (&rc1
, 1, 1);
6029 InvalidateRect (hwnd
, &rc1
, TRUE
);
6032 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
6035 ZeroMemory(&nmt
, sizeof(nmt
));
6036 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6037 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6038 infoPtr
->bDragOutSent
= TRUE
;
6041 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
6047 TOOLBAR_MouseMove (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6049 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6051 TRACKMOUSEEVENT trackinfo
;
6053 TBUTTON_INFO
*btnPtr
;
6055 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
6056 TOOLBAR_TooltipCreateControl(infoPtr
);
6058 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
6059 /* fill in the TRACKMOUSEEVENT struct */
6060 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
6061 trackinfo
.dwFlags
= TME_QUERY
;
6063 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6064 _TrackMouseEvent(&trackinfo
);
6066 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6067 if(trackinfo
.hwndTrack
!= hwnd
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
6068 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
6069 trackinfo
.hwndTrack
= hwnd
;
6071 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6072 /* and can properly deactivate the hot toolbar button */
6073 _TrackMouseEvent(&trackinfo
);
6077 if (infoPtr
->hwndToolTip
)
6078 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
6079 WM_MOUSEMOVE
, wParam
, lParam
);
6081 pt
.x
= (short)LOWORD(lParam
);
6082 pt
.y
= (short)HIWORD(lParam
);
6084 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
6086 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6087 && (!infoPtr
->bAnchor
|| (nHit
>= 0)))
6088 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
);
6090 if (infoPtr
->nOldHit
!= nHit
)
6092 if (infoPtr
->bCaptured
)
6094 if (!infoPtr
->bDragOutSent
)
6097 ZeroMemory(&nmt
, sizeof(nmt
));
6098 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6099 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6100 infoPtr
->bDragOutSent
= TRUE
;
6103 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6104 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
6105 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6106 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6108 else if (nHit
== infoPtr
->nButtonDown
) {
6109 btnPtr
->fsState
|= TBSTATE_PRESSED
;
6110 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6112 infoPtr
->nOldHit
= nHit
;
6120 static inline LRESULT
6121 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6123 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6124 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
6126 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6130 static inline LRESULT
6131 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6133 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
6134 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
6136 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
6141 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6143 TOOLBAR_INFO
*infoPtr
;
6144 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
6147 /* allocate memory for info structure */
6148 infoPtr
= (TOOLBAR_INFO
*)Alloc (sizeof(TOOLBAR_INFO
));
6149 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
6152 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
6154 infoPtr
->nWidth
= 0;
6156 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6157 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
6158 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
6159 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
6162 /* native control does:
6163 * Get a lot of colors and brushes
6165 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6166 * CreateFontIndirectW(adr1)
6167 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6168 * hdc = GetDC(toolbar)
6169 * GetSystemMetrics(0x48)
6170 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6171 * 0, 0, 0, 0, "MARLETT")
6172 * oldfnt = SelectObject(hdc, fnt2)
6173 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6174 * GetTextMetricsW(hdc, adr3)
6175 * SelectObject(hdc, oldfnt)
6176 * DeleteObject(fnt2)
6178 * InvalidateRect(toolbar, 0, 1)
6179 * SetWindowLongW(toolbar, 0, addr)
6180 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6183 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6184 * ie 2 0x4600094c 0x4600094c 0x4600894d
6185 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6186 * rebar 0x50008844 0x40008844 0x50008845
6187 * pager 0x50000844 0x40000844 0x50008845
6188 * IC35mgr 0x5400084e **nochange**
6189 * on entry to _NCCREATE 0x5400084e
6190 * rowlist 0x5400004e **nochange**
6191 * on entry to _NCCREATE 0x5400004e
6195 /* I think the code below is a bug, but it is the way that the native
6196 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6197 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6198 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6199 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6200 * Somehow, the only cases of this seem to be MFC programs.
6202 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6203 * does not occur in the WM_STYLECHANGING routine.
6204 * (Guy Albertelli 9/2001)
6207 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6208 && !(cs
->style
& TBSTYLE_TRANSPARENT
))
6209 styleadd
|= TBSTYLE_TRANSPARENT
;
6210 if (!(cs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
6211 styleadd
|= CCS_TOP
; /* default to top */
6212 SetWindowLongW (hwnd
, GWL_STYLE
, cs
->style
| styleadd
);
6215 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, lParam
);
6220 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6222 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
6226 if (dwStyle
& WS_MINIMIZE
)
6227 return 0; /* Nothing to do */
6229 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
6231 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
6234 if (!(dwStyle
& CCS_NODIVIDER
))
6236 GetWindowRect (hwnd
, &rcWindow
);
6237 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
6238 if( dwStyle
& WS_BORDER
)
6239 OffsetRect (&rcWindow
, 1, 1);
6240 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6243 ReleaseDC( hwnd
, hdc
);
6249 /* handles requests from the tooltip control on what text to display */
6250 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6252 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6254 TRACE("button index = %d\n", index
);
6256 Free (infoPtr
->pszTooltipText
);
6257 infoPtr
->pszTooltipText
= NULL
;
6262 if (infoPtr
->bUnicode
)
6264 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6265 NMTBGETINFOTIPW tbgit
;
6266 unsigned int len
; /* in chars */
6268 wszBuffer
[0] = '\0';
6269 wszBuffer
[INFOTIPSIZE
] = '\0';
6271 tbgit
.pszText
= wszBuffer
;
6272 tbgit
.cchTextMax
= INFOTIPSIZE
;
6273 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6274 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6276 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6278 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6280 len
= strlenW(tbgit
.pszText
);
6281 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6283 /* need to allocate temporary buffer in infoPtr as there
6284 * isn't enough space in buffer passed to us by the
6285 * tooltip control */
6286 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6287 if (infoPtr
->pszTooltipText
)
6289 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6290 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6296 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6302 CHAR szBuffer
[INFOTIPSIZE
+1];
6303 NMTBGETINFOTIPA tbgit
;
6304 unsigned int len
; /* in chars */
6307 szBuffer
[INFOTIPSIZE
] = '\0';
6309 tbgit
.pszText
= szBuffer
;
6310 tbgit
.cchTextMax
= INFOTIPSIZE
;
6311 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6312 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6314 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6316 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6318 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6319 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]))
6321 /* need to allocate temporary buffer in infoPtr as there
6322 * isn't enough space in buffer passed to us by the
6323 * tooltip control */
6324 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6325 if (infoPtr
->pszTooltipText
)
6327 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6328 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6332 else if (tbgit
.pszText
[0])
6334 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1,
6335 lpnmtdi
->lpszText
, sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]));
6340 /* if button has text, but it is not shown then automatically
6341 * use that text as tooltip */
6342 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6343 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6345 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6346 unsigned int len
= pszText
? strlenW(pszText
) : 0;
6348 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6350 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6352 /* need to allocate temporary buffer in infoPtr as there
6353 * isn't enough space in buffer passed to us by the
6354 * tooltip control */
6355 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6356 if (infoPtr
->pszTooltipText
)
6358 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6359 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6365 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6370 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6372 /* last resort: send notification on to app */
6373 /* FIXME: find out what is really used here */
6374 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmtdi
->hdr
.idFrom
, (LPARAM
)lpnmtdi
);
6378 static inline LRESULT
6379 TOOLBAR_Notify (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6381 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6382 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
6384 switch (lpnmh
->code
)
6388 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
6390 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6391 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6392 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6396 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6397 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6405 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lParam
;
6407 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6408 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6409 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6410 lppgs
->iScroll
, lppgs
->iDir
);
6414 case TTN_GETDISPINFOW
:
6415 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lParam
);
6417 case TTN_GETDISPINFOA
:
6418 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6428 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6432 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam
, lParam
);
6434 if (lParam
== NF_QUERY
)
6437 if (lParam
== NF_REQUERY
) {
6438 format
= SendMessageW(infoPtr
->hwndNotify
,
6439 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6440 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6441 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6452 TOOLBAR_Paint (HWND hwnd
, WPARAM wParam
)
6454 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
6458 /* fill ps.rcPaint with a default rect */
6459 ps
.rcPaint
= infoPtr
->rcBound
;
6461 hdc
= wParam
==0 ? BeginPaint(hwnd
, &ps
) : (HDC
)wParam
;
6463 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps
.rcPaint
));
6465 TOOLBAR_Refresh (hwnd
, hdc
, &ps
);
6466 if (!wParam
) EndPaint (hwnd
, &ps
);
6473 TOOLBAR_SetFocus (HWND hwnd
, WPARAM wParam
)
6475 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6477 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6479 /* make first item hot */
6480 if (infoPtr
->nNumButtons
> 0)
6481 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6487 TOOLBAR_SetFont(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6489 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
6491 TRACE("font=%p redraw=%ld\n", (HFONT
)wParam
, lParam
);
6494 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6496 infoPtr
->hFont
= (HFONT
)wParam
;
6498 TOOLBAR_CalcToolbar(hwnd
);
6501 InvalidateRect(hwnd
, NULL
, TRUE
);
6506 TOOLBAR_SetRedraw (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6507 /*****************************************************
6510 * Handles the WM_SETREDRAW message.
6513 * According to testing V4.71 of COMCTL32 returns the
6514 * *previous* status of the redraw flag (either 0 or 1)
6515 * instead of the MSDN documented value of 0 if handled.
6516 * (For laughs see the "consistency" with same function
6519 *****************************************************/
6521 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6522 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6524 TRACE("set to %s\n",
6525 (wParam
) ? "TRUE" : "FALSE");
6526 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6528 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6530 return (oldredraw
) ? 1 : 0;
6535 TOOLBAR_Size (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6537 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6539 TRACE("sizing toolbar!\n");
6541 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6543 RECT delta_width
, delta_height
, client
, dummy
;
6544 DWORD min_x
, max_x
, min_y
, max_y
;
6545 TBUTTON_INFO
*btnPtr
;
6548 GetClientRect(hwnd
, &client
);
6549 if(client
.right
> infoPtr
->client_rect
.right
)
6551 min_x
= infoPtr
->client_rect
.right
;
6552 max_x
= client
.right
;
6556 max_x
= infoPtr
->client_rect
.right
;
6557 min_x
= client
.right
;
6559 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6561 min_y
= infoPtr
->client_rect
.bottom
;
6562 max_y
= client
.bottom
;
6566 max_y
= infoPtr
->client_rect
.bottom
;
6567 min_y
= client
.bottom
;
6570 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6571 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6573 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6574 btnPtr
= infoPtr
->buttons
;
6575 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6576 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6577 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6578 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6580 GetClientRect(hwnd
, &infoPtr
->client_rect
);
6581 TOOLBAR_AutoSize(hwnd
);
6587 TOOLBAR_StyleChanged (HWND hwnd
, INT nType
, const STYLESTRUCT
*lpStyle
)
6589 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6591 if (nType
== GWL_STYLE
)
6593 DWORD dwOldStyle
= infoPtr
->dwStyle
;
6595 if (lpStyle
->styleNew
& TBSTYLE_LIST
)
6596 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
6598 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
6600 TOOLBAR_CheckStyle (hwnd
, lpStyle
->styleNew
);
6602 TRACE("new style 0x%08x\n", lpStyle
->styleNew
);
6604 infoPtr
->dwStyle
= lpStyle
->styleNew
;
6606 if ((dwOldStyle
^ lpStyle
->styleNew
) & (TBSTYLE_WRAPABLE
| CCS_VERT
))
6607 TOOLBAR_LayoutToolbar(hwnd
);
6609 /* only resize if one of the CCS_* styles was changed */
6610 if ((dwOldStyle
^ lpStyle
->styleNew
) & COMMON_STYLES
)
6612 TOOLBAR_AutoSize (hwnd
);
6614 InvalidateRect(hwnd
, NULL
, TRUE
);
6623 TOOLBAR_SysColorChange (HWND hwnd
)
6625 COMCTL32_RefreshSysColors();
6631 /* update theme after a WM_THEMECHANGED message */
6632 static LRESULT
theme_changed (HWND hwnd
)
6634 HTHEME theme
= GetWindowTheme (hwnd
);
6635 CloseThemeData (theme
);
6636 OpenThemeData (hwnd
, themeClass
);
6641 static LRESULT WINAPI
6642 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6644 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6646 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6647 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6649 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6650 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6655 return TOOLBAR_AddBitmap (hwnd
, wParam
, lParam
);
6657 case TB_ADDBUTTONSA
:
6658 return TOOLBAR_AddButtonsT(hwnd
, wParam
, lParam
, FALSE
);
6660 case TB_ADDBUTTONSW
:
6661 return TOOLBAR_AddButtonsT(hwnd
, wParam
, lParam
, TRUE
);
6664 return TOOLBAR_AddStringA (hwnd
, wParam
, lParam
);
6667 return TOOLBAR_AddStringW (hwnd
, wParam
, lParam
);
6670 return TOOLBAR_AutoSize (hwnd
);
6672 case TB_BUTTONCOUNT
:
6673 return TOOLBAR_ButtonCount (hwnd
, wParam
, lParam
);
6675 case TB_BUTTONSTRUCTSIZE
:
6676 return TOOLBAR_ButtonStructSize (hwnd
, wParam
, lParam
);
6678 case TB_CHANGEBITMAP
:
6679 return TOOLBAR_ChangeBitmap (hwnd
, wParam
, lParam
);
6681 case TB_CHECKBUTTON
:
6682 return TOOLBAR_CheckButton (hwnd
, wParam
, lParam
);
6684 case TB_COMMANDTOINDEX
:
6685 return TOOLBAR_CommandToIndex (hwnd
, wParam
, lParam
);
6688 return TOOLBAR_Customize (hwnd
);
6690 case TB_DELETEBUTTON
:
6691 return TOOLBAR_DeleteButton (hwnd
, wParam
, lParam
);
6693 case TB_ENABLEBUTTON
:
6694 return TOOLBAR_EnableButton (hwnd
, wParam
, lParam
);
6696 case TB_GETANCHORHIGHLIGHT
:
6697 return TOOLBAR_GetAnchorHighlight (hwnd
);
6700 return TOOLBAR_GetBitmap (hwnd
, wParam
, lParam
);
6702 case TB_GETBITMAPFLAGS
:
6703 return TOOLBAR_GetBitmapFlags (hwnd
, wParam
, lParam
);
6706 return TOOLBAR_GetButton (hwnd
, wParam
, lParam
);
6708 case TB_GETBUTTONINFOA
:
6709 return TOOLBAR_GetButtonInfoT(hwnd
, wParam
, lParam
, FALSE
);
6711 case TB_GETBUTTONINFOW
:
6712 return TOOLBAR_GetButtonInfoT(hwnd
, wParam
, lParam
, TRUE
);
6714 case TB_GETBUTTONSIZE
:
6715 return TOOLBAR_GetButtonSize (hwnd
);
6717 case TB_GETBUTTONTEXTA
:
6718 return TOOLBAR_GetButtonTextA (hwnd
, wParam
, lParam
);
6720 case TB_GETBUTTONTEXTW
:
6721 return TOOLBAR_GetButtonTextW (hwnd
, wParam
, lParam
);
6723 case TB_GETDISABLEDIMAGELIST
:
6724 return TOOLBAR_GetDisabledImageList (hwnd
, wParam
, lParam
);
6726 case TB_GETEXTENDEDSTYLE
:
6727 return TOOLBAR_GetExtendedStyle (hwnd
);
6729 case TB_GETHOTIMAGELIST
:
6730 return TOOLBAR_GetHotImageList (hwnd
, wParam
, lParam
);
6733 return TOOLBAR_GetHotItem (hwnd
);
6735 case TB_GETIMAGELIST
:
6736 return TOOLBAR_GetDefImageList (hwnd
, wParam
, lParam
);
6738 case TB_GETINSERTMARK
:
6739 return TOOLBAR_GetInsertMark (hwnd
, wParam
, lParam
);
6741 case TB_GETINSERTMARKCOLOR
:
6742 return TOOLBAR_GetInsertMarkColor (hwnd
, wParam
, lParam
);
6744 case TB_GETITEMRECT
:
6745 return TOOLBAR_GetItemRect (hwnd
, wParam
, lParam
);
6748 return TOOLBAR_GetMaxSize (hwnd
, wParam
, lParam
);
6750 /* case TB_GETOBJECT: */ /* 4.71 */
6753 return TOOLBAR_GetPadding (hwnd
);
6756 return TOOLBAR_GetRect (hwnd
, wParam
, lParam
);
6759 return TOOLBAR_GetRows (hwnd
, wParam
, lParam
);
6762 return TOOLBAR_GetState (hwnd
, wParam
, lParam
);
6765 return TOOLBAR_GetStringA (hwnd
, wParam
, lParam
);
6768 return TOOLBAR_GetStringW (hwnd
, wParam
, lParam
);
6771 return TOOLBAR_GetStyle (hwnd
, wParam
, lParam
);
6773 case TB_GETTEXTROWS
:
6774 return TOOLBAR_GetTextRows (hwnd
, wParam
, lParam
);
6776 case TB_GETTOOLTIPS
:
6777 return TOOLBAR_GetToolTips (hwnd
, wParam
, lParam
);
6779 case TB_GETUNICODEFORMAT
:
6780 return TOOLBAR_GetUnicodeFormat (hwnd
, wParam
, lParam
);
6783 return TOOLBAR_HideButton (hwnd
, wParam
, lParam
);
6786 return TOOLBAR_HitTest (hwnd
, wParam
, lParam
);
6788 case TB_INDETERMINATE
:
6789 return TOOLBAR_Indeterminate (hwnd
, wParam
, lParam
);
6791 case TB_INSERTBUTTONA
:
6792 return TOOLBAR_InsertButtonT(hwnd
, wParam
, lParam
, FALSE
);
6794 case TB_INSERTBUTTONW
:
6795 return TOOLBAR_InsertButtonT(hwnd
, wParam
, lParam
, TRUE
);
6797 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6799 case TB_ISBUTTONCHECKED
:
6800 return TOOLBAR_IsButtonChecked (hwnd
, wParam
, lParam
);
6802 case TB_ISBUTTONENABLED
:
6803 return TOOLBAR_IsButtonEnabled (hwnd
, wParam
, lParam
);
6805 case TB_ISBUTTONHIDDEN
:
6806 return TOOLBAR_IsButtonHidden (hwnd
, wParam
, lParam
);
6808 case TB_ISBUTTONHIGHLIGHTED
:
6809 return TOOLBAR_IsButtonHighlighted (hwnd
, wParam
, lParam
);
6811 case TB_ISBUTTONINDETERMINATE
:
6812 return TOOLBAR_IsButtonIndeterminate (hwnd
, wParam
, lParam
);
6814 case TB_ISBUTTONPRESSED
:
6815 return TOOLBAR_IsButtonPressed (hwnd
, wParam
, lParam
);
6818 return TOOLBAR_LoadImages (hwnd
, wParam
, lParam
);
6820 case TB_MAPACCELERATORA
:
6821 case TB_MAPACCELERATORW
:
6822 return TOOLBAR_MapAccelerator (hwnd
, wParam
, lParam
);
6825 return TOOLBAR_MarkButton (hwnd
, wParam
, lParam
);
6828 return TOOLBAR_MoveButton (hwnd
, wParam
, lParam
);
6830 case TB_PRESSBUTTON
:
6831 return TOOLBAR_PressButton (hwnd
, wParam
, lParam
);
6833 case TB_REPLACEBITMAP
:
6834 return TOOLBAR_ReplaceBitmap (hwnd
, wParam
, lParam
);
6836 case TB_SAVERESTOREA
:
6837 return TOOLBAR_SaveRestoreA (hwnd
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6839 case TB_SAVERESTOREW
:
6840 return TOOLBAR_SaveRestoreW (hwnd
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6842 case TB_SETANCHORHIGHLIGHT
:
6843 return TOOLBAR_SetAnchorHighlight (hwnd
, wParam
);
6845 case TB_SETBITMAPSIZE
:
6846 return TOOLBAR_SetBitmapSize (hwnd
, wParam
, lParam
);
6848 case TB_SETBUTTONINFOA
:
6849 return TOOLBAR_SetButtonInfoA (hwnd
, wParam
, lParam
);
6851 case TB_SETBUTTONINFOW
:
6852 return TOOLBAR_SetButtonInfoW (hwnd
, wParam
, lParam
);
6854 case TB_SETBUTTONSIZE
:
6855 return TOOLBAR_SetButtonSize (hwnd
, wParam
, lParam
);
6857 case TB_SETBUTTONWIDTH
:
6858 return TOOLBAR_SetButtonWidth (hwnd
, wParam
, lParam
);
6861 return TOOLBAR_SetCmdId (hwnd
, wParam
, lParam
);
6863 case TB_SETDISABLEDIMAGELIST
:
6864 return TOOLBAR_SetDisabledImageList (hwnd
, wParam
, lParam
);
6866 case TB_SETDRAWTEXTFLAGS
:
6867 return TOOLBAR_SetDrawTextFlags (hwnd
, wParam
, lParam
);
6869 case TB_SETEXTENDEDSTYLE
:
6870 return TOOLBAR_SetExtendedStyle (hwnd
, wParam
, lParam
);
6872 case TB_SETHOTIMAGELIST
:
6873 return TOOLBAR_SetHotImageList (hwnd
, wParam
, lParam
);
6876 return TOOLBAR_SetHotItem (hwnd
, wParam
);
6878 case TB_SETIMAGELIST
:
6879 return TOOLBAR_SetImageList (hwnd
, wParam
, lParam
);
6882 return TOOLBAR_SetIndent (hwnd
, wParam
, lParam
);
6884 case TB_SETINSERTMARK
:
6885 return TOOLBAR_SetInsertMark (hwnd
, wParam
, lParam
);
6887 case TB_SETINSERTMARKCOLOR
:
6888 return TOOLBAR_SetInsertMarkColor (hwnd
, wParam
, lParam
);
6890 case TB_SETMAXTEXTROWS
:
6891 return TOOLBAR_SetMaxTextRows (hwnd
, wParam
, lParam
);
6894 return TOOLBAR_SetPadding (hwnd
, wParam
, lParam
);
6897 return TOOLBAR_SetParent (hwnd
, wParam
, lParam
);
6900 return TOOLBAR_SetRows (hwnd
, wParam
, lParam
);
6903 return TOOLBAR_SetState (hwnd
, wParam
, lParam
);
6906 return TOOLBAR_SetStyle (hwnd
, wParam
, lParam
);
6908 case TB_SETTOOLTIPS
:
6909 return TOOLBAR_SetToolTips (hwnd
, wParam
, lParam
);
6911 case TB_SETUNICODEFORMAT
:
6912 return TOOLBAR_SetUnicodeFormat (hwnd
, wParam
, lParam
);
6915 return TOOLBAR_Unkwn45D(hwnd
, wParam
, lParam
);
6918 return TOOLBAR_Unkwn45E (hwnd
, wParam
, lParam
);
6921 return TOOLBAR_Unkwn460(hwnd
, wParam
, lParam
);
6924 return TOOLBAR_Unkwn462(hwnd
, wParam
, lParam
);
6927 return TOOLBAR_Unkwn463 (hwnd
, wParam
, lParam
);
6930 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6932 /* Common Control Messages */
6934 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6935 case CCM_GETCOLORSCHEME
:
6936 return TOOLBAR_GetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
6938 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6939 case CCM_SETCOLORSCHEME
:
6940 return TOOLBAR_SetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
6942 case CCM_GETVERSION
:
6943 return TOOLBAR_GetVersion (hwnd
);
6945 case CCM_SETVERSION
:
6946 return TOOLBAR_SetVersion (hwnd
, (INT
)wParam
);
6952 return TOOLBAR_Create (hwnd
, wParam
, lParam
);
6955 return TOOLBAR_Destroy (hwnd
, wParam
, lParam
);
6958 return TOOLBAR_EraseBackground (hwnd
, wParam
, lParam
);
6961 return TOOLBAR_GetFont (hwnd
, wParam
, lParam
);
6964 return TOOLBAR_KeyDown (hwnd
, wParam
, lParam
);
6966 /* case WM_KILLFOCUS: */
6968 case WM_LBUTTONDBLCLK
:
6969 return TOOLBAR_LButtonDblClk (hwnd
, wParam
, lParam
);
6971 case WM_LBUTTONDOWN
:
6972 return TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
6975 return TOOLBAR_LButtonUp (hwnd
, wParam
, lParam
);
6978 return TOOLBAR_RButtonUp (hwnd
, wParam
, lParam
);
6980 case WM_RBUTTONDBLCLK
:
6981 return TOOLBAR_RButtonDblClk (hwnd
, wParam
, lParam
);
6984 return TOOLBAR_MouseMove (hwnd
, wParam
, lParam
);
6987 return TOOLBAR_MouseLeave (hwnd
, wParam
, lParam
);
6989 case WM_CAPTURECHANGED
:
6990 return TOOLBAR_CaptureChanged(hwnd
);
6993 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6996 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6999 return TOOLBAR_NCCreate (hwnd
, wParam
, lParam
);
7002 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
7005 return TOOLBAR_Notify (hwnd
, wParam
, lParam
);
7007 case WM_NOTIFYFORMAT
:
7008 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
7010 case WM_PRINTCLIENT
:
7012 return TOOLBAR_Paint (hwnd
, wParam
);
7015 return TOOLBAR_SetFocus (hwnd
, wParam
);
7018 return TOOLBAR_SetFont(hwnd
, wParam
, lParam
);
7021 return TOOLBAR_SetRedraw (hwnd
, wParam
, lParam
);
7024 return TOOLBAR_Size (hwnd
, wParam
, lParam
);
7026 case WM_STYLECHANGED
:
7027 return TOOLBAR_StyleChanged (hwnd
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
7029 case WM_SYSCOLORCHANGE
:
7030 return TOOLBAR_SysColorChange (hwnd
);
7032 case WM_THEMECHANGED
:
7033 return theme_changed (hwnd
);
7035 /* case WM_WININICHANGE: */
7040 case WM_MEASUREITEM
:
7042 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
7044 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7045 case PGM_FORWARDMOUSE
:
7046 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7049 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
7050 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
7051 uMsg
, wParam
, lParam
);
7052 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7058 TOOLBAR_Register (void)
7062 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
7063 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
7064 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
7065 wndClass
.cbClsExtra
= 0;
7066 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
7067 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
7068 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
7069 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
7071 RegisterClassW (&wndClass
);
7076 TOOLBAR_Unregister (void)
7078 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
7081 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
7086 /* Check if the entry already exists */
7087 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
7089 /* If this is a new entry we must create it and insert into the array */
7094 c
= (PIMLENTRY
) Alloc(sizeof(IMLENTRY
));
7097 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
7098 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
7113 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
7117 for (i
= 0; i
< *cies
; i
++)
7127 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
7135 for (i
= 0; i
< cies
; i
++)
7137 if (pies
[i
]->id
== id
)
7149 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
7151 HIMAGELIST himlDef
= 0;
7152 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
7155 himlDef
= pie
->himl
;
7161 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
7163 if (infoPtr
->bUnicode
)
7164 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
7171 nmtba
.iItem
= nmtb
->iItem
;
7172 nmtba
.pszText
= Buffer
;
7173 nmtba
.cchText
= 256;
7174 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
7176 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
7178 int ccht
= strlen(nmtba
.pszText
);
7180 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)nmtba
.pszText
, -1,
7181 nmtb
->pszText
, nmtb
->cchText
);
7183 nmtb
->tbButton
= nmtba
.tbButton
;
7192 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, PCUSTOMBUTTON btnInfo
)
7196 /* MSDN states that iItem is the index of the button, rather than the
7197 * command ID as used by every other NMTOOLBAR notification */
7199 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
7201 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);