4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
38 * - TB_INSERTMARKHITTEST
46 * - Button wrapping (under construction).
47 * - Fix TB_SETROWS and Separators.
48 * - iListGap custom draw support.
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
79 #include "wine/unicode.h"
85 #include "wine/debug.h"
87 WINE_DEFAULT_DEBUG_CHANNEL(toolbar
);
89 static HCURSOR hCursorDrag
= NULL
;
98 BYTE bDropDownPressed
;
103 INT cx
; /* manually set size */
117 } IMLENTRY
, *PIMLENTRY
;
121 DWORD dwStructSize
; /* size of TBBUTTON struct */
122 INT nWidth
; /* width of the toolbar */
124 RECT rcBound
; /* bounding rectangle */
130 INT nRows
; /* number of button rows */
131 INT nMaxTextRows
; /* maximum number of text rows */
132 INT cxMin
; /* minimum button width */
133 INT cxMax
; /* maximum button width */
134 INT nNumButtons
; /* number of buttons */
135 INT nNumBitmaps
; /* number of bitmaps */
136 INT nNumStrings
; /* number of strings */
138 INT nButtonDown
; /* toolbar button being pressed or -1 if none */
139 INT nButtonDrag
; /* toolbar button being dragged or -1 if none */
141 INT nHotItem
; /* index of the "hot" item */
142 SIZE szPadding
; /* padding values around button */
143 INT iTopMargin
; /* the top margin */
144 INT iListGap
; /* default gap between text and image for toolbar with list style */
146 HFONT hFont
; /* text font */
147 HIMAGELIST himlInt
; /* image list created internally */
148 PIMLENTRY
*himlDef
; /* default image list array */
149 INT cimlDef
; /* default image list array count */
150 PIMLENTRY
*himlHot
; /* hot image list array */
151 INT cimlHot
; /* hot image list array count */
152 PIMLENTRY
*himlDis
; /* disabled image list array */
153 INT cimlDis
; /* disabled image list array count */
154 HWND hwndToolTip
; /* handle to tool tip control */
155 HWND hwndNotify
; /* handle to the window that gets notifications */
156 HWND hwndSelf
; /* my own handle */
157 BOOL bAnchor
; /* anchor highlight enabled */
158 BOOL bDoRedraw
; /* Redraw status */
159 BOOL bDragOutSent
; /* has TBN_DRAGOUT notification been sent for this drag? */
160 BOOL bUnicode
; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
161 BOOL bCaptured
; /* mouse captured? */
162 DWORD dwStyle
; /* regular toolbar style */
163 DWORD dwExStyle
; /* extended toolbar style */
164 DWORD dwDTFlags
; /* DrawText flags */
166 COLORREF clrInsertMark
; /* insert mark color */
167 COLORREF clrBtnHighlight
; /* color for Flat Separator */
168 COLORREF clrBtnShadow
; /* color for Flag Separator */
170 LPWSTR pszTooltipText
; /* temporary store for a string > 80 characters
171 * for TTN_GETDISPINFOW notification */
172 TBINSERTMARK tbim
; /* info on insertion mark */
173 TBUTTON_INFO
*buttons
; /* pointer to button array */
174 LPWSTR
*strings
; /* pointer to string array */
175 TBITMAP_INFO
*bitmaps
;
176 } TOOLBAR_INFO
, *PTOOLBAR_INFO
;
179 /* used by customization dialog */
182 PTOOLBAR_INFO tbInfo
;
184 } CUSTDLG_INFO
, *PCUSTDLG_INFO
;
192 } CUSTOMBUTTON
, *PCUSTOMBUTTON
;
201 #define SEPARATOR_WIDTH 8
203 #define BOTTOM_BORDER 2
204 #define DDARROW_WIDTH 11
205 #define ARROW_HEIGHT 3
206 #define INSERTMARK_WIDTH 2
212 /* vertical padding used in list mode when image is present */
215 /* how wide to treat the bitmap if it isn't present */
216 #define NONLIST_NOTEXT_OFFSET 2
218 #define TOOLBAR_NOWHERE (-1)
220 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
221 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
222 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
224 /* Used to find undocumented extended styles */
225 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
226 TBSTYLE_EX_UNDOC1 | \
227 TBSTYLE_EX_MIXEDBUTTONS | \
228 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
230 /* all of the CCS_ styles */
231 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
232 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
234 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
235 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
236 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
237 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
238 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
240 static const WCHAR themeClass
[] = { 'T','o','o','l','b','a','r',0 };
242 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
);
243 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, PCUSTOMBUTTON btnInfo
);
244 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
);
245 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
);
246 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
);
247 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
);
248 static LRESULT
TOOLBAR_LButtonDown(HWND hwnd
, WPARAM wParam
, LPARAM lParam
);
249 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
);
250 static void TOOLBAR_LayoutToolbar(HWND hwnd
);
251 static LRESULT
TOOLBAR_AutoSize(HWND hwnd
);
252 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
);
253 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
256 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
);
258 static inline int default_top_margin(const TOOLBAR_INFO
*infoPtr
)
260 return (infoPtr
->dwStyle
& TBSTYLE_FLAT
? 0 : TOP_BORDER
);
264 TOOLBAR_GetText(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
266 LPWSTR lpText
= NULL
;
268 /* NOTE: iString == -1 is undocumented */
269 if ((HIWORD(btnPtr
->iString
) != 0) && (btnPtr
->iString
!= -1))
270 lpText
= (LPWSTR
)btnPtr
->iString
;
271 else if ((btnPtr
->iString
>= 0) && (btnPtr
->iString
< infoPtr
->nNumStrings
))
272 lpText
= infoPtr
->strings
[btnPtr
->iString
];
278 TOOLBAR_DumpButton(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*bP
, INT btn_num
, BOOL internal
)
280 if (TRACE_ON(toolbar
)){
281 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
282 btn_num
, bP
->idCommand
, GETIBITMAP(infoPtr
, bP
->iBitmap
),
283 bP
->fsState
, bP
->fsStyle
, bP
->dwData
, bP
->iString
);
284 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr
,bP
)));
286 TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n",
287 btn_num
, bP
->idCommand
,
288 (bP
->bHot
) ? "TRUE":"FALSE", bP
->nRow
,
289 bP
->rect
.left
, bP
->rect
.top
,
290 bP
->rect
.right
, bP
->rect
.bottom
);
296 TOOLBAR_DumpToolbar(const TOOLBAR_INFO
*iP
, INT line
)
298 if (TRACE_ON(toolbar
)) {
301 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
303 iP
->dwExStyle
, iP
->nNumButtons
, iP
->nNumBitmaps
,
304 iP
->nNumStrings
, iP
->dwStyle
);
305 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
307 iP
->himlInt
, iP
->himlDef
, iP
->himlHot
, iP
->himlDis
,
308 (iP
->bDoRedraw
) ? "TRUE" : "FALSE");
309 for(i
=0; i
<iP
->nNumButtons
; i
++) {
310 TOOLBAR_DumpButton(iP
, &iP
->buttons
[i
], i
, TRUE
);
316 /***********************************************************************
319 * This function validates that the styles set are implemented and
320 * issues FIXME's warning of possible problems. In a perfect world this
321 * function should be null.
324 TOOLBAR_CheckStyle (HWND hwnd
, DWORD dwStyle
)
326 if (dwStyle
& TBSTYLE_REGISTERDROP
)
327 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd
);
332 TOOLBAR_SendNotify (NMHDR
*nmhdr
, const TOOLBAR_INFO
*infoPtr
, UINT code
)
334 if(!IsWindow(infoPtr
->hwndSelf
))
335 return 0; /* we have just been destroyed */
337 nmhdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
338 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
341 TRACE("to window %p, code=%08x, %s\n", infoPtr
->hwndNotify
, code
,
342 (infoPtr
->bUnicode
) ? "via Unicode" : "via ANSI");
344 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhdr
->idFrom
, (LPARAM
)nmhdr
);
347 /***********************************************************************
348 * TOOLBAR_GetBitmapIndex
350 * This function returns the bitmap index associated with a button.
351 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
352 * is issued to retrieve the index.
355 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
357 INT ret
= btnPtr
->iBitmap
;
359 if (ret
== I_IMAGECALLBACK
)
361 /* issue TBN_GETDISPINFO */
364 memset(&nmgd
, 0, sizeof(nmgd
));
365 nmgd
.idCommand
= btnPtr
->idCommand
;
366 nmgd
.lParam
= btnPtr
->dwData
;
367 nmgd
.dwMask
= TBNF_IMAGE
;
369 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
370 TOOLBAR_SendNotify(&nmgd
.hdr
, infoPtr
, TBN_GETDISPINFOW
);
371 if (nmgd
.dwMask
& TBNF_DI_SETITEM
)
372 btnPtr
->iBitmap
= nmgd
.iImage
;
374 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
375 ret
, nmgd
.dwMask
, infoPtr
->nNumBitmaps
);
378 if (ret
!= I_IMAGENONE
)
379 ret
= GETIBITMAP(infoPtr
, ret
);
386 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO
*infoPtr
, INT index
)
389 INT id
= GETHIMLID(infoPtr
, index
);
390 INT iBitmap
= GETIBITMAP(infoPtr
, index
);
392 if (((himl
= GETDEFIMAGELIST(infoPtr
, id
)) &&
393 iBitmap
>= 0 && iBitmap
< ImageList_GetImageCount(himl
)) ||
394 (index
== I_IMAGECALLBACK
))
402 TOOLBAR_IsValidImageList(const TOOLBAR_INFO
*infoPtr
, INT index
)
404 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, index
));
405 return (himl
!= NULL
) && (ImageList_GetImageCount(himl
) > 0);
409 /***********************************************************************
410 * TOOLBAR_GetImageListForDrawing
412 * This function validates the bitmap index (including I_IMAGECALLBACK
413 * functionality) and returns the corresponding image list.
416 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
,
417 IMAGE_LIST_TYPE imagelist
, INT
* index
)
421 if (!TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
)) {
422 if (btnPtr
->iBitmap
== I_IMAGENONE
) return NULL
;
423 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
424 HIWORD(btnPtr
->iBitmap
), LOWORD(btnPtr
->iBitmap
), infoPtr
->nNumBitmaps
);
428 if ((*index
= TOOLBAR_GetBitmapIndex(infoPtr
, btnPtr
)) < 0) {
429 if ((*index
== I_IMAGECALLBACK
) ||
430 (*index
== I_IMAGENONE
)) return NULL
;
431 ERR("TBN_GETDISPINFO returned invalid index %d\n",
438 case IMAGE_LIST_DEFAULT
:
439 himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
442 himl
= GETHOTIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
444 case IMAGE_LIST_DISABLED
:
445 himl
= GETDISIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
449 FIXME("Shouldn't reach here\n");
453 TRACE("no image list\n");
460 TOOLBAR_DrawFlatSeparator (const RECT
*lpRect
, HDC hdc
, const TOOLBAR_INFO
*infoPtr
)
463 COLORREF oldcolor
, newcolor
;
465 myrect
.left
= (lpRect
->left
+ lpRect
->right
) / 2 - 1;
466 myrect
.right
= myrect
.left
+ 1;
467 myrect
.top
= lpRect
->top
+ 2;
468 myrect
.bottom
= lpRect
->bottom
- 2;
470 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
471 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
472 oldcolor
= SetBkColor (hdc
, newcolor
);
473 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
475 myrect
.left
= myrect
.right
;
476 myrect
.right
= myrect
.left
+ 1;
478 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
479 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
480 SetBkColor (hdc
, newcolor
);
481 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
483 SetBkColor (hdc
, oldcolor
);
487 /***********************************************************************
488 * TOOLBAR_DrawDDFlatSeparator
490 * This function draws the separator that was flagged as BTNS_DROPDOWN.
491 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
492 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
493 * are horizontal as opposed to the vertical separators for not dropdown
496 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
499 TOOLBAR_DrawDDFlatSeparator (const RECT
*lpRect
, HDC hdc
, const TBUTTON_INFO
*btnPtr
,
500 const TOOLBAR_INFO
*infoPtr
)
503 COLORREF oldcolor
, newcolor
;
505 myrect
.left
= lpRect
->left
;
506 myrect
.right
= lpRect
->right
;
507 myrect
.top
= lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
- 2)/2;
508 myrect
.bottom
= myrect
.top
+ 1;
510 InflateRect (&myrect
, -2, 0);
512 TRACE("rect=(%d,%d)-(%d,%d)\n",
513 myrect
.left
, myrect
.top
, myrect
.right
, myrect
.bottom
);
515 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
516 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
517 oldcolor
= SetBkColor (hdc
, newcolor
);
518 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
520 myrect
.top
= myrect
.bottom
;
521 myrect
.bottom
= myrect
.top
+ 1;
523 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
524 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
525 SetBkColor (hdc
, newcolor
);
526 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
528 SetBkColor (hdc
, oldcolor
);
533 TOOLBAR_DrawArrow (HDC hdc
, INT left
, INT top
, COLORREF clr
)
538 if (!(hPen
= CreatePen( PS_SOLID
, 1, clr
))) return;
539 hOldPen
= SelectObject ( hdc
, hPen
);
542 MoveToEx (hdc
, x
, y
, NULL
);
543 LineTo (hdc
, x
+5, y
++); x
++;
544 MoveToEx (hdc
, x
, y
, NULL
);
545 LineTo (hdc
, x
+3, y
++); x
++;
546 MoveToEx (hdc
, x
, y
, NULL
);
547 LineTo (hdc
, x
+1, y
++);
548 SelectObject( hdc
, hOldPen
);
549 DeleteObject( hPen
);
553 * Draw the text string for this button.
554 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
555 * is non-zero, so we can simply check himlDef to see if we have
559 TOOLBAR_DrawString (const TOOLBAR_INFO
*infoPtr
, RECT
*rcText
, LPCWSTR lpText
,
560 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
562 HDC hdc
= tbcd
->nmcd
.hdc
;
565 COLORREF clrOldBk
= 0;
567 UINT state
= tbcd
->nmcd
.uItemState
;
571 TRACE("string=%s rect=(%d,%d)-(%d,%d)\n", debugstr_w(lpText
),
572 rcText
->left
, rcText
->top
, rcText
->right
, rcText
->bottom
);
574 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
575 if ((state
& CDIS_HOT
) && (dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)) {
576 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
578 else if (state
& CDIS_DISABLED
) {
579 clrOld
= SetTextColor (hdc
, tbcd
->clrBtnHighlight
);
580 OffsetRect (rcText
, 1, 1);
581 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
582 SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
583 OffsetRect (rcText
, -1, -1);
585 else if (state
& CDIS_INDETERMINATE
) {
586 clrOld
= SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
588 else if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
)) {
589 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
590 clrOldBk
= SetBkColor (hdc
, tbcd
->clrMark
);
591 oldBkMode
= SetBkMode (hdc
, tbcd
->nHLStringBkMode
);
594 clrOld
= SetTextColor (hdc
, tbcd
->clrText
);
597 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
598 SetTextColor (hdc
, clrOld
);
599 if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
))
601 SetBkColor (hdc
, clrOldBk
);
602 SetBkMode (hdc
, oldBkMode
);
604 SelectObject (hdc
, hOldFont
);
610 TOOLBAR_DrawPattern (const RECT
*lpRect
, const NMTBCUSTOMDRAW
*tbcd
)
612 HDC hdc
= tbcd
->nmcd
.hdc
;
613 HBRUSH hbr
= SelectObject (hdc
, tbcd
->hbrMonoDither
);
616 INT cx
= lpRect
->right
- lpRect
->left
;
617 INT cy
= lpRect
->bottom
- lpRect
->top
;
618 INT cxEdge
= GetSystemMetrics(SM_CXEDGE
);
619 INT cyEdge
= GetSystemMetrics(SM_CYEDGE
);
620 clrTextOld
= SetTextColor(hdc
, tbcd
->clrBtnHighlight
);
621 clrBkOld
= SetBkColor(hdc
, tbcd
->clrBtnFace
);
622 PatBlt (hdc
, lpRect
->left
+ cxEdge
, lpRect
->top
+ cyEdge
,
623 cx
- (2 * cxEdge
), cy
- (2 * cyEdge
), PATCOPY
);
624 SetBkColor(hdc
, clrBkOld
);
625 SetTextColor(hdc
, clrTextOld
);
626 SelectObject (hdc
, hbr
);
630 static void TOOLBAR_DrawMasked(HIMAGELIST himl
, int index
, HDC hdc
, INT x
, INT y
, UINT draw_flags
)
633 HBITMAP hbmMask
, hbmImage
;
634 HDC hdcMask
, hdcImage
;
636 ImageList_GetIconSize(himl
, &cx
, &cy
);
638 /* Create src image */
639 hdcImage
= CreateCompatibleDC(hdc
);
640 hbmImage
= CreateCompatibleBitmap(hdc
, cx
, cy
);
641 SelectObject(hdcImage
, hbmImage
);
642 ImageList_DrawEx(himl
, index
, hdcImage
, 0, 0, cx
, cy
,
643 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags
);
646 hdcMask
= CreateCompatibleDC(0);
647 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
648 SelectObject(hdcMask
, hbmMask
);
650 /* Remove the background and all white pixels */
651 ImageList_DrawEx(himl
, index
, hdcMask
, 0, 0, cx
, cy
,
652 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK
);
653 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
654 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
656 /* draw the new mask 'etched' to hdc */
657 SetBkColor(hdc
, RGB(255, 255, 255));
658 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
659 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
660 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
661 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
662 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
665 DeleteObject(hbmImage
);
667 DeleteObject (hbmMask
);
673 TOOLBAR_TranslateState(const TBUTTON_INFO
*btnPtr
)
677 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
678 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
679 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
680 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
681 retstate
|= (btnPtr
->bHot
) ? CDIS_HOT
: 0;
682 retstate
|= ((btnPtr
->fsState
& (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) == (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) ? CDIS_INDETERMINATE
: 0;
683 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
687 /* draws the image on a toolbar button */
689 TOOLBAR_DrawImage(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
,
690 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
692 HIMAGELIST himl
= NULL
;
693 BOOL draw_masked
= FALSE
;
696 UINT draw_flags
= ILD_TRANSPARENT
;
698 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
700 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
703 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
707 else if (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
||
708 ((tbcd
->nmcd
.uItemState
& CDIS_HOT
)
709 && ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))))
711 /* if hot, attempt to draw with hot image list, if fails,
712 use default image list */
713 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
715 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
718 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
723 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
724 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
727 if (!(dwItemCDFlag
& TBCDRF_NOMARK
) &&
728 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
729 draw_flags
|= ILD_BLEND50
;
731 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
732 index
, himl
, left
, top
, offset
);
735 TOOLBAR_DrawMasked (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
737 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
740 /* draws a blank frame for a toolbar button */
742 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
744 HDC hdc
= tbcd
->nmcd
.hdc
;
745 RECT rc
= tbcd
->nmcd
.rc
;
746 /* if the state is disabled or indeterminate then the button
747 * cannot have an interactive look like pressed or hot */
748 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
749 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
750 BOOL pressed_look
= !non_interactive_state
&&
751 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
752 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
754 /* app don't want us to draw any edges */
755 if (dwItemCDFlag
& TBCDRF_NOEDGES
)
758 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
761 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
762 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
763 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
768 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
770 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
771 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
776 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
, BOOL bDropDownPressed
, DWORD dwItemCDFlag
)
778 HDC hdc
= tbcd
->nmcd
.hdc
;
780 BOOL pressed
= bDropDownPressed
||
781 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
));
783 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
786 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
);
787 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
788 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
789 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
790 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
795 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
797 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
798 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
802 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
804 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
806 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
807 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
810 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
813 /* draws a complete toolbar button */
815 TOOLBAR_DrawButton (HWND hwnd
, TBUTTON_INFO
*btnPtr
, HDC hdc
, DWORD dwBaseCustDraw
)
817 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
818 DWORD dwStyle
= infoPtr
->dwStyle
;
819 BOOL hasDropDownArrow
= (TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) &&
820 (btnPtr
->fsStyle
& BTNS_DROPDOWN
)) ||
821 (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
822 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
823 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
824 RECT rc
, rcArrow
, rcBitmap
, rcText
;
825 LPWSTR lpText
= NULL
;
830 DWORD dwItemCustDraw
;
832 HTHEME theme
= GetWindowTheme (hwnd
);
835 CopyRect (&rcArrow
, &rc
);
837 /* separator - doesn't send NM_CUSTOMDRAW */
838 if (btnPtr
->fsStyle
& BTNS_SEP
) {
841 DrawThemeBackground (theme
, hdc
,
842 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
846 /* with the FLAT style, iBitmap is the width and has already */
847 /* been taken into consideration in calculating the width */
848 /* so now we need to draw the vertical separator */
849 /* empirical tests show that iBitmap can/will be non-zero */
850 /* when drawing the vertical bar... */
851 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
852 if (btnPtr
->fsStyle
& BTNS_DROPDOWN
)
853 TOOLBAR_DrawDDFlatSeparator (&rc
, hdc
, btnPtr
, infoPtr
);
855 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
857 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
858 FIXME("Draw some kind of separator: fsStyle=%x\n",
864 /* get a pointer to the text */
865 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
867 if (hasDropDownArrow
)
871 if (dwStyle
& TBSTYLE_FLAT
)
872 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
874 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
876 if (drawSepDropDownArrow
)
879 rcArrow
.left
= right
;
882 /* copy text & bitmap rects after adjusting for drop-down arrow
883 * so that text & bitmap is centred in the rectangle not containing
885 CopyRect(&rcText
, &rc
);
886 CopyRect(&rcBitmap
, &rc
);
888 /* Center the bitmap horizontally and vertically */
889 if (dwStyle
& TBSTYLE_LIST
)
892 infoPtr
->nMaxTextRows
> 0 &&
893 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
894 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
895 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
897 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
900 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
902 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
904 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
905 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
906 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
907 TRACE("Text=%s\n", debugstr_w(lpText
));
908 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
910 /* calculate text position */
913 rcText
.left
+= GetSystemMetrics(SM_CXEDGE
);
914 rcText
.right
-= GetSystemMetrics(SM_CXEDGE
);
915 if (dwStyle
& TBSTYLE_LIST
)
917 if (TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
))
918 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
922 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
923 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
925 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
929 /* Initialize fields in all cases, because we use these later
930 * NOTE: applications can and do alter these to customize their
932 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
933 tbcd
.clrText
= comctl32_color
.clrBtnText
;
934 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
935 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
936 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
937 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
938 tbcd
.clrHighlightHotTrack
= 0;
939 tbcd
.nStringBkMode
= TRANSPARENT
;
940 tbcd
.nHLStringBkMode
= OPAQUE
;
941 /* MSDN says that this is the text rectangle.
942 * But (why always a but) tracing of v5.7 of native shows
943 * that this is really a *relative* rectangle based on the
944 * the nmcd.rc. Also the left and top are always 0 ignoring
945 * any bitmap that might be present. */
946 tbcd
.rcText
.left
= 0;
948 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
949 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
950 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
953 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
955 /* FIXME: what are these used for? */
959 /* Issue Item Prepaint notify */
962 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
964 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
965 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
966 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
967 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
968 /* reset these fields so the user can't alter the behaviour like native */
972 dwItemCustDraw
= ntfret
& 0xffff;
973 dwItemCDFlag
= ntfret
& 0xffff0000;
974 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
976 /* save the only part of the rect that the user can change */
977 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
978 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
981 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
982 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
983 OffsetRect(&rcText
, 1, 1);
985 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
986 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
987 TOOLBAR_DrawPattern (&rc
, &tbcd
);
989 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
990 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
992 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
996 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
997 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
998 if (hasDropDownArrow
)
999 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
1000 SetBkColor(hdc
, oldclr
);
1006 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
1007 int stateId
= TS_NORMAL
;
1009 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1010 stateId
= TS_DISABLED
;
1011 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1012 stateId
= TS_PRESSED
;
1013 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1014 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1015 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1016 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1019 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &tbcd
.nmcd
.rc
, NULL
);
1022 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, dwItemCDFlag
);
1024 if (drawSepDropDownArrow
)
1028 int stateId
= TS_NORMAL
;
1030 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1031 stateId
= TS_DISABLED
;
1032 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1033 stateId
= TS_PRESSED
;
1034 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1035 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1036 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1039 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1040 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1043 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1046 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1047 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1048 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1049 SetBkMode (hdc
, oldBkMode
);
1051 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1053 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1055 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1057 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1058 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1060 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1062 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1063 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1066 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1069 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1071 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1072 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1079 TOOLBAR_Refresh (HWND hwnd
, HDC hdc
, const PAINTSTRUCT
*ps
)
1081 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1082 TBUTTON_INFO
*btnPtr
;
1084 RECT rcTemp
, rcClient
;
1085 NMTBCUSTOMDRAW tbcd
;
1087 DWORD dwBaseCustDraw
;
1089 /* the app has told us not to redraw the toolbar */
1090 if (!infoPtr
->bDoRedraw
)
1093 /* if imagelist belongs to the app, it can be changed
1094 by the app after setting it */
1095 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1097 infoPtr
->nNumBitmaps
= 0;
1098 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1099 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1102 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1104 /* change the imagelist icon size if we manage the list and it is necessary */
1105 TOOLBAR_CheckImageListIconSize(infoPtr
);
1107 /* Send initial notify */
1108 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1109 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1110 tbcd
.nmcd
.hdc
= hdc
;
1111 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1112 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1113 dwBaseCustDraw
= ntfret
& 0xffff;
1115 GetClientRect(hwnd
, &rcClient
);
1117 /* redraw necessary buttons */
1118 btnPtr
= infoPtr
->buttons
;
1119 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1122 if (!RectVisible(hdc
, &btnPtr
->rect
))
1124 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1126 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1127 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1131 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1132 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1134 TOOLBAR_DrawButton(hwnd
, btnPtr
, hdc
, dwBaseCustDraw
);
1137 /* draw insert mark if required */
1138 if (infoPtr
->tbim
.iButton
!= -1)
1140 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1142 rcInsertMark
.top
= rcButton
.top
;
1143 rcInsertMark
.bottom
= rcButton
.bottom
;
1144 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1145 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1147 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1148 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1151 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1153 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1154 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1155 tbcd
.nmcd
.hdc
= hdc
;
1156 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1157 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1161 /***********************************************************************
1162 * TOOLBAR_MeasureString
1164 * This function gets the width and height of a string in pixels. This
1165 * is done first by using GetTextExtentPoint to get the basic width
1166 * and height. The DrawText is called with DT_CALCRECT to get the exact
1167 * width. The reason is because the text may have more than one "&" (or
1168 * prefix characters as M$ likes to call them). The prefix character
1169 * indicates where the underline goes, except for the string "&&" which
1170 * is reduced to a single "&". GetTextExtentPoint does not process these
1171 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1174 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1175 HDC hdc
, LPSIZE lpSize
)
1182 if (infoPtr
->nMaxTextRows
> 0 &&
1183 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1184 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1185 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1187 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1189 if(lpText
!= NULL
) {
1190 /* first get size of all the text */
1191 GetTextExtentPoint32W (hdc
, lpText
, strlenW (lpText
), lpSize
);
1193 /* feed above size into the rectangle for DrawText */
1194 myrect
.left
= myrect
.top
= 0;
1195 myrect
.right
= lpSize
->cx
;
1196 myrect
.bottom
= lpSize
->cy
;
1198 /* Use DrawText to get true size as drawn (less pesky "&") */
1199 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1200 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1203 /* feed back to caller */
1204 lpSize
->cx
= myrect
.right
;
1205 lpSize
->cy
= myrect
.bottom
;
1209 TRACE("string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1212 /***********************************************************************
1213 * TOOLBAR_CalcStrings
1215 * This function walks through each string and measures it and returns
1216 * the largest height and width to caller.
1219 TOOLBAR_CalcStrings (HWND hwnd
, LPSIZE lpSize
)
1221 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1222 TBUTTON_INFO
*btnPtr
;
1231 if (infoPtr
->nMaxTextRows
== 0)
1235 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1237 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1241 GetTextMetricsW(hdc
, &tm
);
1242 lpSize
->cy
= tm
.tmHeight
;
1245 btnPtr
= infoPtr
->buttons
;
1246 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1247 if(TOOLBAR_HasText(infoPtr
, btnPtr
))
1249 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1250 if (sz
.cx
> lpSize
->cx
)
1252 if (sz
.cy
> lpSize
->cy
)
1257 SelectObject (hdc
, hOldFont
);
1258 ReleaseDC (hwnd
, hdc
);
1260 TRACE("max string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1263 /***********************************************************************
1264 * TOOLBAR_WrapToolbar
1266 * This function walks through the buttons and separators in the
1267 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1268 * wrapping should occur based on the width of the toolbar window.
1269 * It does *not* calculate button placement itself. That task
1270 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1271 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1272 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1274 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1275 * vertical toolbar lists.
1279 TOOLBAR_WrapToolbar( HWND hwnd
, DWORD dwStyle
)
1281 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1282 TBUTTON_INFO
*btnPtr
;
1285 BOOL bWrap
, bButtonWrap
;
1287 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1288 /* no layout is necessary. Applications may use this style */
1289 /* to perform their own layout on the toolbar. */
1290 if( !(dwStyle
& TBSTYLE_WRAPABLE
) &&
1291 !(infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
) ) return;
1293 btnPtr
= infoPtr
->buttons
;
1294 x
= infoPtr
->nIndent
;
1296 if (GetParent(hwnd
))
1298 /* this can get the parents width, to know how far we can extend
1299 * this toolbar. We cannot use its height, as there may be multiple
1300 * toolbars in a rebar control
1302 GetClientRect( GetParent(hwnd
), &rc
);
1303 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1307 GetWindowRect( hwnd
, &rc
);
1308 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1311 bButtonWrap
= FALSE
;
1313 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1314 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, infoPtr
->nWidth
,
1317 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1320 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1322 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1325 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1326 /* it is the actual width of the separator. This is used for */
1327 /* custom controls in toolbars. */
1329 /* BTNS_DROPDOWN separators are treated as buttons for */
1330 /* width. - GA 8/01 */
1331 if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1332 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
))
1333 cx
= (btnPtr
[i
].iBitmap
> 0) ?
1334 btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1336 cx
= infoPtr
->nButtonWidth
;
1338 /* Two or more adjacent separators form a separator group. */
1339 /* The first separator in a group should be wrapped to the */
1340 /* next row if the previous wrapping is on a button. */
1342 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1343 (i
+ 1 < infoPtr
->nNumButtons
) &&
1344 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1346 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1347 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1348 x
= infoPtr
->nIndent
;
1350 bButtonWrap
= FALSE
;
1354 /* The layout makes sure the bitmap is visible, but not the button. */
1355 /* Test added to also wrap after a button that starts a row but */
1356 /* is bigger than the area. - GA 8/01 */
1357 if (( x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2
1358 > infoPtr
->nWidth
) ||
1359 ((x
== infoPtr
->nIndent
) && (cx
> infoPtr
->nWidth
)))
1361 BOOL bFound
= FALSE
;
1363 /* If the current button is a separator and not hidden, */
1364 /* go to the next until it reaches a non separator. */
1365 /* Wrap the last separator if it is before a button. */
1366 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1367 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1368 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1369 i
< infoPtr
->nNumButtons
)
1375 if( bFound
&& i
< infoPtr
->nNumButtons
)
1378 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1379 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1380 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1381 x
= infoPtr
->nIndent
;
1382 bButtonWrap
= FALSE
;
1385 else if ( i
>= infoPtr
->nNumButtons
)
1388 /* If the current button is not a separator, find the last */
1389 /* separator and wrap it. */
1390 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1392 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1393 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1397 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1398 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1399 x
= infoPtr
->nIndent
;
1400 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1401 bButtonWrap
= FALSE
;
1406 /* If no separator available for wrapping, wrap one of */
1407 /* non-hidden previous button. */
1411 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1413 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1418 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1419 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1420 x
= infoPtr
->nIndent
;
1421 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1427 /* If all above failed, wrap the current button. */
1430 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1431 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1432 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1434 x
= infoPtr
->nIndent
;
1435 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1436 bButtonWrap
= FALSE
;
1442 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1443 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1450 /***********************************************************************
1451 * TOOLBAR_MeasureButton
1453 * Calculates the width and height required for a button. Used in
1454 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1455 * the width of buttons that are autosized.
1457 * Note that it would have been rather elegant to use one piece of code for
1458 * both the laying out of the toolbar and for controlling where button parts
1459 * are drawn, but the native control has inconsistencies between the two that
1460 * prevent this from being effectively. These inconsistencies can be seen as
1461 * artefacts where parts of the button appear outside of the bounding button
1464 * There are several cases for the calculation of the button dimensions and
1465 * button part positioning:
1472 * +--------------------------------------------------------+ ^
1474 * | | pad.cy / 2 | centred | |
1475 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1476 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1477 * | |<------------>| | | | |
1478 * | +--------------+ +------------+ | |
1479 * |<-------------------------------------->| | |
1480 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1482 * +--------------------------------------------------------+ -
1483 * <-------------------------------------------------------->
1484 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1486 * Without Bitmap (I_IMAGENONE):
1488 * +-----------------------------------+ ^
1490 * | | centred | | LISTPAD_CY +
1491 * | +------------+ | | szText.cy
1494 * | +------------+ | |
1495 * |<----------------->| | |
1496 * | cxedge |<-----------> | |
1498 * +-----------------------------------+ -
1499 * <----------------------------------->
1500 * szText.cx + pad.cx
1504 * +--------------------------------------+ ^
1506 * | | padding.cy/2 | | DEFPAD_CY +
1507 * | +------------+ | | nBitmapHeight
1510 * | +------------+ | |
1511 * |<------------------->| | |
1512 * | cxedge + iListGap/2 |<-----------> | |
1513 * | nBitmapWidth | |
1514 * +--------------------------------------+ -
1515 * <-------------------------------------->
1516 * 2*cxedge + nBitmapWidth + iListGap
1523 * +-----------------------------------+ ^
1525 * | | pad.cy / 2 | | nBitmapHeight +
1526 * | - | | szText.cy +
1527 * | +------------+ | | DEFPAD_CY + 1
1528 * | centred | Bitmap | | |
1529 * |<----------------->| | | |
1530 * | +------------+ | |
1534 * | centred +---------------+ | |
1535 * |<--------------->| Text | | |
1536 * | +---------------+ | |
1537 * +-----------------------------------+ -
1538 * <----------------------------------->
1539 * pad.cx + max(nBitmapWidth, szText.cx)
1541 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1543 * +---------------------------------------+ ^
1545 * | | 2 + pad.cy / 2 | |
1546 * | - | | szText.cy +
1547 * | centred +-----------------+ | | pad.cy + 2
1548 * |<--------------->| Text | | |
1549 * | +-----------------+ | |
1551 * +---------------------------------------+ -
1552 * <--------------------------------------->
1553 * 2*cxedge + pad.cx + szText.cx
1556 * As for with bitmaps, but with szText.cx zero.
1558 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1559 BOOL bHasBitmap
, BOOL bValidImageList
)
1562 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1564 /* set button height from bitmap / text height... */
1565 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1568 /* ... add on the necessary padding */
1569 if (bValidImageList
)
1572 sizeButton
.cy
+= DEFPAD_CY
;
1574 sizeButton
.cy
+= LISTPAD_CY
;
1577 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1579 /* calculate button width */
1582 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1583 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1584 if (sizeString
.cx
> 0)
1585 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1588 sizeButton
.cx
= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1594 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1595 if (sizeString
.cy
> 0)
1596 sizeButton
.cy
+= 1 + sizeString
.cy
;
1597 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1598 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1602 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1603 NONLIST_NOTEXT_OFFSET
;
1604 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1605 infoPtr
->szPadding
.cx
+ sizeString
.cx
;
1612 /***********************************************************************
1613 * TOOLBAR_CalcToolbar
1615 * This function calculates button and separator placement. It first
1616 * calculates the button sizes, gets the toolbar window width and then
1617 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1618 * on. It assigns a new location to each item and sends this location to
1619 * the tooltip window if appropriate. Finally, it updates the rcBound
1620 * rect and calculates the new required toolbar window height.
1623 TOOLBAR_CalcToolbar (HWND hwnd
)
1625 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
1626 SIZE sizeString
, sizeButton
;
1627 BOOL validImageList
= FALSE
;
1629 TOOLBAR_CalcStrings (hwnd
, &sizeString
);
1631 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1633 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1634 validImageList
= TRUE
;
1635 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1636 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1637 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1638 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1640 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1641 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1642 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1643 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1645 TOOLBAR_LayoutToolbar(hwnd
);
1649 TOOLBAR_LayoutToolbar(HWND hwnd
)
1651 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
1652 TBUTTON_INFO
*btnPtr
;
1654 INT i
, nRows
, nSepRows
;
1657 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1658 BOOL hasDropDownArrows
= TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
);
1660 TOOLBAR_WrapToolbar(hwnd
, infoPtr
->dwStyle
);
1662 x
= infoPtr
->nIndent
;
1663 y
= infoPtr
->iTopMargin
;
1664 cx
= infoPtr
->nButtonWidth
;
1665 cy
= infoPtr
->nButtonHeight
;
1667 nRows
= nSepRows
= 0;
1669 infoPtr
->rcBound
.top
= y
;
1670 infoPtr
->rcBound
.left
= x
;
1671 infoPtr
->rcBound
.bottom
= y
+ cy
;
1672 infoPtr
->rcBound
.right
= x
;
1674 btnPtr
= infoPtr
->buttons
;
1676 TRACE("cy=%d\n", cy
);
1678 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1681 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1683 SetRectEmpty (&btnPtr
->rect
);
1687 cy
= infoPtr
->nButtonHeight
;
1689 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1690 /* it is the actual width of the separator. This is used for */
1691 /* custom controls in toolbars. */
1692 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1693 if (btnPtr
->fsStyle
& BTNS_DROPDOWN
) {
1694 cy
= (btnPtr
->iBitmap
> 0) ?
1695 btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1696 cx
= infoPtr
->nButtonWidth
;
1699 cx
= (btnPtr
->iBitmap
> 0) ?
1700 btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1706 else if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1707 (btnPtr
->fsStyle
& BTNS_AUTOSIZE
))
1714 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1716 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1718 SelectObject (hdc
, hOldFont
);
1719 ReleaseDC (hwnd
, hdc
);
1721 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1722 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1727 cx
= infoPtr
->nButtonWidth
;
1729 /* if size has been set manually then don't add on extra space
1730 * for the drop down arrow */
1731 if (!btnPtr
->cx
&& hasDropDownArrows
&&
1732 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) || (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)))
1733 cx
+= DDARROW_WIDTH
;
1735 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1738 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1740 if (infoPtr
->rcBound
.left
> x
)
1741 infoPtr
->rcBound
.left
= x
;
1742 if (infoPtr
->rcBound
.right
< x
+ cx
)
1743 infoPtr
->rcBound
.right
= x
+ cx
;
1744 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1745 infoPtr
->rcBound
.bottom
= y
+ cy
;
1747 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1749 /* btnPtr->nRow is zero based. The space between the rows is */
1750 /* also considered as a row. */
1751 btnPtr
->nRow
= nRows
+ nSepRows
;
1753 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1754 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1759 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1763 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1764 /* it is the actual width of the separator. This is used for */
1765 /* custom controls in toolbars. */
1766 if ( !(btnPtr
->fsStyle
& BTNS_DROPDOWN
))
1767 y
+= cy
+ ( (btnPtr
->iBitmap
> 0 ) ?
1768 btnPtr
->iBitmap
: SEPARATOR_WIDTH
) * 2 /3;
1772 /* nSepRows is used to calculate the extra height follwoing */
1776 x
= infoPtr
->nIndent
;
1778 /* Increment row number unless this is the last button */
1779 /* and it has Wrap set. */
1780 if (i
!= infoPtr
->nNumButtons
-1)
1787 /* infoPtr->nRows is the number of rows on the toolbar */
1788 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1790 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1795 TOOLBAR_InternalHitTest (HWND hwnd
, const POINT
*lpPt
)
1797 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1798 TBUTTON_INFO
*btnPtr
;
1801 btnPtr
= infoPtr
->buttons
;
1802 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1803 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1806 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1807 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1808 TRACE(" ON SEPARATOR %d!\n", i
);
1813 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1814 TRACE(" ON BUTTON %d!\n", i
);
1820 TRACE(" NOWHERE!\n");
1821 return TOOLBAR_NOWHERE
;
1826 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1828 TBUTTON_INFO
*btnPtr
;
1831 if (CommandIsIndex
) {
1832 TRACE("command is really index command=%d\n", idCommand
);
1833 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1836 btnPtr
= infoPtr
->buttons
;
1837 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1838 if (btnPtr
->idCommand
== idCommand
) {
1839 TRACE("command=%d index=%d\n", idCommand
, i
);
1843 TRACE("no index found for command=%d\n", idCommand
);
1849 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1851 TBUTTON_INFO
*btnPtr
;
1854 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1857 /* check index button */
1858 btnPtr
= &infoPtr
->buttons
[nIndex
];
1859 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1860 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1864 /* check previous buttons */
1865 nRunIndex
= nIndex
- 1;
1866 while (nRunIndex
>= 0) {
1867 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1868 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1869 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1877 /* check next buttons */
1878 nRunIndex
= nIndex
+ 1;
1879 while (nRunIndex
< infoPtr
->nNumButtons
) {
1880 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1881 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1882 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1895 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1896 WPARAM wParam
, LPARAM lParam
)
1902 msg
.wParam
= wParam
;
1903 msg
.lParam
= lParam
;
1904 msg
.time
= GetMessageTime ();
1905 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
1906 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
1908 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1912 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1914 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
1917 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
1918 ti
.cbSize
= sizeof (TTTOOLINFOW
);
1919 ti
.hwnd
= infoPtr
->hwndSelf
;
1920 ti
.uId
= button
->idCommand
;
1922 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
1923 /* ti.lParam = random value from the stack? */
1925 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
1931 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1933 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
1936 ZeroMemory(&ti
, sizeof(ti
));
1937 ti
.cbSize
= sizeof(ti
);
1938 ti
.hwnd
= infoPtr
->hwndSelf
;
1939 ti
.uId
= button
->idCommand
;
1941 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
1945 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1947 /* Set the toolTip only for non-hidden, non-separator button */
1948 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
1952 ZeroMemory(&ti
, sizeof(ti
));
1953 ti
.cbSize
= sizeof(ti
);
1954 ti
.hwnd
= infoPtr
->hwndSelf
;
1955 ti
.uId
= button
->idCommand
;
1956 ti
.rect
= button
->rect
;
1957 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
1961 /* Creates the tooltip control */
1963 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
1966 NMTOOLTIPSCREATED nmttc
;
1968 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
1969 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1970 infoPtr
->hwndSelf
, 0, 0, 0);
1972 if (!infoPtr
->hwndToolTip
)
1975 /* Send NM_TOOLTIPSCREATED notification */
1976 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
1977 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
1979 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
1981 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
1982 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
1986 /* keeps available button list box sorted by button id */
1987 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
1991 PCUSTOMBUTTON btnInfo
;
1992 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
1994 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
1996 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
1998 /* position 0 is always separator */
1999 for (i
= 1; i
< count
; i
++)
2001 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2002 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2004 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2005 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2009 /* id higher than all others add to end */
2010 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2011 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2014 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2018 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2020 if (nIndexFrom
== nIndexTo
)
2023 /* MSDN states that iItem is the index of the button, rather than the
2024 * command ID as used by every other NMTOOLBAR notification */
2025 nmtb
.iItem
= nIndexFrom
;
2026 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2028 PCUSTOMBUTTON btnInfo
;
2030 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2031 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2033 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2035 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2036 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2037 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2038 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2041 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2043 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2045 /* last item is always separator, so -2 instead of -1 */
2046 if (nIndexTo
>= (count
- 2))
2047 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2049 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2051 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2052 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2054 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2058 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2062 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2064 /* MSDN states that iItem is the index of the button, rather than the
2065 * command ID as used by every other NMTOOLBAR notification */
2066 nmtb
.iItem
= nIndexAvail
;
2067 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2069 PCUSTOMBUTTON btnInfo
;
2071 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2072 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2073 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2075 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2077 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2079 /* remove from 'available buttons' list */
2080 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2081 if (nIndexAvail
== count
-1)
2082 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2084 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2088 PCUSTOMBUTTON btnNew
;
2090 /* duplicate 'separator' button */
2091 btnNew
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2092 memcpy(btnNew
, btnInfo
, sizeof(CUSTOMBUTTON
));
2096 /* insert into 'toolbar button' list */
2097 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2098 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2100 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2102 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2106 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2108 PCUSTOMBUTTON btnInfo
;
2109 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2111 TRACE("Remove: index %d\n", index
);
2113 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2115 /* send TBN_QUERYDELETE notification */
2116 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2120 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2121 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2123 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2125 /* insert into 'available button' list */
2126 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2127 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2131 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2135 /* drag list notification function for toolbar buttons list box */
2136 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2137 const DRAGLISTINFO
*pDLI
)
2139 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2140 switch (pDLI
->uNotification
)
2144 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2145 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2146 /* no dragging for last item (separator) */
2147 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2152 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2153 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2154 /* no dragging past last item (separator) */
2155 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2157 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2158 /* FIXME: native uses "move button" cursor */
2159 return DL_COPYCURSOR
;
2162 /* not over toolbar buttons list */
2163 if (nCurrentItem
< 0)
2165 POINT ptWindow
= pDLI
->ptCursor
;
2166 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2167 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2168 /* over available buttons list? */
2169 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2170 /* FIXME: native uses "move button" cursor */
2171 return DL_COPYCURSOR
;
2173 /* clear drag arrow */
2174 DrawInsert(hwnd
, hwndList
, -1);
2175 return DL_STOPCURSOR
;
2179 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2180 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2181 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2182 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2184 /* clear drag arrow */
2185 DrawInsert(hwnd
, hwndList
, -1);
2187 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2189 /* not over toolbar buttons list */
2192 POINT ptWindow
= pDLI
->ptCursor
;
2193 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2194 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2195 /* over available buttons list? */
2196 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2197 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2202 /* Clear drag arrow */
2203 DrawInsert(hwnd
, hwndList
, -1);
2210 /* drag list notification function for available buttons list box */
2211 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2212 const DRAGLISTINFO
*pDLI
)
2214 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2215 switch (pDLI
->uNotification
)
2221 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2222 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2223 /* no dragging past last item (separator) */
2224 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2226 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2227 /* FIXME: native uses "move button" cursor */
2228 return DL_COPYCURSOR
;
2231 /* not over toolbar buttons list */
2232 if (nCurrentItem
< 0)
2234 POINT ptWindow
= pDLI
->ptCursor
;
2235 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2236 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2237 /* over available buttons list? */
2238 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2239 /* FIXME: native uses "move button" cursor */
2240 return DL_COPYCURSOR
;
2242 /* clear drag arrow */
2243 DrawInsert(hwnd
, hwndList
, -1);
2244 return DL_STOPCURSOR
;
2248 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2249 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2250 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2251 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2253 /* clear drag arrow */
2254 DrawInsert(hwnd
, hwndList
, -1);
2256 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2260 /* Clear drag arrow */
2261 DrawInsert(hwnd
, hwndList
, -1);
2267 extern UINT uDragListMessage
;
2269 /***********************************************************************
2270 * TOOLBAR_CustomizeDialogProc
2271 * This function implements the toolbar customization dialog.
2273 static INT_PTR CALLBACK
2274 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2276 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2277 PCUSTOMBUTTON btnInfo
;
2279 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2284 custInfo
= (PCUSTDLG_INFO
)lParam
;
2285 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2292 NMTBINITCUSTOMIZE nmtbic
;
2294 infoPtr
= custInfo
->tbInfo
;
2296 /* send TBN_QUERYINSERT notification */
2297 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2299 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2302 nmtbic
.hwndDialog
= hwnd
;
2303 /* Send TBN_INITCUSTOMIZE notification */
2304 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2307 TRACE("TBNRF_HIDEHELP requested\n");
2308 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2311 /* add items to 'toolbar buttons' list and check if removable */
2312 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2314 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2315 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2316 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2317 btnInfo
->bVirtual
= FALSE
;
2318 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2320 /* send TBN_QUERYDELETE notification */
2321 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2323 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2324 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2327 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2329 /* insert separator button into 'available buttons' list */
2330 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2331 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2332 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2333 btnInfo
->bVirtual
= FALSE
;
2334 btnInfo
->bRemovable
= TRUE
;
2335 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2336 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2337 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2339 /* insert all buttons into dsa */
2342 /* send TBN_GETBUTTONINFO notification */
2345 nmtb
.pszText
= Buffer
;
2348 /* Clear previous button's text */
2349 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2351 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2354 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2355 nmtb
.tbButton
.fsStyle
, i
,
2356 nmtb
.tbButton
.idCommand
,
2357 nmtb
.tbButton
.iString
,
2358 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2361 /* insert button into the apropriate list */
2362 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2365 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2366 btnInfo
->bVirtual
= FALSE
;
2367 btnInfo
->bRemovable
= TRUE
;
2371 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2372 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2375 memcpy (&btnInfo
->btn
, &nmtb
.tbButton
, sizeof(TBBUTTON
));
2376 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2378 if (lstrlenW(nmtb
.pszText
))
2379 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2380 else if (nmtb
.tbButton
.iString
>= 0 &&
2381 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2383 lstrcpyW(btnInfo
->text
,
2384 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2389 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2392 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2394 /* select first item in the 'available' list */
2395 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2397 /* append 'virtual' separator button to the 'toolbar buttons' list */
2398 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2399 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2400 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2401 btnInfo
->bVirtual
= TRUE
;
2402 btnInfo
->bRemovable
= FALSE
;
2403 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2404 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2405 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2407 /* select last item in the 'toolbar' list */
2408 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2409 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2411 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2412 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2414 /* set focus and disable buttons */
2415 PostMessageW (hwnd
, WM_USER
, 0, 0);
2420 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2421 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2422 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2423 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2427 EndDialog(hwnd
, FALSE
);
2431 switch (LOWORD(wParam
))
2433 case IDC_TOOLBARBTN_LBOX
:
2434 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2436 PCUSTOMBUTTON btnInfo
;
2441 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2442 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2444 /* send TBN_QUERYINSERT notification */
2446 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2448 /* get list box item */
2449 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2451 if (index
== (count
- 1))
2453 /* last item (virtual separator) */
2454 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2455 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2457 else if (index
== (count
- 2))
2459 /* second last item (last non-virtual item) */
2460 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2461 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2463 else if (index
== 0)
2466 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2467 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2471 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2472 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2475 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2479 case IDC_MOVEUP_BTN
:
2481 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2482 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2486 case IDC_MOVEDN_BTN
: /* move down */
2488 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2489 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2493 case IDC_REMOVE_BTN
: /* remove button */
2495 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2497 if (LB_ERR
== index
)
2500 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2504 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2507 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2510 case IDOK
: /* Add button */
2515 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2516 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2518 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2523 EndDialog(hwnd
, FALSE
);
2533 /* delete items from 'toolbar buttons' listbox*/
2534 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2535 for (i
= 0; i
< count
; i
++)
2537 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2539 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2541 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2544 /* delete items from 'available buttons' listbox*/
2545 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2546 for (i
= 0; i
< count
; i
++)
2548 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2550 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2552 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2557 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2559 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2564 COLORREF oldText
= 0;
2568 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, (WPARAM
)lpdis
->itemID
, 0);
2569 if (btnInfo
== NULL
)
2571 FIXME("btnInfo invalid!\n");
2575 /* set colors and select objects */
2576 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2577 if (btnInfo
->bVirtual
)
2578 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2580 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2581 hPen
= CreatePen( PS_SOLID
, 1,
2582 GetSysColor( (lpdis
->itemState
& ODS_SELECTED
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2583 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2584 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2586 /* fill background rectangle */
2587 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2588 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2590 /* calculate button and text rectangles */
2591 CopyRect (&rcButton
, &lpdis
->rcItem
);
2592 InflateRect (&rcButton
, -1, -1);
2593 CopyRect (&rcText
, &rcButton
);
2594 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2595 rcText
.left
= rcButton
.right
+ 2;
2597 /* draw focus rectangle */
2598 if (lpdis
->itemState
& ODS_FOCUS
)
2599 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2602 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2603 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2605 /* draw image and text */
2606 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2607 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2608 btnInfo
->btn
.iBitmap
));
2609 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2610 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2612 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2613 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2615 /* delete objects and reset colors */
2616 SelectObject (lpdis
->hDC
, hOldBrush
);
2617 SelectObject (lpdis
->hDC
, hOldPen
);
2618 SetBkColor (lpdis
->hDC
, oldBk
);
2619 SetTextColor (lpdis
->hDC
, oldText
);
2620 DeleteObject( hPen
);
2625 case WM_MEASUREITEM
:
2626 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2628 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2630 lpmis
->itemHeight
= 15 + 8; /* default height */
2637 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2639 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2641 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2642 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2643 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2646 else if (wParam
== IDC_AVAILBTN_LBOX
)
2648 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2649 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2650 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2659 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2662 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2668 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2669 /* Add bitmaps to the default image list */
2670 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2671 hbmLoad
= (HBITMAP
)CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2673 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2675 /* enlarge the bitmap if needed */
2676 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2677 if (bitmap
->hInst
!= COMCTL32_hModule
)
2678 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2680 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2681 DeleteObject(hbmLoad
);
2685 nCountAfter
= ImageList_GetImageCount(himlDef
);
2686 nAdded
= nCountAfter
- nCountBefore
;
2687 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2689 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2690 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2691 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2692 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2695 infoPtr
->nNumBitmaps
+= nAdded
;
2700 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2707 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2708 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2710 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2712 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2715 TRACE("Update icon size: %dx%d -> %dx%d\n",
2716 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2718 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2719 ILC_COLORDDB
|ILC_MASK
, 8, 2);
2720 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2721 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2722 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2723 infoPtr
->himlInt
= himlNew
;
2725 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2726 ImageList_Destroy(himlDef
);
2729 /***********************************************************************
2730 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2734 TOOLBAR_AddBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2736 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2737 LPTBADDBITMAP lpAddBmp
= (LPTBADDBITMAP
)lParam
;
2742 TRACE("hwnd=%p wParam=%lx lParam=%lx\n", hwnd
, wParam
, lParam
);
2746 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2748 info
.hInst
= COMCTL32_hModule
;
2749 switch (lpAddBmp
->nID
)
2751 case IDB_STD_SMALL_COLOR
:
2753 info
.nID
= IDB_STD_SMALL
;
2755 case IDB_STD_LARGE_COLOR
:
2757 info
.nID
= IDB_STD_LARGE
;
2759 case IDB_VIEW_SMALL_COLOR
:
2761 info
.nID
= IDB_VIEW_SMALL
;
2763 case IDB_VIEW_LARGE_COLOR
:
2765 info
.nID
= IDB_VIEW_LARGE
;
2767 case IDB_HIST_SMALL_COLOR
:
2769 info
.nID
= IDB_HIST_SMALL
;
2771 case IDB_HIST_LARGE_COLOR
:
2773 info
.nID
= IDB_HIST_LARGE
;
2779 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2781 /* Windows resize all the buttons to the size of a newly added standard image */
2782 if (lpAddBmp
->nID
& 1)
2784 /* large icons: 24x24. Will make the button 31x30 */
2785 SendMessageW (hwnd
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2789 /* small icons: 16x16. Will make the buttons 23x22 */
2790 SendMessageW (hwnd
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2793 TOOLBAR_CalcToolbar (hwnd
);
2797 info
.nButtons
= (INT
)wParam
;
2798 info
.hInst
= lpAddBmp
->hInst
;
2799 info
.nID
= lpAddBmp
->nID
;
2800 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2803 /* check if the bitmap is already loaded and compute iSumButtons */
2805 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2807 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2808 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2810 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2813 if (!infoPtr
->cimlDef
) {
2814 /* create new default image list */
2815 TRACE ("creating default image list!\n");
2817 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2818 ILC_COLORDDB
| ILC_MASK
, info
.nButtons
, 2);
2819 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2820 infoPtr
->himlInt
= himlDef
;
2823 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2827 WARN("No default image list available\n");
2831 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2834 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2835 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2836 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2837 infoPtr
->nNumBitmapInfos
++;
2838 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2840 InvalidateRect(hwnd
, NULL
, TRUE
);
2846 TOOLBAR_AddButtonsT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL fUnicode
)
2848 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2849 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
2850 INT nOldButtons
, nNewButtons
, nAddButtons
, nCount
;
2851 BOOL fHasString
= FALSE
;
2853 TRACE("adding %ld buttons (unicode=%d)!\n", wParam
, fUnicode
);
2855 nAddButtons
= (UINT
)wParam
;
2856 nOldButtons
= infoPtr
->nNumButtons
;
2857 nNewButtons
= nOldButtons
+ nAddButtons
;
2859 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
2860 infoPtr
->nNumButtons
= nNewButtons
;
2862 /* insert new button data */
2863 for (nCount
= 0; nCount
< nAddButtons
; nCount
++) {
2864 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nOldButtons
+nCount
];
2865 btnPtr
->iBitmap
= lpTbb
[nCount
].iBitmap
;
2866 btnPtr
->idCommand
= lpTbb
[nCount
].idCommand
;
2867 btnPtr
->fsState
= lpTbb
[nCount
].fsState
;
2868 btnPtr
->fsStyle
= lpTbb
[nCount
].fsStyle
;
2869 btnPtr
->dwData
= lpTbb
[nCount
].dwData
;
2870 btnPtr
->bHot
= FALSE
;
2871 if(HIWORD(lpTbb
[nCount
].iString
) && lpTbb
[nCount
].iString
!= -1)
2874 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, (LPWSTR
)lpTbb
[nCount
].iString
);
2876 Str_SetPtrAtoW((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lpTbb
[nCount
].iString
);
2880 btnPtr
->iString
= lpTbb
[nCount
].iString
;
2882 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
2885 if (infoPtr
->nNumStrings
> 0 || fHasString
)
2886 TOOLBAR_CalcToolbar(hwnd
);
2888 TOOLBAR_LayoutToolbar(hwnd
);
2889 TOOLBAR_AutoSize (hwnd
);
2891 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
2893 InvalidateRect(hwnd
, NULL
, TRUE
);
2900 TOOLBAR_AddStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2902 #define MAX_RESOURCE_STRING_LENGTH 512
2903 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2904 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2905 INT nIndex
= infoPtr
->nNumStrings
;
2907 if ((wParam
) && (HIWORD(lParam
) == 0)) {
2908 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2913 TRACE("adding string from resource!\n");
2915 len
= LoadStringW ((HINSTANCE
)wParam
, (UINT
)lParam
,
2916 szString
, MAX_RESOURCE_STRING_LENGTH
);
2918 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2919 if (len
== 0 || len
== 1)
2922 TRACE("Delimiter: 0x%x\n", *szString
);
2923 delimiter
= *szString
;
2926 while ((next_delim
= strchrW(p
, delimiter
)) != NULL
) {
2928 if (next_delim
+ 1 >= szString
+ len
)
2930 /* this may happen if delimiter == '\0' or if the last char is a
2931 * delimiter (then it is ignored like the native does) */
2935 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2936 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2937 infoPtr
->nNumStrings
++;
2943 LPWSTR p
= (LPWSTR
)lParam
;
2948 TRACE("adding string(s) from array!\n");
2952 TRACE("len=%d %s\n", len
, debugstr_w(p
));
2953 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2954 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2955 infoPtr
->nNumStrings
++;
2962 TOOLBAR_CalcToolbar(hwnd
);
2968 TOOLBAR_AddStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2970 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2971 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2976 if ((wParam
) && (HIWORD(lParam
) == 0)) /* load from resources */
2977 return TOOLBAR_AddStringW(hwnd
, wParam
, lParam
);
2983 TRACE("adding string(s) from array!\n");
2984 nIndex
= infoPtr
->nNumStrings
;
2987 TRACE("len=%d \"%s\"\n", len
, p
);
2989 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2990 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2991 infoPtr
->nNumStrings
++;
2997 TOOLBAR_CalcToolbar(hwnd
);
3003 TOOLBAR_AutoSize (HWND hwnd
)
3005 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3011 TRACE("auto sizing, style=%x!\n", infoPtr
->dwStyle
);
3013 parent
= GetParent (hwnd
);
3015 if (!parent
|| !infoPtr
->bDoRedraw
)
3018 GetClientRect(parent
, &parent_rect
);
3020 x
= parent_rect
.left
;
3021 y
= parent_rect
.top
;
3023 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3025 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3026 cx
= parent_rect
.right
- parent_rect
.left
;
3028 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
))
3030 TOOLBAR_LayoutToolbar(hwnd
);
3031 InvalidateRect( hwnd
, NULL
, TRUE
);
3034 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3037 UINT uPosFlags
= SWP_NOZORDER
;
3039 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3041 GetWindowRect(hwnd
, &window_rect
);
3042 ScreenToClient(parent
, (LPPOINT
)&window_rect
.left
);
3043 y
= window_rect
.top
;
3045 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3047 GetWindowRect(hwnd
, &window_rect
);
3048 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3051 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3052 uPosFlags
|= SWP_NOMOVE
;
3054 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3055 cy
+= GetSystemMetrics(SM_CYEDGE
);
3057 if (infoPtr
->dwStyle
& WS_BORDER
)
3059 x
= y
= 1; /* FIXME: this looks wrong */
3060 cy
+= GetSystemMetrics(SM_CYEDGE
);
3061 cx
+= GetSystemMetrics(SM_CXEDGE
);
3064 SetWindowPos(hwnd
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3072 TOOLBAR_ButtonCount (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3074 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3076 return infoPtr
->nNumButtons
;
3081 TOOLBAR_ButtonStructSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3083 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3085 infoPtr
->dwStructSize
= (DWORD
)wParam
;
3092 TOOLBAR_ChangeBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3094 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3095 TBUTTON_INFO
*btnPtr
;
3098 TRACE("button %ld, iBitmap now %d\n", wParam
, LOWORD(lParam
));
3100 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3104 btnPtr
= &infoPtr
->buttons
[nIndex
];
3105 btnPtr
->iBitmap
= LOWORD(lParam
);
3107 /* we HAVE to erase the background, the new bitmap could be */
3109 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3116 TOOLBAR_CheckButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3118 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3119 TBUTTON_INFO
*btnPtr
;
3122 BOOL bChecked
= FALSE
;
3124 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3126 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd
, nIndex
, lParam
);
3131 btnPtr
= &infoPtr
->buttons
[nIndex
];
3133 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? TRUE
: FALSE
;
3135 if (LOWORD(lParam
) == FALSE
)
3136 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3138 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3140 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3141 if (nOldIndex
== nIndex
)
3143 if (nOldIndex
!= -1)
3144 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3146 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3149 if( bChecked
!= LOWORD(lParam
) )
3151 if (nOldIndex
!= -1)
3152 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3153 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3156 /* FIXME: Send a WM_NOTIFY?? */
3163 TOOLBAR_CommandToIndex (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3165 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3167 return TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3172 TOOLBAR_Customize (HWND hwnd
)
3174 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3175 CUSTDLG_INFO custInfo
;
3181 custInfo
.tbInfo
= infoPtr
;
3182 custInfo
.tbHwnd
= hwnd
;
3184 /* send TBN_BEGINADJUST notification */
3185 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3187 if (!(hRes
= FindResourceW (COMCTL32_hModule
,
3188 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3189 (LPWSTR
)RT_DIALOG
)))
3192 if(!(template = LoadResource (COMCTL32_hModule
, hRes
)))
3195 ret
= DialogBoxIndirectParamW ((HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
),
3196 (LPCDLGTEMPLATEW
)template,
3198 TOOLBAR_CustomizeDialogProc
,
3201 /* send TBN_ENDADJUST notification */
3202 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3209 TOOLBAR_DeleteButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3211 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3212 INT nIndex
= (INT
)wParam
;
3214 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3216 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3219 memset(&nmtb
, 0, sizeof(nmtb
));
3220 nmtb
.iItem
= btnPtr
->idCommand
;
3221 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3222 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3223 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3224 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3225 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3226 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3227 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3229 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3231 if (infoPtr
->nNumButtons
== 1) {
3232 TRACE(" simple delete!\n");
3233 Free (infoPtr
->buttons
);
3234 infoPtr
->buttons
= NULL
;
3235 infoPtr
->nNumButtons
= 0;
3238 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3239 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3241 infoPtr
->nNumButtons
--;
3242 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3244 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3245 nIndex
* sizeof(TBUTTON_INFO
));
3248 if (nIndex
< infoPtr
->nNumButtons
) {
3249 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3250 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3256 TOOLBAR_LayoutToolbar(hwnd
);
3258 InvalidateRect (hwnd
, NULL
, TRUE
);
3265 TOOLBAR_EnableButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3267 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3268 TBUTTON_INFO
*btnPtr
;
3272 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3274 TRACE("hwnd=%p, btn index=%ld, lParam=0x%08lx\n", hwnd
, wParam
, lParam
);
3279 btnPtr
= &infoPtr
->buttons
[nIndex
];
3281 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3283 /* update the toolbar button state */
3284 if(LOWORD(lParam
) == FALSE
) {
3285 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3287 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3290 /* redraw the button only if the state of the button changed */
3291 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3292 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3298 static inline LRESULT
3299 TOOLBAR_GetAnchorHighlight (HWND hwnd
)
3301 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3303 return infoPtr
->bAnchor
;
3308 TOOLBAR_GetBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3310 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3313 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3317 return infoPtr
->buttons
[nIndex
].iBitmap
;
3321 static inline LRESULT
3322 TOOLBAR_GetBitmapFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3324 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3329 TOOLBAR_GetButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3331 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3332 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3333 INT nIndex
= (INT
)wParam
;
3334 TBUTTON_INFO
*btnPtr
;
3339 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3342 btnPtr
= &infoPtr
->buttons
[nIndex
];
3343 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3344 lpTbb
->idCommand
= btnPtr
->idCommand
;
3345 lpTbb
->fsState
= btnPtr
->fsState
;
3346 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3347 lpTbb
->bReserved
[0] = 0;
3348 lpTbb
->bReserved
[1] = 0;
3349 lpTbb
->dwData
= btnPtr
->dwData
;
3350 lpTbb
->iString
= btnPtr
->iString
;
3357 TOOLBAR_GetButtonInfoT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL bUnicode
)
3359 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3360 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3361 LPTBBUTTONINFOW lpTbInfo
= (LPTBBUTTONINFOW
)lParam
;
3362 TBUTTON_INFO
*btnPtr
;
3365 if (lpTbInfo
== NULL
)
3368 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3369 * the headers and tests shows that even with comctl 6 Vista accepts only the
3370 * original TBBUTTONINFO size
3372 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3374 WARN("Invalid button size\n");
3378 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
3379 lpTbInfo
->dwMask
& 0x80000000);
3383 if (!(btnPtr
= &infoPtr
->buttons
[nIndex
])) return -1;
3385 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3386 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3387 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3388 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3389 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3390 lpTbInfo
->lParam
= btnPtr
->dwData
;
3391 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3392 lpTbInfo
->cx
= (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3393 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3394 lpTbInfo
->fsState
= btnPtr
->fsState
;
3395 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3396 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3397 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3398 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3399 can't use TOOLBAR_GetText here */
3400 if (HIWORD(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3401 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3403 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3405 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3407 lpTbInfo
->pszText
[0] = '\0';
3414 TOOLBAR_GetButtonSize (HWND hwnd
)
3416 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3418 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3419 (WORD
)infoPtr
->nButtonHeight
);
3424 TOOLBAR_GetButtonTextA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3426 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3433 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3437 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3439 return WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3440 (LPSTR
)lParam
, 0x7fffffff, NULL
, NULL
) - 1;
3445 TOOLBAR_GetButtonTextW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3447 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3452 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3456 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3460 ret
= strlenW (lpText
);
3463 strcpyW ((LPWSTR
)lParam
, lpText
);
3471 TOOLBAR_GetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3473 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3474 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3475 return (LRESULT
)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3479 static inline LRESULT
3480 TOOLBAR_GetExtendedStyle (HWND hwnd
)
3482 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3486 return infoPtr
->dwExStyle
;
3491 TOOLBAR_GetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3493 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3494 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3495 return (LRESULT
)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3500 TOOLBAR_GetHotItem (HWND hwnd
)
3502 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3504 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3507 if (infoPtr
->nHotItem
< 0)
3510 return (LRESULT
)infoPtr
->nHotItem
;
3515 TOOLBAR_GetDefImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3517 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3518 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3519 return (LRESULT
) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd
), wParam
);
3524 TOOLBAR_GetInsertMark (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3526 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3527 TBINSERTMARK
*lptbim
= (TBINSERTMARK
*)lParam
;
3529 TRACE("hwnd = %p, lptbim = %p\n", hwnd
, lptbim
);
3531 *lptbim
= infoPtr
->tbim
;
3538 TOOLBAR_GetInsertMarkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3540 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3542 TRACE("hwnd = %p\n", hwnd
);
3544 return (LRESULT
)infoPtr
->clrInsertMark
;
3549 TOOLBAR_GetItemRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3551 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3552 TBUTTON_INFO
*btnPtr
;
3556 nIndex
= (INT
)wParam
;
3557 btnPtr
= &infoPtr
->buttons
[nIndex
];
3558 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3560 lpRect
= (LPRECT
)lParam
;
3563 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3566 lpRect
->left
= btnPtr
->rect
.left
;
3567 lpRect
->right
= btnPtr
->rect
.right
;
3568 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3569 lpRect
->top
= btnPtr
->rect
.top
;
3576 TOOLBAR_GetMaxSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3578 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3579 LPSIZE lpSize
= (LPSIZE
)lParam
;
3584 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3585 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3587 TRACE("maximum size %d x %d\n",
3588 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3589 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3595 /* << TOOLBAR_GetObject >> */
3599 TOOLBAR_GetPadding (HWND hwnd
)
3601 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3604 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3605 return (LRESULT
) oldPad
;
3610 TOOLBAR_GetRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3612 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3613 TBUTTON_INFO
*btnPtr
;
3617 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3618 btnPtr
= &infoPtr
->buttons
[nIndex
];
3619 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3621 lpRect
= (LPRECT
)lParam
;
3625 lpRect
->left
= btnPtr
->rect
.left
;
3626 lpRect
->right
= btnPtr
->rect
.right
;
3627 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3628 lpRect
->top
= btnPtr
->rect
.top
;
3635 TOOLBAR_GetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3637 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3639 return infoPtr
->nRows
;
3644 TOOLBAR_GetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3646 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3649 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3653 return infoPtr
->buttons
[nIndex
].fsState
;
3658 TOOLBAR_GetStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3660 return GetWindowLongW(hwnd
, GWL_STYLE
);
3665 TOOLBAR_GetTextRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3667 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3669 return infoPtr
->nMaxTextRows
;
3674 TOOLBAR_GetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3676 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3678 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3679 TOOLBAR_TooltipCreateControl(infoPtr
);
3680 return (LRESULT
)infoPtr
->hwndToolTip
;
3685 TOOLBAR_GetUnicodeFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3687 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3689 TRACE("%s hwnd=%p\n",
3690 infoPtr
->bUnicode
? "TRUE" : "FALSE", hwnd
);
3692 return infoPtr
->bUnicode
;
3696 static inline LRESULT
3697 TOOLBAR_GetVersion (HWND hwnd
)
3699 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3700 return infoPtr
->iVersion
;
3705 TOOLBAR_HideButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3707 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3708 TBUTTON_INFO
*btnPtr
;
3713 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3717 btnPtr
= &infoPtr
->buttons
[nIndex
];
3718 if (LOWORD(lParam
) == FALSE
)
3719 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3721 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3723 TOOLBAR_LayoutToolbar (hwnd
);
3725 InvalidateRect (hwnd
, NULL
, TRUE
);
3731 static inline LRESULT
3732 TOOLBAR_HitTest (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3734 return TOOLBAR_InternalHitTest (hwnd
, (LPPOINT
)lParam
);
3739 TOOLBAR_Indeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3741 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3742 TBUTTON_INFO
*btnPtr
;
3746 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3750 btnPtr
= &infoPtr
->buttons
[nIndex
];
3751 oldState
= btnPtr
->fsState
;
3752 if (LOWORD(lParam
) == FALSE
)
3753 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3755 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3757 if(oldState
!= btnPtr
->fsState
)
3758 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3765 TOOLBAR_InsertButtonT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL fUnicode
)
3767 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3768 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3769 INT nIndex
= (INT
)wParam
;
3774 TOOLBAR_DumpButton(infoPtr
, (TBUTTON_INFO
*)lpTbb
, nIndex
, FALSE
);
3777 /* EPP: this seems to be an undocumented call (from my IE4)
3778 * I assume in that case that:
3779 * - index of insertion is at the end of existing buttons
3780 * I only see this happen with nIndex == -1, but it could have a special
3781 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3783 nIndex
= infoPtr
->nNumButtons
;
3785 } else if (nIndex
< 0)
3788 TRACE("inserting button index=%d\n", nIndex
);
3789 if (nIndex
> infoPtr
->nNumButtons
) {
3790 nIndex
= infoPtr
->nNumButtons
;
3791 TRACE("adjust index=%d\n", nIndex
);
3794 infoPtr
->nNumButtons
++;
3795 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3796 memmove(&infoPtr
->buttons
[nIndex
+1], &infoPtr
->buttons
[nIndex
],
3797 (infoPtr
->nNumButtons
- nIndex
- 1) * sizeof(TBUTTON_INFO
));
3799 /* insert new button */
3800 infoPtr
->buttons
[nIndex
].iBitmap
= lpTbb
->iBitmap
;
3801 infoPtr
->buttons
[nIndex
].idCommand
= lpTbb
->idCommand
;
3802 infoPtr
->buttons
[nIndex
].fsState
= lpTbb
->fsState
;
3803 infoPtr
->buttons
[nIndex
].fsStyle
= lpTbb
->fsStyle
;
3804 infoPtr
->buttons
[nIndex
].dwData
= lpTbb
->dwData
;
3805 /* if passed string and not index, then add string */
3806 if(HIWORD(lpTbb
->iString
) && lpTbb
->iString
!=-1) {
3808 Str_SetPtrW((LPWSTR
*)&infoPtr
->buttons
[nIndex
].iString
, (LPWSTR
)lpTbb
->iString
);
3810 Str_SetPtrAtoW((LPWSTR
*)&infoPtr
->buttons
[nIndex
].iString
, (LPCSTR
)lpTbb
->iString
);
3813 infoPtr
->buttons
[nIndex
].iString
= lpTbb
->iString
;
3815 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3817 if (infoPtr
->nNumStrings
> 0)
3818 TOOLBAR_CalcToolbar(hwnd
);
3820 TOOLBAR_LayoutToolbar(hwnd
);
3821 TOOLBAR_AutoSize (hwnd
);
3823 InvalidateRect (hwnd
, NULL
, TRUE
);
3828 /* << TOOLBAR_InsertMarkHitTest >> */
3832 TOOLBAR_IsButtonChecked (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3834 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3837 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3841 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3846 TOOLBAR_IsButtonEnabled (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3848 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3851 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3855 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3860 TOOLBAR_IsButtonHidden (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3862 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3865 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3869 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3874 TOOLBAR_IsButtonHighlighted (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3876 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3879 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3883 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3888 TOOLBAR_IsButtonIndeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3890 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3893 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3897 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3902 TOOLBAR_IsButtonPressed (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3904 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3907 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3911 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3916 TOOLBAR_LoadImages (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3919 tbab
.hInst
= (HINSTANCE
)lParam
;
3922 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", hwnd
, tbab
.hInst
, tbab
.nID
);
3924 return TOOLBAR_AddBitmap(hwnd
, 0, (LPARAM
)&tbab
);
3929 TOOLBAR_MapAccelerator (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3931 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3932 WCHAR wAccel
= (WCHAR
)wParam
;
3933 UINT
* pIDButton
= (UINT
*)lParam
;
3934 WCHAR wszAccel
[] = {'&',wAccel
,0};
3937 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3938 hwnd
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3940 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3942 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3943 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3944 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3946 int iLen
= strlenW(wszAccel
);
3947 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3954 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3959 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
3961 *pIDButton
= btnPtr
->idCommand
;
3973 TOOLBAR_MarkButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3975 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3978 TBUTTON_INFO
*btnPtr
;
3980 TRACE("hwnd = %p, wParam = %ld, lParam = 0x%08lx\n", hwnd
, wParam
, lParam
);
3982 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3986 btnPtr
= &infoPtr
->buttons
[nIndex
];
3987 oldState
= btnPtr
->fsState
;
3990 btnPtr
->fsState
|= TBSTATE_MARKED
;
3992 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
3994 if(oldState
!= btnPtr
->fsState
)
3995 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4001 /* fixes up an index of a button affected by a move */
4002 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
4006 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
4008 else if (*pIndex
== nIndex
)
4009 *pIndex
= nMoveIndex
;
4013 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
4015 else if (*pIndex
== nIndex
)
4016 *pIndex
= nMoveIndex
;
4022 TOOLBAR_MoveButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4024 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4027 INT nMoveIndex
= (INT
)lParam
;
4028 TBUTTON_INFO button
;
4030 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd
, wParam
, lParam
);
4032 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, TRUE
);
4033 if ((nIndex
== -1) || (nMoveIndex
< 0))
4036 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
4037 nMoveIndex
= infoPtr
->nNumButtons
- 1;
4039 button
= infoPtr
->buttons
[nIndex
];
4041 /* move button right */
4042 if (nIndex
< nMoveIndex
)
4044 nCount
= nMoveIndex
- nIndex
;
4045 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
4046 infoPtr
->buttons
[nMoveIndex
] = button
;
4048 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
4049 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
4050 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
4051 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
4053 else if (nIndex
> nMoveIndex
) /* move button left */
4055 nCount
= nIndex
- nMoveIndex
;
4056 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
4057 infoPtr
->buttons
[nMoveIndex
] = button
;
4059 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
4060 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
4061 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
4062 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
4065 TOOLBAR_LayoutToolbar(hwnd
);
4066 TOOLBAR_AutoSize(hwnd
);
4067 InvalidateRect(hwnd
, NULL
, TRUE
);
4074 TOOLBAR_PressButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4076 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4077 TBUTTON_INFO
*btnPtr
;
4081 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4085 btnPtr
= &infoPtr
->buttons
[nIndex
];
4086 oldState
= btnPtr
->fsState
;
4087 if (LOWORD(lParam
) == FALSE
)
4088 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
4090 btnPtr
->fsState
|= TBSTATE_PRESSED
;
4092 if(oldState
!= btnPtr
->fsState
)
4093 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4098 /* FIXME: there might still be some confusion her between number of buttons
4099 * and number of bitmaps */
4101 TOOLBAR_ReplaceBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4103 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4104 LPTBREPLACEBITMAP lpReplace
= (LPTBREPLACEBITMAP
) lParam
;
4106 int i
= 0, nOldButtons
= 0, pos
= 0;
4107 int nOldBitmaps
, nNewBitmaps
= 0;
4108 HIMAGELIST himlDef
= 0;
4110 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4111 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
4112 lpReplace
->nButtons
);
4114 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4116 FIXME("changing standard bitmaps not implemented\n");
4119 else if (lpReplace
->hInstOld
!= 0)
4120 FIXME("resources not in the current module not implemented\n");
4122 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4123 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4124 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4125 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4126 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4128 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4129 nOldButtons
= tbi
->nButtons
;
4130 tbi
->nButtons
= lpReplace
->nButtons
;
4131 tbi
->hInst
= lpReplace
->hInstNew
;
4132 tbi
->nID
= lpReplace
->nIDNew
;
4133 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4136 pos
+= tbi
->nButtons
;
4139 if (nOldButtons
== 0)
4141 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4145 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4148 if (lpReplace
->hInstNew
)
4149 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4151 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4153 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4154 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4156 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4158 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4159 ImageList_Remove(himlDef
, i
);
4163 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4164 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4165 DeleteObject(hBitmap
);
4168 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4170 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4171 pos
, nOldBitmaps
, nNewBitmaps
);
4173 InvalidateRect(hwnd
, NULL
, TRUE
);
4178 /* helper for TOOLBAR_SaveRestoreW */
4180 TOOLBAR_Save(const TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4182 FIXME("save to %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4183 debugstr_w(lpSave
->pszValueName
));
4189 /* helper for TOOLBAR_Restore */
4191 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4195 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4197 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4200 Free(infoPtr
->buttons
);
4201 infoPtr
->buttons
= NULL
;
4202 infoPtr
->nNumButtons
= 0;
4206 /* helper for TOOLBAR_SaveRestoreW */
4208 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4217 /* restore toolbar information */
4218 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4219 debugstr_w(lpSave
->pszValueName
));
4221 memset(&nmtbr
, 0, sizeof(nmtbr
));
4223 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4224 KEY_QUERY_VALUE
, &hkey
);
4226 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4228 if (!res
&& dwType
!= REG_BINARY
)
4229 res
= ERROR_FILE_NOT_FOUND
;
4232 nmtbr
.pData
= Alloc(dwSize
);
4233 nmtbr
.cbData
= dwSize
;
4234 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4237 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4238 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4241 nmtbr
.pCurrent
= nmtbr
.pData
;
4243 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4244 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4246 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4250 /* remove all existing buttons as this function is designed to
4251 * restore the toolbar to a previously saved state */
4252 TOOLBAR_DeleteAllButtons(infoPtr
);
4254 for (i
= 0; i
< nmtbr
.cButtons
; i
++)
4257 nmtbr
.tbButton
.iBitmap
= -1;
4258 nmtbr
.tbButton
.fsState
= 0;
4259 nmtbr
.tbButton
.fsStyle
= 0;
4260 nmtbr
.tbButton
.idCommand
= 0;
4261 if (*nmtbr
.pCurrent
== (DWORD
)-1)
4264 nmtbr
.tbButton
.fsStyle
= TBSTYLE_SEP
;
4265 nmtbr
.tbButton
.iBitmap
= SEPARATOR_WIDTH
;
4267 else if (*nmtbr
.pCurrent
== (DWORD
)-2)
4269 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4271 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4275 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4277 /* can't contain real string as we don't know whether
4278 * the client put an ANSI or Unicode string in there */
4279 if (HIWORD(nmtbr
.tbButton
.iString
))
4280 nmtbr
.tbButton
.iString
= 0;
4282 TOOLBAR_InsertButtonT(infoPtr
->hwndSelf
, -1,
4283 (LPARAM
)&nmtbr
.tbButton
, TRUE
);
4286 /* do legacy notifications */
4287 if (infoPtr
->iVersion
< 5)
4289 /* FIXME: send TBN_BEGINADJUST */
4290 FIXME("send TBN_GETBUTTONINFO for each button\n");
4291 /* FIXME: send TBN_ENDADJUST */
4294 /* remove all uninitialised buttons
4295 * note: loop backwards to avoid having to fixup i on a
4297 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4298 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4299 TOOLBAR_DeleteButton(infoPtr
->hwndSelf
, i
, 0);
4301 /* only indicate success if at least one button survived */
4302 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4313 TOOLBAR_SaveRestoreW (HWND hwnd
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4315 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4317 if (lpSave
== NULL
) return 0;
4320 return TOOLBAR_Save(infoPtr
, lpSave
);
4322 return TOOLBAR_Restore(infoPtr
, lpSave
);
4327 TOOLBAR_SaveRestoreA (HWND hwnd
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4329 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4330 TBSAVEPARAMSW SaveW
;
4334 if (lpSave
== NULL
) return 0;
4336 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4337 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4338 if (pszSubKey
) goto exit
;
4339 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4341 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4342 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4343 if (!pszValueName
) goto exit
;
4344 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4346 SaveW
.pszValueName
= pszValueName
;
4347 SaveW
.pszSubKey
= pszSubKey
;
4348 SaveW
.hkr
= lpSave
->hkr
;
4349 result
= TOOLBAR_SaveRestoreW(hwnd
, wParam
, &SaveW
);
4352 Free (pszValueName
);
4360 TOOLBAR_SetAnchorHighlight (HWND hwnd
, WPARAM wParam
)
4362 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4363 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4365 TRACE("hwnd=%p, bAnchor = %s\n", hwnd
, wParam
? "TRUE" : "FALSE");
4367 infoPtr
->bAnchor
= (BOOL
)wParam
;
4369 /* Native does not remove the hot effect from an already hot button */
4371 return (LRESULT
)bOldAnchor
;
4376 TOOLBAR_SetBitmapSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4378 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4379 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4381 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd
, wParam
, lParam
);
4384 FIXME("wParam is %ld. Perhaps image list index?\n", wParam
);
4386 if (LOWORD(lParam
) == 0)
4387 lParam
= MAKELPARAM(1, HIWORD(lParam
));
4389 if (HIWORD(lParam
)==0)
4390 lParam
= MAKELPARAM(LOWORD(lParam
), 1);
4392 if (infoPtr
->nNumButtons
> 0)
4393 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4394 infoPtr
->nNumButtons
,
4395 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
4396 LOWORD(lParam
), HIWORD(lParam
));
4398 infoPtr
->nBitmapWidth
= (INT
)LOWORD(lParam
);
4399 infoPtr
->nBitmapHeight
= (INT
)HIWORD(lParam
);
4401 if ((himlDef
== infoPtr
->himlInt
) &&
4402 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4404 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4405 infoPtr
->nBitmapHeight
);
4408 TOOLBAR_CalcToolbar(hwnd
);
4409 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4415 TOOLBAR_SetButtonInfoA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4417 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4418 LPTBBUTTONINFOA lptbbi
= (LPTBBUTTONINFOA
)lParam
;
4419 TBUTTON_INFO
*btnPtr
;
4425 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOA
))
4428 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4429 lptbbi
->dwMask
& 0x80000000);
4433 btnPtr
= &infoPtr
->buttons
[nIndex
];
4434 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4435 btnPtr
->idCommand
= lptbbi
->idCommand
;
4436 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4437 btnPtr
->iBitmap
= lptbbi
->iImage
;
4438 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4439 btnPtr
->dwData
= lptbbi
->lParam
;
4440 if (lptbbi
->dwMask
& TBIF_SIZE
)
4441 btnPtr
->cx
= lptbbi
->cx
;
4442 if (lptbbi
->dwMask
& TBIF_STATE
)
4443 btnPtr
->fsState
= lptbbi
->fsState
;
4444 if (lptbbi
->dwMask
& TBIF_STYLE
)
4445 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4447 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4448 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4449 /* iString is index, zero it to make Str_SetPtr succeed */
4452 Str_SetPtrAtoW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4455 /* save the button rect to see if we need to redraw the whole toolbar */
4456 oldBtnRect
= btnPtr
->rect
;
4457 TOOLBAR_CalcToolbar(hwnd
);
4459 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4460 InvalidateRect(hwnd
, NULL
, TRUE
);
4462 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4469 TOOLBAR_SetButtonInfoW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4471 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4472 LPTBBUTTONINFOW lptbbi
= (LPTBBUTTONINFOW
)lParam
;
4473 TBUTTON_INFO
*btnPtr
;
4479 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4482 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4483 lptbbi
->dwMask
& 0x80000000);
4487 btnPtr
= &infoPtr
->buttons
[nIndex
];
4488 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4489 btnPtr
->idCommand
= lptbbi
->idCommand
;
4490 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4491 btnPtr
->iBitmap
= lptbbi
->iImage
;
4492 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4493 btnPtr
->dwData
= lptbbi
->lParam
;
4494 if (lptbbi
->dwMask
& TBIF_SIZE
)
4495 btnPtr
->cx
= lptbbi
->cx
;
4496 if (lptbbi
->dwMask
& TBIF_STATE
)
4497 btnPtr
->fsState
= lptbbi
->fsState
;
4498 if (lptbbi
->dwMask
& TBIF_STYLE
)
4499 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4501 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4502 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4503 /* iString is index, zero it to make Str_SetPtr succeed */
4505 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4508 /* save the button rect to see if we need to redraw the whole toolbar */
4509 oldBtnRect
= btnPtr
->rect
;
4510 TOOLBAR_CalcToolbar(hwnd
);
4512 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4513 InvalidateRect(hwnd
, NULL
, TRUE
);
4515 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4522 TOOLBAR_SetButtonSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4524 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4525 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4527 if ((cx
< 0) || (cy
< 0))
4529 ERR("invalid parameter 0x%08x\n", (DWORD
)lParam
);
4533 TRACE("%p, cx = %d, cy = %d\n", hwnd
, cx
, cy
);
4535 /* The documentation claims you can only change the button size before
4536 * any button has been added. But this is wrong.
4537 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4538 * it to the toolbar, and it checks that the return value is nonzero - mjm
4539 * Further testing shows that we must actually perform the change too.
4542 * The documentation also does not mention that if 0 is supplied for
4543 * either size, the system changes it to the default of 24 wide and
4544 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4546 if (cx
== 0) cx
= 24;
4547 if (cy
== 0) cx
= 22;
4549 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4550 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4552 infoPtr
->nButtonWidth
= cx
;
4553 infoPtr
->nButtonHeight
= cy
;
4555 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
4556 TOOLBAR_LayoutToolbar(hwnd
);
4562 TOOLBAR_SetButtonWidth (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4564 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4566 /* if setting to current values, ignore */
4567 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4568 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4569 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4570 infoPtr
->cxMin
, infoPtr
->cxMax
);
4574 /* save new values */
4575 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4576 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4578 /* otherwise we need to recalc the toolbar and in some cases
4579 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4580 which doesn't actually draw - GA). */
4581 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4582 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4584 TOOLBAR_CalcToolbar (hwnd
);
4586 InvalidateRect (hwnd
, NULL
, TRUE
);
4593 TOOLBAR_SetCmdId (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4595 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4596 INT nIndex
= (INT
)wParam
;
4598 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4601 infoPtr
->buttons
[nIndex
].idCommand
= (INT
)lParam
;
4603 if (infoPtr
->hwndToolTip
) {
4605 FIXME("change tool tip!\n");
4614 TOOLBAR_SetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4616 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4617 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4618 HIMAGELIST himlTemp
;
4621 if (infoPtr
->iVersion
>= 5)
4624 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4625 &infoPtr
->cimlDis
, himl
, id
);
4627 /* FIXME: redraw ? */
4629 return (LRESULT
)himlTemp
;
4634 TOOLBAR_SetDrawTextFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4636 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4639 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd
, (DWORD
)wParam
, (DWORD
)lParam
);
4641 dwTemp
= infoPtr
->dwDTFlags
;
4642 infoPtr
->dwDTFlags
=
4643 (infoPtr
->dwDTFlags
& (DWORD
)wParam
) | (DWORD
)lParam
;
4645 return (LRESULT
)dwTemp
;
4648 /* This function differs a bit from what MSDN says it does:
4649 * 1. lParam contains extended style flags to OR with current style
4650 * (MSDN isn't clear on the OR bit)
4651 * 2. wParam appears to contain extended style flags to be reset
4652 * (MSDN says that this parameter is reserved)
4655 TOOLBAR_SetExtendedStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4657 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4660 dwTemp
= infoPtr
->dwExStyle
;
4661 infoPtr
->dwExStyle
&= ~wParam
;
4662 infoPtr
->dwExStyle
|= (DWORD
)lParam
;
4664 TRACE("new style 0x%08x\n", infoPtr
->dwExStyle
);
4666 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4667 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4668 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4670 TOOLBAR_CalcToolbar (hwnd
);
4672 TOOLBAR_AutoSize(hwnd
);
4674 InvalidateRect(hwnd
, NULL
, TRUE
);
4676 return (LRESULT
)dwTemp
;
4681 TOOLBAR_SetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4683 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4684 HIMAGELIST himlTemp
;
4685 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4688 if (infoPtr
->iVersion
>= 5)
4691 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd
, himl
, id
);
4693 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4694 &infoPtr
->cimlHot
, himl
, id
);
4696 /* FIXME: redraw ? */
4698 return (LRESULT
)himlTemp
;
4702 /* Makes previous hot button no longer hot, makes the specified
4703 * button hot and sends appropriate notifications. dwReason is one or
4704 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4705 * NOTE 1: this function does not validate nHit
4706 * NOTE 2: the name of this function is completely made up and
4707 * not based on any documentation from Microsoft. */
4709 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4711 if (infoPtr
->nHotItem
!= nHit
)
4713 NMTBHOTITEM nmhotitem
;
4714 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4716 nmhotitem
.dwFlags
= dwReason
;
4717 if(infoPtr
->nHotItem
>= 0)
4719 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4720 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4724 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4725 nmhotitem
.idOld
= 0;
4730 btnPtr
= &infoPtr
->buttons
[nHit
];
4731 nmhotitem
.idNew
= btnPtr
->idCommand
;
4735 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4736 nmhotitem
.idNew
= 0;
4739 /* now change the hot and invalidate the old and new buttons - if the
4741 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4744 oldBtnPtr
->bHot
= FALSE
;
4745 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4747 /* setting disabled buttons as hot fails even if the notify contains the button id */
4748 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4749 btnPtr
->bHot
= TRUE
;
4750 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4751 infoPtr
->nHotItem
= nHit
;
4754 infoPtr
->nHotItem
= -1;
4760 TOOLBAR_SetHotItem (HWND hwnd
, WPARAM wParam
)
4762 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4763 INT nOldHotItem
= infoPtr
->nHotItem
;
4765 TRACE("hwnd = %p, nHit = %d\n", hwnd
, (INT
)wParam
);
4767 if ((INT
)wParam
> infoPtr
->nNumButtons
)
4768 return infoPtr
->nHotItem
;
4770 if ((INT
)wParam
< 0)
4773 /* NOTE: an application can still remove the hot item even if anchor
4774 * highlighting is enabled */
4776 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, HICF_OTHER
);
4778 if (nOldHotItem
< 0)
4781 return (LRESULT
)nOldHotItem
;
4786 TOOLBAR_SetImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4788 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4789 HIMAGELIST himlTemp
;
4790 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4791 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4794 if (infoPtr
->iVersion
>= 5)
4797 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4798 &infoPtr
->cimlDef
, himl
, id
);
4800 infoPtr
->nNumBitmaps
= 0;
4801 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4802 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4804 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4805 &infoPtr
->nBitmapHeight
))
4807 infoPtr
->nBitmapWidth
= 1;
4808 infoPtr
->nBitmapHeight
= 1;
4810 TOOLBAR_CalcToolbar(hwnd
);
4811 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4812 TOOLBAR_SetButtonSize(hwnd
, 0, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4814 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4815 hwnd
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4816 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4818 InvalidateRect(hwnd
, NULL
, TRUE
);
4820 return (LRESULT
)himlTemp
;
4825 TOOLBAR_SetIndent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4827 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4829 infoPtr
->nIndent
= (INT
)wParam
;
4833 /* process only on indent changing */
4834 if(infoPtr
->nIndent
!= (INT
)wParam
)
4836 infoPtr
->nIndent
= (INT
)wParam
;
4837 TOOLBAR_CalcToolbar (hwnd
);
4838 InvalidateRect(hwnd
, NULL
, FALSE
);
4846 TOOLBAR_SetInsertMark (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4848 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4849 TBINSERTMARK
*lptbim
= (TBINSERTMARK
*)lParam
;
4851 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd
, lptbim
->iButton
, lptbim
->dwFlags
);
4853 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4855 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4859 if ((lptbim
->iButton
== -1) ||
4860 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4861 (lptbim
->iButton
>= 0)))
4863 infoPtr
->tbim
= *lptbim
;
4864 /* FIXME: don't need to update entire toolbar */
4865 InvalidateRect(hwnd
, NULL
, TRUE
);
4868 ERR("Invalid button index %d\n", lptbim
->iButton
);
4875 TOOLBAR_SetInsertMarkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4877 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4879 infoPtr
->clrInsertMark
= (COLORREF
)lParam
;
4881 /* FIXME: don't need to update entire toolbar */
4882 InvalidateRect(hwnd
, NULL
, TRUE
);
4889 TOOLBAR_SetMaxTextRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4891 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4893 infoPtr
->nMaxTextRows
= (INT
)wParam
;
4895 TOOLBAR_CalcToolbar(hwnd
);
4900 /* MSDN gives slightly wrong info on padding.
4901 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4902 * 2. It is not used to create a blank area between the edge of the button
4903 * and the text or image if TBSTYLE_LIST is set. It is used to control
4904 * the gap between the image and text.
4905 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4906 * to control the bottom and right borders [with the border being
4907 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4908 * is shared evenly on both sides of the button.
4909 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4912 TOOLBAR_SetPadding (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4914 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4917 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4918 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4919 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4920 TRACE("cx=%d, cy=%d\n",
4921 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4922 return (LRESULT
) oldPad
;
4927 TOOLBAR_SetParent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4929 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4934 hwndOldNotify
= infoPtr
->hwndNotify
;
4935 infoPtr
->hwndNotify
= (HWND
)wParam
;
4937 return (LRESULT
)hwndOldNotify
;
4942 TOOLBAR_SetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4944 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4945 LPRECT lprc
= (LPRECT
)lParam
;
4946 int rows
= LOWORD(wParam
);
4947 BOOL bLarger
= HIWORD(wParam
);
4951 TRACE("Setting rows to %d (%d)\n", rows
, bLarger
);
4953 if(infoPtr
->nRows
!= rows
)
4955 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
;
4956 int curColumn
= 0; /* Current column */
4957 int curRow
= 0; /* Current row */
4958 int hidden
= 0; /* Number of hidden buttons */
4959 int seps
= 0; /* Number of separators */
4960 int idealWrap
= 0; /* Ideal wrap point */
4965 Calculate new size and wrap points - Under windows, setrows will
4966 change the dimensions if needed to show the number of requested
4967 rows (if CCS_NORESIZE is set), or will take up the whole window
4968 (if no CCS_NORESIZE).
4970 Basic algorithum - If N buttons, and y rows requested, each row
4971 contains N/y buttons.
4973 FIXME: Handling of separators not obvious from testing results
4974 FIXME: Take width of window into account?
4977 /* Loop through the buttons one by one counting key items */
4978 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4980 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
4981 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4983 else if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
4987 /* FIXME: Separators make this quite complex */
4988 if (seps
) FIXME("Separators unhandled\n");
4990 /* Round up so more per line, ie less rows */
4991 idealWrap
= (infoPtr
->nNumButtons
- hidden
+ (rows
-1)) / rows
;
4993 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4994 achieve the requested number of rows. */
4995 if (bLarger
&& idealWrap
> 1)
4997 int resRows
= (infoPtr
->nNumButtons
+ (idealWrap
-1)) / idealWrap
;
4998 int moreRows
= (infoPtr
->nNumButtons
+ (idealWrap
-2)) / (idealWrap
-1);
5000 if (resRows
< rows
&& moreRows
> rows
)
5003 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap
);
5007 curColumn
= curRow
= 0;
5009 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap
,
5010 infoPtr
->nNumButtons
, hidden
, rows
);
5012 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
5014 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
5017 /* Step on, wrap if necessary or flag next to wrap */
5026 if (curColumn
> (idealWrap
-1)) {
5028 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
5032 TRACE("Result - %d rows\n", curRow
+ 1);
5034 /* recalculate toolbar */
5035 TOOLBAR_CalcToolbar (hwnd
);
5037 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
5038 if NORESIZE is NOT set, then the toolbar will always be resized to
5039 take up the whole window. With it set, sizing needs to be manual. */
5040 if (infoPtr
->dwStyle
& CCS_NORESIZE
) {
5041 SetWindowPos(hwnd
, NULL
, 0, 0,
5042 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
5043 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
,
5047 /* repaint toolbar */
5048 InvalidateRect(hwnd
, NULL
, TRUE
);
5051 /* return bounding rectangle */
5053 lprc
->left
= infoPtr
->rcBound
.left
;
5054 lprc
->right
= infoPtr
->rcBound
.right
;
5055 lprc
->top
= infoPtr
->rcBound
.top
;
5056 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
5064 TOOLBAR_SetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5066 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5067 TBUTTON_INFO
*btnPtr
;
5070 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
5074 btnPtr
= &infoPtr
->buttons
[nIndex
];
5076 /* if hidden state has changed the invalidate entire window and recalc */
5077 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
5078 btnPtr
->fsState
= LOWORD(lParam
);
5079 TOOLBAR_CalcToolbar (hwnd
);
5080 InvalidateRect(hwnd
, 0, TRUE
);
5084 /* process state changing if current state doesn't match new state */
5085 if(btnPtr
->fsState
!= LOWORD(lParam
))
5087 btnPtr
->fsState
= LOWORD(lParam
);
5088 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5096 TOOLBAR_SetStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5098 SetWindowLongW(hwnd
, GWL_STYLE
, lParam
);
5104 static inline LRESULT
5105 TOOLBAR_SetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5107 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5109 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd
, (HWND
)wParam
, lParam
);
5111 infoPtr
->hwndToolTip
= (HWND
)wParam
;
5117 TOOLBAR_SetUnicodeFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5119 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5122 TRACE("%s hwnd=%p\n",
5123 ((BOOL
)wParam
) ? "TRUE" : "FALSE", hwnd
);
5125 bTemp
= infoPtr
->bUnicode
;
5126 infoPtr
->bUnicode
= (BOOL
)wParam
;
5133 TOOLBAR_GetColorScheme (HWND hwnd
, LPCOLORSCHEME lParam
)
5135 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5137 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
5138 comctl32_color
.clrBtnHighlight
:
5139 infoPtr
->clrBtnHighlight
;
5140 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
5141 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
5147 TOOLBAR_SetColorScheme (HWND hwnd
, const COLORSCHEME
*lParam
)
5149 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5151 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5152 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
5153 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
5155 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
5156 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
5157 InvalidateRect(hwnd
, NULL
, TRUE
);
5163 TOOLBAR_SetVersion (HWND hwnd
, INT iVersion
)
5165 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5166 INT iOldVersion
= infoPtr
->iVersion
;
5168 infoPtr
->iVersion
= iVersion
;
5170 if (infoPtr
->iVersion
>= 5)
5171 TOOLBAR_SetUnicodeFormat(hwnd
, (WPARAM
)TRUE
, (LPARAM
)0);
5178 TOOLBAR_GetStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5180 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5181 WORD iString
= HIWORD(wParam
);
5182 WORD buffersize
= LOWORD(wParam
);
5183 LPSTR str
= (LPSTR
)lParam
;
5186 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, buffersize
, str
);
5188 if (iString
< infoPtr
->nNumStrings
)
5190 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
5192 TRACE("returning %s\n", debugstr_a(str
));
5195 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5202 TOOLBAR_GetStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5204 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5205 WORD iString
= HIWORD(wParam
);
5206 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5207 LPWSTR str
= (LPWSTR
)lParam
;
5210 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, LOWORD(wParam
), str
);
5212 if (iString
< infoPtr
->nNumStrings
)
5214 len
= min(len
, strlenW(infoPtr
->strings
[iString
]));
5215 ret
= (len
+1)*sizeof(WCHAR
);
5216 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5219 TRACE("returning %s\n", debugstr_w(str
));
5222 ERR("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5227 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5228 * is the maximum size of the toolbar? */
5229 static LRESULT
TOOLBAR_Unkwn45D(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5231 SIZE
* pSize
= (SIZE
*)lParam
;
5232 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5237 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5238 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5239 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5242 TOOLBAR_Unkwn45E (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5244 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5245 INT nOldHotItem
= infoPtr
->nHotItem
;
5247 TRACE("old item=%d, new item=%d, flags=%08x\n",
5248 nOldHotItem
, infoPtr
->nHotItem
, (DWORD
)lParam
);
5250 if ((INT
) wParam
< 0 || (INT
)wParam
> infoPtr
->nNumButtons
)
5253 /* NOTE: an application can still remove the hot item even if anchor
5254 * highlighting is enabled */
5256 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, lParam
);
5260 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5263 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5264 * which controls the amount of spacing between the image and the text
5265 * of buttons for TBSTYLE_LIST toolbars. */
5266 static LRESULT
TOOLBAR_Unkwn460(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5268 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5270 TRACE("hwnd=%p iListGap=%ld\n", hwnd
, wParam
);
5273 FIXME("lParam = 0x%08lx. Please report\n", lParam
);
5275 infoPtr
->iListGap
= (INT
)wParam
;
5277 InvalidateRect(hwnd
, NULL
, TRUE
);
5282 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5283 * of image lists associated with the various states. */
5284 static LRESULT
TOOLBAR_Unkwn462(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5286 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5288 TRACE("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5290 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5294 TOOLBAR_Unkwn463 (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5296 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5297 LPSIZE lpsize
= (LPSIZE
)lParam
;
5303 * Testing shows the following:
5304 * wParam = 0 adjust cx value
5305 * = 1 set cy value to max size.
5306 * lParam pointer to SIZE structure
5309 TRACE("[0463] wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5310 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5314 if (lpsize
->cx
== -1) {
5315 /* **** this is wrong, native measures each button and sets it */
5316 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5318 else if(HIWORD(lpsize
->cx
)) {
5320 HWND hwndParent
= GetParent(hwnd
);
5322 GetWindowRect(hwnd
, &rc
);
5323 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5324 TRACE("mapped to (%d,%d)-(%d,%d)\n",
5325 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5326 lpsize
->cx
= max(rc
.right
-rc
.left
,
5327 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5330 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5334 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5337 ERR("Unknown wParam %ld for Toolbar message [0463]. Please report\n",
5341 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5342 lpsize
->cx
, lpsize
->cy
);
5346 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5348 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5350 InvalidateRect(hwnd
, NULL
, TRUE
);
5356 TOOLBAR_Create (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5358 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5359 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
5362 TRACE("hwnd = %p\n", hwnd
);
5364 /* initialize info structure */
5365 infoPtr
->nButtonWidth
= 23;
5366 infoPtr
->nButtonHeight
= 22;
5367 infoPtr
->nBitmapHeight
= 16;
5368 infoPtr
->nBitmapWidth
= 16;
5370 infoPtr
->nMaxTextRows
= 1;
5371 infoPtr
->cxMin
= -1;
5372 infoPtr
->cxMax
= -1;
5373 infoPtr
->nNumBitmaps
= 0;
5374 infoPtr
->nNumStrings
= 0;
5376 infoPtr
->bCaptured
= FALSE
;
5377 infoPtr
->nButtonDown
= -1;
5378 infoPtr
->nButtonDrag
= -1;
5379 infoPtr
->nOldHit
= -1;
5380 infoPtr
->nHotItem
= -1;
5381 infoPtr
->hwndNotify
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
5382 infoPtr
->dwDTFlags
= (dwStyle
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
5383 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
5384 infoPtr
->bDragOutSent
= FALSE
;
5385 infoPtr
->iVersion
= 0;
5386 infoPtr
->hwndSelf
= hwnd
;
5387 infoPtr
->bDoRedraw
= TRUE
;
5388 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
5389 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
5390 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
5391 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
5392 infoPtr
->iListGap
= DEFLISTGAP
;
5393 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
5394 infoPtr
->dwStyle
= dwStyle
;
5395 infoPtr
->tbim
.iButton
= -1;
5396 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5397 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5398 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, (LPARAM
)NF_REQUERY
));
5399 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5401 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5402 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5404 OpenThemeData (hwnd
, themeClass
);
5406 TOOLBAR_CheckStyle (hwnd
, dwStyle
);
5413 TOOLBAR_Destroy (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5415 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5417 /* delete tooltip control */
5418 if (infoPtr
->hwndToolTip
)
5419 DestroyWindow (infoPtr
->hwndToolTip
);
5421 /* delete temporary buffer for tooltip text */
5422 Free (infoPtr
->pszTooltipText
);
5423 Free (infoPtr
->bitmaps
); /* bitmaps list */
5425 /* delete button data */
5426 Free (infoPtr
->buttons
);
5428 /* delete strings */
5429 if (infoPtr
->strings
) {
5431 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5432 Free (infoPtr
->strings
[i
]);
5434 Free (infoPtr
->strings
);
5437 /* destroy internal image list */
5438 if (infoPtr
->himlInt
)
5439 ImageList_Destroy (infoPtr
->himlInt
);
5441 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5442 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5443 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5445 /* delete default font */
5446 DeleteObject (infoPtr
->hDefaultFont
);
5448 CloseThemeData (GetWindowTheme (hwnd
));
5450 /* free toolbar info data */
5452 SetWindowLongPtrW (hwnd
, 0, 0);
5459 TOOLBAR_EraseBackground (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5461 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5462 NMTBCUSTOMDRAW tbcd
;
5465 HTHEME theme
= GetWindowTheme (hwnd
);
5466 DWORD dwEraseCustDraw
= 0;
5468 /* the app has told us not to redraw the toolbar */
5469 if (!infoPtr
->bDoRedraw
)
5472 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5473 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5474 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5475 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5476 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5477 dwEraseCustDraw
= ntfret
& 0xffff;
5479 /* FIXME: in general the return flags *can* be or'ed together */
5480 switch (dwEraseCustDraw
)
5482 case CDRF_DODEFAULT
:
5484 case CDRF_SKIPDEFAULT
:
5487 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5492 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5493 * to my parent for processing.
5495 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5497 HDC hdc
= (HDC
)wParam
;
5502 parent
= GetParent(hwnd
);
5503 MapWindowPoints(hwnd
, parent
, &pt
, 1);
5504 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5505 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5506 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5509 ret
= DefWindowProcW (hwnd
, WM_ERASEBKGND
, wParam
, lParam
);
5511 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5512 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5513 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5514 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5515 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5516 dwEraseCustDraw
= ntfret
& 0xffff;
5517 switch (dwEraseCustDraw
)
5519 case CDRF_DODEFAULT
:
5521 case CDRF_SKIPDEFAULT
:
5524 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5533 TOOLBAR_GetFont (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5535 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5537 return (LRESULT
)infoPtr
->hFont
;
5542 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5545 INT nNewHotItem
= infoPtr
->nHotItem
;
5547 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5550 if ((nNewHotItem
+ iDirection
< 0) ||
5551 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5553 NMTBWRAPHOTITEM nmtbwhi
;
5554 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5555 nmtbwhi
.iDirection
= iDirection
;
5556 nmtbwhi
.dwReason
= dwReason
;
5558 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5562 nNewHotItem
+= iDirection
;
5563 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5565 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5566 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5568 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5575 TOOLBAR_KeyDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5577 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5580 nmkey
.nVKey
= (UINT
)wParam
;
5581 nmkey
.uFlags
= HIWORD(lParam
);
5583 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5584 return DefWindowProcW(hwnd
, WM_KEYDOWN
, wParam
, lParam
);
5586 switch ((UINT
)wParam
)
5590 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5594 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5598 if ((infoPtr
->nHotItem
>= 0) &&
5599 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5601 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5602 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5613 TOOLBAR_LButtonDblClk (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5618 pt
.x
= (short)LOWORD(lParam
);
5619 pt
.y
= (short)HIWORD(lParam
);
5620 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5623 TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
5624 else if (GetWindowLongW (hwnd
, GWL_STYLE
) & CCS_ADJUSTABLE
)
5625 TOOLBAR_Customize (hwnd
);
5632 TOOLBAR_LButtonDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5634 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5635 TBUTTON_INFO
*btnPtr
;
5640 BOOL bDragKeyPressed
;
5644 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5645 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5647 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5649 if (infoPtr
->hwndToolTip
)
5650 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5651 WM_LBUTTONDOWN
, wParam
, lParam
);
5653 pt
.x
= (short)LOWORD(lParam
);
5654 pt
.y
= (short)HIWORD(lParam
);
5655 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5657 btnPtr
= &infoPtr
->buttons
[nHit
];
5659 if ((nHit
>= 0) && bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5661 infoPtr
->nButtonDrag
= nHit
;
5664 /* If drag cursor has not been loaded, load it.
5665 * Note: it doesn't need to be freed */
5667 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5668 SetCursor(hCursorDrag
);
5673 infoPtr
->nOldHit
= nHit
;
5675 CopyRect(&arrowRect
, &btnPtr
->rect
);
5676 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5678 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5679 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5680 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5681 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5682 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5683 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5687 /* draw in pressed state */
5688 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5689 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5691 btnPtr
->bDropDownPressed
= TRUE
;
5692 RedrawWindow(hwnd
,&btnPtr
->rect
,0,
5693 RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5695 memset(&nmtb
, 0, sizeof(nmtb
));
5696 nmtb
.iItem
= btnPtr
->idCommand
;
5697 nmtb
.rcButton
= btnPtr
->rect
;
5698 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5700 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5702 if (res
!= TBDDRET_TREATPRESSED
)
5706 /* redraw button in unpressed state */
5707 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5708 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5710 btnPtr
->bDropDownPressed
= FALSE
;
5711 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5713 /* find and set hot item
5714 * NOTE: native doesn't do this, but that is a bug */
5716 ScreenToClient(hwnd
, &pt
);
5717 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
5718 if (!infoPtr
->bAnchor
|| (nHit
>= 0))
5719 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5721 /* remove any left mouse button down or double-click messages
5722 * so that we can get a toggle effect on the button */
5723 while (PeekMessageW(&msg
, hwnd
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5724 PeekMessageW(&msg
, hwnd
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5729 /* otherwise drop through and process as pushed */
5731 infoPtr
->bCaptured
= TRUE
;
5732 infoPtr
->nButtonDown
= nHit
;
5733 infoPtr
->bDragOutSent
= FALSE
;
5735 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5737 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5739 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5740 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5747 memset(&nmtb
, 0, sizeof(nmtb
));
5748 nmtb
.iItem
= btnPtr
->idCommand
;
5749 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5752 nmmouse
.dwHitInfo
= nHit
;
5754 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5756 nmmouse
.dwItemSpec
= -1;
5759 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5760 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5763 ClientToScreen(hwnd
, &pt
);
5766 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5767 return DefWindowProcW(hwnd
, WM_LBUTTONDOWN
, wParam
, lParam
);
5773 TOOLBAR_LButtonUp (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5775 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5776 TBUTTON_INFO
*btnPtr
;
5780 BOOL bSendMessage
= TRUE
;
5785 if (infoPtr
->hwndToolTip
)
5786 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5787 WM_LBUTTONUP
, wParam
, lParam
);
5789 pt
.x
= (short)LOWORD(lParam
);
5790 pt
.y
= (short)HIWORD(lParam
);
5791 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5793 if (!infoPtr
->bAnchor
|| (nHit
>= 0))
5794 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5796 if (infoPtr
->nButtonDrag
>= 0) {
5800 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5803 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5805 GetClientRect(hwnd
, &rcClient
);
5806 if (PtInRect(&rcClient
, pt
))
5813 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5816 if (nButton
== infoPtr
->nButtonDrag
)
5818 /* if the button is moved sightly left and we have a
5819 * separator there then remove it */
5820 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5822 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5823 TOOLBAR_DeleteButton(hwnd
, nButton
- 1, 0);
5825 else /* else insert a separator before the dragged button */
5828 memset(&tbb
, 0, sizeof(tbb
));
5829 tbb
.fsStyle
= BTNS_SEP
;
5831 TOOLBAR_InsertButtonT(hwnd
, nButton
, (LPARAM
)&tbb
, TRUE
);
5838 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5839 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, 0);
5841 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5844 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, nButton
);
5849 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5850 TOOLBAR_DeleteButton(hwnd
, (WPARAM
)infoPtr
->nButtonDrag
, 0);
5853 /* button under cursor changed so need to re-set hot item */
5854 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5855 infoPtr
->nButtonDrag
= -1;
5857 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5859 else if (infoPtr
->nButtonDown
>= 0) {
5860 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5861 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5863 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5864 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5865 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5867 if (nOldIndex
== nHit
)
5868 bSendMessage
= FALSE
;
5869 if ((nOldIndex
!= nHit
) &&
5871 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5872 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5875 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5876 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5878 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5882 if (nOldIndex
!= -1)
5883 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5886 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5887 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5888 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5890 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5892 infoPtr
->nButtonDown
= -1;
5894 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5895 TOOLBAR_SendNotify (&hdr
, infoPtr
,
5896 NM_RELEASEDCAPTURE
);
5898 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5901 memset(&nmtb
, 0, sizeof(nmtb
));
5902 nmtb
.iItem
= btnPtr
->idCommand
;
5903 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5906 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5908 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5909 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)hwnd
);
5911 /* In case we have just been destroyed... */
5917 /* !!! Undocumented - toolbar at 4.71 level and above sends
5918 * NM_CLICK with the NMMOUSE structure. */
5919 nmmouse
.dwHitInfo
= nHit
;
5922 nmmouse
.dwItemSpec
= -1;
5925 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5926 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5929 ClientToScreen(hwnd
, &pt
);
5932 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5933 return DefWindowProcW(hwnd
, WM_LBUTTONUP
, wParam
, lParam
);
5939 TOOLBAR_RButtonUp( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5941 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5946 pt
.x
= (short)LOWORD(lParam
);
5947 pt
.y
= (short)HIWORD(lParam
);
5949 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
5950 nmmouse
.dwHitInfo
= nHit
;
5953 nmmouse
.dwItemSpec
= -1;
5955 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5956 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5959 ClientToScreen(hwnd
, &pt
);
5962 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5963 return DefWindowProcW(hwnd
, WM_RBUTTONUP
, wParam
, lParam
);
5969 TOOLBAR_RButtonDblClk( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5971 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5974 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5975 return DefWindowProcW(hwnd
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
5981 TOOLBAR_CaptureChanged(HWND hwnd
)
5983 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5984 TBUTTON_INFO
*btnPtr
;
5986 infoPtr
->bCaptured
= FALSE
;
5988 if (infoPtr
->nButtonDown
>= 0)
5990 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5991 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5993 infoPtr
->nOldHit
= -1;
5995 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5996 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6002 TOOLBAR_MouseLeave (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6004 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6006 /* don't remove hot effects when in anchor highlighting mode or when a
6007 * drop-down button is pressed */
6008 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
6010 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
6011 if (!hotBtnPtr
->bDropDownPressed
)
6012 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
6015 if (infoPtr
->nOldHit
< 0)
6018 /* If the last button we were over is depressed then make it not */
6019 /* depressed and redraw it */
6020 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
6022 TBUTTON_INFO
*btnPtr
;
6025 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6027 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6030 InflateRect (&rc1
, 1, 1);
6031 InvalidateRect (hwnd
, &rc1
, TRUE
);
6034 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
6037 ZeroMemory(&nmt
, sizeof(nmt
));
6038 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6039 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6040 infoPtr
->bDragOutSent
= TRUE
;
6043 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
6049 TOOLBAR_MouseMove (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6051 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6053 TRACKMOUSEEVENT trackinfo
;
6055 TBUTTON_INFO
*btnPtr
;
6057 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
6058 TOOLBAR_TooltipCreateControl(infoPtr
);
6060 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
6061 /* fill in the TRACKMOUSEEVENT struct */
6062 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
6063 trackinfo
.dwFlags
= TME_QUERY
;
6065 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6066 _TrackMouseEvent(&trackinfo
);
6068 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6069 if(trackinfo
.hwndTrack
!= hwnd
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
6070 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
6071 trackinfo
.hwndTrack
= hwnd
;
6073 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6074 /* and can properly deactivate the hot toolbar button */
6075 _TrackMouseEvent(&trackinfo
);
6079 if (infoPtr
->hwndToolTip
)
6080 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
6081 WM_MOUSEMOVE
, wParam
, lParam
);
6083 pt
.x
= (short)LOWORD(lParam
);
6084 pt
.y
= (short)HIWORD(lParam
);
6086 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
6088 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6089 && (!infoPtr
->bAnchor
|| (nHit
>= 0)))
6090 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
);
6092 if (infoPtr
->nOldHit
!= nHit
)
6094 if (infoPtr
->bCaptured
)
6096 if (!infoPtr
->bDragOutSent
)
6099 ZeroMemory(&nmt
, sizeof(nmt
));
6100 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6101 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6102 infoPtr
->bDragOutSent
= TRUE
;
6105 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6106 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
6107 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6108 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6110 else if (nHit
== infoPtr
->nButtonDown
) {
6111 btnPtr
->fsState
|= TBSTATE_PRESSED
;
6112 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6114 infoPtr
->nOldHit
= nHit
;
6122 static inline LRESULT
6123 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6125 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6126 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
6128 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6132 static inline LRESULT
6133 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6135 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
6136 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
6138 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
6143 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6145 TOOLBAR_INFO
*infoPtr
;
6146 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
6149 /* allocate memory for info structure */
6150 infoPtr
= (TOOLBAR_INFO
*)Alloc (sizeof(TOOLBAR_INFO
));
6151 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
6154 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
6156 infoPtr
->nWidth
= 0;
6158 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6159 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
6160 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
6161 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
6164 /* native control does:
6165 * Get a lot of colors and brushes
6167 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6168 * CreateFontIndirectW(adr1)
6169 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6170 * hdc = GetDC(toolbar)
6171 * GetSystemMetrics(0x48)
6172 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6173 * 0, 0, 0, 0, "MARLETT")
6174 * oldfnt = SelectObject(hdc, fnt2)
6175 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6176 * GetTextMetricsW(hdc, adr3)
6177 * SelectObject(hdc, oldfnt)
6178 * DeleteObject(fnt2)
6180 * InvalidateRect(toolbar, 0, 1)
6181 * SetWindowLongW(toolbar, 0, addr)
6182 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6185 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6186 * ie 2 0x4600094c 0x4600094c 0x4600894d
6187 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6188 * rebar 0x50008844 0x40008844 0x50008845
6189 * pager 0x50000844 0x40000844 0x50008845
6190 * IC35mgr 0x5400084e **nochange**
6191 * on entry to _NCCREATE 0x5400084e
6192 * rowlist 0x5400004e **nochange**
6193 * on entry to _NCCREATE 0x5400004e
6197 /* I think the code below is a bug, but it is the way that the native
6198 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6199 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6200 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6201 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6202 * Somehow, the only cases of this seem to be MFC programs.
6204 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6205 * does not occur in the WM_STYLECHANGING routine.
6206 * (Guy Albertelli 9/2001)
6209 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6210 && !(cs
->style
& TBSTYLE_TRANSPARENT
))
6211 styleadd
|= TBSTYLE_TRANSPARENT
;
6212 if (!(cs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
6213 styleadd
|= CCS_TOP
; /* default to top */
6214 SetWindowLongW (hwnd
, GWL_STYLE
, cs
->style
| styleadd
);
6217 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, lParam
);
6222 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6224 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
6228 if (dwStyle
& WS_MINIMIZE
)
6229 return 0; /* Nothing to do */
6231 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
6233 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
6236 if (!(dwStyle
& CCS_NODIVIDER
))
6238 GetWindowRect (hwnd
, &rcWindow
);
6239 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
6240 if( dwStyle
& WS_BORDER
)
6241 OffsetRect (&rcWindow
, 1, 1);
6242 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6245 ReleaseDC( hwnd
, hdc
);
6251 /* handles requests from the tooltip control on what text to display */
6252 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6254 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6256 TRACE("button index = %d\n", index
);
6258 Free (infoPtr
->pszTooltipText
);
6259 infoPtr
->pszTooltipText
= NULL
;
6264 if (infoPtr
->bUnicode
)
6266 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6267 NMTBGETINFOTIPW tbgit
;
6268 unsigned int len
; /* in chars */
6270 wszBuffer
[0] = '\0';
6271 wszBuffer
[INFOTIPSIZE
] = '\0';
6273 tbgit
.pszText
= wszBuffer
;
6274 tbgit
.cchTextMax
= INFOTIPSIZE
;
6275 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6276 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6278 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6280 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6282 len
= strlenW(tbgit
.pszText
);
6283 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6285 /* need to allocate temporary buffer in infoPtr as there
6286 * isn't enough space in buffer passed to us by the
6287 * tooltip control */
6288 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6289 if (infoPtr
->pszTooltipText
)
6291 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6292 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6298 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6304 CHAR szBuffer
[INFOTIPSIZE
+1];
6305 NMTBGETINFOTIPA tbgit
;
6306 unsigned int len
; /* in chars */
6309 szBuffer
[INFOTIPSIZE
] = '\0';
6311 tbgit
.pszText
= szBuffer
;
6312 tbgit
.cchTextMax
= INFOTIPSIZE
;
6313 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6314 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6316 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6318 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6320 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6321 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]))
6323 /* need to allocate temporary buffer in infoPtr as there
6324 * isn't enough space in buffer passed to us by the
6325 * tooltip control */
6326 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6327 if (infoPtr
->pszTooltipText
)
6329 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6330 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6334 else if (tbgit
.pszText
[0])
6336 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1,
6337 lpnmtdi
->lpszText
, sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]));
6342 /* if button has text, but it is not shown then automatically
6343 * use that text as tooltip */
6344 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6345 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6347 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6348 unsigned int len
= pszText
? strlenW(pszText
) : 0;
6350 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6352 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6354 /* need to allocate temporary buffer in infoPtr as there
6355 * isn't enough space in buffer passed to us by the
6356 * tooltip control */
6357 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6358 if (infoPtr
->pszTooltipText
)
6360 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6361 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6367 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6372 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6374 /* last resort: send notification on to app */
6375 /* FIXME: find out what is really used here */
6376 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmtdi
->hdr
.idFrom
, (LPARAM
)lpnmtdi
);
6380 static inline LRESULT
6381 TOOLBAR_Notify (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6383 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6384 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
6386 switch (lpnmh
->code
)
6390 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
6392 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6393 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6394 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6398 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6399 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6407 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lParam
;
6409 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6410 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6411 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6412 lppgs
->iScroll
, lppgs
->iDir
);
6416 case TTN_GETDISPINFOW
:
6417 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lParam
);
6419 case TTN_GETDISPINFOA
:
6420 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6430 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6434 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam
, lParam
);
6436 if (lParam
== NF_QUERY
)
6439 if (lParam
== NF_REQUERY
) {
6440 format
= SendMessageW(infoPtr
->hwndNotify
,
6441 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6442 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6443 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6454 TOOLBAR_Paint (HWND hwnd
, WPARAM wParam
)
6456 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
6460 /* fill ps.rcPaint with a default rect */
6461 memcpy(&(ps
.rcPaint
), &(infoPtr
->rcBound
), sizeof(infoPtr
->rcBound
));
6463 hdc
= wParam
==0 ? BeginPaint(hwnd
, &ps
) : (HDC
)wParam
;
6465 TRACE("psrect=(%d,%d)-(%d,%d)\n",
6466 ps
.rcPaint
.left
, ps
.rcPaint
.top
,
6467 ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
6469 TOOLBAR_Refresh (hwnd
, hdc
, &ps
);
6470 if (!wParam
) EndPaint (hwnd
, &ps
);
6477 TOOLBAR_SetFocus (HWND hwnd
, WPARAM wParam
)
6479 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6481 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6483 /* make first item hot */
6484 if (infoPtr
->nNumButtons
> 0)
6485 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6491 TOOLBAR_SetFont(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6493 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
6495 TRACE("font=%p redraw=%ld\n", (HFONT
)wParam
, lParam
);
6498 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6500 infoPtr
->hFont
= (HFONT
)wParam
;
6502 TOOLBAR_CalcToolbar(hwnd
);
6505 InvalidateRect(hwnd
, NULL
, TRUE
);
6510 TOOLBAR_SetRedraw (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6511 /*****************************************************
6514 * Handles the WM_SETREDRAW message.
6517 * According to testing V4.71 of COMCTL32 returns the
6518 * *previous* status of the redraw flag (either 0 or 1)
6519 * instead of the MSDN documented value of 0 if handled.
6520 * (For laughs see the "consistency" with same function
6523 *****************************************************/
6525 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6526 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6528 TRACE("set to %s\n",
6529 (wParam
) ? "TRUE" : "FALSE");
6530 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6532 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6534 return (oldredraw
) ? 1 : 0;
6539 TOOLBAR_Size (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6541 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6543 TRACE("sizing toolbar!\n");
6545 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6547 RECT delta_width
, delta_height
, client
, dummy
;
6548 DWORD min_x
, max_x
, min_y
, max_y
;
6549 TBUTTON_INFO
*btnPtr
;
6552 GetClientRect(hwnd
, &client
);
6553 if(client
.right
> infoPtr
->client_rect
.right
)
6555 min_x
= infoPtr
->client_rect
.right
;
6556 max_x
= client
.right
;
6560 max_x
= infoPtr
->client_rect
.right
;
6561 min_x
= client
.right
;
6563 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6565 min_y
= infoPtr
->client_rect
.bottom
;
6566 max_y
= client
.bottom
;
6570 max_y
= infoPtr
->client_rect
.bottom
;
6571 min_y
= client
.bottom
;
6574 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6575 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6577 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6578 btnPtr
= infoPtr
->buttons
;
6579 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6580 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6581 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6582 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6584 GetClientRect(hwnd
, &infoPtr
->client_rect
);
6585 TOOLBAR_AutoSize(hwnd
);
6591 TOOLBAR_StyleChanged (HWND hwnd
, INT nType
, const STYLESTRUCT
*lpStyle
)
6593 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6595 if (nType
== GWL_STYLE
)
6597 DWORD dwOldStyle
= infoPtr
->dwStyle
;
6599 if (lpStyle
->styleNew
& TBSTYLE_LIST
)
6600 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
6602 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
6604 TOOLBAR_CheckStyle (hwnd
, lpStyle
->styleNew
);
6606 TRACE("new style 0x%08x\n", lpStyle
->styleNew
);
6608 infoPtr
->dwStyle
= lpStyle
->styleNew
;
6610 if ((dwOldStyle
^ lpStyle
->styleNew
) & (TBSTYLE_WRAPABLE
| CCS_VERT
))
6611 TOOLBAR_LayoutToolbar(hwnd
);
6613 /* only resize if one of the CCS_* styles was changed */
6614 if ((dwOldStyle
^ lpStyle
->styleNew
) & COMMON_STYLES
)
6616 TOOLBAR_AutoSize (hwnd
);
6618 InvalidateRect(hwnd
, NULL
, TRUE
);
6627 TOOLBAR_SysColorChange (HWND hwnd
)
6629 COMCTL32_RefreshSysColors();
6635 /* update theme after a WM_THEMECHANGED message */
6636 static LRESULT
theme_changed (HWND hwnd
)
6638 HTHEME theme
= GetWindowTheme (hwnd
);
6639 CloseThemeData (theme
);
6640 OpenThemeData (hwnd
, themeClass
);
6645 static LRESULT WINAPI
6646 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6648 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6650 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6651 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6653 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6654 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6659 return TOOLBAR_AddBitmap (hwnd
, wParam
, lParam
);
6661 case TB_ADDBUTTONSA
:
6662 return TOOLBAR_AddButtonsT(hwnd
, wParam
, lParam
, FALSE
);
6664 case TB_ADDBUTTONSW
:
6665 return TOOLBAR_AddButtonsT(hwnd
, wParam
, lParam
, TRUE
);
6668 return TOOLBAR_AddStringA (hwnd
, wParam
, lParam
);
6671 return TOOLBAR_AddStringW (hwnd
, wParam
, lParam
);
6674 return TOOLBAR_AutoSize (hwnd
);
6676 case TB_BUTTONCOUNT
:
6677 return TOOLBAR_ButtonCount (hwnd
, wParam
, lParam
);
6679 case TB_BUTTONSTRUCTSIZE
:
6680 return TOOLBAR_ButtonStructSize (hwnd
, wParam
, lParam
);
6682 case TB_CHANGEBITMAP
:
6683 return TOOLBAR_ChangeBitmap (hwnd
, wParam
, lParam
);
6685 case TB_CHECKBUTTON
:
6686 return TOOLBAR_CheckButton (hwnd
, wParam
, lParam
);
6688 case TB_COMMANDTOINDEX
:
6689 return TOOLBAR_CommandToIndex (hwnd
, wParam
, lParam
);
6692 return TOOLBAR_Customize (hwnd
);
6694 case TB_DELETEBUTTON
:
6695 return TOOLBAR_DeleteButton (hwnd
, wParam
, lParam
);
6697 case TB_ENABLEBUTTON
:
6698 return TOOLBAR_EnableButton (hwnd
, wParam
, lParam
);
6700 case TB_GETANCHORHIGHLIGHT
:
6701 return TOOLBAR_GetAnchorHighlight (hwnd
);
6704 return TOOLBAR_GetBitmap (hwnd
, wParam
, lParam
);
6706 case TB_GETBITMAPFLAGS
:
6707 return TOOLBAR_GetBitmapFlags (hwnd
, wParam
, lParam
);
6710 return TOOLBAR_GetButton (hwnd
, wParam
, lParam
);
6712 case TB_GETBUTTONINFOA
:
6713 return TOOLBAR_GetButtonInfoT(hwnd
, wParam
, lParam
, FALSE
);
6715 case TB_GETBUTTONINFOW
:
6716 return TOOLBAR_GetButtonInfoT(hwnd
, wParam
, lParam
, TRUE
);
6718 case TB_GETBUTTONSIZE
:
6719 return TOOLBAR_GetButtonSize (hwnd
);
6721 case TB_GETBUTTONTEXTA
:
6722 return TOOLBAR_GetButtonTextA (hwnd
, wParam
, lParam
);
6724 case TB_GETBUTTONTEXTW
:
6725 return TOOLBAR_GetButtonTextW (hwnd
, wParam
, lParam
);
6727 case TB_GETDISABLEDIMAGELIST
:
6728 return TOOLBAR_GetDisabledImageList (hwnd
, wParam
, lParam
);
6730 case TB_GETEXTENDEDSTYLE
:
6731 return TOOLBAR_GetExtendedStyle (hwnd
);
6733 case TB_GETHOTIMAGELIST
:
6734 return TOOLBAR_GetHotImageList (hwnd
, wParam
, lParam
);
6737 return TOOLBAR_GetHotItem (hwnd
);
6739 case TB_GETIMAGELIST
:
6740 return TOOLBAR_GetDefImageList (hwnd
, wParam
, lParam
);
6742 case TB_GETINSERTMARK
:
6743 return TOOLBAR_GetInsertMark (hwnd
, wParam
, lParam
);
6745 case TB_GETINSERTMARKCOLOR
:
6746 return TOOLBAR_GetInsertMarkColor (hwnd
, wParam
, lParam
);
6748 case TB_GETITEMRECT
:
6749 return TOOLBAR_GetItemRect (hwnd
, wParam
, lParam
);
6752 return TOOLBAR_GetMaxSize (hwnd
, wParam
, lParam
);
6754 /* case TB_GETOBJECT: */ /* 4.71 */
6757 return TOOLBAR_GetPadding (hwnd
);
6760 return TOOLBAR_GetRect (hwnd
, wParam
, lParam
);
6763 return TOOLBAR_GetRows (hwnd
, wParam
, lParam
);
6766 return TOOLBAR_GetState (hwnd
, wParam
, lParam
);
6769 return TOOLBAR_GetStringA (hwnd
, wParam
, lParam
);
6772 return TOOLBAR_GetStringW (hwnd
, wParam
, lParam
);
6775 return TOOLBAR_GetStyle (hwnd
, wParam
, lParam
);
6777 case TB_GETTEXTROWS
:
6778 return TOOLBAR_GetTextRows (hwnd
, wParam
, lParam
);
6780 case TB_GETTOOLTIPS
:
6781 return TOOLBAR_GetToolTips (hwnd
, wParam
, lParam
);
6783 case TB_GETUNICODEFORMAT
:
6784 return TOOLBAR_GetUnicodeFormat (hwnd
, wParam
, lParam
);
6787 return TOOLBAR_HideButton (hwnd
, wParam
, lParam
);
6790 return TOOLBAR_HitTest (hwnd
, wParam
, lParam
);
6792 case TB_INDETERMINATE
:
6793 return TOOLBAR_Indeterminate (hwnd
, wParam
, lParam
);
6795 case TB_INSERTBUTTONA
:
6796 return TOOLBAR_InsertButtonT(hwnd
, wParam
, lParam
, FALSE
);
6798 case TB_INSERTBUTTONW
:
6799 return TOOLBAR_InsertButtonT(hwnd
, wParam
, lParam
, TRUE
);
6801 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6803 case TB_ISBUTTONCHECKED
:
6804 return TOOLBAR_IsButtonChecked (hwnd
, wParam
, lParam
);
6806 case TB_ISBUTTONENABLED
:
6807 return TOOLBAR_IsButtonEnabled (hwnd
, wParam
, lParam
);
6809 case TB_ISBUTTONHIDDEN
:
6810 return TOOLBAR_IsButtonHidden (hwnd
, wParam
, lParam
);
6812 case TB_ISBUTTONHIGHLIGHTED
:
6813 return TOOLBAR_IsButtonHighlighted (hwnd
, wParam
, lParam
);
6815 case TB_ISBUTTONINDETERMINATE
:
6816 return TOOLBAR_IsButtonIndeterminate (hwnd
, wParam
, lParam
);
6818 case TB_ISBUTTONPRESSED
:
6819 return TOOLBAR_IsButtonPressed (hwnd
, wParam
, lParam
);
6822 return TOOLBAR_LoadImages (hwnd
, wParam
, lParam
);
6824 case TB_MAPACCELERATORA
:
6825 case TB_MAPACCELERATORW
:
6826 return TOOLBAR_MapAccelerator (hwnd
, wParam
, lParam
);
6829 return TOOLBAR_MarkButton (hwnd
, wParam
, lParam
);
6832 return TOOLBAR_MoveButton (hwnd
, wParam
, lParam
);
6834 case TB_PRESSBUTTON
:
6835 return TOOLBAR_PressButton (hwnd
, wParam
, lParam
);
6837 case TB_REPLACEBITMAP
:
6838 return TOOLBAR_ReplaceBitmap (hwnd
, wParam
, lParam
);
6840 case TB_SAVERESTOREA
:
6841 return TOOLBAR_SaveRestoreA (hwnd
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6843 case TB_SAVERESTOREW
:
6844 return TOOLBAR_SaveRestoreW (hwnd
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6846 case TB_SETANCHORHIGHLIGHT
:
6847 return TOOLBAR_SetAnchorHighlight (hwnd
, wParam
);
6849 case TB_SETBITMAPSIZE
:
6850 return TOOLBAR_SetBitmapSize (hwnd
, wParam
, lParam
);
6852 case TB_SETBUTTONINFOA
:
6853 return TOOLBAR_SetButtonInfoA (hwnd
, wParam
, lParam
);
6855 case TB_SETBUTTONINFOW
:
6856 return TOOLBAR_SetButtonInfoW (hwnd
, wParam
, lParam
);
6858 case TB_SETBUTTONSIZE
:
6859 return TOOLBAR_SetButtonSize (hwnd
, wParam
, lParam
);
6861 case TB_SETBUTTONWIDTH
:
6862 return TOOLBAR_SetButtonWidth (hwnd
, wParam
, lParam
);
6865 return TOOLBAR_SetCmdId (hwnd
, wParam
, lParam
);
6867 case TB_SETDISABLEDIMAGELIST
:
6868 return TOOLBAR_SetDisabledImageList (hwnd
, wParam
, lParam
);
6870 case TB_SETDRAWTEXTFLAGS
:
6871 return TOOLBAR_SetDrawTextFlags (hwnd
, wParam
, lParam
);
6873 case TB_SETEXTENDEDSTYLE
:
6874 return TOOLBAR_SetExtendedStyle (hwnd
, wParam
, lParam
);
6876 case TB_SETHOTIMAGELIST
:
6877 return TOOLBAR_SetHotImageList (hwnd
, wParam
, lParam
);
6880 return TOOLBAR_SetHotItem (hwnd
, wParam
);
6882 case TB_SETIMAGELIST
:
6883 return TOOLBAR_SetImageList (hwnd
, wParam
, lParam
);
6886 return TOOLBAR_SetIndent (hwnd
, wParam
, lParam
);
6888 case TB_SETINSERTMARK
:
6889 return TOOLBAR_SetInsertMark (hwnd
, wParam
, lParam
);
6891 case TB_SETINSERTMARKCOLOR
:
6892 return TOOLBAR_SetInsertMarkColor (hwnd
, wParam
, lParam
);
6894 case TB_SETMAXTEXTROWS
:
6895 return TOOLBAR_SetMaxTextRows (hwnd
, wParam
, lParam
);
6898 return TOOLBAR_SetPadding (hwnd
, wParam
, lParam
);
6901 return TOOLBAR_SetParent (hwnd
, wParam
, lParam
);
6904 return TOOLBAR_SetRows (hwnd
, wParam
, lParam
);
6907 return TOOLBAR_SetState (hwnd
, wParam
, lParam
);
6910 return TOOLBAR_SetStyle (hwnd
, wParam
, lParam
);
6912 case TB_SETTOOLTIPS
:
6913 return TOOLBAR_SetToolTips (hwnd
, wParam
, lParam
);
6915 case TB_SETUNICODEFORMAT
:
6916 return TOOLBAR_SetUnicodeFormat (hwnd
, wParam
, lParam
);
6919 return TOOLBAR_Unkwn45D(hwnd
, wParam
, lParam
);
6922 return TOOLBAR_Unkwn45E (hwnd
, wParam
, lParam
);
6925 return TOOLBAR_Unkwn460(hwnd
, wParam
, lParam
);
6928 return TOOLBAR_Unkwn462(hwnd
, wParam
, lParam
);
6931 return TOOLBAR_Unkwn463 (hwnd
, wParam
, lParam
);
6934 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6936 /* Common Control Messages */
6938 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6939 case CCM_GETCOLORSCHEME
:
6940 return TOOLBAR_GetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
6942 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6943 case CCM_SETCOLORSCHEME
:
6944 return TOOLBAR_SetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
6946 case CCM_GETVERSION
:
6947 return TOOLBAR_GetVersion (hwnd
);
6949 case CCM_SETVERSION
:
6950 return TOOLBAR_SetVersion (hwnd
, (INT
)wParam
);
6956 return TOOLBAR_Create (hwnd
, wParam
, lParam
);
6959 return TOOLBAR_Destroy (hwnd
, wParam
, lParam
);
6962 return TOOLBAR_EraseBackground (hwnd
, wParam
, lParam
);
6965 return TOOLBAR_GetFont (hwnd
, wParam
, lParam
);
6968 return TOOLBAR_KeyDown (hwnd
, wParam
, lParam
);
6970 /* case WM_KILLFOCUS: */
6972 case WM_LBUTTONDBLCLK
:
6973 return TOOLBAR_LButtonDblClk (hwnd
, wParam
, lParam
);
6975 case WM_LBUTTONDOWN
:
6976 return TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
6979 return TOOLBAR_LButtonUp (hwnd
, wParam
, lParam
);
6982 return TOOLBAR_RButtonUp (hwnd
, wParam
, lParam
);
6984 case WM_RBUTTONDBLCLK
:
6985 return TOOLBAR_RButtonDblClk (hwnd
, wParam
, lParam
);
6988 return TOOLBAR_MouseMove (hwnd
, wParam
, lParam
);
6991 return TOOLBAR_MouseLeave (hwnd
, wParam
, lParam
);
6993 case WM_CAPTURECHANGED
:
6994 return TOOLBAR_CaptureChanged(hwnd
);
6997 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
7000 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
7003 return TOOLBAR_NCCreate (hwnd
, wParam
, lParam
);
7006 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
7009 return TOOLBAR_Notify (hwnd
, wParam
, lParam
);
7011 case WM_NOTIFYFORMAT
:
7012 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
7014 case WM_PRINTCLIENT
:
7016 return TOOLBAR_Paint (hwnd
, wParam
);
7019 return TOOLBAR_SetFocus (hwnd
, wParam
);
7022 return TOOLBAR_SetFont(hwnd
, wParam
, lParam
);
7025 return TOOLBAR_SetRedraw (hwnd
, wParam
, lParam
);
7028 return TOOLBAR_Size (hwnd
, wParam
, lParam
);
7030 case WM_STYLECHANGED
:
7031 return TOOLBAR_StyleChanged (hwnd
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
7033 case WM_SYSCOLORCHANGE
:
7034 return TOOLBAR_SysColorChange (hwnd
);
7036 case WM_THEMECHANGED
:
7037 return theme_changed (hwnd
);
7039 /* case WM_WININICHANGE: */
7044 case WM_MEASUREITEM
:
7046 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
7048 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7049 case PGM_FORWARDMOUSE
:
7050 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7053 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
7054 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
7055 uMsg
, wParam
, lParam
);
7056 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7062 TOOLBAR_Register (void)
7066 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
7067 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
7068 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
7069 wndClass
.cbClsExtra
= 0;
7070 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
7071 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
7072 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
7073 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
7075 RegisterClassW (&wndClass
);
7080 TOOLBAR_Unregister (void)
7082 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
7085 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
7090 /* Check if the entry already exists */
7091 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
7093 /* If this is a new entry we must create it and insert into the array */
7098 c
= (PIMLENTRY
) Alloc(sizeof(IMLENTRY
));
7101 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
7102 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
7117 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
7121 for (i
= 0; i
< *cies
; i
++)
7131 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
7139 for (i
= 0; i
< cies
; i
++)
7141 if (pies
[i
]->id
== id
)
7153 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
7155 HIMAGELIST himlDef
= 0;
7156 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
7159 himlDef
= pie
->himl
;
7165 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
7167 if (infoPtr
->bUnicode
)
7168 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
7175 nmtba
.iItem
= nmtb
->iItem
;
7176 nmtba
.pszText
= Buffer
;
7177 nmtba
.cchText
= 256;
7178 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
7180 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
7182 int ccht
= strlen(nmtba
.pszText
);
7184 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)nmtba
.pszText
, -1,
7185 nmtb
->pszText
, nmtb
->cchText
);
7187 memcpy(&nmtb
->tbButton
, &nmtba
.tbButton
, sizeof(TBBUTTON
));
7196 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, PCUSTOMBUTTON btnInfo
)
7200 /* MSDN states that iItem is the index of the button, rather than the
7201 * command ID as used by every other NMTOOLBAR notification */
7203 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
7205 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);