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).
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=(%d,%d)-(%d,%d)\n",
287 btn_num
, bP
->idCommand
,
288 (bP
->bHot
) ? "TRUE":"FALSE", bP
->nRow
,
289 bP
->rect
.left
, bP
->rect
.top
,
290 bP
->rect
.right
, bP
->rect
.bottom
);
296 TOOLBAR_DumpToolbar(const TOOLBAR_INFO
*iP
, INT line
)
298 if (TRACE_ON(toolbar
)) {
301 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
303 iP
->dwExStyle
, iP
->nNumButtons
, iP
->nNumBitmaps
,
304 iP
->nNumStrings
, iP
->dwStyle
);
305 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
307 iP
->himlInt
, iP
->himlDef
, iP
->himlHot
, iP
->himlDis
,
308 (iP
->bDoRedraw
) ? "TRUE" : "FALSE");
309 for(i
=0; i
<iP
->nNumButtons
; i
++) {
310 TOOLBAR_DumpButton(iP
, &iP
->buttons
[i
], i
, TRUE
);
316 /***********************************************************************
319 * This function validates that the styles set are implemented and
320 * issues FIXME's warning of possible problems. In a perfect world this
321 * function should be null.
324 TOOLBAR_CheckStyle (HWND hwnd
, DWORD dwStyle
)
326 if (dwStyle
& TBSTYLE_REGISTERDROP
)
327 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd
);
332 TOOLBAR_SendNotify (NMHDR
*nmhdr
, const TOOLBAR_INFO
*infoPtr
, UINT code
)
334 if(!IsWindow(infoPtr
->hwndSelf
))
335 return 0; /* we have just been destroyed */
337 nmhdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
338 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
341 TRACE("to window %p, code=%08x, %s\n", infoPtr
->hwndNotify
, code
,
342 (infoPtr
->bUnicode
) ? "via Unicode" : "via ANSI");
344 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
345 (WPARAM
)nmhdr
->idFrom
, (LPARAM
)nmhdr
);
348 /***********************************************************************
349 * TOOLBAR_GetBitmapIndex
351 * This function returns the bitmap index associated with a button.
352 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
353 * is issued to retrieve the index.
356 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
358 INT ret
= btnPtr
->iBitmap
;
360 if (ret
== I_IMAGECALLBACK
)
362 /* issue TBN_GETDISPINFO */
365 memset(&nmgd
, 0, sizeof(nmgd
));
366 nmgd
.idCommand
= btnPtr
->idCommand
;
367 nmgd
.lParam
= btnPtr
->dwData
;
368 nmgd
.dwMask
= TBNF_IMAGE
;
370 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
371 TOOLBAR_SendNotify(&nmgd
.hdr
, infoPtr
, TBN_GETDISPINFOW
);
372 if (nmgd
.dwMask
& TBNF_DI_SETITEM
)
373 btnPtr
->iBitmap
= nmgd
.iImage
;
375 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
376 ret
, nmgd
.dwMask
, infoPtr
->nNumBitmaps
);
379 if (ret
!= I_IMAGENONE
)
380 ret
= GETIBITMAP(infoPtr
, ret
);
387 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO
*infoPtr
, INT index
)
390 INT id
= GETHIMLID(infoPtr
, index
);
391 INT iBitmap
= GETIBITMAP(infoPtr
, index
);
393 if (((himl
= GETDEFIMAGELIST(infoPtr
, id
)) &&
394 iBitmap
>= 0 && iBitmap
< ImageList_GetImageCount(himl
)) ||
395 (index
== I_IMAGECALLBACK
))
403 TOOLBAR_IsValidImageList(const TOOLBAR_INFO
*infoPtr
, INT index
)
405 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, index
));
406 return (himl
!= NULL
) && (ImageList_GetImageCount(himl
) > 0);
410 /***********************************************************************
411 * TOOLBAR_GetImageListForDrawing
413 * This function validates the bitmap index (including I_IMAGECALLBACK
414 * functionality) and returns the corresponding image list.
417 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
,
418 IMAGE_LIST_TYPE imagelist
, INT
* index
)
422 if (!TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
)) {
423 if (btnPtr
->iBitmap
== I_IMAGENONE
) return NULL
;
424 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
425 HIWORD(btnPtr
->iBitmap
), LOWORD(btnPtr
->iBitmap
), infoPtr
->nNumBitmaps
);
429 if ((*index
= TOOLBAR_GetBitmapIndex(infoPtr
, btnPtr
)) < 0) {
430 if ((*index
== I_IMAGECALLBACK
) ||
431 (*index
== I_IMAGENONE
)) return NULL
;
432 ERR("TBN_GETDISPINFO returned invalid index %d\n",
439 case IMAGE_LIST_DEFAULT
:
440 himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
443 himl
= GETHOTIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
445 case IMAGE_LIST_DISABLED
:
446 himl
= GETDISIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
450 FIXME("Shouldn't reach here\n");
454 TRACE("no image list\n");
461 TOOLBAR_DrawFlatSeparator (const RECT
*lpRect
, HDC hdc
, const TOOLBAR_INFO
*infoPtr
)
464 COLORREF oldcolor
, newcolor
;
466 myrect
.left
= (lpRect
->left
+ lpRect
->right
) / 2 - 1;
467 myrect
.right
= myrect
.left
+ 1;
468 myrect
.top
= lpRect
->top
+ 2;
469 myrect
.bottom
= lpRect
->bottom
- 2;
471 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
472 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
473 oldcolor
= SetBkColor (hdc
, newcolor
);
474 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
476 myrect
.left
= myrect
.right
;
477 myrect
.right
= myrect
.left
+ 1;
479 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
480 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
481 SetBkColor (hdc
, newcolor
);
482 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
484 SetBkColor (hdc
, oldcolor
);
488 /***********************************************************************
489 * TOOLBAR_DrawDDFlatSeparator
491 * This function draws the separator that was flagged as BTNS_DROPDOWN.
492 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
493 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
494 * are horizontal as opposed to the vertical separators for not dropdown
497 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
500 TOOLBAR_DrawDDFlatSeparator (const RECT
*lpRect
, HDC hdc
, const TBUTTON_INFO
*btnPtr
,
501 const TOOLBAR_INFO
*infoPtr
)
504 COLORREF oldcolor
, newcolor
;
506 myrect
.left
= lpRect
->left
;
507 myrect
.right
= lpRect
->right
;
508 myrect
.top
= lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
- 2)/2;
509 myrect
.bottom
= myrect
.top
+ 1;
511 InflateRect (&myrect
, -2, 0);
513 TRACE("rect=(%d,%d)-(%d,%d)\n",
514 myrect
.left
, myrect
.top
, myrect
.right
, myrect
.bottom
);
516 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
517 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
518 oldcolor
= SetBkColor (hdc
, newcolor
);
519 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
521 myrect
.top
= myrect
.bottom
;
522 myrect
.bottom
= myrect
.top
+ 1;
524 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
525 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
526 SetBkColor (hdc
, newcolor
);
527 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
529 SetBkColor (hdc
, oldcolor
);
534 TOOLBAR_DrawArrow (HDC hdc
, INT left
, INT top
, COLORREF clr
)
539 if (!(hPen
= CreatePen( PS_SOLID
, 1, clr
))) return;
540 hOldPen
= SelectObject ( hdc
, hPen
);
543 MoveToEx (hdc
, x
, y
, NULL
);
544 LineTo (hdc
, x
+5, y
++); x
++;
545 MoveToEx (hdc
, x
, y
, NULL
);
546 LineTo (hdc
, x
+3, y
++); x
++;
547 MoveToEx (hdc
, x
, y
, NULL
);
548 LineTo (hdc
, x
+1, y
++);
549 SelectObject( hdc
, hOldPen
);
550 DeleteObject( hPen
);
554 * Draw the text string for this button.
555 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
556 * is non-zero, so we can simply check himlDef to see if we have
560 TOOLBAR_DrawString (const TOOLBAR_INFO
*infoPtr
, RECT
*rcText
, LPCWSTR lpText
,
561 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
563 HDC hdc
= tbcd
->nmcd
.hdc
;
566 COLORREF clrOldBk
= 0;
568 UINT state
= tbcd
->nmcd
.uItemState
;
572 TRACE("string=%s rect=(%d,%d)-(%d,%d)\n", debugstr_w(lpText
),
573 rcText
->left
, rcText
->top
, rcText
->right
, rcText
->bottom
);
575 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
576 if ((state
& CDIS_HOT
) && (dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)) {
577 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
579 else if (state
& CDIS_DISABLED
) {
580 clrOld
= SetTextColor (hdc
, tbcd
->clrBtnHighlight
);
581 OffsetRect (rcText
, 1, 1);
582 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
583 SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
584 OffsetRect (rcText
, -1, -1);
586 else if (state
& CDIS_INDETERMINATE
) {
587 clrOld
= SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
589 else if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
)) {
590 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
591 clrOldBk
= SetBkColor (hdc
, tbcd
->clrMark
);
592 oldBkMode
= SetBkMode (hdc
, tbcd
->nHLStringBkMode
);
595 clrOld
= SetTextColor (hdc
, tbcd
->clrText
);
598 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
599 SetTextColor (hdc
, clrOld
);
600 if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
))
602 SetBkColor (hdc
, clrOldBk
);
603 SetBkMode (hdc
, oldBkMode
);
605 SelectObject (hdc
, hOldFont
);
611 TOOLBAR_DrawPattern (const RECT
*lpRect
, const NMTBCUSTOMDRAW
*tbcd
)
613 HDC hdc
= tbcd
->nmcd
.hdc
;
614 HBRUSH hbr
= SelectObject (hdc
, tbcd
->hbrMonoDither
);
617 INT cx
= lpRect
->right
- lpRect
->left
;
618 INT cy
= lpRect
->bottom
- lpRect
->top
;
619 INT cxEdge
= GetSystemMetrics(SM_CXEDGE
);
620 INT cyEdge
= GetSystemMetrics(SM_CYEDGE
);
621 clrTextOld
= SetTextColor(hdc
, tbcd
->clrBtnHighlight
);
622 clrBkOld
= SetBkColor(hdc
, tbcd
->clrBtnFace
);
623 PatBlt (hdc
, lpRect
->left
+ cxEdge
, lpRect
->top
+ cyEdge
,
624 cx
- (2 * cxEdge
), cy
- (2 * cyEdge
), PATCOPY
);
625 SetBkColor(hdc
, clrBkOld
);
626 SetTextColor(hdc
, clrTextOld
);
627 SelectObject (hdc
, hbr
);
631 static void TOOLBAR_DrawMasked(HIMAGELIST himl
, int index
, HDC hdc
, INT x
, INT y
, UINT draw_flags
)
634 HBITMAP hbmMask
, hbmImage
;
635 HDC hdcMask
, hdcImage
;
637 ImageList_GetIconSize(himl
, &cx
, &cy
);
639 /* Create src image */
640 hdcImage
= CreateCompatibleDC(hdc
);
641 hbmImage
= CreateCompatibleBitmap(hdc
, cx
, cy
);
642 SelectObject(hdcImage
, hbmImage
);
643 ImageList_DrawEx(himl
, index
, hdcImage
, 0, 0, cx
, cy
,
644 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags
);
647 hdcMask
= CreateCompatibleDC(0);
648 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
649 SelectObject(hdcMask
, hbmMask
);
651 /* Remove the background and all white pixels */
652 ImageList_DrawEx(himl
, index
, hdcMask
, 0, 0, cx
, cy
,
653 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK
);
654 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
655 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
657 /* draw the new mask 'etched' to hdc */
658 SetBkColor(hdc
, RGB(255, 255, 255));
659 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
660 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
661 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
662 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
663 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
666 DeleteObject(hbmImage
);
668 DeleteObject (hbmMask
);
674 TOOLBAR_TranslateState(const TBUTTON_INFO
*btnPtr
)
678 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
679 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
680 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
681 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
682 retstate
|= (btnPtr
->bHot
) ? CDIS_HOT
: 0;
683 retstate
|= ((btnPtr
->fsState
& (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) == (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) ? CDIS_INDETERMINATE
: 0;
684 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
688 /* draws the image on a toolbar button */
690 TOOLBAR_DrawImage(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
,
691 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
693 HIMAGELIST himl
= NULL
;
694 BOOL draw_masked
= FALSE
;
697 UINT draw_flags
= ILD_TRANSPARENT
;
699 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
701 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
704 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
708 else if (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
||
709 ((tbcd
->nmcd
.uItemState
& CDIS_HOT
)
710 && ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))))
712 /* if hot, attempt to draw with hot image list, if fails,
713 use default image list */
714 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
716 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
719 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
724 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
725 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
728 if (!(dwItemCDFlag
& TBCDRF_NOMARK
) &&
729 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
730 draw_flags
|= ILD_BLEND50
;
732 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
733 index
, himl
, left
, top
, offset
);
736 TOOLBAR_DrawMasked (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
738 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
741 /* draws a blank frame for a toolbar button */
743 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
745 HDC hdc
= tbcd
->nmcd
.hdc
;
746 RECT rc
= tbcd
->nmcd
.rc
;
747 /* if the state is disabled or indeterminate then the button
748 * cannot have an interactive look like pressed or hot */
749 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
750 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
751 BOOL pressed_look
= !non_interactive_state
&&
752 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
753 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
755 /* app don't want us to draw any edges */
756 if (dwItemCDFlag
& TBCDRF_NOEDGES
)
759 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
762 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
763 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
764 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
769 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
771 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
772 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
777 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
, BOOL bDropDownPressed
, DWORD dwItemCDFlag
)
779 HDC hdc
= tbcd
->nmcd
.hdc
;
781 BOOL pressed
= bDropDownPressed
||
782 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
));
784 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
787 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
);
788 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
789 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
790 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
791 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
796 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
798 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
799 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
803 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
805 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
807 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
808 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
811 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
814 /* draws a complete toolbar button */
816 TOOLBAR_DrawButton (HWND hwnd
, TBUTTON_INFO
*btnPtr
, HDC hdc
, DWORD dwBaseCustDraw
)
818 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
819 DWORD dwStyle
= infoPtr
->dwStyle
;
820 BOOL hasDropDownArrow
= (TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) &&
821 (btnPtr
->fsStyle
& BTNS_DROPDOWN
)) ||
822 (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
823 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
824 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
825 RECT rc
, rcArrow
, rcBitmap
, rcText
;
826 LPWSTR lpText
= NULL
;
831 DWORD dwItemCustDraw
;
833 HTHEME theme
= GetWindowTheme (hwnd
);
836 CopyRect (&rcArrow
, &rc
);
838 /* separator - doesn't send NM_CUSTOMDRAW */
839 if (btnPtr
->fsStyle
& BTNS_SEP
) {
842 DrawThemeBackground (theme
, hdc
,
843 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
847 /* with the FLAT style, iBitmap is the width and has already */
848 /* been taken into consideration in calculating the width */
849 /* so now we need to draw the vertical separator */
850 /* empirical tests show that iBitmap can/will be non-zero */
851 /* when drawing the vertical bar... */
852 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
853 if (btnPtr
->fsStyle
& BTNS_DROPDOWN
)
854 TOOLBAR_DrawDDFlatSeparator (&rc
, hdc
, btnPtr
, infoPtr
);
856 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
858 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
859 FIXME("Draw some kind of separator: fsStyle=%x\n",
865 /* get a pointer to the text */
866 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
868 if (hasDropDownArrow
)
872 if (dwStyle
& TBSTYLE_FLAT
)
873 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
875 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
877 if (drawSepDropDownArrow
)
880 rcArrow
.left
= right
;
883 /* copy text & bitmap rects after adjusting for drop-down arrow
884 * so that text & bitmap is centred in the rectangle not containing
886 CopyRect(&rcText
, &rc
);
887 CopyRect(&rcBitmap
, &rc
);
889 /* Center the bitmap horizontally and vertically */
890 if (dwStyle
& TBSTYLE_LIST
)
893 infoPtr
->nMaxTextRows
> 0 &&
894 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
895 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
896 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
898 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
901 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
903 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
905 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
906 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
907 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
908 TRACE("Text=%s\n", debugstr_w(lpText
));
909 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
911 /* calculate text position */
914 rcText
.left
+= GetSystemMetrics(SM_CXEDGE
);
915 rcText
.right
-= GetSystemMetrics(SM_CXEDGE
);
916 if (dwStyle
& TBSTYLE_LIST
)
918 if (TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
))
919 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
923 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
924 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
926 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
930 /* Initialize fields in all cases, because we use these later
931 * NOTE: applications can and do alter these to customize their
933 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
934 tbcd
.clrText
= comctl32_color
.clrBtnText
;
935 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
936 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
937 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
938 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
939 tbcd
.clrHighlightHotTrack
= 0;
940 tbcd
.nStringBkMode
= TRANSPARENT
;
941 tbcd
.nHLStringBkMode
= OPAQUE
;
942 /* MSDN says that this is the text rectangle.
943 * But (why always a but) tracing of v5.7 of native shows
944 * that this is really a *relative* rectangle based on the
945 * the nmcd.rc. Also the left and top are always 0 ignoring
946 * any bitmap that might be present. */
947 tbcd
.rcText
.left
= 0;
949 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
950 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
951 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
954 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
956 /* FIXME: what are these used for? */
960 /* Issue Item Prepaint notify */
963 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
965 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
966 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
967 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
968 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
969 /* reset these fields so the user can't alter the behaviour like native */
973 dwItemCustDraw
= ntfret
& 0xffff;
974 dwItemCDFlag
= ntfret
& 0xffff0000;
975 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
977 /* save the only part of the rect that the user can change */
978 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
979 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
982 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
983 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
984 OffsetRect(&rcText
, 1, 1);
986 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
987 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
988 TOOLBAR_DrawPattern (&rc
, &tbcd
);
990 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
991 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
993 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
997 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
998 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
999 if (hasDropDownArrow
)
1000 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
1001 SetBkColor(hdc
, oldclr
);
1007 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
1008 int stateId
= TS_NORMAL
;
1010 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1011 stateId
= TS_DISABLED
;
1012 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1013 stateId
= TS_PRESSED
;
1014 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1015 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1016 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1017 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1020 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &tbcd
.nmcd
.rc
, NULL
);
1023 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, dwItemCDFlag
);
1025 if (drawSepDropDownArrow
)
1029 int stateId
= TS_NORMAL
;
1031 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1032 stateId
= TS_DISABLED
;
1033 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1034 stateId
= TS_PRESSED
;
1035 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1036 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1037 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1040 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1041 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1044 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1047 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1048 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1049 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1050 SetBkMode (hdc
, oldBkMode
);
1052 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1054 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1056 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1058 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1059 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1061 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1063 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1064 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1067 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1070 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1072 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1073 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1080 TOOLBAR_Refresh (HWND hwnd
, HDC hdc
, const PAINTSTRUCT
*ps
)
1082 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1083 TBUTTON_INFO
*btnPtr
;
1085 RECT rcTemp
, rcClient
;
1086 NMTBCUSTOMDRAW tbcd
;
1088 DWORD dwBaseCustDraw
;
1090 /* the app has told us not to redraw the toolbar */
1091 if (!infoPtr
->bDoRedraw
)
1094 /* if imagelist belongs to the app, it can be changed
1095 by the app after setting it */
1096 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1098 infoPtr
->nNumBitmaps
= 0;
1099 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1100 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1103 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1105 /* change the imagelist icon size if we manage the list and it is necessary */
1106 TOOLBAR_CheckImageListIconSize(infoPtr
);
1108 /* Send initial notify */
1109 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1110 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1111 tbcd
.nmcd
.hdc
= hdc
;
1112 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1113 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1114 dwBaseCustDraw
= ntfret
& 0xffff;
1116 GetClientRect(hwnd
, &rcClient
);
1118 /* redraw necessary buttons */
1119 btnPtr
= infoPtr
->buttons
;
1120 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1123 if (!RectVisible(hdc
, &btnPtr
->rect
))
1125 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1127 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1128 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1132 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1133 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1135 TOOLBAR_DrawButton(hwnd
, btnPtr
, hdc
, dwBaseCustDraw
);
1138 /* draw insert mark if required */
1139 if (infoPtr
->tbim
.iButton
!= -1)
1141 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1143 rcInsertMark
.top
= rcButton
.top
;
1144 rcInsertMark
.bottom
= rcButton
.bottom
;
1145 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1146 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1148 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1149 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1152 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1154 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1155 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1156 tbcd
.nmcd
.hdc
= hdc
;
1157 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1158 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1162 /***********************************************************************
1163 * TOOLBAR_MeasureString
1165 * This function gets the width and height of a string in pixels. This
1166 * is done first by using GetTextExtentPoint to get the basic width
1167 * and height. The DrawText is called with DT_CALCRECT to get the exact
1168 * width. The reason is because the text may have more than one "&" (or
1169 * prefix characters as M$ likes to call them). The prefix character
1170 * indicates where the underline goes, except for the string "&&" which
1171 * is reduced to a single "&". GetTextExtentPoint does not process these
1172 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1175 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1176 HDC hdc
, LPSIZE lpSize
)
1183 if (infoPtr
->nMaxTextRows
> 0 &&
1184 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1185 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1186 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1188 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1190 if(lpText
!= NULL
) {
1191 /* first get size of all the text */
1192 GetTextExtentPoint32W (hdc
, lpText
, strlenW (lpText
), lpSize
);
1194 /* feed above size into the rectangle for DrawText */
1195 myrect
.left
= myrect
.top
= 0;
1196 myrect
.right
= lpSize
->cx
;
1197 myrect
.bottom
= lpSize
->cy
;
1199 /* Use DrawText to get true size as drawn (less pesky "&") */
1200 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1201 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1204 /* feed back to caller */
1205 lpSize
->cx
= myrect
.right
;
1206 lpSize
->cy
= myrect
.bottom
;
1210 TRACE("string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1213 /***********************************************************************
1214 * TOOLBAR_CalcStrings
1216 * This function walks through each string and measures it and returns
1217 * the largest height and width to caller.
1220 TOOLBAR_CalcStrings (HWND hwnd
, LPSIZE lpSize
)
1222 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1223 TBUTTON_INFO
*btnPtr
;
1232 if (infoPtr
->nMaxTextRows
== 0)
1236 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1238 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1242 GetTextMetricsW(hdc
, &tm
);
1243 lpSize
->cy
= tm
.tmHeight
;
1246 btnPtr
= infoPtr
->buttons
;
1247 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1248 if(TOOLBAR_HasText(infoPtr
, btnPtr
))
1250 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1251 if (sz
.cx
> lpSize
->cx
)
1253 if (sz
.cy
> lpSize
->cy
)
1258 SelectObject (hdc
, hOldFont
);
1259 ReleaseDC (hwnd
, hdc
);
1261 TRACE("max string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1264 /***********************************************************************
1265 * TOOLBAR_WrapToolbar
1267 * This function walks through the buttons and separators in the
1268 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1269 * wrapping should occur based on the width of the toolbar window.
1270 * It does *not* calculate button placement itself. That task
1271 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1272 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1273 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1275 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1276 * vertical toolbar lists.
1280 TOOLBAR_WrapToolbar( HWND hwnd
, DWORD dwStyle
)
1282 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1283 TBUTTON_INFO
*btnPtr
;
1286 BOOL bWrap
, bButtonWrap
;
1288 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1289 /* no layout is necessary. Applications may use this style */
1290 /* to perform their own layout on the toolbar. */
1291 if( !(dwStyle
& TBSTYLE_WRAPABLE
) &&
1292 !(infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
) ) return;
1294 btnPtr
= infoPtr
->buttons
;
1295 x
= infoPtr
->nIndent
;
1297 if (GetParent(hwnd
))
1299 /* this can get the parents width, to know how far we can extend
1300 * this toolbar. We cannot use its height, as there may be multiple
1301 * toolbars in a rebar control
1303 GetClientRect( GetParent(hwnd
), &rc
);
1304 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1308 GetWindowRect( hwnd
, &rc
);
1309 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1312 bButtonWrap
= FALSE
;
1314 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1315 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, infoPtr
->nWidth
,
1318 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1321 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1323 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1326 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1327 /* it is the actual width of the separator. This is used for */
1328 /* custom controls in toolbars. */
1330 /* BTNS_DROPDOWN separators are treated as buttons for */
1331 /* width. - GA 8/01 */
1332 if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1333 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
))
1334 cx
= (btnPtr
[i
].iBitmap
> 0) ?
1335 btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1337 cx
= infoPtr
->nButtonWidth
;
1339 /* Two or more adjacent separators form a separator group. */
1340 /* The first separator in a group should be wrapped to the */
1341 /* next row if the previous wrapping is on a button. */
1343 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1344 (i
+ 1 < infoPtr
->nNumButtons
) &&
1345 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1347 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1348 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1349 x
= infoPtr
->nIndent
;
1351 bButtonWrap
= FALSE
;
1355 /* The layout makes sure the bitmap is visible, but not the button. */
1356 /* Test added to also wrap after a button that starts a row but */
1357 /* is bigger than the area. - GA 8/01 */
1358 if (( x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2
1359 > infoPtr
->nWidth
) ||
1360 ((x
== infoPtr
->nIndent
) && (cx
> infoPtr
->nWidth
)))
1362 BOOL bFound
= FALSE
;
1364 /* If the current button is a separator and not hidden, */
1365 /* go to the next until it reaches a non separator. */
1366 /* Wrap the last separator if it is before a button. */
1367 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1368 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1369 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1370 i
< infoPtr
->nNumButtons
)
1376 if( bFound
&& i
< infoPtr
->nNumButtons
)
1379 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1380 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1381 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1382 x
= infoPtr
->nIndent
;
1383 bButtonWrap
= FALSE
;
1386 else if ( i
>= infoPtr
->nNumButtons
)
1389 /* If the current button is not a separator, find the last */
1390 /* separator and wrap it. */
1391 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1393 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1394 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1398 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1399 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1400 x
= infoPtr
->nIndent
;
1401 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1402 bButtonWrap
= FALSE
;
1407 /* If no separator available for wrapping, wrap one of */
1408 /* non-hidden previous button. */
1412 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1414 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1419 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1420 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1421 x
= infoPtr
->nIndent
;
1422 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1428 /* If all above failed, wrap the current button. */
1431 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1432 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1433 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1435 x
= infoPtr
->nIndent
;
1436 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1437 bButtonWrap
= FALSE
;
1443 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1444 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1451 /***********************************************************************
1452 * TOOLBAR_MeasureButton
1454 * Calculates the width and height required for a button. Used in
1455 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1456 * the width of buttons that are autosized.
1458 * Note that it would have been rather elegant to use one piece of code for
1459 * both the laying out of the toolbar and for controlling where button parts
1460 * are drawn, but the native control has inconsistencies between the two that
1461 * prevent this from being effectively. These inconsistencies can be seen as
1462 * artefacts where parts of the button appear outside of the bounding button
1465 * There are several cases for the calculation of the button dimensions and
1466 * button part positioning:
1473 * +--------------------------------------------------------+ ^
1475 * | | pad.cy / 2 | centred | |
1476 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1477 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1478 * | |<------------>| | | | |
1479 * | +--------------+ +------------+ | |
1480 * |<-------------------------------------->| | |
1481 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1483 * +--------------------------------------------------------+ -
1484 * <-------------------------------------------------------->
1485 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1487 * Without Bitmap (I_IMAGENONE):
1489 * +-----------------------------------+ ^
1491 * | | centred | | LISTPAD_CY +
1492 * | +------------+ | | szText.cy
1495 * | +------------+ | |
1496 * |<----------------->| | |
1497 * | cxedge |<-----------> | |
1499 * +-----------------------------------+ -
1500 * <----------------------------------->
1501 * szText.cx + pad.cx
1505 * +--------------------------------------+ ^
1507 * | | padding.cy/2 | | DEFPAD_CY +
1508 * | +------------+ | | nBitmapHeight
1511 * | +------------+ | |
1512 * |<------------------->| | |
1513 * | cxedge + iListGap/2 |<-----------> | |
1514 * | nBitmapWidth | |
1515 * +--------------------------------------+ -
1516 * <-------------------------------------->
1517 * 2*cxedge + nBitmapWidth + iListGap
1524 * +-----------------------------------+ ^
1526 * | | pad.cy / 2 | | nBitmapHeight +
1527 * | - | | szText.cy +
1528 * | +------------+ | | DEFPAD_CY + 1
1529 * | centred | Bitmap | | |
1530 * |<----------------->| | | |
1531 * | +------------+ | |
1535 * | centred +---------------+ | |
1536 * |<--------------->| Text | | |
1537 * | +---------------+ | |
1538 * +-----------------------------------+ -
1539 * <----------------------------------->
1540 * pad.cx + max(nBitmapWidth, szText.cx)
1542 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1544 * +---------------------------------------+ ^
1546 * | | 2 + pad.cy / 2 | |
1547 * | - | | szText.cy +
1548 * | centred +-----------------+ | | pad.cy + 2
1549 * |<--------------->| Text | | |
1550 * | +-----------------+ | |
1552 * +---------------------------------------+ -
1553 * <--------------------------------------->
1554 * 2*cxedge + pad.cx + szText.cx
1557 * As for with bitmaps, but with szText.cx zero.
1559 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1560 BOOL bHasBitmap
, BOOL bValidImageList
)
1563 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1565 /* set button height from bitmap / text height... */
1566 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1569 /* ... add on the necessary padding */
1570 if (bValidImageList
)
1573 sizeButton
.cy
+= DEFPAD_CY
;
1575 sizeButton
.cy
+= LISTPAD_CY
;
1578 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1580 /* calculate button width */
1583 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1584 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1585 if (sizeString
.cx
> 0)
1586 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1589 sizeButton
.cx
= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1595 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1596 if (sizeString
.cy
> 0)
1597 sizeButton
.cy
+= 1 + sizeString
.cy
;
1598 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1599 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1603 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1604 NONLIST_NOTEXT_OFFSET
;
1605 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1606 infoPtr
->szPadding
.cx
+ sizeString
.cx
;
1613 /***********************************************************************
1614 * TOOLBAR_CalcToolbar
1616 * This function calculates button and separator placement. It first
1617 * calculates the button sizes, gets the toolbar window width and then
1618 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1619 * on. It assigns a new location to each item and sends this location to
1620 * the tooltip window if appropriate. Finally, it updates the rcBound
1621 * rect and calculates the new required toolbar window height.
1624 TOOLBAR_CalcToolbar (HWND hwnd
)
1626 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
1627 SIZE sizeString
, sizeButton
;
1628 BOOL validImageList
= FALSE
;
1630 TOOLBAR_CalcStrings (hwnd
, &sizeString
);
1632 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1634 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1635 validImageList
= TRUE
;
1636 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1637 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1638 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1639 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1641 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1642 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1643 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1644 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1646 TOOLBAR_LayoutToolbar(hwnd
);
1650 TOOLBAR_LayoutToolbar(HWND hwnd
)
1652 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
1653 TBUTTON_INFO
*btnPtr
;
1655 INT i
, nRows
, nSepRows
;
1658 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1659 BOOL hasDropDownArrows
= TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
);
1661 TOOLBAR_WrapToolbar(hwnd
, infoPtr
->dwStyle
);
1663 x
= infoPtr
->nIndent
;
1664 y
= infoPtr
->iTopMargin
;
1665 cx
= infoPtr
->nButtonWidth
;
1666 cy
= infoPtr
->nButtonHeight
;
1668 nRows
= nSepRows
= 0;
1670 infoPtr
->rcBound
.top
= y
;
1671 infoPtr
->rcBound
.left
= x
;
1672 infoPtr
->rcBound
.bottom
= y
+ cy
;
1673 infoPtr
->rcBound
.right
= x
;
1675 btnPtr
= infoPtr
->buttons
;
1677 TRACE("cy=%d\n", cy
);
1679 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1682 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1684 SetRectEmpty (&btnPtr
->rect
);
1688 cy
= infoPtr
->nButtonHeight
;
1690 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1691 /* it is the actual width of the separator. This is used for */
1692 /* custom controls in toolbars. */
1693 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1694 if (btnPtr
->fsStyle
& BTNS_DROPDOWN
) {
1695 cy
= (btnPtr
->iBitmap
> 0) ?
1696 btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1697 cx
= infoPtr
->nButtonWidth
;
1700 cx
= (btnPtr
->iBitmap
> 0) ?
1701 btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1707 else if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1708 (btnPtr
->fsStyle
& BTNS_AUTOSIZE
))
1715 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1717 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1719 SelectObject (hdc
, hOldFont
);
1720 ReleaseDC (hwnd
, hdc
);
1722 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1723 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1728 cx
= infoPtr
->nButtonWidth
;
1730 /* if size has been set manually then don't add on extra space
1731 * for the drop down arrow */
1732 if (!btnPtr
->cx
&& hasDropDownArrows
&&
1733 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) || (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)))
1734 cx
+= DDARROW_WIDTH
;
1736 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1739 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1741 if (infoPtr
->rcBound
.left
> x
)
1742 infoPtr
->rcBound
.left
= x
;
1743 if (infoPtr
->rcBound
.right
< x
+ cx
)
1744 infoPtr
->rcBound
.right
= x
+ cx
;
1745 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1746 infoPtr
->rcBound
.bottom
= y
+ cy
;
1748 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1750 /* btnPtr->nRow is zero based. The space between the rows is */
1751 /* also considered as a row. */
1752 btnPtr
->nRow
= nRows
+ nSepRows
;
1754 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1755 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1760 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1764 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1765 /* it is the actual width of the separator. This is used for */
1766 /* custom controls in toolbars. */
1767 if ( !(btnPtr
->fsStyle
& BTNS_DROPDOWN
))
1768 y
+= cy
+ ( (btnPtr
->iBitmap
> 0 ) ?
1769 btnPtr
->iBitmap
: SEPARATOR_WIDTH
) * 2 /3;
1773 /* nSepRows is used to calculate the extra height follwoing */
1777 x
= infoPtr
->nIndent
;
1779 /* Increment row number unless this is the last button */
1780 /* and it has Wrap set. */
1781 if (i
!= infoPtr
->nNumButtons
-1)
1788 /* infoPtr->nRows is the number of rows on the toolbar */
1789 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1791 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1796 TOOLBAR_InternalHitTest (HWND hwnd
, const POINT
*lpPt
)
1798 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1799 TBUTTON_INFO
*btnPtr
;
1802 btnPtr
= infoPtr
->buttons
;
1803 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1804 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1807 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1808 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1809 TRACE(" ON SEPARATOR %d!\n", i
);
1814 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1815 TRACE(" ON BUTTON %d!\n", i
);
1821 TRACE(" NOWHERE!\n");
1822 return TOOLBAR_NOWHERE
;
1827 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1829 TBUTTON_INFO
*btnPtr
;
1832 if (CommandIsIndex
) {
1833 TRACE("command is really index command=%d\n", idCommand
);
1834 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1837 btnPtr
= infoPtr
->buttons
;
1838 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1839 if (btnPtr
->idCommand
== idCommand
) {
1840 TRACE("command=%d index=%d\n", idCommand
, i
);
1844 TRACE("no index found for command=%d\n", idCommand
);
1850 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1852 TBUTTON_INFO
*btnPtr
;
1855 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1858 /* check index button */
1859 btnPtr
= &infoPtr
->buttons
[nIndex
];
1860 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1861 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1865 /* check previous buttons */
1866 nRunIndex
= nIndex
- 1;
1867 while (nRunIndex
>= 0) {
1868 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1869 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1870 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1878 /* check next buttons */
1879 nRunIndex
= nIndex
+ 1;
1880 while (nRunIndex
< infoPtr
->nNumButtons
) {
1881 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1882 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1883 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1896 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1897 WPARAM wParam
, LPARAM lParam
)
1903 msg
.wParam
= wParam
;
1904 msg
.lParam
= lParam
;
1905 msg
.time
= GetMessageTime ();
1906 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
1907 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
1909 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1913 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1915 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
1918 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
1919 ti
.cbSize
= sizeof (TTTOOLINFOW
);
1920 ti
.hwnd
= infoPtr
->hwndSelf
;
1921 ti
.uId
= button
->idCommand
;
1923 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
1924 /* ti.lParam = random value from the stack? */
1926 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
1932 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1934 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
1937 ZeroMemory(&ti
, sizeof(ti
));
1938 ti
.cbSize
= sizeof(ti
);
1939 ti
.hwnd
= infoPtr
->hwndSelf
;
1940 ti
.uId
= button
->idCommand
;
1942 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
1946 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1948 /* Set the toolTip only for non-hidden, non-separator button */
1949 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
1953 ZeroMemory(&ti
, sizeof(ti
));
1954 ti
.cbSize
= sizeof(ti
);
1955 ti
.hwnd
= infoPtr
->hwndSelf
;
1956 ti
.uId
= button
->idCommand
;
1957 ti
.rect
= button
->rect
;
1958 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
1962 /* Creates the tooltip control */
1964 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
1967 NMTOOLTIPSCREATED nmttc
;
1969 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
1970 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1971 infoPtr
->hwndSelf
, 0, 0, 0);
1973 if (!infoPtr
->hwndToolTip
)
1976 /* Send NM_TOOLTIPSCREATED notification */
1977 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
1978 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
1980 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
1982 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
1983 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
1987 /* keeps available button list box sorted by button id */
1988 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
1992 PCUSTOMBUTTON btnInfo
;
1993 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
1995 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
1997 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
1999 /* position 0 is always separator */
2000 for (i
= 1; i
< count
; i
++)
2002 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2003 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2005 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2006 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2010 /* id higher than all others add to end */
2011 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2012 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2015 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2019 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2021 if (nIndexFrom
== nIndexTo
)
2024 /* MSDN states that iItem is the index of the button, rather than the
2025 * command ID as used by every other NMTOOLBAR notification */
2026 nmtb
.iItem
= nIndexFrom
;
2027 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2029 PCUSTOMBUTTON btnInfo
;
2031 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2032 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2034 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2036 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2037 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2038 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2039 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2042 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2044 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2046 /* last item is always separator, so -2 instead of -1 */
2047 if (nIndexTo
>= (count
- 2))
2048 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2050 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2052 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2053 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2055 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2059 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2063 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2065 /* MSDN states that iItem is the index of the button, rather than the
2066 * command ID as used by every other NMTOOLBAR notification */
2067 nmtb
.iItem
= nIndexAvail
;
2068 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2070 PCUSTOMBUTTON btnInfo
;
2072 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2073 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2074 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2076 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2078 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2080 /* remove from 'available buttons' list */
2081 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2082 if (nIndexAvail
== count
-1)
2083 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2085 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2089 PCUSTOMBUTTON btnNew
;
2091 /* duplicate 'separator' button */
2092 btnNew
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2093 memcpy(btnNew
, btnInfo
, sizeof(CUSTOMBUTTON
));
2097 /* insert into 'toolbar button' list */
2098 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2099 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2101 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2103 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2107 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2109 PCUSTOMBUTTON btnInfo
;
2110 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2112 TRACE("Remove: index %d\n", index
);
2114 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2116 /* send TBN_QUERYDELETE notification */
2117 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2121 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2122 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2124 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2126 /* insert into 'available button' list */
2127 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2128 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2132 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2136 /* drag list notification function for toolbar buttons list box */
2137 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2138 const DRAGLISTINFO
*pDLI
)
2140 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2141 switch (pDLI
->uNotification
)
2145 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2146 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2147 /* no dragging for last item (separator) */
2148 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2153 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2154 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2155 /* no dragging past last item (separator) */
2156 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2158 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2159 /* FIXME: native uses "move button" cursor */
2160 return DL_COPYCURSOR
;
2163 /* not over toolbar buttons list */
2164 if (nCurrentItem
< 0)
2166 POINT ptWindow
= pDLI
->ptCursor
;
2167 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2168 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2169 /* over available buttons list? */
2170 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2171 /* FIXME: native uses "move button" cursor */
2172 return DL_COPYCURSOR
;
2174 /* clear drag arrow */
2175 DrawInsert(hwnd
, hwndList
, -1);
2176 return DL_STOPCURSOR
;
2180 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2181 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2182 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2183 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2185 /* clear drag arrow */
2186 DrawInsert(hwnd
, hwndList
, -1);
2188 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2190 /* not over toolbar buttons list */
2193 POINT ptWindow
= pDLI
->ptCursor
;
2194 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2195 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2196 /* over available buttons list? */
2197 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2198 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2203 /* Clear drag arrow */
2204 DrawInsert(hwnd
, hwndList
, -1);
2211 /* drag list notification function for available buttons list box */
2212 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2213 const DRAGLISTINFO
*pDLI
)
2215 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2216 switch (pDLI
->uNotification
)
2222 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2223 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2224 /* no dragging past last item (separator) */
2225 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2227 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2228 /* FIXME: native uses "move button" cursor */
2229 return DL_COPYCURSOR
;
2232 /* not over toolbar buttons list */
2233 if (nCurrentItem
< 0)
2235 POINT ptWindow
= pDLI
->ptCursor
;
2236 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2237 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2238 /* over available buttons list? */
2239 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2240 /* FIXME: native uses "move button" cursor */
2241 return DL_COPYCURSOR
;
2243 /* clear drag arrow */
2244 DrawInsert(hwnd
, hwndList
, -1);
2245 return DL_STOPCURSOR
;
2249 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2250 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2251 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2252 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2254 /* clear drag arrow */
2255 DrawInsert(hwnd
, hwndList
, -1);
2257 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2261 /* Clear drag arrow */
2262 DrawInsert(hwnd
, hwndList
, -1);
2268 extern UINT uDragListMessage
;
2270 /***********************************************************************
2271 * TOOLBAR_CustomizeDialogProc
2272 * This function implements the toolbar customization dialog.
2274 static INT_PTR CALLBACK
2275 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2277 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2278 PCUSTOMBUTTON btnInfo
;
2280 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2285 custInfo
= (PCUSTDLG_INFO
)lParam
;
2286 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2293 NMTBINITCUSTOMIZE nmtbic
;
2295 infoPtr
= custInfo
->tbInfo
;
2297 /* send TBN_QUERYINSERT notification */
2298 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2300 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2303 nmtbic
.hwndDialog
= hwnd
;
2304 /* Send TBN_INITCUSTOMIZE notification */
2305 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2308 TRACE("TBNRF_HIDEHELP requested\n");
2309 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2312 /* add items to 'toolbar buttons' list and check if removable */
2313 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2315 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2316 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2317 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2318 btnInfo
->bVirtual
= FALSE
;
2319 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2321 /* send TBN_QUERYDELETE notification */
2322 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2324 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2325 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2328 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2330 /* insert separator button into 'available buttons' list */
2331 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2332 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2333 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2334 btnInfo
->bVirtual
= FALSE
;
2335 btnInfo
->bRemovable
= TRUE
;
2336 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2337 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2338 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2340 /* insert all buttons into dsa */
2343 /* send TBN_GETBUTTONINFO notification */
2346 nmtb
.pszText
= Buffer
;
2349 /* Clear previous button's text */
2350 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2352 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2355 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2356 nmtb
.tbButton
.fsStyle
, i
,
2357 nmtb
.tbButton
.idCommand
,
2358 nmtb
.tbButton
.iString
,
2359 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2362 /* insert button into the apropriate list */
2363 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2366 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2367 btnInfo
->bVirtual
= FALSE
;
2368 btnInfo
->bRemovable
= TRUE
;
2372 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2373 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2376 memcpy (&btnInfo
->btn
, &nmtb
.tbButton
, sizeof(TBBUTTON
));
2377 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2379 if (lstrlenW(nmtb
.pszText
))
2380 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2381 else if (nmtb
.tbButton
.iString
>= 0 &&
2382 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2384 lstrcpyW(btnInfo
->text
,
2385 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2390 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2393 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2395 /* select first item in the 'available' list */
2396 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2398 /* append 'virtual' separator button to the 'toolbar buttons' list */
2399 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2400 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2401 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2402 btnInfo
->bVirtual
= TRUE
;
2403 btnInfo
->bRemovable
= FALSE
;
2404 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2405 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2406 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2408 /* select last item in the 'toolbar' list */
2409 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2410 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2412 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2413 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2415 /* set focus and disable buttons */
2416 PostMessageW (hwnd
, WM_USER
, 0, 0);
2421 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2422 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2423 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2424 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2428 EndDialog(hwnd
, FALSE
);
2432 switch (LOWORD(wParam
))
2434 case IDC_TOOLBARBTN_LBOX
:
2435 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2437 PCUSTOMBUTTON btnInfo
;
2442 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2443 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2445 /* send TBN_QUERYINSERT notification */
2447 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2449 /* get list box item */
2450 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2452 if (index
== (count
- 1))
2454 /* last item (virtual separator) */
2455 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2456 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2458 else if (index
== (count
- 2))
2460 /* second last item (last non-virtual item) */
2461 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2462 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2464 else if (index
== 0)
2467 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2468 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2472 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2473 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2476 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2480 case IDC_MOVEUP_BTN
:
2482 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2483 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2487 case IDC_MOVEDN_BTN
: /* move down */
2489 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2490 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2494 case IDC_REMOVE_BTN
: /* remove button */
2496 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2498 if (LB_ERR
== index
)
2501 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2505 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2508 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2511 case IDOK
: /* Add button */
2516 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2517 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2519 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2524 EndDialog(hwnd
, FALSE
);
2534 /* delete items from 'toolbar buttons' listbox*/
2535 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2536 for (i
= 0; i
< count
; i
++)
2538 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2540 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2542 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2545 /* delete items from 'available buttons' listbox*/
2546 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2547 for (i
= 0; i
< count
; i
++)
2549 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2551 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2553 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2558 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2560 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2565 COLORREF oldText
= 0;
2569 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, (WPARAM
)lpdis
->itemID
, 0);
2570 if (btnInfo
== NULL
)
2572 FIXME("btnInfo invalid!\n");
2576 /* set colors and select objects */
2577 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2578 if (btnInfo
->bVirtual
)
2579 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2581 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2582 hPen
= CreatePen( PS_SOLID
, 1,
2583 GetSysColor( (lpdis
->itemState
& ODS_SELECTED
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2584 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2585 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2587 /* fill background rectangle */
2588 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2589 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2591 /* calculate button and text rectangles */
2592 CopyRect (&rcButton
, &lpdis
->rcItem
);
2593 InflateRect (&rcButton
, -1, -1);
2594 CopyRect (&rcText
, &rcButton
);
2595 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2596 rcText
.left
= rcButton
.right
+ 2;
2598 /* draw focus rectangle */
2599 if (lpdis
->itemState
& ODS_FOCUS
)
2600 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2603 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2604 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2606 /* draw image and text */
2607 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2608 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2609 btnInfo
->btn
.iBitmap
));
2610 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2611 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2613 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2614 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2616 /* delete objects and reset colors */
2617 SelectObject (lpdis
->hDC
, hOldBrush
);
2618 SelectObject (lpdis
->hDC
, hOldPen
);
2619 SetBkColor (lpdis
->hDC
, oldBk
);
2620 SetTextColor (lpdis
->hDC
, oldText
);
2621 DeleteObject( hPen
);
2626 case WM_MEASUREITEM
:
2627 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2629 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2631 lpmis
->itemHeight
= 15 + 8; /* default height */
2638 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2640 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2642 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2643 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2644 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2647 else if (wParam
== IDC_AVAILBTN_LBOX
)
2649 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2650 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2651 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2660 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2663 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2669 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2670 /* Add bitmaps to the default image list */
2671 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2672 hbmLoad
= (HBITMAP
)CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2674 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2676 /* enlarge the bitmap if needed */
2677 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2678 if (bitmap
->hInst
!= COMCTL32_hModule
)
2679 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2681 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2682 DeleteObject(hbmLoad
);
2686 nCountAfter
= ImageList_GetImageCount(himlDef
);
2687 nAdded
= nCountAfter
- nCountBefore
;
2688 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2690 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2691 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2692 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2693 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2696 infoPtr
->nNumBitmaps
+= nAdded
;
2701 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2708 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2709 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2711 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2713 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2716 TRACE("Update icon size: %dx%d -> %dx%d\n",
2717 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2719 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2720 ILC_COLORDDB
|ILC_MASK
, 8, 2);
2721 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2722 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2723 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2724 infoPtr
->himlInt
= himlNew
;
2726 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2727 ImageList_Destroy(himlDef
);
2730 /***********************************************************************
2731 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2735 TOOLBAR_AddBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2737 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2738 LPTBADDBITMAP lpAddBmp
= (LPTBADDBITMAP
)lParam
;
2743 TRACE("hwnd=%p wParam=%lx lParam=%lx\n", hwnd
, wParam
, lParam
);
2747 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2749 info
.hInst
= COMCTL32_hModule
;
2750 switch (lpAddBmp
->nID
)
2752 case IDB_STD_SMALL_COLOR
:
2754 info
.nID
= IDB_STD_SMALL
;
2756 case IDB_STD_LARGE_COLOR
:
2758 info
.nID
= IDB_STD_LARGE
;
2760 case IDB_VIEW_SMALL_COLOR
:
2762 info
.nID
= IDB_VIEW_SMALL
;
2764 case IDB_VIEW_LARGE_COLOR
:
2766 info
.nID
= IDB_VIEW_LARGE
;
2768 case IDB_HIST_SMALL_COLOR
:
2770 info
.nID
= IDB_HIST_SMALL
;
2772 case IDB_HIST_LARGE_COLOR
:
2774 info
.nID
= IDB_HIST_LARGE
;
2780 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2782 /* Windows resize all the buttons to the size of a newly added standard image */
2783 if (lpAddBmp
->nID
& 1)
2785 /* large icons: 24x24. Will make the button 31x30 */
2786 SendMessageW (hwnd
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2790 /* small icons: 16x16. Will make the buttons 23x22 */
2791 SendMessageW (hwnd
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2794 TOOLBAR_CalcToolbar (hwnd
);
2798 info
.nButtons
= (INT
)wParam
;
2799 info
.hInst
= lpAddBmp
->hInst
;
2800 info
.nID
= lpAddBmp
->nID
;
2801 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2804 /* check if the bitmap is already loaded and compute iSumButtons */
2806 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2808 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2809 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2811 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2814 if (!infoPtr
->cimlDef
) {
2815 /* create new default image list */
2816 TRACE ("creating default image list!\n");
2818 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2819 ILC_COLORDDB
| ILC_MASK
, info
.nButtons
, 2);
2820 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2821 infoPtr
->himlInt
= himlDef
;
2824 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2828 WARN("No default image list available\n");
2832 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2835 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2836 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2837 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2838 infoPtr
->nNumBitmapInfos
++;
2839 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2841 InvalidateRect(hwnd
, NULL
, TRUE
);
2847 TOOLBAR_AddButtonsT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL fUnicode
)
2849 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2850 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
2851 INT nOldButtons
, nNewButtons
, nAddButtons
, nCount
;
2852 BOOL fHasString
= FALSE
;
2854 TRACE("adding %ld buttons (unicode=%d)!\n", wParam
, fUnicode
);
2856 nAddButtons
= (UINT
)wParam
;
2857 nOldButtons
= infoPtr
->nNumButtons
;
2858 nNewButtons
= nOldButtons
+ nAddButtons
;
2860 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
2861 infoPtr
->nNumButtons
= nNewButtons
;
2863 /* insert new button data */
2864 for (nCount
= 0; nCount
< nAddButtons
; nCount
++) {
2865 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nOldButtons
+nCount
];
2866 btnPtr
->iBitmap
= lpTbb
[nCount
].iBitmap
;
2867 btnPtr
->idCommand
= lpTbb
[nCount
].idCommand
;
2868 btnPtr
->fsState
= lpTbb
[nCount
].fsState
;
2869 btnPtr
->fsStyle
= lpTbb
[nCount
].fsStyle
;
2870 btnPtr
->dwData
= lpTbb
[nCount
].dwData
;
2871 btnPtr
->bHot
= FALSE
;
2872 if(HIWORD(lpTbb
[nCount
].iString
) && lpTbb
[nCount
].iString
!= -1)
2875 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, (LPWSTR
)lpTbb
[nCount
].iString
);
2877 Str_SetPtrAtoW((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lpTbb
[nCount
].iString
);
2881 btnPtr
->iString
= lpTbb
[nCount
].iString
;
2883 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
2886 if (infoPtr
->nNumStrings
> 0 || fHasString
)
2887 TOOLBAR_CalcToolbar(hwnd
);
2889 TOOLBAR_LayoutToolbar(hwnd
);
2890 TOOLBAR_AutoSize (hwnd
);
2892 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
2894 InvalidateRect(hwnd
, NULL
, TRUE
);
2901 TOOLBAR_AddStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2903 #define MAX_RESOURCE_STRING_LENGTH 512
2904 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2905 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2906 INT nIndex
= infoPtr
->nNumStrings
;
2908 if ((wParam
) && (HIWORD(lParam
) == 0)) {
2909 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2914 TRACE("adding string from resource!\n");
2916 len
= LoadStringW ((HINSTANCE
)wParam
, (UINT
)lParam
,
2917 szString
, MAX_RESOURCE_STRING_LENGTH
);
2919 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2920 if (len
== 0 || len
== 1)
2923 TRACE("Delimiter: 0x%x\n", *szString
);
2924 delimiter
= *szString
;
2927 while ((next_delim
= strchrW(p
, delimiter
)) != NULL
) {
2929 if (next_delim
+ 1 >= szString
+ len
)
2931 /* this may happen if delimiter == '\0' or if the last char is a
2932 * delimiter (then it is ignored like the native does) */
2936 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2937 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2938 infoPtr
->nNumStrings
++;
2944 LPWSTR p
= (LPWSTR
)lParam
;
2949 TRACE("adding string(s) from array!\n");
2953 TRACE("len=%d %s\n", len
, debugstr_w(p
));
2954 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2955 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2956 infoPtr
->nNumStrings
++;
2963 TOOLBAR_CalcToolbar(hwnd
);
2969 TOOLBAR_AddStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2971 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2972 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2977 if ((wParam
) && (HIWORD(lParam
) == 0)) /* load from resources */
2978 return TOOLBAR_AddStringW(hwnd
, wParam
, lParam
);
2984 TRACE("adding string(s) from array!\n");
2985 nIndex
= infoPtr
->nNumStrings
;
2988 TRACE("len=%d \"%s\"\n", len
, p
);
2990 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2991 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2992 infoPtr
->nNumStrings
++;
2998 TOOLBAR_CalcToolbar(hwnd
);
3004 TOOLBAR_AutoSize (HWND hwnd
)
3006 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3012 TRACE("auto sizing, style=%x!\n", infoPtr
->dwStyle
);
3014 parent
= GetParent (hwnd
);
3016 if (!parent
|| !infoPtr
->bDoRedraw
)
3019 GetClientRect(parent
, &parent_rect
);
3021 x
= parent_rect
.left
;
3022 y
= parent_rect
.top
;
3024 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3026 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3027 cx
= parent_rect
.right
- parent_rect
.left
;
3029 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
))
3031 TOOLBAR_LayoutToolbar(hwnd
);
3032 InvalidateRect( hwnd
, NULL
, TRUE
);
3035 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3038 UINT uPosFlags
= SWP_NOZORDER
;
3040 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3042 GetWindowRect(hwnd
, &window_rect
);
3043 ScreenToClient(parent
, (LPPOINT
)&window_rect
.left
);
3044 y
= window_rect
.top
;
3046 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3048 GetWindowRect(hwnd
, &window_rect
);
3049 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3052 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3053 uPosFlags
|= SWP_NOMOVE
;
3055 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3056 cy
+= GetSystemMetrics(SM_CYEDGE
);
3058 if (infoPtr
->dwStyle
& WS_BORDER
)
3060 x
= y
= 1; /* FIXME: this looks wrong */
3061 cy
+= GetSystemMetrics(SM_CYEDGE
);
3062 cx
+= GetSystemMetrics(SM_CXEDGE
);
3065 SetWindowPos(hwnd
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3073 TOOLBAR_ButtonCount (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3075 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3077 return infoPtr
->nNumButtons
;
3082 TOOLBAR_ButtonStructSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3084 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3086 infoPtr
->dwStructSize
= (DWORD
)wParam
;
3093 TOOLBAR_ChangeBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3095 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3096 TBUTTON_INFO
*btnPtr
;
3099 TRACE("button %ld, iBitmap now %d\n", wParam
, LOWORD(lParam
));
3101 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3105 btnPtr
= &infoPtr
->buttons
[nIndex
];
3106 btnPtr
->iBitmap
= LOWORD(lParam
);
3108 /* we HAVE to erase the background, the new bitmap could be */
3110 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3117 TOOLBAR_CheckButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3119 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3120 TBUTTON_INFO
*btnPtr
;
3123 BOOL bChecked
= FALSE
;
3125 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3127 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd
, nIndex
, lParam
);
3132 btnPtr
= &infoPtr
->buttons
[nIndex
];
3134 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? TRUE
: FALSE
;
3136 if (LOWORD(lParam
) == FALSE
)
3137 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3139 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3141 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3142 if (nOldIndex
== nIndex
)
3144 if (nOldIndex
!= -1)
3145 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3147 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3150 if( bChecked
!= LOWORD(lParam
) )
3152 if (nOldIndex
!= -1)
3153 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3154 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3157 /* FIXME: Send a WM_NOTIFY?? */
3164 TOOLBAR_CommandToIndex (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3166 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3168 return TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3173 TOOLBAR_Customize (HWND hwnd
)
3175 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3176 CUSTDLG_INFO custInfo
;
3182 custInfo
.tbInfo
= infoPtr
;
3183 custInfo
.tbHwnd
= hwnd
;
3185 /* send TBN_BEGINADJUST notification */
3186 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3188 if (!(hRes
= FindResourceW (COMCTL32_hModule
,
3189 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3190 (LPWSTR
)RT_DIALOG
)))
3193 if(!(template = (LPVOID
)LoadResource (COMCTL32_hModule
, hRes
)))
3196 ret
= DialogBoxIndirectParamW ((HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
),
3197 (LPCDLGTEMPLATEW
)template,
3199 TOOLBAR_CustomizeDialogProc
,
3202 /* send TBN_ENDADJUST notification */
3203 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3210 TOOLBAR_DeleteButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3212 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3213 INT nIndex
= (INT
)wParam
;
3215 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3217 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3220 memset(&nmtb
, 0, sizeof(nmtb
));
3221 nmtb
.iItem
= btnPtr
->idCommand
;
3222 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3223 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3224 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3225 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3226 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3227 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3228 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3230 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3232 if (infoPtr
->nNumButtons
== 1) {
3233 TRACE(" simple delete!\n");
3234 Free (infoPtr
->buttons
);
3235 infoPtr
->buttons
= NULL
;
3236 infoPtr
->nNumButtons
= 0;
3239 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3240 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3242 infoPtr
->nNumButtons
--;
3243 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3245 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3246 nIndex
* sizeof(TBUTTON_INFO
));
3249 if (nIndex
< infoPtr
->nNumButtons
) {
3250 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3251 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3257 TOOLBAR_LayoutToolbar(hwnd
);
3259 InvalidateRect (hwnd
, NULL
, TRUE
);
3266 TOOLBAR_EnableButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3268 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3269 TBUTTON_INFO
*btnPtr
;
3273 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3275 TRACE("hwnd=%p, btn index=%ld, lParam=0x%08lx\n", hwnd
, wParam
, lParam
);
3280 btnPtr
= &infoPtr
->buttons
[nIndex
];
3282 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3284 /* update the toolbar button state */
3285 if(LOWORD(lParam
) == FALSE
) {
3286 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3288 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3291 /* redraw the button only if the state of the button changed */
3292 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3293 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3299 static inline LRESULT
3300 TOOLBAR_GetAnchorHighlight (HWND hwnd
)
3302 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3304 return infoPtr
->bAnchor
;
3309 TOOLBAR_GetBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3311 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3314 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3318 return infoPtr
->buttons
[nIndex
].iBitmap
;
3322 static inline LRESULT
3323 TOOLBAR_GetBitmapFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3325 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3330 TOOLBAR_GetButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3332 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3333 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3334 INT nIndex
= (INT
)wParam
;
3335 TBUTTON_INFO
*btnPtr
;
3340 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3343 btnPtr
= &infoPtr
->buttons
[nIndex
];
3344 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3345 lpTbb
->idCommand
= btnPtr
->idCommand
;
3346 lpTbb
->fsState
= btnPtr
->fsState
;
3347 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3348 lpTbb
->bReserved
[0] = 0;
3349 lpTbb
->bReserved
[1] = 0;
3350 lpTbb
->dwData
= btnPtr
->dwData
;
3351 lpTbb
->iString
= btnPtr
->iString
;
3358 TOOLBAR_GetButtonInfoT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL bUnicode
)
3360 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3361 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3362 LPTBBUTTONINFOW lpTbInfo
= (LPTBBUTTONINFOW
)lParam
;
3363 TBUTTON_INFO
*btnPtr
;
3366 if (lpTbInfo
== NULL
)
3369 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3370 * the headers and tests shows that even with comctl 6 Vista accepts only the
3371 * original TBBUTTONINFO size
3373 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3375 WARN("Invalid button size\n");
3379 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
3380 lpTbInfo
->dwMask
& 0x80000000);
3384 if (!(btnPtr
= &infoPtr
->buttons
[nIndex
])) return -1;
3386 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3387 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3388 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3389 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3390 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3391 lpTbInfo
->lParam
= btnPtr
->dwData
;
3392 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3393 lpTbInfo
->cx
= (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3394 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3395 lpTbInfo
->fsState
= btnPtr
->fsState
;
3396 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3397 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3398 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3399 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3400 can't use TOOLBAR_GetText here */
3401 if (HIWORD(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3402 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3404 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3406 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3408 lpTbInfo
->pszText
[0] = '\0';
3415 TOOLBAR_GetButtonSize (HWND hwnd
)
3417 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3419 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3420 (WORD
)infoPtr
->nButtonHeight
);
3425 TOOLBAR_GetButtonTextA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3427 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3434 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3438 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3440 return WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3441 (LPSTR
)lParam
, 0x7fffffff, NULL
, NULL
) - 1;
3446 TOOLBAR_GetButtonTextW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3448 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3453 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3457 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3461 ret
= strlenW (lpText
);
3464 strcpyW ((LPWSTR
)lParam
, lpText
);
3472 TOOLBAR_GetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3474 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3475 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3476 return (LRESULT
)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3480 static inline LRESULT
3481 TOOLBAR_GetExtendedStyle (HWND hwnd
)
3483 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3487 return infoPtr
->dwExStyle
;
3492 TOOLBAR_GetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3494 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3495 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3496 return (LRESULT
)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3501 TOOLBAR_GetHotItem (HWND hwnd
)
3503 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3505 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3508 if (infoPtr
->nHotItem
< 0)
3511 return (LRESULT
)infoPtr
->nHotItem
;
3516 TOOLBAR_GetDefImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3518 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3519 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3520 return (LRESULT
) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd
), wParam
);
3525 TOOLBAR_GetInsertMark (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3527 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3528 TBINSERTMARK
*lptbim
= (TBINSERTMARK
*)lParam
;
3530 TRACE("hwnd = %p, lptbim = %p\n", hwnd
, lptbim
);
3532 *lptbim
= infoPtr
->tbim
;
3539 TOOLBAR_GetInsertMarkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3541 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3543 TRACE("hwnd = %p\n", hwnd
);
3545 return (LRESULT
)infoPtr
->clrInsertMark
;
3550 TOOLBAR_GetItemRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3552 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3553 TBUTTON_INFO
*btnPtr
;
3557 nIndex
= (INT
)wParam
;
3558 btnPtr
= &infoPtr
->buttons
[nIndex
];
3559 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3561 lpRect
= (LPRECT
)lParam
;
3564 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3567 lpRect
->left
= btnPtr
->rect
.left
;
3568 lpRect
->right
= btnPtr
->rect
.right
;
3569 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3570 lpRect
->top
= btnPtr
->rect
.top
;
3577 TOOLBAR_GetMaxSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3579 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3580 LPSIZE lpSize
= (LPSIZE
)lParam
;
3585 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3586 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3588 TRACE("maximum size %d x %d\n",
3589 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3590 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3596 /* << TOOLBAR_GetObject >> */
3600 TOOLBAR_GetPadding (HWND hwnd
)
3602 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3605 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3606 return (LRESULT
) oldPad
;
3611 TOOLBAR_GetRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3613 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3614 TBUTTON_INFO
*btnPtr
;
3618 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3619 btnPtr
= &infoPtr
->buttons
[nIndex
];
3620 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3622 lpRect
= (LPRECT
)lParam
;
3626 lpRect
->left
= btnPtr
->rect
.left
;
3627 lpRect
->right
= btnPtr
->rect
.right
;
3628 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3629 lpRect
->top
= btnPtr
->rect
.top
;
3636 TOOLBAR_GetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3638 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3640 if (infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
)
3641 return infoPtr
->nRows
;
3648 TOOLBAR_GetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3650 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3653 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3657 return infoPtr
->buttons
[nIndex
].fsState
;
3662 TOOLBAR_GetStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3664 return GetWindowLongW(hwnd
, GWL_STYLE
);
3669 TOOLBAR_GetTextRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3671 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3673 return infoPtr
->nMaxTextRows
;
3678 TOOLBAR_GetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3680 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3682 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3683 TOOLBAR_TooltipCreateControl(infoPtr
);
3684 return (LRESULT
)infoPtr
->hwndToolTip
;
3689 TOOLBAR_GetUnicodeFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3691 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3693 TRACE("%s hwnd=%p\n",
3694 infoPtr
->bUnicode
? "TRUE" : "FALSE", hwnd
);
3696 return infoPtr
->bUnicode
;
3700 static inline LRESULT
3701 TOOLBAR_GetVersion (HWND hwnd
)
3703 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3704 return infoPtr
->iVersion
;
3709 TOOLBAR_HideButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3711 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3712 TBUTTON_INFO
*btnPtr
;
3717 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3721 btnPtr
= &infoPtr
->buttons
[nIndex
];
3722 if (LOWORD(lParam
) == FALSE
)
3723 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3725 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3727 TOOLBAR_LayoutToolbar (hwnd
);
3729 InvalidateRect (hwnd
, NULL
, TRUE
);
3735 static inline LRESULT
3736 TOOLBAR_HitTest (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3738 return TOOLBAR_InternalHitTest (hwnd
, (LPPOINT
)lParam
);
3743 TOOLBAR_Indeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3745 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3746 TBUTTON_INFO
*btnPtr
;
3750 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3754 btnPtr
= &infoPtr
->buttons
[nIndex
];
3755 oldState
= btnPtr
->fsState
;
3756 if (LOWORD(lParam
) == FALSE
)
3757 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3759 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3761 if(oldState
!= btnPtr
->fsState
)
3762 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3769 TOOLBAR_InsertButtonT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL fUnicode
)
3771 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3772 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3773 INT nIndex
= (INT
)wParam
;
3778 TOOLBAR_DumpButton(infoPtr
, (TBUTTON_INFO
*)lpTbb
, nIndex
, FALSE
);
3781 /* EPP: this seems to be an undocumented call (from my IE4)
3782 * I assume in that case that:
3783 * - index of insertion is at the end of existing buttons
3784 * I only see this happen with nIndex == -1, but it could have a special
3785 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3787 nIndex
= infoPtr
->nNumButtons
;
3789 } else if (nIndex
< 0)
3792 TRACE("inserting button index=%d\n", nIndex
);
3793 if (nIndex
> infoPtr
->nNumButtons
) {
3794 nIndex
= infoPtr
->nNumButtons
;
3795 TRACE("adjust index=%d\n", nIndex
);
3798 infoPtr
->nNumButtons
++;
3799 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3800 memmove(&infoPtr
->buttons
[nIndex
+1], &infoPtr
->buttons
[nIndex
],
3801 (infoPtr
->nNumButtons
- nIndex
- 1) * sizeof(TBUTTON_INFO
));
3803 /* insert new button */
3804 infoPtr
->buttons
[nIndex
].iBitmap
= lpTbb
->iBitmap
;
3805 infoPtr
->buttons
[nIndex
].idCommand
= lpTbb
->idCommand
;
3806 infoPtr
->buttons
[nIndex
].fsState
= lpTbb
->fsState
;
3807 infoPtr
->buttons
[nIndex
].fsStyle
= lpTbb
->fsStyle
;
3808 infoPtr
->buttons
[nIndex
].dwData
= lpTbb
->dwData
;
3809 /* if passed string and not index, then add string */
3810 if(HIWORD(lpTbb
->iString
) && lpTbb
->iString
!=-1) {
3812 Str_SetPtrW((LPWSTR
*)&infoPtr
->buttons
[nIndex
].iString
, (LPWSTR
)lpTbb
->iString
);
3814 Str_SetPtrAtoW((LPWSTR
*)&infoPtr
->buttons
[nIndex
].iString
, (LPCSTR
)lpTbb
->iString
);
3817 infoPtr
->buttons
[nIndex
].iString
= lpTbb
->iString
;
3819 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3821 if (infoPtr
->nNumStrings
> 0)
3822 TOOLBAR_CalcToolbar(hwnd
);
3824 TOOLBAR_LayoutToolbar(hwnd
);
3825 TOOLBAR_AutoSize (hwnd
);
3827 InvalidateRect (hwnd
, NULL
, TRUE
);
3832 /* << TOOLBAR_InsertMarkHitTest >> */
3836 TOOLBAR_IsButtonChecked (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3838 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3841 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3845 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3850 TOOLBAR_IsButtonEnabled (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3852 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3855 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3859 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3864 TOOLBAR_IsButtonHidden (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3866 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3869 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3873 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3878 TOOLBAR_IsButtonHighlighted (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3880 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3883 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3887 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3892 TOOLBAR_IsButtonIndeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3894 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3897 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3901 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3906 TOOLBAR_IsButtonPressed (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3908 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3911 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3915 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3920 TOOLBAR_LoadImages (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3923 tbab
.hInst
= (HINSTANCE
)lParam
;
3924 tbab
.nID
= (UINT_PTR
)wParam
;
3926 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", hwnd
, tbab
.hInst
, tbab
.nID
);
3928 return TOOLBAR_AddBitmap(hwnd
, 0, (LPARAM
)&tbab
);
3933 TOOLBAR_MapAccelerator (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3935 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3936 WCHAR wAccel
= (WCHAR
)wParam
;
3937 UINT
* pIDButton
= (UINT
*)lParam
;
3938 WCHAR wszAccel
[] = {'&',wAccel
,0};
3941 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3942 hwnd
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3944 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3946 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3947 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3948 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3950 int iLen
= strlenW(wszAccel
);
3951 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3958 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3963 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
3965 *pIDButton
= btnPtr
->idCommand
;
3977 TOOLBAR_MarkButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3979 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3982 TBUTTON_INFO
*btnPtr
;
3984 TRACE("hwnd = %p, wParam = %ld, lParam = 0x%08lx\n", hwnd
, wParam
, lParam
);
3986 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3990 btnPtr
= &infoPtr
->buttons
[nIndex
];
3991 oldState
= btnPtr
->fsState
;
3994 btnPtr
->fsState
|= TBSTATE_MARKED
;
3996 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
3998 if(oldState
!= btnPtr
->fsState
)
3999 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4005 /* fixes up an index of a button affected by a move */
4006 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
4010 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
4012 else if (*pIndex
== nIndex
)
4013 *pIndex
= nMoveIndex
;
4017 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
4019 else if (*pIndex
== nIndex
)
4020 *pIndex
= nMoveIndex
;
4026 TOOLBAR_MoveButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4028 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4031 INT nMoveIndex
= (INT
)lParam
;
4032 TBUTTON_INFO button
;
4034 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd
, wParam
, lParam
);
4036 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, TRUE
);
4037 if ((nIndex
== -1) || (nMoveIndex
< 0))
4040 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
4041 nMoveIndex
= infoPtr
->nNumButtons
- 1;
4043 button
= infoPtr
->buttons
[nIndex
];
4045 /* move button right */
4046 if (nIndex
< nMoveIndex
)
4048 nCount
= nMoveIndex
- nIndex
;
4049 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
4050 infoPtr
->buttons
[nMoveIndex
] = button
;
4052 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
4053 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
4054 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
4055 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
4057 else if (nIndex
> nMoveIndex
) /* move button left */
4059 nCount
= nIndex
- nMoveIndex
;
4060 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
4061 infoPtr
->buttons
[nMoveIndex
] = button
;
4063 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
4064 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
4065 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
4066 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
4069 TOOLBAR_LayoutToolbar(hwnd
);
4070 TOOLBAR_AutoSize(hwnd
);
4071 InvalidateRect(hwnd
, NULL
, TRUE
);
4078 TOOLBAR_PressButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4080 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4081 TBUTTON_INFO
*btnPtr
;
4085 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4089 btnPtr
= &infoPtr
->buttons
[nIndex
];
4090 oldState
= btnPtr
->fsState
;
4091 if (LOWORD(lParam
) == FALSE
)
4092 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
4094 btnPtr
->fsState
|= TBSTATE_PRESSED
;
4096 if(oldState
!= btnPtr
->fsState
)
4097 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4102 /* FIXME: there might still be some confusion her between number of buttons
4103 * and number of bitmaps */
4105 TOOLBAR_ReplaceBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4107 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4108 LPTBREPLACEBITMAP lpReplace
= (LPTBREPLACEBITMAP
) lParam
;
4110 int i
= 0, nOldButtons
= 0, pos
= 0;
4111 int nOldBitmaps
, nNewBitmaps
= 0;
4112 HIMAGELIST himlDef
= 0;
4114 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4115 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
4116 lpReplace
->nButtons
);
4118 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4120 FIXME("changing standard bitmaps not implemented\n");
4123 else if (lpReplace
->hInstOld
!= 0)
4124 FIXME("resources not in the current module not implemented\n");
4126 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4127 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4128 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4129 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4130 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4132 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4133 nOldButtons
= tbi
->nButtons
;
4134 tbi
->nButtons
= lpReplace
->nButtons
;
4135 tbi
->hInst
= lpReplace
->hInstNew
;
4136 tbi
->nID
= lpReplace
->nIDNew
;
4137 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4140 pos
+= tbi
->nButtons
;
4143 if (nOldButtons
== 0)
4145 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4149 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4152 if (lpReplace
->hInstNew
)
4153 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4155 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4157 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4158 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4160 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4162 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4163 ImageList_Remove(himlDef
, i
);
4167 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4168 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4169 DeleteObject(hBitmap
);
4172 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4174 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4175 pos
, nOldBitmaps
, nNewBitmaps
);
4177 InvalidateRect(hwnd
, NULL
, TRUE
);
4182 /* helper for TOOLBAR_SaveRestoreW */
4184 TOOLBAR_Save(const TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4186 FIXME("save to %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4187 debugstr_w(lpSave
->pszValueName
));
4193 /* helper for TOOLBAR_Restore */
4195 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4199 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4201 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4204 Free(infoPtr
->buttons
);
4205 infoPtr
->buttons
= NULL
;
4206 infoPtr
->nNumButtons
= 0;
4210 /* helper for TOOLBAR_SaveRestoreW */
4212 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4221 /* restore toolbar information */
4222 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4223 debugstr_w(lpSave
->pszValueName
));
4225 memset(&nmtbr
, 0, sizeof(nmtbr
));
4227 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4228 KEY_QUERY_VALUE
, &hkey
);
4230 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4232 if (!res
&& dwType
!= REG_BINARY
)
4233 res
= ERROR_FILE_NOT_FOUND
;
4236 nmtbr
.pData
= Alloc(dwSize
);
4237 nmtbr
.cbData
= (UINT
)dwSize
;
4238 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4241 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4242 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4245 nmtbr
.pCurrent
= nmtbr
.pData
;
4247 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4248 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4250 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4254 /* remove all existing buttons as this function is designed to
4255 * restore the toolbar to a previously saved state */
4256 TOOLBAR_DeleteAllButtons(infoPtr
);
4258 for (i
= 0; i
< nmtbr
.cButtons
; i
++)
4261 nmtbr
.tbButton
.iBitmap
= -1;
4262 nmtbr
.tbButton
.fsState
= 0;
4263 nmtbr
.tbButton
.fsStyle
= 0;
4264 nmtbr
.tbButton
.idCommand
= 0;
4265 if (*nmtbr
.pCurrent
== (DWORD
)-1)
4268 nmtbr
.tbButton
.fsStyle
= TBSTYLE_SEP
;
4269 nmtbr
.tbButton
.iBitmap
= SEPARATOR_WIDTH
;
4271 else if (*nmtbr
.pCurrent
== (DWORD
)-2)
4273 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4275 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4279 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4281 /* can't contain real string as we don't know whether
4282 * the client put an ANSI or Unicode string in there */
4283 if (HIWORD(nmtbr
.tbButton
.iString
))
4284 nmtbr
.tbButton
.iString
= 0;
4286 TOOLBAR_InsertButtonT(infoPtr
->hwndSelf
, -1,
4287 (LPARAM
)&nmtbr
.tbButton
, TRUE
);
4290 /* do legacy notifications */
4291 if (infoPtr
->iVersion
< 5)
4293 /* FIXME: send TBN_BEGINADJUST */
4294 FIXME("send TBN_GETBUTTONINFO for each button\n");
4295 /* FIXME: send TBN_ENDADJUST */
4298 /* remove all uninitialised buttons
4299 * note: loop backwards to avoid having to fixup i on a
4301 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4302 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4303 TOOLBAR_DeleteButton(infoPtr
->hwndSelf
, i
, 0);
4305 /* only indicate success if at least one button survived */
4306 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4317 TOOLBAR_SaveRestoreW (HWND hwnd
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4319 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4321 if (lpSave
== NULL
) return 0;
4324 return TOOLBAR_Save(infoPtr
, lpSave
);
4326 return TOOLBAR_Restore(infoPtr
, lpSave
);
4331 TOOLBAR_SaveRestoreA (HWND hwnd
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4333 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4334 TBSAVEPARAMSW SaveW
;
4338 if (lpSave
== NULL
) return 0;
4340 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4341 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4342 if (pszSubKey
) goto exit
;
4343 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4345 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4346 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4347 if (!pszValueName
) goto exit
;
4348 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4350 SaveW
.pszValueName
= pszValueName
;
4351 SaveW
.pszSubKey
= pszSubKey
;
4352 SaveW
.hkr
= lpSave
->hkr
;
4353 result
= TOOLBAR_SaveRestoreW(hwnd
, wParam
, &SaveW
);
4356 Free (pszValueName
);
4364 TOOLBAR_SetAnchorHighlight (HWND hwnd
, WPARAM wParam
)
4366 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4367 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4369 TRACE("hwnd=%p, bAnchor = %s\n", hwnd
, wParam
? "TRUE" : "FALSE");
4371 infoPtr
->bAnchor
= (BOOL
)wParam
;
4373 /* Native does not remove the hot effect from an already hot button */
4375 return (LRESULT
)bOldAnchor
;
4380 TOOLBAR_SetBitmapSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4382 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4383 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4385 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd
, wParam
, lParam
);
4388 FIXME("wParam is %ld. Perhaps image list index?\n", wParam
);
4390 if (LOWORD(lParam
) == 0)
4391 lParam
= MAKELPARAM(1, HIWORD(lParam
));
4393 if (HIWORD(lParam
)==0)
4394 lParam
= MAKELPARAM(LOWORD(lParam
), 1);
4396 if (infoPtr
->nNumButtons
> 0)
4397 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4398 infoPtr
->nNumButtons
,
4399 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
4400 LOWORD(lParam
), HIWORD(lParam
));
4402 infoPtr
->nBitmapWidth
= (INT
)LOWORD(lParam
);
4403 infoPtr
->nBitmapHeight
= (INT
)HIWORD(lParam
);
4405 if ((himlDef
== infoPtr
->himlInt
) &&
4406 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4408 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4409 infoPtr
->nBitmapHeight
);
4412 TOOLBAR_CalcToolbar(hwnd
);
4413 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4419 TOOLBAR_SetButtonInfoA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4421 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4422 LPTBBUTTONINFOA lptbbi
= (LPTBBUTTONINFOA
)lParam
;
4423 TBUTTON_INFO
*btnPtr
;
4429 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOA
))
4432 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4433 lptbbi
->dwMask
& 0x80000000);
4437 btnPtr
= &infoPtr
->buttons
[nIndex
];
4438 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4439 btnPtr
->idCommand
= lptbbi
->idCommand
;
4440 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4441 btnPtr
->iBitmap
= lptbbi
->iImage
;
4442 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4443 btnPtr
->dwData
= lptbbi
->lParam
;
4444 if (lptbbi
->dwMask
& TBIF_SIZE
)
4445 btnPtr
->cx
= lptbbi
->cx
;
4446 if (lptbbi
->dwMask
& TBIF_STATE
)
4447 btnPtr
->fsState
= lptbbi
->fsState
;
4448 if (lptbbi
->dwMask
& TBIF_STYLE
)
4449 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4451 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4452 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4453 /* iString is index, zero it to make Str_SetPtr succeed */
4456 Str_SetPtrAtoW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4459 /* save the button rect to see if we need to redraw the whole toolbar */
4460 oldBtnRect
= btnPtr
->rect
;
4461 TOOLBAR_CalcToolbar(hwnd
);
4463 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4464 InvalidateRect(hwnd
, NULL
, TRUE
);
4466 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4473 TOOLBAR_SetButtonInfoW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4475 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4476 LPTBBUTTONINFOW lptbbi
= (LPTBBUTTONINFOW
)lParam
;
4477 TBUTTON_INFO
*btnPtr
;
4483 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4486 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4487 lptbbi
->dwMask
& 0x80000000);
4491 btnPtr
= &infoPtr
->buttons
[nIndex
];
4492 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4493 btnPtr
->idCommand
= lptbbi
->idCommand
;
4494 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4495 btnPtr
->iBitmap
= lptbbi
->iImage
;
4496 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4497 btnPtr
->dwData
= lptbbi
->lParam
;
4498 if (lptbbi
->dwMask
& TBIF_SIZE
)
4499 btnPtr
->cx
= lptbbi
->cx
;
4500 if (lptbbi
->dwMask
& TBIF_STATE
)
4501 btnPtr
->fsState
= lptbbi
->fsState
;
4502 if (lptbbi
->dwMask
& TBIF_STYLE
)
4503 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4505 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4506 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4507 /* iString is index, zero it to make Str_SetPtr succeed */
4509 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4512 /* save the button rect to see if we need to redraw the whole toolbar */
4513 oldBtnRect
= btnPtr
->rect
;
4514 TOOLBAR_CalcToolbar(hwnd
);
4516 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4517 InvalidateRect(hwnd
, NULL
, TRUE
);
4519 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4526 TOOLBAR_SetButtonSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4528 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4529 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4531 if ((cx
< 0) || (cy
< 0))
4533 ERR("invalid parameter 0x%08x\n", (DWORD
)lParam
);
4537 TRACE("%p, cx = %d, cy = %d\n", hwnd
, cx
, cy
);
4539 /* The documentation claims you can only change the button size before
4540 * any button has been added. But this is wrong.
4541 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4542 * it to the toolbar, and it checks that the return value is nonzero - mjm
4543 * Further testing shows that we must actually perform the change too.
4546 * The documentation also does not mention that if 0 is supplied for
4547 * either size, the system changes it to the default of 24 wide and
4548 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4550 if (cx
== 0) cx
= 24;
4551 if (cy
== 0) cx
= 22;
4553 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4554 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4556 infoPtr
->nButtonWidth
= cx
;
4557 infoPtr
->nButtonHeight
= cy
;
4559 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
4560 TOOLBAR_LayoutToolbar(hwnd
);
4566 TOOLBAR_SetButtonWidth (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4568 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4570 /* if setting to current values, ignore */
4571 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4572 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4573 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4574 infoPtr
->cxMin
, infoPtr
->cxMax
);
4578 /* save new values */
4579 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4580 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4582 /* otherwise we need to recalc the toolbar and in some cases
4583 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4584 which doesn't actually draw - GA). */
4585 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4586 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4588 TOOLBAR_CalcToolbar (hwnd
);
4590 InvalidateRect (hwnd
, NULL
, TRUE
);
4597 TOOLBAR_SetCmdId (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4599 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4600 INT nIndex
= (INT
)wParam
;
4602 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4605 infoPtr
->buttons
[nIndex
].idCommand
= (INT
)lParam
;
4607 if (infoPtr
->hwndToolTip
) {
4609 FIXME("change tool tip!\n");
4618 TOOLBAR_SetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4620 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4621 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4622 HIMAGELIST himlTemp
;
4625 if (infoPtr
->iVersion
>= 5)
4628 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4629 &infoPtr
->cimlDis
, himl
, id
);
4631 /* FIXME: redraw ? */
4633 return (LRESULT
)himlTemp
;
4638 TOOLBAR_SetDrawTextFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4640 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4643 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd
, (DWORD
)wParam
, (DWORD
)lParam
);
4645 dwTemp
= infoPtr
->dwDTFlags
;
4646 infoPtr
->dwDTFlags
=
4647 (infoPtr
->dwDTFlags
& (DWORD
)wParam
) | (DWORD
)lParam
;
4649 return (LRESULT
)dwTemp
;
4652 /* This function differs a bit from what MSDN says it does:
4653 * 1. lParam contains extended style flags to OR with current style
4654 * (MSDN isn't clear on the OR bit)
4655 * 2. wParam appears to contain extended style flags to be reset
4656 * (MSDN says that this parameter is reserved)
4659 TOOLBAR_SetExtendedStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4661 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4664 dwTemp
= infoPtr
->dwExStyle
;
4665 infoPtr
->dwExStyle
&= ~wParam
;
4666 infoPtr
->dwExStyle
|= (DWORD
)lParam
;
4668 TRACE("new style 0x%08x\n", infoPtr
->dwExStyle
);
4670 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4671 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4672 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4674 TOOLBAR_CalcToolbar (hwnd
);
4676 TOOLBAR_AutoSize(hwnd
);
4678 InvalidateRect(hwnd
, NULL
, TRUE
);
4680 return (LRESULT
)dwTemp
;
4685 TOOLBAR_SetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4687 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4688 HIMAGELIST himlTemp
;
4689 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4692 if (infoPtr
->iVersion
>= 5)
4695 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd
, himl
, id
);
4697 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4698 &infoPtr
->cimlHot
, himl
, id
);
4700 /* FIXME: redraw ? */
4702 return (LRESULT
)himlTemp
;
4706 /* Makes previous hot button no longer hot, makes the specified
4707 * button hot and sends appropriate notifications. dwReason is one or
4708 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4709 * NOTE 1: this function does not validate nHit
4710 * NOTE 2: the name of this function is completely made up and
4711 * not based on any documentation from Microsoft. */
4713 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4715 if (infoPtr
->nHotItem
!= nHit
)
4717 NMTBHOTITEM nmhotitem
;
4718 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4720 nmhotitem
.dwFlags
= dwReason
;
4721 if(infoPtr
->nHotItem
>= 0)
4723 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4724 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4728 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4729 nmhotitem
.idOld
= 0;
4734 btnPtr
= &infoPtr
->buttons
[nHit
];
4735 nmhotitem
.idNew
= btnPtr
->idCommand
;
4739 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4740 nmhotitem
.idNew
= 0;
4743 /* now change the hot and invalidate the old and new buttons - if the
4745 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4748 oldBtnPtr
->bHot
= FALSE
;
4749 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4751 /* setting disabled buttons as hot fails even if the notify contains the button id */
4752 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4753 btnPtr
->bHot
= TRUE
;
4754 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4755 infoPtr
->nHotItem
= nHit
;
4758 infoPtr
->nHotItem
= -1;
4764 TOOLBAR_SetHotItem (HWND hwnd
, WPARAM wParam
)
4766 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4767 INT nOldHotItem
= infoPtr
->nHotItem
;
4769 TRACE("hwnd = %p, nHit = %d\n", hwnd
, (INT
)wParam
);
4771 if ((INT
)wParam
> infoPtr
->nNumButtons
)
4772 return infoPtr
->nHotItem
;
4774 if ((INT
)wParam
< 0)
4777 /* NOTE: an application can still remove the hot item even if anchor
4778 * highlighting is enabled */
4780 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, HICF_OTHER
);
4782 if (nOldHotItem
< 0)
4785 return (LRESULT
)nOldHotItem
;
4790 TOOLBAR_SetImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4792 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4793 HIMAGELIST himlTemp
;
4794 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4795 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4798 if (infoPtr
->iVersion
>= 5)
4801 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4802 &infoPtr
->cimlDef
, himl
, id
);
4804 infoPtr
->nNumBitmaps
= 0;
4805 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4806 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4808 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4809 &infoPtr
->nBitmapHeight
))
4811 infoPtr
->nBitmapWidth
= 1;
4812 infoPtr
->nBitmapHeight
= 1;
4814 TOOLBAR_CalcToolbar(hwnd
);
4815 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4816 TOOLBAR_SetButtonSize(hwnd
, 0, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4818 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4819 hwnd
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4820 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4822 InvalidateRect(hwnd
, NULL
, TRUE
);
4824 return (LRESULT
)himlTemp
;
4829 TOOLBAR_SetIndent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4831 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4833 infoPtr
->nIndent
= (INT
)wParam
;
4837 /* process only on indent changing */
4838 if(infoPtr
->nIndent
!= (INT
)wParam
)
4840 infoPtr
->nIndent
= (INT
)wParam
;
4841 TOOLBAR_CalcToolbar (hwnd
);
4842 InvalidateRect(hwnd
, NULL
, FALSE
);
4850 TOOLBAR_SetInsertMark (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4852 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4853 TBINSERTMARK
*lptbim
= (TBINSERTMARK
*)lParam
;
4855 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd
, lptbim
->iButton
, lptbim
->dwFlags
);
4857 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4859 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4863 if ((lptbim
->iButton
== -1) ||
4864 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4865 (lptbim
->iButton
>= 0)))
4867 infoPtr
->tbim
= *lptbim
;
4868 /* FIXME: don't need to update entire toolbar */
4869 InvalidateRect(hwnd
, NULL
, TRUE
);
4872 ERR("Invalid button index %d\n", lptbim
->iButton
);
4879 TOOLBAR_SetInsertMarkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4881 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4883 infoPtr
->clrInsertMark
= (COLORREF
)lParam
;
4885 /* FIXME: don't need to update entire toolbar */
4886 InvalidateRect(hwnd
, NULL
, TRUE
);
4893 TOOLBAR_SetMaxTextRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4895 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4897 infoPtr
->nMaxTextRows
= (INT
)wParam
;
4899 TOOLBAR_CalcToolbar(hwnd
);
4904 /* MSDN gives slightly wrong info on padding.
4905 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4906 * 2. It is not used to create a blank area between the edge of the button
4907 * and the text or image if TBSTYLE_LIST is set. It is used to control
4908 * the gap between the image and text.
4909 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4910 * to control the bottom and right borders [with the border being
4911 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4912 * is shared evenly on both sides of the button.
4913 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4916 TOOLBAR_SetPadding (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4918 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4921 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4922 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4923 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4924 TRACE("cx=%d, cy=%d\n",
4925 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4926 return (LRESULT
) oldPad
;
4931 TOOLBAR_SetParent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4933 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4938 hwndOldNotify
= infoPtr
->hwndNotify
;
4939 infoPtr
->hwndNotify
= (HWND
)wParam
;
4941 return (LRESULT
)hwndOldNotify
;
4946 TOOLBAR_SetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4948 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4949 LPRECT lprc
= (LPRECT
)lParam
;
4953 if (LOWORD(wParam
) > 1) {
4954 FIXME("multiple rows not supported!\n");
4957 if(infoPtr
->nRows
!= LOWORD(wParam
))
4959 infoPtr
->nRows
= LOWORD(wParam
);
4961 /* recalculate toolbar */
4962 TOOLBAR_CalcToolbar (hwnd
);
4964 /* repaint toolbar */
4965 InvalidateRect(hwnd
, NULL
, TRUE
);
4968 /* return bounding rectangle */
4970 lprc
->left
= infoPtr
->rcBound
.left
;
4971 lprc
->right
= infoPtr
->rcBound
.right
;
4972 lprc
->top
= infoPtr
->rcBound
.top
;
4973 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
4981 TOOLBAR_SetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4983 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4984 TBUTTON_INFO
*btnPtr
;
4987 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4991 btnPtr
= &infoPtr
->buttons
[nIndex
];
4993 /* if hidden state has changed the invalidate entire window and recalc */
4994 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
4995 btnPtr
->fsState
= LOWORD(lParam
);
4996 TOOLBAR_CalcToolbar (hwnd
);
4997 InvalidateRect(hwnd
, 0, TRUE
);
5001 /* process state changing if current state doesn't match new state */
5002 if(btnPtr
->fsState
!= LOWORD(lParam
))
5004 btnPtr
->fsState
= LOWORD(lParam
);
5005 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5013 TOOLBAR_SetStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5015 SetWindowLongW(hwnd
, GWL_STYLE
, lParam
);
5021 static inline LRESULT
5022 TOOLBAR_SetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5024 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5026 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd
, (HWND
)wParam
, lParam
);
5028 infoPtr
->hwndToolTip
= (HWND
)wParam
;
5034 TOOLBAR_SetUnicodeFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5036 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5039 TRACE("%s hwnd=%p\n",
5040 ((BOOL
)wParam
) ? "TRUE" : "FALSE", hwnd
);
5042 bTemp
= infoPtr
->bUnicode
;
5043 infoPtr
->bUnicode
= (BOOL
)wParam
;
5050 TOOLBAR_GetColorScheme (HWND hwnd
, LPCOLORSCHEME lParam
)
5052 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5054 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
5055 comctl32_color
.clrBtnHighlight
:
5056 infoPtr
->clrBtnHighlight
;
5057 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
5058 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
5064 TOOLBAR_SetColorScheme (HWND hwnd
, const COLORSCHEME
*lParam
)
5066 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5068 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5069 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
5070 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
5072 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
5073 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
5074 InvalidateRect(hwnd
, NULL
, TRUE
);
5080 TOOLBAR_SetVersion (HWND hwnd
, INT iVersion
)
5082 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5083 INT iOldVersion
= infoPtr
->iVersion
;
5085 infoPtr
->iVersion
= iVersion
;
5087 if (infoPtr
->iVersion
>= 5)
5088 TOOLBAR_SetUnicodeFormat(hwnd
, (WPARAM
)TRUE
, (LPARAM
)0);
5095 TOOLBAR_GetStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5097 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5098 WORD iString
= HIWORD(wParam
);
5099 WORD buffersize
= LOWORD(wParam
);
5100 LPSTR str
= (LPSTR
)lParam
;
5103 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, buffersize
, str
);
5105 if (iString
< infoPtr
->nNumStrings
)
5107 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
5109 TRACE("returning %s\n", debugstr_a(str
));
5112 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5119 TOOLBAR_GetStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5121 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5122 WORD iString
= HIWORD(wParam
);
5123 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5124 LPWSTR str
= (LPWSTR
)lParam
;
5127 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, LOWORD(wParam
), str
);
5129 if (iString
< infoPtr
->nNumStrings
)
5131 len
= min(len
, strlenW(infoPtr
->strings
[iString
]));
5132 ret
= (len
+1)*sizeof(WCHAR
);
5133 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5136 TRACE("returning %s\n", debugstr_w(str
));
5139 ERR("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5144 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5145 * is the maximum size of the toolbar? */
5146 static LRESULT
TOOLBAR_Unkwn45D(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5148 SIZE
* pSize
= (SIZE
*)lParam
;
5149 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5154 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5155 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5156 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5159 TOOLBAR_Unkwn45E (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5161 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5162 INT nOldHotItem
= infoPtr
->nHotItem
;
5164 TRACE("old item=%d, new item=%d, flags=%08x\n",
5165 nOldHotItem
, infoPtr
->nHotItem
, (DWORD
)lParam
);
5167 if ((INT
) wParam
< 0 || (INT
)wParam
> infoPtr
->nNumButtons
)
5170 /* NOTE: an application can still remove the hot item even if anchor
5171 * highlighting is enabled */
5173 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, lParam
);
5177 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5180 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5181 * which controls the amount of spacing between the image and the text
5182 * of buttons for TBSTYLE_LIST toolbars. */
5183 static LRESULT
TOOLBAR_Unkwn460(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5185 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5187 TRACE("hwnd=%p iListGap=%ld\n", hwnd
, wParam
);
5190 FIXME("lParam = 0x%08lx. Please report\n", lParam
);
5192 infoPtr
->iListGap
= (INT
)wParam
;
5194 InvalidateRect(hwnd
, NULL
, TRUE
);
5199 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5200 * of image lists associated with the various states. */
5201 static LRESULT
TOOLBAR_Unkwn462(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5203 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5205 TRACE("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5207 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5211 TOOLBAR_Unkwn463 (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5213 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5214 LPSIZE lpsize
= (LPSIZE
)lParam
;
5220 * Testing shows the following:
5221 * wParam = 0 adjust cx value
5222 * = 1 set cy value to max size.
5223 * lParam pointer to SIZE structure
5226 TRACE("[0463] wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5227 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5231 if (lpsize
->cx
== -1) {
5232 /* **** this is wrong, native measures each button and sets it */
5233 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5235 else if(HIWORD(lpsize
->cx
)) {
5237 HWND hwndParent
= GetParent(hwnd
);
5239 GetWindowRect(hwnd
, &rc
);
5240 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5241 TRACE("mapped to (%d,%d)-(%d,%d)\n",
5242 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5243 lpsize
->cx
= max(rc
.right
-rc
.left
,
5244 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5247 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5251 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5254 ERR("Unknown wParam %ld for Toolbar message [0463]. Please report\n",
5258 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5259 lpsize
->cx
, lpsize
->cy
);
5263 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5265 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5267 InvalidateRect(hwnd
, NULL
, TRUE
);
5273 TOOLBAR_Create (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5275 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5276 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
5279 TRACE("hwnd = %p\n", hwnd
);
5281 /* initialize info structure */
5282 infoPtr
->nButtonWidth
= 23;
5283 infoPtr
->nButtonHeight
= 22;
5284 infoPtr
->nBitmapHeight
= 16;
5285 infoPtr
->nBitmapWidth
= 16;
5287 infoPtr
->nMaxTextRows
= 1;
5288 infoPtr
->cxMin
= -1;
5289 infoPtr
->cxMax
= -1;
5290 infoPtr
->nNumBitmaps
= 0;
5291 infoPtr
->nNumStrings
= 0;
5293 infoPtr
->bCaptured
= FALSE
;
5294 infoPtr
->nButtonDown
= -1;
5295 infoPtr
->nButtonDrag
= -1;
5296 infoPtr
->nOldHit
= -1;
5297 infoPtr
->nHotItem
= -1;
5298 infoPtr
->hwndNotify
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
5299 infoPtr
->dwDTFlags
= (dwStyle
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
5300 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
5301 infoPtr
->bDragOutSent
= FALSE
;
5302 infoPtr
->iVersion
= 0;
5303 infoPtr
->hwndSelf
= hwnd
;
5304 infoPtr
->bDoRedraw
= TRUE
;
5305 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
5306 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
5307 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
5308 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
5309 infoPtr
->iListGap
= DEFLISTGAP
;
5310 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
5311 infoPtr
->dwStyle
= dwStyle
;
5312 infoPtr
->tbim
.iButton
= -1;
5313 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5314 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5315 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, (LPARAM
)NF_REQUERY
));
5316 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5318 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5319 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5321 OpenThemeData (hwnd
, themeClass
);
5323 TOOLBAR_CheckStyle (hwnd
, dwStyle
);
5330 TOOLBAR_Destroy (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5332 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5334 /* delete tooltip control */
5335 if (infoPtr
->hwndToolTip
)
5336 DestroyWindow (infoPtr
->hwndToolTip
);
5338 /* delete temporary buffer for tooltip text */
5339 Free (infoPtr
->pszTooltipText
);
5340 Free (infoPtr
->bitmaps
); /* bitmaps list */
5342 /* delete button data */
5343 Free (infoPtr
->buttons
);
5345 /* delete strings */
5346 if (infoPtr
->strings
) {
5348 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5349 if (infoPtr
->strings
[i
])
5350 Free (infoPtr
->strings
[i
]);
5352 Free (infoPtr
->strings
);
5355 /* destroy internal image list */
5356 if (infoPtr
->himlInt
)
5357 ImageList_Destroy (infoPtr
->himlInt
);
5359 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5360 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5361 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5363 /* delete default font */
5364 DeleteObject (infoPtr
->hDefaultFont
);
5366 CloseThemeData (GetWindowTheme (hwnd
));
5368 /* free toolbar info data */
5370 SetWindowLongPtrW (hwnd
, 0, 0);
5377 TOOLBAR_EraseBackground (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5379 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5380 NMTBCUSTOMDRAW tbcd
;
5383 HTHEME theme
= GetWindowTheme (hwnd
);
5384 DWORD dwEraseCustDraw
= 0;
5386 /* the app has told us not to redraw the toolbar */
5387 if (!infoPtr
->bDoRedraw
)
5390 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5391 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5392 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5393 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5394 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5395 dwEraseCustDraw
= ntfret
& 0xffff;
5397 /* FIXME: in general the return flags *can* be or'ed together */
5398 switch (dwEraseCustDraw
)
5400 case CDRF_DODEFAULT
:
5402 case CDRF_SKIPDEFAULT
:
5405 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5410 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5411 * to my parent for processing.
5413 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5415 HDC hdc
= (HDC
)wParam
;
5420 parent
= GetParent(hwnd
);
5421 MapWindowPoints(hwnd
, parent
, &pt
, 1);
5422 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5423 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5424 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5427 ret
= DefWindowProcW (hwnd
, WM_ERASEBKGND
, wParam
, lParam
);
5429 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5430 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5431 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5432 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5433 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5434 dwEraseCustDraw
= ntfret
& 0xffff;
5435 switch (dwEraseCustDraw
)
5437 case CDRF_DODEFAULT
:
5439 case CDRF_SKIPDEFAULT
:
5442 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5451 TOOLBAR_GetFont (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5453 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5455 return (LRESULT
)infoPtr
->hFont
;
5460 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5463 INT nNewHotItem
= infoPtr
->nHotItem
;
5465 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5468 if ((nNewHotItem
+ iDirection
< 0) ||
5469 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5471 NMTBWRAPHOTITEM nmtbwhi
;
5472 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5473 nmtbwhi
.iDirection
= iDirection
;
5474 nmtbwhi
.dwReason
= dwReason
;
5476 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5480 nNewHotItem
+= iDirection
;
5481 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5483 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5484 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5486 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5493 TOOLBAR_KeyDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5495 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5498 nmkey
.nVKey
= (UINT
)wParam
;
5499 nmkey
.uFlags
= HIWORD(lParam
);
5501 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5502 return DefWindowProcW(hwnd
, WM_KEYDOWN
, wParam
, lParam
);
5504 switch ((UINT
)wParam
)
5508 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5512 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5516 if ((infoPtr
->nHotItem
>= 0) &&
5517 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5519 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5520 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5531 TOOLBAR_LButtonDblClk (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5536 pt
.x
= (short)LOWORD(lParam
);
5537 pt
.y
= (short)HIWORD(lParam
);
5538 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5541 TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
5542 else if (GetWindowLongW (hwnd
, GWL_STYLE
) & CCS_ADJUSTABLE
)
5543 TOOLBAR_Customize (hwnd
);
5550 TOOLBAR_LButtonDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5552 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5553 TBUTTON_INFO
*btnPtr
;
5558 BOOL bDragKeyPressed
;
5562 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5563 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5565 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5567 if (infoPtr
->hwndToolTip
)
5568 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5569 WM_LBUTTONDOWN
, wParam
, lParam
);
5571 pt
.x
= (short)LOWORD(lParam
);
5572 pt
.y
= (short)HIWORD(lParam
);
5573 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5575 btnPtr
= &infoPtr
->buttons
[nHit
];
5577 if ((nHit
>= 0) && bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5579 infoPtr
->nButtonDrag
= nHit
;
5582 /* If drag cursor has not been loaded, load it.
5583 * Note: it doesn't need to be freed */
5585 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5586 SetCursor(hCursorDrag
);
5591 infoPtr
->nOldHit
= nHit
;
5593 CopyRect(&arrowRect
, &btnPtr
->rect
);
5594 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5596 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5597 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5598 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5599 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5600 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5601 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5605 /* draw in pressed state */
5606 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5607 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5609 btnPtr
->bDropDownPressed
= TRUE
;
5610 RedrawWindow(hwnd
,&btnPtr
->rect
,0,
5611 RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5613 memset(&nmtb
, 0, sizeof(nmtb
));
5614 nmtb
.iItem
= btnPtr
->idCommand
;
5615 nmtb
.rcButton
= btnPtr
->rect
;
5616 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5618 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5620 if (res
!= TBDDRET_TREATPRESSED
)
5624 /* redraw button in unpressed state */
5625 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5626 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5628 btnPtr
->bDropDownPressed
= FALSE
;
5629 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5631 /* find and set hot item
5632 * NOTE: native doesn't do this, but that is a bug */
5634 ScreenToClient(hwnd
, &pt
);
5635 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
5636 if (!infoPtr
->bAnchor
|| (nHit
>= 0))
5637 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5639 /* remove any left mouse button down or double-click messages
5640 * so that we can get a toggle effect on the button */
5641 while (PeekMessageW(&msg
, hwnd
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5642 PeekMessageW(&msg
, hwnd
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5647 /* otherwise drop through and process as pushed */
5649 infoPtr
->bCaptured
= TRUE
;
5650 infoPtr
->nButtonDown
= nHit
;
5651 infoPtr
->bDragOutSent
= FALSE
;
5653 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5655 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5657 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5658 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5665 memset(&nmtb
, 0, sizeof(nmtb
));
5666 nmtb
.iItem
= btnPtr
->idCommand
;
5667 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5670 nmmouse
.dwHitInfo
= nHit
;
5672 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5674 nmmouse
.dwItemSpec
= -1;
5677 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5678 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5681 ClientToScreen(hwnd
, &pt
);
5684 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5685 return DefWindowProcW(hwnd
, WM_LBUTTONDOWN
, wParam
, lParam
);
5691 TOOLBAR_LButtonUp (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5693 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5694 TBUTTON_INFO
*btnPtr
;
5698 BOOL bSendMessage
= TRUE
;
5703 if (infoPtr
->hwndToolTip
)
5704 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5705 WM_LBUTTONUP
, wParam
, lParam
);
5707 pt
.x
= (short)LOWORD(lParam
);
5708 pt
.y
= (short)HIWORD(lParam
);
5709 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5711 if (!infoPtr
->bAnchor
|| (nHit
>= 0))
5712 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5714 if (infoPtr
->nButtonDrag
>= 0) {
5718 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5721 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5723 GetClientRect(hwnd
, &rcClient
);
5724 if (PtInRect(&rcClient
, pt
))
5731 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5734 if (nButton
== infoPtr
->nButtonDrag
)
5736 /* if the button is moved sightly left and we have a
5737 * separator there then remove it */
5738 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5740 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5741 TOOLBAR_DeleteButton(hwnd
, nButton
- 1, 0);
5743 else /* else insert a separator before the dragged button */
5746 memset(&tbb
, 0, sizeof(tbb
));
5747 tbb
.fsStyle
= BTNS_SEP
;
5749 TOOLBAR_InsertButtonT(hwnd
, nButton
, (LPARAM
)&tbb
, TRUE
);
5756 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5757 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, 0);
5759 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5762 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, nButton
);
5767 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5768 TOOLBAR_DeleteButton(hwnd
, (WPARAM
)infoPtr
->nButtonDrag
, 0);
5771 /* button under cursor changed so need to re-set hot item */
5772 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5773 infoPtr
->nButtonDrag
= -1;
5775 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5777 else if (infoPtr
->nButtonDown
>= 0) {
5778 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5779 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5781 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5782 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5783 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5785 if (nOldIndex
== nHit
)
5786 bSendMessage
= FALSE
;
5787 if ((nOldIndex
!= nHit
) &&
5789 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5790 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5793 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5794 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5796 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5800 if (nOldIndex
!= -1)
5801 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5804 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5805 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5806 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5808 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5810 infoPtr
->nButtonDown
= -1;
5812 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5813 TOOLBAR_SendNotify ((NMHDR
*) &hdr
, infoPtr
,
5814 NM_RELEASEDCAPTURE
);
5816 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5819 memset(&nmtb
, 0, sizeof(nmtb
));
5820 nmtb
.iItem
= btnPtr
->idCommand
;
5821 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5824 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5826 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5827 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)hwnd
);
5829 /* In case we have just been destroyed... */
5835 /* !!! Undocumented - toolbar at 4.71 level and above sends
5836 * NM_CLICK with the NMMOUSE structure. */
5837 nmmouse
.dwHitInfo
= nHit
;
5840 nmmouse
.dwItemSpec
= -1;
5843 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5844 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5847 ClientToScreen(hwnd
, &pt
);
5850 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5851 return DefWindowProcW(hwnd
, WM_LBUTTONUP
, wParam
, lParam
);
5857 TOOLBAR_RButtonUp( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5859 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5864 pt
.x
= (short)LOWORD(lParam
);
5865 pt
.y
= (short)HIWORD(lParam
);
5867 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
5868 nmmouse
.dwHitInfo
= nHit
;
5871 nmmouse
.dwItemSpec
= -1;
5873 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5874 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5877 ClientToScreen(hwnd
, &pt
);
5880 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5881 return DefWindowProcW(hwnd
, WM_RBUTTONUP
, wParam
, lParam
);
5887 TOOLBAR_RButtonDblClk( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5889 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5892 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5893 return DefWindowProcW(hwnd
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
5899 TOOLBAR_CaptureChanged(HWND hwnd
)
5901 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5902 TBUTTON_INFO
*btnPtr
;
5904 infoPtr
->bCaptured
= FALSE
;
5906 if (infoPtr
->nButtonDown
>= 0)
5908 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5909 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5911 infoPtr
->nOldHit
= -1;
5913 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5914 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5920 TOOLBAR_MouseLeave (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5922 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5924 /* don't remove hot effects when in anchor highlighting mode or when a
5925 * drop-down button is pressed */
5926 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
5928 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
5929 if (!hotBtnPtr
->bDropDownPressed
)
5930 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
5933 if (infoPtr
->nOldHit
< 0)
5936 /* If the last button we were over is depressed then make it not */
5937 /* depressed and redraw it */
5938 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
5940 TBUTTON_INFO
*btnPtr
;
5943 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5945 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5948 InflateRect (&rc1
, 1, 1);
5949 InvalidateRect (hwnd
, &rc1
, TRUE
);
5952 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
5955 ZeroMemory(&nmt
, sizeof(nmt
));
5956 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
5957 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
5958 infoPtr
->bDragOutSent
= TRUE
;
5961 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
5967 TOOLBAR_MouseMove (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5969 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5971 TRACKMOUSEEVENT trackinfo
;
5973 TBUTTON_INFO
*btnPtr
;
5975 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
5976 TOOLBAR_TooltipCreateControl(infoPtr
);
5978 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
5979 /* fill in the TRACKMOUSEEVENT struct */
5980 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5981 trackinfo
.dwFlags
= TME_QUERY
;
5983 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5984 _TrackMouseEvent(&trackinfo
);
5986 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5987 if(trackinfo
.hwndTrack
!= hwnd
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
5988 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5989 trackinfo
.hwndTrack
= hwnd
;
5991 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5992 /* and can properly deactivate the hot toolbar button */
5993 _TrackMouseEvent(&trackinfo
);
5997 if (infoPtr
->hwndToolTip
)
5998 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5999 WM_MOUSEMOVE
, wParam
, lParam
);
6001 pt
.x
= (short)LOWORD(lParam
);
6002 pt
.y
= (short)HIWORD(lParam
);
6004 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
6006 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6007 && (!infoPtr
->bAnchor
|| (nHit
>= 0)))
6008 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
);
6010 if (infoPtr
->nOldHit
!= nHit
)
6012 if (infoPtr
->bCaptured
)
6014 if (!infoPtr
->bDragOutSent
)
6017 ZeroMemory(&nmt
, sizeof(nmt
));
6018 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6019 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6020 infoPtr
->bDragOutSent
= TRUE
;
6023 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6024 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
6025 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6026 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6028 else if (nHit
== infoPtr
->nButtonDown
) {
6029 btnPtr
->fsState
|= TBSTATE_PRESSED
;
6030 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6032 infoPtr
->nOldHit
= nHit
;
6040 static inline LRESULT
6041 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6043 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6044 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
6046 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6050 static inline LRESULT
6051 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6053 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
6054 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
6056 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
6061 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6063 TOOLBAR_INFO
*infoPtr
;
6064 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
6067 /* allocate memory for info structure */
6068 infoPtr
= (TOOLBAR_INFO
*)Alloc (sizeof(TOOLBAR_INFO
));
6069 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
6072 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
6074 infoPtr
->nWidth
= 0;
6076 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6077 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
6078 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
6079 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
6082 /* native control does:
6083 * Get a lot of colors and brushes
6085 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6086 * CreateFontIndirectW(adr1)
6087 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6088 * hdc = GetDC(toolbar)
6089 * GetSystemMetrics(0x48)
6090 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6091 * 0, 0, 0, 0, "MARLETT")
6092 * oldfnt = SelectObject(hdc, fnt2)
6093 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6094 * GetTextMetricsW(hdc, adr3)
6095 * SelectObject(hdc, oldfnt)
6096 * DeleteObject(fnt2)
6098 * InvalidateRect(toolbar, 0, 1)
6099 * SetWindowLongW(toolbar, 0, addr)
6100 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6103 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6104 * ie 2 0x4600094c 0x4600094c 0x4600894d
6105 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6106 * rebar 0x50008844 0x40008844 0x50008845
6107 * pager 0x50000844 0x40000844 0x50008845
6108 * IC35mgr 0x5400084e **nochange**
6109 * on entry to _NCCREATE 0x5400084e
6110 * rowlist 0x5400004e **nochange**
6111 * on entry to _NCCREATE 0x5400004e
6115 /* I think the code below is a bug, but it is the way that the native
6116 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6117 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6118 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6119 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6120 * Somehow, the only cases of this seem to be MFC programs.
6122 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6123 * does not occur in the WM_STYLECHANGING routine.
6124 * (Guy Albertelli 9/2001)
6127 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6128 && !(cs
->style
& TBSTYLE_TRANSPARENT
))
6129 styleadd
|= TBSTYLE_TRANSPARENT
;
6130 if (!(cs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
6131 styleadd
|= CCS_TOP
; /* default to top */
6132 SetWindowLongW (hwnd
, GWL_STYLE
, cs
->style
| styleadd
);
6135 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, lParam
);
6140 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6142 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
6146 if (dwStyle
& WS_MINIMIZE
)
6147 return 0; /* Nothing to do */
6149 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
6151 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
6154 if (!(dwStyle
& CCS_NODIVIDER
))
6156 GetWindowRect (hwnd
, &rcWindow
);
6157 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
6158 if( dwStyle
& WS_BORDER
)
6159 OffsetRect (&rcWindow
, 1, 1);
6160 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6163 ReleaseDC( hwnd
, hdc
);
6169 /* handles requests from the tooltip control on what text to display */
6170 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6172 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6174 TRACE("button index = %d\n", index
);
6176 Free (infoPtr
->pszTooltipText
);
6177 infoPtr
->pszTooltipText
= NULL
;
6182 if (infoPtr
->bUnicode
)
6184 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6185 NMTBGETINFOTIPW tbgit
;
6186 unsigned int len
; /* in chars */
6188 wszBuffer
[0] = '\0';
6189 wszBuffer
[INFOTIPSIZE
] = '\0';
6191 tbgit
.pszText
= wszBuffer
;
6192 tbgit
.cchTextMax
= INFOTIPSIZE
;
6193 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6194 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6196 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6198 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6200 len
= strlenW(tbgit
.pszText
);
6201 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6203 /* need to allocate temporary buffer in infoPtr as there
6204 * isn't enough space in buffer passed to us by the
6205 * tooltip control */
6206 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6207 if (infoPtr
->pszTooltipText
)
6209 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6210 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6216 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6222 CHAR szBuffer
[INFOTIPSIZE
+1];
6223 NMTBGETINFOTIPA tbgit
;
6224 unsigned int len
; /* in chars */
6227 szBuffer
[INFOTIPSIZE
] = '\0';
6229 tbgit
.pszText
= szBuffer
;
6230 tbgit
.cchTextMax
= INFOTIPSIZE
;
6231 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6232 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6234 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6236 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6238 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6239 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]))
6241 /* need to allocate temporary buffer in infoPtr as there
6242 * isn't enough space in buffer passed to us by the
6243 * tooltip control */
6244 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6245 if (infoPtr
->pszTooltipText
)
6247 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6248 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6254 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1,
6255 lpnmtdi
->lpszText
, sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]));
6260 /* if button has text, but it is not shown then automatically
6261 * use that text as tooltip */
6262 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6263 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6265 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6266 unsigned int len
= pszText
? strlenW(pszText
) : 0;
6268 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6270 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6272 /* need to allocate temporary buffer in infoPtr as there
6273 * isn't enough space in buffer passed to us by the
6274 * tooltip control */
6275 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6276 if (infoPtr
->pszTooltipText
)
6278 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6279 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6285 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6290 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6292 /* last resort: send notification on to app */
6293 /* FIXME: find out what is really used here */
6294 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, 0, (LPARAM
)lpnmtdi
);
6298 static inline LRESULT
6299 TOOLBAR_Notify (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6301 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6302 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
6304 switch (lpnmh
->code
)
6308 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
6310 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6311 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6312 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6316 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6317 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6325 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lParam
;
6327 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6328 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6329 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6330 lppgs
->iScroll
, lppgs
->iDir
);
6334 case TTN_GETDISPINFOW
:
6335 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lParam
);
6337 case TTN_GETDISPINFOA
:
6338 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6348 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6352 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam
, lParam
);
6354 if (lParam
== NF_QUERY
)
6357 if (lParam
== NF_REQUERY
) {
6358 format
= SendMessageW(infoPtr
->hwndNotify
,
6359 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6360 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6361 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6372 TOOLBAR_Paint (HWND hwnd
, WPARAM wParam
)
6374 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
6378 /* fill ps.rcPaint with a default rect */
6379 memcpy(&(ps
.rcPaint
), &(infoPtr
->rcBound
), sizeof(infoPtr
->rcBound
));
6381 hdc
= wParam
==0 ? BeginPaint(hwnd
, &ps
) : (HDC
)wParam
;
6383 TRACE("psrect=(%d,%d)-(%d,%d)\n",
6384 ps
.rcPaint
.left
, ps
.rcPaint
.top
,
6385 ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
6387 TOOLBAR_Refresh (hwnd
, hdc
, &ps
);
6388 if (!wParam
) EndPaint (hwnd
, &ps
);
6395 TOOLBAR_SetFocus (HWND hwnd
, WPARAM wParam
)
6397 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6399 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6401 /* make first item hot */
6402 if (infoPtr
->nNumButtons
> 0)
6403 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6409 TOOLBAR_SetFont(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6411 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
6413 TRACE("font=%p redraw=%ld\n", (HFONT
)wParam
, lParam
);
6416 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6418 infoPtr
->hFont
= (HFONT
)wParam
;
6420 TOOLBAR_CalcToolbar(hwnd
);
6423 InvalidateRect(hwnd
, NULL
, TRUE
);
6428 TOOLBAR_SetRedraw (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6429 /*****************************************************
6432 * Handles the WM_SETREDRAW message.
6435 * According to testing V4.71 of COMCTL32 returns the
6436 * *previous* status of the redraw flag (either 0 or 1)
6437 * instead of the MSDN documented value of 0 if handled.
6438 * (For laughs see the "consistency" with same function
6441 *****************************************************/
6443 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6444 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6446 TRACE("set to %s\n",
6447 (wParam
) ? "TRUE" : "FALSE");
6448 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6450 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6452 return (oldredraw
) ? 1 : 0;
6457 TOOLBAR_Size (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6459 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6461 TRACE("sizing toolbar!\n");
6463 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6465 RECT delta_width
, delta_height
, client
, dummy
;
6466 DWORD min_x
, max_x
, min_y
, max_y
;
6467 TBUTTON_INFO
*btnPtr
;
6470 GetClientRect(hwnd
, &client
);
6471 if(client
.right
> infoPtr
->client_rect
.right
)
6473 min_x
= infoPtr
->client_rect
.right
;
6474 max_x
= client
.right
;
6478 max_x
= infoPtr
->client_rect
.right
;
6479 min_x
= client
.right
;
6481 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6483 min_y
= infoPtr
->client_rect
.bottom
;
6484 max_y
= client
.bottom
;
6488 max_y
= infoPtr
->client_rect
.bottom
;
6489 min_y
= client
.bottom
;
6492 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6493 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6495 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6496 btnPtr
= infoPtr
->buttons
;
6497 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6498 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6499 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6500 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6502 GetClientRect(hwnd
, &infoPtr
->client_rect
);
6503 TOOLBAR_AutoSize(hwnd
);
6509 TOOLBAR_StyleChanged (HWND hwnd
, INT nType
, const STYLESTRUCT
*lpStyle
)
6511 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6513 if (nType
== GWL_STYLE
)
6515 DWORD dwOldStyle
= infoPtr
->dwStyle
;
6517 if (lpStyle
->styleNew
& TBSTYLE_LIST
)
6518 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
6520 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
6522 TOOLBAR_CheckStyle (hwnd
, lpStyle
->styleNew
);
6524 TRACE("new style 0x%08x\n", lpStyle
->styleNew
);
6526 infoPtr
->dwStyle
= lpStyle
->styleNew
;
6528 if ((dwOldStyle
^ lpStyle
->styleNew
) & (TBSTYLE_WRAPABLE
| CCS_VERT
))
6529 TOOLBAR_LayoutToolbar(hwnd
);
6531 /* only resize if one of the CCS_* styles was changed */
6532 if ((dwOldStyle
^ lpStyle
->styleNew
) & COMMON_STYLES
)
6534 TOOLBAR_AutoSize (hwnd
);
6536 InvalidateRect(hwnd
, NULL
, TRUE
);
6545 TOOLBAR_SysColorChange (HWND hwnd
)
6547 COMCTL32_RefreshSysColors();
6553 /* update theme after a WM_THEMECHANGED message */
6554 static LRESULT
theme_changed (HWND hwnd
)
6556 HTHEME theme
= GetWindowTheme (hwnd
);
6557 CloseThemeData (theme
);
6558 OpenThemeData (hwnd
, themeClass
);
6563 static LRESULT WINAPI
6564 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6566 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6568 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6569 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6571 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6572 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6577 return TOOLBAR_AddBitmap (hwnd
, wParam
, lParam
);
6579 case TB_ADDBUTTONSA
:
6580 return TOOLBAR_AddButtonsT(hwnd
, wParam
, lParam
, FALSE
);
6582 case TB_ADDBUTTONSW
:
6583 return TOOLBAR_AddButtonsT(hwnd
, wParam
, lParam
, TRUE
);
6586 return TOOLBAR_AddStringA (hwnd
, wParam
, lParam
);
6589 return TOOLBAR_AddStringW (hwnd
, wParam
, lParam
);
6592 return TOOLBAR_AutoSize (hwnd
);
6594 case TB_BUTTONCOUNT
:
6595 return TOOLBAR_ButtonCount (hwnd
, wParam
, lParam
);
6597 case TB_BUTTONSTRUCTSIZE
:
6598 return TOOLBAR_ButtonStructSize (hwnd
, wParam
, lParam
);
6600 case TB_CHANGEBITMAP
:
6601 return TOOLBAR_ChangeBitmap (hwnd
, wParam
, lParam
);
6603 case TB_CHECKBUTTON
:
6604 return TOOLBAR_CheckButton (hwnd
, wParam
, lParam
);
6606 case TB_COMMANDTOINDEX
:
6607 return TOOLBAR_CommandToIndex (hwnd
, wParam
, lParam
);
6610 return TOOLBAR_Customize (hwnd
);
6612 case TB_DELETEBUTTON
:
6613 return TOOLBAR_DeleteButton (hwnd
, wParam
, lParam
);
6615 case TB_ENABLEBUTTON
:
6616 return TOOLBAR_EnableButton (hwnd
, wParam
, lParam
);
6618 case TB_GETANCHORHIGHLIGHT
:
6619 return TOOLBAR_GetAnchorHighlight (hwnd
);
6622 return TOOLBAR_GetBitmap (hwnd
, wParam
, lParam
);
6624 case TB_GETBITMAPFLAGS
:
6625 return TOOLBAR_GetBitmapFlags (hwnd
, wParam
, lParam
);
6628 return TOOLBAR_GetButton (hwnd
, wParam
, lParam
);
6630 case TB_GETBUTTONINFOA
:
6631 return TOOLBAR_GetButtonInfoT(hwnd
, wParam
, lParam
, FALSE
);
6633 case TB_GETBUTTONINFOW
:
6634 return TOOLBAR_GetButtonInfoT(hwnd
, wParam
, lParam
, TRUE
);
6636 case TB_GETBUTTONSIZE
:
6637 return TOOLBAR_GetButtonSize (hwnd
);
6639 case TB_GETBUTTONTEXTA
:
6640 return TOOLBAR_GetButtonTextA (hwnd
, wParam
, lParam
);
6642 case TB_GETBUTTONTEXTW
:
6643 return TOOLBAR_GetButtonTextW (hwnd
, wParam
, lParam
);
6645 case TB_GETDISABLEDIMAGELIST
:
6646 return TOOLBAR_GetDisabledImageList (hwnd
, wParam
, lParam
);
6648 case TB_GETEXTENDEDSTYLE
:
6649 return TOOLBAR_GetExtendedStyle (hwnd
);
6651 case TB_GETHOTIMAGELIST
:
6652 return TOOLBAR_GetHotImageList (hwnd
, wParam
, lParam
);
6655 return TOOLBAR_GetHotItem (hwnd
);
6657 case TB_GETIMAGELIST
:
6658 return TOOLBAR_GetDefImageList (hwnd
, wParam
, lParam
);
6660 case TB_GETINSERTMARK
:
6661 return TOOLBAR_GetInsertMark (hwnd
, wParam
, lParam
);
6663 case TB_GETINSERTMARKCOLOR
:
6664 return TOOLBAR_GetInsertMarkColor (hwnd
, wParam
, lParam
);
6666 case TB_GETITEMRECT
:
6667 return TOOLBAR_GetItemRect (hwnd
, wParam
, lParam
);
6670 return TOOLBAR_GetMaxSize (hwnd
, wParam
, lParam
);
6672 /* case TB_GETOBJECT: */ /* 4.71 */
6675 return TOOLBAR_GetPadding (hwnd
);
6678 return TOOLBAR_GetRect (hwnd
, wParam
, lParam
);
6681 return TOOLBAR_GetRows (hwnd
, wParam
, lParam
);
6684 return TOOLBAR_GetState (hwnd
, wParam
, lParam
);
6687 return TOOLBAR_GetStringA (hwnd
, wParam
, lParam
);
6690 return TOOLBAR_GetStringW (hwnd
, wParam
, lParam
);
6693 return TOOLBAR_GetStyle (hwnd
, wParam
, lParam
);
6695 case TB_GETTEXTROWS
:
6696 return TOOLBAR_GetTextRows (hwnd
, wParam
, lParam
);
6698 case TB_GETTOOLTIPS
:
6699 return TOOLBAR_GetToolTips (hwnd
, wParam
, lParam
);
6701 case TB_GETUNICODEFORMAT
:
6702 return TOOLBAR_GetUnicodeFormat (hwnd
, wParam
, lParam
);
6705 return TOOLBAR_HideButton (hwnd
, wParam
, lParam
);
6708 return TOOLBAR_HitTest (hwnd
, wParam
, lParam
);
6710 case TB_INDETERMINATE
:
6711 return TOOLBAR_Indeterminate (hwnd
, wParam
, lParam
);
6713 case TB_INSERTBUTTONA
:
6714 return TOOLBAR_InsertButtonT(hwnd
, wParam
, lParam
, FALSE
);
6716 case TB_INSERTBUTTONW
:
6717 return TOOLBAR_InsertButtonT(hwnd
, wParam
, lParam
, TRUE
);
6719 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6721 case TB_ISBUTTONCHECKED
:
6722 return TOOLBAR_IsButtonChecked (hwnd
, wParam
, lParam
);
6724 case TB_ISBUTTONENABLED
:
6725 return TOOLBAR_IsButtonEnabled (hwnd
, wParam
, lParam
);
6727 case TB_ISBUTTONHIDDEN
:
6728 return TOOLBAR_IsButtonHidden (hwnd
, wParam
, lParam
);
6730 case TB_ISBUTTONHIGHLIGHTED
:
6731 return TOOLBAR_IsButtonHighlighted (hwnd
, wParam
, lParam
);
6733 case TB_ISBUTTONINDETERMINATE
:
6734 return TOOLBAR_IsButtonIndeterminate (hwnd
, wParam
, lParam
);
6736 case TB_ISBUTTONPRESSED
:
6737 return TOOLBAR_IsButtonPressed (hwnd
, wParam
, lParam
);
6740 return TOOLBAR_LoadImages (hwnd
, wParam
, lParam
);
6742 case TB_MAPACCELERATORA
:
6743 case TB_MAPACCELERATORW
:
6744 return TOOLBAR_MapAccelerator (hwnd
, wParam
, lParam
);
6747 return TOOLBAR_MarkButton (hwnd
, wParam
, lParam
);
6750 return TOOLBAR_MoveButton (hwnd
, wParam
, lParam
);
6752 case TB_PRESSBUTTON
:
6753 return TOOLBAR_PressButton (hwnd
, wParam
, lParam
);
6755 case TB_REPLACEBITMAP
:
6756 return TOOLBAR_ReplaceBitmap (hwnd
, wParam
, lParam
);
6758 case TB_SAVERESTOREA
:
6759 return TOOLBAR_SaveRestoreA (hwnd
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6761 case TB_SAVERESTOREW
:
6762 return TOOLBAR_SaveRestoreW (hwnd
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6764 case TB_SETANCHORHIGHLIGHT
:
6765 return TOOLBAR_SetAnchorHighlight (hwnd
, wParam
);
6767 case TB_SETBITMAPSIZE
:
6768 return TOOLBAR_SetBitmapSize (hwnd
, wParam
, lParam
);
6770 case TB_SETBUTTONINFOA
:
6771 return TOOLBAR_SetButtonInfoA (hwnd
, wParam
, lParam
);
6773 case TB_SETBUTTONINFOW
:
6774 return TOOLBAR_SetButtonInfoW (hwnd
, wParam
, lParam
);
6776 case TB_SETBUTTONSIZE
:
6777 return TOOLBAR_SetButtonSize (hwnd
, wParam
, lParam
);
6779 case TB_SETBUTTONWIDTH
:
6780 return TOOLBAR_SetButtonWidth (hwnd
, wParam
, lParam
);
6783 return TOOLBAR_SetCmdId (hwnd
, wParam
, lParam
);
6785 case TB_SETDISABLEDIMAGELIST
:
6786 return TOOLBAR_SetDisabledImageList (hwnd
, wParam
, lParam
);
6788 case TB_SETDRAWTEXTFLAGS
:
6789 return TOOLBAR_SetDrawTextFlags (hwnd
, wParam
, lParam
);
6791 case TB_SETEXTENDEDSTYLE
:
6792 return TOOLBAR_SetExtendedStyle (hwnd
, wParam
, lParam
);
6794 case TB_SETHOTIMAGELIST
:
6795 return TOOLBAR_SetHotImageList (hwnd
, wParam
, lParam
);
6798 return TOOLBAR_SetHotItem (hwnd
, wParam
);
6800 case TB_SETIMAGELIST
:
6801 return TOOLBAR_SetImageList (hwnd
, wParam
, lParam
);
6804 return TOOLBAR_SetIndent (hwnd
, wParam
, lParam
);
6806 case TB_SETINSERTMARK
:
6807 return TOOLBAR_SetInsertMark (hwnd
, wParam
, lParam
);
6809 case TB_SETINSERTMARKCOLOR
:
6810 return TOOLBAR_SetInsertMarkColor (hwnd
, wParam
, lParam
);
6812 case TB_SETMAXTEXTROWS
:
6813 return TOOLBAR_SetMaxTextRows (hwnd
, wParam
, lParam
);
6816 return TOOLBAR_SetPadding (hwnd
, wParam
, lParam
);
6819 return TOOLBAR_SetParent (hwnd
, wParam
, lParam
);
6822 return TOOLBAR_SetRows (hwnd
, wParam
, lParam
);
6825 return TOOLBAR_SetState (hwnd
, wParam
, lParam
);
6828 return TOOLBAR_SetStyle (hwnd
, wParam
, lParam
);
6830 case TB_SETTOOLTIPS
:
6831 return TOOLBAR_SetToolTips (hwnd
, wParam
, lParam
);
6833 case TB_SETUNICODEFORMAT
:
6834 return TOOLBAR_SetUnicodeFormat (hwnd
, wParam
, lParam
);
6837 return TOOLBAR_Unkwn45D(hwnd
, wParam
, lParam
);
6840 return TOOLBAR_Unkwn45E (hwnd
, wParam
, lParam
);
6843 return TOOLBAR_Unkwn460(hwnd
, wParam
, lParam
);
6846 return TOOLBAR_Unkwn462(hwnd
, wParam
, lParam
);
6849 return TOOLBAR_Unkwn463 (hwnd
, wParam
, lParam
);
6852 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6854 /* Common Control Messages */
6856 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6857 case CCM_GETCOLORSCHEME
:
6858 return TOOLBAR_GetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
6860 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6861 case CCM_SETCOLORSCHEME
:
6862 return TOOLBAR_SetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
6864 case CCM_GETVERSION
:
6865 return TOOLBAR_GetVersion (hwnd
);
6867 case CCM_SETVERSION
:
6868 return TOOLBAR_SetVersion (hwnd
, (INT
)wParam
);
6874 return TOOLBAR_Create (hwnd
, wParam
, lParam
);
6877 return TOOLBAR_Destroy (hwnd
, wParam
, lParam
);
6880 return TOOLBAR_EraseBackground (hwnd
, wParam
, lParam
);
6883 return TOOLBAR_GetFont (hwnd
, wParam
, lParam
);
6886 return TOOLBAR_KeyDown (hwnd
, wParam
, lParam
);
6888 /* case WM_KILLFOCUS: */
6890 case WM_LBUTTONDBLCLK
:
6891 return TOOLBAR_LButtonDblClk (hwnd
, wParam
, lParam
);
6893 case WM_LBUTTONDOWN
:
6894 return TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
6897 return TOOLBAR_LButtonUp (hwnd
, wParam
, lParam
);
6900 return TOOLBAR_RButtonUp (hwnd
, wParam
, lParam
);
6902 case WM_RBUTTONDBLCLK
:
6903 return TOOLBAR_RButtonDblClk (hwnd
, wParam
, lParam
);
6906 return TOOLBAR_MouseMove (hwnd
, wParam
, lParam
);
6909 return TOOLBAR_MouseLeave (hwnd
, wParam
, lParam
);
6911 case WM_CAPTURECHANGED
:
6912 return TOOLBAR_CaptureChanged(hwnd
);
6915 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6918 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6921 return TOOLBAR_NCCreate (hwnd
, wParam
, lParam
);
6924 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
6927 return TOOLBAR_Notify (hwnd
, wParam
, lParam
);
6929 case WM_NOTIFYFORMAT
:
6930 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
6932 case WM_PRINTCLIENT
:
6934 return TOOLBAR_Paint (hwnd
, wParam
);
6937 return TOOLBAR_SetFocus (hwnd
, wParam
);
6940 return TOOLBAR_SetFont(hwnd
, wParam
, lParam
);
6943 return TOOLBAR_SetRedraw (hwnd
, wParam
, lParam
);
6946 return TOOLBAR_Size (hwnd
, wParam
, lParam
);
6948 case WM_STYLECHANGED
:
6949 return TOOLBAR_StyleChanged (hwnd
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
6951 case WM_SYSCOLORCHANGE
:
6952 return TOOLBAR_SysColorChange (hwnd
);
6954 case WM_THEMECHANGED
:
6955 return theme_changed (hwnd
);
6957 /* case WM_WININICHANGE: */
6962 case WM_MEASUREITEM
:
6964 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
6966 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6967 case PGM_FORWARDMOUSE
:
6968 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6971 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
6972 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
6973 uMsg
, wParam
, lParam
);
6974 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
6980 TOOLBAR_Register (void)
6984 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
6985 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
6986 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
6987 wndClass
.cbClsExtra
= 0;
6988 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
6989 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
6990 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
6991 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
6993 RegisterClassW (&wndClass
);
6998 TOOLBAR_Unregister (void)
7000 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
7003 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
7008 /* Check if the entry already exists */
7009 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
7011 /* If this is a new entry we must create it and insert into the array */
7016 c
= (PIMLENTRY
) Alloc(sizeof(IMLENTRY
));
7019 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
7020 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
7035 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
7039 for (i
= 0; i
< *cies
; i
++)
7049 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
7057 for (i
= 0; i
< cies
; i
++)
7059 if (pies
[i
]->id
== id
)
7071 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
7073 HIMAGELIST himlDef
= 0;
7074 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
7077 himlDef
= pie
->himl
;
7083 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
7085 if (infoPtr
->bUnicode
)
7086 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
7093 nmtba
.iItem
= nmtb
->iItem
;
7094 nmtba
.pszText
= Buffer
;
7095 nmtba
.cchText
= 256;
7096 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
7098 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
7100 int ccht
= strlen(nmtba
.pszText
);
7102 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)nmtba
.pszText
, -1,
7103 nmtb
->pszText
, nmtb
->cchText
);
7105 memcpy(&nmtb
->tbButton
, &nmtba
.tbButton
, sizeof(TBBUTTON
));
7114 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, PCUSTOMBUTTON btnInfo
)
7118 /* MSDN states that iItem is the index of the button, rather than the
7119 * command ID as used by every other NMTOOLBAR notification */
7121 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
7123 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);