4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
38 * - TB_INSERTMARKHITTEST
46 * - Button wrapping (under construction).
48 * - iListGap custom draw support.
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
79 #include "wine/unicode.h"
85 #include "wine/debug.h"
87 WINE_DEFAULT_DEBUG_CHANNEL(toolbar
);
89 static HCURSOR hCursorDrag
= NULL
;
98 BYTE bDropDownPressed
;
103 INT cx
; /* manually set size */
117 } IMLENTRY
, *PIMLENTRY
;
121 DWORD dwStructSize
; /* size of TBBUTTON struct */
122 INT nWidth
; /* width of the toolbar */
124 RECT rcBound
; /* bounding rectangle */
130 INT nRows
; /* number of button rows */
131 INT nMaxTextRows
; /* maximum number of text rows */
132 INT cxMin
; /* minimum button width */
133 INT cxMax
; /* maximum button width */
134 INT nNumButtons
; /* number of buttons */
135 INT nNumBitmaps
; /* number of bitmaps */
136 INT nNumStrings
; /* number of strings */
138 INT nButtonDown
; /* toolbar button being pressed or -1 if none */
139 INT nButtonDrag
; /* toolbar button being dragged or -1 if none */
141 INT nHotItem
; /* index of the "hot" item */
142 DWORD dwBaseCustDraw
; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
143 DWORD dwItemCDFlag
; /* TBCDRF_ flags from last ITEMPREPAINT */
144 SIZE szPadding
; /* padding values around button */
145 INT iListGap
; /* default gap between text and image for toolbar with list style */
147 HFONT hFont
; /* text font */
148 HIMAGELIST himlInt
; /* image list created internally */
149 PIMLENTRY
*himlDef
; /* default image list array */
150 INT cimlDef
; /* default image list array count */
151 PIMLENTRY
*himlHot
; /* hot image list array */
152 INT cimlHot
; /* hot image list array count */
153 PIMLENTRY
*himlDis
; /* disabled image list array */
154 INT cimlDis
; /* disabled image list array count */
155 HWND hwndToolTip
; /* handle to tool tip control */
156 HWND hwndNotify
; /* handle to the window that gets notifications */
157 HWND hwndSelf
; /* my own handle */
158 BOOL bAnchor
; /* anchor highlight enabled */
159 BOOL bDoRedraw
; /* Redraw status */
160 BOOL bDragOutSent
; /* has TBN_DRAGOUT notification been sent for this drag? */
161 BOOL bUnicode
; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
162 BOOL bCaptured
; /* mouse captured? */
163 DWORD dwStyle
; /* regular toolbar style */
164 DWORD dwExStyle
; /* extended toolbar style */
165 DWORD dwDTFlags
; /* DrawText flags */
167 COLORREF clrInsertMark
; /* insert mark color */
168 COLORREF clrBtnHighlight
; /* color for Flat Separator */
169 COLORREF clrBtnShadow
; /* color for Flag Separator */
171 LPWSTR pszTooltipText
; /* temporary store for a string > 80 characters
172 * for TTN_GETDISPINFOW notification */
173 TBINSERTMARK tbim
; /* info on insertion mark */
174 TBUTTON_INFO
*buttons
; /* pointer to button array */
175 LPWSTR
*strings
; /* pointer to string array */
176 TBITMAP_INFO
*bitmaps
;
177 } TOOLBAR_INFO
, *PTOOLBAR_INFO
;
180 /* used by customization dialog */
183 PTOOLBAR_INFO tbInfo
;
185 } CUSTDLG_INFO
, *PCUSTDLG_INFO
;
193 } CUSTOMBUTTON
, *PCUSTOMBUTTON
;
202 #define SEPARATOR_WIDTH 8
204 #define BOTTOM_BORDER 2
205 #define DDARROW_WIDTH 11
206 #define ARROW_HEIGHT 3
207 #define INSERTMARK_WIDTH 2
213 /* vertical padding used in list mode when image is present */
216 /* how wide to treat the bitmap if it isn't present */
217 #define NONLIST_NOTEXT_OFFSET 2
219 #define TOOLBAR_NOWHERE (-1)
221 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
222 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
223 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
225 /* Used to find undocumented extended styles */
226 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
227 TBSTYLE_EX_UNDOC1 | \
228 TBSTYLE_EX_MIXEDBUTTONS | \
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(TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
);
244 static BOOL
TOOLBAR_IsButtonRemovable(TOOLBAR_INFO
*infoPtr
, int iItem
, PCUSTOMBUTTON btnInfo
);
245 static HIMAGELIST
TOOLBAR_GetImageList(PIMLENTRY
*pies
, INT cies
, INT id
);
246 static PIMLENTRY
TOOLBAR_GetImageListEntry(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 LRESULT
TOOLBAR_AutoSize(HWND hwnd
);
252 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
);
253 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*button
);
256 TOOLBAR_NotifyFormat(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
);
260 TOOLBAR_GetText(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
262 LPWSTR lpText
= NULL
;
264 /* NOTE: iString == -1 is undocumented */
265 if ((HIWORD(btnPtr
->iString
) != 0) && (btnPtr
->iString
!= -1))
266 lpText
= (LPWSTR
)btnPtr
->iString
;
267 else if ((btnPtr
->iString
>= 0) && (btnPtr
->iString
< infoPtr
->nNumStrings
))
268 lpText
= infoPtr
->strings
[btnPtr
->iString
];
274 TOOLBAR_DumpButton(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*bP
, INT btn_num
, BOOL internal
)
276 if (TRACE_ON(toolbar
)){
277 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
278 btn_num
, bP
->idCommand
, GETIBITMAP(infoPtr
, bP
->iBitmap
),
279 bP
->fsState
, bP
->fsStyle
, bP
->dwData
, bP
->iString
);
280 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr
,bP
)));
282 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
283 btn_num
, bP
->idCommand
,
284 (bP
->bHot
) ? "TRUE":"FALSE", bP
->nRow
,
285 bP
->rect
.left
, bP
->rect
.top
,
286 bP
->rect
.right
, bP
->rect
.bottom
);
292 TOOLBAR_DumpToolbar(TOOLBAR_INFO
*iP
, INT line
)
294 if (TRACE_ON(toolbar
)) {
297 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
299 iP
->dwExStyle
, iP
->nNumButtons
, iP
->nNumBitmaps
,
300 iP
->nNumStrings
, iP
->dwStyle
);
301 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
303 iP
->himlInt
, iP
->himlDef
, iP
->himlHot
, iP
->himlDis
,
304 (iP
->bDoRedraw
) ? "TRUE" : "FALSE");
305 for(i
=0; i
<iP
->nNumButtons
; i
++) {
306 TOOLBAR_DumpButton(iP
, &iP
->buttons
[i
], i
, TRUE
);
312 /***********************************************************************
315 * This function validates that the styles set are implemented and
316 * issues FIXME's warning of possible problems. In a perfect world this
317 * function should be null.
320 TOOLBAR_CheckStyle (HWND hwnd
, DWORD dwStyle
)
322 if (dwStyle
& TBSTYLE_REGISTERDROP
)
323 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd
);
328 TOOLBAR_SendNotify (NMHDR
*nmhdr
, TOOLBAR_INFO
*infoPtr
, UINT code
)
330 if(!IsWindow(infoPtr
->hwndSelf
))
331 return 0; /* we have just been destroyed */
333 nmhdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
334 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
337 TRACE("to window %p, code=%08x, %s\n", infoPtr
->hwndNotify
, code
,
338 (infoPtr
->bUnicode
) ? "via Unicode" : "via ANSI");
340 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
341 (WPARAM
)nmhdr
->idFrom
, (LPARAM
)nmhdr
);
344 /***********************************************************************
345 * TOOLBAR_GetBitmapIndex
347 * This function returns the bitmap index associated with a button.
348 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
349 * is issued to retrieve the index.
352 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
354 INT ret
= btnPtr
->iBitmap
;
356 if (ret
== I_IMAGECALLBACK
)
358 /* issue TBN_GETDISPINFO */
361 memset(&nmgd
, 0, sizeof(nmgd
));
362 nmgd
.idCommand
= btnPtr
->idCommand
;
363 nmgd
.lParam
= btnPtr
->dwData
;
364 nmgd
.dwMask
= TBNF_IMAGE
;
365 TOOLBAR_SendNotify(&nmgd
.hdr
, infoPtr
,
366 infoPtr
->bUnicode
? TBN_GETDISPINFOW
: TBN_GETDISPINFOA
);
367 if (nmgd
.dwMask
& TBNF_DI_SETITEM
)
368 btnPtr
->iBitmap
= nmgd
.iImage
;
370 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
371 ret
, nmgd
.dwMask
, infoPtr
->nNumBitmaps
);
374 if (ret
!= I_IMAGENONE
)
375 ret
= GETIBITMAP(infoPtr
, ret
);
382 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO
*infoPtr
, INT index
)
385 INT id
= GETHIMLID(infoPtr
, index
);
386 INT iBitmap
= GETIBITMAP(infoPtr
, index
);
388 if (((himl
= GETDEFIMAGELIST(infoPtr
, id
)) &&
389 iBitmap
>= 0 && iBitmap
< ImageList_GetImageCount(himl
)) ||
390 (index
== I_IMAGECALLBACK
))
398 TOOLBAR_IsValidImageList(TOOLBAR_INFO
*infoPtr
, INT index
)
400 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, index
));
401 return (himl
!= NULL
) && (ImageList_GetImageCount(himl
) > 0);
405 /***********************************************************************
406 * TOOLBAR_GetImageListForDrawing
408 * This function validates the bitmap index (including I_IMAGECALLBACK
409 * functionality) and returns the corresponding image list.
412 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, IMAGE_LIST_TYPE imagelist
, INT
* index
)
416 if (!TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
)) {
417 if (btnPtr
->iBitmap
== I_IMAGENONE
) return NULL
;
418 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
419 HIWORD(btnPtr
->iBitmap
), LOWORD(btnPtr
->iBitmap
), infoPtr
->nNumBitmaps
);
423 if ((*index
= TOOLBAR_GetBitmapIndex(infoPtr
, btnPtr
)) < 0) {
424 if ((*index
== I_IMAGECALLBACK
) ||
425 (*index
== I_IMAGENONE
)) return NULL
;
426 ERR("TBN_GETDISPINFO returned invalid index %d\n",
433 case IMAGE_LIST_DEFAULT
:
434 himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
437 himl
= GETHOTIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
439 case IMAGE_LIST_DISABLED
:
440 himl
= GETDISIMAGELIST(infoPtr
, GETHIMLID(infoPtr
, btnPtr
->iBitmap
));
444 FIXME("Shouldn't reach here\n");
448 TRACE("no image list\n");
455 TOOLBAR_DrawFlatSeparator (LPRECT lpRect
, HDC hdc
, TOOLBAR_INFO
*infoPtr
)
458 COLORREF oldcolor
, newcolor
;
460 myrect
.left
= (lpRect
->left
+ lpRect
->right
) / 2 - 1;
461 myrect
.right
= myrect
.left
+ 1;
462 myrect
.top
= lpRect
->top
+ 2;
463 myrect
.bottom
= lpRect
->bottom
- 2;
465 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
466 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
467 oldcolor
= SetBkColor (hdc
, newcolor
);
468 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
470 myrect
.left
= myrect
.right
;
471 myrect
.right
= myrect
.left
+ 1;
473 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
474 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
475 SetBkColor (hdc
, newcolor
);
476 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
478 SetBkColor (hdc
, oldcolor
);
482 /***********************************************************************
483 * TOOLBAR_DrawDDFlatSeparator
485 * This function draws the separator that was flagged as BTNS_DROPDOWN.
486 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
487 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
488 * are horizontal as opposed to the vertical separators for not dropdown
491 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
494 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect
, HDC hdc
, TBUTTON_INFO
*btnPtr
, TOOLBAR_INFO
*infoPtr
)
497 COLORREF oldcolor
, newcolor
;
499 myrect
.left
= lpRect
->left
;
500 myrect
.right
= lpRect
->right
;
501 myrect
.top
= lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
- 2)/2;
502 myrect
.bottom
= myrect
.top
+ 1;
504 InflateRect (&myrect
, -2, 0);
506 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
507 myrect
.left
, myrect
.top
, myrect
.right
, myrect
.bottom
);
509 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
510 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
511 oldcolor
= SetBkColor (hdc
, newcolor
);
512 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
514 myrect
.top
= myrect
.bottom
;
515 myrect
.bottom
= myrect
.top
+ 1;
517 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
518 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
519 SetBkColor (hdc
, newcolor
);
520 ExtTextOutW (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
522 SetBkColor (hdc
, oldcolor
);
527 TOOLBAR_DrawArrow (HDC hdc
, INT left
, INT top
, COLORREF clr
)
532 if (!(hPen
= CreatePen( PS_SOLID
, 1, clr
))) return;
533 hOldPen
= SelectObject ( hdc
, hPen
);
536 MoveToEx (hdc
, x
, y
, NULL
);
537 LineTo (hdc
, x
+5, y
++); x
++;
538 MoveToEx (hdc
, x
, y
, NULL
);
539 LineTo (hdc
, x
+3, y
++); x
++;
540 MoveToEx (hdc
, x
, y
, NULL
);
541 LineTo (hdc
, x
+1, y
++);
542 SelectObject( hdc
, hOldPen
);
543 DeleteObject( hPen
);
547 * Draw the text string for this button.
548 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
549 * is non-zero, so we can simply check himlDef to see if we have
553 TOOLBAR_DrawString (TOOLBAR_INFO
*infoPtr
, RECT
*rcText
, LPWSTR lpText
,
554 NMTBCUSTOMDRAW
*tbcd
)
556 HDC hdc
= tbcd
->nmcd
.hdc
;
559 COLORREF clrOldBk
= 0;
561 UINT state
= tbcd
->nmcd
.uItemState
;
565 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText
),
566 rcText
->left
, rcText
->top
, rcText
->right
, rcText
->bottom
);
568 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
569 if ((state
& CDIS_HOT
) && (infoPtr
->dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)) {
570 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
572 else if (state
& CDIS_DISABLED
) {
573 clrOld
= SetTextColor (hdc
, tbcd
->clrBtnHighlight
);
574 OffsetRect (rcText
, 1, 1);
575 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
576 SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
577 OffsetRect (rcText
, -1, -1);
579 else if (state
& CDIS_INDETERMINATE
) {
580 clrOld
= SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
582 else if ((state
& CDIS_MARKED
) && !(infoPtr
->dwItemCDFlag
& TBCDRF_NOMARK
)) {
583 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
584 clrOldBk
= SetBkColor (hdc
, tbcd
->clrMark
);
585 oldBkMode
= SetBkMode (hdc
, tbcd
->nHLStringBkMode
);
588 clrOld
= SetTextColor (hdc
, tbcd
->clrText
);
591 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
592 SetTextColor (hdc
, clrOld
);
593 if ((state
& CDIS_MARKED
) && !(infoPtr
->dwItemCDFlag
& TBCDRF_NOMARK
))
595 SetBkColor (hdc
, clrOldBk
);
596 SetBkMode (hdc
, oldBkMode
);
598 SelectObject (hdc
, hOldFont
);
604 TOOLBAR_DrawPattern (LPRECT lpRect
, NMTBCUSTOMDRAW
*tbcd
)
606 HDC hdc
= tbcd
->nmcd
.hdc
;
607 HBRUSH hbr
= SelectObject (hdc
, tbcd
->hbrMonoDither
);
610 INT cx
= lpRect
->right
- lpRect
->left
;
611 INT cy
= lpRect
->bottom
- lpRect
->top
;
612 INT cxEdge
= GetSystemMetrics(SM_CXEDGE
);
613 INT cyEdge
= GetSystemMetrics(SM_CYEDGE
);
614 clrTextOld
= SetTextColor(hdc
, tbcd
->clrBtnHighlight
);
615 clrBkOld
= SetBkColor(hdc
, tbcd
->clrBtnFace
);
616 PatBlt (hdc
, lpRect
->left
+ cxEdge
, lpRect
->top
+ cyEdge
,
617 cx
- (2 * cxEdge
), cy
- (2 * cyEdge
), PATCOPY
);
618 SetBkColor(hdc
, clrBkOld
);
619 SetTextColor(hdc
, clrTextOld
);
620 SelectObject (hdc
, hbr
);
624 static void TOOLBAR_DrawMasked(HIMAGELIST himl
, int index
, HDC hdc
, INT x
, INT y
, UINT draw_flags
)
627 HBITMAP hbmMask
, hbmImage
;
628 HDC hdcMask
, hdcImage
;
630 ImageList_GetIconSize(himl
, &cx
, &cy
);
632 /* Create src image */
633 hdcImage
= CreateCompatibleDC(hdc
);
634 hbmImage
= CreateCompatibleBitmap(hdc
, cx
, cy
);
635 SelectObject(hdcImage
, hbmImage
);
636 ImageList_DrawEx(himl
, index
, hdcImage
, 0, 0, cx
, cy
,
637 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags
);
640 hdcMask
= CreateCompatibleDC(0);
641 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
642 SelectObject(hdcMask
, hbmMask
);
644 /* Remove the background and all white pixels */
645 ImageList_DrawEx(himl
, index
, hdcMask
, 0, 0, cx
, cy
,
646 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK
);
647 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
648 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
650 /* draw the new mask 'etched' to hdc */
651 SetBkColor(hdc
, RGB(255, 255, 255));
652 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
653 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
654 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
655 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
656 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
659 DeleteObject(hbmImage
);
661 DeleteObject (hbmMask
);
667 TOOLBAR_TranslateState(TBUTTON_INFO
*btnPtr
)
671 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
672 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
673 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
674 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
675 retstate
|= (btnPtr
->bHot
) ? CDIS_HOT
: 0;
676 retstate
|= ((btnPtr
->fsState
& (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) == (TBSTATE_ENABLED
|TBSTATE_INDETERMINATE
)) ? CDIS_INDETERMINATE
: 0;
677 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
681 /* draws the image on a toolbar button */
683 TOOLBAR_DrawImage(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
, const NMTBCUSTOMDRAW
*tbcd
)
685 HIMAGELIST himl
= NULL
;
686 BOOL draw_masked
= FALSE
;
689 UINT draw_flags
= ILD_TRANSPARENT
;
691 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
693 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
696 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
700 else if (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
||
701 ((tbcd
->nmcd
.uItemState
& CDIS_HOT
)
702 && ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))))
704 /* if hot, attempt to draw with hot image list, if fails,
705 use default image list */
706 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
708 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
711 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
716 if (!(infoPtr
->dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
717 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
720 if (!(infoPtr
->dwItemCDFlag
& TBCDRF_NOMARK
) &&
721 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
722 draw_flags
|= ILD_BLEND50
;
724 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
725 index
, himl
, left
, top
, offset
);
728 TOOLBAR_DrawMasked (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
730 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
733 /* draws a blank frame for a toolbar button */
735 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
)
737 HDC hdc
= tbcd
->nmcd
.hdc
;
738 RECT rc
= tbcd
->nmcd
.rc
;
739 /* if the state is disabled or indeterminate then the button
740 * cannot have an interactive look like pressed or hot */
741 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
742 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
743 BOOL pressed_look
= !non_interactive_state
&&
744 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
745 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
747 /* app don't want us to draw any edges */
748 if (infoPtr
->dwItemCDFlag
& TBCDRF_NOEDGES
)
751 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
754 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
755 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
756 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
761 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
763 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
764 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
769 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
, BOOL bDropDownPressed
)
771 HDC hdc
= tbcd
->nmcd
.hdc
;
773 BOOL pressed
= bDropDownPressed
||
774 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
));
776 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
779 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
);
780 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
781 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
782 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
783 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
788 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
790 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
791 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
795 offset
= (infoPtr
->dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
797 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
799 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
800 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
803 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
806 /* draws a complete toolbar button */
808 TOOLBAR_DrawButton (HWND hwnd
, TBUTTON_INFO
*btnPtr
, HDC hdc
)
810 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
811 DWORD dwStyle
= infoPtr
->dwStyle
;
812 BOOL hasDropDownArrow
= (TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) &&
813 (btnPtr
->fsStyle
& BTNS_DROPDOWN
)) ||
814 (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
815 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
816 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
817 RECT rc
, rcArrow
, rcBitmap
, rcText
;
818 LPWSTR lpText
= NULL
;
823 DWORD dwItemCustDraw
;
824 HTHEME theme
= GetWindowTheme (hwnd
);
827 CopyRect (&rcArrow
, &rc
);
829 /* separator - doesn't send NM_CUSTOMDRAW */
830 if (btnPtr
->fsStyle
& BTNS_SEP
) {
833 DrawThemeBackground (theme
, hdc
,
834 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
838 /* with the FLAT style, iBitmap is the width and has already */
839 /* been taken into consideration in calculating the width */
840 /* so now we need to draw the vertical separator */
841 /* empirical tests show that iBitmap can/will be non-zero */
842 /* when drawing the vertical bar... */
843 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
844 if (btnPtr
->fsStyle
& BTNS_DROPDOWN
)
845 TOOLBAR_DrawDDFlatSeparator (&rc
, hdc
, btnPtr
, infoPtr
);
847 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
849 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
850 FIXME("Draw some kind of separator: fsStyle=%x\n",
856 /* get a pointer to the text */
857 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
859 if (hasDropDownArrow
)
863 if (dwStyle
& TBSTYLE_FLAT
)
864 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
866 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
868 if (drawSepDropDownArrow
)
871 rcArrow
.left
= right
;
874 /* copy text & bitmap rects after adjusting for drop-down arrow
875 * so that text & bitmap is centred in the rectangle not containing
877 CopyRect(&rcText
, &rc
);
878 CopyRect(&rcBitmap
, &rc
);
880 /* Center the bitmap horizontally and vertically */
881 if (dwStyle
& TBSTYLE_LIST
)
884 infoPtr
->nMaxTextRows
> 0 &&
885 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
886 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
887 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
889 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
892 rcBitmap
.left
+= (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2;
894 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
896 TRACE("iBitmap=%d, start=(%ld,%ld) w=%d, h=%d\n",
897 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
898 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
899 TRACE("Text=%s\n", debugstr_w(lpText
));
900 TRACE("iListGap=%d, padding = { %ld, %ld }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
902 /* calculate text position */
905 rcText
.left
+= GetSystemMetrics(SM_CXEDGE
);
906 rcText
.right
-= GetSystemMetrics(SM_CXEDGE
);
907 if (dwStyle
& TBSTYLE_LIST
)
909 if (TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
))
910 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
914 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
915 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
917 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
921 /* Initialize fields in all cases, because we use these later
922 * NOTE: applications can and do alter these to customize their
924 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
925 tbcd
.clrText
= comctl32_color
.clrBtnText
;
926 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
927 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
928 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
929 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
930 tbcd
.clrHighlightHotTrack
= 0;
931 tbcd
.nStringBkMode
= TRANSPARENT
;
932 tbcd
.nHLStringBkMode
= OPAQUE
;
933 /* MSDN says that this is the text rectangle.
934 * But (why always a but) tracing of v5.7 of native shows
935 * that this is really a *relative* rectangle based on the
936 * the nmcd.rc. Also the left and top are always 0 ignoring
937 * any bitmap that might be present. */
938 tbcd
.rcText
.left
= 0;
940 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
941 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
942 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
945 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
947 /* FIXME: what are these used for? */
951 /* Issue Item Prepaint notify */
953 infoPtr
->dwItemCDFlag
= 0;
954 if (infoPtr
->dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
956 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
957 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
958 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
959 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
960 /* reset these fields so the user can't alter the behaviour like native */
964 dwItemCustDraw
= ntfret
& 0xffff;
965 infoPtr
->dwItemCDFlag
= ntfret
& 0xffff0000;
966 if (dwItemCustDraw
& CDRF_SKIPDEFAULT
)
968 /* save the only part of the rect that the user can change */
969 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
970 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
973 if (!(infoPtr
->dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
974 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
975 OffsetRect(&rcText
, 1, 1);
977 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
978 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
979 TOOLBAR_DrawPattern (&rc
, &tbcd
);
981 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
982 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
984 if ( infoPtr
->dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
988 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
989 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
990 if (hasDropDownArrow
)
991 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
992 SetBkColor(hdc
, oldclr
);
998 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
999 int stateId
= TS_NORMAL
;
1001 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1002 stateId
= TS_DISABLED
;
1003 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1004 stateId
= TS_PRESSED
;
1005 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1006 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1007 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1008 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1011 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &tbcd
.nmcd
.rc
, NULL
);
1014 TOOLBAR_DrawFrame(infoPtr
, &tbcd
);
1016 if (drawSepDropDownArrow
)
1020 int stateId
= TS_NORMAL
;
1022 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1023 stateId
= TS_DISABLED
;
1024 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1025 stateId
= TS_PRESSED
;
1026 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1027 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1028 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1031 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1032 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1035 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
);
1038 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1039 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1040 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
);
1041 SetBkMode (hdc
, oldBkMode
);
1043 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
);
1045 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1047 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1049 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1050 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1052 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1054 offset
= (infoPtr
->dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1055 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1058 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1061 if (dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1063 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1064 TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1071 TOOLBAR_Refresh (HWND hwnd
, HDC hdc
, PAINTSTRUCT
* ps
)
1073 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1074 TBUTTON_INFO
*btnPtr
;
1076 RECT rcTemp
, rcClient
;
1077 NMTBCUSTOMDRAW tbcd
;
1080 /* the app has told us not to redraw the toolbar */
1081 if (!infoPtr
->bDoRedraw
)
1084 /* if imagelist belongs to the app, it can be changed
1085 by the app after setting it */
1086 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1088 infoPtr
->nNumBitmaps
= 0;
1089 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1090 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1093 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1095 /* change the imagelist icon size if we manage the list and it is necessary */
1096 TOOLBAR_CheckImageListIconSize(infoPtr
);
1098 /* Send initial notify */
1099 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1100 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1101 tbcd
.nmcd
.hdc
= hdc
;
1102 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1103 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1104 infoPtr
->dwBaseCustDraw
= ntfret
& 0xffff;
1106 GetClientRect(hwnd
, &rcClient
);
1108 /* redraw necessary buttons */
1109 btnPtr
= infoPtr
->buttons
;
1110 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1113 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1115 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1116 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1120 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1121 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1123 TOOLBAR_DrawButton (hwnd
, btnPtr
, hdc
);
1126 /* draw insert mark if required */
1127 if (infoPtr
->tbim
.iButton
!= -1)
1129 RECT rcButton
= infoPtr
->buttons
[infoPtr
->tbim
.iButton
].rect
;
1131 rcInsertMark
.top
= rcButton
.top
;
1132 rcInsertMark
.bottom
= rcButton
.bottom
;
1133 if (infoPtr
->tbim
.dwFlags
& TBIMHT_AFTER
)
1134 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.right
;
1136 rcInsertMark
.left
= rcInsertMark
.right
= rcButton
.left
- INSERTMARK_WIDTH
;
1137 COMCTL32_DrawInsertMark(hdc
, &rcInsertMark
, infoPtr
->clrInsertMark
, FALSE
);
1140 if (infoPtr
->dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1142 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1143 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1144 tbcd
.nmcd
.hdc
= hdc
;
1145 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1146 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
1150 /***********************************************************************
1151 * TOOLBAR_MeasureString
1153 * This function gets the width and height of a string in pixels. This
1154 * is done first by using GetTextExtentPoint to get the basic width
1155 * and height. The DrawText is called with DT_CALCRECT to get the exact
1156 * width. The reason is because the text may have more than one "&" (or
1157 * prefix characters as M$ likes to call them). The prefix character
1158 * indicates where the underline goes, except for the string "&&" which
1159 * is reduced to a single "&". GetTextExtentPoint does not process these
1160 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1163 TOOLBAR_MeasureString(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
,
1164 HDC hdc
, LPSIZE lpSize
)
1171 if (infoPtr
->nMaxTextRows
> 0 &&
1172 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1173 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1174 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1176 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1178 if(lpText
!= NULL
) {
1179 /* first get size of all the text */
1180 GetTextExtentPoint32W (hdc
, lpText
, strlenW (lpText
), lpSize
);
1182 /* feed above size into the rectangle for DrawText */
1183 myrect
.left
= myrect
.top
= 0;
1184 myrect
.right
= lpSize
->cx
;
1185 myrect
.bottom
= lpSize
->cy
;
1187 /* Use DrawText to get true size as drawn (less pesky "&") */
1188 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1189 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1192 /* feed back to caller */
1193 lpSize
->cx
= myrect
.right
;
1194 lpSize
->cy
= myrect
.bottom
;
1198 TRACE("string size %ld x %ld!\n", lpSize
->cx
, lpSize
->cy
);
1201 /***********************************************************************
1202 * TOOLBAR_CalcStrings
1204 * This function walks through each string and measures it and returns
1205 * the largest height and width to caller.
1208 TOOLBAR_CalcStrings (HWND hwnd
, LPSIZE lpSize
)
1210 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1211 TBUTTON_INFO
*btnPtr
;
1220 if (infoPtr
->nMaxTextRows
== 0)
1224 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1226 if (infoPtr
->nNumButtons
== 0)
1230 GetTextMetricsW(hdc
, &tm
);
1231 lpSize
->cy
= tm
.tmHeight
;
1234 btnPtr
= infoPtr
->buttons
;
1235 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1236 if(TOOLBAR_HasText(infoPtr
, btnPtr
))
1238 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1239 if (sz
.cx
> lpSize
->cx
)
1241 if (sz
.cy
> lpSize
->cy
)
1246 SelectObject (hdc
, hOldFont
);
1247 ReleaseDC (hwnd
, hdc
);
1249 TRACE("max string size %ld x %ld!\n", lpSize
->cx
, lpSize
->cy
);
1252 /***********************************************************************
1253 * TOOLBAR_WrapToolbar
1255 * This function walks through the buttons and separators in the
1256 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1257 * wrapping should occur based on the width of the toolbar window.
1258 * It does *not* calculate button placement itself. That task
1259 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1260 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1261 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1263 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1264 * vertical toolbar lists.
1268 TOOLBAR_WrapToolbar( HWND hwnd
, DWORD dwStyle
)
1270 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1271 TBUTTON_INFO
*btnPtr
;
1274 BOOL bWrap
, bButtonWrap
;
1276 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1277 /* no layout is necessary. Applications may use this style */
1278 /* to perform their own layout on the toolbar. */
1279 if( !(dwStyle
& TBSTYLE_WRAPABLE
) &&
1280 !(infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
) ) return;
1282 btnPtr
= infoPtr
->buttons
;
1283 x
= infoPtr
->nIndent
;
1285 if (GetParent(hwnd
))
1287 /* this can get the parents width, to know how far we can extend
1288 * this toolbar. We cannot use its height, as there may be multiple
1289 * toolbars in a rebar control
1291 GetClientRect( GetParent(hwnd
), &rc
);
1292 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1296 GetWindowRect( hwnd
, &rc
);
1297 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1300 bButtonWrap
= FALSE
;
1302 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1303 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, infoPtr
->nWidth
,
1306 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1309 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1311 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1314 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1315 /* it is the actual width of the separator. This is used for */
1316 /* custom controls in toolbars. */
1318 /* BTNS_DROPDOWN separators are treated as buttons for */
1319 /* width. - GA 8/01 */
1320 if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1321 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
))
1322 cx
= (btnPtr
[i
].iBitmap
> 0) ?
1323 btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1325 cx
= infoPtr
->nButtonWidth
;
1327 /* Two or more adjacent separators form a separator group. */
1328 /* The first separator in a group should be wrapped to the */
1329 /* next row if the previous wrapping is on a button. */
1331 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1332 (i
+ 1 < infoPtr
->nNumButtons
) &&
1333 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1335 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1336 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1337 x
= infoPtr
->nIndent
;
1339 bButtonWrap
= FALSE
;
1343 /* The layout makes sure the bitmap is visible, but not the button. */
1344 /* Test added to also wrap after a button that starts a row but */
1345 /* is bigger than the area. - GA 8/01 */
1346 if (( x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2
1347 > infoPtr
->nWidth
) ||
1348 ((x
== infoPtr
->nIndent
) && (cx
> infoPtr
->nWidth
)))
1350 BOOL bFound
= FALSE
;
1352 /* If the current button is a separator and not hidden, */
1353 /* go to the next until it reaches a non separator. */
1354 /* Wrap the last separator if it is before a button. */
1355 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1356 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1357 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1358 i
< infoPtr
->nNumButtons
)
1364 if( bFound
&& i
< infoPtr
->nNumButtons
)
1367 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1368 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1369 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1370 x
= infoPtr
->nIndent
;
1371 bButtonWrap
= FALSE
;
1374 else if ( i
>= infoPtr
->nNumButtons
)
1377 /* If the current button is not a separator, find the last */
1378 /* separator and wrap it. */
1379 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1381 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1382 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1386 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1387 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1388 x
= infoPtr
->nIndent
;
1389 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1390 bButtonWrap
= FALSE
;
1395 /* If no separator available for wrapping, wrap one of */
1396 /* non-hidden previous button. */
1400 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1402 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1407 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1408 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1409 x
= infoPtr
->nIndent
;
1410 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1416 /* If all above failed, wrap the current button. */
1419 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1420 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1421 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1423 x
= infoPtr
->nIndent
;
1424 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1425 bButtonWrap
= FALSE
;
1431 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1432 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1439 /***********************************************************************
1440 * TOOLBAR_MeasureButton
1442 * Calculates the width and height required for a button. Used in
1443 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1444 * the width of buttons that are autosized.
1446 * Note that it would have been rather elegant to use one piece of code for
1447 * both the laying out of the toolbar and for controlling where button parts
1448 * are drawn, but the native control has inconsistencies between the two that
1449 * prevent this from being effectively. These inconsistencies can be seen as
1450 * artefacts where parts of the button appear outside of the bounding button
1453 * There are several cases for the calculation of the button dimensions and
1454 * button part positioning:
1461 * +--------------------------------------------------------+ ^
1463 * | | pad.cy / 2 | centred | |
1464 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1465 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1466 * | |<------------>| | | | |
1467 * | +--------------+ +------------+ | |
1468 * |<-------------------------------------->| | |
1469 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1471 * +--------------------------------------------------------+ -
1472 * <-------------------------------------------------------->
1473 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1475 * Without Bitmap (I_IMAGENONE):
1477 * +-----------------------------------+ ^
1479 * | | centred | | LISTPAD_CY +
1480 * | +------------+ | | szText.cy
1483 * | +------------+ | |
1484 * |<----------------->| | |
1485 * | cxedge |<-----------> | |
1487 * +-----------------------------------+ -
1488 * <----------------------------------->
1489 * szText.cx + pad.cx
1493 * +--------------------------------------+ ^
1495 * | | padding.cy/2 | | DEFPAD_CY +
1496 * | +------------+ | | nBitmapHeight
1499 * | +------------+ | |
1500 * |<------------------->| | |
1501 * | cxedge + iListGap/2 |<-----------> | |
1502 * | nBitmapWidth | |
1503 * +--------------------------------------+ -
1504 * <-------------------------------------->
1505 * 2*cxedge + nBitmapWidth + iListGap
1512 * +-----------------------------------+ ^
1514 * | | pad.cy / 2 | | nBitmapHeight +
1515 * | - | | szText.cy +
1516 * | +------------+ | | DEFPAD_CY + 1
1517 * | centred | Bitmap | | |
1518 * |<----------------->| | | |
1519 * | +------------+ | |
1523 * | centred +---------------+ | |
1524 * |<--------------->| Text | | |
1525 * | +---------------+ | |
1526 * +-----------------------------------+ -
1527 * <----------------------------------->
1528 * pad.cx + max(nBitmapWidth, szText.cx)
1530 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1532 * +---------------------------------------+ ^
1534 * | | 2 + pad.cy / 2 | |
1535 * | - | | szText.cy +
1536 * | centred +-----------------+ | | pad.cy + 2
1537 * |<--------------->| Text | | |
1538 * | +-----------------+ | |
1540 * +---------------------------------------+ -
1541 * <--------------------------------------->
1542 * 2*cxedge + pad.cx + szText.cx
1545 * As for with bitmaps, but with szText.cx zero.
1547 static inline SIZE
TOOLBAR_MeasureButton(TOOLBAR_INFO
*infoPtr
, SIZE sizeString
, BOOL bHasBitmap
, BOOL bValidImageList
)
1550 if (infoPtr
->dwStyle
& TBSTYLE_LIST
)
1552 /* set button height from bitmap / text height... */
1553 sizeButton
.cy
= max((bHasBitmap
? infoPtr
->nBitmapHeight
: 0),
1556 /* ... add on the necessary padding */
1557 if (bValidImageList
)
1560 sizeButton
.cy
+= DEFPAD_CY
;
1562 sizeButton
.cy
+= LISTPAD_CY
;
1565 sizeButton
.cy
+= infoPtr
->szPadding
.cy
;
1567 /* calculate button width */
1570 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1571 infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
;
1572 if (sizeString
.cx
> 0)
1573 sizeButton
.cx
+= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1576 sizeButton
.cx
= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1582 sizeButton
.cy
= infoPtr
->nBitmapHeight
+ 1 +
1583 sizeString
.cy
+ DEFPAD_CY
;
1584 sizeButton
.cx
= infoPtr
->szPadding
.cx
+
1585 max(sizeString
.cx
, infoPtr
->nBitmapWidth
);
1589 sizeButton
.cy
= sizeString
.cy
+ infoPtr
->szPadding
.cy
+
1590 NONLIST_NOTEXT_OFFSET
;
1591 sizeButton
.cx
= 2*GetSystemMetrics(SM_CXEDGE
) +
1592 infoPtr
->szPadding
.cx
+ sizeString
.cx
;
1599 /***********************************************************************
1600 * TOOLBAR_CalcToolbar
1602 * This function calculates button and separator placement. It first
1603 * calculates the button sizes, gets the toolbar window width and then
1604 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1605 * on. It assigns a new location to each item and sends this location to
1606 * the tooltip window if appropriate. Finally, it updates the rcBound
1607 * rect and calculates the new required toolbar window height.
1610 TOOLBAR_CalcToolbar (HWND hwnd
)
1612 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
1613 DWORD dwStyle
= infoPtr
->dwStyle
;
1614 TBUTTON_INFO
*btnPtr
;
1615 INT i
, nRows
, nSepRows
;
1617 SIZE sizeString
, sizeButton
;
1619 BOOL validImageList
= FALSE
;
1620 BOOL hasDropDownArrows
= TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
);
1622 TOOLBAR_CalcStrings (hwnd
, &sizeString
);
1624 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1626 if (TOOLBAR_IsValidImageList(infoPtr
, 0))
1627 validImageList
= TRUE
;
1628 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sizeString
, TRUE
, validImageList
);
1629 infoPtr
->nButtonWidth
= sizeButton
.cx
;
1630 infoPtr
->nButtonHeight
= sizeButton
.cy
;
1632 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1633 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1634 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1635 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1637 TOOLBAR_WrapToolbar( hwnd
, dwStyle
);
1639 x
= infoPtr
->nIndent
;
1640 if (infoPtr
->dwStyle
& TBSTYLE_FLAT
)
1645 /* from above, minimum is a button, and possible text */
1646 cx
= infoPtr
->nButtonWidth
;
1647 cy
= infoPtr
->nButtonHeight
;
1649 nRows
= nSepRows
= 0;
1651 infoPtr
->rcBound
.top
= y
;
1652 infoPtr
->rcBound
.left
= x
;
1653 infoPtr
->rcBound
.bottom
= y
+ cy
;
1654 infoPtr
->rcBound
.right
= x
;
1656 btnPtr
= infoPtr
->buttons
;
1658 TRACE("cy=%d\n", cy
);
1660 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1663 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1665 SetRectEmpty (&btnPtr
->rect
);
1669 cy
= infoPtr
->nButtonHeight
;
1671 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1672 /* it is the actual width of the separator. This is used for */
1673 /* custom controls in toolbars. */
1674 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1675 if (btnPtr
->fsStyle
& BTNS_DROPDOWN
) {
1676 cy
= (btnPtr
->iBitmap
> 0) ?
1677 btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1678 cx
= infoPtr
->nButtonWidth
;
1681 cx
= (btnPtr
->iBitmap
> 0) ?
1682 btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1688 else if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1689 (btnPtr
->fsStyle
& BTNS_AUTOSIZE
))
1696 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1698 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1700 SelectObject (hdc
, hOldFont
);
1701 ReleaseDC (hwnd
, hdc
);
1703 sizeButton
= TOOLBAR_MeasureButton(infoPtr
, sz
,
1704 TOOLBAR_IsValidBitmapIndex(infoPtr
, infoPtr
->buttons
[i
].iBitmap
),
1709 cx
= infoPtr
->nButtonWidth
;
1711 /* if size has been set manually then don't add on extra space
1712 * for the drop down arrow */
1713 if (!btnPtr
->cx
&& hasDropDownArrows
&&
1714 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) || (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)))
1715 cx
+= DDARROW_WIDTH
;
1717 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1720 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1722 if (infoPtr
->rcBound
.left
> x
)
1723 infoPtr
->rcBound
.left
= x
;
1724 if (infoPtr
->rcBound
.right
< x
+ cx
)
1725 infoPtr
->rcBound
.right
= x
+ cx
;
1726 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1727 infoPtr
->rcBound
.bottom
= y
+ cy
;
1729 TOOLBAR_TooltipSetRect(infoPtr
, btnPtr
);
1731 /* btnPtr->nRow is zero based. The space between the rows is */
1732 /* also considered as a row. */
1733 btnPtr
->nRow
= nRows
+ nSepRows
;
1735 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1736 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1741 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1745 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1746 /* it is the actual width of the separator. This is used for */
1747 /* custom controls in toolbars. */
1748 if ( !(btnPtr
->fsStyle
& BTNS_DROPDOWN
))
1749 y
+= cy
+ ( (btnPtr
->iBitmap
> 0 ) ?
1750 btnPtr
->iBitmap
: SEPARATOR_WIDTH
) * 2 /3;
1754 /* nSepRows is used to calculate the extra height follwoing */
1758 x
= infoPtr
->nIndent
;
1760 /* Increment row number unless this is the last button */
1761 /* and it has Wrap set. */
1762 if (i
!= infoPtr
->nNumButtons
-1)
1769 /* infoPtr->nRows is the number of rows on the toolbar */
1770 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1772 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1777 TOOLBAR_InternalHitTest (HWND hwnd
, LPPOINT lpPt
)
1779 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1780 TBUTTON_INFO
*btnPtr
;
1783 btnPtr
= infoPtr
->buttons
;
1784 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1785 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1788 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1789 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1790 TRACE(" ON SEPARATOR %d!\n", i
);
1795 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1796 TRACE(" ON BUTTON %d!\n", i
);
1802 TRACE(" NOWHERE!\n");
1803 return TOOLBAR_NOWHERE
;
1808 TOOLBAR_GetButtonIndex (TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1810 TBUTTON_INFO
*btnPtr
;
1813 if (CommandIsIndex
) {
1814 TRACE("command is really index command=%d\n", idCommand
);
1815 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1818 btnPtr
= infoPtr
->buttons
;
1819 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1820 if (btnPtr
->idCommand
== idCommand
) {
1821 TRACE("command=%d index=%d\n", idCommand
, i
);
1825 TRACE("no index found for command=%d\n", idCommand
);
1831 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1833 TBUTTON_INFO
*btnPtr
;
1836 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1839 /* check index button */
1840 btnPtr
= &infoPtr
->buttons
[nIndex
];
1841 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1842 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1846 /* check previous buttons */
1847 nRunIndex
= nIndex
- 1;
1848 while (nRunIndex
>= 0) {
1849 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1850 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1851 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1859 /* check next buttons */
1860 nRunIndex
= nIndex
+ 1;
1861 while (nRunIndex
< infoPtr
->nNumButtons
) {
1862 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1863 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1864 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1877 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1878 WPARAM wParam
, LPARAM lParam
)
1884 msg
.wParam
= wParam
;
1885 msg
.lParam
= lParam
;
1886 msg
.time
= GetMessageTime ();
1887 msg
.pt
.x
= LOWORD(GetMessagePos ());
1888 msg
.pt
.y
= HIWORD(GetMessagePos ());
1890 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1894 TOOLBAR_TooltipAddTool(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*button
)
1896 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
)) {
1899 ZeroMemory(&ti
, sizeof(TTTOOLINFOW
));
1900 ti
.cbSize
= sizeof (TTTOOLINFOW
);
1901 ti
.hwnd
= infoPtr
->hwndSelf
;
1902 ti
.uId
= button
->idCommand
;
1904 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
1905 /* ti.lParam = random value from the stack? */
1907 SendMessageW(infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
1913 TOOLBAR_TooltipDelTool(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*button
)
1915 if ((infoPtr
->hwndToolTip
) && !(button
->fsStyle
& BTNS_SEP
)) {
1918 ZeroMemory(&ti
, sizeof(ti
));
1919 ti
.cbSize
= sizeof(ti
);
1920 ti
.hwnd
= infoPtr
->hwndSelf
;
1921 ti
.uId
= button
->idCommand
;
1923 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
1927 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*button
)
1929 /* Set the toolTip only for non-hidden, non-separator button */
1930 if (infoPtr
->hwndToolTip
&& !(button
->fsStyle
& BTNS_SEP
))
1934 ZeroMemory(&ti
, sizeof(ti
));
1935 ti
.cbSize
= sizeof(ti
);
1936 ti
.hwnd
= infoPtr
->hwndSelf
;
1937 ti
.uId
= button
->idCommand
;
1938 ti
.rect
= button
->rect
;
1939 SendMessageW(infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
, 0, (LPARAM
)&ti
);
1943 /* Creates the tooltip control */
1945 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO
*infoPtr
)
1948 NMTOOLTIPSCREATED nmttc
;
1950 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, 0,
1951 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1952 infoPtr
->hwndSelf
, 0, 0, 0);
1954 if (!infoPtr
->hwndToolTip
)
1957 /* Send NM_TOOLTIPSCREATED notification */
1958 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
1959 TOOLBAR_SendNotify(&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
1961 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
1963 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[i
]);
1964 TOOLBAR_TooltipSetRect(infoPtr
, &infoPtr
->buttons
[i
]);
1968 /* keeps available button list box sorted by button id */
1969 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
1973 PCUSTOMBUTTON btnInfo
;
1974 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
1976 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
1978 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
1980 /* position 0 is always separator */
1981 for (i
= 1; i
< count
; i
++)
1983 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
1984 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
1986 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
1987 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
1991 /* id higher than all others add to end */
1992 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
1993 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
1996 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
2000 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
2002 if (nIndexFrom
== nIndexTo
)
2005 /* MSDN states that iItem is the index of the button, rather than the
2006 * command ID as used by every other NMTOOLBAR notification */
2007 nmtb
.iItem
= nIndexFrom
;
2008 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2010 PCUSTOMBUTTON btnInfo
;
2012 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2013 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2015 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
2017 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
2018 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2019 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2020 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
2023 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2025 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2027 /* last item is always separator, so -2 instead of -1 */
2028 if (nIndexTo
>= (count
- 2))
2029 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2031 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2033 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
2034 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2036 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2040 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
2044 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
2046 /* MSDN states that iItem is the index of the button, rather than the
2047 * command ID as used by every other NMTOOLBAR notification */
2048 nmtb
.iItem
= nIndexAvail
;
2049 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
2051 PCUSTOMBUTTON btnInfo
;
2053 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2054 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2055 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
2057 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
2059 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
2061 /* remove from 'available buttons' list */
2062 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2063 if (nIndexAvail
== count
-1)
2064 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2066 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2070 PCUSTOMBUTTON btnNew
;
2072 /* duplicate 'separator' button */
2073 btnNew
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2074 memcpy(btnNew
, btnInfo
, sizeof(CUSTOMBUTTON
));
2078 /* insert into 'toolbar button' list */
2079 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2080 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2082 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2084 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2088 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo
, HWND hwnd
, INT index
)
2090 PCUSTOMBUTTON btnInfo
;
2091 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2093 TRACE("Remove: index %d\n", index
);
2095 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2097 /* send TBN_QUERYDELETE notification */
2098 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2102 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2103 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2105 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2107 /* insert into 'available button' list */
2108 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2109 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2113 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2117 /* drag list notification function for toolbar buttons list box */
2118 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo
, HWND hwnd
, DRAGLISTINFO
*pDLI
)
2120 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2121 switch (pDLI
->uNotification
)
2125 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2126 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2127 /* no dragging for last item (separator) */
2128 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2133 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2134 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2135 /* no dragging past last item (separator) */
2136 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2138 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2139 /* FIXME: native uses "move button" cursor */
2140 return DL_COPYCURSOR
;
2143 /* not over toolbar buttons list */
2144 if (nCurrentItem
< 0)
2146 POINT ptWindow
= pDLI
->ptCursor
;
2147 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2148 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2149 /* over available buttons list? */
2150 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2151 /* FIXME: native uses "move button" cursor */
2152 return DL_COPYCURSOR
;
2154 /* clear drag arrow */
2155 DrawInsert(hwnd
, hwndList
, -1);
2156 return DL_STOPCURSOR
;
2160 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2161 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2162 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2163 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2165 /* clear drag arrow */
2166 DrawInsert(hwnd
, hwndList
, -1);
2168 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2170 /* not over toolbar buttons list */
2173 POINT ptWindow
= pDLI
->ptCursor
;
2174 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2175 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2176 /* over available buttons list? */
2177 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2178 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2183 /* Clear drag arrow */
2184 DrawInsert(hwnd
, hwndList
, -1);
2191 /* drag list notification function for available buttons list box */
2192 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo
, HWND hwnd
, DRAGLISTINFO
*pDLI
)
2194 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2195 switch (pDLI
->uNotification
)
2201 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2202 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2203 /* no dragging past last item (separator) */
2204 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2206 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2207 /* FIXME: native uses "move button" cursor */
2208 return DL_COPYCURSOR
;
2211 /* not over toolbar buttons list */
2212 if (nCurrentItem
< 0)
2214 POINT ptWindow
= pDLI
->ptCursor
;
2215 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2216 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2217 /* over available buttons list? */
2218 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2219 /* FIXME: native uses "move button" cursor */
2220 return DL_COPYCURSOR
;
2222 /* clear drag arrow */
2223 DrawInsert(hwnd
, hwndList
, -1);
2224 return DL_STOPCURSOR
;
2228 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2229 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2230 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2231 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2233 /* clear drag arrow */
2234 DrawInsert(hwnd
, hwndList
, -1);
2236 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2240 /* Clear drag arrow */
2241 DrawInsert(hwnd
, hwndList
, -1);
2247 extern UINT uDragListMessage
;
2249 /***********************************************************************
2250 * TOOLBAR_CustomizeDialogProc
2251 * This function implements the toolbar customization dialog.
2253 static INT_PTR CALLBACK
2254 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2256 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2257 PCUSTOMBUTTON btnInfo
;
2259 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2264 custInfo
= (PCUSTDLG_INFO
)lParam
;
2265 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2272 NMTBINITCUSTOMIZE nmtbic
;
2274 infoPtr
= custInfo
->tbInfo
;
2276 /* send TBN_QUERYINSERT notification */
2277 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2279 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2282 nmtbic
.hwndDialog
= hwnd
;
2283 /* Send TBN_INITCUSTOMIZE notification */
2284 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2287 TRACE("TBNRF_HIDEHELP requested\n");
2288 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2291 /* add items to 'toolbar buttons' list and check if removable */
2292 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2294 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2295 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2296 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2297 btnInfo
->bVirtual
= FALSE
;
2298 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2300 /* send TBN_QUERYDELETE notification */
2301 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2303 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2304 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2307 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2309 /* insert separator button into 'available buttons' list */
2310 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2311 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2312 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2313 btnInfo
->bVirtual
= FALSE
;
2314 btnInfo
->bRemovable
= TRUE
;
2315 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2316 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2317 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2319 /* insert all buttons into dsa */
2322 /* send TBN_GETBUTTONINFO notification */
2325 nmtb
.pszText
= Buffer
;
2328 /* Clear previous button's text */
2329 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2331 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2334 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2335 nmtb
.tbButton
.fsStyle
, i
,
2336 nmtb
.tbButton
.idCommand
,
2337 nmtb
.tbButton
.iString
,
2338 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2341 /* insert button into the apropriate list */
2342 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2345 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2346 btnInfo
->bVirtual
= FALSE
;
2347 btnInfo
->bRemovable
= TRUE
;
2351 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2352 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2355 memcpy (&btnInfo
->btn
, &nmtb
.tbButton
, sizeof(TBBUTTON
));
2356 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2358 if (lstrlenW(nmtb
.pszText
))
2359 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2360 else if (nmtb
.tbButton
.iString
>= 0 &&
2361 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2363 lstrcpyW(btnInfo
->text
,
2364 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2369 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2372 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2374 /* select first item in the 'available' list */
2375 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2377 /* append 'virtual' separator button to the 'toolbar buttons' list */
2378 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2379 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2380 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2381 btnInfo
->bVirtual
= TRUE
;
2382 btnInfo
->bRemovable
= FALSE
;
2383 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2384 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2385 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2387 /* select last item in the 'toolbar' list */
2388 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2389 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2391 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2392 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2394 /* set focus and disable buttons */
2395 PostMessageW (hwnd
, WM_USER
, 0, 0);
2400 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2401 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2402 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2403 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2407 EndDialog(hwnd
, FALSE
);
2411 switch (LOWORD(wParam
))
2413 case IDC_TOOLBARBTN_LBOX
:
2414 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2416 PCUSTOMBUTTON btnInfo
;
2421 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2422 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2424 /* send TBN_QUERYINSERT notification */
2426 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2428 /* get list box item */
2429 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2431 if (index
== (count
- 1))
2433 /* last item (virtual separator) */
2434 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2435 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2437 else if (index
== (count
- 2))
2439 /* second last item (last non-virtual item) */
2440 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2441 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2443 else if (index
== 0)
2446 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2447 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2451 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2452 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2455 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2459 case IDC_MOVEUP_BTN
:
2461 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2462 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2466 case IDC_MOVEDN_BTN
: /* move down */
2468 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2469 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2473 case IDC_REMOVE_BTN
: /* remove button */
2475 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2477 if (LB_ERR
== index
)
2480 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2484 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2487 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2490 case IDOK
: /* Add button */
2495 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2496 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2498 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2503 EndDialog(hwnd
, FALSE
);
2513 /* delete items from 'toolbar buttons' listbox*/
2514 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2515 for (i
= 0; i
< count
; i
++)
2517 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2519 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2521 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2524 /* delete items from 'available buttons' listbox*/
2525 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2526 for (i
= 0; i
< count
; i
++)
2528 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2530 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2532 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2537 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2539 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2544 COLORREF oldText
= 0;
2548 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, (WPARAM
)lpdis
->itemID
, 0);
2549 if (btnInfo
== NULL
)
2551 FIXME("btnInfo invalid!\n");
2555 /* set colors and select objects */
2556 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2557 if (btnInfo
->bVirtual
)
2558 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2560 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2561 hPen
= CreatePen( PS_SOLID
, 1,
2562 GetSysColor( (lpdis
->itemState
& ODS_SELECTED
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2563 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2564 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2566 /* fill background rectangle */
2567 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2568 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2570 /* calculate button and text rectangles */
2571 CopyRect (&rcButton
, &lpdis
->rcItem
);
2572 InflateRect (&rcButton
, -1, -1);
2573 CopyRect (&rcText
, &rcButton
);
2574 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2575 rcText
.left
= rcButton
.right
+ 2;
2577 /* draw focus rectangle */
2578 if (lpdis
->itemState
& ODS_FOCUS
)
2579 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2582 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2583 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2585 /* draw image and text */
2586 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2587 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2588 btnInfo
->btn
.iBitmap
));
2589 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2590 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2592 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2593 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2595 /* delete objects and reset colors */
2596 SelectObject (lpdis
->hDC
, hOldBrush
);
2597 SelectObject (lpdis
->hDC
, hOldPen
);
2598 SetBkColor (lpdis
->hDC
, oldBk
);
2599 SetTextColor (lpdis
->hDC
, oldText
);
2600 DeleteObject( hPen
);
2605 case WM_MEASUREITEM
:
2606 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2608 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2610 lpmis
->itemHeight
= 15 + 8; /* default height */
2617 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2619 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2621 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2622 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2623 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2626 else if (wParam
== IDC_AVAILBTN_LBOX
)
2628 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2629 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2630 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2639 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2642 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2648 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2649 /* Add bitmaps to the default image list */
2650 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2653 HBITMAP hOldBitmapBitmap
, hOldBitmapLoad
;
2654 HDC hdcImage
, hdcBitmap
;
2656 /* copy the bitmap before adding it so that the user's bitmap
2657 * doesn't get modified.
2659 GetObjectW ((HBITMAP
)bitmap
->nID
, sizeof(BITMAP
), (LPVOID
)&bmp
);
2661 hdcImage
= CreateCompatibleDC(0);
2662 hdcBitmap
= CreateCompatibleDC(0);
2664 /* create new bitmap */
2665 hbmLoad
= CreateBitmap (bmp
.bmWidth
, bmp
.bmHeight
, bmp
.bmPlanes
, bmp
.bmBitsPixel
, NULL
);
2666 hOldBitmapBitmap
= SelectObject(hdcBitmap
, (HBITMAP
)bitmap
->nID
);
2667 hOldBitmapLoad
= SelectObject(hdcImage
, hbmLoad
);
2669 /* Copy the user's image */
2670 BitBlt (hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
,
2671 hdcBitmap
, 0, 0, SRCCOPY
);
2673 SelectObject (hdcImage
, hOldBitmapLoad
);
2674 SelectObject (hdcBitmap
, hOldBitmapBitmap
);
2675 DeleteDC (hdcImage
);
2676 DeleteDC (hdcBitmap
);
2679 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2681 /* enlarge the bitmap if needed */
2682 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2683 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2685 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2686 DeleteObject(hbmLoad
);
2690 nCountAfter
= ImageList_GetImageCount(himlDef
);
2691 nAdded
= nCountAfter
- nCountBefore
;
2692 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2694 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2695 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2696 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2697 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2700 infoPtr
->nNumBitmaps
+= nAdded
;
2705 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2712 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2713 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2715 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2717 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2720 TRACE("Update icon size: %dx%d -> %dx%d\n",
2721 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2723 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2724 ILC_COLORDDB
|ILC_MASK
, 8, 2);
2725 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2726 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2727 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2728 infoPtr
->himlInt
= himlNew
;
2730 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2731 ImageList_Destroy(himlDef
);
2734 /***********************************************************************
2735 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2739 TOOLBAR_AddBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2741 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2742 LPTBADDBITMAP lpAddBmp
= (LPTBADDBITMAP
)lParam
;
2747 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd
, wParam
, lParam
);
2751 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2753 info
.hInst
= COMCTL32_hModule
;
2754 switch (lpAddBmp
->nID
)
2756 case IDB_STD_SMALL_COLOR
:
2758 info
.nID
= IDB_STD_SMALL
;
2760 case IDB_STD_LARGE_COLOR
:
2762 info
.nID
= IDB_STD_LARGE
;
2764 case IDB_VIEW_SMALL_COLOR
:
2766 info
.nID
= IDB_VIEW_SMALL
;
2768 case IDB_VIEW_LARGE_COLOR
:
2770 info
.nID
= IDB_VIEW_LARGE
;
2772 case IDB_HIST_SMALL_COLOR
:
2774 info
.nID
= IDB_HIST_SMALL
;
2776 case IDB_HIST_LARGE_COLOR
:
2778 info
.nID
= IDB_HIST_LARGE
;
2784 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2786 /* Windows resize all the buttons to the size of a newly added standard image */
2787 if (lpAddBmp
->nID
& 1)
2790 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2791 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2793 SendMessageW (hwnd
, TB_SETBITMAPSIZE
, 0,
2794 MAKELPARAM((WORD
)24, (WORD
)24));
2795 SendMessageW (hwnd
, TB_SETBUTTONSIZE
, 0,
2796 MAKELPARAM((WORD
)31, (WORD
)30));
2801 SendMessageW (hwnd
, TB_SETBITMAPSIZE
, 0,
2802 MAKELPARAM((WORD
)16, (WORD
)16));
2803 SendMessageW (hwnd
, TB_SETBUTTONSIZE
, 0,
2804 MAKELPARAM((WORD
)22, (WORD
)22));
2807 TOOLBAR_CalcToolbar (hwnd
);
2811 info
.nButtons
= (INT
)wParam
;
2812 info
.hInst
= lpAddBmp
->hInst
;
2813 info
.nID
= lpAddBmp
->nID
;
2814 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2817 /* check if the bitmap is already loaded and compute iSumButtons */
2819 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2821 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2822 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2824 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2827 if (!infoPtr
->cimlDef
) {
2828 /* create new default image list */
2829 TRACE ("creating default image list!\n");
2831 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2832 ILC_COLORDDB
| ILC_MASK
, info
.nButtons
, 2);
2833 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2834 infoPtr
->himlInt
= himlDef
;
2837 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2841 WARN("No default image list available\n");
2845 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2848 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2849 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2850 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2851 infoPtr
->nNumBitmapInfos
++;
2852 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2854 InvalidateRect(hwnd
, NULL
, TRUE
);
2860 TOOLBAR_AddButtonsT(HWND hwnd
, WPARAM wParam
, LPARAM lParam
, BOOL fUnicode
)
2862 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2863 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
2864 INT nOldButtons
, nNewButtons
, nAddButtons
, nCount
;
2866 TRACE("adding %d buttons (unicode=%d)!\n", wParam
, fUnicode
);
2868 nAddButtons
= (UINT
)wParam
;
2869 nOldButtons
= infoPtr
->nNumButtons
;
2870 nNewButtons
= nOldButtons
+ nAddButtons
;
2872 infoPtr
->buttons
= ReAlloc(infoPtr
->buttons
, sizeof(TBUTTON_INFO
)*nNewButtons
);
2873 infoPtr
->nNumButtons
= nNewButtons
;
2875 /* insert new button data */
2876 for (nCount
= 0; nCount
< nAddButtons
; nCount
++) {
2877 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nOldButtons
+nCount
];
2878 btnPtr
->iBitmap
= lpTbb
[nCount
].iBitmap
;
2879 btnPtr
->idCommand
= lpTbb
[nCount
].idCommand
;
2880 btnPtr
->fsState
= lpTbb
[nCount
].fsState
;
2881 btnPtr
->fsStyle
= lpTbb
[nCount
].fsStyle
;
2882 btnPtr
->dwData
= lpTbb
[nCount
].dwData
;
2883 btnPtr
->bHot
= FALSE
;
2884 if(HIWORD(lpTbb
[nCount
].iString
) && lpTbb
[nCount
].iString
!= -1)
2887 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, (LPWSTR
)lpTbb
[nCount
].iString
);
2889 Str_SetPtrAtoW((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lpTbb
[nCount
].iString
);
2892 btnPtr
->iString
= lpTbb
[nCount
].iString
;
2894 TOOLBAR_TooltipAddTool(infoPtr
, btnPtr
);
2897 TOOLBAR_CalcToolbar (hwnd
);
2898 TOOLBAR_AutoSize (hwnd
);
2900 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
2902 InvalidateRect(hwnd
, NULL
, TRUE
);
2909 TOOLBAR_AddStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2911 #define MAX_RESOURCE_STRING_LENGTH 512
2912 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2913 INT nIndex
= infoPtr
->nNumStrings
;
2915 if ((wParam
) && (HIWORD(lParam
) == 0)) {
2916 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2921 TRACE("adding string from resource!\n");
2923 len
= LoadStringW ((HINSTANCE
)wParam
, (UINT
)lParam
,
2924 szString
, MAX_RESOURCE_STRING_LENGTH
);
2926 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2927 if (len
== 0 || len
== 1)
2930 TRACE("Delimiter: 0x%x\n", *szString
);
2931 delimiter
= *szString
;
2934 while ((next_delim
= strchrW(p
, delimiter
)) != NULL
) {
2936 if (next_delim
+ 1 >= szString
+ len
)
2938 /* this may happen if delimiter == '\0' or if the last char is a
2939 * delimiter (then it is ignored like the native does) */
2943 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2944 Str_SetPtrW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2945 infoPtr
->nNumStrings
++;
2951 LPWSTR p
= (LPWSTR
)lParam
;
2956 TRACE("adding string(s) from array!\n");
2960 TRACE("len=%d %s\n", len
, debugstr_w(p
));
2961 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2962 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2963 infoPtr
->nNumStrings
++;
2974 TOOLBAR_AddStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2976 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2981 if ((wParam
) && (HIWORD(lParam
) == 0)) /* load from resources */
2982 return TOOLBAR_AddStringW(hwnd
, wParam
, lParam
);
2988 TRACE("adding string(s) from array!\n");
2989 nIndex
= infoPtr
->nNumStrings
;
2992 TRACE("len=%d \"%s\"\n", len
, p
);
2994 infoPtr
->strings
= ReAlloc(infoPtr
->strings
, sizeof(LPWSTR
)*(infoPtr
->nNumStrings
+1));
2995 Str_SetPtrAtoW(&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2996 infoPtr
->nNumStrings
++;
3006 TOOLBAR_AutoSize (HWND hwnd
)
3008 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3014 TRACE("auto sizing, style=%lx!\n", infoPtr
->dwStyle
);
3016 parent
= GetParent (hwnd
);
3018 if (!parent
|| !infoPtr
->bDoRedraw
)
3021 GetClientRect(parent
, &parent_rect
);
3023 x
= parent_rect
.left
;
3024 y
= parent_rect
.top
;
3026 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3028 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3029 cx
= parent_rect
.right
- parent_rect
.left
;
3031 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
))
3033 TOOLBAR_CalcToolbar(hwnd
);
3034 InvalidateRect( hwnd
, NULL
, TRUE
);
3037 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3040 UINT uPosFlags
= SWP_NOZORDER
;
3042 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3044 GetWindowRect(hwnd
, &window_rect
);
3045 ScreenToClient(parent
, (LPPOINT
)&window_rect
.left
);
3046 y
= window_rect
.top
;
3048 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3050 GetWindowRect(hwnd
, &window_rect
);
3051 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3054 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3055 uPosFlags
|= SWP_NOMOVE
;
3057 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3058 cy
+= GetSystemMetrics(SM_CYEDGE
);
3060 if (infoPtr
->dwStyle
& WS_BORDER
)
3062 x
= y
= 1; /* FIXME: this looks wrong */
3063 cy
+= GetSystemMetrics(SM_CYEDGE
);
3064 cx
+= GetSystemMetrics(SM_CXEDGE
);
3067 SetWindowPos(hwnd
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3075 TOOLBAR_ButtonCount (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3077 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3079 return infoPtr
->nNumButtons
;
3084 TOOLBAR_ButtonStructSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3086 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3088 infoPtr
->dwStructSize
= (DWORD
)wParam
;
3095 TOOLBAR_ChangeBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3097 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3098 TBUTTON_INFO
*btnPtr
;
3101 TRACE("button %d, iBitmap now %d\n", wParam
, LOWORD(lParam
));
3103 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3107 btnPtr
= &infoPtr
->buttons
[nIndex
];
3108 btnPtr
->iBitmap
= LOWORD(lParam
);
3110 /* we HAVE to erase the background, the new bitmap could be */
3112 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3119 TOOLBAR_CheckButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3121 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3122 TBUTTON_INFO
*btnPtr
;
3125 BOOL bChecked
= FALSE
;
3127 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3129 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd
, nIndex
, lParam
);
3134 btnPtr
= &infoPtr
->buttons
[nIndex
];
3136 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? TRUE
: FALSE
;
3138 if (LOWORD(lParam
) == FALSE
)
3139 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3141 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3143 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3144 if (nOldIndex
== nIndex
)
3146 if (nOldIndex
!= -1)
3147 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3149 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3152 if( bChecked
!= LOWORD(lParam
) )
3154 if (nOldIndex
!= -1)
3155 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3156 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3159 /* FIXME: Send a WM_NOTIFY?? */
3166 TOOLBAR_CommandToIndex (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3168 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3170 return TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3175 TOOLBAR_Customize (HWND hwnd
)
3177 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3178 CUSTDLG_INFO custInfo
;
3184 custInfo
.tbInfo
= infoPtr
;
3185 custInfo
.tbHwnd
= hwnd
;
3187 /* send TBN_BEGINADJUST notification */
3188 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3190 if (!(hRes
= FindResourceW (COMCTL32_hModule
,
3191 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3192 (LPWSTR
)RT_DIALOG
)))
3195 if(!(template = (LPVOID
)LoadResource (COMCTL32_hModule
, hRes
)))
3198 ret
= DialogBoxIndirectParamW ((HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
),
3199 (LPCDLGTEMPLATEW
)template,
3201 TOOLBAR_CustomizeDialogProc
,
3204 /* send TBN_ENDADJUST notification */
3205 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3212 TOOLBAR_DeleteButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3214 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3215 INT nIndex
= (INT
)wParam
;
3217 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3219 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3222 memset(&nmtb
, 0, sizeof(nmtb
));
3223 nmtb
.iItem
= btnPtr
->idCommand
;
3224 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3225 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3226 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3227 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3228 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3229 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3230 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3232 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3234 if (infoPtr
->nNumButtons
== 1) {
3235 TRACE(" simple delete!\n");
3236 Free (infoPtr
->buttons
);
3237 infoPtr
->buttons
= NULL
;
3238 infoPtr
->nNumButtons
= 0;
3241 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3242 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3244 infoPtr
->nNumButtons
--;
3245 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3247 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3248 nIndex
* sizeof(TBUTTON_INFO
));
3251 if (nIndex
< infoPtr
->nNumButtons
) {
3252 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3253 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3259 TOOLBAR_CalcToolbar (hwnd
);
3261 InvalidateRect (hwnd
, NULL
, TRUE
);
3268 TOOLBAR_EnableButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3270 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3271 TBUTTON_INFO
*btnPtr
;
3275 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3277 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd
, wParam
, lParam
);
3282 btnPtr
= &infoPtr
->buttons
[nIndex
];
3284 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3286 /* update the toolbar button state */
3287 if(LOWORD(lParam
) == FALSE
) {
3288 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3290 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3293 /* redraw the button only if the state of the button changed */
3294 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3295 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3301 static inline LRESULT
3302 TOOLBAR_GetAnchorHighlight (HWND hwnd
)
3304 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3306 return infoPtr
->bAnchor
;
3311 TOOLBAR_GetBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3313 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3316 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3320 return infoPtr
->buttons
[nIndex
].iBitmap
;
3324 static inline LRESULT
3325 TOOLBAR_GetBitmapFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3327 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3332 TOOLBAR_GetButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3334 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3335 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3336 INT nIndex
= (INT
)wParam
;
3337 TBUTTON_INFO
*btnPtr
;
3342 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3345 btnPtr
= &infoPtr
->buttons
[nIndex
];
3346 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3347 lpTbb
->idCommand
= btnPtr
->idCommand
;
3348 lpTbb
->fsState
= btnPtr
->fsState
;
3349 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3350 lpTbb
->bReserved
[0] = 0;
3351 lpTbb
->bReserved
[1] = 0;
3352 lpTbb
->dwData
= btnPtr
->dwData
;
3353 lpTbb
->iString
= btnPtr
->iString
;
3360 TOOLBAR_GetButtonInfoA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3362 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3363 LPTBBUTTONINFOA lpTbInfo
= (LPTBBUTTONINFOA
)lParam
;
3364 TBUTTON_INFO
*btnPtr
;
3367 if (lpTbInfo
== NULL
)
3369 if (lpTbInfo
->cbSize
< sizeof(TBBUTTONINFOA
))
3372 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
3373 lpTbInfo
->dwMask
& 0x80000000);
3377 if (!(btnPtr
= &infoPtr
->buttons
[nIndex
])) return -1;
3379 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3380 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3381 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3382 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3383 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3384 lpTbInfo
->lParam
= btnPtr
->dwData
;
3385 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3386 lpTbInfo
->cx
= (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3387 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3388 lpTbInfo
->fsState
= btnPtr
->fsState
;
3389 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3390 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3391 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3392 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3393 can't use TOOLBAR_GetText here */
3395 if (HIWORD(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3396 lpText
= (LPWSTR
)btnPtr
->iString
;
3397 Str_GetPtrWtoA (lpText
, lpTbInfo
->pszText
,lpTbInfo
->cchText
);
3399 lpTbInfo
->pszText
[0] = '\0';
3406 TOOLBAR_GetButtonInfoW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3408 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3409 LPTBBUTTONINFOW lpTbInfo
= (LPTBBUTTONINFOW
)lParam
;
3410 TBUTTON_INFO
*btnPtr
;
3413 if (lpTbInfo
== NULL
)
3415 if (lpTbInfo
->cbSize
< sizeof(TBBUTTONINFOW
))
3418 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
3419 lpTbInfo
->dwMask
& 0x80000000);
3423 btnPtr
= &infoPtr
->buttons
[nIndex
];
3428 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3429 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3430 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3431 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3432 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3433 lpTbInfo
->lParam
= btnPtr
->dwData
;
3434 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3435 lpTbInfo
->cx
= (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3436 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3437 lpTbInfo
->fsState
= btnPtr
->fsState
;
3438 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3439 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3440 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3441 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3442 can't use TOOLBAR_GetText here */
3444 if (HIWORD(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3445 lpText
= (LPWSTR
)btnPtr
->iString
;
3446 Str_GetPtrW (lpText
,lpTbInfo
->pszText
,lpTbInfo
->cchText
);
3448 lpTbInfo
->pszText
[0] = '\0';
3456 TOOLBAR_GetButtonSize (HWND hwnd
)
3458 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3460 if (infoPtr
->nNumButtons
> 0)
3461 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3462 (WORD
)infoPtr
->nButtonHeight
);
3464 return MAKELONG(23,22);
3469 TOOLBAR_GetButtonTextA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3471 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3478 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3482 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3484 return WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3485 (LPSTR
)lParam
, 0x7fffffff, NULL
, NULL
) - 1;
3490 TOOLBAR_GetButtonTextW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3492 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3497 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3501 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3505 ret
= strlenW (lpText
);
3508 strcpyW ((LPWSTR
)lParam
, lpText
);
3516 TOOLBAR_GetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3518 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3519 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3520 return (LRESULT
)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3524 inline static LRESULT
3525 TOOLBAR_GetExtendedStyle (HWND hwnd
)
3527 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3531 return infoPtr
->dwExStyle
;
3536 TOOLBAR_GetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3538 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3539 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3540 return (LRESULT
)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3545 TOOLBAR_GetHotItem (HWND hwnd
)
3547 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3549 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3552 if (infoPtr
->nHotItem
< 0)
3555 return (LRESULT
)infoPtr
->nHotItem
;
3560 TOOLBAR_GetDefImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3562 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3563 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3564 return (LRESULT
) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd
), wParam
);
3569 TOOLBAR_GetInsertMark (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3571 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3572 TBINSERTMARK
*lptbim
= (TBINSERTMARK
*)lParam
;
3574 TRACE("hwnd = %p, lptbim = %p\n", hwnd
, lptbim
);
3576 *lptbim
= infoPtr
->tbim
;
3583 TOOLBAR_GetInsertMarkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3585 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3587 TRACE("hwnd = %p\n", hwnd
);
3589 return (LRESULT
)infoPtr
->clrInsertMark
;
3594 TOOLBAR_GetItemRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3596 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3597 TBUTTON_INFO
*btnPtr
;
3601 nIndex
= (INT
)wParam
;
3602 btnPtr
= &infoPtr
->buttons
[nIndex
];
3603 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3605 lpRect
= (LPRECT
)lParam
;
3608 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3611 lpRect
->left
= btnPtr
->rect
.left
;
3612 lpRect
->right
= btnPtr
->rect
.right
;
3613 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3614 lpRect
->top
= btnPtr
->rect
.top
;
3621 TOOLBAR_GetMaxSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3623 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3624 LPSIZE lpSize
= (LPSIZE
)lParam
;
3629 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3630 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3632 TRACE("maximum size %ld x %ld\n",
3633 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3634 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3640 /* << TOOLBAR_GetObject >> */
3644 TOOLBAR_GetPadding (HWND hwnd
)
3646 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3649 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3650 return (LRESULT
) oldPad
;
3655 TOOLBAR_GetRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3657 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3658 TBUTTON_INFO
*btnPtr
;
3662 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3663 btnPtr
= &infoPtr
->buttons
[nIndex
];
3664 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3666 lpRect
= (LPRECT
)lParam
;
3670 lpRect
->left
= btnPtr
->rect
.left
;
3671 lpRect
->right
= btnPtr
->rect
.right
;
3672 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3673 lpRect
->top
= btnPtr
->rect
.top
;
3680 TOOLBAR_GetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3682 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3684 if (infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
)
3685 return infoPtr
->nRows
;
3692 TOOLBAR_GetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3694 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3697 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3701 return infoPtr
->buttons
[nIndex
].fsState
;
3706 TOOLBAR_GetStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3708 return GetWindowLongW(hwnd
, GWL_STYLE
);
3713 TOOLBAR_GetTextRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3715 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3717 return infoPtr
->nMaxTextRows
;
3722 TOOLBAR_GetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3724 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3726 return (LRESULT
)infoPtr
->hwndToolTip
;
3731 TOOLBAR_GetUnicodeFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3733 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3735 TRACE("%s hwnd=%p\n",
3736 infoPtr
->bUnicode
? "TRUE" : "FALSE", hwnd
);
3738 return infoPtr
->bUnicode
;
3742 inline static LRESULT
3743 TOOLBAR_GetVersion (HWND hwnd
)
3745 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3746 return infoPtr
->iVersion
;
3751 TOOLBAR_HideButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3753 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3754 TBUTTON_INFO
*btnPtr
;
3759 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3763 btnPtr
= &infoPtr
->buttons
[nIndex
];
3764 if (LOWORD(lParam
) == FALSE
)
3765 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3767 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3769 TOOLBAR_CalcToolbar (hwnd
);
3771 InvalidateRect (hwnd
, NULL
, TRUE
);
3777 inline static LRESULT
3778 TOOLBAR_HitTest (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3780 return TOOLBAR_InternalHitTest (hwnd
, (LPPOINT
)lParam
);
3785 TOOLBAR_Indeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3787 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3788 TBUTTON_INFO
*btnPtr
;
3792 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3796 btnPtr
= &infoPtr
->buttons
[nIndex
];
3797 oldState
= btnPtr
->fsState
;
3798 if (LOWORD(lParam
) == FALSE
)
3799 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3801 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3803 if(oldState
!= btnPtr
->fsState
)
3804 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3811 TOOLBAR_InsertButtonA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3813 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3814 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3815 INT nIndex
= (INT
)wParam
;
3816 TBUTTON_INFO
*oldButtons
;
3821 TOOLBAR_DumpButton(infoPtr
, (TBUTTON_INFO
*)lpTbb
, nIndex
, FALSE
);
3824 /* EPP: this seems to be an undocumented call (from my IE4)
3825 * I assume in that case that:
3826 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3827 * - index of insertion is at the end of existing buttons
3828 * I only see this happen with nIndex == -1, but it could have a special
3829 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3831 nIndex
= infoPtr
->nNumButtons
;
3833 } else if (nIndex
< 0)
3836 TRACE("inserting button index=%d\n", nIndex
);
3837 if (nIndex
> infoPtr
->nNumButtons
) {
3838 nIndex
= infoPtr
->nNumButtons
;
3839 TRACE("adjust index=%d\n", nIndex
);
3842 oldButtons
= infoPtr
->buttons
;
3843 infoPtr
->nNumButtons
++;
3844 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3845 /* pre insert copy */
3847 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3848 nIndex
* sizeof(TBUTTON_INFO
));
3851 /* insert new button */
3852 infoPtr
->buttons
[nIndex
].iBitmap
= lpTbb
->iBitmap
;
3853 infoPtr
->buttons
[nIndex
].idCommand
= lpTbb
->idCommand
;
3854 infoPtr
->buttons
[nIndex
].fsState
= lpTbb
->fsState
;
3855 infoPtr
->buttons
[nIndex
].fsStyle
= lpTbb
->fsStyle
;
3856 infoPtr
->buttons
[nIndex
].dwData
= lpTbb
->dwData
;
3857 /* if passed string and not index, then add string */
3858 if(HIWORD(lpTbb
->iString
) && lpTbb
->iString
!=-1) {
3859 Str_SetPtrAtoW ((LPWSTR
*)&infoPtr
->buttons
[nIndex
].iString
, (LPCSTR
)lpTbb
->iString
);
3862 infoPtr
->buttons
[nIndex
].iString
= lpTbb
->iString
;
3864 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3866 /* post insert copy */
3867 if (nIndex
< infoPtr
->nNumButtons
- 1) {
3868 memcpy (&infoPtr
->buttons
[nIndex
+1], &oldButtons
[nIndex
],
3869 (infoPtr
->nNumButtons
- nIndex
- 1) * sizeof(TBUTTON_INFO
));
3874 TOOLBAR_CalcToolbar (hwnd
);
3875 TOOLBAR_AutoSize (hwnd
);
3877 InvalidateRect (hwnd
, NULL
, TRUE
);
3884 TOOLBAR_InsertButtonW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3886 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3887 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3888 INT nIndex
= (INT
)wParam
;
3889 TBUTTON_INFO
*oldButtons
;
3894 TOOLBAR_DumpButton(infoPtr
, (TBUTTON_INFO
*)lpTbb
, nIndex
, FALSE
);
3897 /* EPP: this seems to be an undocumented call (from my IE4)
3898 * I assume in that case that:
3899 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3900 * - index of insertion is at the end of existing buttons
3901 * I only see this happen with nIndex == -1, but it could have a special
3902 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3904 nIndex
= infoPtr
->nNumButtons
;
3906 } else if (nIndex
< 0)
3909 TRACE("inserting button index=%d\n", nIndex
);
3910 if (nIndex
> infoPtr
->nNumButtons
) {
3911 nIndex
= infoPtr
->nNumButtons
;
3912 TRACE("adjust index=%d\n", nIndex
);
3915 oldButtons
= infoPtr
->buttons
;
3916 infoPtr
->nNumButtons
++;
3917 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3918 /* pre insert copy */
3920 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3921 nIndex
* sizeof(TBUTTON_INFO
));
3924 /* insert new button */
3925 infoPtr
->buttons
[nIndex
].iBitmap
= lpTbb
->iBitmap
;
3926 infoPtr
->buttons
[nIndex
].idCommand
= lpTbb
->idCommand
;
3927 infoPtr
->buttons
[nIndex
].fsState
= lpTbb
->fsState
;
3928 infoPtr
->buttons
[nIndex
].fsStyle
= lpTbb
->fsStyle
;
3929 infoPtr
->buttons
[nIndex
].dwData
= lpTbb
->dwData
;
3930 /* if passed string and not index, then add string */
3931 if(HIWORD(lpTbb
->iString
) && lpTbb
->iString
!=-1) {
3932 Str_SetPtrW ((LPWSTR
*)&infoPtr
->buttons
[nIndex
].iString
, (LPWSTR
)lpTbb
->iString
);
3935 infoPtr
->buttons
[nIndex
].iString
= lpTbb
->iString
;
3937 TOOLBAR_TooltipAddTool(infoPtr
, &infoPtr
->buttons
[nIndex
]);
3939 /* post insert copy */
3940 if (nIndex
< infoPtr
->nNumButtons
- 1) {
3941 memcpy (&infoPtr
->buttons
[nIndex
+1], &oldButtons
[nIndex
],
3942 (infoPtr
->nNumButtons
- nIndex
- 1) * sizeof(TBUTTON_INFO
));
3947 TOOLBAR_CalcToolbar (hwnd
);
3948 TOOLBAR_AutoSize (hwnd
);
3950 InvalidateRect (hwnd
, NULL
, TRUE
);
3956 /* << TOOLBAR_InsertMarkHitTest >> */
3960 TOOLBAR_IsButtonChecked (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3962 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3965 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3969 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3974 TOOLBAR_IsButtonEnabled (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3976 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3979 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3983 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3988 TOOLBAR_IsButtonHidden (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3990 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3993 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3997 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
4002 TOOLBAR_IsButtonHighlighted (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4004 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4007 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4011 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
4016 TOOLBAR_IsButtonIndeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4018 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4021 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4025 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
4030 TOOLBAR_IsButtonPressed (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4032 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4035 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4039 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
4044 TOOLBAR_LoadImages (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4047 tbab
.hInst
= (HINSTANCE
)lParam
;
4048 tbab
.nID
= (UINT_PTR
)wParam
;
4050 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd
, tbab
.hInst
, tbab
.nID
);
4052 return TOOLBAR_AddBitmap(hwnd
, 0, (LPARAM
)&tbab
);
4057 TOOLBAR_MapAccelerator (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4059 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4060 WCHAR wAccel
= (WCHAR
)wParam
;
4061 UINT
* pIDButton
= (UINT
*)lParam
;
4062 WCHAR wszAccel
[] = {'&',wAccel
,0};
4065 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4066 hwnd
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
4068 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4070 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
4071 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
4072 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
4074 int iLen
= strlenW(wszAccel
);
4075 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
4082 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
4087 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
4089 *pIDButton
= btnPtr
->idCommand
;
4101 TOOLBAR_MarkButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4103 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4106 TBUTTON_INFO
*btnPtr
;
4108 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd
, wParam
, lParam
);
4110 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4114 btnPtr
= &infoPtr
->buttons
[nIndex
];
4115 oldState
= btnPtr
->fsState
;
4118 btnPtr
->fsState
|= TBSTATE_MARKED
;
4120 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
4122 if(oldState
!= btnPtr
->fsState
)
4123 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4129 /* fixes up an index of a button affected by a move */
4130 inline static void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
4134 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
4136 else if (*pIndex
== nIndex
)
4137 *pIndex
= nMoveIndex
;
4141 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
4143 else if (*pIndex
== nIndex
)
4144 *pIndex
= nMoveIndex
;
4150 TOOLBAR_MoveButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4152 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4155 INT nMoveIndex
= (INT
)lParam
;
4156 TBUTTON_INFO button
;
4158 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd
, wParam
, lParam
);
4160 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, TRUE
);
4161 if ((nIndex
== -1) || (nMoveIndex
< 0))
4164 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
4165 nMoveIndex
= infoPtr
->nNumButtons
- 1;
4167 button
= infoPtr
->buttons
[nIndex
];
4169 /* move button right */
4170 if (nIndex
< nMoveIndex
)
4172 nCount
= nMoveIndex
- nIndex
;
4173 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
4174 infoPtr
->buttons
[nMoveIndex
] = button
;
4176 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
4177 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
4178 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
4179 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
4181 else if (nIndex
> nMoveIndex
) /* move button left */
4183 nCount
= nIndex
- nMoveIndex
;
4184 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
4185 infoPtr
->buttons
[nMoveIndex
] = button
;
4187 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
4188 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
4189 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
4190 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
4193 TOOLBAR_CalcToolbar(hwnd
);
4194 TOOLBAR_AutoSize(hwnd
);
4195 InvalidateRect(hwnd
, NULL
, TRUE
);
4202 TOOLBAR_PressButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4204 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4205 TBUTTON_INFO
*btnPtr
;
4209 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4213 btnPtr
= &infoPtr
->buttons
[nIndex
];
4214 oldState
= btnPtr
->fsState
;
4215 if (LOWORD(lParam
) == FALSE
)
4216 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
4218 btnPtr
->fsState
|= TBSTATE_PRESSED
;
4220 if(oldState
!= btnPtr
->fsState
)
4221 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4226 /* FIXME: there might still be some confusion her between number of buttons
4227 * and number of bitmaps */
4229 TOOLBAR_ReplaceBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4231 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4232 LPTBREPLACEBITMAP lpReplace
= (LPTBREPLACEBITMAP
) lParam
;
4234 HBITMAP hbmLoad
= NULL
;
4235 int i
= 0, nOldButtons
= 0, pos
= 0;
4236 int nOldBitmaps
, nNewBitmaps
= 0;
4237 HIMAGELIST himlDef
= 0;
4239 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4240 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
4241 lpReplace
->nButtons
);
4243 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4245 FIXME("changing standard bitmaps not implemented\n");
4248 else if (lpReplace
->hInstOld
!= 0)
4249 FIXME("resources not in the current module not implemented\n");
4251 if (lpReplace
->hInstNew
)
4253 hbmLoad
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4258 hBitmap
= (HBITMAP
) lpReplace
->nIDNew
;
4261 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4262 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4263 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4264 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4265 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4267 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4268 nOldButtons
= tbi
->nButtons
;
4269 tbi
->nButtons
= lpReplace
->nButtons
;
4270 tbi
->hInst
= lpReplace
->hInstNew
;
4271 tbi
->nID
= lpReplace
->nIDNew
;
4272 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4275 pos
+= tbi
->nButtons
;
4278 if (nOldButtons
== 0)
4280 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4282 DeleteObject (hbmLoad
);
4286 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4287 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4289 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4291 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4292 ImageList_Remove(himlDef
, i
);
4297 HBITMAP hOldBitmapBitmap
, hOldBitmapLoad
, hbmLoad
;
4298 HDC hdcImage
, hdcBitmap
;
4300 /* copy the bitmap before adding it so that the user's bitmap
4301 * doesn't get modified.
4303 GetObjectW (hBitmap
, sizeof(BITMAP
), (LPVOID
)&bmp
);
4305 hdcImage
= CreateCompatibleDC(0);
4306 hdcBitmap
= CreateCompatibleDC(0);
4308 /* create new bitmap */
4309 hbmLoad
= CreateBitmap (bmp
.bmWidth
, bmp
.bmHeight
, bmp
.bmPlanes
, bmp
.bmBitsPixel
, NULL
);
4310 hOldBitmapBitmap
= SelectObject(hdcBitmap
, hBitmap
);
4311 hOldBitmapLoad
= SelectObject(hdcImage
, hbmLoad
);
4313 /* Copy the user's image */
4314 BitBlt (hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
,
4315 hdcBitmap
, 0, 0, SRCCOPY
);
4317 SelectObject (hdcImage
, hOldBitmapLoad
);
4318 SelectObject (hdcBitmap
, hOldBitmapBitmap
);
4319 DeleteDC (hdcImage
);
4320 DeleteDC (hdcBitmap
);
4322 ImageList_AddMasked (himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
4323 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4324 DeleteObject (hbmLoad
);
4327 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4329 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4330 pos
, nOldBitmaps
, nNewBitmaps
);
4332 InvalidateRect(hwnd
, NULL
, TRUE
);
4335 DeleteObject (hbmLoad
);
4340 /* helper for TOOLBAR_SaveRestoreW */
4342 TOOLBAR_Save(TOOLBAR_INFO
*infoPtr
, LPTBSAVEPARAMSW lpSave
)
4344 FIXME("save to %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4345 debugstr_w(lpSave
->pszValueName
));
4351 /* helper for TOOLBAR_Restore */
4353 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4357 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4359 TOOLBAR_TooltipDelTool(infoPtr
, &infoPtr
->buttons
[i
]);
4362 Free(infoPtr
->buttons
);
4363 infoPtr
->buttons
= NULL
;
4364 infoPtr
->nNumButtons
= 0;
4368 /* helper for TOOLBAR_SaveRestoreW */
4370 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, LPTBSAVEPARAMSW lpSave
)
4379 /* restore toolbar information */
4380 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4381 debugstr_w(lpSave
->pszValueName
));
4383 memset(&nmtbr
, 0, sizeof(nmtbr
));
4385 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4386 KEY_QUERY_VALUE
, &hkey
);
4388 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4390 if (!res
&& dwType
!= REG_BINARY
)
4391 res
= ERROR_FILE_NOT_FOUND
;
4394 nmtbr
.pData
= Alloc(dwSize
);
4395 nmtbr
.cbData
= (UINT
)dwSize
;
4396 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4399 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4400 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4403 nmtbr
.pCurrent
= nmtbr
.pData
;
4405 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4406 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4408 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4412 /* remove all existing buttons as this function is designed to
4413 * restore the toolbar to a previously saved state */
4414 TOOLBAR_DeleteAllButtons(infoPtr
);
4416 for (i
= 0; i
< nmtbr
.cButtons
; i
++)
4419 nmtbr
.tbButton
.iBitmap
= -1;
4420 nmtbr
.tbButton
.fsState
= 0;
4421 nmtbr
.tbButton
.fsStyle
= 0;
4422 nmtbr
.tbButton
.idCommand
= 0;
4423 if (*nmtbr
.pCurrent
== (DWORD
)-1)
4426 nmtbr
.tbButton
.fsStyle
= TBSTYLE_SEP
;
4427 nmtbr
.tbButton
.iBitmap
= SEPARATOR_WIDTH
;
4429 else if (*nmtbr
.pCurrent
== (DWORD
)-2)
4431 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4433 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4437 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4439 /* can't contain real string as we don't know whether
4440 * the client put an ANSI or Unicode string in there */
4441 if (HIWORD(nmtbr
.tbButton
.iString
))
4442 nmtbr
.tbButton
.iString
= 0;
4444 TOOLBAR_InsertButtonW(infoPtr
->hwndSelf
, -1,
4445 (LPARAM
)&nmtbr
.tbButton
);
4448 /* do legacy notifications */
4449 if (infoPtr
->iVersion
< 5)
4451 /* FIXME: send TBN_BEGINADJUST */
4452 FIXME("send TBN_GETBUTTONINFO for each button\n");
4453 /* FIXME: send TBN_ENDADJUST */
4456 /* remove all uninitialised buttons
4457 * note: loop backwards to avoid having to fixup i on a
4459 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4460 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4461 TOOLBAR_DeleteButton(infoPtr
->hwndSelf
, i
, 0);
4463 /* only indicate success if at least one button survived */
4464 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4475 TOOLBAR_SaveRestoreW (HWND hwnd
, WPARAM wParam
, LPTBSAVEPARAMSW lpSave
)
4477 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4479 if (lpSave
== NULL
) return 0;
4482 return TOOLBAR_Save(infoPtr
, lpSave
);
4484 return TOOLBAR_Restore(infoPtr
, lpSave
);
4489 TOOLBAR_SaveRestoreA (HWND hwnd
, WPARAM wParam
, LPTBSAVEPARAMSA lpSave
)
4491 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4492 TBSAVEPARAMSW SaveW
;
4496 if (lpSave
== NULL
) return 0;
4498 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4499 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4500 if (pszSubKey
) goto exit
;
4501 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4503 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4504 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4505 if (!pszValueName
) goto exit
;
4506 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4508 SaveW
.pszValueName
= pszValueName
;
4509 SaveW
.pszSubKey
= pszSubKey
;
4510 SaveW
.hkr
= lpSave
->hkr
;
4511 result
= TOOLBAR_SaveRestoreW(hwnd
, wParam
, &SaveW
);
4514 Free (pszValueName
);
4522 TOOLBAR_SetAnchorHighlight (HWND hwnd
, WPARAM wParam
)
4524 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4525 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4527 TRACE("hwnd=%p, bAnchor = %s\n", hwnd
, wParam
? "TRUE" : "FALSE");
4529 infoPtr
->bAnchor
= (BOOL
)wParam
;
4531 /* Native does not remove the hot effect from an already hot button */
4533 return (LRESULT
)bOldAnchor
;
4538 TOOLBAR_SetBitmapSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4540 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4541 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4543 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd
, wParam
, lParam
);
4546 FIXME("wParam is %d. Perhaps image list index?\n", wParam
);
4548 if ((LOWORD(lParam
) <= 0) || (HIWORD(lParam
)<=0))
4549 lParam
= MAKELPARAM(16, 15);
4551 if (infoPtr
->nNumButtons
> 0)
4552 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4553 infoPtr
->nNumButtons
,
4554 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
4555 LOWORD(lParam
), HIWORD(lParam
));
4557 infoPtr
->nBitmapWidth
= (INT
)LOWORD(lParam
);
4558 infoPtr
->nBitmapHeight
= (INT
)HIWORD(lParam
);
4561 if ((himlDef
== infoPtr
->himlInt
) &&
4562 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4564 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4565 infoPtr
->nBitmapHeight
);
4568 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4574 TOOLBAR_SetButtonInfoA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4576 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4577 LPTBBUTTONINFOA lptbbi
= (LPTBBUTTONINFOA
)lParam
;
4578 TBUTTON_INFO
*btnPtr
;
4584 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOA
))
4587 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4588 lptbbi
->dwMask
& 0x80000000);
4592 btnPtr
= &infoPtr
->buttons
[nIndex
];
4593 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4594 btnPtr
->idCommand
= lptbbi
->idCommand
;
4595 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4596 btnPtr
->iBitmap
= lptbbi
->iImage
;
4597 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4598 btnPtr
->dwData
= lptbbi
->lParam
;
4599 if (lptbbi
->dwMask
& TBIF_SIZE
)
4600 btnPtr
->cx
= lptbbi
->cx
;
4601 if (lptbbi
->dwMask
& TBIF_STATE
)
4602 btnPtr
->fsState
= lptbbi
->fsState
;
4603 if (lptbbi
->dwMask
& TBIF_STYLE
)
4604 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4606 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4607 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4608 /* iString is index, zero it to make Str_SetPtr succeed */
4611 Str_SetPtrAtoW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4614 /* save the button rect to see if we need to redraw the whole toolbar */
4615 oldBtnRect
= btnPtr
->rect
;
4616 TOOLBAR_CalcToolbar(hwnd
);
4618 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4619 InvalidateRect(hwnd
, NULL
, TRUE
);
4621 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4628 TOOLBAR_SetButtonInfoW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4630 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4631 LPTBBUTTONINFOW lptbbi
= (LPTBBUTTONINFOW
)lParam
;
4632 TBUTTON_INFO
*btnPtr
;
4638 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4641 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4642 lptbbi
->dwMask
& 0x80000000);
4646 btnPtr
= &infoPtr
->buttons
[nIndex
];
4647 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4648 btnPtr
->idCommand
= lptbbi
->idCommand
;
4649 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4650 btnPtr
->iBitmap
= lptbbi
->iImage
;
4651 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4652 btnPtr
->dwData
= lptbbi
->lParam
;
4653 if (lptbbi
->dwMask
& TBIF_SIZE
)
4654 btnPtr
->cx
= lptbbi
->cx
;
4655 if (lptbbi
->dwMask
& TBIF_STATE
)
4656 btnPtr
->fsState
= lptbbi
->fsState
;
4657 if (lptbbi
->dwMask
& TBIF_STYLE
)
4658 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4660 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4661 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4662 /* iString is index, zero it to make Str_SetPtr succeed */
4664 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4667 /* save the button rect to see if we need to redraw the whole toolbar */
4668 oldBtnRect
= btnPtr
->rect
;
4669 TOOLBAR_CalcToolbar(hwnd
);
4671 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4672 InvalidateRect(hwnd
, NULL
, TRUE
);
4674 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4681 TOOLBAR_SetButtonSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4683 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4684 INT cx
= LOWORD(lParam
), cy
= HIWORD(lParam
);
4686 if ((cx
< 0) || (cy
< 0))
4688 ERR("invalid parameter 0x%08lx\n", (DWORD
)lParam
);
4692 TRACE("%p, cx = %d, cy = %d\n", hwnd
, cx
, cy
);
4694 /* The documentation claims you can only change the button size before
4695 * any button has been added. But this is wrong.
4696 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4697 * it to the toolbar, and it checks that the return value is nonzero - mjm
4698 * Further testing shows that we must actually perform the change too.
4701 * The documentation also does not mention that if 0 is supplied for
4702 * either size, the system changes it to the default of 24 wide and
4703 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4705 infoPtr
->nButtonWidth
= (cx
) ? cx
: 24;
4706 infoPtr
->nButtonHeight
= (cy
) ? cy
: 22;
4712 TOOLBAR_SetButtonWidth (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4714 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4716 /* if setting to current values, ignore */
4717 if ((infoPtr
->cxMin
== (INT
)LOWORD(lParam
)) &&
4718 (infoPtr
->cxMax
== (INT
)HIWORD(lParam
))) {
4719 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4720 infoPtr
->cxMin
, infoPtr
->cxMax
);
4724 /* save new values */
4725 infoPtr
->cxMin
= (INT
)LOWORD(lParam
);
4726 infoPtr
->cxMax
= (INT
)HIWORD(lParam
);
4728 /* otherwise we need to recalc the toolbar and in some cases
4729 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4730 which doesn't actually draw - GA). */
4731 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4732 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4734 TOOLBAR_CalcToolbar (hwnd
);
4736 InvalidateRect (hwnd
, NULL
, TRUE
);
4743 TOOLBAR_SetCmdId (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4745 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4746 INT nIndex
= (INT
)wParam
;
4748 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4751 infoPtr
->buttons
[nIndex
].idCommand
= (INT
)lParam
;
4753 if (infoPtr
->hwndToolTip
) {
4755 FIXME("change tool tip!\n");
4764 TOOLBAR_SetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4766 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4767 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4768 HIMAGELIST himlTemp
;
4771 if (infoPtr
->iVersion
>= 5)
4774 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4775 &infoPtr
->cimlDis
, himl
, id
);
4777 /* FIXME: redraw ? */
4779 return (LRESULT
)himlTemp
;
4784 TOOLBAR_SetDrawTextFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4786 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4789 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd
, (DWORD
)wParam
, (DWORD
)lParam
);
4791 dwTemp
= infoPtr
->dwDTFlags
;
4792 infoPtr
->dwDTFlags
=
4793 (infoPtr
->dwDTFlags
& (DWORD
)wParam
) | (DWORD
)lParam
;
4795 return (LRESULT
)dwTemp
;
4798 /* This function differs a bit from what MSDN says it does:
4799 * 1. lParam contains extended style flags to OR with current style
4800 * (MSDN isn't clear on the OR bit)
4801 * 2. wParam appears to contain extended style flags to be reset
4802 * (MSDN says that this parameter is reserved)
4805 TOOLBAR_SetExtendedStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4807 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4810 dwTemp
= infoPtr
->dwExStyle
;
4811 infoPtr
->dwExStyle
&= ~wParam
;
4812 infoPtr
->dwExStyle
|= (DWORD
)lParam
;
4814 TRACE("new style 0x%08lx\n", infoPtr
->dwExStyle
);
4816 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4817 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4818 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4820 TOOLBAR_CalcToolbar (hwnd
);
4822 TOOLBAR_AutoSize(hwnd
);
4824 InvalidateRect(hwnd
, NULL
, TRUE
);
4826 return (LRESULT
)dwTemp
;
4831 TOOLBAR_SetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4833 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4834 HIMAGELIST himlTemp
;
4835 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4838 if (infoPtr
->iVersion
>= 5)
4841 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd
, himl
, id
);
4843 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4844 &infoPtr
->cimlHot
, himl
, id
);
4846 /* FIXME: redraw ? */
4848 return (LRESULT
)himlTemp
;
4852 /* Makes previous hot button no longer hot, makes the specified
4853 * button hot and sends appropriate notifications. dwReason is one or
4854 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4855 * NOTE 1: this function does not validate nHit
4856 * NOTE 2: the name of this function is completely made up and
4857 * not based on any documentation from Microsoft. */
4859 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4861 if (infoPtr
->nHotItem
!= nHit
)
4863 NMTBHOTITEM nmhotitem
;
4864 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4865 LRESULT no_highlight
;
4867 /* Remove the effect of an old hot button if the button was
4868 drawn with the hot button effect */
4869 if(infoPtr
->nHotItem
>= 0)
4871 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4872 oldBtnPtr
->bHot
= FALSE
;
4875 infoPtr
->nHotItem
= nHit
;
4877 /* It's not a separator or in nowhere. It's a hot button. */
4879 btnPtr
= &infoPtr
->buttons
[nHit
];
4881 nmhotitem
.dwFlags
= dwReason
;
4883 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4885 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4887 nmhotitem
.idNew
= btnPtr
->idCommand
;
4889 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4891 no_highlight
= TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
);
4893 /* now invalidate the old and new buttons so they will be painted,
4894 * but only if they are enabled - disabled buttons cannot become hot */
4895 if (oldBtnPtr
&& (oldBtnPtr
->fsState
& TBSTATE_ENABLED
))
4896 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4897 if (btnPtr
&& !no_highlight
&& (btnPtr
->fsState
& TBSTATE_ENABLED
))
4899 btnPtr
->bHot
= TRUE
;
4900 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4906 TOOLBAR_SetHotItem (HWND hwnd
, WPARAM wParam
)
4908 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4909 INT nOldHotItem
= infoPtr
->nHotItem
;
4911 TRACE("hwnd = %p, nHit = %d\n", hwnd
, (INT
)wParam
);
4913 if ((INT
) wParam
< 0 || (INT
)wParam
> infoPtr
->nNumButtons
)
4916 /* NOTE: an application can still remove the hot item even if anchor
4917 * highlighting is enabled */
4919 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
4920 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, HICF_OTHER
);
4922 if (nOldHotItem
< 0)
4925 return (LRESULT
)nOldHotItem
;
4930 TOOLBAR_SetImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4932 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4933 HIMAGELIST himlTemp
;
4934 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4937 if (infoPtr
->iVersion
>= 5)
4940 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4941 &infoPtr
->cimlDef
, himl
, id
);
4943 infoPtr
->nNumBitmaps
= 0;
4944 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4945 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4947 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4948 &infoPtr
->nBitmapHeight
))
4950 infoPtr
->nBitmapWidth
= 1;
4951 infoPtr
->nBitmapHeight
= 1;
4954 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4955 hwnd
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
4956 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4958 InvalidateRect(hwnd
, NULL
, TRUE
);
4960 return (LRESULT
)himlTemp
;
4965 TOOLBAR_SetIndent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4967 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4969 infoPtr
->nIndent
= (INT
)wParam
;
4973 /* process only on indent changing */
4974 if(infoPtr
->nIndent
!= (INT
)wParam
)
4976 infoPtr
->nIndent
= (INT
)wParam
;
4977 TOOLBAR_CalcToolbar (hwnd
);
4978 InvalidateRect(hwnd
, NULL
, FALSE
);
4986 TOOLBAR_SetInsertMark (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4988 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4989 TBINSERTMARK
*lptbim
= (TBINSERTMARK
*)lParam
;
4991 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd
, lptbim
->iButton
, lptbim
->dwFlags
);
4993 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
4995 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
4999 if ((lptbim
->iButton
== -1) ||
5000 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
5001 (lptbim
->iButton
>= 0)))
5003 infoPtr
->tbim
= *lptbim
;
5004 /* FIXME: don't need to update entire toolbar */
5005 InvalidateRect(hwnd
, NULL
, TRUE
);
5008 ERR("Invalid button index %d\n", lptbim
->iButton
);
5015 TOOLBAR_SetInsertMarkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5017 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5019 infoPtr
->clrInsertMark
= (COLORREF
)lParam
;
5021 /* FIXME: don't need to update entire toolbar */
5022 InvalidateRect(hwnd
, NULL
, TRUE
);
5029 TOOLBAR_SetMaxTextRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5031 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5033 infoPtr
->nMaxTextRows
= (INT
)wParam
;
5035 TOOLBAR_CalcToolbar(hwnd
);
5040 /* MSDN gives slightly wrong info on padding.
5041 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
5042 * 2. It is not used to create a blank area between the edge of the button
5043 * and the text or image if TBSTYLE_LIST is set. It is used to control
5044 * the gap between the image and text.
5045 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
5046 * to control the bottom and right borders [with the border being
5047 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
5048 * is shared evenly on both sides of the button.
5049 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
5052 TOOLBAR_SetPadding (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5054 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5057 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
5058 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
5059 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
5060 TRACE("cx=%ld, cy=%ld\n",
5061 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
5062 return (LRESULT
) oldPad
;
5067 TOOLBAR_SetParent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5069 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5074 hwndOldNotify
= infoPtr
->hwndNotify
;
5075 infoPtr
->hwndNotify
= (HWND
)wParam
;
5077 return (LRESULT
)hwndOldNotify
;
5082 TOOLBAR_SetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5084 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5085 LPRECT lprc
= (LPRECT
)lParam
;
5089 if (LOWORD(wParam
) > 1) {
5090 FIXME("multiple rows not supported!\n");
5093 if(infoPtr
->nRows
!= LOWORD(wParam
))
5095 infoPtr
->nRows
= LOWORD(wParam
);
5097 /* recalculate toolbar */
5098 TOOLBAR_CalcToolbar (hwnd
);
5100 /* repaint toolbar */
5101 InvalidateRect(hwnd
, NULL
, TRUE
);
5104 /* return bounding rectangle */
5106 lprc
->left
= infoPtr
->rcBound
.left
;
5107 lprc
->right
= infoPtr
->rcBound
.right
;
5108 lprc
->top
= infoPtr
->rcBound
.top
;
5109 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
5117 TOOLBAR_SetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5119 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5120 TBUTTON_INFO
*btnPtr
;
5123 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
5127 btnPtr
= &infoPtr
->buttons
[nIndex
];
5129 /* if hidden state has changed the invalidate entire window and recalc */
5130 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
5131 btnPtr
->fsState
= LOWORD(lParam
);
5132 TOOLBAR_CalcToolbar (hwnd
);
5133 InvalidateRect(hwnd
, 0, TRUE
);
5137 /* process state changing if current state doesn't match new state */
5138 if(btnPtr
->fsState
!= LOWORD(lParam
))
5140 btnPtr
->fsState
= LOWORD(lParam
);
5141 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5149 TOOLBAR_SetStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5151 SetWindowLongW(hwnd
, GWL_STYLE
, lParam
);
5157 inline static LRESULT
5158 TOOLBAR_SetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5160 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5162 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd
, (HWND
)wParam
, lParam
);
5164 infoPtr
->hwndToolTip
= (HWND
)wParam
;
5170 TOOLBAR_SetUnicodeFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5172 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5175 TRACE("%s hwnd=%p\n",
5176 ((BOOL
)wParam
) ? "TRUE" : "FALSE", hwnd
);
5178 bTemp
= infoPtr
->bUnicode
;
5179 infoPtr
->bUnicode
= (BOOL
)wParam
;
5186 TOOLBAR_GetColorScheme (HWND hwnd
, LPCOLORSCHEME lParam
)
5188 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5190 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
5191 comctl32_color
.clrBtnHighlight
:
5192 infoPtr
->clrBtnHighlight
;
5193 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
5194 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
5200 TOOLBAR_SetColorScheme (HWND hwnd
, LPCOLORSCHEME lParam
)
5202 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5204 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5205 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
5206 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
5208 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
5209 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
5210 InvalidateRect(hwnd
, NULL
, TRUE
);
5216 TOOLBAR_SetVersion (HWND hwnd
, INT iVersion
)
5218 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5219 INT iOldVersion
= infoPtr
->iVersion
;
5221 infoPtr
->iVersion
= iVersion
;
5223 if (infoPtr
->iVersion
>= 5)
5224 TOOLBAR_SetUnicodeFormat(hwnd
, (WPARAM
)TRUE
, (LPARAM
)0);
5231 TOOLBAR_GetStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5233 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5234 WORD iString
= HIWORD(wParam
);
5235 WORD buffersize
= LOWORD(wParam
);
5236 LPSTR str
= (LPSTR
)lParam
;
5239 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, buffersize
, str
);
5241 if (iString
< infoPtr
->nNumStrings
)
5243 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
5245 TRACE("returning %s\n", debugstr_a(str
));
5248 ERR("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5255 TOOLBAR_GetStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5257 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5258 WORD iString
= HIWORD(wParam
);
5259 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5260 LPWSTR str
= (LPWSTR
)lParam
;
5263 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, LOWORD(wParam
), str
);
5265 if (iString
< infoPtr
->nNumStrings
)
5267 len
= min(len
, strlenW(infoPtr
->strings
[iString
]));
5268 ret
= (len
+1)*sizeof(WCHAR
);
5269 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5272 TRACE("returning %s\n", debugstr_w(str
));
5275 ERR("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5280 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5281 * is the maximum size of the toolbar? */
5282 static LRESULT
TOOLBAR_Unkwn45D(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5284 SIZE
* pSize
= (SIZE
*)lParam
;
5285 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5290 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5291 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5292 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5295 TOOLBAR_Unkwn45E (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5297 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5298 INT nOldHotItem
= infoPtr
->nHotItem
;
5300 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5301 nOldHotItem
, infoPtr
->nHotItem
, (DWORD
)lParam
);
5303 if ((INT
) wParam
< 0 || (INT
)wParam
> infoPtr
->nNumButtons
)
5306 /* NOTE: an application can still remove the hot item even if anchor
5307 * highlighting is enabled */
5309 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, lParam
);
5313 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5316 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5317 * which controls the amount of spacing between the image and the text
5318 * of buttons for TBSTYLE_LIST toolbars. */
5319 static LRESULT
TOOLBAR_Unkwn460(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5321 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5323 TRACE("hwnd=%p iListGap=%d\n", hwnd
, wParam
);
5326 FIXME("lParam = 0x%08lx. Please report\n", lParam
);
5328 infoPtr
->iListGap
= (INT
)wParam
;
5330 InvalidateRect(hwnd
, NULL
, TRUE
);
5335 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5336 * of image lists associated with the various states. */
5337 static LRESULT
TOOLBAR_Unkwn462(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5339 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5341 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd
, wParam
, lParam
);
5343 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5347 TOOLBAR_Unkwn463 (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5349 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5350 LPSIZE lpsize
= (LPSIZE
)lParam
;
5356 * Testing shows the following:
5357 * wParam = 0 adjust cx value
5358 * = 1 set cy value to max size.
5359 * lParam pointer to SIZE structure
5362 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5363 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5367 if (lpsize
->cx
== -1) {
5368 /* **** this is wrong, native measures each button and sets it */
5369 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5371 else if(HIWORD(lpsize
->cx
)) {
5373 HWND hwndParent
= GetParent(hwnd
);
5375 GetWindowRect(hwnd
, &rc
);
5376 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5377 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5378 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5379 lpsize
->cx
= max(rc
.right
-rc
.left
,
5380 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5383 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5387 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5390 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5394 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5395 lpsize
->cx
, lpsize
->cy
);
5399 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5401 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd
, wParam
, lParam
);
5403 InvalidateRect(hwnd
, NULL
, TRUE
);
5409 TOOLBAR_Create (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5411 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5412 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
5415 TRACE("hwnd = %p\n", hwnd
);
5417 /* initialize info structure */
5418 infoPtr
->nButtonHeight
= 22;
5419 infoPtr
->nButtonWidth
= 24;
5420 infoPtr
->nBitmapHeight
= 15;
5421 infoPtr
->nBitmapWidth
= 16;
5423 infoPtr
->nMaxTextRows
= 1;
5424 infoPtr
->cxMin
= -1;
5425 infoPtr
->cxMax
= -1;
5426 infoPtr
->nNumBitmaps
= 0;
5427 infoPtr
->nNumStrings
= 0;
5429 infoPtr
->bCaptured
= FALSE
;
5430 infoPtr
->nButtonDown
= -1;
5431 infoPtr
->nButtonDrag
= -1;
5432 infoPtr
->nOldHit
= -1;
5433 infoPtr
->nHotItem
= -1;
5434 infoPtr
->hwndNotify
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
5435 infoPtr
->dwDTFlags
= (dwStyle
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
5436 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
5437 infoPtr
->bDragOutSent
= FALSE
;
5438 infoPtr
->iVersion
= 0;
5439 infoPtr
->hwndSelf
= hwnd
;
5440 infoPtr
->bDoRedraw
= TRUE
;
5441 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
5442 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
5443 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
5444 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
5445 infoPtr
->iListGap
= DEFLISTGAP
;
5446 infoPtr
->dwStyle
= dwStyle
;
5447 infoPtr
->tbim
.iButton
= -1;
5448 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5449 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5450 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, (LPARAM
)NF_REQUERY
));
5451 infoPtr
->hwndToolTip
= NULL
; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5453 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5454 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5456 OpenThemeData (hwnd
, themeClass
);
5458 TOOLBAR_CheckStyle (hwnd
, dwStyle
);
5460 TOOLBAR_CalcToolbar(hwnd
);
5467 TOOLBAR_Destroy (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5469 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5471 /* delete tooltip control */
5472 if (infoPtr
->hwndToolTip
)
5473 DestroyWindow (infoPtr
->hwndToolTip
);
5475 /* delete temporary buffer for tooltip text */
5476 Free (infoPtr
->pszTooltipText
);
5477 Free (infoPtr
->bitmaps
); /* bitmaps list */
5479 /* delete button data */
5480 if (infoPtr
->buttons
)
5481 Free (infoPtr
->buttons
);
5483 /* delete strings */
5484 if (infoPtr
->strings
) {
5486 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5487 if (infoPtr
->strings
[i
])
5488 Free (infoPtr
->strings
[i
]);
5490 Free (infoPtr
->strings
);
5493 /* destroy internal image list */
5494 if (infoPtr
->himlInt
)
5495 ImageList_Destroy (infoPtr
->himlInt
);
5497 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5498 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5499 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5501 /* delete default font */
5503 DeleteObject (infoPtr
->hDefaultFont
);
5505 CloseThemeData (GetWindowTheme (hwnd
));
5507 /* free toolbar info data */
5509 SetWindowLongPtrW (hwnd
, 0, 0);
5516 TOOLBAR_EraseBackground (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5518 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5519 NMTBCUSTOMDRAW tbcd
;
5522 HTHEME theme
= GetWindowTheme (hwnd
);
5524 /* the app has told us not to redraw the toolbar */
5525 if (!infoPtr
->bDoRedraw
)
5528 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5529 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5530 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5531 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5532 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5533 infoPtr
->dwBaseCustDraw
= ntfret
& 0xffff;
5535 /* FIXME: in general the return flags *can* be or'ed together */
5536 switch (infoPtr
->dwBaseCustDraw
)
5538 case CDRF_DODEFAULT
:
5540 case CDRF_SKIPDEFAULT
:
5543 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5548 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5549 * to my parent for processing.
5551 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5553 HDC hdc
= (HDC
)wParam
;
5558 parent
= GetParent(hwnd
);
5559 MapWindowPoints(hwnd
, parent
, &pt
, 1);
5560 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5561 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5562 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5565 ret
= DefWindowProcW (hwnd
, WM_ERASEBKGND
, wParam
, lParam
);
5567 if ((infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) &&
5568 (infoPtr
->dwBaseCustDraw
& CDRF_NOTIFYPOSTERASE
)) {
5569 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5570 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5571 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5572 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5573 infoPtr
->dwBaseCustDraw
= ntfret
& 0xffff;
5574 switch (infoPtr
->dwBaseCustDraw
)
5576 case CDRF_DODEFAULT
:
5578 case CDRF_SKIPDEFAULT
:
5581 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5590 TOOLBAR_GetFont (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5592 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5594 return (LRESULT
)infoPtr
->hFont
;
5599 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5602 INT nNewHotItem
= infoPtr
->nHotItem
;
5604 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5607 if ((nNewHotItem
+ iDirection
< 0) ||
5608 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5610 NMTBWRAPHOTITEM nmtbwhi
;
5611 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5612 nmtbwhi
.iDirection
= iDirection
;
5613 nmtbwhi
.dwReason
= dwReason
;
5615 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5619 nNewHotItem
+= iDirection
;
5620 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5622 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5623 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5625 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5632 TOOLBAR_KeyDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5634 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5637 nmkey
.nVKey
= (UINT
)wParam
;
5638 nmkey
.uFlags
= HIWORD(lParam
);
5640 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5641 return DefWindowProcW(hwnd
, WM_KEYDOWN
, wParam
, lParam
);
5643 switch ((UINT
)wParam
)
5647 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5651 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5655 if ((infoPtr
->nHotItem
>= 0) &&
5656 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5658 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5659 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5670 TOOLBAR_LButtonDblClk (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5675 pt
.x
= (INT
)LOWORD(lParam
);
5676 pt
.y
= (INT
)HIWORD(lParam
);
5677 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5680 TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
5681 else if (GetWindowLongW (hwnd
, GWL_STYLE
) & CCS_ADJUSTABLE
)
5682 TOOLBAR_Customize (hwnd
);
5689 TOOLBAR_LButtonDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5691 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5692 TBUTTON_INFO
*btnPtr
;
5697 BOOL bDragKeyPressed
;
5701 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5702 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5704 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5706 if (infoPtr
->hwndToolTip
)
5707 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5708 WM_LBUTTONDOWN
, wParam
, lParam
);
5710 pt
.x
= (INT
)LOWORD(lParam
);
5711 pt
.y
= (INT
)HIWORD(lParam
);
5712 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5714 btnPtr
= &infoPtr
->buttons
[nHit
];
5716 if ((nHit
>= 0) && bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5718 infoPtr
->nButtonDrag
= nHit
;
5721 /* If drag cursor has not been loaded, load it.
5722 * Note: it doesn't need to be freed */
5724 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5725 SetCursor(hCursorDrag
);
5730 infoPtr
->nOldHit
= nHit
;
5732 CopyRect(&arrowRect
, &btnPtr
->rect
);
5733 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5735 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5736 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5737 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5738 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5739 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5740 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5744 /* draw in pressed state */
5745 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5746 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5748 btnPtr
->bDropDownPressed
= TRUE
;
5749 RedrawWindow(hwnd
,&btnPtr
->rect
,0,
5750 RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5752 memset(&nmtb
, 0, sizeof(nmtb
));
5753 nmtb
.iItem
= btnPtr
->idCommand
;
5754 nmtb
.rcButton
= btnPtr
->rect
;
5755 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5757 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5759 if (res
!= TBDDRET_TREATPRESSED
)
5763 /* redraw button in unpressed state */
5764 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5765 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5767 btnPtr
->bDropDownPressed
= FALSE
;
5768 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5770 /* find and set hot item
5771 * NOTE: native doesn't do this, but that is a bug */
5773 ScreenToClient(hwnd
, &pt
);
5774 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
5775 if (!infoPtr
->bAnchor
|| (nHit
>= 0))
5776 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5778 /* remove any left mouse button down or double-click messages
5779 * so that we can get a toggle effect on the button */
5780 while (PeekMessageW(&msg
, hwnd
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5781 PeekMessageW(&msg
, hwnd
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5786 /* otherwise drop through and process as pushed */
5788 infoPtr
->bCaptured
= TRUE
;
5789 infoPtr
->nButtonDown
= nHit
;
5790 infoPtr
->bDragOutSent
= FALSE
;
5792 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5794 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5796 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5797 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5804 memset(&nmtb
, 0, sizeof(nmtb
));
5805 nmtb
.iItem
= btnPtr
->idCommand
;
5806 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
5809 nmmouse
.dwHitInfo
= nHit
;
5811 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5813 nmmouse
.dwItemSpec
= -1;
5816 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5817 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5820 ClientToScreen(hwnd
, &pt
);
5823 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
5824 return DefWindowProcW(hwnd
, WM_LBUTTONDOWN
, wParam
, lParam
);
5830 TOOLBAR_LButtonUp (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5832 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5833 TBUTTON_INFO
*btnPtr
;
5837 BOOL bSendMessage
= TRUE
;
5842 if (infoPtr
->hwndToolTip
)
5843 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5844 WM_LBUTTONUP
, wParam
, lParam
);
5846 pt
.x
= (INT
)LOWORD(lParam
);
5847 pt
.y
= (INT
)HIWORD(lParam
);
5848 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5850 if (!infoPtr
->bAnchor
|| (nHit
>= 0))
5851 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5853 if (infoPtr
->nButtonDrag
>= 0) {
5857 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
5860 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
5862 GetClientRect(hwnd
, &rcClient
);
5863 if (PtInRect(&rcClient
, pt
))
5870 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
5873 if (nButton
== infoPtr
->nButtonDrag
)
5875 /* if the button is moved sightly left and we have a
5876 * separator there then remove it */
5877 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
5879 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
5880 TOOLBAR_DeleteButton(hwnd
, nButton
- 1, 0);
5882 else /* else insert a separator before the dragged button */
5885 memset(&tbb
, 0, sizeof(tbb
));
5886 tbb
.fsStyle
= BTNS_SEP
;
5888 TOOLBAR_InsertButtonW(hwnd
, nButton
, (LPARAM
)&tbb
);
5895 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
5896 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, 0);
5898 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
5901 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, nButton
);
5906 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
5907 TOOLBAR_DeleteButton(hwnd
, (WPARAM
)infoPtr
->nButtonDrag
, 0);
5910 /* button under cursor changed so need to re-set hot item */
5911 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5912 infoPtr
->nButtonDrag
= -1;
5914 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
5916 else if (infoPtr
->nButtonDown
>= 0) {
5917 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5918 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5920 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5921 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5922 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5924 if (nOldIndex
== nHit
)
5925 bSendMessage
= FALSE
;
5926 if ((nOldIndex
!= nHit
) &&
5928 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5929 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5932 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5933 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5935 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5939 if (nOldIndex
!= -1)
5940 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5943 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5944 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5945 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5947 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5949 infoPtr
->nButtonDown
= -1;
5951 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5952 TOOLBAR_SendNotify ((NMHDR
*) &hdr
, infoPtr
,
5953 NM_RELEASEDCAPTURE
);
5955 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5958 memset(&nmtb
, 0, sizeof(nmtb
));
5959 nmtb
.iItem
= btnPtr
->idCommand
;
5960 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5963 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5965 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5966 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)hwnd
);
5970 /* !!! Undocumented - toolbar at 4.71 level and above sends
5971 * NM_CLICK with the NMMOUSE structure. */
5972 nmmouse
.dwHitInfo
= nHit
;
5975 nmmouse
.dwItemSpec
= -1;
5978 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
5979 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
5982 ClientToScreen(hwnd
, &pt
);
5985 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
5986 return DefWindowProcW(hwnd
, WM_LBUTTONUP
, wParam
, lParam
);
5992 TOOLBAR_RButtonUp( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5994 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5999 pt
.x
= LOWORD(lParam
);
6000 pt
.y
= HIWORD(lParam
);
6002 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
6003 nmmouse
.dwHitInfo
= nHit
;
6006 nmmouse
.dwItemSpec
= -1;
6008 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
6009 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
6012 ClientToScreen(hwnd
, &pt
);
6015 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
6016 return DefWindowProcW(hwnd
, WM_RBUTTONUP
, wParam
, lParam
);
6022 TOOLBAR_RButtonDblClk( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6024 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6027 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
6028 return DefWindowProcW(hwnd
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
6034 TOOLBAR_CaptureChanged(HWND hwnd
)
6036 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6037 TBUTTON_INFO
*btnPtr
;
6039 infoPtr
->bCaptured
= FALSE
;
6041 if (infoPtr
->nButtonDown
>= 0)
6043 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6044 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6046 infoPtr
->nOldHit
= -1;
6048 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
6049 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6055 TOOLBAR_MouseLeave (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6057 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6058 TBUTTON_INFO
*hotBtnPtr
;
6060 hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nOldHit
];
6062 /* don't remove hot effects when in anchor highlighting mode or when a
6063 * drop-down button is pressed */
6064 if (!infoPtr
->bAnchor
&& (infoPtr
->nOldHit
< 0 || !hotBtnPtr
->bDropDownPressed
))
6065 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
6067 if (infoPtr
->nOldHit
< 0)
6070 /* If the last button we were over is depressed then make it not */
6071 /* depressed and redraw it */
6072 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
6074 TBUTTON_INFO
*btnPtr
;
6077 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6079 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6081 rc1
= hotBtnPtr
->rect
;
6082 InflateRect (&rc1
, 1, 1);
6083 InvalidateRect (hwnd
, &rc1
, TRUE
);
6086 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
6089 ZeroMemory(&nmt
, sizeof(nmt
));
6090 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6091 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6092 infoPtr
->bDragOutSent
= TRUE
;
6095 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
6101 TOOLBAR_MouseMove (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6103 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6105 TRACKMOUSEEVENT trackinfo
;
6107 TBUTTON_INFO
*btnPtr
;
6109 if ((infoPtr
->dwStyle
& TBSTYLE_TOOLTIPS
) && (infoPtr
->hwndToolTip
== NULL
))
6110 TOOLBAR_TooltipCreateControl(infoPtr
);
6112 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
6113 /* fill in the TRACKMOUSEEVENT struct */
6114 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
6115 trackinfo
.dwFlags
= TME_QUERY
;
6117 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6118 _TrackMouseEvent(&trackinfo
);
6120 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6121 if(trackinfo
.hwndTrack
!= hwnd
|| !(trackinfo
.dwFlags
& TME_LEAVE
)) {
6122 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
6123 trackinfo
.hwndTrack
= hwnd
;
6125 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6126 /* and can properly deactivate the hot toolbar button */
6127 _TrackMouseEvent(&trackinfo
);
6131 if (infoPtr
->hwndToolTip
)
6132 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
6133 WM_MOUSEMOVE
, wParam
, lParam
);
6135 pt
.x
= (INT
)LOWORD(lParam
);
6136 pt
.y
= (INT
)HIWORD(lParam
);
6138 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
6140 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6141 && (!infoPtr
->bAnchor
|| (nHit
>= 0)))
6142 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
);
6144 if (infoPtr
->nOldHit
!= nHit
)
6146 if (infoPtr
->bCaptured
)
6148 if (!infoPtr
->bDragOutSent
)
6151 ZeroMemory(&nmt
, sizeof(nmt
));
6152 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6153 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6154 infoPtr
->bDragOutSent
= TRUE
;
6157 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6158 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
6159 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6160 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6162 else if (nHit
== infoPtr
->nButtonDown
) {
6163 btnPtr
->fsState
|= TBSTATE_PRESSED
;
6164 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6166 infoPtr
->nOldHit
= nHit
;
6174 inline static LRESULT
6175 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6177 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6178 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
6180 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6184 inline static LRESULT
6185 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6187 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
6188 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
6190 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
6195 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6197 TOOLBAR_INFO
*infoPtr
;
6198 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
6201 /* allocate memory for info structure */
6202 infoPtr
= (TOOLBAR_INFO
*)Alloc (sizeof(TOOLBAR_INFO
));
6203 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
6206 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
6208 infoPtr
->nWidth
= 0;
6210 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6211 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
6212 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
6213 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
6216 /* native control does:
6217 * Get a lot of colors and brushes
6219 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6220 * CreateFontIndirectW(adr1)
6221 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6222 * hdc = GetDC(toolbar)
6223 * GetSystemMetrics(0x48)
6224 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6225 * 0, 0, 0, 0, "MARLETT")
6226 * oldfnt = SelectObject(hdc, fnt2)
6227 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6228 * GetTextMetricsW(hdc, adr3)
6229 * SelectObject(hdc, oldfnt)
6230 * DeleteObject(fnt2)
6232 * InvalidateRect(toolbar, 0, 1)
6233 * SetWindowLongW(toolbar, 0, addr)
6234 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6237 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6238 * ie 2 0x4600094c 0x4600094c 0x4600894d
6239 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6240 * rebar 0x50008844 0x40008844 0x50008845
6241 * pager 0x50000844 0x40000844 0x50008845
6242 * IC35mgr 0x5400084e **nochange**
6243 * on entry to _NCCREATE 0x5400084e
6244 * rowlist 0x5400004e **nochange**
6245 * on entry to _NCCREATE 0x5400004e
6249 /* I think the code below is a bug, but it is the way that the native
6250 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6251 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6252 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6253 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6254 * Somehow, the only cases of this seem to be MFC programs.
6256 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6257 * does not occur in the WM_STYLECHANGING routine.
6258 * (Guy Albertelli 9/2001)
6261 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6262 && !(cs
->style
& TBSTYLE_TRANSPARENT
))
6263 styleadd
|= TBSTYLE_TRANSPARENT
;
6264 if (!(cs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
6265 styleadd
|= CCS_TOP
; /* default to top */
6266 SetWindowLongW (hwnd
, GWL_STYLE
, cs
->style
| styleadd
);
6269 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, lParam
);
6274 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6276 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
6280 if (dwStyle
& WS_MINIMIZE
)
6281 return 0; /* Nothing to do */
6283 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
6285 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
6288 if (!(dwStyle
& CCS_NODIVIDER
))
6290 GetWindowRect (hwnd
, &rcWindow
);
6291 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
6292 if( dwStyle
& WS_BORDER
)
6293 OffsetRect (&rcWindow
, 1, 1);
6294 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6297 ReleaseDC( hwnd
, hdc
);
6303 /* handles requests from the tooltip control on what text to display */
6304 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6306 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6308 TRACE("button index = %d\n", index
);
6310 Free (infoPtr
->pszTooltipText
);
6311 infoPtr
->pszTooltipText
= NULL
;
6316 if (infoPtr
->bUnicode
)
6318 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6319 NMTBGETINFOTIPW tbgit
;
6320 unsigned int len
; /* in chars */
6322 wszBuffer
[0] = '\0';
6323 wszBuffer
[INFOTIPSIZE
] = '\0';
6325 tbgit
.pszText
= wszBuffer
;
6326 tbgit
.cchTextMax
= INFOTIPSIZE
;
6327 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6328 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6330 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6332 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6334 len
= strlenW(tbgit
.pszText
);
6335 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6337 /* need to allocate temporary buffer in infoPtr as there
6338 * isn't enough space in buffer passed to us by the
6339 * tooltip control */
6340 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6341 if (infoPtr
->pszTooltipText
)
6343 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6344 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6350 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6356 CHAR szBuffer
[INFOTIPSIZE
+1];
6357 NMTBGETINFOTIPA tbgit
;
6358 unsigned int len
; /* in chars */
6361 szBuffer
[INFOTIPSIZE
] = '\0';
6363 tbgit
.pszText
= szBuffer
;
6364 tbgit
.cchTextMax
= INFOTIPSIZE
;
6365 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6366 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6368 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6370 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6372 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6373 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]))
6375 /* need to allocate temporary buffer in infoPtr as there
6376 * isn't enough space in buffer passed to us by the
6377 * tooltip control */
6378 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6379 if (infoPtr
->pszTooltipText
)
6381 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6382 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6388 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1,
6389 lpnmtdi
->lpszText
, sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]));
6394 /* if button has text, but it is not shown then automatically
6395 * use that text as tooltip */
6396 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6397 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6399 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6400 unsigned int len
= pszText
? strlenW(pszText
) : 0;
6402 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6404 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6406 /* need to allocate temporary buffer in infoPtr as there
6407 * isn't enough space in buffer passed to us by the
6408 * tooltip control */
6409 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6410 if (infoPtr
->pszTooltipText
)
6412 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6413 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6419 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6424 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6426 /* last resort: send notification on to app */
6427 /* FIXME: find out what is really used here */
6428 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, 0, (LPARAM
)lpnmtdi
);
6432 inline static LRESULT
6433 TOOLBAR_Notify (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6435 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6436 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
6438 switch (lpnmh
->code
)
6442 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
6444 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6445 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6446 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6450 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6451 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6459 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lParam
;
6461 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6462 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6463 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6464 lppgs
->iScroll
, lppgs
->iDir
);
6468 case TTN_GETDISPINFOW
:
6469 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lParam
);
6471 case TTN_GETDISPINFOA
:
6472 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6482 TOOLBAR_NotifyFormat(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6486 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam
, lParam
);
6488 if (lParam
== NF_QUERY
)
6491 if (lParam
== NF_REQUERY
) {
6492 format
= SendMessageW(infoPtr
->hwndNotify
,
6493 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6494 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6495 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6506 TOOLBAR_Paint (HWND hwnd
, WPARAM wParam
)
6508 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
6512 /* fill ps.rcPaint with a default rect */
6513 memcpy(&(ps
.rcPaint
), &(infoPtr
->rcBound
), sizeof(infoPtr
->rcBound
));
6515 hdc
= wParam
==0 ? BeginPaint(hwnd
, &ps
) : (HDC
)wParam
;
6517 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6518 ps
.rcPaint
.left
, ps
.rcPaint
.top
,
6519 ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
6521 TOOLBAR_Refresh (hwnd
, hdc
, &ps
);
6522 if (!wParam
) EndPaint (hwnd
, &ps
);
6529 TOOLBAR_SetFocus (HWND hwnd
, WPARAM wParam
)
6531 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6533 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6535 /* make first item hot */
6536 if (infoPtr
->nNumButtons
> 0)
6537 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6544 TOOLBAR_SetRedraw (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6545 /*****************************************************
6548 * Handles the WM_SETREDRAW message.
6551 * According to testing V4.71 of COMCTL32 returns the
6552 * *previous* status of the redraw flag (either 0 or 1)
6553 * instead of the MSDN documented value of 0 if handled.
6554 * (For laughs see the "consistency" with same function
6557 *****************************************************/
6559 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6560 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6562 TRACE("set to %s\n",
6563 (wParam
) ? "TRUE" : "FALSE");
6564 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6566 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6568 return (oldredraw
) ? 1 : 0;
6573 TOOLBAR_Size (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6575 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6577 TRACE("sizing toolbar!\n");
6579 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6581 RECT delta_width
, delta_height
, client
, dummy
;
6582 DWORD min_x
, max_x
, min_y
, max_y
;
6583 TBUTTON_INFO
*btnPtr
;
6586 GetClientRect(hwnd
, &client
);
6587 if(client
.right
> infoPtr
->client_rect
.right
)
6589 min_x
= infoPtr
->client_rect
.right
;
6590 max_x
= client
.right
;
6594 max_x
= infoPtr
->client_rect
.right
;
6595 min_x
= client
.right
;
6597 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6599 min_y
= infoPtr
->client_rect
.bottom
;
6600 max_y
= client
.bottom
;
6604 max_y
= infoPtr
->client_rect
.bottom
;
6605 min_y
= client
.bottom
;
6608 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6609 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6611 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6612 btnPtr
= infoPtr
->buttons
;
6613 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6614 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6615 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6616 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6618 GetClientRect(hwnd
, &infoPtr
->client_rect
);
6619 TOOLBAR_AutoSize(hwnd
);
6625 TOOLBAR_StyleChanged (HWND hwnd
, INT nType
, LPSTYLESTRUCT lpStyle
)
6627 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6629 if (nType
== GWL_STYLE
)
6631 DWORD dwOldStyle
= infoPtr
->dwStyle
;
6633 if (lpStyle
->styleNew
& TBSTYLE_LIST
)
6634 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
6636 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
6638 TOOLBAR_CheckStyle (hwnd
, lpStyle
->styleNew
);
6640 TRACE("new style 0x%08lx\n", lpStyle
->styleNew
);
6642 infoPtr
->dwStyle
= lpStyle
->styleNew
;
6644 /* only resize if one of the CCS_* styles was changed */
6645 if ((dwOldStyle
^ lpStyle
->styleNew
) & COMMON_STYLES
)
6647 TOOLBAR_AutoSize (hwnd
);
6649 InvalidateRect(hwnd
, NULL
, TRUE
);
6658 TOOLBAR_SysColorChange (HWND hwnd
)
6660 COMCTL32_RefreshSysColors();
6666 /* update theme after a WM_THEMECHANGED message */
6667 static LRESULT
theme_changed (HWND hwnd
)
6669 HTHEME theme
= GetWindowTheme (hwnd
);
6670 CloseThemeData (theme
);
6671 OpenThemeData (hwnd
, themeClass
);
6676 static LRESULT WINAPI
6677 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6679 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6681 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6682 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6684 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6685 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6690 return TOOLBAR_AddBitmap (hwnd
, wParam
, lParam
);
6692 case TB_ADDBUTTONSA
:
6693 return TOOLBAR_AddButtonsT(hwnd
, wParam
, lParam
, FALSE
);
6695 case TB_ADDBUTTONSW
:
6696 return TOOLBAR_AddButtonsT(hwnd
, wParam
, lParam
, TRUE
);
6699 return TOOLBAR_AddStringA (hwnd
, wParam
, lParam
);
6702 return TOOLBAR_AddStringW (hwnd
, wParam
, lParam
);
6705 return TOOLBAR_AutoSize (hwnd
);
6707 case TB_BUTTONCOUNT
:
6708 return TOOLBAR_ButtonCount (hwnd
, wParam
, lParam
);
6710 case TB_BUTTONSTRUCTSIZE
:
6711 return TOOLBAR_ButtonStructSize (hwnd
, wParam
, lParam
);
6713 case TB_CHANGEBITMAP
:
6714 return TOOLBAR_ChangeBitmap (hwnd
, wParam
, lParam
);
6716 case TB_CHECKBUTTON
:
6717 return TOOLBAR_CheckButton (hwnd
, wParam
, lParam
);
6719 case TB_COMMANDTOINDEX
:
6720 return TOOLBAR_CommandToIndex (hwnd
, wParam
, lParam
);
6723 return TOOLBAR_Customize (hwnd
);
6725 case TB_DELETEBUTTON
:
6726 return TOOLBAR_DeleteButton (hwnd
, wParam
, lParam
);
6728 case TB_ENABLEBUTTON
:
6729 return TOOLBAR_EnableButton (hwnd
, wParam
, lParam
);
6731 case TB_GETANCHORHIGHLIGHT
:
6732 return TOOLBAR_GetAnchorHighlight (hwnd
);
6735 return TOOLBAR_GetBitmap (hwnd
, wParam
, lParam
);
6737 case TB_GETBITMAPFLAGS
:
6738 return TOOLBAR_GetBitmapFlags (hwnd
, wParam
, lParam
);
6741 return TOOLBAR_GetButton (hwnd
, wParam
, lParam
);
6743 case TB_GETBUTTONINFOA
:
6744 return TOOLBAR_GetButtonInfoA (hwnd
, wParam
, lParam
);
6746 case TB_GETBUTTONINFOW
:
6747 return TOOLBAR_GetButtonInfoW (hwnd
, wParam
, lParam
);
6749 case TB_GETBUTTONSIZE
:
6750 return TOOLBAR_GetButtonSize (hwnd
);
6752 case TB_GETBUTTONTEXTA
:
6753 return TOOLBAR_GetButtonTextA (hwnd
, wParam
, lParam
);
6755 case TB_GETBUTTONTEXTW
:
6756 return TOOLBAR_GetButtonTextW (hwnd
, wParam
, lParam
);
6758 case TB_GETDISABLEDIMAGELIST
:
6759 return TOOLBAR_GetDisabledImageList (hwnd
, wParam
, lParam
);
6761 case TB_GETEXTENDEDSTYLE
:
6762 return TOOLBAR_GetExtendedStyle (hwnd
);
6764 case TB_GETHOTIMAGELIST
:
6765 return TOOLBAR_GetHotImageList (hwnd
, wParam
, lParam
);
6768 return TOOLBAR_GetHotItem (hwnd
);
6770 case TB_GETIMAGELIST
:
6771 return TOOLBAR_GetDefImageList (hwnd
, wParam
, lParam
);
6773 case TB_GETINSERTMARK
:
6774 return TOOLBAR_GetInsertMark (hwnd
, wParam
, lParam
);
6776 case TB_GETINSERTMARKCOLOR
:
6777 return TOOLBAR_GetInsertMarkColor (hwnd
, wParam
, lParam
);
6779 case TB_GETITEMRECT
:
6780 return TOOLBAR_GetItemRect (hwnd
, wParam
, lParam
);
6783 return TOOLBAR_GetMaxSize (hwnd
, wParam
, lParam
);
6785 /* case TB_GETOBJECT: */ /* 4.71 */
6788 return TOOLBAR_GetPadding (hwnd
);
6791 return TOOLBAR_GetRect (hwnd
, wParam
, lParam
);
6794 return TOOLBAR_GetRows (hwnd
, wParam
, lParam
);
6797 return TOOLBAR_GetState (hwnd
, wParam
, lParam
);
6800 return TOOLBAR_GetStringA (hwnd
, wParam
, lParam
);
6803 return TOOLBAR_GetStringW (hwnd
, wParam
, lParam
);
6806 return TOOLBAR_GetStyle (hwnd
, wParam
, lParam
);
6808 case TB_GETTEXTROWS
:
6809 return TOOLBAR_GetTextRows (hwnd
, wParam
, lParam
);
6811 case TB_GETTOOLTIPS
:
6812 return TOOLBAR_GetToolTips (hwnd
, wParam
, lParam
);
6814 case TB_GETUNICODEFORMAT
:
6815 return TOOLBAR_GetUnicodeFormat (hwnd
, wParam
, lParam
);
6818 return TOOLBAR_HideButton (hwnd
, wParam
, lParam
);
6821 return TOOLBAR_HitTest (hwnd
, wParam
, lParam
);
6823 case TB_INDETERMINATE
:
6824 return TOOLBAR_Indeterminate (hwnd
, wParam
, lParam
);
6826 case TB_INSERTBUTTONA
:
6827 return TOOLBAR_InsertButtonA (hwnd
, wParam
, lParam
);
6829 case TB_INSERTBUTTONW
:
6830 return TOOLBAR_InsertButtonW (hwnd
, wParam
, lParam
);
6832 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6834 case TB_ISBUTTONCHECKED
:
6835 return TOOLBAR_IsButtonChecked (hwnd
, wParam
, lParam
);
6837 case TB_ISBUTTONENABLED
:
6838 return TOOLBAR_IsButtonEnabled (hwnd
, wParam
, lParam
);
6840 case TB_ISBUTTONHIDDEN
:
6841 return TOOLBAR_IsButtonHidden (hwnd
, wParam
, lParam
);
6843 case TB_ISBUTTONHIGHLIGHTED
:
6844 return TOOLBAR_IsButtonHighlighted (hwnd
, wParam
, lParam
);
6846 case TB_ISBUTTONINDETERMINATE
:
6847 return TOOLBAR_IsButtonIndeterminate (hwnd
, wParam
, lParam
);
6849 case TB_ISBUTTONPRESSED
:
6850 return TOOLBAR_IsButtonPressed (hwnd
, wParam
, lParam
);
6853 return TOOLBAR_LoadImages (hwnd
, wParam
, lParam
);
6855 case TB_MAPACCELERATORA
:
6856 case TB_MAPACCELERATORW
:
6857 return TOOLBAR_MapAccelerator (hwnd
, wParam
, lParam
);
6860 return TOOLBAR_MarkButton (hwnd
, wParam
, lParam
);
6863 return TOOLBAR_MoveButton (hwnd
, wParam
, lParam
);
6865 case TB_PRESSBUTTON
:
6866 return TOOLBAR_PressButton (hwnd
, wParam
, lParam
);
6868 case TB_REPLACEBITMAP
:
6869 return TOOLBAR_ReplaceBitmap (hwnd
, wParam
, lParam
);
6871 case TB_SAVERESTOREA
:
6872 return TOOLBAR_SaveRestoreA (hwnd
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
6874 case TB_SAVERESTOREW
:
6875 return TOOLBAR_SaveRestoreW (hwnd
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
6877 case TB_SETANCHORHIGHLIGHT
:
6878 return TOOLBAR_SetAnchorHighlight (hwnd
, wParam
);
6880 case TB_SETBITMAPSIZE
:
6881 return TOOLBAR_SetBitmapSize (hwnd
, wParam
, lParam
);
6883 case TB_SETBUTTONINFOA
:
6884 return TOOLBAR_SetButtonInfoA (hwnd
, wParam
, lParam
);
6886 case TB_SETBUTTONINFOW
:
6887 return TOOLBAR_SetButtonInfoW (hwnd
, wParam
, lParam
);
6889 case TB_SETBUTTONSIZE
:
6890 return TOOLBAR_SetButtonSize (hwnd
, wParam
, lParam
);
6892 case TB_SETBUTTONWIDTH
:
6893 return TOOLBAR_SetButtonWidth (hwnd
, wParam
, lParam
);
6896 return TOOLBAR_SetCmdId (hwnd
, wParam
, lParam
);
6898 case TB_SETDISABLEDIMAGELIST
:
6899 return TOOLBAR_SetDisabledImageList (hwnd
, wParam
, lParam
);
6901 case TB_SETDRAWTEXTFLAGS
:
6902 return TOOLBAR_SetDrawTextFlags (hwnd
, wParam
, lParam
);
6904 case TB_SETEXTENDEDSTYLE
:
6905 return TOOLBAR_SetExtendedStyle (hwnd
, wParam
, lParam
);
6907 case TB_SETHOTIMAGELIST
:
6908 return TOOLBAR_SetHotImageList (hwnd
, wParam
, lParam
);
6911 return TOOLBAR_SetHotItem (hwnd
, wParam
);
6913 case TB_SETIMAGELIST
:
6914 return TOOLBAR_SetImageList (hwnd
, wParam
, lParam
);
6917 return TOOLBAR_SetIndent (hwnd
, wParam
, lParam
);
6919 case TB_SETINSERTMARK
:
6920 return TOOLBAR_SetInsertMark (hwnd
, wParam
, lParam
);
6922 case TB_SETINSERTMARKCOLOR
:
6923 return TOOLBAR_SetInsertMarkColor (hwnd
, wParam
, lParam
);
6925 case TB_SETMAXTEXTROWS
:
6926 return TOOLBAR_SetMaxTextRows (hwnd
, wParam
, lParam
);
6929 return TOOLBAR_SetPadding (hwnd
, wParam
, lParam
);
6932 return TOOLBAR_SetParent (hwnd
, wParam
, lParam
);
6935 return TOOLBAR_SetRows (hwnd
, wParam
, lParam
);
6938 return TOOLBAR_SetState (hwnd
, wParam
, lParam
);
6941 return TOOLBAR_SetStyle (hwnd
, wParam
, lParam
);
6943 case TB_SETTOOLTIPS
:
6944 return TOOLBAR_SetToolTips (hwnd
, wParam
, lParam
);
6946 case TB_SETUNICODEFORMAT
:
6947 return TOOLBAR_SetUnicodeFormat (hwnd
, wParam
, lParam
);
6950 return TOOLBAR_Unkwn45D(hwnd
, wParam
, lParam
);
6953 return TOOLBAR_Unkwn45E (hwnd
, wParam
, lParam
);
6956 return TOOLBAR_Unkwn460(hwnd
, wParam
, lParam
);
6959 return TOOLBAR_Unkwn462(hwnd
, wParam
, lParam
);
6962 return TOOLBAR_Unkwn463 (hwnd
, wParam
, lParam
);
6965 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6967 /* Common Control Messages */
6969 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6970 case CCM_GETCOLORSCHEME
:
6971 return TOOLBAR_GetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
6973 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6974 case CCM_SETCOLORSCHEME
:
6975 return TOOLBAR_SetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
6977 case CCM_GETVERSION
:
6978 return TOOLBAR_GetVersion (hwnd
);
6980 case CCM_SETVERSION
:
6981 return TOOLBAR_SetVersion (hwnd
, (INT
)wParam
);
6987 return TOOLBAR_Create (hwnd
, wParam
, lParam
);
6990 return TOOLBAR_Destroy (hwnd
, wParam
, lParam
);
6993 return TOOLBAR_EraseBackground (hwnd
, wParam
, lParam
);
6996 return TOOLBAR_GetFont (hwnd
, wParam
, lParam
);
6999 return TOOLBAR_KeyDown (hwnd
, wParam
, lParam
);
7001 /* case WM_KILLFOCUS: */
7003 case WM_LBUTTONDBLCLK
:
7004 return TOOLBAR_LButtonDblClk (hwnd
, wParam
, lParam
);
7006 case WM_LBUTTONDOWN
:
7007 return TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
7010 return TOOLBAR_LButtonUp (hwnd
, wParam
, lParam
);
7013 return TOOLBAR_RButtonUp (hwnd
, wParam
, lParam
);
7015 case WM_RBUTTONDBLCLK
:
7016 return TOOLBAR_RButtonDblClk (hwnd
, wParam
, lParam
);
7019 return TOOLBAR_MouseMove (hwnd
, wParam
, lParam
);
7022 return TOOLBAR_MouseLeave (hwnd
, wParam
, lParam
);
7024 case WM_CAPTURECHANGED
:
7025 return TOOLBAR_CaptureChanged(hwnd
);
7028 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
7031 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
7034 return TOOLBAR_NCCreate (hwnd
, wParam
, lParam
);
7037 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
7040 return TOOLBAR_Notify (hwnd
, wParam
, lParam
);
7042 case WM_NOTIFYFORMAT
:
7043 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
7045 case WM_PRINTCLIENT
:
7047 return TOOLBAR_Paint (hwnd
, wParam
);
7050 return TOOLBAR_SetFocus (hwnd
, wParam
);
7053 return TOOLBAR_SetRedraw (hwnd
, wParam
, lParam
);
7056 return TOOLBAR_Size (hwnd
, wParam
, lParam
);
7058 case WM_STYLECHANGED
:
7059 return TOOLBAR_StyleChanged (hwnd
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
7061 case WM_SYSCOLORCHANGE
:
7062 return TOOLBAR_SysColorChange (hwnd
);
7064 case WM_THEMECHANGED
:
7065 return theme_changed (hwnd
);
7067 /* case WM_WININICHANGE: */
7072 case WM_MEASUREITEM
:
7074 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
7076 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7077 case PGM_FORWARDMOUSE
:
7078 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7081 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
7082 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7083 uMsg
, wParam
, lParam
);
7084 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7090 TOOLBAR_Register (void)
7094 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
7095 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
7096 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
7097 wndClass
.cbClsExtra
= 0;
7098 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
7099 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
7100 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
7101 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
7103 RegisterClassW (&wndClass
);
7108 TOOLBAR_Unregister (void)
7110 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
7113 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
7118 /* Check if the entry already exists */
7119 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
7121 /* If this is a new entry we must create it and insert into the array */
7126 c
= (PIMLENTRY
) Alloc(sizeof(IMLENTRY
));
7129 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
7130 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
7145 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
7149 for (i
= 0; i
< *cies
; i
++)
7159 static PIMLENTRY
TOOLBAR_GetImageListEntry(PIMLENTRY
*pies
, INT cies
, INT id
)
7167 for (i
= 0; i
< cies
; i
++)
7169 if (pies
[i
]->id
== id
)
7181 static HIMAGELIST
TOOLBAR_GetImageList(PIMLENTRY
*pies
, INT cies
, INT id
)
7183 HIMAGELIST himlDef
= 0;
7184 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
7187 himlDef
= pie
->himl
;
7193 static BOOL
TOOLBAR_GetButtonInfo(TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
7195 if (infoPtr
->bUnicode
)
7196 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
7203 nmtba
.iItem
= nmtb
->iItem
;
7204 nmtba
.pszText
= Buffer
;
7205 nmtba
.cchText
= 256;
7206 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
7208 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
7210 int ccht
= strlen(nmtba
.pszText
);
7212 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)nmtba
.pszText
, -1,
7213 nmtb
->pszText
, nmtb
->cchText
);
7215 memcpy(&nmtb
->tbButton
, &nmtba
.tbButton
, sizeof(TBBUTTON
));
7224 static BOOL
TOOLBAR_IsButtonRemovable(TOOLBAR_INFO
*infoPtr
,
7225 int iItem
, PCUSTOMBUTTON btnInfo
)
7229 /* MSDN states that iItem is the index of the button, rather than the
7230 * command ID as used by every other NMTOOLBAR notification */
7232 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
7234 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);