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_DOUBLEBUFFER | \
229 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
231 /* all of the CCS_ styles */
232 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
233 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
235 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
236 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
237 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
238 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
239 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
241 static const WCHAR themeClass
[] = { 'T','o','o','l','b','a','r',0 };
243 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
);
244 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, PCUSTOMBUTTON btnInfo
);
245 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
);
246 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
);
247 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
);
248 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
);
249 static LRESULT
TOOLBAR_LButtonDown(HWND hwnd
, WPARAM wParam
, LPARAM lParam
);
250 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
);
251 static void TOOLBAR_LayoutToolbar(HWND hwnd
);
252 static LRESULT
TOOLBAR_AutoSize(HWND hwnd
);
253 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
);
254 static void TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
255 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
);
258 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
);
260 static inline int default_top_margin(const TOOLBAR_INFO
*infoPtr
)
262 return (infoPtr
->dwStyle
& TBSTYLE_FLAT
? 0 : TOP_BORDER
);
266 TOOLBAR_GetText(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
)
268 LPWSTR lpText
= NULL
;
270 /* NOTE: iString == -1 is undocumented */
271 if ((HIWORD(btnPtr
->iString
) != 0) && (btnPtr
->iString
!= -1))
272 lpText
= (LPWSTR
)btnPtr
->iString
;
273 else if ((btnPtr
->iString
>= 0) && (btnPtr
->iString
< infoPtr
->nNumStrings
))
274 lpText
= infoPtr
->strings
[btnPtr
->iString
];
280 TOOLBAR_DumpTBButton(const TBBUTTON
*tbb
, BOOL fUnicode
)
282 TRACE("TBBUTTON: id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx (%s)\n",
283 tbb
->idCommand
,tbb
->iBitmap
, tbb
->fsState
, tbb
->fsStyle
, tbb
->dwData
, tbb
->iString
,
284 (fUnicode
? wine_dbgstr_w((LPWSTR
)tbb
->iString
) : wine_dbgstr_a((LPSTR
)tbb
->iString
)));
288 TOOLBAR_DumpButton(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*bP
, INT btn_num
)
290 if (TRACE_ON(toolbar
)){
291 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
292 btn_num
, bP
->idCommand
, GETIBITMAP(infoPtr
, bP
->iBitmap
),
293 bP
->fsState
, bP
->fsStyle
, bP
->dwData
, bP
->iString
);
294 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr
,bP
)));
295 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n",
296 btn_num
, bP
->idCommand
, (bP
->bHot
) ? "TRUE":"FALSE", bP
->nRow
,
297 wine_dbgstr_rect(&bP
->rect
));
303 TOOLBAR_DumpToolbar(const TOOLBAR_INFO
*iP
, INT line
)
305 if (TRACE_ON(toolbar
)) {
308 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
310 iP
->dwExStyle
, iP
->nNumButtons
, iP
->nNumBitmaps
,
311 iP
->nNumStrings
, iP
->dwStyle
);
312 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
314 iP
->himlInt
, iP
->himlDef
, iP
->himlHot
, iP
->himlDis
,
315 (iP
->bDoRedraw
) ? "TRUE" : "FALSE");
316 for(i
=0; i
<iP
->nNumButtons
; i
++) {
317 TOOLBAR_DumpButton(iP
, &iP
->buttons
[i
], i
);
323 /***********************************************************************
326 * This function validates that the styles set are implemented and
327 * issues FIXME's warning of possible problems. In a perfect world this
328 * function should be null.
331 TOOLBAR_CheckStyle (HWND hwnd
, DWORD dwStyle
)
333 if (dwStyle
& TBSTYLE_REGISTERDROP
)
334 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd
);
339 TOOLBAR_SendNotify (NMHDR
*nmhdr
, const TOOLBAR_INFO
*infoPtr
, UINT code
)
341 if(!IsWindow(infoPtr
->hwndSelf
))
342 return 0; /* we have just been destroyed */
344 nmhdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
345 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
348 TRACE("to window %p, code=%08x, %s\n", infoPtr
->hwndNotify
, code
,
349 (infoPtr
->bUnicode
) ? "via Unicode" : "via ANSI");
351 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhdr
->idFrom
, (LPARAM
)nmhdr
);
354 /***********************************************************************
355 * TOOLBAR_GetBitmapIndex
357 * This function returns the bitmap index associated with a button.
358 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
359 * is issued to retrieve the index.
362 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
364 INT ret
= btnPtr
->iBitmap
;
366 if (ret
== I_IMAGECALLBACK
)
368 /* issue TBN_GETDISPINFO */
371 memset(&nmgd
, 0, sizeof(nmgd
));
372 nmgd
.idCommand
= btnPtr
->idCommand
;
373 nmgd
.lParam
= btnPtr
->dwData
;
374 nmgd
.dwMask
= TBNF_IMAGE
;
376 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
377 TOOLBAR_SendNotify(&nmgd
.hdr
, infoPtr
, TBN_GETDISPINFOW
);
378 if (nmgd
.dwMask
& TBNF_DI_SETITEM
)
379 btnPtr
->iBitmap
= nmgd
.iImage
;
381 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
382 ret
, nmgd
.dwMask
, infoPtr
->nNumBitmaps
);
385 if (ret
!= I_IMAGENONE
)
386 ret
= GETIBITMAP(infoPtr
, ret
);
393 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO
*infoPtr
, INT index
)
396 INT id
= GETHIMLID(infoPtr
, index
);
397 INT iBitmap
= GETIBITMAP(infoPtr
, index
);
399 if (((himl
= GETDEFIMAGELIST(infoPtr
, id
)) &&
400 iBitmap
>= 0 && iBitmap
< ImageList_GetImageCount(himl
)) ||
401 (index
== I_IMAGECALLBACK
))
409 TOOLBAR_IsValidImageList(const TOOLBAR_INFO
*infoPtr
, INT index
)
411 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, index
));
412 return (himl
!= NULL
) && (ImageList_GetImageCount(himl
) > 0);
416 /***********************************************************************
417 * TOOLBAR_GetImageListForDrawing
419 * This function validates the bitmap index (including I_IMAGECALLBACK
420 * functionality) and returns the corresponding image list.
423 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
,
424 IMAGE_LIST_TYPE imagelist
, INT
* index
)
428 if (!TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
)) {
429 if (btnPtr
->iBitmap
== I_IMAGENONE
) return NULL
;
430 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
431 HIWORD(btnPtr
->iBitmap
), LOWORD(btnPtr
->iBitmap
), infoPtr
->nNumBitmaps
);
435 if ((*index
= TOOLBAR_GetBitmapIndex(infoPtr
, btnPtr
)) < 0) {
436 if ((*index
== I_IMAGECALLBACK
) ||
437 (*index
== I_IMAGENONE
)) return NULL
;
438 ERR("TBN_GETDISPINFO returned invalid index %d\n",
445 case IMAGE_LIST_DEFAULT
:
446 himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
449 himl
= GETHOTIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
451 case IMAGE_LIST_DISABLED
:
452 himl
= GETDISIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
456 FIXME("Shouldn't reach here\n");
460 TRACE("no image list\n");
467 TOOLBAR_DrawFlatSeparator (const RECT
*lpRect
, HDC hdc
, const TOOLBAR_INFO
*infoPtr
)
470 COLORREF oldcolor
, newcolor
;
472 myrect
.left
= (lpRect
->left
+ lpRect
->right
) / 2 - 1;
473 myrect
.right
= myrect
.left
+ 1;
474 myrect
.top
= lpRect
->top
+ 2;
475 myrect
.bottom
= lpRect
->bottom
- 2;
477 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
478 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
479 oldcolor
= SetBkColor (hdc
, newcolor
);
480 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
482 myrect
.left
= myrect
.right
;
483 myrect
.right
= myrect
.left
+ 1;
485 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
486 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
487 SetBkColor (hdc
, newcolor
);
488 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
490 SetBkColor (hdc
, oldcolor
);
494 /***********************************************************************
495 * TOOLBAR_DrawDDFlatSeparator
497 * This function draws the separator that was flagged as BTNS_DROPDOWN.
498 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
499 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
500 * are horizontal as opposed to the vertical separators for not dropdown
503 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
506 TOOLBAR_DrawDDFlatSeparator (const RECT
*lpRect
, HDC hdc
,
507 const TOOLBAR_INFO
*infoPtr
)
510 COLORREF oldcolor
, newcolor
;
512 myrect
.left
= lpRect
->left
;
513 myrect
.right
= lpRect
->right
;
514 myrect
.top
= lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
- 2)/2;
515 myrect
.bottom
= myrect
.top
+ 1;
517 InflateRect (&myrect
, -2, 0);
519 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect
));
521 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
522 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
523 oldcolor
= SetBkColor (hdc
, newcolor
);
524 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
526 myrect
.top
= myrect
.bottom
;
527 myrect
.bottom
= myrect
.top
+ 1;
529 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
530 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
531 SetBkColor (hdc
, newcolor
);
532 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
534 SetBkColor (hdc
, oldcolor
);
539 TOOLBAR_DrawArrow (HDC hdc
, INT left
, INT top
, COLORREF clr
)
544 if (!(hPen
= CreatePen( PS_SOLID
, 1, clr
))) return;
545 hOldPen
= SelectObject ( hdc
, hPen
);
548 MoveToEx (hdc
, x
, y
, NULL
);
549 LineTo (hdc
, x
+5, y
++); x
++;
550 MoveToEx (hdc
, x
, y
, NULL
);
551 LineTo (hdc
, x
+3, y
++); x
++;
552 MoveToEx (hdc
, x
, y
, NULL
);
553 LineTo (hdc
, x
+1, y
);
554 SelectObject( hdc
, hOldPen
);
555 DeleteObject( hPen
);
559 * Draw the text string for this button.
560 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
561 * is non-zero, so we can simply check himlDef to see if we have
565 TOOLBAR_DrawString (const TOOLBAR_INFO
*infoPtr
, RECT
*rcText
, LPCWSTR lpText
,
566 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
568 HDC hdc
= tbcd
->nmcd
.hdc
;
571 COLORREF clrOldBk
= 0;
573 UINT state
= tbcd
->nmcd
.uItemState
;
577 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText
),
578 wine_dbgstr_rect(rcText
));
580 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
581 if ((state
& CDIS_HOT
) && (dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)) {
582 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
584 else if (state
& CDIS_DISABLED
) {
585 clrOld
= SetTextColor (hdc
, tbcd
->clrBtnHighlight
);
586 OffsetRect (rcText
, 1, 1);
587 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
588 SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
589 OffsetRect (rcText
, -1, -1);
591 else if (state
& CDIS_INDETERMINATE
) {
592 clrOld
= SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
594 else if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
)) {
595 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
596 clrOldBk
= SetBkColor (hdc
, tbcd
->clrMark
);
597 oldBkMode
= SetBkMode (hdc
, tbcd
->nHLStringBkMode
);
600 clrOld
= SetTextColor (hdc
, tbcd
->clrText
);
603 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
604 SetTextColor (hdc
, clrOld
);
605 if ((state
& CDIS_MARKED
) && !(dwItemCDFlag
& TBCDRF_NOMARK
))
607 SetBkColor (hdc
, clrOldBk
);
608 SetBkMode (hdc
, oldBkMode
);
610 SelectObject (hdc
, hOldFont
);
616 TOOLBAR_DrawPattern (const RECT
*lpRect
, const NMTBCUSTOMDRAW
*tbcd
)
618 HDC hdc
= tbcd
->nmcd
.hdc
;
619 HBRUSH hbr
= SelectObject (hdc
, tbcd
->hbrMonoDither
);
622 INT cx
= lpRect
->right
- lpRect
->left
;
623 INT cy
= lpRect
->bottom
- lpRect
->top
;
624 INT cxEdge
= GetSystemMetrics(SM_CXEDGE
);
625 INT cyEdge
= GetSystemMetrics(SM_CYEDGE
);
626 clrTextOld
= SetTextColor(hdc
, tbcd
->clrBtnHighlight
);
627 clrBkOld
= SetBkColor(hdc
, tbcd
->clrBtnFace
);
628 PatBlt (hdc
, lpRect
->left
+ cxEdge
, lpRect
->top
+ cyEdge
,
629 cx
- (2 * cxEdge
), cy
- (2 * cyEdge
), PATCOPY
);
630 SetBkColor(hdc
, clrBkOld
);
631 SetTextColor(hdc
, clrTextOld
);
632 SelectObject (hdc
, hbr
);
636 static void TOOLBAR_DrawMasked(HIMAGELIST himl
, int index
, HDC hdc
, INT x
, INT y
, UINT draw_flags
)
639 HBITMAP hbmMask
, hbmImage
;
640 HDC hdcMask
, hdcImage
;
642 ImageList_GetIconSize(himl
, &cx
, &cy
);
644 /* Create src image */
645 hdcImage
= CreateCompatibleDC(hdc
);
646 hbmImage
= CreateCompatibleBitmap(hdc
, cx
, cy
);
647 SelectObject(hdcImage
, hbmImage
);
648 ImageList_DrawEx(himl
, index
, hdcImage
, 0, 0, cx
, cy
,
649 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags
);
652 hdcMask
= CreateCompatibleDC(0);
653 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
654 SelectObject(hdcMask
, hbmMask
);
656 /* Remove the background and all white pixels */
657 ImageList_DrawEx(himl
, index
, hdcMask
, 0, 0, cx
, cy
,
658 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK
);
659 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
660 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
662 /* draw the new mask 'etched' to hdc */
663 SetBkColor(hdc
, RGB(255, 255, 255));
664 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
665 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
666 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
667 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
668 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
671 DeleteObject(hbmImage
);
673 DeleteObject (hbmMask
);
679 TOOLBAR_TranslateState(const TBUTTON_INFO
*btnPtr
)
683 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
684 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
685 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
686 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
687 retstate
|= (btnPtr
->bHot
) ? CDIS_HOT
: 0;
688 retstate
|= ((btnPtr
->fsState
& (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) == (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) ? CDIS_INDETERMINATE
: 0;
689 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
693 /* draws the image on a toolbar button */
695 TOOLBAR_DrawImage(const TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
,
696 const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
698 HIMAGELIST himl
= NULL
;
699 BOOL draw_masked
= FALSE
;
702 UINT draw_flags
= ILD_TRANSPARENT
;
704 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
706 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
709 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
713 else if (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
||
714 ((tbcd
->nmcd
.uItemState
& CDIS_HOT
)
715 && ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))))
717 /* if hot, attempt to draw with hot image list, if fails,
718 use default image list */
719 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
721 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
724 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
729 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
730 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
733 if (!(dwItemCDFlag
& TBCDRF_NOMARK
) &&
734 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
735 draw_flags
|= ILD_BLEND50
;
737 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
738 index
, himl
, left
, top
, offset
);
741 TOOLBAR_DrawMasked (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
743 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
746 /* draws a blank frame for a toolbar button */
748 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, DWORD dwItemCDFlag
)
750 HDC hdc
= tbcd
->nmcd
.hdc
;
751 RECT rc
= tbcd
->nmcd
.rc
;
752 /* if the state is disabled or indeterminate then the button
753 * cannot have an interactive look like pressed or hot */
754 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
755 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
756 BOOL pressed_look
= !non_interactive_state
&&
757 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
758 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
760 /* app don't want us to draw any edges */
761 if (dwItemCDFlag
& TBCDRF_NOEDGES
)
764 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
767 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
768 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
769 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
774 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
776 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
777 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
782 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
, BOOL bDropDownPressed
, DWORD dwItemCDFlag
)
784 HDC hdc
= tbcd
->nmcd
.hdc
;
786 BOOL pressed
= bDropDownPressed
||
787 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
));
789 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
792 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
);
793 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
794 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
795 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
796 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
801 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
803 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
804 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
808 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
810 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
812 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
813 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
816 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
819 /* draws a complete toolbar button */
821 TOOLBAR_DrawButton (HWND hwnd
, TBUTTON_INFO
*btnPtr
, HDC hdc
, DWORD dwBaseCustDraw
)
823 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
824 DWORD dwStyle
= infoPtr
->dwStyle
;
825 BOOL hasDropDownArrow
= (TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) &&
826 (btnPtr
->fsStyle
& BTNS_DROPDOWN
)) ||
827 (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
828 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
829 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
830 RECT rc
, rcArrow
, rcBitmap
, rcText
;
831 LPWSTR lpText
= NULL
;
836 DWORD dwItemCustDraw
;
838 HTHEME theme
= GetWindowTheme (hwnd
);
841 CopyRect (&rcArrow
, &rc
);
843 /* separator - doesn't send NM_CUSTOMDRAW */
844 if (btnPtr
->fsStyle
& BTNS_SEP
) {
847 DrawThemeBackground (theme
, hdc
,
848 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
852 /* with the FLAT style, iBitmap is the width and has already */
853 /* been taken into consideration in calculating the width */
854 /* so now we need to draw the vertical separator */
855 /* empirical tests show that iBitmap can/will be non-zero */
856 /* when drawing the vertical bar... */
857 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
858 if (btnPtr
->fsStyle
& BTNS_DROPDOWN
)
859 TOOLBAR_DrawDDFlatSeparator (&rc
, hdc
, infoPtr
);
861 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
863 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
864 FIXME("Draw some kind of separator: fsStyle=%x\n",
870 /* get a pointer to the text */
871 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
873 if (hasDropDownArrow
)
877 if (dwStyle
& TBSTYLE_FLAT
)
878 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
880 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
882 if (drawSepDropDownArrow
)
885 rcArrow
.left
= right
;
888 /* copy text & bitmap rects after adjusting for drop-down arrow
889 * so that text & bitmap is centered in the rectangle not containing
891 CopyRect(&rcText
, &rc
);
892 CopyRect(&rcBitmap
, &rc
);
894 /* Center the bitmap horizontally and vertically */
895 if (dwStyle
& TBSTYLE_LIST
)
898 infoPtr
->nMaxTextRows
> 0 &&
899 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
900 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
901 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
903 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
906 rcBitmap
.left
+= ((rc
.right
- rc
.left
) - infoPtr
->nBitmapWidth
) / 2;
908 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
910 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
911 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
912 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
913 TRACE("Text=%s\n", debugstr_w(lpText
));
914 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
916 /* calculate text position */
919 rcText
.left
+= GetSystemMetrics(SM_CXEDGE
);
920 rcText
.right
-= GetSystemMetrics(SM_CXEDGE
);
921 if (dwStyle
& TBSTYLE_LIST
)
923 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
927 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
928 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
930 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
934 /* Initialize fields in all cases, because we use these later
935 * NOTE: applications can and do alter these to customize their
937 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
938 tbcd
.clrText
= comctl32_color
.clrBtnText
;
939 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
940 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
941 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
942 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
943 tbcd
.clrHighlightHotTrack
= 0;
944 tbcd
.nStringBkMode
= TRANSPARENT
;
945 tbcd
.nHLStringBkMode
= OPAQUE
;
946 /* MSDN says that this is the text rectangle.
947 * But (why always a but) tracing of v5.7 of native shows
948 * that this is really a *relative* rectangle based on the
949 * the nmcd.rc. Also the left and top are always 0 ignoring
950 * any bitmap that might be present. */
951 tbcd
.rcText
.left
= 0;
953 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
954 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
955 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
958 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
960 /* FIXME: what are these used for? */
964 /* Issue Item Prepaint notify */
967 if (dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
969 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
970 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
971 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
972 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
973 /* reset these fields so the user can't alter the behaviour like native */
977 dwItemCustDraw
= ntfret
& 0xffff;
978 dwItemCDFlag
= ntfret
& 0xffff0000;
979 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
981 /* save the only part of the rect that the user can change */
982 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
983 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
986 if (!(dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
987 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
988 OffsetRect(&rcText
, 1, 1);
990 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
991 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
992 TOOLBAR_DrawPattern (&rc
, &tbcd
);
994 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
995 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
997 if ( dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
1001 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
1002 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
1003 if (hasDropDownArrow
)
1004 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
1005 SetBkColor(hdc
, oldclr
);
1011 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
1012 int stateId
= TS_NORMAL
;
1014 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1015 stateId
= TS_DISABLED
;
1016 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1017 stateId
= TS_PRESSED
;
1018 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1019 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1020 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1021 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1024 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &tbcd
.nmcd
.rc
, NULL
);
1027 TOOLBAR_DrawFrame(infoPtr
, &tbcd
, dwItemCDFlag
);
1029 if (drawSepDropDownArrow
)
1033 int stateId
= TS_NORMAL
;
1035 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1036 stateId
= TS_DISABLED
;
1037 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1038 stateId
= TS_PRESSED
;
1039 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1040 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1041 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1044 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1045 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1048 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
, dwItemCDFlag
);
1051 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1052 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1053 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
, dwItemCDFlag
);
1054 SetBkMode (hdc
, oldBkMode
);
1056 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
, dwItemCDFlag
);
1058 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1060 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1062 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1063 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1065 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1067 offset
= (dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1068 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1071 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1074 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1076 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1077 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1084 TOOLBAR_Refresh (HWND hwnd
, HDC hdc
, const PAINTSTRUCT
*ps
)
1086 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1087 TBUTTON_INFO
*btnPtr
;
1089 RECT rcTemp
, rcClient
;
1090 NMTBCUSTOMDRAW tbcd
;
1092 DWORD dwBaseCustDraw
;
1094 /* the app has told us not to redraw the toolbar */
1095 if (!infoPtr
->bDoRedraw
)
1098 /* if imagelist belongs to the app, it can be changed
1099 by the app after setting it */
1100 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1102 infoPtr
->nNumBitmaps
= 0;
1103 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1104 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1107 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1109 /* change the imagelist icon size if we manage the list and it is necessary */
1110 TOOLBAR_CheckImageListIconSize(infoPtr
);
1112 /* Send initial notify */
1113 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1114 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1115 tbcd
.nmcd
.hdc
= hdc
;
1116 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1117 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1118 dwBaseCustDraw
= ntfret
& 0xffff;
1120 GetClientRect(hwnd
, &rcClient
);
1122 /* redraw necessary buttons */
1123 btnPtr
= infoPtr
->buttons
;
1124 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1127 if (!RectVisible(hdc
, &btnPtr
->rect
))
1129 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1131 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1132 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1136 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1137 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1139 TOOLBAR_DrawButton(hwnd
, btnPtr
, hdc
, dwBaseCustDraw
);
1142 /* draw insert mark if required */
1143 if (infoPtr
->tbim
.iButton
!= -1)
1145 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1147 rcInsertMark
.top
= rcButton
.top
;
1148 rcInsertMark
.bottom
= rcButton
.bottom
;
1149 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1150 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1152 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1153 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1156 if (dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1158 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1159 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1160 tbcd
.nmcd
.hdc
= hdc
;
1161 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1162 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1166 /***********************************************************************
1167 * TOOLBAR_MeasureString
1169 * This function gets the width and height of a string in pixels. This
1170 * is done first by using GetTextExtentPoint to get the basic width
1171 * and height. The DrawText is called with DT_CALCRECT to get the exact
1172 * width. The reason is because the text may have more than one "&" (or
1173 * prefix characters as M$ likes to call them). The prefix character
1174 * indicates where the underline goes, except for the string "&&" which
1175 * is reduced to a single "&". GetTextExtentPoint does not process these
1176 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1179 TOOLBAR_MeasureString(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*btnPtr
,
1180 HDC hdc
, LPSIZE lpSize
)
1187 if (infoPtr
->nMaxTextRows
> 0 &&
1188 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1189 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1190 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1192 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1194 if(lpText
!= NULL
) {
1195 /* first get size of all the text */
1196 GetTextExtentPoint32W (hdc
, lpText
, strlenW (lpText
), lpSize
);
1198 /* feed above size into the rectangle for DrawText */
1199 myrect
.left
= myrect
.top
= 0;
1200 myrect
.right
= lpSize
->cx
;
1201 myrect
.bottom
= lpSize
->cy
;
1203 /* Use DrawText to get true size as drawn (less pesky "&") */
1204 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1205 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1208 /* feed back to caller */
1209 lpSize
->cx
= myrect
.right
;
1210 lpSize
->cy
= myrect
.bottom
;
1214 TRACE("string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1217 /***********************************************************************
1218 * TOOLBAR_CalcStrings
1220 * This function walks through each string and measures it and returns
1221 * the largest height and width to caller.
1224 TOOLBAR_CalcStrings (HWND hwnd
, LPSIZE lpSize
)
1226 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1227 TBUTTON_INFO
*btnPtr
;
1236 if (infoPtr
->nMaxTextRows
== 0)
1240 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1242 if (infoPtr
->nNumButtons
== 0 && infoPtr
->nNumStrings
> 0)
1246 GetTextMetricsW(hdc
, &tm
);
1247 lpSize
->cy
= tm
.tmHeight
;
1250 btnPtr
= infoPtr
->buttons
;
1251 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1252 if(TOOLBAR_HasText(infoPtr
, btnPtr
))
1254 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1255 if (sz
.cx
> lpSize
->cx
)
1257 if (sz
.cy
> lpSize
->cy
)
1262 SelectObject (hdc
, hOldFont
);
1263 ReleaseDC (hwnd
, hdc
);
1265 TRACE("max string size %d x %d!\n", lpSize
->cx
, lpSize
->cy
);
1268 /***********************************************************************
1269 * TOOLBAR_WrapToolbar
1271 * This function walks through the buttons and separators in the
1272 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1273 * wrapping should occur based on the width of the toolbar window.
1274 * It does *not* calculate button placement itself. That task
1275 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1276 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1277 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1279 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1280 * vertical toolbar lists.
1284 TOOLBAR_WrapToolbar( HWND hwnd
, DWORD dwStyle
)
1286 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1287 TBUTTON_INFO
*btnPtr
;
1292 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1293 /* no layout is necessary. Applications may use this style */
1294 /* to perform their own layout on the toolbar. */
1295 if( !(dwStyle
& TBSTYLE_WRAPABLE
) &&
1296 !(infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
) ) return;
1298 btnPtr
= infoPtr
->buttons
;
1299 x
= infoPtr
->nIndent
;
1301 if (GetParent(hwnd
))
1303 /* this can get the parents width, to know how far we can extend
1304 * this toolbar. We cannot use its height, as there may be multiple
1305 * toolbars in a rebar control
1307 GetClientRect( GetParent(hwnd
), &rc
);
1308 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1312 GetWindowRect( hwnd
, &rc
);
1313 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1316 bButtonWrap
= FALSE
;
1318 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1319 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, infoPtr
->nWidth
,
1322 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1324 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1326 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1329 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1330 /* it is the actual width of the separator. This is used for */
1331 /* custom controls in toolbars. */
1333 /* BTNS_DROPDOWN separators are treated as buttons for */
1334 /* width. - GA 8/01 */
1335 if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1336 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
))
1337 cx
= (btnPtr
[i
].iBitmap
> 0) ?
1338 btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1340 cx
= (btnPtr
[i
].cx
) ? btnPtr
[i
].cx
: infoPtr
->nButtonWidth
;
1342 /* Two or more adjacent separators form a separator group. */
1343 /* The first separator in a group should be wrapped to the */
1344 /* next row if the previous wrapping is on a button. */
1346 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1347 (i
+ 1 < infoPtr
->nNumButtons
) &&
1348 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1350 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1351 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1352 x
= infoPtr
->nIndent
;
1354 bButtonWrap
= FALSE
;
1358 /* The layout makes sure the bitmap is visible, but not the button. */
1359 /* Test added to also wrap after a button that starts a row but */
1360 /* is bigger than the area. - GA 8/01 */
1361 if (( x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2
1362 > infoPtr
->nWidth
) ||
1363 ((x
== infoPtr
->nIndent
) && (cx
> infoPtr
->nWidth
)))
1365 BOOL bFound
= FALSE
;
1367 /* If the current button is a separator and not hidden, */
1368 /* go to the next until it reaches a non separator. */
1369 /* Wrap the last separator if it is before a button. */
1370 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1371 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1372 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1373 i
< infoPtr
->nNumButtons
)
1379 if( bFound
&& i
< infoPtr
->nNumButtons
)
1382 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1383 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1384 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1385 x
= infoPtr
->nIndent
;
1386 bButtonWrap
= FALSE
;
1389 else if ( i
>= infoPtr
->nNumButtons
)
1392 /* If the current button is not a separator, find the last */
1393 /* separator and wrap it. */
1394 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1396 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1397 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1401 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1402 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1403 x
= infoPtr
->nIndent
;
1404 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1405 bButtonWrap
= FALSE
;
1410 /* If no separator available for wrapping, wrap one of */
1411 /* non-hidden previous button. */
1415 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1417 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1422 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1423 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1424 x
= infoPtr
->nIndent
;
1425 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1431 /* If all above failed, wrap the current button. */
1434 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1435 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1436 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1437 x
= infoPtr
->nIndent
;
1438 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1439 bButtonWrap
= FALSE
;
1445 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1446 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1453 /***********************************************************************
1454 * TOOLBAR_MeasureButton
1456 * Calculates the width and height required for a button. Used in
1457 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1458 * the width of buttons that are autosized.
1460 * Note that it would have been rather elegant to use one piece of code for
1461 * both the laying out of the toolbar and for controlling where button parts
1462 * are drawn, but the native control has inconsistencies between the two that
1463 * prevent this from being effectively. These inconsistencies can be seen as
1464 * artefacts where parts of the button appear outside of the bounding button
1467 * There are several cases for the calculation of the button dimensions and
1468 * button part positioning:
1475 * +--------------------------------------------------------+ ^
1477 * | | pad.cy / 2 | centred | |
1478 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1479 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1480 * | |<------------>| | | | |
1481 * | +--------------+ +------------+ | |
1482 * |<-------------------------------------->| | |
1483 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1485 * +--------------------------------------------------------+ -
1486 * <-------------------------------------------------------->
1487 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1489 * Without Bitmap (I_IMAGENONE):
1491 * +-----------------------------------+ ^
1493 * | | centred | | LISTPAD_CY +
1494 * | +------------+ | | szText.cy
1497 * | +------------+ | |
1498 * |<----------------->| | |
1499 * | cxedge |<-----------> | |
1501 * +-----------------------------------+ -
1502 * <----------------------------------->
1503 * szText.cx + pad.cx
1507 * +--------------------------------------+ ^
1509 * | | padding.cy/2 | | DEFPAD_CY +
1510 * | +------------+ | | nBitmapHeight
1513 * | +------------+ | |
1514 * |<------------------->| | |
1515 * | cxedge + iListGap/2 |<-----------> | |
1516 * | nBitmapWidth | |
1517 * +--------------------------------------+ -
1518 * <-------------------------------------->
1519 * 2*cxedge + nBitmapWidth + iListGap
1526 * +-----------------------------------+ ^
1528 * | | pad.cy / 2 | | nBitmapHeight +
1529 * | - | | szText.cy +
1530 * | +------------+ | | DEFPAD_CY + 1
1531 * | centred | Bitmap | | |
1532 * |<----------------->| | | |
1533 * | +------------+ | |
1537 * | centred +---------------+ | |
1538 * |<--------------->| Text | | |
1539 * | +---------------+ | |
1540 * +-----------------------------------+ -
1541 * <----------------------------------->
1542 * pad.cx + max(nBitmapWidth, szText.cx)
1544 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1546 * +---------------------------------------+ ^
1548 * | | 2 + pad.cy / 2 | |
1549 * | - | | szText.cy +
1550 * | centred +-----------------+ | | pad.cy + 2
1551 * |<--------------->| Text | | |
1552 * | +-----------------+ | |
1554 * +---------------------------------------+ -
1555 * <--------------------------------------->
1556 * 2*cxedge + pad.cx + szText.cx
1559 * As for with bitmaps, but with szText.cx zero.
1561 static inline SIZE
TOOLBAR_MeasureButton(const TOOLBAR_INFO
*infoPtr
, SIZE sizeString
,
1562 BOOL bHasBitmap
, BOOL bValidImageList
)
1565 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1567 /* set button height from bitmap / text height... */
1568 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1571 /* ... add on the necessary padding */
1572 if (bValidImageList
)
1575 sizeButton
.cy
+= DEFPAD_CY
;
1577 sizeButton
.cy
+= LISTPAD_CY
;
1580 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1582 /* calculate button width */
1583 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1584 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1585 if (sizeString
.cx
> 0)
1586 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1593 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ DEFPAD_CY
;
1594 if (sizeString
.cy
> 0)
1595 sizeButton
.cy
+= 1 + sizeString
.cy
;
1596 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1597 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1601 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1602 NONLIST_NOTEXT_OFFSET
;
1603 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1604 max(2*GetSystemMetrics(SM_CXEDGE
) + sizeString
.cx
, infoPtr
->nBitmapWidth
);
1611 /***********************************************************************
1612 * TOOLBAR_CalcToolbar
1614 * This function calculates button and separator placement. It first
1615 * calculates the button sizes, gets the toolbar window width and then
1616 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1617 * on. It assigns a new location to each item and sends this location to
1618 * the tooltip window if appropriate. Finally, it updates the rcBound
1619 * rect and calculates the new required toolbar window height.
1622 TOOLBAR_CalcToolbar (HWND hwnd
)
1624 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
1625 SIZE sizeString
, sizeButton
;
1626 BOOL validImageList
= FALSE
;
1628 TOOLBAR_CalcStrings (hwnd
, &sizeString
);
1630 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1632 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1633 validImageList
= TRUE
;
1634 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1635 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1636 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1637 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
1639 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1640 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1641 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1642 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1644 TOOLBAR_LayoutToolbar(hwnd
);
1648 TOOLBAR_LayoutToolbar(HWND hwnd
)
1650 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
1651 TBUTTON_INFO
*btnPtr
;
1653 INT i
, nRows
, nSepRows
;
1656 BOOL validImageList
= TOOLBAR_IsValidImageList(infoPtr
, 0);
1657 BOOL hasDropDownArrows
= TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
);
1659 TOOLBAR_WrapToolbar(hwnd
, infoPtr
->dwStyle
);
1661 x
= infoPtr
->nIndent
;
1662 y
= infoPtr
->iTopMargin
;
1663 cx
= infoPtr
->nButtonWidth
;
1664 cy
= infoPtr
->nButtonHeight
;
1666 nRows
= nSepRows
= 0;
1668 infoPtr
->rcBound
.top
= y
;
1669 infoPtr
->rcBound
.left
= x
;
1670 infoPtr
->rcBound
.bottom
= y
+ cy
;
1671 infoPtr
->rcBound
.right
= x
;
1673 btnPtr
= infoPtr
->buttons
;
1675 TRACE("cy=%d\n", cy
);
1677 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1680 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1682 SetRectEmpty (&btnPtr
->rect
);
1686 cy
= infoPtr
->nButtonHeight
;
1688 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1689 /* it is the actual width of the separator. This is used for */
1690 /* custom controls in toolbars. */
1691 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1692 if (btnPtr
->fsStyle
& BTNS_DROPDOWN
) {
1693 cy
= (btnPtr
->iBitmap
> 0) ?
1694 btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1695 cx
= infoPtr
->nButtonWidth
;
1698 cx
= (btnPtr
->iBitmap
> 0) ?
1699 btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1705 else if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1706 (btnPtr
->fsStyle
& BTNS_AUTOSIZE
))
1713 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1715 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1717 SelectObject (hdc
, hOldFont
);
1718 ReleaseDC (hwnd
, hdc
);
1720 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1721 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1726 cx
= infoPtr
->nButtonWidth
;
1728 /* if size has been set manually then don't add on extra space
1729 * for the drop down arrow */
1730 if (!btnPtr
->cx
&& hasDropDownArrows
&&
1731 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) || (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)))
1732 cx
+= DDARROW_WIDTH
;
1734 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1737 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1739 if (infoPtr
->rcBound
.left
> x
)
1740 infoPtr
->rcBound
.left
= x
;
1741 if (infoPtr
->rcBound
.right
< x
+ cx
)
1742 infoPtr
->rcBound
.right
= x
+ cx
;
1743 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1744 infoPtr
->rcBound
.bottom
= y
+ cy
;
1746 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1748 /* btnPtr->nRow is zero based. The space between the rows is */
1749 /* also considered as a row. */
1750 btnPtr
->nRow
= nRows
+ nSepRows
;
1752 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1753 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1758 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1762 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1763 /* it is the actual width of the separator. This is used for */
1764 /* custom controls in toolbars. */
1765 if ( !(btnPtr
->fsStyle
& BTNS_DROPDOWN
))
1766 y
+= cy
+ ( (btnPtr
->iBitmap
> 0 ) ?
1767 btnPtr
->iBitmap
: SEPARATOR_WIDTH
) * 2 /3;
1771 /* nSepRows is used to calculate the extra height following */
1775 x
= infoPtr
->nIndent
;
1777 /* Increment row number unless this is the last button */
1778 /* and it has Wrap set. */
1779 if (i
!= infoPtr
->nNumButtons
-1)
1786 /* infoPtr->nRows is the number of rows on the toolbar */
1787 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1789 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1794 TOOLBAR_InternalHitTest (HWND hwnd
, const POINT
*lpPt
)
1796 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1797 TBUTTON_INFO
*btnPtr
;
1800 btnPtr
= infoPtr
->buttons
;
1801 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1802 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1805 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1806 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1807 TRACE(" ON SEPARATOR %d!\n", i
);
1812 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1813 TRACE(" ON BUTTON %d!\n", i
);
1819 TRACE(" NOWHERE!\n");
1820 return TOOLBAR_NOWHERE
;
1824 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1826 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO
*infoPtr
, INT iIndex
, UINT nAddButtons
, TBBUTTON
*lpTbb
, BOOL fUnicode
)
1828 INT nOldButtons
, nNewButtons
, iButton
;
1829 BOOL fHasString
= FALSE
;
1831 if (iIndex
< 0) /* iIndex can be negative, what means adding at the end */
1832 iIndex
= infoPtr
->nNumButtons
;
1834 nOldButtons
= infoPtr
->nNumButtons
;
1835 nNewButtons
= nOldButtons
+ nAddButtons
;
1837 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
1838 memmove(&infoPtr
->buttons
[iIndex
+ nAddButtons
], &infoPtr
->buttons
[iIndex
],
1839 (nOldButtons
- iIndex
) * sizeof(TBUTTON_INFO
));
1840 infoPtr
->nNumButtons
+= nAddButtons
;
1842 /* insert new buttons data */
1843 for (iButton
= 0; iButton
< nAddButtons
; iButton
++) {
1844 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[iIndex
+ iButton
];
1846 TOOLBAR_DumpTBButton(lpTbb
, fUnicode
);
1848 ZeroMemory(btnPtr
, sizeof(*btnPtr
));
1849 btnPtr
->iBitmap
= lpTbb
[iButton
].iBitmap
;
1850 btnPtr
->idCommand
= lpTbb
[iButton
].idCommand
;
1851 btnPtr
->fsState
= lpTbb
[iButton
].fsState
;
1852 btnPtr
->fsStyle
= lpTbb
[iButton
].fsStyle
;
1853 btnPtr
->dwData
= lpTbb
[iButton
].dwData
;
1854 if(HIWORD(lpTbb
[iButton
].iString
) && lpTbb
[iButton
].iString
!= -1)
1857 Str_SetPtrW((LPWSTR
*)&btnPtr
->iString
, (LPWSTR
)lpTbb
[iButton
].iString
);
1859 Str_SetPtrAtoW((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lpTbb
[iButton
].iString
);
1863 btnPtr
->iString
= lpTbb
[iButton
].iString
;
1865 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
1868 if (infoPtr
->nNumStrings
> 0 || fHasString
)
1869 TOOLBAR_CalcToolbar(infoPtr
->hwndSelf
);
1871 TOOLBAR_LayoutToolbar(infoPtr
->hwndSelf
);
1872 TOOLBAR_AutoSize(infoPtr
->hwndSelf
);
1874 TOOLBAR_DumpToolbar(infoPtr
, __LINE__
);
1875 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1881 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1883 TBUTTON_INFO
*btnPtr
;
1886 if (CommandIsIndex
) {
1887 TRACE("command is really index command=%d\n", idCommand
);
1888 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1891 btnPtr
= infoPtr
->buttons
;
1892 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1893 if (btnPtr
->idCommand
== idCommand
) {
1894 TRACE("command=%d index=%d\n", idCommand
, i
);
1898 TRACE("no index found for command=%d\n", idCommand
);
1904 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1906 TBUTTON_INFO
*btnPtr
;
1909 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1912 /* check index button */
1913 btnPtr
= &infoPtr
->buttons
[nIndex
];
1914 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1915 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1919 /* check previous buttons */
1920 nRunIndex
= nIndex
- 1;
1921 while (nRunIndex
>= 0) {
1922 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1923 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1924 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1932 /* check next buttons */
1933 nRunIndex
= nIndex
+ 1;
1934 while (nRunIndex
< infoPtr
->nNumButtons
) {
1935 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1936 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1937 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1950 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1951 WPARAM wParam
, LPARAM lParam
)
1957 msg
.wParam
= wParam
;
1958 msg
.lParam
= lParam
;
1959 msg
.time
= GetMessageTime ();
1960 msg
.pt
.x
= (short)LOWORD(GetMessagePos ());
1961 msg
.pt
.y
= (short)HIWORD(GetMessagePos ());
1963 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1967 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1969 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
1972 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
1973 ti
.cbSize
= sizeof (TTTOOLINFOW
);
1974 ti
.hwnd
= infoPtr
->hwndSelf
;
1975 ti
.uId
= button
->idCommand
;
1977 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
1978 /* ti.lParam = random value from the stack? */
1980 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
1986 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
1988 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
1991 ZeroMemory(&ti
, sizeof(ti
));
1992 ti
.cbSize
= sizeof(ti
);
1993 ti
.hwnd
= infoPtr
->hwndSelf
;
1994 ti
.uId
= button
->idCommand
;
1996 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
2000 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO
*infoPtr
, const TBUTTON_INFO
*button
)
2002 /* Set the toolTip only for non-hidden, non-separator button */
2003 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
2007 ZeroMemory(&ti
, sizeof(ti
));
2008 ti
.cbSize
= sizeof(ti
);
2009 ti
.hwnd
= infoPtr
->hwndSelf
;
2010 ti
.uId
= button
->idCommand
;
2011 ti
.rect
= button
->rect
;
2012 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
2016 /* Creates the tooltip control */
2018 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
2021 NMTOOLTIPSCREATED nmttc
;
2023 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
2024 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2025 infoPtr
->hwndSelf
, 0, 0, 0);
2027 if (!infoPtr
->hwndToolTip
)
2030 /* Send NM_TOOLTIPSCREATED notification */
2031 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
2032 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
2034 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
2036 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
2037 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
2041 /* keeps available button list box sorted by button id */
2042 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
2046 PCUSTOMBUTTON btnInfo
;
2047 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2049 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
2051 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2053 /* position 0 is always separator */
2054 for (i
= 1; i
< count
; i
++)
2056 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
2057 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
2059 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
2060 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2064 /* id higher than all others add to end */
2065 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
2066 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
2069 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2073 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2075 if (nIndexFrom
== nIndexTo
)
2078 /* MSDN states that iItem is the index of the button, rather than the
2079 * command ID as used by every other NMTOOLBAR notification */
2080 nmtb
.iItem
= nIndexFrom
;
2081 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2083 PCUSTOMBUTTON btnInfo
;
2085 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2086 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2088 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2090 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2091 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2092 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2093 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2096 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2098 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2100 /* last item is always separator, so -2 instead of -1 */
2101 if (nIndexTo
>= (count
- 2))
2102 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2104 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2106 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2107 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2109 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2113 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2117 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2119 /* MSDN states that iItem is the index of the button, rather than the
2120 * command ID as used by every other NMTOOLBAR notification */
2121 nmtb
.iItem
= nIndexAvail
;
2122 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2124 PCUSTOMBUTTON btnInfo
;
2126 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2127 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2128 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2130 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2132 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2134 /* remove from 'available buttons' list */
2135 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2136 if (nIndexAvail
== count
-1)
2137 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2139 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2143 PCUSTOMBUTTON btnNew
;
2145 /* duplicate 'separator' button */
2146 btnNew
= Alloc(sizeof(CUSTOMBUTTON
));
2151 /* insert into 'toolbar button' list */
2152 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2153 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2155 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2157 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2161 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO
*custInfo
, HWND hwnd
, INT index
)
2163 PCUSTOMBUTTON btnInfo
;
2164 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2166 TRACE("Remove: index %d\n", index
);
2168 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2170 /* send TBN_QUERYDELETE notification */
2171 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2175 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2176 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2178 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2180 /* insert into 'available button' list */
2181 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2182 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2186 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2190 /* drag list notification function for toolbar buttons list box */
2191 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2192 const DRAGLISTINFO
*pDLI
)
2194 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2195 switch (pDLI
->uNotification
)
2199 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2200 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2201 /* no dragging for last item (separator) */
2202 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2207 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2208 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2209 /* no dragging past last item (separator) */
2210 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2212 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2213 /* FIXME: native uses "move button" cursor */
2214 return DL_COPYCURSOR
;
2217 /* not over toolbar buttons list */
2218 if (nCurrentItem
< 0)
2220 POINT ptWindow
= pDLI
->ptCursor
;
2221 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2222 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2223 /* over available buttons list? */
2224 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2225 /* FIXME: native uses "move button" cursor */
2226 return DL_COPYCURSOR
;
2228 /* clear drag arrow */
2229 DrawInsert(hwnd
, hwndList
, -1);
2230 return DL_STOPCURSOR
;
2234 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2235 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2236 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2237 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2239 /* clear drag arrow */
2240 DrawInsert(hwnd
, hwndList
, -1);
2242 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2244 /* not over toolbar buttons list */
2247 POINT ptWindow
= pDLI
->ptCursor
;
2248 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2249 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2250 /* over available buttons list? */
2251 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2252 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2257 /* Clear drag arrow */
2258 DrawInsert(hwnd
, hwndList
, -1);
2265 /* drag list notification function for available buttons list box */
2266 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO
*custInfo
, HWND hwnd
,
2267 const DRAGLISTINFO
*pDLI
)
2269 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2270 switch (pDLI
->uNotification
)
2276 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2277 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2278 /* no dragging past last item (separator) */
2279 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2281 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2282 /* FIXME: native uses "move button" cursor */
2283 return DL_COPYCURSOR
;
2286 /* not over toolbar buttons list */
2287 if (nCurrentItem
< 0)
2289 POINT ptWindow
= pDLI
->ptCursor
;
2290 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2291 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2292 /* over available buttons list? */
2293 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2294 /* FIXME: native uses "move button" cursor */
2295 return DL_COPYCURSOR
;
2297 /* clear drag arrow */
2298 DrawInsert(hwnd
, hwndList
, -1);
2299 return DL_STOPCURSOR
;
2303 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2304 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2305 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2306 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2308 /* clear drag arrow */
2309 DrawInsert(hwnd
, hwndList
, -1);
2311 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2315 /* Clear drag arrow */
2316 DrawInsert(hwnd
, hwndList
, -1);
2322 extern UINT uDragListMessage
;
2324 /***********************************************************************
2325 * TOOLBAR_CustomizeDialogProc
2326 * This function implements the toolbar customization dialog.
2328 static INT_PTR CALLBACK
2329 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2331 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2332 PCUSTOMBUTTON btnInfo
;
2334 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2339 custInfo
= (PCUSTDLG_INFO
)lParam
;
2340 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2347 NMTBINITCUSTOMIZE nmtbic
;
2349 infoPtr
= custInfo
->tbInfo
;
2351 /* send TBN_QUERYINSERT notification */
2352 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2354 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2357 nmtbic
.hwndDialog
= hwnd
;
2358 /* Send TBN_INITCUSTOMIZE notification */
2359 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2362 TRACE("TBNRF_HIDEHELP requested\n");
2363 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2366 /* add items to 'toolbar buttons' list and check if removable */
2367 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2369 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2370 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2371 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2372 btnInfo
->bVirtual
= FALSE
;
2373 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2375 /* send TBN_QUERYDELETE notification */
2376 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2378 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2379 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2382 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2384 /* insert separator button into 'available buttons' list */
2385 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2386 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2387 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2388 btnInfo
->bVirtual
= FALSE
;
2389 btnInfo
->bRemovable
= TRUE
;
2390 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2391 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2392 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2394 /* insert all buttons into dsa */
2397 /* send TBN_GETBUTTONINFO notification */
2400 nmtb
.pszText
= Buffer
;
2403 /* Clear previous button's text */
2404 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2406 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2409 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2410 nmtb
.tbButton
.fsStyle
, i
,
2411 nmtb
.tbButton
.idCommand
,
2412 nmtb
.tbButton
.iString
,
2413 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2416 /* insert button into the apropriate list */
2417 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2420 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2421 btnInfo
->bVirtual
= FALSE
;
2422 btnInfo
->bRemovable
= TRUE
;
2426 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2427 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2430 btnInfo
->btn
= nmtb
.tbButton
;
2431 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2433 if (lstrlenW(nmtb
.pszText
))
2434 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2435 else if (nmtb
.tbButton
.iString
>= 0 &&
2436 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2438 lstrcpyW(btnInfo
->text
,
2439 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2444 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2447 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2449 /* select first item in the 'available' list */
2450 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2452 /* append 'virtual' separator button to the 'toolbar buttons' list */
2453 btnInfo
= Alloc(sizeof(CUSTOMBUTTON
));
2454 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2455 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2456 btnInfo
->bVirtual
= TRUE
;
2457 btnInfo
->bRemovable
= FALSE
;
2458 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2459 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2460 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2462 /* select last item in the 'toolbar' list */
2463 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2464 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2466 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2467 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2469 /* set focus and disable buttons */
2470 PostMessageW (hwnd
, WM_USER
, 0, 0);
2475 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2476 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2477 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2478 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2482 EndDialog(hwnd
, FALSE
);
2486 switch (LOWORD(wParam
))
2488 case IDC_TOOLBARBTN_LBOX
:
2489 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2491 PCUSTOMBUTTON btnInfo
;
2496 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2497 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2499 /* send TBN_QUERYINSERT notification */
2501 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2503 /* get list box item */
2504 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2506 if (index
== (count
- 1))
2508 /* last item (virtual separator) */
2509 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2510 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2512 else if (index
== (count
- 2))
2514 /* second last item (last non-virtual item) */
2515 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2516 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2518 else if (index
== 0)
2521 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2522 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2526 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2527 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2530 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2534 case IDC_MOVEUP_BTN
:
2536 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2537 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2541 case IDC_MOVEDN_BTN
: /* move down */
2543 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2544 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2548 case IDC_REMOVE_BTN
: /* remove button */
2550 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2552 if (LB_ERR
== index
)
2555 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2559 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2562 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2565 case IDOK
: /* Add button */
2570 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2571 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2573 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2578 EndDialog(hwnd
, FALSE
);
2588 /* delete items from 'toolbar buttons' listbox*/
2589 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2590 for (i
= 0; i
< count
; i
++)
2592 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2594 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2596 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2599 /* delete items from 'available buttons' listbox*/
2600 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2601 for (i
= 0; i
< count
; i
++)
2603 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2605 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2607 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2612 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2614 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2619 COLORREF oldText
= 0;
2623 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, (WPARAM
)lpdis
->itemID
, 0);
2624 if (btnInfo
== NULL
)
2626 FIXME("btnInfo invalid!\n");
2630 /* set colors and select objects */
2631 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2632 if (btnInfo
->bVirtual
)
2633 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2635 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2636 hPen
= CreatePen( PS_SOLID
, 1,
2637 GetSysColor( (lpdis
->itemState
& ODS_SELECTED
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2638 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2639 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2641 /* fill background rectangle */
2642 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2643 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2645 /* calculate button and text rectangles */
2646 CopyRect (&rcButton
, &lpdis
->rcItem
);
2647 InflateRect (&rcButton
, -1, -1);
2648 CopyRect (&rcText
, &rcButton
);
2649 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2650 rcText
.left
= rcButton
.right
+ 2;
2652 /* draw focus rectangle */
2653 if (lpdis
->itemState
& ODS_FOCUS
)
2654 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2657 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2658 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2660 /* draw image and text */
2661 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2662 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2663 btnInfo
->btn
.iBitmap
));
2664 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2665 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2667 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2668 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2670 /* delete objects and reset colors */
2671 SelectObject (lpdis
->hDC
, hOldBrush
);
2672 SelectObject (lpdis
->hDC
, hOldPen
);
2673 SetBkColor (lpdis
->hDC
, oldBk
);
2674 SetTextColor (lpdis
->hDC
, oldText
);
2675 DeleteObject( hPen
);
2680 case WM_MEASUREITEM
:
2681 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2683 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2685 lpmis
->itemHeight
= 15 + 8; /* default height */
2692 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2694 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2696 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2697 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2698 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2701 else if (wParam
== IDC_AVAILBTN_LBOX
)
2703 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2704 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2705 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2714 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2717 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2723 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2724 /* Add bitmaps to the default image list */
2725 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2726 hbmLoad
= CopyImage(ULongToHandle(bitmap
->nID
), IMAGE_BITMAP
, 0, 0, 0);
2728 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2730 /* enlarge the bitmap if needed */
2731 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2732 if (bitmap
->hInst
!= COMCTL32_hModule
)
2733 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2735 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2736 DeleteObject(hbmLoad
);
2740 nCountAfter
= ImageList_GetImageCount(himlDef
);
2741 nAdded
= nCountAfter
- nCountBefore
;
2742 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2744 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2745 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2746 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2747 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2750 infoPtr
->nNumBitmaps
+= nAdded
;
2755 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2762 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2763 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2765 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2767 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2770 TRACE("Update icon size: %dx%d -> %dx%d\n",
2771 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2773 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2774 ILC_COLORDDB
|ILC_MASK
, 8, 2);
2775 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2776 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2777 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2778 infoPtr
->himlInt
= himlNew
;
2780 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2781 ImageList_Destroy(himlDef
);
2784 /***********************************************************************
2785 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2789 TOOLBAR_AddBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2791 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2792 LPTBADDBITMAP lpAddBmp
= (LPTBADDBITMAP
)lParam
;
2797 TRACE("hwnd=%p wParam=%lx lParam=%lx\n", hwnd
, wParam
, lParam
);
2801 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2803 info
.hInst
= COMCTL32_hModule
;
2804 switch (lpAddBmp
->nID
)
2806 case IDB_STD_SMALL_COLOR
:
2808 info
.nID
= IDB_STD_SMALL
;
2810 case IDB_STD_LARGE_COLOR
:
2812 info
.nID
= IDB_STD_LARGE
;
2814 case IDB_VIEW_SMALL_COLOR
:
2816 info
.nID
= IDB_VIEW_SMALL
;
2818 case IDB_VIEW_LARGE_COLOR
:
2820 info
.nID
= IDB_VIEW_LARGE
;
2822 case IDB_HIST_SMALL_COLOR
:
2824 info
.nID
= IDB_HIST_SMALL
;
2826 case IDB_HIST_LARGE_COLOR
:
2828 info
.nID
= IDB_HIST_LARGE
;
2834 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2836 /* Windows resize all the buttons to the size of a newly added standard image */
2837 if (lpAddBmp
->nID
& 1)
2839 /* large icons: 24x24. Will make the button 31x30 */
2840 SendMessageW (hwnd
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(24, 24));
2844 /* small icons: 16x16. Will make the buttons 23x22 */
2845 SendMessageW (hwnd
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(16, 16));
2848 TOOLBAR_CalcToolbar (hwnd
);
2852 info
.nButtons
= (INT
)wParam
;
2853 info
.hInst
= lpAddBmp
->hInst
;
2854 info
.nID
= lpAddBmp
->nID
;
2855 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2858 /* check if the bitmap is already loaded and compute iSumButtons */
2860 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2862 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2863 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2865 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2868 if (!infoPtr
->cimlDef
) {
2869 /* create new default image list */
2870 TRACE ("creating default image list!\n");
2872 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2873 ILC_COLORDDB
| ILC_MASK
, info
.nButtons
, 2);
2874 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2875 infoPtr
->himlInt
= himlDef
;
2878 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2882 WARN("No default image list available\n");
2886 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2889 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2890 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2891 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2892 infoPtr
->nNumBitmapInfos
++;
2893 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2895 InvalidateRect(hwnd
, NULL
, TRUE
);
2901 TOOLBAR_AddButtonsT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL fUnicode
)
2903 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2904 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
2905 INT nAddButtons
= (UINT
)wParam
;
2907 TRACE("adding %ld buttons (unicode=%d)!\n", wParam
, fUnicode
);
2909 return TOOLBAR_InternalInsertButtonsT(infoPtr
, -1, nAddButtons
, lpTbb
, fUnicode
);
2914 TOOLBAR_AddStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2916 #define MAX_RESOURCE_STRING_LENGTH 512
2917 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2918 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2919 INT nIndex
= infoPtr
->nNumStrings
;
2921 if ((wParam
) && (HIWORD(lParam
) == 0)) {
2922 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2927 TRACE("adding string from resource!\n");
2929 len
= LoadStringW ((HINSTANCE
)wParam
, (UINT
)lParam
,
2930 szString
, MAX_RESOURCE_STRING_LENGTH
);
2932 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2933 if (len
== 0 || len
== 1)
2936 TRACE("Delimiter: 0x%x\n", *szString
);
2937 delimiter
= *szString
;
2940 while ((next_delim
= strchrW(p
, delimiter
)) != NULL
) {
2942 if (next_delim
+ 1 >= szString
+ len
)
2944 /* this may happen if delimiter == '\0' or if the last char is a
2945 * delimiter (then it is ignored like the native does) */
2949 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2950 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2951 infoPtr
->nNumStrings
++;
2957 LPWSTR p
= (LPWSTR
)lParam
;
2962 TRACE("adding string(s) from array!\n");
2966 TRACE("len=%d %s\n", len
, debugstr_w(p
));
2967 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2968 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2969 infoPtr
->nNumStrings
++;
2976 TOOLBAR_CalcToolbar(hwnd
);
2982 TOOLBAR_AddStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2984 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2985 BOOL fFirstString
= (infoPtr
->nNumStrings
== 0);
2990 if ((wParam
) && (HIWORD(lParam
) == 0)) /* load from resources */
2991 return TOOLBAR_AddStringW(hwnd
, wParam
, lParam
);
2997 TRACE("adding string(s) from array!\n");
2998 nIndex
= infoPtr
->nNumStrings
;
3001 TRACE("len=%d \"%s\"\n", len
, p
);
3003 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
3004 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3005 infoPtr
->nNumStrings
++;
3011 TOOLBAR_CalcToolbar(hwnd
);
3017 TOOLBAR_AutoSize (HWND hwnd
)
3019 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3025 TRACE("auto sizing, style=%x!\n", infoPtr
->dwStyle
);
3027 parent
= GetParent (hwnd
);
3029 if (!parent
|| !infoPtr
->bDoRedraw
)
3032 GetClientRect(parent
, &parent_rect
);
3034 x
= parent_rect
.left
;
3035 y
= parent_rect
.top
;
3037 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3039 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3040 cx
= parent_rect
.right
- parent_rect
.left
;
3042 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
))
3044 TOOLBAR_LayoutToolbar(hwnd
);
3045 InvalidateRect( hwnd
, NULL
, TRUE
);
3048 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3051 UINT uPosFlags
= SWP_NOZORDER
;
3053 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3055 GetWindowRect(hwnd
, &window_rect
);
3056 ScreenToClient(parent
, (LPPOINT
)&window_rect
.left
);
3057 y
= window_rect
.top
;
3059 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3061 GetWindowRect(hwnd
, &window_rect
);
3062 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3065 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3066 uPosFlags
|= SWP_NOMOVE
;
3068 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3069 cy
+= GetSystemMetrics(SM_CYEDGE
);
3071 if (infoPtr
->dwStyle
& WS_BORDER
)
3073 x
= y
= 1; /* FIXME: this looks wrong */
3074 cy
+= GetSystemMetrics(SM_CYEDGE
);
3075 cx
+= GetSystemMetrics(SM_CXEDGE
);
3078 SetWindowPos(hwnd
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3086 TOOLBAR_ButtonCount (HWND hwnd
)
3088 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3090 return infoPtr
->nNumButtons
;
3095 TOOLBAR_ButtonStructSize (HWND hwnd
, WPARAM wParam
)
3097 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3099 infoPtr
->dwStructSize
= (DWORD
)wParam
;
3106 TOOLBAR_ChangeBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3108 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3109 TBUTTON_INFO
*btnPtr
;
3112 TRACE("button %ld, iBitmap now %d\n", wParam
, LOWORD(lParam
));
3114 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3118 btnPtr
= &infoPtr
->buttons
[nIndex
];
3119 btnPtr
->iBitmap
= LOWORD(lParam
);
3121 /* we HAVE to erase the background, the new bitmap could be */
3123 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3130 TOOLBAR_CheckButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3132 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3133 TBUTTON_INFO
*btnPtr
;
3136 BOOL bChecked
= FALSE
;
3138 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3140 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd
, nIndex
, lParam
);
3145 btnPtr
= &infoPtr
->buttons
[nIndex
];
3147 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? TRUE
: FALSE
;
3149 if (LOWORD(lParam
) == FALSE
)
3150 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3152 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3154 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3155 if (nOldIndex
== nIndex
)
3157 if (nOldIndex
!= -1)
3158 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3160 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3163 if( bChecked
!= LOWORD(lParam
) )
3165 if (nOldIndex
!= -1)
3166 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3167 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3170 /* FIXME: Send a WM_NOTIFY?? */
3177 TOOLBAR_CommandToIndex (HWND hwnd
, WPARAM wParam
)
3179 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3181 return TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3186 TOOLBAR_Customize (HWND hwnd
)
3188 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3189 CUSTDLG_INFO custInfo
;
3195 custInfo
.tbInfo
= infoPtr
;
3196 custInfo
.tbHwnd
= hwnd
;
3198 /* send TBN_BEGINADJUST notification */
3199 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3201 if (!(hRes
= FindResourceW (COMCTL32_hModule
,
3202 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3203 (LPWSTR
)RT_DIALOG
)))
3206 if(!(template = LoadResource (COMCTL32_hModule
, hRes
)))
3209 ret
= DialogBoxIndirectParamW ((HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
),
3210 template, hwnd
, TOOLBAR_CustomizeDialogProc
,
3213 /* send TBN_ENDADJUST notification */
3214 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3221 TOOLBAR_DeleteButton (HWND hwnd
, WPARAM wParam
)
3223 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3224 INT nIndex
= (INT
)wParam
;
3226 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3228 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3231 memset(&nmtb
, 0, sizeof(nmtb
));
3232 nmtb
.iItem
= btnPtr
->idCommand
;
3233 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3234 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3235 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3236 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3237 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3238 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3239 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3241 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3243 if (infoPtr
->nNumButtons
== 1) {
3244 TRACE(" simple delete!\n");
3245 Free (infoPtr
->buttons
);
3246 infoPtr
->buttons
= NULL
;
3247 infoPtr
->nNumButtons
= 0;
3250 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3251 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3253 infoPtr
->nNumButtons
--;
3254 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3256 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3257 nIndex
* sizeof(TBUTTON_INFO
));
3260 if (nIndex
< infoPtr
->nNumButtons
) {
3261 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3262 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3268 TOOLBAR_LayoutToolbar(hwnd
);
3270 InvalidateRect (hwnd
, NULL
, TRUE
);
3277 TOOLBAR_EnableButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3279 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3280 TBUTTON_INFO
*btnPtr
;
3284 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3286 TRACE("hwnd=%p, btn index=%ld, lParam=0x%08lx\n", hwnd
, wParam
, lParam
);
3291 btnPtr
= &infoPtr
->buttons
[nIndex
];
3293 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3295 /* update the toolbar button state */
3296 if(LOWORD(lParam
) == FALSE
) {
3297 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3299 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3302 /* redraw the button only if the state of the button changed */
3303 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3304 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3310 static inline LRESULT
3311 TOOLBAR_GetAnchorHighlight (HWND hwnd
)
3313 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3315 return infoPtr
->bAnchor
;
3320 TOOLBAR_GetBitmap (HWND hwnd
, WPARAM wParam
)
3322 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3325 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3329 return infoPtr
->buttons
[nIndex
].iBitmap
;
3333 static inline LRESULT
3334 TOOLBAR_GetBitmapFlags (void)
3336 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3341 TOOLBAR_GetButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3343 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3344 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3345 INT nIndex
= (INT
)wParam
;
3346 TBUTTON_INFO
*btnPtr
;
3351 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3354 btnPtr
= &infoPtr
->buttons
[nIndex
];
3355 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3356 lpTbb
->idCommand
= btnPtr
->idCommand
;
3357 lpTbb
->fsState
= btnPtr
->fsState
;
3358 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3359 lpTbb
->bReserved
[0] = 0;
3360 lpTbb
->bReserved
[1] = 0;
3361 lpTbb
->dwData
= btnPtr
->dwData
;
3362 lpTbb
->iString
= btnPtr
->iString
;
3369 TOOLBAR_GetButtonInfoT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL bUnicode
)
3371 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3372 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3373 LPTBBUTTONINFOW lpTbInfo
= (LPTBBUTTONINFOW
)lParam
;
3374 TBUTTON_INFO
*btnPtr
;
3377 if (lpTbInfo
== NULL
)
3380 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3381 * the headers and tests shows that even with comctl 6 Vista accepts only the
3382 * original TBBUTTONINFO size
3384 if (lpTbInfo
->cbSize
!= sizeof(TBBUTTONINFOW
))
3386 WARN("Invalid button size\n");
3390 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
3391 lpTbInfo
->dwMask
& 0x80000000);
3395 if (!(btnPtr
= &infoPtr
->buttons
[nIndex
])) return -1;
3397 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3398 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3399 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3400 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3401 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3402 lpTbInfo
->lParam
= btnPtr
->dwData
;
3403 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3404 lpTbInfo
->cx
= (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3405 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3406 lpTbInfo
->fsState
= btnPtr
->fsState
;
3407 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3408 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3409 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3410 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3411 can't use TOOLBAR_GetText here */
3412 if (HIWORD(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3413 LPWSTR lpText
= (LPWSTR
)btnPtr
->iString
;
3415 Str_GetPtrW(lpText
, lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3417 Str_GetPtrWtoA(lpText
, (LPSTR
)lpTbInfo
->pszText
, lpTbInfo
->cchText
);
3419 lpTbInfo
->pszText
[0] = '\0';
3426 TOOLBAR_GetButtonSize (HWND hwnd
)
3428 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3430 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3431 (WORD
)infoPtr
->nButtonHeight
);
3436 TOOLBAR_GetButtonTextA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3438 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3445 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3449 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3451 return WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3452 (LPSTR
)lParam
, 0x7fffffff, NULL
, NULL
) - 1;
3457 TOOLBAR_GetButtonTextW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3459 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3464 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3468 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3472 ret
= strlenW (lpText
);
3475 strcpyW ((LPWSTR
)lParam
, lpText
);
3483 TOOLBAR_GetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3485 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3486 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3487 return (LRESULT
)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3491 static inline LRESULT
3492 TOOLBAR_GetExtendedStyle (HWND hwnd
)
3494 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3498 return infoPtr
->dwExStyle
;
3503 TOOLBAR_GetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3505 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3506 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3507 return (LRESULT
)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3512 TOOLBAR_GetHotItem (HWND hwnd
)
3514 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3516 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3519 if (infoPtr
->nHotItem
< 0)
3522 return (LRESULT
)infoPtr
->nHotItem
;
3527 TOOLBAR_GetDefImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3529 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3530 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3531 return (LRESULT
) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd
), wParam
);
3536 TOOLBAR_GetInsertMark (HWND hwnd
, LPARAM lParam
)
3538 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3539 TBINSERTMARK
*lptbim
= (TBINSERTMARK
*)lParam
;
3541 TRACE("hwnd = %p, lptbim = %p\n", hwnd
, lptbim
);
3543 *lptbim
= infoPtr
->tbim
;
3550 TOOLBAR_GetInsertMarkColor (HWND hwnd
)
3552 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3554 TRACE("hwnd = %p\n", hwnd
);
3556 return (LRESULT
)infoPtr
->clrInsertMark
;
3561 TOOLBAR_GetItemRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3563 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3564 TBUTTON_INFO
*btnPtr
;
3568 nIndex
= (INT
)wParam
;
3569 btnPtr
= &infoPtr
->buttons
[nIndex
];
3570 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3572 lpRect
= (LPRECT
)lParam
;
3575 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3578 lpRect
->left
= btnPtr
->rect
.left
;
3579 lpRect
->right
= btnPtr
->rect
.right
;
3580 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3581 lpRect
->top
= btnPtr
->rect
.top
;
3588 TOOLBAR_GetMaxSize (HWND hwnd
, LPARAM lParam
)
3590 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3591 LPSIZE lpSize
= (LPSIZE
)lParam
;
3596 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3597 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3599 TRACE("maximum size %d x %d\n",
3600 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3601 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3607 /* << TOOLBAR_GetObject >> */
3611 TOOLBAR_GetPadding (HWND hwnd
)
3613 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3616 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3617 return (LRESULT
) oldPad
;
3622 TOOLBAR_GetRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3624 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3625 TBUTTON_INFO
*btnPtr
;
3629 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3630 btnPtr
= &infoPtr
->buttons
[nIndex
];
3631 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3633 lpRect
= (LPRECT
)lParam
;
3637 lpRect
->left
= btnPtr
->rect
.left
;
3638 lpRect
->right
= btnPtr
->rect
.right
;
3639 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3640 lpRect
->top
= btnPtr
->rect
.top
;
3647 TOOLBAR_GetRows (HWND hwnd
)
3649 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3651 return infoPtr
->nRows
;
3656 TOOLBAR_GetState (HWND hwnd
, WPARAM wParam
)
3658 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3661 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3665 return infoPtr
->buttons
[nIndex
].fsState
;
3670 TOOLBAR_GetStyle (HWND hwnd
)
3672 return GetWindowLongW(hwnd
, GWL_STYLE
);
3677 TOOLBAR_GetTextRows (HWND hwnd
)
3679 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3681 return infoPtr
->nMaxTextRows
;
3686 TOOLBAR_GetToolTips (HWND hwnd
)
3688 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3690 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
3691 TOOLBAR_TooltipCreateControl(infoPtr
);
3692 return (LRESULT
)infoPtr
->hwndToolTip
;
3697 TOOLBAR_GetUnicodeFormat (HWND hwnd
)
3699 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3701 TRACE("%s hwnd=%p\n",
3702 infoPtr
->bUnicode
? "TRUE" : "FALSE", hwnd
);
3704 return infoPtr
->bUnicode
;
3708 static inline LRESULT
3709 TOOLBAR_GetVersion (HWND hwnd
)
3711 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3712 return infoPtr
->iVersion
;
3717 TOOLBAR_HideButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3719 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3720 TBUTTON_INFO
*btnPtr
;
3725 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3729 btnPtr
= &infoPtr
->buttons
[nIndex
];
3730 if (LOWORD(lParam
) == FALSE
)
3731 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3733 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3735 TOOLBAR_LayoutToolbar (hwnd
);
3737 InvalidateRect (hwnd
, NULL
, TRUE
);
3743 static inline LRESULT
3744 TOOLBAR_HitTest (HWND hwnd
, LPARAM lParam
)
3746 return TOOLBAR_InternalHitTest (hwnd
, (LPPOINT
)lParam
);
3751 TOOLBAR_Indeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3753 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3754 TBUTTON_INFO
*btnPtr
;
3758 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3762 btnPtr
= &infoPtr
->buttons
[nIndex
];
3763 oldState
= btnPtr
->fsState
;
3764 if (LOWORD(lParam
) == FALSE
)
3765 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3767 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3769 if(oldState
!= btnPtr
->fsState
)
3770 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3777 TOOLBAR_InsertButtonT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL fUnicode
)
3779 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3780 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3781 INT nIndex
= (INT
)wParam
;
3787 /* EPP: this seems to be an undocumented call (from my IE4)
3788 * I assume in that case that:
3789 * - index of insertion is at the end of existing buttons
3790 * I only see this happen with nIndex == -1, but it could have a special
3791 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3793 nIndex
= infoPtr
->nNumButtons
;
3795 } else if (nIndex
< 0)
3798 TRACE("inserting button index=%d\n", nIndex
);
3799 if (nIndex
> infoPtr
->nNumButtons
) {
3800 nIndex
= infoPtr
->nNumButtons
;
3801 TRACE("adjust index=%d\n", nIndex
);
3804 return TOOLBAR_InternalInsertButtonsT(infoPtr
, nIndex
, 1, lpTbb
, fUnicode
);
3807 /* << TOOLBAR_InsertMarkHitTest >> */
3811 TOOLBAR_IsButtonChecked (HWND hwnd
, WPARAM wParam
)
3813 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3816 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3820 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3825 TOOLBAR_IsButtonEnabled (HWND hwnd
, WPARAM wParam
)
3827 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3830 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3834 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3839 TOOLBAR_IsButtonHidden (HWND hwnd
, WPARAM wParam
)
3841 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3844 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3848 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3853 TOOLBAR_IsButtonHighlighted (HWND hwnd
, WPARAM wParam
)
3855 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3858 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3862 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3867 TOOLBAR_IsButtonIndeterminate (HWND hwnd
, WPARAM wParam
)
3869 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3872 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3876 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3881 TOOLBAR_IsButtonPressed (HWND hwnd
, WPARAM wParam
)
3883 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3886 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3890 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3895 TOOLBAR_LoadImages (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3898 tbab
.hInst
= (HINSTANCE
)lParam
;
3901 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", hwnd
, tbab
.hInst
, tbab
.nID
);
3903 return TOOLBAR_AddBitmap(hwnd
, 0, (LPARAM
)&tbab
);
3908 TOOLBAR_MapAccelerator (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3910 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3911 WCHAR wAccel
= (WCHAR
)wParam
;
3912 UINT
* pIDButton
= (UINT
*)lParam
;
3913 WCHAR wszAccel
[] = {'&',wAccel
,0};
3916 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3917 hwnd
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3919 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3921 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3922 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3923 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3925 int iLen
= strlenW(wszAccel
);
3926 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3933 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3938 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
3940 *pIDButton
= btnPtr
->idCommand
;
3952 TOOLBAR_MarkButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3954 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3957 TBUTTON_INFO
*btnPtr
;
3959 TRACE("hwnd = %p, wParam = %ld, lParam = 0x%08lx\n", hwnd
, wParam
, lParam
);
3961 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3965 btnPtr
= &infoPtr
->buttons
[nIndex
];
3966 oldState
= btnPtr
->fsState
;
3969 btnPtr
->fsState
|= TBSTATE_MARKED
;
3971 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
3973 if(oldState
!= btnPtr
->fsState
)
3974 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3980 /* fixes up an index of a button affected by a move */
3981 static inline void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
3985 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
3987 else if (*pIndex
== nIndex
)
3988 *pIndex
= nMoveIndex
;
3992 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
3994 else if (*pIndex
== nIndex
)
3995 *pIndex
= nMoveIndex
;
4001 TOOLBAR_MoveButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4003 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4006 INT nMoveIndex
= (INT
)lParam
;
4007 TBUTTON_INFO button
;
4009 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd
, wParam
, lParam
);
4011 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, TRUE
);
4012 if ((nIndex
== -1) || (nMoveIndex
< 0))
4015 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
4016 nMoveIndex
= infoPtr
->nNumButtons
- 1;
4018 button
= infoPtr
->buttons
[nIndex
];
4020 /* move button right */
4021 if (nIndex
< nMoveIndex
)
4023 nCount
= nMoveIndex
- nIndex
;
4024 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
4025 infoPtr
->buttons
[nMoveIndex
] = button
;
4027 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
4028 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
4029 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
4030 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
4032 else if (nIndex
> nMoveIndex
) /* move button left */
4034 nCount
= nIndex
- nMoveIndex
;
4035 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
4036 infoPtr
->buttons
[nMoveIndex
] = button
;
4038 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
4039 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
4040 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
4041 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
4044 TOOLBAR_LayoutToolbar(hwnd
);
4045 TOOLBAR_AutoSize(hwnd
);
4046 InvalidateRect(hwnd
, NULL
, TRUE
);
4053 TOOLBAR_PressButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4055 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4056 TBUTTON_INFO
*btnPtr
;
4060 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4064 btnPtr
= &infoPtr
->buttons
[nIndex
];
4065 oldState
= btnPtr
->fsState
;
4066 if (LOWORD(lParam
) == FALSE
)
4067 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
4069 btnPtr
->fsState
|= TBSTATE_PRESSED
;
4071 if(oldState
!= btnPtr
->fsState
)
4072 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4077 /* FIXME: there might still be some confusion her between number of buttons
4078 * and number of bitmaps */
4080 TOOLBAR_ReplaceBitmap (HWND hwnd
, LPARAM lParam
)
4082 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4083 LPTBREPLACEBITMAP lpReplace
= (LPTBREPLACEBITMAP
) lParam
;
4085 int i
= 0, nOldButtons
= 0, pos
= 0;
4086 int nOldBitmaps
, nNewBitmaps
= 0;
4087 HIMAGELIST himlDef
= 0;
4089 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4090 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
4091 lpReplace
->nButtons
);
4093 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4095 FIXME("changing standard bitmaps not implemented\n");
4098 else if (lpReplace
->hInstOld
!= 0)
4099 FIXME("resources not in the current module not implemented\n");
4101 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4102 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4103 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4104 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4105 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4107 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4108 nOldButtons
= tbi
->nButtons
;
4109 tbi
->nButtons
= lpReplace
->nButtons
;
4110 tbi
->hInst
= lpReplace
->hInstNew
;
4111 tbi
->nID
= lpReplace
->nIDNew
;
4112 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4115 pos
+= tbi
->nButtons
;
4118 if (nOldButtons
== 0)
4120 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4124 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4127 if (lpReplace
->hInstNew
)
4128 hBitmap
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4130 hBitmap
= CopyImage((HBITMAP
)lpReplace
->nIDNew
, IMAGE_BITMAP
, 0, 0, 0);
4132 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4133 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4135 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4137 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4138 ImageList_Remove(himlDef
, i
);
4142 ImageList_AddMasked (himlDef
, hBitmap
, comctl32_color
.clrBtnFace
);
4143 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4144 DeleteObject(hBitmap
);
4147 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4149 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4150 pos
, nOldBitmaps
, nNewBitmaps
);
4152 InvalidateRect(hwnd
, NULL
, TRUE
);
4157 /* helper for TOOLBAR_SaveRestoreW */
4159 TOOLBAR_Save(const TBSAVEPARAMSW
*lpSave
)
4161 FIXME("save to %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4162 debugstr_w(lpSave
->pszValueName
));
4168 /* helper for TOOLBAR_Restore */
4170 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4174 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4176 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4179 Free(infoPtr
->buttons
);
4180 infoPtr
->buttons
= NULL
;
4181 infoPtr
->nNumButtons
= 0;
4185 /* helper for TOOLBAR_SaveRestoreW */
4187 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, const TBSAVEPARAMSW
*lpSave
)
4196 /* restore toolbar information */
4197 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4198 debugstr_w(lpSave
->pszValueName
));
4200 memset(&nmtbr
, 0, sizeof(nmtbr
));
4202 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4203 KEY_QUERY_VALUE
, &hkey
);
4205 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4207 if (!res
&& dwType
!= REG_BINARY
)
4208 res
= ERROR_FILE_NOT_FOUND
;
4211 nmtbr
.pData
= Alloc(dwSize
);
4212 nmtbr
.cbData
= dwSize
;
4213 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4216 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4217 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4220 nmtbr
.pCurrent
= nmtbr
.pData
;
4222 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4223 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4225 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4229 /* remove all existing buttons as this function is designed to
4230 * restore the toolbar to a previously saved state */
4231 TOOLBAR_DeleteAllButtons(infoPtr
);
4233 for (i
= 0; i
< nmtbr
.cButtons
; i
++)
4236 nmtbr
.tbButton
.iBitmap
= -1;
4237 nmtbr
.tbButton
.fsState
= 0;
4238 nmtbr
.tbButton
.fsStyle
= 0;
4239 nmtbr
.tbButton
.idCommand
= 0;
4240 if (*nmtbr
.pCurrent
== (DWORD
)-1)
4243 nmtbr
.tbButton
.fsStyle
= TBSTYLE_SEP
;
4244 nmtbr
.tbButton
.iBitmap
= SEPARATOR_WIDTH
;
4246 else if (*nmtbr
.pCurrent
== (DWORD
)-2)
4248 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4250 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4254 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4256 /* can't contain real string as we don't know whether
4257 * the client put an ANSI or Unicode string in there */
4258 if (HIWORD(nmtbr
.tbButton
.iString
))
4259 nmtbr
.tbButton
.iString
= 0;
4261 TOOLBAR_InsertButtonT(infoPtr
->hwndSelf
, -1,
4262 (LPARAM
)&nmtbr
.tbButton
, TRUE
);
4265 /* do legacy notifications */
4266 if (infoPtr
->iVersion
< 5)
4268 /* FIXME: send TBN_BEGINADJUST */
4269 FIXME("send TBN_GETBUTTONINFO for each button\n");
4270 /* FIXME: send TBN_ENDADJUST */
4273 /* remove all uninitialised buttons
4274 * note: loop backwards to avoid having to fixup i on a
4276 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4277 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4278 TOOLBAR_DeleteButton(infoPtr
->hwndSelf
, i
);
4280 /* only indicate success if at least one button survived */
4281 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4292 TOOLBAR_SaveRestoreW (HWND hwnd
, WPARAM wParam
, const TBSAVEPARAMSW
*lpSave
)
4294 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4296 if (lpSave
== NULL
) return 0;
4299 return TOOLBAR_Save(lpSave
);
4301 return TOOLBAR_Restore(infoPtr
, lpSave
);
4306 TOOLBAR_SaveRestoreA (HWND hwnd
, WPARAM wParam
, const TBSAVEPARAMSA
*lpSave
)
4308 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4309 TBSAVEPARAMSW SaveW
;
4313 if (lpSave
== NULL
) return 0;
4315 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4316 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4317 if (pszSubKey
) goto exit
;
4318 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4320 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4321 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4322 if (!pszValueName
) goto exit
;
4323 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4325 SaveW
.pszValueName
= pszValueName
;
4326 SaveW
.pszSubKey
= pszSubKey
;
4327 SaveW
.hkr
= lpSave
->hkr
;
4328 result
= TOOLBAR_SaveRestoreW(hwnd
, wParam
, &SaveW
);
4331 Free (pszValueName
);
4339 TOOLBAR_SetAnchorHighlight (HWND hwnd
, WPARAM wParam
)
4341 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4342 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4344 TRACE("hwnd=%p, bAnchor = %s\n", hwnd
, wParam
? "TRUE" : "FALSE");
4346 infoPtr
->bAnchor
= (BOOL
)wParam
;
4348 /* Native does not remove the hot effect from an already hot button */
4350 return (LRESULT
)bOldAnchor
;
4355 TOOLBAR_SetBitmapSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4357 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4358 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4359 short width
= (short)LOWORD(lParam
);
4360 short height
= (short)HIWORD(lParam
);
4362 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd
, wParam
, lParam
);
4365 FIXME("wParam is %ld. Perhaps image list index?\n", wParam
);
4367 /* 0 width or height is changed to 1 */
4373 if (infoPtr
->nNumButtons
> 0)
4374 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4375 infoPtr
->nNumButtons
,
4376 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
, width
, height
);
4378 if (width
< -1 || height
< -1)
4380 /* Windows destroys the imagelist and seems to actually use negative
4381 * values to compute button sizes */
4382 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width
, height
);
4386 /* width or height of -1 means no change */
4388 infoPtr
->nBitmapWidth
= width
;
4390 infoPtr
->nBitmapHeight
= height
;
4392 if ((himlDef
== infoPtr
->himlInt
) &&
4393 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4395 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4396 infoPtr
->nBitmapHeight
);
4399 TOOLBAR_CalcToolbar(hwnd
);
4400 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4406 TOOLBAR_SetButtonInfoA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4408 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4409 LPTBBUTTONINFOA lptbbi
= (LPTBBUTTONINFOA
)lParam
;
4410 TBUTTON_INFO
*btnPtr
;
4416 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOA
))
4419 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4420 lptbbi
->dwMask
& 0x80000000);
4424 btnPtr
= &infoPtr
->buttons
[nIndex
];
4425 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4426 btnPtr
->idCommand
= lptbbi
->idCommand
;
4427 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4428 btnPtr
->iBitmap
= lptbbi
->iImage
;
4429 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4430 btnPtr
->dwData
= lptbbi
->lParam
;
4431 if (lptbbi
->dwMask
& TBIF_SIZE
)
4432 btnPtr
->cx
= lptbbi
->cx
;
4433 if (lptbbi
->dwMask
& TBIF_STATE
)
4434 btnPtr
->fsState
= lptbbi
->fsState
;
4435 if (lptbbi
->dwMask
& TBIF_STYLE
)
4436 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4438 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4439 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4440 /* iString is index, zero it to make Str_SetPtr succeed */
4443 Str_SetPtrAtoW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4446 /* save the button rect to see if we need to redraw the whole toolbar */
4447 oldBtnRect
= btnPtr
->rect
;
4448 TOOLBAR_LayoutToolbar(hwnd
);
4450 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4451 InvalidateRect(hwnd
, NULL
, TRUE
);
4453 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4460 TOOLBAR_SetButtonInfoW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4462 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4463 LPTBBUTTONINFOW lptbbi
= (LPTBBUTTONINFOW
)lParam
;
4464 TBUTTON_INFO
*btnPtr
;
4470 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4473 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4474 lptbbi
->dwMask
& 0x80000000);
4478 btnPtr
= &infoPtr
->buttons
[nIndex
];
4479 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4480 btnPtr
->idCommand
= lptbbi
->idCommand
;
4481 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4482 btnPtr
->iBitmap
= lptbbi
->iImage
;
4483 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4484 btnPtr
->dwData
= lptbbi
->lParam
;
4485 if (lptbbi
->dwMask
& TBIF_SIZE
)
4486 btnPtr
->cx
= lptbbi
->cx
;
4487 if (lptbbi
->dwMask
& TBIF_STATE
)
4488 btnPtr
->fsState
= lptbbi
->fsState
;
4489 if (lptbbi
->dwMask
& TBIF_STYLE
)
4490 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4492 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4493 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4494 /* iString is index, zero it to make Str_SetPtr succeed */
4496 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4499 /* save the button rect to see if we need to redraw the whole toolbar */
4500 oldBtnRect
= btnPtr
->rect
;
4501 TOOLBAR_LayoutToolbar(hwnd
);
4503 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4504 InvalidateRect(hwnd
, NULL
, TRUE
);
4506 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4513 TOOLBAR_SetButtonSize (HWND hwnd
, LPARAM lParam
)
4515 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4516 INT cx
= (short)LOWORD(lParam
), cy
= (short)HIWORD(lParam
);
4518 if ((cx
< 0) || (cy
< 0))
4520 ERR("invalid parameter 0x%08x\n", (DWORD
)lParam
);
4524 TRACE("%p, cx = %d, cy = %d\n", hwnd
, cx
, cy
);
4526 /* The documentation claims you can only change the button size before
4527 * any button has been added. But this is wrong.
4528 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4529 * it to the toolbar, and it checks that the return value is nonzero - mjm
4530 * Further testing shows that we must actually perform the change too.
4533 * The documentation also does not mention that if 0 is supplied for
4534 * either size, the system changes it to the default of 24 wide and
4535 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4537 if (cx
== 0) cx
= 24;
4538 if (cy
== 0) cx
= 22;
4540 cx
= max(cx
, infoPtr
->szPadding
.cx
+ infoPtr
->nBitmapWidth
);
4541 cy
= max(cy
, infoPtr
->szPadding
.cy
+ infoPtr
->nBitmapHeight
);
4543 infoPtr
->nButtonWidth
= cx
;
4544 infoPtr
->nButtonHeight
= cy
;
4546 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
4547 TOOLBAR_LayoutToolbar(hwnd
);
4553 TOOLBAR_SetButtonWidth (HWND hwnd
, LPARAM lParam
)
4555 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4557 /* if setting to current values, ignore */
4558 if ((infoPtr
->cxMin
== (short)LOWORD(lParam
)) &&
4559 (infoPtr
->cxMax
== (short)HIWORD(lParam
))) {
4560 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4561 infoPtr
->cxMin
, infoPtr
->cxMax
);
4565 /* save new values */
4566 infoPtr
->cxMin
= (short)LOWORD(lParam
);
4567 infoPtr
->cxMax
= (short)HIWORD(lParam
);
4569 /* otherwise we need to recalc the toolbar and in some cases
4570 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4571 which doesn't actually draw - GA). */
4572 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4573 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4575 TOOLBAR_CalcToolbar (hwnd
);
4577 InvalidateRect (hwnd
, NULL
, TRUE
);
4584 TOOLBAR_SetCmdId (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4586 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4587 INT nIndex
= (INT
)wParam
;
4589 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4592 infoPtr
->buttons
[nIndex
].idCommand
= (INT
)lParam
;
4594 if (infoPtr
->hwndToolTip
) {
4596 FIXME("change tool tip!\n");
4605 TOOLBAR_SetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4607 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4608 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4609 HIMAGELIST himlTemp
;
4612 if (infoPtr
->iVersion
>= 5)
4615 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4616 &infoPtr
->cimlDis
, himl
, id
);
4618 /* FIXME: redraw ? */
4620 return (LRESULT
)himlTemp
;
4625 TOOLBAR_SetDrawTextFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4627 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4630 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd
, (DWORD
)wParam
, (DWORD
)lParam
);
4632 dwTemp
= infoPtr
->dwDTFlags
;
4633 infoPtr
->dwDTFlags
=
4634 (infoPtr
->dwDTFlags
& (DWORD
)wParam
) | (DWORD
)lParam
;
4636 return (LRESULT
)dwTemp
;
4639 /* This function differs a bit from what MSDN says it does:
4640 * 1. lParam contains extended style flags to OR with current style
4641 * (MSDN isn't clear on the OR bit)
4642 * 2. wParam appears to contain extended style flags to be reset
4643 * (MSDN says that this parameter is reserved)
4646 TOOLBAR_SetExtendedStyle (HWND hwnd
, LPARAM lParam
)
4648 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4651 dwOldStyle
= infoPtr
->dwExStyle
;
4652 infoPtr
->dwExStyle
= (DWORD
)lParam
;
4654 TRACE("new style 0x%08x\n", infoPtr
->dwExStyle
);
4656 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4657 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4658 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4660 if ((dwOldStyle
^ infoPtr
->dwExStyle
) & TBSTYLE_EX_MIXEDBUTTONS
)
4661 TOOLBAR_CalcToolbar(hwnd
);
4663 TOOLBAR_LayoutToolbar(hwnd
);
4665 TOOLBAR_AutoSize(hwnd
);
4666 InvalidateRect(hwnd
, NULL
, TRUE
);
4668 return (LRESULT
)dwOldStyle
;
4673 TOOLBAR_SetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4675 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4676 HIMAGELIST himlTemp
;
4677 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4680 if (infoPtr
->iVersion
>= 5)
4683 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd
, himl
, id
);
4685 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4686 &infoPtr
->cimlHot
, himl
, id
);
4688 /* FIXME: redraw ? */
4690 return (LRESULT
)himlTemp
;
4694 /* Makes previous hot button no longer hot, makes the specified
4695 * button hot and sends appropriate notifications. dwReason is one or
4696 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4697 * NOTE 1: this function does not validate nHit
4698 * NOTE 2: the name of this function is completely made up and
4699 * not based on any documentation from Microsoft. */
4701 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4703 if (infoPtr
->nHotItem
!= nHit
)
4705 NMTBHOTITEM nmhotitem
;
4706 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4708 nmhotitem
.dwFlags
= dwReason
;
4709 if(infoPtr
->nHotItem
>= 0)
4711 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4712 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4716 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4717 nmhotitem
.idOld
= 0;
4722 btnPtr
= &infoPtr
->buttons
[nHit
];
4723 nmhotitem
.idNew
= btnPtr
->idCommand
;
4727 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4728 nmhotitem
.idNew
= 0;
4731 /* now change the hot and invalidate the old and new buttons - if the
4733 if (!TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
))
4736 oldBtnPtr
->bHot
= FALSE
;
4737 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4739 /* setting disabled buttons as hot fails even if the notify contains the button id */
4740 if (btnPtr
&& (btnPtr
->fsState
& TBSTATE_ENABLED
)) {
4741 btnPtr
->bHot
= TRUE
;
4742 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4743 infoPtr
->nHotItem
= nHit
;
4746 infoPtr
->nHotItem
= -1;
4752 TOOLBAR_SetHotItem (HWND hwnd
, WPARAM wParam
)
4754 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4755 INT nOldHotItem
= infoPtr
->nHotItem
;
4757 TRACE("hwnd = %p, nHit = %d\n", hwnd
, (INT
)wParam
);
4759 if ((INT
)wParam
>= infoPtr
->nNumButtons
)
4760 return infoPtr
->nHotItem
;
4762 if ((INT
)wParam
< 0)
4765 /* NOTE: an application can still remove the hot item even if anchor
4766 * highlighting is enabled */
4768 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, HICF_OTHER
);
4770 if (nOldHotItem
< 0)
4773 return (LRESULT
)nOldHotItem
;
4778 TOOLBAR_SetImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4780 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4781 HIMAGELIST himlTemp
;
4782 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4783 INT oldButtonWidth
= infoPtr
->nButtonWidth
;
4786 if (infoPtr
->iVersion
>= 5)
4789 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4790 &infoPtr
->cimlDef
, himl
, id
);
4792 infoPtr
->nNumBitmaps
= 0;
4793 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4794 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4796 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4797 &infoPtr
->nBitmapHeight
))
4799 infoPtr
->nBitmapWidth
= 1;
4800 infoPtr
->nBitmapHeight
= 1;
4802 TOOLBAR_CalcToolbar(hwnd
);
4803 if (infoPtr
->nButtonWidth
< oldButtonWidth
)
4804 TOOLBAR_SetButtonSize(hwnd
, MAKELONG(oldButtonWidth
, infoPtr
->nButtonHeight
));
4806 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4807 hwnd
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4808 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4810 InvalidateRect(hwnd
, NULL
, TRUE
);
4812 return (LRESULT
)himlTemp
;
4817 TOOLBAR_SetIndent (HWND hwnd
, WPARAM wParam
)
4819 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4821 infoPtr
->nIndent
= (INT
)wParam
;
4825 /* process only on indent changing */
4826 if(infoPtr
->nIndent
!= (INT
)wParam
)
4828 infoPtr
->nIndent
= (INT
)wParam
;
4829 TOOLBAR_CalcToolbar (hwnd
);
4830 InvalidateRect(hwnd
, NULL
, FALSE
);
4838 TOOLBAR_SetInsertMark (HWND hwnd
, LPARAM lParam
)
4840 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4841 TBINSERTMARK
*lptbim
= (TBINSERTMARK
*)lParam
;
4843 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd
, lptbim
->iButton
, lptbim
->dwFlags
);
4845 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4847 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4851 if ((lptbim
->iButton
== -1) ||
4852 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
4853 (lptbim
->iButton
>= 0)))
4855 infoPtr
->tbim
= *lptbim
;
4856 /* FIXME: don't need to update entire toolbar */
4857 InvalidateRect(hwnd
, NULL
, TRUE
);
4860 ERR("Invalid button index %d\n", lptbim
->iButton
);
4867 TOOLBAR_SetInsertMarkColor (HWND hwnd
, LPARAM lParam
)
4869 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4871 infoPtr
->clrInsertMark
= (COLORREF
)lParam
;
4873 /* FIXME: don't need to update entire toolbar */
4874 InvalidateRect(hwnd
, NULL
, TRUE
);
4881 TOOLBAR_SetMaxTextRows (HWND hwnd
, WPARAM wParam
)
4883 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4885 infoPtr
->nMaxTextRows
= (INT
)wParam
;
4887 TOOLBAR_CalcToolbar(hwnd
);
4892 /* MSDN gives slightly wrong info on padding.
4893 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4894 * 2. It is not used to create a blank area between the edge of the button
4895 * and the text or image if TBSTYLE_LIST is set. It is used to control
4896 * the gap between the image and text.
4897 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4898 * to control the bottom and right borders [with the border being
4899 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4900 * is shared evenly on both sides of the button.
4901 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4904 TOOLBAR_SetPadding (HWND hwnd
, LPARAM lParam
)
4906 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4909 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4910 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
4911 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
4912 TRACE("cx=%d, cy=%d\n",
4913 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4914 return (LRESULT
) oldPad
;
4919 TOOLBAR_SetParent (HWND hwnd
, WPARAM wParam
)
4921 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4926 hwndOldNotify
= infoPtr
->hwndNotify
;
4927 infoPtr
->hwndNotify
= (HWND
)wParam
;
4929 return (LRESULT
)hwndOldNotify
;
4934 TOOLBAR_SetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4936 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4937 LPRECT lprc
= (LPRECT
)lParam
;
4938 int rows
= LOWORD(wParam
);
4939 BOOL bLarger
= HIWORD(wParam
);
4943 TRACE("Setting rows to %d (%d)\n", rows
, bLarger
);
4945 if(infoPtr
->nRows
!= rows
)
4947 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
;
4948 int curColumn
= 0; /* Current column */
4949 int curRow
= 0; /* Current row */
4950 int hidden
= 0; /* Number of hidden buttons */
4951 int seps
= 0; /* Number of separators */
4952 int idealWrap
= 0; /* Ideal wrap point */
4957 Calculate new size and wrap points - Under windows, setrows will
4958 change the dimensions if needed to show the number of requested
4959 rows (if CCS_NORESIZE is set), or will take up the whole window
4960 (if no CCS_NORESIZE).
4962 Basic algorithm - If N buttons, and y rows requested, each row
4963 contains N/y buttons.
4965 FIXME: Handling of separators not obvious from testing results
4966 FIXME: Take width of window into account?
4969 /* Loop through the buttons one by one counting key items */
4970 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
4972 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
4973 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
4975 else if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
4979 /* FIXME: Separators make this quite complex */
4980 if (seps
) FIXME("Separators unhandled\n");
4982 /* Round up so more per line, i.e., less rows */
4983 idealWrap
= (infoPtr
->nNumButtons
- hidden
+ (rows
-1)) / rows
;
4985 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4986 achieve the requested number of rows. */
4987 if (bLarger
&& idealWrap
> 1)
4989 int resRows
= (infoPtr
->nNumButtons
+ (idealWrap
-1)) / idealWrap
;
4990 int moreRows
= (infoPtr
->nNumButtons
+ (idealWrap
-2)) / (idealWrap
-1);
4992 if (resRows
< rows
&& moreRows
> rows
)
4995 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap
);
4999 curColumn
= curRow
= 0;
5001 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap
,
5002 infoPtr
->nNumButtons
, hidden
, rows
);
5004 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
5006 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
5009 /* Step on, wrap if necessary or flag next to wrap */
5018 if (curColumn
> (idealWrap
-1)) {
5020 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
5024 TRACE("Result - %d rows\n", curRow
+ 1);
5026 /* recalculate toolbar */
5027 TOOLBAR_CalcToolbar (hwnd
);
5029 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
5030 if NORESIZE is NOT set, then the toolbar will always be resized to
5031 take up the whole window. With it set, sizing needs to be manual. */
5032 if (infoPtr
->dwStyle
& CCS_NORESIZE
) {
5033 SetWindowPos(hwnd
, NULL
, 0, 0,
5034 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
5035 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
,
5039 /* repaint toolbar */
5040 InvalidateRect(hwnd
, NULL
, TRUE
);
5043 /* return bounding rectangle */
5045 lprc
->left
= infoPtr
->rcBound
.left
;
5046 lprc
->right
= infoPtr
->rcBound
.right
;
5047 lprc
->top
= infoPtr
->rcBound
.top
;
5048 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
5056 TOOLBAR_SetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5058 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5059 TBUTTON_INFO
*btnPtr
;
5062 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
5066 btnPtr
= &infoPtr
->buttons
[nIndex
];
5068 /* if hidden state has changed the invalidate entire window and recalc */
5069 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
5070 btnPtr
->fsState
= LOWORD(lParam
);
5071 TOOLBAR_CalcToolbar (hwnd
);
5072 InvalidateRect(hwnd
, 0, TRUE
);
5076 /* process state changing if current state doesn't match new state */
5077 if(btnPtr
->fsState
!= LOWORD(lParam
))
5079 btnPtr
->fsState
= LOWORD(lParam
);
5080 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5088 TOOLBAR_SetStyle (HWND hwnd
, LPARAM lParam
)
5090 SetWindowLongW(hwnd
, GWL_STYLE
, lParam
);
5096 static inline LRESULT
5097 TOOLBAR_SetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5099 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5101 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd
, (HWND
)wParam
, lParam
);
5103 infoPtr
->hwndToolTip
= (HWND
)wParam
;
5109 TOOLBAR_SetUnicodeFormat (HWND hwnd
, WPARAM wParam
)
5111 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5114 TRACE("%s hwnd=%p\n",
5115 ((BOOL
)wParam
) ? "TRUE" : "FALSE", hwnd
);
5117 bTemp
= infoPtr
->bUnicode
;
5118 infoPtr
->bUnicode
= (BOOL
)wParam
;
5125 TOOLBAR_GetColorScheme (HWND hwnd
, LPCOLORSCHEME lParam
)
5127 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5129 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
5130 comctl32_color
.clrBtnHighlight
:
5131 infoPtr
->clrBtnHighlight
;
5132 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
5133 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
5139 TOOLBAR_SetColorScheme (HWND hwnd
, const COLORSCHEME
*lParam
)
5141 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5143 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5144 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
5145 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
5147 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
5148 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
5149 InvalidateRect(hwnd
, NULL
, TRUE
);
5155 TOOLBAR_SetVersion (HWND hwnd
, INT iVersion
)
5157 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5158 INT iOldVersion
= infoPtr
->iVersion
;
5160 infoPtr
->iVersion
= iVersion
;
5162 if (infoPtr
->iVersion
>= 5)
5163 TOOLBAR_SetUnicodeFormat(hwnd
, TRUE
);
5170 TOOLBAR_GetStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5172 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5173 WORD iString
= HIWORD(wParam
);
5174 WORD buffersize
= LOWORD(wParam
);
5175 LPSTR str
= (LPSTR
)lParam
;
5178 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, buffersize
, str
);
5180 if (iString
< infoPtr
->nNumStrings
)
5182 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
5185 TRACE("returning %s\n", debugstr_a(str
));
5188 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5195 TOOLBAR_GetStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5197 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5198 WORD iString
= HIWORD(wParam
);
5199 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5200 LPWSTR str
= (LPWSTR
)lParam
;
5203 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, LOWORD(wParam
), str
);
5205 if (iString
< infoPtr
->nNumStrings
)
5207 len
= min(len
, strlenW(infoPtr
->strings
[iString
]));
5208 ret
= (len
+1)*sizeof(WCHAR
);
5211 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5216 TRACE("returning %s\n", debugstr_w(str
));
5219 WARN("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5224 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5225 * is the maximum size of the toolbar? */
5226 static LRESULT
TOOLBAR_Unkwn45D(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5228 SIZE
* pSize
= (SIZE
*)lParam
;
5229 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5234 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5235 * caller to specify a reason why the hot item changed (rather than just the
5236 * HICF_OTHER that TB_SETHOTITEM sends). */
5238 TOOLBAR_SetHotItem2 (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5240 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5241 INT nOldHotItem
= infoPtr
->nHotItem
;
5243 TRACE("old item=%d, new item=%d, flags=%08x\n",
5244 nOldHotItem
, infoPtr
->nHotItem
, (DWORD
)lParam
);
5246 if ((INT
) wParam
< 0 || (INT
)wParam
> infoPtr
->nNumButtons
)
5249 /* NOTE: an application can still remove the hot item even if anchor
5250 * highlighting is enabled */
5252 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, lParam
);
5256 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5259 /* Sets the toolbar global iListGap parameter which controls the amount of
5260 * spacing between the image and the text of buttons for TBSTYLE_LIST
5262 static LRESULT
TOOLBAR_SetListGap(HWND hwnd
, WPARAM wParam
)
5264 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5266 TRACE("hwnd=%p iListGap=%ld\n", hwnd
, wParam
);
5268 infoPtr
->iListGap
= (INT
)wParam
;
5270 InvalidateRect(hwnd
, NULL
, TRUE
);
5275 /* Returns the number of maximum number of image lists associated with the
5276 * various states. */
5277 static LRESULT
TOOLBAR_GetImageListCount(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5279 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5281 TRACE("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5283 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5287 TOOLBAR_GetIdealSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5289 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5290 LPSIZE lpsize
= (LPSIZE
)lParam
;
5296 * Testing shows the following:
5297 * wParam = 0 adjust cx value
5298 * = 1 set cy value to max size.
5299 * lParam pointer to SIZE structure
5302 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5303 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5307 if (lpsize
->cx
== -1) {
5308 /* **** this is wrong, native measures each button and sets it */
5309 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5311 else if(HIWORD(lpsize
->cx
)) {
5313 HWND hwndParent
= GetParent(hwnd
);
5315 GetWindowRect(hwnd
, &rc
);
5316 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5317 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc
));
5318 lpsize
->cx
= max(rc
.right
-rc
.left
,
5319 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5322 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5326 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5329 FIXME("Unknown wParam %ld\n", wParam
);
5332 TRACE("set to -> 0x%08x 0x%08x\n",
5333 lpsize
->cx
, lpsize
->cy
);
5337 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5339 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd
, wParam
, lParam
);
5341 InvalidateRect(hwnd
, NULL
, TRUE
);
5347 TOOLBAR_Create (HWND hwnd
, LPARAM lParam
)
5349 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5350 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
5353 TRACE("hwnd = %p\n", hwnd
);
5355 /* initialize info structure */
5356 infoPtr
->nButtonWidth
= 23;
5357 infoPtr
->nButtonHeight
= 22;
5358 infoPtr
->nBitmapHeight
= 16;
5359 infoPtr
->nBitmapWidth
= 16;
5361 infoPtr
->nMaxTextRows
= 1;
5362 infoPtr
->cxMin
= -1;
5363 infoPtr
->cxMax
= -1;
5364 infoPtr
->nNumBitmaps
= 0;
5365 infoPtr
->nNumStrings
= 0;
5367 infoPtr
->bCaptured
= FALSE
;
5368 infoPtr
->nButtonDown
= -1;
5369 infoPtr
->nButtonDrag
= -1;
5370 infoPtr
->nOldHit
= -1;
5371 infoPtr
->nHotItem
= -1;
5372 infoPtr
->hwndNotify
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
5373 infoPtr
->dwDTFlags
= (dwStyle
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
5374 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
5375 infoPtr
->bDragOutSent
= FALSE
;
5376 infoPtr
->iVersion
= 0;
5377 infoPtr
->hwndSelf
= hwnd
;
5378 infoPtr
->bDoRedraw
= TRUE
;
5379 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
5380 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
5381 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
5382 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
5383 infoPtr
->iListGap
= DEFLISTGAP
;
5384 infoPtr
->iTopMargin
= default_top_margin(infoPtr
);
5385 infoPtr
->dwStyle
= dwStyle
;
5386 infoPtr
->tbim
.iButton
= -1;
5387 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5388 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5389 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, (LPARAM
)NF_REQUERY
));
5390 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5392 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5393 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5395 OpenThemeData (hwnd
, themeClass
);
5397 TOOLBAR_CheckStyle (hwnd
, dwStyle
);
5404 TOOLBAR_Destroy (HWND hwnd
)
5406 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5408 /* delete tooltip control */
5409 if (infoPtr
->hwndToolTip
)
5410 DestroyWindow (infoPtr
->hwndToolTip
);
5412 /* delete temporary buffer for tooltip text */
5413 Free (infoPtr
->pszTooltipText
);
5414 Free (infoPtr
->bitmaps
); /* bitmaps list */
5416 /* delete button data */
5417 Free (infoPtr
->buttons
);
5419 /* delete strings */
5420 if (infoPtr
->strings
) {
5422 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5423 Free (infoPtr
->strings
[i
]);
5425 Free (infoPtr
->strings
);
5428 /* destroy internal image list */
5429 if (infoPtr
->himlInt
)
5430 ImageList_Destroy (infoPtr
->himlInt
);
5432 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5433 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5434 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5436 /* delete default font */
5437 DeleteObject (infoPtr
->hDefaultFont
);
5439 CloseThemeData (GetWindowTheme (hwnd
));
5441 /* free toolbar info data */
5443 SetWindowLongPtrW (hwnd
, 0, 0);
5450 TOOLBAR_EraseBackground (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5452 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5453 NMTBCUSTOMDRAW tbcd
;
5456 HTHEME theme
= GetWindowTheme (hwnd
);
5457 DWORD dwEraseCustDraw
= 0;
5459 /* the app has told us not to redraw the toolbar */
5460 if (!infoPtr
->bDoRedraw
)
5463 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5464 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5465 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5466 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5467 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5468 dwEraseCustDraw
= ntfret
& 0xffff;
5470 /* FIXME: in general the return flags *can* be or'ed together */
5471 switch (dwEraseCustDraw
)
5473 case CDRF_DODEFAULT
:
5475 case CDRF_SKIPDEFAULT
:
5478 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5483 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5484 * to my parent for processing.
5486 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5488 HDC hdc
= (HDC
)wParam
;
5493 parent
= GetParent(hwnd
);
5494 MapWindowPoints(hwnd
, parent
, &pt
, 1);
5495 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5496 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5497 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5500 ret
= DefWindowProcW (hwnd
, WM_ERASEBKGND
, wParam
, lParam
);
5502 if (dwEraseCustDraw
& CDRF_NOTIFYPOSTERASE
) {
5503 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5504 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5505 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5506 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5507 dwEraseCustDraw
= ntfret
& 0xffff;
5508 switch (dwEraseCustDraw
)
5510 case CDRF_DODEFAULT
:
5512 case CDRF_SKIPDEFAULT
:
5515 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5524 TOOLBAR_GetFont (HWND hwnd
)
5526 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5528 return (LRESULT
)infoPtr
->hFont
;
5533 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5536 INT nNewHotItem
= infoPtr
->nHotItem
;
5538 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5541 if ((nNewHotItem
+ iDirection
< 0) ||
5542 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5544 NMTBWRAPHOTITEM nmtbwhi
;
5545 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5546 nmtbwhi
.iDirection
= iDirection
;
5547 nmtbwhi
.dwReason
= dwReason
;
5549 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5553 nNewHotItem
+= iDirection
;
5554 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5556 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5557 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5559 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5566 TOOLBAR_KeyDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5568 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5571 nmkey
.nVKey
= (UINT
)wParam
;
5572 nmkey
.uFlags
= HIWORD(lParam
);
5574 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5575 return DefWindowProcW(hwnd
, WM_KEYDOWN
, wParam
, lParam
);
5577 switch ((UINT
)wParam
)
5581 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5585 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5589 if ((infoPtr
->nHotItem
>= 0) &&
5590 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5592 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5593 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5604 TOOLBAR_LButtonDblClk (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5609 pt
.x
= (short)LOWORD(lParam
);
5610 pt
.y
= (short)HIWORD(lParam
);
5611 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5614 TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
5615 else if (GetWindowLongW (hwnd
, GWL_STYLE
) & CCS_ADJUSTABLE
)
5616 TOOLBAR_Customize (hwnd
);
5623 TOOLBAR_LButtonDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5625 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5626 TBUTTON_INFO
*btnPtr
;
5631 BOOL bDragKeyPressed
;
5635 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5636 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5638 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5640 if (infoPtr
->hwndToolTip
)
5641 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5642 WM_LBUTTONDOWN
, wParam
, lParam
);
5644 pt
.x
= (short)LOWORD(lParam
);
5645 pt
.y
= (short)HIWORD(lParam
);
5646 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5648 btnPtr
= &infoPtr
->buttons
[nHit
];
5650 if ((nHit
>= 0) && bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5652 infoPtr
->nButtonDrag
= nHit
;
5655 /* If drag cursor has not been loaded, load it.
5656 * Note: it doesn't need to be freed */
5658 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5659 SetCursor(hCursorDrag
);
5664 infoPtr
->nOldHit
= nHit
;
5666 CopyRect(&arrowRect
, &btnPtr
->rect
);
5667 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5669 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5670 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5671 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5672 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5673 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5674 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5678 /* draw in pressed state */
5679 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5680 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5682 btnPtr
->bDropDownPressed
= TRUE
;
5683 RedrawWindow(hwnd
,&btnPtr
->rect
,0,
5684 RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5686 memset(&nmtb
, 0, sizeof(nmtb
));
5687 nmtb
.iItem
= btnPtr
->idCommand
;
5688 nmtb
.rcButton
= btnPtr
->rect
;
5689 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5691 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5693 if (res
!= TBDDRET_TREATPRESSED
)
5697 /* redraw button in unpressed state */
5698 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5699 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5701 btnPtr
->bDropDownPressed
= FALSE
;
5702 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5704 /* find and set hot item
5705 * NOTE: native doesn't do this, but that is a bug */
5707 ScreenToClient(hwnd
, &pt
);
5708 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
5709 if (!infoPtr
->bAnchor
|| (nHit
>= 0))
5710 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5712 /* remove any left mouse button down or double-click messages
5713 * so that we can get a toggle effect on the button */
5714 while (PeekMessageW(&msg
, hwnd
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5715 PeekMessageW(&msg
, hwnd
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5720 /* otherwise drop through and process as pushed */
5722 infoPtr
->bCaptured
= TRUE
;
5723 infoPtr
->nButtonDown
= nHit
;
5724 infoPtr
->bDragOutSent
= FALSE
;
5726 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5728 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5730 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5731 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5738 memset(&nmtb
, 0, sizeof(nmtb
));
5739 nmtb
.iItem
= btnPtr
->idCommand
;
5740 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5743 nmmouse
.dwHitInfo
= nHit
;
5745 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5747 nmmouse
.dwItemSpec
= -1;
5750 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5751 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5754 ClientToScreen(hwnd
, &pt
);
5757 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5758 return DefWindowProcW(hwnd
, WM_LBUTTONDOWN
, wParam
, lParam
);
5764 TOOLBAR_LButtonUp (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5766 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5767 TBUTTON_INFO
*btnPtr
;
5775 if (infoPtr
->hwndToolTip
)
5776 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5777 WM_LBUTTONUP
, wParam
, lParam
);
5779 pt
.x
= (short)LOWORD(lParam
);
5780 pt
.y
= (short)HIWORD(lParam
);
5781 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5783 if (!infoPtr
->bAnchor
|| (nHit
>= 0))
5784 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5786 if (infoPtr
->nButtonDrag
>= 0) {
5790 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5793 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5795 GetClientRect(hwnd
, &rcClient
);
5796 if (PtInRect(&rcClient
, pt
))
5803 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5806 if (nButton
== infoPtr
->nButtonDrag
)
5808 /* if the button is moved sightly left and we have a
5809 * separator there then remove it */
5810 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5812 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5813 TOOLBAR_DeleteButton(hwnd
, nButton
- 1);
5815 else /* else insert a separator before the dragged button */
5818 memset(&tbb
, 0, sizeof(tbb
));
5819 tbb
.fsStyle
= BTNS_SEP
;
5821 TOOLBAR_InsertButtonT(hwnd
, nButton
, (LPARAM
)&tbb
, TRUE
);
5828 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5829 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, 0);
5831 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5834 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, nButton
);
5839 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5840 TOOLBAR_DeleteButton(hwnd
, (WPARAM
)infoPtr
->nButtonDrag
);
5843 /* button under cursor changed so need to re-set hot item */
5844 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5845 infoPtr
->nButtonDrag
= -1;
5847 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5849 else if (infoPtr
->nButtonDown
>= 0) {
5850 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5851 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5853 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5854 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5855 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5857 if ((nOldIndex
!= nHit
) &&
5859 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5860 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5863 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5864 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5866 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5870 if (nOldIndex
!= -1)
5871 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5874 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5875 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5876 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5878 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5880 infoPtr
->nButtonDown
= -1;
5882 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5883 TOOLBAR_SendNotify (&hdr
, infoPtr
,
5884 NM_RELEASEDCAPTURE
);
5886 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5889 memset(&nmtb
, 0, sizeof(nmtb
));
5890 nmtb
.iItem
= btnPtr
->idCommand
;
5891 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5894 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5896 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5897 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)hwnd
);
5899 /* In case we have just been destroyed... */
5905 /* !!! Undocumented - toolbar at 4.71 level and above sends
5906 * NM_CLICK with the NMMOUSE structure. */
5907 nmmouse
.dwHitInfo
= nHit
;
5910 nmmouse
.dwItemSpec
= -1;
5913 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5914 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5917 ClientToScreen(hwnd
, &pt
);
5920 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5921 return DefWindowProcW(hwnd
, WM_LBUTTONUP
, wParam
, lParam
);
5927 TOOLBAR_RButtonUp( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5929 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5934 pt
.x
= (short)LOWORD(lParam
);
5935 pt
.y
= (short)HIWORD(lParam
);
5937 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
5938 nmmouse
.dwHitInfo
= nHit
;
5941 nmmouse
.dwItemSpec
= -1;
5943 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5944 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5947 ClientToScreen(hwnd
, &pt
);
5950 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
5951 return DefWindowProcW(hwnd
, WM_RBUTTONUP
, wParam
, lParam
);
5957 TOOLBAR_RButtonDblClk( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5959 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5962 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
5963 return DefWindowProcW(hwnd
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
5969 TOOLBAR_CaptureChanged(HWND hwnd
)
5971 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5972 TBUTTON_INFO
*btnPtr
;
5974 infoPtr
->bCaptured
= FALSE
;
5976 if (infoPtr
->nButtonDown
>= 0)
5978 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5979 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5981 infoPtr
->nOldHit
= -1;
5983 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5984 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5990 TOOLBAR_MouseLeave (HWND hwnd
)
5992 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5994 /* don't remove hot effects when in anchor highlighting mode or when a
5995 * drop-down button is pressed */
5996 if (infoPtr
->nHotItem
>= 0 && !infoPtr
->bAnchor
)
5998 TBUTTON_INFO
*hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
5999 if (!hotBtnPtr
->bDropDownPressed
)
6000 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
6003 if (infoPtr
->nOldHit
< 0)
6006 /* If the last button we were over is depressed then make it not */
6007 /* depressed and redraw it */
6008 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
6010 TBUTTON_INFO
*btnPtr
;
6013 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6015 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6018 InflateRect (&rc1
, 1, 1);
6019 InvalidateRect (hwnd
, &rc1
, TRUE
);
6022 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
6025 ZeroMemory(&nmt
, sizeof(nmt
));
6026 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6027 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6028 infoPtr
->bDragOutSent
= TRUE
;
6031 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
6037 TOOLBAR_MouseMove (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6039 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6041 TRACKMOUSEEVENT trackinfo
;
6043 TBUTTON_INFO
*btnPtr
;
6045 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
6046 TOOLBAR_TooltipCreateControl(infoPtr
);
6048 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
6049 /* fill in the TRACKMOUSEEVENT struct */
6050 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
6051 trackinfo
.dwFlags
= TME_QUERY
;
6053 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6054 _TrackMouseEvent(&trackinfo
);
6056 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6057 if(trackinfo
.hwndTrack
!= hwnd
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
6058 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
6059 trackinfo
.hwndTrack
= hwnd
;
6061 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6062 /* and can properly deactivate the hot toolbar button */
6063 _TrackMouseEvent(&trackinfo
);
6067 if (infoPtr
->hwndToolTip
)
6068 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
6069 WM_MOUSEMOVE
, wParam
, lParam
);
6071 pt
.x
= (short)LOWORD(lParam
);
6072 pt
.y
= (short)HIWORD(lParam
);
6074 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
6076 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6077 && (!infoPtr
->bAnchor
|| (nHit
>= 0)))
6078 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
);
6080 if (infoPtr
->nOldHit
!= nHit
)
6082 if (infoPtr
->bCaptured
)
6084 if (!infoPtr
->bDragOutSent
)
6087 ZeroMemory(&nmt
, sizeof(nmt
));
6088 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6089 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6090 infoPtr
->bDragOutSent
= TRUE
;
6093 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6094 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
6095 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6096 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6098 else if (nHit
== infoPtr
->nButtonDown
) {
6099 btnPtr
->fsState
|= TBSTATE_PRESSED
;
6100 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6102 infoPtr
->nOldHit
= nHit
;
6110 static inline LRESULT
6111 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6113 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6114 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
6116 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6120 static inline LRESULT
6121 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6123 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
6124 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
6126 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
6131 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6133 TOOLBAR_INFO
*infoPtr
;
6134 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
6137 /* allocate memory for info structure */
6138 infoPtr
= Alloc (sizeof(TOOLBAR_INFO
));
6139 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
6142 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
6144 infoPtr
->nWidth
= 0;
6146 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6147 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
6148 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
6149 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
6152 /* native control does:
6153 * Get a lot of colors and brushes
6155 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6156 * CreateFontIndirectW(adr1)
6157 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6158 * hdc = GetDC(toolbar)
6159 * GetSystemMetrics(0x48)
6160 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6161 * 0, 0, 0, 0, "MARLETT")
6162 * oldfnt = SelectObject(hdc, fnt2)
6163 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6164 * GetTextMetricsW(hdc, adr3)
6165 * SelectObject(hdc, oldfnt)
6166 * DeleteObject(fnt2)
6168 * InvalidateRect(toolbar, 0, 1)
6169 * SetWindowLongW(toolbar, 0, addr)
6170 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6173 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6174 * ie 2 0x4600094c 0x4600094c 0x4600894d
6175 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6176 * rebar 0x50008844 0x40008844 0x50008845
6177 * pager 0x50000844 0x40000844 0x50008845
6178 * IC35mgr 0x5400084e **nochange**
6179 * on entry to _NCCREATE 0x5400084e
6180 * rowlist 0x5400004e **nochange**
6181 * on entry to _NCCREATE 0x5400004e
6185 /* I think the code below is a bug, but it is the way that the native
6186 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6187 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6188 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6189 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6190 * Somehow, the only cases of this seem to be MFC programs.
6192 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6193 * does not occur in the WM_STYLECHANGING routine.
6194 * (Guy Albertelli 9/2001)
6197 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6198 && !(cs
->style
& TBSTYLE_TRANSPARENT
))
6199 styleadd
|= TBSTYLE_TRANSPARENT
;
6200 if (!(cs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
6201 styleadd
|= CCS_TOP
; /* default to top */
6202 SetWindowLongW (hwnd
, GWL_STYLE
, cs
->style
| styleadd
);
6205 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, lParam
);
6210 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6212 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
6216 if (dwStyle
& WS_MINIMIZE
)
6217 return 0; /* Nothing to do */
6219 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
6221 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
6224 if (!(dwStyle
& CCS_NODIVIDER
))
6226 GetWindowRect (hwnd
, &rcWindow
);
6227 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
6228 if( dwStyle
& WS_BORDER
)
6229 OffsetRect (&rcWindow
, 1, 1);
6230 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6233 ReleaseDC( hwnd
, hdc
);
6239 /* handles requests from the tooltip control on what text to display */
6240 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6242 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6244 TRACE("button index = %d\n", index
);
6246 Free (infoPtr
->pszTooltipText
);
6247 infoPtr
->pszTooltipText
= NULL
;
6252 if (infoPtr
->bUnicode
)
6254 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6255 NMTBGETINFOTIPW tbgit
;
6256 unsigned int len
; /* in chars */
6258 wszBuffer
[0] = '\0';
6259 wszBuffer
[INFOTIPSIZE
] = '\0';
6261 tbgit
.pszText
= wszBuffer
;
6262 tbgit
.cchTextMax
= INFOTIPSIZE
;
6263 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6264 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6266 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6268 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6270 len
= strlenW(tbgit
.pszText
);
6271 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6273 /* need to allocate temporary buffer in infoPtr as there
6274 * isn't enough space in buffer passed to us by the
6275 * tooltip control */
6276 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6277 if (infoPtr
->pszTooltipText
)
6279 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6280 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6286 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6292 CHAR szBuffer
[INFOTIPSIZE
+1];
6293 NMTBGETINFOTIPA tbgit
;
6294 unsigned int len
; /* in chars */
6297 szBuffer
[INFOTIPSIZE
] = '\0';
6299 tbgit
.pszText
= szBuffer
;
6300 tbgit
.cchTextMax
= INFOTIPSIZE
;
6301 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6302 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6304 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6306 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6308 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6309 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]))
6311 /* need to allocate temporary buffer in infoPtr as there
6312 * isn't enough space in buffer passed to us by the
6313 * tooltip control */
6314 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6315 if (infoPtr
->pszTooltipText
)
6317 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6318 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6322 else if (tbgit
.pszText
[0])
6324 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1,
6325 lpnmtdi
->lpszText
, sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]));
6330 /* if button has text, but it is not shown then automatically
6331 * use that text as tooltip */
6332 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6333 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6335 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6336 unsigned int len
= pszText
? strlenW(pszText
) : 0;
6338 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6340 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6342 /* need to allocate temporary buffer in infoPtr as there
6343 * isn't enough space in buffer passed to us by the
6344 * tooltip control */
6345 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6346 if (infoPtr
->pszTooltipText
)
6348 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6349 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6355 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6360 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6362 /* last resort: send notification on to app */
6363 /* FIXME: find out what is really used here */
6364 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmtdi
->hdr
.idFrom
, (LPARAM
)lpnmtdi
);
6368 static inline LRESULT
6369 TOOLBAR_Notify (HWND hwnd
, LPARAM lParam
)
6371 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6372 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
6374 switch (lpnmh
->code
)
6378 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
6380 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6381 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6382 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6386 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6387 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6395 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lParam
;
6397 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6398 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6399 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6400 lppgs
->iScroll
, lppgs
->iDir
);
6404 case TTN_GETDISPINFOW
:
6405 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lParam
);
6407 case TTN_GETDISPINFOA
:
6408 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6418 TOOLBAR_NotifyFormat(const TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6422 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam
, lParam
);
6424 if (lParam
== NF_QUERY
)
6427 if (lParam
== NF_REQUERY
) {
6428 format
= SendMessageW(infoPtr
->hwndNotify
,
6429 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6430 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6431 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6442 TOOLBAR_Paint (HWND hwnd
, WPARAM wParam
)
6444 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
6448 /* fill ps.rcPaint with a default rect */
6449 ps
.rcPaint
= infoPtr
->rcBound
;
6451 hdc
= wParam
==0 ? BeginPaint(hwnd
, &ps
) : (HDC
)wParam
;
6453 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps
.rcPaint
));
6455 TOOLBAR_Refresh (hwnd
, hdc
, &ps
);
6456 if (!wParam
) EndPaint (hwnd
, &ps
);
6463 TOOLBAR_SetFocus (HWND hwnd
)
6465 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6467 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6469 /* make first item hot */
6470 if (infoPtr
->nNumButtons
> 0)
6471 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6477 TOOLBAR_SetFont(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6479 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
6481 TRACE("font=%p redraw=%ld\n", (HFONT
)wParam
, lParam
);
6484 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
6486 infoPtr
->hFont
= (HFONT
)wParam
;
6488 TOOLBAR_CalcToolbar(hwnd
);
6491 InvalidateRect(hwnd
, NULL
, TRUE
);
6496 TOOLBAR_SetRedraw (HWND hwnd
, WPARAM wParam
)
6497 /*****************************************************
6500 * Handles the WM_SETREDRAW message.
6503 * According to testing V4.71 of COMCTL32 returns the
6504 * *previous* status of the redraw flag (either 0 or 1)
6505 * instead of the MSDN documented value of 0 if handled.
6506 * (For laughs see the "consistency" with same function
6509 *****************************************************/
6511 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6512 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6514 TRACE("set to %s\n",
6515 (wParam
) ? "TRUE" : "FALSE");
6516 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6518 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6520 return (oldredraw
) ? 1 : 0;
6525 TOOLBAR_Size (HWND hwnd
)
6527 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6529 TRACE("sizing toolbar!\n");
6531 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6533 RECT delta_width
, delta_height
, client
, dummy
;
6534 DWORD min_x
, max_x
, min_y
, max_y
;
6535 TBUTTON_INFO
*btnPtr
;
6538 GetClientRect(hwnd
, &client
);
6539 if(client
.right
> infoPtr
->client_rect
.right
)
6541 min_x
= infoPtr
->client_rect
.right
;
6542 max_x
= client
.right
;
6546 max_x
= infoPtr
->client_rect
.right
;
6547 min_x
= client
.right
;
6549 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6551 min_y
= infoPtr
->client_rect
.bottom
;
6552 max_y
= client
.bottom
;
6556 max_y
= infoPtr
->client_rect
.bottom
;
6557 min_y
= client
.bottom
;
6560 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6561 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6563 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6564 btnPtr
= infoPtr
->buttons
;
6565 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6566 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6567 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6568 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6570 GetClientRect(hwnd
, &infoPtr
->client_rect
);
6571 TOOLBAR_AutoSize(hwnd
);
6577 TOOLBAR_StyleChanged (HWND hwnd
, INT nType
, const STYLESTRUCT
*lpStyle
)
6579 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6581 if (nType
== GWL_STYLE
)
6583 DWORD dwOldStyle
= infoPtr
->dwStyle
;
6585 if (lpStyle
->styleNew
& TBSTYLE_LIST
)
6586 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
6588 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
6590 TOOLBAR_CheckStyle (hwnd
, lpStyle
->styleNew
);
6592 TRACE("new style 0x%08x\n", lpStyle
->styleNew
);
6594 infoPtr
->dwStyle
= lpStyle
->styleNew
;
6596 if ((dwOldStyle
^ lpStyle
->styleNew
) & (TBSTYLE_WRAPABLE
| CCS_VERT
))
6597 TOOLBAR_LayoutToolbar(hwnd
);
6599 /* only resize if one of the CCS_* styles was changed */
6600 if ((dwOldStyle
^ lpStyle
->styleNew
) & COMMON_STYLES
)
6602 TOOLBAR_AutoSize (hwnd
);
6604 InvalidateRect(hwnd
, NULL
, TRUE
);
6613 TOOLBAR_SysColorChange ()
6615 COMCTL32_RefreshSysColors();
6621 /* update theme after a WM_THEMECHANGED message */
6622 static LRESULT
theme_changed (HWND hwnd
)
6624 HTHEME theme
= GetWindowTheme (hwnd
);
6625 CloseThemeData (theme
);
6626 OpenThemeData (hwnd
, themeClass
);
6631 static LRESULT WINAPI
6632 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6634 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6636 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6637 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6639 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6640 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6645 return TOOLBAR_AddBitmap (hwnd
, wParam
, lParam
);
6647 case TB_ADDBUTTONSA
:
6648 return TOOLBAR_AddButtonsT(hwnd
, wParam
, lParam
, FALSE
);
6650 case TB_ADDBUTTONSW
:
6651 return TOOLBAR_AddButtonsT(hwnd
, wParam
, lParam
, TRUE
);
6654 return TOOLBAR_AddStringA (hwnd
, wParam
, lParam
);
6657 return TOOLBAR_AddStringW (hwnd
, wParam
, lParam
);
6660 return TOOLBAR_AutoSize (hwnd
);
6662 case TB_BUTTONCOUNT
:
6663 return TOOLBAR_ButtonCount (hwnd
);
6665 case TB_BUTTONSTRUCTSIZE
:
6666 return TOOLBAR_ButtonStructSize (hwnd
, wParam
);
6668 case TB_CHANGEBITMAP
:
6669 return TOOLBAR_ChangeBitmap (hwnd
, wParam
, lParam
);
6671 case TB_CHECKBUTTON
:
6672 return TOOLBAR_CheckButton (hwnd
, wParam
, lParam
);
6674 case TB_COMMANDTOINDEX
:
6675 return TOOLBAR_CommandToIndex (hwnd
, wParam
);
6678 return TOOLBAR_Customize (hwnd
);
6680 case TB_DELETEBUTTON
:
6681 return TOOLBAR_DeleteButton (hwnd
, wParam
);
6683 case TB_ENABLEBUTTON
:
6684 return TOOLBAR_EnableButton (hwnd
, wParam
, lParam
);
6686 case TB_GETANCHORHIGHLIGHT
:
6687 return TOOLBAR_GetAnchorHighlight (hwnd
);
6690 return TOOLBAR_GetBitmap (hwnd
, wParam
);
6692 case TB_GETBITMAPFLAGS
:
6693 return TOOLBAR_GetBitmapFlags ();
6696 return TOOLBAR_GetButton (hwnd
, wParam
, lParam
);
6698 case TB_GETBUTTONINFOA
:
6699 return TOOLBAR_GetButtonInfoT(hwnd
, wParam
, lParam
, FALSE
);
6701 case TB_GETBUTTONINFOW
:
6702 return TOOLBAR_GetButtonInfoT(hwnd
, wParam
, lParam
, TRUE
);
6704 case TB_GETBUTTONSIZE
:
6705 return TOOLBAR_GetButtonSize (hwnd
);
6707 case TB_GETBUTTONTEXTA
:
6708 return TOOLBAR_GetButtonTextA (hwnd
, wParam
, lParam
);
6710 case TB_GETBUTTONTEXTW
:
6711 return TOOLBAR_GetButtonTextW (hwnd
, wParam
, lParam
);
6713 case TB_GETDISABLEDIMAGELIST
:
6714 return TOOLBAR_GetDisabledImageList (hwnd
, wParam
, lParam
);
6716 case TB_GETEXTENDEDSTYLE
:
6717 return TOOLBAR_GetExtendedStyle (hwnd
);
6719 case TB_GETHOTIMAGELIST
:
6720 return TOOLBAR_GetHotImageList (hwnd
, wParam
, lParam
);
6723 return TOOLBAR_GetHotItem (hwnd
);
6725 case TB_GETIMAGELIST
:
6726 return TOOLBAR_GetDefImageList (hwnd
, wParam
, lParam
);
6728 case TB_GETINSERTMARK
:
6729 return TOOLBAR_GetInsertMark (hwnd
, lParam
);
6731 case TB_GETINSERTMARKCOLOR
:
6732 return TOOLBAR_GetInsertMarkColor (hwnd
);
6734 case TB_GETITEMRECT
:
6735 return TOOLBAR_GetItemRect (hwnd
, wParam
, lParam
);
6738 return TOOLBAR_GetMaxSize (hwnd
, lParam
);
6740 /* case TB_GETOBJECT: */ /* 4.71 */
6743 return TOOLBAR_GetPadding (hwnd
);
6746 return TOOLBAR_GetRect (hwnd
, wParam
, lParam
);
6749 return TOOLBAR_GetRows (hwnd
);
6752 return TOOLBAR_GetState (hwnd
, wParam
);
6755 return TOOLBAR_GetStringA (hwnd
, wParam
, lParam
);
6758 return TOOLBAR_GetStringW (hwnd
, wParam
, lParam
);
6761 return TOOLBAR_GetStyle (hwnd
);
6763 case TB_GETTEXTROWS
:
6764 return TOOLBAR_GetTextRows (hwnd
);
6766 case TB_GETTOOLTIPS
:
6767 return TOOLBAR_GetToolTips (hwnd
);
6769 case TB_GETUNICODEFORMAT
:
6770 return TOOLBAR_GetUnicodeFormat (hwnd
);
6773 return TOOLBAR_HideButton (hwnd
, wParam
, lParam
);
6776 return TOOLBAR_HitTest (hwnd
, lParam
);
6778 case TB_INDETERMINATE
:
6779 return TOOLBAR_Indeterminate (hwnd
, wParam
, lParam
);
6781 case TB_INSERTBUTTONA
:
6782 return TOOLBAR_InsertButtonT(hwnd
, wParam
, lParam
, FALSE
);
6784 case TB_INSERTBUTTONW
:
6785 return TOOLBAR_InsertButtonT(hwnd
, wParam
, lParam
, TRUE
);
6787 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6789 case TB_ISBUTTONCHECKED
:
6790 return TOOLBAR_IsButtonChecked (hwnd
, wParam
);
6792 case TB_ISBUTTONENABLED
:
6793 return TOOLBAR_IsButtonEnabled (hwnd
, wParam
);
6795 case TB_ISBUTTONHIDDEN
:
6796 return TOOLBAR_IsButtonHidden (hwnd
, wParam
);
6798 case TB_ISBUTTONHIGHLIGHTED
:
6799 return TOOLBAR_IsButtonHighlighted (hwnd
, wParam
);
6801 case TB_ISBUTTONINDETERMINATE
:
6802 return TOOLBAR_IsButtonIndeterminate (hwnd
, wParam
);
6804 case TB_ISBUTTONPRESSED
:
6805 return TOOLBAR_IsButtonPressed (hwnd
, wParam
);
6808 return TOOLBAR_LoadImages (hwnd
, wParam
, lParam
);
6810 case TB_MAPACCELERATORA
:
6811 case TB_MAPACCELERATORW
:
6812 return TOOLBAR_MapAccelerator (hwnd
, wParam
, lParam
);
6815 return TOOLBAR_MarkButton (hwnd
, wParam
, lParam
);
6818 return TOOLBAR_MoveButton (hwnd
, wParam
, lParam
);
6820 case TB_PRESSBUTTON
:
6821 return TOOLBAR_PressButton (hwnd
, wParam
, lParam
);
6823 case TB_REPLACEBITMAP
:
6824 return TOOLBAR_ReplaceBitmap (hwnd
, lParam
);
6826 case TB_SAVERESTOREA
:
6827 return TOOLBAR_SaveRestoreA (hwnd
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6829 case TB_SAVERESTOREW
:
6830 return TOOLBAR_SaveRestoreW (hwnd
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6832 case TB_SETANCHORHIGHLIGHT
:
6833 return TOOLBAR_SetAnchorHighlight (hwnd
, wParam
);
6835 case TB_SETBITMAPSIZE
:
6836 return TOOLBAR_SetBitmapSize (hwnd
, wParam
, lParam
);
6838 case TB_SETBUTTONINFOA
:
6839 return TOOLBAR_SetButtonInfoA (hwnd
, wParam
, lParam
);
6841 case TB_SETBUTTONINFOW
:
6842 return TOOLBAR_SetButtonInfoW (hwnd
, wParam
, lParam
);
6844 case TB_SETBUTTONSIZE
:
6845 return TOOLBAR_SetButtonSize (hwnd
, lParam
);
6847 case TB_SETBUTTONWIDTH
:
6848 return TOOLBAR_SetButtonWidth (hwnd
, lParam
);
6851 return TOOLBAR_SetCmdId (hwnd
, wParam
, lParam
);
6853 case TB_SETDISABLEDIMAGELIST
:
6854 return TOOLBAR_SetDisabledImageList (hwnd
, wParam
, lParam
);
6856 case TB_SETDRAWTEXTFLAGS
:
6857 return TOOLBAR_SetDrawTextFlags (hwnd
, wParam
, lParam
);
6859 case TB_SETEXTENDEDSTYLE
:
6860 return TOOLBAR_SetExtendedStyle (hwnd
, lParam
);
6862 case TB_SETHOTIMAGELIST
:
6863 return TOOLBAR_SetHotImageList (hwnd
, wParam
, lParam
);
6866 return TOOLBAR_SetHotItem (hwnd
, wParam
);
6868 case TB_SETIMAGELIST
:
6869 return TOOLBAR_SetImageList (hwnd
, wParam
, lParam
);
6872 return TOOLBAR_SetIndent (hwnd
, wParam
);
6874 case TB_SETINSERTMARK
:
6875 return TOOLBAR_SetInsertMark (hwnd
, lParam
);
6877 case TB_SETINSERTMARKCOLOR
:
6878 return TOOLBAR_SetInsertMarkColor (hwnd
, lParam
);
6880 case TB_SETMAXTEXTROWS
:
6881 return TOOLBAR_SetMaxTextRows (hwnd
, wParam
);
6884 return TOOLBAR_SetPadding (hwnd
, lParam
);
6887 return TOOLBAR_SetParent (hwnd
, wParam
);
6890 return TOOLBAR_SetRows (hwnd
, wParam
, lParam
);
6893 return TOOLBAR_SetState (hwnd
, wParam
, lParam
);
6896 return TOOLBAR_SetStyle (hwnd
, lParam
);
6898 case TB_SETTOOLTIPS
:
6899 return TOOLBAR_SetToolTips (hwnd
, wParam
, lParam
);
6901 case TB_SETUNICODEFORMAT
:
6902 return TOOLBAR_SetUnicodeFormat (hwnd
, wParam
);
6905 return TOOLBAR_Unkwn45D(hwnd
, wParam
, lParam
);
6907 case TB_SETHOTITEM2
:
6908 return TOOLBAR_SetHotItem2 (hwnd
, wParam
, lParam
);
6911 return TOOLBAR_SetListGap(hwnd
, wParam
);
6913 case TB_GETIMAGELISTCOUNT
:
6914 return TOOLBAR_GetImageListCount(hwnd
, wParam
, lParam
);
6916 case TB_GETIDEALSIZE
:
6917 return TOOLBAR_GetIdealSize (hwnd
, wParam
, lParam
);
6920 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6922 /* Common Control Messages */
6924 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6925 case CCM_GETCOLORSCHEME
:
6926 return TOOLBAR_GetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
6928 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6929 case CCM_SETCOLORSCHEME
:
6930 return TOOLBAR_SetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
6932 case CCM_GETVERSION
:
6933 return TOOLBAR_GetVersion (hwnd
);
6935 case CCM_SETVERSION
:
6936 return TOOLBAR_SetVersion (hwnd
, (INT
)wParam
);
6942 return TOOLBAR_Create (hwnd
, lParam
);
6945 return TOOLBAR_Destroy (hwnd
);
6948 return TOOLBAR_EraseBackground (hwnd
, wParam
, lParam
);
6951 return TOOLBAR_GetFont (hwnd
);
6954 return TOOLBAR_KeyDown (hwnd
, wParam
, lParam
);
6956 /* case WM_KILLFOCUS: */
6958 case WM_LBUTTONDBLCLK
:
6959 return TOOLBAR_LButtonDblClk (hwnd
, wParam
, lParam
);
6961 case WM_LBUTTONDOWN
:
6962 return TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
6965 return TOOLBAR_LButtonUp (hwnd
, wParam
, lParam
);
6968 return TOOLBAR_RButtonUp (hwnd
, wParam
, lParam
);
6970 case WM_RBUTTONDBLCLK
:
6971 return TOOLBAR_RButtonDblClk (hwnd
, wParam
, lParam
);
6974 return TOOLBAR_MouseMove (hwnd
, wParam
, lParam
);
6977 return TOOLBAR_MouseLeave (hwnd
);
6979 case WM_CAPTURECHANGED
:
6980 return TOOLBAR_CaptureChanged(hwnd
);
6983 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6986 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6989 return TOOLBAR_NCCreate (hwnd
, wParam
, lParam
);
6992 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
6995 return TOOLBAR_Notify (hwnd
, lParam
);
6997 case WM_NOTIFYFORMAT
:
6998 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
7000 case WM_PRINTCLIENT
:
7002 return TOOLBAR_Paint (hwnd
, wParam
);
7005 return TOOLBAR_SetFocus (hwnd
);
7008 return TOOLBAR_SetFont(hwnd
, wParam
, lParam
);
7011 return TOOLBAR_SetRedraw (hwnd
, wParam
);
7014 return TOOLBAR_Size (hwnd
);
7016 case WM_STYLECHANGED
:
7017 return TOOLBAR_StyleChanged (hwnd
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
7019 case WM_SYSCOLORCHANGE
:
7020 return TOOLBAR_SysColorChange ();
7022 case WM_THEMECHANGED
:
7023 return theme_changed (hwnd
);
7025 /* case WM_WININICHANGE: */
7030 case WM_MEASUREITEM
:
7032 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
7034 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7035 case PGM_FORWARDMOUSE
:
7036 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7039 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
7040 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
7041 uMsg
, wParam
, lParam
);
7042 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7048 TOOLBAR_Register (void)
7052 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
7053 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
7054 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
7055 wndClass
.cbClsExtra
= 0;
7056 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
7057 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
7058 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
7059 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
7061 RegisterClassW (&wndClass
);
7066 TOOLBAR_Unregister (void)
7068 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
7071 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
7076 /* Check if the entry already exists */
7077 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
7079 /* If this is a new entry we must create it and insert into the array */
7084 c
= Alloc(sizeof(IMLENTRY
));
7087 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
7088 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
7103 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
7107 for (i
= 0; i
< *cies
; i
++)
7117 static PIMLENTRY
TOOLBAR_GetImageListEntry(const PIMLENTRY
*pies
, INT cies
, INT id
)
7125 for (i
= 0; i
< cies
; i
++)
7127 if (pies
[i
]->id
== id
)
7139 static HIMAGELIST
TOOLBAR_GetImageList(const PIMLENTRY
*pies
, INT cies
, INT id
)
7141 HIMAGELIST himlDef
= 0;
7142 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
7145 himlDef
= pie
->himl
;
7151 static BOOL
TOOLBAR_GetButtonInfo(const TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
7153 if (infoPtr
->bUnicode
)
7154 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
7161 nmtba
.iItem
= nmtb
->iItem
;
7162 nmtba
.pszText
= Buffer
;
7163 nmtba
.cchText
= 256;
7164 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
7166 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
7168 int ccht
= strlen(nmtba
.pszText
);
7170 MultiByteToWideChar(CP_ACP
, 0, nmtba
.pszText
, -1,
7171 nmtb
->pszText
, nmtb
->cchText
);
7173 nmtb
->tbButton
= nmtba
.tbButton
;
7182 static BOOL
TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO
*infoPtr
, int iItem
, PCUSTOMBUTTON btnInfo
)
7186 /* MSDN states that iItem is the index of the button, rather than the
7187 * command ID as used by every other NMTOOLBAR notification */
7189 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
7191 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);