comctl32: Pass command id of button in wParam.
[wine.git] / dlls / comctl32 / toolbar.c
blobb55298a98540d24f74891ad6cefd67504eea6823
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 and Separators.
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 NMTBDISPINFOW nmgd;
365 memset(&nmgd, 0, sizeof(nmgd));
366 nmgd.idCommand = btnPtr->idCommand;
367 nmgd.lParam = btnPtr->dwData;
368 nmgd.dwMask = TBNF_IMAGE;
369 nmgd.iImage = -1;
370 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
371 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr, TBN_GETDISPINFOW);
372 if (nmgd.dwMask & TBNF_DI_SETITEM)
373 btnPtr->iBitmap = nmgd.iImage;
374 ret = nmgd.iImage;
375 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
376 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
379 if (ret != I_IMAGENONE)
380 ret = GETIBITMAP(infoPtr, ret);
382 return ret;
386 static BOOL
387 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO *infoPtr, INT index)
389 HIMAGELIST himl;
390 INT id = GETHIMLID(infoPtr, index);
391 INT iBitmap = GETIBITMAP(infoPtr, index);
393 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
394 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
395 (index == I_IMAGECALLBACK))
396 return TRUE;
397 else
398 return FALSE;
402 static inline BOOL
403 TOOLBAR_IsValidImageList(const TOOLBAR_INFO *infoPtr, INT index)
405 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
406 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
410 /***********************************************************************
411 * TOOLBAR_GetImageListForDrawing
413 * This function validates the bitmap index (including I_IMAGECALLBACK
414 * functionality) and returns the corresponding image list.
416 static HIMAGELIST
417 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
418 IMAGE_LIST_TYPE imagelist, INT * index)
420 HIMAGELIST himl;
422 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
423 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
424 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
425 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
426 return NULL;
429 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
430 if ((*index == I_IMAGECALLBACK) ||
431 (*index == I_IMAGENONE)) return NULL;
432 ERR("TBN_GETDISPINFO returned invalid index %d\n",
433 *index);
434 return NULL;
437 switch(imagelist)
439 case IMAGE_LIST_DEFAULT:
440 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
441 break;
442 case IMAGE_LIST_HOT:
443 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
444 break;
445 case IMAGE_LIST_DISABLED:
446 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
447 break;
448 default:
449 himl = NULL;
450 FIXME("Shouldn't reach here\n");
453 if (!himl)
454 TRACE("no image list\n");
456 return himl;
460 static void
461 TOOLBAR_DrawFlatSeparator (const RECT *lpRect, HDC hdc, const TOOLBAR_INFO *infoPtr)
463 RECT myrect;
464 COLORREF oldcolor, newcolor;
466 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
467 myrect.right = myrect.left + 1;
468 myrect.top = lpRect->top + 2;
469 myrect.bottom = lpRect->bottom - 2;
471 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
472 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
473 oldcolor = SetBkColor (hdc, newcolor);
474 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
476 myrect.left = myrect.right;
477 myrect.right = myrect.left + 1;
479 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
480 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
481 SetBkColor (hdc, newcolor);
482 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
484 SetBkColor (hdc, oldcolor);
488 /***********************************************************************
489 * TOOLBAR_DrawDDFlatSeparator
491 * This function draws the separator that was flagged as BTNS_DROPDOWN.
492 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
493 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
494 * are horizontal as opposed to the vertical separators for not dropdown
495 * type.
497 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
499 static void
500 TOOLBAR_DrawDDFlatSeparator (const RECT *lpRect, HDC hdc, const TBUTTON_INFO *btnPtr,
501 const TOOLBAR_INFO *infoPtr)
503 RECT myrect;
504 COLORREF oldcolor, newcolor;
506 myrect.left = lpRect->left;
507 myrect.right = lpRect->right;
508 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
509 myrect.bottom = myrect.top + 1;
511 InflateRect (&myrect, -2, 0);
513 TRACE("rect=(%d,%d)-(%d,%d)\n",
514 myrect.left, myrect.top, myrect.right, myrect.bottom);
516 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
517 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
518 oldcolor = SetBkColor (hdc, newcolor);
519 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
521 myrect.top = myrect.bottom;
522 myrect.bottom = myrect.top + 1;
524 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
525 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
526 SetBkColor (hdc, newcolor);
527 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
529 SetBkColor (hdc, oldcolor);
533 static void
534 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
536 INT x, y;
537 HPEN hPen, hOldPen;
539 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
540 hOldPen = SelectObject ( hdc, hPen );
541 x = left + 2;
542 y = top;
543 MoveToEx (hdc, x, y, NULL);
544 LineTo (hdc, x+5, y++); x++;
545 MoveToEx (hdc, x, y, NULL);
546 LineTo (hdc, x+3, y++); x++;
547 MoveToEx (hdc, x, y, NULL);
548 LineTo (hdc, x+1, y++);
549 SelectObject( hdc, hOldPen );
550 DeleteObject( hPen );
554 * Draw the text string for this button.
555 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
556 * is non-zero, so we can simply check himlDef to see if we have
557 * an image list
559 static void
560 TOOLBAR_DrawString (const TOOLBAR_INFO *infoPtr, RECT *rcText, LPCWSTR lpText,
561 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
563 HDC hdc = tbcd->nmcd.hdc;
564 HFONT hOldFont = 0;
565 COLORREF clrOld = 0;
566 COLORREF clrOldBk = 0;
567 int oldBkMode = 0;
568 UINT state = tbcd->nmcd.uItemState;
570 /* draw text */
571 if (lpText) {
572 TRACE("string=%s rect=(%d,%d)-(%d,%d)\n", debugstr_w(lpText),
573 rcText->left, rcText->top, rcText->right, rcText->bottom);
575 hOldFont = SelectObject (hdc, infoPtr->hFont);
576 if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
577 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
579 else if (state & CDIS_DISABLED) {
580 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
581 OffsetRect (rcText, 1, 1);
582 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
583 SetTextColor (hdc, comctl32_color.clr3dShadow);
584 OffsetRect (rcText, -1, -1);
586 else if (state & CDIS_INDETERMINATE) {
587 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
589 else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
590 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
591 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
592 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
594 else {
595 clrOld = SetTextColor (hdc, tbcd->clrText);
598 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
599 SetTextColor (hdc, clrOld);
600 if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
602 SetBkColor (hdc, clrOldBk);
603 SetBkMode (hdc, oldBkMode);
605 SelectObject (hdc, hOldFont);
610 static void
611 TOOLBAR_DrawPattern (const RECT *lpRect, const NMTBCUSTOMDRAW *tbcd)
613 HDC hdc = tbcd->nmcd.hdc;
614 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
615 COLORREF clrTextOld;
616 COLORREF clrBkOld;
617 INT cx = lpRect->right - lpRect->left;
618 INT cy = lpRect->bottom - lpRect->top;
619 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
620 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
621 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
622 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
623 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
624 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
625 SetBkColor(hdc, clrBkOld);
626 SetTextColor(hdc, clrTextOld);
627 SelectObject (hdc, hbr);
631 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
633 INT cx, cy;
634 HBITMAP hbmMask, hbmImage;
635 HDC hdcMask, hdcImage;
637 ImageList_GetIconSize(himl, &cx, &cy);
639 /* Create src image */
640 hdcImage = CreateCompatibleDC(hdc);
641 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
642 SelectObject(hdcImage, hbmImage);
643 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
644 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
646 /* Create Mask */
647 hdcMask = CreateCompatibleDC(0);
648 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
649 SelectObject(hdcMask, hbmMask);
651 /* Remove the background and all white pixels */
652 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
653 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
654 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
655 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
657 /* draw the new mask 'etched' to hdc */
658 SetBkColor(hdc, RGB(255, 255, 255));
659 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
660 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
661 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
662 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
663 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
665 /* Cleanup */
666 DeleteObject(hbmImage);
667 DeleteDC(hdcImage);
668 DeleteObject (hbmMask);
669 DeleteDC(hdcMask);
673 static UINT
674 TOOLBAR_TranslateState(const TBUTTON_INFO *btnPtr)
676 UINT retstate = 0;
678 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
679 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
680 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
681 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
682 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
683 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
684 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
685 return retstate;
688 /* draws the image on a toolbar button */
689 static void
690 TOOLBAR_DrawImage(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
691 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
693 HIMAGELIST himl = NULL;
694 BOOL draw_masked = FALSE;
695 INT index;
696 INT offset = 0;
697 UINT draw_flags = ILD_TRANSPARENT;
699 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
701 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
702 if (!himl)
704 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
705 draw_masked = TRUE;
708 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
709 ((tbcd->nmcd.uItemState & CDIS_HOT)
710 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
712 /* if hot, attempt to draw with hot image list, if fails,
713 use default image list */
714 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
715 if (!himl)
716 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
718 else
719 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
721 if (!himl)
722 return;
724 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
725 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
726 offset = 1;
728 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
729 (tbcd->nmcd.uItemState & CDIS_MARKED))
730 draw_flags |= ILD_BLEND50;
732 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
733 index, himl, left, top, offset);
735 if (draw_masked)
736 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
737 else
738 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
741 /* draws a blank frame for a toolbar button */
742 static void
743 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
745 HDC hdc = tbcd->nmcd.hdc;
746 RECT rc = tbcd->nmcd.rc;
747 /* if the state is disabled or indeterminate then the button
748 * cannot have an interactive look like pressed or hot */
749 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
750 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
751 BOOL pressed_look = !non_interactive_state &&
752 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
753 (tbcd->nmcd.uItemState & CDIS_CHECKED));
755 /* app don't want us to draw any edges */
756 if (dwItemCDFlag & TBCDRF_NOEDGES)
757 return;
759 if (infoPtr->dwStyle & TBSTYLE_FLAT)
761 if (pressed_look)
762 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
763 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
764 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
766 else
768 if (pressed_look)
769 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
770 else
771 DrawEdge (hdc, &rc, EDGE_RAISED,
772 BF_SOFT | BF_RECT | BF_MIDDLE);
776 static void
777 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
779 HDC hdc = tbcd->nmcd.hdc;
780 int offset = 0;
781 BOOL pressed = bDropDownPressed ||
782 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
784 if (infoPtr->dwStyle & TBSTYLE_FLAT)
786 if (pressed)
787 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
788 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
789 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
790 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
791 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
793 else
795 if (pressed)
796 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
797 else
798 DrawEdge (hdc, rcArrow, EDGE_RAISED,
799 BF_SOFT | BF_RECT | BF_MIDDLE);
802 if (pressed)
803 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
805 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
807 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
808 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
810 else
811 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
814 /* draws a complete toolbar button */
815 static void
816 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
818 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
819 DWORD dwStyle = infoPtr->dwStyle;
820 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
821 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
822 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
823 BOOL drawSepDropDownArrow = hasDropDownArrow &&
824 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
825 RECT rc, rcArrow, rcBitmap, rcText;
826 LPWSTR lpText = NULL;
827 NMTBCUSTOMDRAW tbcd;
828 DWORD ntfret;
829 INT offset;
830 INT oldBkMode;
831 DWORD dwItemCustDraw;
832 DWORD dwItemCDFlag;
833 HTHEME theme = GetWindowTheme (hwnd);
835 rc = btnPtr->rect;
836 CopyRect (&rcArrow, &rc);
838 /* separator - doesn't send NM_CUSTOMDRAW */
839 if (btnPtr->fsStyle & BTNS_SEP) {
840 if (theme)
842 DrawThemeBackground (theme, hdc,
843 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
844 &rc, NULL);
846 else
847 /* with the FLAT style, iBitmap is the width and has already */
848 /* been taken into consideration in calculating the width */
849 /* so now we need to draw the vertical separator */
850 /* empirical tests show that iBitmap can/will be non-zero */
851 /* when drawing the vertical bar... */
852 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
853 if (btnPtr->fsStyle & BTNS_DROPDOWN)
854 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
855 else
856 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
858 else if (btnPtr->fsStyle != BTNS_SEP) {
859 FIXME("Draw some kind of separator: fsStyle=%x\n",
860 btnPtr->fsStyle);
862 return;
865 /* get a pointer to the text */
866 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
868 if (hasDropDownArrow)
870 int right;
872 if (dwStyle & TBSTYLE_FLAT)
873 right = max(rc.left, rc.right - DDARROW_WIDTH);
874 else
875 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
877 if (drawSepDropDownArrow)
878 rc.right = right;
880 rcArrow.left = right;
883 /* copy text & bitmap rects after adjusting for drop-down arrow
884 * so that text & bitmap is centred in the rectangle not containing
885 * the arrow */
886 CopyRect(&rcText, &rc);
887 CopyRect(&rcBitmap, &rc);
889 /* Center the bitmap horizontally and vertically */
890 if (dwStyle & TBSTYLE_LIST)
892 if (lpText &&
893 infoPtr->nMaxTextRows > 0 &&
894 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
895 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
896 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
897 else
898 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
900 else
901 rcBitmap.left += ((rc.right - rc.left) - infoPtr->nBitmapWidth) / 2;
903 rcBitmap.top += infoPtr->szPadding.cy / 2;
905 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
906 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
907 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
908 TRACE("Text=%s\n", debugstr_w(lpText));
909 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
911 /* calculate text position */
912 if (lpText)
914 rcText.left += GetSystemMetrics(SM_CXEDGE);
915 rcText.right -= GetSystemMetrics(SM_CXEDGE);
916 if (dwStyle & TBSTYLE_LIST)
918 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
919 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
921 else
923 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
924 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
925 else
926 rcText.top += infoPtr->szPadding.cy/2 + 2;
930 /* Initialize fields in all cases, because we use these later
931 * NOTE: applications can and do alter these to customize their
932 * toolbars */
933 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
934 tbcd.clrText = comctl32_color.clrBtnText;
935 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
936 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
937 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
938 tbcd.clrMark = comctl32_color.clrHighlight;
939 tbcd.clrHighlightHotTrack = 0;
940 tbcd.nStringBkMode = TRANSPARENT;
941 tbcd.nHLStringBkMode = OPAQUE;
942 /* MSDN says that this is the text rectangle.
943 * But (why always a but) tracing of v5.7 of native shows
944 * that this is really a *relative* rectangle based on the
945 * the nmcd.rc. Also the left and top are always 0 ignoring
946 * any bitmap that might be present. */
947 tbcd.rcText.left = 0;
948 tbcd.rcText.top = 0;
949 tbcd.rcText.right = rcText.right - rc.left;
950 tbcd.rcText.bottom = rcText.bottom - rc.top;
951 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
952 tbcd.nmcd.hdc = hdc;
953 tbcd.nmcd.rc = rc;
954 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
956 /* FIXME: what are these used for? */
957 tbcd.hbrLines = 0;
958 tbcd.hpenLines = 0;
960 /* Issue Item Prepaint notify */
961 dwItemCustDraw = 0;
962 dwItemCDFlag = 0;
963 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
965 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
966 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
967 tbcd.nmcd.lItemlParam = btnPtr->dwData;
968 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
969 /* reset these fields so the user can't alter the behaviour like native */
970 tbcd.nmcd.hdc = hdc;
971 tbcd.nmcd.rc = rc;
973 dwItemCustDraw = ntfret & 0xffff;
974 dwItemCDFlag = ntfret & 0xffff0000;
975 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
976 return;
977 /* save the only part of the rect that the user can change */
978 rcText.right = tbcd.rcText.right + rc.left;
979 rcText.bottom = tbcd.rcText.bottom + rc.top;
982 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
983 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
984 OffsetRect(&rcText, 1, 1);
986 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
987 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
988 TOOLBAR_DrawPattern (&rc, &tbcd);
990 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
991 && (tbcd.nmcd.uItemState & CDIS_HOT))
993 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
995 COLORREF oldclr;
997 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
998 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
999 if (hasDropDownArrow)
1000 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
1001 SetBkColor(hdc, oldclr);
1005 if (theme)
1007 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1008 int stateId = TS_NORMAL;
1010 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1011 stateId = TS_DISABLED;
1012 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1013 stateId = TS_PRESSED;
1014 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1015 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1016 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1017 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1018 stateId = TS_HOT;
1020 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1022 else
1023 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1025 if (drawSepDropDownArrow)
1027 if (theme)
1029 int stateId = TS_NORMAL;
1031 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1032 stateId = TS_DISABLED;
1033 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1034 stateId = TS_PRESSED;
1035 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1036 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1037 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1038 stateId = TS_HOT;
1040 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1041 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1043 else
1044 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1047 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1048 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1049 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1050 SetBkMode (hdc, oldBkMode);
1052 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1054 if (hasDropDownArrow && !drawSepDropDownArrow)
1056 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1058 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1059 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1061 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1063 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1064 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1066 else
1067 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1070 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1072 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1073 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1079 static void
1080 TOOLBAR_Refresh (HWND hwnd, HDC hdc, const PAINTSTRUCT *ps)
1082 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1083 TBUTTON_INFO *btnPtr;
1084 INT i;
1085 RECT rcTemp, rcClient;
1086 NMTBCUSTOMDRAW tbcd;
1087 DWORD ntfret;
1088 DWORD dwBaseCustDraw;
1090 /* the app has told us not to redraw the toolbar */
1091 if (!infoPtr->bDoRedraw)
1092 return;
1094 /* if imagelist belongs to the app, it can be changed
1095 by the app after setting it */
1096 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1098 infoPtr->nNumBitmaps = 0;
1099 for (i = 0; i < infoPtr->cimlDef; i++)
1100 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1103 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1105 /* change the imagelist icon size if we manage the list and it is necessary */
1106 TOOLBAR_CheckImageListIconSize(infoPtr);
1108 /* Send initial notify */
1109 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1110 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1111 tbcd.nmcd.hdc = hdc;
1112 tbcd.nmcd.rc = ps->rcPaint;
1113 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1114 dwBaseCustDraw = ntfret & 0xffff;
1116 GetClientRect(hwnd, &rcClient);
1118 /* redraw necessary buttons */
1119 btnPtr = infoPtr->buttons;
1120 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1122 BOOL bDraw;
1123 if (!RectVisible(hdc, &btnPtr->rect))
1124 continue;
1125 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1127 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1128 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1130 else
1131 bDraw = TRUE;
1132 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1133 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1134 if (bDraw)
1135 TOOLBAR_DrawButton(hwnd, btnPtr, hdc, dwBaseCustDraw);
1138 /* draw insert mark if required */
1139 if (infoPtr->tbim.iButton != -1)
1141 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1142 RECT rcInsertMark;
1143 rcInsertMark.top = rcButton.top;
1144 rcInsertMark.bottom = rcButton.bottom;
1145 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1146 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1147 else
1148 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1149 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1152 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1154 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1155 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1156 tbcd.nmcd.hdc = hdc;
1157 tbcd.nmcd.rc = ps->rcPaint;
1158 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1162 /***********************************************************************
1163 * TOOLBAR_MeasureString
1165 * This function gets the width and height of a string in pixels. This
1166 * is done first by using GetTextExtentPoint to get the basic width
1167 * and height. The DrawText is called with DT_CALCRECT to get the exact
1168 * width. The reason is because the text may have more than one "&" (or
1169 * prefix characters as M$ likes to call them). The prefix character
1170 * indicates where the underline goes, except for the string "&&" which
1171 * is reduced to a single "&". GetTextExtentPoint does not process these
1172 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1174 static void
1175 TOOLBAR_MeasureString(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr,
1176 HDC hdc, LPSIZE lpSize)
1178 RECT myrect;
1180 lpSize->cx = 0;
1181 lpSize->cy = 0;
1183 if (infoPtr->nMaxTextRows > 0 &&
1184 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1185 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1186 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1188 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1190 if(lpText != NULL) {
1191 /* first get size of all the text */
1192 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1194 /* feed above size into the rectangle for DrawText */
1195 myrect.left = myrect.top = 0;
1196 myrect.right = lpSize->cx;
1197 myrect.bottom = lpSize->cy;
1199 /* Use DrawText to get true size as drawn (less pesky "&") */
1200 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1201 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1202 DT_NOPREFIX : 0));
1204 /* feed back to caller */
1205 lpSize->cx = myrect.right;
1206 lpSize->cy = myrect.bottom;
1210 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1213 /***********************************************************************
1214 * TOOLBAR_CalcStrings
1216 * This function walks through each string and measures it and returns
1217 * the largest height and width to caller.
1219 static void
1220 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1222 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1223 TBUTTON_INFO *btnPtr;
1224 INT i;
1225 SIZE sz;
1226 HDC hdc;
1227 HFONT hOldFont;
1229 lpSize->cx = 0;
1230 lpSize->cy = 0;
1232 if (infoPtr->nMaxTextRows == 0)
1233 return;
1235 hdc = GetDC (hwnd);
1236 hOldFont = SelectObject (hdc, infoPtr->hFont);
1238 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1240 TEXTMETRICW tm;
1242 GetTextMetricsW(hdc, &tm);
1243 lpSize->cy = tm.tmHeight;
1246 btnPtr = infoPtr->buttons;
1247 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1248 if(TOOLBAR_HasText(infoPtr, btnPtr))
1250 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1251 if (sz.cx > lpSize->cx)
1252 lpSize->cx = sz.cx;
1253 if (sz.cy > lpSize->cy)
1254 lpSize->cy = sz.cy;
1258 SelectObject (hdc, hOldFont);
1259 ReleaseDC (hwnd, hdc);
1261 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1264 /***********************************************************************
1265 * TOOLBAR_WrapToolbar
1267 * This function walks through the buttons and separators in the
1268 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1269 * wrapping should occur based on the width of the toolbar window.
1270 * It does *not* calculate button placement itself. That task
1271 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1272 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1273 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1275 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1276 * vertical toolbar lists.
1279 static void
1280 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1282 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1283 TBUTTON_INFO *btnPtr;
1284 INT x, cx, i, j;
1285 RECT rc;
1286 BOOL bWrap, bButtonWrap;
1288 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1289 /* no layout is necessary. Applications may use this style */
1290 /* to perform their own layout on the toolbar. */
1291 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1292 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1294 btnPtr = infoPtr->buttons;
1295 x = infoPtr->nIndent;
1297 if (GetParent(hwnd))
1299 /* this can get the parents width, to know how far we can extend
1300 * this toolbar. We cannot use its height, as there may be multiple
1301 * toolbars in a rebar control
1303 GetClientRect( GetParent(hwnd), &rc );
1304 infoPtr->nWidth = rc.right - rc.left;
1306 else
1308 GetWindowRect( hwnd, &rc );
1309 infoPtr->nWidth = rc.right - rc.left;
1312 bButtonWrap = FALSE;
1314 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1315 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1316 infoPtr->nIndent);
1318 for (i = 0; i < infoPtr->nNumButtons; i++ )
1320 bWrap = FALSE;
1321 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1323 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1324 continue;
1326 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1327 /* it is the actual width of the separator. This is used for */
1328 /* custom controls in toolbars. */
1329 /* */
1330 /* BTNS_DROPDOWN separators are treated as buttons for */
1331 /* width. - GA 8/01 */
1332 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1333 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1334 cx = (btnPtr[i].iBitmap > 0) ?
1335 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1336 else
1337 cx = infoPtr->nButtonWidth;
1339 /* Two or more adjacent separators form a separator group. */
1340 /* The first separator in a group should be wrapped to the */
1341 /* next row if the previous wrapping is on a button. */
1342 if( bButtonWrap &&
1343 (btnPtr[i].fsStyle & BTNS_SEP) &&
1344 (i + 1 < infoPtr->nNumButtons ) &&
1345 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1347 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1348 btnPtr[i].fsState |= TBSTATE_WRAP;
1349 x = infoPtr->nIndent;
1350 i++;
1351 bButtonWrap = FALSE;
1352 continue;
1355 /* The layout makes sure the bitmap is visible, but not the button. */
1356 /* Test added to also wrap after a button that starts a row but */
1357 /* is bigger than the area. - GA 8/01 */
1358 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1359 > infoPtr->nWidth ) ||
1360 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1362 BOOL bFound = FALSE;
1364 /* If the current button is a separator and not hidden, */
1365 /* go to the next until it reaches a non separator. */
1366 /* Wrap the last separator if it is before a button. */
1367 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1368 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1369 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1370 i < infoPtr->nNumButtons )
1372 i++;
1373 bFound = TRUE;
1376 if( bFound && i < infoPtr->nNumButtons )
1378 i--;
1379 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1380 i, btnPtr[i].fsStyle, x, cx);
1381 btnPtr[i].fsState |= TBSTATE_WRAP;
1382 x = infoPtr->nIndent;
1383 bButtonWrap = FALSE;
1384 continue;
1386 else if ( i >= infoPtr->nNumButtons)
1387 break;
1389 /* If the current button is not a separator, find the last */
1390 /* separator and wrap it. */
1391 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1393 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1394 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1396 bFound = TRUE;
1397 i = j;
1398 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1399 i, btnPtr[i].fsStyle, x, cx);
1400 x = infoPtr->nIndent;
1401 btnPtr[j].fsState |= TBSTATE_WRAP;
1402 bButtonWrap = FALSE;
1403 break;
1407 /* If no separator available for wrapping, wrap one of */
1408 /* non-hidden previous button. */
1409 if (!bFound)
1411 for ( j = i - 1;
1412 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1414 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1415 continue;
1417 bFound = TRUE;
1418 i = j;
1419 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1420 i, btnPtr[i].fsStyle, x, cx);
1421 x = infoPtr->nIndent;
1422 btnPtr[j].fsState |= TBSTATE_WRAP;
1423 bButtonWrap = TRUE;
1424 break;
1428 /* If all above failed, wrap the current button. */
1429 if (!bFound)
1431 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1432 i, btnPtr[i].fsStyle, x, cx);
1433 btnPtr[i].fsState |= TBSTATE_WRAP;
1434 bFound = TRUE;
1435 x = infoPtr->nIndent;
1436 if (btnPtr[i].fsStyle & BTNS_SEP )
1437 bButtonWrap = FALSE;
1438 else
1439 bButtonWrap = TRUE;
1442 else {
1443 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1444 i, btnPtr[i].fsStyle, x, cx);
1445 x += cx;
1451 /***********************************************************************
1452 * TOOLBAR_MeasureButton
1454 * Calculates the width and height required for a button. Used in
1455 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1456 * the width of buttons that are autosized.
1458 * Note that it would have been rather elegant to use one piece of code for
1459 * both the laying out of the toolbar and for controlling where button parts
1460 * are drawn, but the native control has inconsistencies between the two that
1461 * prevent this from being effectively. These inconsistencies can be seen as
1462 * artefacts where parts of the button appear outside of the bounding button
1463 * rectangle.
1465 * There are several cases for the calculation of the button dimensions and
1466 * button part positioning:
1468 * List
1469 * ====
1471 * With Bitmap:
1473 * +--------------------------------------------------------+ ^
1474 * | ^ ^ | |
1475 * | | pad.cy / 2 | centred | |
1476 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1477 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1478 * | |<------------>| | | | |
1479 * | +--------------+ +------------+ | |
1480 * |<-------------------------------------->| | |
1481 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1482 * | szText.cx | |
1483 * +--------------------------------------------------------+ -
1484 * <-------------------------------------------------------->
1485 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1487 * Without Bitmap (I_IMAGENONE):
1489 * +-----------------------------------+ ^
1490 * | ^ | |
1491 * | | centred | | LISTPAD_CY +
1492 * | +------------+ | | szText.cy
1493 * | | Text | | |
1494 * | | | | |
1495 * | +------------+ | |
1496 * |<----------------->| | |
1497 * | cxedge |<-----------> | |
1498 * | szText.cx | |
1499 * +-----------------------------------+ -
1500 * <----------------------------------->
1501 * szText.cx + pad.cx
1503 * Without text:
1505 * +--------------------------------------+ ^
1506 * | ^ | |
1507 * | | padding.cy/2 | | DEFPAD_CY +
1508 * | +------------+ | | nBitmapHeight
1509 * | | Bitmap | | |
1510 * | | | | |
1511 * | +------------+ | |
1512 * |<------------------->| | |
1513 * | cxedge + iListGap/2 |<-----------> | |
1514 * | nBitmapWidth | |
1515 * +--------------------------------------+ -
1516 * <-------------------------------------->
1517 * 2*cxedge + nBitmapWidth + iListGap
1519 * Non-List
1520 * ========
1522 * With bitmap:
1524 * +-----------------------------------+ ^
1525 * | ^ | |
1526 * | | pad.cy / 2 | | nBitmapHeight +
1527 * | - | | szText.cy +
1528 * | +------------+ | | DEFPAD_CY + 1
1529 * | centred | Bitmap | | |
1530 * |<----------------->| | | |
1531 * | +------------+ | |
1532 * | ^ | |
1533 * | 1 | | |
1534 * | - | |
1535 * | centred +---------------+ | |
1536 * |<--------------->| Text | | |
1537 * | +---------------+ | |
1538 * +-----------------------------------+ -
1539 * <----------------------------------->
1540 * pad.cx + max(nBitmapWidth, szText.cx)
1542 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1544 * +---------------------------------------+ ^
1545 * | ^ | |
1546 * | | 2 + pad.cy / 2 | |
1547 * | - | | szText.cy +
1548 * | centred +-----------------+ | | pad.cy + 2
1549 * |<--------------->| Text | | |
1550 * | +-----------------+ | |
1551 * | | |
1552 * +---------------------------------------+ -
1553 * <--------------------------------------->
1554 * 2*cxedge + pad.cx + szText.cx
1556 * Without text:
1557 * As for with bitmaps, but with szText.cx zero.
1559 static inline SIZE TOOLBAR_MeasureButton(const TOOLBAR_INFO *infoPtr, SIZE sizeString,
1560 BOOL bHasBitmap, BOOL bValidImageList)
1562 SIZE sizeButton;
1563 if (infoPtr->dwStyle & TBSTYLE_LIST)
1565 /* set button height from bitmap / text height... */
1566 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1567 sizeString.cy);
1569 /* ... add on the necessary padding */
1570 if (bValidImageList)
1572 if (bHasBitmap)
1573 sizeButton.cy += DEFPAD_CY;
1574 else
1575 sizeButton.cy += LISTPAD_CY;
1577 else
1578 sizeButton.cy += infoPtr->szPadding.cy;
1580 /* calculate button width */
1581 if (bHasBitmap)
1583 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1584 infoPtr->nBitmapWidth + infoPtr->iListGap;
1585 if (sizeString.cx > 0)
1586 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1588 else
1589 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1591 else
1593 if (bHasBitmap)
1595 sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
1596 if (sizeString.cy > 0)
1597 sizeButton.cy += 1 + sizeString.cy;
1598 sizeButton.cx = infoPtr->szPadding.cx +
1599 max(sizeString.cx, infoPtr->nBitmapWidth);
1601 else
1603 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1604 NONLIST_NOTEXT_OFFSET;
1605 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1606 infoPtr->szPadding.cx + sizeString.cx;
1609 return sizeButton;
1613 /***********************************************************************
1614 * TOOLBAR_CalcToolbar
1616 * This function calculates button and separator placement. It first
1617 * calculates the button sizes, gets the toolbar window width and then
1618 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1619 * on. It assigns a new location to each item and sends this location to
1620 * the tooltip window if appropriate. Finally, it updates the rcBound
1621 * rect and calculates the new required toolbar window height.
1623 static void
1624 TOOLBAR_CalcToolbar (HWND hwnd)
1626 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1627 SIZE sizeString, sizeButton;
1628 BOOL validImageList = FALSE;
1630 TOOLBAR_CalcStrings (hwnd, &sizeString);
1632 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1634 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1635 validImageList = TRUE;
1636 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1637 infoPtr->nButtonWidth = sizeButton.cx;
1638 infoPtr->nButtonHeight = sizeButton.cy;
1639 infoPtr->iTopMargin = default_top_margin(infoPtr);
1641 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1642 infoPtr->nButtonWidth = infoPtr->cxMin;
1643 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1644 infoPtr->nButtonWidth = infoPtr->cxMax;
1646 TOOLBAR_LayoutToolbar(hwnd);
1649 static void
1650 TOOLBAR_LayoutToolbar(HWND hwnd)
1652 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1653 TBUTTON_INFO *btnPtr;
1654 SIZE sizeButton;
1655 INT i, nRows, nSepRows;
1656 INT x, y, cx, cy;
1657 BOOL bWrap;
1658 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1659 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1661 TOOLBAR_WrapToolbar(hwnd, infoPtr->dwStyle);
1663 x = infoPtr->nIndent;
1664 y = infoPtr->iTopMargin;
1665 cx = infoPtr->nButtonWidth;
1666 cy = infoPtr->nButtonHeight;
1668 nRows = nSepRows = 0;
1670 infoPtr->rcBound.top = y;
1671 infoPtr->rcBound.left = x;
1672 infoPtr->rcBound.bottom = y + cy;
1673 infoPtr->rcBound.right = x;
1675 btnPtr = infoPtr->buttons;
1677 TRACE("cy=%d\n", cy);
1679 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1681 bWrap = FALSE;
1682 if (btnPtr->fsState & TBSTATE_HIDDEN)
1684 SetRectEmpty (&btnPtr->rect);
1685 continue;
1688 cy = infoPtr->nButtonHeight;
1690 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1691 /* it is the actual width of the separator. This is used for */
1692 /* custom controls in toolbars. */
1693 if (btnPtr->fsStyle & BTNS_SEP) {
1694 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1695 cy = (btnPtr->iBitmap > 0) ?
1696 btnPtr->iBitmap : SEPARATOR_WIDTH;
1697 cx = infoPtr->nButtonWidth;
1699 else
1700 cx = (btnPtr->iBitmap > 0) ?
1701 btnPtr->iBitmap : SEPARATOR_WIDTH;
1703 else
1705 if (btnPtr->cx)
1706 cx = btnPtr->cx;
1707 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1708 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1710 SIZE sz;
1711 HDC hdc;
1712 HFONT hOldFont;
1714 hdc = GetDC (hwnd);
1715 hOldFont = SelectObject (hdc, infoPtr->hFont);
1717 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1719 SelectObject (hdc, hOldFont);
1720 ReleaseDC (hwnd, hdc);
1722 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1723 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1724 validImageList);
1725 cx = sizeButton.cx;
1727 else
1728 cx = infoPtr->nButtonWidth;
1730 /* if size has been set manually then don't add on extra space
1731 * for the drop down arrow */
1732 if (!btnPtr->cx && hasDropDownArrows &&
1733 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1734 cx += DDARROW_WIDTH;
1736 if (btnPtr->fsState & TBSTATE_WRAP )
1737 bWrap = TRUE;
1739 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1741 if (infoPtr->rcBound.left > x)
1742 infoPtr->rcBound.left = x;
1743 if (infoPtr->rcBound.right < x + cx)
1744 infoPtr->rcBound.right = x + cx;
1745 if (infoPtr->rcBound.bottom < y + cy)
1746 infoPtr->rcBound.bottom = y + cy;
1748 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1750 /* btnPtr->nRow is zero based. The space between the rows is */
1751 /* also considered as a row. */
1752 btnPtr->nRow = nRows + nSepRows;
1754 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1755 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1756 x, y, x+cx, y+cy);
1758 if( bWrap )
1760 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1761 y += cy;
1762 else
1764 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1765 /* it is the actual width of the separator. This is used for */
1766 /* custom controls in toolbars. */
1767 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1768 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1769 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1770 else
1771 y += cy;
1773 /* nSepRows is used to calculate the extra height follwoing */
1774 /* the last row. */
1775 nSepRows++;
1777 x = infoPtr->nIndent;
1779 /* Increment row number unless this is the last button */
1780 /* and it has Wrap set. */
1781 if (i != infoPtr->nNumButtons-1)
1782 nRows++;
1784 else
1785 x += cx;
1788 /* infoPtr->nRows is the number of rows on the toolbar */
1789 infoPtr->nRows = nRows + nSepRows + 1;
1791 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1795 static INT
1796 TOOLBAR_InternalHitTest (HWND hwnd, const POINT *lpPt)
1798 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1799 TBUTTON_INFO *btnPtr;
1800 INT i;
1802 btnPtr = infoPtr->buttons;
1803 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1804 if (btnPtr->fsState & TBSTATE_HIDDEN)
1805 continue;
1807 if (btnPtr->fsStyle & BTNS_SEP) {
1808 if (PtInRect (&btnPtr->rect, *lpPt)) {
1809 TRACE(" ON SEPARATOR %d!\n", i);
1810 return -i;
1813 else {
1814 if (PtInRect (&btnPtr->rect, *lpPt)) {
1815 TRACE(" ON BUTTON %d!\n", i);
1816 return i;
1821 TRACE(" NOWHERE!\n");
1822 return TOOLBAR_NOWHERE;
1826 static INT
1827 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1829 TBUTTON_INFO *btnPtr;
1830 INT i;
1832 if (CommandIsIndex) {
1833 TRACE("command is really index command=%d\n", idCommand);
1834 if (idCommand >= infoPtr->nNumButtons) return -1;
1835 return idCommand;
1837 btnPtr = infoPtr->buttons;
1838 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1839 if (btnPtr->idCommand == idCommand) {
1840 TRACE("command=%d index=%d\n", idCommand, i);
1841 return i;
1844 TRACE("no index found for command=%d\n", idCommand);
1845 return -1;
1849 static INT
1850 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO *infoPtr, INT nIndex)
1852 TBUTTON_INFO *btnPtr;
1853 INT nRunIndex;
1855 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1856 return -1;
1858 /* check index button */
1859 btnPtr = &infoPtr->buttons[nIndex];
1860 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1861 if (btnPtr->fsState & TBSTATE_CHECKED)
1862 return nIndex;
1865 /* check previous buttons */
1866 nRunIndex = nIndex - 1;
1867 while (nRunIndex >= 0) {
1868 btnPtr = &infoPtr->buttons[nRunIndex];
1869 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1870 if (btnPtr->fsState & TBSTATE_CHECKED)
1871 return nRunIndex;
1873 else
1874 break;
1875 nRunIndex--;
1878 /* check next buttons */
1879 nRunIndex = nIndex + 1;
1880 while (nRunIndex < infoPtr->nNumButtons) {
1881 btnPtr = &infoPtr->buttons[nRunIndex];
1882 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1883 if (btnPtr->fsState & TBSTATE_CHECKED)
1884 return nRunIndex;
1886 else
1887 break;
1888 nRunIndex++;
1891 return -1;
1895 static VOID
1896 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1897 WPARAM wParam, LPARAM lParam)
1899 MSG msg;
1901 msg.hwnd = hwndMsg;
1902 msg.message = uMsg;
1903 msg.wParam = wParam;
1904 msg.lParam = lParam;
1905 msg.time = GetMessageTime ();
1906 msg.pt.x = (short)LOWORD(GetMessagePos ());
1907 msg.pt.y = (short)HIWORD(GetMessagePos ());
1909 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1912 static void
1913 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1915 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1916 TTTOOLINFOW ti;
1918 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1919 ti.cbSize = sizeof (TTTOOLINFOW);
1920 ti.hwnd = infoPtr->hwndSelf;
1921 ti.uId = button->idCommand;
1922 ti.hinst = 0;
1923 ti.lpszText = LPSTR_TEXTCALLBACKW;
1924 /* ti.lParam = random value from the stack? */
1926 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1927 0, (LPARAM)&ti);
1931 static void
1932 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1934 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1935 TTTOOLINFOW ti;
1937 ZeroMemory(&ti, sizeof(ti));
1938 ti.cbSize = sizeof(ti);
1939 ti.hwnd = infoPtr->hwndSelf;
1940 ti.uId = button->idCommand;
1942 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1946 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1948 /* Set the toolTip only for non-hidden, non-separator button */
1949 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1951 TTTOOLINFOW ti;
1953 ZeroMemory(&ti, sizeof(ti));
1954 ti.cbSize = sizeof(ti);
1955 ti.hwnd = infoPtr->hwndSelf;
1956 ti.uId = button->idCommand;
1957 ti.rect = button->rect;
1958 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1962 /* Creates the tooltip control */
1963 static void
1964 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
1966 int i;
1967 NMTOOLTIPSCREATED nmttc;
1969 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1970 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1971 infoPtr->hwndSelf, 0, 0, 0);
1973 if (!infoPtr->hwndToolTip)
1974 return;
1976 /* Send NM_TOOLTIPSCREATED notification */
1977 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1978 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
1980 for (i = 0; i < infoPtr->nNumButtons; i++)
1982 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
1983 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
1987 /* keeps available button list box sorted by button id */
1988 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1990 int i;
1991 int count;
1992 PCUSTOMBUTTON btnInfo;
1993 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1995 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1997 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1999 /* position 0 is always separator */
2000 for (i = 1; i < count; i++)
2002 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
2003 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2005 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2006 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2007 return;
2010 /* id higher than all others add to end */
2011 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2012 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2015 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2017 NMTOOLBARW nmtb;
2019 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2021 if (nIndexFrom == nIndexTo)
2022 return;
2024 /* MSDN states that iItem is the index of the button, rather than the
2025 * command ID as used by every other NMTOOLBAR notification */
2026 nmtb.iItem = nIndexFrom;
2027 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2029 PCUSTOMBUTTON btnInfo;
2030 NMHDR hdr;
2031 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2032 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2034 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2036 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2037 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2038 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2039 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2041 if (nIndexTo <= 0)
2042 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2043 else
2044 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2046 /* last item is always separator, so -2 instead of -1 */
2047 if (nIndexTo >= (count - 2))
2048 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2049 else
2050 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2052 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2053 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2055 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2059 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2061 NMTOOLBARW nmtb;
2063 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2065 /* MSDN states that iItem is the index of the button, rather than the
2066 * command ID as used by every other NMTOOLBAR notification */
2067 nmtb.iItem = nIndexAvail;
2068 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2070 PCUSTOMBUTTON btnInfo;
2071 NMHDR hdr;
2072 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2073 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2074 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2076 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2078 if (nIndexAvail != 0) /* index == 0 indicates separator */
2080 /* remove from 'available buttons' list */
2081 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2082 if (nIndexAvail == count-1)
2083 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2084 else
2085 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2087 else
2089 PCUSTOMBUTTON btnNew;
2091 /* duplicate 'separator' button */
2092 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2093 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2094 btnInfo = btnNew;
2097 /* insert into 'toolbar button' list */
2098 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2099 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2101 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2103 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2107 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT index)
2109 PCUSTOMBUTTON btnInfo;
2110 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2112 TRACE("Remove: index %d\n", index);
2114 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2116 /* send TBN_QUERYDELETE notification */
2117 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2119 NMHDR hdr;
2121 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2122 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2124 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2126 /* insert into 'available button' list */
2127 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2128 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2129 else
2130 Free(btnInfo);
2132 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2136 /* drag list notification function for toolbar buttons list box */
2137 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2138 const DRAGLISTINFO *pDLI)
2140 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2141 switch (pDLI->uNotification)
2143 case DL_BEGINDRAG:
2145 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2146 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2147 /* no dragging for last item (separator) */
2148 if (nCurrentItem >= (nCount - 1)) return FALSE;
2149 return TRUE;
2151 case DL_DRAGGING:
2153 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2154 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2155 /* no dragging past last item (separator) */
2156 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2158 DrawInsert(hwnd, hwndList, nCurrentItem);
2159 /* FIXME: native uses "move button" cursor */
2160 return DL_COPYCURSOR;
2163 /* not over toolbar buttons list */
2164 if (nCurrentItem < 0)
2166 POINT ptWindow = pDLI->ptCursor;
2167 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2168 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2169 /* over available buttons list? */
2170 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2171 /* FIXME: native uses "move button" cursor */
2172 return DL_COPYCURSOR;
2174 /* clear drag arrow */
2175 DrawInsert(hwnd, hwndList, -1);
2176 return DL_STOPCURSOR;
2178 case DL_DROPPED:
2180 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2181 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2182 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2183 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2185 /* clear drag arrow */
2186 DrawInsert(hwnd, hwndList, -1);
2187 /* move item */
2188 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2190 /* not over toolbar buttons list */
2191 if (nIndexTo < 0)
2193 POINT ptWindow = pDLI->ptCursor;
2194 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2195 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2196 /* over available buttons list? */
2197 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2198 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2200 break;
2202 case DL_CANCELDRAG:
2203 /* Clear drag arrow */
2204 DrawInsert(hwnd, hwndList, -1);
2205 break;
2208 return 0;
2211 /* drag list notification function for available buttons list box */
2212 static LRESULT TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2213 const DRAGLISTINFO *pDLI)
2215 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2216 switch (pDLI->uNotification)
2218 case DL_BEGINDRAG:
2219 return TRUE;
2220 case DL_DRAGGING:
2222 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2223 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2224 /* no dragging past last item (separator) */
2225 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2227 DrawInsert(hwnd, hwndList, nCurrentItem);
2228 /* FIXME: native uses "move button" cursor */
2229 return DL_COPYCURSOR;
2232 /* not over toolbar buttons list */
2233 if (nCurrentItem < 0)
2235 POINT ptWindow = pDLI->ptCursor;
2236 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2237 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2238 /* over available buttons list? */
2239 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2240 /* FIXME: native uses "move button" cursor */
2241 return DL_COPYCURSOR;
2243 /* clear drag arrow */
2244 DrawInsert(hwnd, hwndList, -1);
2245 return DL_STOPCURSOR;
2247 case DL_DROPPED:
2249 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2250 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2251 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2252 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2254 /* clear drag arrow */
2255 DrawInsert(hwnd, hwndList, -1);
2256 /* add item */
2257 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2260 case DL_CANCELDRAG:
2261 /* Clear drag arrow */
2262 DrawInsert(hwnd, hwndList, -1);
2263 break;
2265 return 0;
2268 extern UINT uDragListMessage;
2270 /***********************************************************************
2271 * TOOLBAR_CustomizeDialogProc
2272 * This function implements the toolbar customization dialog.
2274 static INT_PTR CALLBACK
2275 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2277 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2278 PCUSTOMBUTTON btnInfo;
2279 NMTOOLBARA nmtb;
2280 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2282 switch (uMsg)
2284 case WM_INITDIALOG:
2285 custInfo = (PCUSTDLG_INFO)lParam;
2286 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2288 if (custInfo)
2290 WCHAR Buffer[256];
2291 int i = 0;
2292 int index;
2293 NMTBINITCUSTOMIZE nmtbic;
2295 infoPtr = custInfo->tbInfo;
2297 /* send TBN_QUERYINSERT notification */
2298 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2300 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2301 return FALSE;
2303 nmtbic.hwndDialog = hwnd;
2304 /* Send TBN_INITCUSTOMIZE notification */
2305 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2306 TBNRF_HIDEHELP)
2308 TRACE("TBNRF_HIDEHELP requested\n");
2309 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2312 /* add items to 'toolbar buttons' list and check if removable */
2313 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2315 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2316 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2317 btnInfo->btn.fsStyle = BTNS_SEP;
2318 btnInfo->bVirtual = FALSE;
2319 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2321 /* send TBN_QUERYDELETE notification */
2322 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2324 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2325 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2328 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2330 /* insert separator button into 'available buttons' list */
2331 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2332 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2333 btnInfo->btn.fsStyle = BTNS_SEP;
2334 btnInfo->bVirtual = FALSE;
2335 btnInfo->bRemovable = TRUE;
2336 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2337 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2338 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2340 /* insert all buttons into dsa */
2341 for (i = 0;; i++)
2343 /* send TBN_GETBUTTONINFO notification */
2344 NMTOOLBARW nmtb;
2345 nmtb.iItem = i;
2346 nmtb.pszText = Buffer;
2347 nmtb.cchText = 256;
2349 /* Clear previous button's text */
2350 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2352 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2353 break;
2355 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2356 nmtb.tbButton.fsStyle, i,
2357 nmtb.tbButton.idCommand,
2358 nmtb.tbButton.iString,
2359 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2360 : "");
2362 /* insert button into the apropriate list */
2363 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2364 if (index == -1)
2366 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2367 btnInfo->bVirtual = FALSE;
2368 btnInfo->bRemovable = TRUE;
2370 else
2372 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2373 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2376 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2377 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2379 if (lstrlenW(nmtb.pszText))
2380 lstrcpyW(btnInfo->text, nmtb.pszText);
2381 else if (nmtb.tbButton.iString >= 0 &&
2382 nmtb.tbButton.iString < infoPtr->nNumStrings)
2384 lstrcpyW(btnInfo->text,
2385 infoPtr->strings[nmtb.tbButton.iString]);
2389 if (index == -1)
2390 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2393 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2395 /* select first item in the 'available' list */
2396 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2398 /* append 'virtual' separator button to the 'toolbar buttons' list */
2399 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2400 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2401 btnInfo->btn.fsStyle = BTNS_SEP;
2402 btnInfo->bVirtual = TRUE;
2403 btnInfo->bRemovable = FALSE;
2404 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2405 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2406 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2408 /* select last item in the 'toolbar' list */
2409 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2410 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2412 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2413 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2415 /* set focus and disable buttons */
2416 PostMessageW (hwnd, WM_USER, 0, 0);
2418 return TRUE;
2420 case WM_USER:
2421 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2422 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2423 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2424 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2425 return TRUE;
2427 case WM_CLOSE:
2428 EndDialog(hwnd, FALSE);
2429 return TRUE;
2431 case WM_COMMAND:
2432 switch (LOWORD(wParam))
2434 case IDC_TOOLBARBTN_LBOX:
2435 if (HIWORD(wParam) == LBN_SELCHANGE)
2437 PCUSTOMBUTTON btnInfo;
2438 NMTOOLBARA nmtb;
2439 int count;
2440 int index;
2442 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2443 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2445 /* send TBN_QUERYINSERT notification */
2446 nmtb.iItem = index;
2447 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2449 /* get list box item */
2450 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2452 if (index == (count - 1))
2454 /* last item (virtual separator) */
2455 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2456 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2458 else if (index == (count - 2))
2460 /* second last item (last non-virtual item) */
2461 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2462 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2464 else if (index == 0)
2466 /* first item */
2467 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2468 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2470 else
2472 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2473 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2476 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2478 break;
2480 case IDC_MOVEUP_BTN:
2482 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2483 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2485 break;
2487 case IDC_MOVEDN_BTN: /* move down */
2489 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2490 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2492 break;
2494 case IDC_REMOVE_BTN: /* remove button */
2496 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2498 if (LB_ERR == index)
2499 break;
2501 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2503 break;
2504 case IDC_HELP_BTN:
2505 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2506 break;
2507 case IDC_RESET_BTN:
2508 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2509 break;
2511 case IDOK: /* Add button */
2513 int index;
2514 int indexto;
2516 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2517 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2519 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2521 break;
2523 case IDCANCEL:
2524 EndDialog(hwnd, FALSE);
2525 break;
2527 return TRUE;
2529 case WM_DESTROY:
2531 int count;
2532 int i;
2534 /* delete items from 'toolbar buttons' listbox*/
2535 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2536 for (i = 0; i < count; i++)
2538 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2539 Free(btnInfo);
2540 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2542 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2545 /* delete items from 'available buttons' listbox*/
2546 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2547 for (i = 0; i < count; i++)
2549 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2550 Free(btnInfo);
2551 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2553 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2555 return TRUE;
2557 case WM_DRAWITEM:
2558 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2560 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2561 RECT rcButton;
2562 RECT rcText;
2563 HPEN hPen, hOldPen;
2564 HBRUSH hOldBrush;
2565 COLORREF oldText = 0;
2566 COLORREF oldBk = 0;
2568 /* get item data */
2569 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2570 if (btnInfo == NULL)
2572 FIXME("btnInfo invalid!\n");
2573 return TRUE;
2576 /* set colors and select objects */
2577 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2578 if (btnInfo->bVirtual)
2579 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2580 else
2581 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2582 hPen = CreatePen( PS_SOLID, 1,
2583 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2584 hOldPen = SelectObject (lpdis->hDC, hPen );
2585 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2587 /* fill background rectangle */
2588 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2589 lpdis->rcItem.right, lpdis->rcItem.bottom);
2591 /* calculate button and text rectangles */
2592 CopyRect (&rcButton, &lpdis->rcItem);
2593 InflateRect (&rcButton, -1, -1);
2594 CopyRect (&rcText, &rcButton);
2595 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2596 rcText.left = rcButton.right + 2;
2598 /* draw focus rectangle */
2599 if (lpdis->itemState & ODS_FOCUS)
2600 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2602 /* draw button */
2603 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2604 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2606 /* draw image and text */
2607 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2608 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2609 btnInfo->btn.iBitmap));
2610 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2611 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2613 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2614 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2616 /* delete objects and reset colors */
2617 SelectObject (lpdis->hDC, hOldBrush);
2618 SelectObject (lpdis->hDC, hOldPen);
2619 SetBkColor (lpdis->hDC, oldBk);
2620 SetTextColor (lpdis->hDC, oldText);
2621 DeleteObject( hPen );
2622 return TRUE;
2624 return FALSE;
2626 case WM_MEASUREITEM:
2627 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2629 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2631 lpmis->itemHeight = 15 + 8; /* default height */
2633 return TRUE;
2635 return FALSE;
2637 default:
2638 if (uDragListMessage && (uMsg == uDragListMessage))
2640 if (wParam == IDC_TOOLBARBTN_LBOX)
2642 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2643 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2644 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2645 return TRUE;
2647 else if (wParam == IDC_AVAILBTN_LBOX)
2649 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2650 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2651 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2652 return TRUE;
2655 return FALSE;
2659 static BOOL
2660 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2662 HBITMAP hbmLoad;
2663 INT nCountBefore = ImageList_GetImageCount(himlDef);
2664 INT nCountAfter;
2665 INT cxIcon, cyIcon;
2666 INT nAdded;
2667 INT nIndex;
2669 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2670 /* Add bitmaps to the default image list */
2671 if (bitmap->hInst == NULL) /* a handle was passed */
2672 hbmLoad = (HBITMAP)CopyImage(ULongToHandle(bitmap->nID), IMAGE_BITMAP, 0, 0, 0);
2673 else
2674 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2676 /* enlarge the bitmap if needed */
2677 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2678 if (bitmap->hInst != COMCTL32_hModule)
2679 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2681 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2682 DeleteObject(hbmLoad);
2683 if (nIndex == -1)
2684 return FALSE;
2686 nCountAfter = ImageList_GetImageCount(himlDef);
2687 nAdded = nCountAfter - nCountBefore;
2688 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2690 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2691 } else if (nAdded > (INT)bitmap->nButtons) {
2692 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2693 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2696 infoPtr->nNumBitmaps += nAdded;
2697 return TRUE;
2700 static void
2701 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2703 HIMAGELIST himlDef;
2704 HIMAGELIST himlNew;
2705 INT cx, cy;
2706 INT i;
2708 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2709 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2710 return;
2711 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2712 return;
2713 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2714 return;
2716 TRACE("Update icon size: %dx%d -> %dx%d\n",
2717 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2719 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2720 ILC_COLORDDB|ILC_MASK, 8, 2);
2721 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2722 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2723 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2724 infoPtr->himlInt = himlNew;
2726 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2727 ImageList_Destroy(himlDef);
2730 /***********************************************************************
2731 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2734 static LRESULT
2735 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2737 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2738 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2739 TBITMAP_INFO info;
2740 INT iSumButtons, i;
2741 HIMAGELIST himlDef;
2743 TRACE("hwnd=%p wParam=%lx lParam=%lx\n", hwnd, wParam, lParam);
2744 if (!lpAddBmp)
2745 return -1;
2747 if (lpAddBmp->hInst == HINST_COMMCTRL)
2749 info.hInst = COMCTL32_hModule;
2750 switch (lpAddBmp->nID)
2752 case IDB_STD_SMALL_COLOR:
2753 info.nButtons = 15;
2754 info.nID = IDB_STD_SMALL;
2755 break;
2756 case IDB_STD_LARGE_COLOR:
2757 info.nButtons = 15;
2758 info.nID = IDB_STD_LARGE;
2759 break;
2760 case IDB_VIEW_SMALL_COLOR:
2761 info.nButtons = 12;
2762 info.nID = IDB_VIEW_SMALL;
2763 break;
2764 case IDB_VIEW_LARGE_COLOR:
2765 info.nButtons = 12;
2766 info.nID = IDB_VIEW_LARGE;
2767 break;
2768 case IDB_HIST_SMALL_COLOR:
2769 info.nButtons = 5;
2770 info.nID = IDB_HIST_SMALL;
2771 break;
2772 case IDB_HIST_LARGE_COLOR:
2773 info.nButtons = 5;
2774 info.nID = IDB_HIST_LARGE;
2775 break;
2776 default:
2777 return -1;
2780 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2782 /* Windows resize all the buttons to the size of a newly added standard image */
2783 if (lpAddBmp->nID & 1)
2785 /* large icons: 24x24. Will make the button 31x30 */
2786 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
2788 else
2790 /* small icons: 16x16. Will make the buttons 23x22 */
2791 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
2794 TOOLBAR_CalcToolbar (hwnd);
2796 else
2798 info.nButtons = (INT)wParam;
2799 info.hInst = lpAddBmp->hInst;
2800 info.nID = lpAddBmp->nID;
2801 TRACE("adding %d bitmaps!\n", info.nButtons);
2804 /* check if the bitmap is already loaded and compute iSumButtons */
2805 iSumButtons = 0;
2806 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2808 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2809 infoPtr->bitmaps[i].nID == info.nID)
2810 return iSumButtons;
2811 iSumButtons += infoPtr->bitmaps[i].nButtons;
2814 if (!infoPtr->cimlDef) {
2815 /* create new default image list */
2816 TRACE ("creating default image list!\n");
2818 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2819 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2820 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2821 infoPtr->himlInt = himlDef;
2823 else {
2824 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2827 if (!himlDef) {
2828 WARN("No default image list available\n");
2829 return -1;
2832 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2833 return -1;
2835 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2836 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2837 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2838 infoPtr->nNumBitmapInfos++;
2839 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2841 InvalidateRect(hwnd, NULL, TRUE);
2842 return iSumButtons;
2846 static LRESULT
2847 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2849 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2850 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2851 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2852 BOOL fHasString = FALSE;
2854 TRACE("adding %ld buttons (unicode=%d)!\n", wParam, fUnicode);
2856 nAddButtons = (UINT)wParam;
2857 nOldButtons = infoPtr->nNumButtons;
2858 nNewButtons = nOldButtons + nAddButtons;
2860 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
2861 infoPtr->nNumButtons = nNewButtons;
2863 /* insert new button data */
2864 for (nCount = 0; nCount < nAddButtons; nCount++) {
2865 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2866 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2867 btnPtr->idCommand = lpTbb[nCount].idCommand;
2868 btnPtr->fsState = lpTbb[nCount].fsState;
2869 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2870 btnPtr->dwData = lpTbb[nCount].dwData;
2871 btnPtr->bHot = FALSE;
2872 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2874 if (fUnicode)
2875 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2876 else
2877 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString);
2878 fHasString = TRUE;
2880 else
2881 btnPtr->iString = lpTbb[nCount].iString;
2883 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
2886 if (infoPtr->nNumStrings > 0 || fHasString)
2887 TOOLBAR_CalcToolbar(hwnd);
2888 else
2889 TOOLBAR_LayoutToolbar(hwnd);
2890 TOOLBAR_AutoSize (hwnd);
2892 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2894 InvalidateRect(hwnd, NULL, TRUE);
2896 return TRUE;
2900 static LRESULT
2901 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2903 #define MAX_RESOURCE_STRING_LENGTH 512
2904 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2905 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2906 INT nIndex = infoPtr->nNumStrings;
2908 if ((wParam) && (HIWORD(lParam) == 0)) {
2909 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2910 WCHAR delimiter;
2911 WCHAR *next_delim;
2912 WCHAR *p;
2913 INT len;
2914 TRACE("adding string from resource!\n");
2916 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2917 szString, MAX_RESOURCE_STRING_LENGTH);
2919 TRACE("len=%d %s\n", len, debugstr_w(szString));
2920 if (len == 0 || len == 1)
2921 return nIndex;
2923 TRACE("Delimiter: 0x%x\n", *szString);
2924 delimiter = *szString;
2925 p = szString + 1;
2927 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2928 *next_delim = 0;
2929 if (next_delim + 1 >= szString + len)
2931 /* this may happen if delimiter == '\0' or if the last char is a
2932 * delimiter (then it is ignored like the native does) */
2933 break;
2936 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2937 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2938 infoPtr->nNumStrings++;
2940 p = next_delim + 1;
2943 else {
2944 LPWSTR p = (LPWSTR)lParam;
2945 INT len;
2947 if (p == NULL)
2948 return -1;
2949 TRACE("adding string(s) from array!\n");
2950 while (*p) {
2951 len = strlenW (p);
2953 TRACE("len=%d %s\n", len, debugstr_w(p));
2954 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2955 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2956 infoPtr->nNumStrings++;
2958 p += (len+1);
2962 if (fFirstString)
2963 TOOLBAR_CalcToolbar(hwnd);
2964 return nIndex;
2968 static LRESULT
2969 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2971 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2972 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2973 LPSTR p;
2974 INT nIndex;
2975 INT len;
2977 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
2978 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
2980 p = (LPSTR)lParam;
2981 if (p == NULL)
2982 return -1;
2984 TRACE("adding string(s) from array!\n");
2985 nIndex = infoPtr->nNumStrings;
2986 while (*p) {
2987 len = strlen (p);
2988 TRACE("len=%d \"%s\"\n", len, p);
2990 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2991 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
2992 infoPtr->nNumStrings++;
2994 p += (len+1);
2997 if (fFirstString)
2998 TOOLBAR_CalcToolbar(hwnd);
2999 return nIndex;
3003 static LRESULT
3004 TOOLBAR_AutoSize (HWND hwnd)
3006 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3007 RECT parent_rect;
3008 HWND parent;
3009 INT x, y;
3010 INT cx, cy;
3012 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3014 parent = GetParent (hwnd);
3016 if (!parent || !infoPtr->bDoRedraw)
3017 return 0;
3019 GetClientRect(parent, &parent_rect);
3021 x = parent_rect.left;
3022 y = parent_rect.top;
3024 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3026 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3027 cx = parent_rect.right - parent_rect.left;
3029 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3031 TOOLBAR_LayoutToolbar(hwnd);
3032 InvalidateRect( hwnd, NULL, TRUE );
3035 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3037 RECT window_rect;
3038 UINT uPosFlags = SWP_NOZORDER;
3040 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3042 GetWindowRect(hwnd, &window_rect);
3043 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3044 y = window_rect.top;
3046 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3048 GetWindowRect(hwnd, &window_rect);
3049 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3052 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3053 uPosFlags |= SWP_NOMOVE;
3055 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3056 cy += GetSystemMetrics(SM_CYEDGE);
3058 if (infoPtr->dwStyle & WS_BORDER)
3060 x = y = 1; /* FIXME: this looks wrong */
3061 cy += GetSystemMetrics(SM_CYEDGE);
3062 cx += GetSystemMetrics(SM_CXEDGE);
3065 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3068 return 0;
3072 static LRESULT
3073 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3075 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3077 return infoPtr->nNumButtons;
3081 static LRESULT
3082 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3084 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3086 infoPtr->dwStructSize = (DWORD)wParam;
3088 return 0;
3092 static LRESULT
3093 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3095 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3096 TBUTTON_INFO *btnPtr;
3097 INT nIndex;
3099 TRACE("button %ld, iBitmap now %d\n", wParam, LOWORD(lParam));
3101 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3102 if (nIndex == -1)
3103 return FALSE;
3105 btnPtr = &infoPtr->buttons[nIndex];
3106 btnPtr->iBitmap = LOWORD(lParam);
3108 /* we HAVE to erase the background, the new bitmap could be */
3109 /* transparent */
3110 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3112 return TRUE;
3116 static LRESULT
3117 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3119 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3120 TBUTTON_INFO *btnPtr;
3121 INT nIndex;
3122 INT nOldIndex = -1;
3123 BOOL bChecked = FALSE;
3125 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3127 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3129 if (nIndex == -1)
3130 return FALSE;
3132 btnPtr = &infoPtr->buttons[nIndex];
3134 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3136 if (LOWORD(lParam) == FALSE)
3137 btnPtr->fsState &= ~TBSTATE_CHECKED;
3138 else {
3139 if (btnPtr->fsStyle & BTNS_GROUP) {
3140 nOldIndex =
3141 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3142 if (nOldIndex == nIndex)
3143 return 0;
3144 if (nOldIndex != -1)
3145 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3147 btnPtr->fsState |= TBSTATE_CHECKED;
3150 if( bChecked != LOWORD(lParam) )
3152 if (nOldIndex != -1)
3153 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3154 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3157 /* FIXME: Send a WM_NOTIFY?? */
3159 return TRUE;
3163 static LRESULT
3164 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3166 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3168 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3172 static LRESULT
3173 TOOLBAR_Customize (HWND hwnd)
3175 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3176 CUSTDLG_INFO custInfo;
3177 LRESULT ret;
3178 LPCVOID template;
3179 HRSRC hRes;
3180 NMHDR nmhdr;
3182 custInfo.tbInfo = infoPtr;
3183 custInfo.tbHwnd = hwnd;
3185 /* send TBN_BEGINADJUST notification */
3186 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3188 if (!(hRes = FindResourceW (COMCTL32_hModule,
3189 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3190 (LPWSTR)RT_DIALOG)))
3191 return FALSE;
3193 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3194 return FALSE;
3196 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3197 (LPCDLGTEMPLATEW)template,
3198 hwnd,
3199 TOOLBAR_CustomizeDialogProc,
3200 (LPARAM)&custInfo);
3202 /* send TBN_ENDADJUST notification */
3203 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3205 return ret;
3209 static LRESULT
3210 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3212 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3213 INT nIndex = (INT)wParam;
3214 NMTOOLBARW nmtb;
3215 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3217 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3218 return FALSE;
3220 memset(&nmtb, 0, sizeof(nmtb));
3221 nmtb.iItem = btnPtr->idCommand;
3222 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3223 nmtb.tbButton.idCommand = btnPtr->idCommand;
3224 nmtb.tbButton.fsState = btnPtr->fsState;
3225 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3226 nmtb.tbButton.dwData = btnPtr->dwData;
3227 nmtb.tbButton.iString = btnPtr->iString;
3228 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3230 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3232 if (infoPtr->nNumButtons == 1) {
3233 TRACE(" simple delete!\n");
3234 Free (infoPtr->buttons);
3235 infoPtr->buttons = NULL;
3236 infoPtr->nNumButtons = 0;
3238 else {
3239 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3240 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3242 infoPtr->nNumButtons--;
3243 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3244 if (nIndex > 0) {
3245 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3246 nIndex * sizeof(TBUTTON_INFO));
3249 if (nIndex < infoPtr->nNumButtons) {
3250 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3251 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3254 Free (oldButtons);
3257 TOOLBAR_LayoutToolbar(hwnd);
3259 InvalidateRect (hwnd, NULL, TRUE);
3261 return TRUE;
3265 static LRESULT
3266 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3268 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3269 TBUTTON_INFO *btnPtr;
3270 INT nIndex;
3271 DWORD bState;
3273 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3275 TRACE("hwnd=%p, btn index=%ld, lParam=0x%08lx\n", hwnd, wParam, lParam);
3277 if (nIndex == -1)
3278 return FALSE;
3280 btnPtr = &infoPtr->buttons[nIndex];
3282 bState = btnPtr->fsState & TBSTATE_ENABLED;
3284 /* update the toolbar button state */
3285 if(LOWORD(lParam) == FALSE) {
3286 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3287 } else {
3288 btnPtr->fsState |= TBSTATE_ENABLED;
3291 /* redraw the button only if the state of the button changed */
3292 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3293 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3295 return TRUE;
3299 static inline LRESULT
3300 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3302 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3304 return infoPtr->bAnchor;
3308 static LRESULT
3309 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3311 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3312 INT nIndex;
3314 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3315 if (nIndex == -1)
3316 return -1;
3318 return infoPtr->buttons[nIndex].iBitmap;
3322 static inline LRESULT
3323 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3325 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3329 static LRESULT
3330 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3332 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3333 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3334 INT nIndex = (INT)wParam;
3335 TBUTTON_INFO *btnPtr;
3337 if (lpTbb == NULL)
3338 return FALSE;
3340 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3341 return FALSE;
3343 btnPtr = &infoPtr->buttons[nIndex];
3344 lpTbb->iBitmap = btnPtr->iBitmap;
3345 lpTbb->idCommand = btnPtr->idCommand;
3346 lpTbb->fsState = btnPtr->fsState;
3347 lpTbb->fsStyle = btnPtr->fsStyle;
3348 lpTbb->bReserved[0] = 0;
3349 lpTbb->bReserved[1] = 0;
3350 lpTbb->dwData = btnPtr->dwData;
3351 lpTbb->iString = btnPtr->iString;
3353 return TRUE;
3357 static LRESULT
3358 TOOLBAR_GetButtonInfoT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL bUnicode)
3360 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3361 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3362 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3363 TBUTTON_INFO *btnPtr;
3364 INT nIndex;
3366 if (lpTbInfo == NULL)
3367 return -1;
3369 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3370 * the headers and tests shows that even with comctl 6 Vista accepts only the
3371 * original TBBUTTONINFO size
3373 if (lpTbInfo->cbSize != sizeof(TBBUTTONINFOW))
3375 WARN("Invalid button size\n");
3376 return -1;
3379 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3380 lpTbInfo->dwMask & 0x80000000);
3381 if (nIndex == -1)
3382 return -1;
3384 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3386 if (lpTbInfo->dwMask & TBIF_COMMAND)
3387 lpTbInfo->idCommand = btnPtr->idCommand;
3388 if (lpTbInfo->dwMask & TBIF_IMAGE)
3389 lpTbInfo->iImage = btnPtr->iBitmap;
3390 if (lpTbInfo->dwMask & TBIF_LPARAM)
3391 lpTbInfo->lParam = btnPtr->dwData;
3392 if (lpTbInfo->dwMask & TBIF_SIZE)
3393 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3394 if (lpTbInfo->dwMask & TBIF_STATE)
3395 lpTbInfo->fsState = btnPtr->fsState;
3396 if (lpTbInfo->dwMask & TBIF_STYLE)
3397 lpTbInfo->fsStyle = btnPtr->fsStyle;
3398 if (lpTbInfo->dwMask & TBIF_TEXT) {
3399 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3400 can't use TOOLBAR_GetText here */
3401 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3402 LPWSTR lpText = (LPWSTR)btnPtr->iString;
3403 if (bUnicode)
3404 Str_GetPtrW(lpText, lpTbInfo->pszText, lpTbInfo->cchText);
3405 else
3406 Str_GetPtrWtoA(lpText, (LPSTR)lpTbInfo->pszText, lpTbInfo->cchText);
3407 } else
3408 lpTbInfo->pszText[0] = '\0';
3410 return nIndex;
3414 static LRESULT
3415 TOOLBAR_GetButtonSize (HWND hwnd)
3417 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3419 return MAKELONG((WORD)infoPtr->nButtonWidth,
3420 (WORD)infoPtr->nButtonHeight);
3424 static LRESULT
3425 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3427 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3428 INT nIndex;
3429 LPWSTR lpText;
3431 if (lParam == 0)
3432 return -1;
3434 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3435 if (nIndex == -1)
3436 return -1;
3438 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3440 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3441 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3445 static LRESULT
3446 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3448 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3449 INT nIndex;
3450 LPWSTR lpText;
3451 LRESULT ret = 0;
3453 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3454 if (nIndex == -1)
3455 return -1;
3457 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3459 if (lpText)
3461 ret = strlenW (lpText);
3463 if (lParam)
3464 strcpyW ((LPWSTR)lParam, lpText);
3467 return ret;
3471 static LRESULT
3472 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3474 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3475 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3476 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3480 static inline LRESULT
3481 TOOLBAR_GetExtendedStyle (HWND hwnd)
3483 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3485 TRACE("\n");
3487 return infoPtr->dwExStyle;
3491 static LRESULT
3492 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3494 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3495 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3496 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3500 static LRESULT
3501 TOOLBAR_GetHotItem (HWND hwnd)
3503 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3505 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3506 return -1;
3508 if (infoPtr->nHotItem < 0)
3509 return -1;
3511 return (LRESULT)infoPtr->nHotItem;
3515 static LRESULT
3516 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3518 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3519 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3520 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3524 static LRESULT
3525 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3527 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3528 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3530 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3532 *lptbim = infoPtr->tbim;
3534 return 0;
3538 static LRESULT
3539 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3541 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3543 TRACE("hwnd = %p\n", hwnd);
3545 return (LRESULT)infoPtr->clrInsertMark;
3549 static LRESULT
3550 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3552 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3553 TBUTTON_INFO *btnPtr;
3554 LPRECT lpRect;
3555 INT nIndex;
3557 nIndex = (INT)wParam;
3558 btnPtr = &infoPtr->buttons[nIndex];
3559 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3560 return FALSE;
3561 lpRect = (LPRECT)lParam;
3562 if (lpRect == NULL)
3563 return FALSE;
3564 if (btnPtr->fsState & TBSTATE_HIDDEN)
3565 return FALSE;
3567 lpRect->left = btnPtr->rect.left;
3568 lpRect->right = btnPtr->rect.right;
3569 lpRect->bottom = btnPtr->rect.bottom;
3570 lpRect->top = btnPtr->rect.top;
3572 return TRUE;
3576 static LRESULT
3577 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3579 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3580 LPSIZE lpSize = (LPSIZE)lParam;
3582 if (lpSize == NULL)
3583 return FALSE;
3585 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3586 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3588 TRACE("maximum size %d x %d\n",
3589 infoPtr->rcBound.right - infoPtr->rcBound.left,
3590 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3592 return TRUE;
3596 /* << TOOLBAR_GetObject >> */
3599 static LRESULT
3600 TOOLBAR_GetPadding (HWND hwnd)
3602 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3603 DWORD oldPad;
3605 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3606 return (LRESULT) oldPad;
3610 static LRESULT
3611 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3613 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3614 TBUTTON_INFO *btnPtr;
3615 LPRECT lpRect;
3616 INT nIndex;
3618 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3619 btnPtr = &infoPtr->buttons[nIndex];
3620 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3621 return FALSE;
3622 lpRect = (LPRECT)lParam;
3623 if (lpRect == NULL)
3624 return FALSE;
3626 lpRect->left = btnPtr->rect.left;
3627 lpRect->right = btnPtr->rect.right;
3628 lpRect->bottom = btnPtr->rect.bottom;
3629 lpRect->top = btnPtr->rect.top;
3631 return TRUE;
3635 static LRESULT
3636 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3638 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3640 return infoPtr->nRows;
3644 static LRESULT
3645 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3647 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3648 INT nIndex;
3650 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3651 if (nIndex == -1)
3652 return -1;
3654 return infoPtr->buttons[nIndex].fsState;
3658 static LRESULT
3659 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3661 return GetWindowLongW(hwnd, GWL_STYLE);
3665 static LRESULT
3666 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3668 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3670 return infoPtr->nMaxTextRows;
3674 static LRESULT
3675 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3677 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3679 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3680 TOOLBAR_TooltipCreateControl(infoPtr);
3681 return (LRESULT)infoPtr->hwndToolTip;
3685 static LRESULT
3686 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3688 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3690 TRACE("%s hwnd=%p\n",
3691 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3693 return infoPtr->bUnicode;
3697 static inline LRESULT
3698 TOOLBAR_GetVersion (HWND hwnd)
3700 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3701 return infoPtr->iVersion;
3705 static LRESULT
3706 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3708 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3709 TBUTTON_INFO *btnPtr;
3710 INT nIndex;
3712 TRACE("\n");
3714 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3715 if (nIndex == -1)
3716 return FALSE;
3718 btnPtr = &infoPtr->buttons[nIndex];
3719 if (LOWORD(lParam) == FALSE)
3720 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3721 else
3722 btnPtr->fsState |= TBSTATE_HIDDEN;
3724 TOOLBAR_LayoutToolbar (hwnd);
3726 InvalidateRect (hwnd, NULL, TRUE);
3728 return TRUE;
3732 static inline LRESULT
3733 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3735 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3739 static LRESULT
3740 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3742 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3743 TBUTTON_INFO *btnPtr;
3744 INT nIndex;
3745 DWORD oldState;
3747 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3748 if (nIndex == -1)
3749 return FALSE;
3751 btnPtr = &infoPtr->buttons[nIndex];
3752 oldState = btnPtr->fsState;
3753 if (LOWORD(lParam) == FALSE)
3754 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3755 else
3756 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3758 if(oldState != btnPtr->fsState)
3759 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3761 return TRUE;
3765 static LRESULT
3766 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3768 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3769 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3770 INT nIndex = (INT)wParam;
3772 if (lpTbb == NULL)
3773 return FALSE;
3775 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3777 if (nIndex == -1) {
3778 /* EPP: this seems to be an undocumented call (from my IE4)
3779 * I assume in that case that:
3780 * - index of insertion is at the end of existing buttons
3781 * I only see this happen with nIndex == -1, but it could have a special
3782 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3784 nIndex = infoPtr->nNumButtons;
3786 } else if (nIndex < 0)
3787 return FALSE;
3789 TRACE("inserting button index=%d\n", nIndex);
3790 if (nIndex > infoPtr->nNumButtons) {
3791 nIndex = infoPtr->nNumButtons;
3792 TRACE("adjust index=%d\n", nIndex);
3795 infoPtr->nNumButtons++;
3796 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO) * infoPtr->nNumButtons);
3797 memmove(&infoPtr->buttons[nIndex+1], &infoPtr->buttons[nIndex],
3798 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3800 /* insert new button */
3801 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3802 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3803 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3804 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3805 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3806 /* if passed string and not index, then add string */
3807 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3808 if (fUnicode)
3809 Str_SetPtrW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3810 else
3811 Str_SetPtrAtoW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3813 else
3814 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3816 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
3818 if (infoPtr->nNumStrings > 0)
3819 TOOLBAR_CalcToolbar(hwnd);
3820 else
3821 TOOLBAR_LayoutToolbar(hwnd);
3822 TOOLBAR_AutoSize (hwnd);
3824 InvalidateRect (hwnd, NULL, TRUE);
3826 return TRUE;
3829 /* << TOOLBAR_InsertMarkHitTest >> */
3832 static LRESULT
3833 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3835 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3836 INT nIndex;
3838 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3839 if (nIndex == -1)
3840 return -1;
3842 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3846 static LRESULT
3847 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3849 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3850 INT nIndex;
3852 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3853 if (nIndex == -1)
3854 return -1;
3856 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3860 static LRESULT
3861 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3863 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3864 INT nIndex;
3866 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3867 if (nIndex == -1)
3868 return -1;
3870 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3874 static LRESULT
3875 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3877 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3878 INT nIndex;
3880 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3881 if (nIndex == -1)
3882 return -1;
3884 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3888 static LRESULT
3889 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3891 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3892 INT nIndex;
3894 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3895 if (nIndex == -1)
3896 return -1;
3898 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3902 static LRESULT
3903 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3905 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3906 INT nIndex;
3908 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3909 if (nIndex == -1)
3910 return -1;
3912 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3916 static LRESULT
3917 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3919 TBADDBITMAP tbab;
3920 tbab.hInst = (HINSTANCE)lParam;
3921 tbab.nID = (UINT_PTR)wParam;
3923 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", hwnd, tbab.hInst, tbab.nID);
3925 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3929 static LRESULT
3930 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3932 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3933 WCHAR wAccel = (WCHAR)wParam;
3934 UINT* pIDButton = (UINT*)lParam;
3935 WCHAR wszAccel[] = {'&',wAccel,0};
3936 int i;
3938 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3939 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3941 for (i = 0; i < infoPtr->nNumButtons; i++)
3943 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3944 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3945 !(btnPtr->fsState & TBSTATE_HIDDEN))
3947 int iLen = strlenW(wszAccel);
3948 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3950 if (!lpszStr)
3951 continue;
3953 while (*lpszStr)
3955 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3957 lpszStr += 2;
3958 continue;
3960 if (!strncmpiW(lpszStr, wszAccel, iLen))
3962 *pIDButton = btnPtr->idCommand;
3963 return TRUE;
3965 lpszStr++;
3969 return FALSE;
3973 static LRESULT
3974 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3976 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3977 INT nIndex;
3978 DWORD oldState;
3979 TBUTTON_INFO *btnPtr;
3981 TRACE("hwnd = %p, wParam = %ld, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3983 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3984 if (nIndex == -1)
3985 return FALSE;
3987 btnPtr = &infoPtr->buttons[nIndex];
3988 oldState = btnPtr->fsState;
3990 if (LOWORD(lParam))
3991 btnPtr->fsState |= TBSTATE_MARKED;
3992 else
3993 btnPtr->fsState &= ~TBSTATE_MARKED;
3995 if(oldState != btnPtr->fsState)
3996 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3998 return TRUE;
4002 /* fixes up an index of a button affected by a move */
4003 static inline void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4005 if (bMoveUp)
4007 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4008 (*pIndex)--;
4009 else if (*pIndex == nIndex)
4010 *pIndex = nMoveIndex;
4012 else
4014 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4015 (*pIndex)++;
4016 else if (*pIndex == nIndex)
4017 *pIndex = nMoveIndex;
4022 static LRESULT
4023 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4025 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4026 INT nIndex;
4027 INT nCount;
4028 INT nMoveIndex = (INT)lParam;
4029 TBUTTON_INFO button;
4031 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
4033 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4034 if ((nIndex == -1) || (nMoveIndex < 0))
4035 return FALSE;
4037 if (nMoveIndex > infoPtr->nNumButtons - 1)
4038 nMoveIndex = infoPtr->nNumButtons - 1;
4040 button = infoPtr->buttons[nIndex];
4042 /* move button right */
4043 if (nIndex < nMoveIndex)
4045 nCount = nMoveIndex - nIndex;
4046 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4047 infoPtr->buttons[nMoveIndex] = button;
4049 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4050 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4051 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4052 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4054 else if (nIndex > nMoveIndex) /* move button left */
4056 nCount = nIndex - nMoveIndex;
4057 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4058 infoPtr->buttons[nMoveIndex] = button;
4060 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4061 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4062 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4063 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4066 TOOLBAR_LayoutToolbar(hwnd);
4067 TOOLBAR_AutoSize(hwnd);
4068 InvalidateRect(hwnd, NULL, TRUE);
4070 return TRUE;
4074 static LRESULT
4075 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4077 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4078 TBUTTON_INFO *btnPtr;
4079 INT nIndex;
4080 DWORD oldState;
4082 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4083 if (nIndex == -1)
4084 return FALSE;
4086 btnPtr = &infoPtr->buttons[nIndex];
4087 oldState = btnPtr->fsState;
4088 if (LOWORD(lParam) == FALSE)
4089 btnPtr->fsState &= ~TBSTATE_PRESSED;
4090 else
4091 btnPtr->fsState |= TBSTATE_PRESSED;
4093 if(oldState != btnPtr->fsState)
4094 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4096 return TRUE;
4099 /* FIXME: there might still be some confusion her between number of buttons
4100 * and number of bitmaps */
4101 static LRESULT
4102 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4104 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4105 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4106 HBITMAP hBitmap;
4107 int i = 0, nOldButtons = 0, pos = 0;
4108 int nOldBitmaps, nNewBitmaps = 0;
4109 HIMAGELIST himlDef = 0;
4111 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4112 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4113 lpReplace->nButtons);
4115 if (lpReplace->hInstOld == HINST_COMMCTRL)
4117 FIXME("changing standard bitmaps not implemented\n");
4118 return FALSE;
4120 else if (lpReplace->hInstOld != 0)
4121 FIXME("resources not in the current module not implemented\n");
4123 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4124 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4125 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4126 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4127 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4129 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4130 nOldButtons = tbi->nButtons;
4131 tbi->nButtons = lpReplace->nButtons;
4132 tbi->hInst = lpReplace->hInstNew;
4133 tbi->nID = lpReplace->nIDNew;
4134 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4135 break;
4137 pos += tbi->nButtons;
4140 if (nOldButtons == 0)
4142 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4143 return FALSE;
4146 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4147 * bitmap
4149 if (lpReplace->hInstNew)
4150 hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4151 else
4152 hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
4154 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4155 nOldBitmaps = ImageList_GetImageCount(himlDef);
4157 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4159 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4160 ImageList_Remove(himlDef, i);
4162 if (hBitmap)
4164 ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
4165 nNewBitmaps = ImageList_GetImageCount(himlDef);
4166 DeleteObject(hBitmap);
4169 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4171 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4172 pos, nOldBitmaps, nNewBitmaps);
4174 InvalidateRect(hwnd, NULL, TRUE);
4175 return TRUE;
4179 /* helper for TOOLBAR_SaveRestoreW */
4180 static BOOL
4181 TOOLBAR_Save(const TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
4183 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4184 debugstr_w(lpSave->pszValueName));
4186 return FALSE;
4190 /* helper for TOOLBAR_Restore */
4191 static void
4192 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4194 INT i;
4196 for (i = 0; i < infoPtr->nNumButtons; i++)
4198 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4201 Free(infoPtr->buttons);
4202 infoPtr->buttons = NULL;
4203 infoPtr->nNumButtons = 0;
4207 /* helper for TOOLBAR_SaveRestoreW */
4208 static BOOL
4209 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
4211 LONG res;
4212 HKEY hkey = NULL;
4213 BOOL ret = FALSE;
4214 DWORD dwType;
4215 DWORD dwSize = 0;
4216 NMTBRESTORE nmtbr;
4218 /* restore toolbar information */
4219 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4220 debugstr_w(lpSave->pszValueName));
4222 memset(&nmtbr, 0, sizeof(nmtbr));
4224 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4225 KEY_QUERY_VALUE, &hkey);
4226 if (!res)
4227 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4228 NULL, &dwSize);
4229 if (!res && dwType != REG_BINARY)
4230 res = ERROR_FILE_NOT_FOUND;
4231 if (!res)
4233 nmtbr.pData = Alloc(dwSize);
4234 nmtbr.cbData = (UINT)dwSize;
4235 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4237 if (!res)
4238 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4239 (LPBYTE)nmtbr.pData, &dwSize);
4240 if (!res)
4242 nmtbr.pCurrent = nmtbr.pData;
4243 nmtbr.iItem = -1;
4244 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4245 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4247 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4249 INT i;
4251 /* remove all existing buttons as this function is designed to
4252 * restore the toolbar to a previously saved state */
4253 TOOLBAR_DeleteAllButtons(infoPtr);
4255 for (i = 0; i < nmtbr.cButtons; i++)
4257 nmtbr.iItem = i;
4258 nmtbr.tbButton.iBitmap = -1;
4259 nmtbr.tbButton.fsState = 0;
4260 nmtbr.tbButton.fsStyle = 0;
4261 nmtbr.tbButton.idCommand = 0;
4262 if (*nmtbr.pCurrent == (DWORD)-1)
4264 /* separator */
4265 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4266 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4268 else if (*nmtbr.pCurrent == (DWORD)-2)
4269 /* hidden button */
4270 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4271 else
4272 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4274 nmtbr.pCurrent++;
4276 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4278 /* can't contain real string as we don't know whether
4279 * the client put an ANSI or Unicode string in there */
4280 if (HIWORD(nmtbr.tbButton.iString))
4281 nmtbr.tbButton.iString = 0;
4283 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4284 (LPARAM)&nmtbr.tbButton, TRUE);
4287 /* do legacy notifications */
4288 if (infoPtr->iVersion < 5)
4290 /* FIXME: send TBN_BEGINADJUST */
4291 FIXME("send TBN_GETBUTTONINFO for each button\n");
4292 /* FIXME: send TBN_ENDADJUST */
4295 /* remove all uninitialised buttons
4296 * note: loop backwards to avoid having to fixup i on a
4297 * delete */
4298 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4299 if (infoPtr->buttons[i].iBitmap == -1)
4300 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4302 /* only indicate success if at least one button survived */
4303 if (infoPtr->nNumButtons > 0) ret = TRUE;
4306 Free (nmtbr.pData);
4307 RegCloseKey(hkey);
4309 return ret;
4313 static LRESULT
4314 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, const TBSAVEPARAMSW *lpSave)
4316 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4318 if (lpSave == NULL) return 0;
4320 if (wParam)
4321 return TOOLBAR_Save(infoPtr, lpSave);
4322 else
4323 return TOOLBAR_Restore(infoPtr, lpSave);
4327 static LRESULT
4328 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, const TBSAVEPARAMSA *lpSave)
4330 LPWSTR pszValueName = 0, pszSubKey = 0;
4331 TBSAVEPARAMSW SaveW;
4332 LRESULT result = 0;
4333 int len;
4335 if (lpSave == NULL) return 0;
4337 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4338 pszSubKey = Alloc(len * sizeof(WCHAR));
4339 if (pszSubKey) goto exit;
4340 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4342 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4343 pszValueName = Alloc(len * sizeof(WCHAR));
4344 if (!pszValueName) goto exit;
4345 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4347 SaveW.pszValueName = pszValueName;
4348 SaveW.pszSubKey = pszSubKey;
4349 SaveW.hkr = lpSave->hkr;
4350 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4352 exit:
4353 Free (pszValueName);
4354 Free (pszSubKey);
4356 return result;
4360 static LRESULT
4361 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4363 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4364 BOOL bOldAnchor = infoPtr->bAnchor;
4366 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4368 infoPtr->bAnchor = (BOOL)wParam;
4370 /* Native does not remove the hot effect from an already hot button */
4372 return (LRESULT)bOldAnchor;
4376 static LRESULT
4377 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4379 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4380 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4382 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
4384 if (wParam != 0)
4385 FIXME("wParam is %ld. Perhaps image list index?\n", wParam);
4387 if (LOWORD(lParam) == 0)
4388 lParam = MAKELPARAM(1, HIWORD(lParam));
4390 if (HIWORD(lParam)==0)
4391 lParam = MAKELPARAM(LOWORD(lParam), 1);
4393 if (infoPtr->nNumButtons > 0)
4394 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4395 infoPtr->nNumButtons,
4396 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4397 LOWORD(lParam), HIWORD(lParam));
4399 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4400 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4402 if ((himlDef == infoPtr->himlInt) &&
4403 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4405 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4406 infoPtr->nBitmapHeight);
4409 TOOLBAR_CalcToolbar(hwnd);
4410 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4411 return TRUE;
4415 static LRESULT
4416 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4418 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4419 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4420 TBUTTON_INFO *btnPtr;
4421 INT nIndex;
4422 RECT oldBtnRect;
4424 if (lptbbi == NULL)
4425 return FALSE;
4426 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4427 return FALSE;
4429 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4430 lptbbi->dwMask & 0x80000000);
4431 if (nIndex == -1)
4432 return FALSE;
4434 btnPtr = &infoPtr->buttons[nIndex];
4435 if (lptbbi->dwMask & TBIF_COMMAND)
4436 btnPtr->idCommand = lptbbi->idCommand;
4437 if (lptbbi->dwMask & TBIF_IMAGE)
4438 btnPtr->iBitmap = lptbbi->iImage;
4439 if (lptbbi->dwMask & TBIF_LPARAM)
4440 btnPtr->dwData = lptbbi->lParam;
4441 if (lptbbi->dwMask & TBIF_SIZE)
4442 btnPtr->cx = lptbbi->cx;
4443 if (lptbbi->dwMask & TBIF_STATE)
4444 btnPtr->fsState = lptbbi->fsState;
4445 if (lptbbi->dwMask & TBIF_STYLE)
4446 btnPtr->fsStyle = lptbbi->fsStyle;
4448 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4449 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4450 /* iString is index, zero it to make Str_SetPtr succeed */
4451 btnPtr->iString=0;
4453 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4456 /* save the button rect to see if we need to redraw the whole toolbar */
4457 oldBtnRect = btnPtr->rect;
4458 TOOLBAR_CalcToolbar(hwnd);
4460 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4461 InvalidateRect(hwnd, NULL, TRUE);
4462 else
4463 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4465 return TRUE;
4469 static LRESULT
4470 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4472 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4473 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4474 TBUTTON_INFO *btnPtr;
4475 INT nIndex;
4476 RECT oldBtnRect;
4478 if (lptbbi == NULL)
4479 return FALSE;
4480 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4481 return FALSE;
4483 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4484 lptbbi->dwMask & 0x80000000);
4485 if (nIndex == -1)
4486 return FALSE;
4488 btnPtr = &infoPtr->buttons[nIndex];
4489 if (lptbbi->dwMask & TBIF_COMMAND)
4490 btnPtr->idCommand = lptbbi->idCommand;
4491 if (lptbbi->dwMask & TBIF_IMAGE)
4492 btnPtr->iBitmap = lptbbi->iImage;
4493 if (lptbbi->dwMask & TBIF_LPARAM)
4494 btnPtr->dwData = lptbbi->lParam;
4495 if (lptbbi->dwMask & TBIF_SIZE)
4496 btnPtr->cx = lptbbi->cx;
4497 if (lptbbi->dwMask & TBIF_STATE)
4498 btnPtr->fsState = lptbbi->fsState;
4499 if (lptbbi->dwMask & TBIF_STYLE)
4500 btnPtr->fsStyle = lptbbi->fsStyle;
4502 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4503 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4504 /* iString is index, zero it to make Str_SetPtr succeed */
4505 btnPtr->iString=0;
4506 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4509 /* save the button rect to see if we need to redraw the whole toolbar */
4510 oldBtnRect = btnPtr->rect;
4511 TOOLBAR_CalcToolbar(hwnd);
4513 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4514 InvalidateRect(hwnd, NULL, TRUE);
4515 else
4516 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4518 return TRUE;
4522 static LRESULT
4523 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4525 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4526 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4528 if ((cx < 0) || (cy < 0))
4530 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4531 return FALSE;
4534 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4536 /* The documentation claims you can only change the button size before
4537 * any button has been added. But this is wrong.
4538 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4539 * it to the toolbar, and it checks that the return value is nonzero - mjm
4540 * Further testing shows that we must actually perform the change too.
4543 * The documentation also does not mention that if 0 is supplied for
4544 * either size, the system changes it to the default of 24 wide and
4545 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4547 if (cx == 0) cx = 24;
4548 if (cy == 0) cx = 22;
4550 cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
4551 cy = max(cy, infoPtr->szPadding.cy + infoPtr->nBitmapHeight);
4553 infoPtr->nButtonWidth = cx;
4554 infoPtr->nButtonHeight = cy;
4556 infoPtr->iTopMargin = default_top_margin(infoPtr);
4557 TOOLBAR_LayoutToolbar(hwnd);
4558 return TRUE;
4562 static LRESULT
4563 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4565 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4567 /* if setting to current values, ignore */
4568 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4569 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4570 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4571 infoPtr->cxMin, infoPtr->cxMax);
4572 return TRUE;
4575 /* save new values */
4576 infoPtr->cxMin = (short)LOWORD(lParam);
4577 infoPtr->cxMax = (short)HIWORD(lParam);
4579 /* otherwise we need to recalc the toolbar and in some cases
4580 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4581 which doesn't actually draw - GA). */
4582 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4583 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4585 TOOLBAR_CalcToolbar (hwnd);
4587 InvalidateRect (hwnd, NULL, TRUE);
4589 return TRUE;
4593 static LRESULT
4594 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4596 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4597 INT nIndex = (INT)wParam;
4599 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4600 return FALSE;
4602 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4604 if (infoPtr->hwndToolTip) {
4606 FIXME("change tool tip!\n");
4610 return TRUE;
4614 static LRESULT
4615 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4617 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4618 HIMAGELIST himl = (HIMAGELIST)lParam;
4619 HIMAGELIST himlTemp;
4620 INT id = 0;
4622 if (infoPtr->iVersion >= 5)
4623 id = wParam;
4625 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4626 &infoPtr->cimlDis, himl, id);
4628 /* FIXME: redraw ? */
4630 return (LRESULT)himlTemp;
4634 static LRESULT
4635 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4637 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4638 DWORD dwTemp;
4640 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4642 dwTemp = infoPtr->dwDTFlags;
4643 infoPtr->dwDTFlags =
4644 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4646 return (LRESULT)dwTemp;
4649 /* This function differs a bit from what MSDN says it does:
4650 * 1. lParam contains extended style flags to OR with current style
4651 * (MSDN isn't clear on the OR bit)
4652 * 2. wParam appears to contain extended style flags to be reset
4653 * (MSDN says that this parameter is reserved)
4655 static LRESULT
4656 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4658 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4659 DWORD dwTemp;
4661 dwTemp = infoPtr->dwExStyle;
4662 infoPtr->dwExStyle &= ~wParam;
4663 infoPtr->dwExStyle |= (DWORD)lParam;
4665 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4667 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4668 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4669 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4671 TOOLBAR_CalcToolbar (hwnd);
4673 TOOLBAR_AutoSize(hwnd);
4675 InvalidateRect(hwnd, NULL, TRUE);
4677 return (LRESULT)dwTemp;
4681 static LRESULT
4682 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4684 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4685 HIMAGELIST himlTemp;
4686 HIMAGELIST himl = (HIMAGELIST)lParam;
4687 INT id = 0;
4689 if (infoPtr->iVersion >= 5)
4690 id = wParam;
4692 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4694 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4695 &infoPtr->cimlHot, himl, id);
4697 /* FIXME: redraw ? */
4699 return (LRESULT)himlTemp;
4703 /* Makes previous hot button no longer hot, makes the specified
4704 * button hot and sends appropriate notifications. dwReason is one or
4705 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4706 * NOTE 1: this function does not validate nHit
4707 * NOTE 2: the name of this function is completely made up and
4708 * not based on any documentation from Microsoft. */
4709 static void
4710 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4712 if (infoPtr->nHotItem != nHit)
4714 NMTBHOTITEM nmhotitem;
4715 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4717 nmhotitem.dwFlags = dwReason;
4718 if(infoPtr->nHotItem >= 0)
4720 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4721 nmhotitem.idOld = oldBtnPtr->idCommand;
4723 else
4725 nmhotitem.dwFlags |= HICF_ENTERING;
4726 nmhotitem.idOld = 0;
4729 if (nHit >= 0)
4731 btnPtr = &infoPtr->buttons[nHit];
4732 nmhotitem.idNew = btnPtr->idCommand;
4734 else
4736 nmhotitem.dwFlags |= HICF_LEAVING;
4737 nmhotitem.idNew = 0;
4740 /* now change the hot and invalidate the old and new buttons - if the
4741 * parent agrees */
4742 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4744 if (oldBtnPtr) {
4745 oldBtnPtr->bHot = FALSE;
4746 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4748 /* setting disabled buttons as hot fails even if the notify contains the button id */
4749 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4750 btnPtr->bHot = TRUE;
4751 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4752 infoPtr->nHotItem = nHit;
4754 else
4755 infoPtr->nHotItem = -1;
4760 static LRESULT
4761 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4763 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4764 INT nOldHotItem = infoPtr->nHotItem;
4766 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4768 if ((INT)wParam > infoPtr->nNumButtons)
4769 return infoPtr->nHotItem;
4771 if ((INT)wParam < 0)
4772 wParam = -1;
4774 /* NOTE: an application can still remove the hot item even if anchor
4775 * highlighting is enabled */
4777 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4779 if (nOldHotItem < 0)
4780 return -1;
4782 return (LRESULT)nOldHotItem;
4786 static LRESULT
4787 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4789 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4790 HIMAGELIST himlTemp;
4791 HIMAGELIST himl = (HIMAGELIST)lParam;
4792 INT oldButtonWidth = infoPtr->nButtonWidth;
4793 INT i, id = 0;
4795 if (infoPtr->iVersion >= 5)
4796 id = wParam;
4798 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4799 &infoPtr->cimlDef, himl, id);
4801 infoPtr->nNumBitmaps = 0;
4802 for (i = 0; i < infoPtr->cimlDef; i++)
4803 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4805 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4806 &infoPtr->nBitmapHeight))
4808 infoPtr->nBitmapWidth = 1;
4809 infoPtr->nBitmapHeight = 1;
4811 TOOLBAR_CalcToolbar(hwnd);
4812 if (infoPtr->nButtonWidth < oldButtonWidth)
4813 TOOLBAR_SetButtonSize(hwnd, 0, MAKELONG(oldButtonWidth, infoPtr->nButtonHeight));
4815 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4816 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4817 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4819 InvalidateRect(hwnd, NULL, TRUE);
4821 return (LRESULT)himlTemp;
4825 static LRESULT
4826 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4828 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4830 infoPtr->nIndent = (INT)wParam;
4832 TRACE("\n");
4834 /* process only on indent changing */
4835 if(infoPtr->nIndent != (INT)wParam)
4837 infoPtr->nIndent = (INT)wParam;
4838 TOOLBAR_CalcToolbar (hwnd);
4839 InvalidateRect(hwnd, NULL, FALSE);
4842 return TRUE;
4846 static LRESULT
4847 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4849 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4850 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4852 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4854 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4856 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4857 return 0;
4860 if ((lptbim->iButton == -1) ||
4861 ((lptbim->iButton < infoPtr->nNumButtons) &&
4862 (lptbim->iButton >= 0)))
4864 infoPtr->tbim = *lptbim;
4865 /* FIXME: don't need to update entire toolbar */
4866 InvalidateRect(hwnd, NULL, TRUE);
4868 else
4869 ERR("Invalid button index %d\n", lptbim->iButton);
4871 return 0;
4875 static LRESULT
4876 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4878 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4880 infoPtr->clrInsertMark = (COLORREF)lParam;
4882 /* FIXME: don't need to update entire toolbar */
4883 InvalidateRect(hwnd, NULL, TRUE);
4885 return 0;
4889 static LRESULT
4890 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4892 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4894 infoPtr->nMaxTextRows = (INT)wParam;
4896 TOOLBAR_CalcToolbar(hwnd);
4897 return TRUE;
4901 /* MSDN gives slightly wrong info on padding.
4902 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4903 * 2. It is not used to create a blank area between the edge of the button
4904 * and the text or image if TBSTYLE_LIST is set. It is used to control
4905 * the gap between the image and text.
4906 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4907 * to control the bottom and right borders [with the border being
4908 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4909 * is shared evenly on both sides of the button.
4910 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4912 static LRESULT
4913 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4915 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4916 DWORD oldPad;
4918 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4919 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4920 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4921 TRACE("cx=%d, cy=%d\n",
4922 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4923 return (LRESULT) oldPad;
4927 static LRESULT
4928 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4930 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4931 HWND hwndOldNotify;
4933 TRACE("\n");
4935 hwndOldNotify = infoPtr->hwndNotify;
4936 infoPtr->hwndNotify = (HWND)wParam;
4938 return (LRESULT)hwndOldNotify;
4942 static LRESULT
4943 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4945 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4946 LPRECT lprc = (LPRECT)lParam;
4947 int rows = LOWORD(wParam);
4948 BOOL bLarger = HIWORD(wParam);
4950 TRACE("\n");
4952 TRACE("Setting rows to %d (%d)\n", rows, bLarger);
4954 if(infoPtr->nRows != rows)
4956 TBUTTON_INFO *btnPtr = infoPtr->buttons;
4957 int curColumn = 0; /* Current column */
4958 int curRow = 0; /* Current row */
4959 int hidden = 0; /* Number of hidden buttons */
4960 int seps = 0; /* Number of separators */
4961 int idealWrap = 0; /* Ideal wrap point */
4962 int i;
4963 BOOL wrap;
4966 Calculate new size and wrap points - Under windows, setrows will
4967 change the dimensions if needed to show the number of requested
4968 rows (if CCS_NORESIZE is set), or will take up the whole window
4969 (if no CCS_NORESIZE).
4971 Basic algorithum - If N buttons, and y rows requested, each row
4972 contains N/y buttons.
4974 FIXME: Handling of separators not obvious from testing results
4975 FIXME: Take width of window into account?
4978 /* Loop through the buttons one by one counting key items */
4979 for (i = 0; i < infoPtr->nNumButtons; i++ )
4981 btnPtr[i].fsState &= ~TBSTATE_WRAP;
4982 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
4983 hidden++;
4984 else if (btnPtr[i].fsStyle & BTNS_SEP)
4985 seps++;
4988 /* FIXME: Separators make this quite complex */
4989 if (seps) FIXME("Separators unhandled\n");
4991 /* Round up so more per line, ie less rows */
4992 idealWrap = (infoPtr->nNumButtons - hidden + (rows-1)) / rows;
4994 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4995 achieve the requested number of rows. */
4996 if (bLarger && idealWrap > 1)
4998 int resRows = (infoPtr->nNumButtons + (idealWrap-1)) / idealWrap;
4999 int moreRows = (infoPtr->nNumButtons + (idealWrap-2)) / (idealWrap-1);
5001 if (resRows < rows && moreRows > rows)
5003 idealWrap--;
5004 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap);
5008 curColumn = curRow = 0;
5009 wrap = FALSE;
5010 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap,
5011 infoPtr->nNumButtons, hidden, rows);
5013 for (i = 0; i < infoPtr->nNumButtons; i++ )
5015 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
5016 continue;
5018 /* Step on, wrap if necessary or flag next to wrap */
5019 if (!wrap) {
5020 curColumn++;
5021 } else {
5022 wrap = FALSE;
5023 curColumn = 1;
5024 curRow++;
5027 if (curColumn > (idealWrap-1)) {
5028 wrap = TRUE;
5029 btnPtr[i].fsState |= TBSTATE_WRAP;
5033 TRACE("Result - %d rows\n", curRow + 1);
5035 /* recalculate toolbar */
5036 TOOLBAR_CalcToolbar (hwnd);
5038 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
5039 if NORESIZE is NOT set, then the toolbar will always be resized to
5040 take up the whole window. With it set, sizing needs to be manual. */
5041 if (infoPtr->dwStyle & CCS_NORESIZE) {
5042 SetWindowPos(hwnd, NULL, 0, 0,
5043 infoPtr->rcBound.right - infoPtr->rcBound.left,
5044 infoPtr->rcBound.bottom - infoPtr->rcBound.top,
5045 SWP_NOMOVE);
5048 /* repaint toolbar */
5049 InvalidateRect(hwnd, NULL, TRUE);
5052 /* return bounding rectangle */
5053 if (lprc) {
5054 lprc->left = infoPtr->rcBound.left;
5055 lprc->right = infoPtr->rcBound.right;
5056 lprc->top = infoPtr->rcBound.top;
5057 lprc->bottom = infoPtr->rcBound.bottom;
5060 return 0;
5064 static LRESULT
5065 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5067 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5068 TBUTTON_INFO *btnPtr;
5069 INT nIndex;
5071 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5072 if (nIndex == -1)
5073 return FALSE;
5075 btnPtr = &infoPtr->buttons[nIndex];
5077 /* if hidden state has changed the invalidate entire window and recalc */
5078 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5079 btnPtr->fsState = LOWORD(lParam);
5080 TOOLBAR_CalcToolbar (hwnd);
5081 InvalidateRect(hwnd, 0, TRUE);
5082 return TRUE;
5085 /* process state changing if current state doesn't match new state */
5086 if(btnPtr->fsState != LOWORD(lParam))
5088 btnPtr->fsState = LOWORD(lParam);
5089 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5092 return TRUE;
5096 static LRESULT
5097 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5099 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5101 return TRUE;
5105 static inline LRESULT
5106 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5108 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5110 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5112 infoPtr->hwndToolTip = (HWND)wParam;
5113 return 0;
5117 static LRESULT
5118 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5120 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5121 BOOL bTemp;
5123 TRACE("%s hwnd=%p\n",
5124 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5126 bTemp = infoPtr->bUnicode;
5127 infoPtr->bUnicode = (BOOL)wParam;
5129 return bTemp;
5133 static LRESULT
5134 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5136 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5138 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5139 comctl32_color.clrBtnHighlight :
5140 infoPtr->clrBtnHighlight;
5141 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5142 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5143 return 1;
5147 static LRESULT
5148 TOOLBAR_SetColorScheme (HWND hwnd, const COLORSCHEME *lParam)
5150 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5152 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5153 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5154 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5156 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5157 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5158 InvalidateRect(hwnd, NULL, TRUE);
5159 return 0;
5163 static LRESULT
5164 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5166 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5167 INT iOldVersion = infoPtr->iVersion;
5169 infoPtr->iVersion = iVersion;
5171 if (infoPtr->iVersion >= 5)
5172 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5174 return iOldVersion;
5178 static LRESULT
5179 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5181 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5182 WORD iString = HIWORD(wParam);
5183 WORD buffersize = LOWORD(wParam);
5184 LPSTR str = (LPSTR)lParam;
5185 LRESULT ret = -1;
5187 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5189 if (iString < infoPtr->nNumStrings)
5191 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5193 TRACE("returning %s\n", debugstr_a(str));
5195 else
5196 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5198 return ret;
5202 static LRESULT
5203 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5205 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5206 WORD iString = HIWORD(wParam);
5207 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5208 LPWSTR str = (LPWSTR)lParam;
5209 LRESULT ret = -1;
5211 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5213 if (iString < infoPtr->nNumStrings)
5215 len = min(len, strlenW(infoPtr->strings[iString]));
5216 ret = (len+1)*sizeof(WCHAR);
5217 memcpy(str, infoPtr->strings[iString], ret);
5218 str[len] = '\0';
5220 TRACE("returning %s\n", debugstr_w(str));
5222 else
5223 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5225 return ret;
5228 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5229 * is the maximum size of the toolbar? */
5230 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5232 SIZE * pSize = (SIZE*)lParam;
5233 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5234 return 0;
5238 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5239 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5240 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5241 * sends). */
5242 static LRESULT
5243 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5245 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5246 INT nOldHotItem = infoPtr->nHotItem;
5248 TRACE("old item=%d, new item=%d, flags=%08x\n",
5249 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5251 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5252 wParam = -1;
5254 /* NOTE: an application can still remove the hot item even if anchor
5255 * highlighting is enabled */
5257 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5259 GetFocus();
5261 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5264 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5265 * which controls the amount of spacing between the image and the text
5266 * of buttons for TBSTYLE_LIST toolbars. */
5267 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5269 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5271 TRACE("hwnd=%p iListGap=%ld\n", hwnd, wParam);
5273 if (lParam != 0)
5274 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5276 infoPtr->iListGap = (INT)wParam;
5278 InvalidateRect(hwnd, NULL, TRUE);
5280 return 0;
5283 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5284 * of image lists associated with the various states. */
5285 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5287 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5289 TRACE("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5291 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5294 static LRESULT
5295 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5297 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5298 LPSIZE lpsize = (LPSIZE)lParam;
5300 if (lpsize == NULL)
5301 return FALSE;
5304 * Testing shows the following:
5305 * wParam = 0 adjust cx value
5306 * = 1 set cy value to max size.
5307 * lParam pointer to SIZE structure
5310 TRACE("[0463] wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5311 wParam, lParam, lpsize->cx, lpsize->cy);
5313 switch(wParam) {
5314 case 0:
5315 if (lpsize->cx == -1) {
5316 /* **** this is wrong, native measures each button and sets it */
5317 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5319 else if(HIWORD(lpsize->cx)) {
5320 RECT rc;
5321 HWND hwndParent = GetParent(hwnd);
5323 GetWindowRect(hwnd, &rc);
5324 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5325 TRACE("mapped to (%d,%d)-(%d,%d)\n",
5326 rc.left, rc.top, rc.right, rc.bottom);
5327 lpsize->cx = max(rc.right-rc.left,
5328 infoPtr->rcBound.right - infoPtr->rcBound.left);
5330 else {
5331 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5333 break;
5334 case 1:
5335 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5336 break;
5337 default:
5338 ERR("Unknown wParam %ld for Toolbar message [0463]. Please report\n",
5339 wParam);
5340 return 0;
5342 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5343 lpsize->cx, lpsize->cy);
5344 return 1;
5347 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5349 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5351 InvalidateRect(hwnd, NULL, TRUE);
5352 return 1;
5356 static LRESULT
5357 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5359 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5360 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5361 LOGFONTW logFont;
5363 TRACE("hwnd = %p\n", hwnd);
5365 /* initialize info structure */
5366 infoPtr->nButtonWidth = 23;
5367 infoPtr->nButtonHeight = 22;
5368 infoPtr->nBitmapHeight = 16;
5369 infoPtr->nBitmapWidth = 16;
5371 infoPtr->nMaxTextRows = 1;
5372 infoPtr->cxMin = -1;
5373 infoPtr->cxMax = -1;
5374 infoPtr->nNumBitmaps = 0;
5375 infoPtr->nNumStrings = 0;
5377 infoPtr->bCaptured = FALSE;
5378 infoPtr->nButtonDown = -1;
5379 infoPtr->nButtonDrag = -1;
5380 infoPtr->nOldHit = -1;
5381 infoPtr->nHotItem = -1;
5382 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5383 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5384 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5385 infoPtr->bDragOutSent = FALSE;
5386 infoPtr->iVersion = 0;
5387 infoPtr->hwndSelf = hwnd;
5388 infoPtr->bDoRedraw = TRUE;
5389 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5390 infoPtr->clrBtnShadow = CLR_DEFAULT;
5391 infoPtr->szPadding.cx = DEFPAD_CX;
5392 infoPtr->szPadding.cy = DEFPAD_CY;
5393 infoPtr->iListGap = DEFLISTGAP;
5394 infoPtr->iTopMargin = default_top_margin(infoPtr);
5395 infoPtr->dwStyle = dwStyle;
5396 infoPtr->tbim.iButton = -1;
5397 GetClientRect(hwnd, &infoPtr->client_rect);
5398 infoPtr->bUnicode = infoPtr->hwndNotify &&
5399 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5400 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5402 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5403 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5405 OpenThemeData (hwnd, themeClass);
5407 TOOLBAR_CheckStyle (hwnd, dwStyle);
5409 return 0;
5413 static LRESULT
5414 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5416 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5418 /* delete tooltip control */
5419 if (infoPtr->hwndToolTip)
5420 DestroyWindow (infoPtr->hwndToolTip);
5422 /* delete temporary buffer for tooltip text */
5423 Free (infoPtr->pszTooltipText);
5424 Free (infoPtr->bitmaps); /* bitmaps list */
5426 /* delete button data */
5427 Free (infoPtr->buttons);
5429 /* delete strings */
5430 if (infoPtr->strings) {
5431 INT i;
5432 for (i = 0; i < infoPtr->nNumStrings; i++)
5433 Free (infoPtr->strings[i]);
5435 Free (infoPtr->strings);
5438 /* destroy internal image list */
5439 if (infoPtr->himlInt)
5440 ImageList_Destroy (infoPtr->himlInt);
5442 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5443 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5444 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5446 /* delete default font */
5447 DeleteObject (infoPtr->hDefaultFont);
5449 CloseThemeData (GetWindowTheme (hwnd));
5451 /* free toolbar info data */
5452 Free (infoPtr);
5453 SetWindowLongPtrW (hwnd, 0, 0);
5455 return 0;
5459 static LRESULT
5460 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5462 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5463 NMTBCUSTOMDRAW tbcd;
5464 INT ret = FALSE;
5465 DWORD ntfret;
5466 HTHEME theme = GetWindowTheme (hwnd);
5467 DWORD dwEraseCustDraw = 0;
5469 /* the app has told us not to redraw the toolbar */
5470 if (!infoPtr->bDoRedraw)
5471 return FALSE;
5473 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5474 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5475 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5476 tbcd.nmcd.hdc = (HDC)wParam;
5477 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5478 dwEraseCustDraw = ntfret & 0xffff;
5480 /* FIXME: in general the return flags *can* be or'ed together */
5481 switch (dwEraseCustDraw)
5483 case CDRF_DODEFAULT:
5484 break;
5485 case CDRF_SKIPDEFAULT:
5486 return TRUE;
5487 default:
5488 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5489 hwnd, ntfret);
5493 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5494 * to my parent for processing.
5496 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5497 POINT pt, ptorig;
5498 HDC hdc = (HDC)wParam;
5499 HWND parent;
5501 pt.x = 0;
5502 pt.y = 0;
5503 parent = GetParent(hwnd);
5504 MapWindowPoints(hwnd, parent, &pt, 1);
5505 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5506 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5507 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5509 if (!ret)
5510 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5512 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5513 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5514 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5515 tbcd.nmcd.hdc = (HDC)wParam;
5516 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5517 dwEraseCustDraw = ntfret & 0xffff;
5518 switch (dwEraseCustDraw)
5520 case CDRF_DODEFAULT:
5521 break;
5522 case CDRF_SKIPDEFAULT:
5523 return TRUE;
5524 default:
5525 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5526 hwnd, ntfret);
5529 return ret;
5533 static LRESULT
5534 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5536 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5538 return (LRESULT)infoPtr->hFont;
5542 static void
5543 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5545 INT i;
5546 INT nNewHotItem = infoPtr->nHotItem;
5548 for (i = 0; i < infoPtr->nNumButtons; i++)
5550 /* did we wrap? */
5551 if ((nNewHotItem + iDirection < 0) ||
5552 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5554 NMTBWRAPHOTITEM nmtbwhi;
5555 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5556 nmtbwhi.iDirection = iDirection;
5557 nmtbwhi.dwReason = dwReason;
5559 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5560 return;
5563 nNewHotItem += iDirection;
5564 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5566 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5567 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5569 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5570 break;
5575 static LRESULT
5576 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5578 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5579 NMKEY nmkey;
5581 nmkey.nVKey = (UINT)wParam;
5582 nmkey.uFlags = HIWORD(lParam);
5584 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5585 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5587 switch ((UINT)wParam)
5589 case VK_LEFT:
5590 case VK_UP:
5591 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5592 break;
5593 case VK_RIGHT:
5594 case VK_DOWN:
5595 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5596 break;
5597 case VK_SPACE:
5598 case VK_RETURN:
5599 if ((infoPtr->nHotItem >= 0) &&
5600 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5602 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5603 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5604 (LPARAM)hwnd);
5606 break;
5609 return 0;
5613 static LRESULT
5614 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5616 POINT pt;
5617 INT nHit;
5619 pt.x = (short)LOWORD(lParam);
5620 pt.y = (short)HIWORD(lParam);
5621 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5623 if (nHit >= 0)
5624 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5625 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5626 TOOLBAR_Customize (hwnd);
5628 return 0;
5632 static LRESULT
5633 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5635 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5636 TBUTTON_INFO *btnPtr;
5637 POINT pt;
5638 INT nHit;
5639 NMTOOLBARA nmtb;
5640 NMMOUSE nmmouse;
5641 BOOL bDragKeyPressed;
5643 TRACE("\n");
5645 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5646 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5647 else
5648 bDragKeyPressed = (wParam & MK_SHIFT);
5650 if (infoPtr->hwndToolTip)
5651 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5652 WM_LBUTTONDOWN, wParam, lParam);
5654 pt.x = (short)LOWORD(lParam);
5655 pt.y = (short)HIWORD(lParam);
5656 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5658 btnPtr = &infoPtr->buttons[nHit];
5660 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5662 infoPtr->nButtonDrag = nHit;
5663 SetCapture (hwnd);
5665 /* If drag cursor has not been loaded, load it.
5666 * Note: it doesn't need to be freed */
5667 if (!hCursorDrag)
5668 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5669 SetCursor(hCursorDrag);
5671 else if (nHit >= 0)
5673 RECT arrowRect;
5674 infoPtr->nOldHit = nHit;
5676 CopyRect(&arrowRect, &btnPtr->rect);
5677 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5679 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5680 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5681 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5682 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5683 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5684 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5686 LRESULT res;
5688 /* draw in pressed state */
5689 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5690 btnPtr->fsState |= TBSTATE_PRESSED;
5691 else
5692 btnPtr->bDropDownPressed = TRUE;
5693 RedrawWindow(hwnd,&btnPtr->rect,0,
5694 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5696 memset(&nmtb, 0, sizeof(nmtb));
5697 nmtb.iItem = btnPtr->idCommand;
5698 nmtb.rcButton = btnPtr->rect;
5699 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5700 TBN_DROPDOWN);
5701 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5703 if (res != TBDDRET_TREATPRESSED)
5705 MSG msg;
5707 /* redraw button in unpressed state */
5708 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5709 btnPtr->fsState &= ~TBSTATE_PRESSED;
5710 else
5711 btnPtr->bDropDownPressed = FALSE;
5712 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5714 /* find and set hot item
5715 * NOTE: native doesn't do this, but that is a bug */
5716 GetCursorPos(&pt);
5717 ScreenToClient(hwnd, &pt);
5718 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5719 if (!infoPtr->bAnchor || (nHit >= 0))
5720 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5722 /* remove any left mouse button down or double-click messages
5723 * so that we can get a toggle effect on the button */
5724 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5725 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5728 return 0;
5730 /* otherwise drop through and process as pushed */
5732 infoPtr->bCaptured = TRUE;
5733 infoPtr->nButtonDown = nHit;
5734 infoPtr->bDragOutSent = FALSE;
5736 btnPtr->fsState |= TBSTATE_PRESSED;
5738 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5740 if (btnPtr->fsState & TBSTATE_ENABLED)
5741 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5742 UpdateWindow(hwnd);
5743 SetCapture (hwnd);
5746 if (nHit >=0)
5748 memset(&nmtb, 0, sizeof(nmtb));
5749 nmtb.iItem = btnPtr->idCommand;
5750 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5753 nmmouse.dwHitInfo = nHit;
5755 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5756 if (nHit < 0)
5757 nmmouse.dwItemSpec = -1;
5758 else
5760 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5761 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5764 ClientToScreen(hwnd, &pt);
5765 nmmouse.pt = pt;
5767 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5768 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5770 return 0;
5773 static LRESULT
5774 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5776 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5777 TBUTTON_INFO *btnPtr;
5778 POINT pt;
5779 INT nHit;
5780 INT nOldIndex = -1;
5781 BOOL bSendMessage = TRUE;
5782 NMHDR hdr;
5783 NMMOUSE nmmouse;
5784 NMTOOLBARA nmtb;
5786 if (infoPtr->hwndToolTip)
5787 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5788 WM_LBUTTONUP, wParam, lParam);
5790 pt.x = (short)LOWORD(lParam);
5791 pt.y = (short)HIWORD(lParam);
5792 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5794 if (!infoPtr->bAnchor || (nHit >= 0))
5795 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5797 if (infoPtr->nButtonDrag >= 0) {
5798 RECT rcClient;
5799 NMHDR hdr;
5801 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5802 ReleaseCapture();
5803 /* reset cursor */
5804 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5806 GetClientRect(hwnd, &rcClient);
5807 if (PtInRect(&rcClient, pt))
5809 INT nButton = -1;
5810 if (nHit >= 0)
5811 nButton = nHit;
5812 else if (nHit < -1)
5813 nButton = -nHit;
5814 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5815 nButton = -nHit;
5817 if (nButton == infoPtr->nButtonDrag)
5819 /* if the button is moved sightly left and we have a
5820 * separator there then remove it */
5821 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5823 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5824 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5826 else /* else insert a separator before the dragged button */
5828 TBBUTTON tbb;
5829 memset(&tbb, 0, sizeof(tbb));
5830 tbb.fsStyle = BTNS_SEP;
5831 tbb.iString = -1;
5832 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5835 else
5837 if (nButton == -1)
5839 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5840 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5841 else
5842 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5844 else
5845 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5848 else
5850 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5851 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5854 /* button under cursor changed so need to re-set hot item */
5855 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5856 infoPtr->nButtonDrag = -1;
5858 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5860 else if (infoPtr->nButtonDown >= 0) {
5861 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5862 btnPtr->fsState &= ~TBSTATE_PRESSED;
5864 if (btnPtr->fsStyle & BTNS_CHECK) {
5865 if (btnPtr->fsStyle & BTNS_GROUP) {
5866 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5867 nHit);
5868 if (nOldIndex == nHit)
5869 bSendMessage = FALSE;
5870 if ((nOldIndex != nHit) &&
5871 (nOldIndex != -1))
5872 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5873 btnPtr->fsState |= TBSTATE_CHECKED;
5875 else {
5876 if (btnPtr->fsState & TBSTATE_CHECKED)
5877 btnPtr->fsState &= ~TBSTATE_CHECKED;
5878 else
5879 btnPtr->fsState |= TBSTATE_CHECKED;
5883 if (nOldIndex != -1)
5884 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5887 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5888 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5889 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5891 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5892 ReleaseCapture ();
5893 infoPtr->nButtonDown = -1;
5895 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5896 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5897 NM_RELEASEDCAPTURE);
5899 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5900 * TBN_BEGINDRAG
5902 memset(&nmtb, 0, sizeof(nmtb));
5903 nmtb.iItem = btnPtr->idCommand;
5904 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5905 TBN_ENDDRAG);
5907 if (btnPtr->fsState & TBSTATE_ENABLED)
5909 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5910 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5912 /* In case we have just been destroyed... */
5913 if(!IsWindow(hwnd))
5914 return 0;
5918 /* !!! Undocumented - toolbar at 4.71 level and above sends
5919 * NM_CLICK with the NMMOUSE structure. */
5920 nmmouse.dwHitInfo = nHit;
5922 if (nHit < 0)
5923 nmmouse.dwItemSpec = -1;
5924 else
5926 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5927 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5930 ClientToScreen(hwnd, &pt);
5931 nmmouse.pt = pt;
5933 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5934 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5936 return 0;
5939 static LRESULT
5940 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5942 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5943 INT nHit;
5944 NMMOUSE nmmouse;
5945 POINT pt;
5947 pt.x = (short)LOWORD(lParam);
5948 pt.y = (short)HIWORD(lParam);
5950 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5951 nmmouse.dwHitInfo = nHit;
5953 if (nHit < 0) {
5954 nmmouse.dwItemSpec = -1;
5955 } else {
5956 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5957 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5960 ClientToScreen(hwnd, &pt);
5961 nmmouse.pt = pt;
5963 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5964 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5966 return 0;
5969 static LRESULT
5970 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5972 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5973 NMHDR nmhdr;
5975 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5976 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5978 return 0;
5981 static LRESULT
5982 TOOLBAR_CaptureChanged(HWND hwnd)
5984 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5985 TBUTTON_INFO *btnPtr;
5987 infoPtr->bCaptured = FALSE;
5989 if (infoPtr->nButtonDown >= 0)
5991 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5992 btnPtr->fsState &= ~TBSTATE_PRESSED;
5994 infoPtr->nOldHit = -1;
5996 if (btnPtr->fsState & TBSTATE_ENABLED)
5997 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5999 return 0;
6002 static LRESULT
6003 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6005 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6007 /* don't remove hot effects when in anchor highlighting mode or when a
6008 * drop-down button is pressed */
6009 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
6011 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
6012 if (!hotBtnPtr->bDropDownPressed)
6013 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6016 if (infoPtr->nOldHit < 0)
6017 return TRUE;
6019 /* If the last button we were over is depressed then make it not */
6020 /* depressed and redraw it */
6021 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6023 TBUTTON_INFO *btnPtr;
6024 RECT rc1;
6026 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6028 btnPtr->fsState &= ~TBSTATE_PRESSED;
6030 rc1 = btnPtr->rect;
6031 InflateRect (&rc1, 1, 1);
6032 InvalidateRect (hwnd, &rc1, TRUE);
6035 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6037 NMTOOLBARW nmt;
6038 ZeroMemory(&nmt, sizeof(nmt));
6039 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6040 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6041 infoPtr->bDragOutSent = TRUE;
6044 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6046 return TRUE;
6049 static LRESULT
6050 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6052 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6053 POINT pt;
6054 TRACKMOUSEEVENT trackinfo;
6055 INT nHit;
6056 TBUTTON_INFO *btnPtr;
6058 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6059 TOOLBAR_TooltipCreateControl(infoPtr);
6061 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6062 /* fill in the TRACKMOUSEEVENT struct */
6063 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6064 trackinfo.dwFlags = TME_QUERY;
6066 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6067 _TrackMouseEvent(&trackinfo);
6069 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6070 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6071 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6072 trackinfo.hwndTrack = hwnd;
6074 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6075 /* and can properly deactivate the hot toolbar button */
6076 _TrackMouseEvent(&trackinfo);
6080 if (infoPtr->hwndToolTip)
6081 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6082 WM_MOUSEMOVE, wParam, lParam);
6084 pt.x = (short)LOWORD(lParam);
6085 pt.y = (short)HIWORD(lParam);
6087 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6089 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6090 && (!infoPtr->bAnchor || (nHit >= 0)))
6091 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6093 if (infoPtr->nOldHit != nHit)
6095 if (infoPtr->bCaptured)
6097 if (!infoPtr->bDragOutSent)
6099 NMTOOLBARW nmt;
6100 ZeroMemory(&nmt, sizeof(nmt));
6101 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6102 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6103 infoPtr->bDragOutSent = TRUE;
6106 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6107 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6108 btnPtr->fsState &= ~TBSTATE_PRESSED;
6109 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6111 else if (nHit == infoPtr->nButtonDown) {
6112 btnPtr->fsState |= TBSTATE_PRESSED;
6113 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6115 infoPtr->nOldHit = nHit;
6119 return 0;
6123 static inline LRESULT
6124 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6126 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6127 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6128 /* else */
6129 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6133 static inline LRESULT
6134 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6136 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6137 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6139 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6143 static LRESULT
6144 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6146 TOOLBAR_INFO *infoPtr;
6147 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6148 DWORD styleadd = 0;
6150 /* allocate memory for info structure */
6151 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6152 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6154 /* paranoid!! */
6155 infoPtr->dwStructSize = sizeof(TBBUTTON);
6156 infoPtr->nRows = 1;
6157 infoPtr->nWidth = 0;
6159 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6160 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6161 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6162 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6165 /* native control does:
6166 * Get a lot of colors and brushes
6167 * WM_NOTIFYFORMAT
6168 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6169 * CreateFontIndirectW(adr1)
6170 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6171 * hdc = GetDC(toolbar)
6172 * GetSystemMetrics(0x48)
6173 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6174 * 0, 0, 0, 0, "MARLETT")
6175 * oldfnt = SelectObject(hdc, fnt2)
6176 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6177 * GetTextMetricsW(hdc, adr3)
6178 * SelectObject(hdc, oldfnt)
6179 * DeleteObject(fnt2)
6180 * ReleaseDC(hdc)
6181 * InvalidateRect(toolbar, 0, 1)
6182 * SetWindowLongW(toolbar, 0, addr)
6183 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6184 * WM_STYLECHANGING
6185 * CallWinEx old new
6186 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6187 * ie 2 0x4600094c 0x4600094c 0x4600894d
6188 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6189 * rebar 0x50008844 0x40008844 0x50008845
6190 * pager 0x50000844 0x40000844 0x50008845
6191 * IC35mgr 0x5400084e **nochange**
6192 * on entry to _NCCREATE 0x5400084e
6193 * rowlist 0x5400004e **nochange**
6194 * on entry to _NCCREATE 0x5400004e
6198 /* I think the code below is a bug, but it is the way that the native
6199 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6200 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6201 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6202 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6203 * Somehow, the only cases of this seem to be MFC programs.
6205 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6206 * does not occur in the WM_STYLECHANGING routine.
6207 * (Guy Albertelli 9/2001)
6210 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6211 && !(cs->style & TBSTYLE_TRANSPARENT))
6212 styleadd |= TBSTYLE_TRANSPARENT;
6213 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6214 styleadd |= CCS_TOP; /* default to top */
6215 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6218 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6222 static LRESULT
6223 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6225 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6226 RECT rcWindow;
6227 HDC hdc;
6229 if (dwStyle & WS_MINIMIZE)
6230 return 0; /* Nothing to do */
6232 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6234 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6235 return 0;
6237 if (!(dwStyle & CCS_NODIVIDER))
6239 GetWindowRect (hwnd, &rcWindow);
6240 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6241 if( dwStyle & WS_BORDER )
6242 OffsetRect (&rcWindow, 1, 1);
6243 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6246 ReleaseDC( hwnd, hdc );
6248 return 0;
6252 /* handles requests from the tooltip control on what text to display */
6253 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6255 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6257 TRACE("button index = %d\n", index);
6259 Free (infoPtr->pszTooltipText);
6260 infoPtr->pszTooltipText = NULL;
6262 if (index < 0)
6263 return 0;
6265 if (infoPtr->bUnicode)
6267 WCHAR wszBuffer[INFOTIPSIZE+1];
6268 NMTBGETINFOTIPW tbgit;
6269 unsigned int len; /* in chars */
6271 wszBuffer[0] = '\0';
6272 wszBuffer[INFOTIPSIZE] = '\0';
6274 tbgit.pszText = wszBuffer;
6275 tbgit.cchTextMax = INFOTIPSIZE;
6276 tbgit.iItem = lpnmtdi->hdr.idFrom;
6277 tbgit.lParam = infoPtr->buttons[index].dwData;
6279 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6281 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6283 len = strlenW(tbgit.pszText);
6284 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6286 /* need to allocate temporary buffer in infoPtr as there
6287 * isn't enough space in buffer passed to us by the
6288 * tooltip control */
6289 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6290 if (infoPtr->pszTooltipText)
6292 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6293 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6294 return 0;
6297 else if (len > 0)
6299 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6300 return 0;
6303 else
6305 CHAR szBuffer[INFOTIPSIZE+1];
6306 NMTBGETINFOTIPA tbgit;
6307 unsigned int len; /* in chars */
6309 szBuffer[0] = '\0';
6310 szBuffer[INFOTIPSIZE] = '\0';
6312 tbgit.pszText = szBuffer;
6313 tbgit.cchTextMax = INFOTIPSIZE;
6314 tbgit.iItem = lpnmtdi->hdr.idFrom;
6315 tbgit.lParam = infoPtr->buttons[index].dwData;
6317 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6319 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6321 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6322 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6324 /* need to allocate temporary buffer in infoPtr as there
6325 * isn't enough space in buffer passed to us by the
6326 * tooltip control */
6327 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6328 if (infoPtr->pszTooltipText)
6330 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6331 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6332 return 0;
6335 else if (len > 0)
6337 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6338 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6339 return 0;
6343 /* if button has text, but it is not shown then automatically
6344 * use that text as tooltip */
6345 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6346 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6348 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6349 unsigned int len = pszText ? strlenW(pszText) : 0;
6351 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6353 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6355 /* need to allocate temporary buffer in infoPtr as there
6356 * isn't enough space in buffer passed to us by the
6357 * tooltip control */
6358 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6359 if (infoPtr->pszTooltipText)
6361 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6362 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6363 return 0;
6366 else if (len > 0)
6368 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6369 return 0;
6373 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6375 /* last resort: send notification on to app */
6376 /* FIXME: find out what is really used here */
6377 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, (WPARAM)lpnmtdi->hdr.idFrom, (LPARAM)lpnmtdi);
6381 static inline LRESULT
6382 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6384 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6385 LPNMHDR lpnmh = (LPNMHDR)lParam;
6387 switch (lpnmh->code)
6389 case PGN_CALCSIZE:
6391 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6393 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6394 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6395 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6396 lppgc->iWidth);
6398 else {
6399 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6400 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6401 lppgc->iHeight);
6403 return 0;
6406 case PGN_SCROLL:
6408 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6410 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6411 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6412 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6413 lppgs->iScroll, lppgs->iDir);
6414 return 0;
6417 case TTN_GETDISPINFOW:
6418 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6420 case TTN_GETDISPINFOA:
6421 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6422 return 0;
6424 default:
6425 return 0;
6430 static LRESULT
6431 TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6433 LRESULT format;
6435 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam, lParam);
6437 if (lParam == NF_QUERY)
6438 return NFR_UNICODE;
6440 if (lParam == NF_REQUERY) {
6441 format = SendMessageW(infoPtr->hwndNotify,
6442 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6443 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6444 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6445 format);
6446 format = NFR_ANSI;
6448 return format;
6450 return 0;
6454 static LRESULT
6455 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6457 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6458 HDC hdc;
6459 PAINTSTRUCT ps;
6461 /* fill ps.rcPaint with a default rect */
6462 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6464 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6466 TRACE("psrect=(%d,%d)-(%d,%d)\n",
6467 ps.rcPaint.left, ps.rcPaint.top,
6468 ps.rcPaint.right, ps.rcPaint.bottom);
6470 TOOLBAR_Refresh (hwnd, hdc, &ps);
6471 if (!wParam) EndPaint (hwnd, &ps);
6473 return 0;
6477 static LRESULT
6478 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6480 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6482 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6484 /* make first item hot */
6485 if (infoPtr->nNumButtons > 0)
6486 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6488 return 0;
6491 static LRESULT
6492 TOOLBAR_SetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
6494 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6496 TRACE("font=%p redraw=%ld\n", (HFONT)wParam, lParam);
6498 if (wParam == 0)
6499 infoPtr->hFont = infoPtr->hDefaultFont;
6500 else
6501 infoPtr->hFont = (HFONT)wParam;
6503 TOOLBAR_CalcToolbar(hwnd);
6505 if (lParam)
6506 InvalidateRect(hwnd, NULL, TRUE);
6507 return 1;
6510 static LRESULT
6511 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6512 /*****************************************************
6514 * Function;
6515 * Handles the WM_SETREDRAW message.
6517 * Documentation:
6518 * According to testing V4.71 of COMCTL32 returns the
6519 * *previous* status of the redraw flag (either 0 or 1)
6520 * instead of the MSDN documented value of 0 if handled.
6521 * (For laughs see the "consistency" with same function
6522 * in rebar.)
6524 *****************************************************/
6526 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6527 BOOL oldredraw = infoPtr->bDoRedraw;
6529 TRACE("set to %s\n",
6530 (wParam) ? "TRUE" : "FALSE");
6531 infoPtr->bDoRedraw = (BOOL) wParam;
6532 if (wParam) {
6533 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6535 return (oldredraw) ? 1 : 0;
6539 static LRESULT
6540 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6542 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6544 TRACE("sizing toolbar!\n");
6546 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6548 RECT delta_width, delta_height, client, dummy;
6549 DWORD min_x, max_x, min_y, max_y;
6550 TBUTTON_INFO *btnPtr;
6551 INT i;
6553 GetClientRect(hwnd, &client);
6554 if(client.right > infoPtr->client_rect.right)
6556 min_x = infoPtr->client_rect.right;
6557 max_x = client.right;
6559 else
6561 max_x = infoPtr->client_rect.right;
6562 min_x = client.right;
6564 if(client.bottom > infoPtr->client_rect.bottom)
6566 min_y = infoPtr->client_rect.bottom;
6567 max_y = client.bottom;
6569 else
6571 max_y = infoPtr->client_rect.bottom;
6572 min_y = client.bottom;
6575 SetRect(&delta_width, min_x, 0, max_x, min_y);
6576 SetRect(&delta_height, 0, min_y, max_x, max_y);
6578 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6579 btnPtr = infoPtr->buttons;
6580 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6581 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6582 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6583 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6585 GetClientRect(hwnd, &infoPtr->client_rect);
6586 TOOLBAR_AutoSize(hwnd);
6587 return 0;
6591 static LRESULT
6592 TOOLBAR_StyleChanged (HWND hwnd, INT nType, const STYLESTRUCT *lpStyle)
6594 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6596 if (nType == GWL_STYLE)
6598 DWORD dwOldStyle = infoPtr->dwStyle;
6600 if (lpStyle->styleNew & TBSTYLE_LIST)
6601 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6602 else
6603 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6605 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6607 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6609 infoPtr->dwStyle = lpStyle->styleNew;
6611 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6612 TOOLBAR_LayoutToolbar(hwnd);
6614 /* only resize if one of the CCS_* styles was changed */
6615 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6617 TOOLBAR_AutoSize (hwnd);
6619 InvalidateRect(hwnd, NULL, TRUE);
6623 return 0;
6627 static LRESULT
6628 TOOLBAR_SysColorChange (HWND hwnd)
6630 COMCTL32_RefreshSysColors();
6632 return 0;
6636 /* update theme after a WM_THEMECHANGED message */
6637 static LRESULT theme_changed (HWND hwnd)
6639 HTHEME theme = GetWindowTheme (hwnd);
6640 CloseThemeData (theme);
6641 OpenThemeData (hwnd, themeClass);
6642 return 0;
6646 static LRESULT WINAPI
6647 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6649 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6651 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6652 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6654 if (!infoPtr && (uMsg != WM_NCCREATE))
6655 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6657 switch (uMsg)
6659 case TB_ADDBITMAP:
6660 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6662 case TB_ADDBUTTONSA:
6663 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6665 case TB_ADDBUTTONSW:
6666 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6668 case TB_ADDSTRINGA:
6669 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6671 case TB_ADDSTRINGW:
6672 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6674 case TB_AUTOSIZE:
6675 return TOOLBAR_AutoSize (hwnd);
6677 case TB_BUTTONCOUNT:
6678 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6680 case TB_BUTTONSTRUCTSIZE:
6681 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6683 case TB_CHANGEBITMAP:
6684 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6686 case TB_CHECKBUTTON:
6687 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6689 case TB_COMMANDTOINDEX:
6690 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6692 case TB_CUSTOMIZE:
6693 return TOOLBAR_Customize (hwnd);
6695 case TB_DELETEBUTTON:
6696 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6698 case TB_ENABLEBUTTON:
6699 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6701 case TB_GETANCHORHIGHLIGHT:
6702 return TOOLBAR_GetAnchorHighlight (hwnd);
6704 case TB_GETBITMAP:
6705 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6707 case TB_GETBITMAPFLAGS:
6708 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6710 case TB_GETBUTTON:
6711 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6713 case TB_GETBUTTONINFOA:
6714 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, FALSE);
6716 case TB_GETBUTTONINFOW:
6717 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, TRUE);
6719 case TB_GETBUTTONSIZE:
6720 return TOOLBAR_GetButtonSize (hwnd);
6722 case TB_GETBUTTONTEXTA:
6723 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6725 case TB_GETBUTTONTEXTW:
6726 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6728 case TB_GETDISABLEDIMAGELIST:
6729 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6731 case TB_GETEXTENDEDSTYLE:
6732 return TOOLBAR_GetExtendedStyle (hwnd);
6734 case TB_GETHOTIMAGELIST:
6735 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6737 case TB_GETHOTITEM:
6738 return TOOLBAR_GetHotItem (hwnd);
6740 case TB_GETIMAGELIST:
6741 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6743 case TB_GETINSERTMARK:
6744 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6746 case TB_GETINSERTMARKCOLOR:
6747 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6749 case TB_GETITEMRECT:
6750 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6752 case TB_GETMAXSIZE:
6753 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6755 /* case TB_GETOBJECT: */ /* 4.71 */
6757 case TB_GETPADDING:
6758 return TOOLBAR_GetPadding (hwnd);
6760 case TB_GETRECT:
6761 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6763 case TB_GETROWS:
6764 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6766 case TB_GETSTATE:
6767 return TOOLBAR_GetState (hwnd, wParam, lParam);
6769 case TB_GETSTRINGA:
6770 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6772 case TB_GETSTRINGW:
6773 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6775 case TB_GETSTYLE:
6776 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6778 case TB_GETTEXTROWS:
6779 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6781 case TB_GETTOOLTIPS:
6782 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6784 case TB_GETUNICODEFORMAT:
6785 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6787 case TB_HIDEBUTTON:
6788 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6790 case TB_HITTEST:
6791 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6793 case TB_INDETERMINATE:
6794 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6796 case TB_INSERTBUTTONA:
6797 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6799 case TB_INSERTBUTTONW:
6800 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6802 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6804 case TB_ISBUTTONCHECKED:
6805 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6807 case TB_ISBUTTONENABLED:
6808 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6810 case TB_ISBUTTONHIDDEN:
6811 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6813 case TB_ISBUTTONHIGHLIGHTED:
6814 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6816 case TB_ISBUTTONINDETERMINATE:
6817 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6819 case TB_ISBUTTONPRESSED:
6820 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6822 case TB_LOADIMAGES:
6823 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6825 case TB_MAPACCELERATORA:
6826 case TB_MAPACCELERATORW:
6827 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6829 case TB_MARKBUTTON:
6830 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6832 case TB_MOVEBUTTON:
6833 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6835 case TB_PRESSBUTTON:
6836 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6838 case TB_REPLACEBITMAP:
6839 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6841 case TB_SAVERESTOREA:
6842 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6844 case TB_SAVERESTOREW:
6845 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6847 case TB_SETANCHORHIGHLIGHT:
6848 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6850 case TB_SETBITMAPSIZE:
6851 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6853 case TB_SETBUTTONINFOA:
6854 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6856 case TB_SETBUTTONINFOW:
6857 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6859 case TB_SETBUTTONSIZE:
6860 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6862 case TB_SETBUTTONWIDTH:
6863 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6865 case TB_SETCMDID:
6866 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6868 case TB_SETDISABLEDIMAGELIST:
6869 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6871 case TB_SETDRAWTEXTFLAGS:
6872 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6874 case TB_SETEXTENDEDSTYLE:
6875 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6877 case TB_SETHOTIMAGELIST:
6878 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6880 case TB_SETHOTITEM:
6881 return TOOLBAR_SetHotItem (hwnd, wParam);
6883 case TB_SETIMAGELIST:
6884 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6886 case TB_SETINDENT:
6887 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6889 case TB_SETINSERTMARK:
6890 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6892 case TB_SETINSERTMARKCOLOR:
6893 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6895 case TB_SETMAXTEXTROWS:
6896 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6898 case TB_SETPADDING:
6899 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6901 case TB_SETPARENT:
6902 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6904 case TB_SETROWS:
6905 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6907 case TB_SETSTATE:
6908 return TOOLBAR_SetState (hwnd, wParam, lParam);
6910 case TB_SETSTYLE:
6911 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6913 case TB_SETTOOLTIPS:
6914 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6916 case TB_SETUNICODEFORMAT:
6917 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6919 case TB_UNKWN45D:
6920 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6922 case TB_UNKWN45E:
6923 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6925 case TB_UNKWN460:
6926 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6928 case TB_UNKWN462:
6929 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6931 case TB_UNKWN463:
6932 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6934 case TB_UNKWN464:
6935 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6937 /* Common Control Messages */
6939 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6940 case CCM_GETCOLORSCHEME:
6941 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6943 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6944 case CCM_SETCOLORSCHEME:
6945 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6947 case CCM_GETVERSION:
6948 return TOOLBAR_GetVersion (hwnd);
6950 case CCM_SETVERSION:
6951 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6954 /* case WM_CHAR: */
6956 case WM_CREATE:
6957 return TOOLBAR_Create (hwnd, wParam, lParam);
6959 case WM_DESTROY:
6960 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6962 case WM_ERASEBKGND:
6963 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6965 case WM_GETFONT:
6966 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6968 case WM_KEYDOWN:
6969 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6971 /* case WM_KILLFOCUS: */
6973 case WM_LBUTTONDBLCLK:
6974 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6976 case WM_LBUTTONDOWN:
6977 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6979 case WM_LBUTTONUP:
6980 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6982 case WM_RBUTTONUP:
6983 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6985 case WM_RBUTTONDBLCLK:
6986 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6988 case WM_MOUSEMOVE:
6989 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6991 case WM_MOUSELEAVE:
6992 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6994 case WM_CAPTURECHANGED:
6995 return TOOLBAR_CaptureChanged(hwnd);
6997 case WM_NCACTIVATE:
6998 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7000 case WM_NCCALCSIZE:
7001 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7003 case WM_NCCREATE:
7004 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7006 case WM_NCPAINT:
7007 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7009 case WM_NOTIFY:
7010 return TOOLBAR_Notify (hwnd, wParam, lParam);
7012 case WM_NOTIFYFORMAT:
7013 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7015 case WM_PRINTCLIENT:
7016 case WM_PAINT:
7017 return TOOLBAR_Paint (hwnd, wParam);
7019 case WM_SETFOCUS:
7020 return TOOLBAR_SetFocus (hwnd, wParam);
7022 case WM_SETFONT:
7023 return TOOLBAR_SetFont(hwnd, wParam, lParam);
7025 case WM_SETREDRAW:
7026 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7028 case WM_SIZE:
7029 return TOOLBAR_Size (hwnd, wParam, lParam);
7031 case WM_STYLECHANGED:
7032 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7034 case WM_SYSCOLORCHANGE:
7035 return TOOLBAR_SysColorChange (hwnd);
7037 case WM_THEMECHANGED:
7038 return theme_changed (hwnd);
7040 /* case WM_WININICHANGE: */
7042 case WM_CHARTOITEM:
7043 case WM_COMMAND:
7044 case WM_DRAWITEM:
7045 case WM_MEASUREITEM:
7046 case WM_VKEYTOITEM:
7047 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7049 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7050 case PGM_FORWARDMOUSE:
7051 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7053 default:
7054 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7055 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
7056 uMsg, wParam, lParam);
7057 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7062 VOID
7063 TOOLBAR_Register (void)
7065 WNDCLASSW wndClass;
7067 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7068 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7069 wndClass.lpfnWndProc = ToolbarWindowProc;
7070 wndClass.cbClsExtra = 0;
7071 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7072 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7073 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7074 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7076 RegisterClassW (&wndClass);
7080 VOID
7081 TOOLBAR_Unregister (void)
7083 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7086 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7088 HIMAGELIST himlold;
7089 PIMLENTRY c = NULL;
7091 /* Check if the entry already exists */
7092 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7094 /* If this is a new entry we must create it and insert into the array */
7095 if (!c)
7097 PIMLENTRY *pnies;
7099 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7100 c->id = id;
7102 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7103 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7104 pnies[*cies] = c;
7105 (*cies)++;
7107 Free(*pies);
7108 *pies = pnies;
7111 himlold = c->himl;
7112 c->himl = himl;
7114 return himlold;
7118 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7120 int i;
7122 for (i = 0; i < *cies; i++)
7123 Free((*pies)[i]);
7125 Free(*pies);
7127 *cies = 0;
7128 *pies = NULL;
7132 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id)
7134 PIMLENTRY c = NULL;
7136 if (pies != NULL)
7138 int i;
7140 for (i = 0; i < cies; i++)
7142 if (pies[i]->id == id)
7144 c = pies[i];
7145 break;
7150 return c;
7154 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id)
7156 HIMAGELIST himlDef = 0;
7157 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7159 if (pie)
7160 himlDef = pie->himl;
7162 return himlDef;
7166 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7168 if (infoPtr->bUnicode)
7169 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7170 else
7172 CHAR Buffer[256];
7173 NMTOOLBARA nmtba;
7174 BOOL bRet = FALSE;
7176 nmtba.iItem = nmtb->iItem;
7177 nmtba.pszText = Buffer;
7178 nmtba.cchText = 256;
7179 ZeroMemory(nmtba.pszText, nmtba.cchText);
7181 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7183 int ccht = strlen(nmtba.pszText);
7184 if (ccht)
7185 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7186 nmtb->pszText, nmtb->cchText);
7188 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7189 bRet = TRUE;
7192 return bRet;
7197 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo)
7199 NMTOOLBARW nmtb;
7201 /* MSDN states that iItem is the index of the button, rather than the
7202 * command ID as used by every other NMTOOLBAR notification */
7203 nmtb.iItem = iItem;
7204 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7206 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);