gdiplus: Rendering of linecaps.
[wine.git] / dlls / comctl32 / toolbar.c
blob4b1e552cb34354cfe712442d94135345a5a1b36c
1 /*
2 * Toolbar control
4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * NOTES
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
31 * TODO:
32 * - Styles:
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
35 * - Messages:
36 * - TB_GETMETRICS
37 * - TB_GETOBJECT
38 * - TB_INSERTMARKHITTEST
39 * - TB_SAVERESTORE
40 * - TB_SETMETRICS
41 * - WM_WININICHANGE
42 * - Notifications:
43 * - NM_CHAR
44 * - TBN_GETOBJECT
45 * - TBN_SAVE
46 * - Button wrapping (under construction).
47 * - Fix TB_SETROWS.
48 * - iListGap custom draw support.
50 * Testing:
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
71 #include <stdarg.h>
72 #include <string.h>
74 #include "windef.h"
75 #include "winbase.h"
76 #include "winreg.h"
77 #include "wingdi.h"
78 #include "winuser.h"
79 #include "wine/unicode.h"
80 #include "winnls.h"
81 #include "commctrl.h"
82 #include "comctl32.h"
83 #include "uxtheme.h"
84 #include "tmschema.h"
85 #include "wine/debug.h"
87 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
89 static HCURSOR hCursorDrag = NULL;
91 typedef struct
93 INT iBitmap;
94 INT idCommand;
95 BYTE fsState;
96 BYTE fsStyle;
97 BYTE bHot;
98 BYTE bDropDownPressed;
99 DWORD_PTR dwData;
100 INT_PTR iString;
101 INT nRow;
102 RECT rect;
103 INT cx; /* manually set size */
104 } TBUTTON_INFO;
106 typedef struct
108 UINT nButtons;
109 HINSTANCE hInst;
110 UINT nID;
111 } TBITMAP_INFO;
113 typedef struct
115 HIMAGELIST himl;
116 INT id;
117 } IMLENTRY, *PIMLENTRY;
119 typedef struct
121 DWORD dwStructSize; /* size of TBBUTTON struct */
122 INT nWidth; /* width of the toolbar */
123 RECT client_rect;
124 RECT rcBound; /* bounding rectangle */
125 INT nButtonHeight;
126 INT nButtonWidth;
127 INT nBitmapHeight;
128 INT nBitmapWidth;
129 INT nIndent;
130 INT nRows; /* number of button rows */
131 INT nMaxTextRows; /* maximum number of text rows */
132 INT cxMin; /* minimum button width */
133 INT cxMax; /* maximum button width */
134 INT nNumButtons; /* number of buttons */
135 INT nNumBitmaps; /* number of bitmaps */
136 INT nNumStrings; /* number of strings */
137 INT nNumBitmapInfos;
138 INT nButtonDown; /* toolbar button being pressed or -1 if none */
139 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
140 INT nOldHit;
141 INT nHotItem; /* index of the "hot" item */
142 SIZE szPadding; /* padding values around button */
143 INT iTopMargin; /* the top margin */
144 INT iListGap; /* default gap between text and image for toolbar with list style */
145 HFONT hDefaultFont;
146 HFONT hFont; /* text font */
147 HIMAGELIST himlInt; /* image list created internally */
148 PIMLENTRY *himlDef; /* default image list array */
149 INT cimlDef; /* default image list array count */
150 PIMLENTRY *himlHot; /* hot image list array */
151 INT cimlHot; /* hot image list array count */
152 PIMLENTRY *himlDis; /* disabled image list array */
153 INT cimlDis; /* disabled image list array count */
154 HWND hwndToolTip; /* handle to tool tip control */
155 HWND hwndNotify; /* handle to the window that gets notifications */
156 HWND hwndSelf; /* my own handle */
157 BOOL bAnchor; /* anchor highlight enabled */
158 BOOL bDoRedraw; /* Redraw status */
159 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
160 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
161 BOOL bCaptured; /* mouse captured? */
162 DWORD dwStyle; /* regular toolbar style */
163 DWORD dwExStyle; /* extended toolbar style */
164 DWORD dwDTFlags; /* DrawText flags */
166 COLORREF clrInsertMark; /* insert mark color */
167 COLORREF clrBtnHighlight; /* color for Flat Separator */
168 COLORREF clrBtnShadow; /* color for Flag Separator */
169 INT iVersion;
170 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
171 * for TTN_GETDISPINFOW notification */
172 TBINSERTMARK tbim; /* info on insertion mark */
173 TBUTTON_INFO *buttons; /* pointer to button array */
174 LPWSTR *strings; /* pointer to string array */
175 TBITMAP_INFO *bitmaps;
176 } TOOLBAR_INFO, *PTOOLBAR_INFO;
179 /* used by customization dialog */
180 typedef struct
182 PTOOLBAR_INFO tbInfo;
183 HWND tbHwnd;
184 } CUSTDLG_INFO, *PCUSTDLG_INFO;
186 typedef struct
188 TBBUTTON btn;
189 BOOL bVirtual;
190 BOOL bRemovable;
191 WCHAR text[64];
192 } CUSTOMBUTTON, *PCUSTOMBUTTON;
194 typedef enum
196 IMAGE_LIST_DEFAULT,
197 IMAGE_LIST_HOT,
198 IMAGE_LIST_DISABLED
199 } IMAGE_LIST_TYPE;
201 #define SEPARATOR_WIDTH 8
202 #define TOP_BORDER 2
203 #define BOTTOM_BORDER 2
204 #define DDARROW_WIDTH 11
205 #define ARROW_HEIGHT 3
206 #define INSERTMARK_WIDTH 2
208 #define DEFPAD_CX 7
209 #define DEFPAD_CY 6
210 #define DEFLISTGAP 4
212 /* vertical padding used in list mode when image is present */
213 #define LISTPAD_CY 9
215 /* how wide to treat the bitmap if it isn't present */
216 #define NONLIST_NOTEXT_OFFSET 2
218 #define TOOLBAR_NOWHERE (-1)
220 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
221 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
222 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
224 /* Used to find undocumented extended styles */
225 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
226 TBSTYLE_EX_UNDOC1 | \
227 TBSTYLE_EX_MIXEDBUTTONS | \
228 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
230 /* all of the CCS_ styles */
231 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
232 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
234 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
235 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
236 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
237 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
238 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
240 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
242 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
243 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
244 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id);
245 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id);
246 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
247 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
248 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
249 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
250 static void TOOLBAR_LayoutToolbar(HWND hwnd);
251 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
252 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
253 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
255 static LRESULT
256 TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
258 static inline int default_top_margin(const TOOLBAR_INFO *infoPtr)
260 return (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
263 static LPWSTR
264 TOOLBAR_GetText(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr)
266 LPWSTR lpText = NULL;
268 /* NOTE: iString == -1 is undocumented */
269 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
270 lpText = (LPWSTR)btnPtr->iString;
271 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
272 lpText = infoPtr->strings[btnPtr->iString];
274 return lpText;
277 static void
278 TOOLBAR_DumpButton(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *bP, INT btn_num, BOOL internal)
280 if (TRACE_ON(toolbar)){
281 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
282 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
283 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
284 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
285 if (internal)
286 TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n",
287 btn_num, bP->idCommand,
288 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
289 bP->rect.left, bP->rect.top,
290 bP->rect.right, bP->rect.bottom);
295 static void
296 TOOLBAR_DumpToolbar(const TOOLBAR_INFO *iP, INT line)
298 if (TRACE_ON(toolbar)) {
299 INT i;
301 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
302 iP->hwndSelf, line,
303 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
304 iP->nNumStrings, iP->dwStyle);
305 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
306 iP->hwndSelf, line,
307 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
308 (iP->bDoRedraw) ? "TRUE" : "FALSE");
309 for(i=0; i<iP->nNumButtons; i++) {
310 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
316 /***********************************************************************
317 * TOOLBAR_CheckStyle
319 * This function validates that the styles set are implemented and
320 * issues FIXME's warning of possible problems. In a perfect world this
321 * function should be null.
323 static void
324 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
326 if (dwStyle & TBSTYLE_REGISTERDROP)
327 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
331 static INT
332 TOOLBAR_SendNotify (NMHDR *nmhdr, const TOOLBAR_INFO *infoPtr, UINT code)
334 if(!IsWindow(infoPtr->hwndSelf))
335 return 0; /* we have just been destroyed */
337 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
338 nmhdr->hwndFrom = infoPtr->hwndSelf;
339 nmhdr->code = code;
341 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
342 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
344 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
345 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
348 /***********************************************************************
349 * TOOLBAR_GetBitmapIndex
351 * This function returns the bitmap index associated with a button.
352 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
353 * is issued to retrieve the index.
355 static INT
356 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
358 INT ret = btnPtr->iBitmap;
360 if (ret == I_IMAGECALLBACK)
362 /* issue TBN_GETDISPINFO */
363 NMTBDISPINFOA nmgd;
365 memset(&nmgd, 0, sizeof(nmgd));
366 nmgd.idCommand = btnPtr->idCommand;
367 nmgd.lParam = btnPtr->dwData;
368 nmgd.dwMask = TBNF_IMAGE;
369 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
370 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
371 if (nmgd.dwMask & TBNF_DI_SETITEM)
372 btnPtr->iBitmap = nmgd.iImage;
373 ret = nmgd.iImage;
374 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
375 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
378 if (ret != I_IMAGENONE)
379 ret = GETIBITMAP(infoPtr, ret);
381 return ret;
385 static BOOL
386 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO *infoPtr, INT index)
388 HIMAGELIST himl;
389 INT id = GETHIMLID(infoPtr, index);
390 INT iBitmap = GETIBITMAP(infoPtr, index);
392 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
393 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
394 (index == I_IMAGECALLBACK))
395 return TRUE;
396 else
397 return FALSE;
401 static inline BOOL
402 TOOLBAR_IsValidImageList(const TOOLBAR_INFO *infoPtr, INT index)
404 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
405 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
409 /***********************************************************************
410 * TOOLBAR_GetImageListForDrawing
412 * This function validates the bitmap index (including I_IMAGECALLBACK
413 * functionality) and returns the corresponding image list.
415 static HIMAGELIST
416 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
417 IMAGE_LIST_TYPE imagelist, INT * index)
419 HIMAGELIST himl;
421 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
422 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
423 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
424 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
425 return NULL;
428 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
429 if ((*index == I_IMAGECALLBACK) ||
430 (*index == I_IMAGENONE)) return NULL;
431 ERR("TBN_GETDISPINFO returned invalid index %d\n",
432 *index);
433 return NULL;
436 switch(imagelist)
438 case IMAGE_LIST_DEFAULT:
439 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
440 break;
441 case IMAGE_LIST_HOT:
442 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
443 break;
444 case IMAGE_LIST_DISABLED:
445 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
446 break;
447 default:
448 himl = NULL;
449 FIXME("Shouldn't reach here\n");
452 if (!himl)
453 TRACE("no image list\n");
455 return himl;
459 static void
460 TOOLBAR_DrawFlatSeparator (const RECT *lpRect, HDC hdc, const TOOLBAR_INFO *infoPtr)
462 RECT myrect;
463 COLORREF oldcolor, newcolor;
465 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
466 myrect.right = myrect.left + 1;
467 myrect.top = lpRect->top + 2;
468 myrect.bottom = lpRect->bottom - 2;
470 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
471 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
472 oldcolor = SetBkColor (hdc, newcolor);
473 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
475 myrect.left = myrect.right;
476 myrect.right = myrect.left + 1;
478 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
479 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
480 SetBkColor (hdc, newcolor);
481 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
483 SetBkColor (hdc, oldcolor);
487 /***********************************************************************
488 * TOOLBAR_DrawDDFlatSeparator
490 * This function draws the separator that was flagged as BTNS_DROPDOWN.
491 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
492 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
493 * are horizontal as opposed to the vertical separators for not dropdown
494 * type.
496 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
498 static void
499 TOOLBAR_DrawDDFlatSeparator (const RECT *lpRect, HDC hdc, const TBUTTON_INFO *btnPtr,
500 const TOOLBAR_INFO *infoPtr)
502 RECT myrect;
503 COLORREF oldcolor, newcolor;
505 myrect.left = lpRect->left;
506 myrect.right = lpRect->right;
507 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
508 myrect.bottom = myrect.top + 1;
510 InflateRect (&myrect, -2, 0);
512 TRACE("rect=(%d,%d)-(%d,%d)\n",
513 myrect.left, myrect.top, myrect.right, myrect.bottom);
515 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
516 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
517 oldcolor = SetBkColor (hdc, newcolor);
518 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
520 myrect.top = myrect.bottom;
521 myrect.bottom = myrect.top + 1;
523 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
524 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
525 SetBkColor (hdc, newcolor);
526 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
528 SetBkColor (hdc, oldcolor);
532 static void
533 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
535 INT x, y;
536 HPEN hPen, hOldPen;
538 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
539 hOldPen = SelectObject ( hdc, hPen );
540 x = left + 2;
541 y = top;
542 MoveToEx (hdc, x, y, NULL);
543 LineTo (hdc, x+5, y++); x++;
544 MoveToEx (hdc, x, y, NULL);
545 LineTo (hdc, x+3, y++); x++;
546 MoveToEx (hdc, x, y, NULL);
547 LineTo (hdc, x+1, y++);
548 SelectObject( hdc, hOldPen );
549 DeleteObject( hPen );
553 * Draw the text string for this button.
554 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
555 * is non-zero, so we can simply check himlDef to see if we have
556 * an image list
558 static void
559 TOOLBAR_DrawString (const TOOLBAR_INFO *infoPtr, RECT *rcText, LPCWSTR lpText,
560 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
562 HDC hdc = tbcd->nmcd.hdc;
563 HFONT hOldFont = 0;
564 COLORREF clrOld = 0;
565 COLORREF clrOldBk = 0;
566 int oldBkMode = 0;
567 UINT state = tbcd->nmcd.uItemState;
569 /* draw text */
570 if (lpText) {
571 TRACE("string=%s rect=(%d,%d)-(%d,%d)\n", debugstr_w(lpText),
572 rcText->left, rcText->top, rcText->right, rcText->bottom);
574 hOldFont = SelectObject (hdc, infoPtr->hFont);
575 if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
576 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
578 else if (state & CDIS_DISABLED) {
579 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
580 OffsetRect (rcText, 1, 1);
581 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
582 SetTextColor (hdc, comctl32_color.clr3dShadow);
583 OffsetRect (rcText, -1, -1);
585 else if (state & CDIS_INDETERMINATE) {
586 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
588 else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
589 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
590 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
591 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
593 else {
594 clrOld = SetTextColor (hdc, tbcd->clrText);
597 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
598 SetTextColor (hdc, clrOld);
599 if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
601 SetBkColor (hdc, clrOldBk);
602 SetBkMode (hdc, oldBkMode);
604 SelectObject (hdc, hOldFont);
609 static void
610 TOOLBAR_DrawPattern (const RECT *lpRect, const NMTBCUSTOMDRAW *tbcd)
612 HDC hdc = tbcd->nmcd.hdc;
613 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
614 COLORREF clrTextOld;
615 COLORREF clrBkOld;
616 INT cx = lpRect->right - lpRect->left;
617 INT cy = lpRect->bottom - lpRect->top;
618 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
619 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
620 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
621 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
622 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
623 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
624 SetBkColor(hdc, clrBkOld);
625 SetTextColor(hdc, clrTextOld);
626 SelectObject (hdc, hbr);
630 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
632 INT cx, cy;
633 HBITMAP hbmMask, hbmImage;
634 HDC hdcMask, hdcImage;
636 ImageList_GetIconSize(himl, &cx, &cy);
638 /* Create src image */
639 hdcImage = CreateCompatibleDC(hdc);
640 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
641 SelectObject(hdcImage, hbmImage);
642 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
643 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
645 /* Create Mask */
646 hdcMask = CreateCompatibleDC(0);
647 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
648 SelectObject(hdcMask, hbmMask);
650 /* Remove the background and all white pixels */
651 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
652 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
653 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
654 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
656 /* draw the new mask 'etched' to hdc */
657 SetBkColor(hdc, RGB(255, 255, 255));
658 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
659 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
660 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
661 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
662 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
664 /* Cleanup */
665 DeleteObject(hbmImage);
666 DeleteDC(hdcImage);
667 DeleteObject (hbmMask);
668 DeleteDC(hdcMask);
672 static UINT
673 TOOLBAR_TranslateState(const TBUTTON_INFO *btnPtr)
675 UINT retstate = 0;
677 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
678 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
679 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
680 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
681 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
682 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
683 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
684 return retstate;
687 /* draws the image on a toolbar button */
688 static void
689 TOOLBAR_DrawImage(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
690 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
692 HIMAGELIST himl = NULL;
693 BOOL draw_masked = FALSE;
694 INT index;
695 INT offset = 0;
696 UINT draw_flags = ILD_TRANSPARENT;
698 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
700 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
701 if (!himl)
703 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
704 draw_masked = TRUE;
707 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
708 ((tbcd->nmcd.uItemState & CDIS_HOT)
709 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
711 /* if hot, attempt to draw with hot image list, if fails,
712 use default image list */
713 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
714 if (!himl)
715 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
717 else
718 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
720 if (!himl)
721 return;
723 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
724 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
725 offset = 1;
727 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
728 (tbcd->nmcd.uItemState & CDIS_MARKED))
729 draw_flags |= ILD_BLEND50;
731 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
732 index, himl, left, top, offset);
734 if (draw_masked)
735 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
736 else
737 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
740 /* draws a blank frame for a toolbar button */
741 static void
742 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
744 HDC hdc = tbcd->nmcd.hdc;
745 RECT rc = tbcd->nmcd.rc;
746 /* if the state is disabled or indeterminate then the button
747 * cannot have an interactive look like pressed or hot */
748 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
749 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
750 BOOL pressed_look = !non_interactive_state &&
751 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
752 (tbcd->nmcd.uItemState & CDIS_CHECKED));
754 /* app don't want us to draw any edges */
755 if (dwItemCDFlag & TBCDRF_NOEDGES)
756 return;
758 if (infoPtr->dwStyle & TBSTYLE_FLAT)
760 if (pressed_look)
761 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
762 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
763 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
765 else
767 if (pressed_look)
768 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
769 else
770 DrawEdge (hdc, &rc, EDGE_RAISED,
771 BF_SOFT | BF_RECT | BF_MIDDLE);
775 static void
776 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
778 HDC hdc = tbcd->nmcd.hdc;
779 int offset = 0;
780 BOOL pressed = bDropDownPressed ||
781 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
783 if (infoPtr->dwStyle & TBSTYLE_FLAT)
785 if (pressed)
786 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
787 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
788 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
789 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
790 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
792 else
794 if (pressed)
795 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
796 else
797 DrawEdge (hdc, rcArrow, EDGE_RAISED,
798 BF_SOFT | BF_RECT | BF_MIDDLE);
801 if (pressed)
802 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
804 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
806 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
807 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
809 else
810 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
813 /* draws a complete toolbar button */
814 static void
815 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
817 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
818 DWORD dwStyle = infoPtr->dwStyle;
819 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
820 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
821 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
822 BOOL drawSepDropDownArrow = hasDropDownArrow &&
823 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
824 RECT rc, rcArrow, rcBitmap, rcText;
825 LPWSTR lpText = NULL;
826 NMTBCUSTOMDRAW tbcd;
827 DWORD ntfret;
828 INT offset;
829 INT oldBkMode;
830 DWORD dwItemCustDraw;
831 DWORD dwItemCDFlag;
832 HTHEME theme = GetWindowTheme (hwnd);
834 rc = btnPtr->rect;
835 CopyRect (&rcArrow, &rc);
837 /* separator - doesn't send NM_CUSTOMDRAW */
838 if (btnPtr->fsStyle & BTNS_SEP) {
839 if (theme)
841 DrawThemeBackground (theme, hdc,
842 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
843 &rc, NULL);
845 else
846 /* with the FLAT style, iBitmap is the width and has already */
847 /* been taken into consideration in calculating the width */
848 /* so now we need to draw the vertical separator */
849 /* empirical tests show that iBitmap can/will be non-zero */
850 /* when drawing the vertical bar... */
851 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
852 if (btnPtr->fsStyle & BTNS_DROPDOWN)
853 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
854 else
855 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
857 else if (btnPtr->fsStyle != BTNS_SEP) {
858 FIXME("Draw some kind of separator: fsStyle=%x\n",
859 btnPtr->fsStyle);
861 return;
864 /* get a pointer to the text */
865 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
867 if (hasDropDownArrow)
869 int right;
871 if (dwStyle & TBSTYLE_FLAT)
872 right = max(rc.left, rc.right - DDARROW_WIDTH);
873 else
874 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
876 if (drawSepDropDownArrow)
877 rc.right = right;
879 rcArrow.left = right;
882 /* copy text & bitmap rects after adjusting for drop-down arrow
883 * so that text & bitmap is centred in the rectangle not containing
884 * the arrow */
885 CopyRect(&rcText, &rc);
886 CopyRect(&rcBitmap, &rc);
888 /* Center the bitmap horizontally and vertically */
889 if (dwStyle & TBSTYLE_LIST)
891 if (lpText &&
892 infoPtr->nMaxTextRows > 0 &&
893 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
894 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
895 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
896 else
897 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
899 else
900 rcBitmap.left += ((rc.right - rc.left) - infoPtr->nBitmapWidth) / 2;
902 rcBitmap.top += infoPtr->szPadding.cy / 2;
904 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
905 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
906 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
907 TRACE("Text=%s\n", debugstr_w(lpText));
908 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
910 /* calculate text position */
911 if (lpText)
913 rcText.left += GetSystemMetrics(SM_CXEDGE);
914 rcText.right -= GetSystemMetrics(SM_CXEDGE);
915 if (dwStyle & TBSTYLE_LIST)
917 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
918 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
920 else
922 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
923 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
924 else
925 rcText.top += infoPtr->szPadding.cy/2 + 2;
929 /* Initialize fields in all cases, because we use these later
930 * NOTE: applications can and do alter these to customize their
931 * toolbars */
932 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
933 tbcd.clrText = comctl32_color.clrBtnText;
934 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
935 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
936 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
937 tbcd.clrMark = comctl32_color.clrHighlight;
938 tbcd.clrHighlightHotTrack = 0;
939 tbcd.nStringBkMode = TRANSPARENT;
940 tbcd.nHLStringBkMode = OPAQUE;
941 /* MSDN says that this is the text rectangle.
942 * But (why always a but) tracing of v5.7 of native shows
943 * that this is really a *relative* rectangle based on the
944 * the nmcd.rc. Also the left and top are always 0 ignoring
945 * any bitmap that might be present. */
946 tbcd.rcText.left = 0;
947 tbcd.rcText.top = 0;
948 tbcd.rcText.right = rcText.right - rc.left;
949 tbcd.rcText.bottom = rcText.bottom - rc.top;
950 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
951 tbcd.nmcd.hdc = hdc;
952 tbcd.nmcd.rc = rc;
953 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
955 /* FIXME: what are these used for? */
956 tbcd.hbrLines = 0;
957 tbcd.hpenLines = 0;
959 /* Issue Item Prepaint notify */
960 dwItemCustDraw = 0;
961 dwItemCDFlag = 0;
962 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
964 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
965 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
966 tbcd.nmcd.lItemlParam = btnPtr->dwData;
967 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
968 /* reset these fields so the user can't alter the behaviour like native */
969 tbcd.nmcd.hdc = hdc;
970 tbcd.nmcd.rc = rc;
972 dwItemCustDraw = ntfret & 0xffff;
973 dwItemCDFlag = ntfret & 0xffff0000;
974 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
975 return;
976 /* save the only part of the rect that the user can change */
977 rcText.right = tbcd.rcText.right + rc.left;
978 rcText.bottom = tbcd.rcText.bottom + rc.top;
981 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
982 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
983 OffsetRect(&rcText, 1, 1);
985 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
986 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
987 TOOLBAR_DrawPattern (&rc, &tbcd);
989 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
990 && (tbcd.nmcd.uItemState & CDIS_HOT))
992 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
994 COLORREF oldclr;
996 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
997 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
998 if (hasDropDownArrow)
999 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
1000 SetBkColor(hdc, oldclr);
1004 if (theme)
1006 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1007 int stateId = TS_NORMAL;
1009 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1010 stateId = TS_DISABLED;
1011 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1012 stateId = TS_PRESSED;
1013 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1014 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1015 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1016 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1017 stateId = TS_HOT;
1019 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1021 else
1022 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1024 if (drawSepDropDownArrow)
1026 if (theme)
1028 int stateId = TS_NORMAL;
1030 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1031 stateId = TS_DISABLED;
1032 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1033 stateId = TS_PRESSED;
1034 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1035 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1036 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1037 stateId = TS_HOT;
1039 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1040 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1042 else
1043 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1046 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1047 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1048 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1049 SetBkMode (hdc, oldBkMode);
1051 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1053 if (hasDropDownArrow && !drawSepDropDownArrow)
1055 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1057 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1058 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1060 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1062 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1063 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1065 else
1066 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1069 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1071 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1072 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1078 static void
1079 TOOLBAR_Refresh (HWND hwnd, HDC hdc, const PAINTSTRUCT *ps)
1081 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1082 TBUTTON_INFO *btnPtr;
1083 INT i;
1084 RECT rcTemp, rcClient;
1085 NMTBCUSTOMDRAW tbcd;
1086 DWORD ntfret;
1087 DWORD dwBaseCustDraw;
1089 /* the app has told us not to redraw the toolbar */
1090 if (!infoPtr->bDoRedraw)
1091 return;
1093 /* if imagelist belongs to the app, it can be changed
1094 by the app after setting it */
1095 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1097 infoPtr->nNumBitmaps = 0;
1098 for (i = 0; i < infoPtr->cimlDef; i++)
1099 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1102 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1104 /* change the imagelist icon size if we manage the list and it is necessary */
1105 TOOLBAR_CheckImageListIconSize(infoPtr);
1107 /* Send initial notify */
1108 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1109 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1110 tbcd.nmcd.hdc = hdc;
1111 tbcd.nmcd.rc = ps->rcPaint;
1112 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1113 dwBaseCustDraw = ntfret & 0xffff;
1115 GetClientRect(hwnd, &rcClient);
1117 /* redraw necessary buttons */
1118 btnPtr = infoPtr->buttons;
1119 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1121 BOOL bDraw;
1122 if (!RectVisible(hdc, &btnPtr->rect))
1123 continue;
1124 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1126 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1127 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1129 else
1130 bDraw = TRUE;
1131 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1132 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1133 if (bDraw)
1134 TOOLBAR_DrawButton(hwnd, btnPtr, hdc, dwBaseCustDraw);
1137 /* draw insert mark if required */
1138 if (infoPtr->tbim.iButton != -1)
1140 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1141 RECT rcInsertMark;
1142 rcInsertMark.top = rcButton.top;
1143 rcInsertMark.bottom = rcButton.bottom;
1144 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1145 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1146 else
1147 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1148 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1151 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1153 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1154 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1155 tbcd.nmcd.hdc = hdc;
1156 tbcd.nmcd.rc = ps->rcPaint;
1157 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1161 /***********************************************************************
1162 * TOOLBAR_MeasureString
1164 * This function gets the width and height of a string in pixels. This
1165 * is done first by using GetTextExtentPoint to get the basic width
1166 * and height. The DrawText is called with DT_CALCRECT to get the exact
1167 * width. The reason is because the text may have more than one "&" (or
1168 * prefix characters as M$ likes to call them). The prefix character
1169 * indicates where the underline goes, except for the string "&&" which
1170 * is reduced to a single "&". GetTextExtentPoint does not process these
1171 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1173 static void
1174 TOOLBAR_MeasureString(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr,
1175 HDC hdc, LPSIZE lpSize)
1177 RECT myrect;
1179 lpSize->cx = 0;
1180 lpSize->cy = 0;
1182 if (infoPtr->nMaxTextRows > 0 &&
1183 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1184 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1185 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1187 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1189 if(lpText != NULL) {
1190 /* first get size of all the text */
1191 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1193 /* feed above size into the rectangle for DrawText */
1194 myrect.left = myrect.top = 0;
1195 myrect.right = lpSize->cx;
1196 myrect.bottom = lpSize->cy;
1198 /* Use DrawText to get true size as drawn (less pesky "&") */
1199 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1200 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1201 DT_NOPREFIX : 0));
1203 /* feed back to caller */
1204 lpSize->cx = myrect.right;
1205 lpSize->cy = myrect.bottom;
1209 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1212 /***********************************************************************
1213 * TOOLBAR_CalcStrings
1215 * This function walks through each string and measures it and returns
1216 * the largest height and width to caller.
1218 static void
1219 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1221 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1222 TBUTTON_INFO *btnPtr;
1223 INT i;
1224 SIZE sz;
1225 HDC hdc;
1226 HFONT hOldFont;
1228 lpSize->cx = 0;
1229 lpSize->cy = 0;
1231 if (infoPtr->nMaxTextRows == 0)
1232 return;
1234 hdc = GetDC (hwnd);
1235 hOldFont = SelectObject (hdc, infoPtr->hFont);
1237 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1239 TEXTMETRICW tm;
1241 GetTextMetricsW(hdc, &tm);
1242 lpSize->cy = tm.tmHeight;
1245 btnPtr = infoPtr->buttons;
1246 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1247 if(TOOLBAR_HasText(infoPtr, btnPtr))
1249 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1250 if (sz.cx > lpSize->cx)
1251 lpSize->cx = sz.cx;
1252 if (sz.cy > lpSize->cy)
1253 lpSize->cy = sz.cy;
1257 SelectObject (hdc, hOldFont);
1258 ReleaseDC (hwnd, hdc);
1260 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1263 /***********************************************************************
1264 * TOOLBAR_WrapToolbar
1266 * This function walks through the buttons and separators in the
1267 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1268 * wrapping should occur based on the width of the toolbar window.
1269 * It does *not* calculate button placement itself. That task
1270 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1271 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1272 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1274 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1275 * vertical toolbar lists.
1278 static void
1279 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1281 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1282 TBUTTON_INFO *btnPtr;
1283 INT x, cx, i, j;
1284 RECT rc;
1285 BOOL bWrap, bButtonWrap;
1287 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1288 /* no layout is necessary. Applications may use this style */
1289 /* to perform their own layout on the toolbar. */
1290 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1291 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1293 btnPtr = infoPtr->buttons;
1294 x = infoPtr->nIndent;
1296 if (GetParent(hwnd))
1298 /* this can get the parents width, to know how far we can extend
1299 * this toolbar. We cannot use its height, as there may be multiple
1300 * toolbars in a rebar control
1302 GetClientRect( GetParent(hwnd), &rc );
1303 infoPtr->nWidth = rc.right - rc.left;
1305 else
1307 GetWindowRect( hwnd, &rc );
1308 infoPtr->nWidth = rc.right - rc.left;
1311 bButtonWrap = FALSE;
1313 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1314 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1315 infoPtr->nIndent);
1317 for (i = 0; i < infoPtr->nNumButtons; i++ )
1319 bWrap = FALSE;
1320 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1322 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1323 continue;
1325 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1326 /* it is the actual width of the separator. This is used for */
1327 /* custom controls in toolbars. */
1328 /* */
1329 /* BTNS_DROPDOWN separators are treated as buttons for */
1330 /* width. - GA 8/01 */
1331 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1332 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1333 cx = (btnPtr[i].iBitmap > 0) ?
1334 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1335 else
1336 cx = infoPtr->nButtonWidth;
1338 /* Two or more adjacent separators form a separator group. */
1339 /* The first separator in a group should be wrapped to the */
1340 /* next row if the previous wrapping is on a button. */
1341 if( bButtonWrap &&
1342 (btnPtr[i].fsStyle & BTNS_SEP) &&
1343 (i + 1 < infoPtr->nNumButtons ) &&
1344 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1346 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1347 btnPtr[i].fsState |= TBSTATE_WRAP;
1348 x = infoPtr->nIndent;
1349 i++;
1350 bButtonWrap = FALSE;
1351 continue;
1354 /* The layout makes sure the bitmap is visible, but not the button. */
1355 /* Test added to also wrap after a button that starts a row but */
1356 /* is bigger than the area. - GA 8/01 */
1357 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1358 > infoPtr->nWidth ) ||
1359 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1361 BOOL bFound = FALSE;
1363 /* If the current button is a separator and not hidden, */
1364 /* go to the next until it reaches a non separator. */
1365 /* Wrap the last separator if it is before a button. */
1366 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1367 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1368 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1369 i < infoPtr->nNumButtons )
1371 i++;
1372 bFound = TRUE;
1375 if( bFound && i < infoPtr->nNumButtons )
1377 i--;
1378 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1379 i, btnPtr[i].fsStyle, x, cx);
1380 btnPtr[i].fsState |= TBSTATE_WRAP;
1381 x = infoPtr->nIndent;
1382 bButtonWrap = FALSE;
1383 continue;
1385 else if ( i >= infoPtr->nNumButtons)
1386 break;
1388 /* If the current button is not a separator, find the last */
1389 /* separator and wrap it. */
1390 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1392 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1393 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1395 bFound = TRUE;
1396 i = j;
1397 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1398 i, btnPtr[i].fsStyle, x, cx);
1399 x = infoPtr->nIndent;
1400 btnPtr[j].fsState |= TBSTATE_WRAP;
1401 bButtonWrap = FALSE;
1402 break;
1406 /* If no separator available for wrapping, wrap one of */
1407 /* non-hidden previous button. */
1408 if (!bFound)
1410 for ( j = i - 1;
1411 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1413 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1414 continue;
1416 bFound = TRUE;
1417 i = j;
1418 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1419 i, btnPtr[i].fsStyle, x, cx);
1420 x = infoPtr->nIndent;
1421 btnPtr[j].fsState |= TBSTATE_WRAP;
1422 bButtonWrap = TRUE;
1423 break;
1427 /* If all above failed, wrap the current button. */
1428 if (!bFound)
1430 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1431 i, btnPtr[i].fsStyle, x, cx);
1432 btnPtr[i].fsState |= TBSTATE_WRAP;
1433 bFound = TRUE;
1434 x = infoPtr->nIndent;
1435 if (btnPtr[i].fsStyle & BTNS_SEP )
1436 bButtonWrap = FALSE;
1437 else
1438 bButtonWrap = TRUE;
1441 else {
1442 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1443 i, btnPtr[i].fsStyle, x, cx);
1444 x += cx;
1450 /***********************************************************************
1451 * TOOLBAR_MeasureButton
1453 * Calculates the width and height required for a button. Used in
1454 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1455 * the width of buttons that are autosized.
1457 * Note that it would have been rather elegant to use one piece of code for
1458 * both the laying out of the toolbar and for controlling where button parts
1459 * are drawn, but the native control has inconsistencies between the two that
1460 * prevent this from being effectively. These inconsistencies can be seen as
1461 * artefacts where parts of the button appear outside of the bounding button
1462 * rectangle.
1464 * There are several cases for the calculation of the button dimensions and
1465 * button part positioning:
1467 * List
1468 * ====
1470 * With Bitmap:
1472 * +--------------------------------------------------------+ ^
1473 * | ^ ^ | |
1474 * | | pad.cy / 2 | centred | |
1475 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1476 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1477 * | |<------------>| | | | |
1478 * | +--------------+ +------------+ | |
1479 * |<-------------------------------------->| | |
1480 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1481 * | szText.cx | |
1482 * +--------------------------------------------------------+ -
1483 * <-------------------------------------------------------->
1484 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1486 * Without Bitmap (I_IMAGENONE):
1488 * +-----------------------------------+ ^
1489 * | ^ | |
1490 * | | centred | | LISTPAD_CY +
1491 * | +------------+ | | szText.cy
1492 * | | Text | | |
1493 * | | | | |
1494 * | +------------+ | |
1495 * |<----------------->| | |
1496 * | cxedge |<-----------> | |
1497 * | szText.cx | |
1498 * +-----------------------------------+ -
1499 * <----------------------------------->
1500 * szText.cx + pad.cx
1502 * Without text:
1504 * +--------------------------------------+ ^
1505 * | ^ | |
1506 * | | padding.cy/2 | | DEFPAD_CY +
1507 * | +------------+ | | nBitmapHeight
1508 * | | Bitmap | | |
1509 * | | | | |
1510 * | +------------+ | |
1511 * |<------------------->| | |
1512 * | cxedge + iListGap/2 |<-----------> | |
1513 * | nBitmapWidth | |
1514 * +--------------------------------------+ -
1515 * <-------------------------------------->
1516 * 2*cxedge + nBitmapWidth + iListGap
1518 * Non-List
1519 * ========
1521 * With bitmap:
1523 * +-----------------------------------+ ^
1524 * | ^ | |
1525 * | | pad.cy / 2 | | nBitmapHeight +
1526 * | - | | szText.cy +
1527 * | +------------+ | | DEFPAD_CY + 1
1528 * | centred | Bitmap | | |
1529 * |<----------------->| | | |
1530 * | +------------+ | |
1531 * | ^ | |
1532 * | 1 | | |
1533 * | - | |
1534 * | centred +---------------+ | |
1535 * |<--------------->| Text | | |
1536 * | +---------------+ | |
1537 * +-----------------------------------+ -
1538 * <----------------------------------->
1539 * pad.cx + max(nBitmapWidth, szText.cx)
1541 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1543 * +---------------------------------------+ ^
1544 * | ^ | |
1545 * | | 2 + pad.cy / 2 | |
1546 * | - | | szText.cy +
1547 * | centred +-----------------+ | | pad.cy + 2
1548 * |<--------------->| Text | | |
1549 * | +-----------------+ | |
1550 * | | |
1551 * +---------------------------------------+ -
1552 * <--------------------------------------->
1553 * 2*cxedge + pad.cx + szText.cx
1555 * Without text:
1556 * As for with bitmaps, but with szText.cx zero.
1558 static inline SIZE TOOLBAR_MeasureButton(const TOOLBAR_INFO *infoPtr, SIZE sizeString,
1559 BOOL bHasBitmap, BOOL bValidImageList)
1561 SIZE sizeButton;
1562 if (infoPtr->dwStyle & TBSTYLE_LIST)
1564 /* set button height from bitmap / text height... */
1565 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1566 sizeString.cy);
1568 /* ... add on the necessary padding */
1569 if (bValidImageList)
1571 if (bHasBitmap)
1572 sizeButton.cy += DEFPAD_CY;
1573 else
1574 sizeButton.cy += LISTPAD_CY;
1576 else
1577 sizeButton.cy += infoPtr->szPadding.cy;
1579 /* calculate button width */
1580 if (bHasBitmap)
1582 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1583 infoPtr->nBitmapWidth + infoPtr->iListGap;
1584 if (sizeString.cx > 0)
1585 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1587 else
1588 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1590 else
1592 if (bHasBitmap)
1594 sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
1595 if (sizeString.cy > 0)
1596 sizeButton.cy += 1 + sizeString.cy;
1597 sizeButton.cx = infoPtr->szPadding.cx +
1598 max(sizeString.cx, infoPtr->nBitmapWidth);
1600 else
1602 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1603 NONLIST_NOTEXT_OFFSET;
1604 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1605 infoPtr->szPadding.cx + sizeString.cx;
1608 return sizeButton;
1612 /***********************************************************************
1613 * TOOLBAR_CalcToolbar
1615 * This function calculates button and separator placement. It first
1616 * calculates the button sizes, gets the toolbar window width and then
1617 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1618 * on. It assigns a new location to each item and sends this location to
1619 * the tooltip window if appropriate. Finally, it updates the rcBound
1620 * rect and calculates the new required toolbar window height.
1622 static void
1623 TOOLBAR_CalcToolbar (HWND hwnd)
1625 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1626 SIZE sizeString, sizeButton;
1627 BOOL validImageList = FALSE;
1629 TOOLBAR_CalcStrings (hwnd, &sizeString);
1631 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1633 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1634 validImageList = TRUE;
1635 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1636 infoPtr->nButtonWidth = sizeButton.cx;
1637 infoPtr->nButtonHeight = sizeButton.cy;
1638 infoPtr->iTopMargin = default_top_margin(infoPtr);
1640 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1641 infoPtr->nButtonWidth = infoPtr->cxMin;
1642 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1643 infoPtr->nButtonWidth = infoPtr->cxMax;
1645 TOOLBAR_LayoutToolbar(hwnd);
1648 static void
1649 TOOLBAR_LayoutToolbar(HWND hwnd)
1651 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1652 TBUTTON_INFO *btnPtr;
1653 SIZE sizeButton;
1654 INT i, nRows, nSepRows;
1655 INT x, y, cx, cy;
1656 BOOL bWrap;
1657 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1658 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1660 TOOLBAR_WrapToolbar(hwnd, infoPtr->dwStyle);
1662 x = infoPtr->nIndent;
1663 y = infoPtr->iTopMargin;
1664 cx = infoPtr->nButtonWidth;
1665 cy = infoPtr->nButtonHeight;
1667 nRows = nSepRows = 0;
1669 infoPtr->rcBound.top = y;
1670 infoPtr->rcBound.left = x;
1671 infoPtr->rcBound.bottom = y + cy;
1672 infoPtr->rcBound.right = x;
1674 btnPtr = infoPtr->buttons;
1676 TRACE("cy=%d\n", cy);
1678 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1680 bWrap = FALSE;
1681 if (btnPtr->fsState & TBSTATE_HIDDEN)
1683 SetRectEmpty (&btnPtr->rect);
1684 continue;
1687 cy = infoPtr->nButtonHeight;
1689 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1690 /* it is the actual width of the separator. This is used for */
1691 /* custom controls in toolbars. */
1692 if (btnPtr->fsStyle & BTNS_SEP) {
1693 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1694 cy = (btnPtr->iBitmap > 0) ?
1695 btnPtr->iBitmap : SEPARATOR_WIDTH;
1696 cx = infoPtr->nButtonWidth;
1698 else
1699 cx = (btnPtr->iBitmap > 0) ?
1700 btnPtr->iBitmap : SEPARATOR_WIDTH;
1702 else
1704 if (btnPtr->cx)
1705 cx = btnPtr->cx;
1706 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1707 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1709 SIZE sz;
1710 HDC hdc;
1711 HFONT hOldFont;
1713 hdc = GetDC (hwnd);
1714 hOldFont = SelectObject (hdc, infoPtr->hFont);
1716 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1718 SelectObject (hdc, hOldFont);
1719 ReleaseDC (hwnd, hdc);
1721 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1722 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1723 validImageList);
1724 cx = sizeButton.cx;
1726 else
1727 cx = infoPtr->nButtonWidth;
1729 /* if size has been set manually then don't add on extra space
1730 * for the drop down arrow */
1731 if (!btnPtr->cx && hasDropDownArrows &&
1732 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1733 cx += DDARROW_WIDTH;
1735 if (btnPtr->fsState & TBSTATE_WRAP )
1736 bWrap = TRUE;
1738 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1740 if (infoPtr->rcBound.left > x)
1741 infoPtr->rcBound.left = x;
1742 if (infoPtr->rcBound.right < x + cx)
1743 infoPtr->rcBound.right = x + cx;
1744 if (infoPtr->rcBound.bottom < y + cy)
1745 infoPtr->rcBound.bottom = y + cy;
1747 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1749 /* btnPtr->nRow is zero based. The space between the rows is */
1750 /* also considered as a row. */
1751 btnPtr->nRow = nRows + nSepRows;
1753 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1754 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1755 x, y, x+cx, y+cy);
1757 if( bWrap )
1759 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1760 y += cy;
1761 else
1763 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1764 /* it is the actual width of the separator. This is used for */
1765 /* custom controls in toolbars. */
1766 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1767 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1768 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1769 else
1770 y += cy;
1772 /* nSepRows is used to calculate the extra height follwoing */
1773 /* the last row. */
1774 nSepRows++;
1776 x = infoPtr->nIndent;
1778 /* Increment row number unless this is the last button */
1779 /* and it has Wrap set. */
1780 if (i != infoPtr->nNumButtons-1)
1781 nRows++;
1783 else
1784 x += cx;
1787 /* infoPtr->nRows is the number of rows on the toolbar */
1788 infoPtr->nRows = nRows + nSepRows + 1;
1790 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1794 static INT
1795 TOOLBAR_InternalHitTest (HWND hwnd, const POINT *lpPt)
1797 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1798 TBUTTON_INFO *btnPtr;
1799 INT i;
1801 btnPtr = infoPtr->buttons;
1802 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1803 if (btnPtr->fsState & TBSTATE_HIDDEN)
1804 continue;
1806 if (btnPtr->fsStyle & BTNS_SEP) {
1807 if (PtInRect (&btnPtr->rect, *lpPt)) {
1808 TRACE(" ON SEPARATOR %d!\n", i);
1809 return -i;
1812 else {
1813 if (PtInRect (&btnPtr->rect, *lpPt)) {
1814 TRACE(" ON BUTTON %d!\n", i);
1815 return i;
1820 TRACE(" NOWHERE!\n");
1821 return TOOLBAR_NOWHERE;
1825 static INT
1826 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1828 TBUTTON_INFO *btnPtr;
1829 INT i;
1831 if (CommandIsIndex) {
1832 TRACE("command is really index command=%d\n", idCommand);
1833 if (idCommand >= infoPtr->nNumButtons) return -1;
1834 return idCommand;
1836 btnPtr = infoPtr->buttons;
1837 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1838 if (btnPtr->idCommand == idCommand) {
1839 TRACE("command=%d index=%d\n", idCommand, i);
1840 return i;
1843 TRACE("no index found for command=%d\n", idCommand);
1844 return -1;
1848 static INT
1849 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO *infoPtr, INT nIndex)
1851 TBUTTON_INFO *btnPtr;
1852 INT nRunIndex;
1854 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1855 return -1;
1857 /* check index button */
1858 btnPtr = &infoPtr->buttons[nIndex];
1859 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1860 if (btnPtr->fsState & TBSTATE_CHECKED)
1861 return nIndex;
1864 /* check previous buttons */
1865 nRunIndex = nIndex - 1;
1866 while (nRunIndex >= 0) {
1867 btnPtr = &infoPtr->buttons[nRunIndex];
1868 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1869 if (btnPtr->fsState & TBSTATE_CHECKED)
1870 return nRunIndex;
1872 else
1873 break;
1874 nRunIndex--;
1877 /* check next buttons */
1878 nRunIndex = nIndex + 1;
1879 while (nRunIndex < infoPtr->nNumButtons) {
1880 btnPtr = &infoPtr->buttons[nRunIndex];
1881 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1882 if (btnPtr->fsState & TBSTATE_CHECKED)
1883 return nRunIndex;
1885 else
1886 break;
1887 nRunIndex++;
1890 return -1;
1894 static VOID
1895 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1896 WPARAM wParam, LPARAM lParam)
1898 MSG msg;
1900 msg.hwnd = hwndMsg;
1901 msg.message = uMsg;
1902 msg.wParam = wParam;
1903 msg.lParam = lParam;
1904 msg.time = GetMessageTime ();
1905 msg.pt.x = (short)LOWORD(GetMessagePos ());
1906 msg.pt.y = (short)HIWORD(GetMessagePos ());
1908 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1911 static void
1912 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1914 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1915 TTTOOLINFOW ti;
1917 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1918 ti.cbSize = sizeof (TTTOOLINFOW);
1919 ti.hwnd = infoPtr->hwndSelf;
1920 ti.uId = button->idCommand;
1921 ti.hinst = 0;
1922 ti.lpszText = LPSTR_TEXTCALLBACKW;
1923 /* ti.lParam = random value from the stack? */
1925 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1926 0, (LPARAM)&ti);
1930 static void
1931 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1933 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1934 TTTOOLINFOW ti;
1936 ZeroMemory(&ti, sizeof(ti));
1937 ti.cbSize = sizeof(ti);
1938 ti.hwnd = infoPtr->hwndSelf;
1939 ti.uId = button->idCommand;
1941 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1945 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1947 /* Set the toolTip only for non-hidden, non-separator button */
1948 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1950 TTTOOLINFOW ti;
1952 ZeroMemory(&ti, sizeof(ti));
1953 ti.cbSize = sizeof(ti);
1954 ti.hwnd = infoPtr->hwndSelf;
1955 ti.uId = button->idCommand;
1956 ti.rect = button->rect;
1957 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1961 /* Creates the tooltip control */
1962 static void
1963 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
1965 int i;
1966 NMTOOLTIPSCREATED nmttc;
1968 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1969 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1970 infoPtr->hwndSelf, 0, 0, 0);
1972 if (!infoPtr->hwndToolTip)
1973 return;
1975 /* Send NM_TOOLTIPSCREATED notification */
1976 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1977 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
1979 for (i = 0; i < infoPtr->nNumButtons; i++)
1981 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
1982 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
1986 /* keeps available button list box sorted by button id */
1987 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1989 int i;
1990 int count;
1991 PCUSTOMBUTTON btnInfo;
1992 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1994 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1996 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1998 /* position 0 is always separator */
1999 for (i = 1; i < count; i++)
2001 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
2002 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2004 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2005 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2006 return;
2009 /* id higher than all others add to end */
2010 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2011 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2014 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2016 NMTOOLBARW nmtb;
2018 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2020 if (nIndexFrom == nIndexTo)
2021 return;
2023 /* MSDN states that iItem is the index of the button, rather than the
2024 * command ID as used by every other NMTOOLBAR notification */
2025 nmtb.iItem = nIndexFrom;
2026 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2028 PCUSTOMBUTTON btnInfo;
2029 NMHDR hdr;
2030 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2031 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2033 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2035 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2036 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2037 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2038 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2040 if (nIndexTo <= 0)
2041 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2042 else
2043 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2045 /* last item is always separator, so -2 instead of -1 */
2046 if (nIndexTo >= (count - 2))
2047 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2048 else
2049 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2051 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2052 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2054 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2058 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2060 NMTOOLBARW nmtb;
2062 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2064 /* MSDN states that iItem is the index of the button, rather than the
2065 * command ID as used by every other NMTOOLBAR notification */
2066 nmtb.iItem = nIndexAvail;
2067 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2069 PCUSTOMBUTTON btnInfo;
2070 NMHDR hdr;
2071 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2072 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2073 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2075 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2077 if (nIndexAvail != 0) /* index == 0 indicates separator */
2079 /* remove from 'available buttons' list */
2080 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2081 if (nIndexAvail == count-1)
2082 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2083 else
2084 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2086 else
2088 PCUSTOMBUTTON btnNew;
2090 /* duplicate 'separator' button */
2091 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2092 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2093 btnInfo = btnNew;
2096 /* insert into 'toolbar button' list */
2097 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2098 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2100 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2102 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2106 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT index)
2108 PCUSTOMBUTTON btnInfo;
2109 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2111 TRACE("Remove: index %d\n", index);
2113 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2115 /* send TBN_QUERYDELETE notification */
2116 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2118 NMHDR hdr;
2120 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2121 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2123 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2125 /* insert into 'available button' list */
2126 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2127 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2128 else
2129 Free(btnInfo);
2131 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2135 /* drag list notification function for toolbar buttons list box */
2136 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2137 const DRAGLISTINFO *pDLI)
2139 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2140 switch (pDLI->uNotification)
2142 case DL_BEGINDRAG:
2144 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2145 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2146 /* no dragging for last item (separator) */
2147 if (nCurrentItem >= (nCount - 1)) return FALSE;
2148 return TRUE;
2150 case DL_DRAGGING:
2152 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2153 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2154 /* no dragging past last item (separator) */
2155 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2157 DrawInsert(hwnd, hwndList, nCurrentItem);
2158 /* FIXME: native uses "move button" cursor */
2159 return DL_COPYCURSOR;
2162 /* not over toolbar buttons list */
2163 if (nCurrentItem < 0)
2165 POINT ptWindow = pDLI->ptCursor;
2166 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2167 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2168 /* over available buttons list? */
2169 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2170 /* FIXME: native uses "move button" cursor */
2171 return DL_COPYCURSOR;
2173 /* clear drag arrow */
2174 DrawInsert(hwnd, hwndList, -1);
2175 return DL_STOPCURSOR;
2177 case DL_DROPPED:
2179 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2180 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2181 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2182 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2184 /* clear drag arrow */
2185 DrawInsert(hwnd, hwndList, -1);
2186 /* move item */
2187 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2189 /* not over toolbar buttons list */
2190 if (nIndexTo < 0)
2192 POINT ptWindow = pDLI->ptCursor;
2193 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2194 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2195 /* over available buttons list? */
2196 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2197 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2199 break;
2201 case DL_CANCELDRAG:
2202 /* Clear drag arrow */
2203 DrawInsert(hwnd, hwndList, -1);
2204 break;
2207 return 0;
2210 /* drag list notification function for available buttons list box */
2211 static LRESULT TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2212 const DRAGLISTINFO *pDLI)
2214 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2215 switch (pDLI->uNotification)
2217 case DL_BEGINDRAG:
2218 return TRUE;
2219 case DL_DRAGGING:
2221 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2222 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2223 /* no dragging past last item (separator) */
2224 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2226 DrawInsert(hwnd, hwndList, nCurrentItem);
2227 /* FIXME: native uses "move button" cursor */
2228 return DL_COPYCURSOR;
2231 /* not over toolbar buttons list */
2232 if (nCurrentItem < 0)
2234 POINT ptWindow = pDLI->ptCursor;
2235 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2236 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2237 /* over available buttons list? */
2238 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2239 /* FIXME: native uses "move button" cursor */
2240 return DL_COPYCURSOR;
2242 /* clear drag arrow */
2243 DrawInsert(hwnd, hwndList, -1);
2244 return DL_STOPCURSOR;
2246 case DL_DROPPED:
2248 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2249 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2250 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2251 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2253 /* clear drag arrow */
2254 DrawInsert(hwnd, hwndList, -1);
2255 /* add item */
2256 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2259 case DL_CANCELDRAG:
2260 /* Clear drag arrow */
2261 DrawInsert(hwnd, hwndList, -1);
2262 break;
2264 return 0;
2267 extern UINT uDragListMessage;
2269 /***********************************************************************
2270 * TOOLBAR_CustomizeDialogProc
2271 * This function implements the toolbar customization dialog.
2273 static INT_PTR CALLBACK
2274 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2276 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2277 PCUSTOMBUTTON btnInfo;
2278 NMTOOLBARA nmtb;
2279 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2281 switch (uMsg)
2283 case WM_INITDIALOG:
2284 custInfo = (PCUSTDLG_INFO)lParam;
2285 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2287 if (custInfo)
2289 WCHAR Buffer[256];
2290 int i = 0;
2291 int index;
2292 NMTBINITCUSTOMIZE nmtbic;
2294 infoPtr = custInfo->tbInfo;
2296 /* send TBN_QUERYINSERT notification */
2297 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2299 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2300 return FALSE;
2302 nmtbic.hwndDialog = hwnd;
2303 /* Send TBN_INITCUSTOMIZE notification */
2304 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2305 TBNRF_HIDEHELP)
2307 TRACE("TBNRF_HIDEHELP requested\n");
2308 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2311 /* add items to 'toolbar buttons' list and check if removable */
2312 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2314 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2315 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2316 btnInfo->btn.fsStyle = BTNS_SEP;
2317 btnInfo->bVirtual = FALSE;
2318 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2320 /* send TBN_QUERYDELETE notification */
2321 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2323 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2324 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2327 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2329 /* insert separator button into 'available buttons' list */
2330 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2331 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2332 btnInfo->btn.fsStyle = BTNS_SEP;
2333 btnInfo->bVirtual = FALSE;
2334 btnInfo->bRemovable = TRUE;
2335 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2336 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2337 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2339 /* insert all buttons into dsa */
2340 for (i = 0;; i++)
2342 /* send TBN_GETBUTTONINFO notification */
2343 NMTOOLBARW nmtb;
2344 nmtb.iItem = i;
2345 nmtb.pszText = Buffer;
2346 nmtb.cchText = 256;
2348 /* Clear previous button's text */
2349 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2351 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2352 break;
2354 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2355 nmtb.tbButton.fsStyle, i,
2356 nmtb.tbButton.idCommand,
2357 nmtb.tbButton.iString,
2358 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2359 : "");
2361 /* insert button into the apropriate list */
2362 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2363 if (index == -1)
2365 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2366 btnInfo->bVirtual = FALSE;
2367 btnInfo->bRemovable = TRUE;
2369 else
2371 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2372 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2375 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2376 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2378 if (lstrlenW(nmtb.pszText))
2379 lstrcpyW(btnInfo->text, nmtb.pszText);
2380 else if (nmtb.tbButton.iString >= 0 &&
2381 nmtb.tbButton.iString < infoPtr->nNumStrings)
2383 lstrcpyW(btnInfo->text,
2384 infoPtr->strings[nmtb.tbButton.iString]);
2388 if (index == -1)
2389 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2392 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2394 /* select first item in the 'available' list */
2395 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2397 /* append 'virtual' separator button to the 'toolbar buttons' list */
2398 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2399 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2400 btnInfo->btn.fsStyle = BTNS_SEP;
2401 btnInfo->bVirtual = TRUE;
2402 btnInfo->bRemovable = FALSE;
2403 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2404 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2405 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2407 /* select last item in the 'toolbar' list */
2408 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2409 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2411 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2412 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2414 /* set focus and disable buttons */
2415 PostMessageW (hwnd, WM_USER, 0, 0);
2417 return TRUE;
2419 case WM_USER:
2420 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2421 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2422 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2423 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2424 return TRUE;
2426 case WM_CLOSE:
2427 EndDialog(hwnd, FALSE);
2428 return TRUE;
2430 case WM_COMMAND:
2431 switch (LOWORD(wParam))
2433 case IDC_TOOLBARBTN_LBOX:
2434 if (HIWORD(wParam) == LBN_SELCHANGE)
2436 PCUSTOMBUTTON btnInfo;
2437 NMTOOLBARA nmtb;
2438 int count;
2439 int index;
2441 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2442 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2444 /* send TBN_QUERYINSERT notification */
2445 nmtb.iItem = index;
2446 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2448 /* get list box item */
2449 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2451 if (index == (count - 1))
2453 /* last item (virtual separator) */
2454 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2455 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2457 else if (index == (count - 2))
2459 /* second last item (last non-virtual item) */
2460 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2461 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2463 else if (index == 0)
2465 /* first item */
2466 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2467 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2469 else
2471 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2472 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2475 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2477 break;
2479 case IDC_MOVEUP_BTN:
2481 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2482 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2484 break;
2486 case IDC_MOVEDN_BTN: /* move down */
2488 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2489 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2491 break;
2493 case IDC_REMOVE_BTN: /* remove button */
2495 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2497 if (LB_ERR == index)
2498 break;
2500 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2502 break;
2503 case IDC_HELP_BTN:
2504 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2505 break;
2506 case IDC_RESET_BTN:
2507 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2508 break;
2510 case IDOK: /* Add button */
2512 int index;
2513 int indexto;
2515 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2516 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2518 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2520 break;
2522 case IDCANCEL:
2523 EndDialog(hwnd, FALSE);
2524 break;
2526 return TRUE;
2528 case WM_DESTROY:
2530 int count;
2531 int i;
2533 /* delete items from 'toolbar buttons' listbox*/
2534 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2535 for (i = 0; i < count; i++)
2537 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2538 Free(btnInfo);
2539 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2541 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2544 /* delete items from 'available buttons' listbox*/
2545 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2546 for (i = 0; i < count; i++)
2548 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2549 Free(btnInfo);
2550 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2552 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2554 return TRUE;
2556 case WM_DRAWITEM:
2557 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2559 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2560 RECT rcButton;
2561 RECT rcText;
2562 HPEN hPen, hOldPen;
2563 HBRUSH hOldBrush;
2564 COLORREF oldText = 0;
2565 COLORREF oldBk = 0;
2567 /* get item data */
2568 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2569 if (btnInfo == NULL)
2571 FIXME("btnInfo invalid!\n");
2572 return TRUE;
2575 /* set colors and select objects */
2576 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2577 if (btnInfo->bVirtual)
2578 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2579 else
2580 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2581 hPen = CreatePen( PS_SOLID, 1,
2582 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2583 hOldPen = SelectObject (lpdis->hDC, hPen );
2584 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2586 /* fill background rectangle */
2587 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2588 lpdis->rcItem.right, lpdis->rcItem.bottom);
2590 /* calculate button and text rectangles */
2591 CopyRect (&rcButton, &lpdis->rcItem);
2592 InflateRect (&rcButton, -1, -1);
2593 CopyRect (&rcText, &rcButton);
2594 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2595 rcText.left = rcButton.right + 2;
2597 /* draw focus rectangle */
2598 if (lpdis->itemState & ODS_FOCUS)
2599 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2601 /* draw button */
2602 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2603 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2605 /* draw image and text */
2606 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2607 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2608 btnInfo->btn.iBitmap));
2609 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2610 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2612 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2613 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2615 /* delete objects and reset colors */
2616 SelectObject (lpdis->hDC, hOldBrush);
2617 SelectObject (lpdis->hDC, hOldPen);
2618 SetBkColor (lpdis->hDC, oldBk);
2619 SetTextColor (lpdis->hDC, oldText);
2620 DeleteObject( hPen );
2621 return TRUE;
2623 return FALSE;
2625 case WM_MEASUREITEM:
2626 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2628 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2630 lpmis->itemHeight = 15 + 8; /* default height */
2632 return TRUE;
2634 return FALSE;
2636 default:
2637 if (uDragListMessage && (uMsg == uDragListMessage))
2639 if (wParam == IDC_TOOLBARBTN_LBOX)
2641 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2642 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2643 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2644 return TRUE;
2646 else if (wParam == IDC_AVAILBTN_LBOX)
2648 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2649 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2650 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2651 return TRUE;
2654 return FALSE;
2658 static BOOL
2659 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2661 HBITMAP hbmLoad;
2662 INT nCountBefore = ImageList_GetImageCount(himlDef);
2663 INT nCountAfter;
2664 INT cxIcon, cyIcon;
2665 INT nAdded;
2666 INT nIndex;
2668 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2669 /* Add bitmaps to the default image list */
2670 if (bitmap->hInst == NULL) /* a handle was passed */
2671 hbmLoad = (HBITMAP)CopyImage(ULongToHandle(bitmap->nID), IMAGE_BITMAP, 0, 0, 0);
2672 else
2673 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2675 /* enlarge the bitmap if needed */
2676 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2677 if (bitmap->hInst != COMCTL32_hModule)
2678 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2680 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2681 DeleteObject(hbmLoad);
2682 if (nIndex == -1)
2683 return FALSE;
2685 nCountAfter = ImageList_GetImageCount(himlDef);
2686 nAdded = nCountAfter - nCountBefore;
2687 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2689 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2690 } else if (nAdded > (INT)bitmap->nButtons) {
2691 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2692 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2695 infoPtr->nNumBitmaps += nAdded;
2696 return TRUE;
2699 static void
2700 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2702 HIMAGELIST himlDef;
2703 HIMAGELIST himlNew;
2704 INT cx, cy;
2705 INT i;
2707 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2708 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2709 return;
2710 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2711 return;
2712 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2713 return;
2715 TRACE("Update icon size: %dx%d -> %dx%d\n",
2716 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2718 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2719 ILC_COLORDDB|ILC_MASK, 8, 2);
2720 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2721 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2722 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2723 infoPtr->himlInt = himlNew;
2725 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2726 ImageList_Destroy(himlDef);
2729 /***********************************************************************
2730 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2733 static LRESULT
2734 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2736 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2737 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2738 TBITMAP_INFO info;
2739 INT iSumButtons, i;
2740 HIMAGELIST himlDef;
2742 TRACE("hwnd=%p wParam=%lx lParam=%lx\n", hwnd, wParam, lParam);
2743 if (!lpAddBmp)
2744 return -1;
2746 if (lpAddBmp->hInst == HINST_COMMCTRL)
2748 info.hInst = COMCTL32_hModule;
2749 switch (lpAddBmp->nID)
2751 case IDB_STD_SMALL_COLOR:
2752 info.nButtons = 15;
2753 info.nID = IDB_STD_SMALL;
2754 break;
2755 case IDB_STD_LARGE_COLOR:
2756 info.nButtons = 15;
2757 info.nID = IDB_STD_LARGE;
2758 break;
2759 case IDB_VIEW_SMALL_COLOR:
2760 info.nButtons = 12;
2761 info.nID = IDB_VIEW_SMALL;
2762 break;
2763 case IDB_VIEW_LARGE_COLOR:
2764 info.nButtons = 12;
2765 info.nID = IDB_VIEW_LARGE;
2766 break;
2767 case IDB_HIST_SMALL_COLOR:
2768 info.nButtons = 5;
2769 info.nID = IDB_HIST_SMALL;
2770 break;
2771 case IDB_HIST_LARGE_COLOR:
2772 info.nButtons = 5;
2773 info.nID = IDB_HIST_LARGE;
2774 break;
2775 default:
2776 return -1;
2779 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2781 /* Windows resize all the buttons to the size of a newly added standard image */
2782 if (lpAddBmp->nID & 1)
2784 /* large icons: 24x24. Will make the button 31x30 */
2785 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
2787 else
2789 /* small icons: 16x16. Will make the buttons 23x22 */
2790 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
2793 TOOLBAR_CalcToolbar (hwnd);
2795 else
2797 info.nButtons = (INT)wParam;
2798 info.hInst = lpAddBmp->hInst;
2799 info.nID = lpAddBmp->nID;
2800 TRACE("adding %d bitmaps!\n", info.nButtons);
2803 /* check if the bitmap is already loaded and compute iSumButtons */
2804 iSumButtons = 0;
2805 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2807 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2808 infoPtr->bitmaps[i].nID == info.nID)
2809 return iSumButtons;
2810 iSumButtons += infoPtr->bitmaps[i].nButtons;
2813 if (!infoPtr->cimlDef) {
2814 /* create new default image list */
2815 TRACE ("creating default image list!\n");
2817 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2818 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2819 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2820 infoPtr->himlInt = himlDef;
2822 else {
2823 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2826 if (!himlDef) {
2827 WARN("No default image list available\n");
2828 return -1;
2831 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2832 return -1;
2834 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2835 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2836 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2837 infoPtr->nNumBitmapInfos++;
2838 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2840 InvalidateRect(hwnd, NULL, TRUE);
2841 return iSumButtons;
2845 static LRESULT
2846 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2848 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2849 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2850 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2851 BOOL fHasString = FALSE;
2853 TRACE("adding %ld buttons (unicode=%d)!\n", wParam, fUnicode);
2855 nAddButtons = (UINT)wParam;
2856 nOldButtons = infoPtr->nNumButtons;
2857 nNewButtons = nOldButtons + nAddButtons;
2859 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
2860 infoPtr->nNumButtons = nNewButtons;
2862 /* insert new button data */
2863 for (nCount = 0; nCount < nAddButtons; nCount++) {
2864 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2865 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2866 btnPtr->idCommand = lpTbb[nCount].idCommand;
2867 btnPtr->fsState = lpTbb[nCount].fsState;
2868 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2869 btnPtr->dwData = lpTbb[nCount].dwData;
2870 btnPtr->bHot = FALSE;
2871 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2873 if (fUnicode)
2874 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2875 else
2876 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString);
2877 fHasString = TRUE;
2879 else
2880 btnPtr->iString = lpTbb[nCount].iString;
2882 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
2885 if (infoPtr->nNumStrings > 0 || fHasString)
2886 TOOLBAR_CalcToolbar(hwnd);
2887 else
2888 TOOLBAR_LayoutToolbar(hwnd);
2889 TOOLBAR_AutoSize (hwnd);
2891 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2893 InvalidateRect(hwnd, NULL, TRUE);
2895 return TRUE;
2899 static LRESULT
2900 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2902 #define MAX_RESOURCE_STRING_LENGTH 512
2903 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2904 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2905 INT nIndex = infoPtr->nNumStrings;
2907 if ((wParam) && (HIWORD(lParam) == 0)) {
2908 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2909 WCHAR delimiter;
2910 WCHAR *next_delim;
2911 WCHAR *p;
2912 INT len;
2913 TRACE("adding string from resource!\n");
2915 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2916 szString, MAX_RESOURCE_STRING_LENGTH);
2918 TRACE("len=%d %s\n", len, debugstr_w(szString));
2919 if (len == 0 || len == 1)
2920 return nIndex;
2922 TRACE("Delimiter: 0x%x\n", *szString);
2923 delimiter = *szString;
2924 p = szString + 1;
2926 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2927 *next_delim = 0;
2928 if (next_delim + 1 >= szString + len)
2930 /* this may happen if delimiter == '\0' or if the last char is a
2931 * delimiter (then it is ignored like the native does) */
2932 break;
2935 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2936 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2937 infoPtr->nNumStrings++;
2939 p = next_delim + 1;
2942 else {
2943 LPWSTR p = (LPWSTR)lParam;
2944 INT len;
2946 if (p == NULL)
2947 return -1;
2948 TRACE("adding string(s) from array!\n");
2949 while (*p) {
2950 len = strlenW (p);
2952 TRACE("len=%d %s\n", len, debugstr_w(p));
2953 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2954 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2955 infoPtr->nNumStrings++;
2957 p += (len+1);
2961 if (fFirstString)
2962 TOOLBAR_CalcToolbar(hwnd);
2963 return nIndex;
2967 static LRESULT
2968 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2970 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2971 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2972 LPSTR p;
2973 INT nIndex;
2974 INT len;
2976 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
2977 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
2979 p = (LPSTR)lParam;
2980 if (p == NULL)
2981 return -1;
2983 TRACE("adding string(s) from array!\n");
2984 nIndex = infoPtr->nNumStrings;
2985 while (*p) {
2986 len = strlen (p);
2987 TRACE("len=%d \"%s\"\n", len, p);
2989 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2990 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
2991 infoPtr->nNumStrings++;
2993 p += (len+1);
2996 if (fFirstString)
2997 TOOLBAR_CalcToolbar(hwnd);
2998 return nIndex;
3002 static LRESULT
3003 TOOLBAR_AutoSize (HWND hwnd)
3005 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3006 RECT parent_rect;
3007 HWND parent;
3008 INT x, y;
3009 INT cx, cy;
3011 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3013 parent = GetParent (hwnd);
3015 if (!parent || !infoPtr->bDoRedraw)
3016 return 0;
3018 GetClientRect(parent, &parent_rect);
3020 x = parent_rect.left;
3021 y = parent_rect.top;
3023 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3025 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3026 cx = parent_rect.right - parent_rect.left;
3028 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3030 TOOLBAR_LayoutToolbar(hwnd);
3031 InvalidateRect( hwnd, NULL, TRUE );
3034 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3036 RECT window_rect;
3037 UINT uPosFlags = SWP_NOZORDER;
3039 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3041 GetWindowRect(hwnd, &window_rect);
3042 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3043 y = window_rect.top;
3045 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3047 GetWindowRect(hwnd, &window_rect);
3048 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3051 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3052 uPosFlags |= SWP_NOMOVE;
3054 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3055 cy += GetSystemMetrics(SM_CYEDGE);
3057 if (infoPtr->dwStyle & WS_BORDER)
3059 x = y = 1; /* FIXME: this looks wrong */
3060 cy += GetSystemMetrics(SM_CYEDGE);
3061 cx += GetSystemMetrics(SM_CXEDGE);
3064 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3067 return 0;
3071 static LRESULT
3072 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3074 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3076 return infoPtr->nNumButtons;
3080 static LRESULT
3081 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3083 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3085 infoPtr->dwStructSize = (DWORD)wParam;
3087 return 0;
3091 static LRESULT
3092 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3094 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3095 TBUTTON_INFO *btnPtr;
3096 INT nIndex;
3098 TRACE("button %ld, iBitmap now %d\n", wParam, LOWORD(lParam));
3100 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3101 if (nIndex == -1)
3102 return FALSE;
3104 btnPtr = &infoPtr->buttons[nIndex];
3105 btnPtr->iBitmap = LOWORD(lParam);
3107 /* we HAVE to erase the background, the new bitmap could be */
3108 /* transparent */
3109 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3111 return TRUE;
3115 static LRESULT
3116 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3118 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3119 TBUTTON_INFO *btnPtr;
3120 INT nIndex;
3121 INT nOldIndex = -1;
3122 BOOL bChecked = FALSE;
3124 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3126 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3128 if (nIndex == -1)
3129 return FALSE;
3131 btnPtr = &infoPtr->buttons[nIndex];
3133 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3135 if (LOWORD(lParam) == FALSE)
3136 btnPtr->fsState &= ~TBSTATE_CHECKED;
3137 else {
3138 if (btnPtr->fsStyle & BTNS_GROUP) {
3139 nOldIndex =
3140 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3141 if (nOldIndex == nIndex)
3142 return 0;
3143 if (nOldIndex != -1)
3144 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3146 btnPtr->fsState |= TBSTATE_CHECKED;
3149 if( bChecked != LOWORD(lParam) )
3151 if (nOldIndex != -1)
3152 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3153 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3156 /* FIXME: Send a WM_NOTIFY?? */
3158 return TRUE;
3162 static LRESULT
3163 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3165 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3167 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3171 static LRESULT
3172 TOOLBAR_Customize (HWND hwnd)
3174 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3175 CUSTDLG_INFO custInfo;
3176 LRESULT ret;
3177 LPCVOID template;
3178 HRSRC hRes;
3179 NMHDR nmhdr;
3181 custInfo.tbInfo = infoPtr;
3182 custInfo.tbHwnd = hwnd;
3184 /* send TBN_BEGINADJUST notification */
3185 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3187 if (!(hRes = FindResourceW (COMCTL32_hModule,
3188 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3189 (LPWSTR)RT_DIALOG)))
3190 return FALSE;
3192 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3193 return FALSE;
3195 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3196 (LPCDLGTEMPLATEW)template,
3197 hwnd,
3198 TOOLBAR_CustomizeDialogProc,
3199 (LPARAM)&custInfo);
3201 /* send TBN_ENDADJUST notification */
3202 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3204 return ret;
3208 static LRESULT
3209 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3211 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3212 INT nIndex = (INT)wParam;
3213 NMTOOLBARW nmtb;
3214 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3216 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3217 return FALSE;
3219 memset(&nmtb, 0, sizeof(nmtb));
3220 nmtb.iItem = btnPtr->idCommand;
3221 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3222 nmtb.tbButton.idCommand = btnPtr->idCommand;
3223 nmtb.tbButton.fsState = btnPtr->fsState;
3224 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3225 nmtb.tbButton.dwData = btnPtr->dwData;
3226 nmtb.tbButton.iString = btnPtr->iString;
3227 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3229 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3231 if (infoPtr->nNumButtons == 1) {
3232 TRACE(" simple delete!\n");
3233 Free (infoPtr->buttons);
3234 infoPtr->buttons = NULL;
3235 infoPtr->nNumButtons = 0;
3237 else {
3238 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3239 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3241 infoPtr->nNumButtons--;
3242 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3243 if (nIndex > 0) {
3244 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3245 nIndex * sizeof(TBUTTON_INFO));
3248 if (nIndex < infoPtr->nNumButtons) {
3249 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3250 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3253 Free (oldButtons);
3256 TOOLBAR_LayoutToolbar(hwnd);
3258 InvalidateRect (hwnd, NULL, TRUE);
3260 return TRUE;
3264 static LRESULT
3265 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3267 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3268 TBUTTON_INFO *btnPtr;
3269 INT nIndex;
3270 DWORD bState;
3272 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3274 TRACE("hwnd=%p, btn index=%ld, lParam=0x%08lx\n", hwnd, wParam, lParam);
3276 if (nIndex == -1)
3277 return FALSE;
3279 btnPtr = &infoPtr->buttons[nIndex];
3281 bState = btnPtr->fsState & TBSTATE_ENABLED;
3283 /* update the toolbar button state */
3284 if(LOWORD(lParam) == FALSE) {
3285 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3286 } else {
3287 btnPtr->fsState |= TBSTATE_ENABLED;
3290 /* redraw the button only if the state of the button changed */
3291 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3292 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3294 return TRUE;
3298 static inline LRESULT
3299 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3301 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3303 return infoPtr->bAnchor;
3307 static LRESULT
3308 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3310 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3311 INT nIndex;
3313 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3314 if (nIndex == -1)
3315 return -1;
3317 return infoPtr->buttons[nIndex].iBitmap;
3321 static inline LRESULT
3322 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3324 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3328 static LRESULT
3329 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3331 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3332 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3333 INT nIndex = (INT)wParam;
3334 TBUTTON_INFO *btnPtr;
3336 if (lpTbb == NULL)
3337 return FALSE;
3339 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3340 return FALSE;
3342 btnPtr = &infoPtr->buttons[nIndex];
3343 lpTbb->iBitmap = btnPtr->iBitmap;
3344 lpTbb->idCommand = btnPtr->idCommand;
3345 lpTbb->fsState = btnPtr->fsState;
3346 lpTbb->fsStyle = btnPtr->fsStyle;
3347 lpTbb->bReserved[0] = 0;
3348 lpTbb->bReserved[1] = 0;
3349 lpTbb->dwData = btnPtr->dwData;
3350 lpTbb->iString = btnPtr->iString;
3352 return TRUE;
3356 static LRESULT
3357 TOOLBAR_GetButtonInfoT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL bUnicode)
3359 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3360 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3361 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3362 TBUTTON_INFO *btnPtr;
3363 INT nIndex;
3365 if (lpTbInfo == NULL)
3366 return -1;
3368 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3369 * the headers and tests shows that even with comctl 6 Vista accepts only the
3370 * original TBBUTTONINFO size
3372 if (lpTbInfo->cbSize != sizeof(TBBUTTONINFOW))
3374 WARN("Invalid button size\n");
3375 return -1;
3378 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3379 lpTbInfo->dwMask & 0x80000000);
3380 if (nIndex == -1)
3381 return -1;
3383 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3385 if (lpTbInfo->dwMask & TBIF_COMMAND)
3386 lpTbInfo->idCommand = btnPtr->idCommand;
3387 if (lpTbInfo->dwMask & TBIF_IMAGE)
3388 lpTbInfo->iImage = btnPtr->iBitmap;
3389 if (lpTbInfo->dwMask & TBIF_LPARAM)
3390 lpTbInfo->lParam = btnPtr->dwData;
3391 if (lpTbInfo->dwMask & TBIF_SIZE)
3392 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3393 if (lpTbInfo->dwMask & TBIF_STATE)
3394 lpTbInfo->fsState = btnPtr->fsState;
3395 if (lpTbInfo->dwMask & TBIF_STYLE)
3396 lpTbInfo->fsStyle = btnPtr->fsStyle;
3397 if (lpTbInfo->dwMask & TBIF_TEXT) {
3398 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3399 can't use TOOLBAR_GetText here */
3400 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3401 LPWSTR lpText = (LPWSTR)btnPtr->iString;
3402 if (bUnicode)
3403 Str_GetPtrW(lpText, lpTbInfo->pszText, lpTbInfo->cchText);
3404 else
3405 Str_GetPtrWtoA(lpText, (LPSTR)lpTbInfo->pszText, lpTbInfo->cchText);
3406 } else
3407 lpTbInfo->pszText[0] = '\0';
3409 return nIndex;
3413 static LRESULT
3414 TOOLBAR_GetButtonSize (HWND hwnd)
3416 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3418 return MAKELONG((WORD)infoPtr->nButtonWidth,
3419 (WORD)infoPtr->nButtonHeight);
3423 static LRESULT
3424 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3426 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3427 INT nIndex;
3428 LPWSTR lpText;
3430 if (lParam == 0)
3431 return -1;
3433 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3434 if (nIndex == -1)
3435 return -1;
3437 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3439 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3440 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3444 static LRESULT
3445 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3447 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3448 INT nIndex;
3449 LPWSTR lpText;
3450 LRESULT ret = 0;
3452 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3453 if (nIndex == -1)
3454 return -1;
3456 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3458 if (lpText)
3460 ret = strlenW (lpText);
3462 if (lParam)
3463 strcpyW ((LPWSTR)lParam, lpText);
3466 return ret;
3470 static LRESULT
3471 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3473 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3474 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3475 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3479 static inline LRESULT
3480 TOOLBAR_GetExtendedStyle (HWND hwnd)
3482 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3484 TRACE("\n");
3486 return infoPtr->dwExStyle;
3490 static LRESULT
3491 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3493 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3494 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3495 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3499 static LRESULT
3500 TOOLBAR_GetHotItem (HWND hwnd)
3502 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3504 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3505 return -1;
3507 if (infoPtr->nHotItem < 0)
3508 return -1;
3510 return (LRESULT)infoPtr->nHotItem;
3514 static LRESULT
3515 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3517 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3518 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3519 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3523 static LRESULT
3524 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3526 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3527 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3529 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3531 *lptbim = infoPtr->tbim;
3533 return 0;
3537 static LRESULT
3538 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3540 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3542 TRACE("hwnd = %p\n", hwnd);
3544 return (LRESULT)infoPtr->clrInsertMark;
3548 static LRESULT
3549 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3551 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3552 TBUTTON_INFO *btnPtr;
3553 LPRECT lpRect;
3554 INT nIndex;
3556 nIndex = (INT)wParam;
3557 btnPtr = &infoPtr->buttons[nIndex];
3558 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3559 return FALSE;
3560 lpRect = (LPRECT)lParam;
3561 if (lpRect == NULL)
3562 return FALSE;
3563 if (btnPtr->fsState & TBSTATE_HIDDEN)
3564 return FALSE;
3566 lpRect->left = btnPtr->rect.left;
3567 lpRect->right = btnPtr->rect.right;
3568 lpRect->bottom = btnPtr->rect.bottom;
3569 lpRect->top = btnPtr->rect.top;
3571 return TRUE;
3575 static LRESULT
3576 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3578 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3579 LPSIZE lpSize = (LPSIZE)lParam;
3581 if (lpSize == NULL)
3582 return FALSE;
3584 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3585 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3587 TRACE("maximum size %d x %d\n",
3588 infoPtr->rcBound.right - infoPtr->rcBound.left,
3589 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3591 return TRUE;
3595 /* << TOOLBAR_GetObject >> */
3598 static LRESULT
3599 TOOLBAR_GetPadding (HWND hwnd)
3601 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3602 DWORD oldPad;
3604 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3605 return (LRESULT) oldPad;
3609 static LRESULT
3610 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3612 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3613 TBUTTON_INFO *btnPtr;
3614 LPRECT lpRect;
3615 INT nIndex;
3617 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3618 btnPtr = &infoPtr->buttons[nIndex];
3619 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3620 return FALSE;
3621 lpRect = (LPRECT)lParam;
3622 if (lpRect == NULL)
3623 return FALSE;
3625 lpRect->left = btnPtr->rect.left;
3626 lpRect->right = btnPtr->rect.right;
3627 lpRect->bottom = btnPtr->rect.bottom;
3628 lpRect->top = btnPtr->rect.top;
3630 return TRUE;
3634 static LRESULT
3635 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3637 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3639 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3640 return infoPtr->nRows;
3641 else
3642 return 1;
3646 static LRESULT
3647 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3649 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3650 INT nIndex;
3652 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3653 if (nIndex == -1)
3654 return -1;
3656 return infoPtr->buttons[nIndex].fsState;
3660 static LRESULT
3661 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3663 return GetWindowLongW(hwnd, GWL_STYLE);
3667 static LRESULT
3668 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3670 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3672 return infoPtr->nMaxTextRows;
3676 static LRESULT
3677 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3679 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3681 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3682 TOOLBAR_TooltipCreateControl(infoPtr);
3683 return (LRESULT)infoPtr->hwndToolTip;
3687 static LRESULT
3688 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3690 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3692 TRACE("%s hwnd=%p\n",
3693 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3695 return infoPtr->bUnicode;
3699 static inline LRESULT
3700 TOOLBAR_GetVersion (HWND hwnd)
3702 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3703 return infoPtr->iVersion;
3707 static LRESULT
3708 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3710 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3711 TBUTTON_INFO *btnPtr;
3712 INT nIndex;
3714 TRACE("\n");
3716 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3717 if (nIndex == -1)
3718 return FALSE;
3720 btnPtr = &infoPtr->buttons[nIndex];
3721 if (LOWORD(lParam) == FALSE)
3722 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3723 else
3724 btnPtr->fsState |= TBSTATE_HIDDEN;
3726 TOOLBAR_LayoutToolbar (hwnd);
3728 InvalidateRect (hwnd, NULL, TRUE);
3730 return TRUE;
3734 static inline LRESULT
3735 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3737 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3741 static LRESULT
3742 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3744 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3745 TBUTTON_INFO *btnPtr;
3746 INT nIndex;
3747 DWORD oldState;
3749 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3750 if (nIndex == -1)
3751 return FALSE;
3753 btnPtr = &infoPtr->buttons[nIndex];
3754 oldState = btnPtr->fsState;
3755 if (LOWORD(lParam) == FALSE)
3756 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3757 else
3758 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3760 if(oldState != btnPtr->fsState)
3761 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3763 return TRUE;
3767 static LRESULT
3768 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3770 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3771 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3772 INT nIndex = (INT)wParam;
3774 if (lpTbb == NULL)
3775 return FALSE;
3777 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3779 if (nIndex == -1) {
3780 /* EPP: this seems to be an undocumented call (from my IE4)
3781 * I assume in that case that:
3782 * - index of insertion is at the end of existing buttons
3783 * I only see this happen with nIndex == -1, but it could have a special
3784 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3786 nIndex = infoPtr->nNumButtons;
3788 } else if (nIndex < 0)
3789 return FALSE;
3791 TRACE("inserting button index=%d\n", nIndex);
3792 if (nIndex > infoPtr->nNumButtons) {
3793 nIndex = infoPtr->nNumButtons;
3794 TRACE("adjust index=%d\n", nIndex);
3797 infoPtr->nNumButtons++;
3798 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO) * infoPtr->nNumButtons);
3799 memmove(&infoPtr->buttons[nIndex+1], &infoPtr->buttons[nIndex],
3800 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3802 /* insert new button */
3803 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3804 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3805 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3806 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3807 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3808 /* if passed string and not index, then add string */
3809 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3810 if (fUnicode)
3811 Str_SetPtrW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3812 else
3813 Str_SetPtrAtoW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3815 else
3816 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3818 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
3820 if (infoPtr->nNumStrings > 0)
3821 TOOLBAR_CalcToolbar(hwnd);
3822 else
3823 TOOLBAR_LayoutToolbar(hwnd);
3824 TOOLBAR_AutoSize (hwnd);
3826 InvalidateRect (hwnd, NULL, TRUE);
3828 return TRUE;
3831 /* << TOOLBAR_InsertMarkHitTest >> */
3834 static LRESULT
3835 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3837 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3838 INT nIndex;
3840 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3841 if (nIndex == -1)
3842 return FALSE;
3844 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3848 static LRESULT
3849 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3851 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3852 INT nIndex;
3854 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3855 if (nIndex == -1)
3856 return FALSE;
3858 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3862 static LRESULT
3863 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3865 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3866 INT nIndex;
3868 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3869 if (nIndex == -1)
3870 return TRUE;
3872 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3876 static LRESULT
3877 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3879 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3880 INT nIndex;
3882 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3883 if (nIndex == -1)
3884 return FALSE;
3886 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3890 static LRESULT
3891 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3893 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3894 INT nIndex;
3896 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3897 if (nIndex == -1)
3898 return FALSE;
3900 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3904 static LRESULT
3905 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3907 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3908 INT nIndex;
3910 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3911 if (nIndex == -1)
3912 return FALSE;
3914 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3918 static LRESULT
3919 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3921 TBADDBITMAP tbab;
3922 tbab.hInst = (HINSTANCE)lParam;
3923 tbab.nID = (UINT_PTR)wParam;
3925 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", hwnd, tbab.hInst, tbab.nID);
3927 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3931 static LRESULT
3932 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3934 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3935 WCHAR wAccel = (WCHAR)wParam;
3936 UINT* pIDButton = (UINT*)lParam;
3937 WCHAR wszAccel[] = {'&',wAccel,0};
3938 int i;
3940 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3941 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3943 for (i = 0; i < infoPtr->nNumButtons; i++)
3945 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3946 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3947 !(btnPtr->fsState & TBSTATE_HIDDEN))
3949 int iLen = strlenW(wszAccel);
3950 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3952 if (!lpszStr)
3953 continue;
3955 while (*lpszStr)
3957 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3959 lpszStr += 2;
3960 continue;
3962 if (!strncmpiW(lpszStr, wszAccel, iLen))
3964 *pIDButton = btnPtr->idCommand;
3965 return TRUE;
3967 lpszStr++;
3971 return FALSE;
3975 static LRESULT
3976 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3978 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3979 INT nIndex;
3980 DWORD oldState;
3981 TBUTTON_INFO *btnPtr;
3983 TRACE("hwnd = %p, wParam = %ld, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3985 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3986 if (nIndex == -1)
3987 return FALSE;
3989 btnPtr = &infoPtr->buttons[nIndex];
3990 oldState = btnPtr->fsState;
3992 if (LOWORD(lParam))
3993 btnPtr->fsState |= TBSTATE_MARKED;
3994 else
3995 btnPtr->fsState &= ~TBSTATE_MARKED;
3997 if(oldState != btnPtr->fsState)
3998 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4000 return TRUE;
4004 /* fixes up an index of a button affected by a move */
4005 static inline void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4007 if (bMoveUp)
4009 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4010 (*pIndex)--;
4011 else if (*pIndex == nIndex)
4012 *pIndex = nMoveIndex;
4014 else
4016 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4017 (*pIndex)++;
4018 else if (*pIndex == nIndex)
4019 *pIndex = nMoveIndex;
4024 static LRESULT
4025 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4027 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4028 INT nIndex;
4029 INT nCount;
4030 INT nMoveIndex = (INT)lParam;
4031 TBUTTON_INFO button;
4033 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
4035 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4036 if ((nIndex == -1) || (nMoveIndex < 0))
4037 return FALSE;
4039 if (nMoveIndex > infoPtr->nNumButtons - 1)
4040 nMoveIndex = infoPtr->nNumButtons - 1;
4042 button = infoPtr->buttons[nIndex];
4044 /* move button right */
4045 if (nIndex < nMoveIndex)
4047 nCount = nMoveIndex - nIndex;
4048 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4049 infoPtr->buttons[nMoveIndex] = button;
4051 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4052 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4053 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4054 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4056 else if (nIndex > nMoveIndex) /* move button left */
4058 nCount = nIndex - nMoveIndex;
4059 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4060 infoPtr->buttons[nMoveIndex] = button;
4062 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4063 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4064 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4065 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4068 TOOLBAR_LayoutToolbar(hwnd);
4069 TOOLBAR_AutoSize(hwnd);
4070 InvalidateRect(hwnd, NULL, TRUE);
4072 return TRUE;
4076 static LRESULT
4077 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4079 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4080 TBUTTON_INFO *btnPtr;
4081 INT nIndex;
4082 DWORD oldState;
4084 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4085 if (nIndex == -1)
4086 return FALSE;
4088 btnPtr = &infoPtr->buttons[nIndex];
4089 oldState = btnPtr->fsState;
4090 if (LOWORD(lParam) == FALSE)
4091 btnPtr->fsState &= ~TBSTATE_PRESSED;
4092 else
4093 btnPtr->fsState |= TBSTATE_PRESSED;
4095 if(oldState != btnPtr->fsState)
4096 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4098 return TRUE;
4101 /* FIXME: there might still be some confusion her between number of buttons
4102 * and number of bitmaps */
4103 static LRESULT
4104 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4106 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4107 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4108 HBITMAP hBitmap;
4109 int i = 0, nOldButtons = 0, pos = 0;
4110 int nOldBitmaps, nNewBitmaps = 0;
4111 HIMAGELIST himlDef = 0;
4113 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4114 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4115 lpReplace->nButtons);
4117 if (lpReplace->hInstOld == HINST_COMMCTRL)
4119 FIXME("changing standard bitmaps not implemented\n");
4120 return FALSE;
4122 else if (lpReplace->hInstOld != 0)
4123 FIXME("resources not in the current module not implemented\n");
4125 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4126 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4127 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4128 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4129 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4131 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4132 nOldButtons = tbi->nButtons;
4133 tbi->nButtons = lpReplace->nButtons;
4134 tbi->hInst = lpReplace->hInstNew;
4135 tbi->nID = lpReplace->nIDNew;
4136 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4137 break;
4139 pos += tbi->nButtons;
4142 if (nOldButtons == 0)
4144 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4145 return FALSE;
4148 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4149 * bitmap
4151 if (lpReplace->hInstNew)
4152 hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4153 else
4154 hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
4156 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4157 nOldBitmaps = ImageList_GetImageCount(himlDef);
4159 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4161 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4162 ImageList_Remove(himlDef, i);
4164 if (hBitmap)
4166 ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
4167 nNewBitmaps = ImageList_GetImageCount(himlDef);
4168 DeleteObject(hBitmap);
4171 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4173 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4174 pos, nOldBitmaps, nNewBitmaps);
4176 InvalidateRect(hwnd, NULL, TRUE);
4177 return TRUE;
4181 /* helper for TOOLBAR_SaveRestoreW */
4182 static BOOL
4183 TOOLBAR_Save(const TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
4185 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4186 debugstr_w(lpSave->pszValueName));
4188 return FALSE;
4192 /* helper for TOOLBAR_Restore */
4193 static void
4194 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4196 INT i;
4198 for (i = 0; i < infoPtr->nNumButtons; i++)
4200 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4203 Free(infoPtr->buttons);
4204 infoPtr->buttons = NULL;
4205 infoPtr->nNumButtons = 0;
4209 /* helper for TOOLBAR_SaveRestoreW */
4210 static BOOL
4211 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
4213 LONG res;
4214 HKEY hkey = NULL;
4215 BOOL ret = FALSE;
4216 DWORD dwType;
4217 DWORD dwSize = 0;
4218 NMTBRESTORE nmtbr;
4220 /* restore toolbar information */
4221 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4222 debugstr_w(lpSave->pszValueName));
4224 memset(&nmtbr, 0, sizeof(nmtbr));
4226 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4227 KEY_QUERY_VALUE, &hkey);
4228 if (!res)
4229 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4230 NULL, &dwSize);
4231 if (!res && dwType != REG_BINARY)
4232 res = ERROR_FILE_NOT_FOUND;
4233 if (!res)
4235 nmtbr.pData = Alloc(dwSize);
4236 nmtbr.cbData = (UINT)dwSize;
4237 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4239 if (!res)
4240 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4241 (LPBYTE)nmtbr.pData, &dwSize);
4242 if (!res)
4244 nmtbr.pCurrent = nmtbr.pData;
4245 nmtbr.iItem = -1;
4246 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4247 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4249 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4251 INT i;
4253 /* remove all existing buttons as this function is designed to
4254 * restore the toolbar to a previously saved state */
4255 TOOLBAR_DeleteAllButtons(infoPtr);
4257 for (i = 0; i < nmtbr.cButtons; i++)
4259 nmtbr.iItem = i;
4260 nmtbr.tbButton.iBitmap = -1;
4261 nmtbr.tbButton.fsState = 0;
4262 nmtbr.tbButton.fsStyle = 0;
4263 nmtbr.tbButton.idCommand = 0;
4264 if (*nmtbr.pCurrent == (DWORD)-1)
4266 /* separator */
4267 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4268 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4270 else if (*nmtbr.pCurrent == (DWORD)-2)
4271 /* hidden button */
4272 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4273 else
4274 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4276 nmtbr.pCurrent++;
4278 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4280 /* can't contain real string as we don't know whether
4281 * the client put an ANSI or Unicode string in there */
4282 if (HIWORD(nmtbr.tbButton.iString))
4283 nmtbr.tbButton.iString = 0;
4285 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4286 (LPARAM)&nmtbr.tbButton, TRUE);
4289 /* do legacy notifications */
4290 if (infoPtr->iVersion < 5)
4292 /* FIXME: send TBN_BEGINADJUST */
4293 FIXME("send TBN_GETBUTTONINFO for each button\n");
4294 /* FIXME: send TBN_ENDADJUST */
4297 /* remove all uninitialised buttons
4298 * note: loop backwards to avoid having to fixup i on a
4299 * delete */
4300 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4301 if (infoPtr->buttons[i].iBitmap == -1)
4302 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4304 /* only indicate success if at least one button survived */
4305 if (infoPtr->nNumButtons > 0) ret = TRUE;
4308 Free (nmtbr.pData);
4309 RegCloseKey(hkey);
4311 return ret;
4315 static LRESULT
4316 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, const TBSAVEPARAMSW *lpSave)
4318 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4320 if (lpSave == NULL) return 0;
4322 if (wParam)
4323 return TOOLBAR_Save(infoPtr, lpSave);
4324 else
4325 return TOOLBAR_Restore(infoPtr, lpSave);
4329 static LRESULT
4330 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, const TBSAVEPARAMSA *lpSave)
4332 LPWSTR pszValueName = 0, pszSubKey = 0;
4333 TBSAVEPARAMSW SaveW;
4334 LRESULT result = 0;
4335 int len;
4337 if (lpSave == NULL) return 0;
4339 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4340 pszSubKey = Alloc(len * sizeof(WCHAR));
4341 if (pszSubKey) goto exit;
4342 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4344 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4345 pszValueName = Alloc(len * sizeof(WCHAR));
4346 if (!pszValueName) goto exit;
4347 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4349 SaveW.pszValueName = pszValueName;
4350 SaveW.pszSubKey = pszSubKey;
4351 SaveW.hkr = lpSave->hkr;
4352 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4354 exit:
4355 Free (pszValueName);
4356 Free (pszSubKey);
4358 return result;
4362 static LRESULT
4363 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4365 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4366 BOOL bOldAnchor = infoPtr->bAnchor;
4368 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4370 infoPtr->bAnchor = (BOOL)wParam;
4372 /* Native does not remove the hot effect from an already hot button */
4374 return (LRESULT)bOldAnchor;
4378 static LRESULT
4379 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4381 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4382 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4384 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
4386 if (wParam != 0)
4387 FIXME("wParam is %ld. Perhaps image list index?\n", wParam);
4389 if (LOWORD(lParam) == 0)
4390 lParam = MAKELPARAM(1, HIWORD(lParam));
4392 if (HIWORD(lParam)==0)
4393 lParam = MAKELPARAM(LOWORD(lParam), 1);
4395 if (infoPtr->nNumButtons > 0)
4396 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4397 infoPtr->nNumButtons,
4398 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4399 LOWORD(lParam), HIWORD(lParam));
4401 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4402 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4404 if ((himlDef == infoPtr->himlInt) &&
4405 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4407 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4408 infoPtr->nBitmapHeight);
4411 TOOLBAR_CalcToolbar(hwnd);
4412 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4413 return TRUE;
4417 static LRESULT
4418 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4420 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4421 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4422 TBUTTON_INFO *btnPtr;
4423 INT nIndex;
4424 RECT oldBtnRect;
4426 if (lptbbi == NULL)
4427 return FALSE;
4428 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4429 return FALSE;
4431 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4432 lptbbi->dwMask & 0x80000000);
4433 if (nIndex == -1)
4434 return FALSE;
4436 btnPtr = &infoPtr->buttons[nIndex];
4437 if (lptbbi->dwMask & TBIF_COMMAND)
4438 btnPtr->idCommand = lptbbi->idCommand;
4439 if (lptbbi->dwMask & TBIF_IMAGE)
4440 btnPtr->iBitmap = lptbbi->iImage;
4441 if (lptbbi->dwMask & TBIF_LPARAM)
4442 btnPtr->dwData = lptbbi->lParam;
4443 if (lptbbi->dwMask & TBIF_SIZE)
4444 btnPtr->cx = lptbbi->cx;
4445 if (lptbbi->dwMask & TBIF_STATE)
4446 btnPtr->fsState = lptbbi->fsState;
4447 if (lptbbi->dwMask & TBIF_STYLE)
4448 btnPtr->fsStyle = lptbbi->fsStyle;
4450 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4451 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4452 /* iString is index, zero it to make Str_SetPtr succeed */
4453 btnPtr->iString=0;
4455 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4458 /* save the button rect to see if we need to redraw the whole toolbar */
4459 oldBtnRect = btnPtr->rect;
4460 TOOLBAR_CalcToolbar(hwnd);
4462 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4463 InvalidateRect(hwnd, NULL, TRUE);
4464 else
4465 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4467 return TRUE;
4471 static LRESULT
4472 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4474 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4475 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4476 TBUTTON_INFO *btnPtr;
4477 INT nIndex;
4478 RECT oldBtnRect;
4480 if (lptbbi == NULL)
4481 return FALSE;
4482 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4483 return FALSE;
4485 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4486 lptbbi->dwMask & 0x80000000);
4487 if (nIndex == -1)
4488 return FALSE;
4490 btnPtr = &infoPtr->buttons[nIndex];
4491 if (lptbbi->dwMask & TBIF_COMMAND)
4492 btnPtr->idCommand = lptbbi->idCommand;
4493 if (lptbbi->dwMask & TBIF_IMAGE)
4494 btnPtr->iBitmap = lptbbi->iImage;
4495 if (lptbbi->dwMask & TBIF_LPARAM)
4496 btnPtr->dwData = lptbbi->lParam;
4497 if (lptbbi->dwMask & TBIF_SIZE)
4498 btnPtr->cx = lptbbi->cx;
4499 if (lptbbi->dwMask & TBIF_STATE)
4500 btnPtr->fsState = lptbbi->fsState;
4501 if (lptbbi->dwMask & TBIF_STYLE)
4502 btnPtr->fsStyle = lptbbi->fsStyle;
4504 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4505 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4506 /* iString is index, zero it to make Str_SetPtr succeed */
4507 btnPtr->iString=0;
4508 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4511 /* save the button rect to see if we need to redraw the whole toolbar */
4512 oldBtnRect = btnPtr->rect;
4513 TOOLBAR_CalcToolbar(hwnd);
4515 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4516 InvalidateRect(hwnd, NULL, TRUE);
4517 else
4518 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4520 return TRUE;
4524 static LRESULT
4525 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4527 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4528 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4530 if ((cx < 0) || (cy < 0))
4532 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4533 return FALSE;
4536 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4538 /* The documentation claims you can only change the button size before
4539 * any button has been added. But this is wrong.
4540 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4541 * it to the toolbar, and it checks that the return value is nonzero - mjm
4542 * Further testing shows that we must actually perform the change too.
4545 * The documentation also does not mention that if 0 is supplied for
4546 * either size, the system changes it to the default of 24 wide and
4547 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4549 if (cx == 0) cx = 24;
4550 if (cy == 0) cx = 22;
4552 cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
4553 cy = max(cy, infoPtr->szPadding.cy + infoPtr->nBitmapHeight);
4555 infoPtr->nButtonWidth = cx;
4556 infoPtr->nButtonHeight = cy;
4558 infoPtr->iTopMargin = default_top_margin(infoPtr);
4559 TOOLBAR_LayoutToolbar(hwnd);
4560 return TRUE;
4564 static LRESULT
4565 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4567 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4569 /* if setting to current values, ignore */
4570 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4571 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4572 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4573 infoPtr->cxMin, infoPtr->cxMax);
4574 return TRUE;
4577 /* save new values */
4578 infoPtr->cxMin = (short)LOWORD(lParam);
4579 infoPtr->cxMax = (short)HIWORD(lParam);
4581 /* otherwise we need to recalc the toolbar and in some cases
4582 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4583 which doesn't actually draw - GA). */
4584 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4585 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4587 TOOLBAR_CalcToolbar (hwnd);
4589 InvalidateRect (hwnd, NULL, TRUE);
4591 return TRUE;
4595 static LRESULT
4596 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4598 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4599 INT nIndex = (INT)wParam;
4601 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4602 return FALSE;
4604 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4606 if (infoPtr->hwndToolTip) {
4608 FIXME("change tool tip!\n");
4612 return TRUE;
4616 static LRESULT
4617 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4619 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4620 HIMAGELIST himl = (HIMAGELIST)lParam;
4621 HIMAGELIST himlTemp;
4622 INT id = 0;
4624 if (infoPtr->iVersion >= 5)
4625 id = wParam;
4627 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4628 &infoPtr->cimlDis, himl, id);
4630 /* FIXME: redraw ? */
4632 return (LRESULT)himlTemp;
4636 static LRESULT
4637 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4639 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4640 DWORD dwTemp;
4642 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4644 dwTemp = infoPtr->dwDTFlags;
4645 infoPtr->dwDTFlags =
4646 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4648 return (LRESULT)dwTemp;
4651 /* This function differs a bit from what MSDN says it does:
4652 * 1. lParam contains extended style flags to OR with current style
4653 * (MSDN isn't clear on the OR bit)
4654 * 2. wParam appears to contain extended style flags to be reset
4655 * (MSDN says that this parameter is reserved)
4657 static LRESULT
4658 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4660 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4661 DWORD dwTemp;
4663 dwTemp = infoPtr->dwExStyle;
4664 infoPtr->dwExStyle &= ~wParam;
4665 infoPtr->dwExStyle |= (DWORD)lParam;
4667 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4669 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4670 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4671 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4673 TOOLBAR_CalcToolbar (hwnd);
4675 TOOLBAR_AutoSize(hwnd);
4677 InvalidateRect(hwnd, NULL, TRUE);
4679 return (LRESULT)dwTemp;
4683 static LRESULT
4684 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4686 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4687 HIMAGELIST himlTemp;
4688 HIMAGELIST himl = (HIMAGELIST)lParam;
4689 INT id = 0;
4691 if (infoPtr->iVersion >= 5)
4692 id = wParam;
4694 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4696 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4697 &infoPtr->cimlHot, himl, id);
4699 /* FIXME: redraw ? */
4701 return (LRESULT)himlTemp;
4705 /* Makes previous hot button no longer hot, makes the specified
4706 * button hot and sends appropriate notifications. dwReason is one or
4707 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4708 * NOTE 1: this function does not validate nHit
4709 * NOTE 2: the name of this function is completely made up and
4710 * not based on any documentation from Microsoft. */
4711 static void
4712 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4714 if (infoPtr->nHotItem != nHit)
4716 NMTBHOTITEM nmhotitem;
4717 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4719 nmhotitem.dwFlags = dwReason;
4720 if(infoPtr->nHotItem >= 0)
4722 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4723 nmhotitem.idOld = oldBtnPtr->idCommand;
4725 else
4727 nmhotitem.dwFlags |= HICF_ENTERING;
4728 nmhotitem.idOld = 0;
4731 if (nHit >= 0)
4733 btnPtr = &infoPtr->buttons[nHit];
4734 nmhotitem.idNew = btnPtr->idCommand;
4736 else
4738 nmhotitem.dwFlags |= HICF_LEAVING;
4739 nmhotitem.idNew = 0;
4742 /* now change the hot and invalidate the old and new buttons - if the
4743 * parent agrees */
4744 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4746 if (oldBtnPtr) {
4747 oldBtnPtr->bHot = FALSE;
4748 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4750 /* setting disabled buttons as hot fails even if the notify contains the button id */
4751 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4752 btnPtr->bHot = TRUE;
4753 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4754 infoPtr->nHotItem = nHit;
4756 else
4757 infoPtr->nHotItem = -1;
4762 static LRESULT
4763 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4765 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4766 INT nOldHotItem = infoPtr->nHotItem;
4768 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4770 if ((INT)wParam > infoPtr->nNumButtons)
4771 return infoPtr->nHotItem;
4773 if ((INT)wParam < 0)
4774 wParam = -1;
4776 /* NOTE: an application can still remove the hot item even if anchor
4777 * highlighting is enabled */
4779 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4781 if (nOldHotItem < 0)
4782 return -1;
4784 return (LRESULT)nOldHotItem;
4788 static LRESULT
4789 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4791 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4792 HIMAGELIST himlTemp;
4793 HIMAGELIST himl = (HIMAGELIST)lParam;
4794 INT oldButtonWidth = infoPtr->nButtonWidth;
4795 INT i, id = 0;
4797 if (infoPtr->iVersion >= 5)
4798 id = wParam;
4800 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4801 &infoPtr->cimlDef, himl, id);
4803 infoPtr->nNumBitmaps = 0;
4804 for (i = 0; i < infoPtr->cimlDef; i++)
4805 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4807 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4808 &infoPtr->nBitmapHeight))
4810 infoPtr->nBitmapWidth = 1;
4811 infoPtr->nBitmapHeight = 1;
4813 TOOLBAR_CalcToolbar(hwnd);
4814 if (infoPtr->nButtonWidth < oldButtonWidth)
4815 TOOLBAR_SetButtonSize(hwnd, 0, MAKELONG(oldButtonWidth, infoPtr->nButtonHeight));
4817 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4818 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4819 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4821 InvalidateRect(hwnd, NULL, TRUE);
4823 return (LRESULT)himlTemp;
4827 static LRESULT
4828 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4830 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4832 infoPtr->nIndent = (INT)wParam;
4834 TRACE("\n");
4836 /* process only on indent changing */
4837 if(infoPtr->nIndent != (INT)wParam)
4839 infoPtr->nIndent = (INT)wParam;
4840 TOOLBAR_CalcToolbar (hwnd);
4841 InvalidateRect(hwnd, NULL, FALSE);
4844 return TRUE;
4848 static LRESULT
4849 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4851 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4852 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4854 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4856 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4858 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4859 return 0;
4862 if ((lptbim->iButton == -1) ||
4863 ((lptbim->iButton < infoPtr->nNumButtons) &&
4864 (lptbim->iButton >= 0)))
4866 infoPtr->tbim = *lptbim;
4867 /* FIXME: don't need to update entire toolbar */
4868 InvalidateRect(hwnd, NULL, TRUE);
4870 else
4871 ERR("Invalid button index %d\n", lptbim->iButton);
4873 return 0;
4877 static LRESULT
4878 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4880 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4882 infoPtr->clrInsertMark = (COLORREF)lParam;
4884 /* FIXME: don't need to update entire toolbar */
4885 InvalidateRect(hwnd, NULL, TRUE);
4887 return 0;
4891 static LRESULT
4892 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4894 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4896 infoPtr->nMaxTextRows = (INT)wParam;
4898 TOOLBAR_CalcToolbar(hwnd);
4899 return TRUE;
4903 /* MSDN gives slightly wrong info on padding.
4904 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4905 * 2. It is not used to create a blank area between the edge of the button
4906 * and the text or image if TBSTYLE_LIST is set. It is used to control
4907 * the gap between the image and text.
4908 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4909 * to control the bottom and right borders [with the border being
4910 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4911 * is shared evenly on both sides of the button.
4912 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4914 static LRESULT
4915 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4917 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4918 DWORD oldPad;
4920 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4921 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4922 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4923 TRACE("cx=%d, cy=%d\n",
4924 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4925 return (LRESULT) oldPad;
4929 static LRESULT
4930 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4932 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4933 HWND hwndOldNotify;
4935 TRACE("\n");
4937 hwndOldNotify = infoPtr->hwndNotify;
4938 infoPtr->hwndNotify = (HWND)wParam;
4940 return (LRESULT)hwndOldNotify;
4944 static LRESULT
4945 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4947 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4948 LPRECT lprc = (LPRECT)lParam;
4950 TRACE("\n");
4952 if (LOWORD(wParam) > 1) {
4953 FIXME("multiple rows not supported!\n");
4956 if(infoPtr->nRows != LOWORD(wParam))
4958 infoPtr->nRows = LOWORD(wParam);
4960 /* recalculate toolbar */
4961 TOOLBAR_CalcToolbar (hwnd);
4963 /* repaint toolbar */
4964 InvalidateRect(hwnd, NULL, TRUE);
4967 /* return bounding rectangle */
4968 if (lprc) {
4969 lprc->left = infoPtr->rcBound.left;
4970 lprc->right = infoPtr->rcBound.right;
4971 lprc->top = infoPtr->rcBound.top;
4972 lprc->bottom = infoPtr->rcBound.bottom;
4975 return 0;
4979 static LRESULT
4980 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4982 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4983 TBUTTON_INFO *btnPtr;
4984 INT nIndex;
4986 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4987 if (nIndex == -1)
4988 return FALSE;
4990 btnPtr = &infoPtr->buttons[nIndex];
4992 /* if hidden state has changed the invalidate entire window and recalc */
4993 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4994 btnPtr->fsState = LOWORD(lParam);
4995 TOOLBAR_CalcToolbar (hwnd);
4996 InvalidateRect(hwnd, 0, TRUE);
4997 return TRUE;
5000 /* process state changing if current state doesn't match new state */
5001 if(btnPtr->fsState != LOWORD(lParam))
5003 btnPtr->fsState = LOWORD(lParam);
5004 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5007 return TRUE;
5011 static LRESULT
5012 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5014 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5016 return TRUE;
5020 static inline LRESULT
5021 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5023 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5025 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5027 infoPtr->hwndToolTip = (HWND)wParam;
5028 return 0;
5032 static LRESULT
5033 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5035 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5036 BOOL bTemp;
5038 TRACE("%s hwnd=%p\n",
5039 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5041 bTemp = infoPtr->bUnicode;
5042 infoPtr->bUnicode = (BOOL)wParam;
5044 return bTemp;
5048 static LRESULT
5049 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5051 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5053 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5054 comctl32_color.clrBtnHighlight :
5055 infoPtr->clrBtnHighlight;
5056 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5057 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5058 return 1;
5062 static LRESULT
5063 TOOLBAR_SetColorScheme (HWND hwnd, const COLORSCHEME *lParam)
5065 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5067 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5068 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5069 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5071 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5072 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5073 InvalidateRect(hwnd, NULL, TRUE);
5074 return 0;
5078 static LRESULT
5079 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5081 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5082 INT iOldVersion = infoPtr->iVersion;
5084 infoPtr->iVersion = iVersion;
5086 if (infoPtr->iVersion >= 5)
5087 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5089 return iOldVersion;
5093 static LRESULT
5094 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5096 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5097 WORD iString = HIWORD(wParam);
5098 WORD buffersize = LOWORD(wParam);
5099 LPSTR str = (LPSTR)lParam;
5100 LRESULT ret = -1;
5102 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5104 if (iString < infoPtr->nNumStrings)
5106 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5108 TRACE("returning %s\n", debugstr_a(str));
5110 else
5111 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5113 return ret;
5117 static LRESULT
5118 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5120 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5121 WORD iString = HIWORD(wParam);
5122 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5123 LPWSTR str = (LPWSTR)lParam;
5124 LRESULT ret = -1;
5126 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5128 if (iString < infoPtr->nNumStrings)
5130 len = min(len, strlenW(infoPtr->strings[iString]));
5131 ret = (len+1)*sizeof(WCHAR);
5132 memcpy(str, infoPtr->strings[iString], ret);
5133 str[len] = '\0';
5135 TRACE("returning %s\n", debugstr_w(str));
5137 else
5138 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5140 return ret;
5143 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5144 * is the maximum size of the toolbar? */
5145 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5147 SIZE * pSize = (SIZE*)lParam;
5148 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5149 return 0;
5153 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5154 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5155 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5156 * sends). */
5157 static LRESULT
5158 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5160 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5161 INT nOldHotItem = infoPtr->nHotItem;
5163 TRACE("old item=%d, new item=%d, flags=%08x\n",
5164 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5166 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5167 wParam = -1;
5169 /* NOTE: an application can still remove the hot item even if anchor
5170 * highlighting is enabled */
5172 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5174 GetFocus();
5176 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5179 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5180 * which controls the amount of spacing between the image and the text
5181 * of buttons for TBSTYLE_LIST toolbars. */
5182 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5184 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5186 TRACE("hwnd=%p iListGap=%ld\n", hwnd, wParam);
5188 if (lParam != 0)
5189 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5191 infoPtr->iListGap = (INT)wParam;
5193 InvalidateRect(hwnd, NULL, TRUE);
5195 return 0;
5198 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5199 * of image lists associated with the various states. */
5200 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5202 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5204 TRACE("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5206 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5209 static LRESULT
5210 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5212 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5213 LPSIZE lpsize = (LPSIZE)lParam;
5215 if (lpsize == NULL)
5216 return FALSE;
5219 * Testing shows the following:
5220 * wParam = 0 adjust cx value
5221 * = 1 set cy value to max size.
5222 * lParam pointer to SIZE structure
5225 TRACE("[0463] wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5226 wParam, lParam, lpsize->cx, lpsize->cy);
5228 switch(wParam) {
5229 case 0:
5230 if (lpsize->cx == -1) {
5231 /* **** this is wrong, native measures each button and sets it */
5232 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5234 else if(HIWORD(lpsize->cx)) {
5235 RECT rc;
5236 HWND hwndParent = GetParent(hwnd);
5238 GetWindowRect(hwnd, &rc);
5239 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5240 TRACE("mapped to (%d,%d)-(%d,%d)\n",
5241 rc.left, rc.top, rc.right, rc.bottom);
5242 lpsize->cx = max(rc.right-rc.left,
5243 infoPtr->rcBound.right - infoPtr->rcBound.left);
5245 else {
5246 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5248 break;
5249 case 1:
5250 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5251 break;
5252 default:
5253 ERR("Unknown wParam %ld for Toolbar message [0463]. Please report\n",
5254 wParam);
5255 return 0;
5257 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5258 lpsize->cx, lpsize->cy);
5259 return 1;
5262 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5264 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5266 InvalidateRect(hwnd, NULL, TRUE);
5267 return 1;
5271 static LRESULT
5272 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5274 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5275 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5276 LOGFONTW logFont;
5278 TRACE("hwnd = %p\n", hwnd);
5280 /* initialize info structure */
5281 infoPtr->nButtonWidth = 23;
5282 infoPtr->nButtonHeight = 22;
5283 infoPtr->nBitmapHeight = 16;
5284 infoPtr->nBitmapWidth = 16;
5286 infoPtr->nMaxTextRows = 1;
5287 infoPtr->cxMin = -1;
5288 infoPtr->cxMax = -1;
5289 infoPtr->nNumBitmaps = 0;
5290 infoPtr->nNumStrings = 0;
5292 infoPtr->bCaptured = FALSE;
5293 infoPtr->nButtonDown = -1;
5294 infoPtr->nButtonDrag = -1;
5295 infoPtr->nOldHit = -1;
5296 infoPtr->nHotItem = -1;
5297 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5298 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5299 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5300 infoPtr->bDragOutSent = FALSE;
5301 infoPtr->iVersion = 0;
5302 infoPtr->hwndSelf = hwnd;
5303 infoPtr->bDoRedraw = TRUE;
5304 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5305 infoPtr->clrBtnShadow = CLR_DEFAULT;
5306 infoPtr->szPadding.cx = DEFPAD_CX;
5307 infoPtr->szPadding.cy = DEFPAD_CY;
5308 infoPtr->iListGap = DEFLISTGAP;
5309 infoPtr->iTopMargin = default_top_margin(infoPtr);
5310 infoPtr->dwStyle = dwStyle;
5311 infoPtr->tbim.iButton = -1;
5312 GetClientRect(hwnd, &infoPtr->client_rect);
5313 infoPtr->bUnicode = infoPtr->hwndNotify &&
5314 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5315 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5317 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5318 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5320 OpenThemeData (hwnd, themeClass);
5322 TOOLBAR_CheckStyle (hwnd, dwStyle);
5324 return 0;
5328 static LRESULT
5329 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5331 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5333 /* delete tooltip control */
5334 if (infoPtr->hwndToolTip)
5335 DestroyWindow (infoPtr->hwndToolTip);
5337 /* delete temporary buffer for tooltip text */
5338 Free (infoPtr->pszTooltipText);
5339 Free (infoPtr->bitmaps); /* bitmaps list */
5341 /* delete button data */
5342 Free (infoPtr->buttons);
5344 /* delete strings */
5345 if (infoPtr->strings) {
5346 INT i;
5347 for (i = 0; i < infoPtr->nNumStrings; i++)
5348 if (infoPtr->strings[i])
5349 Free (infoPtr->strings[i]);
5351 Free (infoPtr->strings);
5354 /* destroy internal image list */
5355 if (infoPtr->himlInt)
5356 ImageList_Destroy (infoPtr->himlInt);
5358 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5359 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5360 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5362 /* delete default font */
5363 DeleteObject (infoPtr->hDefaultFont);
5365 CloseThemeData (GetWindowTheme (hwnd));
5367 /* free toolbar info data */
5368 Free (infoPtr);
5369 SetWindowLongPtrW (hwnd, 0, 0);
5371 return 0;
5375 static LRESULT
5376 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5378 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5379 NMTBCUSTOMDRAW tbcd;
5380 INT ret = FALSE;
5381 DWORD ntfret;
5382 HTHEME theme = GetWindowTheme (hwnd);
5383 DWORD dwEraseCustDraw = 0;
5385 /* the app has told us not to redraw the toolbar */
5386 if (!infoPtr->bDoRedraw)
5387 return FALSE;
5389 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5390 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5391 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5392 tbcd.nmcd.hdc = (HDC)wParam;
5393 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5394 dwEraseCustDraw = ntfret & 0xffff;
5396 /* FIXME: in general the return flags *can* be or'ed together */
5397 switch (dwEraseCustDraw)
5399 case CDRF_DODEFAULT:
5400 break;
5401 case CDRF_SKIPDEFAULT:
5402 return TRUE;
5403 default:
5404 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5405 hwnd, ntfret);
5409 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5410 * to my parent for processing.
5412 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5413 POINT pt, ptorig;
5414 HDC hdc = (HDC)wParam;
5415 HWND parent;
5417 pt.x = 0;
5418 pt.y = 0;
5419 parent = GetParent(hwnd);
5420 MapWindowPoints(hwnd, parent, &pt, 1);
5421 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5422 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5423 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5425 if (!ret)
5426 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5428 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5429 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5430 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5431 tbcd.nmcd.hdc = (HDC)wParam;
5432 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5433 dwEraseCustDraw = ntfret & 0xffff;
5434 switch (dwEraseCustDraw)
5436 case CDRF_DODEFAULT:
5437 break;
5438 case CDRF_SKIPDEFAULT:
5439 return TRUE;
5440 default:
5441 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5442 hwnd, ntfret);
5445 return ret;
5449 static LRESULT
5450 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5452 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5454 return (LRESULT)infoPtr->hFont;
5458 static void
5459 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5461 INT i;
5462 INT nNewHotItem = infoPtr->nHotItem;
5464 for (i = 0; i < infoPtr->nNumButtons; i++)
5466 /* did we wrap? */
5467 if ((nNewHotItem + iDirection < 0) ||
5468 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5470 NMTBWRAPHOTITEM nmtbwhi;
5471 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5472 nmtbwhi.iDirection = iDirection;
5473 nmtbwhi.dwReason = dwReason;
5475 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5476 return;
5479 nNewHotItem += iDirection;
5480 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5482 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5483 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5485 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5486 break;
5491 static LRESULT
5492 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5494 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5495 NMKEY nmkey;
5497 nmkey.nVKey = (UINT)wParam;
5498 nmkey.uFlags = HIWORD(lParam);
5500 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5501 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5503 switch ((UINT)wParam)
5505 case VK_LEFT:
5506 case VK_UP:
5507 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5508 break;
5509 case VK_RIGHT:
5510 case VK_DOWN:
5511 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5512 break;
5513 case VK_SPACE:
5514 case VK_RETURN:
5515 if ((infoPtr->nHotItem >= 0) &&
5516 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5518 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5519 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5520 (LPARAM)hwnd);
5522 break;
5525 return 0;
5529 static LRESULT
5530 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5532 POINT pt;
5533 INT nHit;
5535 pt.x = (short)LOWORD(lParam);
5536 pt.y = (short)HIWORD(lParam);
5537 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5539 if (nHit >= 0)
5540 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5541 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5542 TOOLBAR_Customize (hwnd);
5544 return 0;
5548 static LRESULT
5549 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5551 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5552 TBUTTON_INFO *btnPtr;
5553 POINT pt;
5554 INT nHit;
5555 NMTOOLBARA nmtb;
5556 NMMOUSE nmmouse;
5557 BOOL bDragKeyPressed;
5559 TRACE("\n");
5561 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5562 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5563 else
5564 bDragKeyPressed = (wParam & MK_SHIFT);
5566 if (infoPtr->hwndToolTip)
5567 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5568 WM_LBUTTONDOWN, wParam, lParam);
5570 pt.x = (short)LOWORD(lParam);
5571 pt.y = (short)HIWORD(lParam);
5572 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5574 btnPtr = &infoPtr->buttons[nHit];
5576 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5578 infoPtr->nButtonDrag = nHit;
5579 SetCapture (hwnd);
5581 /* If drag cursor has not been loaded, load it.
5582 * Note: it doesn't need to be freed */
5583 if (!hCursorDrag)
5584 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5585 SetCursor(hCursorDrag);
5587 else if (nHit >= 0)
5589 RECT arrowRect;
5590 infoPtr->nOldHit = nHit;
5592 CopyRect(&arrowRect, &btnPtr->rect);
5593 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5595 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5596 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5597 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5598 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5599 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5600 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5602 LRESULT res;
5604 /* draw in pressed state */
5605 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5606 btnPtr->fsState |= TBSTATE_PRESSED;
5607 else
5608 btnPtr->bDropDownPressed = TRUE;
5609 RedrawWindow(hwnd,&btnPtr->rect,0,
5610 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5612 memset(&nmtb, 0, sizeof(nmtb));
5613 nmtb.iItem = btnPtr->idCommand;
5614 nmtb.rcButton = btnPtr->rect;
5615 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5616 TBN_DROPDOWN);
5617 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5619 if (res != TBDDRET_TREATPRESSED)
5621 MSG msg;
5623 /* redraw button in unpressed state */
5624 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5625 btnPtr->fsState &= ~TBSTATE_PRESSED;
5626 else
5627 btnPtr->bDropDownPressed = FALSE;
5628 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5630 /* find and set hot item
5631 * NOTE: native doesn't do this, but that is a bug */
5632 GetCursorPos(&pt);
5633 ScreenToClient(hwnd, &pt);
5634 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5635 if (!infoPtr->bAnchor || (nHit >= 0))
5636 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5638 /* remove any left mouse button down or double-click messages
5639 * so that we can get a toggle effect on the button */
5640 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5641 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5644 return 0;
5646 /* otherwise drop through and process as pushed */
5648 infoPtr->bCaptured = TRUE;
5649 infoPtr->nButtonDown = nHit;
5650 infoPtr->bDragOutSent = FALSE;
5652 btnPtr->fsState |= TBSTATE_PRESSED;
5654 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5656 if (btnPtr->fsState & TBSTATE_ENABLED)
5657 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5658 UpdateWindow(hwnd);
5659 SetCapture (hwnd);
5662 if (nHit >=0)
5664 memset(&nmtb, 0, sizeof(nmtb));
5665 nmtb.iItem = btnPtr->idCommand;
5666 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5669 nmmouse.dwHitInfo = nHit;
5671 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5672 if (nHit < 0)
5673 nmmouse.dwItemSpec = -1;
5674 else
5676 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5677 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5680 ClientToScreen(hwnd, &pt);
5681 nmmouse.pt = pt;
5683 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5684 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5686 return 0;
5689 static LRESULT
5690 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5692 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5693 TBUTTON_INFO *btnPtr;
5694 POINT pt;
5695 INT nHit;
5696 INT nOldIndex = -1;
5697 BOOL bSendMessage = TRUE;
5698 NMHDR hdr;
5699 NMMOUSE nmmouse;
5700 NMTOOLBARA nmtb;
5702 if (infoPtr->hwndToolTip)
5703 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5704 WM_LBUTTONUP, wParam, lParam);
5706 pt.x = (short)LOWORD(lParam);
5707 pt.y = (short)HIWORD(lParam);
5708 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5710 if (!infoPtr->bAnchor || (nHit >= 0))
5711 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5713 if (infoPtr->nButtonDrag >= 0) {
5714 RECT rcClient;
5715 NMHDR hdr;
5717 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5718 ReleaseCapture();
5719 /* reset cursor */
5720 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5722 GetClientRect(hwnd, &rcClient);
5723 if (PtInRect(&rcClient, pt))
5725 INT nButton = -1;
5726 if (nHit >= 0)
5727 nButton = nHit;
5728 else if (nHit < -1)
5729 nButton = -nHit;
5730 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5731 nButton = -nHit;
5733 if (nButton == infoPtr->nButtonDrag)
5735 /* if the button is moved sightly left and we have a
5736 * separator there then remove it */
5737 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5739 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5740 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5742 else /* else insert a separator before the dragged button */
5744 TBBUTTON tbb;
5745 memset(&tbb, 0, sizeof(tbb));
5746 tbb.fsStyle = BTNS_SEP;
5747 tbb.iString = -1;
5748 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5751 else
5753 if (nButton == -1)
5755 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5756 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5757 else
5758 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5760 else
5761 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5764 else
5766 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5767 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5770 /* button under cursor changed so need to re-set hot item */
5771 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5772 infoPtr->nButtonDrag = -1;
5774 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5776 else if (infoPtr->nButtonDown >= 0) {
5777 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5778 btnPtr->fsState &= ~TBSTATE_PRESSED;
5780 if (btnPtr->fsStyle & BTNS_CHECK) {
5781 if (btnPtr->fsStyle & BTNS_GROUP) {
5782 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5783 nHit);
5784 if (nOldIndex == nHit)
5785 bSendMessage = FALSE;
5786 if ((nOldIndex != nHit) &&
5787 (nOldIndex != -1))
5788 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5789 btnPtr->fsState |= TBSTATE_CHECKED;
5791 else {
5792 if (btnPtr->fsState & TBSTATE_CHECKED)
5793 btnPtr->fsState &= ~TBSTATE_CHECKED;
5794 else
5795 btnPtr->fsState |= TBSTATE_CHECKED;
5799 if (nOldIndex != -1)
5800 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5803 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5804 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5805 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5807 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5808 ReleaseCapture ();
5809 infoPtr->nButtonDown = -1;
5811 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5812 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5813 NM_RELEASEDCAPTURE);
5815 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5816 * TBN_BEGINDRAG
5818 memset(&nmtb, 0, sizeof(nmtb));
5819 nmtb.iItem = btnPtr->idCommand;
5820 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5821 TBN_ENDDRAG);
5823 if (btnPtr->fsState & TBSTATE_ENABLED)
5825 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5826 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5828 /* In case we have just been destroyed... */
5829 if(!IsWindow(hwnd))
5830 return 0;
5834 /* !!! Undocumented - toolbar at 4.71 level and above sends
5835 * NM_CLICK with the NMMOUSE structure. */
5836 nmmouse.dwHitInfo = nHit;
5838 if (nHit < 0)
5839 nmmouse.dwItemSpec = -1;
5840 else
5842 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5843 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5846 ClientToScreen(hwnd, &pt);
5847 nmmouse.pt = pt;
5849 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5850 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5852 return 0;
5855 static LRESULT
5856 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5858 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5859 INT nHit;
5860 NMMOUSE nmmouse;
5861 POINT pt;
5863 pt.x = (short)LOWORD(lParam);
5864 pt.y = (short)HIWORD(lParam);
5866 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5867 nmmouse.dwHitInfo = nHit;
5869 if (nHit < 0) {
5870 nmmouse.dwItemSpec = -1;
5871 } else {
5872 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5873 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5876 ClientToScreen(hwnd, &pt);
5877 nmmouse.pt = pt;
5879 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5880 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5882 return 0;
5885 static LRESULT
5886 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5888 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5889 NMHDR nmhdr;
5891 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5892 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5894 return 0;
5897 static LRESULT
5898 TOOLBAR_CaptureChanged(HWND hwnd)
5900 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5901 TBUTTON_INFO *btnPtr;
5903 infoPtr->bCaptured = FALSE;
5905 if (infoPtr->nButtonDown >= 0)
5907 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5908 btnPtr->fsState &= ~TBSTATE_PRESSED;
5910 infoPtr->nOldHit = -1;
5912 if (btnPtr->fsState & TBSTATE_ENABLED)
5913 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5915 return 0;
5918 static LRESULT
5919 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5921 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5923 /* don't remove hot effects when in anchor highlighting mode or when a
5924 * drop-down button is pressed */
5925 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
5927 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5928 if (!hotBtnPtr->bDropDownPressed)
5929 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
5932 if (infoPtr->nOldHit < 0)
5933 return TRUE;
5935 /* If the last button we were over is depressed then make it not */
5936 /* depressed and redraw it */
5937 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5939 TBUTTON_INFO *btnPtr;
5940 RECT rc1;
5942 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5944 btnPtr->fsState &= ~TBSTATE_PRESSED;
5946 rc1 = btnPtr->rect;
5947 InflateRect (&rc1, 1, 1);
5948 InvalidateRect (hwnd, &rc1, TRUE);
5951 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
5953 NMTOOLBARW nmt;
5954 ZeroMemory(&nmt, sizeof(nmt));
5955 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5956 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5957 infoPtr->bDragOutSent = TRUE;
5960 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5962 return TRUE;
5965 static LRESULT
5966 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5968 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5969 POINT pt;
5970 TRACKMOUSEEVENT trackinfo;
5971 INT nHit;
5972 TBUTTON_INFO *btnPtr;
5974 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
5975 TOOLBAR_TooltipCreateControl(infoPtr);
5977 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
5978 /* fill in the TRACKMOUSEEVENT struct */
5979 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5980 trackinfo.dwFlags = TME_QUERY;
5982 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5983 _TrackMouseEvent(&trackinfo);
5985 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5986 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
5987 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5988 trackinfo.hwndTrack = hwnd;
5990 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5991 /* and can properly deactivate the hot toolbar button */
5992 _TrackMouseEvent(&trackinfo);
5996 if (infoPtr->hwndToolTip)
5997 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5998 WM_MOUSEMOVE, wParam, lParam);
6000 pt.x = (short)LOWORD(lParam);
6001 pt.y = (short)HIWORD(lParam);
6003 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6005 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6006 && (!infoPtr->bAnchor || (nHit >= 0)))
6007 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6009 if (infoPtr->nOldHit != nHit)
6011 if (infoPtr->bCaptured)
6013 if (!infoPtr->bDragOutSent)
6015 NMTOOLBARW nmt;
6016 ZeroMemory(&nmt, sizeof(nmt));
6017 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6018 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6019 infoPtr->bDragOutSent = TRUE;
6022 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6023 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6024 btnPtr->fsState &= ~TBSTATE_PRESSED;
6025 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6027 else if (nHit == infoPtr->nButtonDown) {
6028 btnPtr->fsState |= TBSTATE_PRESSED;
6029 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6031 infoPtr->nOldHit = nHit;
6035 return 0;
6039 static inline LRESULT
6040 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6042 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6043 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6044 /* else */
6045 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6049 static inline LRESULT
6050 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6052 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6053 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6055 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6059 static LRESULT
6060 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6062 TOOLBAR_INFO *infoPtr;
6063 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6064 DWORD styleadd = 0;
6066 /* allocate memory for info structure */
6067 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6068 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6070 /* paranoid!! */
6071 infoPtr->dwStructSize = sizeof(TBBUTTON);
6072 infoPtr->nRows = 1;
6073 infoPtr->nWidth = 0;
6075 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6076 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6077 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6078 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6081 /* native control does:
6082 * Get a lot of colors and brushes
6083 * WM_NOTIFYFORMAT
6084 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6085 * CreateFontIndirectW(adr1)
6086 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6087 * hdc = GetDC(toolbar)
6088 * GetSystemMetrics(0x48)
6089 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6090 * 0, 0, 0, 0, "MARLETT")
6091 * oldfnt = SelectObject(hdc, fnt2)
6092 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6093 * GetTextMetricsW(hdc, adr3)
6094 * SelectObject(hdc, oldfnt)
6095 * DeleteObject(fnt2)
6096 * ReleaseDC(hdc)
6097 * InvalidateRect(toolbar, 0, 1)
6098 * SetWindowLongW(toolbar, 0, addr)
6099 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6100 * WM_STYLECHANGING
6101 * CallWinEx old new
6102 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6103 * ie 2 0x4600094c 0x4600094c 0x4600894d
6104 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6105 * rebar 0x50008844 0x40008844 0x50008845
6106 * pager 0x50000844 0x40000844 0x50008845
6107 * IC35mgr 0x5400084e **nochange**
6108 * on entry to _NCCREATE 0x5400084e
6109 * rowlist 0x5400004e **nochange**
6110 * on entry to _NCCREATE 0x5400004e
6114 /* I think the code below is a bug, but it is the way that the native
6115 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6116 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6117 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6118 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6119 * Somehow, the only cases of this seem to be MFC programs.
6121 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6122 * does not occur in the WM_STYLECHANGING routine.
6123 * (Guy Albertelli 9/2001)
6126 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6127 && !(cs->style & TBSTYLE_TRANSPARENT))
6128 styleadd |= TBSTYLE_TRANSPARENT;
6129 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6130 styleadd |= CCS_TOP; /* default to top */
6131 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6134 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6138 static LRESULT
6139 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6141 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6142 RECT rcWindow;
6143 HDC hdc;
6145 if (dwStyle & WS_MINIMIZE)
6146 return 0; /* Nothing to do */
6148 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6150 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6151 return 0;
6153 if (!(dwStyle & CCS_NODIVIDER))
6155 GetWindowRect (hwnd, &rcWindow);
6156 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6157 if( dwStyle & WS_BORDER )
6158 OffsetRect (&rcWindow, 1, 1);
6159 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6162 ReleaseDC( hwnd, hdc );
6164 return 0;
6168 /* handles requests from the tooltip control on what text to display */
6169 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6171 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6173 TRACE("button index = %d\n", index);
6175 Free (infoPtr->pszTooltipText);
6176 infoPtr->pszTooltipText = NULL;
6178 if (index < 0)
6179 return 0;
6181 if (infoPtr->bUnicode)
6183 WCHAR wszBuffer[INFOTIPSIZE+1];
6184 NMTBGETINFOTIPW tbgit;
6185 unsigned int len; /* in chars */
6187 wszBuffer[0] = '\0';
6188 wszBuffer[INFOTIPSIZE] = '\0';
6190 tbgit.pszText = wszBuffer;
6191 tbgit.cchTextMax = INFOTIPSIZE;
6192 tbgit.iItem = lpnmtdi->hdr.idFrom;
6193 tbgit.lParam = infoPtr->buttons[index].dwData;
6195 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6197 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6199 len = strlenW(tbgit.pszText);
6200 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6202 /* need to allocate temporary buffer in infoPtr as there
6203 * isn't enough space in buffer passed to us by the
6204 * tooltip control */
6205 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6206 if (infoPtr->pszTooltipText)
6208 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6209 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6210 return 0;
6213 else if (len > 0)
6215 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6216 return 0;
6219 else
6221 CHAR szBuffer[INFOTIPSIZE+1];
6222 NMTBGETINFOTIPA tbgit;
6223 unsigned int len; /* in chars */
6225 szBuffer[0] = '\0';
6226 szBuffer[INFOTIPSIZE] = '\0';
6228 tbgit.pszText = szBuffer;
6229 tbgit.cchTextMax = INFOTIPSIZE;
6230 tbgit.iItem = lpnmtdi->hdr.idFrom;
6231 tbgit.lParam = infoPtr->buttons[index].dwData;
6233 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6235 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6237 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6238 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6240 /* need to allocate temporary buffer in infoPtr as there
6241 * isn't enough space in buffer passed to us by the
6242 * tooltip control */
6243 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6244 if (infoPtr->pszTooltipText)
6246 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6247 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6248 return 0;
6251 else if (len > 0)
6253 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6254 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6255 return 0;
6259 /* if button has text, but it is not shown then automatically
6260 * use that text as tooltip */
6261 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6262 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6264 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6265 unsigned int len = pszText ? strlenW(pszText) : 0;
6267 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6269 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6271 /* need to allocate temporary buffer in infoPtr as there
6272 * isn't enough space in buffer passed to us by the
6273 * tooltip control */
6274 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6275 if (infoPtr->pszTooltipText)
6277 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6278 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6279 return 0;
6282 else if (len > 0)
6284 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6285 return 0;
6289 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6291 /* last resort: send notification on to app */
6292 /* FIXME: find out what is really used here */
6293 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6297 static inline LRESULT
6298 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6300 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6301 LPNMHDR lpnmh = (LPNMHDR)lParam;
6303 switch (lpnmh->code)
6305 case PGN_CALCSIZE:
6307 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6309 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6310 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6311 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6312 lppgc->iWidth);
6314 else {
6315 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6316 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6317 lppgc->iHeight);
6319 return 0;
6322 case PGN_SCROLL:
6324 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6326 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6327 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6328 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6329 lppgs->iScroll, lppgs->iDir);
6330 return 0;
6333 case TTN_GETDISPINFOW:
6334 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6336 case TTN_GETDISPINFOA:
6337 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6338 return 0;
6340 default:
6341 return 0;
6346 static LRESULT
6347 TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6349 LRESULT format;
6351 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam, lParam);
6353 if (lParam == NF_QUERY)
6354 return NFR_UNICODE;
6356 if (lParam == NF_REQUERY) {
6357 format = SendMessageW(infoPtr->hwndNotify,
6358 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6359 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6360 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6361 format);
6362 format = NFR_ANSI;
6364 return format;
6366 return 0;
6370 static LRESULT
6371 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6373 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6374 HDC hdc;
6375 PAINTSTRUCT ps;
6377 /* fill ps.rcPaint with a default rect */
6378 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6380 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6382 TRACE("psrect=(%d,%d)-(%d,%d)\n",
6383 ps.rcPaint.left, ps.rcPaint.top,
6384 ps.rcPaint.right, ps.rcPaint.bottom);
6386 TOOLBAR_Refresh (hwnd, hdc, &ps);
6387 if (!wParam) EndPaint (hwnd, &ps);
6389 return 0;
6393 static LRESULT
6394 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6396 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6398 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6400 /* make first item hot */
6401 if (infoPtr->nNumButtons > 0)
6402 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6404 return 0;
6407 static LRESULT
6408 TOOLBAR_SetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
6410 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6412 TRACE("font=%p redraw=%ld\n", (HFONT)wParam, lParam);
6414 if (wParam == 0)
6415 infoPtr->hFont = infoPtr->hDefaultFont;
6416 else
6417 infoPtr->hFont = (HFONT)wParam;
6419 TOOLBAR_CalcToolbar(hwnd);
6421 if (lParam)
6422 InvalidateRect(hwnd, NULL, TRUE);
6423 return 1;
6426 static LRESULT
6427 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6428 /*****************************************************
6430 * Function;
6431 * Handles the WM_SETREDRAW message.
6433 * Documentation:
6434 * According to testing V4.71 of COMCTL32 returns the
6435 * *previous* status of the redraw flag (either 0 or 1)
6436 * instead of the MSDN documented value of 0 if handled.
6437 * (For laughs see the "consistency" with same function
6438 * in rebar.)
6440 *****************************************************/
6442 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6443 BOOL oldredraw = infoPtr->bDoRedraw;
6445 TRACE("set to %s\n",
6446 (wParam) ? "TRUE" : "FALSE");
6447 infoPtr->bDoRedraw = (BOOL) wParam;
6448 if (wParam) {
6449 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6451 return (oldredraw) ? 1 : 0;
6455 static LRESULT
6456 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6458 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6460 TRACE("sizing toolbar!\n");
6462 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6464 RECT delta_width, delta_height, client, dummy;
6465 DWORD min_x, max_x, min_y, max_y;
6466 TBUTTON_INFO *btnPtr;
6467 INT i;
6469 GetClientRect(hwnd, &client);
6470 if(client.right > infoPtr->client_rect.right)
6472 min_x = infoPtr->client_rect.right;
6473 max_x = client.right;
6475 else
6477 max_x = infoPtr->client_rect.right;
6478 min_x = client.right;
6480 if(client.bottom > infoPtr->client_rect.bottom)
6482 min_y = infoPtr->client_rect.bottom;
6483 max_y = client.bottom;
6485 else
6487 max_y = infoPtr->client_rect.bottom;
6488 min_y = client.bottom;
6491 SetRect(&delta_width, min_x, 0, max_x, min_y);
6492 SetRect(&delta_height, 0, min_y, max_x, max_y);
6494 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6495 btnPtr = infoPtr->buttons;
6496 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6497 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6498 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6499 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6501 GetClientRect(hwnd, &infoPtr->client_rect);
6502 TOOLBAR_AutoSize(hwnd);
6503 return 0;
6507 static LRESULT
6508 TOOLBAR_StyleChanged (HWND hwnd, INT nType, const STYLESTRUCT *lpStyle)
6510 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6512 if (nType == GWL_STYLE)
6514 DWORD dwOldStyle = infoPtr->dwStyle;
6516 if (lpStyle->styleNew & TBSTYLE_LIST)
6517 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6518 else
6519 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6521 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6523 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6525 infoPtr->dwStyle = lpStyle->styleNew;
6527 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6528 TOOLBAR_LayoutToolbar(hwnd);
6530 /* only resize if one of the CCS_* styles was changed */
6531 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6533 TOOLBAR_AutoSize (hwnd);
6535 InvalidateRect(hwnd, NULL, TRUE);
6539 return 0;
6543 static LRESULT
6544 TOOLBAR_SysColorChange (HWND hwnd)
6546 COMCTL32_RefreshSysColors();
6548 return 0;
6552 /* update theme after a WM_THEMECHANGED message */
6553 static LRESULT theme_changed (HWND hwnd)
6555 HTHEME theme = GetWindowTheme (hwnd);
6556 CloseThemeData (theme);
6557 OpenThemeData (hwnd, themeClass);
6558 return 0;
6562 static LRESULT WINAPI
6563 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6565 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6567 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6568 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6570 if (!infoPtr && (uMsg != WM_NCCREATE))
6571 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6573 switch (uMsg)
6575 case TB_ADDBITMAP:
6576 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6578 case TB_ADDBUTTONSA:
6579 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6581 case TB_ADDBUTTONSW:
6582 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6584 case TB_ADDSTRINGA:
6585 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6587 case TB_ADDSTRINGW:
6588 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6590 case TB_AUTOSIZE:
6591 return TOOLBAR_AutoSize (hwnd);
6593 case TB_BUTTONCOUNT:
6594 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6596 case TB_BUTTONSTRUCTSIZE:
6597 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6599 case TB_CHANGEBITMAP:
6600 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6602 case TB_CHECKBUTTON:
6603 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6605 case TB_COMMANDTOINDEX:
6606 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6608 case TB_CUSTOMIZE:
6609 return TOOLBAR_Customize (hwnd);
6611 case TB_DELETEBUTTON:
6612 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6614 case TB_ENABLEBUTTON:
6615 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6617 case TB_GETANCHORHIGHLIGHT:
6618 return TOOLBAR_GetAnchorHighlight (hwnd);
6620 case TB_GETBITMAP:
6621 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6623 case TB_GETBITMAPFLAGS:
6624 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6626 case TB_GETBUTTON:
6627 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6629 case TB_GETBUTTONINFOA:
6630 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, FALSE);
6632 case TB_GETBUTTONINFOW:
6633 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, TRUE);
6635 case TB_GETBUTTONSIZE:
6636 return TOOLBAR_GetButtonSize (hwnd);
6638 case TB_GETBUTTONTEXTA:
6639 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6641 case TB_GETBUTTONTEXTW:
6642 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6644 case TB_GETDISABLEDIMAGELIST:
6645 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6647 case TB_GETEXTENDEDSTYLE:
6648 return TOOLBAR_GetExtendedStyle (hwnd);
6650 case TB_GETHOTIMAGELIST:
6651 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6653 case TB_GETHOTITEM:
6654 return TOOLBAR_GetHotItem (hwnd);
6656 case TB_GETIMAGELIST:
6657 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6659 case TB_GETINSERTMARK:
6660 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6662 case TB_GETINSERTMARKCOLOR:
6663 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6665 case TB_GETITEMRECT:
6666 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6668 case TB_GETMAXSIZE:
6669 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6671 /* case TB_GETOBJECT: */ /* 4.71 */
6673 case TB_GETPADDING:
6674 return TOOLBAR_GetPadding (hwnd);
6676 case TB_GETRECT:
6677 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6679 case TB_GETROWS:
6680 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6682 case TB_GETSTATE:
6683 return TOOLBAR_GetState (hwnd, wParam, lParam);
6685 case TB_GETSTRINGA:
6686 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6688 case TB_GETSTRINGW:
6689 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6691 case TB_GETSTYLE:
6692 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6694 case TB_GETTEXTROWS:
6695 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6697 case TB_GETTOOLTIPS:
6698 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6700 case TB_GETUNICODEFORMAT:
6701 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6703 case TB_HIDEBUTTON:
6704 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6706 case TB_HITTEST:
6707 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6709 case TB_INDETERMINATE:
6710 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6712 case TB_INSERTBUTTONA:
6713 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6715 case TB_INSERTBUTTONW:
6716 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6718 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6720 case TB_ISBUTTONCHECKED:
6721 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6723 case TB_ISBUTTONENABLED:
6724 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6726 case TB_ISBUTTONHIDDEN:
6727 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6729 case TB_ISBUTTONHIGHLIGHTED:
6730 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6732 case TB_ISBUTTONINDETERMINATE:
6733 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6735 case TB_ISBUTTONPRESSED:
6736 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6738 case TB_LOADIMAGES:
6739 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6741 case TB_MAPACCELERATORA:
6742 case TB_MAPACCELERATORW:
6743 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6745 case TB_MARKBUTTON:
6746 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6748 case TB_MOVEBUTTON:
6749 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6751 case TB_PRESSBUTTON:
6752 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6754 case TB_REPLACEBITMAP:
6755 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6757 case TB_SAVERESTOREA:
6758 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6760 case TB_SAVERESTOREW:
6761 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6763 case TB_SETANCHORHIGHLIGHT:
6764 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6766 case TB_SETBITMAPSIZE:
6767 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6769 case TB_SETBUTTONINFOA:
6770 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6772 case TB_SETBUTTONINFOW:
6773 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6775 case TB_SETBUTTONSIZE:
6776 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6778 case TB_SETBUTTONWIDTH:
6779 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6781 case TB_SETCMDID:
6782 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6784 case TB_SETDISABLEDIMAGELIST:
6785 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6787 case TB_SETDRAWTEXTFLAGS:
6788 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6790 case TB_SETEXTENDEDSTYLE:
6791 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6793 case TB_SETHOTIMAGELIST:
6794 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6796 case TB_SETHOTITEM:
6797 return TOOLBAR_SetHotItem (hwnd, wParam);
6799 case TB_SETIMAGELIST:
6800 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6802 case TB_SETINDENT:
6803 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6805 case TB_SETINSERTMARK:
6806 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6808 case TB_SETINSERTMARKCOLOR:
6809 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6811 case TB_SETMAXTEXTROWS:
6812 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6814 case TB_SETPADDING:
6815 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6817 case TB_SETPARENT:
6818 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6820 case TB_SETROWS:
6821 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6823 case TB_SETSTATE:
6824 return TOOLBAR_SetState (hwnd, wParam, lParam);
6826 case TB_SETSTYLE:
6827 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6829 case TB_SETTOOLTIPS:
6830 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6832 case TB_SETUNICODEFORMAT:
6833 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6835 case TB_UNKWN45D:
6836 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6838 case TB_UNKWN45E:
6839 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6841 case TB_UNKWN460:
6842 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6844 case TB_UNKWN462:
6845 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6847 case TB_UNKWN463:
6848 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6850 case TB_UNKWN464:
6851 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6853 /* Common Control Messages */
6855 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6856 case CCM_GETCOLORSCHEME:
6857 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6859 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6860 case CCM_SETCOLORSCHEME:
6861 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6863 case CCM_GETVERSION:
6864 return TOOLBAR_GetVersion (hwnd);
6866 case CCM_SETVERSION:
6867 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6870 /* case WM_CHAR: */
6872 case WM_CREATE:
6873 return TOOLBAR_Create (hwnd, wParam, lParam);
6875 case WM_DESTROY:
6876 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6878 case WM_ERASEBKGND:
6879 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6881 case WM_GETFONT:
6882 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6884 case WM_KEYDOWN:
6885 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6887 /* case WM_KILLFOCUS: */
6889 case WM_LBUTTONDBLCLK:
6890 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6892 case WM_LBUTTONDOWN:
6893 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6895 case WM_LBUTTONUP:
6896 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6898 case WM_RBUTTONUP:
6899 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6901 case WM_RBUTTONDBLCLK:
6902 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6904 case WM_MOUSEMOVE:
6905 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6907 case WM_MOUSELEAVE:
6908 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6910 case WM_CAPTURECHANGED:
6911 return TOOLBAR_CaptureChanged(hwnd);
6913 case WM_NCACTIVATE:
6914 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6916 case WM_NCCALCSIZE:
6917 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6919 case WM_NCCREATE:
6920 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6922 case WM_NCPAINT:
6923 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6925 case WM_NOTIFY:
6926 return TOOLBAR_Notify (hwnd, wParam, lParam);
6928 case WM_NOTIFYFORMAT:
6929 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
6931 case WM_PRINTCLIENT:
6932 case WM_PAINT:
6933 return TOOLBAR_Paint (hwnd, wParam);
6935 case WM_SETFOCUS:
6936 return TOOLBAR_SetFocus (hwnd, wParam);
6938 case WM_SETFONT:
6939 return TOOLBAR_SetFont(hwnd, wParam, lParam);
6941 case WM_SETREDRAW:
6942 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6944 case WM_SIZE:
6945 return TOOLBAR_Size (hwnd, wParam, lParam);
6947 case WM_STYLECHANGED:
6948 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6950 case WM_SYSCOLORCHANGE:
6951 return TOOLBAR_SysColorChange (hwnd);
6953 case WM_THEMECHANGED:
6954 return theme_changed (hwnd);
6956 /* case WM_WININICHANGE: */
6958 case WM_CHARTOITEM:
6959 case WM_COMMAND:
6960 case WM_DRAWITEM:
6961 case WM_MEASUREITEM:
6962 case WM_VKEYTOITEM:
6963 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
6965 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6966 case PGM_FORWARDMOUSE:
6967 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
6969 default:
6970 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6971 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
6972 uMsg, wParam, lParam);
6973 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
6978 VOID
6979 TOOLBAR_Register (void)
6981 WNDCLASSW wndClass;
6983 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
6984 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6985 wndClass.lpfnWndProc = ToolbarWindowProc;
6986 wndClass.cbClsExtra = 0;
6987 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6988 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
6989 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
6990 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
6992 RegisterClassW (&wndClass);
6996 VOID
6997 TOOLBAR_Unregister (void)
6999 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7002 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7004 HIMAGELIST himlold;
7005 PIMLENTRY c = NULL;
7007 /* Check if the entry already exists */
7008 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7010 /* If this is a new entry we must create it and insert into the array */
7011 if (!c)
7013 PIMLENTRY *pnies;
7015 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7016 c->id = id;
7018 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7019 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7020 pnies[*cies] = c;
7021 (*cies)++;
7023 Free(*pies);
7024 *pies = pnies;
7027 himlold = c->himl;
7028 c->himl = himl;
7030 return himlold;
7034 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7036 int i;
7038 for (i = 0; i < *cies; i++)
7039 Free((*pies)[i]);
7041 Free(*pies);
7043 *cies = 0;
7044 *pies = NULL;
7048 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id)
7050 PIMLENTRY c = NULL;
7052 if (pies != NULL)
7054 int i;
7056 for (i = 0; i < cies; i++)
7058 if (pies[i]->id == id)
7060 c = pies[i];
7061 break;
7066 return c;
7070 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id)
7072 HIMAGELIST himlDef = 0;
7073 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7075 if (pie)
7076 himlDef = pie->himl;
7078 return himlDef;
7082 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7084 if (infoPtr->bUnicode)
7085 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7086 else
7088 CHAR Buffer[256];
7089 NMTOOLBARA nmtba;
7090 BOOL bRet = FALSE;
7092 nmtba.iItem = nmtb->iItem;
7093 nmtba.pszText = Buffer;
7094 nmtba.cchText = 256;
7095 ZeroMemory(nmtba.pszText, nmtba.cchText);
7097 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7099 int ccht = strlen(nmtba.pszText);
7100 if (ccht)
7101 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7102 nmtb->pszText, nmtb->cchText);
7104 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7105 bRet = TRUE;
7108 return bRet;
7113 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo)
7115 NMTOOLBARW nmtb;
7117 /* MSDN states that iItem is the index of the button, rather than the
7118 * command ID as used by every other NMTOOLBAR notification */
7119 nmtb.iItem = iItem;
7120 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7122 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);