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 iListGap
; /* default gap between text and image for toolbar with list style */
145 HFONT hFont
; /* text font */
146 HIMAGELIST himlInt
; /* image list created internally */
147 PIMLENTRY
*himlDef
; /* default image list array */
148 INT cimlDef
; /* default image list array count */
149 PIMLENTRY
*himlHot
; /* hot image list array */
150 INT cimlHot
; /* hot image list array count */
151 PIMLENTRY
*himlDis
; /* disabled image list array */
152 INT cimlDis
; /* disabled image list array count */
153 HWND hwndToolTip
; /* handle to tool tip control */
154 HWND hwndNotify
; /* handle to the window that gets notifications */
155 HWND hwndSelf
; /* my own handle */
156 BOOL bAnchor
; /* anchor highlight enabled */
157 BOOL bDoRedraw
; /* Redraw status */
158 BOOL bDragOutSent
; /* has TBN_DRAGOUT notification been sent for this drag? */
159 BOOL bUnicode
; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
160 BOOL bCaptured
; /* mouse captured? */
161 DWORD dwStyle
; /* regular toolbar style */
162 DWORD dwExStyle
; /* extended toolbar style */
163 DWORD dwDTFlags
; /* DrawText flags */
165 COLORREF clrInsertMark
; /* insert mark color */
166 COLORREF clrBtnHighlight
; /* color for Flat Separator */
167 COLORREF clrBtnShadow
; /* color for Flag Separator */
169 LPWSTR pszTooltipText
; /* temporary store for a string > 80 characters
170 * for TTN_GETDISPINFOW notification */
171 TBINSERTMARK tbim
; /* info on insertion mark */
172 TBUTTON_INFO
*buttons
; /* pointer to button array */
173 LPWSTR
*strings
; /* pointer to string array */
174 TBITMAP_INFO
*bitmaps
;
175 } TOOLBAR_INFO
, *PTOOLBAR_INFO
;
178 /* used by customization dialog */
181 PTOOLBAR_INFO tbInfo
;
183 } CUSTDLG_INFO
, *PCUSTDLG_INFO
;
191 } CUSTOMBUTTON
, *PCUSTOMBUTTON
;
200 #define SEPARATOR_WIDTH 8
202 #define BOTTOM_BORDER 2
203 #define DDARROW_WIDTH 11
204 #define ARROW_HEIGHT 3
205 #define INSERTMARK_WIDTH 2
211 /* vertical padding used in list mode when image is present */
214 /* how wide to treat the bitmap if it isn't present */
215 #define NONLIST_NOTEXT_OFFSET 2
217 #define TOOLBAR_NOWHERE (-1)
219 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
220 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
221 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
223 /* Used to find undocumented extended styles */
224 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
225 TBSTYLE_EX_UNDOC1 | \
226 TBSTYLE_EX_MIXEDBUTTONS | \
227 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
229 /* all of the CCS_ styles */
230 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
231 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
233 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
234 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
235 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
236 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
237 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
239 static const WCHAR themeClass
[] = { 'T','o','o','l','b','a','r',0 };
241 static BOOL
TOOLBAR_GetButtonInfo(TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
);
242 static BOOL
TOOLBAR_IsButtonRemovable(TOOLBAR_INFO
*infoPtr
, int iItem
, PCUSTOMBUTTON btnInfo
);
243 static HIMAGELIST
TOOLBAR_GetImageList(PIMLENTRY
*pies
, INT cies
, INT id
);
244 static PIMLENTRY
TOOLBAR_GetImageListEntry(PIMLENTRY
*pies
, INT cies
, INT id
);
245 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
);
246 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
);
247 static LRESULT
TOOLBAR_LButtonDown(HWND hwnd
, WPARAM wParam
, LPARAM lParam
);
248 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
);
249 static LRESULT
TOOLBAR_AutoSize(HWND hwnd
);
250 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
);
251 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*button
);
254 TOOLBAR_NotifyFormat(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
);
258 TOOLBAR_GetText(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
260 LPWSTR lpText
= NULL
;
262 /* NOTE: iString == -1 is undocumented */
263 if ((HIWORD(btnPtr
->iString
) != 0) && (btnPtr
->iString
!= -1))
264 lpText
= (LPWSTR
)btnPtr
->iString
;
265 else if ((btnPtr
->iString
>= 0) && (btnPtr
->iString
< infoPtr
->nNumStrings
))
266 lpText
= infoPtr
->strings
[btnPtr
->iString
];
272 TOOLBAR_DumpButton(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*bP
, INT btn_num
, BOOL internal
)
274 if (TRACE_ON(toolbar
)){
275 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
276 btn_num
, bP
->idCommand
, GETIBITMAP(infoPtr
, bP
->iBitmap
),
277 bP
->fsState
, bP
->fsStyle
, bP
->dwData
, bP
->iString
);
278 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr
,bP
)));
280 TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n",
281 btn_num
, bP
->idCommand
,
282 (bP
->bHot
) ? "TRUE":"FALSE", bP
->nRow
,
283 bP
->rect
.left
, bP
->rect
.top
,
284 bP
->rect
.right
, bP
->rect
.bottom
);
290 TOOLBAR_DumpToolbar(TOOLBAR_INFO
*iP
, INT line
)
292 if (TRACE_ON(toolbar
)) {
295 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
297 iP
->dwExStyle
, iP
->nNumButtons
, iP
->nNumBitmaps
,
298 iP
->nNumStrings
, iP
->dwStyle
);
299 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
301 iP
->himlInt
, iP
->himlDef
, iP
->himlHot
, iP
->himlDis
,
302 (iP
->bDoRedraw
) ? "TRUE" : "FALSE");
303 for(i
=0; i
<iP
->nNumButtons
; i
++) {
304 TOOLBAR_DumpButton(iP
, &iP
->buttons
[i
], i
, TRUE
);
310 /***********************************************************************
313 * This function validates that the styles set are implemented and
314 * issues FIXME's warning of possible problems. In a perfect world this
315 * function should be null.
318 TOOLBAR_CheckStyle (HWND hwnd
, DWORD dwStyle
)
320 if (dwStyle
& TBSTYLE_REGISTERDROP
)
321 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd
);
326 TOOLBAR_SendNotify (NMHDR
*nmhdr
, TOOLBAR_INFO
*infoPtr
, UINT code
)
328 if(!IsWindow(infoPtr
->hwndSelf
))
329 return 0; /* we have just been destroyed */
331 nmhdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
332 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
335 TRACE("to window %p, code=%08x, %s\n", infoPtr
->hwndNotify
, code
,
336 (infoPtr
->bUnicode
) ? "via Unicode" : "via ANSI");
338 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
339 (WPARAM
)nmhdr
->idFrom
, (LPARAM
)nmhdr
);
342 /***********************************************************************
343 * TOOLBAR_GetBitmapIndex
345 * This function returns the bitmap index associated with a button.
346 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
347 * is issued to retrieve the index.
350 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
352 INT ret
= btnPtr
->iBitmap
;
354 if (ret
== I_IMAGECALLBACK
)
356 /* issue TBN_GETDISPINFO */
359 memset(&nmgd
, 0, sizeof(nmgd
));
360 nmgd
.idCommand
= btnPtr
->idCommand
;
361 nmgd
.lParam
= btnPtr
->dwData
;
362 nmgd
.dwMask
= TBNF_IMAGE
;
363 TOOLBAR_SendNotify(&nmgd
.hdr
, infoPtr
,
364 infoPtr
->bUnicode
? TBN_GETDISPINFOW
: TBN_GETDISPINFOA
);
365 if (nmgd
.dwMask
& TBNF_DI_SETITEM
)
366 btnPtr
->iBitmap
= nmgd
.iImage
;
368 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
369 ret
, nmgd
.dwMask
, infoPtr
->nNumBitmaps
);
372 if (ret
!= I_IMAGENONE
)
373 ret
= GETIBITMAP(infoPtr
, ret
);
380 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO
*infoPtr
, INT index
)
383 INT id
= GETHIMLID(infoPtr
, index
);
384 INT iBitmap
= GETIBITMAP(infoPtr
, index
);
386 if (((himl
= GETDEFIMAGELIST(infoPtr
, id
)) &&
387 iBitmap
>= 0 && iBitmap
< ImageList_GetImageCount(himl
)) ||
388 (index
== I_IMAGECALLBACK
))
396 TOOLBAR_IsValidImageList(TOOLBAR_INFO
*infoPtr
, INT index
)
398 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, index
));
399 return (himl
!= NULL
) && (ImageList_GetImageCount(himl
) > 0);
403 /***********************************************************************
404 * TOOLBAR_GetImageListForDrawing
406 * This function validates the bitmap index (including I_IMAGECALLBACK
407 * functionality) and returns the corresponding image list.
410 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, IMAGE_LIST_TYPE imagelist
, INT
* index
)
414 if (!TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
)) {
415 if (btnPtr
->iBitmap
== I_IMAGENONE
) return NULL
;
416 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
417 HIWORD(btnPtr
->iBitmap
), LOWORD(btnPtr
->iBitmap
), infoPtr
->nNumBitmaps
);
421 if ((*index
= TOOLBAR_GetBitmapIndex(infoPtr
, btnPtr
)) < 0) {
422 if ((*index
== I_IMAGECALLBACK
) ||
423 (*index
== I_IMAGENONE
)) return NULL
;
424 ERR("TBN_GETDISPINFO returned invalid index %d\n",
431 case IMAGE_LIST_DEFAULT
:
432 himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
435 himl
= GETHOTIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
437 case IMAGE_LIST_DISABLED
:
438 himl
= GETDISIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
442 FIXME("Shouldn't reach here\n");
446 TRACE("no image list\n");
453 TOOLBAR_DrawFlatSeparator (LPRECT lpRect
, HDC hdc
, TOOLBAR_INFO
*infoPtr
)
456 COLORREF oldcolor
, newcolor
;
458 myrect
.left
= (lpRect
->left
+ lpRect
->right
) / 2 - 1;
459 myrect
.right
= myrect
.left
+ 1;
460 myrect
.top
= lpRect
->top
+ 2;
461 myrect
.bottom
= lpRect
->bottom
- 2;
463 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
464 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
465 oldcolor
= SetBkColor (hdc
, newcolor
);
466 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
468 myrect
.left
= myrect
.right
;
469 myrect
.right
= myrect
.left
+ 1;
471 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
472 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
473 SetBkColor (hdc
, newcolor
);
474 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
476 SetBkColor (hdc
, oldcolor
);
480 /***********************************************************************
481 * TOOLBAR_DrawDDFlatSeparator
483 * This function draws the separator that was flagged as BTNS_DROPDOWN.
484 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
485 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
486 * are horizontal as opposed to the vertical separators for not dropdown
489 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
492 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect
, HDC hdc
, TBUTTON_INFO
*btnPtr
, TOOLBAR_INFO
*infoPtr
)
495 COLORREF oldcolor
, newcolor
;
497 myrect
.left
= lpRect
->left
;
498 myrect
.right
= lpRect
->right
;
499 myrect
.top
= lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
- 2)/2;
500 myrect
.bottom
= myrect
.top
+ 1;
502 InflateRect (&myrect
, -2, 0);
504 TRACE("rect=(%d,%d)-(%d,%d)\n",
505 myrect
.left
, myrect
.top
, myrect
.right
, myrect
.bottom
);
507 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
508 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
509 oldcolor
= SetBkColor (hdc
, newcolor
);
510 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
512 myrect
.top
= myrect
.bottom
;
513 myrect
.bottom
= myrect
.top
+ 1;
515 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
516 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
517 SetBkColor (hdc
, newcolor
);
518 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
520 SetBkColor (hdc
, oldcolor
);
525 TOOLBAR_DrawArrow (HDC hdc
, INT left
, INT top
, COLORREF clr
)
530 if (!(hPen
= CreatePen( PS_SOLID
, 1, clr
))) return;
531 hOldPen
= SelectObject ( hdc
, hPen
);
534 MoveToEx (hdc
, x
, y
, NULL
);
535 LineTo (hdc
, x
+5, y
++); x
++;
536 MoveToEx (hdc
, x
, y
, NULL
);
537 LineTo (hdc
, x
+3, y
++); x
++;
538 MoveToEx (hdc
, x
, y
, NULL
);
539 LineTo (hdc
, x
+1, y
++);
540 SelectObject( hdc
, hOldPen
);
541 DeleteObject( hPen
);
545 * Draw the text string for this button.
546 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
547 * is non-zero, so we can simply check himlDef to see if we have
551 TOOLBAR_DrawString (TOOLBAR_INFO
*infoPtr
, RECT
*rcText
, LPWSTR lpText
,
552 NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
554 HDC hdc
= tbcd
->nmcd
.hdc
;
557 COLORREF clrOldBk
= 0;
559 UINT state
= tbcd
->nmcd
.uItemState
;
563 TRACE("string=%s rect=(%d,%d)-(%d,%d)\n", debugstr_w(lpText
),
564 rcText
->left
, rcText
->top
, rcText
->right
, rcText
->bottom
);
566 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
567 if ((state
& CDIS_HOT
) && (dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)) {
568 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
570 else if (state
& CDIS_DISABLED
) {
571 clrOld
= SetTextColor (hdc
, tbcd
->clrBtnHighlight
);
572 OffsetRect (rcText
, 1, 1);
573 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
574 SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
575 OffsetRect (rcText
, -1, -1);
577 else if (state
& CDIS_INDETERMINATE
) {
578 clrOld
= SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
580 else if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
)) {
581 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
582 clrOldBk
= SetBkColor (hdc
, tbcd
->clrMark
);
583 oldBkMode
= SetBkMode (hdc
, tbcd
->nHLStringBkMode
);
586 clrOld
= SetTextColor (hdc
, tbcd
->clrText
);
589 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
590 SetTextColor (hdc
, clrOld
);
591 if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
))
593 SetBkColor (hdc
, clrOldBk
);
594 SetBkMode (hdc
, oldBkMode
);
596 SelectObject (hdc
, hOldFont
);
602 TOOLBAR_DrawPattern (LPRECT lpRect
, NMTBCUSTOMDRAW
*tbcd
)
604 HDC hdc
= tbcd
->nmcd
.hdc
;
605 HBRUSH hbr
= SelectObject (hdc
, tbcd
->hbrMonoDither
);
608 INT cx
= lpRect
->right
- lpRect
->left
;
609 INT cy
= lpRect
->bottom
- lpRect
->top
;
610 INT cxEdge
= GetSystemMetrics(SM_CXEDGE
);
611 INT cyEdge
= GetSystemMetrics(SM_CYEDGE
);
612 clrTextOld
= SetTextColor(hdc
, tbcd
->clrBtnHighlight
);
613 clrBkOld
= SetBkColor(hdc
, tbcd
->clrBtnFace
);
614 PatBlt (hdc
, lpRect
->left
+ cxEdge
, lpRect
->top
+ cyEdge
,
615 cx
- (2 * cxEdge
), cy
- (2 * cyEdge
), PATCOPY
);
616 SetBkColor(hdc
, clrBkOld
);
617 SetTextColor(hdc
, clrTextOld
);
618 SelectObject (hdc
, hbr
);
622 static void TOOLBAR_DrawMasked(HIMAGELIST himl
, int index
, HDC hdc
, INT x
, INT y
, UINT draw_flags
)
625 HBITMAP hbmMask
, hbmImage
;
626 HDC hdcMask
, hdcImage
;
628 ImageList_GetIconSize(himl
, &cx
, &cy
);
630 /* Create src image */
631 hdcImage
= CreateCompatibleDC(hdc
);
632 hbmImage
= CreateCompatibleBitmap(hdc
, cx
, cy
);
633 SelectObject(hdcImage
, hbmImage
);
634 ImageList_DrawEx(himl
, index
, hdcImage
, 0, 0, cx
, cy
,
635 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags
);
638 hdcMask
= CreateCompatibleDC(0);
639 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
640 SelectObject(hdcMask
, hbmMask
);
642 /* Remove the background and all white pixels */
643 ImageList_DrawEx(himl
, index
, hdcMask
, 0, 0, cx
, cy
,
644 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK
);
645 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
646 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
648 /* draw the new mask 'etched' to hdc */
649 SetBkColor(hdc
, RGB(255, 255, 255));
650 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
651 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
652 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
653 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
654 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
657 DeleteObject(hbmImage
);
659 DeleteObject (hbmMask
);
665 TOOLBAR_TranslateState(TBUTTON_INFO
*btnPtr
)
669 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
670 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
671 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
672 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
673 retstate
|= (btnPtr
->bHot
) ? CDIS_HOT
: 0;
674 retstate
|= ((btnPtr
->fsState
& (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) == (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) ? CDIS_INDETERMINATE
: 0;
675 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
679 /* draws the image on a toolbar button */
681 TOOLBAR_DrawImage(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
,
682 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
684 HIMAGELIST himl
= NULL
;
685 BOOL draw_masked
= FALSE
;
688 UINT draw_flags
= ILD_TRANSPARENT
;
690 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
692 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
695 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
699 else if (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
||
700 ((tbcd
->nmcd
.uItemState
& CDIS_HOT
)
701 && ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))))
703 /* if hot, attempt to draw with hot image list, if fails,
704 use default image list */
705 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
707 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
710 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
715 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
716 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
719 if (!(dwItemCDFlag
& TBCDRF_NOMARK
) &&
720 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
721 draw_flags
|= ILD_BLEND50
;
723 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
724 index
, himl
, left
, top
, offset
);
727 TOOLBAR_DrawMasked (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
729 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
732 /* draws a blank frame for a toolbar button */
734 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
736 HDC hdc
= tbcd
->nmcd
.hdc
;
737 RECT rc
= tbcd
->nmcd
.rc
;
738 /* if the state is disabled or indeterminate then the button
739 * cannot have an interactive look like pressed or hot */
740 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
741 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
742 BOOL pressed_look
= !non_interactive_state
&&
743 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
744 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
746 /* app don't want us to draw any edges */
747 if (dwItemCDFlag
& TBCDRF_NOEDGES
)
750 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
753 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
754 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
755 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
760 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
762 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
763 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
768 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
, BOOL bDropDownPressed
, DWORD dwItemCDFlag
)
770 HDC hdc
= tbcd
->nmcd
.hdc
;
772 BOOL pressed
= bDropDownPressed
||
773 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
));
775 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
778 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
);
779 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
780 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
781 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
782 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
787 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
789 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
790 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
794 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
796 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
798 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
799 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
802 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
805 /* draws a complete toolbar button */
807 TOOLBAR_DrawButton (HWND hwnd
, TBUTTON_INFO
*btnPtr
, HDC hdc
, DWORD dwBaseCustDraw
)
809 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
810 DWORD dwStyle
= infoPtr
->dwStyle
;
811 BOOL hasDropDownArrow
= (TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) &&
812 (btnPtr
->fsStyle
& BTNS_DROPDOWN
)) ||
813 (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
814 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
815 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
816 RECT rc
, rcArrow
, rcBitmap
, rcText
;
817 LPWSTR lpText
= NULL
;
822 DWORD dwItemCustDraw
;
824 HTHEME theme
= GetWindowTheme (hwnd
);
827 CopyRect (&rcArrow
, &rc
);
829 /* separator - doesn't send NM_CUSTOMDRAW */
830 if (btnPtr
->fsStyle
& BTNS_SEP
) {
833 DrawThemeBackground (theme
, hdc
,
834 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
838 /* with the FLAT style, iBitmap is the width and has already */
839 /* been taken into consideration in calculating the width */
840 /* so now we need to draw the vertical separator */
841 /* empirical tests show that iBitmap can/will be non-zero */
842 /* when drawing the vertical bar... */
843 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
844 if (btnPtr
->fsStyle
& BTNS_DROPDOWN
)
845 TOOLBAR_DrawDDFlatSeparator (&rc
, hdc
, btnPtr
, infoPtr
);
847 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
849 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
850 FIXME("Draw some kind of separator: fsStyle=%x\n",
856 /* get a pointer to the text */
857 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
859 if (hasDropDownArrow
)
863 if (dwStyle
& TBSTYLE_FLAT
)
864 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
866 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
868 if (drawSepDropDownArrow
)
871 rcArrow
.left
= right
;
874 /* copy text & bitmap rects after adjusting for drop-down arrow
875 * so that text & bitmap is centred in the rectangle not containing
877 CopyRect(&rcText
, &rc
);
878 CopyRect(&rcBitmap
, &rc
);
880 /* Center the bitmap horizontally and vertically */
881 if (dwStyle
& TBSTYLE_LIST
)
884 infoPtr
->nMaxTextRows
> 0 &&
885 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
886 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
887 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
889 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
892 rcBitmap
.left
+= (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2;
894 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
896 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
897 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
898 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
899 TRACE("Text=%s\n", debugstr_w(lpText
));
900 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
902 /* calculate text position */
905 rcText
.left
+= GetSystemMetrics(SM_CXEDGE
);
906 rcText
.right
-= GetSystemMetrics(SM_CXEDGE
);
907 if (dwStyle
& TBSTYLE_LIST
)
909 if (TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
))
910 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
914 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
915 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
917 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
921 /* Initialize fields in all cases, because we use these later
922 * NOTE: applications can and do alter these to customize their
924 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
925 tbcd
.clrText
= comctl32_color
.clrBtnText
;
926 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
927 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
928 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
929 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
930 tbcd
.clrHighlightHotTrack
= 0;
931 tbcd
.nStringBkMode
= TRANSPARENT
;
932 tbcd
.nHLStringBkMode
= OPAQUE
;
933 /* MSDN says that this is the text rectangle.
934 * But (why always a but) tracing of v5.7 of native shows
935 * that this is really a *relative* rectangle based on the
936 * the nmcd.rc. Also the left and top are always 0 ignoring
937 * any bitmap that might be present. */
938 tbcd
.rcText
.left
= 0;
940 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
941 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
942 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
945 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
947 /* FIXME: what are these used for? */
951 /* Issue Item Prepaint notify */
954 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
956 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
957 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
958 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
959 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
960 /* reset these fields so the user can't alter the behaviour like native */
964 dwItemCustDraw
= ntfret
& 0xffff;
965 dwItemCDFlag
= ntfret
& 0xffff0000;
966 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
968 /* save the only part of the rect that the user can change */
969 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
970 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
973 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
974 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
975 OffsetRect(&rcText
, 1, 1);
977 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
978 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
979 TOOLBAR_DrawPattern (&rc
, &tbcd
);
981 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
982 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
984 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
988 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
989 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
990 if (hasDropDownArrow
)
991 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
992 SetBkColor(hdc
, oldclr
);
998 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
999 int stateId
= TS_NORMAL
;
1001 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1002 stateId
= TS_DISABLED
;
1003 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1004 stateId
= TS_PRESSED
;
1005 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1006 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1007 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1008 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1011 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &tbcd
.nmcd
.rc
, NULL
);
1014 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, dwItemCDFlag
);
1016 if (drawSepDropDownArrow
)
1020 int stateId
= TS_NORMAL
;
1022 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1023 stateId
= TS_DISABLED
;
1024 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1025 stateId
= TS_PRESSED
;
1026 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1027 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1028 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1031 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1032 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1035 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1038 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1039 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1040 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1041 SetBkMode (hdc
, oldBkMode
);
1043 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1045 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1047 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1049 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1050 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1052 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1054 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1055 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1058 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1061 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1063 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1064 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1071 TOOLBAR_Refresh (HWND hwnd
, HDC hdc
, PAINTSTRUCT
* ps
)
1073 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1074 TBUTTON_INFO
*btnPtr
;
1076 RECT rcTemp
, rcClient
;
1077 NMTBCUSTOMDRAW tbcd
;
1079 DWORD dwBaseCustDraw
;
1081 /* the app has told us not to redraw the toolbar */
1082 if (!infoPtr
->bDoRedraw
)
1085 /* if imagelist belongs to the app, it can be changed
1086 by the app after setting it */
1087 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1089 infoPtr
->nNumBitmaps
= 0;
1090 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1091 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1094 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1096 /* change the imagelist icon size if we manage the list and it is necessary */
1097 TOOLBAR_CheckImageListIconSize(infoPtr
);
1099 /* Send initial notify */
1100 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1101 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1102 tbcd
.nmcd
.hdc
= hdc
;
1103 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1104 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1105 dwBaseCustDraw
= ntfret
& 0xffff;
1107 GetClientRect(hwnd
, &rcClient
);
1109 /* redraw necessary buttons */
1110 btnPtr
= infoPtr
->buttons
;
1111 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1114 if (!RectVisible(hdc
, &btnPtr
->rect
))
1116 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1118 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1119 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1123 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1124 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1126 TOOLBAR_DrawButton(hwnd
, btnPtr
, hdc
, dwBaseCustDraw
);
1129 /* draw insert mark if required */
1130 if (infoPtr
->tbim
.iButton
!= -1)
1132 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1134 rcInsertMark
.top
= rcButton
.top
;
1135 rcInsertMark
.bottom
= rcButton
.bottom
;
1136 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1137 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1139 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1140 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1143 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1145 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1146 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1147 tbcd
.nmcd
.hdc
= hdc
;
1148 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1149 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1153 /***********************************************************************
1154 * TOOLBAR_MeasureString
1156 * This function gets the width and height of a string in pixels. This
1157 * is done first by using GetTextExtentPoint to get the basic width
1158 * and height. The DrawText is called with DT_CALCRECT to get the exact
1159 * width. The reason is because the text may have more than one "&" (or
1160 * prefix characters as M$ likes to call them). The prefix character
1161 * indicates where the underline goes, except for the string "&&" which
1162 * is reduced to a single "&". GetTextExtentPoint does not process these
1163 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1166 TOOLBAR_MeasureString(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
,
1167 HDC hdc
, LPSIZE lpSize
)
1174 if (infoPtr
->nMaxTextRows
> 0 &&
1175 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1176 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1177 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1179 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1181 if(lpText
!= NULL
) {
1182 /* first get size of all the text */
1183 GetTextExtentPoint32W (hdc
, lpText
, strlenW (lpText
), lpSize
);
1185 /* feed above size into the rectangle for DrawText */
1186 myrect
.left
= myrect
.top
= 0;
1187 myrect
.right
= lpSize
->cx
;
1188 myrect
.bottom
= lpSize
->cy
;
1190 /* Use DrawText to get true size as drawn (less pesky "&") */
1191 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1192 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1195 /* feed back to caller */
1196 lpSize
->cx
= myrect
.right
;
1197 lpSize
->cy
= myrect
.bottom
;
1201 TRACE("string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1204 /***********************************************************************
1205 * TOOLBAR_CalcStrings
1207 * This function walks through each string and measures it and returns
1208 * the largest height and width to caller.
1211 TOOLBAR_CalcStrings (HWND hwnd
, LPSIZE lpSize
)
1213 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1214 TBUTTON_INFO
*btnPtr
;
1223 if (infoPtr
->nMaxTextRows
== 0)
1227 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1229 if (infoPtr
->nNumButtons
== 0)
1233 GetTextMetricsW(hdc
, &tm
);
1234 lpSize
->cy
= tm
.tmHeight
;
1237 btnPtr
= infoPtr
->buttons
;
1238 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1239 if(TOOLBAR_HasText(infoPtr
, btnPtr
))
1241 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1242 if (sz
.cx
> lpSize
->cx
)
1244 if (sz
.cy
> lpSize
->cy
)
1249 SelectObject (hdc
, hOldFont
);
1250 ReleaseDC (hwnd
, hdc
);
1252 TRACE("max string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1255 /***********************************************************************
1256 * TOOLBAR_WrapToolbar
1258 * This function walks through the buttons and separators in the
1259 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1260 * wrapping should occur based on the width of the toolbar window.
1261 * It does *not* calculate button placement itself. That task
1262 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1263 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1264 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1266 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1267 * vertical toolbar lists.
1271 TOOLBAR_WrapToolbar( HWND hwnd
, DWORD dwStyle
)
1273 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1274 TBUTTON_INFO
*btnPtr
;
1277 BOOL bWrap
, bButtonWrap
;
1279 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1280 /* no layout is necessary. Applications may use this style */
1281 /* to perform their own layout on the toolbar. */
1282 if( !(dwStyle
& TBSTYLE_WRAPABLE
) &&
1283 !(infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
) ) return;
1285 btnPtr
= infoPtr
->buttons
;
1286 x
= infoPtr
->nIndent
;
1288 if (GetParent(hwnd
))
1290 /* this can get the parents width, to know how far we can extend
1291 * this toolbar. We cannot use its height, as there may be multiple
1292 * toolbars in a rebar control
1294 GetClientRect( GetParent(hwnd
), &rc
);
1295 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1299 GetWindowRect( hwnd
, &rc
);
1300 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1303 bButtonWrap
= FALSE
;
1305 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1306 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, infoPtr
->nWidth
,
1309 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1312 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1314 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1317 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1318 /* it is the actual width of the separator. This is used for */
1319 /* custom controls in toolbars. */
1321 /* BTNS_DROPDOWN separators are treated as buttons for */
1322 /* width. - GA 8/01 */
1323 if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1324 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
))
1325 cx
= (btnPtr
[i
].iBitmap
> 0) ?
1326 btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1328 cx
= infoPtr
->nButtonWidth
;
1330 /* Two or more adjacent separators form a separator group. */
1331 /* The first separator in a group should be wrapped to the */
1332 /* next row if the previous wrapping is on a button. */
1334 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1335 (i
+ 1 < infoPtr
->nNumButtons
) &&
1336 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1338 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1339 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1340 x
= infoPtr
->nIndent
;
1342 bButtonWrap
= FALSE
;
1346 /* The layout makes sure the bitmap is visible, but not the button. */
1347 /* Test added to also wrap after a button that starts a row but */
1348 /* is bigger than the area. - GA 8/01 */
1349 if (( x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2
1350 > infoPtr
->nWidth
) ||
1351 ((x
== infoPtr
->nIndent
) && (cx
> infoPtr
->nWidth
)))
1353 BOOL bFound
= FALSE
;
1355 /* If the current button is a separator and not hidden, */
1356 /* go to the next until it reaches a non separator. */
1357 /* Wrap the last separator if it is before a button. */
1358 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1359 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1360 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1361 i
< infoPtr
->nNumButtons
)
1367 if( bFound
&& i
< infoPtr
->nNumButtons
)
1370 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1371 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1372 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1373 x
= infoPtr
->nIndent
;
1374 bButtonWrap
= FALSE
;
1377 else if ( i
>= infoPtr
->nNumButtons
)
1380 /* If the current button is not a separator, find the last */
1381 /* separator and wrap it. */
1382 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1384 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1385 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1389 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1390 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1391 x
= infoPtr
->nIndent
;
1392 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1393 bButtonWrap
= FALSE
;
1398 /* If no separator available for wrapping, wrap one of */
1399 /* non-hidden previous button. */
1403 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1405 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1410 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1411 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1412 x
= infoPtr
->nIndent
;
1413 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1419 /* If all above failed, wrap the current button. */
1422 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1423 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1424 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1426 x
= infoPtr
->nIndent
;
1427 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1428 bButtonWrap
= FALSE
;
1434 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1435 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1442 /***********************************************************************
1443 * TOOLBAR_MeasureButton
1445 * Calculates the width and height required for a button. Used in
1446 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1447 * the width of buttons that are autosized.
1449 * Note that it would have been rather elegant to use one piece of code for
1450 * both the laying out of the toolbar and for controlling where button parts
1451 * are drawn, but the native control has inconsistencies between the two that
1452 * prevent this from being effectively. These inconsistencies can be seen as
1453 * artefacts where parts of the button appear outside of the bounding button
1456 * There are several cases for the calculation of the button dimensions and
1457 * button part positioning:
1464 * +--------------------------------------------------------+ ^
1466 * | | pad.cy / 2 | centred | |
1467 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1468 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1469 * | |<------------>| | | | |
1470 * | +--------------+ +------------+ | |
1471 * |<-------------------------------------->| | |
1472 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1474 * +--------------------------------------------------------+ -
1475 * <-------------------------------------------------------->
1476 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1478 * Without Bitmap (I_IMAGENONE):
1480 * +-----------------------------------+ ^
1482 * | | centred | | LISTPAD_CY +
1483 * | +------------+ | | szText.cy
1486 * | +------------+ | |
1487 * |<----------------->| | |
1488 * | cxedge |<-----------> | |
1490 * +-----------------------------------+ -
1491 * <----------------------------------->
1492 * szText.cx + pad.cx
1496 * +--------------------------------------+ ^
1498 * | | padding.cy/2 | | DEFPAD_CY +
1499 * | +------------+ | | nBitmapHeight
1502 * | +------------+ | |
1503 * |<------------------->| | |
1504 * | cxedge + iListGap/2 |<-----------> | |
1505 * | nBitmapWidth | |
1506 * +--------------------------------------+ -
1507 * <-------------------------------------->
1508 * 2*cxedge + nBitmapWidth + iListGap
1515 * +-----------------------------------+ ^
1517 * | | pad.cy / 2 | | nBitmapHeight +
1518 * | - | | szText.cy +
1519 * | +------------+ | | DEFPAD_CY + 1
1520 * | centred | Bitmap | | |
1521 * |<----------------->| | | |
1522 * | +------------+ | |
1526 * | centred +---------------+ | |
1527 * |<--------------->| Text | | |
1528 * | +---------------+ | |
1529 * +-----------------------------------+ -
1530 * <----------------------------------->
1531 * pad.cx + max(nBitmapWidth, szText.cx)
1533 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1535 * +---------------------------------------+ ^
1537 * | | 2 + pad.cy / 2 | |
1538 * | - | | szText.cy +
1539 * | centred +-----------------+ | | pad.cy + 2
1540 * |<--------------->| Text | | |
1541 * | +-----------------+ | |
1543 * +---------------------------------------+ -
1544 * <--------------------------------------->
1545 * 2*cxedge + pad.cx + szText.cx
1548 * As for with bitmaps, but with szText.cx zero.
1550 static inline SIZE
TOOLBAR_MeasureButton(TOOLBAR_INFO
*infoPtr
, SIZE sizeString
, BOOL bHasBitmap
, BOOL bValidImageList
)
1553 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1555 /* set button height from bitmap / text height... */
1556 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1559 /* ... add on the necessary padding */
1560 if (bValidImageList
)
1563 sizeButton
.cy
+= DEFPAD_CY
;
1565 sizeButton
.cy
+= LISTPAD_CY
;
1568 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1570 /* calculate button width */
1573 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1574 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1575 if (sizeString
.cx
> 0)
1576 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1579 sizeButton
.cx
= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1585 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ 1 +
1586 sizeString
.cy
+ DEFPAD_CY
;
1587 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1588 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1592 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1593 NONLIST_NOTEXT_OFFSET
;
1594 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1595 infoPtr
->szPadding
.cx
+ sizeString
.cx
;
1602 /***********************************************************************
1603 * TOOLBAR_CalcToolbar
1605 * This function calculates button and separator placement. It first
1606 * calculates the button sizes, gets the toolbar window width and then
1607 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1608 * on. It assigns a new location to each item and sends this location to
1609 * the tooltip window if appropriate. Finally, it updates the rcBound
1610 * rect and calculates the new required toolbar window height.
1613 TOOLBAR_CalcToolbar (HWND hwnd
)
1615 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
1616 DWORD dwStyle
= infoPtr
->dwStyle
;
1617 TBUTTON_INFO
*btnPtr
;
1618 INT i
, nRows
, nSepRows
;
1620 SIZE sizeString
, sizeButton
;
1622 BOOL validImageList
= FALSE
;
1623 BOOL hasDropDownArrows
= TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
);
1625 TOOLBAR_CalcStrings (hwnd
, &sizeString
);
1627 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1629 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1630 validImageList
= TRUE
;
1631 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1632 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1633 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1635 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1636 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1637 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1638 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1640 TOOLBAR_WrapToolbar( hwnd
, dwStyle
);
1642 x
= infoPtr
->nIndent
;
1643 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
1648 /* from above, minimum is a button, and possible text */
1649 cx
= infoPtr
->nButtonWidth
;
1650 cy
= infoPtr
->nButtonHeight
;
1652 nRows
= nSepRows
= 0;
1654 infoPtr
->rcBound
.top
= y
;
1655 infoPtr
->rcBound
.left
= x
;
1656 infoPtr
->rcBound
.bottom
= y
+ cy
;
1657 infoPtr
->rcBound
.right
= x
;
1659 btnPtr
= infoPtr
->buttons
;
1661 TRACE("cy=%d\n", cy
);
1663 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1666 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1668 SetRectEmpty (&btnPtr
->rect
);
1672 cy
= infoPtr
->nButtonHeight
;
1674 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1675 /* it is the actual width of the separator. This is used for */
1676 /* custom controls in toolbars. */
1677 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1678 if (btnPtr
->fsStyle
& BTNS_DROPDOWN
) {
1679 cy
= (btnPtr
->iBitmap
> 0) ?
1680 btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1681 cx
= infoPtr
->nButtonWidth
;
1684 cx
= (btnPtr
->iBitmap
> 0) ?
1685 btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1691 else if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1692 (btnPtr
->fsStyle
& BTNS_AUTOSIZE
))
1699 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1701 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1703 SelectObject (hdc
, hOldFont
);
1704 ReleaseDC (hwnd
, hdc
);
1706 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1707 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1712 cx
= infoPtr
->nButtonWidth
;
1714 /* if size has been set manually then don't add on extra space
1715 * for the drop down arrow */
1716 if (!btnPtr
->cx
&& hasDropDownArrows
&&
1717 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) || (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)))
1718 cx
+= DDARROW_WIDTH
;
1720 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1723 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1725 if (infoPtr
->rcBound
.left
> x
)
1726 infoPtr
->rcBound
.left
= x
;
1727 if (infoPtr
->rcBound
.right
< x
+ cx
)
1728 infoPtr
->rcBound
.right
= x
+ cx
;
1729 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1730 infoPtr
->rcBound
.bottom
= y
+ cy
;
1732 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1734 /* btnPtr->nRow is zero based. The space between the rows is */
1735 /* also considered as a row. */
1736 btnPtr
->nRow
= nRows
+ nSepRows
;
1738 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1739 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1744 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1748 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1749 /* it is the actual width of the separator. This is used for */
1750 /* custom controls in toolbars. */
1751 if ( !(btnPtr
->fsStyle
& BTNS_DROPDOWN
))
1752 y
+= cy
+ ( (btnPtr
->iBitmap
> 0 ) ?
1753 btnPtr
->iBitmap
: SEPARATOR_WIDTH
) * 2 /3;
1757 /* nSepRows is used to calculate the extra height follwoing */
1761 x
= infoPtr
->nIndent
;
1763 /* Increment row number unless this is the last button */
1764 /* and it has Wrap set. */
1765 if (i
!= infoPtr
->nNumButtons
-1)
1772 /* infoPtr->nRows is the number of rows on the toolbar */
1773 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1775 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1780 TOOLBAR_InternalHitTest (HWND hwnd
, LPPOINT lpPt
)
1782 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1783 TBUTTON_INFO
*btnPtr
;
1786 btnPtr
= infoPtr
->buttons
;
1787 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1788 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1791 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1792 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1793 TRACE(" ON SEPARATOR %d!\n", i
);
1798 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1799 TRACE(" ON BUTTON %d!\n", i
);
1805 TRACE(" NOWHERE!\n");
1806 return TOOLBAR_NOWHERE
;
1811 TOOLBAR_GetButtonIndex (TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1813 TBUTTON_INFO
*btnPtr
;
1816 if (CommandIsIndex
) {
1817 TRACE("command is really index command=%d\n", idCommand
);
1818 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1821 btnPtr
= infoPtr
->buttons
;
1822 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1823 if (btnPtr
->idCommand
== idCommand
) {
1824 TRACE("command=%d index=%d\n", idCommand
, i
);
1828 TRACE("no index found for command=%d\n", idCommand
);
1834 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1836 TBUTTON_INFO
*btnPtr
;
1839 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1842 /* check index button */
1843 btnPtr
= &infoPtr
->buttons
[nIndex
];
1844 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1845 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1849 /* check previous buttons */
1850 nRunIndex
= nIndex
- 1;
1851 while (nRunIndex
>= 0) {
1852 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1853 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1854 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1862 /* check next buttons */
1863 nRunIndex
= nIndex
+ 1;
1864 while (nRunIndex
< infoPtr
->nNumButtons
) {
1865 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1866 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1867 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1880 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1881 WPARAM wParam
, LPARAM lParam
)
1887 msg
.wParam
= wParam
;
1888 msg
.lParam
= lParam
;
1889 msg
.time
= GetMessageTime ();
1890 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
1891 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
1893 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1897 TOOLBAR_TooltipAddTool(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*button
)
1899 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
1902 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
1903 ti
.cbSize
= sizeof (TTTOOLINFOW
);
1904 ti
.hwnd
= infoPtr
->hwndSelf
;
1905 ti
.uId
= button
->idCommand
;
1907 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
1908 /* ti.lParam = random value from the stack? */
1910 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
1916 TOOLBAR_TooltipDelTool(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*button
)
1918 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
1921 ZeroMemory(&ti
, sizeof(ti
));
1922 ti
.cbSize
= sizeof(ti
);
1923 ti
.hwnd
= infoPtr
->hwndSelf
;
1924 ti
.uId
= button
->idCommand
;
1926 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
1930 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*button
)
1932 /* Set the toolTip only for non-hidden, non-separator button */
1933 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
;
1941 ti
.rect
= button
->rect
;
1942 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
1946 /* Creates the tooltip control */
1948 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
1951 NMTOOLTIPSCREATED nmttc
;
1953 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
1954 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1955 infoPtr
->hwndSelf
, 0, 0, 0);
1957 if (!infoPtr
->hwndToolTip
)
1960 /* Send NM_TOOLTIPSCREATED notification */
1961 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
1962 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
1964 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
1966 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
1967 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
1971 /* keeps available button list box sorted by button id */
1972 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
1976 PCUSTOMBUTTON btnInfo
;
1977 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
1979 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
1981 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
1983 /* position 0 is always separator */
1984 for (i
= 1; i
< count
; i
++)
1986 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
1987 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
1989 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
1990 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
1994 /* id higher than all others add to end */
1995 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
1996 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
1999 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2003 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2005 if (nIndexFrom
== nIndexTo
)
2008 /* MSDN states that iItem is the index of the button, rather than the
2009 * command ID as used by every other NMTOOLBAR notification */
2010 nmtb
.iItem
= nIndexFrom
;
2011 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2013 PCUSTOMBUTTON btnInfo
;
2015 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2016 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2018 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2020 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2021 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2022 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2023 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2026 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2028 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2030 /* last item is always separator, so -2 instead of -1 */
2031 if (nIndexTo
>= (count
- 2))
2032 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2034 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2036 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2037 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2039 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2043 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2047 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2049 /* MSDN states that iItem is the index of the button, rather than the
2050 * command ID as used by every other NMTOOLBAR notification */
2051 nmtb
.iItem
= nIndexAvail
;
2052 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2054 PCUSTOMBUTTON btnInfo
;
2056 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2057 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2058 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2060 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2062 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2064 /* remove from 'available buttons' list */
2065 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2066 if (nIndexAvail
== count
-1)
2067 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2069 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2073 PCUSTOMBUTTON btnNew
;
2075 /* duplicate 'separator' button */
2076 btnNew
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2077 memcpy(btnNew
, btnInfo
, sizeof(CUSTOMBUTTON
));
2081 /* insert into 'toolbar button' list */
2082 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2083 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2085 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2087 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2091 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo
, HWND hwnd
, INT index
)
2093 PCUSTOMBUTTON btnInfo
;
2094 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2096 TRACE("Remove: index %d\n", index
);
2098 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2100 /* send TBN_QUERYDELETE notification */
2101 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2105 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2106 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2108 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2110 /* insert into 'available button' list */
2111 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2112 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2116 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2120 /* drag list notification function for toolbar buttons list box */
2121 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo
, HWND hwnd
, DRAGLISTINFO
*pDLI
)
2123 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2124 switch (pDLI
->uNotification
)
2128 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2129 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2130 /* no dragging for last item (separator) */
2131 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2136 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2137 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2138 /* no dragging past last item (separator) */
2139 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2141 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2142 /* FIXME: native uses "move button" cursor */
2143 return DL_COPYCURSOR
;
2146 /* not over toolbar buttons list */
2147 if (nCurrentItem
< 0)
2149 POINT ptWindow
= pDLI
->ptCursor
;
2150 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2151 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2152 /* over available buttons list? */
2153 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2154 /* FIXME: native uses "move button" cursor */
2155 return DL_COPYCURSOR
;
2157 /* clear drag arrow */
2158 DrawInsert(hwnd
, hwndList
, -1);
2159 return DL_STOPCURSOR
;
2163 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2164 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2165 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2166 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2168 /* clear drag arrow */
2169 DrawInsert(hwnd
, hwndList
, -1);
2171 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2173 /* not over toolbar buttons list */
2176 POINT ptWindow
= pDLI
->ptCursor
;
2177 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2178 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2179 /* over available buttons list? */
2180 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2181 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2186 /* Clear drag arrow */
2187 DrawInsert(hwnd
, hwndList
, -1);
2194 /* drag list notification function for available buttons list box */
2195 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo
, HWND hwnd
, DRAGLISTINFO
*pDLI
)
2197 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2198 switch (pDLI
->uNotification
)
2204 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2205 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2206 /* no dragging past last item (separator) */
2207 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2209 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2210 /* FIXME: native uses "move button" cursor */
2211 return DL_COPYCURSOR
;
2214 /* not over toolbar buttons list */
2215 if (nCurrentItem
< 0)
2217 POINT ptWindow
= pDLI
->ptCursor
;
2218 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2219 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2220 /* over available buttons list? */
2221 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2222 /* FIXME: native uses "move button" cursor */
2223 return DL_COPYCURSOR
;
2225 /* clear drag arrow */
2226 DrawInsert(hwnd
, hwndList
, -1);
2227 return DL_STOPCURSOR
;
2231 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2232 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2233 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2234 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2236 /* clear drag arrow */
2237 DrawInsert(hwnd
, hwndList
, -1);
2239 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2243 /* Clear drag arrow */
2244 DrawInsert(hwnd
, hwndList
, -1);
2250 extern UINT uDragListMessage
;
2252 /***********************************************************************
2253 * TOOLBAR_CustomizeDialogProc
2254 * This function implements the toolbar customization dialog.
2256 static INT_PTR CALLBACK
2257 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2259 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2260 PCUSTOMBUTTON btnInfo
;
2262 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2267 custInfo
= (PCUSTDLG_INFO
)lParam
;
2268 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2275 NMTBINITCUSTOMIZE nmtbic
;
2277 infoPtr
= custInfo
->tbInfo
;
2279 /* send TBN_QUERYINSERT notification */
2280 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2282 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2285 nmtbic
.hwndDialog
= hwnd
;
2286 /* Send TBN_INITCUSTOMIZE notification */
2287 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2290 TRACE("TBNRF_HIDEHELP requested\n");
2291 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2294 /* add items to 'toolbar buttons' list and check if removable */
2295 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2297 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2298 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2299 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2300 btnInfo
->bVirtual
= FALSE
;
2301 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2303 /* send TBN_QUERYDELETE notification */
2304 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2306 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2307 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2310 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2312 /* insert separator button into 'available buttons' list */
2313 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2314 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2315 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2316 btnInfo
->bVirtual
= FALSE
;
2317 btnInfo
->bRemovable
= TRUE
;
2318 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2319 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2320 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2322 /* insert all buttons into dsa */
2325 /* send TBN_GETBUTTONINFO notification */
2328 nmtb
.pszText
= Buffer
;
2331 /* Clear previous button's text */
2332 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2334 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2337 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2338 nmtb
.tbButton
.fsStyle
, i
,
2339 nmtb
.tbButton
.idCommand
,
2340 nmtb
.tbButton
.iString
,
2341 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2344 /* insert button into the apropriate list */
2345 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2348 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2349 btnInfo
->bVirtual
= FALSE
;
2350 btnInfo
->bRemovable
= TRUE
;
2354 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2355 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2358 memcpy (&btnInfo
->btn
, &nmtb
.tbButton
, sizeof(TBBUTTON
));
2359 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2361 if (lstrlenW(nmtb
.pszText
))
2362 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2363 else if (nmtb
.tbButton
.iString
>= 0 &&
2364 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2366 lstrcpyW(btnInfo
->text
,
2367 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2372 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2375 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2377 /* select first item in the 'available' list */
2378 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2380 /* append 'virtual' separator button to the 'toolbar buttons' list */
2381 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2382 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2383 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2384 btnInfo
->bVirtual
= TRUE
;
2385 btnInfo
->bRemovable
= FALSE
;
2386 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2387 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2388 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2390 /* select last item in the 'toolbar' list */
2391 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2392 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2394 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2395 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2397 /* set focus and disable buttons */
2398 PostMessageW (hwnd
, WM_USER
, 0, 0);
2403 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2404 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2405 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2406 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2410 EndDialog(hwnd
, FALSE
);
2414 switch (LOWORD(wParam
))
2416 case IDC_TOOLBARBTN_LBOX
:
2417 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2419 PCUSTOMBUTTON btnInfo
;
2424 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2425 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2427 /* send TBN_QUERYINSERT notification */
2429 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2431 /* get list box item */
2432 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2434 if (index
== (count
- 1))
2436 /* last item (virtual separator) */
2437 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2438 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2440 else if (index
== (count
- 2))
2442 /* second last item (last non-virtual item) */
2443 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2444 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2446 else if (index
== 0)
2449 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2450 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2454 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2455 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2458 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2462 case IDC_MOVEUP_BTN
:
2464 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2465 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2469 case IDC_MOVEDN_BTN
: /* move down */
2471 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2472 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2476 case IDC_REMOVE_BTN
: /* remove button */
2478 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2480 if (LB_ERR
== index
)
2483 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2487 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2490 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2493 case IDOK
: /* Add button */
2498 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2499 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2501 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2506 EndDialog(hwnd
, FALSE
);
2516 /* delete items from 'toolbar buttons' listbox*/
2517 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2518 for (i
= 0; i
< count
; i
++)
2520 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2522 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2524 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2527 /* delete items from 'available buttons' listbox*/
2528 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2529 for (i
= 0; i
< count
; i
++)
2531 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2533 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2535 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2540 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2542 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2547 COLORREF oldText
= 0;
2551 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, (WPARAM
)lpdis
->itemID
, 0);
2552 if (btnInfo
== NULL
)
2554 FIXME("btnInfo invalid!\n");
2558 /* set colors and select objects */
2559 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2560 if (btnInfo
->bVirtual
)
2561 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2563 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2564 hPen
= CreatePen( PS_SOLID
, 1,
2565 GetSysColor( (lpdis
->itemState
& ODS_SELECTED
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2566 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2567 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2569 /* fill background rectangle */
2570 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2571 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2573 /* calculate button and text rectangles */
2574 CopyRect (&rcButton
, &lpdis
->rcItem
);
2575 InflateRect (&rcButton
, -1, -1);
2576 CopyRect (&rcText
, &rcButton
);
2577 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2578 rcText
.left
= rcButton
.right
+ 2;
2580 /* draw focus rectangle */
2581 if (lpdis
->itemState
& ODS_FOCUS
)
2582 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2585 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2586 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2588 /* draw image and text */
2589 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2590 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2591 btnInfo
->btn
.iBitmap
));
2592 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2593 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2595 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2596 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2598 /* delete objects and reset colors */
2599 SelectObject (lpdis
->hDC
, hOldBrush
);
2600 SelectObject (lpdis
->hDC
, hOldPen
);
2601 SetBkColor (lpdis
->hDC
, oldBk
);
2602 SetTextColor (lpdis
->hDC
, oldText
);
2603 DeleteObject( hPen
);
2608 case WM_MEASUREITEM
:
2609 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2611 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2613 lpmis
->itemHeight
= 15 + 8; /* default height */
2620 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2622 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2624 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2625 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2626 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2629 else if (wParam
== IDC_AVAILBTN_LBOX
)
2631 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2632 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2633 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2642 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2645 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2651 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2652 /* Add bitmaps to the default image list */
2653 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2656 HBITMAP hOldBitmapBitmap
, hOldBitmapLoad
;
2657 HDC hdcImage
, hdcBitmap
;
2659 /* copy the bitmap before adding it so that the user's bitmap
2660 * doesn't get modified.
2662 GetObjectW ((HBITMAP
)bitmap
->nID
, sizeof(BITMAP
), (LPVOID
)&bmp
);
2664 hdcImage
= CreateCompatibleDC(0);
2665 hdcBitmap
= CreateCompatibleDC(0);
2667 /* create new bitmap */
2668 hbmLoad
= CreateBitmap (bmp
.bmWidth
, bmp
.bmHeight
, bmp
.bmPlanes
, bmp
.bmBitsPixel
, NULL
);
2669 hOldBitmapBitmap
= SelectObject(hdcBitmap
, (HBITMAP
)bitmap
->nID
);
2670 hOldBitmapLoad
= SelectObject(hdcImage
, hbmLoad
);
2672 /* Copy the user's image */
2673 BitBlt (hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
,
2674 hdcBitmap
, 0, 0, SRCCOPY
);
2676 SelectObject (hdcImage
, hOldBitmapLoad
);
2677 SelectObject (hdcBitmap
, hOldBitmapBitmap
);
2678 DeleteDC (hdcImage
);
2679 DeleteDC (hdcBitmap
);
2682 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2684 /* enlarge the bitmap if needed */
2685 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2686 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2688 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2689 DeleteObject(hbmLoad
);
2693 nCountAfter
= ImageList_GetImageCount(himlDef
);
2694 nAdded
= nCountAfter
- nCountBefore
;
2695 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2697 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2698 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2699 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2700 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2703 infoPtr
->nNumBitmaps
+= nAdded
;
2708 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2715 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2716 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2718 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2720 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2723 TRACE("Update icon size: %dx%d -> %dx%d\n",
2724 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2726 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2727 ILC_COLORDDB
|ILC_MASK
, 8, 2);
2728 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2729 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2730 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2731 infoPtr
->himlInt
= himlNew
;
2733 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2734 ImageList_Destroy(himlDef
);
2737 /***********************************************************************
2738 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2742 TOOLBAR_AddBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2744 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2745 LPTBADDBITMAP lpAddBmp
= (LPTBADDBITMAP
)lParam
;
2750 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd
, wParam
, lParam
);
2754 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2756 info
.hInst
= COMCTL32_hModule
;
2757 switch (lpAddBmp
->nID
)
2759 case IDB_STD_SMALL_COLOR
:
2761 info
.nID
= IDB_STD_SMALL
;
2763 case IDB_STD_LARGE_COLOR
:
2765 info
.nID
= IDB_STD_LARGE
;
2767 case IDB_VIEW_SMALL_COLOR
:
2769 info
.nID
= IDB_VIEW_SMALL
;
2771 case IDB_VIEW_LARGE_COLOR
:
2773 info
.nID
= IDB_VIEW_LARGE
;
2775 case IDB_HIST_SMALL_COLOR
:
2777 info
.nID
= IDB_HIST_SMALL
;
2779 case IDB_HIST_LARGE_COLOR
:
2781 info
.nID
= IDB_HIST_LARGE
;
2787 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2789 /* Windows resize all the buttons to the size of a newly added standard image */
2790 if (lpAddBmp
->nID
& 1)
2793 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2794 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2796 SendMessageW (hwnd
, TB_SETBITMAPSIZE
, 0,
2797 MAKELPARAM((WORD
)24, (WORD
)24));
2798 SendMessageW (hwnd
, TB_SETBUTTONSIZE
, 0,
2799 MAKELPARAM((WORD
)31, (WORD
)30));
2804 SendMessageW (hwnd
, TB_SETBITMAPSIZE
, 0,
2805 MAKELPARAM((WORD
)16, (WORD
)16));
2806 SendMessageW (hwnd
, TB_SETBUTTONSIZE
, 0,
2807 MAKELPARAM((WORD
)22, (WORD
)22));
2810 TOOLBAR_CalcToolbar (hwnd
);
2814 info
.nButtons
= (INT
)wParam
;
2815 info
.hInst
= lpAddBmp
->hInst
;
2816 info
.nID
= lpAddBmp
->nID
;
2817 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2820 /* check if the bitmap is already loaded and compute iSumButtons */
2822 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2824 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2825 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2827 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2830 if (!infoPtr
->cimlDef
) {
2831 /* create new default image list */
2832 TRACE ("creating default image list!\n");
2834 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2835 ILC_COLORDDB
| ILC_MASK
, info
.nButtons
, 2);
2836 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2837 infoPtr
->himlInt
= himlDef
;
2840 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2844 WARN("No default image list available\n");
2848 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2851 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2852 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2853 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2854 infoPtr
->nNumBitmapInfos
++;
2855 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2857 InvalidateRect(hwnd
, NULL
, TRUE
);
2863 TOOLBAR_AddButtonsT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL fUnicode
)
2865 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2866 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
2867 INT nOldButtons
, nNewButtons
, nAddButtons
, nCount
;
2869 TRACE("adding %d buttons (unicode=%d)!\n", wParam
, fUnicode
);
2871 nAddButtons
= (UINT
)wParam
;
2872 nOldButtons
= infoPtr
->nNumButtons
;
2873 nNewButtons
= nOldButtons
+ nAddButtons
;
2875 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
2876 infoPtr
->nNumButtons
= nNewButtons
;
2878 /* insert new button data */
2879 for (nCount
= 0; nCount
< nAddButtons
; nCount
++) {
2880 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nOldButtons
+nCount
];
2881 btnPtr
->iBitmap
= lpTbb
[nCount
].iBitmap
;
2882 btnPtr
->idCommand
= lpTbb
[nCount
].idCommand
;
2883 btnPtr
->fsState
= lpTbb
[nCount
].fsState
;
2884 btnPtr
->fsStyle
= lpTbb
[nCount
].fsStyle
;
2885 btnPtr
->dwData
= lpTbb
[nCount
].dwData
;
2886 btnPtr
->bHot
= FALSE
;
2887 if(HIWORD(lpTbb
[nCount
].iString
) && lpTbb
[nCount
].iString
!= -1)
2890 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, (LPWSTR
)lpTbb
[nCount
].iString
);
2892 Str_SetPtrAtoW((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lpTbb
[nCount
].iString
);
2895 btnPtr
->iString
= lpTbb
[nCount
].iString
;
2897 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
2900 TOOLBAR_CalcToolbar (hwnd
);
2901 TOOLBAR_AutoSize (hwnd
);
2903 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
2905 InvalidateRect(hwnd
, NULL
, TRUE
);
2912 TOOLBAR_AddStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2914 #define MAX_RESOURCE_STRING_LENGTH 512
2915 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2916 INT nIndex
= infoPtr
->nNumStrings
;
2918 if ((wParam
) && (HIWORD(lParam
) == 0)) {
2919 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2924 TRACE("adding string from resource!\n");
2926 len
= LoadStringW ((HINSTANCE
)wParam
, (UINT
)lParam
,
2927 szString
, MAX_RESOURCE_STRING_LENGTH
);
2929 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2930 if (len
== 0 || len
== 1)
2933 TRACE("Delimiter: 0x%x\n", *szString
);
2934 delimiter
= *szString
;
2937 while ((next_delim
= strchrW(p
, delimiter
)) != NULL
) {
2939 if (next_delim
+ 1 >= szString
+ len
)
2941 /* this may happen if delimiter == '\0' or if the last char is a
2942 * delimiter (then it is ignored like the native does) */
2946 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2947 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2948 infoPtr
->nNumStrings
++;
2954 LPWSTR p
= (LPWSTR
)lParam
;
2959 TRACE("adding string(s) from array!\n");
2963 TRACE("len=%d %s\n", len
, debugstr_w(p
));
2964 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2965 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2966 infoPtr
->nNumStrings
++;
2977 TOOLBAR_AddStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2979 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2984 if ((wParam
) && (HIWORD(lParam
) == 0)) /* load from resources */
2985 return TOOLBAR_AddStringW(hwnd
, wParam
, lParam
);
2991 TRACE("adding string(s) from array!\n");
2992 nIndex
= infoPtr
->nNumStrings
;
2995 TRACE("len=%d \"%s\"\n", len
, p
);
2997 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2998 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2999 infoPtr
->nNumStrings
++;
3009 TOOLBAR_AutoSize (HWND hwnd
)
3011 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3017 TRACE("auto sizing, style=%x!\n", infoPtr
->dwStyle
);
3019 parent
= GetParent (hwnd
);
3021 if (!parent
|| !infoPtr
->bDoRedraw
)
3024 GetClientRect(parent
, &parent_rect
);
3026 x
= parent_rect
.left
;
3027 y
= parent_rect
.top
;
3029 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3031 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3032 cx
= parent_rect
.right
- parent_rect
.left
;
3034 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
))
3036 TOOLBAR_CalcToolbar(hwnd
);
3037 InvalidateRect( hwnd
, NULL
, TRUE
);
3040 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3043 UINT uPosFlags
= SWP_NOZORDER
;
3045 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3047 GetWindowRect(hwnd
, &window_rect
);
3048 ScreenToClient(parent
, (LPPOINT
)&window_rect
.left
);
3049 y
= window_rect
.top
;
3051 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3053 GetWindowRect(hwnd
, &window_rect
);
3054 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3057 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3058 uPosFlags
|= SWP_NOMOVE
;
3060 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3061 cy
+= GetSystemMetrics(SM_CYEDGE
);
3063 if (infoPtr
->dwStyle
& WS_BORDER
)
3065 x
= y
= 1; /* FIXME: this looks wrong */
3066 cy
+= GetSystemMetrics(SM_CYEDGE
);
3067 cx
+= GetSystemMetrics(SM_CXEDGE
);
3070 SetWindowPos(hwnd
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3078 TOOLBAR_ButtonCount (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3080 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3082 return infoPtr
->nNumButtons
;
3087 TOOLBAR_ButtonStructSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3089 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3091 infoPtr
->dwStructSize
= (DWORD
)wParam
;
3098 TOOLBAR_ChangeBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3100 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3101 TBUTTON_INFO
*btnPtr
;
3104 TRACE("button %d, iBitmap now %d\n", wParam
, LOWORD(lParam
));
3106 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3110 btnPtr
= &infoPtr
->buttons
[nIndex
];
3111 btnPtr
->iBitmap
= LOWORD(lParam
);
3113 /* we HAVE to erase the background, the new bitmap could be */
3115 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3122 TOOLBAR_CheckButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3124 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3125 TBUTTON_INFO
*btnPtr
;
3128 BOOL bChecked
= FALSE
;
3130 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3132 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd
, nIndex
, lParam
);
3137 btnPtr
= &infoPtr
->buttons
[nIndex
];
3139 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? TRUE
: FALSE
;
3141 if (LOWORD(lParam
) == FALSE
)
3142 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3144 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3146 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3147 if (nOldIndex
== nIndex
)
3149 if (nOldIndex
!= -1)
3150 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3152 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3155 if( bChecked
!= LOWORD(lParam
) )
3157 if (nOldIndex
!= -1)
3158 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3159 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3162 /* FIXME: Send a WM_NOTIFY?? */
3169 TOOLBAR_CommandToIndex (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3171 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3173 return TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3178 TOOLBAR_Customize (HWND hwnd
)
3180 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3181 CUSTDLG_INFO custInfo
;
3187 custInfo
.tbInfo
= infoPtr
;
3188 custInfo
.tbHwnd
= hwnd
;
3190 /* send TBN_BEGINADJUST notification */
3191 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3193 if (!(hRes
= FindResourceW (COMCTL32_hModule
,
3194 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3195 (LPWSTR
)RT_DIALOG
)))
3198 if(!(template = (LPVOID
)LoadResource (COMCTL32_hModule
, hRes
)))
3201 ret
= DialogBoxIndirectParamW ((HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
),
3202 (LPCDLGTEMPLATEW
)template,
3204 TOOLBAR_CustomizeDialogProc
,
3207 /* send TBN_ENDADJUST notification */
3208 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3215 TOOLBAR_DeleteButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3217 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3218 INT nIndex
= (INT
)wParam
;
3220 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3222 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3225 memset(&nmtb
, 0, sizeof(nmtb
));
3226 nmtb
.iItem
= btnPtr
->idCommand
;
3227 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3228 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3229 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3230 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3231 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3232 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3233 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3235 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3237 if (infoPtr
->nNumButtons
== 1) {
3238 TRACE(" simple delete!\n");
3239 Free (infoPtr
->buttons
);
3240 infoPtr
->buttons
= NULL
;
3241 infoPtr
->nNumButtons
= 0;
3244 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3245 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3247 infoPtr
->nNumButtons
--;
3248 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3250 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3251 nIndex
* sizeof(TBUTTON_INFO
));
3254 if (nIndex
< infoPtr
->nNumButtons
) {
3255 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3256 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3262 TOOLBAR_CalcToolbar (hwnd
);
3264 InvalidateRect (hwnd
, NULL
, TRUE
);
3271 TOOLBAR_EnableButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3273 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3274 TBUTTON_INFO
*btnPtr
;
3278 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3280 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd
, wParam
, lParam
);
3285 btnPtr
= &infoPtr
->buttons
[nIndex
];
3287 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3289 /* update the toolbar button state */
3290 if(LOWORD(lParam
) == FALSE
) {
3291 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3293 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3296 /* redraw the button only if the state of the button changed */
3297 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3298 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3304 static inline LRESULT
3305 TOOLBAR_GetAnchorHighlight (HWND hwnd
)
3307 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3309 return infoPtr
->bAnchor
;
3314 TOOLBAR_GetBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3316 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3319 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3323 return infoPtr
->buttons
[nIndex
].iBitmap
;
3327 static inline LRESULT
3328 TOOLBAR_GetBitmapFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3330 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3335 TOOLBAR_GetButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3337 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3338 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3339 INT nIndex
= (INT
)wParam
;
3340 TBUTTON_INFO
*btnPtr
;
3345 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3348 btnPtr
= &infoPtr
->buttons
[nIndex
];
3349 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3350 lpTbb
->idCommand
= btnPtr
->idCommand
;
3351 lpTbb
->fsState
= btnPtr
->fsState
;
3352 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3353 lpTbb
->bReserved
[0] = 0;
3354 lpTbb
->bReserved
[1] = 0;
3355 lpTbb
->dwData
= btnPtr
->dwData
;
3356 lpTbb
->iString
= btnPtr
->iString
;
3363 TOOLBAR_GetButtonInfoA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3365 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3366 LPTBBUTTONINFOA lpTbInfo
= (LPTBBUTTONINFOA
)lParam
;
3367 TBUTTON_INFO
*btnPtr
;
3370 if (lpTbInfo
== NULL
)
3372 if (lpTbInfo
->cbSize
< sizeof(TBBUTTONINFOA
))
3375 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
3376 lpTbInfo
->dwMask
& 0x80000000);
3380 if (!(btnPtr
= &infoPtr
->buttons
[nIndex
])) return -1;
3382 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3383 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3384 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3385 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3386 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3387 lpTbInfo
->lParam
= btnPtr
->dwData
;
3388 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3389 lpTbInfo
->cx
= (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3390 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3391 lpTbInfo
->fsState
= btnPtr
->fsState
;
3392 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3393 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3394 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3395 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3396 can't use TOOLBAR_GetText here */
3398 if (HIWORD(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3399 lpText
= (LPWSTR
)btnPtr
->iString
;
3400 Str_GetPtrWtoA (lpText
, lpTbInfo
->pszText
,lpTbInfo
->cchText
);
3402 lpTbInfo
->pszText
[0] = '\0';
3409 TOOLBAR_GetButtonInfoW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3411 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3412 LPTBBUTTONINFOW lpTbInfo
= (LPTBBUTTONINFOW
)lParam
;
3413 TBUTTON_INFO
*btnPtr
;
3416 if (lpTbInfo
== NULL
)
3418 if (lpTbInfo
->cbSize
< sizeof(TBBUTTONINFOW
))
3421 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
3422 lpTbInfo
->dwMask
& 0x80000000);
3426 btnPtr
= &infoPtr
->buttons
[nIndex
];
3431 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3432 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3433 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3434 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3435 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3436 lpTbInfo
->lParam
= btnPtr
->dwData
;
3437 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3438 lpTbInfo
->cx
= (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3439 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3440 lpTbInfo
->fsState
= btnPtr
->fsState
;
3441 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3442 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3443 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3444 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3445 can't use TOOLBAR_GetText here */
3447 if (HIWORD(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3448 lpText
= (LPWSTR
)btnPtr
->iString
;
3449 Str_GetPtrW (lpText
,lpTbInfo
->pszText
,lpTbInfo
->cchText
);
3451 lpTbInfo
->pszText
[0] = '\0';
3459 TOOLBAR_GetButtonSize (HWND hwnd
)
3461 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3463 if (infoPtr
->nNumButtons
> 0)
3464 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3465 (WORD
)infoPtr
->nButtonHeight
);
3467 return MAKELONG(23,22);
3472 TOOLBAR_GetButtonTextA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3474 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3481 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3485 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3487 return WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3488 (LPSTR
)lParam
, 0x7fffffff, NULL
, NULL
) - 1;
3493 TOOLBAR_GetButtonTextW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3495 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3500 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3504 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3508 ret
= strlenW (lpText
);
3511 strcpyW ((LPWSTR
)lParam
, lpText
);
3519 TOOLBAR_GetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3521 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3522 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3523 return (LRESULT
)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3527 inline static LRESULT
3528 TOOLBAR_GetExtendedStyle (HWND hwnd
)
3530 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3534 return infoPtr
->dwExStyle
;
3539 TOOLBAR_GetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3541 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3542 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3543 return (LRESULT
)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3548 TOOLBAR_GetHotItem (HWND hwnd
)
3550 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3552 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3555 if (infoPtr
->nHotItem
< 0)
3558 return (LRESULT
)infoPtr
->nHotItem
;
3563 TOOLBAR_GetDefImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3565 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3566 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3567 return (LRESULT
) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd
), wParam
);
3572 TOOLBAR_GetInsertMark (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3574 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3575 TBINSERTMARK
*lptbim
= (TBINSERTMARK
*)lParam
;
3577 TRACE("hwnd = %p, lptbim = %p\n", hwnd
, lptbim
);
3579 *lptbim
= infoPtr
->tbim
;
3586 TOOLBAR_GetInsertMarkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3588 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3590 TRACE("hwnd = %p\n", hwnd
);
3592 return (LRESULT
)infoPtr
->clrInsertMark
;
3597 TOOLBAR_GetItemRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3599 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3600 TBUTTON_INFO
*btnPtr
;
3604 nIndex
= (INT
)wParam
;
3605 btnPtr
= &infoPtr
->buttons
[nIndex
];
3606 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3608 lpRect
= (LPRECT
)lParam
;
3611 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3614 lpRect
->left
= btnPtr
->rect
.left
;
3615 lpRect
->right
= btnPtr
->rect
.right
;
3616 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3617 lpRect
->top
= btnPtr
->rect
.top
;
3624 TOOLBAR_GetMaxSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3626 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3627 LPSIZE lpSize
= (LPSIZE
)lParam
;
3632 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3633 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3635 TRACE("maximum size %d x %d\n",
3636 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3637 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3643 /* << TOOLBAR_GetObject >> */
3647 TOOLBAR_GetPadding (HWND hwnd
)
3649 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3652 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3653 return (LRESULT
) oldPad
;
3658 TOOLBAR_GetRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3660 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3661 TBUTTON_INFO
*btnPtr
;
3665 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3666 btnPtr
= &infoPtr
->buttons
[nIndex
];
3667 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3669 lpRect
= (LPRECT
)lParam
;
3673 lpRect
->left
= btnPtr
->rect
.left
;
3674 lpRect
->right
= btnPtr
->rect
.right
;
3675 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3676 lpRect
->top
= btnPtr
->rect
.top
;
3683 TOOLBAR_GetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3685 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3687 if (infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
)
3688 return infoPtr
->nRows
;
3695 TOOLBAR_GetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3697 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3700 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3704 return infoPtr
->buttons
[nIndex
].fsState
;
3709 TOOLBAR_GetStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3711 return GetWindowLongW(hwnd
, GWL_STYLE
);
3716 TOOLBAR_GetTextRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3718 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3720 return infoPtr
->nMaxTextRows
;
3725 TOOLBAR_GetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3727 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3729 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3730 TOOLBAR_TooltipCreateControl(infoPtr
);
3731 return (LRESULT
)infoPtr
->hwndToolTip
;
3736 TOOLBAR_GetUnicodeFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3738 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3740 TRACE("%s hwnd=%p\n",
3741 infoPtr
->bUnicode
? "TRUE" : "FALSE", hwnd
);
3743 return infoPtr
->bUnicode
;
3747 inline static LRESULT
3748 TOOLBAR_GetVersion (HWND hwnd
)
3750 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3751 return infoPtr
->iVersion
;
3756 TOOLBAR_HideButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3758 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3759 TBUTTON_INFO
*btnPtr
;
3764 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3768 btnPtr
= &infoPtr
->buttons
[nIndex
];
3769 if (LOWORD(lParam
) == FALSE
)
3770 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3772 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3774 TOOLBAR_CalcToolbar (hwnd
);
3776 InvalidateRect (hwnd
, NULL
, TRUE
);
3782 inline static LRESULT
3783 TOOLBAR_HitTest (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3785 return TOOLBAR_InternalHitTest (hwnd
, (LPPOINT
)lParam
);
3790 TOOLBAR_Indeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3792 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3793 TBUTTON_INFO
*btnPtr
;
3797 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3801 btnPtr
= &infoPtr
->buttons
[nIndex
];
3802 oldState
= btnPtr
->fsState
;
3803 if (LOWORD(lParam
) == FALSE
)
3804 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3806 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3808 if(oldState
!= btnPtr
->fsState
)
3809 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3816 TOOLBAR_InsertButtonT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL fUnicode
)
3818 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3819 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3820 INT nIndex
= (INT
)wParam
;
3825 TOOLBAR_DumpButton(infoPtr
, (TBUTTON_INFO
*)lpTbb
, nIndex
, FALSE
);
3828 /* EPP: this seems to be an undocumented call (from my IE4)
3829 * I assume in that case that:
3830 * - index of insertion is at the end of existing buttons
3831 * I only see this happen with nIndex == -1, but it could have a special
3832 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3834 nIndex
= infoPtr
->nNumButtons
;
3836 } else if (nIndex
< 0)
3839 TRACE("inserting button index=%d\n", nIndex
);
3840 if (nIndex
> infoPtr
->nNumButtons
) {
3841 nIndex
= infoPtr
->nNumButtons
;
3842 TRACE("adjust index=%d\n", nIndex
);
3845 infoPtr
->nNumButtons
++;
3846 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3847 memmove(&infoPtr
->buttons
[nIndex
+1], &infoPtr
->buttons
[nIndex
],
3848 (infoPtr
->nNumButtons
- nIndex
- 1) * sizeof(TBUTTON_INFO
));
3850 /* insert new button */
3851 infoPtr
->buttons
[nIndex
].iBitmap
= lpTbb
->iBitmap
;
3852 infoPtr
->buttons
[nIndex
].idCommand
= lpTbb
->idCommand
;
3853 infoPtr
->buttons
[nIndex
].fsState
= lpTbb
->fsState
;
3854 infoPtr
->buttons
[nIndex
].fsStyle
= lpTbb
->fsStyle
;
3855 infoPtr
->buttons
[nIndex
].dwData
= lpTbb
->dwData
;
3856 /* if passed string and not index, then add string */
3857 if(HIWORD(lpTbb
->iString
) && lpTbb
->iString
!=-1) {
3859 Str_SetPtrW((LPWSTR
*)&infoPtr
->buttons
[nIndex
].iString
, (LPWSTR
)lpTbb
->iString
);
3861 Str_SetPtrAtoW((LPWSTR
*)&infoPtr
->buttons
[nIndex
].iString
, (LPCSTR
)lpTbb
->iString
);
3864 infoPtr
->buttons
[nIndex
].iString
= lpTbb
->iString
;
3866 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3868 TOOLBAR_CalcToolbar (hwnd
);
3869 TOOLBAR_AutoSize (hwnd
);
3871 InvalidateRect (hwnd
, NULL
, TRUE
);
3876 /* << TOOLBAR_InsertMarkHitTest >> */
3880 TOOLBAR_IsButtonChecked (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3882 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3885 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3889 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3894 TOOLBAR_IsButtonEnabled (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3896 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3899 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3903 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3908 TOOLBAR_IsButtonHidden (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3910 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3913 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3917 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3922 TOOLBAR_IsButtonHighlighted (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3924 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3927 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3931 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3936 TOOLBAR_IsButtonIndeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3938 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3941 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3945 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3950 TOOLBAR_IsButtonPressed (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3952 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3955 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3959 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3964 TOOLBAR_LoadImages (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3967 tbab
.hInst
= (HINSTANCE
)lParam
;
3968 tbab
.nID
= (UINT_PTR
)wParam
;
3970 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd
, tbab
.hInst
, tbab
.nID
);
3972 return TOOLBAR_AddBitmap(hwnd
, 0, (LPARAM
)&tbab
);
3977 TOOLBAR_MapAccelerator (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3979 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3980 WCHAR wAccel
= (WCHAR
)wParam
;
3981 UINT
* pIDButton
= (UINT
*)lParam
;
3982 WCHAR wszAccel
[] = {'&',wAccel
,0};
3985 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3986 hwnd
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3988 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3990 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3991 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3992 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3994 int iLen
= strlenW(wszAccel
);
3995 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
4002 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
4007 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
4009 *pIDButton
= btnPtr
->idCommand
;
4021 TOOLBAR_MarkButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4023 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4026 TBUTTON_INFO
*btnPtr
;
4028 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd
, wParam
, lParam
);
4030 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4034 btnPtr
= &infoPtr
->buttons
[nIndex
];
4035 oldState
= btnPtr
->fsState
;
4038 btnPtr
->fsState
|= TBSTATE_MARKED
;
4040 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
4042 if(oldState
!= btnPtr
->fsState
)
4043 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4049 /* fixes up an index of a button affected by a move */
4050 inline static void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
4054 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
4056 else if (*pIndex
== nIndex
)
4057 *pIndex
= nMoveIndex
;
4061 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
4063 else if (*pIndex
== nIndex
)
4064 *pIndex
= nMoveIndex
;
4070 TOOLBAR_MoveButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4072 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4075 INT nMoveIndex
= (INT
)lParam
;
4076 TBUTTON_INFO button
;
4078 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd
, wParam
, lParam
);
4080 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, TRUE
);
4081 if ((nIndex
== -1) || (nMoveIndex
< 0))
4084 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
4085 nMoveIndex
= infoPtr
->nNumButtons
- 1;
4087 button
= infoPtr
->buttons
[nIndex
];
4089 /* move button right */
4090 if (nIndex
< nMoveIndex
)
4092 nCount
= nMoveIndex
- nIndex
;
4093 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
4094 infoPtr
->buttons
[nMoveIndex
] = button
;
4096 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
4097 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
4098 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
4099 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
4101 else if (nIndex
> nMoveIndex
) /* move button left */
4103 nCount
= nIndex
- nMoveIndex
;
4104 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
4105 infoPtr
->buttons
[nMoveIndex
] = button
;
4107 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
4108 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
4109 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
4110 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
4113 TOOLBAR_CalcToolbar(hwnd
);
4114 TOOLBAR_AutoSize(hwnd
);
4115 InvalidateRect(hwnd
, NULL
, TRUE
);
4122 TOOLBAR_PressButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4124 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4125 TBUTTON_INFO
*btnPtr
;
4129 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4133 btnPtr
= &infoPtr
->buttons
[nIndex
];
4134 oldState
= btnPtr
->fsState
;
4135 if (LOWORD(lParam
) == FALSE
)
4136 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
4138 btnPtr
->fsState
|= TBSTATE_PRESSED
;
4140 if(oldState
!= btnPtr
->fsState
)
4141 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4146 /* FIXME: there might still be some confusion her between number of buttons
4147 * and number of bitmaps */
4149 TOOLBAR_ReplaceBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4151 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4152 LPTBREPLACEBITMAP lpReplace
= (LPTBREPLACEBITMAP
) lParam
;
4154 HBITMAP hbmLoad
= NULL
;
4155 int i
= 0, nOldButtons
= 0, pos
= 0;
4156 int nOldBitmaps
, nNewBitmaps
= 0;
4157 HIMAGELIST himlDef
= 0;
4159 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4160 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
4161 lpReplace
->nButtons
);
4163 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4165 FIXME("changing standard bitmaps not implemented\n");
4168 else if (lpReplace
->hInstOld
!= 0)
4169 FIXME("resources not in the current module not implemented\n");
4171 if (lpReplace
->hInstNew
)
4173 hbmLoad
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4178 hBitmap
= (HBITMAP
) lpReplace
->nIDNew
;
4181 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4182 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4183 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4184 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4185 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4187 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4188 nOldButtons
= tbi
->nButtons
;
4189 tbi
->nButtons
= lpReplace
->nButtons
;
4190 tbi
->hInst
= lpReplace
->hInstNew
;
4191 tbi
->nID
= lpReplace
->nIDNew
;
4192 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4195 pos
+= tbi
->nButtons
;
4198 if (nOldButtons
== 0)
4200 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4202 DeleteObject (hbmLoad
);
4206 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4207 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4209 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4211 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4212 ImageList_Remove(himlDef
, i
);
4217 HBITMAP hOldBitmapBitmap
, hOldBitmapLoad
, hbmLoad
;
4218 HDC hdcImage
, hdcBitmap
;
4220 /* copy the bitmap before adding it so that the user's bitmap
4221 * doesn't get modified.
4223 GetObjectW (hBitmap
, sizeof(BITMAP
), (LPVOID
)&bmp
);
4225 hdcImage
= CreateCompatibleDC(0);
4226 hdcBitmap
= CreateCompatibleDC(0);
4228 /* create new bitmap */
4229 hbmLoad
= CreateBitmap (bmp
.bmWidth
, bmp
.bmHeight
, bmp
.bmPlanes
, bmp
.bmBitsPixel
, NULL
);
4230 hOldBitmapBitmap
= SelectObject(hdcBitmap
, hBitmap
);
4231 hOldBitmapLoad
= SelectObject(hdcImage
, hbmLoad
);
4233 /* Copy the user's image */
4234 BitBlt (hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
,
4235 hdcBitmap
, 0, 0, SRCCOPY
);
4237 SelectObject (hdcImage
, hOldBitmapLoad
);
4238 SelectObject (hdcBitmap
, hOldBitmapBitmap
);
4239 DeleteDC (hdcImage
);
4240 DeleteDC (hdcBitmap
);
4242 ImageList_AddMasked (himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
4243 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4244 DeleteObject (hbmLoad
);
4247 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4249 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4250 pos
, nOldBitmaps
, nNewBitmaps
);
4252 InvalidateRect(hwnd
, NULL
, TRUE
);
4255 DeleteObject (hbmLoad
);
4260 /* helper for TOOLBAR_SaveRestoreW */
4262 TOOLBAR_Save(TOOLBAR_INFO
*infoPtr
, LPTBSAVEPARAMSW lpSave
)
4264 FIXME("save to %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4265 debugstr_w(lpSave
->pszValueName
));
4271 /* helper for TOOLBAR_Restore */
4273 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4277 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4279 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4282 Free(infoPtr
->buttons
);
4283 infoPtr
->buttons
= NULL
;
4284 infoPtr
->nNumButtons
= 0;
4288 /* helper for TOOLBAR_SaveRestoreW */
4290 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, LPTBSAVEPARAMSW lpSave
)
4299 /* restore toolbar information */
4300 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4301 debugstr_w(lpSave
->pszValueName
));
4303 memset(&nmtbr
, 0, sizeof(nmtbr
));
4305 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4306 KEY_QUERY_VALUE
, &hkey
);
4308 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4310 if (!res
&& dwType
!= REG_BINARY
)
4311 res
= ERROR_FILE_NOT_FOUND
;
4314 nmtbr
.pData
= Alloc(dwSize
);
4315 nmtbr
.cbData
= (UINT
)dwSize
;
4316 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4319 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4320 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4323 nmtbr
.pCurrent
= nmtbr
.pData
;
4325 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4326 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4328 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4332 /* remove all existing buttons as this function is designed to
4333 * restore the toolbar to a previously saved state */
4334 TOOLBAR_DeleteAllButtons(infoPtr
);
4336 for (i
= 0; i
< nmtbr
.cButtons
; i
++)
4339 nmtbr
.tbButton
.iBitmap
= -1;
4340 nmtbr
.tbButton
.fsState
= 0;
4341 nmtbr
.tbButton
.fsStyle
= 0;
4342 nmtbr
.tbButton
.idCommand
= 0;
4343 if (*nmtbr
.pCurrent
== (DWORD
)-1)
4346 nmtbr
.tbButton
.fsStyle
= TBSTYLE_SEP
;
4347 nmtbr
.tbButton
.iBitmap
= SEPARATOR_WIDTH
;
4349 else if (*nmtbr
.pCurrent
== (DWORD
)-2)
4351 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4353 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4357 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4359 /* can't contain real string as we don't know whether
4360 * the client put an ANSI or Unicode string in there */
4361 if (HIWORD(nmtbr
.tbButton
.iString
))
4362 nmtbr
.tbButton
.iString
= 0;
4364 TOOLBAR_InsertButtonT(infoPtr
->hwndSelf
, -1,
4365 (LPARAM
)&nmtbr
.tbButton
, TRUE
);
4368 /* do legacy notifications */
4369 if (infoPtr
->iVersion
< 5)
4371 /* FIXME: send TBN_BEGINADJUST */
4372 FIXME("send TBN_GETBUTTONINFO for each button\n");
4373 /* FIXME: send TBN_ENDADJUST */
4376 /* remove all uninitialised buttons
4377 * note: loop backwards to avoid having to fixup i on a
4379 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4380 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4381 TOOLBAR_DeleteButton(infoPtr
->hwndSelf
, i
, 0);
4383 /* only indicate success if at least one button survived */
4384 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4395 TOOLBAR_SaveRestoreW (HWND hwnd
, WPARAM wParam
, LPTBSAVEPARAMSW lpSave
)
4397 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4399 if (lpSave
== NULL
) return 0;
4402 return TOOLBAR_Save(infoPtr
, lpSave
);
4404 return TOOLBAR_Restore(infoPtr
, lpSave
);
4409 TOOLBAR_SaveRestoreA (HWND hwnd
, WPARAM wParam
, LPTBSAVEPARAMSA lpSave
)
4411 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4412 TBSAVEPARAMSW SaveW
;
4416 if (lpSave
== NULL
) return 0;
4418 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4419 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4420 if (pszSubKey
) goto exit
;
4421 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4423 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4424 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4425 if (!pszValueName
) goto exit
;
4426 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4428 SaveW
.pszValueName
= pszValueName
;
4429 SaveW
.pszSubKey
= pszSubKey
;
4430 SaveW
.hkr
= lpSave
->hkr
;
4431 result
= TOOLBAR_SaveRestoreW(hwnd
, wParam
, &SaveW
);
4434 Free (pszValueName
);
4442 TOOLBAR_SetAnchorHighlight (HWND hwnd
, WPARAM wParam
)
4444 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4445 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4447 TRACE("hwnd=%p, bAnchor = %s\n", hwnd
, wParam
? "TRUE" : "FALSE");
4449 infoPtr
->bAnchor
= (BOOL
)wParam
;
4451 /* Native does not remove the hot effect from an already hot button */
4453 return (LRESULT
)bOldAnchor
;
4458 TOOLBAR_SetBitmapSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4460 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4461 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4463 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd
, wParam
, lParam
);
4466 FIXME("wParam is %d. Perhaps image list index?\n", wParam
);
4468 if ((LOWORD(lParam
) <= 0) || (HIWORD(lParam
)<=0))
4469 lParam
= MAKELPARAM(16, 15);
4471 if (infoPtr
->nNumButtons
> 0)
4472 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4473 infoPtr
->nNumButtons
,
4474 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
4475 LOWORD(lParam
), HIWORD(lParam
));
4477 infoPtr
->nBitmapWidth
= (INT
)LOWORD(lParam
);
4478 infoPtr
->nBitmapHeight
= (INT
)HIWORD(lParam
);
4481 if ((himlDef
== infoPtr
->himlInt
) &&
4482 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4484 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4485 infoPtr
->nBitmapHeight
);
4488 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4494 TOOLBAR_SetButtonInfoA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4496 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4497 LPTBBUTTONINFOA lptbbi
= (LPTBBUTTONINFOA
)lParam
;
4498 TBUTTON_INFO
*btnPtr
;
4504 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOA
))
4507 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4508 lptbbi
->dwMask
& 0x80000000);
4512 btnPtr
= &infoPtr
->buttons
[nIndex
];
4513 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4514 btnPtr
->idCommand
= lptbbi
->idCommand
;
4515 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4516 btnPtr
->iBitmap
= lptbbi
->iImage
;
4517 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4518 btnPtr
->dwData
= lptbbi
->lParam
;
4519 if (lptbbi
->dwMask
& TBIF_SIZE
)
4520 btnPtr
->cx
= lptbbi
->cx
;
4521 if (lptbbi
->dwMask
& TBIF_STATE
)
4522 btnPtr
->fsState
= lptbbi
->fsState
;
4523 if (lptbbi
->dwMask
& TBIF_STYLE
)
4524 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4526 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4527 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4528 /* iString is index, zero it to make Str_SetPtr succeed */
4531 Str_SetPtrAtoW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4534 /* save the button rect to see if we need to redraw the whole toolbar */
4535 oldBtnRect
= btnPtr
->rect
;
4536 TOOLBAR_CalcToolbar(hwnd
);
4538 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4539 InvalidateRect(hwnd
, NULL
, TRUE
);
4541 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4548 TOOLBAR_SetButtonInfoW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4550 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4551 LPTBBUTTONINFOW lptbbi
= (LPTBBUTTONINFOW
)lParam
;
4552 TBUTTON_INFO
*btnPtr
;
4558 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4561 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4562 lptbbi
->dwMask
& 0x80000000);
4566 btnPtr
= &infoPtr
->buttons
[nIndex
];
4567 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4568 btnPtr
->idCommand
= lptbbi
->idCommand
;
4569 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4570 btnPtr
->iBitmap
= lptbbi
->iImage
;
4571 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4572 btnPtr
->dwData
= lptbbi
->lParam
;
4573 if (lptbbi
->dwMask
& TBIF_SIZE
)
4574 btnPtr
->cx
= lptbbi
->cx
;
4575 if (lptbbi
->dwMask
& TBIF_STATE
)
4576 btnPtr
->fsState
= lptbbi
->fsState
;
4577 if (lptbbi
->dwMask
& TBIF_STYLE
)
4578 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4580 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4581 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4582 /* iString is index, zero it to make Str_SetPtr succeed */
4584 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4587 /* save the button rect to see if we need to redraw the whole toolbar */
4588 oldBtnRect
= btnPtr
->rect
;
4589 TOOLBAR_CalcToolbar(hwnd
);
4591 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4592 InvalidateRect(hwnd
, NULL
, TRUE
);
4594 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4601 TOOLBAR_SetButtonSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4603 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4604 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4606 if ((cx
< 0) || (cy
< 0))
4608 ERR("invalid parameter 0x%08x\n", (DWORD
)lParam
);
4612 TRACE("%p, cx = %d, cy = %d\n", hwnd
, cx
, cy
);
4614 /* The documentation claims you can only change the button size before
4615 * any button has been added. But this is wrong.
4616 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4617 * it to the toolbar, and it checks that the return value is nonzero - mjm
4618 * Further testing shows that we must actually perform the change too.
4621 * The documentation also does not mention that if 0 is supplied for
4622 * either size, the system changes it to the default of 24 wide and
4623 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4625 infoPtr
->nButtonWidth
= (cx
) ? cx
: 24;
4626 infoPtr
->nButtonHeight
= (cy
) ? cy
: 22;
4632 TOOLBAR_SetButtonWidth (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4634 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4636 /* if setting to current values, ignore */
4637 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4638 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4639 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4640 infoPtr
->cxMin
, infoPtr
->cxMax
);
4644 /* save new values */
4645 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4646 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4648 /* otherwise we need to recalc the toolbar and in some cases
4649 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4650 which doesn't actually draw - GA). */
4651 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4652 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4654 TOOLBAR_CalcToolbar (hwnd
);
4656 InvalidateRect (hwnd
, NULL
, TRUE
);
4663 TOOLBAR_SetCmdId (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4665 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4666 INT nIndex
= (INT
)wParam
;
4668 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4671 infoPtr
->buttons
[nIndex
].idCommand
= (INT
)lParam
;
4673 if (infoPtr
->hwndToolTip
) {
4675 FIXME("change tool tip!\n");
4684 TOOLBAR_SetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4686 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4687 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4688 HIMAGELIST himlTemp
;
4691 if (infoPtr
->iVersion
>= 5)
4694 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4695 &infoPtr
->cimlDis
, himl
, id
);
4697 /* FIXME: redraw ? */
4699 return (LRESULT
)himlTemp
;
4704 TOOLBAR_SetDrawTextFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4706 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4709 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd
, (DWORD
)wParam
, (DWORD
)lParam
);
4711 dwTemp
= infoPtr
->dwDTFlags
;
4712 infoPtr
->dwDTFlags
=
4713 (infoPtr
->dwDTFlags
& (DWORD
)wParam
) | (DWORD
)lParam
;
4715 return (LRESULT
)dwTemp
;
4718 /* This function differs a bit from what MSDN says it does:
4719 * 1. lParam contains extended style flags to OR with current style
4720 * (MSDN isn't clear on the OR bit)
4721 * 2. wParam appears to contain extended style flags to be reset
4722 * (MSDN says that this parameter is reserved)
4725 TOOLBAR_SetExtendedStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4727 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4730 dwTemp
= infoPtr
->dwExStyle
;
4731 infoPtr
->dwExStyle
&= ~wParam
;
4732 infoPtr
->dwExStyle
|= (DWORD
)lParam
;
4734 TRACE("new style 0x%08x\n", infoPtr
->dwExStyle
);
4736 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4737 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4738 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4740 TOOLBAR_CalcToolbar (hwnd
);
4742 TOOLBAR_AutoSize(hwnd
);
4744 InvalidateRect(hwnd
, NULL
, TRUE
);
4746 return (LRESULT
)dwTemp
;
4751 TOOLBAR_SetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4753 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4754 HIMAGELIST himlTemp
;
4755 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4758 if (infoPtr
->iVersion
>= 5)
4761 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd
, himl
, id
);
4763 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4764 &infoPtr
->cimlHot
, himl
, id
);
4766 /* FIXME: redraw ? */
4768 return (LRESULT
)himlTemp
;
4772 /* Makes previous hot button no longer hot, makes the specified
4773 * button hot and sends appropriate notifications. dwReason is one or
4774 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4775 * NOTE 1: this function does not validate nHit
4776 * NOTE 2: the name of this function is completely made up and
4777 * not based on any documentation from Microsoft. */
4779 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4781 if (infoPtr
->nHotItem
!= nHit
)
4783 NMTBHOTITEM nmhotitem
;
4784 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4786 nmhotitem
.dwFlags
= dwReason
;
4787 if(infoPtr
->nHotItem
>= 0)
4789 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4790 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4794 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4795 nmhotitem
.idOld
= 0;
4800 btnPtr
= &infoPtr
->buttons
[nHit
];
4801 nmhotitem
.idNew
= btnPtr
->idCommand
;
4805 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4806 nmhotitem
.idNew
= 0;
4809 /* now change the hot and invalidate the old and new buttons - if the
4811 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4814 oldBtnPtr
->bHot
= FALSE
;
4815 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4817 /* setting disabled buttons as hot fails even if the notify contains the button id */
4818 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4819 btnPtr
->bHot
= TRUE
;
4820 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4821 infoPtr
->nHotItem
= nHit
;
4824 infoPtr
->nHotItem
= -1;
4830 TOOLBAR_SetHotItem (HWND hwnd
, WPARAM wParam
)
4832 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4833 INT nOldHotItem
= infoPtr
->nHotItem
;
4835 TRACE("hwnd = %p, nHit = %d\n", hwnd
, (INT
)wParam
);
4837 if ((INT
)wParam
> infoPtr
->nNumButtons
)
4838 return infoPtr
->nHotItem
;
4840 if ((INT
)wParam
< 0)
4843 /* NOTE: an application can still remove the hot item even if anchor
4844 * highlighting is enabled */
4846 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, HICF_OTHER
);
4848 if (nOldHotItem
< 0)
4851 return (LRESULT
)nOldHotItem
;
4856 TOOLBAR_SetImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4858 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4859 HIMAGELIST himlTemp
;
4860 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4863 if (infoPtr
->iVersion
>= 5)
4866 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4867 &infoPtr
->cimlDef
, himl
, id
);
4869 infoPtr
->nNumBitmaps
= 0;
4870 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4871 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4873 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4874 &infoPtr
->nBitmapHeight
))
4876 infoPtr
->nBitmapWidth
= 1;
4877 infoPtr
->nBitmapHeight
= 1;
4880 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4881 hwnd
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4882 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4884 InvalidateRect(hwnd
, NULL
, TRUE
);
4886 return (LRESULT
)himlTemp
;
4891 TOOLBAR_SetIndent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4893 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4895 infoPtr
->nIndent
= (INT
)wParam
;
4899 /* process only on indent changing */
4900 if(infoPtr
->nIndent
!= (INT
)wParam
)
4902 infoPtr
->nIndent
= (INT
)wParam
;
4903 TOOLBAR_CalcToolbar (hwnd
);
4904 InvalidateRect(hwnd
, NULL
, FALSE
);
4912 TOOLBAR_SetInsertMark (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4914 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4915 TBINSERTMARK
*lptbim
= (TBINSERTMARK
*)lParam
;
4917 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd
, lptbim
->iButton
, lptbim
->dwFlags
);
4919 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4921 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4925 if ((lptbim
->iButton
== -1) ||
4926 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4927 (lptbim
->iButton
>= 0)))
4929 infoPtr
->tbim
= *lptbim
;
4930 /* FIXME: don't need to update entire toolbar */
4931 InvalidateRect(hwnd
, NULL
, TRUE
);
4934 ERR("Invalid button index %d\n", lptbim
->iButton
);
4941 TOOLBAR_SetInsertMarkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4943 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4945 infoPtr
->clrInsertMark
= (COLORREF
)lParam
;
4947 /* FIXME: don't need to update entire toolbar */
4948 InvalidateRect(hwnd
, NULL
, TRUE
);
4955 TOOLBAR_SetMaxTextRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4957 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4959 infoPtr
->nMaxTextRows
= (INT
)wParam
;
4961 TOOLBAR_CalcToolbar(hwnd
);
4966 /* MSDN gives slightly wrong info on padding.
4967 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4968 * 2. It is not used to create a blank area between the edge of the button
4969 * and the text or image if TBSTYLE_LIST is set. It is used to control
4970 * the gap between the image and text.
4971 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4972 * to control the bottom and right borders [with the border being
4973 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4974 * is shared evenly on both sides of the button.
4975 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4978 TOOLBAR_SetPadding (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4980 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4983 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4984 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4985 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4986 TRACE("cx=%d, cy=%d\n",
4987 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4988 return (LRESULT
) oldPad
;
4993 TOOLBAR_SetParent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4995 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5000 hwndOldNotify
= infoPtr
->hwndNotify
;
5001 infoPtr
->hwndNotify
= (HWND
)wParam
;
5003 return (LRESULT
)hwndOldNotify
;
5008 TOOLBAR_SetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5010 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5011 LPRECT lprc
= (LPRECT
)lParam
;
5015 if (LOWORD(wParam
) > 1) {
5016 FIXME("multiple rows not supported!\n");
5019 if(infoPtr
->nRows
!= LOWORD(wParam
))
5021 infoPtr
->nRows
= LOWORD(wParam
);
5023 /* recalculate toolbar */
5024 TOOLBAR_CalcToolbar (hwnd
);
5026 /* repaint toolbar */
5027 InvalidateRect(hwnd
, NULL
, TRUE
);
5030 /* return bounding rectangle */
5032 lprc
->left
= infoPtr
->rcBound
.left
;
5033 lprc
->right
= infoPtr
->rcBound
.right
;
5034 lprc
->top
= infoPtr
->rcBound
.top
;
5035 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
5043 TOOLBAR_SetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5045 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5046 TBUTTON_INFO
*btnPtr
;
5049 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
5053 btnPtr
= &infoPtr
->buttons
[nIndex
];
5055 /* if hidden state has changed the invalidate entire window and recalc */
5056 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
5057 btnPtr
->fsState
= LOWORD(lParam
);
5058 TOOLBAR_CalcToolbar (hwnd
);
5059 InvalidateRect(hwnd
, 0, TRUE
);
5063 /* process state changing if current state doesn't match new state */
5064 if(btnPtr
->fsState
!= LOWORD(lParam
))
5066 btnPtr
->fsState
= LOWORD(lParam
);
5067 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5075 TOOLBAR_SetStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5077 SetWindowLongW(hwnd
, GWL_STYLE
, lParam
);
5083 inline static LRESULT
5084 TOOLBAR_SetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5086 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5088 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd
, (HWND
)wParam
, lParam
);
5090 infoPtr
->hwndToolTip
= (HWND
)wParam
;
5096 TOOLBAR_SetUnicodeFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5098 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5101 TRACE("%s hwnd=%p\n",
5102 ((BOOL
)wParam
) ? "TRUE" : "FALSE", hwnd
);
5104 bTemp
= infoPtr
->bUnicode
;
5105 infoPtr
->bUnicode
= (BOOL
)wParam
;
5112 TOOLBAR_GetColorScheme (HWND hwnd
, LPCOLORSCHEME lParam
)
5114 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5116 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
5117 comctl32_color
.clrBtnHighlight
:
5118 infoPtr
->clrBtnHighlight
;
5119 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
5120 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
5126 TOOLBAR_SetColorScheme (HWND hwnd
, LPCOLORSCHEME lParam
)
5128 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5130 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5131 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
5132 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
5134 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
5135 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
5136 InvalidateRect(hwnd
, NULL
, TRUE
);
5142 TOOLBAR_SetVersion (HWND hwnd
, INT iVersion
)
5144 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5145 INT iOldVersion
= infoPtr
->iVersion
;
5147 infoPtr
->iVersion
= iVersion
;
5149 if (infoPtr
->iVersion
>= 5)
5150 TOOLBAR_SetUnicodeFormat(hwnd
, (WPARAM
)TRUE
, (LPARAM
)0);
5157 TOOLBAR_GetStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5159 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5160 WORD iString
= HIWORD(wParam
);
5161 WORD buffersize
= LOWORD(wParam
);
5162 LPSTR str
= (LPSTR
)lParam
;
5165 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, buffersize
, str
);
5167 if (iString
< infoPtr
->nNumStrings
)
5169 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
5171 TRACE("returning %s\n", debugstr_a(str
));
5174 ERR("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5181 TOOLBAR_GetStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5183 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5184 WORD iString
= HIWORD(wParam
);
5185 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5186 LPWSTR str
= (LPWSTR
)lParam
;
5189 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, LOWORD(wParam
), str
);
5191 if (iString
< infoPtr
->nNumStrings
)
5193 len
= min(len
, strlenW(infoPtr
->strings
[iString
]));
5194 ret
= (len
+1)*sizeof(WCHAR
);
5195 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5198 TRACE("returning %s\n", debugstr_w(str
));
5201 ERR("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5206 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5207 * is the maximum size of the toolbar? */
5208 static LRESULT
TOOLBAR_Unkwn45D(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5210 SIZE
* pSize
= (SIZE
*)lParam
;
5211 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%d, size.cy=%d stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5216 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5217 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5218 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5221 TOOLBAR_Unkwn45E (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5223 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5224 INT nOldHotItem
= infoPtr
->nHotItem
;
5226 TRACE("old item=%d, new item=%d, flags=%08x\n",
5227 nOldHotItem
, infoPtr
->nHotItem
, (DWORD
)lParam
);
5229 if ((INT
) wParam
< 0 || (INT
)wParam
> infoPtr
->nNumButtons
)
5232 /* NOTE: an application can still remove the hot item even if anchor
5233 * highlighting is enabled */
5235 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, lParam
);
5239 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5242 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5243 * which controls the amount of spacing between the image and the text
5244 * of buttons for TBSTYLE_LIST toolbars. */
5245 static LRESULT
TOOLBAR_Unkwn460(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5247 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5249 TRACE("hwnd=%p iListGap=%d\n", hwnd
, wParam
);
5252 FIXME("lParam = 0x%08lx. Please report\n", lParam
);
5254 infoPtr
->iListGap
= (INT
)wParam
;
5256 InvalidateRect(hwnd
, NULL
, TRUE
);
5261 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5262 * of image lists associated with the various states. */
5263 static LRESULT
TOOLBAR_Unkwn462(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5265 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5267 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd
, wParam
, lParam
);
5269 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5273 TOOLBAR_Unkwn463 (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5275 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5276 LPSIZE lpsize
= (LPSIZE
)lParam
;
5282 * Testing shows the following:
5283 * wParam = 0 adjust cx value
5284 * = 1 set cy value to max size.
5285 * lParam pointer to SIZE structure
5288 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5289 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5293 if (lpsize
->cx
== -1) {
5294 /* **** this is wrong, native measures each button and sets it */
5295 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5297 else if(HIWORD(lpsize
->cx
)) {
5299 HWND hwndParent
= GetParent(hwnd
);
5301 GetWindowRect(hwnd
, &rc
);
5302 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5303 TRACE("mapped to (%d,%d)-(%d,%d)\n",
5304 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5305 lpsize
->cx
= max(rc
.right
-rc
.left
,
5306 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5309 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5313 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5316 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5320 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5321 lpsize
->cx
, lpsize
->cy
);
5325 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5327 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd
, wParam
, lParam
);
5329 InvalidateRect(hwnd
, NULL
, TRUE
);
5335 TOOLBAR_Create (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5337 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5338 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
5341 TRACE("hwnd = %p\n", hwnd
);
5343 /* initialize info structure */
5344 infoPtr
->nButtonHeight
= 22;
5345 infoPtr
->nButtonWidth
= 24;
5346 infoPtr
->nBitmapHeight
= 15;
5347 infoPtr
->nBitmapWidth
= 16;
5349 infoPtr
->nMaxTextRows
= 1;
5350 infoPtr
->cxMin
= -1;
5351 infoPtr
->cxMax
= -1;
5352 infoPtr
->nNumBitmaps
= 0;
5353 infoPtr
->nNumStrings
= 0;
5355 infoPtr
->bCaptured
= FALSE
;
5356 infoPtr
->nButtonDown
= -1;
5357 infoPtr
->nButtonDrag
= -1;
5358 infoPtr
->nOldHit
= -1;
5359 infoPtr
->nHotItem
= -1;
5360 infoPtr
->hwndNotify
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
5361 infoPtr
->dwDTFlags
= (dwStyle
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
5362 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
5363 infoPtr
->bDragOutSent
= FALSE
;
5364 infoPtr
->iVersion
= 0;
5365 infoPtr
->hwndSelf
= hwnd
;
5366 infoPtr
->bDoRedraw
= TRUE
;
5367 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
5368 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
5369 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
5370 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
5371 infoPtr
->iListGap
= DEFLISTGAP
;
5372 infoPtr
->dwStyle
= dwStyle
;
5373 infoPtr
->tbim
.iButton
= -1;
5374 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5375 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5376 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, (LPARAM
)NF_REQUERY
));
5377 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5379 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5380 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5382 OpenThemeData (hwnd
, themeClass
);
5384 TOOLBAR_CheckStyle (hwnd
, dwStyle
);
5386 TOOLBAR_CalcToolbar(hwnd
);
5393 TOOLBAR_Destroy (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5395 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5397 /* delete tooltip control */
5398 if (infoPtr
->hwndToolTip
)
5399 DestroyWindow (infoPtr
->hwndToolTip
);
5401 /* delete temporary buffer for tooltip text */
5402 Free (infoPtr
->pszTooltipText
);
5403 Free (infoPtr
->bitmaps
); /* bitmaps list */
5405 /* delete button data */
5406 if (infoPtr
->buttons
)
5407 Free (infoPtr
->buttons
);
5409 /* delete strings */
5410 if (infoPtr
->strings
) {
5412 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5413 if (infoPtr
->strings
[i
])
5414 Free (infoPtr
->strings
[i
]);
5416 Free (infoPtr
->strings
);
5419 /* destroy internal image list */
5420 if (infoPtr
->himlInt
)
5421 ImageList_Destroy (infoPtr
->himlInt
);
5423 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5424 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5425 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5427 /* delete default font */
5429 DeleteObject (infoPtr
->hDefaultFont
);
5431 CloseThemeData (GetWindowTheme (hwnd
));
5433 /* free toolbar info data */
5435 SetWindowLongPtrW (hwnd
, 0, 0);
5442 TOOLBAR_EraseBackground (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5444 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5445 NMTBCUSTOMDRAW tbcd
;
5448 HTHEME theme
= GetWindowTheme (hwnd
);
5449 DWORD dwEraseCustDraw
= 0;
5451 /* the app has told us not to redraw the toolbar */
5452 if (!infoPtr
->bDoRedraw
)
5455 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5456 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5457 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5458 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5459 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5460 dwEraseCustDraw
= ntfret
& 0xffff;
5462 /* FIXME: in general the return flags *can* be or'ed together */
5463 switch (dwEraseCustDraw
)
5465 case CDRF_DODEFAULT
:
5467 case CDRF_SKIPDEFAULT
:
5470 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5475 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5476 * to my parent for processing.
5478 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5480 HDC hdc
= (HDC
)wParam
;
5485 parent
= GetParent(hwnd
);
5486 MapWindowPoints(hwnd
, parent
, &pt
, 1);
5487 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5488 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5489 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5492 ret
= DefWindowProcW (hwnd
, WM_ERASEBKGND
, wParam
, lParam
);
5494 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5495 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5496 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5497 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5498 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5499 dwEraseCustDraw
= ntfret
& 0xffff;
5500 switch (dwEraseCustDraw
)
5502 case CDRF_DODEFAULT
:
5504 case CDRF_SKIPDEFAULT
:
5507 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5516 TOOLBAR_GetFont (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5518 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5520 return (LRESULT
)infoPtr
->hFont
;
5525 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5528 INT nNewHotItem
= infoPtr
->nHotItem
;
5530 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5533 if ((nNewHotItem
+ iDirection
< 0) ||
5534 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5536 NMTBWRAPHOTITEM nmtbwhi
;
5537 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5538 nmtbwhi
.iDirection
= iDirection
;
5539 nmtbwhi
.dwReason
= dwReason
;
5541 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5545 nNewHotItem
+= iDirection
;
5546 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5548 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5549 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5551 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5558 TOOLBAR_KeyDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5560 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5563 nmkey
.nVKey
= (UINT
)wParam
;
5564 nmkey
.uFlags
= HIWORD(lParam
);
5566 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5567 return DefWindowProcW(hwnd
, WM_KEYDOWN
, wParam
, lParam
);
5569 switch ((UINT
)wParam
)
5573 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5577 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5581 if ((infoPtr
->nHotItem
>= 0) &&
5582 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5584 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5585 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5596 TOOLBAR_LButtonDblClk (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5601 pt
.x
= (short)LOWORD(lParam
);
5602 pt
.y
= (short)HIWORD(lParam
);
5603 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5606 TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
5607 else if (GetWindowLongW (hwnd
, GWL_STYLE
) & CCS_ADJUSTABLE
)
5608 TOOLBAR_Customize (hwnd
);
5615 TOOLBAR_LButtonDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5617 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5618 TBUTTON_INFO
*btnPtr
;
5623 BOOL bDragKeyPressed
;
5627 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5628 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5630 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5632 if (infoPtr
->hwndToolTip
)
5633 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5634 WM_LBUTTONDOWN
, wParam
, lParam
);
5636 pt
.x
= (short)LOWORD(lParam
);
5637 pt
.y
= (short)HIWORD(lParam
);
5638 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5640 btnPtr
= &infoPtr
->buttons
[nHit
];
5642 if ((nHit
>= 0) && bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5644 infoPtr
->nButtonDrag
= nHit
;
5647 /* If drag cursor has not been loaded, load it.
5648 * Note: it doesn't need to be freed */
5650 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5651 SetCursor(hCursorDrag
);
5656 infoPtr
->nOldHit
= nHit
;
5658 CopyRect(&arrowRect
, &btnPtr
->rect
);
5659 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5661 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5662 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5663 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5664 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5665 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5666 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5670 /* draw in pressed state */
5671 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5672 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5674 btnPtr
->bDropDownPressed
= TRUE
;
5675 RedrawWindow(hwnd
,&btnPtr
->rect
,0,
5676 RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5678 memset(&nmtb
, 0, sizeof(nmtb
));
5679 nmtb
.iItem
= btnPtr
->idCommand
;
5680 nmtb
.rcButton
= btnPtr
->rect
;
5681 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5683 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5685 if (res
!= TBDDRET_TREATPRESSED
)
5689 /* redraw button in unpressed state */
5690 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5691 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5693 btnPtr
->bDropDownPressed
= FALSE
;
5694 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5696 /* find and set hot item
5697 * NOTE: native doesn't do this, but that is a bug */
5699 ScreenToClient(hwnd
, &pt
);
5700 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
5701 if (!infoPtr
->bAnchor
|| (nHit
>= 0))
5702 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5704 /* remove any left mouse button down or double-click messages
5705 * so that we can get a toggle effect on the button */
5706 while (PeekMessageW(&msg
, hwnd
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5707 PeekMessageW(&msg
, hwnd
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5712 /* otherwise drop through and process as pushed */
5714 infoPtr
->bCaptured
= TRUE
;
5715 infoPtr
->nButtonDown
= nHit
;
5716 infoPtr
->bDragOutSent
= FALSE
;
5718 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5720 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5722 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5723 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5730 memset(&nmtb
, 0, sizeof(nmtb
));
5731 nmtb
.iItem
= btnPtr
->idCommand
;
5732 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5735 nmmouse
.dwHitInfo
= nHit
;
5737 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5739 nmmouse
.dwItemSpec
= -1;
5742 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5743 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5746 ClientToScreen(hwnd
, &pt
);
5749 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5750 return DefWindowProcW(hwnd
, WM_LBUTTONDOWN
, wParam
, lParam
);
5756 TOOLBAR_LButtonUp (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5758 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5759 TBUTTON_INFO
*btnPtr
;
5763 BOOL bSendMessage
= TRUE
;
5768 if (infoPtr
->hwndToolTip
)
5769 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5770 WM_LBUTTONUP
, wParam
, lParam
);
5772 pt
.x
= (short)LOWORD(lParam
);
5773 pt
.y
= (short)HIWORD(lParam
);
5774 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5776 if (!infoPtr
->bAnchor
|| (nHit
>= 0))
5777 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5779 if (infoPtr
->nButtonDrag
>= 0) {
5783 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5786 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5788 GetClientRect(hwnd
, &rcClient
);
5789 if (PtInRect(&rcClient
, pt
))
5796 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5799 if (nButton
== infoPtr
->nButtonDrag
)
5801 /* if the button is moved sightly left and we have a
5802 * separator there then remove it */
5803 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5805 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5806 TOOLBAR_DeleteButton(hwnd
, nButton
- 1, 0);
5808 else /* else insert a separator before the dragged button */
5811 memset(&tbb
, 0, sizeof(tbb
));
5812 tbb
.fsStyle
= BTNS_SEP
;
5814 TOOLBAR_InsertButtonT(hwnd
, nButton
, (LPARAM
)&tbb
, TRUE
);
5821 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5822 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, 0);
5824 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5827 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, nButton
);
5832 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5833 TOOLBAR_DeleteButton(hwnd
, (WPARAM
)infoPtr
->nButtonDrag
, 0);
5836 /* button under cursor changed so need to re-set hot item */
5837 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5838 infoPtr
->nButtonDrag
= -1;
5840 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5842 else if (infoPtr
->nButtonDown
>= 0) {
5843 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5844 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5846 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5847 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5848 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5850 if (nOldIndex
== nHit
)
5851 bSendMessage
= FALSE
;
5852 if ((nOldIndex
!= nHit
) &&
5854 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5855 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5858 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5859 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5861 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5865 if (nOldIndex
!= -1)
5866 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5869 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5870 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5871 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5873 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5875 infoPtr
->nButtonDown
= -1;
5877 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5878 TOOLBAR_SendNotify ((NMHDR
*) &hdr
, infoPtr
,
5879 NM_RELEASEDCAPTURE
);
5881 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5884 memset(&nmtb
, 0, sizeof(nmtb
));
5885 nmtb
.iItem
= btnPtr
->idCommand
;
5886 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5889 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5891 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5892 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)hwnd
);
5896 /* !!! Undocumented - toolbar at 4.71 level and above sends
5897 * NM_CLICK with the NMMOUSE structure. */
5898 nmmouse
.dwHitInfo
= nHit
;
5901 nmmouse
.dwItemSpec
= -1;
5904 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5905 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5908 ClientToScreen(hwnd
, &pt
);
5911 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5912 return DefWindowProcW(hwnd
, WM_LBUTTONUP
, wParam
, lParam
);
5918 TOOLBAR_RButtonUp( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5920 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5925 pt
.x
= (short)LOWORD(lParam
);
5926 pt
.y
= (short)HIWORD(lParam
);
5928 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
5929 nmmouse
.dwHitInfo
= nHit
;
5932 nmmouse
.dwItemSpec
= -1;
5934 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5935 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5938 ClientToScreen(hwnd
, &pt
);
5941 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5942 return DefWindowProcW(hwnd
, WM_RBUTTONUP
, wParam
, lParam
);
5948 TOOLBAR_RButtonDblClk( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5950 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5953 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5954 return DefWindowProcW(hwnd
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
5960 TOOLBAR_CaptureChanged(HWND hwnd
)
5962 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5963 TBUTTON_INFO
*btnPtr
;
5965 infoPtr
->bCaptured
= FALSE
;
5967 if (infoPtr
->nButtonDown
>= 0)
5969 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5970 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5972 infoPtr
->nOldHit
= -1;
5974 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5975 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5981 TOOLBAR_MouseLeave (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5983 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5985 /* don't remove hot effects when in anchor highlighting mode or when a
5986 * drop-down button is pressed */
5987 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
5989 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
5990 if (!hotBtnPtr
->bDropDownPressed
)
5991 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
5994 if (infoPtr
->nOldHit
< 0)
5997 /* If the last button we were over is depressed then make it not */
5998 /* depressed and redraw it */
5999 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
6001 TBUTTON_INFO
*btnPtr
;
6004 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6006 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6009 InflateRect (&rc1
, 1, 1);
6010 InvalidateRect (hwnd
, &rc1
, TRUE
);
6013 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
6016 ZeroMemory(&nmt
, sizeof(nmt
));
6017 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6018 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6019 infoPtr
->bDragOutSent
= TRUE
;
6022 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
6028 TOOLBAR_MouseMove (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6030 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6032 TRACKMOUSEEVENT trackinfo
;
6034 TBUTTON_INFO
*btnPtr
;
6036 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
6037 TOOLBAR_TooltipCreateControl(infoPtr
);
6039 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
6040 /* fill in the TRACKMOUSEEVENT struct */
6041 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
6042 trackinfo
.dwFlags
= TME_QUERY
;
6044 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6045 _TrackMouseEvent(&trackinfo
);
6047 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6048 if(trackinfo
.hwndTrack
!= hwnd
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
6049 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
6050 trackinfo
.hwndTrack
= hwnd
;
6052 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6053 /* and can properly deactivate the hot toolbar button */
6054 _TrackMouseEvent(&trackinfo
);
6058 if (infoPtr
->hwndToolTip
)
6059 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
6060 WM_MOUSEMOVE
, wParam
, lParam
);
6062 pt
.x
= (short)LOWORD(lParam
);
6063 pt
.y
= (short)HIWORD(lParam
);
6065 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
6067 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6068 && (!infoPtr
->bAnchor
|| (nHit
>= 0)))
6069 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
);
6071 if (infoPtr
->nOldHit
!= nHit
)
6073 if (infoPtr
->bCaptured
)
6075 if (!infoPtr
->bDragOutSent
)
6078 ZeroMemory(&nmt
, sizeof(nmt
));
6079 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6080 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6081 infoPtr
->bDragOutSent
= TRUE
;
6084 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6085 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
6086 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6087 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6089 else if (nHit
== infoPtr
->nButtonDown
) {
6090 btnPtr
->fsState
|= TBSTATE_PRESSED
;
6091 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6093 infoPtr
->nOldHit
= nHit
;
6101 inline static LRESULT
6102 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6104 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6105 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
6107 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6111 inline static LRESULT
6112 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6114 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
6115 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
6117 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
6122 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6124 TOOLBAR_INFO
*infoPtr
;
6125 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
6128 /* allocate memory for info structure */
6129 infoPtr
= (TOOLBAR_INFO
*)Alloc (sizeof(TOOLBAR_INFO
));
6130 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
6133 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
6135 infoPtr
->nWidth
= 0;
6137 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6138 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
6139 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
6140 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
6143 /* native control does:
6144 * Get a lot of colors and brushes
6146 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6147 * CreateFontIndirectW(adr1)
6148 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6149 * hdc = GetDC(toolbar)
6150 * GetSystemMetrics(0x48)
6151 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6152 * 0, 0, 0, 0, "MARLETT")
6153 * oldfnt = SelectObject(hdc, fnt2)
6154 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6155 * GetTextMetricsW(hdc, adr3)
6156 * SelectObject(hdc, oldfnt)
6157 * DeleteObject(fnt2)
6159 * InvalidateRect(toolbar, 0, 1)
6160 * SetWindowLongW(toolbar, 0, addr)
6161 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6164 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6165 * ie 2 0x4600094c 0x4600094c 0x4600894d
6166 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6167 * rebar 0x50008844 0x40008844 0x50008845
6168 * pager 0x50000844 0x40000844 0x50008845
6169 * IC35mgr 0x5400084e **nochange**
6170 * on entry to _NCCREATE 0x5400084e
6171 * rowlist 0x5400004e **nochange**
6172 * on entry to _NCCREATE 0x5400004e
6176 /* I think the code below is a bug, but it is the way that the native
6177 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6178 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6179 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6180 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6181 * Somehow, the only cases of this seem to be MFC programs.
6183 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6184 * does not occur in the WM_STYLECHANGING routine.
6185 * (Guy Albertelli 9/2001)
6188 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6189 && !(cs
->style
& TBSTYLE_TRANSPARENT
))
6190 styleadd
|= TBSTYLE_TRANSPARENT
;
6191 if (!(cs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
6192 styleadd
|= CCS_TOP
; /* default to top */
6193 SetWindowLongW (hwnd
, GWL_STYLE
, cs
->style
| styleadd
);
6196 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, lParam
);
6201 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6203 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
6207 if (dwStyle
& WS_MINIMIZE
)
6208 return 0; /* Nothing to do */
6210 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
6212 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
6215 if (!(dwStyle
& CCS_NODIVIDER
))
6217 GetWindowRect (hwnd
, &rcWindow
);
6218 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
6219 if( dwStyle
& WS_BORDER
)
6220 OffsetRect (&rcWindow
, 1, 1);
6221 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6224 ReleaseDC( hwnd
, hdc
);
6230 /* handles requests from the tooltip control on what text to display */
6231 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6233 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6235 TRACE("button index = %d\n", index
);
6237 Free (infoPtr
->pszTooltipText
);
6238 infoPtr
->pszTooltipText
= NULL
;
6243 if (infoPtr
->bUnicode
)
6245 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6246 NMTBGETINFOTIPW tbgit
;
6247 unsigned int len
; /* in chars */
6249 wszBuffer
[0] = '\0';
6250 wszBuffer
[INFOTIPSIZE
] = '\0';
6252 tbgit
.pszText
= wszBuffer
;
6253 tbgit
.cchTextMax
= INFOTIPSIZE
;
6254 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6255 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6257 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6259 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6261 len
= strlenW(tbgit
.pszText
);
6262 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6264 /* need to allocate temporary buffer in infoPtr as there
6265 * isn't enough space in buffer passed to us by the
6266 * tooltip control */
6267 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6268 if (infoPtr
->pszTooltipText
)
6270 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6271 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6277 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6283 CHAR szBuffer
[INFOTIPSIZE
+1];
6284 NMTBGETINFOTIPA tbgit
;
6285 unsigned int len
; /* in chars */
6288 szBuffer
[INFOTIPSIZE
] = '\0';
6290 tbgit
.pszText
= szBuffer
;
6291 tbgit
.cchTextMax
= INFOTIPSIZE
;
6292 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6293 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6295 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6297 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6299 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6300 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]))
6302 /* need to allocate temporary buffer in infoPtr as there
6303 * isn't enough space in buffer passed to us by the
6304 * tooltip control */
6305 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6306 if (infoPtr
->pszTooltipText
)
6308 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6309 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6315 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1,
6316 lpnmtdi
->lpszText
, sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]));
6321 /* if button has text, but it is not shown then automatically
6322 * use that text as tooltip */
6323 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6324 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6326 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6327 unsigned int len
= pszText
? strlenW(pszText
) : 0;
6329 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6331 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6333 /* need to allocate temporary buffer in infoPtr as there
6334 * isn't enough space in buffer passed to us by the
6335 * tooltip control */
6336 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6337 if (infoPtr
->pszTooltipText
)
6339 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6340 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6346 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6351 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6353 /* last resort: send notification on to app */
6354 /* FIXME: find out what is really used here */
6355 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, 0, (LPARAM
)lpnmtdi
);
6359 inline static LRESULT
6360 TOOLBAR_Notify (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6362 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6363 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
6365 switch (lpnmh
->code
)
6369 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
6371 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6372 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6373 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6377 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6378 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6386 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lParam
;
6388 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6389 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6390 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6391 lppgs
->iScroll
, lppgs
->iDir
);
6395 case TTN_GETDISPINFOW
:
6396 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lParam
);
6398 case TTN_GETDISPINFOA
:
6399 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6409 TOOLBAR_NotifyFormat(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6413 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam
, lParam
);
6415 if (lParam
== NF_QUERY
)
6418 if (lParam
== NF_REQUERY
) {
6419 format
= SendMessageW(infoPtr
->hwndNotify
,
6420 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6421 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6422 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6433 TOOLBAR_Paint (HWND hwnd
, WPARAM wParam
)
6435 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
6439 /* fill ps.rcPaint with a default rect */
6440 memcpy(&(ps
.rcPaint
), &(infoPtr
->rcBound
), sizeof(infoPtr
->rcBound
));
6442 hdc
= wParam
==0 ? BeginPaint(hwnd
, &ps
) : (HDC
)wParam
;
6444 TRACE("psrect=(%d,%d)-(%d,%d)\n",
6445 ps
.rcPaint
.left
, ps
.rcPaint
.top
,
6446 ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
6448 TOOLBAR_Refresh (hwnd
, hdc
, &ps
);
6449 if (!wParam
) EndPaint (hwnd
, &ps
);
6456 TOOLBAR_SetFocus (HWND hwnd
, WPARAM wParam
)
6458 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6460 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6462 /* make first item hot */
6463 if (infoPtr
->nNumButtons
> 0)
6464 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6471 TOOLBAR_SetRedraw (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6472 /*****************************************************
6475 * Handles the WM_SETREDRAW message.
6478 * According to testing V4.71 of COMCTL32 returns the
6479 * *previous* status of the redraw flag (either 0 or 1)
6480 * instead of the MSDN documented value of 0 if handled.
6481 * (For laughs see the "consistency" with same function
6484 *****************************************************/
6486 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6487 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6489 TRACE("set to %s\n",
6490 (wParam
) ? "TRUE" : "FALSE");
6491 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6493 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6495 return (oldredraw
) ? 1 : 0;
6500 TOOLBAR_Size (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6502 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6504 TRACE("sizing toolbar!\n");
6506 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6508 RECT delta_width
, delta_height
, client
, dummy
;
6509 DWORD min_x
, max_x
, min_y
, max_y
;
6510 TBUTTON_INFO
*btnPtr
;
6513 GetClientRect(hwnd
, &client
);
6514 if(client
.right
> infoPtr
->client_rect
.right
)
6516 min_x
= infoPtr
->client_rect
.right
;
6517 max_x
= client
.right
;
6521 max_x
= infoPtr
->client_rect
.right
;
6522 min_x
= client
.right
;
6524 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6526 min_y
= infoPtr
->client_rect
.bottom
;
6527 max_y
= client
.bottom
;
6531 max_y
= infoPtr
->client_rect
.bottom
;
6532 min_y
= client
.bottom
;
6535 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6536 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6538 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6539 btnPtr
= infoPtr
->buttons
;
6540 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6541 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6542 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6543 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6545 GetClientRect(hwnd
, &infoPtr
->client_rect
);
6546 TOOLBAR_AutoSize(hwnd
);
6552 TOOLBAR_StyleChanged (HWND hwnd
, INT nType
, LPSTYLESTRUCT lpStyle
)
6554 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6556 if (nType
== GWL_STYLE
)
6558 DWORD dwOldStyle
= infoPtr
->dwStyle
;
6560 if (lpStyle
->styleNew
& TBSTYLE_LIST
)
6561 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
6563 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
6565 TOOLBAR_CheckStyle (hwnd
, lpStyle
->styleNew
);
6567 TRACE("new style 0x%08x\n", lpStyle
->styleNew
);
6569 infoPtr
->dwStyle
= lpStyle
->styleNew
;
6571 /* only resize if one of the CCS_* styles was changed */
6572 if ((dwOldStyle
^ lpStyle
->styleNew
) & COMMON_STYLES
)
6574 TOOLBAR_AutoSize (hwnd
);
6576 InvalidateRect(hwnd
, NULL
, TRUE
);
6585 TOOLBAR_SysColorChange (HWND hwnd
)
6587 COMCTL32_RefreshSysColors();
6593 /* update theme after a WM_THEMECHANGED message */
6594 static LRESULT
theme_changed (HWND hwnd
)
6596 HTHEME theme
= GetWindowTheme (hwnd
);
6597 CloseThemeData (theme
);
6598 OpenThemeData (hwnd
, themeClass
);
6603 static LRESULT WINAPI
6604 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6606 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6608 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6609 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6611 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6612 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6617 return TOOLBAR_AddBitmap (hwnd
, wParam
, lParam
);
6619 case TB_ADDBUTTONSA
:
6620 return TOOLBAR_AddButtonsT(hwnd
, wParam
, lParam
, FALSE
);
6622 case TB_ADDBUTTONSW
:
6623 return TOOLBAR_AddButtonsT(hwnd
, wParam
, lParam
, TRUE
);
6626 return TOOLBAR_AddStringA (hwnd
, wParam
, lParam
);
6629 return TOOLBAR_AddStringW (hwnd
, wParam
, lParam
);
6632 return TOOLBAR_AutoSize (hwnd
);
6634 case TB_BUTTONCOUNT
:
6635 return TOOLBAR_ButtonCount (hwnd
, wParam
, lParam
);
6637 case TB_BUTTONSTRUCTSIZE
:
6638 return TOOLBAR_ButtonStructSize (hwnd
, wParam
, lParam
);
6640 case TB_CHANGEBITMAP
:
6641 return TOOLBAR_ChangeBitmap (hwnd
, wParam
, lParam
);
6643 case TB_CHECKBUTTON
:
6644 return TOOLBAR_CheckButton (hwnd
, wParam
, lParam
);
6646 case TB_COMMANDTOINDEX
:
6647 return TOOLBAR_CommandToIndex (hwnd
, wParam
, lParam
);
6650 return TOOLBAR_Customize (hwnd
);
6652 case TB_DELETEBUTTON
:
6653 return TOOLBAR_DeleteButton (hwnd
, wParam
, lParam
);
6655 case TB_ENABLEBUTTON
:
6656 return TOOLBAR_EnableButton (hwnd
, wParam
, lParam
);
6658 case TB_GETANCHORHIGHLIGHT
:
6659 return TOOLBAR_GetAnchorHighlight (hwnd
);
6662 return TOOLBAR_GetBitmap (hwnd
, wParam
, lParam
);
6664 case TB_GETBITMAPFLAGS
:
6665 return TOOLBAR_GetBitmapFlags (hwnd
, wParam
, lParam
);
6668 return TOOLBAR_GetButton (hwnd
, wParam
, lParam
);
6670 case TB_GETBUTTONINFOA
:
6671 return TOOLBAR_GetButtonInfoA (hwnd
, wParam
, lParam
);
6673 case TB_GETBUTTONINFOW
:
6674 return TOOLBAR_GetButtonInfoW (hwnd
, wParam
, lParam
);
6676 case TB_GETBUTTONSIZE
:
6677 return TOOLBAR_GetButtonSize (hwnd
);
6679 case TB_GETBUTTONTEXTA
:
6680 return TOOLBAR_GetButtonTextA (hwnd
, wParam
, lParam
);
6682 case TB_GETBUTTONTEXTW
:
6683 return TOOLBAR_GetButtonTextW (hwnd
, wParam
, lParam
);
6685 case TB_GETDISABLEDIMAGELIST
:
6686 return TOOLBAR_GetDisabledImageList (hwnd
, wParam
, lParam
);
6688 case TB_GETEXTENDEDSTYLE
:
6689 return TOOLBAR_GetExtendedStyle (hwnd
);
6691 case TB_GETHOTIMAGELIST
:
6692 return TOOLBAR_GetHotImageList (hwnd
, wParam
, lParam
);
6695 return TOOLBAR_GetHotItem (hwnd
);
6697 case TB_GETIMAGELIST
:
6698 return TOOLBAR_GetDefImageList (hwnd
, wParam
, lParam
);
6700 case TB_GETINSERTMARK
:
6701 return TOOLBAR_GetInsertMark (hwnd
, wParam
, lParam
);
6703 case TB_GETINSERTMARKCOLOR
:
6704 return TOOLBAR_GetInsertMarkColor (hwnd
, wParam
, lParam
);
6706 case TB_GETITEMRECT
:
6707 return TOOLBAR_GetItemRect (hwnd
, wParam
, lParam
);
6710 return TOOLBAR_GetMaxSize (hwnd
, wParam
, lParam
);
6712 /* case TB_GETOBJECT: */ /* 4.71 */
6715 return TOOLBAR_GetPadding (hwnd
);
6718 return TOOLBAR_GetRect (hwnd
, wParam
, lParam
);
6721 return TOOLBAR_GetRows (hwnd
, wParam
, lParam
);
6724 return TOOLBAR_GetState (hwnd
, wParam
, lParam
);
6727 return TOOLBAR_GetStringA (hwnd
, wParam
, lParam
);
6730 return TOOLBAR_GetStringW (hwnd
, wParam
, lParam
);
6733 return TOOLBAR_GetStyle (hwnd
, wParam
, lParam
);
6735 case TB_GETTEXTROWS
:
6736 return TOOLBAR_GetTextRows (hwnd
, wParam
, lParam
);
6738 case TB_GETTOOLTIPS
:
6739 return TOOLBAR_GetToolTips (hwnd
, wParam
, lParam
);
6741 case TB_GETUNICODEFORMAT
:
6742 return TOOLBAR_GetUnicodeFormat (hwnd
, wParam
, lParam
);
6745 return TOOLBAR_HideButton (hwnd
, wParam
, lParam
);
6748 return TOOLBAR_HitTest (hwnd
, wParam
, lParam
);
6750 case TB_INDETERMINATE
:
6751 return TOOLBAR_Indeterminate (hwnd
, wParam
, lParam
);
6753 case TB_INSERTBUTTONA
:
6754 return TOOLBAR_InsertButtonT(hwnd
, wParam
, lParam
, FALSE
);
6756 case TB_INSERTBUTTONW
:
6757 return TOOLBAR_InsertButtonT(hwnd
, wParam
, lParam
, TRUE
);
6759 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6761 case TB_ISBUTTONCHECKED
:
6762 return TOOLBAR_IsButtonChecked (hwnd
, wParam
, lParam
);
6764 case TB_ISBUTTONENABLED
:
6765 return TOOLBAR_IsButtonEnabled (hwnd
, wParam
, lParam
);
6767 case TB_ISBUTTONHIDDEN
:
6768 return TOOLBAR_IsButtonHidden (hwnd
, wParam
, lParam
);
6770 case TB_ISBUTTONHIGHLIGHTED
:
6771 return TOOLBAR_IsButtonHighlighted (hwnd
, wParam
, lParam
);
6773 case TB_ISBUTTONINDETERMINATE
:
6774 return TOOLBAR_IsButtonIndeterminate (hwnd
, wParam
, lParam
);
6776 case TB_ISBUTTONPRESSED
:
6777 return TOOLBAR_IsButtonPressed (hwnd
, wParam
, lParam
);
6780 return TOOLBAR_LoadImages (hwnd
, wParam
, lParam
);
6782 case TB_MAPACCELERATORA
:
6783 case TB_MAPACCELERATORW
:
6784 return TOOLBAR_MapAccelerator (hwnd
, wParam
, lParam
);
6787 return TOOLBAR_MarkButton (hwnd
, wParam
, lParam
);
6790 return TOOLBAR_MoveButton (hwnd
, wParam
, lParam
);
6792 case TB_PRESSBUTTON
:
6793 return TOOLBAR_PressButton (hwnd
, wParam
, lParam
);
6795 case TB_REPLACEBITMAP
:
6796 return TOOLBAR_ReplaceBitmap (hwnd
, wParam
, lParam
);
6798 case TB_SAVERESTOREA
:
6799 return TOOLBAR_SaveRestoreA (hwnd
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6801 case TB_SAVERESTOREW
:
6802 return TOOLBAR_SaveRestoreW (hwnd
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6804 case TB_SETANCHORHIGHLIGHT
:
6805 return TOOLBAR_SetAnchorHighlight (hwnd
, wParam
);
6807 case TB_SETBITMAPSIZE
:
6808 return TOOLBAR_SetBitmapSize (hwnd
, wParam
, lParam
);
6810 case TB_SETBUTTONINFOA
:
6811 return TOOLBAR_SetButtonInfoA (hwnd
, wParam
, lParam
);
6813 case TB_SETBUTTONINFOW
:
6814 return TOOLBAR_SetButtonInfoW (hwnd
, wParam
, lParam
);
6816 case TB_SETBUTTONSIZE
:
6817 return TOOLBAR_SetButtonSize (hwnd
, wParam
, lParam
);
6819 case TB_SETBUTTONWIDTH
:
6820 return TOOLBAR_SetButtonWidth (hwnd
, wParam
, lParam
);
6823 return TOOLBAR_SetCmdId (hwnd
, wParam
, lParam
);
6825 case TB_SETDISABLEDIMAGELIST
:
6826 return TOOLBAR_SetDisabledImageList (hwnd
, wParam
, lParam
);
6828 case TB_SETDRAWTEXTFLAGS
:
6829 return TOOLBAR_SetDrawTextFlags (hwnd
, wParam
, lParam
);
6831 case TB_SETEXTENDEDSTYLE
:
6832 return TOOLBAR_SetExtendedStyle (hwnd
, wParam
, lParam
);
6834 case TB_SETHOTIMAGELIST
:
6835 return TOOLBAR_SetHotImageList (hwnd
, wParam
, lParam
);
6838 return TOOLBAR_SetHotItem (hwnd
, wParam
);
6840 case TB_SETIMAGELIST
:
6841 return TOOLBAR_SetImageList (hwnd
, wParam
, lParam
);
6844 return TOOLBAR_SetIndent (hwnd
, wParam
, lParam
);
6846 case TB_SETINSERTMARK
:
6847 return TOOLBAR_SetInsertMark (hwnd
, wParam
, lParam
);
6849 case TB_SETINSERTMARKCOLOR
:
6850 return TOOLBAR_SetInsertMarkColor (hwnd
, wParam
, lParam
);
6852 case TB_SETMAXTEXTROWS
:
6853 return TOOLBAR_SetMaxTextRows (hwnd
, wParam
, lParam
);
6856 return TOOLBAR_SetPadding (hwnd
, wParam
, lParam
);
6859 return TOOLBAR_SetParent (hwnd
, wParam
, lParam
);
6862 return TOOLBAR_SetRows (hwnd
, wParam
, lParam
);
6865 return TOOLBAR_SetState (hwnd
, wParam
, lParam
);
6868 return TOOLBAR_SetStyle (hwnd
, wParam
, lParam
);
6870 case TB_SETTOOLTIPS
:
6871 return TOOLBAR_SetToolTips (hwnd
, wParam
, lParam
);
6873 case TB_SETUNICODEFORMAT
:
6874 return TOOLBAR_SetUnicodeFormat (hwnd
, wParam
, lParam
);
6877 return TOOLBAR_Unkwn45D(hwnd
, wParam
, lParam
);
6880 return TOOLBAR_Unkwn45E (hwnd
, wParam
, lParam
);
6883 return TOOLBAR_Unkwn460(hwnd
, wParam
, lParam
);
6886 return TOOLBAR_Unkwn462(hwnd
, wParam
, lParam
);
6889 return TOOLBAR_Unkwn463 (hwnd
, wParam
, lParam
);
6892 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6894 /* Common Control Messages */
6896 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6897 case CCM_GETCOLORSCHEME
:
6898 return TOOLBAR_GetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
6900 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6901 case CCM_SETCOLORSCHEME
:
6902 return TOOLBAR_SetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
6904 case CCM_GETVERSION
:
6905 return TOOLBAR_GetVersion (hwnd
);
6907 case CCM_SETVERSION
:
6908 return TOOLBAR_SetVersion (hwnd
, (INT
)wParam
);
6914 return TOOLBAR_Create (hwnd
, wParam
, lParam
);
6917 return TOOLBAR_Destroy (hwnd
, wParam
, lParam
);
6920 return TOOLBAR_EraseBackground (hwnd
, wParam
, lParam
);
6923 return TOOLBAR_GetFont (hwnd
, wParam
, lParam
);
6926 return TOOLBAR_KeyDown (hwnd
, wParam
, lParam
);
6928 /* case WM_KILLFOCUS: */
6930 case WM_LBUTTONDBLCLK
:
6931 return TOOLBAR_LButtonDblClk (hwnd
, wParam
, lParam
);
6933 case WM_LBUTTONDOWN
:
6934 return TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
6937 return TOOLBAR_LButtonUp (hwnd
, wParam
, lParam
);
6940 return TOOLBAR_RButtonUp (hwnd
, wParam
, lParam
);
6942 case WM_RBUTTONDBLCLK
:
6943 return TOOLBAR_RButtonDblClk (hwnd
, wParam
, lParam
);
6946 return TOOLBAR_MouseMove (hwnd
, wParam
, lParam
);
6949 return TOOLBAR_MouseLeave (hwnd
, wParam
, lParam
);
6951 case WM_CAPTURECHANGED
:
6952 return TOOLBAR_CaptureChanged(hwnd
);
6955 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6958 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6961 return TOOLBAR_NCCreate (hwnd
, wParam
, lParam
);
6964 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
6967 return TOOLBAR_Notify (hwnd
, wParam
, lParam
);
6969 case WM_NOTIFYFORMAT
:
6970 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
6972 case WM_PRINTCLIENT
:
6974 return TOOLBAR_Paint (hwnd
, wParam
);
6977 return TOOLBAR_SetFocus (hwnd
, wParam
);
6980 return TOOLBAR_SetRedraw (hwnd
, wParam
, lParam
);
6983 return TOOLBAR_Size (hwnd
, wParam
, lParam
);
6985 case WM_STYLECHANGED
:
6986 return TOOLBAR_StyleChanged (hwnd
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
6988 case WM_SYSCOLORCHANGE
:
6989 return TOOLBAR_SysColorChange (hwnd
);
6991 case WM_THEMECHANGED
:
6992 return theme_changed (hwnd
);
6994 /* case WM_WININICHANGE: */
6999 case WM_MEASUREITEM
:
7001 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
7003 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7004 case PGM_FORWARDMOUSE
:
7005 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7008 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
7009 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7010 uMsg
, wParam
, lParam
);
7011 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7017 TOOLBAR_Register (void)
7021 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
7022 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
7023 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
7024 wndClass
.cbClsExtra
= 0;
7025 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
7026 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
7027 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
7028 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
7030 RegisterClassW (&wndClass
);
7035 TOOLBAR_Unregister (void)
7037 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
7040 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
7045 /* Check if the entry already exists */
7046 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
7048 /* If this is a new entry we must create it and insert into the array */
7053 c
= (PIMLENTRY
) Alloc(sizeof(IMLENTRY
));
7056 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
7057 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
7072 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
7076 for (i
= 0; i
< *cies
; i
++)
7086 static PIMLENTRY
TOOLBAR_GetImageListEntry(PIMLENTRY
*pies
, INT cies
, INT id
)
7094 for (i
= 0; i
< cies
; i
++)
7096 if (pies
[i
]->id
== id
)
7108 static HIMAGELIST
TOOLBAR_GetImageList(PIMLENTRY
*pies
, INT cies
, INT id
)
7110 HIMAGELIST himlDef
= 0;
7111 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
7114 himlDef
= pie
->himl
;
7120 static BOOL
TOOLBAR_GetButtonInfo(TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
7122 if (infoPtr
->bUnicode
)
7123 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
7130 nmtba
.iItem
= nmtb
->iItem
;
7131 nmtba
.pszText
= Buffer
;
7132 nmtba
.cchText
= 256;
7133 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
7135 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
7137 int ccht
= strlen(nmtba
.pszText
);
7139 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)nmtba
.pszText
, -1,
7140 nmtb
->pszText
, nmtb
->cchText
);
7142 memcpy(&nmtb
->tbButton
, &nmtba
.tbButton
, sizeof(TBBUTTON
));
7151 static BOOL
TOOLBAR_IsButtonRemovable(TOOLBAR_INFO
*infoPtr
,
7152 int iItem
, PCUSTOMBUTTON btnInfo
)
7156 /* MSDN states that iItem is the index of the button, rather than the
7157 * command ID as used by every other NMTOOLBAR notification */
7159 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
7161 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);