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 dwItemCustDraw
; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
144 DWORD dwItemCDFlag
; /* TBCDRF_ flags from last ITEMPREPAINT */
145 SIZE szPadding
; /* padding values around button */
146 INT iListGap
; /* default gap between text and image for toolbar with list style */
148 HFONT hFont
; /* text font */
149 HIMAGELIST himlInt
; /* image list created internally */
150 PIMLENTRY
*himlDef
; /* default image list array */
151 INT cimlDef
; /* default image list array count */
152 PIMLENTRY
*himlHot
; /* hot image list array */
153 INT cimlHot
; /* hot image list array count */
154 PIMLENTRY
*himlDis
; /* disabled image list array */
155 INT cimlDis
; /* disabled image list array count */
156 HWND hwndToolTip
; /* handle to tool tip control */
157 HWND hwndNotify
; /* handle to the window that gets notifications */
158 HWND hwndSelf
; /* my own handle */
159 BOOL bAnchor
; /* anchor highlight enabled */
160 BOOL bDoRedraw
; /* Redraw status */
161 BOOL bDragOutSent
; /* has TBN_DRAGOUT notification been sent for this drag? */
162 BOOL bUnicode
; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
163 BOOL bCaptured
; /* mouse captured? */
164 DWORD dwStyle
; /* regular toolbar style */
165 DWORD dwExStyle
; /* extended toolbar style */
166 DWORD dwDTFlags
; /* DrawText flags */
168 COLORREF clrInsertMark
; /* insert mark color */
169 COLORREF clrBtnHighlight
; /* color for Flat Separator */
170 COLORREF clrBtnShadow
; /* color for Flag Separator */
172 LPWSTR pszTooltipText
; /* temporary store for a string > 80 characters
173 * for TTN_GETDISPINFOW notification */
174 TBINSERTMARK tbim
; /* info on insertion mark */
175 TBUTTON_INFO
*buttons
; /* pointer to button array */
176 LPWSTR
*strings
; /* pointer to string array */
177 TBITMAP_INFO
*bitmaps
;
178 } TOOLBAR_INFO
, *PTOOLBAR_INFO
;
181 /* used by customization dialog */
184 PTOOLBAR_INFO tbInfo
;
186 } CUSTDLG_INFO
, *PCUSTDLG_INFO
;
194 } CUSTOMBUTTON
, *PCUSTOMBUTTON
;
203 #define SEPARATOR_WIDTH 8
205 #define BOTTOM_BORDER 2
206 #define DDARROW_WIDTH 11
207 #define ARROW_HEIGHT 3
208 #define INSERTMARK_WIDTH 2
214 /* vertical padding used in list mode when image is present */
217 /* how wide to treat the bitmap if it isn't present */
218 #define NONLIST_NOTEXT_OFFSET 2
220 #define TOOLBAR_NOWHERE (-1)
222 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
223 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
224 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
226 /* Used to find undocumented extended styles */
227 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
228 TBSTYLE_EX_UNDOC1 | \
229 TBSTYLE_EX_MIXEDBUTTONS | \
230 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
232 /* all of the CCS_ styles */
233 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
234 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
236 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
237 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
238 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
239 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
240 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
242 static const WCHAR themeClass
[] = { 'T','o','o','l','b','a','r',0 };
244 static BOOL
TOOLBAR_GetButtonInfo(TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
);
245 static BOOL
TOOLBAR_IsButtonRemovable(TOOLBAR_INFO
*infoPtr
, int iItem
, PCUSTOMBUTTON btnInfo
);
246 static HIMAGELIST
TOOLBAR_GetImageList(PIMLENTRY
*pies
, INT cies
, INT id
);
247 static PIMLENTRY
TOOLBAR_GetImageListEntry(PIMLENTRY
*pies
, INT cies
, INT id
);
248 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
);
249 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
);
250 static LRESULT
TOOLBAR_LButtonDown(HWND hwnd
, WPARAM wParam
, LPARAM lParam
);
251 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
);
252 static LRESULT
TOOLBAR_AutoSize(HWND hwnd
);
253 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
);
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 HTHEME theme
= GetWindowTheme (hwnd
);
826 CopyRect (&rcArrow
, &rc
);
828 /* get a pointer to the text */
829 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
831 if (hasDropDownArrow
)
835 if (dwStyle
& TBSTYLE_FLAT
)
836 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
838 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
840 if (drawSepDropDownArrow
)
843 rcArrow
.left
= right
;
846 /* copy text & bitmap rects after adjusting for drop-down arrow
847 * so that text & bitmap is centred in the rectangle not containing
849 CopyRect(&rcText
, &rc
);
850 CopyRect(&rcBitmap
, &rc
);
852 /* Center the bitmap horizontally and vertically */
853 if (dwStyle
& TBSTYLE_LIST
)
856 infoPtr
->nMaxTextRows
> 0 &&
857 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
858 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
859 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->szPadding
.cx
/ 2;
861 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + infoPtr
->iListGap
/ 2;
864 rcBitmap
.left
+= (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2;
866 rcBitmap
.top
+= infoPtr
->szPadding
.cy
/ 2;
868 TRACE("iBitmap=%d, start=(%ld,%ld) w=%d, h=%d\n",
869 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
870 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
871 TRACE("Text=%s\n", debugstr_w(lpText
));
872 TRACE("iListGap=%d, padding = { %ld, %ld }\n", infoPtr
->iListGap
, infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
874 /* calculate text position */
877 rcText
.left
+= GetSystemMetrics(SM_CXEDGE
);
878 rcText
.right
-= GetSystemMetrics(SM_CXEDGE
);
879 if (dwStyle
& TBSTYLE_LIST
)
881 if (TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
))
882 rcText
.left
+= infoPtr
->nBitmapWidth
+ infoPtr
->iListGap
+ 2;
886 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr
, 0)) > 0)
887 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + infoPtr
->nBitmapHeight
+ 1;
889 rcText
.top
+= infoPtr
->szPadding
.cy
/2 + 2;
893 /* Initialize fields in all cases, because we use these later
894 * NOTE: applications can and do alter these to customize their
896 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
897 tbcd
.clrText
= comctl32_color
.clrBtnText
;
898 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
899 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
900 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
901 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
902 tbcd
.clrHighlightHotTrack
= 0;
903 tbcd
.nStringBkMode
= TRANSPARENT
;
904 tbcd
.nHLStringBkMode
= OPAQUE
;
905 /* MSDN says that this is the text rectangle.
906 * But (why always a but) tracing of v5.7 of native shows
907 * that this is really a *relative* rectangle based on the
908 * the nmcd.rc. Also the left and top are always 0 ignoring
909 * any bitmap that might be present. */
910 tbcd
.rcText
.left
= 0;
912 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
913 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
914 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
917 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
919 /* FIXME: what are these used for? */
923 /* Issue Item Prepaint notify */
924 infoPtr
->dwItemCustDraw
= 0;
925 infoPtr
->dwItemCDFlag
= 0;
926 if (infoPtr
->dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
928 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
929 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
930 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
931 ntfret
= TOOLBAR_SendNotify(&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
932 /* reset these fields so the user can't alter the behaviour like native */
936 infoPtr
->dwItemCustDraw
= ntfret
& 0xffff;
937 infoPtr
->dwItemCDFlag
= ntfret
& 0xffff0000;
938 if (infoPtr
->dwItemCustDraw
& CDRF_SKIPDEFAULT
)
940 /* save the only part of the rect that the user can change */
941 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
942 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
946 if (btnPtr
->fsStyle
& BTNS_SEP
) {
949 DrawThemeBackground (theme
, hdc
,
950 (dwStyle
& CCS_VERT
) ? TP_SEPARATORVERT
: TP_SEPARATOR
, 0,
951 &tbcd
.nmcd
.rc
, NULL
);
954 /* with the FLAT style, iBitmap is the width and has already */
955 /* been taken into consideration in calculating the width */
956 /* so now we need to draw the vertical separator */
957 /* empirical tests show that iBitmap can/will be non-zero */
958 /* when drawing the vertical bar... */
959 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
960 if (btnPtr
->fsStyle
& BTNS_DROPDOWN
)
961 TOOLBAR_DrawDDFlatSeparator (&rc
, hdc
, btnPtr
, infoPtr
);
963 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
965 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
966 FIXME("Draw some kind of separator: fsStyle=%x\n",
972 if (!(infoPtr
->dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
973 (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
)))
974 OffsetRect(&rcText
, 1, 1);
976 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
977 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
978 TOOLBAR_DrawPattern (&rc
, &tbcd
);
980 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
981 && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
983 if ( infoPtr
->dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
987 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
988 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
989 if (hasDropDownArrow
)
990 ExtTextOutW(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
991 SetBkColor(hdc
, oldclr
);
997 int partId
= drawSepDropDownArrow
? TP_SPLITBUTTON
: TP_BUTTON
;
998 int stateId
= TS_NORMAL
;
1000 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1001 stateId
= TS_DISABLED
;
1002 else if (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
)
1003 stateId
= TS_PRESSED
;
1004 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1005 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1006 else if ((tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1007 || (drawSepDropDownArrow
&& btnPtr
->bDropDownPressed
))
1010 DrawThemeBackground (theme
, hdc
, partId
, stateId
, &tbcd
.nmcd
.rc
, NULL
);
1013 TOOLBAR_DrawFrame(infoPtr
, &tbcd
);
1015 if (drawSepDropDownArrow
)
1019 int stateId
= TS_NORMAL
;
1021 if (tbcd
.nmcd
.uItemState
& CDIS_DISABLED
)
1022 stateId
= TS_DISABLED
;
1023 else if (btnPtr
->bDropDownPressed
|| (tbcd
.nmcd
.uItemState
& CDIS_SELECTED
))
1024 stateId
= TS_PRESSED
;
1025 else if (tbcd
.nmcd
.uItemState
& CDIS_CHECKED
)
1026 stateId
= (tbcd
.nmcd
.uItemState
& CDIS_HOT
) ? TS_HOTCHECKED
: TS_HOT
;
1027 else if (tbcd
.nmcd
.uItemState
& CDIS_HOT
)
1030 DrawThemeBackground (theme
, hdc
, TP_DROPDOWNBUTTON
, stateId
, &rcArrow
, NULL
);
1031 DrawThemeBackground (theme
, hdc
, TP_SPLITBUTTONDROPDOWN
, stateId
, &rcArrow
, NULL
);
1034 TOOLBAR_DrawSepDDArrow(infoPtr
, &tbcd
, &rcArrow
, btnPtr
->bDropDownPressed
);
1037 oldBkMode
= SetBkMode (hdc
, tbcd
.nStringBkMode
);
1038 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1039 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
);
1040 SetBkMode (hdc
, oldBkMode
);
1042 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
);
1044 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1046 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1048 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1049 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1051 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1053 offset
= (infoPtr
->dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1054 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1057 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1061 if (infoPtr
->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 /* Set the toolTip only for non-hidden, non-separator button */
1730 if (infoPtr
->hwndToolTip
&& !(btnPtr
->fsStyle
& BTNS_SEP
))
1734 ZeroMemory (&ti
, sizeof(ti
));
1735 ti
.cbSize
= sizeof(ti
);
1737 ti
.uId
= btnPtr
->idCommand
;
1738 ti
.rect
= btnPtr
->rect
;
1739 SendMessageW (infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTW
,
1743 /* btnPtr->nRow is zero based. The space between the rows is */
1744 /* also considered as a row. */
1745 btnPtr
->nRow
= nRows
+ nSepRows
;
1747 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1748 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1753 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1757 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1758 /* it is the actual width of the separator. This is used for */
1759 /* custom controls in toolbars. */
1760 if ( !(btnPtr
->fsStyle
& BTNS_DROPDOWN
))
1761 y
+= cy
+ ( (btnPtr
->iBitmap
> 0 ) ?
1762 btnPtr
->iBitmap
: SEPARATOR_WIDTH
) * 2 /3;
1766 /* nSepRows is used to calculate the extra height follwoing */
1770 x
= infoPtr
->nIndent
;
1772 /* Increment row number unless this is the last button */
1773 /* and it has Wrap set. */
1774 if (i
!= infoPtr
->nNumButtons
-1)
1781 /* infoPtr->nRows is the number of rows on the toolbar */
1782 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1784 TRACE("toolbar button width %d\n", infoPtr
->nButtonWidth
);
1789 TOOLBAR_InternalHitTest (HWND hwnd
, LPPOINT lpPt
)
1791 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1792 TBUTTON_INFO
*btnPtr
;
1795 btnPtr
= infoPtr
->buttons
;
1796 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1797 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1800 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1801 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1802 TRACE(" ON SEPARATOR %d!\n", i
);
1807 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1808 TRACE(" ON BUTTON %d!\n", i
);
1814 TRACE(" NOWHERE!\n");
1815 return TOOLBAR_NOWHERE
;
1820 TOOLBAR_GetButtonIndex (TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1822 TBUTTON_INFO
*btnPtr
;
1825 if (CommandIsIndex
) {
1826 TRACE("command is really index command=%d\n", idCommand
);
1827 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1830 btnPtr
= infoPtr
->buttons
;
1831 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1832 if (btnPtr
->idCommand
== idCommand
) {
1833 TRACE("command=%d index=%d\n", idCommand
, i
);
1837 TRACE("no index found for command=%d\n", idCommand
);
1843 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1845 TBUTTON_INFO
*btnPtr
;
1848 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1851 /* check index button */
1852 btnPtr
= &infoPtr
->buttons
[nIndex
];
1853 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1854 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1858 /* check previous buttons */
1859 nRunIndex
= nIndex
- 1;
1860 while (nRunIndex
>= 0) {
1861 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1862 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1863 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1871 /* check next buttons */
1872 nRunIndex
= nIndex
+ 1;
1873 while (nRunIndex
< infoPtr
->nNumButtons
) {
1874 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1875 if ((btnPtr
->fsStyle
& BTNS_GROUP
) == BTNS_GROUP
) {
1876 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1889 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1890 WPARAM wParam
, LPARAM lParam
)
1896 msg
.wParam
= wParam
;
1897 msg
.lParam
= lParam
;
1898 msg
.time
= GetMessageTime ();
1899 msg
.pt
.x
= LOWORD(GetMessagePos ());
1900 msg
.pt
.y
= HIWORD(GetMessagePos ());
1902 SendMessageW (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1905 /* keeps available button list box sorted by button id */
1906 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd
, PCUSTOMBUTTON btnInfoNew
)
1910 PCUSTOMBUTTON btnInfo
;
1911 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
1913 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew
->text
), btnInfoNew
->btn
.idCommand
);
1915 count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
1917 /* position 0 is always separator */
1918 for (i
= 1; i
< count
; i
++)
1920 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, i
, 0);
1921 if (btnInfoNew
->btn
.idCommand
< btnInfo
->btn
.idCommand
)
1923 i
= SendMessageW(hwndAvail
, LB_INSERTSTRING
, i
, 0);
1924 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
1928 /* id higher than all others add to end */
1929 i
= SendMessageW(hwndAvail
, LB_ADDSTRING
, 0, 0);
1930 SendMessageW(hwndAvail
, LB_SETITEMDATA
, i
, (LPARAM
)btnInfoNew
);
1933 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo
, HWND hwnd
, INT nIndexFrom
, INT nIndexTo
)
1937 TRACE("index from %d, index to %d\n", nIndexFrom
, nIndexTo
);
1939 if (nIndexFrom
== nIndexTo
)
1942 /* MSDN states that iItem is the index of the button, rather than the
1943 * command ID as used by every other NMTOOLBAR notification */
1944 nmtb
.iItem
= nIndexFrom
;
1945 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
1947 PCUSTOMBUTTON btnInfo
;
1949 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
1950 int count
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
1952 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, nIndexFrom
, 0);
1954 SendMessageW(hwndList
, LB_DELETESTRING
, nIndexFrom
, 0);
1955 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
1956 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
1957 SendMessageW(hwndList
, LB_SETCURSEL
, nIndexTo
, 0);
1960 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), FALSE
);
1962 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEUP_BTN
), TRUE
);
1964 /* last item is always separator, so -2 instead of -1 */
1965 if (nIndexTo
>= (count
- 2))
1966 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), FALSE
);
1968 EnableWindow(GetDlgItem(hwnd
,IDC_MOVEDN_BTN
), TRUE
);
1970 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, nIndexFrom
, 0);
1971 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
1973 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
1977 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo
, HWND hwnd
, INT nIndexAvail
, INT nIndexTo
)
1981 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail
, nIndexTo
);
1983 /* MSDN states that iItem is the index of the button, rather than the
1984 * command ID as used by every other NMTOOLBAR notification */
1985 nmtb
.iItem
= nIndexAvail
;
1986 if (TOOLBAR_SendNotify(&nmtb
.hdr
, custInfo
->tbInfo
, TBN_QUERYINSERT
))
1988 PCUSTOMBUTTON btnInfo
;
1990 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
1991 HWND hwndAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
1992 int count
= SendMessageW(hwndAvail
, LB_GETCOUNT
, 0, 0);
1994 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndAvail
, LB_GETITEMDATA
, nIndexAvail
, 0);
1996 if (nIndexAvail
!= 0) /* index == 0 indicates separator */
1998 /* remove from 'available buttons' list */
1999 SendMessageW(hwndAvail
, LB_DELETESTRING
, nIndexAvail
, 0);
2000 if (nIndexAvail
== count
-1)
2001 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
-1 , 0);
2003 SendMessageW(hwndAvail
, LB_SETCURSEL
, nIndexAvail
, 0);
2007 PCUSTOMBUTTON btnNew
;
2009 /* duplicate 'separator' button */
2010 btnNew
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2011 memcpy(btnNew
, btnInfo
, sizeof(CUSTOMBUTTON
));
2015 /* insert into 'toolbar button' list */
2016 SendMessageW(hwndList
, LB_INSERTSTRING
, nIndexTo
, 0);
2017 SendMessageW(hwndList
, LB_SETITEMDATA
, nIndexTo
, (LPARAM
)btnInfo
);
2019 SendMessageW(custInfo
->tbHwnd
, TB_INSERTBUTTONW
, nIndexTo
, (LPARAM
)&(btnInfo
->btn
));
2021 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2025 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo
, HWND hwnd
, INT index
)
2027 PCUSTOMBUTTON btnInfo
;
2028 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2030 TRACE("Remove: index %d\n", index
);
2032 btnInfo
= (PCUSTOMBUTTON
)SendMessageW(hwndList
, LB_GETITEMDATA
, index
, 0);
2034 /* send TBN_QUERYDELETE notification */
2035 if (TOOLBAR_IsButtonRemovable(custInfo
->tbInfo
, index
, btnInfo
))
2039 SendMessageW(hwndList
, LB_DELETESTRING
, index
, 0);
2040 SendMessageW(hwndList
, LB_SETCURSEL
, index
, 0);
2042 SendMessageW(custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2044 /* insert into 'available button' list */
2045 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2046 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2050 TOOLBAR_SendNotify(&hdr
, custInfo
->tbInfo
, TBN_TOOLBARCHANGE
);
2054 /* drag list notification function for toolbar buttons list box */
2055 static LRESULT
TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo
, HWND hwnd
, DRAGLISTINFO
*pDLI
)
2057 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2058 switch (pDLI
->uNotification
)
2062 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2063 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2064 /* no dragging for last item (separator) */
2065 if (nCurrentItem
>= (nCount
- 1)) return FALSE
;
2070 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2071 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2072 /* no dragging past last item (separator) */
2073 if ((nCurrentItem
>= 0) && (nCurrentItem
< (nCount
- 1)))
2075 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2076 /* FIXME: native uses "move button" cursor */
2077 return DL_COPYCURSOR
;
2080 /* not over toolbar buttons list */
2081 if (nCurrentItem
< 0)
2083 POINT ptWindow
= pDLI
->ptCursor
;
2084 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2085 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2086 /* over available buttons list? */
2087 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2088 /* FIXME: native uses "move button" cursor */
2089 return DL_COPYCURSOR
;
2091 /* clear drag arrow */
2092 DrawInsert(hwnd
, hwndList
, -1);
2093 return DL_STOPCURSOR
;
2097 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2098 INT nIndexFrom
= SendMessageW(hwndList
, LB_GETCURSEL
, 0, 0);
2099 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2100 if ((nIndexTo
>= 0) && (nIndexTo
< (nCount
- 1)))
2102 /* clear drag arrow */
2103 DrawInsert(hwnd
, hwndList
, -1);
2105 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2107 /* not over toolbar buttons list */
2110 POINT ptWindow
= pDLI
->ptCursor
;
2111 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2112 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2113 /* over available buttons list? */
2114 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2115 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, nIndexFrom
);
2120 /* Clear drag arrow */
2121 DrawInsert(hwnd
, hwndList
, -1);
2128 /* drag list notification function for available buttons list box */
2129 static LRESULT
TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo
, HWND hwnd
, DRAGLISTINFO
*pDLI
)
2131 HWND hwndList
= GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
);
2132 switch (pDLI
->uNotification
)
2138 INT nCurrentItem
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2139 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2140 /* no dragging past last item (separator) */
2141 if ((nCurrentItem
>= 0) && (nCurrentItem
< nCount
))
2143 DrawInsert(hwnd
, hwndList
, nCurrentItem
);
2144 /* FIXME: native uses "move button" cursor */
2145 return DL_COPYCURSOR
;
2148 /* not over toolbar buttons list */
2149 if (nCurrentItem
< 0)
2151 POINT ptWindow
= pDLI
->ptCursor
;
2152 HWND hwndListAvail
= GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
);
2153 MapWindowPoints(NULL
, hwnd
, &ptWindow
, 1);
2154 /* over available buttons list? */
2155 if (ChildWindowFromPoint(hwnd
, ptWindow
) == hwndListAvail
)
2156 /* FIXME: native uses "move button" cursor */
2157 return DL_COPYCURSOR
;
2159 /* clear drag arrow */
2160 DrawInsert(hwnd
, hwndList
, -1);
2161 return DL_STOPCURSOR
;
2165 INT nIndexTo
= LBItemFromPt(hwndList
, pDLI
->ptCursor
, TRUE
);
2166 INT nCount
= SendMessageW(hwndList
, LB_GETCOUNT
, 0, 0);
2167 INT nIndexFrom
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2168 if ((nIndexTo
>= 0) && (nIndexTo
< nCount
))
2170 /* clear drag arrow */
2171 DrawInsert(hwnd
, hwndList
, -1);
2173 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, nIndexFrom
, nIndexTo
);
2177 /* Clear drag arrow */
2178 DrawInsert(hwnd
, hwndList
, -1);
2184 extern UINT uDragListMessage
;
2186 /***********************************************************************
2187 * TOOLBAR_CustomizeDialogProc
2188 * This function implements the toolbar customization dialog.
2190 static INT_PTR CALLBACK
2191 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2193 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongPtrW (hwnd
, DWLP_USER
);
2194 PCUSTOMBUTTON btnInfo
;
2196 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
2201 custInfo
= (PCUSTDLG_INFO
)lParam
;
2202 SetWindowLongPtrW (hwnd
, DWLP_USER
, (LONG_PTR
)custInfo
);
2209 NMTBINITCUSTOMIZE nmtbic
;
2211 infoPtr
= custInfo
->tbInfo
;
2213 /* send TBN_QUERYINSERT notification */
2214 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
2216 if (!TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
))
2219 nmtbic
.hwndDialog
= hwnd
;
2220 /* Send TBN_INITCUSTOMIZE notification */
2221 if (TOOLBAR_SendNotify (&nmtbic
.hdr
, infoPtr
, TBN_INITCUSTOMIZE
) ==
2224 TRACE("TBNRF_HIDEHELP requested\n");
2225 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
2228 /* add items to 'toolbar buttons' list and check if removable */
2229 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
2231 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2232 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2233 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2234 btnInfo
->bVirtual
= FALSE
;
2235 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2237 /* send TBN_QUERYDELETE notification */
2238 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
2240 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2241 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2244 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2246 /* insert separator button into 'available buttons' list */
2247 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2248 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2249 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2250 btnInfo
->bVirtual
= FALSE
;
2251 btnInfo
->bRemovable
= TRUE
;
2252 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2253 index
= (int)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2254 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2256 /* insert all buttons into dsa */
2259 /* send TBN_GETBUTTONINFO notification */
2262 nmtb
.pszText
= Buffer
;
2265 /* Clear previous button's text */
2266 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
2268 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
2271 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2272 nmtb
.tbButton
.fsStyle
, i
,
2273 nmtb
.tbButton
.idCommand
,
2274 nmtb
.tbButton
.iString
,
2275 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
2278 /* insert button into the apropriate list */
2279 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
2282 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2283 btnInfo
->bVirtual
= FALSE
;
2284 btnInfo
->bRemovable
= TRUE
;
2288 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
,
2289 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2292 memcpy (&btnInfo
->btn
, &nmtb
.tbButton
, sizeof(TBBUTTON
));
2293 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
2295 if (lstrlenW(nmtb
.pszText
))
2296 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
2297 else if (nmtb
.tbButton
.iString
>= 0 &&
2298 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
2300 lstrcpyW(btnInfo
->text
,
2301 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
2306 TOOLBAR_Cust_InsertAvailButton(hwnd
, btnInfo
);
2309 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMHEIGHT
, 0, infoPtr
->nBitmapHeight
+ 8);
2311 /* select first item in the 'available' list */
2312 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
2314 /* append 'virtual' separator button to the 'toolbar buttons' list */
2315 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
2316 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
2317 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
2318 btnInfo
->bVirtual
= TRUE
;
2319 btnInfo
->bRemovable
= FALSE
;
2320 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
2321 index
= (int)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
2322 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2324 /* select last item in the 'toolbar' list */
2325 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2326 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
2328 MakeDragList(GetDlgItem(hwnd
, IDC_TOOLBARBTN_LBOX
));
2329 MakeDragList(GetDlgItem(hwnd
, IDC_AVAILBTN_LBOX
));
2331 /* set focus and disable buttons */
2332 PostMessageW (hwnd
, WM_USER
, 0, 0);
2337 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2338 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2339 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
2340 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
2344 EndDialog(hwnd
, FALSE
);
2348 switch (LOWORD(wParam
))
2350 case IDC_TOOLBARBTN_LBOX
:
2351 if (HIWORD(wParam
) == LBN_SELCHANGE
)
2353 PCUSTOMBUTTON btnInfo
;
2358 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2359 index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2361 /* send TBN_QUERYINSERT notification */
2363 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYINSERT
);
2365 /* get list box item */
2366 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2368 if (index
== (count
- 1))
2370 /* last item (virtual separator) */
2371 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2372 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2374 else if (index
== (count
- 2))
2376 /* second last item (last non-virtual item) */
2377 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2378 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2380 else if (index
== 0)
2383 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
2384 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2388 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2389 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
2392 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
2396 case IDC_MOVEUP_BTN
:
2398 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2399 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
-1);
2403 case IDC_MOVEDN_BTN
: /* move down */
2405 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2406 TOOLBAR_Cust_MoveButton(custInfo
, hwnd
, index
, index
+1);
2410 case IDC_REMOVE_BTN
: /* remove button */
2412 int index
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2414 if (LB_ERR
== index
)
2417 TOOLBAR_Cust_RemoveButton(custInfo
, hwnd
, index
);
2421 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2424 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2427 case IDOK
: /* Add button */
2432 index
= SendDlgItemMessageW(hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2433 indexto
= SendDlgItemMessageW(hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2435 TOOLBAR_Cust_AddButton(custInfo
, hwnd
, index
, indexto
);
2440 EndDialog(hwnd
, FALSE
);
2450 /* delete items from 'toolbar buttons' listbox*/
2451 count
= SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2452 for (i
= 0; i
< count
; i
++)
2454 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2456 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2458 SendDlgItemMessageW (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2461 /* delete items from 'available buttons' listbox*/
2462 count
= SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2463 for (i
= 0; i
< count
; i
++)
2465 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2467 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2469 SendDlgItemMessageW (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2474 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2476 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2481 COLORREF oldText
= 0;
2485 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageW (hwnd
, wParam
, LB_GETITEMDATA
, (WPARAM
)lpdis
->itemID
, 0);
2486 if (btnInfo
== NULL
)
2488 FIXME("btnInfo invalid!\n");
2492 /* set colors and select objects */
2493 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2494 if (btnInfo
->bVirtual
)
2495 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2497 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2498 hPen
= CreatePen( PS_SOLID
, 1,
2499 GetSysColor( (lpdis
->itemState
& ODS_SELECTED
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2500 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2501 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2503 /* fill background rectangle */
2504 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2505 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2507 /* calculate button and text rectangles */
2508 CopyRect (&rcButton
, &lpdis
->rcItem
);
2509 InflateRect (&rcButton
, -1, -1);
2510 CopyRect (&rcText
, &rcButton
);
2511 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2512 rcText
.left
= rcButton
.right
+ 2;
2514 /* draw focus rectangle */
2515 if (lpdis
->itemState
& ODS_FOCUS
)
2516 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2519 if (!(infoPtr
->dwStyle
& TBSTYLE_FLAT
))
2520 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2522 /* draw image and text */
2523 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2524 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2525 btnInfo
->btn
.iBitmap
));
2526 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2527 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2529 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2530 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2532 /* delete objects and reset colors */
2533 SelectObject (lpdis
->hDC
, hOldBrush
);
2534 SelectObject (lpdis
->hDC
, hOldPen
);
2535 SetBkColor (lpdis
->hDC
, oldBk
);
2536 SetTextColor (lpdis
->hDC
, oldText
);
2537 DeleteObject( hPen
);
2542 case WM_MEASUREITEM
:
2543 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2545 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2547 lpmis
->itemHeight
= 15 + 8; /* default height */
2554 if (uDragListMessage
&& (uMsg
== uDragListMessage
))
2556 if (wParam
== IDC_TOOLBARBTN_LBOX
)
2558 LRESULT res
= TOOLBAR_Cust_ToolbarDragListNotification(
2559 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2560 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2563 else if (wParam
== IDC_AVAILBTN_LBOX
)
2565 LRESULT res
= TOOLBAR_Cust_AvailDragListNotification(
2566 custInfo
, hwnd
, (DRAGLISTINFO
*)lParam
);
2567 SetWindowLongPtrW(hwnd
, DWLP_MSGRESULT
, res
);
2576 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO
*infoPtr
, HIMAGELIST himlDef
, const TBITMAP_INFO
*bitmap
)
2579 INT nCountBefore
= ImageList_GetImageCount(himlDef
);
2585 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap
->hInst
, bitmap
->nID
, bitmap
->nButtons
);
2586 /* Add bitmaps to the default image list */
2587 if (bitmap
->hInst
== NULL
) /* a handle was passed */
2590 HBITMAP hOldBitmapBitmap
, hOldBitmapLoad
;
2591 HDC hdcImage
, hdcBitmap
;
2593 /* copy the bitmap before adding it so that the user's bitmap
2594 * doesn't get modified.
2596 GetObjectW ((HBITMAP
)bitmap
->nID
, sizeof(BITMAP
), (LPVOID
)&bmp
);
2598 hdcImage
= CreateCompatibleDC(0);
2599 hdcBitmap
= CreateCompatibleDC(0);
2601 /* create new bitmap */
2602 hbmLoad
= CreateBitmap (bmp
.bmWidth
, bmp
.bmHeight
, bmp
.bmPlanes
, bmp
.bmBitsPixel
, NULL
);
2603 hOldBitmapBitmap
= SelectObject(hdcBitmap
, (HBITMAP
)bitmap
->nID
);
2604 hOldBitmapLoad
= SelectObject(hdcImage
, hbmLoad
);
2606 /* Copy the user's image */
2607 BitBlt (hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
,
2608 hdcBitmap
, 0, 0, SRCCOPY
);
2610 SelectObject (hdcImage
, hOldBitmapLoad
);
2611 SelectObject (hdcBitmap
, hOldBitmapBitmap
);
2612 DeleteDC (hdcImage
);
2613 DeleteDC (hdcBitmap
);
2616 hbmLoad
= CreateMappedBitmap(bitmap
->hInst
, bitmap
->nID
, 0, NULL
, 0);
2618 /* enlarge the bitmap if needed */
2619 ImageList_GetIconSize(himlDef
, &cxIcon
, &cyIcon
);
2620 COMCTL32_EnsureBitmapSize(&hbmLoad
, cxIcon
*(INT
)bitmap
->nButtons
, cyIcon
, comctl32_color
.clrBtnFace
);
2622 nIndex
= ImageList_AddMasked(himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2623 DeleteObject(hbmLoad
);
2627 nCountAfter
= ImageList_GetImageCount(himlDef
);
2628 nAdded
= nCountAfter
- nCountBefore
;
2629 if (bitmap
->nButtons
== 0) /* wParam == 0 is special and means add only one image */
2631 ImageList_SetImageCount(himlDef
, nCountBefore
+ 1);
2632 } else if (nAdded
> (INT
)bitmap
->nButtons
) {
2633 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2634 nCountBefore
, nAdded
, bitmap
->nButtons
, nCountAfter
);
2637 infoPtr
->nNumBitmaps
+= nAdded
;
2642 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO
*infoPtr
)
2649 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2650 if (himlDef
== NULL
|| himlDef
!= infoPtr
->himlInt
)
2652 if (!ImageList_GetIconSize(himlDef
, &cx
, &cy
))
2654 if (cx
== infoPtr
->nBitmapWidth
&& cy
== infoPtr
->nBitmapHeight
)
2657 TRACE("Update icon size: %dx%d -> %dx%d\n",
2658 cx
, cy
, infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
2660 himlNew
= ImageList_Create(infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2661 ILC_COLORDDB
|ILC_MASK
, 8, 2);
2662 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2663 TOOLBAR_AddBitmapToImageList(infoPtr
, himlNew
, &infoPtr
->bitmaps
[i
]);
2664 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlNew
, 0);
2665 infoPtr
->himlInt
= himlNew
;
2667 infoPtr
->nNumBitmaps
-= ImageList_GetImageCount(himlDef
);
2668 ImageList_Destroy(himlDef
);
2671 /***********************************************************************
2672 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2676 TOOLBAR_AddBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2678 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2679 LPTBADDBITMAP lpAddBmp
= (LPTBADDBITMAP
)lParam
;
2684 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd
, wParam
, lParam
);
2688 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2690 info
.hInst
= COMCTL32_hModule
;
2691 switch (lpAddBmp
->nID
)
2693 case IDB_STD_SMALL_COLOR
:
2695 info
.nID
= IDB_STD_SMALL
;
2697 case IDB_STD_LARGE_COLOR
:
2699 info
.nID
= IDB_STD_LARGE
;
2701 case IDB_VIEW_SMALL_COLOR
:
2703 info
.nID
= IDB_VIEW_SMALL
;
2705 case IDB_VIEW_LARGE_COLOR
:
2707 info
.nID
= IDB_VIEW_LARGE
;
2709 case IDB_HIST_SMALL_COLOR
:
2711 info
.nID
= IDB_HIST_SMALL
;
2713 case IDB_HIST_LARGE_COLOR
:
2715 info
.nID
= IDB_HIST_LARGE
;
2721 TRACE ("adding %d internal bitmaps!\n", info
.nButtons
);
2723 /* Windows resize all the buttons to the size of a newly added standard image */
2724 if (lpAddBmp
->nID
& 1)
2727 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2728 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2730 SendMessageW (hwnd
, TB_SETBITMAPSIZE
, 0,
2731 MAKELPARAM((WORD
)24, (WORD
)24));
2732 SendMessageW (hwnd
, TB_SETBUTTONSIZE
, 0,
2733 MAKELPARAM((WORD
)31, (WORD
)30));
2738 SendMessageW (hwnd
, TB_SETBITMAPSIZE
, 0,
2739 MAKELPARAM((WORD
)16, (WORD
)16));
2740 SendMessageW (hwnd
, TB_SETBUTTONSIZE
, 0,
2741 MAKELPARAM((WORD
)22, (WORD
)22));
2744 TOOLBAR_CalcToolbar (hwnd
);
2748 info
.nButtons
= (INT
)wParam
;
2749 info
.hInst
= lpAddBmp
->hInst
;
2750 info
.nID
= lpAddBmp
->nID
;
2751 TRACE("adding %d bitmaps!\n", info
.nButtons
);
2754 /* check if the bitmap is already loaded and compute iSumButtons */
2756 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++)
2758 if (infoPtr
->bitmaps
[i
].hInst
== info
.hInst
&&
2759 infoPtr
->bitmaps
[i
].nID
== info
.nID
)
2761 iSumButtons
+= infoPtr
->bitmaps
[i
].nButtons
;
2764 if (!infoPtr
->cimlDef
) {
2765 /* create new default image list */
2766 TRACE ("creating default image list!\n");
2768 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2769 ILC_COLORDDB
| ILC_MASK
, info
.nButtons
, 2);
2770 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2771 infoPtr
->himlInt
= himlDef
;
2774 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2778 WARN("No default image list available\n");
2782 if (!TOOLBAR_AddBitmapToImageList(infoPtr
, himlDef
, &info
))
2785 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2786 infoPtr
->bitmaps
= ReAlloc(infoPtr
->bitmaps
, (infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2787 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
] = info
;
2788 infoPtr
->nNumBitmapInfos
++;
2789 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2791 InvalidateRect(hwnd
, NULL
, TRUE
);
2797 TOOLBAR_AddButtonsA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2799 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2800 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
2801 INT nOldButtons
, nNewButtons
, nAddButtons
, nCount
;
2803 TRACE("adding %d buttons!\n", wParam
);
2805 nAddButtons
= (UINT
)wParam
;
2806 nOldButtons
= infoPtr
->nNumButtons
;
2807 nNewButtons
= nOldButtons
+ nAddButtons
;
2809 if (infoPtr
->nNumButtons
== 0) {
2811 Alloc (sizeof(TBUTTON_INFO
) * nNewButtons
);
2814 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
2816 Alloc (sizeof(TBUTTON_INFO
) * nNewButtons
);
2817 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
2818 nOldButtons
* sizeof(TBUTTON_INFO
));
2822 infoPtr
->nNumButtons
= nNewButtons
;
2824 /* insert new button data */
2825 for (nCount
= 0; nCount
< nAddButtons
; nCount
++) {
2826 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nOldButtons
+nCount
];
2827 btnPtr
->iBitmap
= lpTbb
[nCount
].iBitmap
;
2828 btnPtr
->idCommand
= lpTbb
[nCount
].idCommand
;
2829 btnPtr
->fsState
= lpTbb
[nCount
].fsState
;
2830 btnPtr
->fsStyle
= lpTbb
[nCount
].fsStyle
;
2831 btnPtr
->dwData
= lpTbb
[nCount
].dwData
;
2832 if(HIWORD(lpTbb
[nCount
].iString
) && lpTbb
[nCount
].iString
!= -1)
2833 Str_SetPtrAtoW ((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lpTbb
[nCount
].iString
);
2835 btnPtr
->iString
= lpTbb
[nCount
].iString
;
2836 btnPtr
->bHot
= FALSE
;
2838 if ((infoPtr
->hwndToolTip
) && !(btnPtr
->fsStyle
& BTNS_SEP
)) {
2841 ZeroMemory (&ti
, sizeof(ti
));
2842 ti
.cbSize
= sizeof(ti
);
2844 ti
.uId
= btnPtr
->idCommand
;
2846 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
2848 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
2853 TOOLBAR_CalcToolbar (hwnd
);
2854 TOOLBAR_AutoSize (hwnd
);
2856 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
2858 InvalidateRect(hwnd
, NULL
, TRUE
);
2865 TOOLBAR_AddButtonsW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2867 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2868 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
2869 INT nOldButtons
, nNewButtons
, nAddButtons
, nCount
;
2871 TRACE("adding %d buttons!\n", wParam
);
2873 nAddButtons
= (UINT
)wParam
;
2874 nOldButtons
= infoPtr
->nNumButtons
;
2875 nNewButtons
= nOldButtons
+ nAddButtons
;
2877 if (infoPtr
->nNumButtons
== 0) {
2879 Alloc (sizeof(TBUTTON_INFO
) * nNewButtons
);
2882 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
2884 Alloc (sizeof(TBUTTON_INFO
) * nNewButtons
);
2885 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
2886 nOldButtons
* sizeof(TBUTTON_INFO
));
2890 infoPtr
->nNumButtons
= nNewButtons
;
2892 /* insert new button data */
2893 for (nCount
= 0; nCount
< nAddButtons
; nCount
++) {
2894 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nOldButtons
+nCount
];
2895 btnPtr
->iBitmap
= lpTbb
[nCount
].iBitmap
;
2896 btnPtr
->idCommand
= lpTbb
[nCount
].idCommand
;
2897 btnPtr
->fsState
= lpTbb
[nCount
].fsState
;
2898 btnPtr
->fsStyle
= lpTbb
[nCount
].fsStyle
;
2899 btnPtr
->dwData
= lpTbb
[nCount
].dwData
;
2900 if(HIWORD(lpTbb
[nCount
].iString
) && lpTbb
[nCount
].iString
!= -1)
2901 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, (LPWSTR
)lpTbb
[nCount
].iString
);
2903 btnPtr
->iString
= lpTbb
[nCount
].iString
;
2904 btnPtr
->bHot
= FALSE
;
2906 if ((infoPtr
->hwndToolTip
) && !(btnPtr
->fsStyle
& BTNS_SEP
)) {
2909 ZeroMemory (&ti
, sizeof(TTTOOLINFOW
));
2910 ti
.cbSize
= sizeof (TTTOOLINFOW
);
2912 ti
.uId
= btnPtr
->idCommand
;
2914 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
2917 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
2922 TOOLBAR_CalcToolbar (hwnd
);
2923 TOOLBAR_AutoSize (hwnd
);
2925 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
2927 InvalidateRect(hwnd
, NULL
, TRUE
);
2934 TOOLBAR_AddStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2936 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2939 if ((wParam
) && (HIWORD(lParam
) == 0)) {
2942 TRACE("adding string from resource!\n");
2944 len
= LoadStringA ((HINSTANCE
)wParam
, (UINT
)lParam
, szString
, sizeof(szString
));
2946 TRACE("len=%d \"%s\"\n", len
, szString
);
2947 nIndex
= infoPtr
->nNumStrings
;
2948 if (infoPtr
->nNumStrings
== 0) {
2950 Alloc (sizeof(LPWSTR
));
2953 LPWSTR
*oldStrings
= infoPtr
->strings
;
2955 Alloc (sizeof(LPWSTR
) * (infoPtr
->nNumStrings
+ 1));
2956 memcpy (&infoPtr
->strings
[0], &oldStrings
[0],
2957 sizeof(LPWSTR
) * infoPtr
->nNumStrings
);
2961 /*Alloc zeros out the allocated memory*/
2962 Str_SetPtrAtoW (&infoPtr
->strings
[infoPtr
->nNumStrings
], szString
);
2963 infoPtr
->nNumStrings
++;
2966 LPSTR p
= (LPSTR
)lParam
;
2971 TRACE("adding string(s) from array!\n");
2973 nIndex
= infoPtr
->nNumStrings
;
2976 TRACE("len=%d \"%s\"\n", len
, p
);
2978 if (infoPtr
->nNumStrings
== 0) {
2980 Alloc (sizeof(LPWSTR
));
2983 LPWSTR
*oldStrings
= infoPtr
->strings
;
2985 Alloc (sizeof(LPWSTR
) * (infoPtr
->nNumStrings
+ 1));
2986 memcpy (&infoPtr
->strings
[0], &oldStrings
[0],
2987 sizeof(LPWSTR
) * infoPtr
->nNumStrings
);
2991 Str_SetPtrAtoW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2992 infoPtr
->nNumStrings
++;
3003 TOOLBAR_AddStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3005 #define MAX_RESOURCE_STRING_LENGTH 512
3006 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3009 if ((wParam
) && (HIWORD(lParam
) == 0)) {
3010 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
3012 TRACE("adding string from resource!\n");
3014 len
= LoadStringW ((HINSTANCE
)wParam
, (UINT
)lParam
,
3015 szString
, MAX_RESOURCE_STRING_LENGTH
);
3017 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
3018 TRACE("First char: 0x%x\n", *szString
);
3019 if (szString
[0] == L
'|')
3021 PWSTR p
= szString
+ 1;
3023 nIndex
= infoPtr
->nNumStrings
;
3024 while (*p
!= L
'|' && *p
!= L
'\0') {
3027 if (infoPtr
->nNumStrings
== 0) {
3028 infoPtr
->strings
= Alloc (sizeof(LPWSTR
));
3032 LPWSTR
*oldStrings
= infoPtr
->strings
;
3033 infoPtr
->strings
= Alloc(sizeof(LPWSTR
) * (infoPtr
->nNumStrings
+ 1));
3034 memcpy(&infoPtr
->strings
[0], &oldStrings
[0],
3035 sizeof(LPWSTR
) * infoPtr
->nNumStrings
);
3039 np
=strchrW (p
, '|');
3047 TRACE("len=%d %s\n", len
, debugstr_w(p
));
3048 infoPtr
->strings
[infoPtr
->nNumStrings
] =
3049 Alloc (sizeof(WCHAR
)*(len
+1));
3050 lstrcpynW (infoPtr
->strings
[infoPtr
->nNumStrings
], p
, len
+1);
3051 infoPtr
->nNumStrings
++;
3058 nIndex
= infoPtr
->nNumStrings
;
3059 if (infoPtr
->nNumStrings
== 0) {
3061 Alloc (sizeof(LPWSTR
));
3064 LPWSTR
*oldStrings
= infoPtr
->strings
;
3066 Alloc (sizeof(LPWSTR
) * (infoPtr
->nNumStrings
+ 1));
3067 memcpy (&infoPtr
->strings
[0], &oldStrings
[0],
3068 sizeof(LPWSTR
) * infoPtr
->nNumStrings
);
3072 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], szString
);
3073 infoPtr
->nNumStrings
++;
3077 LPWSTR p
= (LPWSTR
)lParam
;
3082 TRACE("adding string(s) from array!\n");
3083 nIndex
= infoPtr
->nNumStrings
;
3087 TRACE("len=%d %s\n", len
, debugstr_w(p
));
3088 if (infoPtr
->nNumStrings
== 0) {
3090 Alloc (sizeof(LPWSTR
));
3093 LPWSTR
*oldStrings
= infoPtr
->strings
;
3095 Alloc (sizeof(LPWSTR
) * (infoPtr
->nNumStrings
+ 1));
3096 memcpy (&infoPtr
->strings
[0], &oldStrings
[0],
3097 sizeof(LPWSTR
) * infoPtr
->nNumStrings
);
3101 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
3102 infoPtr
->nNumStrings
++;
3113 TOOLBAR_AutoSize (HWND hwnd
)
3115 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3121 TRACE("auto sizing, style=%lx!\n", infoPtr
->dwStyle
);
3123 parent
= GetParent (hwnd
);
3125 if (!parent
|| !infoPtr
->bDoRedraw
)
3128 GetClientRect(parent
, &parent_rect
);
3130 x
= parent_rect
.left
;
3131 y
= parent_rect
.top
;
3133 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr
->nRows
, infoPtr
->nButtonHeight
);
3135 cy
= TOP_BORDER
+ infoPtr
->nRows
* infoPtr
->nButtonHeight
+ BOTTOM_BORDER
;
3136 cx
= parent_rect
.right
- parent_rect
.left
;
3138 if ((infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
) || (infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
))
3140 TOOLBAR_CalcToolbar(hwnd
);
3141 InvalidateRect( hwnd
, NULL
, TRUE
);
3144 if (!(infoPtr
->dwStyle
& CCS_NORESIZE
))
3147 UINT uPosFlags
= SWP_NOZORDER
;
3149 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
)
3151 GetWindowRect(hwnd
, &window_rect
);
3152 ScreenToClient(parent
, (LPPOINT
)&window_rect
.left
);
3153 y
= window_rect
.top
;
3155 if ((infoPtr
->dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
)
3157 GetWindowRect(hwnd
, &window_rect
);
3158 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
3161 if (infoPtr
->dwStyle
& CCS_NOPARENTALIGN
)
3162 uPosFlags
|= SWP_NOMOVE
;
3164 if (!(infoPtr
->dwStyle
& CCS_NODIVIDER
))
3165 cy
+= GetSystemMetrics(SM_CYEDGE
);
3167 if (infoPtr
->dwStyle
& WS_BORDER
)
3169 x
= y
= 1; /* FIXME: this looks wrong */
3170 cy
+= GetSystemMetrics(SM_CYEDGE
);
3171 cx
+= GetSystemMetrics(SM_CXEDGE
);
3174 SetWindowPos(hwnd
, NULL
, x
, y
, cx
, cy
, uPosFlags
);
3182 TOOLBAR_ButtonCount (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3184 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3186 return infoPtr
->nNumButtons
;
3191 TOOLBAR_ButtonStructSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3193 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3195 infoPtr
->dwStructSize
= (DWORD
)wParam
;
3202 TOOLBAR_ChangeBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3204 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3205 TBUTTON_INFO
*btnPtr
;
3208 TRACE("button %d, iBitmap now %d\n", wParam
, LOWORD(lParam
));
3210 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3214 btnPtr
= &infoPtr
->buttons
[nIndex
];
3215 btnPtr
->iBitmap
= LOWORD(lParam
);
3217 /* we HAVE to erase the background, the new bitmap could be */
3219 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3226 TOOLBAR_CheckButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3228 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3229 TBUTTON_INFO
*btnPtr
;
3232 BOOL bChecked
= FALSE
;
3234 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3236 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd
, nIndex
, lParam
);
3241 btnPtr
= &infoPtr
->buttons
[nIndex
];
3243 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? TRUE
: FALSE
;
3245 if (LOWORD(lParam
) == FALSE
)
3246 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
3248 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
3250 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
3251 if (nOldIndex
== nIndex
)
3253 if (nOldIndex
!= -1)
3254 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
3256 btnPtr
->fsState
|= TBSTATE_CHECKED
;
3259 if( bChecked
!= LOWORD(lParam
) )
3261 if (nOldIndex
!= -1)
3262 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
3263 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3266 /* FIXME: Send a WM_NOTIFY?? */
3273 TOOLBAR_CommandToIndex (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3275 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3277 return TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3282 TOOLBAR_Customize (HWND hwnd
)
3284 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3285 CUSTDLG_INFO custInfo
;
3291 custInfo
.tbInfo
= infoPtr
;
3292 custInfo
.tbHwnd
= hwnd
;
3294 /* send TBN_BEGINADJUST notification */
3295 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_BEGINADJUST
);
3297 if (!(hRes
= FindResourceW (COMCTL32_hModule
,
3298 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE
),
3299 (LPWSTR
)RT_DIALOG
)))
3302 if(!(template = (LPVOID
)LoadResource (COMCTL32_hModule
, hRes
)))
3305 ret
= DialogBoxIndirectParamW ((HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
),
3306 (LPCDLGTEMPLATEW
)template,
3308 TOOLBAR_CustomizeDialogProc
,
3311 /* send TBN_ENDADJUST notification */
3312 TOOLBAR_SendNotify (&nmhdr
, infoPtr
, TBN_ENDADJUST
);
3319 TOOLBAR_DeleteButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3321 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3322 INT nIndex
= (INT
)wParam
;
3324 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nIndex
];
3326 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3329 memset(&nmtb
, 0, sizeof(nmtb
));
3330 nmtb
.iItem
= btnPtr
->idCommand
;
3331 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
3332 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
3333 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
3334 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
3335 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
3336 nmtb
.tbButton
.iString
= btnPtr
->iString
;
3337 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_DELETINGBUTTON
);
3339 if ((infoPtr
->hwndToolTip
) &&
3340 !(btnPtr
->fsStyle
& BTNS_SEP
)) {
3343 ZeroMemory (&ti
, sizeof(ti
));
3344 ti
.cbSize
= sizeof(ti
);
3346 ti
.uId
= infoPtr
->buttons
[nIndex
].idCommand
;
3348 SendMessageW (infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
3351 if (infoPtr
->nNumButtons
== 1) {
3352 TRACE(" simple delete!\n");
3353 Free (infoPtr
->buttons
);
3354 infoPtr
->buttons
= NULL
;
3355 infoPtr
->nNumButtons
= 0;
3358 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3359 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3361 infoPtr
->nNumButtons
--;
3362 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3364 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3365 nIndex
* sizeof(TBUTTON_INFO
));
3368 if (nIndex
< infoPtr
->nNumButtons
) {
3369 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3370 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3376 TOOLBAR_CalcToolbar (hwnd
);
3378 InvalidateRect (hwnd
, NULL
, TRUE
);
3385 TOOLBAR_EnableButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3387 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3388 TBUTTON_INFO
*btnPtr
;
3392 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3394 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd
, wParam
, lParam
);
3399 btnPtr
= &infoPtr
->buttons
[nIndex
];
3401 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3403 /* update the toolbar button state */
3404 if(LOWORD(lParam
) == FALSE
) {
3405 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3407 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3410 /* redraw the button only if the state of the button changed */
3411 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3412 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3418 static inline LRESULT
3419 TOOLBAR_GetAnchorHighlight (HWND hwnd
)
3421 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3423 return infoPtr
->bAnchor
;
3428 TOOLBAR_GetBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3430 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3433 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3437 return infoPtr
->buttons
[nIndex
].iBitmap
;
3441 static inline LRESULT
3442 TOOLBAR_GetBitmapFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3444 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3449 TOOLBAR_GetButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3451 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3452 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3453 INT nIndex
= (INT
)wParam
;
3454 TBUTTON_INFO
*btnPtr
;
3459 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3462 btnPtr
= &infoPtr
->buttons
[nIndex
];
3463 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3464 lpTbb
->idCommand
= btnPtr
->idCommand
;
3465 lpTbb
->fsState
= btnPtr
->fsState
;
3466 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3467 lpTbb
->bReserved
[0] = 0;
3468 lpTbb
->bReserved
[1] = 0;
3469 lpTbb
->dwData
= btnPtr
->dwData
;
3470 lpTbb
->iString
= btnPtr
->iString
;
3477 TOOLBAR_GetButtonInfoA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3479 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3480 LPTBBUTTONINFOA lpTbInfo
= (LPTBBUTTONINFOA
)lParam
;
3481 TBUTTON_INFO
*btnPtr
;
3484 if (lpTbInfo
== NULL
)
3486 if (lpTbInfo
->cbSize
< sizeof(TBBUTTONINFOA
))
3489 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
3490 lpTbInfo
->dwMask
& 0x80000000);
3494 if (!(btnPtr
= &infoPtr
->buttons
[nIndex
])) return -1;
3496 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3497 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3498 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3499 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3500 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3501 lpTbInfo
->lParam
= btnPtr
->dwData
;
3502 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3503 lpTbInfo
->cx
= (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3504 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3505 lpTbInfo
->fsState
= btnPtr
->fsState
;
3506 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3507 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3508 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3509 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3510 can't use TOOLBAR_GetText here */
3512 if (HIWORD(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3513 lpText
= (LPWSTR
)btnPtr
->iString
;
3514 Str_GetPtrWtoA (lpText
, lpTbInfo
->pszText
,lpTbInfo
->cchText
);
3516 lpTbInfo
->pszText
[0] = '\0';
3523 TOOLBAR_GetButtonInfoW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3525 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3526 LPTBBUTTONINFOW lpTbInfo
= (LPTBBUTTONINFOW
)lParam
;
3527 TBUTTON_INFO
*btnPtr
;
3530 if (lpTbInfo
== NULL
)
3532 if (lpTbInfo
->cbSize
< sizeof(TBBUTTONINFOW
))
3535 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
3536 lpTbInfo
->dwMask
& 0x80000000);
3540 btnPtr
= &infoPtr
->buttons
[nIndex
];
3545 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3546 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3547 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3548 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3549 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3550 lpTbInfo
->lParam
= btnPtr
->dwData
;
3551 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3552 lpTbInfo
->cx
= (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3553 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3554 lpTbInfo
->fsState
= btnPtr
->fsState
;
3555 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3556 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3557 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3558 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3559 can't use TOOLBAR_GetText here */
3561 if (HIWORD(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3562 lpText
= (LPWSTR
)btnPtr
->iString
;
3563 Str_GetPtrW (lpText
,lpTbInfo
->pszText
,lpTbInfo
->cchText
);
3565 lpTbInfo
->pszText
[0] = '\0';
3573 TOOLBAR_GetButtonSize (HWND hwnd
)
3575 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3577 if (infoPtr
->nNumButtons
> 0)
3578 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3579 (WORD
)infoPtr
->nButtonHeight
);
3581 return MAKELONG(23,22);
3586 TOOLBAR_GetButtonTextA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3588 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3595 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3599 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3601 return WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3602 (LPSTR
)lParam
, 0x7fffffff, NULL
, NULL
) - 1;
3607 TOOLBAR_GetButtonTextW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3609 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3614 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3618 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3622 ret
= strlenW (lpText
);
3625 strcpyW ((LPWSTR
)lParam
, lpText
);
3633 TOOLBAR_GetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3635 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3636 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3637 return (LRESULT
)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3641 inline static LRESULT
3642 TOOLBAR_GetExtendedStyle (HWND hwnd
)
3644 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3648 return infoPtr
->dwExStyle
;
3653 TOOLBAR_GetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3655 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3656 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3657 return (LRESULT
)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3662 TOOLBAR_GetHotItem (HWND hwnd
)
3664 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3666 if (!((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)))
3669 if (infoPtr
->nHotItem
< 0)
3672 return (LRESULT
)infoPtr
->nHotItem
;
3677 TOOLBAR_GetDefImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3679 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3680 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3681 return (LRESULT
) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd
), wParam
);
3686 TOOLBAR_GetInsertMark (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3688 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3689 TBINSERTMARK
*lptbim
= (TBINSERTMARK
*)lParam
;
3691 TRACE("hwnd = %p, lptbim = %p\n", hwnd
, lptbim
);
3693 *lptbim
= infoPtr
->tbim
;
3700 TOOLBAR_GetInsertMarkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3702 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3704 TRACE("hwnd = %p\n", hwnd
);
3706 return (LRESULT
)infoPtr
->clrInsertMark
;
3711 TOOLBAR_GetItemRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3713 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3714 TBUTTON_INFO
*btnPtr
;
3718 nIndex
= (INT
)wParam
;
3719 btnPtr
= &infoPtr
->buttons
[nIndex
];
3720 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3722 lpRect
= (LPRECT
)lParam
;
3725 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3728 lpRect
->left
= btnPtr
->rect
.left
;
3729 lpRect
->right
= btnPtr
->rect
.right
;
3730 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3731 lpRect
->top
= btnPtr
->rect
.top
;
3738 TOOLBAR_GetMaxSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3740 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3741 LPSIZE lpSize
= (LPSIZE
)lParam
;
3746 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3747 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3749 TRACE("maximum size %ld x %ld\n",
3750 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3751 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3757 /* << TOOLBAR_GetObject >> */
3761 TOOLBAR_GetPadding (HWND hwnd
)
3763 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3766 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3767 return (LRESULT
) oldPad
;
3772 TOOLBAR_GetRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3774 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3775 TBUTTON_INFO
*btnPtr
;
3779 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3780 btnPtr
= &infoPtr
->buttons
[nIndex
];
3781 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3783 lpRect
= (LPRECT
)lParam
;
3787 lpRect
->left
= btnPtr
->rect
.left
;
3788 lpRect
->right
= btnPtr
->rect
.right
;
3789 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3790 lpRect
->top
= btnPtr
->rect
.top
;
3797 TOOLBAR_GetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3799 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3801 if (infoPtr
->dwStyle
& TBSTYLE_WRAPABLE
)
3802 return infoPtr
->nRows
;
3809 TOOLBAR_GetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3811 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3814 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3818 return infoPtr
->buttons
[nIndex
].fsState
;
3823 TOOLBAR_GetStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3825 return GetWindowLongW(hwnd
, GWL_STYLE
);
3830 TOOLBAR_GetTextRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3832 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3834 return infoPtr
->nMaxTextRows
;
3839 TOOLBAR_GetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3841 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3843 return (LRESULT
)infoPtr
->hwndToolTip
;
3848 TOOLBAR_GetUnicodeFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3850 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3852 TRACE("%s hwnd=%p\n",
3853 infoPtr
->bUnicode
? "TRUE" : "FALSE", hwnd
);
3855 return infoPtr
->bUnicode
;
3859 inline static LRESULT
3860 TOOLBAR_GetVersion (HWND hwnd
)
3862 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3863 return infoPtr
->iVersion
;
3868 TOOLBAR_HideButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3870 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3871 TBUTTON_INFO
*btnPtr
;
3876 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3880 btnPtr
= &infoPtr
->buttons
[nIndex
];
3881 if (LOWORD(lParam
) == FALSE
)
3882 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3884 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3886 TOOLBAR_CalcToolbar (hwnd
);
3888 InvalidateRect (hwnd
, NULL
, TRUE
);
3894 inline static LRESULT
3895 TOOLBAR_HitTest (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3897 return TOOLBAR_InternalHitTest (hwnd
, (LPPOINT
)lParam
);
3902 TOOLBAR_Indeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3904 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3905 TBUTTON_INFO
*btnPtr
;
3909 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3913 btnPtr
= &infoPtr
->buttons
[nIndex
];
3914 oldState
= btnPtr
->fsState
;
3915 if (LOWORD(lParam
) == FALSE
)
3916 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3918 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3920 if(oldState
!= btnPtr
->fsState
)
3921 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3928 TOOLBAR_InsertButtonA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3930 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3931 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3932 INT nIndex
= (INT
)wParam
;
3933 TBUTTON_INFO
*oldButtons
;
3938 TOOLBAR_DumpButton(infoPtr
, (TBUTTON_INFO
*)lpTbb
, nIndex
, FALSE
);
3941 /* EPP: this seems to be an undocumented call (from my IE4)
3942 * I assume in that case that:
3943 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3944 * - index of insertion is at the end of existing buttons
3945 * I only see this happen with nIndex == -1, but it could have a special
3946 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3948 nIndex
= infoPtr
->nNumButtons
;
3950 } else if (nIndex
< 0)
3953 /* If the string passed is not an index, assume address of string
3954 and do our own AddString */
3955 if ((HIWORD(lpTbb
->iString
) != 0) && (lpTbb
->iString
!= -1)) {
3959 TRACE("string %s passed instead of index, adding string\n",
3960 debugstr_a((LPSTR
)lpTbb
->iString
));
3961 len
= strlen((LPSTR
)lpTbb
->iString
) + 2;
3963 strcpy(ptr
, (LPSTR
)lpTbb
->iString
);
3964 ptr
[len
- 1] = 0; /* ended by two '\0' */
3965 lpTbb
->iString
= TOOLBAR_AddStringA(hwnd
, 0, (LPARAM
)ptr
);
3969 TRACE("inserting button index=%d\n", nIndex
);
3970 if (nIndex
> infoPtr
->nNumButtons
) {
3971 nIndex
= infoPtr
->nNumButtons
;
3972 TRACE("adjust index=%d\n", nIndex
);
3975 oldButtons
= infoPtr
->buttons
;
3976 infoPtr
->nNumButtons
++;
3977 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3978 /* pre insert copy */
3980 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3981 nIndex
* sizeof(TBUTTON_INFO
));
3984 /* insert new button */
3985 infoPtr
->buttons
[nIndex
].iBitmap
= lpTbb
->iBitmap
;
3986 infoPtr
->buttons
[nIndex
].idCommand
= lpTbb
->idCommand
;
3987 infoPtr
->buttons
[nIndex
].fsState
= lpTbb
->fsState
;
3988 infoPtr
->buttons
[nIndex
].fsStyle
= lpTbb
->fsStyle
;
3989 infoPtr
->buttons
[nIndex
].dwData
= lpTbb
->dwData
;
3990 /* if passed string and not index, then add string */
3991 if(HIWORD(lpTbb
->iString
) && lpTbb
->iString
!=-1) {
3992 Str_SetPtrAtoW ((LPWSTR
*)&infoPtr
->buttons
[nIndex
].iString
, (LPCSTR
)lpTbb
->iString
);
3995 infoPtr
->buttons
[nIndex
].iString
= lpTbb
->iString
;
3997 if ((infoPtr
->hwndToolTip
) && !(lpTbb
->fsStyle
& BTNS_SEP
)) {
4000 ZeroMemory (&ti
, sizeof(ti
));
4001 ti
.cbSize
= sizeof (ti
);
4003 ti
.uId
= lpTbb
->idCommand
;
4005 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
4007 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
4011 /* post insert copy */
4012 if (nIndex
< infoPtr
->nNumButtons
- 1) {
4013 memcpy (&infoPtr
->buttons
[nIndex
+1], &oldButtons
[nIndex
],
4014 (infoPtr
->nNumButtons
- nIndex
- 1) * sizeof(TBUTTON_INFO
));
4019 TOOLBAR_CalcToolbar (hwnd
);
4020 TOOLBAR_AutoSize (hwnd
);
4022 InvalidateRect (hwnd
, NULL
, TRUE
);
4029 TOOLBAR_InsertButtonW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4031 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4032 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
4033 INT nIndex
= (INT
)wParam
;
4034 TBUTTON_INFO
*oldButtons
;
4039 TOOLBAR_DumpButton(infoPtr
, (TBUTTON_INFO
*)lpTbb
, nIndex
, FALSE
);
4042 /* EPP: this seems to be an undocumented call (from my IE4)
4043 * I assume in that case that:
4044 * - lpTbb->iString is a string pointer (not a string index in strings[] table
4045 * - index of insertion is at the end of existing buttons
4046 * I only see this happen with nIndex == -1, but it could have a special
4047 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
4049 nIndex
= infoPtr
->nNumButtons
;
4051 } else if (nIndex
< 0)
4054 /* If the string passed is not an index, assume address of string
4055 and do our own AddString */
4056 if ((HIWORD(lpTbb
->iString
) != 0) && (lpTbb
->iString
!= -1)) {
4060 TRACE("string %s passed instead of index, adding string\n",
4061 debugstr_w((LPWSTR
)lpTbb
->iString
));
4062 len
= strlenW((LPWSTR
)lpTbb
->iString
) + 2;
4063 ptr
= Alloc(len
*sizeof(WCHAR
));
4064 strcpyW(ptr
, (LPWSTR
)lpTbb
->iString
);
4065 ptr
[len
- 1] = 0; /* ended by two '\0' */
4066 lpTbb
->iString
= TOOLBAR_AddStringW(hwnd
, 0, (LPARAM
)ptr
);
4070 TRACE("inserting button index=%d\n", nIndex
);
4071 if (nIndex
> infoPtr
->nNumButtons
) {
4072 nIndex
= infoPtr
->nNumButtons
;
4073 TRACE("adjust index=%d\n", nIndex
);
4076 oldButtons
= infoPtr
->buttons
;
4077 infoPtr
->nNumButtons
++;
4078 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
4079 /* pre insert copy */
4081 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
4082 nIndex
* sizeof(TBUTTON_INFO
));
4085 /* insert new button */
4086 infoPtr
->buttons
[nIndex
].iBitmap
= lpTbb
->iBitmap
;
4087 infoPtr
->buttons
[nIndex
].idCommand
= lpTbb
->idCommand
;
4088 infoPtr
->buttons
[nIndex
].fsState
= lpTbb
->fsState
;
4089 infoPtr
->buttons
[nIndex
].fsStyle
= lpTbb
->fsStyle
;
4090 infoPtr
->buttons
[nIndex
].dwData
= lpTbb
->dwData
;
4091 /* if passed string and not index, then add string */
4092 if(HIWORD(lpTbb
->iString
) && lpTbb
->iString
!=-1) {
4093 Str_SetPtrW ((LPWSTR
*)&infoPtr
->buttons
[nIndex
].iString
, (LPWSTR
)lpTbb
->iString
);
4096 infoPtr
->buttons
[nIndex
].iString
= lpTbb
->iString
;
4098 if ((infoPtr
->hwndToolTip
) && !(lpTbb
->fsStyle
& BTNS_SEP
)) {
4101 ZeroMemory (&ti
, sizeof(TTTOOLINFOW
));
4102 ti
.cbSize
= sizeof (TTTOOLINFOW
);
4104 ti
.uId
= lpTbb
->idCommand
;
4106 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
4108 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
4112 /* post insert copy */
4113 if (nIndex
< infoPtr
->nNumButtons
- 1) {
4114 memcpy (&infoPtr
->buttons
[nIndex
+1], &oldButtons
[nIndex
],
4115 (infoPtr
->nNumButtons
- nIndex
- 1) * sizeof(TBUTTON_INFO
));
4120 TOOLBAR_CalcToolbar (hwnd
);
4121 TOOLBAR_AutoSize (hwnd
);
4123 InvalidateRect (hwnd
, NULL
, TRUE
);
4129 /* << TOOLBAR_InsertMarkHitTest >> */
4133 TOOLBAR_IsButtonChecked (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4135 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4138 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4142 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
4147 TOOLBAR_IsButtonEnabled (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4149 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4152 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4156 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
4161 TOOLBAR_IsButtonHidden (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4163 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4166 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4170 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
4175 TOOLBAR_IsButtonHighlighted (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4177 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4180 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4184 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
4189 TOOLBAR_IsButtonIndeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4191 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4194 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4198 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
4203 TOOLBAR_IsButtonPressed (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4205 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4208 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4212 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
4217 TOOLBAR_LoadImages (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4220 tbab
.hInst
= (HINSTANCE
)lParam
;
4221 tbab
.nID
= (UINT_PTR
)wParam
;
4223 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd
, tbab
.hInst
, tbab
.nID
);
4225 return TOOLBAR_AddBitmap(hwnd
, 0, (LPARAM
)&tbab
);
4230 TOOLBAR_MapAccelerator (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4232 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4233 WCHAR wAccel
= (WCHAR
)wParam
;
4234 UINT
* pIDButton
= (UINT
*)lParam
;
4235 WCHAR wszAccel
[] = {'&',wAccel
,0};
4238 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4239 hwnd
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
4241 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4243 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
4244 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
4245 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
4247 int iLen
= strlenW(wszAccel
);
4248 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
4255 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
4260 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
4262 *pIDButton
= btnPtr
->idCommand
;
4274 TOOLBAR_MarkButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4276 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4279 TBUTTON_INFO
*btnPtr
;
4281 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd
, wParam
, lParam
);
4283 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4287 btnPtr
= &infoPtr
->buttons
[nIndex
];
4288 oldState
= btnPtr
->fsState
;
4291 btnPtr
->fsState
|= TBSTATE_MARKED
;
4293 btnPtr
->fsState
&= ~TBSTATE_MARKED
;
4295 if(oldState
!= btnPtr
->fsState
)
4296 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4302 /* fixes up an index of a button affected by a move */
4303 inline static void TOOLBAR_MoveFixupIndex(INT
* pIndex
, INT nIndex
, INT nMoveIndex
, BOOL bMoveUp
)
4307 if (*pIndex
> nIndex
&& *pIndex
<= nMoveIndex
)
4309 else if (*pIndex
== nIndex
)
4310 *pIndex
= nMoveIndex
;
4314 if (*pIndex
>= nMoveIndex
&& *pIndex
< nIndex
)
4316 else if (*pIndex
== nIndex
)
4317 *pIndex
= nMoveIndex
;
4323 TOOLBAR_MoveButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4325 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4328 INT nMoveIndex
= (INT
)lParam
;
4329 TBUTTON_INFO button
;
4331 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd
, wParam
, lParam
);
4333 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, TRUE
);
4334 if ((nIndex
== -1) || (nMoveIndex
< 0))
4337 if (nMoveIndex
> infoPtr
->nNumButtons
- 1)
4338 nMoveIndex
= infoPtr
->nNumButtons
- 1;
4340 button
= infoPtr
->buttons
[nIndex
];
4342 /* move button right */
4343 if (nIndex
< nMoveIndex
)
4345 nCount
= nMoveIndex
- nIndex
;
4346 memmove(&infoPtr
->buttons
[nIndex
], &infoPtr
->buttons
[nIndex
+1], nCount
*sizeof(TBUTTON_INFO
));
4347 infoPtr
->buttons
[nMoveIndex
] = button
;
4349 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, TRUE
);
4350 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, TRUE
);
4351 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, TRUE
);
4352 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, TRUE
);
4354 else if (nIndex
> nMoveIndex
) /* move button left */
4356 nCount
= nIndex
- nMoveIndex
;
4357 memmove(&infoPtr
->buttons
[nMoveIndex
+1], &infoPtr
->buttons
[nMoveIndex
], nCount
*sizeof(TBUTTON_INFO
));
4358 infoPtr
->buttons
[nMoveIndex
] = button
;
4360 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDown
, nIndex
, nMoveIndex
, FALSE
);
4361 TOOLBAR_MoveFixupIndex(&infoPtr
->nButtonDrag
, nIndex
, nMoveIndex
, FALSE
);
4362 TOOLBAR_MoveFixupIndex(&infoPtr
->nOldHit
, nIndex
, nMoveIndex
, FALSE
);
4363 TOOLBAR_MoveFixupIndex(&infoPtr
->nHotItem
, nIndex
, nMoveIndex
, FALSE
);
4366 TOOLBAR_CalcToolbar(hwnd
);
4367 TOOLBAR_AutoSize(hwnd
);
4368 InvalidateRect(hwnd
, NULL
, TRUE
);
4375 TOOLBAR_PressButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4377 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4378 TBUTTON_INFO
*btnPtr
;
4382 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4386 btnPtr
= &infoPtr
->buttons
[nIndex
];
4387 oldState
= btnPtr
->fsState
;
4388 if (LOWORD(lParam
) == FALSE
)
4389 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
4391 btnPtr
->fsState
|= TBSTATE_PRESSED
;
4393 if(oldState
!= btnPtr
->fsState
)
4394 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4399 /* FIXME: there might still be some confusion her between number of buttons
4400 * and number of bitmaps */
4402 TOOLBAR_ReplaceBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4404 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4405 LPTBREPLACEBITMAP lpReplace
= (LPTBREPLACEBITMAP
) lParam
;
4407 HBITMAP hbmLoad
= NULL
;
4408 int i
= 0, nOldButtons
= 0, pos
= 0;
4409 int nOldBitmaps
, nNewBitmaps
= 0;
4410 HIMAGELIST himlDef
= 0;
4412 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4413 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
4414 lpReplace
->nButtons
);
4416 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
4418 FIXME("changing standard bitmaps not implemented\n");
4421 else if (lpReplace
->hInstOld
!= 0)
4422 FIXME("resources not in the current module not implemented\n");
4424 if (lpReplace
->hInstNew
)
4426 hbmLoad
= LoadBitmapW(lpReplace
->hInstNew
,(LPWSTR
)lpReplace
->nIDNew
);
4431 hBitmap
= (HBITMAP
) lpReplace
->nIDNew
;
4434 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4435 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4436 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4437 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4438 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4440 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4441 nOldButtons
= tbi
->nButtons
;
4442 tbi
->nButtons
= lpReplace
->nButtons
;
4443 tbi
->hInst
= lpReplace
->hInstNew
;
4444 tbi
->nID
= lpReplace
->nIDNew
;
4445 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4448 pos
+= tbi
->nButtons
;
4451 if (nOldButtons
== 0)
4453 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4455 DeleteObject (hbmLoad
);
4459 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4460 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4462 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4464 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4465 ImageList_Remove(himlDef
, i
);
4470 HBITMAP hOldBitmapBitmap
, hOldBitmapLoad
, hbmLoad
;
4471 HDC hdcImage
, hdcBitmap
;
4473 /* copy the bitmap before adding it so that the user's bitmap
4474 * doesn't get modified.
4476 GetObjectW (hBitmap
, sizeof(BITMAP
), (LPVOID
)&bmp
);
4478 hdcImage
= CreateCompatibleDC(0);
4479 hdcBitmap
= CreateCompatibleDC(0);
4481 /* create new bitmap */
4482 hbmLoad
= CreateBitmap (bmp
.bmWidth
, bmp
.bmHeight
, bmp
.bmPlanes
, bmp
.bmBitsPixel
, NULL
);
4483 hOldBitmapBitmap
= SelectObject(hdcBitmap
, hBitmap
);
4484 hOldBitmapLoad
= SelectObject(hdcImage
, hbmLoad
);
4486 /* Copy the user's image */
4487 BitBlt (hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
,
4488 hdcBitmap
, 0, 0, SRCCOPY
);
4490 SelectObject (hdcImage
, hOldBitmapLoad
);
4491 SelectObject (hdcBitmap
, hOldBitmapBitmap
);
4492 DeleteDC (hdcImage
);
4493 DeleteDC (hdcBitmap
);
4495 ImageList_AddMasked (himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
4496 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4497 DeleteObject (hbmLoad
);
4500 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4502 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4503 pos
, nOldBitmaps
, nNewBitmaps
);
4505 InvalidateRect(hwnd
, NULL
, TRUE
);
4508 DeleteObject (hbmLoad
);
4513 /* helper for TOOLBAR_SaveRestoreW */
4515 TOOLBAR_Save(TOOLBAR_INFO
*infoPtr
, LPTBSAVEPARAMSW lpSave
)
4517 FIXME("save to %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4518 debugstr_w(lpSave
->pszValueName
));
4524 /* helper for TOOLBAR_Restore */
4526 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO
*infoPtr
)
4531 ZeroMemory(&ti
, sizeof(ti
));
4532 ti
.cbSize
= sizeof(ti
);
4533 ti
.hwnd
= infoPtr
->hwndSelf
;
4535 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
4537 if ((infoPtr
->hwndToolTip
) &&
4538 !(infoPtr
->buttons
[i
].fsStyle
& BTNS_SEP
))
4540 ti
.uId
= infoPtr
->buttons
[i
].idCommand
;
4541 SendMessageW(infoPtr
->hwndToolTip
, TTM_DELTOOLW
, 0, (LPARAM
)&ti
);
4545 Free(infoPtr
->buttons
);
4546 infoPtr
->buttons
= NULL
;
4547 infoPtr
->nNumButtons
= 0;
4551 /* helper for TOOLBAR_SaveRestoreW */
4553 TOOLBAR_Restore(TOOLBAR_INFO
*infoPtr
, LPTBSAVEPARAMSW lpSave
)
4562 /* restore toolbar information */
4563 TRACE("restore from %s %s\n", debugstr_w(lpSave
->pszSubKey
),
4564 debugstr_w(lpSave
->pszValueName
));
4566 memset(&nmtbr
, 0, sizeof(nmtbr
));
4568 res
= RegOpenKeyExW(lpSave
->hkr
, lpSave
->pszSubKey
, 0,
4569 KEY_QUERY_VALUE
, &hkey
);
4571 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4573 if (!res
&& dwType
!= REG_BINARY
)
4574 res
= ERROR_FILE_NOT_FOUND
;
4577 nmtbr
.pData
= Alloc(dwSize
);
4578 nmtbr
.cbData
= (UINT
)dwSize
;
4579 if (!nmtbr
.pData
) res
= ERROR_OUTOFMEMORY
;
4582 res
= RegQueryValueExW(hkey
, lpSave
->pszValueName
, NULL
, &dwType
,
4583 (LPBYTE
)nmtbr
.pData
, &dwSize
);
4586 nmtbr
.pCurrent
= nmtbr
.pData
;
4588 nmtbr
.cbBytesPerRecord
= sizeof(DWORD
);
4589 nmtbr
.cButtons
= nmtbr
.cbData
/ nmtbr
.cbBytesPerRecord
;
4591 if (!TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
))
4595 /* remove all existing buttons as this function is designed to
4596 * restore the toolbar to a previously saved state */
4597 TOOLBAR_DeleteAllButtons(infoPtr
);
4599 for (i
= 0; i
< nmtbr
.cButtons
; i
++)
4602 nmtbr
.tbButton
.iBitmap
= -1;
4603 nmtbr
.tbButton
.fsState
= 0;
4604 nmtbr
.tbButton
.fsStyle
= 0;
4605 nmtbr
.tbButton
.idCommand
= 0;
4606 if (*nmtbr
.pCurrent
== (DWORD
)-1)
4609 nmtbr
.tbButton
.fsStyle
= TBSTYLE_SEP
;
4610 nmtbr
.tbButton
.iBitmap
= SEPARATOR_WIDTH
;
4612 else if (*nmtbr
.pCurrent
== (DWORD
)-2)
4614 nmtbr
.tbButton
.fsState
= TBSTATE_HIDDEN
;
4616 nmtbr
.tbButton
.idCommand
= (int)*nmtbr
.pCurrent
;
4620 TOOLBAR_SendNotify(&nmtbr
.hdr
, infoPtr
, TBN_RESTORE
);
4622 /* can't contain real string as we don't know whether
4623 * the client put an ANSI or Unicode string in there */
4624 if (HIWORD(nmtbr
.tbButton
.iString
))
4625 nmtbr
.tbButton
.iString
= 0;
4627 TOOLBAR_InsertButtonW(infoPtr
->hwndSelf
, -1,
4628 (LPARAM
)&nmtbr
.tbButton
);
4631 /* do legacy notifications */
4632 if (infoPtr
->iVersion
< 5)
4634 /* FIXME: send TBN_BEGINADJUST */
4635 FIXME("send TBN_GETBUTTONINFO for each button\n");
4636 /* FIXME: send TBN_ENDADJUST */
4639 /* remove all uninitialised buttons
4640 * note: loop backwards to avoid having to fixup i on a
4642 for (i
= infoPtr
->nNumButtons
- 1; i
>= 0; i
--)
4643 if (infoPtr
->buttons
[i
].iBitmap
== -1)
4644 TOOLBAR_DeleteButton(infoPtr
->hwndSelf
, i
, 0);
4646 /* only indicate success if at least one button survived */
4647 if (infoPtr
->nNumButtons
> 0) ret
= TRUE
;
4658 TOOLBAR_SaveRestoreW (HWND hwnd
, WPARAM wParam
, LPTBSAVEPARAMSW lpSave
)
4660 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4662 if (lpSave
== NULL
) return 0;
4665 return TOOLBAR_Save(infoPtr
, lpSave
);
4667 return TOOLBAR_Restore(infoPtr
, lpSave
);
4672 TOOLBAR_SaveRestoreA (HWND hwnd
, WPARAM wParam
, LPTBSAVEPARAMSA lpSave
)
4674 LPWSTR pszValueName
= 0, pszSubKey
= 0;
4675 TBSAVEPARAMSW SaveW
;
4679 if (lpSave
== NULL
) return 0;
4681 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, NULL
, 0);
4682 pszSubKey
= Alloc(len
* sizeof(WCHAR
));
4683 if (pszSubKey
) goto exit
;
4684 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszSubKey
, -1, pszSubKey
, len
);
4686 len
= MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, NULL
, 0);
4687 pszValueName
= Alloc(len
* sizeof(WCHAR
));
4688 if (!pszValueName
) goto exit
;
4689 MultiByteToWideChar(CP_ACP
, 0, lpSave
->pszValueName
, -1, pszValueName
, len
);
4691 SaveW
.pszValueName
= pszValueName
;
4692 SaveW
.pszSubKey
= pszSubKey
;
4693 SaveW
.hkr
= lpSave
->hkr
;
4694 result
= TOOLBAR_SaveRestoreW(hwnd
, wParam
, &SaveW
);
4697 Free (pszValueName
);
4705 TOOLBAR_SetAnchorHighlight (HWND hwnd
, WPARAM wParam
)
4707 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4708 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4710 TRACE("hwnd=%p, bAnchor = %s\n", hwnd
, wParam
? "TRUE" : "FALSE");
4712 infoPtr
->bAnchor
= (BOOL
)wParam
;
4714 /* Native does not remove the hot effect from an already hot button */
4716 return (LRESULT
)bOldAnchor
;
4721 TOOLBAR_SetBitmapSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4723 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4724 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4726 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd
, wParam
, lParam
);
4729 FIXME("wParam is %d. Perhaps image list index?\n", wParam
);
4731 if ((LOWORD(lParam
) <= 0) || (HIWORD(lParam
)<=0))
4732 lParam
= MAKELPARAM(16, 15);
4734 if (infoPtr
->nNumButtons
> 0)
4735 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4736 infoPtr
->nNumButtons
,
4737 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
4738 LOWORD(lParam
), HIWORD(lParam
));
4740 infoPtr
->nBitmapWidth
= (INT
)LOWORD(lParam
);
4741 infoPtr
->nBitmapHeight
= (INT
)HIWORD(lParam
);
4744 if ((himlDef
== infoPtr
->himlInt
) &&
4745 (ImageList_GetImageCount(infoPtr
->himlInt
) == 0))
4747 ImageList_SetIconSize(infoPtr
->himlInt
, infoPtr
->nBitmapWidth
,
4748 infoPtr
->nBitmapHeight
);
4751 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
4757 TOOLBAR_SetButtonInfoA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4759 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4760 LPTBBUTTONINFOA lptbbi
= (LPTBBUTTONINFOA
)lParam
;
4761 TBUTTON_INFO
*btnPtr
;
4767 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOA
))
4770 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4771 lptbbi
->dwMask
& 0x80000000);
4775 btnPtr
= &infoPtr
->buttons
[nIndex
];
4776 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4777 btnPtr
->idCommand
= lptbbi
->idCommand
;
4778 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4779 btnPtr
->iBitmap
= lptbbi
->iImage
;
4780 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4781 btnPtr
->dwData
= lptbbi
->lParam
;
4782 if (lptbbi
->dwMask
& TBIF_SIZE
)
4783 btnPtr
->cx
= lptbbi
->cx
;
4784 if (lptbbi
->dwMask
& TBIF_STATE
)
4785 btnPtr
->fsState
= lptbbi
->fsState
;
4786 if (lptbbi
->dwMask
& TBIF_STYLE
)
4787 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4789 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4790 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4791 /* iString is index, zero it to make Str_SetPtr succeed */
4794 Str_SetPtrAtoW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4797 /* save the button rect to see if we need to redraw the whole toolbar */
4798 oldBtnRect
= btnPtr
->rect
;
4799 TOOLBAR_CalcToolbar(hwnd
);
4801 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4802 InvalidateRect(hwnd
, NULL
, TRUE
);
4804 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4811 TOOLBAR_SetButtonInfoW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4813 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4814 LPTBBUTTONINFOW lptbbi
= (LPTBBUTTONINFOW
)lParam
;
4815 TBUTTON_INFO
*btnPtr
;
4821 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4824 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4825 lptbbi
->dwMask
& 0x80000000);
4829 btnPtr
= &infoPtr
->buttons
[nIndex
];
4830 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4831 btnPtr
->idCommand
= lptbbi
->idCommand
;
4832 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4833 btnPtr
->iBitmap
= lptbbi
->iImage
;
4834 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4835 btnPtr
->dwData
= lptbbi
->lParam
;
4836 if (lptbbi
->dwMask
& TBIF_SIZE
)
4837 btnPtr
->cx
= lptbbi
->cx
;
4838 if (lptbbi
->dwMask
& TBIF_STATE
)
4839 btnPtr
->fsState
= lptbbi
->fsState
;
4840 if (lptbbi
->dwMask
& TBIF_STYLE
)
4841 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4843 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT_PTR
)lptbbi
->pszText
!= -1)) {
4844 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4845 /* iString is index, zero it to make Str_SetPtr succeed */
4847 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4850 /* save the button rect to see if we need to redraw the whole toolbar */
4851 oldBtnRect
= btnPtr
->rect
;
4852 TOOLBAR_CalcToolbar(hwnd
);
4854 if (!EqualRect(&oldBtnRect
, &btnPtr
->rect
))
4855 InvalidateRect(hwnd
, NULL
, TRUE
);
4857 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4864 TOOLBAR_SetButtonSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4866 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4867 INT cx
= LOWORD(lParam
), cy
= HIWORD(lParam
);
4869 if ((cx
< 0) || (cy
< 0))
4871 ERR("invalid parameter 0x%08lx\n", (DWORD
)lParam
);
4875 TRACE("%p, cx = %d, cy = %d\n", hwnd
, cx
, cy
);
4877 /* The documentation claims you can only change the button size before
4878 * any button has been added. But this is wrong.
4879 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4880 * it to the toolbar, and it checks that the return value is nonzero - mjm
4881 * Further testing shows that we must actually perform the change too.
4884 * The documentation also does not mention that if 0 is supplied for
4885 * either size, the system changes it to the default of 24 wide and
4886 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4888 infoPtr
->nButtonWidth
= (cx
) ? cx
: 24;
4889 infoPtr
->nButtonHeight
= (cy
) ? cy
: 22;
4895 TOOLBAR_SetButtonWidth (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4897 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4899 /* if setting to current values, ignore */
4900 if ((infoPtr
->cxMin
== (INT
)LOWORD(lParam
)) &&
4901 (infoPtr
->cxMax
== (INT
)HIWORD(lParam
))) {
4902 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4903 infoPtr
->cxMin
, infoPtr
->cxMax
);
4907 /* save new values */
4908 infoPtr
->cxMin
= (INT
)LOWORD(lParam
);
4909 infoPtr
->cxMax
= (INT
)HIWORD(lParam
);
4911 /* otherwise we need to recalc the toolbar and in some cases
4912 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4913 which doesn't actually draw - GA). */
4914 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4915 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4917 TOOLBAR_CalcToolbar (hwnd
);
4919 InvalidateRect (hwnd
, NULL
, TRUE
);
4926 TOOLBAR_SetCmdId (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4928 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4929 INT nIndex
= (INT
)wParam
;
4931 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4934 infoPtr
->buttons
[nIndex
].idCommand
= (INT
)lParam
;
4936 if (infoPtr
->hwndToolTip
) {
4938 FIXME("change tool tip!\n");
4947 TOOLBAR_SetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4949 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4950 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4951 HIMAGELIST himlTemp
;
4954 if (infoPtr
->iVersion
>= 5)
4957 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4958 &infoPtr
->cimlDis
, himl
, id
);
4960 /* FIXME: redraw ? */
4962 return (LRESULT
)himlTemp
;
4967 TOOLBAR_SetDrawTextFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4969 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4972 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd
, (DWORD
)wParam
, (DWORD
)lParam
);
4974 dwTemp
= infoPtr
->dwDTFlags
;
4975 infoPtr
->dwDTFlags
=
4976 (infoPtr
->dwDTFlags
& (DWORD
)wParam
) | (DWORD
)lParam
;
4978 return (LRESULT
)dwTemp
;
4981 /* This function differs a bit from what MSDN says it does:
4982 * 1. lParam contains extended style flags to OR with current style
4983 * (MSDN isn't clear on the OR bit)
4984 * 2. wParam appears to contain extended style flags to be reset
4985 * (MSDN says that this parameter is reserved)
4988 TOOLBAR_SetExtendedStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4990 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4993 dwTemp
= infoPtr
->dwExStyle
;
4994 infoPtr
->dwExStyle
&= ~wParam
;
4995 infoPtr
->dwExStyle
|= (DWORD
)lParam
;
4997 TRACE("new style 0x%08lx\n", infoPtr
->dwExStyle
);
4999 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
5000 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
5001 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
5003 TOOLBAR_CalcToolbar (hwnd
);
5005 TOOLBAR_AutoSize(hwnd
);
5007 InvalidateRect(hwnd
, NULL
, TRUE
);
5009 return (LRESULT
)dwTemp
;
5014 TOOLBAR_SetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5016 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5017 HIMAGELIST himlTemp
;
5018 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
5021 if (infoPtr
->iVersion
>= 5)
5024 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd
, himl
, id
);
5026 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
5027 &infoPtr
->cimlHot
, himl
, id
);
5029 /* FIXME: redraw ? */
5031 return (LRESULT
)himlTemp
;
5035 /* Makes previous hot button no longer hot, makes the specified
5036 * button hot and sends appropriate notifications. dwReason is one or
5037 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
5038 * NOTE 1: this function does not validate nHit
5039 * NOTE 2: the name of this function is completely made up and
5040 * not based on any documentation from Microsoft. */
5042 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
5044 if (infoPtr
->nHotItem
!= nHit
)
5046 NMTBHOTITEM nmhotitem
;
5047 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
5048 LRESULT no_highlight
;
5050 /* Remove the effect of an old hot button if the button was
5051 drawn with the hot button effect */
5052 if(infoPtr
->nHotItem
>= 0)
5054 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
5055 oldBtnPtr
->bHot
= FALSE
;
5058 infoPtr
->nHotItem
= nHit
;
5060 /* It's not a separator or in nowhere. It's a hot button. */
5062 btnPtr
= &infoPtr
->buttons
[nHit
];
5064 nmhotitem
.dwFlags
= dwReason
;
5066 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
5068 nmhotitem
.dwFlags
|= HICF_ENTERING
;
5070 nmhotitem
.idNew
= btnPtr
->idCommand
;
5072 nmhotitem
.dwFlags
|= HICF_LEAVING
;
5074 no_highlight
= TOOLBAR_SendNotify(&nmhotitem
.hdr
, infoPtr
, TBN_HOTITEMCHANGE
);
5076 /* now invalidate the old and new buttons so they will be painted,
5077 * but only if they are enabled - disabled buttons cannot become hot */
5078 if (oldBtnPtr
&& (oldBtnPtr
->fsState
& TBSTATE_ENABLED
))
5079 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
5080 if (btnPtr
&& !no_highlight
&& (btnPtr
->fsState
& TBSTATE_ENABLED
))
5082 btnPtr
->bHot
= TRUE
;
5083 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
5089 TOOLBAR_SetHotItem (HWND hwnd
, WPARAM wParam
)
5091 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5092 INT nOldHotItem
= infoPtr
->nHotItem
;
5094 TRACE("hwnd = %p, nHit = %d\n", hwnd
, (INT
)wParam
);
5096 if ((INT
) wParam
< 0 || (INT
)wParam
> infoPtr
->nNumButtons
)
5099 /* NOTE: an application can still remove the hot item even if anchor
5100 * highlighting is enabled */
5102 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
5103 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, HICF_OTHER
);
5105 if (nOldHotItem
< 0)
5108 return (LRESULT
)nOldHotItem
;
5113 TOOLBAR_SetImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5115 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5116 HIMAGELIST himlTemp
;
5117 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
5120 if (infoPtr
->iVersion
>= 5)
5123 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
5124 &infoPtr
->cimlDef
, himl
, id
);
5126 infoPtr
->nNumBitmaps
= 0;
5127 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
5128 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
5130 if (!ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
5131 &infoPtr
->nBitmapHeight
))
5133 infoPtr
->nBitmapWidth
= 1;
5134 infoPtr
->nBitmapHeight
= 1;
5137 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
5138 hwnd
, infoPtr
->himlDef
, id
, infoPtr
->nNumBitmaps
,
5139 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
5141 InvalidateRect(hwnd
, NULL
, TRUE
);
5143 return (LRESULT
)himlTemp
;
5148 TOOLBAR_SetIndent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5150 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5152 infoPtr
->nIndent
= (INT
)wParam
;
5156 /* process only on indent changing */
5157 if(infoPtr
->nIndent
!= (INT
)wParam
)
5159 infoPtr
->nIndent
= (INT
)wParam
;
5160 TOOLBAR_CalcToolbar (hwnd
);
5161 InvalidateRect(hwnd
, NULL
, FALSE
);
5169 TOOLBAR_SetInsertMark (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5171 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5172 TBINSERTMARK
*lptbim
= (TBINSERTMARK
*)lParam
;
5174 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd
, lptbim
->iButton
, lptbim
->dwFlags
);
5176 if ((lptbim
->dwFlags
& ~TBIMHT_AFTER
) != 0)
5178 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim
->dwFlags
& ~TBIMHT_AFTER
));
5182 if ((lptbim
->iButton
== -1) ||
5183 ((lptbim
->iButton
< infoPtr
->nNumButtons
) &&
5184 (lptbim
->iButton
>= 0)))
5186 infoPtr
->tbim
= *lptbim
;
5187 /* FIXME: don't need to update entire toolbar */
5188 InvalidateRect(hwnd
, NULL
, TRUE
);
5191 ERR("Invalid button index %d\n", lptbim
->iButton
);
5198 TOOLBAR_SetInsertMarkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5200 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5202 infoPtr
->clrInsertMark
= (COLORREF
)lParam
;
5204 /* FIXME: don't need to update entire toolbar */
5205 InvalidateRect(hwnd
, NULL
, TRUE
);
5212 TOOLBAR_SetMaxTextRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5214 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5216 infoPtr
->nMaxTextRows
= (INT
)wParam
;
5218 TOOLBAR_CalcToolbar(hwnd
);
5223 /* MSDN gives slightly wrong info on padding.
5224 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
5225 * 2. It is not used to create a blank area between the edge of the button
5226 * and the text or image if TBSTYLE_LIST is set. It is used to control
5227 * the gap between the image and text.
5228 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
5229 * to control the bottom and right borders [with the border being
5230 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
5231 * is shared evenly on both sides of the button.
5232 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
5235 TOOLBAR_SetPadding (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5237 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5240 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
5241 infoPtr
->szPadding
.cx
= min(LOWORD((DWORD
)lParam
), GetSystemMetrics(SM_CXEDGE
));
5242 infoPtr
->szPadding
.cy
= min(HIWORD((DWORD
)lParam
), GetSystemMetrics(SM_CYEDGE
));
5243 TRACE("cx=%ld, cy=%ld\n",
5244 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
5245 return (LRESULT
) oldPad
;
5250 TOOLBAR_SetParent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5252 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5257 hwndOldNotify
= infoPtr
->hwndNotify
;
5258 infoPtr
->hwndNotify
= (HWND
)wParam
;
5260 return (LRESULT
)hwndOldNotify
;
5265 TOOLBAR_SetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5267 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5268 LPRECT lprc
= (LPRECT
)lParam
;
5272 if (LOWORD(wParam
) > 1) {
5273 FIXME("multiple rows not supported!\n");
5276 if(infoPtr
->nRows
!= LOWORD(wParam
))
5278 infoPtr
->nRows
= LOWORD(wParam
);
5280 /* recalculate toolbar */
5281 TOOLBAR_CalcToolbar (hwnd
);
5283 /* repaint toolbar */
5284 InvalidateRect(hwnd
, NULL
, TRUE
);
5287 /* return bounding rectangle */
5289 lprc
->left
= infoPtr
->rcBound
.left
;
5290 lprc
->right
= infoPtr
->rcBound
.right
;
5291 lprc
->top
= infoPtr
->rcBound
.top
;
5292 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
5300 TOOLBAR_SetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5302 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5303 TBUTTON_INFO
*btnPtr
;
5306 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
5310 btnPtr
= &infoPtr
->buttons
[nIndex
];
5312 /* if hidden state has changed the invalidate entire window and recalc */
5313 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
5314 btnPtr
->fsState
= LOWORD(lParam
);
5315 TOOLBAR_CalcToolbar (hwnd
);
5316 InvalidateRect(hwnd
, 0, TRUE
);
5320 /* process state changing if current state doesn't match new state */
5321 if(btnPtr
->fsState
!= LOWORD(lParam
))
5323 btnPtr
->fsState
= LOWORD(lParam
);
5324 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5332 TOOLBAR_SetStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5334 SetWindowLongW(hwnd
, GWL_STYLE
, lParam
);
5340 inline static LRESULT
5341 TOOLBAR_SetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5343 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5345 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd
, (HWND
)wParam
, lParam
);
5347 infoPtr
->hwndToolTip
= (HWND
)wParam
;
5353 TOOLBAR_SetUnicodeFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5355 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5358 TRACE("%s hwnd=%p\n",
5359 ((BOOL
)wParam
) ? "TRUE" : "FALSE", hwnd
);
5361 bTemp
= infoPtr
->bUnicode
;
5362 infoPtr
->bUnicode
= (BOOL
)wParam
;
5369 TOOLBAR_GetColorScheme (HWND hwnd
, LPCOLORSCHEME lParam
)
5371 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5373 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
5374 comctl32_color
.clrBtnHighlight
:
5375 infoPtr
->clrBtnHighlight
;
5376 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
5377 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
5383 TOOLBAR_SetColorScheme (HWND hwnd
, LPCOLORSCHEME lParam
)
5385 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5387 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5388 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
5389 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
5391 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
5392 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
5393 InvalidateRect(hwnd
, NULL
, TRUE
);
5399 TOOLBAR_SetVersion (HWND hwnd
, INT iVersion
)
5401 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5402 INT iOldVersion
= infoPtr
->iVersion
;
5404 infoPtr
->iVersion
= iVersion
;
5406 if (infoPtr
->iVersion
>= 5)
5407 TOOLBAR_SetUnicodeFormat(hwnd
, (WPARAM
)TRUE
, (LPARAM
)0);
5414 TOOLBAR_GetStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5416 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5417 WORD iString
= HIWORD(wParam
);
5418 WORD buffersize
= LOWORD(wParam
);
5419 LPSTR str
= (LPSTR
)lParam
;
5422 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, buffersize
, str
);
5424 if (iString
< infoPtr
->nNumStrings
)
5426 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
5428 TRACE("returning %s\n", debugstr_a(str
));
5431 ERR("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5438 TOOLBAR_GetStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5440 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5441 WORD iString
= HIWORD(wParam
);
5442 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
5443 LPWSTR str
= (LPWSTR
)lParam
;
5446 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, LOWORD(wParam
), str
);
5448 if (iString
< infoPtr
->nNumStrings
)
5450 len
= min(len
, strlenW(infoPtr
->strings
[iString
]));
5451 ret
= (len
+1)*sizeof(WCHAR
);
5452 memcpy(str
, infoPtr
->strings
[iString
], ret
);
5455 TRACE("returning %s\n", debugstr_w(str
));
5458 ERR("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
5463 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5464 * is the maximum size of the toolbar? */
5465 static LRESULT
TOOLBAR_Unkwn45D(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5467 SIZE
* pSize
= (SIZE
*)lParam
;
5468 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
5473 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5474 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5475 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5478 TOOLBAR_Unkwn45E (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5480 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5481 INT nOldHotItem
= infoPtr
->nHotItem
;
5483 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5484 nOldHotItem
, infoPtr
->nHotItem
, (DWORD
)lParam
);
5486 if ((INT
) wParam
< 0 || (INT
)wParam
> infoPtr
->nNumButtons
)
5489 /* NOTE: an application can still remove the hot item even if anchor
5490 * highlighting is enabled */
5492 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, lParam
);
5496 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
5499 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5500 * which controls the amount of spacing between the image and the text
5501 * of buttons for TBSTYLE_LIST toolbars. */
5502 static LRESULT
TOOLBAR_Unkwn460(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5504 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5506 TRACE("hwnd=%p iListGap=%d\n", hwnd
, wParam
);
5509 FIXME("lParam = 0x%08lx. Please report\n", lParam
);
5511 infoPtr
->iListGap
= (INT
)wParam
;
5513 InvalidateRect(hwnd
, NULL
, TRUE
);
5518 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5519 * of image lists associated with the various states. */
5520 static LRESULT
TOOLBAR_Unkwn462(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5522 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5524 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd
, wParam
, lParam
);
5526 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
5530 TOOLBAR_Unkwn463 (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5532 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5533 LPSIZE lpsize
= (LPSIZE
)lParam
;
5539 * Testing shows the following:
5540 * wParam = 0 adjust cx value
5541 * = 1 set cy value to max size.
5542 * lParam pointer to SIZE structure
5545 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5546 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
5550 if (lpsize
->cx
== -1) {
5551 /* **** this is wrong, native measures each button and sets it */
5552 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5554 else if(HIWORD(lpsize
->cx
)) {
5556 HWND hwndParent
= GetParent(hwnd
);
5558 GetWindowRect(hwnd
, &rc
);
5559 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
5560 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5561 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
5562 lpsize
->cx
= max(rc
.right
-rc
.left
,
5563 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
5566 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5570 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5573 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5577 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5578 lpsize
->cx
, lpsize
->cy
);
5582 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5584 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd
, wParam
, lParam
);
5586 InvalidateRect(hwnd
, NULL
, TRUE
);
5592 TOOLBAR_Create (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5594 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5595 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
5598 TRACE("hwnd = %p\n", hwnd
);
5600 /* initialize info structure */
5601 infoPtr
->nButtonHeight
= 22;
5602 infoPtr
->nButtonWidth
= 24;
5603 infoPtr
->nBitmapHeight
= 15;
5604 infoPtr
->nBitmapWidth
= 16;
5606 infoPtr
->nMaxTextRows
= 1;
5607 infoPtr
->cxMin
= -1;
5608 infoPtr
->cxMax
= -1;
5609 infoPtr
->nNumBitmaps
= 0;
5610 infoPtr
->nNumStrings
= 0;
5612 infoPtr
->bCaptured
= FALSE
;
5613 infoPtr
->nButtonDown
= -1;
5614 infoPtr
->nButtonDrag
= -1;
5615 infoPtr
->nOldHit
= -1;
5616 infoPtr
->nHotItem
= -1;
5617 infoPtr
->hwndNotify
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
5618 infoPtr
->dwDTFlags
= (dwStyle
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
: DT_CENTER
| DT_END_ELLIPSIS
;
5619 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
5620 infoPtr
->bDragOutSent
= FALSE
;
5621 infoPtr
->iVersion
= 0;
5622 infoPtr
->hwndSelf
= hwnd
;
5623 infoPtr
->bDoRedraw
= TRUE
;
5624 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
5625 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
5626 infoPtr
->szPadding
.cx
= DEFPAD_CX
;
5627 infoPtr
->szPadding
.cy
= DEFPAD_CY
;
5628 infoPtr
->iListGap
= DEFLISTGAP
;
5629 infoPtr
->dwStyle
= dwStyle
;
5630 infoPtr
->tbim
.iButton
= -1;
5631 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5632 infoPtr
->bUnicode
= infoPtr
->hwndNotify
&&
5633 (NFR_UNICODE
== SendMessageW(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, (LPARAM
)NF_REQUERY
));
5635 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5636 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW (&logFont
);
5638 if (dwStyle
& TBSTYLE_TOOLTIPS
) {
5639 /* Create tooltip control */
5640 infoPtr
->hwndToolTip
=
5641 CreateWindowExW (0, TOOLTIPS_CLASSW
, NULL
, 0,
5642 CW_USEDEFAULT
, CW_USEDEFAULT
,
5643 CW_USEDEFAULT
, CW_USEDEFAULT
,
5646 /* Send NM_TOOLTIPSCREATED notification */
5647 if (infoPtr
->hwndToolTip
)
5649 NMTOOLTIPSCREATED nmttc
;
5651 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
5653 TOOLBAR_SendNotify (&nmttc
.hdr
, infoPtr
, NM_TOOLTIPSCREATED
);
5657 OpenThemeData (hwnd
, themeClass
);
5659 TOOLBAR_CheckStyle (hwnd
, dwStyle
);
5661 TOOLBAR_CalcToolbar(hwnd
);
5668 TOOLBAR_Destroy (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5670 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5672 /* delete tooltip control */
5673 if (infoPtr
->hwndToolTip
)
5674 DestroyWindow (infoPtr
->hwndToolTip
);
5676 /* delete temporary buffer for tooltip text */
5677 Free (infoPtr
->pszTooltipText
);
5678 Free (infoPtr
->bitmaps
); /* bitmaps list */
5680 /* delete button data */
5681 if (infoPtr
->buttons
)
5682 Free (infoPtr
->buttons
);
5684 /* delete strings */
5685 if (infoPtr
->strings
) {
5687 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5688 if (infoPtr
->strings
[i
])
5689 Free (infoPtr
->strings
[i
]);
5691 Free (infoPtr
->strings
);
5694 /* destroy internal image list */
5695 if (infoPtr
->himlInt
)
5696 ImageList_Destroy (infoPtr
->himlInt
);
5698 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5699 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5700 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5702 /* delete default font */
5704 DeleteObject (infoPtr
->hDefaultFont
);
5706 CloseThemeData (GetWindowTheme (hwnd
));
5708 /* free toolbar info data */
5710 SetWindowLongPtrW (hwnd
, 0, 0);
5717 TOOLBAR_EraseBackground (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5719 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5720 NMTBCUSTOMDRAW tbcd
;
5723 HTHEME theme
= GetWindowTheme (hwnd
);
5725 /* the app has told us not to redraw the toolbar */
5726 if (!infoPtr
->bDoRedraw
)
5729 if (infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) {
5730 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5731 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5732 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5733 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5734 infoPtr
->dwBaseCustDraw
= ntfret
& 0xffff;
5736 /* FIXME: in general the return flags *can* be or'ed together */
5737 switch (infoPtr
->dwBaseCustDraw
)
5739 case CDRF_DODEFAULT
:
5741 case CDRF_SKIPDEFAULT
:
5744 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5749 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5750 * to my parent for processing.
5752 if (theme
|| (infoPtr
->dwStyle
& TBSTYLE_TRANSPARENT
)) {
5754 HDC hdc
= (HDC
)wParam
;
5759 parent
= GetParent(hwnd
);
5760 MapWindowPoints(hwnd
, parent
, &pt
, 1);
5761 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5762 ret
= SendMessageW (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5763 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5766 ret
= DefWindowProcW (hwnd
, WM_ERASEBKGND
, wParam
, lParam
);
5768 if ((infoPtr
->dwStyle
& TBSTYLE_CUSTOMERASE
) &&
5769 (infoPtr
->dwBaseCustDraw
& CDRF_NOTIFYPOSTERASE
)) {
5770 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5771 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5772 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5773 ntfret
= TOOLBAR_SendNotify (&tbcd
.nmcd
.hdr
, infoPtr
, NM_CUSTOMDRAW
);
5774 infoPtr
->dwBaseCustDraw
= ntfret
& 0xffff;
5775 switch (infoPtr
->dwBaseCustDraw
)
5777 case CDRF_DODEFAULT
:
5779 case CDRF_SKIPDEFAULT
:
5782 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5791 TOOLBAR_GetFont (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5793 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5795 return (LRESULT
)infoPtr
->hFont
;
5800 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO
*infoPtr
, INT iDirection
, DWORD dwReason
)
5803 INT nNewHotItem
= infoPtr
->nHotItem
;
5805 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
5808 if ((nNewHotItem
+ iDirection
< 0) ||
5809 (nNewHotItem
+ iDirection
>= infoPtr
->nNumButtons
))
5811 NMTBWRAPHOTITEM nmtbwhi
;
5812 nmtbwhi
.idNew
= infoPtr
->buttons
[nNewHotItem
].idCommand
;
5813 nmtbwhi
.iDirection
= iDirection
;
5814 nmtbwhi
.dwReason
= dwReason
;
5816 if (TOOLBAR_SendNotify(&nmtbwhi
.hdr
, infoPtr
, TBN_WRAPHOTITEM
))
5820 nNewHotItem
+= iDirection
;
5821 nNewHotItem
= (nNewHotItem
+ infoPtr
->nNumButtons
) % infoPtr
->nNumButtons
;
5823 if ((infoPtr
->buttons
[nNewHotItem
].fsState
& TBSTATE_ENABLED
) &&
5824 !(infoPtr
->buttons
[nNewHotItem
].fsStyle
& BTNS_SEP
))
5826 TOOLBAR_SetHotItemEx(infoPtr
, nNewHotItem
, dwReason
);
5833 TOOLBAR_KeyDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5835 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5838 nmkey
.nVKey
= (UINT
)wParam
;
5839 nmkey
.uFlags
= HIWORD(lParam
);
5841 if (TOOLBAR_SendNotify(&nmkey
.hdr
, infoPtr
, NM_KEYDOWN
))
5842 return DefWindowProcW(hwnd
, WM_KEYDOWN
, wParam
, lParam
);
5844 switch ((UINT
)wParam
)
5848 TOOLBAR_SetRelativeHotItem(infoPtr
, -1, HICF_ARROWKEYS
);
5852 TOOLBAR_SetRelativeHotItem(infoPtr
, 1, HICF_ARROWKEYS
);
5856 if ((infoPtr
->nHotItem
>= 0) &&
5857 (infoPtr
->buttons
[infoPtr
->nHotItem
].fsState
& TBSTATE_ENABLED
))
5859 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
5860 MAKEWPARAM(infoPtr
->buttons
[infoPtr
->nHotItem
].idCommand
, BN_CLICKED
),
5871 TOOLBAR_LButtonDblClk (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5876 pt
.x
= (INT
)LOWORD(lParam
);
5877 pt
.y
= (INT
)HIWORD(lParam
);
5878 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5881 TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
5882 else if (GetWindowLongW (hwnd
, GWL_STYLE
) & CCS_ADJUSTABLE
)
5883 TOOLBAR_Customize (hwnd
);
5890 TOOLBAR_LButtonDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5892 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5893 TBUTTON_INFO
*btnPtr
;
5898 BOOL bDragKeyPressed
;
5902 if (infoPtr
->dwStyle
& TBSTYLE_ALTDRAG
)
5903 bDragKeyPressed
= (GetKeyState(VK_MENU
) < 0);
5905 bDragKeyPressed
= (wParam
& MK_SHIFT
);
5907 if (infoPtr
->hwndToolTip
)
5908 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5909 WM_LBUTTONDOWN
, wParam
, lParam
);
5911 pt
.x
= (INT
)LOWORD(lParam
);
5912 pt
.y
= (INT
)HIWORD(lParam
);
5913 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5915 btnPtr
= &infoPtr
->buttons
[nHit
];
5917 if ((nHit
>= 0) && bDragKeyPressed
&& (infoPtr
->dwStyle
& CCS_ADJUSTABLE
))
5919 infoPtr
->nButtonDrag
= nHit
;
5922 /* If drag cursor has not been loaded, load it.
5923 * Note: it doesn't need to be freed */
5925 hCursorDrag
= LoadCursorW(COMCTL32_hModule
, (LPCWSTR
)IDC_MOVEBUTTON
);
5926 SetCursor(hCursorDrag
);
5931 infoPtr
->nOldHit
= nHit
;
5933 CopyRect(&arrowRect
, &btnPtr
->rect
);
5934 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5936 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5937 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5938 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5939 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5940 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5941 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5945 /* draw in pressed state */
5946 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5947 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5949 btnPtr
->bDropDownPressed
= TRUE
;
5950 RedrawWindow(hwnd
,&btnPtr
->rect
,0,
5951 RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5953 memset(&nmtb
, 0, sizeof(nmtb
));
5954 nmtb
.iItem
= btnPtr
->idCommand
;
5955 nmtb
.rcButton
= btnPtr
->rect
;
5956 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5958 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5960 if (res
!= TBDDRET_TREATPRESSED
)
5964 /* redraw button in unpressed state */
5965 if (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
)
5966 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5968 btnPtr
->bDropDownPressed
= FALSE
;
5969 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5971 /* find and set hot item
5972 * NOTE: native doesn't do this, but that is a bug */
5974 ScreenToClient(hwnd
, &pt
);
5975 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
5976 if (!infoPtr
->bAnchor
|| (nHit
>= 0))
5977 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5979 /* remove any left mouse button down or double-click messages
5980 * so that we can get a toggle effect on the button */
5981 while (PeekMessageW(&msg
, hwnd
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
) ||
5982 PeekMessageW(&msg
, hwnd
, WM_LBUTTONDBLCLK
, WM_LBUTTONDBLCLK
, PM_REMOVE
))
5987 /* otherwise drop through and process as pushed */
5989 infoPtr
->bCaptured
= TRUE
;
5990 infoPtr
->nButtonDown
= nHit
;
5991 infoPtr
->bDragOutSent
= FALSE
;
5993 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5995 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5997 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5998 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6005 memset(&nmtb
, 0, sizeof(nmtb
));
6006 nmtb
.iItem
= btnPtr
->idCommand
;
6007 TOOLBAR_SendNotify((NMHDR
*)&nmtb
, infoPtr
, TBN_BEGINDRAG
);
6010 nmmouse
.dwHitInfo
= nHit
;
6012 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
6014 nmmouse
.dwItemSpec
= -1;
6017 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
6018 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
6021 ClientToScreen(hwnd
, &pt
);
6024 if (!TOOLBAR_SendNotify(&nmmouse
.hdr
, infoPtr
, NM_LDOWN
))
6025 return DefWindowProcW(hwnd
, WM_LBUTTONDOWN
, wParam
, lParam
);
6031 TOOLBAR_LButtonUp (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6033 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6034 TBUTTON_INFO
*btnPtr
;
6038 BOOL bSendMessage
= TRUE
;
6043 if (infoPtr
->hwndToolTip
)
6044 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
6045 WM_LBUTTONUP
, wParam
, lParam
);
6047 pt
.x
= (INT
)LOWORD(lParam
);
6048 pt
.y
= (INT
)HIWORD(lParam
);
6049 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
6051 if (!infoPtr
->bAnchor
|| (nHit
>= 0))
6052 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
6054 if (infoPtr
->nButtonDrag
>= 0) {
6058 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDrag
];
6061 SetCursor(LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
));
6063 GetClientRect(hwnd
, &rcClient
);
6064 if (PtInRect(&rcClient
, pt
))
6071 else if ((nHit
== -1) && PtInRect(&infoPtr
->buttons
[-nHit
].rect
, pt
))
6074 if (nButton
== infoPtr
->nButtonDrag
)
6076 /* if the button is moved sightly left and we have a
6077 * separator there then remove it */
6078 if (pt
.x
< (btnPtr
->rect
.left
+ (btnPtr
->rect
.right
- btnPtr
->rect
.left
)/2))
6080 if ((nButton
> 0) && (infoPtr
->buttons
[nButton
-1].fsStyle
& BTNS_SEP
))
6081 TOOLBAR_DeleteButton(hwnd
, nButton
- 1, 0);
6083 else /* else insert a separator before the dragged button */
6086 memset(&tbb
, 0, sizeof(tbb
));
6087 tbb
.fsStyle
= BTNS_SEP
;
6089 TOOLBAR_InsertButtonW(hwnd
, nButton
, (LPARAM
)&tbb
);
6096 if ((infoPtr
->nNumButtons
> 0) && (pt
.x
< infoPtr
->buttons
[0].rect
.left
))
6097 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, 0);
6099 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, infoPtr
->nNumButtons
);
6102 TOOLBAR_MoveButton(hwnd
, infoPtr
->nButtonDrag
, nButton
);
6107 TRACE("button %d dragged out of toolbar\n", infoPtr
->nButtonDrag
);
6108 TOOLBAR_DeleteButton(hwnd
, (WPARAM
)infoPtr
->nButtonDrag
, 0);
6111 /* button under cursor changed so need to re-set hot item */
6112 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
6113 infoPtr
->nButtonDrag
= -1;
6115 TOOLBAR_SendNotify(&hdr
, infoPtr
, TBN_TOOLBARCHANGE
);
6117 else if (infoPtr
->nButtonDown
>= 0) {
6118 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6119 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6121 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
6122 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
6123 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
6125 if (nOldIndex
== nHit
)
6126 bSendMessage
= FALSE
;
6127 if ((nOldIndex
!= nHit
) &&
6129 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
6130 btnPtr
->fsState
|= TBSTATE_CHECKED
;
6133 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
6134 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
6136 btnPtr
->fsState
|= TBSTATE_CHECKED
;
6140 if (nOldIndex
!= -1)
6141 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
6144 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
6145 * that resets bCaptured and btn TBSTATE_PRESSED flags,
6146 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
6148 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
6150 infoPtr
->nButtonDown
= -1;
6152 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
6153 TOOLBAR_SendNotify ((NMHDR
*) &hdr
, infoPtr
,
6154 NM_RELEASEDCAPTURE
);
6156 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
6159 memset(&nmtb
, 0, sizeof(nmtb
));
6160 nmtb
.iItem
= btnPtr
->idCommand
;
6161 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
6164 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
6166 SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
,
6167 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, BN_CLICKED
), (LPARAM
)hwnd
);
6171 /* !!! Undocumented - toolbar at 4.71 level and above sends
6172 * NM_CLICK with the NMMOUSE structure. */
6173 nmmouse
.dwHitInfo
= nHit
;
6176 nmmouse
.dwItemSpec
= -1;
6179 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
6180 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
6183 ClientToScreen(hwnd
, &pt
);
6186 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_CLICK
))
6187 return DefWindowProcW(hwnd
, WM_LBUTTONUP
, wParam
, lParam
);
6193 TOOLBAR_RButtonUp( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6195 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6200 pt
.x
= LOWORD(lParam
);
6201 pt
.y
= HIWORD(lParam
);
6203 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
6204 nmmouse
.dwHitInfo
= nHit
;
6207 nmmouse
.dwItemSpec
= -1;
6209 nmmouse
.dwItemSpec
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].idCommand
;
6210 nmmouse
.dwItemData
= infoPtr
->buttons
[nmmouse
.dwHitInfo
].dwData
;
6213 ClientToScreen(hwnd
, &pt
);
6216 if (!TOOLBAR_SendNotify((LPNMHDR
)&nmmouse
, infoPtr
, NM_RCLICK
))
6217 return DefWindowProcW(hwnd
, WM_RBUTTONUP
, wParam
, lParam
);
6223 TOOLBAR_RButtonDblClk( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6225 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6228 if (!TOOLBAR_SendNotify(&nmhdr
, infoPtr
, NM_RDBLCLK
))
6229 return DefWindowProcW(hwnd
, WM_RBUTTONDBLCLK
, wParam
, lParam
);
6235 TOOLBAR_CaptureChanged(HWND hwnd
)
6237 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6238 TBUTTON_INFO
*btnPtr
;
6240 infoPtr
->bCaptured
= FALSE
;
6242 if (infoPtr
->nButtonDown
>= 0)
6244 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6245 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6247 infoPtr
->nOldHit
= -1;
6249 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
6250 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6256 TOOLBAR_MouseLeave (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6258 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6259 TBUTTON_INFO
*hotBtnPtr
;
6261 hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nOldHit
];
6263 /* don't remove hot effects when in anchor highlighting mode or when a
6264 * drop-down button is pressed */
6265 if (!infoPtr
->bAnchor
&& (infoPtr
->nOldHit
< 0 || !hotBtnPtr
->bDropDownPressed
))
6266 TOOLBAR_SetHotItemEx(infoPtr
, TOOLBAR_NOWHERE
, HICF_MOUSE
);
6268 if (infoPtr
->nOldHit
< 0)
6271 /* If the last button we were over is depressed then make it not */
6272 /* depressed and redraw it */
6273 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
6275 TBUTTON_INFO
*btnPtr
;
6278 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6280 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6282 rc1
= hotBtnPtr
->rect
;
6283 InflateRect (&rc1
, 1, 1);
6284 InvalidateRect (hwnd
, &rc1
, TRUE
);
6287 if (infoPtr
->bCaptured
&& !infoPtr
->bDragOutSent
)
6290 ZeroMemory(&nmt
, sizeof(nmt
));
6291 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6292 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6293 infoPtr
->bDragOutSent
= TRUE
;
6296 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
6302 TOOLBAR_MouseMove (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6304 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6306 TRACKMOUSEEVENT trackinfo
;
6308 TBUTTON_INFO
*btnPtr
;
6310 if ((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
)) {
6311 /* fill in the TRACKMOUSEEVENT struct */
6312 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
6313 trackinfo
.dwFlags
= TME_QUERY
;
6314 trackinfo
.hwndTrack
= hwnd
;
6315 trackinfo
.dwHoverTime
= HOVER_DEFAULT
;
6317 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6318 _TrackMouseEvent(&trackinfo
);
6320 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6321 if(!(trackinfo
.dwFlags
& TME_LEAVE
)) {
6322 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
6324 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6325 /* and can properly deactivate the hot toolbar button */
6326 _TrackMouseEvent(&trackinfo
);
6330 if (infoPtr
->hwndToolTip
)
6331 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
6332 WM_MOUSEMOVE
, wParam
, lParam
);
6334 pt
.x
= (INT
)LOWORD(lParam
);
6335 pt
.y
= (INT
)HIWORD(lParam
);
6337 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
6339 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6340 && (!infoPtr
->bAnchor
|| (nHit
>= 0)))
6341 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
);
6343 if (infoPtr
->nOldHit
!= nHit
)
6345 if (infoPtr
->bCaptured
)
6347 if (!infoPtr
->bDragOutSent
)
6350 ZeroMemory(&nmt
, sizeof(nmt
));
6351 nmt
.iItem
= infoPtr
->buttons
[infoPtr
->nButtonDown
].idCommand
;
6352 TOOLBAR_SendNotify(&nmt
.hdr
, infoPtr
, TBN_DRAGOUT
);
6353 infoPtr
->bDragOutSent
= TRUE
;
6356 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
6357 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
6358 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
6359 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6361 else if (nHit
== infoPtr
->nButtonDown
) {
6362 btnPtr
->fsState
|= TBSTATE_PRESSED
;
6363 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6365 infoPtr
->nOldHit
= nHit
;
6373 inline static LRESULT
6374 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6376 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6377 return DefWindowProcW (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
6379 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6383 inline static LRESULT
6384 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6386 if (!(GetWindowLongW(hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
6387 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
6389 return DefWindowProcW (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
6394 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6396 TOOLBAR_INFO
*infoPtr
;
6397 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
6400 /* allocate memory for info structure */
6401 infoPtr
= (TOOLBAR_INFO
*)Alloc (sizeof(TOOLBAR_INFO
));
6402 SetWindowLongPtrW (hwnd
, 0, (LONG_PTR
)infoPtr
);
6405 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
6407 infoPtr
->nWidth
= 0;
6409 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6410 if (!GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
)) {
6411 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongPtrW (GetParent (hwnd
), GWLP_HINSTANCE
);
6412 SetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
, (LONG_PTR
)hInst
);
6415 /* native control does:
6416 * Get a lot of colors and brushes
6418 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6419 * CreateFontIndirectW(adr1)
6420 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6421 * hdc = GetDC(toolbar)
6422 * GetSystemMetrics(0x48)
6423 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6424 * 0, 0, 0, 0, "MARLETT")
6425 * oldfnt = SelectObject(hdc, fnt2)
6426 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6427 * GetTextMetricsW(hdc, adr3)
6428 * SelectObject(hdc, oldfnt)
6429 * DeleteObject(fnt2)
6431 * InvalidateRect(toolbar, 0, 1)
6432 * SetWindowLongW(toolbar, 0, addr)
6433 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6436 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6437 * ie 2 0x4600094c 0x4600094c 0x4600894d
6438 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6439 * rebar 0x50008844 0x40008844 0x50008845
6440 * pager 0x50000844 0x40000844 0x50008845
6441 * IC35mgr 0x5400084e **nochange**
6442 * on entry to _NCCREATE 0x5400084e
6443 * rowlist 0x5400004e **nochange**
6444 * on entry to _NCCREATE 0x5400004e
6448 /* I think the code below is a bug, but it is the way that the native
6449 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6450 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6451 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6452 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6453 * Somehow, the only cases of this seem to be MFC programs.
6455 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6456 * does not occur in the WM_STYLECHANGING routine.
6457 * (Guy Albertelli 9/2001)
6460 if (((infoPtr
->dwStyle
& TBSTYLE_FLAT
) || GetWindowTheme (infoPtr
->hwndSelf
))
6461 && !(cs
->style
& TBSTYLE_TRANSPARENT
))
6462 styleadd
|= TBSTYLE_TRANSPARENT
;
6463 if (!(cs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
6464 styleadd
|= CCS_TOP
; /* default to top */
6465 SetWindowLongW (hwnd
, GWL_STYLE
, cs
->style
| styleadd
);
6468 return DefWindowProcW (hwnd
, WM_NCCREATE
, wParam
, lParam
);
6473 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6475 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
6479 if (dwStyle
& WS_MINIMIZE
)
6480 return 0; /* Nothing to do */
6482 DefWindowProcW (hwnd
, WM_NCPAINT
, wParam
, lParam
);
6484 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
6487 if (!(dwStyle
& CCS_NODIVIDER
))
6489 GetWindowRect (hwnd
, &rcWindow
);
6490 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
6491 if( dwStyle
& WS_BORDER
)
6492 OffsetRect (&rcWindow
, 1, 1);
6493 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
6496 ReleaseDC( hwnd
, hdc
);
6502 /* handles requests from the tooltip control on what text to display */
6503 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
6505 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
6507 TRACE("button index = %d\n", index
);
6509 Free (infoPtr
->pszTooltipText
);
6510 infoPtr
->pszTooltipText
= NULL
;
6515 if (infoPtr
->bUnicode
)
6517 WCHAR wszBuffer
[INFOTIPSIZE
+1];
6518 NMTBGETINFOTIPW tbgit
;
6519 unsigned int len
; /* in chars */
6521 wszBuffer
[0] = '\0';
6522 wszBuffer
[INFOTIPSIZE
] = '\0';
6524 tbgit
.pszText
= wszBuffer
;
6525 tbgit
.cchTextMax
= INFOTIPSIZE
;
6526 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6527 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6529 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
6531 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
6533 len
= strlenW(tbgit
.pszText
);
6534 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6536 /* need to allocate temporary buffer in infoPtr as there
6537 * isn't enough space in buffer passed to us by the
6538 * tooltip control */
6539 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6540 if (infoPtr
->pszTooltipText
)
6542 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6543 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6549 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
6555 CHAR szBuffer
[INFOTIPSIZE
+1];
6556 NMTBGETINFOTIPA tbgit
;
6557 unsigned int len
; /* in chars */
6560 szBuffer
[INFOTIPSIZE
] = '\0';
6562 tbgit
.pszText
= szBuffer
;
6563 tbgit
.cchTextMax
= INFOTIPSIZE
;
6564 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
6565 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
6567 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
6569 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
6571 len
= MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
6572 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]))
6574 /* need to allocate temporary buffer in infoPtr as there
6575 * isn't enough space in buffer passed to us by the
6576 * tooltip control */
6577 infoPtr
->pszTooltipText
= Alloc(len
*sizeof(WCHAR
));
6578 if (infoPtr
->pszTooltipText
)
6580 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, infoPtr
->pszTooltipText
, len
);
6581 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6587 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1,
6588 lpnmtdi
->lpszText
, sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0]));
6593 /* if button has text, but it is not shown then automatically
6594 * use that text as tooltip */
6595 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
6596 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
6598 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
6599 unsigned int len
= pszText
? strlenW(pszText
) : 0;
6601 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
6603 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
6605 /* need to allocate temporary buffer in infoPtr as there
6606 * isn't enough space in buffer passed to us by the
6607 * tooltip control */
6608 infoPtr
->pszTooltipText
= Alloc((len
+1)*sizeof(WCHAR
));
6609 if (infoPtr
->pszTooltipText
)
6611 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
6612 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
6618 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
6623 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
6625 /* last resort: send notification on to app */
6626 /* FIXME: find out what is really used here */
6627 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, 0, (LPARAM
)lpnmtdi
);
6631 inline static LRESULT
6632 TOOLBAR_Notify (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6634 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6635 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
6637 switch (lpnmh
->code
)
6641 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
6643 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
6644 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
6645 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6649 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
6650 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6658 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lParam
;
6660 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
6661 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
6662 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6663 lppgs
->iScroll
, lppgs
->iDir
);
6667 case TTN_GETDISPINFOW
:
6668 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lParam
);
6670 case TTN_GETDISPINFOA
:
6671 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6681 TOOLBAR_NotifyFormat(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
6685 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam
, lParam
);
6687 if (lParam
== NF_QUERY
)
6690 if (lParam
== NF_REQUERY
) {
6691 format
= SendMessageW(infoPtr
->hwndNotify
,
6692 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
6693 if ((format
!= NFR_ANSI
) && (format
!= NFR_UNICODE
)) {
6694 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6705 TOOLBAR_Paint (HWND hwnd
, WPARAM wParam
)
6707 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
6711 /* fill ps.rcPaint with a default rect */
6712 memcpy(&(ps
.rcPaint
), &(infoPtr
->rcBound
), sizeof(infoPtr
->rcBound
));
6714 hdc
= wParam
==0 ? BeginPaint(hwnd
, &ps
) : (HDC
)wParam
;
6716 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6717 ps
.rcPaint
.left
, ps
.rcPaint
.top
,
6718 ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
6720 TOOLBAR_Refresh (hwnd
, hdc
, &ps
);
6721 if (!wParam
) EndPaint (hwnd
, &ps
);
6728 TOOLBAR_SetFocus (HWND hwnd
, WPARAM wParam
)
6730 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6732 TRACE("nHotItem = %d\n", infoPtr
->nHotItem
);
6734 /* make first item hot */
6735 if (infoPtr
->nNumButtons
> 0)
6736 TOOLBAR_SetHotItemEx(infoPtr
, 0, HICF_OTHER
);
6743 TOOLBAR_SetRedraw (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6744 /*****************************************************
6747 * Handles the WM_SETREDRAW message.
6750 * According to testing V4.71 of COMCTL32 returns the
6751 * *previous* status of the redraw flag (either 0 or 1)
6752 * instead of the MSDN documented value of 0 if handled.
6753 * (For laughs see the "consistency" with same function
6756 *****************************************************/
6758 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6759 BOOL oldredraw
= infoPtr
->bDoRedraw
;
6761 TRACE("set to %s\n",
6762 (wParam
) ? "TRUE" : "FALSE");
6763 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
6765 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
6767 return (oldredraw
) ? 1 : 0;
6772 TOOLBAR_Size (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
6774 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6776 TRACE("sizing toolbar!\n");
6778 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
6780 RECT delta_width
, delta_height
, client
, dummy
;
6781 DWORD min_x
, max_x
, min_y
, max_y
;
6782 TBUTTON_INFO
*btnPtr
;
6785 GetClientRect(hwnd
, &client
);
6786 if(client
.right
> infoPtr
->client_rect
.right
)
6788 min_x
= infoPtr
->client_rect
.right
;
6789 max_x
= client
.right
;
6793 max_x
= infoPtr
->client_rect
.right
;
6794 min_x
= client
.right
;
6796 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6798 min_y
= infoPtr
->client_rect
.bottom
;
6799 max_y
= client
.bottom
;
6803 max_y
= infoPtr
->client_rect
.bottom
;
6804 min_y
= client
.bottom
;
6807 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6808 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6810 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6811 btnPtr
= infoPtr
->buttons
;
6812 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6813 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6814 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6815 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6817 GetClientRect(hwnd
, &infoPtr
->client_rect
);
6818 TOOLBAR_AutoSize(hwnd
);
6824 TOOLBAR_StyleChanged (HWND hwnd
, INT nType
, LPSTYLESTRUCT lpStyle
)
6826 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6828 if (nType
== GWL_STYLE
)
6830 if (lpStyle
->styleNew
& TBSTYLE_LIST
)
6831 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
;
6833 infoPtr
->dwDTFlags
= DT_CENTER
| DT_END_ELLIPSIS
;
6835 TOOLBAR_CheckStyle (hwnd
, lpStyle
->styleNew
);
6837 TRACE("new style 0x%08lx\n", lpStyle
->styleNew
);
6839 infoPtr
->dwStyle
= lpStyle
->styleNew
;
6841 /* only resize if one of the CCS_* styles was changed */
6842 if ((infoPtr
->dwStyle
^ lpStyle
->styleNew
) & COMMON_STYLES
)
6844 TOOLBAR_AutoSize (hwnd
);
6846 InvalidateRect(hwnd
, NULL
, TRUE
);
6855 TOOLBAR_SysColorChange (HWND hwnd
)
6857 COMCTL32_RefreshSysColors();
6863 /* update theme after a WM_THEMECHANGED message */
6864 static LRESULT
theme_changed (HWND hwnd
)
6866 HTHEME theme
= GetWindowTheme (hwnd
);
6867 CloseThemeData (theme
);
6868 OpenThemeData (hwnd
, themeClass
);
6873 static LRESULT WINAPI
6874 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6876 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6878 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6879 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6881 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
6882 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
6887 return TOOLBAR_AddBitmap (hwnd
, wParam
, lParam
);
6889 case TB_ADDBUTTONSA
:
6890 return TOOLBAR_AddButtonsA (hwnd
, wParam
, lParam
);
6892 case TB_ADDBUTTONSW
:
6893 return TOOLBAR_AddButtonsW (hwnd
, wParam
, lParam
);
6896 return TOOLBAR_AddStringA (hwnd
, wParam
, lParam
);
6899 return TOOLBAR_AddStringW (hwnd
, wParam
, lParam
);
6902 return TOOLBAR_AutoSize (hwnd
);
6904 case TB_BUTTONCOUNT
:
6905 return TOOLBAR_ButtonCount (hwnd
, wParam
, lParam
);
6907 case TB_BUTTONSTRUCTSIZE
:
6908 return TOOLBAR_ButtonStructSize (hwnd
, wParam
, lParam
);
6910 case TB_CHANGEBITMAP
:
6911 return TOOLBAR_ChangeBitmap (hwnd
, wParam
, lParam
);
6913 case TB_CHECKBUTTON
:
6914 return TOOLBAR_CheckButton (hwnd
, wParam
, lParam
);
6916 case TB_COMMANDTOINDEX
:
6917 return TOOLBAR_CommandToIndex (hwnd
, wParam
, lParam
);
6920 return TOOLBAR_Customize (hwnd
);
6922 case TB_DELETEBUTTON
:
6923 return TOOLBAR_DeleteButton (hwnd
, wParam
, lParam
);
6925 case TB_ENABLEBUTTON
:
6926 return TOOLBAR_EnableButton (hwnd
, wParam
, lParam
);
6928 case TB_GETANCHORHIGHLIGHT
:
6929 return TOOLBAR_GetAnchorHighlight (hwnd
);
6932 return TOOLBAR_GetBitmap (hwnd
, wParam
, lParam
);
6934 case TB_GETBITMAPFLAGS
:
6935 return TOOLBAR_GetBitmapFlags (hwnd
, wParam
, lParam
);
6938 return TOOLBAR_GetButton (hwnd
, wParam
, lParam
);
6940 case TB_GETBUTTONINFOA
:
6941 return TOOLBAR_GetButtonInfoA (hwnd
, wParam
, lParam
);
6943 case TB_GETBUTTONINFOW
:
6944 return TOOLBAR_GetButtonInfoW (hwnd
, wParam
, lParam
);
6946 case TB_GETBUTTONSIZE
:
6947 return TOOLBAR_GetButtonSize (hwnd
);
6949 case TB_GETBUTTONTEXTA
:
6950 return TOOLBAR_GetButtonTextA (hwnd
, wParam
, lParam
);
6952 case TB_GETBUTTONTEXTW
:
6953 return TOOLBAR_GetButtonTextW (hwnd
, wParam
, lParam
);
6955 case TB_GETDISABLEDIMAGELIST
:
6956 return TOOLBAR_GetDisabledImageList (hwnd
, wParam
, lParam
);
6958 case TB_GETEXTENDEDSTYLE
:
6959 return TOOLBAR_GetExtendedStyle (hwnd
);
6961 case TB_GETHOTIMAGELIST
:
6962 return TOOLBAR_GetHotImageList (hwnd
, wParam
, lParam
);
6965 return TOOLBAR_GetHotItem (hwnd
);
6967 case TB_GETIMAGELIST
:
6968 return TOOLBAR_GetDefImageList (hwnd
, wParam
, lParam
);
6970 case TB_GETINSERTMARK
:
6971 return TOOLBAR_GetInsertMark (hwnd
, wParam
, lParam
);
6973 case TB_GETINSERTMARKCOLOR
:
6974 return TOOLBAR_GetInsertMarkColor (hwnd
, wParam
, lParam
);
6976 case TB_GETITEMRECT
:
6977 return TOOLBAR_GetItemRect (hwnd
, wParam
, lParam
);
6980 return TOOLBAR_GetMaxSize (hwnd
, wParam
, lParam
);
6982 /* case TB_GETOBJECT: */ /* 4.71 */
6985 return TOOLBAR_GetPadding (hwnd
);
6988 return TOOLBAR_GetRect (hwnd
, wParam
, lParam
);
6991 return TOOLBAR_GetRows (hwnd
, wParam
, lParam
);
6994 return TOOLBAR_GetState (hwnd
, wParam
, lParam
);
6997 return TOOLBAR_GetStringA (hwnd
, wParam
, lParam
);
7000 return TOOLBAR_GetStringW (hwnd
, wParam
, lParam
);
7003 return TOOLBAR_GetStyle (hwnd
, wParam
, lParam
);
7005 case TB_GETTEXTROWS
:
7006 return TOOLBAR_GetTextRows (hwnd
, wParam
, lParam
);
7008 case TB_GETTOOLTIPS
:
7009 return TOOLBAR_GetToolTips (hwnd
, wParam
, lParam
);
7011 case TB_GETUNICODEFORMAT
:
7012 return TOOLBAR_GetUnicodeFormat (hwnd
, wParam
, lParam
);
7015 return TOOLBAR_HideButton (hwnd
, wParam
, lParam
);
7018 return TOOLBAR_HitTest (hwnd
, wParam
, lParam
);
7020 case TB_INDETERMINATE
:
7021 return TOOLBAR_Indeterminate (hwnd
, wParam
, lParam
);
7023 case TB_INSERTBUTTONA
:
7024 return TOOLBAR_InsertButtonA (hwnd
, wParam
, lParam
);
7026 case TB_INSERTBUTTONW
:
7027 return TOOLBAR_InsertButtonW (hwnd
, wParam
, lParam
);
7029 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
7031 case TB_ISBUTTONCHECKED
:
7032 return TOOLBAR_IsButtonChecked (hwnd
, wParam
, lParam
);
7034 case TB_ISBUTTONENABLED
:
7035 return TOOLBAR_IsButtonEnabled (hwnd
, wParam
, lParam
);
7037 case TB_ISBUTTONHIDDEN
:
7038 return TOOLBAR_IsButtonHidden (hwnd
, wParam
, lParam
);
7040 case TB_ISBUTTONHIGHLIGHTED
:
7041 return TOOLBAR_IsButtonHighlighted (hwnd
, wParam
, lParam
);
7043 case TB_ISBUTTONINDETERMINATE
:
7044 return TOOLBAR_IsButtonIndeterminate (hwnd
, wParam
, lParam
);
7046 case TB_ISBUTTONPRESSED
:
7047 return TOOLBAR_IsButtonPressed (hwnd
, wParam
, lParam
);
7050 return TOOLBAR_LoadImages (hwnd
, wParam
, lParam
);
7052 case TB_MAPACCELERATORA
:
7053 case TB_MAPACCELERATORW
:
7054 return TOOLBAR_MapAccelerator (hwnd
, wParam
, lParam
);
7057 return TOOLBAR_MarkButton (hwnd
, wParam
, lParam
);
7060 return TOOLBAR_MoveButton (hwnd
, wParam
, lParam
);
7062 case TB_PRESSBUTTON
:
7063 return TOOLBAR_PressButton (hwnd
, wParam
, lParam
);
7065 case TB_REPLACEBITMAP
:
7066 return TOOLBAR_ReplaceBitmap (hwnd
, wParam
, lParam
);
7068 case TB_SAVERESTOREA
:
7069 return TOOLBAR_SaveRestoreA (hwnd
, wParam
, (LPTBSAVEPARAMSA
)lParam
);
7071 case TB_SAVERESTOREW
:
7072 return TOOLBAR_SaveRestoreW (hwnd
, wParam
, (LPTBSAVEPARAMSW
)lParam
);
7074 case TB_SETANCHORHIGHLIGHT
:
7075 return TOOLBAR_SetAnchorHighlight (hwnd
, wParam
);
7077 case TB_SETBITMAPSIZE
:
7078 return TOOLBAR_SetBitmapSize (hwnd
, wParam
, lParam
);
7080 case TB_SETBUTTONINFOA
:
7081 return TOOLBAR_SetButtonInfoA (hwnd
, wParam
, lParam
);
7083 case TB_SETBUTTONINFOW
:
7084 return TOOLBAR_SetButtonInfoW (hwnd
, wParam
, lParam
);
7086 case TB_SETBUTTONSIZE
:
7087 return TOOLBAR_SetButtonSize (hwnd
, wParam
, lParam
);
7089 case TB_SETBUTTONWIDTH
:
7090 return TOOLBAR_SetButtonWidth (hwnd
, wParam
, lParam
);
7093 return TOOLBAR_SetCmdId (hwnd
, wParam
, lParam
);
7095 case TB_SETDISABLEDIMAGELIST
:
7096 return TOOLBAR_SetDisabledImageList (hwnd
, wParam
, lParam
);
7098 case TB_SETDRAWTEXTFLAGS
:
7099 return TOOLBAR_SetDrawTextFlags (hwnd
, wParam
, lParam
);
7101 case TB_SETEXTENDEDSTYLE
:
7102 return TOOLBAR_SetExtendedStyle (hwnd
, wParam
, lParam
);
7104 case TB_SETHOTIMAGELIST
:
7105 return TOOLBAR_SetHotImageList (hwnd
, wParam
, lParam
);
7108 return TOOLBAR_SetHotItem (hwnd
, wParam
);
7110 case TB_SETIMAGELIST
:
7111 return TOOLBAR_SetImageList (hwnd
, wParam
, lParam
);
7114 return TOOLBAR_SetIndent (hwnd
, wParam
, lParam
);
7116 case TB_SETINSERTMARK
:
7117 return TOOLBAR_SetInsertMark (hwnd
, wParam
, lParam
);
7119 case TB_SETINSERTMARKCOLOR
:
7120 return TOOLBAR_SetInsertMarkColor (hwnd
, wParam
, lParam
);
7122 case TB_SETMAXTEXTROWS
:
7123 return TOOLBAR_SetMaxTextRows (hwnd
, wParam
, lParam
);
7126 return TOOLBAR_SetPadding (hwnd
, wParam
, lParam
);
7129 return TOOLBAR_SetParent (hwnd
, wParam
, lParam
);
7132 return TOOLBAR_SetRows (hwnd
, wParam
, lParam
);
7135 return TOOLBAR_SetState (hwnd
, wParam
, lParam
);
7138 return TOOLBAR_SetStyle (hwnd
, wParam
, lParam
);
7140 case TB_SETTOOLTIPS
:
7141 return TOOLBAR_SetToolTips (hwnd
, wParam
, lParam
);
7143 case TB_SETUNICODEFORMAT
:
7144 return TOOLBAR_SetUnicodeFormat (hwnd
, wParam
, lParam
);
7147 return TOOLBAR_Unkwn45D(hwnd
, wParam
, lParam
);
7150 return TOOLBAR_Unkwn45E (hwnd
, wParam
, lParam
);
7153 return TOOLBAR_Unkwn460(hwnd
, wParam
, lParam
);
7156 return TOOLBAR_Unkwn462(hwnd
, wParam
, lParam
);
7159 return TOOLBAR_Unkwn463 (hwnd
, wParam
, lParam
);
7162 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
7164 /* Common Control Messages */
7166 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
7167 case CCM_GETCOLORSCHEME
:
7168 return TOOLBAR_GetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
7170 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
7171 case CCM_SETCOLORSCHEME
:
7172 return TOOLBAR_SetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
7174 case CCM_GETVERSION
:
7175 return TOOLBAR_GetVersion (hwnd
);
7177 case CCM_SETVERSION
:
7178 return TOOLBAR_SetVersion (hwnd
, (INT
)wParam
);
7184 return TOOLBAR_Create (hwnd
, wParam
, lParam
);
7187 return TOOLBAR_Destroy (hwnd
, wParam
, lParam
);
7190 return TOOLBAR_EraseBackground (hwnd
, wParam
, lParam
);
7193 return TOOLBAR_GetFont (hwnd
, wParam
, lParam
);
7196 return TOOLBAR_KeyDown (hwnd
, wParam
, lParam
);
7198 /* case WM_KILLFOCUS: */
7200 case WM_LBUTTONDBLCLK
:
7201 return TOOLBAR_LButtonDblClk (hwnd
, wParam
, lParam
);
7203 case WM_LBUTTONDOWN
:
7204 return TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
7207 return TOOLBAR_LButtonUp (hwnd
, wParam
, lParam
);
7210 return TOOLBAR_RButtonUp (hwnd
, wParam
, lParam
);
7212 case WM_RBUTTONDBLCLK
:
7213 return TOOLBAR_RButtonDblClk (hwnd
, wParam
, lParam
);
7216 return TOOLBAR_MouseMove (hwnd
, wParam
, lParam
);
7219 return TOOLBAR_MouseLeave (hwnd
, wParam
, lParam
);
7221 case WM_CAPTURECHANGED
:
7222 return TOOLBAR_CaptureChanged(hwnd
);
7225 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
7228 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
7231 return TOOLBAR_NCCreate (hwnd
, wParam
, lParam
);
7234 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
7237 return TOOLBAR_Notify (hwnd
, wParam
, lParam
);
7239 case WM_NOTIFYFORMAT
:
7240 return TOOLBAR_NotifyFormat (infoPtr
, wParam
, lParam
);
7242 case WM_PRINTCLIENT
:
7244 return TOOLBAR_Paint (hwnd
, wParam
);
7247 return TOOLBAR_SetFocus (hwnd
, wParam
);
7250 return TOOLBAR_SetRedraw (hwnd
, wParam
, lParam
);
7253 return TOOLBAR_Size (hwnd
, wParam
, lParam
);
7255 case WM_STYLECHANGED
:
7256 return TOOLBAR_StyleChanged (hwnd
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
7258 case WM_SYSCOLORCHANGE
:
7259 return TOOLBAR_SysColorChange (hwnd
);
7261 case WM_THEMECHANGED
:
7262 return theme_changed (hwnd
);
7264 /* case WM_WININICHANGE: */
7269 case WM_MEASUREITEM
:
7271 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
7273 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7274 case PGM_FORWARDMOUSE
:
7275 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7278 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
7279 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7280 uMsg
, wParam
, lParam
);
7281 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
7287 TOOLBAR_Register (void)
7291 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
7292 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
7293 wndClass
.lpfnWndProc
= ToolbarWindowProc
;
7294 wndClass
.cbClsExtra
= 0;
7295 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
7296 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
7297 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
7298 wndClass
.lpszClassName
= TOOLBARCLASSNAMEW
;
7300 RegisterClassW (&wndClass
);
7305 TOOLBAR_Unregister (void)
7307 UnregisterClassW (TOOLBARCLASSNAMEW
, NULL
);
7310 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
7315 /* Check if the entry already exists */
7316 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
7318 /* If this is a new entry we must create it and insert into the array */
7323 c
= (PIMLENTRY
) Alloc(sizeof(IMLENTRY
));
7326 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
7327 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
7342 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
7346 for (i
= 0; i
< *cies
; i
++)
7356 static PIMLENTRY
TOOLBAR_GetImageListEntry(PIMLENTRY
*pies
, INT cies
, INT id
)
7364 for (i
= 0; i
< cies
; i
++)
7366 if (pies
[i
]->id
== id
)
7378 static HIMAGELIST
TOOLBAR_GetImageList(PIMLENTRY
*pies
, INT cies
, INT id
)
7380 HIMAGELIST himlDef
= 0;
7381 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
7384 himlDef
= pie
->himl
;
7390 static BOOL
TOOLBAR_GetButtonInfo(TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
7392 if (infoPtr
->bUnicode
)
7393 return TOOLBAR_SendNotify(&nmtb
->hdr
, infoPtr
, TBN_GETBUTTONINFOW
);
7400 nmtba
.iItem
= nmtb
->iItem
;
7401 nmtba
.pszText
= Buffer
;
7402 nmtba
.cchText
= 256;
7403 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
7405 if (TOOLBAR_SendNotify(&nmtba
.hdr
, infoPtr
, TBN_GETBUTTONINFOA
))
7407 int ccht
= strlen(nmtba
.pszText
);
7409 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)nmtba
.pszText
, -1,
7410 nmtb
->pszText
, nmtb
->cchText
);
7412 memcpy(&nmtb
->tbButton
, &nmtba
.tbButton
, sizeof(TBBUTTON
));
7421 static BOOL
TOOLBAR_IsButtonRemovable(TOOLBAR_INFO
*infoPtr
,
7422 int iItem
, PCUSTOMBUTTON btnInfo
)
7426 /* MSDN states that iItem is the index of the button, rather than the
7427 * command ID as used by every other NMTOOLBAR notification */
7429 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
7431 return TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_QUERYDELETE
);