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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Differences between MSDN and actual native control operation:
25 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
26 * to the right of the bitmap. Otherwise, this style is
27 * identical to TBSTYLE_FLAT."
28 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
29 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
30 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
31 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
33 * This code was audited for completeness against the documented features
34 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
36 * Unless otherwise noted, we believe this code to be complete, as per
37 * the specification mentioned above.
38 * If you discover missing features or bugs please note them below.
43 * - TBSTYLE_REGISTERDROP
44 * - TBSTYLE_EX_DOUBLEBUFFER
47 * - TB_GETINSERTMARKCOLOR
50 * - TB_INSERTMARKHITTEST
60 * - TBN_DELETINGBUTTON
66 * - Button wrapping (under construction).
68 * - Fix TOOLBAR_SetButtonInfo32A/W.
69 * - iListGap custom draw support.
70 * - Customization dialog:
71 * - Minor buglet in 'available buttons' list:
72 * Buttons are not listed in MS-like order. MS seems to use a single
73 * internal list to store the button information of both listboxes.
74 * - Drag list support.
77 * - Run tests using Waite Group Windows95 API Bible Volume 2.
78 * The second cdrom contains executables addstr.exe, btncount.exe,
79 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
80 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
81 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
82 * setparnt.exe, setrows.exe, toolwnd.exe.
83 * - Microsofts controlspy examples.
84 * - Charles Petzold's 'Programming Windows': gadgets.exe
94 #include "wine/unicode.h"
97 #include "imagelist.h"
99 #include "wine/debug.h"
101 WINE_DEFAULT_DEBUG_CHANNEL(toolbar
);
128 } IMLENTRY
, *PIMLENTRY
;
132 DWORD dwStructSize
; /* size of TBBUTTON struct */
133 INT nHeight
; /* height of the toolbar */
134 INT nWidth
; /* width of the toolbar */
141 INT nRows
; /* number of button rows */
142 INT nMaxTextRows
; /* maximum number of text rows */
143 INT cxMin
; /* minimum button width */
144 INT cxMax
; /* maximum button width */
145 INT nNumButtons
; /* number of buttons */
146 INT nNumBitmaps
; /* number of bitmaps */
147 INT nNumStrings
; /* number of strings */
149 BOOL bUnicode
; /* ASCII (FALSE) or Unicode (TRUE)? */
150 BOOL bCaptured
; /* mouse captured? */
153 INT nHotItem
; /* index of the "hot" item */
154 DWORD dwBaseCustDraw
; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
155 DWORD dwItemCustDraw
; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
156 DWORD dwItemCDFlag
; /* TBCDRF_ flags from last ITEMPREPAINT */
157 SIZE szPadding
; /* padding values around button */
158 INT iListGap
; /* default gap between text and image for toolbar with list style */
160 HFONT hFont
; /* text font */
161 HIMAGELIST himlInt
; /* image list created internally */
162 PIMLENTRY
*himlDef
; /* default image list array */
163 INT cimlDef
; /* default image list array count */
164 PIMLENTRY
*himlHot
; /* hot image list array */
165 INT cimlHot
; /* hot image list array count */
166 PIMLENTRY
*himlDis
; /* disabled image list array */
167 INT cimlDis
; /* disabled image list array count */
168 HWND hwndToolTip
; /* handle to tool tip control */
169 HWND hwndNotify
; /* handle to the window that gets notifications */
170 HWND hwndSelf
; /* my own handle */
171 BOOL bTransparent
; /* background transparency flag */
172 BOOL bBtnTranspnt
; /* button transparency flag */
173 BOOL bAutoSize
; /* auto size deadlock indicator */
174 BOOL bAnchor
; /* anchor highlight enabled */
175 BOOL bNtfUnicode
; /* TRUE if NOTIFYs use {W} */
176 BOOL bDoRedraw
; /* Redraw status */
177 DWORD dwExStyle
; /* extended toolbar style */
178 DWORD dwDTFlags
; /* DrawText flags */
180 COLORREF clrInsertMark
; /* insert mark color */
181 COLORREF clrBtnHighlight
; /* color for Flat Separator */
182 COLORREF clrBtnShadow
; /* color for Flag Separator */
183 RECT rcBound
; /* bounding rectangle */
185 LPWSTR pszTooltipText
; /* temporary store for a string > 80 characters
186 * for TTN_GETDISPINFOW notification */
187 TBUTTON_INFO
*buttons
; /* pointer to button array */
188 LPWSTR
*strings
; /* pointer to string array */
189 TBITMAP_INFO
*bitmaps
;
190 } TOOLBAR_INFO
, *PTOOLBAR_INFO
;
193 /* used by customization dialog */
196 PTOOLBAR_INFO tbInfo
;
198 } CUSTDLG_INFO
, *PCUSTDLG_INFO
;
206 } CUSTOMBUTTON
, *PCUSTOMBUTTON
;
215 #define SEPARATOR_WIDTH 8
217 #define BOTTOM_BORDER 2
218 #define DDARROW_WIDTH 11
219 #define ARROW_HEIGHT 3
221 /* gap between border of button and text/image */
224 /* how wide to treat the bitmap if it isn't present */
225 #define LIST_IMAGE_ABSENT_WIDTH 2
227 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
228 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
229 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
231 static inline int TOOLBAR_GetListTextOffset(TOOLBAR_INFO
*infoPtr
, INT iListGap
)
233 return GetSystemMetrics(SM_CXEDGE
) + iListGap
- infoPtr
->szPadding
.cx
/2;
236 /* Used to find undocumented extended styles */
237 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
238 TBSTYLE_EX_UNDOC1 | \
239 TBSTYLE_EX_MIXEDBUTTONS | \
240 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
242 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
243 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
244 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
245 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
246 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
248 static BOOL
TOOLBAR_GetButtonInfo(TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
);
249 static BOOL
TOOLBAR_IsButtonRemovable(TOOLBAR_INFO
*infoPtr
, int iItem
, PCUSTOMBUTTON btnInfo
);
250 static HIMAGELIST
TOOLBAR_GetImageList(PIMLENTRY
*pies
, INT cies
, INT id
);
251 static PIMLENTRY
TOOLBAR_GetImageListEntry(PIMLENTRY
*pies
, INT cies
, INT id
);
252 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
);
253 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
);
256 TOOLBAR_NotifyFormat(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
);
260 TOOLBAR_GetText(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
262 LPWSTR lpText
= NULL
;
264 /* FIXME: 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
)) {
298 dwStyle
= GetWindowLongA (iP
->hwndSelf
, GWL_STYLE
);
299 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
301 iP
->dwExStyle
, iP
->nNumButtons
, iP
->nNumBitmaps
,
302 iP
->nNumStrings
, dwStyle
);
303 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
305 iP
->himlInt
, iP
->himlDef
, iP
->himlHot
, iP
->himlDis
,
306 (iP
->bDoRedraw
) ? "TRUE" : "FALSE");
307 for(i
=0; i
<iP
->nNumButtons
; i
++) {
308 TOOLBAR_DumpButton(iP
, &iP
->buttons
[i
], i
, TRUE
);
314 /***********************************************************************
317 * This function validates that the styles set are implemented and
318 * issues FIXME's warning of possible problems. In a perfect world this
319 * function should be null.
322 TOOLBAR_CheckStyle (HWND hwnd
, DWORD dwStyle
)
324 if (dwStyle
& TBSTYLE_ALTDRAG
)
325 FIXME("[%p] TBSTYLE_ALTDRAG not implemented\n", hwnd
);
326 if (dwStyle
& TBSTYLE_REGISTERDROP
)
327 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd
);
332 TOOLBAR_SendNotify (NMHDR
*nmhdr
, TOOLBAR_INFO
*infoPtr
, UINT code
)
334 if(!IsWindow(infoPtr
->hwndSelf
))
335 return 0; /* we have just been destroyed */
337 nmhdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
338 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
341 TRACE("to window %p, code=%08x, %s\n", infoPtr
->hwndNotify
, code
,
342 (infoPtr
->bNtfUnicode
) ? "via Unicode" : "via ANSI");
344 if (infoPtr
->bNtfUnicode
)
345 return SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
346 (WPARAM
) nmhdr
->idFrom
, (LPARAM
)nmhdr
);
348 return SendMessageA (infoPtr
->hwndNotify
, WM_NOTIFY
,
349 (WPARAM
) nmhdr
->idFrom
, (LPARAM
)nmhdr
);
352 /***********************************************************************
353 * TOOLBAR_GetBitmapIndex
355 * This function returns the bitmap index associated with a button.
356 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
357 * is issued to retrieve the index.
360 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
)
362 INT ret
= btnPtr
->iBitmap
;
364 if (ret
== I_IMAGECALLBACK
) {
365 /* issue TBN_GETDISPINFO */
368 nmgd
.idCommand
= btnPtr
->idCommand
;
369 nmgd
.lParam
= btnPtr
->dwData
;
370 nmgd
.dwMask
= TBNF_IMAGE
;
371 TOOLBAR_SendNotify ((NMHDR
*) &nmgd
, infoPtr
,
372 (infoPtr
->bNtfUnicode
) ? TBN_GETDISPINFOW
:
374 if (nmgd
.dwMask
& TBNF_DI_SETITEM
) {
375 btnPtr
->iBitmap
= nmgd
.iImage
;
378 TRACE("TBN_GETDISPINFOA returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
379 ret
, nmgd
.dwMask
, infoPtr
->nNumBitmaps
);
382 if (ret
!= I_IMAGENONE
)
383 ret
= GETIBITMAP(infoPtr
, ret
);
390 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO
*infoPtr
, INT index
)
393 INT id
= GETHIMLID(infoPtr
, index
);
394 INT iBitmap
= GETIBITMAP(infoPtr
, index
);
396 if (((himl
= GETDEFIMAGELIST(infoPtr
, id
)) &&
397 iBitmap
>= 0 && iBitmap
< ImageList_GetImageCount(himl
)) ||
398 (index
== I_IMAGECALLBACK
))
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("index %d,%d is not valid, max %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");
454 /***********************************************************************
455 * TOOLBAR_TestImageExist
457 * This function is similar to TOOLBAR_GetImageListForDrawing, except it does not
458 * return the image list. The I_IMAGECALLBACK functionality is implemented.
461 TOOLBAR_TestImageExist (TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, HIMAGELIST himl
)
465 if (!himl
) return FALSE
;
467 if (!TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
)) {
468 if (btnPtr
->iBitmap
== I_IMAGENONE
) return FALSE
;
469 ERR("index %d is not valid, max %d\n",
470 btnPtr
->iBitmap
, infoPtr
->nNumBitmaps
);
474 if ((index
= TOOLBAR_GetBitmapIndex(infoPtr
, btnPtr
)) < 0) {
475 if ((index
== I_IMAGECALLBACK
) ||
476 (index
== I_IMAGENONE
)) return FALSE
;
477 ERR("TBN_GETDISPINFO returned invalid index %d\n",
486 TOOLBAR_DrawFlatSeparator (LPRECT lpRect
, HDC hdc
, TOOLBAR_INFO
*infoPtr
)
489 COLORREF oldcolor
, newcolor
;
491 myrect
.left
= (lpRect
->left
+ lpRect
->right
) / 2 - 1;
492 myrect
.right
= myrect
.left
+ 1;
493 myrect
.top
= lpRect
->top
+ 2;
494 myrect
.bottom
= lpRect
->bottom
- 2;
496 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
497 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
498 oldcolor
= SetBkColor (hdc
, newcolor
);
499 ExtTextOutA (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
501 myrect
.left
= myrect
.right
;
502 myrect
.right
= myrect
.left
+ 1;
504 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
505 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
506 SetBkColor (hdc
, newcolor
);
507 ExtTextOutA (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
509 SetBkColor (hdc
, oldcolor
);
513 /***********************************************************************
514 * TOOLBAR_DrawDDFlatSeparator
516 * This function draws the separator that was flagged as BTNS_DROPDOWN.
517 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
518 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
519 * are horizontal as opposed to the vertical separators for not dropdown
522 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
525 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect
, HDC hdc
, TBUTTON_INFO
*btnPtr
, TOOLBAR_INFO
*infoPtr
)
528 COLORREF oldcolor
, newcolor
;
530 myrect
.left
= lpRect
->left
;
531 myrect
.right
= lpRect
->right
;
532 myrect
.top
= lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
- 2)/2;
533 myrect
.bottom
= myrect
.top
+ 1;
535 InflateRect (&myrect
, -2, 0);
537 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
538 myrect
.left
, myrect
.top
, myrect
.right
, myrect
.bottom
);
540 newcolor
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
541 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
542 oldcolor
= SetBkColor (hdc
, newcolor
);
543 ExtTextOutA (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
545 myrect
.top
= myrect
.bottom
;
546 myrect
.bottom
= myrect
.top
+ 1;
548 newcolor
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
549 comctl32_color
.clrBtnHighlight
: infoPtr
->clrBtnHighlight
;
550 SetBkColor (hdc
, newcolor
);
551 ExtTextOutA (hdc
, 0, 0, ETO_OPAQUE
, &myrect
, 0, 0, 0);
553 SetBkColor (hdc
, oldcolor
);
558 TOOLBAR_DrawArrow (HDC hdc
, INT left
, INT top
, COLORREF clr
)
563 if (!(hPen
= CreatePen( PS_SOLID
, 1, clr
))) return;
564 hOldPen
= SelectObject ( hdc
, hPen
);
567 MoveToEx (hdc
, x
, y
, NULL
);
568 LineTo (hdc
, x
+5, y
++); x
++;
569 MoveToEx (hdc
, x
, y
, NULL
);
570 LineTo (hdc
, x
+3, y
++); x
++;
571 MoveToEx (hdc
, x
, y
, NULL
);
572 LineTo (hdc
, x
+1, y
++);
573 SelectObject( hdc
, hOldPen
);
574 DeleteObject( hPen
);
578 * Draw the text string for this button.
579 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
580 * is non-zero, so we can simply check himlDef to see if we have
584 TOOLBAR_DrawString (TOOLBAR_INFO
*infoPtr
, RECT
*rcText
, LPWSTR lpText
,
585 NMTBCUSTOMDRAW
*tbcd
)
587 HDC hdc
= tbcd
->nmcd
.hdc
;
590 COLORREF clrOldBk
= 0;
592 UINT state
= tbcd
->nmcd
.uItemState
;
596 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText
),
597 rcText
->left
, rcText
->top
, rcText
->right
, rcText
->bottom
);
599 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
600 if ((state
& CDIS_HOT
) && (infoPtr
->dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)) {
601 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
603 else if (state
& CDIS_DISABLED
) {
604 clrOld
= SetTextColor (hdc
, tbcd
->clrBtnHighlight
);
605 OffsetRect (rcText
, 1, 1);
606 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
607 SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
608 OffsetRect (rcText
, -1, -1);
610 else if (state
& CDIS_INDETERMINATE
) {
611 clrOld
= SetTextColor (hdc
, comctl32_color
.clr3dShadow
);
613 else if ((state
& CDIS_MARKED
) && !(infoPtr
->dwItemCDFlag
& TBCDRF_NOMARK
)) {
614 clrOld
= SetTextColor (hdc
, tbcd
->clrTextHighlight
);
615 clrOldBk
= SetBkColor (hdc
, tbcd
->clrMark
);
616 oldBkMode
= SetBkMode (hdc
, OPAQUE
); /* FIXME: should this be in the NMTBCUSTOMDRAW structure? */
619 clrOld
= SetTextColor (hdc
, tbcd
->clrText
);
622 DrawTextW (hdc
, lpText
, -1, rcText
, infoPtr
->dwDTFlags
);
623 SetTextColor (hdc
, clrOld
);
624 if ((state
& CDIS_MARKED
) && !(infoPtr
->dwItemCDFlag
& TBCDRF_NOMARK
))
626 SetBkColor (hdc
, clrOldBk
);
627 SetBkMode (hdc
, oldBkMode
);
629 SelectObject (hdc
, hOldFont
);
635 TOOLBAR_DrawPattern (LPRECT lpRect
, NMTBCUSTOMDRAW
*tbcd
)
637 HDC hdc
= tbcd
->nmcd
.hdc
;
638 HBRUSH hbr
= SelectObject (hdc
, tbcd
->hbrMonoDither
);
641 INT cx
= lpRect
->right
- lpRect
->left
;
642 INT cy
= lpRect
->bottom
- lpRect
->top
;
643 clrTextOld
= SetTextColor(hdc
, tbcd
->clrBtnHighlight
);
644 clrBkOld
= SetBkColor(hdc
, tbcd
->clrBtnFace
);
645 PatBlt (hdc
, lpRect
->left
, lpRect
->top
, cx
, cy
, PATCOPY
);
646 SetBkColor(hdc
, clrBkOld
);
647 SetTextColor(hdc
, clrTextOld
);
648 SelectObject (hdc
, hbr
);
652 static void TOOLBAR_DrawMasked(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
,
653 HDC hdc
, INT x
, INT y
)
657 TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
662 HBITMAP hbmMask
, hbmImage
;
663 HDC hdcMask
, hdcImage
;
665 ImageList_GetIconSize(himl
, &cx
, &cy
);
667 /* Create src image */
668 hdcImage
= CreateCompatibleDC(hdc
);
669 hbmImage
= CreateBitmap(cx
, cy
, GetDeviceCaps(hdc
,PLANES
),
670 GetDeviceCaps(hdc
,BITSPIXEL
), NULL
);
671 SelectObject(hdcImage
, hbmImage
);
672 ImageList_DrawEx(himl
, index
, hdcImage
, 0, 0, cx
, cy
,
673 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_NORMAL
);
676 hdcMask
= CreateCompatibleDC(0);
677 hbmMask
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
678 SelectObject(hdcMask
, hbmMask
);
680 /* Remove the background and all white pixels */
681 SetBkColor(hdcImage
, ImageList_GetBkColor(himl
));
682 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, SRCCOPY
);
683 SetBkColor(hdcImage
, RGB(0xff, 0xff, 0xff));
684 BitBlt(hdcMask
, 0, 0, cx
, cy
, hdcImage
, 0, 0, NOTSRCERASE
);
686 /* draw the new mask 'etched' to hdc */
687 SetBkColor(hdc
, RGB(255, 255, 255));
688 SelectObject(hdc
, GetSysColorBrush(COLOR_3DHILIGHT
));
689 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
690 BitBlt(hdc
, x
+ 1, y
+ 1, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
691 SelectObject(hdc
, GetSysColorBrush(COLOR_3DSHADOW
));
692 BitBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, 0, 0, 0xE20746);
695 DeleteObject(hbmImage
);
697 DeleteObject (hbmMask
);
704 TOOLBAR_TranslateState(TBUTTON_INFO
*btnPtr
)
708 retstate
|= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? CDIS_CHECKED
: 0;
709 retstate
|= (btnPtr
->fsState
& TBSTATE_PRESSED
) ? CDIS_SELECTED
: 0;
710 retstate
|= (btnPtr
->fsState
& TBSTATE_ENABLED
) ? 0 : CDIS_DISABLED
;
711 retstate
|= (btnPtr
->fsState
& TBSTATE_MARKED
) ? CDIS_MARKED
: 0;
712 retstate
|= (btnPtr
->bHot
) ? CDIS_HOT
: 0;
713 retstate
|= (btnPtr
->fsState
& TBSTATE_INDETERMINATE
) ? CDIS_INDETERMINATE
: 0;
714 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
718 /* draws the image on a toolbar button */
720 TOOLBAR_DrawImage(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
, INT left
, INT top
, const NMTBCUSTOMDRAW
*tbcd
)
722 HIMAGELIST himl
= NULL
;
723 BOOL draw_masked
= FALSE
;
726 UINT draw_flags
= ILD_NORMAL
;
728 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
730 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DISABLED
, &index
);
734 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && (GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & TBSTYLE_FLAT
))
736 /* if hot, attempt to draw with hot image list, if fails,
737 use default image list */
738 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_HOT
, &index
);
740 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
743 himl
= TOOLBAR_GetImageListForDrawing(infoPtr
, btnPtr
, IMAGE_LIST_DEFAULT
, &index
);
745 if (!(infoPtr
->dwItemCDFlag
& TBCDRF_NOOFFSET
) &&
746 (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
)))
749 if (!(infoPtr
->dwItemCDFlag
& TBCDRF_NOMARK
) &&
750 (tbcd
->nmcd
.uItemState
& CDIS_MARKED
))
751 draw_flags
|= ILD_BLEND50
;
753 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
754 index
, himl
, left
, top
, offset
);
757 TOOLBAR_DrawMasked (infoPtr
, btnPtr
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
);
759 ImageList_Draw (himl
, index
, tbcd
->nmcd
.hdc
, left
+ offset
, top
+ offset
, draw_flags
);
762 /* draws a blank frame for a toolbar button */
764 TOOLBAR_DrawFrame(const TOOLBAR_INFO
*infoPtr
, BOOL flat
, const NMTBCUSTOMDRAW
*tbcd
)
766 HDC hdc
= tbcd
->nmcd
.hdc
;
767 RECT rc
= tbcd
->nmcd
.rc
;
768 /* if the state is disabled or indeterminate then the button
769 * cannot have an interactive look like pressed or hot */
770 BOOL non_interactive_state
= (tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) ||
771 (tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
);
772 BOOL pressed_look
= !non_interactive_state
&&
773 ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) ||
774 (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
));
776 /* app don't want us to draw any edges */
777 if (infoPtr
->dwItemCDFlag
& TBCDRF_NOEDGES
)
783 DrawEdge (hdc
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
784 else if ((tbcd
->nmcd
.uItemState
& CDIS_HOT
) && !non_interactive_state
)
785 DrawEdge (hdc
, &rc
, BDR_RAISEDINNER
, BF_RECT
);
790 DrawEdge (hdc
, &rc
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
);
792 DrawEdge (hdc
, &rc
, EDGE_RAISED
,
793 BF_SOFT
| BF_RECT
| BF_MIDDLE
);
798 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO
*infoPtr
, BOOL flat
, const NMTBCUSTOMDRAW
*tbcd
, RECT
*rcArrow
)
800 HDC hdc
= tbcd
->nmcd
.hdc
;
805 if ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) || (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
))
806 DrawEdge (hdc
, rcArrow
, BDR_SUNKENOUTER
, BF_RECT
| BF_ADJUST
);
807 else if ( (tbcd
->nmcd
.uItemState
& CDIS_HOT
) &&
808 !(tbcd
->nmcd
.uItemState
& CDIS_DISABLED
) &&
809 !(tbcd
->nmcd
.uItemState
& CDIS_INDETERMINATE
))
810 DrawEdge (hdc
, rcArrow
, BDR_RAISEDINNER
, BF_RECT
);
814 if ((tbcd
->nmcd
.uItemState
& CDIS_SELECTED
) || (tbcd
->nmcd
.uItemState
& CDIS_CHECKED
))
815 DrawEdge (hdc
, rcArrow
, EDGE_SUNKEN
, BF_RECT
| BF_MIDDLE
| BF_ADJUST
);
817 DrawEdge (hdc
, rcArrow
, EDGE_RAISED
,
818 BF_SOFT
| BF_RECT
| BF_MIDDLE
| BF_ADJUST
);
821 if (tbcd
->nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
822 offset
= (infoPtr
->dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
824 if (tbcd
->nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
826 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+1, rcArrow
->top
+1 + (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
827 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
, rcArrow
->top
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
830 TOOLBAR_DrawArrow(hdc
, rcArrow
->left
+ offset
, rcArrow
->top
+ offset
+ (rcArrow
->bottom
- rcArrow
->top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
833 /* draws a complete toolbar button */
835 TOOLBAR_DrawButton (HWND hwnd
, TBUTTON_INFO
*btnPtr
, HDC hdc
)
837 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
838 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
839 BOOL hasDropDownArrow
= (TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) &&
840 (btnPtr
->fsStyle
& BTNS_DROPDOWN
)) ||
841 (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
842 BOOL drawSepDropDownArrow
= hasDropDownArrow
&&
843 (~btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
);
844 RECT rc
, rcArrow
, rcBitmap
, rcText
;
845 LPWSTR lpText
= NULL
;
851 CopyRect (&rcArrow
, &rc
);
852 CopyRect(&rcBitmap
, &rc
);
854 /* get a pointer to the text */
855 lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
857 if (hasDropDownArrow
)
861 if (dwStyle
& TBSTYLE_FLAT
)
862 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
);
864 right
= max(rc
.left
, rc
.right
- DDARROW_WIDTH
- 2);
866 if (drawSepDropDownArrow
)
869 rcArrow
.left
= right
;
872 /* copy text rect after adjusting for drop-down arrow
873 * so that text is centred in the rectangle not containing
875 CopyRect(&rcText
, &rc
);
877 /* Center the bitmap horizontally and vertically */
878 if (dwStyle
& TBSTYLE_LIST
)
879 rcBitmap
.left
+= GetSystemMetrics(SM_CXEDGE
) + OFFSET_X
;
881 rcBitmap
.left
+=(infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2;
884 rcBitmap
.top
+= GetSystemMetrics(SM_CYEDGE
) + OFFSET_Y
;
886 rcBitmap
.top
+=(infoPtr
->nButtonHeight
- infoPtr
->nBitmapHeight
) / 2;
888 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n",
889 btnPtr
->iBitmap
, rcBitmap
.left
, rcBitmap
.top
,
890 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
891 TRACE ("iString: %x\n", btnPtr
->iString
);
892 TRACE ("Stringtext: %s\n", debugstr_w(lpText
));
896 rcText
.left
+= GetSystemMetrics(SM_CXEDGE
) + OFFSET_X
;
897 rcText
.right
-= GetSystemMetrics(SM_CXEDGE
) + OFFSET_X
;
898 if (GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,btnPtr
->iBitmap
)) &&
899 TOOLBAR_IsValidBitmapIndex(infoPtr
,btnPtr
->iBitmap
))
901 if (dwStyle
& TBSTYLE_LIST
)
902 rcText
.left
+= infoPtr
->nBitmapWidth
+ TOOLBAR_GetListTextOffset(infoPtr
, infoPtr
->iListGap
);
904 rcText
.top
+= GetSystemMetrics(SM_CYEDGE
) + OFFSET_Y
+ infoPtr
->nBitmapHeight
+ infoPtr
->szPadding
.cy
/2;
907 if (dwStyle
& TBSTYLE_LIST
)
908 rcText
.left
+= LIST_IMAGE_ABSENT_WIDTH
+ TOOLBAR_GetListTextOffset(infoPtr
, infoPtr
->iListGap
);
910 if (btnPtr
->fsState
& (TBSTATE_PRESSED
| TBSTATE_CHECKED
))
911 OffsetRect (&rcText
, 1, 1);
914 /* Initialize fields in all cases, because we use these later
915 * NOTE: applications can and do alter these to customize their
917 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
918 tbcd
.clrText
= comctl32_color
.clrBtnText
;
919 tbcd
.clrTextHighlight
= comctl32_color
.clrHighlightText
;
920 tbcd
.clrBtnFace
= comctl32_color
.clrBtnFace
;
921 tbcd
.clrBtnHighlight
= comctl32_color
.clrBtnHighlight
;
922 tbcd
.clrMark
= comctl32_color
.clrHighlight
;
923 tbcd
.clrHighlightHotTrack
= 0;
924 tbcd
.nStringBkMode
= (infoPtr
->bBtnTranspnt
) ? TRANSPARENT
: OPAQUE
;
925 tbcd
.nHLStringBkMode
= (infoPtr
->bBtnTranspnt
) ? TRANSPARENT
: OPAQUE
;
926 /* MSDN says that this is the text rectangle.
927 * But (why always a but) tracing of v5.7 of native shows
928 * that this is really a *relative* rectangle based on the
929 * the nmcd.rc. Also the left and top are always 0 ignoring
930 * any bitmap that might be present. */
931 tbcd
.rcText
.left
= 0;
933 tbcd
.rcText
.right
= rcText
.right
- rc
.left
;
934 tbcd
.rcText
.bottom
= rcText
.bottom
- rc
.top
;
935 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
938 tbcd
.hbrMonoDither
= COMCTL32_hPattern55AABrush
;
940 /* FIXME: what are these used for? */
944 /* Issue Item Prepaint notify */
945 infoPtr
->dwItemCustDraw
= 0;
946 infoPtr
->dwItemCDFlag
= 0;
947 if (infoPtr
->dwBaseCustDraw
& CDRF_NOTIFYITEMDRAW
)
949 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPREPAINT
;
950 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
951 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
952 ntfret
= TOOLBAR_SendNotify ((NMHDR
*)&tbcd
, infoPtr
, NM_CUSTOMDRAW
);
953 /* reset these fields so the user can't alter the behaviour like native */
957 infoPtr
->dwItemCustDraw
= ntfret
& 0xffff;
958 infoPtr
->dwItemCDFlag
= ntfret
& 0xffff0000;
959 if (infoPtr
->dwItemCustDraw
& CDRF_SKIPDEFAULT
)
961 /* save the only part of the rect that the user can change */
962 rcText
.right
= tbcd
.rcText
.right
+ rc
.left
;
963 rcText
.bottom
= tbcd
.rcText
.bottom
+ rc
.top
;
967 if (btnPtr
->fsStyle
& BTNS_SEP
) {
968 /* with the FLAT style, iBitmap is the width and has already */
969 /* been taken into consideration in calculating the width */
970 /* so now we need to draw the vertical separator */
971 /* empirical tests show that iBitmap can/will be non-zero */
972 /* when drawing the vertical bar... */
973 if ((dwStyle
& TBSTYLE_FLAT
) /* && (btnPtr->iBitmap == 0) */) {
974 if (btnPtr
->fsStyle
& BTNS_DROPDOWN
)
975 TOOLBAR_DrawDDFlatSeparator (&rc
, hdc
, btnPtr
, infoPtr
);
977 TOOLBAR_DrawFlatSeparator (&rc
, hdc
, infoPtr
);
979 else if (btnPtr
->fsStyle
!= BTNS_SEP
) {
980 FIXME("Draw some kind of separator: fsStyle=%x\n",
986 if (!(tbcd
.nmcd
.uItemState
& CDIS_HOT
) &&
987 ((tbcd
.nmcd
.uItemState
& CDIS_CHECKED
) || (tbcd
.nmcd
.uItemState
& CDIS_INDETERMINATE
)))
988 TOOLBAR_DrawPattern (&rc
, &tbcd
);
990 if ((dwStyle
& TBSTYLE_FLAT
) && (tbcd
.nmcd
.uItemState
& CDIS_HOT
))
992 if ( infoPtr
->dwItemCDFlag
& TBCDRF_HILITEHOTTRACK
)
996 oldclr
= SetBkColor(hdc
, tbcd
.clrHighlightHotTrack
);
997 ExtTextOutA(hdc
, 0, 0, ETO_OPAQUE
, &rc
, NULL
, 0, 0);
998 if (hasDropDownArrow
)
999 ExtTextOutA(hdc
, 0, 0, ETO_OPAQUE
, &rcArrow
, NULL
, 0, 0);
1000 SetBkColor(hdc
, oldclr
);
1004 TOOLBAR_DrawFrame(infoPtr
, dwStyle
& TBSTYLE_FLAT
, &tbcd
);
1006 if (drawSepDropDownArrow
)
1007 TOOLBAR_DrawSepDDArrow(infoPtr
, dwStyle
& TBSTYLE_FLAT
, &tbcd
, &rcArrow
);
1009 if (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) || (btnPtr
->fsStyle
& BTNS_SHOWTEXT
))
1010 TOOLBAR_DrawString (infoPtr
, &rcText
, lpText
, &tbcd
);
1012 TOOLBAR_DrawImage(infoPtr
, btnPtr
, rcBitmap
.left
, rcBitmap
.top
, &tbcd
);
1014 if (hasDropDownArrow
&& !drawSepDropDownArrow
)
1016 if (tbcd
.nmcd
.uItemState
& (CDIS_DISABLED
| CDIS_INDETERMINATE
))
1018 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+1, rcArrow
.top
+1 + (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnHighlight
);
1019 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clr3dShadow
);
1021 else if (tbcd
.nmcd
.uItemState
& (CDIS_SELECTED
| CDIS_CHECKED
))
1023 offset
= (infoPtr
->dwItemCDFlag
& TBCDRF_NOOFFSET
) ? 0 : 1;
1024 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
+ offset
, rcArrow
.top
+ offset
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1027 TOOLBAR_DrawArrow(hdc
, rcArrow
.left
, rcArrow
.top
+ (rcArrow
.bottom
- rcArrow
.top
- ARROW_HEIGHT
) / 2, comctl32_color
.clrBtnText
);
1031 if (infoPtr
->dwItemCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1033 tbcd
.nmcd
.dwDrawStage
= CDDS_ITEMPOSTPAINT
;
1034 tbcd
.nmcd
.hdc
= hdc
;
1036 tbcd
.nmcd
.dwItemSpec
= btnPtr
->idCommand
;
1037 tbcd
.nmcd
.uItemState
= TOOLBAR_TranslateState(btnPtr
);
1038 tbcd
.nmcd
.lItemlParam
= btnPtr
->dwData
;
1039 tbcd
.rcText
= rcText
;
1040 tbcd
.nStringBkMode
= (infoPtr
->bBtnTranspnt
) ? TRANSPARENT
: OPAQUE
;
1041 tbcd
.nHLStringBkMode
= (infoPtr
->bBtnTranspnt
) ? TRANSPARENT
: OPAQUE
;
1042 ntfret
= TOOLBAR_SendNotify ((NMHDR
*)&tbcd
, infoPtr
, NM_CUSTOMDRAW
);
1049 TOOLBAR_Refresh (HWND hwnd
, HDC hdc
, PAINTSTRUCT
* ps
)
1051 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1052 TBUTTON_INFO
*btnPtr
;
1053 INT i
, oldBKmode
= 0;
1054 RECT rcTemp
, rcClient
;
1055 NMTBCUSTOMDRAW tbcd
;
1058 /* the app has told us not to redraw the toolbar */
1059 if (!infoPtr
->bDoRedraw
)
1062 /* if imagelist belongs to the app, it can be changed
1063 by the app after setting it */
1064 if (GETDEFIMAGELIST(infoPtr
, 0) != infoPtr
->himlInt
)
1066 infoPtr
->nNumBitmaps
= 0;
1067 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
1068 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
1071 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1073 /* Send initial notify */
1074 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1075 tbcd
.nmcd
.dwDrawStage
= CDDS_PREPAINT
;
1076 tbcd
.nmcd
.hdc
= hdc
;
1077 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1078 ntfret
= TOOLBAR_SendNotify ((NMHDR
*)&tbcd
, infoPtr
, NM_CUSTOMDRAW
);
1079 infoPtr
->dwBaseCustDraw
= ntfret
& 0xffff;
1081 if (infoPtr
->bBtnTranspnt
)
1082 oldBKmode
= SetBkMode (hdc
, TRANSPARENT
);
1084 GetClientRect(hwnd
, &rcClient
);
1086 /* redraw necessary buttons */
1087 btnPtr
= infoPtr
->buttons
;
1088 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
1091 if (infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
1093 IntersectRect(&rcTemp
, &rcClient
, &btnPtr
->rect
);
1094 bDraw
= EqualRect(&rcTemp
, &btnPtr
->rect
);
1098 bDraw
&= IntersectRect(&rcTemp
, &(ps
->rcPaint
), &(btnPtr
->rect
));
1099 bDraw
= (btnPtr
->fsState
& TBSTATE_HIDDEN
) ? FALSE
: bDraw
;
1101 TOOLBAR_DrawButton (hwnd
, btnPtr
, hdc
);
1104 if (infoPtr
->bBtnTranspnt
&& (oldBKmode
!= TRANSPARENT
))
1105 SetBkMode (hdc
, oldBKmode
);
1107 if (infoPtr
->dwBaseCustDraw
& CDRF_NOTIFYPOSTPAINT
)
1109 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
1110 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTPAINT
;
1111 tbcd
.nmcd
.hdc
= hdc
;
1112 tbcd
.nmcd
.rc
= ps
->rcPaint
;
1113 ntfret
= TOOLBAR_SendNotify ((NMHDR
*)&tbcd
, infoPtr
, NM_CUSTOMDRAW
);
1117 /***********************************************************************
1118 * TOOLBAR_MeasureString
1120 * This function gets the width and height of a string in pixels. This
1121 * is done first by using GetTextExtentPoint to get the basic width
1122 * and height. The DrawText is called with DT_CALCRECT to get the exact
1123 * width. The reason is because the text may have more than one "&" (or
1124 * prefix characters as M$ likes to call them). The prefix character
1125 * indicates where the underline goes, except for the string "&&" which
1126 * is reduced to a single "&". GetTextExtentPoint does not process these
1127 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1130 TOOLBAR_MeasureString(TOOLBAR_INFO
*infoPtr
, TBUTTON_INFO
*btnPtr
,
1131 HDC hdc
, LPSIZE lpSize
)
1138 if (infoPtr
->nMaxTextRows
> 0 &&
1139 !(btnPtr
->fsState
& TBSTATE_HIDDEN
) &&
1140 (!(infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1141 (btnPtr
->fsStyle
& BTNS_SHOWTEXT
)) )
1143 LPWSTR lpText
= TOOLBAR_GetText(infoPtr
, btnPtr
);
1145 if(lpText
!= NULL
) {
1146 /* first get size of all the text */
1147 GetTextExtentPoint32W (hdc
, lpText
, strlenW (lpText
), lpSize
);
1149 /* feed above size into the rectangle for DrawText */
1150 myrect
.left
= myrect
.top
= 0;
1151 myrect
.right
= lpSize
->cx
;
1152 myrect
.bottom
= lpSize
->cy
;
1154 /* Use DrawText to get true size as drawn (less pesky "&") */
1155 DrawTextW (hdc
, lpText
, -1, &myrect
, DT_VCENTER
| DT_SINGLELINE
|
1156 DT_CALCRECT
| ((btnPtr
->fsStyle
& BTNS_NOPREFIX
) ?
1159 /* feed back to caller */
1160 lpSize
->cx
= myrect
.right
;
1161 lpSize
->cy
= myrect
.bottom
;
1165 TRACE("string size %ld x %ld!\n", lpSize
->cx
, lpSize
->cy
);
1168 /***********************************************************************
1169 * TOOLBAR_CalcStrings
1171 * This function walks through each string and measures it and returns
1172 * the largest height and width to caller.
1175 TOOLBAR_CalcStrings (HWND hwnd
, LPSIZE lpSize
)
1177 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1178 TBUTTON_INFO
*btnPtr
;
1187 if(infoPtr
->nMaxTextRows
== 0)
1191 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1193 btnPtr
= infoPtr
->buttons
;
1194 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1195 if(TOOLBAR_HasText(infoPtr
, btnPtr
))
1197 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1198 if (sz
.cx
> lpSize
->cx
)
1200 if (sz
.cy
> lpSize
->cy
)
1205 SelectObject (hdc
, hOldFont
);
1206 ReleaseDC (hwnd
, hdc
);
1208 TRACE("max string size %ld x %ld!\n", lpSize
->cx
, lpSize
->cy
);
1211 /***********************************************************************
1212 * TOOLBAR_WrapToolbar
1214 * This function walks through the buttons and separators in the
1215 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1216 * wrapping should occur based on the width of the toolbar window.
1217 * It does *not* calculate button placement itself. That task
1218 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1219 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1220 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1222 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1223 * vertical toolbar lists.
1227 TOOLBAR_WrapToolbar( HWND hwnd
, DWORD dwStyle
)
1229 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1230 TBUTTON_INFO
*btnPtr
;
1233 BOOL bWrap
, bButtonWrap
;
1235 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1236 /* no layout is necessary. Applications may use this style */
1237 /* to perform their own layout on the toolbar. */
1238 if( !(dwStyle
& TBSTYLE_WRAPABLE
) &&
1239 !(infoPtr
->dwExStyle
& TBSTYLE_EX_UNDOC1
) ) return;
1241 btnPtr
= infoPtr
->buttons
;
1242 x
= infoPtr
->nIndent
;
1244 /* this can get the parents width, to know how far we can extend
1245 * this toolbar. We cannot use its height, as there may be multiple
1246 * toolbars in a rebar control
1248 GetClientRect( GetParent(hwnd
), &rc
);
1249 infoPtr
->nWidth
= rc
.right
- rc
.left
;
1250 bButtonWrap
= FALSE
;
1252 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1253 infoPtr
->nButtonWidth
, infoPtr
->nBitmapWidth
, infoPtr
->nWidth
,
1256 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++ )
1259 btnPtr
[i
].fsState
&= ~TBSTATE_WRAP
;
1261 if (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
)
1264 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1265 /* it is the actual width of the separator. This is used for */
1266 /* custom controls in toolbars. */
1268 /* BTNS_DROPDOWN separators are treated as buttons for */
1269 /* width. - GA 8/01 */
1270 if ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1271 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
))
1272 cx
= (btnPtr
[i
].iBitmap
> 0) ?
1273 btnPtr
[i
].iBitmap
: SEPARATOR_WIDTH
;
1275 cx
= infoPtr
->nButtonWidth
;
1277 /* Two or more adjacent separators form a separator group. */
1278 /* The first separator in a group should be wrapped to the */
1279 /* next row if the previous wrapping is on a button. */
1281 (btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1282 (i
+ 1 < infoPtr
->nNumButtons
) &&
1283 (btnPtr
[i
+ 1].fsStyle
& BTNS_SEP
) )
1285 TRACE("wrap point 1 btn %d style %02x\n", i
, btnPtr
[i
].fsStyle
);
1286 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1287 x
= infoPtr
->nIndent
;
1289 bButtonWrap
= FALSE
;
1293 /* The layout makes sure the bitmap is visible, but not the button. */
1294 /* Test added to also wrap after a button that starts a row but */
1295 /* is bigger than the area. - GA 8/01 */
1296 if (( x
+ cx
- (infoPtr
->nButtonWidth
- infoPtr
->nBitmapWidth
) / 2
1297 > infoPtr
->nWidth
) ||
1298 ((x
== infoPtr
->nIndent
) && (cx
> infoPtr
->nWidth
)))
1300 BOOL bFound
= FALSE
;
1302 /* If the current button is a separator and not hidden, */
1303 /* go to the next until it reaches a non separator. */
1304 /* Wrap the last separator if it is before a button. */
1305 while( ( ((btnPtr
[i
].fsStyle
& BTNS_SEP
) &&
1306 !(btnPtr
[i
].fsStyle
& BTNS_DROPDOWN
)) ||
1307 (btnPtr
[i
].fsState
& TBSTATE_HIDDEN
) ) &&
1308 i
< infoPtr
->nNumButtons
)
1314 if( bFound
&& i
< infoPtr
->nNumButtons
)
1317 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1318 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1319 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1320 x
= infoPtr
->nIndent
;
1321 bButtonWrap
= FALSE
;
1324 else if ( i
>= infoPtr
->nNumButtons
)
1327 /* If the current button is not a separator, find the last */
1328 /* separator and wrap it. */
1329 for ( j
= i
- 1; j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1331 if ((btnPtr
[j
].fsStyle
& BTNS_SEP
) &&
1332 !(btnPtr
[j
].fsState
& TBSTATE_HIDDEN
))
1336 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1337 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1338 x
= infoPtr
->nIndent
;
1339 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1340 bButtonWrap
= FALSE
;
1345 /* If no separator available for wrapping, wrap one of */
1346 /* non-hidden previous button. */
1350 j
>= 0 && !(btnPtr
[j
].fsState
& TBSTATE_WRAP
); j
--)
1352 if (btnPtr
[j
].fsState
& TBSTATE_HIDDEN
)
1357 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1358 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1359 x
= infoPtr
->nIndent
;
1360 btnPtr
[j
].fsState
|= TBSTATE_WRAP
;
1366 /* If all above failed, wrap the current button. */
1369 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1370 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1371 btnPtr
[i
].fsState
|= TBSTATE_WRAP
;
1373 x
= infoPtr
->nIndent
;
1374 if (btnPtr
[i
].fsStyle
& BTNS_SEP
)
1375 bButtonWrap
= FALSE
;
1381 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1382 i
, btnPtr
[i
].fsStyle
, x
, cx
);
1389 /***********************************************************************
1390 * TOOLBAR_CalcToolbar
1392 * This function calculates button and separator placement. It first
1393 * calculates the button sizes, gets the toolbar window width and then
1394 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1395 * on. It assigns a new location to each item and sends this location to
1396 * the tooltip window if appropriate. Finally, it updates the rcBound
1397 * rect and calculates the new required toolbar window height.
1401 TOOLBAR_CalcToolbar (HWND hwnd
)
1403 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
1404 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
1405 TBUTTON_INFO
*btnPtr
;
1406 INT i
, nRows
, nSepRows
;
1410 BOOL usesBitmaps
= FALSE
;
1411 BOOL hasDropDownArrows
= TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
);
1413 TOOLBAR_CalcStrings (hwnd
, &sizeString
);
1415 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
1417 for (i
= 0; i
< infoPtr
->nNumButtons
&& !usesBitmaps
; i
++)
1419 if (TOOLBAR_IsValidBitmapIndex(infoPtr
,infoPtr
->buttons
[i
].iBitmap
))
1422 if (dwStyle
& TBSTYLE_LIST
)
1424 infoPtr
->nButtonHeight
= max((usesBitmaps
) ? infoPtr
->nBitmapHeight
:
1425 0, sizeString
.cy
) + infoPtr
->szPadding
.cy
;
1426 infoPtr
->nButtonWidth
= ((usesBitmaps
) ? infoPtr
->nBitmapWidth
:
1427 LIST_IMAGE_ABSENT_WIDTH
) + sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1428 if (sizeString
.cx
> 0)
1429 infoPtr
->nButtonWidth
+= TOOLBAR_GetListTextOffset(infoPtr
, infoPtr
->iListGap
) + infoPtr
->szPadding
.cx
/2;
1430 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1431 infoPtr
->nButtonWidth
, infoPtr
->nButtonHeight
, usesBitmaps
,
1432 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
1435 if (sizeString
.cy
> 0)
1438 infoPtr
->nButtonHeight
= sizeString
.cy
+
1439 infoPtr
->szPadding
.cy
/2 + /* this is the space to separate text from bitmap */
1440 infoPtr
->nBitmapHeight
+ infoPtr
->szPadding
.cy
;
1442 infoPtr
->nButtonHeight
= sizeString
.cy
+ infoPtr
->szPadding
.cy
;
1445 infoPtr
->nButtonHeight
= infoPtr
->nBitmapHeight
+ infoPtr
->szPadding
.cy
;
1447 if (sizeString
.cx
> infoPtr
->nBitmapWidth
)
1448 infoPtr
->nButtonWidth
= sizeString
.cx
+ infoPtr
->szPadding
.cx
;
1450 infoPtr
->nButtonWidth
= infoPtr
->nBitmapWidth
+ infoPtr
->szPadding
.cx
;
1453 if ( infoPtr
->cxMin
>= 0 && infoPtr
->nButtonWidth
< infoPtr
->cxMin
)
1454 infoPtr
->nButtonWidth
= infoPtr
->cxMin
;
1455 if ( infoPtr
->cxMax
> 0 && infoPtr
->nButtonWidth
> infoPtr
->cxMax
)
1456 infoPtr
->nButtonWidth
= infoPtr
->cxMax
;
1458 TOOLBAR_WrapToolbar( hwnd
, dwStyle
);
1460 x
= infoPtr
->nIndent
;
1463 /* from above, minimum is a button, and possible text */
1464 cx
= infoPtr
->nButtonWidth
;
1466 /* cannot use just ButtonHeight, we may have no buttons! */
1467 if (infoPtr
->nNumButtons
> 0)
1468 infoPtr
->nHeight
= infoPtr
->nButtonHeight
;
1470 cy
= infoPtr
->nHeight
;
1472 nRows
= nSepRows
= 0;
1474 infoPtr
->rcBound
.top
= y
;
1475 infoPtr
->rcBound
.left
= x
;
1476 infoPtr
->rcBound
.bottom
= y
+ cy
;
1477 infoPtr
->rcBound
.right
= x
;
1479 btnPtr
= infoPtr
->buttons
;
1481 TRACE("cy=%d\n", cy
);
1483 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++ )
1486 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1488 SetRectEmpty (&btnPtr
->rect
);
1492 cy
= infoPtr
->nHeight
;
1494 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1495 /* it is the actual width of the separator. This is used for */
1496 /* custom controls in toolbars. */
1497 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1498 if (btnPtr
->fsStyle
& BTNS_DROPDOWN
) {
1499 cy
= (btnPtr
->iBitmap
> 0) ?
1500 btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1501 cx
= infoPtr
->nButtonWidth
;
1504 cx
= (btnPtr
->iBitmap
> 0) ?
1505 btnPtr
->iBitmap
: SEPARATOR_WIDTH
;
1509 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) ||
1510 (btnPtr
->fsStyle
& BTNS_AUTOSIZE
))
1517 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
);
1519 TOOLBAR_MeasureString(infoPtr
, btnPtr
, hdc
, &sz
);
1521 SelectObject (hdc
, hOldFont
);
1522 ReleaseDC (hwnd
, hdc
);
1524 /* add space on for button frame, etc */
1525 cx
= sz
.cx
+ infoPtr
->szPadding
.cx
;
1527 /* add list padding */
1528 if ((dwStyle
& TBSTYLE_LIST
) && sz
.cx
> 0)
1529 cx
+= TOOLBAR_GetListTextOffset(infoPtr
, infoPtr
->iListGap
) + infoPtr
->szPadding
.cx
/2;
1531 if (TOOLBAR_TestImageExist (infoPtr
, btnPtr
, GETDEFIMAGELIST(infoPtr
,0)))
1533 if (dwStyle
& TBSTYLE_LIST
)
1534 cx
+= infoPtr
->nBitmapWidth
;
1535 else if (cx
< (infoPtr
->nBitmapWidth
+infoPtr
->szPadding
.cx
))
1536 cx
= infoPtr
->nBitmapWidth
+infoPtr
->szPadding
.cx
;
1538 else if (dwStyle
& TBSTYLE_LIST
)
1539 cx
+= LIST_IMAGE_ABSENT_WIDTH
;
1542 cx
= infoPtr
->nButtonWidth
;
1544 if ((hasDropDownArrows
&& (btnPtr
->fsStyle
& BTNS_DROPDOWN
)) || (btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
))
1545 cx
+= DDARROW_WIDTH
;
1547 if (btnPtr
->fsState
& TBSTATE_WRAP
)
1550 SetRect (&btnPtr
->rect
, x
, y
, x
+ cx
, y
+ cy
);
1552 if (infoPtr
->rcBound
.left
> x
)
1553 infoPtr
->rcBound
.left
= x
;
1554 if (infoPtr
->rcBound
.right
< x
+ cx
)
1555 infoPtr
->rcBound
.right
= x
+ cx
;
1556 if (infoPtr
->rcBound
.bottom
< y
+ cy
)
1557 infoPtr
->rcBound
.bottom
= y
+ cy
;
1559 /* Set the toolTip only for non-hidden, non-separator button */
1560 if (infoPtr
->hwndToolTip
&& !(btnPtr
->fsStyle
& BTNS_SEP
))
1564 ZeroMemory (&ti
, sizeof(TTTOOLINFOA
));
1565 ti
.cbSize
= sizeof(TTTOOLINFOA
);
1567 ti
.uId
= btnPtr
->idCommand
;
1568 ti
.rect
= btnPtr
->rect
;
1569 SendMessageA (infoPtr
->hwndToolTip
, TTM_NEWTOOLRECTA
,
1573 /* btnPtr->nRow is zero based. The space between the rows is */
1574 /* also considered as a row. */
1575 btnPtr
->nRow
= nRows
+ nSepRows
;
1577 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1578 i
, btnPtr
->fsStyle
, bWrap
, nRows
, nSepRows
, btnPtr
->nRow
,
1583 if ( !(btnPtr
->fsStyle
& BTNS_SEP
) )
1587 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1588 /* it is the actual width of the separator. This is used for */
1589 /* custom controls in toolbars. */
1590 if ( !(btnPtr
->fsStyle
& BTNS_DROPDOWN
))
1591 y
+= cy
+ ( (btnPtr
->iBitmap
> 0 ) ?
1592 btnPtr
->iBitmap
: SEPARATOR_WIDTH
) * 2 /3;
1596 /* nSepRows is used to calculate the extra height follwoing */
1600 x
= infoPtr
->nIndent
;
1602 /* Increment row number unless this is the last button */
1603 /* and it has Wrap set. */
1604 if (i
!= infoPtr
->nNumButtons
-1)
1611 /* infoPtr->nRows is the number of rows on the toolbar */
1612 infoPtr
->nRows
= nRows
+ nSepRows
+ 1;
1615 /********************************************************************
1616 * The following while interesting, does not match the values *
1617 * created above for the button rectangles, nor the rcBound rect. *
1618 * We will comment it out and remove it later. *
1620 * The problem showed up as heights in the pager control that was *
1622 ********************************************************************/
1624 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1626 infoPtr
->nHeight
= TOP_BORDER
+ (nRows
+ 1) * infoPtr
->nButtonHeight
+
1627 nSepRows
* (SEPARATOR_WIDTH
* 2 / 3) +
1628 nSepRows
* (infoPtr
->nBitmapHeight
+ 1) +
1632 infoPtr
->nHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
1634 TRACE("toolbar height %d, button width %d\n", infoPtr
->nHeight
, infoPtr
->nButtonWidth
);
1639 TOOLBAR_InternalHitTest (HWND hwnd
, LPPOINT lpPt
)
1641 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
1642 TBUTTON_INFO
*btnPtr
;
1645 btnPtr
= infoPtr
->buttons
;
1646 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1647 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
1650 if (btnPtr
->fsStyle
& BTNS_SEP
) {
1651 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1652 TRACE(" ON SEPARATOR %d!\n", i
);
1657 if (PtInRect (&btnPtr
->rect
, *lpPt
)) {
1658 TRACE(" ON BUTTON %d!\n", i
);
1664 TRACE(" NOWHERE!\n");
1670 TOOLBAR_GetButtonIndex (TOOLBAR_INFO
*infoPtr
, INT idCommand
, BOOL CommandIsIndex
)
1672 TBUTTON_INFO
*btnPtr
;
1675 if (CommandIsIndex
) {
1676 TRACE("command is really index command=%d\n", idCommand
);
1677 if (idCommand
>= infoPtr
->nNumButtons
) return -1;
1680 btnPtr
= infoPtr
->buttons
;
1681 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++) {
1682 if (btnPtr
->idCommand
== idCommand
) {
1683 TRACE("command=%d index=%d\n", idCommand
, i
);
1687 TRACE("no index found for command=%d\n", idCommand
);
1693 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO
*infoPtr
, INT nIndex
)
1695 TBUTTON_INFO
*btnPtr
;
1698 if ((nIndex
< 0) || (nIndex
> infoPtr
->nNumButtons
))
1701 /* check index button */
1702 btnPtr
= &infoPtr
->buttons
[nIndex
];
1703 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1704 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1708 /* check previous buttons */
1709 nRunIndex
= nIndex
- 1;
1710 while (nRunIndex
>= 0) {
1711 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1712 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1713 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1721 /* check next buttons */
1722 nRunIndex
= nIndex
+ 1;
1723 while (nRunIndex
< infoPtr
->nNumButtons
) {
1724 btnPtr
= &infoPtr
->buttons
[nRunIndex
];
1725 if ((btnPtr
->fsStyle
& BTNS_CHECKGROUP
) == BTNS_CHECKGROUP
) {
1726 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
1739 TOOLBAR_RelayEvent (HWND hwndTip
, HWND hwndMsg
, UINT uMsg
,
1740 WPARAM wParam
, LPARAM lParam
)
1746 msg
.wParam
= wParam
;
1747 msg
.lParam
= lParam
;
1748 msg
.time
= GetMessageTime ();
1749 msg
.pt
.x
= LOWORD(GetMessagePos ());
1750 msg
.pt
.y
= HIWORD(GetMessagePos ());
1752 SendMessageA (hwndTip
, TTM_RELAYEVENT
, 0, (LPARAM
)&msg
);
1756 /***********************************************************************
1757 * TOOLBAR_CustomizeDialogProc
1758 * This function implements the toolbar customization dialog.
1760 static INT_PTR CALLBACK
1761 TOOLBAR_CustomizeDialogProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1763 PCUSTDLG_INFO custInfo
= (PCUSTDLG_INFO
)GetWindowLongA (hwnd
, DWL_USER
);
1764 PCUSTOMBUTTON btnInfo
;
1766 TOOLBAR_INFO
*infoPtr
= custInfo
? custInfo
->tbInfo
: NULL
;
1771 custInfo
= (PCUSTDLG_INFO
)lParam
;
1772 SetWindowLongA (hwnd
, DWL_USER
, (DWORD
)custInfo
);
1780 infoPtr
= custInfo
->tbInfo
;
1782 /* send TBN_QUERYINSERT notification */
1783 nmtb
.iItem
= custInfo
->tbInfo
->nNumButtons
;
1785 if (!TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
, TBN_QUERYINSERT
))
1788 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
1789 nmtb
.iItem
= (int)hwnd
;
1790 /* Send TBN_INITCUSTOMIZE notification */
1791 if (TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
, TBN_INITCUSTOMIZE
) ==
1794 TRACE("TBNRF_HIDEHELP requested\n");
1795 ShowWindow(GetDlgItem(hwnd
, IDC_HELP_BTN
), SW_HIDE
);
1798 /* add items to 'toolbar buttons' list and check if removable */
1799 for (i
= 0; i
< custInfo
->tbInfo
->nNumButtons
; i
++)
1801 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
1802 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
1803 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
1804 btnInfo
->bVirtual
= FALSE
;
1805 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
1807 /* send TBN_QUERYDELETE notification */
1808 btnInfo
->bRemovable
= TOOLBAR_IsButtonRemovable(infoPtr
, i
, btnInfo
);
1810 index
= (int)SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, 0);
1811 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
1814 /* insert separator button into 'available buttons' list */
1815 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
1816 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
1817 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
1818 btnInfo
->bVirtual
= FALSE
;
1819 btnInfo
->bRemovable
= TRUE
;
1820 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
1821 index
= (int)SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
1822 SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
1824 /* insert all buttons into dsa */
1827 /* send TBN_GETBUTTONINFO notification */
1830 nmtb
.pszText
= Buffer
;
1833 /* Clear previous button's text */
1834 ZeroMemory(nmtb
.pszText
, nmtb
.cchText
* sizeof(WCHAR
));
1836 if (!TOOLBAR_GetButtonInfo(infoPtr
, &nmtb
))
1839 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
1840 nmtb
.tbButton
.fsStyle
, i
,
1841 nmtb
.tbButton
.idCommand
,
1842 nmtb
.tbButton
.iString
,
1843 nmtb
.tbButton
.iString
>= 0 ? debugstr_w(infoPtr
->strings
[nmtb
.tbButton
.iString
])
1846 /* insert button into the apropriate list */
1847 index
= TOOLBAR_GetButtonIndex (custInfo
->tbInfo
, nmtb
.tbButton
.idCommand
, FALSE
);
1850 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
1851 btnInfo
->bVirtual
= FALSE
;
1852 btnInfo
->bRemovable
= TRUE
;
1854 index
= SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, 0);
1855 SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
,
1856 LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
1860 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageA (hwnd
,
1861 IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
1864 memcpy (&btnInfo
->btn
, &nmtb
.tbButton
, sizeof(TBBUTTON
));
1865 if (!(nmtb
.tbButton
.fsStyle
& BTNS_SEP
))
1867 if (lstrlenW(nmtb
.pszText
))
1868 lstrcpyW(btnInfo
->text
, nmtb
.pszText
);
1869 else if (nmtb
.tbButton
.iString
>= 0 &&
1870 nmtb
.tbButton
.iString
< infoPtr
->nNumStrings
)
1872 lstrcpyW(btnInfo
->text
,
1873 infoPtr
->strings
[nmtb
.tbButton
.iString
]);
1878 /* select first item in the 'available' list */
1879 SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, 0, 0);
1881 /* append 'virtual' separator button to the 'toolbar buttons' list */
1882 btnInfo
= (PCUSTOMBUTTON
)Alloc(sizeof(CUSTOMBUTTON
));
1883 memset (&btnInfo
->btn
, 0, sizeof(TBBUTTON
));
1884 btnInfo
->btn
.fsStyle
= BTNS_SEP
;
1885 btnInfo
->bVirtual
= TRUE
;
1886 btnInfo
->bRemovable
= FALSE
;
1887 LoadStringW (COMCTL32_hModule
, IDS_SEPARATOR
, btnInfo
->text
, 64);
1888 index
= (int)SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_ADDSTRING
, 0, (LPARAM
)btnInfo
);
1889 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
1891 /* select last item in the 'toolbar' list */
1892 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
1893 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETTOPINDEX
, index
, 0);
1895 /* set focus and disable buttons */
1896 PostMessageA (hwnd
, WM_USER
, 0, 0);
1901 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
1902 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
1903 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), FALSE
);
1904 SetFocus (GetDlgItem (hwnd
, IDC_TOOLBARBTN_LBOX
));
1908 EndDialog(hwnd
, FALSE
);
1912 switch (LOWORD(wParam
))
1914 case IDC_TOOLBARBTN_LBOX
:
1915 if (HIWORD(wParam
) == LBN_SELCHANGE
)
1917 PCUSTOMBUTTON btnInfo
;
1922 count
= SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
1923 index
= SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
1925 /* send TBN_QUERYINSERT notification */
1927 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
1930 /* get list box item */
1931 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
1933 if (index
== (count
- 1))
1935 /* last item (virtual separator) */
1936 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
1937 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
1939 else if (index
== (count
- 2))
1941 /* second last item (last non-virtual item) */
1942 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
1943 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
1945 else if (index
== 0)
1948 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
1949 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
1953 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
1954 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
1957 EnableWindow (GetDlgItem (hwnd
,IDC_REMOVE_BTN
), btnInfo
->bRemovable
);
1961 case IDC_MOVEUP_BTN
:
1963 PCUSTOMBUTTON btnInfo
;
1967 count
= SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
1968 index
= SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
1969 TRACE("Move up: index %d\n", index
);
1971 /* send TBN_QUERYINSERT notification */
1974 if (TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
1977 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
1979 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_DELETESTRING
, index
, 0);
1980 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_INSERTSTRING
, index
-1, 0);
1981 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
-1, (LPARAM
)btnInfo
);
1982 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
-1 , 0);
1985 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), FALSE
);
1986 else if (index
>= (count
- 3))
1987 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), TRUE
);
1989 SendMessageA (custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
1990 SendMessageA (custInfo
->tbHwnd
, TB_INSERTBUTTONA
, index
-1, (LPARAM
)&(btnInfo
->btn
));
1995 case IDC_MOVEDN_BTN
: /* move down */
1997 PCUSTOMBUTTON btnInfo
;
2001 count
= SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2002 index
= SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2003 TRACE("Move up: index %d\n", index
);
2005 /* send TBN_QUERYINSERT notification */
2007 if (TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
2010 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2012 /* move button down */
2013 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_DELETESTRING
, index
, 0);
2014 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_INSERTSTRING
, index
+1, 0);
2015 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
+1, (LPARAM
)btnInfo
);
2016 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
+1 , 0);
2019 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEUP_BTN
), TRUE
);
2020 else if (index
>= (count
- 3))
2021 EnableWindow (GetDlgItem (hwnd
,IDC_MOVEDN_BTN
), FALSE
);
2023 SendMessageA (custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2024 SendMessageA (custInfo
->tbHwnd
, TB_INSERTBUTTONA
, index
+1, (LPARAM
)&(btnInfo
->btn
));
2029 case IDC_REMOVE_BTN
: /* remove button */
2031 PCUSTOMBUTTON btnInfo
;
2034 index
= SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2036 if (LB_ERR
== index
)
2039 TRACE("Remove: index %d\n", index
);
2041 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
,
2042 LB_GETITEMDATA
, index
, 0);
2044 /* send TBN_QUERYDELETE notification */
2045 if (TOOLBAR_IsButtonRemovable(infoPtr
, index
, btnInfo
))
2047 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2048 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_DELETESTRING
, index
, 0);
2049 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2051 SendMessageA (custInfo
->tbHwnd
, TB_DELETEBUTTON
, index
, 0);
2053 /* insert into 'available button' list */
2054 if (!(btnInfo
->btn
.fsStyle
& BTNS_SEP
))
2056 index
= (int)SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
, LB_ADDSTRING
, 0, 0);
2057 SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2065 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_CUSTHELP
);
2068 TOOLBAR_SendNotify(&nmtb
.hdr
, infoPtr
, TBN_RESET
);
2071 case IDOK
: /* Add button */
2076 count
= SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2077 index
= SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2078 TRACE("Add: index %d\n", index
);
2080 /* send TBN_QUERYINSERT notification */
2082 if (TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
2085 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, index
, 0);
2089 /* remove from 'available buttons' list */
2090 SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
, LB_DELETESTRING
, index
, 0);
2091 if (index
== count
-1)
2092 SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, index
-1 , 0);
2094 SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETCURSEL
, index
, 0);
2098 PCUSTOMBUTTON btnNew
;
2100 /* duplicate 'separator' button */
2101 btnNew
= (PCUSTOMBUTTON
)Alloc (sizeof(CUSTOMBUTTON
));
2102 memcpy (btnNew
, btnInfo
, sizeof(CUSTOMBUTTON
));
2106 /* insert into 'toolbar button' list */
2107 index
= SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCURSEL
, 0, 0);
2108 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_INSERTSTRING
, index
, 0);
2109 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, index
, (LPARAM
)btnInfo
);
2111 SendMessageA (custInfo
->tbHwnd
, TB_INSERTBUTTONA
, index
, (LPARAM
)&(btnInfo
->btn
));
2117 EndDialog(hwnd
, FALSE
);
2127 /* delete items from 'toolbar buttons' listbox*/
2128 count
= SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2129 for (i
= 0; i
< count
; i
++)
2131 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2133 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_SETITEMDATA
, 0, 0);
2135 SendDlgItemMessageA (hwnd
, IDC_TOOLBARBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2138 /* delete items from 'available buttons' listbox*/
2139 count
= SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETCOUNT
, 0, 0);
2140 for (i
= 0; i
< count
; i
++)
2142 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
, LB_GETITEMDATA
, i
, 0);
2144 SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
, LB_SETITEMDATA
, i
, 0);
2146 SendDlgItemMessageA (hwnd
, IDC_AVAILBTN_LBOX
, LB_RESETCONTENT
, 0, 0);
2151 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2153 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
2154 DWORD dwStyle
= GetWindowLongA (infoPtr
->hwndSelf
, GWL_STYLE
);
2159 COLORREF oldText
= 0;
2163 btnInfo
= (PCUSTOMBUTTON
)SendDlgItemMessageA (hwnd
, wParam
, LB_GETITEMDATA
, (WPARAM
)lpdis
->itemID
, 0);
2164 if (btnInfo
== NULL
)
2166 FIXME("btnInfo invalid!\n");
2170 /* set colors and select objects */
2171 oldBk
= SetBkColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlight
:comctl32_color
.clrWindow
);
2172 if (btnInfo
->bVirtual
)
2173 oldText
= SetTextColor (lpdis
->hDC
, comctl32_color
.clrGrayText
);
2175 oldText
= SetTextColor (lpdis
->hDC
, (lpdis
->itemState
& ODS_FOCUS
)?comctl32_color
.clrHighlightText
:comctl32_color
.clrWindowText
);
2176 hPen
= CreatePen( PS_SOLID
, 1,
2177 GetSysColor( (lpdis
->itemState
& ODS_SELECTED
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2178 hOldPen
= SelectObject (lpdis
->hDC
, hPen
);
2179 hOldBrush
= SelectObject (lpdis
->hDC
, GetSysColorBrush ((lpdis
->itemState
& ODS_FOCUS
)?COLOR_HIGHLIGHT
:COLOR_WINDOW
));
2181 /* fill background rectangle */
2182 Rectangle (lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
2183 lpdis
->rcItem
.right
, lpdis
->rcItem
.bottom
);
2185 /* calculate button and text rectangles */
2186 CopyRect (&rcButton
, &lpdis
->rcItem
);
2187 InflateRect (&rcButton
, -1, -1);
2188 CopyRect (&rcText
, &rcButton
);
2189 rcButton
.right
= rcButton
.left
+ custInfo
->tbInfo
->nBitmapWidth
+ 6;
2190 rcText
.left
= rcButton
.right
+ 2;
2192 /* draw focus rectangle */
2193 if (lpdis
->itemState
& ODS_FOCUS
)
2194 DrawFocusRect (lpdis
->hDC
, &lpdis
->rcItem
);
2197 if (!(dwStyle
& TBSTYLE_FLAT
))
2198 DrawEdge (lpdis
->hDC
, &rcButton
, EDGE_RAISED
, BF_RECT
|BF_MIDDLE
|BF_SOFT
);
2200 /* draw image and text */
2201 if ((btnInfo
->btn
.fsStyle
& BTNS_SEP
) == 0) {
2202 HIMAGELIST himl
= GETDEFIMAGELIST(infoPtr
, GETHIMLID(infoPtr
,
2203 btnInfo
->btn
.iBitmap
));
2204 ImageList_Draw (himl
, GETIBITMAP(infoPtr
, btnInfo
->btn
.iBitmap
),
2205 lpdis
->hDC
, rcButton
.left
+3, rcButton
.top
+3, ILD_NORMAL
);
2207 DrawTextW (lpdis
->hDC
, btnInfo
->text
, -1, &rcText
,
2208 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
2210 /* delete objects and reset colors */
2211 SelectObject (lpdis
->hDC
, hOldBrush
);
2212 SelectObject (lpdis
->hDC
, hOldPen
);
2213 SetBkColor (lpdis
->hDC
, oldBk
);
2214 SetTextColor (lpdis
->hDC
, oldText
);
2215 DeleteObject( hPen
);
2220 case WM_MEASUREITEM
:
2221 if (wParam
== IDC_AVAILBTN_LBOX
|| wParam
== IDC_TOOLBARBTN_LBOX
)
2223 MEASUREITEMSTRUCT
*lpmis
= (MEASUREITEMSTRUCT
*)lParam
;
2225 if (custInfo
&& custInfo
->tbInfo
)
2226 lpmis
->itemHeight
= custInfo
->tbInfo
->nBitmapHeight
+ 8;
2228 lpmis
->itemHeight
= 15 + 8; /* default height */
2240 /***********************************************************************
2241 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2245 TOOLBAR_AddBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2247 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2248 LPTBADDBITMAP lpAddBmp
= (LPTBADDBITMAP
)lParam
;
2249 INT nIndex
= 0, nButtons
, nCount
;
2253 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd
, wParam
, lParam
);
2257 if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2259 if ((lpAddBmp
->nID
& ~1) == IDB_STD_SMALL_COLOR
)
2261 else if ((lpAddBmp
->nID
& ~1) == IDB_VIEW_SMALL_COLOR
)
2263 else if ((lpAddBmp
->nID
& ~1) == IDB_HIST_SMALL_COLOR
)
2268 TRACE ("adding %d internal bitmaps!\n", nButtons
);
2270 /* Windows resize all the buttons to the size of a newly added standard image */
2271 if (lpAddBmp
->nID
& 1)
2274 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2275 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2277 SendMessageA (hwnd
, TB_SETBITMAPSIZE
, 0,
2278 MAKELPARAM((WORD
)24, (WORD
)24));
2279 SendMessageA (hwnd
, TB_SETBUTTONSIZE
, 0,
2280 MAKELPARAM((WORD
)31, (WORD
)30));
2285 SendMessageA (hwnd
, TB_SETBITMAPSIZE
, 0,
2286 MAKELPARAM((WORD
)16, (WORD
)16));
2287 SendMessageA (hwnd
, TB_SETBUTTONSIZE
, 0,
2288 MAKELPARAM((WORD
)22, (WORD
)22));
2291 TOOLBAR_CalcToolbar (hwnd
);
2295 nButtons
= (INT
)wParam
;
2299 TRACE ("adding %d bitmaps!\n", nButtons
);
2302 if (!infoPtr
->cimlDef
) {
2303 /* create new default image list */
2304 TRACE ("creating default image list!\n");
2306 himlDef
= ImageList_Create (infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
2307 ILC_COLORDDB
| ILC_MASK
, nButtons
, 2);
2308 TOOLBAR_InsertImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
, himlDef
, 0);
2309 infoPtr
->himlInt
= himlDef
;
2312 himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
2316 WARN("No default image list available\n");
2320 nCount
= ImageList_GetImageCount(himlDef
);
2322 /* Add bitmaps to the default image list */
2323 if (lpAddBmp
->hInst
== NULL
)
2326 HBITMAP hOldBitmapBitmap
, hOldBitmapLoad
;
2327 HDC hdcImage
, hdcBitmap
;
2329 /* copy the bitmap before adding it so that the user's bitmap
2330 * doesn't get modified.
2332 GetObjectA ((HBITMAP
)lpAddBmp
->nID
, sizeof(BITMAP
), (LPVOID
)&bmp
);
2334 hdcImage
= CreateCompatibleDC(0);
2335 hdcBitmap
= CreateCompatibleDC(0);
2337 /* create new bitmap */
2338 hbmLoad
= CreateBitmap (bmp
.bmWidth
, bmp
.bmHeight
, bmp
.bmPlanes
, bmp
.bmBitsPixel
, NULL
);
2339 hOldBitmapBitmap
= SelectObject(hdcBitmap
, (HBITMAP
)lpAddBmp
->nID
);
2340 hOldBitmapLoad
= SelectObject(hdcImage
, hbmLoad
);
2342 /* Copy the user's image */
2343 BitBlt (hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
,
2344 hdcBitmap
, 0, 0, SRCCOPY
);
2346 SelectObject (hdcImage
, hOldBitmapLoad
);
2347 SelectObject (hdcBitmap
, hOldBitmapBitmap
);
2348 DeleteDC (hdcImage
);
2349 DeleteDC (hdcBitmap
);
2351 nIndex
= ImageList_AddMasked (himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2352 DeleteObject (hbmLoad
);
2354 else if (lpAddBmp
->hInst
== HINST_COMMCTRL
)
2356 /* Add system bitmaps */
2357 switch (lpAddBmp
->nID
)
2359 case IDB_STD_SMALL_COLOR
:
2360 hbmLoad
= LoadBitmapA (COMCTL32_hModule
,
2361 MAKEINTRESOURCEA(IDB_STD_SMALL
));
2362 nIndex
= ImageList_AddMasked (himlDef
,
2363 hbmLoad
, comctl32_color
.clrBtnFace
);
2364 DeleteObject (hbmLoad
);
2367 case IDB_STD_LARGE_COLOR
:
2368 hbmLoad
= LoadBitmapA (COMCTL32_hModule
,
2369 MAKEINTRESOURCEA(IDB_STD_LARGE
));
2370 nIndex
= ImageList_AddMasked (himlDef
,
2371 hbmLoad
, comctl32_color
.clrBtnFace
);
2372 DeleteObject (hbmLoad
);
2375 case IDB_VIEW_SMALL_COLOR
:
2376 hbmLoad
= LoadBitmapA (COMCTL32_hModule
,
2377 MAKEINTRESOURCEA(IDB_VIEW_SMALL
));
2378 nIndex
= ImageList_AddMasked (himlDef
,
2379 hbmLoad
, comctl32_color
.clrBtnFace
);
2380 DeleteObject (hbmLoad
);
2383 case IDB_VIEW_LARGE_COLOR
:
2384 hbmLoad
= LoadBitmapA (COMCTL32_hModule
,
2385 MAKEINTRESOURCEA(IDB_VIEW_LARGE
));
2386 nIndex
= ImageList_AddMasked (himlDef
,
2387 hbmLoad
, comctl32_color
.clrBtnFace
);
2388 DeleteObject (hbmLoad
);
2391 case IDB_HIST_SMALL_COLOR
:
2392 hbmLoad
= LoadBitmapA (COMCTL32_hModule
,
2393 MAKEINTRESOURCEA(IDB_HIST_SMALL
));
2394 nIndex
= ImageList_AddMasked (himlDef
,
2395 hbmLoad
, comctl32_color
.clrBtnFace
);
2396 DeleteObject (hbmLoad
);
2399 case IDB_HIST_LARGE_COLOR
:
2400 hbmLoad
= LoadBitmapA (COMCTL32_hModule
,
2401 MAKEINTRESOURCEA(IDB_HIST_LARGE
));
2402 nIndex
= ImageList_AddMasked (himlDef
,
2403 hbmLoad
, comctl32_color
.clrBtnFace
);
2404 DeleteObject (hbmLoad
);
2408 nIndex
= ImageList_GetImageCount (himlDef
);
2409 ERR ("invalid imagelist!\n");
2415 hbmLoad
= LoadBitmapA (lpAddBmp
->hInst
, (LPSTR
)lpAddBmp
->nID
);
2416 nIndex
= ImageList_AddMasked (himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
2417 DeleteObject (hbmLoad
);
2420 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2422 if (infoPtr
->nNumBitmapInfos
== 0)
2424 infoPtr
->bitmaps
= Alloc(sizeof(TBITMAP_INFO
));
2428 TBITMAP_INFO
*oldBitmaps
= infoPtr
->bitmaps
;
2429 infoPtr
->bitmaps
= Alloc((infoPtr
->nNumBitmapInfos
+ 1) * sizeof(TBITMAP_INFO
));
2430 memcpy(&infoPtr
->bitmaps
[0], &oldBitmaps
[0], infoPtr
->nNumBitmapInfos
);
2433 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
].nButtons
= nButtons
;
2434 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
].hInst
= lpAddBmp
->hInst
;
2435 infoPtr
->bitmaps
[infoPtr
->nNumBitmapInfos
].nID
= lpAddBmp
->nID
;
2437 infoPtr
->nNumBitmapInfos
++;
2438 TRACE("Number of bitmap infos: %d\n", infoPtr
->nNumBitmapInfos
);
2442 INT imagecount
= ImageList_GetImageCount(himlDef
);
2444 if (infoPtr
->nNumBitmaps
+ nButtons
!= imagecount
)
2446 WARN("Desired images do not match received images : Previous image number %i Previous images in list %i added %i expecting total %i, Images in list %i\n",
2447 infoPtr
->nNumBitmaps
, nCount
, imagecount
- nCount
,
2448 infoPtr
->nNumBitmaps
+nButtons
,imagecount
);
2450 infoPtr
->nNumBitmaps
= imagecount
;
2453 infoPtr
->nNumBitmaps
+= nButtons
;
2456 InvalidateRect(hwnd
, NULL
, TRUE
);
2463 TOOLBAR_AddButtonsA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2465 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2466 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
2467 INT nOldButtons
, nNewButtons
, nAddButtons
, nCount
;
2469 TRACE("adding %d buttons!\n", wParam
);
2471 nAddButtons
= (UINT
)wParam
;
2472 nOldButtons
= infoPtr
->nNumButtons
;
2473 nNewButtons
= nOldButtons
+ nAddButtons
;
2475 if (infoPtr
->nNumButtons
== 0) {
2477 Alloc (sizeof(TBUTTON_INFO
) * nNewButtons
);
2480 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
2482 Alloc (sizeof(TBUTTON_INFO
) * nNewButtons
);
2483 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
2484 nOldButtons
* sizeof(TBUTTON_INFO
));
2488 infoPtr
->nNumButtons
= nNewButtons
;
2490 /* insert new button data */
2491 for (nCount
= 0; nCount
< nAddButtons
; nCount
++) {
2492 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nOldButtons
+nCount
];
2493 btnPtr
->iBitmap
= lpTbb
[nCount
].iBitmap
;
2494 btnPtr
->idCommand
= lpTbb
[nCount
].idCommand
;
2495 btnPtr
->fsState
= lpTbb
[nCount
].fsState
;
2496 btnPtr
->fsStyle
= lpTbb
[nCount
].fsStyle
;
2497 btnPtr
->dwData
= lpTbb
[nCount
].dwData
;
2498 if(HIWORD(lpTbb
[nCount
].iString
) && lpTbb
[nCount
].iString
!= -1)
2499 Str_SetPtrAtoW ((LPWSTR
*)&btnPtr
->iString
, (LPSTR
)lpTbb
[nCount
].iString
);
2501 btnPtr
->iString
= lpTbb
[nCount
].iString
;
2502 btnPtr
->bHot
= FALSE
;
2504 if ((infoPtr
->hwndToolTip
) && !(btnPtr
->fsStyle
& BTNS_SEP
)) {
2507 ZeroMemory (&ti
, sizeof(TTTOOLINFOA
));
2508 ti
.cbSize
= sizeof (TTTOOLINFOA
);
2510 ti
.uId
= btnPtr
->idCommand
;
2512 ti
.lpszText
= LPSTR_TEXTCALLBACKA
;
2514 SendMessageA (infoPtr
->hwndToolTip
, TTM_ADDTOOLA
,
2519 TOOLBAR_CalcToolbar (hwnd
);
2521 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
2523 InvalidateRect(hwnd
, NULL
, TRUE
);
2530 TOOLBAR_AddButtonsW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2532 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2533 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
2534 INT nOldButtons
, nNewButtons
, nAddButtons
, nCount
;
2536 TRACE("adding %d buttons!\n", wParam
);
2538 nAddButtons
= (UINT
)wParam
;
2539 nOldButtons
= infoPtr
->nNumButtons
;
2540 nNewButtons
= nOldButtons
+ nAddButtons
;
2542 if (infoPtr
->nNumButtons
== 0) {
2544 Alloc (sizeof(TBUTTON_INFO
) * nNewButtons
);
2547 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
2549 Alloc (sizeof(TBUTTON_INFO
) * nNewButtons
);
2550 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
2551 nOldButtons
* sizeof(TBUTTON_INFO
));
2555 infoPtr
->nNumButtons
= nNewButtons
;
2557 /* insert new button data */
2558 for (nCount
= 0; nCount
< nAddButtons
; nCount
++) {
2559 TBUTTON_INFO
*btnPtr
= &infoPtr
->buttons
[nOldButtons
+nCount
];
2560 btnPtr
->iBitmap
= lpTbb
[nCount
].iBitmap
;
2561 btnPtr
->idCommand
= lpTbb
[nCount
].idCommand
;
2562 btnPtr
->fsState
= lpTbb
[nCount
].fsState
;
2563 btnPtr
->fsStyle
= lpTbb
[nCount
].fsStyle
;
2564 btnPtr
->dwData
= lpTbb
[nCount
].dwData
;
2565 if(HIWORD(lpTbb
[nCount
].iString
) && lpTbb
[nCount
].iString
!= -1)
2566 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, (LPWSTR
)lpTbb
[nCount
].iString
);
2568 btnPtr
->iString
= lpTbb
[nCount
].iString
;
2569 btnPtr
->bHot
= FALSE
;
2571 if ((infoPtr
->hwndToolTip
) && !(btnPtr
->fsStyle
& BTNS_SEP
)) {
2574 ZeroMemory (&ti
, sizeof(TTTOOLINFOW
));
2575 ti
.cbSize
= sizeof (TTTOOLINFOW
);
2577 ti
.uId
= btnPtr
->idCommand
;
2579 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
2582 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
2587 TOOLBAR_CalcToolbar (hwnd
);
2589 TOOLBAR_DumpToolbar (infoPtr
, __LINE__
);
2591 InvalidateRect(hwnd
, NULL
, TRUE
);
2598 TOOLBAR_AddStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2600 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2603 if ((wParam
) && (HIWORD(lParam
) == 0)) {
2606 TRACE("adding string from resource!\n");
2608 len
= LoadStringA ((HINSTANCE
)wParam
, (UINT
)lParam
,
2611 TRACE("len=%d \"%s\"\n", len
, szString
);
2612 nIndex
= infoPtr
->nNumStrings
;
2613 if (infoPtr
->nNumStrings
== 0) {
2615 Alloc (sizeof(LPWSTR
));
2618 LPWSTR
*oldStrings
= infoPtr
->strings
;
2620 Alloc (sizeof(LPWSTR
) * (infoPtr
->nNumStrings
+ 1));
2621 memcpy (&infoPtr
->strings
[0], &oldStrings
[0],
2622 sizeof(LPWSTR
) * infoPtr
->nNumStrings
);
2626 /*Alloc zeros out the allocated memory*/
2627 Str_SetPtrAtoW (&infoPtr
->strings
[infoPtr
->nNumStrings
], szString
);
2628 infoPtr
->nNumStrings
++;
2631 LPSTR p
= (LPSTR
)lParam
;
2636 TRACE("adding string(s) from array!\n");
2638 nIndex
= infoPtr
->nNumStrings
;
2641 TRACE("len=%d \"%s\"\n", len
, p
);
2643 if (infoPtr
->nNumStrings
== 0) {
2645 Alloc (sizeof(LPWSTR
));
2648 LPWSTR
*oldStrings
= infoPtr
->strings
;
2650 Alloc (sizeof(LPWSTR
) * (infoPtr
->nNumStrings
+ 1));
2651 memcpy (&infoPtr
->strings
[0], &oldStrings
[0],
2652 sizeof(LPWSTR
) * infoPtr
->nNumStrings
);
2656 Str_SetPtrAtoW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2657 infoPtr
->nNumStrings
++;
2668 TOOLBAR_AddStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2670 #define MAX_RESOURCE_STRING_LENGTH 512
2671 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2674 if ((wParam
) && (HIWORD(lParam
) == 0)) {
2675 WCHAR szString
[MAX_RESOURCE_STRING_LENGTH
];
2677 TRACE("adding string from resource!\n");
2679 len
= LoadStringW ((HINSTANCE
)wParam
, (UINT
)lParam
,
2680 szString
, MAX_RESOURCE_STRING_LENGTH
);
2682 TRACE("len=%d %s\n", len
, debugstr_w(szString
));
2683 TRACE("First char: 0x%x\n", *szString
);
2684 if (szString
[0] == L
'|')
2686 PWSTR p
= szString
+ 1;
2688 nIndex
= infoPtr
->nNumStrings
;
2689 while (*p
!= L
'|' && *p
!= L
'\0') {
2692 if (infoPtr
->nNumStrings
== 0) {
2693 infoPtr
->strings
= Alloc (sizeof(LPWSTR
));
2697 LPWSTR
*oldStrings
= infoPtr
->strings
;
2698 infoPtr
->strings
= Alloc(sizeof(LPWSTR
) * (infoPtr
->nNumStrings
+ 1));
2699 memcpy(&infoPtr
->strings
[0], &oldStrings
[0],
2700 sizeof(LPWSTR
) * infoPtr
->nNumStrings
);
2704 np
=strchrW (p
, '|');
2712 TRACE("len=%d %s\n", len
, debugstr_w(p
));
2713 infoPtr
->strings
[infoPtr
->nNumStrings
] =
2714 Alloc (sizeof(WCHAR
)*(len
+1));
2715 lstrcpynW (infoPtr
->strings
[infoPtr
->nNumStrings
], p
, len
+1);
2716 infoPtr
->nNumStrings
++;
2723 nIndex
= infoPtr
->nNumStrings
;
2724 if (infoPtr
->nNumStrings
== 0) {
2726 Alloc (sizeof(LPWSTR
));
2729 LPWSTR
*oldStrings
= infoPtr
->strings
;
2731 Alloc (sizeof(LPWSTR
) * (infoPtr
->nNumStrings
+ 1));
2732 memcpy (&infoPtr
->strings
[0], &oldStrings
[0],
2733 sizeof(LPWSTR
) * infoPtr
->nNumStrings
);
2737 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], szString
);
2738 infoPtr
->nNumStrings
++;
2742 LPWSTR p
= (LPWSTR
)lParam
;
2747 TRACE("adding string(s) from array!\n");
2748 nIndex
= infoPtr
->nNumStrings
;
2752 TRACE("len=%d %s\n", len
, debugstr_w(p
));
2753 if (infoPtr
->nNumStrings
== 0) {
2755 Alloc (sizeof(LPWSTR
));
2758 LPWSTR
*oldStrings
= infoPtr
->strings
;
2760 Alloc (sizeof(LPWSTR
) * (infoPtr
->nNumStrings
+ 1));
2761 memcpy (&infoPtr
->strings
[0], &oldStrings
[0],
2762 sizeof(LPWSTR
) * infoPtr
->nNumStrings
);
2766 Str_SetPtrW (&infoPtr
->strings
[infoPtr
->nNumStrings
], p
);
2767 infoPtr
->nNumStrings
++;
2778 TOOLBAR_AutoSize (HWND hwnd
)
2780 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2781 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
2787 UINT uPosFlags
= SWP_NOZORDER
;
2789 TRACE("resize forced, style=%lx!\n", dwStyle
);
2791 parent
= GetParent (hwnd
);
2792 GetClientRect(parent
, &parent_rect
);
2794 x
= parent_rect
.left
;
2795 y
= parent_rect
.top
;
2797 /* FIXME: we should be able to early out if nothing */
2798 /* has changed with nWidth != parent_rect width */
2800 if (dwStyle
& CCS_NORESIZE
) {
2801 uPosFlags
|= (SWP_NOSIZE
| SWP_NOMOVE
);
2804 TOOLBAR_CalcToolbar (hwnd
);
2807 infoPtr
->nWidth
= parent_rect
.right
- parent_rect
.left
;
2808 TOOLBAR_CalcToolbar (hwnd
);
2809 InvalidateRect( hwnd
, NULL
, TRUE
);
2810 cy
= infoPtr
->nHeight
;
2811 cx
= infoPtr
->nWidth
;
2813 if ((dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
) {
2814 GetWindowRect(hwnd
, &window_rect
);
2815 ScreenToClient(parent
, (LPPOINT
)&window_rect
.left
);
2816 y
= window_rect
.top
;
2818 if ((dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
) {
2819 GetWindowRect(hwnd
, &window_rect
);
2820 y
= parent_rect
.bottom
- ( window_rect
.bottom
- window_rect
.top
);
2824 if (dwStyle
& CCS_NOPARENTALIGN
)
2825 uPosFlags
|= SWP_NOMOVE
;
2827 if (!(dwStyle
& CCS_NODIVIDER
))
2828 cy
+= GetSystemMetrics(SM_CYEDGE
);
2830 if (dwStyle
& WS_BORDER
)
2833 cy
+= GetSystemMetrics(SM_CYEDGE
);
2834 cx
+= GetSystemMetrics(SM_CYEDGE
);
2837 infoPtr
->bAutoSize
= TRUE
;
2838 SetWindowPos (hwnd
, HWND_TOP
, x
, y
, cx
, cy
, uPosFlags
);
2839 /* The following line makes sure that the infoPtr->bAutoSize is turned off
2840 * after the setwindowpos calls */
2841 infoPtr
->bAutoSize
= FALSE
;
2848 TOOLBAR_ButtonCount (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2850 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2852 return infoPtr
->nNumButtons
;
2857 TOOLBAR_ButtonStructSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2859 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2861 if (infoPtr
== NULL
) {
2862 ERR("(%p, 0x%x, 0x%lx)\n", hwnd
, wParam
, lParam
);
2863 ERR("infoPtr == NULL!\n");
2867 infoPtr
->dwStructSize
= (DWORD
)wParam
;
2874 TOOLBAR_ChangeBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2876 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2877 TBUTTON_INFO
*btnPtr
;
2880 TRACE("button %d, iBitmap now %d\n", wParam
, LOWORD(lParam
));
2882 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
2886 btnPtr
= &infoPtr
->buttons
[nIndex
];
2887 btnPtr
->iBitmap
= LOWORD(lParam
);
2889 /* we HAVE to erase the background, the new bitmap could be */
2891 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
2898 TOOLBAR_CheckButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2900 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2901 TBUTTON_INFO
*btnPtr
;
2904 BOOL bChecked
= FALSE
;
2906 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
2908 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd
, nIndex
, lParam
);
2913 btnPtr
= &infoPtr
->buttons
[nIndex
];
2915 bChecked
= (btnPtr
->fsState
& TBSTATE_CHECKED
) ? TRUE
: FALSE
;
2917 if (LOWORD(lParam
) == FALSE
)
2918 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
2920 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
2922 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
, nIndex
);
2923 if (nOldIndex
== nIndex
)
2925 if (nOldIndex
!= -1)
2926 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
2928 btnPtr
->fsState
|= TBSTATE_CHECKED
;
2931 if( bChecked
!= LOWORD(lParam
) )
2933 if (nOldIndex
!= -1)
2934 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
2935 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
2938 /* FIXME: Send a WM_NOTIFY?? */
2945 TOOLBAR_CommandToIndex (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2947 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2949 return TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
2954 TOOLBAR_Customize (HWND hwnd
)
2956 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2957 CUSTDLG_INFO custInfo
;
2963 custInfo
.tbInfo
= infoPtr
;
2964 custInfo
.tbHwnd
= hwnd
;
2966 /* send TBN_BEGINADJUST notification */
2967 TOOLBAR_SendNotify ((NMHDR
*) &nmhdr
, infoPtr
,
2970 if (!(hRes
= FindResourceA (COMCTL32_hModule
,
2971 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE
),
2975 if(!(template = (LPVOID
)LoadResource (COMCTL32_hModule
, hRes
)))
2978 ret
= DialogBoxIndirectParamA ((HINSTANCE
)GetWindowLongA(hwnd
, GWL_HINSTANCE
),
2979 (LPDLGTEMPLATEA
)template,
2981 TOOLBAR_CustomizeDialogProc
,
2984 /* send TBN_ENDADJUST notification */
2985 TOOLBAR_SendNotify ((NMHDR
*) &nmhdr
, infoPtr
,
2993 TOOLBAR_DeleteButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
2995 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
2996 INT nIndex
= (INT
)wParam
;
2998 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3001 if ((infoPtr
->hwndToolTip
) &&
3002 !(infoPtr
->buttons
[nIndex
].fsStyle
& BTNS_SEP
)) {
3005 ZeroMemory (&ti
, sizeof(TTTOOLINFOA
));
3006 ti
.cbSize
= sizeof (TTTOOLINFOA
);
3008 ti
.uId
= infoPtr
->buttons
[nIndex
].idCommand
;
3010 SendMessageA (infoPtr
->hwndToolTip
, TTM_DELTOOLA
, 0, (LPARAM
)&ti
);
3013 if (infoPtr
->nNumButtons
== 1) {
3014 TRACE(" simple delete!\n");
3015 Free (infoPtr
->buttons
);
3016 infoPtr
->buttons
= NULL
;
3017 infoPtr
->nNumButtons
= 0;
3020 TBUTTON_INFO
*oldButtons
= infoPtr
->buttons
;
3021 TRACE("complex delete! [nIndex=%d]\n", nIndex
);
3023 infoPtr
->nNumButtons
--;
3024 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3026 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3027 nIndex
* sizeof(TBUTTON_INFO
));
3030 if (nIndex
< infoPtr
->nNumButtons
) {
3031 memcpy (&infoPtr
->buttons
[nIndex
], &oldButtons
[nIndex
+1],
3032 (infoPtr
->nNumButtons
- nIndex
) * sizeof(TBUTTON_INFO
));
3038 TOOLBAR_CalcToolbar (hwnd
);
3040 InvalidateRect (hwnd
, NULL
, TRUE
);
3047 TOOLBAR_EnableButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3049 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3050 TBUTTON_INFO
*btnPtr
;
3054 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3056 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd
, wParam
, lParam
);
3061 btnPtr
= &infoPtr
->buttons
[nIndex
];
3063 bState
= btnPtr
->fsState
& TBSTATE_ENABLED
;
3065 /* update the toolbar button state */
3066 if(LOWORD(lParam
) == FALSE
) {
3067 btnPtr
->fsState
&= ~(TBSTATE_ENABLED
| TBSTATE_PRESSED
);
3069 btnPtr
->fsState
|= TBSTATE_ENABLED
;
3072 /* redraw the button only if the state of the button changed */
3073 if(bState
!= (btnPtr
->fsState
& TBSTATE_ENABLED
))
3074 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3080 static inline LRESULT
3081 TOOLBAR_GetAnchorHighlight (HWND hwnd
)
3083 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3085 return infoPtr
->bAnchor
;
3090 TOOLBAR_GetBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3092 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3095 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3099 return infoPtr
->buttons
[nIndex
].iBitmap
;
3103 static inline LRESULT
3104 TOOLBAR_GetBitmapFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3106 return (GetDeviceCaps (0, LOGPIXELSX
) >= 120) ? TBBF_LARGE
: 0;
3111 TOOLBAR_GetButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3113 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3114 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3115 INT nIndex
= (INT
)wParam
;
3116 TBUTTON_INFO
*btnPtr
;
3118 if (infoPtr
== NULL
)
3124 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3127 btnPtr
= &infoPtr
->buttons
[nIndex
];
3128 lpTbb
->iBitmap
= btnPtr
->iBitmap
;
3129 lpTbb
->idCommand
= btnPtr
->idCommand
;
3130 lpTbb
->fsState
= btnPtr
->fsState
;
3131 lpTbb
->fsStyle
= btnPtr
->fsStyle
;
3132 lpTbb
->bReserved
[0] = 0;
3133 lpTbb
->bReserved
[1] = 0;
3134 lpTbb
->dwData
= btnPtr
->dwData
;
3135 lpTbb
->iString
= btnPtr
->iString
;
3142 TOOLBAR_GetButtonInfoA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3144 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3145 LPTBBUTTONINFOA lpTbInfo
= (LPTBBUTTONINFOA
)lParam
;
3146 TBUTTON_INFO
*btnPtr
;
3149 if (infoPtr
== NULL
)
3151 if (lpTbInfo
== NULL
)
3153 if (lpTbInfo
->cbSize
< sizeof(TBBUTTONINFOA
))
3156 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
3157 lpTbInfo
->dwMask
& 0x80000000);
3161 if (!(btnPtr
= &infoPtr
->buttons
[nIndex
])) return -1;
3163 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3164 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3165 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3166 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3167 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3168 lpTbInfo
->lParam
= btnPtr
->dwData
;
3169 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3170 lpTbInfo
->cx
= (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3171 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3172 lpTbInfo
->fsState
= btnPtr
->fsState
;
3173 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3174 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3175 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3176 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3177 can't use TOOLBAR_GetText here */
3179 if (HIWORD(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3180 lpText
= (LPWSTR
)btnPtr
->iString
;
3181 Str_GetPtrWtoA (lpText
, lpTbInfo
->pszText
,lpTbInfo
->cchText
);
3183 lpTbInfo
->pszText
[0] = '\0';
3190 TOOLBAR_GetButtonInfoW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3192 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3193 LPTBBUTTONINFOW lpTbInfo
= (LPTBBUTTONINFOW
)lParam
;
3194 TBUTTON_INFO
*btnPtr
;
3197 if (infoPtr
== NULL
)
3199 if (lpTbInfo
== NULL
)
3201 if (lpTbInfo
->cbSize
< sizeof(TBBUTTONINFOW
))
3204 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
3205 lpTbInfo
->dwMask
& 0x80000000);
3209 btnPtr
= &infoPtr
->buttons
[nIndex
];
3214 if (lpTbInfo
->dwMask
& TBIF_COMMAND
)
3215 lpTbInfo
->idCommand
= btnPtr
->idCommand
;
3216 if (lpTbInfo
->dwMask
& TBIF_IMAGE
)
3217 lpTbInfo
->iImage
= btnPtr
->iBitmap
;
3218 if (lpTbInfo
->dwMask
& TBIF_LPARAM
)
3219 lpTbInfo
->lParam
= btnPtr
->dwData
;
3220 if (lpTbInfo
->dwMask
& TBIF_SIZE
)
3221 lpTbInfo
->cx
= (WORD
)(btnPtr
->rect
.right
- btnPtr
->rect
.left
);
3222 if (lpTbInfo
->dwMask
& TBIF_STATE
)
3223 lpTbInfo
->fsState
= btnPtr
->fsState
;
3224 if (lpTbInfo
->dwMask
& TBIF_STYLE
)
3225 lpTbInfo
->fsStyle
= btnPtr
->fsStyle
;
3226 if (lpTbInfo
->dwMask
& TBIF_TEXT
) {
3227 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3228 can't use TOOLBAR_GetText here */
3230 if (HIWORD(btnPtr
->iString
) && (btnPtr
->iString
!= -1)) {
3231 lpText
= (LPWSTR
)btnPtr
->iString
;
3232 Str_GetPtrW (lpText
,lpTbInfo
->pszText
,lpTbInfo
->cchText
);
3234 lpTbInfo
->pszText
[0] = '\0';
3242 TOOLBAR_GetButtonSize (HWND hwnd
)
3244 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3246 if (infoPtr
->nNumButtons
> 0)
3247 return MAKELONG((WORD
)infoPtr
->nButtonWidth
,
3248 (WORD
)infoPtr
->nButtonHeight
);
3250 return MAKELONG(8,7);
3255 TOOLBAR_GetButtonTextA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3257 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3264 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3268 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3270 return WideCharToMultiByte( CP_ACP
, 0, lpText
, -1,
3271 (LPSTR
)lParam
, 0x7fffffff, NULL
, NULL
) - 1;
3276 TOOLBAR_GetButtonTextW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3278 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3285 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3289 lpText
= TOOLBAR_GetText(infoPtr
,&infoPtr
->buttons
[nIndex
]);
3291 strcpyW ((LPWSTR
)lParam
, lpText
);
3293 return strlenW (lpText
);
3298 TOOLBAR_GetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3300 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3301 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3302 return (LRESULT
)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3306 inline static LRESULT
3307 TOOLBAR_GetExtendedStyle (HWND hwnd
)
3309 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3313 return infoPtr
->dwExStyle
;
3318 TOOLBAR_GetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3320 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3321 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3322 return (LRESULT
)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd
), wParam
);
3327 TOOLBAR_GetHotItem (HWND hwnd
)
3329 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3331 if (!(GetWindowLongA (hwnd
, GWL_STYLE
) & TBSTYLE_FLAT
))
3334 if (infoPtr
->nHotItem
< 0)
3337 return (LRESULT
)infoPtr
->nHotItem
;
3342 TOOLBAR_GetDefImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3344 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd
, wParam
, lParam
);
3345 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3346 return (LRESULT
) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd
), wParam
);
3350 /* << TOOLBAR_GetInsertMark >> */
3351 /* << TOOLBAR_GetInsertMarkColor >> */
3355 TOOLBAR_GetItemRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3357 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3358 TBUTTON_INFO
*btnPtr
;
3362 if (infoPtr
== NULL
)
3364 nIndex
= (INT
)wParam
;
3365 btnPtr
= &infoPtr
->buttons
[nIndex
];
3366 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3368 lpRect
= (LPRECT
)lParam
;
3371 if (btnPtr
->fsState
& TBSTATE_HIDDEN
)
3374 lpRect
->left
= btnPtr
->rect
.left
;
3375 lpRect
->right
= btnPtr
->rect
.right
;
3376 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3377 lpRect
->top
= btnPtr
->rect
.top
;
3384 TOOLBAR_GetMaxSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3386 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3387 LPSIZE lpSize
= (LPSIZE
)lParam
;
3392 lpSize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
3393 lpSize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
3395 TRACE("maximum size %ld x %ld\n",
3396 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
,
3397 infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
);
3403 /* << TOOLBAR_GetObject >> */
3407 TOOLBAR_GetPadding (HWND hwnd
)
3409 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3412 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
3413 return (LRESULT
) oldPad
;
3418 TOOLBAR_GetRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3420 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3421 TBUTTON_INFO
*btnPtr
;
3425 if (infoPtr
== NULL
)
3427 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3428 btnPtr
= &infoPtr
->buttons
[nIndex
];
3429 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
3431 lpRect
= (LPRECT
)lParam
;
3435 lpRect
->left
= btnPtr
->rect
.left
;
3436 lpRect
->right
= btnPtr
->rect
.right
;
3437 lpRect
->bottom
= btnPtr
->rect
.bottom
;
3438 lpRect
->top
= btnPtr
->rect
.top
;
3445 TOOLBAR_GetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3447 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3449 if (GetWindowLongA (hwnd
, GWL_STYLE
) & TBSTYLE_WRAPABLE
)
3450 return infoPtr
->nRows
;
3457 TOOLBAR_GetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3459 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3462 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3466 return infoPtr
->buttons
[nIndex
].fsState
;
3471 TOOLBAR_GetStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3473 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3476 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3480 return infoPtr
->buttons
[nIndex
].fsStyle
;
3485 TOOLBAR_GetTextRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3487 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3489 if (infoPtr
== NULL
)
3492 return infoPtr
->nMaxTextRows
;
3497 TOOLBAR_GetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3499 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3501 if (infoPtr
== NULL
)
3503 return (LRESULT
)infoPtr
->hwndToolTip
;
3508 TOOLBAR_GetUnicodeFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3510 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3512 TRACE("%s hwnd=%p stub!\n",
3513 infoPtr
->bUnicode
? "TRUE" : "FALSE", hwnd
);
3515 return infoPtr
->bUnicode
;
3519 inline static LRESULT
3520 TOOLBAR_GetVersion (HWND hwnd
)
3522 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3523 return infoPtr
->iVersion
;
3528 TOOLBAR_HideButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3530 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3531 TBUTTON_INFO
*btnPtr
;
3536 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3540 btnPtr
= &infoPtr
->buttons
[nIndex
];
3541 if (LOWORD(lParam
) == FALSE
)
3542 btnPtr
->fsState
&= ~TBSTATE_HIDDEN
;
3544 btnPtr
->fsState
|= TBSTATE_HIDDEN
;
3546 TOOLBAR_CalcToolbar (hwnd
);
3548 InvalidateRect (hwnd
, NULL
, TRUE
);
3554 inline static LRESULT
3555 TOOLBAR_HitTest (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3557 return TOOLBAR_InternalHitTest (hwnd
, (LPPOINT
)lParam
);
3562 TOOLBAR_Indeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3564 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3565 TBUTTON_INFO
*btnPtr
;
3569 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3573 btnPtr
= &infoPtr
->buttons
[nIndex
];
3574 oldState
= btnPtr
->fsState
;
3575 if (LOWORD(lParam
) == FALSE
)
3576 btnPtr
->fsState
&= ~TBSTATE_INDETERMINATE
;
3578 btnPtr
->fsState
|= TBSTATE_INDETERMINATE
;
3580 if(oldState
!= btnPtr
->fsState
)
3581 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3588 TOOLBAR_InsertButtonA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3590 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3591 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3592 INT nIndex
= (INT
)wParam
;
3593 TBUTTON_INFO
*oldButtons
;
3598 TOOLBAR_DumpButton(infoPtr
, (TBUTTON_INFO
*)lpTbb
, nIndex
, FALSE
);
3601 /* EPP: this seems to be an undocumented call (from my IE4)
3602 * I assume in that case that:
3603 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3604 * - index of insertion is at the end of existing buttons
3605 * I only see this happen with nIndex == -1, but it could have a special
3606 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3608 nIndex
= infoPtr
->nNumButtons
;
3610 } else if (nIndex
< 0)
3613 /* If the string passed is not an index, assume address of string
3614 and do our own AddString */
3615 if ((HIWORD(lpTbb
->iString
) != 0) && (lpTbb
->iString
!= -1)) {
3619 TRACE("string %s passed instead of index, adding string\n",
3620 debugstr_a((LPSTR
)lpTbb
->iString
));
3621 len
= strlen((LPSTR
)lpTbb
->iString
) + 2;
3623 strcpy(ptr
, (LPSTR
)lpTbb
->iString
);
3624 ptr
[len
- 1] = 0; /* ended by two '\0' */
3625 lpTbb
->iString
= TOOLBAR_AddStringA(hwnd
, 0, (LPARAM
)ptr
);
3629 TRACE("inserting button index=%d\n", nIndex
);
3630 if (nIndex
> infoPtr
->nNumButtons
) {
3631 nIndex
= infoPtr
->nNumButtons
;
3632 TRACE("adjust index=%d\n", nIndex
);
3635 oldButtons
= infoPtr
->buttons
;
3636 infoPtr
->nNumButtons
++;
3637 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3638 /* pre insert copy */
3640 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3641 nIndex
* sizeof(TBUTTON_INFO
));
3644 /* insert new button */
3645 infoPtr
->buttons
[nIndex
].iBitmap
= lpTbb
->iBitmap
;
3646 infoPtr
->buttons
[nIndex
].idCommand
= lpTbb
->idCommand
;
3647 infoPtr
->buttons
[nIndex
].fsState
= lpTbb
->fsState
;
3648 infoPtr
->buttons
[nIndex
].fsStyle
= lpTbb
->fsStyle
;
3649 infoPtr
->buttons
[nIndex
].dwData
= lpTbb
->dwData
;
3650 /* if passed string and not index, then add string */
3651 if(HIWORD(lpTbb
->iString
) && lpTbb
->iString
!=-1) {
3652 Str_SetPtrAtoW ((LPWSTR
*)&infoPtr
->buttons
[nIndex
].iString
, (LPCSTR
)lpTbb
->iString
);
3655 infoPtr
->buttons
[nIndex
].iString
= lpTbb
->iString
;
3657 if ((infoPtr
->hwndToolTip
) && !(lpTbb
->fsStyle
& BTNS_SEP
)) {
3660 ZeroMemory (&ti
, sizeof(TTTOOLINFOA
));
3661 ti
.cbSize
= sizeof (TTTOOLINFOA
);
3663 ti
.uId
= lpTbb
->idCommand
;
3665 ti
.lpszText
= LPSTR_TEXTCALLBACKA
;
3667 SendMessageA (infoPtr
->hwndToolTip
, TTM_ADDTOOLA
,
3671 /* post insert copy */
3672 if (nIndex
< infoPtr
->nNumButtons
- 1) {
3673 memcpy (&infoPtr
->buttons
[nIndex
+1], &oldButtons
[nIndex
],
3674 (infoPtr
->nNumButtons
- nIndex
- 1) * sizeof(TBUTTON_INFO
));
3679 TOOLBAR_CalcToolbar (hwnd
);
3681 InvalidateRect (hwnd
, NULL
, TRUE
);
3688 TOOLBAR_InsertButtonW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3690 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3691 LPTBBUTTON lpTbb
= (LPTBBUTTON
)lParam
;
3692 INT nIndex
= (INT
)wParam
;
3693 TBUTTON_INFO
*oldButtons
;
3698 TOOLBAR_DumpButton(infoPtr
, (TBUTTON_INFO
*)lpTbb
, nIndex
, FALSE
);
3701 /* EPP: this seems to be an undocumented call (from my IE4)
3702 * I assume in that case that:
3703 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3704 * - index of insertion is at the end of existing buttons
3705 * I only see this happen with nIndex == -1, but it could have a special
3706 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3708 nIndex
= infoPtr
->nNumButtons
;
3710 } else if (nIndex
< 0)
3713 /* If the string passed is not an index, assume address of string
3714 and do our own AddString */
3715 if ((HIWORD(lpTbb
->iString
) != 0) && (lpTbb
->iString
!= -1)) {
3719 TRACE("string %s passed instead of index, adding string\n",
3720 debugstr_w((LPWSTR
)lpTbb
->iString
));
3721 len
= strlenW((LPWSTR
)lpTbb
->iString
) + 2;
3722 ptr
= Alloc(len
*sizeof(WCHAR
));
3723 strcpyW(ptr
, (LPWSTR
)lpTbb
->iString
);
3724 ptr
[len
- 1] = 0; /* ended by two '\0' */
3725 lpTbb
->iString
= TOOLBAR_AddStringW(hwnd
, 0, (LPARAM
)ptr
);
3729 TRACE("inserting button index=%d\n", nIndex
);
3730 if (nIndex
> infoPtr
->nNumButtons
) {
3731 nIndex
= infoPtr
->nNumButtons
;
3732 TRACE("adjust index=%d\n", nIndex
);
3735 oldButtons
= infoPtr
->buttons
;
3736 infoPtr
->nNumButtons
++;
3737 infoPtr
->buttons
= Alloc (sizeof (TBUTTON_INFO
) * infoPtr
->nNumButtons
);
3738 /* pre insert copy */
3740 memcpy (&infoPtr
->buttons
[0], &oldButtons
[0],
3741 nIndex
* sizeof(TBUTTON_INFO
));
3744 /* insert new button */
3745 infoPtr
->buttons
[nIndex
].iBitmap
= lpTbb
->iBitmap
;
3746 infoPtr
->buttons
[nIndex
].idCommand
= lpTbb
->idCommand
;
3747 infoPtr
->buttons
[nIndex
].fsState
= lpTbb
->fsState
;
3748 infoPtr
->buttons
[nIndex
].fsStyle
= lpTbb
->fsStyle
;
3749 infoPtr
->buttons
[nIndex
].dwData
= lpTbb
->dwData
;
3750 /* if passed string and not index, then add string */
3751 if(HIWORD(lpTbb
->iString
) && lpTbb
->iString
!=-1) {
3752 Str_SetPtrW ((LPWSTR
*)&infoPtr
->buttons
[nIndex
].iString
, (LPWSTR
)lpTbb
->iString
);
3755 infoPtr
->buttons
[nIndex
].iString
= lpTbb
->iString
;
3757 if ((infoPtr
->hwndToolTip
) && !(lpTbb
->fsStyle
& BTNS_SEP
)) {
3760 ZeroMemory (&ti
, sizeof(TTTOOLINFOW
));
3761 ti
.cbSize
= sizeof (TTTOOLINFOW
);
3763 ti
.uId
= lpTbb
->idCommand
;
3765 ti
.lpszText
= LPSTR_TEXTCALLBACKW
;
3767 SendMessageW (infoPtr
->hwndToolTip
, TTM_ADDTOOLW
,
3771 /* post insert copy */
3772 if (nIndex
< infoPtr
->nNumButtons
- 1) {
3773 memcpy (&infoPtr
->buttons
[nIndex
+1], &oldButtons
[nIndex
],
3774 (infoPtr
->nNumButtons
- nIndex
- 1) * sizeof(TBUTTON_INFO
));
3779 TOOLBAR_CalcToolbar (hwnd
);
3781 InvalidateRect (hwnd
, NULL
, TRUE
);
3787 /* << TOOLBAR_InsertMarkHitTest >> */
3791 TOOLBAR_IsButtonChecked (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3793 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3796 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3800 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_CHECKED
);
3805 TOOLBAR_IsButtonEnabled (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3807 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3810 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3814 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_ENABLED
);
3819 TOOLBAR_IsButtonHidden (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3821 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3824 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3828 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_HIDDEN
);
3833 TOOLBAR_IsButtonHighlighted (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3835 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3838 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3842 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_MARKED
);
3847 TOOLBAR_IsButtonIndeterminate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3849 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3852 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3856 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_INDETERMINATE
);
3861 TOOLBAR_IsButtonPressed (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3863 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3866 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3870 return (infoPtr
->buttons
[nIndex
].fsState
& TBSTATE_PRESSED
);
3875 TOOLBAR_LoadImages (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3878 tbab
.hInst
= (HINSTANCE
)lParam
;
3879 tbab
.nID
= (UINT_PTR
)wParam
;
3881 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd
, tbab
.hInst
, tbab
.nID
);
3883 return TOOLBAR_AddBitmap(hwnd
, 0, (LPARAM
)&tbab
);
3888 TOOLBAR_MapAccelerator (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3890 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3891 WCHAR wAccel
= (WCHAR
)wParam
;
3892 UINT
* pIDButton
= (UINT
*)lParam
;
3893 WCHAR wszAccel
[] = {'&',wAccel
,0};
3896 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3897 hwnd
, wAccel
, debugstr_wn(&wAccel
,1), pIDButton
);
3899 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++)
3901 TBUTTON_INFO
*btnPtr
= infoPtr
->buttons
+i
;
3902 if (!(btnPtr
->fsStyle
& BTNS_NOPREFIX
) &&
3903 !(btnPtr
->fsState
& TBSTATE_HIDDEN
))
3905 int iLen
= strlenW(wszAccel
);
3906 LPCWSTR lpszStr
= TOOLBAR_GetText(infoPtr
, btnPtr
);
3913 if ((lpszStr
[0] == '&') && (lpszStr
[1] == '&'))
3918 if (!strncmpiW(lpszStr
, wszAccel
, iLen
))
3920 *pIDButton
= btnPtr
->idCommand
;
3932 TOOLBAR_MarkButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3934 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3937 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd
, wParam
, lParam
);
3939 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3944 infoPtr
->buttons
[nIndex
].fsState
|= TBSTATE_MARKED
;
3946 infoPtr
->buttons
[nIndex
].fsState
&= ~TBSTATE_MARKED
;
3951 /* << TOOLBAR_MoveButton >> */
3955 TOOLBAR_PressButton (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3957 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3958 TBUTTON_INFO
*btnPtr
;
3962 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
3966 btnPtr
= &infoPtr
->buttons
[nIndex
];
3967 oldState
= btnPtr
->fsState
;
3968 if (LOWORD(lParam
) == FALSE
)
3969 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
3971 btnPtr
->fsState
|= TBSTATE_PRESSED
;
3973 if(oldState
!= btnPtr
->fsState
)
3974 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
3979 /* FIXME: there might still be some confusion her between number of buttons
3980 * and number of bitmaps */
3982 TOOLBAR_ReplaceBitmap (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
3984 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
3985 LPTBREPLACEBITMAP lpReplace
= (LPTBREPLACEBITMAP
) lParam
;
3987 int i
= 0, nOldButtons
= 0, pos
= 0;
3988 int nOldBitmaps
, nNewBitmaps
;
3989 HIMAGELIST himlDef
= 0;
3991 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
3992 lpReplace
->hInstOld
, lpReplace
->nIDOld
, lpReplace
->hInstNew
, lpReplace
->nIDNew
,
3993 lpReplace
->nButtons
);
3995 if (lpReplace
->hInstOld
== HINST_COMMCTRL
)
3997 FIXME("changing standard bitmaps not implemented\n");
4000 else if (lpReplace
->hInstOld
!= 0)
4002 FIXME("resources not in the current module not implemented\n");
4007 hBitmap
= (HBITMAP
) lpReplace
->nIDNew
;
4010 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4011 for (i
= 0; i
< infoPtr
->nNumBitmapInfos
; i
++) {
4012 TBITMAP_INFO
*tbi
= &infoPtr
->bitmaps
[i
];
4013 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4014 if (tbi
->hInst
== lpReplace
->hInstOld
&& tbi
->nID
== lpReplace
->nIDOld
)
4016 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi
->nButtons
, tbi
->hInst
, tbi
->nID
);
4017 nOldButtons
= tbi
->nButtons
;
4018 tbi
->nButtons
= lpReplace
->nButtons
;
4019 tbi
->hInst
= lpReplace
->hInstNew
;
4020 tbi
->nID
= lpReplace
->nIDNew
;
4021 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i
, tbi
->hInst
, tbi
->nID
);
4024 pos
+= tbi
->nButtons
;
4027 if (nOldButtons
== 0)
4029 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace
->hInstOld
, lpReplace
->nIDOld
);
4033 himlDef
= GETDEFIMAGELIST(infoPtr
, 0); /* fixme: correct? */
4034 nOldBitmaps
= ImageList_GetImageCount(himlDef
);
4036 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4038 for (i
= pos
+ nOldBitmaps
- 1; i
>= pos
; i
--)
4039 ImageList_Remove(himlDef
, i
);
4043 HBITMAP hOldBitmapBitmap
, hOldBitmapLoad
, hbmLoad
;
4044 HDC hdcImage
, hdcBitmap
;
4046 /* copy the bitmap before adding it so that the user's bitmap
4047 * doesn't get modified.
4049 GetObjectA (hBitmap
, sizeof(BITMAP
), (LPVOID
)&bmp
);
4051 hdcImage
= CreateCompatibleDC(0);
4052 hdcBitmap
= CreateCompatibleDC(0);
4054 /* create new bitmap */
4055 hbmLoad
= CreateBitmap (bmp
.bmWidth
, bmp
.bmHeight
, bmp
.bmPlanes
, bmp
.bmBitsPixel
, NULL
);
4056 hOldBitmapBitmap
= SelectObject(hdcBitmap
, hBitmap
);
4057 hOldBitmapLoad
= SelectObject(hdcImage
, hbmLoad
);
4059 /* Copy the user's image */
4060 BitBlt (hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
,
4061 hdcBitmap
, 0, 0, SRCCOPY
);
4063 SelectObject (hdcImage
, hOldBitmapLoad
);
4064 SelectObject (hdcBitmap
, hOldBitmapBitmap
);
4065 DeleteDC (hdcImage
);
4066 DeleteDC (hdcBitmap
);
4068 ImageList_AddMasked (himlDef
, hbmLoad
, comctl32_color
.clrBtnFace
);
4069 nNewBitmaps
= ImageList_GetImageCount(himlDef
);
4070 DeleteObject (hbmLoad
);
4073 infoPtr
->nNumBitmaps
= infoPtr
->nNumBitmaps
- nOldBitmaps
+ nNewBitmaps
;
4075 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4076 pos
, nOldBitmaps
, nNewBitmaps
);
4078 InvalidateRect(hwnd
, NULL
, TRUE
);
4084 TOOLBAR_SaveRestoreA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4087 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4088 LPTBSAVEPARAMSA lpSave
= (LPTBSAVEPARAMSA
)lParam
;
4090 if (lpSave
== NULL
) return 0;
4093 /* save toolbar information */
4094 FIXME("save to \"%s\" \"%s\"\n",
4095 lpSave
->pszSubKey
, lpSave
->pszValueName
);
4100 /* restore toolbar information */
4102 FIXME("restore from \"%s\" \"%s\"\n",
4103 lpSave
->pszSubKey
, lpSave
->pszValueName
);
4114 TOOLBAR_SaveRestoreW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4117 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4118 LPTBSAVEPARAMSW lpSave
= (LPTBSAVEPARAMSW
)lParam
;
4124 /* save toolbar information */
4125 FIXME("save to \"%s\" \"%s\"\n",
4126 lpSave
->pszSubKey
, lpSave
->pszValueName
);
4131 /* restore toolbar information */
4133 FIXME("restore from \"%s\" \"%s\"\n",
4134 lpSave
->pszSubKey
, lpSave
->pszValueName
);
4145 TOOLBAR_SetAnchorHighlight (HWND hwnd
, WPARAM wParam
)
4147 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4148 BOOL bOldAnchor
= infoPtr
->bAnchor
;
4150 infoPtr
->bAnchor
= (BOOL
)wParam
;
4152 return (LRESULT
)bOldAnchor
;
4157 TOOLBAR_SetBitmapSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4159 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4160 HIMAGELIST himlDef
= GETDEFIMAGELIST(infoPtr
, 0);
4162 if ((LOWORD(lParam
) <= 0) || (HIWORD(lParam
)<=0))
4165 if (infoPtr
->nNumButtons
> 0)
4166 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4167 infoPtr
->nNumButtons
,
4168 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
,
4169 LOWORD(lParam
), HIWORD(lParam
));
4171 infoPtr
->nBitmapWidth
= (INT
)LOWORD(lParam
);
4172 infoPtr
->nBitmapHeight
= (INT
)HIWORD(lParam
);
4175 /* uses image list internals directly */
4177 himlDef
->cx
= infoPtr
->nBitmapWidth
;
4178 himlDef
->cy
= infoPtr
->nBitmapHeight
;
4186 TOOLBAR_SetButtonInfoA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4188 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4189 LPTBBUTTONINFOA lptbbi
= (LPTBBUTTONINFOA
)lParam
;
4190 TBUTTON_INFO
*btnPtr
;
4195 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOA
))
4198 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4199 lptbbi
->dwMask
& 0x80000000);
4203 btnPtr
= &infoPtr
->buttons
[nIndex
];
4204 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4205 btnPtr
->idCommand
= lptbbi
->idCommand
;
4206 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4207 btnPtr
->iBitmap
= lptbbi
->iImage
;
4208 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4209 btnPtr
->dwData
= lptbbi
->lParam
;
4210 /* if (lptbbi->dwMask & TBIF_SIZE) */
4211 /* btnPtr->cx = lptbbi->cx; */
4212 if (lptbbi
->dwMask
& TBIF_STATE
)
4213 btnPtr
->fsState
= lptbbi
->fsState
;
4214 if (lptbbi
->dwMask
& TBIF_STYLE
)
4215 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4217 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT
)lptbbi
->pszText
!= -1)) {
4218 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4219 /* iString is index, zero it to make Str_SetPtr succeed */
4222 Str_SetPtrAtoW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4229 TOOLBAR_SetButtonInfoW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4231 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4232 LPTBBUTTONINFOW lptbbi
= (LPTBBUTTONINFOW
)lParam
;
4233 TBUTTON_INFO
*btnPtr
;
4238 if (lptbbi
->cbSize
< sizeof(TBBUTTONINFOW
))
4241 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
,
4242 lptbbi
->dwMask
& 0x80000000);
4246 btnPtr
= &infoPtr
->buttons
[nIndex
];
4247 if (lptbbi
->dwMask
& TBIF_COMMAND
)
4248 btnPtr
->idCommand
= lptbbi
->idCommand
;
4249 if (lptbbi
->dwMask
& TBIF_IMAGE
)
4250 btnPtr
->iBitmap
= lptbbi
->iImage
;
4251 if (lptbbi
->dwMask
& TBIF_LPARAM
)
4252 btnPtr
->dwData
= lptbbi
->lParam
;
4253 /* if (lptbbi->dwMask & TBIF_SIZE) */
4254 /* btnPtr->cx = lptbbi->cx; */
4255 if (lptbbi
->dwMask
& TBIF_STATE
)
4256 btnPtr
->fsState
= lptbbi
->fsState
;
4257 if (lptbbi
->dwMask
& TBIF_STYLE
)
4258 btnPtr
->fsStyle
= lptbbi
->fsStyle
;
4260 if ((lptbbi
->dwMask
& TBIF_TEXT
) && ((INT
)lptbbi
->pszText
!= -1)) {
4261 if ((HIWORD(btnPtr
->iString
) == 0) || (btnPtr
->iString
== -1))
4262 /* iString is index, zero it to make Str_SetPtr succeed */
4264 Str_SetPtrW ((LPWSTR
*)&btnPtr
->iString
, lptbbi
->pszText
);
4271 TOOLBAR_SetButtonSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4273 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4274 INT cx
= LOWORD(lParam
), cy
= HIWORD(lParam
);
4276 if ((cx
< 0) || (cy
< 0))
4278 ERR("invalid parameter 0x%08lx\n", (DWORD
)lParam
);
4282 /* The documentation claims you can only change the button size before
4283 * any button has been added. But this is wrong.
4284 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4285 * it to the toolbar, and it checks that the return value is nonzero - mjm
4286 * Further testing shows that we must actually perform the change too.
4289 * The documentation also does not mention that if 0 is supplied for
4290 * either size, the system changes it to the default of 24 wide and
4291 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4293 infoPtr
->nButtonWidth
= (cx
) ? cx
: 24;
4294 infoPtr
->nButtonHeight
= (cy
) ? cy
: 22;
4300 TOOLBAR_SetButtonWidth (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4302 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4304 if (infoPtr
== NULL
) {
4305 TRACE("Toolbar not initialized yet?????\n");
4309 /* if setting to current values, ignore */
4310 if ((infoPtr
->cxMin
== (INT
)LOWORD(lParam
)) &&
4311 (infoPtr
->cxMax
== (INT
)HIWORD(lParam
))) {
4312 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4313 infoPtr
->cxMin
, infoPtr
->cxMax
);
4317 /* save new values */
4318 infoPtr
->cxMin
= (INT
)LOWORD(lParam
);
4319 infoPtr
->cxMax
= (INT
)HIWORD(lParam
);
4321 /* if both values are 0 then we are done */
4323 TRACE("setting both min and max to 0, norecalc\n");
4327 /* otherwise we need to recalc the toolbar and in some cases
4328 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4329 which doesn't actually draw - GA). */
4330 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4331 infoPtr
->nNumButtons
, infoPtr
->cxMin
, infoPtr
->cxMax
);
4333 TOOLBAR_CalcToolbar (hwnd
);
4335 InvalidateRect (hwnd
, NULL
, TRUE
);
4342 TOOLBAR_SetCmdId (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4344 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4345 INT nIndex
= (INT
)wParam
;
4347 if ((nIndex
< 0) || (nIndex
>= infoPtr
->nNumButtons
))
4350 infoPtr
->buttons
[nIndex
].idCommand
= (INT
)lParam
;
4352 if (infoPtr
->hwndToolTip
) {
4354 FIXME("change tool tip!\n");
4363 TOOLBAR_SetDisabledImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4365 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4366 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4367 HIMAGELIST himlTemp
;
4370 if (infoPtr
->iVersion
>= 5)
4373 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDis
,
4374 &infoPtr
->cimlDis
, himl
, id
);
4376 /* FIXME: redraw ? */
4378 return (LRESULT
)himlTemp
;
4383 TOOLBAR_SetDrawTextFlags (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4385 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4388 dwTemp
= infoPtr
->dwDTFlags
;
4389 infoPtr
->dwDTFlags
=
4390 (infoPtr
->dwDTFlags
& (DWORD
)wParam
) | (DWORD
)lParam
;
4392 return (LRESULT
)dwTemp
;
4395 /* This function differs a bit from what MSDN says it does:
4396 * 1. lParam contains extended style flags to OR with current style
4397 * (MSDN isn't clear on the OR bit)
4398 * 2. wParam appears to contain extended style flags to be reset
4399 * (MSDN says that this parameter is reserved)
4402 TOOLBAR_SetExtendedStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4404 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4407 dwTemp
= infoPtr
->dwExStyle
;
4408 infoPtr
->dwExStyle
&= ~wParam
;
4409 infoPtr
->dwExStyle
|= (DWORD
)lParam
;
4411 TRACE("new style 0x%08lx\n", infoPtr
->dwExStyle
);
4413 if (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
)
4414 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4415 (infoPtr
->dwExStyle
& ~TBSTYLE_EX_ALL
));
4417 TOOLBAR_CalcToolbar (hwnd
);
4419 TOOLBAR_AutoSize(hwnd
);
4421 InvalidateRect(hwnd
, NULL
, TRUE
);
4423 return (LRESULT
)dwTemp
;
4428 TOOLBAR_SetHotImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4430 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4431 HIMAGELIST himlTemp
;
4432 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4435 if (infoPtr
->iVersion
>= 5)
4438 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd
, himl
, id
);
4440 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlHot
,
4441 &infoPtr
->cimlHot
, himl
, id
);
4443 /* FIXME: redraw ? */
4445 return (LRESULT
)himlTemp
;
4449 /* Makes previous hot button no longer hot, makes the specified
4450 * button hot and sends appropriate notifications. dwReason is one or
4451 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4452 * NOTE 1: this function does not validate nHit
4453 * NOTE 2: the name of this function is completely made up and
4454 * not based on any documentation from Microsoft. */
4456 TOOLBAR_SetHotItemEx (TOOLBAR_INFO
*infoPtr
, INT nHit
, DWORD dwReason
)
4458 if (infoPtr
->nHotItem
!= nHit
)
4460 NMTBHOTITEM nmhotitem
;
4461 TBUTTON_INFO
*btnPtr
= NULL
, *oldBtnPtr
= NULL
;
4462 LRESULT no_highlight
;
4464 /* Remove the effect of an old hot button if the button was
4465 drawn with the hot button effect */
4466 if(infoPtr
->nHotItem
>= 0)
4468 oldBtnPtr
= &infoPtr
->buttons
[infoPtr
->nHotItem
];
4469 oldBtnPtr
->bHot
= FALSE
;
4472 infoPtr
->nHotItem
= nHit
;
4474 /* It's not a separator or in nowhere. It's a hot button. */
4476 btnPtr
= &infoPtr
->buttons
[nHit
];
4478 nmhotitem
.dwFlags
= dwReason
;
4480 nmhotitem
.idOld
= oldBtnPtr
->idCommand
;
4482 nmhotitem
.dwFlags
|= HICF_ENTERING
;
4484 nmhotitem
.idNew
= btnPtr
->idCommand
;
4486 nmhotitem
.dwFlags
|= HICF_LEAVING
;
4488 no_highlight
= TOOLBAR_SendNotify((NMHDR
*)&nmhotitem
, infoPtr
, TBN_HOTITEMCHANGE
);
4490 /* now invalidate the old and new buttons so they will be painted */
4492 InvalidateRect(infoPtr
->hwndSelf
, &oldBtnPtr
->rect
, TRUE
);
4493 if (btnPtr
&& !no_highlight
)
4495 btnPtr
->bHot
= TRUE
;
4496 InvalidateRect(infoPtr
->hwndSelf
, &btnPtr
->rect
, TRUE
);
4502 TOOLBAR_SetHotItem (HWND hwnd
, WPARAM wParam
)
4504 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4505 INT nOldHotItem
= infoPtr
->nHotItem
;
4507 if ((INT
) wParam
< 0 || (INT
)wParam
> infoPtr
->nNumButtons
)
4510 if (GetWindowLongW(hwnd
, GWL_STYLE
) & TBSTYLE_FLAT
)
4511 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, HICF_OTHER
);
4513 if (nOldHotItem
< 0)
4516 return (LRESULT
)nOldHotItem
;
4521 TOOLBAR_SetImageList (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4523 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4524 HIMAGELIST himlTemp
;
4525 HIMAGELIST himl
= (HIMAGELIST
)lParam
;
4528 if (infoPtr
->iVersion
>= 5)
4531 himlTemp
= TOOLBAR_InsertImageList(&infoPtr
->himlDef
,
4532 &infoPtr
->cimlDef
, himl
, id
);
4534 infoPtr
->nNumBitmaps
= 0;
4535 for (i
= 0; i
< infoPtr
->cimlDef
; i
++)
4536 infoPtr
->nNumBitmaps
+= ImageList_GetImageCount(infoPtr
->himlDef
[i
]->himl
);
4538 ImageList_GetIconSize(himl
, &infoPtr
->nBitmapWidth
,
4539 &infoPtr
->nBitmapHeight
);
4540 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4541 hwnd
, (INT
)infoPtr
->himlDef
, infoPtr
->nNumBitmaps
,
4542 infoPtr
->nBitmapWidth
, infoPtr
->nBitmapHeight
);
4544 InvalidateRect(hwnd
, NULL
, TRUE
);
4546 return (LRESULT
)himlTemp
;
4551 TOOLBAR_SetIndent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4553 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4555 infoPtr
->nIndent
= (INT
)wParam
;
4559 /* process only on indent changing */
4560 if(infoPtr
->nIndent
!= (INT
)wParam
)
4562 infoPtr
->nIndent
= (INT
)wParam
;
4563 TOOLBAR_CalcToolbar (hwnd
);
4564 InvalidateRect(hwnd
, NULL
, FALSE
);
4571 /* << TOOLBAR_SetInsertMark >> */
4575 TOOLBAR_SetInsertMarkColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4577 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4579 infoPtr
->clrInsertMark
= (COLORREF
)lParam
;
4581 /* FIXME : redraw ??*/
4588 TOOLBAR_SetMaxTextRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4590 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4592 if (infoPtr
== NULL
)
4595 infoPtr
->nMaxTextRows
= (INT
)wParam
;
4597 TOOLBAR_CalcToolbar(hwnd
);
4602 /* MSDN gives slightly wrong info on padding.
4603 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4604 * 2. It is not used to create a blank area between the edge of the button
4605 * and the text or image if TBSTYLE_LIST is set. It is used to control
4606 * the gap between the image and text.
4607 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4608 * to control the bottom and right borders [with the border being
4609 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4610 * is shared evenly on both sides of the button.
4613 TOOLBAR_SetPadding (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4615 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4618 oldPad
= MAKELONG(infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4619 infoPtr
->szPadding
.cx
= LOWORD((DWORD
)lParam
);
4620 infoPtr
->szPadding
.cy
= HIWORD((DWORD
)lParam
);
4621 TRACE("cx=%ld, cy=%ld\n",
4622 infoPtr
->szPadding
.cx
, infoPtr
->szPadding
.cy
);
4623 return (LRESULT
) oldPad
;
4628 TOOLBAR_SetParent (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4630 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4635 if (infoPtr
== NULL
)
4637 hwndOldNotify
= infoPtr
->hwndNotify
;
4638 infoPtr
->hwndNotify
= (HWND
)wParam
;
4640 return (LRESULT
)hwndOldNotify
;
4645 TOOLBAR_SetRows (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4647 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4648 LPRECT lprc
= (LPRECT
)lParam
;
4652 if (LOWORD(wParam
) > 1) {
4653 FIXME("multiple rows not supported!\n");
4656 if(infoPtr
->nRows
!= LOWORD(wParam
))
4658 infoPtr
->nRows
= LOWORD(wParam
);
4660 /* recalculate toolbar */
4661 TOOLBAR_CalcToolbar (hwnd
);
4663 /* repaint toolbar */
4664 InvalidateRect(hwnd
, NULL
, TRUE
);
4667 /* return bounding rectangle */
4669 lprc
->left
= infoPtr
->rcBound
.left
;
4670 lprc
->right
= infoPtr
->rcBound
.right
;
4671 lprc
->top
= infoPtr
->rcBound
.top
;
4672 lprc
->bottom
= infoPtr
->rcBound
.bottom
;
4680 TOOLBAR_SetState (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4682 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4683 TBUTTON_INFO
*btnPtr
;
4686 nIndex
= TOOLBAR_GetButtonIndex (infoPtr
, (INT
)wParam
, FALSE
);
4690 btnPtr
= &infoPtr
->buttons
[nIndex
];
4692 /* if hidden state has changed the invalidate entire window and recalc */
4693 if ((btnPtr
->fsState
& TBSTATE_HIDDEN
) != (LOWORD(lParam
) & TBSTATE_HIDDEN
)) {
4694 btnPtr
->fsState
= LOWORD(lParam
);
4695 TOOLBAR_CalcToolbar (hwnd
);
4696 InvalidateRect(hwnd
, 0, TRUE
);
4700 /* process state changing if current state doesn't match new state */
4701 if(btnPtr
->fsState
!= LOWORD(lParam
))
4703 btnPtr
->fsState
= LOWORD(lParam
);
4704 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
4712 TOOLBAR_SetStyle (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4714 SetWindowLongW(hwnd
, GWL_STYLE
, lParam
);
4720 inline static LRESULT
4721 TOOLBAR_SetToolTips (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4723 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4725 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd
, (HWND
)wParam
, lParam
);
4727 if (infoPtr
== NULL
)
4729 infoPtr
->hwndToolTip
= (HWND
)wParam
;
4735 TOOLBAR_SetUnicodeFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4737 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4740 TRACE("%s hwnd=%p stub!\n",
4741 ((BOOL
)wParam
) ? "TRUE" : "FALSE", hwnd
);
4743 bTemp
= infoPtr
->bUnicode
;
4744 infoPtr
->bUnicode
= (BOOL
)wParam
;
4751 TOOLBAR_GetColorScheme (HWND hwnd
, LPCOLORSCHEME lParam
)
4753 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4755 lParam
->clrBtnHighlight
= (infoPtr
->clrBtnHighlight
== CLR_DEFAULT
) ?
4756 comctl32_color
.clrBtnHighlight
:
4757 infoPtr
->clrBtnHighlight
;
4758 lParam
->clrBtnShadow
= (infoPtr
->clrBtnShadow
== CLR_DEFAULT
) ?
4759 comctl32_color
.clrBtnShadow
: infoPtr
->clrBtnShadow
;
4765 TOOLBAR_SetColorScheme (HWND hwnd
, LPCOLORSCHEME lParam
)
4767 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4769 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4770 lParam
->clrBtnHighlight
, lParam
->clrBtnShadow
,
4771 infoPtr
->clrBtnHighlight
, infoPtr
->clrBtnShadow
);
4773 infoPtr
->clrBtnHighlight
= lParam
->clrBtnHighlight
;
4774 infoPtr
->clrBtnShadow
= lParam
->clrBtnShadow
;
4775 InvalidateRect(hwnd
, NULL
, TRUE
);
4781 TOOLBAR_SetVersion (HWND hwnd
, INT iVersion
)
4783 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4784 INT iOldVersion
= infoPtr
->iVersion
;
4786 infoPtr
->iVersion
= iVersion
;
4788 if (infoPtr
->iVersion
>= 5)
4789 TOOLBAR_SetUnicodeFormat(hwnd
, (WPARAM
)TRUE
, (LPARAM
)0);
4796 TOOLBAR_GetStringA (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4798 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4799 WORD iString
= HIWORD(wParam
);
4800 WORD buffersize
= LOWORD(wParam
);
4801 LPSTR str
= (LPSTR
)lParam
;
4804 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, buffersize
, str
);
4806 if (iString
< infoPtr
->nNumStrings
)
4808 ret
= WideCharToMultiByte(CP_ACP
, 0, infoPtr
->strings
[iString
], -1, str
, buffersize
, NULL
, NULL
);
4810 TRACE("returning %s\n", debugstr_a(str
));
4813 ERR("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
4820 TOOLBAR_GetStringW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4822 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4823 WORD iString
= HIWORD(wParam
);
4824 WORD len
= LOWORD(wParam
)/sizeof(WCHAR
) - 1;
4825 LPWSTR str
= (LPWSTR
)lParam
;
4828 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd
, iString
, LOWORD(wParam
), str
);
4830 if (iString
< infoPtr
->nNumStrings
)
4832 len
= min(len
, strlenW(infoPtr
->strings
[iString
]));
4833 ret
= (len
+1)*sizeof(WCHAR
);
4834 memcpy(str
, infoPtr
->strings
[iString
], ret
);
4837 TRACE("returning %s\n", debugstr_w(str
));
4840 ERR("String index %d out of range (largest is %d)\n", iString
, infoPtr
->nNumStrings
- 1);
4845 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
4846 * is the maximum size of the toolbar? */
4847 static LRESULT
TOOLBAR_Unkwn45D(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4849 SIZE
* pSize
= (SIZE
*)lParam
;
4850 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd
, wParam
, pSize
->cx
, pSize
->cy
);
4855 /* UNDOCUMENTED MESSAGE: This is an extended version of the
4856 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
4857 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
4860 TOOLBAR_Unkwn45E (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4862 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4863 INT nOldHotItem
= infoPtr
->nHotItem
;
4865 TRACE("old item=%d, new item=%d, flags=%08lx\n",
4866 nOldHotItem
, infoPtr
->nHotItem
, (DWORD
)lParam
);
4868 if ((INT
) wParam
< 0 || (INT
)wParam
> infoPtr
->nNumButtons
)
4871 TOOLBAR_SetHotItemEx(infoPtr
, wParam
, lParam
);
4875 return (nOldHotItem
< 0) ? -1 : (LRESULT
)nOldHotItem
;
4878 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
4879 * which controls the amount of spacing between the image and the text
4880 * of buttons for TBSTYLE_LIST toolbars. */
4881 static LRESULT
TOOLBAR_Unkwn460(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4883 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4885 TRACE("hwnd=%p iListGap=%d\n", hwnd
, wParam
);
4888 FIXME("lParam = 0x%08lx. Please report\n", lParam
);
4890 infoPtr
->iListGap
= (INT
)wParam
;
4892 TOOLBAR_CalcToolbar(hwnd
);
4893 InvalidateRect(hwnd
, NULL
, TRUE
);
4898 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
4899 * of image lists associated with the various states. */
4900 static LRESULT
TOOLBAR_Unkwn462(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4902 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
4904 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd
, wParam
, lParam
);
4906 return max(infoPtr
->cimlDef
, max(infoPtr
->cimlHot
, infoPtr
->cimlDis
));
4910 TOOLBAR_Unkwn463 (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4912 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4913 LPSIZE lpsize
= (LPSIZE
)lParam
;
4919 * Testing shows the following:
4920 * wParam = 0 adjust cx value
4921 * = 1 set cy value to max size.
4922 * lParam pointer to SIZE structure
4925 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
4926 wParam
, lParam
, lpsize
->cx
, lpsize
->cy
);
4930 if (lpsize
->cx
== -1) {
4931 /* **** this is wrong, native measures each button and sets it */
4932 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
4934 else if(HIWORD(lpsize
->cx
)) {
4936 HWND hwndParent
= GetParent(hwnd
);
4938 GetWindowRect(hwnd
, &rc
);
4939 MapWindowPoints(0, hwndParent
, (LPPOINT
)&rc
, 2);
4940 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
4941 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4942 lpsize
->cx
= max(rc
.right
-rc
.left
,
4943 infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
);
4946 lpsize
->cx
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
4950 lpsize
->cy
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
4951 /* lpsize->cy = infoPtr->nHeight; */
4954 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
4958 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
4959 lpsize
->cx
, lpsize
->cy
);
4963 static LRESULT
TOOLBAR_Unkwn464(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4965 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd
, wParam
, lParam
);
4967 InvalidateRect(hwnd
, NULL
, TRUE
);
4973 TOOLBAR_Create (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
4975 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
4976 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
4979 TRACE("hwnd = %p\n", hwnd
);
4981 /* initialize info structure */
4982 infoPtr
->nButtonHeight
= 22;
4983 infoPtr
->nButtonWidth
= 24;
4984 infoPtr
->nBitmapHeight
= 15;
4985 infoPtr
->nBitmapWidth
= 16;
4987 infoPtr
->nHeight
= infoPtr
->nButtonHeight
+ TOP_BORDER
+ BOTTOM_BORDER
;
4988 infoPtr
->nMaxTextRows
= 1;
4989 infoPtr
->cxMin
= -1;
4990 infoPtr
->cxMax
= -1;
4991 infoPtr
->nNumBitmaps
= 0;
4992 infoPtr
->nNumStrings
= 0;
4994 infoPtr
->bCaptured
= FALSE
;
4995 infoPtr
->bUnicode
= IsWindowUnicode (hwnd
);
4996 infoPtr
->nButtonDown
= -1;
4997 infoPtr
->nOldHit
= -1;
4998 infoPtr
->nHotItem
= -1;
4999 infoPtr
->hwndNotify
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
5000 infoPtr
->bTransparent
= (dwStyle
& TBSTYLE_TRANSPARENT
);
5001 infoPtr
->bBtnTranspnt
= (dwStyle
& (TBSTYLE_FLAT
| TBSTYLE_LIST
));
5002 infoPtr
->dwDTFlags
= (dwStyle
& TBSTYLE_LIST
) ? DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
: DT_CENTER
;
5003 infoPtr
->bAnchor
= FALSE
; /* no anchor highlighting */
5004 infoPtr
->iVersion
= 0;
5005 infoPtr
->hwndSelf
= hwnd
;
5006 infoPtr
->bDoRedraw
= TRUE
;
5007 infoPtr
->clrBtnHighlight
= CLR_DEFAULT
;
5008 infoPtr
->clrBtnShadow
= CLR_DEFAULT
;
5009 /* not sure where the +1 comes from, but this comes to the same value
5010 * as native so this is probably correct */
5011 infoPtr
->szPadding
.cx
= 2*(GetSystemMetrics(SM_CXEDGE
)+OFFSET_X
) + 1;
5012 infoPtr
->szPadding
.cy
= 2*(GetSystemMetrics(SM_CYEDGE
)+OFFSET_Y
);
5013 infoPtr
->iListGap
= infoPtr
->szPadding
.cx
/ 2;
5014 GetClientRect(hwnd
, &infoPtr
->client_rect
);
5015 TOOLBAR_NotifyFormat(infoPtr
, (WPARAM
)hwnd
, (LPARAM
)NF_REQUERY
);
5017 SystemParametersInfoA (SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
5018 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectA (&logFont
);
5020 if (dwStyle
& TBSTYLE_TOOLTIPS
) {
5021 /* Create tooltip control */
5022 infoPtr
->hwndToolTip
=
5023 CreateWindowExA (0, TOOLTIPS_CLASSA
, NULL
, 0,
5024 CW_USEDEFAULT
, CW_USEDEFAULT
,
5025 CW_USEDEFAULT
, CW_USEDEFAULT
,
5028 /* Send NM_TOOLTIPSCREATED notification */
5029 if (infoPtr
->hwndToolTip
) {
5030 NMTOOLTIPSCREATED nmttc
;
5032 nmttc
.hwndToolTips
= infoPtr
->hwndToolTip
;
5034 TOOLBAR_SendNotify ((NMHDR
*) &nmttc
, infoPtr
,
5035 NM_TOOLTIPSCREATED
);
5039 TOOLBAR_CheckStyle (hwnd
, dwStyle
);
5041 TOOLBAR_CalcToolbar(hwnd
);
5048 TOOLBAR_Destroy (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5050 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5052 /* delete tooltip control */
5053 if (infoPtr
->hwndToolTip
)
5054 DestroyWindow (infoPtr
->hwndToolTip
);
5056 /* delete temporary buffer for tooltip text */
5057 if (infoPtr
->pszTooltipText
)
5058 HeapFree(GetProcessHeap(), 0, infoPtr
->pszTooltipText
);
5060 /* delete button data */
5061 if (infoPtr
->buttons
)
5062 Free (infoPtr
->buttons
);
5064 /* delete strings */
5065 if (infoPtr
->strings
) {
5067 for (i
= 0; i
< infoPtr
->nNumStrings
; i
++)
5068 if (infoPtr
->strings
[i
])
5069 Free (infoPtr
->strings
[i
]);
5071 Free (infoPtr
->strings
);
5074 /* destroy internal image list */
5075 if (infoPtr
->himlInt
)
5076 ImageList_Destroy (infoPtr
->himlInt
);
5078 TOOLBAR_DeleteImageList(&infoPtr
->himlDef
, &infoPtr
->cimlDef
);
5079 TOOLBAR_DeleteImageList(&infoPtr
->himlDis
, &infoPtr
->cimlDis
);
5080 TOOLBAR_DeleteImageList(&infoPtr
->himlHot
, &infoPtr
->cimlHot
);
5082 /* delete default font */
5084 DeleteObject (infoPtr
->hDefaultFont
);
5086 /* free toolbar info data */
5088 SetWindowLongA (hwnd
, 0, 0);
5095 TOOLBAR_EraseBackground (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5097 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5098 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
5099 NMTBCUSTOMDRAW tbcd
;
5103 if (dwStyle
& TBSTYLE_CUSTOMERASE
) {
5104 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5105 tbcd
.nmcd
.dwDrawStage
= CDDS_PREERASE
;
5106 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5107 ntfret
= TOOLBAR_SendNotify ((NMHDR
*)&tbcd
, infoPtr
, NM_CUSTOMDRAW
);
5108 infoPtr
->dwBaseCustDraw
= ntfret
& 0xffff;
5110 /* FIXME: in general the return flags *can* be or'ed together */
5111 switch (infoPtr
->dwBaseCustDraw
)
5113 case CDRF_DODEFAULT
:
5115 case CDRF_SKIPDEFAULT
:
5118 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5123 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5124 * to my parent for processing.
5126 if (infoPtr
->bTransparent
) {
5128 HDC hdc
= (HDC
)wParam
;
5133 parent
= GetParent(hwnd
);
5134 MapWindowPoints(hwnd
, parent
, &pt
, 1);
5135 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
5136 ret
= SendMessageA (parent
, WM_ERASEBKGND
, wParam
, lParam
);
5137 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
5140 ret
= DefWindowProcA (hwnd
, WM_ERASEBKGND
, wParam
, lParam
);
5142 if ((dwStyle
& TBSTYLE_CUSTOMERASE
) &&
5143 (infoPtr
->dwBaseCustDraw
& CDRF_NOTIFYPOSTERASE
)) {
5144 ZeroMemory (&tbcd
, sizeof(NMTBCUSTOMDRAW
));
5145 tbcd
.nmcd
.dwDrawStage
= CDDS_POSTERASE
;
5146 tbcd
.nmcd
.hdc
= (HDC
)wParam
;
5147 ntfret
= TOOLBAR_SendNotify ((NMHDR
*)&tbcd
, infoPtr
, NM_CUSTOMDRAW
);
5148 infoPtr
->dwBaseCustDraw
= ntfret
& 0xffff;
5149 switch (infoPtr
->dwBaseCustDraw
)
5151 case CDRF_DODEFAULT
:
5153 case CDRF_SKIPDEFAULT
:
5156 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5165 TOOLBAR_GetFont (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5167 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5169 return (LRESULT
)infoPtr
->hFont
;
5174 TOOLBAR_LButtonDblClk (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5176 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5177 TBUTTON_INFO
*btnPtr
;
5181 pt
.x
= (INT
)LOWORD(lParam
);
5182 pt
.y
= (INT
)HIWORD(lParam
);
5183 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5186 btnPtr
= &infoPtr
->buttons
[nHit
];
5187 if (!(btnPtr
->fsState
& TBSTATE_ENABLED
))
5190 infoPtr
->bCaptured
= TRUE
;
5191 infoPtr
->nButtonDown
= nHit
;
5193 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5195 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5197 else if (GetWindowLongA (hwnd
, GWL_STYLE
) & CCS_ADJUSTABLE
)
5198 TOOLBAR_Customize (hwnd
);
5205 TOOLBAR_LButtonDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5207 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5208 TBUTTON_INFO
*btnPtr
;
5213 if (infoPtr
->hwndToolTip
)
5214 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5215 WM_LBUTTONDOWN
, wParam
, lParam
);
5217 pt
.x
= (INT
)LOWORD(lParam
);
5218 pt
.y
= (INT
)HIWORD(lParam
);
5219 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5221 btnPtr
= &infoPtr
->buttons
[nHit
];
5225 infoPtr
->nOldHit
= nHit
;
5227 CopyRect(&arrowRect
, &btnPtr
->rect
);
5228 arrowRect
.left
= max(btnPtr
->rect
.left
, btnPtr
->rect
.right
- DDARROW_WIDTH
);
5230 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5231 if ((btnPtr
->fsState
& TBSTATE_ENABLED
) &&
5232 ((btnPtr
->fsStyle
& BTNS_WHOLEDROPDOWN
) ||
5233 ((btnPtr
->fsStyle
& BTNS_DROPDOWN
) &&
5234 ((TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
) && PtInRect(&arrowRect
, pt
)) ||
5235 (!TOOLBAR_HasDropDownArrows(infoPtr
->dwExStyle
))))))
5239 /* draw in pressed state */
5240 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5241 RedrawWindow(hwnd
,&btnPtr
->rect
,0,
5242 RDW_ERASE
|RDW_INVALIDATE
|RDW_UPDATENOW
);
5244 nmtb
.iItem
= btnPtr
->idCommand
;
5245 memset(&nmtb
.tbButton
, 0, sizeof(TBBUTTON
));
5248 CopyRect(&nmtb
.rcButton
, &btnPtr
->rect
);
5249 res
= TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5251 TRACE("TBN_DROPDOWN responded with %ld\n", res
);
5253 if (res
!= TBDDRET_TREATPRESSED
)
5257 /* redraw button in unpressed state */
5258 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5259 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5261 /* find and set hot item
5262 * NOTE: native doesn't do this, but that is a bug */
5264 ScreenToClient(hwnd
, &pt
);
5265 nHit
= TOOLBAR_InternalHitTest(hwnd
, &pt
);
5266 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5268 /* remove any left mouse button down messages so that we can
5269 * get a toggle effect on the button */
5270 while (PeekMessageW(&msg
, hwnd
, WM_LBUTTONDOWN
, WM_LBUTTONDOWN
, PM_REMOVE
))
5275 /* otherwise drop through and process as pushed */
5277 infoPtr
->bCaptured
= TRUE
;
5278 infoPtr
->nButtonDown
= nHit
;
5280 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5282 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5284 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5285 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5289 /* native issues the TBN_BEGINDRAG here */
5290 nmtb
.iItem
= btnPtr
->idCommand
;
5291 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
5292 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
5293 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
5294 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
5295 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
5296 nmtb
.tbButton
.iString
= btnPtr
->iString
;
5297 nmtb
.cchText
= 0; /* !!! not correct */
5298 nmtb
.pszText
= 0; /* !!! not correct */
5299 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5307 TOOLBAR_LButtonUp (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5309 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5310 TBUTTON_INFO
*btnPtr
;
5314 BOOL bSendMessage
= TRUE
;
5319 if (infoPtr
->hwndToolTip
)
5320 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5321 WM_LBUTTONUP
, wParam
, lParam
);
5323 pt
.x
= (INT
)LOWORD(lParam
);
5324 pt
.y
= (INT
)HIWORD(lParam
);
5325 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5327 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
| HICF_LMOUSE
);
5329 if (0 <= infoPtr
->nButtonDown
) {
5330 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5331 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5333 if (btnPtr
->fsStyle
& BTNS_CHECK
) {
5334 if (btnPtr
->fsStyle
& BTNS_GROUP
) {
5335 nOldIndex
= TOOLBAR_GetCheckedGroupButtonIndex (infoPtr
,
5337 if (nOldIndex
== nHit
)
5338 bSendMessage
= FALSE
;
5339 if ((nOldIndex
!= nHit
) &&
5341 infoPtr
->buttons
[nOldIndex
].fsState
&= ~TBSTATE_CHECKED
;
5342 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5345 if (btnPtr
->fsState
& TBSTATE_CHECKED
)
5346 btnPtr
->fsState
&= ~TBSTATE_CHECKED
;
5348 btnPtr
->fsState
|= TBSTATE_CHECKED
;
5352 if (nOldIndex
!= -1)
5353 InvalidateRect(hwnd
, &infoPtr
->buttons
[nOldIndex
].rect
, TRUE
);
5356 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5357 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5358 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5360 if ((infoPtr
->bCaptured
) && (infoPtr
->nButtonDown
>= 0))
5362 infoPtr
->nButtonDown
= -1;
5364 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5365 TOOLBAR_SendNotify ((NMHDR
*) &hdr
, infoPtr
,
5366 NM_RELEASEDCAPTURE
);
5368 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5371 nmtb
.iItem
= btnPtr
->idCommand
;
5372 nmtb
.tbButton
.iBitmap
= btnPtr
->iBitmap
;
5373 nmtb
.tbButton
.idCommand
= btnPtr
->idCommand
;
5374 nmtb
.tbButton
.fsState
= btnPtr
->fsState
;
5375 nmtb
.tbButton
.fsStyle
= btnPtr
->fsStyle
;
5376 nmtb
.tbButton
.dwData
= btnPtr
->dwData
;
5377 nmtb
.tbButton
.iString
= btnPtr
->iString
;
5378 nmtb
.cchText
= 0; /* !!! not correct */
5379 nmtb
.pszText
= 0; /* !!! not correct */
5380 TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
,
5383 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5385 SendMessageA (infoPtr
->hwndNotify
, WM_COMMAND
,
5386 MAKEWPARAM(infoPtr
->buttons
[nHit
].idCommand
, 0), (LPARAM
)hwnd
);
5388 /* !!! Undocumented - toolbar at 4.71 level and above sends
5389 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
5390 * Only NM_RCLICK is documented.
5392 nmmouse
.dwItemSpec
= btnPtr
->idCommand
;
5393 nmmouse
.dwItemData
= btnPtr
->dwData
;
5394 TOOLBAR_SendNotify ((NMHDR
*) &nmmouse
, infoPtr
, NM_CLICK
);
5401 TOOLBAR_CaptureChanged(HWND hwnd
)
5403 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5404 TBUTTON_INFO
*btnPtr
;
5406 infoPtr
->bCaptured
= FALSE
;
5408 if (infoPtr
->nButtonDown
>= 0)
5410 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5411 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5413 infoPtr
->nOldHit
= -1;
5415 if (btnPtr
->fsState
& TBSTATE_ENABLED
)
5416 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5422 TOOLBAR_MouseLeave (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5424 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5425 TBUTTON_INFO
*hotBtnPtr
, *btnPtr
;
5428 TOOLBAR_SetHotItemEx(infoPtr
, -1, HICF_MOUSE
);
5430 if (infoPtr
->nOldHit
< 0)
5433 hotBtnPtr
= &infoPtr
->buttons
[infoPtr
->nOldHit
];
5435 /* If the last button we were over is depressed then make it not */
5436 /* depressed and redraw it */
5437 if(infoPtr
->nOldHit
== infoPtr
->nButtonDown
)
5439 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5441 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5443 rc1
= hotBtnPtr
->rect
;
5444 InflateRect (&rc1
, 1, 1);
5445 InvalidateRect (hwnd
, &rc1
, TRUE
);
5448 infoPtr
->nOldHit
= -1; /* reset the old hit index as we've left the toolbar */
5454 TOOLBAR_MouseMove (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5456 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5458 TRACKMOUSEEVENT trackinfo
;
5460 TBUTTON_INFO
*btnPtr
;
5462 /* fill in the TRACKMOUSEEVENT struct */
5463 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5464 trackinfo
.dwFlags
= TME_QUERY
;
5465 trackinfo
.hwndTrack
= hwnd
;
5466 trackinfo
.dwHoverTime
= HOVER_DEFAULT
;
5468 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5469 _TrackMouseEvent(&trackinfo
);
5471 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5472 if(!(trackinfo
.dwFlags
& TME_LEAVE
)) {
5473 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5475 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5476 /* and can properly deactivate the hot toolbar button */
5477 _TrackMouseEvent(&trackinfo
);
5480 if (infoPtr
->hwndToolTip
)
5481 TOOLBAR_RelayEvent (infoPtr
->hwndToolTip
, hwnd
,
5482 WM_MOUSEMOVE
, wParam
, lParam
);
5484 pt
.x
= (INT
)LOWORD(lParam
);
5485 pt
.y
= (INT
)HIWORD(lParam
);
5487 nHit
= TOOLBAR_InternalHitTest (hwnd
, &pt
);
5489 TOOLBAR_SetHotItemEx(infoPtr
, nHit
, HICF_MOUSE
);
5491 if (infoPtr
->nOldHit
!= nHit
)
5493 if (infoPtr
->bCaptured
)
5495 btnPtr
= &infoPtr
->buttons
[infoPtr
->nButtonDown
];
5496 if (infoPtr
->nOldHit
== infoPtr
->nButtonDown
) {
5497 btnPtr
->fsState
&= ~TBSTATE_PRESSED
;
5498 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5500 else if (nHit
== infoPtr
->nButtonDown
) {
5501 btnPtr
->fsState
|= TBSTATE_PRESSED
;
5502 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
5504 infoPtr
->nOldHit
= nHit
;
5512 inline static LRESULT
5513 TOOLBAR_NCActivate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5515 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5516 return DefWindowProcA (hwnd
, WM_NCACTIVATE
, wParam
, lParam
);
5518 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5522 inline static LRESULT
5523 TOOLBAR_NCCalcSize (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5525 if (!(GetWindowLongA (hwnd
, GWL_STYLE
) & CCS_NODIVIDER
))
5526 ((LPRECT
)lParam
)->top
+= GetSystemMetrics(SM_CYEDGE
);
5528 return DefWindowProcA (hwnd
, WM_NCCALCSIZE
, wParam
, lParam
);
5533 TOOLBAR_NCCreate (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5535 TOOLBAR_INFO
*infoPtr
;
5536 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
5539 /* allocate memory for info structure */
5540 infoPtr
= (TOOLBAR_INFO
*)Alloc (sizeof(TOOLBAR_INFO
));
5541 SetWindowLongA (hwnd
, 0, (DWORD
)infoPtr
);
5544 infoPtr
->dwStructSize
= sizeof(TBBUTTON
);
5547 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5548 if (!GetWindowLongA (hwnd
, GWL_HINSTANCE
)) {
5549 HINSTANCE hInst
= (HINSTANCE
)GetWindowLongA (GetParent (hwnd
), GWL_HINSTANCE
);
5550 SetWindowLongA (hwnd
, GWL_HINSTANCE
, (DWORD
)hInst
);
5553 /* native control does:
5554 * Get a lot of colors and brushes
5556 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5557 * CreateFontIndirectA(adr1)
5558 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5559 * hdc = GetDC(toolbar)
5560 * GetSystemMetrics(0x48)
5561 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5562 * 0, 0, 0, 0, "MARLETT")
5563 * oldfnt = SelectObject(hdc, fnt2)
5564 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5565 * GetTextMetricsA(hdc, adr3)
5566 * SelectObject(hdc, oldfnt)
5567 * DeleteObject(fnt2)
5569 * InvalidateRect(toolbar, 0, 1)
5570 * SetWindowLongA(toolbar, 0, addr)
5571 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5574 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5575 * ie 2 0x4600094c 0x4600094c 0x4600894d
5576 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5577 * rebar 0x50008844 0x40008844 0x50008845
5578 * pager 0x50000844 0x40000844 0x50008845
5579 * IC35mgr 0x5400084e **nochange**
5580 * on entry to _NCCREATE 0x5400084e
5581 * rowlist 0x5400004e **nochange**
5582 * on entry to _NCCREATE 0x5400004e
5586 /* I think the code below is a bug, but it is the way that the native
5587 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5588 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5589 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5590 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5591 * Some how, the only cases of this seem to be MFC programs.
5593 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5594 * does not occur in the WM_STYLECHANGING routine.
5595 * (Guy Albertelli 9/2001)
5598 if ((cs
->style
& TBSTYLE_FLAT
) && !(cs
->style
& TBSTYLE_TRANSPARENT
))
5599 styleadd
|= TBSTYLE_TRANSPARENT
;
5600 if (!(cs
->style
& (CCS_TOP
| CCS_NOMOVEY
))) {
5601 styleadd
|= CCS_TOP
; /* default to top */
5602 SetWindowLongA (hwnd
, GWL_STYLE
, cs
->style
| styleadd
);
5605 return DefWindowProcA (hwnd
, WM_NCCREATE
, wParam
, lParam
);
5610 TOOLBAR_NCPaint (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5612 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
5616 if (dwStyle
& WS_MINIMIZE
)
5617 return 0; /* Nothing to do */
5619 DefWindowProcA (hwnd
, WM_NCPAINT
, wParam
, lParam
);
5621 if (!(hdc
= GetDCEx (hwnd
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
5624 if (!(dwStyle
& CCS_NODIVIDER
))
5626 GetWindowRect (hwnd
, &rcWindow
);
5627 OffsetRect (&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
5628 if( dwStyle
& WS_BORDER
)
5629 OffsetRect (&rcWindow
, 1, 1);
5630 DrawEdge (hdc
, &rcWindow
, EDGE_ETCHED
, BF_TOP
);
5633 ReleaseDC( hwnd
, hdc
);
5639 /* handles requests from the tooltip control on what text to display */
5640 static LRESULT
TOOLBAR_TTGetDispInfo (TOOLBAR_INFO
*infoPtr
, NMTTDISPINFOW
*lpnmtdi
)
5642 int index
= TOOLBAR_GetButtonIndex(infoPtr
, lpnmtdi
->hdr
.idFrom
, FALSE
);
5644 TRACE("button index = %d\n", index
);
5646 if (infoPtr
->pszTooltipText
)
5648 HeapFree(GetProcessHeap(), 0, infoPtr
->pszTooltipText
);
5649 infoPtr
->pszTooltipText
= NULL
;
5655 if (infoPtr
->bNtfUnicode
)
5657 WCHAR wszBuffer
[INFOTIPSIZE
+1];
5658 NMTBGETINFOTIPW tbgit
;
5659 int len
; /* in chars */
5661 wszBuffer
[0] = '\0';
5662 wszBuffer
[INFOTIPSIZE
] = '\0';
5664 tbgit
.pszText
= wszBuffer
;
5665 tbgit
.cchTextMax
= INFOTIPSIZE
;
5666 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
5667 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
5669 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPW
);
5671 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit
.pszText
));
5673 len
= strlenW(tbgit
.pszText
);
5674 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
5676 /* need to allocate temporary buffer in infoPtr as there
5677 * isn't enough space in buffer passed to us by the
5678 * tooltip control */
5679 infoPtr
->pszTooltipText
= HeapAlloc(GetProcessHeap(), 0, (len
+1)*sizeof(WCHAR
));
5680 if (infoPtr
->pszTooltipText
)
5682 memcpy(infoPtr
->pszTooltipText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
5683 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
5689 memcpy(lpnmtdi
->lpszText
, tbgit
.pszText
, (len
+1)*sizeof(WCHAR
));
5695 CHAR szBuffer
[INFOTIPSIZE
+1];
5696 NMTBGETINFOTIPA tbgit
;
5697 int len
; /* in chars */
5700 szBuffer
[INFOTIPSIZE
] = '\0';
5702 tbgit
.pszText
= szBuffer
;
5703 tbgit
.cchTextMax
= INFOTIPSIZE
;
5704 tbgit
.iItem
= lpnmtdi
->hdr
.idFrom
;
5705 tbgit
.lParam
= infoPtr
->buttons
[index
].dwData
;
5707 TOOLBAR_SendNotify(&tbgit
.hdr
, infoPtr
, TBN_GETINFOTIPA
);
5709 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit
.pszText
));
5711 len
= -1 + MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, -1, NULL
, 0);
5712 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
5714 /* need to allocate temporary buffer in infoPtr as there
5715 * isn't enough space in buffer passed to us by the
5716 * tooltip control */
5717 infoPtr
->pszTooltipText
= HeapAlloc(GetProcessHeap(), 0, (len
+1)*sizeof(WCHAR
));
5718 if (infoPtr
->pszTooltipText
)
5720 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, len
+1, infoPtr
->pszTooltipText
, (len
+1)*sizeof(WCHAR
));
5721 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
5727 MultiByteToWideChar(CP_ACP
, 0, tbgit
.pszText
, len
+1, lpnmtdi
->lpszText
, (len
+1)*sizeof(WCHAR
));
5732 /* if button has text, but it is not shown then automatically
5733 * use that text as tooltip */
5734 if ((infoPtr
->dwExStyle
& TBSTYLE_EX_MIXEDBUTTONS
) &&
5735 !(infoPtr
->buttons
[index
].fsStyle
& BTNS_SHOWTEXT
))
5737 LPWSTR pszText
= TOOLBAR_GetText(infoPtr
, &infoPtr
->buttons
[index
]);
5738 int len
= pszText
? strlenW(pszText
) : 0;
5740 TRACE("using button hidden text %s\n", debugstr_w(pszText
));
5742 if (len
> sizeof(lpnmtdi
->szText
)/sizeof(lpnmtdi
->szText
[0])-1)
5744 /* need to allocate temporary buffer in infoPtr as there
5745 * isn't enough space in buffer passed to us by the
5746 * tooltip control */
5747 infoPtr
->pszTooltipText
= HeapAlloc(GetProcessHeap(), 0, (len
+1)*sizeof(WCHAR
));
5748 if (infoPtr
->pszTooltipText
)
5750 memcpy(infoPtr
->pszTooltipText
, pszText
, (len
+1)*sizeof(WCHAR
));
5751 lpnmtdi
->lpszText
= infoPtr
->pszTooltipText
;
5757 memcpy(lpnmtdi
->lpszText
, pszText
, (len
+1)*sizeof(WCHAR
));
5762 TRACE("Sending tooltip notification to %p\n", infoPtr
->hwndNotify
);
5764 /* last resort: send notification on to app */
5765 /* FIXME: find out what is really used here */
5766 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, 0, (LPARAM
)lpnmtdi
);
5770 inline static LRESULT
5771 TOOLBAR_Notify (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5773 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5774 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
5776 switch (lpnmh
->code
)
5780 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
5782 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
5783 lppgc
->iWidth
= infoPtr
->rcBound
.right
- infoPtr
->rcBound
.left
;
5784 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
5788 lppgc
->iHeight
= infoPtr
->rcBound
.bottom
- infoPtr
->rcBound
.top
;
5789 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
5797 LPNMPGSCROLL lppgs
= (LPNMPGSCROLL
)lParam
;
5799 lppgs
->iScroll
= (lppgs
->iDir
& (PGF_SCROLLLEFT
| PGF_SCROLLRIGHT
)) ?
5800 infoPtr
->nButtonWidth
: infoPtr
->nButtonHeight
;
5801 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
5802 lppgs
->iScroll
, lppgs
->iDir
);
5806 case TTN_GETDISPINFOW
:
5807 return TOOLBAR_TTGetDispInfo(infoPtr
, (LPNMTTDISPINFOW
)lParam
);
5809 case TTN_GETDISPINFOA
:
5810 FIXME("TTN_GETDISPINFOA - stub\n");
5820 TOOLBAR_NotifyFormatFake(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5822 /* remove this routine when Toolbar is improved to pass infoPtr
5823 * around instead of hwnd.
5825 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5826 return TOOLBAR_NotifyFormat(infoPtr
, wParam
, lParam
);
5831 TOOLBAR_NotifyFormat(TOOLBAR_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5835 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam
, lParam
);
5837 if ((lParam
== NF_QUERY
) && ((HWND
)wParam
== infoPtr
->hwndToolTip
))
5840 if (lParam
== NF_REQUERY
) {
5841 i
= SendMessageA(infoPtr
->hwndNotify
,
5842 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
5843 if ((i
< NFR_ANSI
) || (i
> NFR_UNICODE
)) {
5844 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
5848 infoPtr
->bNtfUnicode
= (i
== NFR_UNICODE
) ? 1 : 0;
5851 return (LRESULT
)((infoPtr
->bUnicode
) ? NFR_UNICODE
: NFR_ANSI
);
5856 TOOLBAR_Paint (HWND hwnd
, WPARAM wParam
)
5858 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr(hwnd
);
5862 /* fill ps.rcPaint with a default rect */
5863 memcpy(&(ps
.rcPaint
), &(infoPtr
->rcBound
), sizeof(infoPtr
->rcBound
));
5865 hdc
= wParam
==0 ? BeginPaint(hwnd
, &ps
) : (HDC
)wParam
;
5867 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
5868 ps
.rcPaint
.left
, ps
.rcPaint
.top
,
5869 ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
5871 TOOLBAR_Refresh (hwnd
, hdc
, &ps
);
5872 if (!wParam
) EndPaint (hwnd
, &ps
);
5879 TOOLBAR_SetRedraw (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5880 /*****************************************************
5883 * Handles the WM_SETREDRAW message.
5886 * According to testing V4.71 of COMCTL32 returns the
5887 * *previous* status of the redraw flag (either 0 or 1)
5888 * instead of the MSDN documented value of 0 if handled.
5889 * (For laughs see the "consistency" with same function
5892 *****************************************************/
5894 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5895 BOOL oldredraw
= infoPtr
->bDoRedraw
;
5897 TRACE("set to %s\n",
5898 (wParam
) ? "TRUE" : "FALSE");
5899 infoPtr
->bDoRedraw
= (BOOL
) wParam
;
5901 InvalidateRect (infoPtr
->hwndSelf
, 0, TRUE
);
5903 return (oldredraw
) ? 1 : 0;
5908 TOOLBAR_Size (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
5910 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
5911 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
5920 /* Resize deadlock check */
5921 if (infoPtr
->bAutoSize
) {
5922 infoPtr
->bAutoSize
= FALSE
;
5926 /* FIXME: optimize to only update size if the new size doesn't */
5927 /* match the current size */
5929 flags
= (INT
) wParam
;
5931 /* FIXME for flags =
5932 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
5935 TRACE("sizing toolbar!\n");
5937 if (flags
== SIZE_RESTORED
) {
5938 /* width and height don't apply */
5939 parent
= GetParent (hwnd
);
5940 GetClientRect(parent
, &parent_rect
);
5941 x
= parent_rect
.left
;
5942 y
= parent_rect
.top
;
5944 if (dwStyle
& CCS_NORESIZE
) {
5945 uPosFlags
|= (SWP_NOSIZE
| SWP_NOMOVE
);
5948 * this sets the working width of the toolbar, and
5949 * Calc Toolbar will not adjust it, only the height
5951 infoPtr
->nWidth
= parent_rect
.right
- parent_rect
.left
;
5952 cy
= infoPtr
->nHeight
;
5953 cx
= infoPtr
->nWidth
;
5954 TOOLBAR_CalcToolbar (hwnd
);
5955 infoPtr
->nWidth
= cx
;
5956 infoPtr
->nHeight
= cy
;
5959 infoPtr
->nWidth
= parent_rect
.right
- parent_rect
.left
;
5960 TOOLBAR_CalcToolbar (hwnd
);
5961 cy
= infoPtr
->nHeight
;
5962 cx
= infoPtr
->nWidth
;
5964 if ((dwStyle
& CCS_BOTTOM
) == CCS_NOMOVEY
) {
5965 GetWindowRect(hwnd
, &window_rect
);
5966 ScreenToClient(parent
, (LPPOINT
)&window_rect
.left
);
5967 y
= window_rect
.top
;
5969 if ((dwStyle
& CCS_BOTTOM
) == CCS_BOTTOM
) {
5970 GetWindowRect(hwnd
, &window_rect
);
5971 y
= parent_rect
.bottom
-
5972 ( window_rect
.bottom
- window_rect
.top
);
5976 if (dwStyle
& CCS_NOPARENTALIGN
) {
5977 uPosFlags
|= SWP_NOMOVE
;
5978 cy
= infoPtr
->nHeight
;
5979 cx
= infoPtr
->nWidth
;
5982 if (!(dwStyle
& CCS_NODIVIDER
))
5983 cy
+= GetSystemMetrics(SM_CYEDGE
);
5985 if (dwStyle
& WS_BORDER
)
5988 cy
+= GetSystemMetrics(SM_CYEDGE
);
5989 cx
+= GetSystemMetrics(SM_CYEDGE
);
5992 if(infoPtr
->dwExStyle
& TBSTYLE_EX_HIDECLIPPEDBUTTONS
)
5994 RECT delta_width
, delta_height
, client
, dummy
;
5995 DWORD min_x
, max_x
, min_y
, max_y
;
5996 TBUTTON_INFO
*btnPtr
;
5999 GetClientRect(hwnd
, &client
);
6000 if(client
.right
> infoPtr
->client_rect
.right
)
6002 min_x
= infoPtr
->client_rect
.right
;
6003 max_x
= client
.right
;
6007 max_x
= infoPtr
->client_rect
.right
;
6008 min_x
= client
.right
;
6010 if(client
.bottom
> infoPtr
->client_rect
.bottom
)
6012 min_y
= infoPtr
->client_rect
.bottom
;
6013 max_y
= client
.bottom
;
6017 max_y
= infoPtr
->client_rect
.bottom
;
6018 min_y
= client
.bottom
;
6021 SetRect(&delta_width
, min_x
, 0, max_x
, min_y
);
6022 SetRect(&delta_height
, 0, min_y
, max_x
, max_y
);
6024 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width
), wine_dbgstr_rect(&delta_height
));
6025 btnPtr
= infoPtr
->buttons
;
6026 for (i
= 0; i
< infoPtr
->nNumButtons
; i
++, btnPtr
++)
6027 if(IntersectRect(&dummy
, &delta_width
, &btnPtr
->rect
) ||
6028 IntersectRect(&dummy
, &delta_height
, &btnPtr
->rect
))
6029 InvalidateRect(hwnd
, &btnPtr
->rect
, TRUE
);
6032 if((uPosFlags
& (SWP_NOSIZE
| SWP_NOMOVE
)) == (SWP_NOSIZE
| SWP_NOMOVE
))
6033 SetWindowPos (hwnd
, 0, x
, y
, cx
, cy
, uPosFlags
| SWP_NOZORDER
);
6035 GetClientRect(hwnd
, &infoPtr
->client_rect
);
6041 TOOLBAR_StyleChanged (HWND hwnd
, INT nType
, LPSTYLESTRUCT lpStyle
)
6043 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6045 if (nType
== GWL_STYLE
) {
6046 if (lpStyle
->styleNew
& TBSTYLE_LIST
) {
6047 infoPtr
->dwDTFlags
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
;
6050 infoPtr
->dwDTFlags
= DT_CENTER
;
6052 infoPtr
->bTransparent
= (lpStyle
->styleNew
& TBSTYLE_TRANSPARENT
);
6053 infoPtr
->bBtnTranspnt
= (lpStyle
->styleNew
&
6054 (TBSTYLE_FLAT
| TBSTYLE_LIST
));
6055 TOOLBAR_CheckStyle (hwnd
, lpStyle
->styleNew
);
6057 TRACE("new style 0x%08lx\n", lpStyle
->styleNew
);
6060 TOOLBAR_CalcToolbar(hwnd
);
6062 TOOLBAR_AutoSize (hwnd
);
6064 InvalidateRect(hwnd
, NULL
, TRUE
);
6071 TOOLBAR_SysColorChange (HWND hwnd
)
6073 COMCTL32_RefreshSysColors();
6080 static LRESULT WINAPI
6081 ToolbarWindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6083 TOOLBAR_INFO
*infoPtr
= TOOLBAR_GetInfoPtr (hwnd
);
6085 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6086 hwnd
, uMsg
, /* SPY_GetMsgName(uMsg), */ wParam
, lParam
);
6088 if (!TOOLBAR_GetInfoPtr(hwnd
) && (uMsg
!= WM_NCCREATE
))
6089 return DefWindowProcA( hwnd
, uMsg
, wParam
, lParam
);
6094 return TOOLBAR_AddBitmap (hwnd
, wParam
, lParam
);
6096 case TB_ADDBUTTONSA
:
6097 return TOOLBAR_AddButtonsA (hwnd
, wParam
, lParam
);
6099 case TB_ADDBUTTONSW
:
6100 return TOOLBAR_AddButtonsW (hwnd
, wParam
, lParam
);
6103 return TOOLBAR_AddStringA (hwnd
, wParam
, lParam
);
6106 return TOOLBAR_AddStringW (hwnd
, wParam
, lParam
);
6109 return TOOLBAR_AutoSize (hwnd
);
6111 case TB_BUTTONCOUNT
:
6112 return TOOLBAR_ButtonCount (hwnd
, wParam
, lParam
);
6114 case TB_BUTTONSTRUCTSIZE
:
6115 return TOOLBAR_ButtonStructSize (hwnd
, wParam
, lParam
);
6117 case TB_CHANGEBITMAP
:
6118 return TOOLBAR_ChangeBitmap (hwnd
, wParam
, lParam
);
6120 case TB_CHECKBUTTON
:
6121 return TOOLBAR_CheckButton (hwnd
, wParam
, lParam
);
6123 case TB_COMMANDTOINDEX
:
6124 return TOOLBAR_CommandToIndex (hwnd
, wParam
, lParam
);
6127 return TOOLBAR_Customize (hwnd
);
6129 case TB_DELETEBUTTON
:
6130 return TOOLBAR_DeleteButton (hwnd
, wParam
, lParam
);
6132 case TB_ENABLEBUTTON
:
6133 return TOOLBAR_EnableButton (hwnd
, wParam
, lParam
);
6135 case TB_GETANCHORHIGHLIGHT
:
6136 return TOOLBAR_GetAnchorHighlight (hwnd
);
6139 return TOOLBAR_GetBitmap (hwnd
, wParam
, lParam
);
6141 case TB_GETBITMAPFLAGS
:
6142 return TOOLBAR_GetBitmapFlags (hwnd
, wParam
, lParam
);
6145 return TOOLBAR_GetButton (hwnd
, wParam
, lParam
);
6147 case TB_GETBUTTONINFOA
:
6148 return TOOLBAR_GetButtonInfoA (hwnd
, wParam
, lParam
);
6150 case TB_GETBUTTONINFOW
:
6151 return TOOLBAR_GetButtonInfoW (hwnd
, wParam
, lParam
);
6153 case TB_GETBUTTONSIZE
:
6154 return TOOLBAR_GetButtonSize (hwnd
);
6156 case TB_GETBUTTONTEXTA
:
6157 return TOOLBAR_GetButtonTextA (hwnd
, wParam
, lParam
);
6159 case TB_GETBUTTONTEXTW
:
6160 return TOOLBAR_GetButtonTextW (hwnd
, wParam
, lParam
);
6162 case TB_GETDISABLEDIMAGELIST
:
6163 return TOOLBAR_GetDisabledImageList (hwnd
, wParam
, lParam
);
6165 case TB_GETEXTENDEDSTYLE
:
6166 return TOOLBAR_GetExtendedStyle (hwnd
);
6168 case TB_GETHOTIMAGELIST
:
6169 return TOOLBAR_GetHotImageList (hwnd
, wParam
, lParam
);
6172 return TOOLBAR_GetHotItem (hwnd
);
6174 case TB_GETIMAGELIST
:
6175 return TOOLBAR_GetDefImageList (hwnd
, wParam
, lParam
);
6177 /* case TB_GETINSERTMARK: */ /* 4.71 */
6178 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
6180 case TB_GETITEMRECT
:
6181 return TOOLBAR_GetItemRect (hwnd
, wParam
, lParam
);
6184 return TOOLBAR_GetMaxSize (hwnd
, wParam
, lParam
);
6186 /* case TB_GETOBJECT: */ /* 4.71 */
6189 return TOOLBAR_GetPadding (hwnd
);
6192 return TOOLBAR_GetRect (hwnd
, wParam
, lParam
);
6195 return TOOLBAR_GetRows (hwnd
, wParam
, lParam
);
6198 return TOOLBAR_GetState (hwnd
, wParam
, lParam
);
6201 return TOOLBAR_GetStringA (hwnd
, wParam
, lParam
);
6204 return TOOLBAR_GetStringW (hwnd
, wParam
, lParam
);
6207 return TOOLBAR_GetStyle (hwnd
, wParam
, lParam
);
6209 case TB_GETTEXTROWS
:
6210 return TOOLBAR_GetTextRows (hwnd
, wParam
, lParam
);
6212 case TB_GETTOOLTIPS
:
6213 return TOOLBAR_GetToolTips (hwnd
, wParam
, lParam
);
6215 case TB_GETUNICODEFORMAT
:
6216 return TOOLBAR_GetUnicodeFormat (hwnd
, wParam
, lParam
);
6219 return TOOLBAR_HideButton (hwnd
, wParam
, lParam
);
6222 return TOOLBAR_HitTest (hwnd
, wParam
, lParam
);
6224 case TB_INDETERMINATE
:
6225 return TOOLBAR_Indeterminate (hwnd
, wParam
, lParam
);
6227 case TB_INSERTBUTTONA
:
6228 return TOOLBAR_InsertButtonA (hwnd
, wParam
, lParam
);
6230 case TB_INSERTBUTTONW
:
6231 return TOOLBAR_InsertButtonW (hwnd
, wParam
, lParam
);
6233 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6235 case TB_ISBUTTONCHECKED
:
6236 return TOOLBAR_IsButtonChecked (hwnd
, wParam
, lParam
);
6238 case TB_ISBUTTONENABLED
:
6239 return TOOLBAR_IsButtonEnabled (hwnd
, wParam
, lParam
);
6241 case TB_ISBUTTONHIDDEN
:
6242 return TOOLBAR_IsButtonHidden (hwnd
, wParam
, lParam
);
6244 case TB_ISBUTTONHIGHLIGHTED
:
6245 return TOOLBAR_IsButtonHighlighted (hwnd
, wParam
, lParam
);
6247 case TB_ISBUTTONINDETERMINATE
:
6248 return TOOLBAR_IsButtonIndeterminate (hwnd
, wParam
, lParam
);
6250 case TB_ISBUTTONPRESSED
:
6251 return TOOLBAR_IsButtonPressed (hwnd
, wParam
, lParam
);
6254 return TOOLBAR_LoadImages (hwnd
, wParam
, lParam
);
6256 case TB_MAPACCELERATORA
:
6257 case TB_MAPACCELERATORW
:
6258 return TOOLBAR_MapAccelerator (hwnd
, wParam
, lParam
);
6261 return TOOLBAR_MarkButton (hwnd
, wParam
, lParam
);
6263 /* case TB_MOVEBUTTON: */ /* 4.71 */
6265 case TB_PRESSBUTTON
:
6266 return TOOLBAR_PressButton (hwnd
, wParam
, lParam
);
6268 case TB_REPLACEBITMAP
:
6269 return TOOLBAR_ReplaceBitmap (hwnd
, wParam
, lParam
);
6271 case TB_SAVERESTOREA
:
6272 return TOOLBAR_SaveRestoreA (hwnd
, wParam
, lParam
);
6274 case TB_SAVERESTOREW
:
6275 return TOOLBAR_SaveRestoreW (hwnd
, wParam
, lParam
);
6277 case TB_SETANCHORHIGHLIGHT
:
6278 return TOOLBAR_SetAnchorHighlight (hwnd
, wParam
);
6280 case TB_SETBITMAPSIZE
:
6281 return TOOLBAR_SetBitmapSize (hwnd
, wParam
, lParam
);
6283 case TB_SETBUTTONINFOA
:
6284 return TOOLBAR_SetButtonInfoA (hwnd
, wParam
, lParam
);
6286 case TB_SETBUTTONINFOW
:
6287 return TOOLBAR_SetButtonInfoW (hwnd
, wParam
, lParam
);
6289 case TB_SETBUTTONSIZE
:
6290 return TOOLBAR_SetButtonSize (hwnd
, wParam
, lParam
);
6292 case TB_SETBUTTONWIDTH
:
6293 return TOOLBAR_SetButtonWidth (hwnd
, wParam
, lParam
);
6296 return TOOLBAR_SetCmdId (hwnd
, wParam
, lParam
);
6298 case TB_SETDISABLEDIMAGELIST
:
6299 return TOOLBAR_SetDisabledImageList (hwnd
, wParam
, lParam
);
6301 case TB_SETDRAWTEXTFLAGS
:
6302 return TOOLBAR_SetDrawTextFlags (hwnd
, wParam
, lParam
);
6304 case TB_SETEXTENDEDSTYLE
:
6305 return TOOLBAR_SetExtendedStyle (hwnd
, wParam
, lParam
);
6307 case TB_SETHOTIMAGELIST
:
6308 return TOOLBAR_SetHotImageList (hwnd
, wParam
, lParam
);
6311 return TOOLBAR_SetHotItem (hwnd
, wParam
);
6313 case TB_SETIMAGELIST
:
6314 return TOOLBAR_SetImageList (hwnd
, wParam
, lParam
);
6317 return TOOLBAR_SetIndent (hwnd
, wParam
, lParam
);
6319 /* case TB_SETINSERTMARK: */ /* 4.71 */
6321 case TB_SETINSERTMARKCOLOR
:
6322 return TOOLBAR_SetInsertMarkColor (hwnd
, wParam
, lParam
);
6324 case TB_SETMAXTEXTROWS
:
6325 return TOOLBAR_SetMaxTextRows (hwnd
, wParam
, lParam
);
6328 return TOOLBAR_SetPadding (hwnd
, wParam
, lParam
);
6331 return TOOLBAR_SetParent (hwnd
, wParam
, lParam
);
6334 return TOOLBAR_SetRows (hwnd
, wParam
, lParam
);
6337 return TOOLBAR_SetState (hwnd
, wParam
, lParam
);
6340 return TOOLBAR_SetStyle (hwnd
, wParam
, lParam
);
6342 case TB_SETTOOLTIPS
:
6343 return TOOLBAR_SetToolTips (hwnd
, wParam
, lParam
);
6345 case TB_SETUNICODEFORMAT
:
6346 return TOOLBAR_SetUnicodeFormat (hwnd
, wParam
, lParam
);
6349 return TOOLBAR_Unkwn45D(hwnd
, wParam
, lParam
);
6352 return TOOLBAR_Unkwn45E (hwnd
, wParam
, lParam
);
6355 return TOOLBAR_Unkwn460(hwnd
, wParam
, lParam
);
6358 return TOOLBAR_Unkwn462(hwnd
, wParam
, lParam
);
6361 return TOOLBAR_Unkwn463 (hwnd
, wParam
, lParam
);
6364 return TOOLBAR_Unkwn464(hwnd
, wParam
, lParam
);
6366 /* Common Control Messages */
6368 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6369 case CCM_GETCOLORSCHEME
:
6370 return TOOLBAR_GetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
6372 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6373 case CCM_SETCOLORSCHEME
:
6374 return TOOLBAR_SetColorScheme (hwnd
, (LPCOLORSCHEME
)lParam
);
6376 case CCM_GETVERSION
:
6377 return TOOLBAR_GetVersion (hwnd
);
6379 case CCM_SETVERSION
:
6380 return TOOLBAR_SetVersion (hwnd
, (INT
)wParam
);
6386 return TOOLBAR_Create (hwnd
, wParam
, lParam
);
6389 return TOOLBAR_Destroy (hwnd
, wParam
, lParam
);
6392 return TOOLBAR_EraseBackground (hwnd
, wParam
, lParam
);
6395 return TOOLBAR_GetFont (hwnd
, wParam
, lParam
);
6397 /* case WM_KEYDOWN: */
6398 /* case WM_KILLFOCUS: */
6400 case WM_LBUTTONDBLCLK
:
6401 return TOOLBAR_LButtonDblClk (hwnd
, wParam
, lParam
);
6403 case WM_LBUTTONDOWN
:
6404 return TOOLBAR_LButtonDown (hwnd
, wParam
, lParam
);
6407 return TOOLBAR_LButtonUp (hwnd
, wParam
, lParam
);
6410 return TOOLBAR_MouseMove (hwnd
, wParam
, lParam
);
6413 return TOOLBAR_MouseLeave (hwnd
, wParam
, lParam
);
6415 case WM_CAPTURECHANGED
:
6416 return TOOLBAR_CaptureChanged(hwnd
);
6419 return TOOLBAR_NCActivate (hwnd
, wParam
, lParam
);
6422 return TOOLBAR_NCCalcSize (hwnd
, wParam
, lParam
);
6425 return TOOLBAR_NCCreate (hwnd
, wParam
, lParam
);
6428 return TOOLBAR_NCPaint (hwnd
, wParam
, lParam
);
6431 return TOOLBAR_Notify (hwnd
, wParam
, lParam
);
6433 case WM_NOTIFYFORMAT
:
6434 return TOOLBAR_NotifyFormatFake (hwnd
, wParam
, lParam
);
6437 return TOOLBAR_Paint (hwnd
, wParam
);
6440 return TOOLBAR_SetRedraw (hwnd
, wParam
, lParam
);
6443 return TOOLBAR_Size (hwnd
, wParam
, lParam
);
6445 case WM_STYLECHANGED
:
6446 return TOOLBAR_StyleChanged (hwnd
, (INT
)wParam
, (LPSTYLESTRUCT
)lParam
);
6448 case WM_SYSCOLORCHANGE
:
6449 return TOOLBAR_SysColorChange (hwnd
);
6451 /* case WM_WININICHANGE: */
6456 case WM_MEASUREITEM
:
6458 return SendMessageA (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
6460 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6461 case PGM_FORWARDMOUSE
:
6462 return DefWindowProcA (hwnd
, uMsg
, wParam
, lParam
);
6465 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
6466 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6467 uMsg
, wParam
, lParam
);
6468 return DefWindowProcA (hwnd
, uMsg
, wParam
, lParam
);
6475 TOOLBAR_Register (void)
6479 ZeroMemory (&wndClass
, sizeof(WNDCLASSA
));
6480 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
6481 wndClass
.lpfnWndProc
= (WNDPROC
)ToolbarWindowProc
;
6482 wndClass
.cbClsExtra
= 0;
6483 wndClass
.cbWndExtra
= sizeof(TOOLBAR_INFO
*);
6484 wndClass
.hCursor
= LoadCursorA (0, (LPSTR
)IDC_ARROW
);
6485 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
6486 wndClass
.lpszClassName
= TOOLBARCLASSNAMEA
;
6488 RegisterClassA (&wndClass
);
6493 TOOLBAR_Unregister (void)
6495 UnregisterClassA (TOOLBARCLASSNAMEA
, NULL
);
6498 static HIMAGELIST
TOOLBAR_InsertImageList(PIMLENTRY
**pies
, INT
*cies
, HIMAGELIST himl
, INT id
)
6503 /* Check if the entry already exists */
6504 c
= TOOLBAR_GetImageListEntry(*pies
, *cies
, id
);
6506 /* If this is a new entry we must create it and insert into the array */
6511 c
= (PIMLENTRY
) Alloc(sizeof(IMLENTRY
));
6514 pnies
= Alloc((*cies
+ 1) * sizeof(PIMLENTRY
));
6515 memcpy(pnies
, *pies
, ((*cies
) * sizeof(PIMLENTRY
)));
6530 static VOID
TOOLBAR_DeleteImageList(PIMLENTRY
**pies
, INT
*cies
)
6534 for (i
= 0; i
< *cies
; i
++)
6544 static PIMLENTRY
TOOLBAR_GetImageListEntry(PIMLENTRY
*pies
, INT cies
, INT id
)
6552 for (i
= 0; i
< cies
; i
++)
6554 if (pies
[i
]->id
== id
)
6566 static HIMAGELIST
TOOLBAR_GetImageList(PIMLENTRY
*pies
, INT cies
, INT id
)
6568 HIMAGELIST himlDef
= 0;
6569 PIMLENTRY pie
= TOOLBAR_GetImageListEntry(pies
, cies
, id
);
6572 himlDef
= pie
->himl
;
6578 static BOOL
TOOLBAR_GetButtonInfo(TOOLBAR_INFO
*infoPtr
, NMTOOLBARW
*nmtb
)
6580 if (infoPtr
->bUnicode
)
6581 return TOOLBAR_SendNotify ((NMHDR
*) nmtb
, infoPtr
, TBN_GETBUTTONINFOW
);
6588 nmtba
.iItem
= nmtb
->iItem
;
6589 nmtba
.pszText
= Buffer
;
6590 nmtba
.cchText
= 256;
6591 ZeroMemory(nmtba
.pszText
, nmtba
.cchText
);
6593 if (TOOLBAR_SendNotify ((NMHDR
*) &nmtba
, infoPtr
, TBN_GETBUTTONINFOA
))
6595 int ccht
= strlen(nmtba
.pszText
);
6597 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)nmtba
.pszText
, -1,
6598 nmtb
->pszText
, nmtb
->cchText
);
6600 memcpy(&nmtb
->tbButton
, &nmtba
.tbButton
, sizeof(TBBUTTON
));
6609 static BOOL
TOOLBAR_IsButtonRemovable(TOOLBAR_INFO
*infoPtr
,
6610 int iItem
, PCUSTOMBUTTON btnInfo
)
6615 memcpy(&nmtb
.tbButton
, &btnInfo
->btn
, sizeof(TBBUTTON
));
6617 return TOOLBAR_SendNotify ((NMHDR
*) &nmtb
, infoPtr
, TBN_QUERYDELETE
);