regedit: Fix the English (Neutral) menu.
[wine/multimedia.git] / dlls / comctl32 / toolbar.c
blobfe26ac1b3786aebb9872d620d0792ed63af303fd
1 /*
2 * Toolbar control
4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * NOTES
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
31 * TODO:
32 * - Styles:
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
35 * - Messages:
36 * - TB_GETMETRICS
37 * - TB_GETOBJECT
38 * - TB_INSERTMARKHITTEST
39 * - TB_SAVERESTORE
40 * - TB_SETMETRICS
41 * - WM_WININICHANGE
42 * - Notifications:
43 * - NM_CHAR
44 * - TBN_GETOBJECT
45 * - TBN_SAVE
46 * - Button wrapping (under construction).
47 * - Fix TB_SETROWS.
48 * - iListGap custom draw support.
50 * Testing:
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
71 #include <stdarg.h>
72 #include <string.h>
74 #include "windef.h"
75 #include "winbase.h"
76 #include "winreg.h"
77 #include "wingdi.h"
78 #include "winuser.h"
79 #include "wine/unicode.h"
80 #include "winnls.h"
81 #include "commctrl.h"
82 #include "comctl32.h"
83 #include "uxtheme.h"
84 #include "tmschema.h"
85 #include "wine/debug.h"
87 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
89 static HCURSOR hCursorDrag = NULL;
91 typedef struct
93 INT iBitmap;
94 INT idCommand;
95 BYTE fsState;
96 BYTE fsStyle;
97 BYTE bHot;
98 BYTE bDropDownPressed;
99 DWORD 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 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
143 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
144 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
145 SIZE szPadding; /* padding values around button */
146 INT iListGap; /* default gap between text and image for toolbar with list style */
147 HFONT hDefaultFont;
148 HFONT hFont; /* text font */
149 HIMAGELIST himlInt; /* image list created internally */
150 PIMLENTRY *himlDef; /* default image list array */
151 INT cimlDef; /* default image list array count */
152 PIMLENTRY *himlHot; /* hot image list array */
153 INT cimlHot; /* hot image list array count */
154 PIMLENTRY *himlDis; /* disabled image list array */
155 INT cimlDis; /* disabled image list array count */
156 HWND hwndToolTip; /* handle to tool tip control */
157 HWND hwndNotify; /* handle to the window that gets notifications */
158 HWND hwndSelf; /* my own handle */
159 BOOL bAnchor; /* anchor highlight enabled */
160 BOOL bDoRedraw; /* Redraw status */
161 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
162 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
163 BOOL bCaptured; /* mouse captured? */
164 DWORD dwStyle; /* regular toolbar style */
165 DWORD dwExStyle; /* extended toolbar style */
166 DWORD dwDTFlags; /* DrawText flags */
168 COLORREF clrInsertMark; /* insert mark color */
169 COLORREF clrBtnHighlight; /* color for Flat Separator */
170 COLORREF clrBtnShadow; /* color for Flag Separator */
171 INT iVersion;
172 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
173 * for TTN_GETDISPINFOW notification */
174 TBINSERTMARK tbim; /* info on insertion mark */
175 TBUTTON_INFO *buttons; /* pointer to button array */
176 LPWSTR *strings; /* pointer to string array */
177 TBITMAP_INFO *bitmaps;
178 } TOOLBAR_INFO, *PTOOLBAR_INFO;
181 /* used by customization dialog */
182 typedef struct
184 PTOOLBAR_INFO tbInfo;
185 HWND tbHwnd;
186 } CUSTDLG_INFO, *PCUSTDLG_INFO;
188 typedef struct
190 TBBUTTON btn;
191 BOOL bVirtual;
192 BOOL bRemovable;
193 WCHAR text[64];
194 } CUSTOMBUTTON, *PCUSTOMBUTTON;
196 typedef enum
198 IMAGE_LIST_DEFAULT,
199 IMAGE_LIST_HOT,
200 IMAGE_LIST_DISABLED
201 } IMAGE_LIST_TYPE;
203 #define SEPARATOR_WIDTH 8
204 #define TOP_BORDER 2
205 #define BOTTOM_BORDER 2
206 #define DDARROW_WIDTH 11
207 #define ARROW_HEIGHT 3
208 #define INSERTMARK_WIDTH 2
210 #define DEFPAD_CX 7
211 #define DEFPAD_CY 6
212 #define DEFLISTGAP 4
214 /* vertical padding used in list mode when image is present */
215 #define LISTPAD_CY 9
217 /* how wide to treat the bitmap if it isn't present */
218 #define NONLIST_NOTEXT_OFFSET 2
220 #define TOOLBAR_NOWHERE (-1)
222 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
223 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
224 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
226 /* Used to find undocumented extended styles */
227 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
228 TBSTYLE_EX_UNDOC1 | \
229 TBSTYLE_EX_MIXEDBUTTONS | \
230 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
232 /* all of the CCS_ styles */
233 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
234 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
236 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
237 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
238 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
239 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
240 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
242 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
244 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
245 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
246 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
247 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
248 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
249 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
250 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
251 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
252 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
253 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
255 static LRESULT
256 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
259 static LPWSTR
260 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
262 LPWSTR lpText = NULL;
264 /* NOTE: iString == -1 is undocumented */
265 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
266 lpText = (LPWSTR)btnPtr->iString;
267 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
268 lpText = infoPtr->strings[btnPtr->iString];
270 return lpText;
273 static void
274 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
276 if (TRACE_ON(toolbar)){
277 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
278 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
279 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
280 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
281 if (internal)
282 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
283 btn_num, bP->idCommand,
284 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
285 bP->rect.left, bP->rect.top,
286 bP->rect.right, bP->rect.bottom);
291 static void
292 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
294 if (TRACE_ON(toolbar)) {
295 INT i;
297 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
298 iP->hwndSelf, line,
299 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
300 iP->nNumStrings, iP->dwStyle);
301 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
302 iP->hwndSelf, line,
303 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
304 (iP->bDoRedraw) ? "TRUE" : "FALSE");
305 for(i=0; i<iP->nNumButtons; i++) {
306 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
312 /***********************************************************************
313 * TOOLBAR_CheckStyle
315 * This function validates that the styles set are implemented and
316 * issues FIXME's warning of possible problems. In a perfect world this
317 * function should be null.
319 static void
320 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
322 if (dwStyle & TBSTYLE_REGISTERDROP)
323 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
327 static INT
328 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
330 if(!IsWindow(infoPtr->hwndSelf))
331 return 0; /* we have just been destroyed */
333 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
334 nmhdr->hwndFrom = infoPtr->hwndSelf;
335 nmhdr->code = code;
337 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
338 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
340 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
341 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
344 /***********************************************************************
345 * TOOLBAR_GetBitmapIndex
347 * This function returns the bitmap index associated with a button.
348 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
349 * is issued to retrieve the index.
351 static INT
352 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
354 INT ret = btnPtr->iBitmap;
356 if (ret == I_IMAGECALLBACK)
358 /* issue TBN_GETDISPINFO */
359 NMTBDISPINFOA nmgd;
361 memset(&nmgd, 0, sizeof(nmgd));
362 nmgd.idCommand = btnPtr->idCommand;
363 nmgd.lParam = btnPtr->dwData;
364 nmgd.dwMask = TBNF_IMAGE;
365 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
366 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
367 if (nmgd.dwMask & TBNF_DI_SETITEM)
368 btnPtr->iBitmap = nmgd.iImage;
369 ret = nmgd.iImage;
370 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
371 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
374 if (ret != I_IMAGENONE)
375 ret = GETIBITMAP(infoPtr, ret);
377 return ret;
381 static BOOL
382 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
384 HIMAGELIST himl;
385 INT id = GETHIMLID(infoPtr, index);
386 INT iBitmap = GETIBITMAP(infoPtr, index);
388 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
389 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
390 (index == I_IMAGECALLBACK))
391 return TRUE;
392 else
393 return FALSE;
397 static inline BOOL
398 TOOLBAR_IsValidImageList(TOOLBAR_INFO *infoPtr, INT index)
400 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
401 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
405 /***********************************************************************
406 * TOOLBAR_GetImageListForDrawing
408 * This function validates the bitmap index (including I_IMAGECALLBACK
409 * functionality) and returns the corresponding image list.
411 static HIMAGELIST
412 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
414 HIMAGELIST himl;
416 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
417 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
418 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
419 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
420 return NULL;
423 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
424 if ((*index == I_IMAGECALLBACK) ||
425 (*index == I_IMAGENONE)) return NULL;
426 ERR("TBN_GETDISPINFO returned invalid index %d\n",
427 *index);
428 return NULL;
431 switch(imagelist)
433 case IMAGE_LIST_DEFAULT:
434 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
435 break;
436 case IMAGE_LIST_HOT:
437 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
438 break;
439 case IMAGE_LIST_DISABLED:
440 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
441 break;
442 default:
443 himl = NULL;
444 FIXME("Shouldn't reach here\n");
447 if (!himl)
448 TRACE("no image list\n");
450 return himl;
454 static void
455 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
457 RECT myrect;
458 COLORREF oldcolor, newcolor;
460 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
461 myrect.right = myrect.left + 1;
462 myrect.top = lpRect->top + 2;
463 myrect.bottom = lpRect->bottom - 2;
465 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
466 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
467 oldcolor = SetBkColor (hdc, newcolor);
468 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
470 myrect.left = myrect.right;
471 myrect.right = myrect.left + 1;
473 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
474 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
475 SetBkColor (hdc, newcolor);
476 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
478 SetBkColor (hdc, oldcolor);
482 /***********************************************************************
483 * TOOLBAR_DrawDDFlatSeparator
485 * This function draws the separator that was flagged as BTNS_DROPDOWN.
486 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
487 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
488 * are horizontal as opposed to the vertical separators for not dropdown
489 * type.
491 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
493 static void
494 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
496 RECT myrect;
497 COLORREF oldcolor, newcolor;
499 myrect.left = lpRect->left;
500 myrect.right = lpRect->right;
501 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
502 myrect.bottom = myrect.top + 1;
504 InflateRect (&myrect, -2, 0);
506 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
507 myrect.left, myrect.top, myrect.right, myrect.bottom);
509 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
510 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
511 oldcolor = SetBkColor (hdc, newcolor);
512 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
514 myrect.top = myrect.bottom;
515 myrect.bottom = myrect.top + 1;
517 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
518 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
519 SetBkColor (hdc, newcolor);
520 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
522 SetBkColor (hdc, oldcolor);
526 static void
527 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
529 INT x, y;
530 HPEN hPen, hOldPen;
532 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
533 hOldPen = SelectObject ( hdc, hPen );
534 x = left + 2;
535 y = top;
536 MoveToEx (hdc, x, y, NULL);
537 LineTo (hdc, x+5, y++); x++;
538 MoveToEx (hdc, x, y, NULL);
539 LineTo (hdc, x+3, y++); x++;
540 MoveToEx (hdc, x, y, NULL);
541 LineTo (hdc, x+1, y++);
542 SelectObject( hdc, hOldPen );
543 DeleteObject( hPen );
547 * Draw the text string for this button.
548 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
549 * is non-zero, so we can simply check himlDef to see if we have
550 * an image list
552 static void
553 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
554 NMTBCUSTOMDRAW *tbcd)
556 HDC hdc = tbcd->nmcd.hdc;
557 HFONT hOldFont = 0;
558 COLORREF clrOld = 0;
559 COLORREF clrOldBk = 0;
560 int oldBkMode = 0;
561 UINT state = tbcd->nmcd.uItemState;
563 /* draw text */
564 if (lpText) {
565 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
566 rcText->left, rcText->top, rcText->right, rcText->bottom);
568 hOldFont = SelectObject (hdc, infoPtr->hFont);
569 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
570 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
572 else if (state & CDIS_DISABLED) {
573 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
574 OffsetRect (rcText, 1, 1);
575 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
576 SetTextColor (hdc, comctl32_color.clr3dShadow);
577 OffsetRect (rcText, -1, -1);
579 else if (state & CDIS_INDETERMINATE) {
580 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
582 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
583 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
584 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
585 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
587 else {
588 clrOld = SetTextColor (hdc, tbcd->clrText);
591 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
592 SetTextColor (hdc, clrOld);
593 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
595 SetBkColor (hdc, clrOldBk);
596 SetBkMode (hdc, oldBkMode);
598 SelectObject (hdc, hOldFont);
603 static void
604 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
606 HDC hdc = tbcd->nmcd.hdc;
607 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
608 COLORREF clrTextOld;
609 COLORREF clrBkOld;
610 INT cx = lpRect->right - lpRect->left;
611 INT cy = lpRect->bottom - lpRect->top;
612 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
613 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
614 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
615 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
616 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
617 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
618 SetBkColor(hdc, clrBkOld);
619 SetTextColor(hdc, clrTextOld);
620 SelectObject (hdc, hbr);
624 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
626 INT cx, cy;
627 HBITMAP hbmMask, hbmImage;
628 HDC hdcMask, hdcImage;
630 ImageList_GetIconSize(himl, &cx, &cy);
632 /* Create src image */
633 hdcImage = CreateCompatibleDC(hdc);
634 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
635 SelectObject(hdcImage, hbmImage);
636 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
637 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
639 /* Create Mask */
640 hdcMask = CreateCompatibleDC(0);
641 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
642 SelectObject(hdcMask, hbmMask);
644 /* Remove the background and all white pixels */
645 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
646 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
647 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
648 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
650 /* draw the new mask 'etched' to hdc */
651 SetBkColor(hdc, RGB(255, 255, 255));
652 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
653 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
654 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
655 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
656 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
658 /* Cleanup */
659 DeleteObject(hbmImage);
660 DeleteDC(hdcImage);
661 DeleteObject (hbmMask);
662 DeleteDC(hdcMask);
666 static UINT
667 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
669 UINT retstate = 0;
671 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
672 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
673 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
674 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
675 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
676 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
677 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
678 return retstate;
681 /* draws the image on a toolbar button */
682 static void
683 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
685 HIMAGELIST himl = NULL;
686 BOOL draw_masked = FALSE;
687 INT index;
688 INT offset = 0;
689 UINT draw_flags = ILD_TRANSPARENT;
691 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
693 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
694 if (!himl)
696 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
697 draw_masked = TRUE;
700 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
701 ((tbcd->nmcd.uItemState & CDIS_HOT)
702 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
704 /* if hot, attempt to draw with hot image list, if fails,
705 use default image list */
706 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
707 if (!himl)
708 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
710 else
711 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
713 if (!himl)
714 return;
716 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
717 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
718 offset = 1;
720 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
721 (tbcd->nmcd.uItemState & CDIS_MARKED))
722 draw_flags |= ILD_BLEND50;
724 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
725 index, himl, left, top, offset);
727 if (draw_masked)
728 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
729 else
730 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
733 /* draws a blank frame for a toolbar button */
734 static void
735 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd)
737 HDC hdc = tbcd->nmcd.hdc;
738 RECT rc = tbcd->nmcd.rc;
739 /* if the state is disabled or indeterminate then the button
740 * cannot have an interactive look like pressed or hot */
741 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
742 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
743 BOOL pressed_look = !non_interactive_state &&
744 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
745 (tbcd->nmcd.uItemState & CDIS_CHECKED));
747 /* app don't want us to draw any edges */
748 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
749 return;
751 if (infoPtr->dwStyle & TBSTYLE_FLAT)
753 if (pressed_look)
754 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
755 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
756 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
758 else
760 if (pressed_look)
761 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
762 else
763 DrawEdge (hdc, &rc, EDGE_RAISED,
764 BF_SOFT | BF_RECT | BF_MIDDLE);
768 static void
769 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed)
771 HDC hdc = tbcd->nmcd.hdc;
772 int offset = 0;
773 BOOL pressed = bDropDownPressed ||
774 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
776 if (infoPtr->dwStyle & TBSTYLE_FLAT)
778 if (pressed)
779 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
780 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
781 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
782 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
783 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
785 else
787 if (pressed)
788 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
789 else
790 DrawEdge (hdc, rcArrow, EDGE_RAISED,
791 BF_SOFT | BF_RECT | BF_MIDDLE);
794 if (pressed)
795 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
797 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
799 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
800 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
802 else
803 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
806 /* draws a complete toolbar button */
807 static void
808 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
810 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
811 DWORD dwStyle = infoPtr->dwStyle;
812 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
813 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
814 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
815 BOOL drawSepDropDownArrow = hasDropDownArrow &&
816 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
817 RECT rc, rcArrow, rcBitmap, rcText;
818 LPWSTR lpText = NULL;
819 NMTBCUSTOMDRAW tbcd;
820 DWORD ntfret;
821 INT offset;
822 INT oldBkMode;
823 HTHEME theme = GetWindowTheme (hwnd);
825 rc = btnPtr->rect;
826 CopyRect (&rcArrow, &rc);
828 /* get a pointer to the text */
829 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
831 if (hasDropDownArrow)
833 int right;
835 if (dwStyle & TBSTYLE_FLAT)
836 right = max(rc.left, rc.right - DDARROW_WIDTH);
837 else
838 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
840 if (drawSepDropDownArrow)
841 rc.right = right;
843 rcArrow.left = right;
846 /* copy text & bitmap rects after adjusting for drop-down arrow
847 * so that text & bitmap is centred in the rectangle not containing
848 * the arrow */
849 CopyRect(&rcText, &rc);
850 CopyRect(&rcBitmap, &rc);
852 /* Center the bitmap horizontally and vertically */
853 if (dwStyle & TBSTYLE_LIST)
855 if (lpText &&
856 infoPtr->nMaxTextRows > 0 &&
857 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
858 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
859 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
860 else
861 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
863 else
864 rcBitmap.left += (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
866 rcBitmap.top += infoPtr->szPadding.cy / 2;
868 TRACE("iBitmap=%d, start=(%ld,%ld) w=%d, h=%d\n",
869 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
870 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
871 TRACE("Text=%s\n", debugstr_w(lpText));
872 TRACE("iListGap=%d, padding = { %ld, %ld }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
874 /* calculate text position */
875 if (lpText)
877 rcText.left += GetSystemMetrics(SM_CXEDGE);
878 rcText.right -= GetSystemMetrics(SM_CXEDGE);
879 if (dwStyle & TBSTYLE_LIST)
881 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
882 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
884 else
886 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
887 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
888 else
889 rcText.top += infoPtr->szPadding.cy/2 + 2;
893 /* Initialize fields in all cases, because we use these later
894 * NOTE: applications can and do alter these to customize their
895 * toolbars */
896 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
897 tbcd.clrText = comctl32_color.clrBtnText;
898 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
899 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
900 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
901 tbcd.clrMark = comctl32_color.clrHighlight;
902 tbcd.clrHighlightHotTrack = 0;
903 tbcd.nStringBkMode = TRANSPARENT;
904 tbcd.nHLStringBkMode = OPAQUE;
905 /* MSDN says that this is the text rectangle.
906 * But (why always a but) tracing of v5.7 of native shows
907 * that this is really a *relative* rectangle based on the
908 * the nmcd.rc. Also the left and top are always 0 ignoring
909 * any bitmap that might be present. */
910 tbcd.rcText.left = 0;
911 tbcd.rcText.top = 0;
912 tbcd.rcText.right = rcText.right - rc.left;
913 tbcd.rcText.bottom = rcText.bottom - rc.top;
914 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
915 tbcd.nmcd.hdc = hdc;
916 tbcd.nmcd.rc = rc;
917 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
919 /* FIXME: what are these used for? */
920 tbcd.hbrLines = 0;
921 tbcd.hpenLines = 0;
923 /* Issue Item Prepaint notify */
924 infoPtr->dwItemCustDraw = 0;
925 infoPtr->dwItemCDFlag = 0;
926 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
928 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
929 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
930 tbcd.nmcd.lItemlParam = btnPtr->dwData;
931 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
932 /* reset these fields so the user can't alter the behaviour like native */
933 tbcd.nmcd.hdc = hdc;
934 tbcd.nmcd.rc = rc;
936 infoPtr->dwItemCustDraw = ntfret & 0xffff;
937 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
938 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
939 return;
940 /* save the only part of the rect that the user can change */
941 rcText.right = tbcd.rcText.right + rc.left;
942 rcText.bottom = tbcd.rcText.bottom + rc.top;
945 /* separator */
946 if (btnPtr->fsStyle & BTNS_SEP) {
947 if (theme)
949 DrawThemeBackground (theme, hdc,
950 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
951 &tbcd.nmcd.rc, NULL);
953 else
954 /* with the FLAT style, iBitmap is the width and has already */
955 /* been taken into consideration in calculating the width */
956 /* so now we need to draw the vertical separator */
957 /* empirical tests show that iBitmap can/will be non-zero */
958 /* when drawing the vertical bar... */
959 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
960 if (btnPtr->fsStyle & BTNS_DROPDOWN)
961 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
962 else
963 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
965 else if (btnPtr->fsStyle != BTNS_SEP) {
966 FIXME("Draw some kind of separator: fsStyle=%x\n",
967 btnPtr->fsStyle);
969 goto FINALNOTIFY;
972 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
973 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
974 OffsetRect(&rcText, 1, 1);
976 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
977 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
978 TOOLBAR_DrawPattern (&rc, &tbcd);
980 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
981 && (tbcd.nmcd.uItemState & CDIS_HOT))
983 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
985 COLORREF oldclr;
987 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
988 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
989 if (hasDropDownArrow)
990 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
991 SetBkColor(hdc, oldclr);
995 if (theme)
997 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
998 int stateId = TS_NORMAL;
1000 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1001 stateId = TS_DISABLED;
1002 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1003 stateId = TS_PRESSED;
1004 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1005 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1006 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1007 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1008 stateId = TS_HOT;
1010 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1012 else
1013 TOOLBAR_DrawFrame(infoPtr, &tbcd);
1015 if (drawSepDropDownArrow)
1017 if (theme)
1019 int stateId = TS_NORMAL;
1021 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1022 stateId = TS_DISABLED;
1023 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1024 stateId = TS_PRESSED;
1025 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1026 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1027 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1028 stateId = TS_HOT;
1030 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1031 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1033 else
1034 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
1037 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1038 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1039 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1040 SetBkMode (hdc, oldBkMode);
1042 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1044 if (hasDropDownArrow && !drawSepDropDownArrow)
1046 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1048 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1049 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1051 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1053 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1054 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1056 else
1057 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1060 FINALNOTIFY:
1061 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1063 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1064 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1070 static void
1071 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1073 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1074 TBUTTON_INFO *btnPtr;
1075 INT i;
1076 RECT rcTemp, rcClient;
1077 NMTBCUSTOMDRAW tbcd;
1078 DWORD ntfret;
1080 /* the app has told us not to redraw the toolbar */
1081 if (!infoPtr->bDoRedraw)
1082 return;
1084 /* if imagelist belongs to the app, it can be changed
1085 by the app after setting it */
1086 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1088 infoPtr->nNumBitmaps = 0;
1089 for (i = 0; i < infoPtr->cimlDef; i++)
1090 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1093 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1095 /* change the imagelist icon size if we manage the list and it is necessary */
1096 TOOLBAR_CheckImageListIconSize(infoPtr);
1098 /* Send initial notify */
1099 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1100 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1101 tbcd.nmcd.hdc = hdc;
1102 tbcd.nmcd.rc = ps->rcPaint;
1103 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1104 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1106 GetClientRect(hwnd, &rcClient);
1108 /* redraw necessary buttons */
1109 btnPtr = infoPtr->buttons;
1110 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1112 BOOL bDraw;
1113 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1115 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1116 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1118 else
1119 bDraw = TRUE;
1120 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1121 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1122 if (bDraw)
1123 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1126 /* draw insert mark if required */
1127 if (infoPtr->tbim.iButton != -1)
1129 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1130 RECT rcInsertMark;
1131 rcInsertMark.top = rcButton.top;
1132 rcInsertMark.bottom = rcButton.bottom;
1133 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1134 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1135 else
1136 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1137 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1140 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1142 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1143 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1144 tbcd.nmcd.hdc = hdc;
1145 tbcd.nmcd.rc = ps->rcPaint;
1146 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1150 /***********************************************************************
1151 * TOOLBAR_MeasureString
1153 * This function gets the width and height of a string in pixels. This
1154 * is done first by using GetTextExtentPoint to get the basic width
1155 * and height. The DrawText is called with DT_CALCRECT to get the exact
1156 * width. The reason is because the text may have more than one "&" (or
1157 * prefix characters as M$ likes to call them). The prefix character
1158 * indicates where the underline goes, except for the string "&&" which
1159 * is reduced to a single "&". GetTextExtentPoint does not process these
1160 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1162 static void
1163 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1164 HDC hdc, LPSIZE lpSize)
1166 RECT myrect;
1168 lpSize->cx = 0;
1169 lpSize->cy = 0;
1171 if (infoPtr->nMaxTextRows > 0 &&
1172 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1173 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1174 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1176 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1178 if(lpText != NULL) {
1179 /* first get size of all the text */
1180 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1182 /* feed above size into the rectangle for DrawText */
1183 myrect.left = myrect.top = 0;
1184 myrect.right = lpSize->cx;
1185 myrect.bottom = lpSize->cy;
1187 /* Use DrawText to get true size as drawn (less pesky "&") */
1188 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1189 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1190 DT_NOPREFIX : 0));
1192 /* feed back to caller */
1193 lpSize->cx = myrect.right;
1194 lpSize->cy = myrect.bottom;
1198 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1201 /***********************************************************************
1202 * TOOLBAR_CalcStrings
1204 * This function walks through each string and measures it and returns
1205 * the largest height and width to caller.
1207 static void
1208 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1210 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1211 TBUTTON_INFO *btnPtr;
1212 INT i;
1213 SIZE sz;
1214 HDC hdc;
1215 HFONT hOldFont;
1217 lpSize->cx = 0;
1218 lpSize->cy = 0;
1220 if (infoPtr->nMaxTextRows == 0)
1221 return;
1223 hdc = GetDC (hwnd);
1224 hOldFont = SelectObject (hdc, infoPtr->hFont);
1226 if (infoPtr->nNumButtons == 0)
1228 TEXTMETRICW tm;
1230 GetTextMetricsW(hdc, &tm);
1231 lpSize->cy = tm.tmHeight;
1234 btnPtr = infoPtr->buttons;
1235 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1236 if(TOOLBAR_HasText(infoPtr, btnPtr))
1238 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1239 if (sz.cx > lpSize->cx)
1240 lpSize->cx = sz.cx;
1241 if (sz.cy > lpSize->cy)
1242 lpSize->cy = sz.cy;
1246 SelectObject (hdc, hOldFont);
1247 ReleaseDC (hwnd, hdc);
1249 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1252 /***********************************************************************
1253 * TOOLBAR_WrapToolbar
1255 * This function walks through the buttons and separators in the
1256 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1257 * wrapping should occur based on the width of the toolbar window.
1258 * It does *not* calculate button placement itself. That task
1259 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1260 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1261 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1263 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1264 * vertical toolbar lists.
1267 static void
1268 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1270 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1271 TBUTTON_INFO *btnPtr;
1272 INT x, cx, i, j;
1273 RECT rc;
1274 BOOL bWrap, bButtonWrap;
1276 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1277 /* no layout is necessary. Applications may use this style */
1278 /* to perform their own layout on the toolbar. */
1279 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1280 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1282 btnPtr = infoPtr->buttons;
1283 x = infoPtr->nIndent;
1285 if (GetParent(hwnd))
1287 /* this can get the parents width, to know how far we can extend
1288 * this toolbar. We cannot use its height, as there may be multiple
1289 * toolbars in a rebar control
1291 GetClientRect( GetParent(hwnd), &rc );
1292 infoPtr->nWidth = rc.right - rc.left;
1294 else
1296 GetWindowRect( hwnd, &rc );
1297 infoPtr->nWidth = rc.right - rc.left;
1300 bButtonWrap = FALSE;
1302 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1303 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1304 infoPtr->nIndent);
1306 for (i = 0; i < infoPtr->nNumButtons; i++ )
1308 bWrap = FALSE;
1309 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1311 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1312 continue;
1314 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1315 /* it is the actual width of the separator. This is used for */
1316 /* custom controls in toolbars. */
1317 /* */
1318 /* BTNS_DROPDOWN separators are treated as buttons for */
1319 /* width. - GA 8/01 */
1320 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1321 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1322 cx = (btnPtr[i].iBitmap > 0) ?
1323 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1324 else
1325 cx = infoPtr->nButtonWidth;
1327 /* Two or more adjacent separators form a separator group. */
1328 /* The first separator in a group should be wrapped to the */
1329 /* next row if the previous wrapping is on a button. */
1330 if( bButtonWrap &&
1331 (btnPtr[i].fsStyle & BTNS_SEP) &&
1332 (i + 1 < infoPtr->nNumButtons ) &&
1333 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1335 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1336 btnPtr[i].fsState |= TBSTATE_WRAP;
1337 x = infoPtr->nIndent;
1338 i++;
1339 bButtonWrap = FALSE;
1340 continue;
1343 /* The layout makes sure the bitmap is visible, but not the button. */
1344 /* Test added to also wrap after a button that starts a row but */
1345 /* is bigger than the area. - GA 8/01 */
1346 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1347 > infoPtr->nWidth ) ||
1348 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1350 BOOL bFound = FALSE;
1352 /* If the current button is a separator and not hidden, */
1353 /* go to the next until it reaches a non separator. */
1354 /* Wrap the last separator if it is before a button. */
1355 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1356 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1357 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1358 i < infoPtr->nNumButtons )
1360 i++;
1361 bFound = TRUE;
1364 if( bFound && i < infoPtr->nNumButtons )
1366 i--;
1367 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1368 i, btnPtr[i].fsStyle, x, cx);
1369 btnPtr[i].fsState |= TBSTATE_WRAP;
1370 x = infoPtr->nIndent;
1371 bButtonWrap = FALSE;
1372 continue;
1374 else if ( i >= infoPtr->nNumButtons)
1375 break;
1377 /* If the current button is not a separator, find the last */
1378 /* separator and wrap it. */
1379 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1381 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1382 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1384 bFound = TRUE;
1385 i = j;
1386 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1387 i, btnPtr[i].fsStyle, x, cx);
1388 x = infoPtr->nIndent;
1389 btnPtr[j].fsState |= TBSTATE_WRAP;
1390 bButtonWrap = FALSE;
1391 break;
1395 /* If no separator available for wrapping, wrap one of */
1396 /* non-hidden previous button. */
1397 if (!bFound)
1399 for ( j = i - 1;
1400 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1402 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1403 continue;
1405 bFound = TRUE;
1406 i = j;
1407 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1408 i, btnPtr[i].fsStyle, x, cx);
1409 x = infoPtr->nIndent;
1410 btnPtr[j].fsState |= TBSTATE_WRAP;
1411 bButtonWrap = TRUE;
1412 break;
1416 /* If all above failed, wrap the current button. */
1417 if (!bFound)
1419 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1420 i, btnPtr[i].fsStyle, x, cx);
1421 btnPtr[i].fsState |= TBSTATE_WRAP;
1422 bFound = TRUE;
1423 x = infoPtr->nIndent;
1424 if (btnPtr[i].fsStyle & BTNS_SEP )
1425 bButtonWrap = FALSE;
1426 else
1427 bButtonWrap = TRUE;
1430 else {
1431 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1432 i, btnPtr[i].fsStyle, x, cx);
1433 x += cx;
1439 /***********************************************************************
1440 * TOOLBAR_MeasureButton
1442 * Calculates the width and height required for a button. Used in
1443 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1444 * the width of buttons that are autosized.
1446 * Note that it would have been rather elegant to use one piece of code for
1447 * both the laying out of the toolbar and for controlling where button parts
1448 * are drawn, but the native control has inconsistencies between the two that
1449 * prevent this from being effectively. These inconsistencies can be seen as
1450 * artefacts where parts of the button appear outside of the bounding button
1451 * rectangle.
1453 * There are several cases for the calculation of the button dimensions and
1454 * button part positioning:
1456 * List
1457 * ====
1459 * With Bitmap:
1461 * +--------------------------------------------------------+ ^
1462 * | ^ ^ | |
1463 * | | pad.cy / 2 | centred | |
1464 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1465 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1466 * | |<------------>| | | | |
1467 * | +--------------+ +------------+ | |
1468 * |<-------------------------------------->| | |
1469 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1470 * | szText.cx | |
1471 * +--------------------------------------------------------+ -
1472 * <-------------------------------------------------------->
1473 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1475 * Without Bitmap (I_IMAGENONE):
1477 * +-----------------------------------+ ^
1478 * | ^ | |
1479 * | | centred | | LISTPAD_CY +
1480 * | +------------+ | | szText.cy
1481 * | | Text | | |
1482 * | | | | |
1483 * | +------------+ | |
1484 * |<----------------->| | |
1485 * | cxedge |<-----------> | |
1486 * | szText.cx | |
1487 * +-----------------------------------+ -
1488 * <----------------------------------->
1489 * szText.cx + pad.cx
1491 * Without text:
1493 * +--------------------------------------+ ^
1494 * | ^ | |
1495 * | | padding.cy/2 | | DEFPAD_CY +
1496 * | +------------+ | | nBitmapHeight
1497 * | | Bitmap | | |
1498 * | | | | |
1499 * | +------------+ | |
1500 * |<------------------->| | |
1501 * | cxedge + iListGap/2 |<-----------> | |
1502 * | nBitmapWidth | |
1503 * +--------------------------------------+ -
1504 * <-------------------------------------->
1505 * 2*cxedge + nBitmapWidth + iListGap
1507 * Non-List
1508 * ========
1510 * With bitmap:
1512 * +-----------------------------------+ ^
1513 * | ^ | |
1514 * | | pad.cy / 2 | | nBitmapHeight +
1515 * | - | | szText.cy +
1516 * | +------------+ | | DEFPAD_CY + 1
1517 * | centred | Bitmap | | |
1518 * |<----------------->| | | |
1519 * | +------------+ | |
1520 * | ^ | |
1521 * | 1 | | |
1522 * | - | |
1523 * | centred +---------------+ | |
1524 * |<--------------->| Text | | |
1525 * | +---------------+ | |
1526 * +-----------------------------------+ -
1527 * <----------------------------------->
1528 * pad.cx + max(nBitmapWidth, szText.cx)
1530 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1532 * +---------------------------------------+ ^
1533 * | ^ | |
1534 * | | 2 + pad.cy / 2 | |
1535 * | - | | szText.cy +
1536 * | centred +-----------------+ | | pad.cy + 2
1537 * |<--------------->| Text | | |
1538 * | +-----------------+ | |
1539 * | | |
1540 * +---------------------------------------+ -
1541 * <--------------------------------------->
1542 * 2*cxedge + pad.cx + szText.cx
1544 * Without text:
1545 * As for with bitmaps, but with szText.cx zero.
1547 static inline SIZE TOOLBAR_MeasureButton(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1549 SIZE sizeButton;
1550 if (infoPtr->dwStyle & TBSTYLE_LIST)
1552 /* set button height from bitmap / text height... */
1553 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1554 sizeString.cy);
1556 /* ... add on the necessary padding */
1557 if (bValidImageList)
1559 if (bHasBitmap)
1560 sizeButton.cy += DEFPAD_CY;
1561 else
1562 sizeButton.cy += LISTPAD_CY;
1564 else
1565 sizeButton.cy += infoPtr->szPadding.cy;
1567 /* calculate button width */
1568 if (bHasBitmap)
1570 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1571 infoPtr->nBitmapWidth + infoPtr->iListGap;
1572 if (sizeString.cx > 0)
1573 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1575 else
1576 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1578 else
1580 if (bHasBitmap)
1582 sizeButton.cy = infoPtr->nBitmapHeight + 1 +
1583 sizeString.cy + DEFPAD_CY;
1584 sizeButton.cx = infoPtr->szPadding.cx +
1585 max(sizeString.cx, infoPtr->nBitmapWidth);
1587 else
1589 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1590 NONLIST_NOTEXT_OFFSET;
1591 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1592 infoPtr->szPadding.cx + sizeString.cx;
1595 return sizeButton;
1599 /***********************************************************************
1600 * TOOLBAR_CalcToolbar
1602 * This function calculates button and separator placement. It first
1603 * calculates the button sizes, gets the toolbar window width and then
1604 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1605 * on. It assigns a new location to each item and sends this location to
1606 * the tooltip window if appropriate. Finally, it updates the rcBound
1607 * rect and calculates the new required toolbar window height.
1609 static void
1610 TOOLBAR_CalcToolbar (HWND hwnd)
1612 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1613 DWORD dwStyle = infoPtr->dwStyle;
1614 TBUTTON_INFO *btnPtr;
1615 INT i, nRows, nSepRows;
1616 INT x, y, cx, cy;
1617 SIZE sizeString, sizeButton;
1618 BOOL bWrap;
1619 BOOL validImageList = FALSE;
1620 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1622 TOOLBAR_CalcStrings (hwnd, &sizeString);
1624 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1626 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1627 validImageList = TRUE;
1628 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1629 infoPtr->nButtonWidth = sizeButton.cx;
1630 infoPtr->nButtonHeight = sizeButton.cy;
1632 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1633 infoPtr->nButtonWidth = infoPtr->cxMin;
1634 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1635 infoPtr->nButtonWidth = infoPtr->cxMax;
1637 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1639 x = infoPtr->nIndent;
1640 if (infoPtr->dwStyle & TBSTYLE_FLAT)
1641 y = 0;
1642 else
1643 y = TOP_BORDER;
1645 /* from above, minimum is a button, and possible text */
1646 cx = infoPtr->nButtonWidth;
1647 cy = infoPtr->nButtonHeight;
1649 nRows = nSepRows = 0;
1651 infoPtr->rcBound.top = y;
1652 infoPtr->rcBound.left = x;
1653 infoPtr->rcBound.bottom = y + cy;
1654 infoPtr->rcBound.right = x;
1656 btnPtr = infoPtr->buttons;
1658 TRACE("cy=%d\n", cy);
1660 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1662 bWrap = FALSE;
1663 if (btnPtr->fsState & TBSTATE_HIDDEN)
1665 SetRectEmpty (&btnPtr->rect);
1666 continue;
1669 cy = infoPtr->nButtonHeight;
1671 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1672 /* it is the actual width of the separator. This is used for */
1673 /* custom controls in toolbars. */
1674 if (btnPtr->fsStyle & BTNS_SEP) {
1675 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1676 cy = (btnPtr->iBitmap > 0) ?
1677 btnPtr->iBitmap : SEPARATOR_WIDTH;
1678 cx = infoPtr->nButtonWidth;
1680 else
1681 cx = (btnPtr->iBitmap > 0) ?
1682 btnPtr->iBitmap : SEPARATOR_WIDTH;
1684 else
1686 if (btnPtr->cx)
1687 cx = btnPtr->cx;
1688 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1689 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1691 SIZE sz;
1692 HDC hdc;
1693 HFONT hOldFont;
1695 hdc = GetDC (hwnd);
1696 hOldFont = SelectObject (hdc, infoPtr->hFont);
1698 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1700 SelectObject (hdc, hOldFont);
1701 ReleaseDC (hwnd, hdc);
1703 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1704 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1705 validImageList);
1706 cx = sizeButton.cx;
1708 else
1709 cx = infoPtr->nButtonWidth;
1711 /* if size has been set manually then don't add on extra space
1712 * for the drop down arrow */
1713 if (!btnPtr->cx && hasDropDownArrows &&
1714 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1715 cx += DDARROW_WIDTH;
1717 if (btnPtr->fsState & TBSTATE_WRAP )
1718 bWrap = TRUE;
1720 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1722 if (infoPtr->rcBound.left > x)
1723 infoPtr->rcBound.left = x;
1724 if (infoPtr->rcBound.right < x + cx)
1725 infoPtr->rcBound.right = x + cx;
1726 if (infoPtr->rcBound.bottom < y + cy)
1727 infoPtr->rcBound.bottom = y + cy;
1729 /* Set the toolTip only for non-hidden, non-separator button */
1730 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1732 TTTOOLINFOW ti;
1734 ZeroMemory (&ti, sizeof(ti));
1735 ti.cbSize = sizeof(ti);
1736 ti.hwnd = hwnd;
1737 ti.uId = btnPtr->idCommand;
1738 ti.rect = btnPtr->rect;
1739 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
1740 0, (LPARAM)&ti);
1743 /* btnPtr->nRow is zero based. The space between the rows is */
1744 /* also considered as a row. */
1745 btnPtr->nRow = nRows + nSepRows;
1747 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1748 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1749 x, y, x+cx, y+cy);
1751 if( bWrap )
1753 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1754 y += cy;
1755 else
1757 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1758 /* it is the actual width of the separator. This is used for */
1759 /* custom controls in toolbars. */
1760 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1761 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1762 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1763 else
1764 y += cy;
1766 /* nSepRows is used to calculate the extra height follwoing */
1767 /* the last row. */
1768 nSepRows++;
1770 x = infoPtr->nIndent;
1772 /* Increment row number unless this is the last button */
1773 /* and it has Wrap set. */
1774 if (i != infoPtr->nNumButtons-1)
1775 nRows++;
1777 else
1778 x += cx;
1781 /* infoPtr->nRows is the number of rows on the toolbar */
1782 infoPtr->nRows = nRows + nSepRows + 1;
1784 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1788 static INT
1789 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1791 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1792 TBUTTON_INFO *btnPtr;
1793 INT i;
1795 btnPtr = infoPtr->buttons;
1796 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1797 if (btnPtr->fsState & TBSTATE_HIDDEN)
1798 continue;
1800 if (btnPtr->fsStyle & BTNS_SEP) {
1801 if (PtInRect (&btnPtr->rect, *lpPt)) {
1802 TRACE(" ON SEPARATOR %d!\n", i);
1803 return -i;
1806 else {
1807 if (PtInRect (&btnPtr->rect, *lpPt)) {
1808 TRACE(" ON BUTTON %d!\n", i);
1809 return i;
1814 TRACE(" NOWHERE!\n");
1815 return TOOLBAR_NOWHERE;
1819 static INT
1820 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1822 TBUTTON_INFO *btnPtr;
1823 INT i;
1825 if (CommandIsIndex) {
1826 TRACE("command is really index command=%d\n", idCommand);
1827 if (idCommand >= infoPtr->nNumButtons) return -1;
1828 return idCommand;
1830 btnPtr = infoPtr->buttons;
1831 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1832 if (btnPtr->idCommand == idCommand) {
1833 TRACE("command=%d index=%d\n", idCommand, i);
1834 return i;
1837 TRACE("no index found for command=%d\n", idCommand);
1838 return -1;
1842 static INT
1843 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1845 TBUTTON_INFO *btnPtr;
1846 INT nRunIndex;
1848 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1849 return -1;
1851 /* check index button */
1852 btnPtr = &infoPtr->buttons[nIndex];
1853 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1854 if (btnPtr->fsState & TBSTATE_CHECKED)
1855 return nIndex;
1858 /* check previous buttons */
1859 nRunIndex = nIndex - 1;
1860 while (nRunIndex >= 0) {
1861 btnPtr = &infoPtr->buttons[nRunIndex];
1862 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1863 if (btnPtr->fsState & TBSTATE_CHECKED)
1864 return nRunIndex;
1866 else
1867 break;
1868 nRunIndex--;
1871 /* check next buttons */
1872 nRunIndex = nIndex + 1;
1873 while (nRunIndex < infoPtr->nNumButtons) {
1874 btnPtr = &infoPtr->buttons[nRunIndex];
1875 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1876 if (btnPtr->fsState & TBSTATE_CHECKED)
1877 return nRunIndex;
1879 else
1880 break;
1881 nRunIndex++;
1884 return -1;
1888 static VOID
1889 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1890 WPARAM wParam, LPARAM lParam)
1892 MSG msg;
1894 msg.hwnd = hwndMsg;
1895 msg.message = uMsg;
1896 msg.wParam = wParam;
1897 msg.lParam = lParam;
1898 msg.time = GetMessageTime ();
1899 msg.pt.x = LOWORD(GetMessagePos ());
1900 msg.pt.y = HIWORD(GetMessagePos ());
1902 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1905 /* keeps available button list box sorted by button id */
1906 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1908 int i;
1909 int count;
1910 PCUSTOMBUTTON btnInfo;
1911 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1913 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1915 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1917 /* position 0 is always separator */
1918 for (i = 1; i < count; i++)
1920 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1921 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1923 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1924 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1925 return;
1928 /* id higher than all others add to end */
1929 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
1930 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1933 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
1935 NMTOOLBARW nmtb;
1937 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
1939 if (nIndexFrom == nIndexTo)
1940 return;
1942 /* MSDN states that iItem is the index of the button, rather than the
1943 * command ID as used by every other NMTOOLBAR notification */
1944 nmtb.iItem = nIndexFrom;
1945 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1947 PCUSTOMBUTTON btnInfo;
1948 NMHDR hdr;
1949 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1950 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1952 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
1954 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
1955 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1956 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1957 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
1959 if (nIndexTo <= 0)
1960 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
1961 else
1962 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
1964 /* last item is always separator, so -2 instead of -1 */
1965 if (nIndexTo >= (count - 2))
1966 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
1967 else
1968 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
1970 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
1971 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1973 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1977 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
1979 NMTOOLBARW nmtb;
1981 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
1983 /* MSDN states that iItem is the index of the button, rather than the
1984 * command ID as used by every other NMTOOLBAR notification */
1985 nmtb.iItem = nIndexAvail;
1986 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1988 PCUSTOMBUTTON btnInfo;
1989 NMHDR hdr;
1990 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1991 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1992 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1994 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
1996 if (nIndexAvail != 0) /* index == 0 indicates separator */
1998 /* remove from 'available buttons' list */
1999 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2000 if (nIndexAvail == count-1)
2001 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2002 else
2003 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2005 else
2007 PCUSTOMBUTTON btnNew;
2009 /* duplicate 'separator' button */
2010 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2011 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2012 btnInfo = btnNew;
2015 /* insert into 'toolbar button' list */
2016 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2017 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2019 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2021 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2025 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
2027 PCUSTOMBUTTON btnInfo;
2028 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2030 TRACE("Remove: index %d\n", index);
2032 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2034 /* send TBN_QUERYDELETE notification */
2035 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2037 NMHDR hdr;
2039 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2040 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2042 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2044 /* insert into 'available button' list */
2045 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2046 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2047 else
2048 Free(btnInfo);
2050 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2054 /* drag list notification function for toolbar buttons list box */
2055 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2057 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2058 switch (pDLI->uNotification)
2060 case DL_BEGINDRAG:
2062 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2063 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2064 /* no dragging for last item (separator) */
2065 if (nCurrentItem >= (nCount - 1)) return FALSE;
2066 return TRUE;
2068 case DL_DRAGGING:
2070 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2071 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2072 /* no dragging past last item (separator) */
2073 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2075 DrawInsert(hwnd, hwndList, nCurrentItem);
2076 /* FIXME: native uses "move button" cursor */
2077 return DL_COPYCURSOR;
2080 /* not over toolbar buttons list */
2081 if (nCurrentItem < 0)
2083 POINT ptWindow = pDLI->ptCursor;
2084 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2085 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2086 /* over available buttons list? */
2087 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2088 /* FIXME: native uses "move button" cursor */
2089 return DL_COPYCURSOR;
2091 /* clear drag arrow */
2092 DrawInsert(hwnd, hwndList, -1);
2093 return DL_STOPCURSOR;
2095 case DL_DROPPED:
2097 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2098 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2099 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2100 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2102 /* clear drag arrow */
2103 DrawInsert(hwnd, hwndList, -1);
2104 /* move item */
2105 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2107 /* not over toolbar buttons list */
2108 if (nIndexTo < 0)
2110 POINT ptWindow = pDLI->ptCursor;
2111 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2112 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2113 /* over available buttons list? */
2114 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2115 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2117 break;
2119 case DL_CANCELDRAG:
2120 /* Clear drag arrow */
2121 DrawInsert(hwnd, hwndList, -1);
2122 break;
2125 return 0;
2128 /* drag list notification function for available buttons list box */
2129 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2131 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2132 switch (pDLI->uNotification)
2134 case DL_BEGINDRAG:
2135 return TRUE;
2136 case DL_DRAGGING:
2138 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2139 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2140 /* no dragging past last item (separator) */
2141 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2143 DrawInsert(hwnd, hwndList, nCurrentItem);
2144 /* FIXME: native uses "move button" cursor */
2145 return DL_COPYCURSOR;
2148 /* not over toolbar buttons list */
2149 if (nCurrentItem < 0)
2151 POINT ptWindow = pDLI->ptCursor;
2152 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2153 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2154 /* over available buttons list? */
2155 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2156 /* FIXME: native uses "move button" cursor */
2157 return DL_COPYCURSOR;
2159 /* clear drag arrow */
2160 DrawInsert(hwnd, hwndList, -1);
2161 return DL_STOPCURSOR;
2163 case DL_DROPPED:
2165 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2166 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2167 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2168 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2170 /* clear drag arrow */
2171 DrawInsert(hwnd, hwndList, -1);
2172 /* add item */
2173 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2176 case DL_CANCELDRAG:
2177 /* Clear drag arrow */
2178 DrawInsert(hwnd, hwndList, -1);
2179 break;
2181 return 0;
2184 extern UINT uDragListMessage;
2186 /***********************************************************************
2187 * TOOLBAR_CustomizeDialogProc
2188 * This function implements the toolbar customization dialog.
2190 static INT_PTR CALLBACK
2191 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2193 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2194 PCUSTOMBUTTON btnInfo;
2195 NMTOOLBARA nmtb;
2196 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2198 switch (uMsg)
2200 case WM_INITDIALOG:
2201 custInfo = (PCUSTDLG_INFO)lParam;
2202 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2204 if (custInfo)
2206 WCHAR Buffer[256];
2207 int i = 0;
2208 int index;
2209 NMTBINITCUSTOMIZE nmtbic;
2211 infoPtr = custInfo->tbInfo;
2213 /* send TBN_QUERYINSERT notification */
2214 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2216 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2217 return FALSE;
2219 nmtbic.hwndDialog = hwnd;
2220 /* Send TBN_INITCUSTOMIZE notification */
2221 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2222 TBNRF_HIDEHELP)
2224 TRACE("TBNRF_HIDEHELP requested\n");
2225 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2228 /* add items to 'toolbar buttons' list and check if removable */
2229 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2231 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2232 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2233 btnInfo->btn.fsStyle = BTNS_SEP;
2234 btnInfo->bVirtual = FALSE;
2235 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2237 /* send TBN_QUERYDELETE notification */
2238 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2240 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2241 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2244 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2246 /* insert separator button into 'available buttons' list */
2247 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2248 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2249 btnInfo->btn.fsStyle = BTNS_SEP;
2250 btnInfo->bVirtual = FALSE;
2251 btnInfo->bRemovable = TRUE;
2252 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2253 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2254 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2256 /* insert all buttons into dsa */
2257 for (i = 0;; i++)
2259 /* send TBN_GETBUTTONINFO notification */
2260 NMTOOLBARW nmtb;
2261 nmtb.iItem = i;
2262 nmtb.pszText = Buffer;
2263 nmtb.cchText = 256;
2265 /* Clear previous button's text */
2266 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2268 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2269 break;
2271 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2272 nmtb.tbButton.fsStyle, i,
2273 nmtb.tbButton.idCommand,
2274 nmtb.tbButton.iString,
2275 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2276 : "");
2278 /* insert button into the apropriate list */
2279 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2280 if (index == -1)
2282 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2283 btnInfo->bVirtual = FALSE;
2284 btnInfo->bRemovable = TRUE;
2286 else
2288 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2289 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2292 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2293 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2295 if (lstrlenW(nmtb.pszText))
2296 lstrcpyW(btnInfo->text, nmtb.pszText);
2297 else if (nmtb.tbButton.iString >= 0 &&
2298 nmtb.tbButton.iString < infoPtr->nNumStrings)
2300 lstrcpyW(btnInfo->text,
2301 infoPtr->strings[nmtb.tbButton.iString]);
2305 if (index == -1)
2306 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2309 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2311 /* select first item in the 'available' list */
2312 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2314 /* append 'virtual' separator button to the 'toolbar buttons' list */
2315 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2316 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2317 btnInfo->btn.fsStyle = BTNS_SEP;
2318 btnInfo->bVirtual = TRUE;
2319 btnInfo->bRemovable = FALSE;
2320 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2321 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2322 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2324 /* select last item in the 'toolbar' list */
2325 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2326 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2328 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2329 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2331 /* set focus and disable buttons */
2332 PostMessageW (hwnd, WM_USER, 0, 0);
2334 return TRUE;
2336 case WM_USER:
2337 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2338 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2339 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2340 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2341 return TRUE;
2343 case WM_CLOSE:
2344 EndDialog(hwnd, FALSE);
2345 return TRUE;
2347 case WM_COMMAND:
2348 switch (LOWORD(wParam))
2350 case IDC_TOOLBARBTN_LBOX:
2351 if (HIWORD(wParam) == LBN_SELCHANGE)
2353 PCUSTOMBUTTON btnInfo;
2354 NMTOOLBARA nmtb;
2355 int count;
2356 int index;
2358 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2359 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2361 /* send TBN_QUERYINSERT notification */
2362 nmtb.iItem = index;
2363 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2365 /* get list box item */
2366 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2368 if (index == (count - 1))
2370 /* last item (virtual separator) */
2371 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2372 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2374 else if (index == (count - 2))
2376 /* second last item (last non-virtual item) */
2377 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2378 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2380 else if (index == 0)
2382 /* first item */
2383 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2384 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2386 else
2388 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2389 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2392 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2394 break;
2396 case IDC_MOVEUP_BTN:
2398 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2399 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2401 break;
2403 case IDC_MOVEDN_BTN: /* move down */
2405 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2406 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2408 break;
2410 case IDC_REMOVE_BTN: /* remove button */
2412 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2414 if (LB_ERR == index)
2415 break;
2417 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2419 break;
2420 case IDC_HELP_BTN:
2421 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2422 break;
2423 case IDC_RESET_BTN:
2424 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2425 break;
2427 case IDOK: /* Add button */
2429 int index;
2430 int indexto;
2432 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2433 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2435 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2437 break;
2439 case IDCANCEL:
2440 EndDialog(hwnd, FALSE);
2441 break;
2443 return TRUE;
2445 case WM_DESTROY:
2447 int count;
2448 int i;
2450 /* delete items from 'toolbar buttons' listbox*/
2451 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2452 for (i = 0; i < count; i++)
2454 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2455 Free(btnInfo);
2456 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2458 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2461 /* delete items from 'available buttons' listbox*/
2462 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2463 for (i = 0; i < count; i++)
2465 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2466 Free(btnInfo);
2467 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2469 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2471 return TRUE;
2473 case WM_DRAWITEM:
2474 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2476 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2477 RECT rcButton;
2478 RECT rcText;
2479 HPEN hPen, hOldPen;
2480 HBRUSH hOldBrush;
2481 COLORREF oldText = 0;
2482 COLORREF oldBk = 0;
2484 /* get item data */
2485 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2486 if (btnInfo == NULL)
2488 FIXME("btnInfo invalid!\n");
2489 return TRUE;
2492 /* set colors and select objects */
2493 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2494 if (btnInfo->bVirtual)
2495 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2496 else
2497 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2498 hPen = CreatePen( PS_SOLID, 1,
2499 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2500 hOldPen = SelectObject (lpdis->hDC, hPen );
2501 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2503 /* fill background rectangle */
2504 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2505 lpdis->rcItem.right, lpdis->rcItem.bottom);
2507 /* calculate button and text rectangles */
2508 CopyRect (&rcButton, &lpdis->rcItem);
2509 InflateRect (&rcButton, -1, -1);
2510 CopyRect (&rcText, &rcButton);
2511 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2512 rcText.left = rcButton.right + 2;
2514 /* draw focus rectangle */
2515 if (lpdis->itemState & ODS_FOCUS)
2516 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2518 /* draw button */
2519 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2520 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2522 /* draw image and text */
2523 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2524 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2525 btnInfo->btn.iBitmap));
2526 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2527 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2529 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2530 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2532 /* delete objects and reset colors */
2533 SelectObject (lpdis->hDC, hOldBrush);
2534 SelectObject (lpdis->hDC, hOldPen);
2535 SetBkColor (lpdis->hDC, oldBk);
2536 SetTextColor (lpdis->hDC, oldText);
2537 DeleteObject( hPen );
2538 return TRUE;
2540 return FALSE;
2542 case WM_MEASUREITEM:
2543 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2545 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2547 lpmis->itemHeight = 15 + 8; /* default height */
2549 return TRUE;
2551 return FALSE;
2553 default:
2554 if (uDragListMessage && (uMsg == uDragListMessage))
2556 if (wParam == IDC_TOOLBARBTN_LBOX)
2558 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2559 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2560 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2561 return TRUE;
2563 else if (wParam == IDC_AVAILBTN_LBOX)
2565 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2566 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2567 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2568 return TRUE;
2571 return FALSE;
2575 static BOOL
2576 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2578 HBITMAP hbmLoad;
2579 INT nCountBefore = ImageList_GetImageCount(himlDef);
2580 INT nCountAfter;
2581 INT cxIcon, cyIcon;
2582 INT nAdded;
2583 INT nIndex;
2585 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2586 /* Add bitmaps to the default image list */
2587 if (bitmap->hInst == NULL) /* a handle was passed */
2589 BITMAP bmp;
2590 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2591 HDC hdcImage, hdcBitmap;
2593 /* copy the bitmap before adding it so that the user's bitmap
2594 * doesn't get modified.
2596 GetObjectW ((HBITMAP)bitmap->nID, sizeof(BITMAP), (LPVOID)&bmp);
2598 hdcImage = CreateCompatibleDC(0);
2599 hdcBitmap = CreateCompatibleDC(0);
2601 /* create new bitmap */
2602 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2603 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)bitmap->nID);
2604 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2606 /* Copy the user's image */
2607 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2608 hdcBitmap, 0, 0, SRCCOPY);
2610 SelectObject (hdcImage, hOldBitmapLoad);
2611 SelectObject (hdcBitmap, hOldBitmapBitmap);
2612 DeleteDC (hdcImage);
2613 DeleteDC (hdcBitmap);
2615 else
2616 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2618 /* enlarge the bitmap if needed */
2619 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2620 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2622 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2623 DeleteObject(hbmLoad);
2624 if (nIndex == -1)
2625 return FALSE;
2627 nCountAfter = ImageList_GetImageCount(himlDef);
2628 nAdded = nCountAfter - nCountBefore;
2629 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2631 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2632 } else if (nAdded > (INT)bitmap->nButtons) {
2633 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2634 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2637 infoPtr->nNumBitmaps += nAdded;
2638 return TRUE;
2641 static void
2642 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2644 HIMAGELIST himlDef;
2645 HIMAGELIST himlNew;
2646 INT cx, cy;
2647 INT i;
2649 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2650 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2651 return;
2652 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2653 return;
2654 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2655 return;
2657 TRACE("Update icon size: %dx%d -> %dx%d\n",
2658 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2660 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2661 ILC_COLORDDB|ILC_MASK, 8, 2);
2662 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2663 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2664 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2665 infoPtr->himlInt = himlNew;
2667 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2668 ImageList_Destroy(himlDef);
2671 /***********************************************************************
2672 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2675 static LRESULT
2676 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2678 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2679 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2680 TBITMAP_INFO info;
2681 INT iSumButtons, i;
2682 HIMAGELIST himlDef;
2684 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2685 if (!lpAddBmp)
2686 return -1;
2688 if (lpAddBmp->hInst == HINST_COMMCTRL)
2690 info.hInst = COMCTL32_hModule;
2691 switch (lpAddBmp->nID)
2693 case IDB_STD_SMALL_COLOR:
2694 info.nButtons = 15;
2695 info.nID = IDB_STD_SMALL;
2696 break;
2697 case IDB_STD_LARGE_COLOR:
2698 info.nButtons = 15;
2699 info.nID = IDB_STD_LARGE;
2700 break;
2701 case IDB_VIEW_SMALL_COLOR:
2702 info.nButtons = 12;
2703 info.nID = IDB_VIEW_SMALL;
2704 break;
2705 case IDB_VIEW_LARGE_COLOR:
2706 info.nButtons = 12;
2707 info.nID = IDB_VIEW_LARGE;
2708 break;
2709 case IDB_HIST_SMALL_COLOR:
2710 info.nButtons = 5;
2711 info.nID = IDB_HIST_SMALL;
2712 break;
2713 case IDB_HIST_LARGE_COLOR:
2714 info.nButtons = 5;
2715 info.nID = IDB_HIST_LARGE;
2716 break;
2717 default:
2718 return -1;
2721 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2723 /* Windows resize all the buttons to the size of a newly added standard image */
2724 if (lpAddBmp->nID & 1)
2726 /* large icons */
2727 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2728 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2730 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2731 MAKELPARAM((WORD)24, (WORD)24));
2732 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2733 MAKELPARAM((WORD)31, (WORD)30));
2735 else
2737 /* small icons */
2738 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2739 MAKELPARAM((WORD)16, (WORD)16));
2740 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2741 MAKELPARAM((WORD)22, (WORD)22));
2744 TOOLBAR_CalcToolbar (hwnd);
2746 else
2748 info.nButtons = (INT)wParam;
2749 info.hInst = lpAddBmp->hInst;
2750 info.nID = lpAddBmp->nID;
2751 TRACE("adding %d bitmaps!\n", info.nButtons);
2754 /* check if the bitmap is already loaded and compute iSumButtons */
2755 iSumButtons = 0;
2756 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2758 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2759 infoPtr->bitmaps[i].nID == info.nID)
2760 return iSumButtons;
2761 iSumButtons += infoPtr->bitmaps[i].nButtons;
2764 if (!infoPtr->cimlDef) {
2765 /* create new default image list */
2766 TRACE ("creating default image list!\n");
2768 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2769 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2770 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2771 infoPtr->himlInt = himlDef;
2773 else {
2774 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2777 if (!himlDef) {
2778 WARN("No default image list available\n");
2779 return -1;
2782 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2783 return -1;
2785 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2786 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2787 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2788 infoPtr->nNumBitmapInfos++;
2789 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2791 InvalidateRect(hwnd, NULL, TRUE);
2792 return iSumButtons;
2796 static LRESULT
2797 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2799 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2800 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2801 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2803 TRACE("adding %d buttons!\n", wParam);
2805 nAddButtons = (UINT)wParam;
2806 nOldButtons = infoPtr->nNumButtons;
2807 nNewButtons = nOldButtons + nAddButtons;
2809 if (infoPtr->nNumButtons == 0) {
2810 infoPtr->buttons =
2811 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2813 else {
2814 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2815 infoPtr->buttons =
2816 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2817 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2818 nOldButtons * sizeof(TBUTTON_INFO));
2819 Free (oldButtons);
2822 infoPtr->nNumButtons = nNewButtons;
2824 /* insert new button data */
2825 for (nCount = 0; nCount < nAddButtons; nCount++) {
2826 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2827 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2828 btnPtr->idCommand = lpTbb[nCount].idCommand;
2829 btnPtr->fsState = lpTbb[nCount].fsState;
2830 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2831 btnPtr->dwData = lpTbb[nCount].dwData;
2832 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2833 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2834 else
2835 btnPtr->iString = lpTbb[nCount].iString;
2836 btnPtr->bHot = FALSE;
2838 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2839 TTTOOLINFOW ti;
2841 ZeroMemory (&ti, sizeof(ti));
2842 ti.cbSize = sizeof(ti);
2843 ti.hwnd = hwnd;
2844 ti.uId = btnPtr->idCommand;
2845 ti.hinst = 0;
2846 ti.lpszText = LPSTR_TEXTCALLBACKW;
2848 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2849 0, (LPARAM)&ti);
2853 TOOLBAR_CalcToolbar (hwnd);
2854 TOOLBAR_AutoSize (hwnd);
2856 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2858 InvalidateRect(hwnd, NULL, TRUE);
2860 return TRUE;
2864 static LRESULT
2865 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2867 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2868 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2869 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2871 TRACE("adding %d buttons!\n", wParam);
2873 nAddButtons = (UINT)wParam;
2874 nOldButtons = infoPtr->nNumButtons;
2875 nNewButtons = nOldButtons + nAddButtons;
2877 if (infoPtr->nNumButtons == 0) {
2878 infoPtr->buttons =
2879 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2881 else {
2882 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2883 infoPtr->buttons =
2884 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2885 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2886 nOldButtons * sizeof(TBUTTON_INFO));
2887 Free (oldButtons);
2890 infoPtr->nNumButtons = nNewButtons;
2892 /* insert new button data */
2893 for (nCount = 0; nCount < nAddButtons; nCount++) {
2894 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2895 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2896 btnPtr->idCommand = lpTbb[nCount].idCommand;
2897 btnPtr->fsState = lpTbb[nCount].fsState;
2898 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2899 btnPtr->dwData = lpTbb[nCount].dwData;
2900 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2901 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2902 else
2903 btnPtr->iString = lpTbb[nCount].iString;
2904 btnPtr->bHot = FALSE;
2906 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2907 TTTOOLINFOW ti;
2909 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2910 ti.cbSize = sizeof (TTTOOLINFOW);
2911 ti.hwnd = hwnd;
2912 ti.uId = btnPtr->idCommand;
2913 ti.hinst = 0;
2914 ti.lpszText = LPSTR_TEXTCALLBACKW;
2915 ti.lParam = lParam;
2917 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2918 0, (LPARAM)&ti);
2922 TOOLBAR_CalcToolbar (hwnd);
2923 TOOLBAR_AutoSize (hwnd);
2925 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2927 InvalidateRect(hwnd, NULL, TRUE);
2929 return TRUE;
2933 static LRESULT
2934 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2936 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2937 INT nIndex;
2939 if ((wParam) && (HIWORD(lParam) == 0)) {
2940 char szString[256];
2941 INT len;
2942 TRACE("adding string from resource!\n");
2944 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam, szString, sizeof(szString));
2946 TRACE("len=%d \"%s\"\n", len, szString);
2947 nIndex = infoPtr->nNumStrings;
2948 if (infoPtr->nNumStrings == 0) {
2949 infoPtr->strings =
2950 Alloc (sizeof(LPWSTR));
2952 else {
2953 LPWSTR *oldStrings = infoPtr->strings;
2954 infoPtr->strings =
2955 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2956 memcpy (&infoPtr->strings[0], &oldStrings[0],
2957 sizeof(LPWSTR) * infoPtr->nNumStrings);
2958 Free (oldStrings);
2961 /*Alloc zeros out the allocated memory*/
2962 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2963 infoPtr->nNumStrings++;
2965 else {
2966 LPSTR p = (LPSTR)lParam;
2967 INT len;
2969 if (p == NULL)
2970 return -1;
2971 TRACE("adding string(s) from array!\n");
2973 nIndex = infoPtr->nNumStrings;
2974 while (*p) {
2975 len = strlen (p);
2976 TRACE("len=%d \"%s\"\n", len, p);
2978 if (infoPtr->nNumStrings == 0) {
2979 infoPtr->strings =
2980 Alloc (sizeof(LPWSTR));
2982 else {
2983 LPWSTR *oldStrings = infoPtr->strings;
2984 infoPtr->strings =
2985 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2986 memcpy (&infoPtr->strings[0], &oldStrings[0],
2987 sizeof(LPWSTR) * infoPtr->nNumStrings);
2988 Free (oldStrings);
2991 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2992 infoPtr->nNumStrings++;
2994 p += (len+1);
2998 return nIndex;
3002 static LRESULT
3003 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3005 #define MAX_RESOURCE_STRING_LENGTH 512
3006 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3007 INT nIndex;
3009 if ((wParam) && (HIWORD(lParam) == 0)) {
3010 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
3011 INT len;
3012 TRACE("adding string from resource!\n");
3014 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
3015 szString, MAX_RESOURCE_STRING_LENGTH);
3017 TRACE("len=%d %s\n", len, debugstr_w(szString));
3018 TRACE("First char: 0x%x\n", *szString);
3019 if (szString[0] == L'|')
3021 PWSTR p = szString + 1;
3023 nIndex = infoPtr->nNumStrings;
3024 while (*p != L'|' && *p != L'\0') {
3025 PWSTR np;
3027 if (infoPtr->nNumStrings == 0) {
3028 infoPtr->strings = Alloc (sizeof(LPWSTR));
3030 else
3032 LPWSTR *oldStrings = infoPtr->strings;
3033 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3034 memcpy(&infoPtr->strings[0], &oldStrings[0],
3035 sizeof(LPWSTR) * infoPtr->nNumStrings);
3036 Free(oldStrings);
3039 np=strchrW (p, '|');
3040 if (np!=NULL) {
3041 len = np - p;
3042 np++;
3043 } else {
3044 len = strlenW(p);
3045 np = p + len;
3047 TRACE("len=%d %s\n", len, debugstr_w(p));
3048 infoPtr->strings[infoPtr->nNumStrings] =
3049 Alloc (sizeof(WCHAR)*(len+1));
3050 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
3051 infoPtr->nNumStrings++;
3053 p = np;
3056 else
3058 nIndex = infoPtr->nNumStrings;
3059 if (infoPtr->nNumStrings == 0) {
3060 infoPtr->strings =
3061 Alloc (sizeof(LPWSTR));
3063 else {
3064 LPWSTR *oldStrings = infoPtr->strings;
3065 infoPtr->strings =
3066 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3067 memcpy (&infoPtr->strings[0], &oldStrings[0],
3068 sizeof(LPWSTR) * infoPtr->nNumStrings);
3069 Free (oldStrings);
3072 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
3073 infoPtr->nNumStrings++;
3076 else {
3077 LPWSTR p = (LPWSTR)lParam;
3078 INT len;
3080 if (p == NULL)
3081 return -1;
3082 TRACE("adding string(s) from array!\n");
3083 nIndex = infoPtr->nNumStrings;
3084 while (*p) {
3085 len = strlenW (p);
3087 TRACE("len=%d %s\n", len, debugstr_w(p));
3088 if (infoPtr->nNumStrings == 0) {
3089 infoPtr->strings =
3090 Alloc (sizeof(LPWSTR));
3092 else {
3093 LPWSTR *oldStrings = infoPtr->strings;
3094 infoPtr->strings =
3095 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3096 memcpy (&infoPtr->strings[0], &oldStrings[0],
3097 sizeof(LPWSTR) * infoPtr->nNumStrings);
3098 Free (oldStrings);
3101 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
3102 infoPtr->nNumStrings++;
3104 p += (len+1);
3108 return nIndex;
3112 static LRESULT
3113 TOOLBAR_AutoSize (HWND hwnd)
3115 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3116 RECT parent_rect;
3117 HWND parent;
3118 INT x, y;
3119 INT cx, cy;
3121 TRACE("auto sizing, style=%lx!\n", infoPtr->dwStyle);
3123 parent = GetParent (hwnd);
3125 if (!parent || !infoPtr->bDoRedraw)
3126 return 0;
3128 GetClientRect(parent, &parent_rect);
3130 x = parent_rect.left;
3131 y = parent_rect.top;
3133 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3135 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3136 cx = parent_rect.right - parent_rect.left;
3138 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3140 TOOLBAR_CalcToolbar(hwnd);
3141 InvalidateRect( hwnd, NULL, TRUE );
3144 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3146 RECT window_rect;
3147 UINT uPosFlags = SWP_NOZORDER;
3149 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3151 GetWindowRect(hwnd, &window_rect);
3152 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3153 y = window_rect.top;
3155 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3157 GetWindowRect(hwnd, &window_rect);
3158 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3161 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3162 uPosFlags |= SWP_NOMOVE;
3164 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3165 cy += GetSystemMetrics(SM_CYEDGE);
3167 if (infoPtr->dwStyle & WS_BORDER)
3169 x = y = 1; /* FIXME: this looks wrong */
3170 cy += GetSystemMetrics(SM_CYEDGE);
3171 cx += GetSystemMetrics(SM_CXEDGE);
3174 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3177 return 0;
3181 static LRESULT
3182 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3184 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3186 return infoPtr->nNumButtons;
3190 static LRESULT
3191 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3193 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3195 infoPtr->dwStructSize = (DWORD)wParam;
3197 return 0;
3201 static LRESULT
3202 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3204 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3205 TBUTTON_INFO *btnPtr;
3206 INT nIndex;
3208 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3210 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3211 if (nIndex == -1)
3212 return FALSE;
3214 btnPtr = &infoPtr->buttons[nIndex];
3215 btnPtr->iBitmap = LOWORD(lParam);
3217 /* we HAVE to erase the background, the new bitmap could be */
3218 /* transparent */
3219 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3221 return TRUE;
3225 static LRESULT
3226 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3228 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3229 TBUTTON_INFO *btnPtr;
3230 INT nIndex;
3231 INT nOldIndex = -1;
3232 BOOL bChecked = FALSE;
3234 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3236 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3238 if (nIndex == -1)
3239 return FALSE;
3241 btnPtr = &infoPtr->buttons[nIndex];
3243 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3245 if (LOWORD(lParam) == FALSE)
3246 btnPtr->fsState &= ~TBSTATE_CHECKED;
3247 else {
3248 if (btnPtr->fsStyle & BTNS_GROUP) {
3249 nOldIndex =
3250 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3251 if (nOldIndex == nIndex)
3252 return 0;
3253 if (nOldIndex != -1)
3254 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3256 btnPtr->fsState |= TBSTATE_CHECKED;
3259 if( bChecked != LOWORD(lParam) )
3261 if (nOldIndex != -1)
3262 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3263 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3266 /* FIXME: Send a WM_NOTIFY?? */
3268 return TRUE;
3272 static LRESULT
3273 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3275 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3277 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3281 static LRESULT
3282 TOOLBAR_Customize (HWND hwnd)
3284 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3285 CUSTDLG_INFO custInfo;
3286 LRESULT ret;
3287 LPCVOID template;
3288 HRSRC hRes;
3289 NMHDR nmhdr;
3291 custInfo.tbInfo = infoPtr;
3292 custInfo.tbHwnd = hwnd;
3294 /* send TBN_BEGINADJUST notification */
3295 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3297 if (!(hRes = FindResourceW (COMCTL32_hModule,
3298 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3299 (LPWSTR)RT_DIALOG)))
3300 return FALSE;
3302 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3303 return FALSE;
3305 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3306 (LPCDLGTEMPLATEW)template,
3307 hwnd,
3308 TOOLBAR_CustomizeDialogProc,
3309 (LPARAM)&custInfo);
3311 /* send TBN_ENDADJUST notification */
3312 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3314 return ret;
3318 static LRESULT
3319 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3321 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3322 INT nIndex = (INT)wParam;
3323 NMTOOLBARW nmtb;
3324 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3326 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3327 return FALSE;
3329 memset(&nmtb, 0, sizeof(nmtb));
3330 nmtb.iItem = btnPtr->idCommand;
3331 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3332 nmtb.tbButton.idCommand = btnPtr->idCommand;
3333 nmtb.tbButton.fsState = btnPtr->fsState;
3334 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3335 nmtb.tbButton.dwData = btnPtr->dwData;
3336 nmtb.tbButton.iString = btnPtr->iString;
3337 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3339 if ((infoPtr->hwndToolTip) &&
3340 !(btnPtr->fsStyle & BTNS_SEP)) {
3341 TTTOOLINFOW ti;
3343 ZeroMemory (&ti, sizeof(ti));
3344 ti.cbSize = sizeof(ti);
3345 ti.hwnd = hwnd;
3346 ti.uId = infoPtr->buttons[nIndex].idCommand;
3348 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
3351 if (infoPtr->nNumButtons == 1) {
3352 TRACE(" simple delete!\n");
3353 Free (infoPtr->buttons);
3354 infoPtr->buttons = NULL;
3355 infoPtr->nNumButtons = 0;
3357 else {
3358 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3359 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3361 infoPtr->nNumButtons--;
3362 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3363 if (nIndex > 0) {
3364 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3365 nIndex * sizeof(TBUTTON_INFO));
3368 if (nIndex < infoPtr->nNumButtons) {
3369 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3370 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3373 Free (oldButtons);
3376 TOOLBAR_CalcToolbar (hwnd);
3378 InvalidateRect (hwnd, NULL, TRUE);
3380 return TRUE;
3384 static LRESULT
3385 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3387 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3388 TBUTTON_INFO *btnPtr;
3389 INT nIndex;
3390 DWORD bState;
3392 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3394 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3396 if (nIndex == -1)
3397 return FALSE;
3399 btnPtr = &infoPtr->buttons[nIndex];
3401 bState = btnPtr->fsState & TBSTATE_ENABLED;
3403 /* update the toolbar button state */
3404 if(LOWORD(lParam) == FALSE) {
3405 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3406 } else {
3407 btnPtr->fsState |= TBSTATE_ENABLED;
3410 /* redraw the button only if the state of the button changed */
3411 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3412 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3414 return TRUE;
3418 static inline LRESULT
3419 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3421 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3423 return infoPtr->bAnchor;
3427 static LRESULT
3428 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3430 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3431 INT nIndex;
3433 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3434 if (nIndex == -1)
3435 return -1;
3437 return infoPtr->buttons[nIndex].iBitmap;
3441 static inline LRESULT
3442 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3444 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3448 static LRESULT
3449 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3451 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3452 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3453 INT nIndex = (INT)wParam;
3454 TBUTTON_INFO *btnPtr;
3456 if (lpTbb == NULL)
3457 return FALSE;
3459 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3460 return FALSE;
3462 btnPtr = &infoPtr->buttons[nIndex];
3463 lpTbb->iBitmap = btnPtr->iBitmap;
3464 lpTbb->idCommand = btnPtr->idCommand;
3465 lpTbb->fsState = btnPtr->fsState;
3466 lpTbb->fsStyle = btnPtr->fsStyle;
3467 lpTbb->bReserved[0] = 0;
3468 lpTbb->bReserved[1] = 0;
3469 lpTbb->dwData = btnPtr->dwData;
3470 lpTbb->iString = btnPtr->iString;
3472 return TRUE;
3476 static LRESULT
3477 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3479 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3480 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3481 TBUTTON_INFO *btnPtr;
3482 INT nIndex;
3484 if (lpTbInfo == NULL)
3485 return -1;
3486 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3487 return -1;
3489 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3490 lpTbInfo->dwMask & 0x80000000);
3491 if (nIndex == -1)
3492 return -1;
3494 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3496 if (lpTbInfo->dwMask & TBIF_COMMAND)
3497 lpTbInfo->idCommand = btnPtr->idCommand;
3498 if (lpTbInfo->dwMask & TBIF_IMAGE)
3499 lpTbInfo->iImage = btnPtr->iBitmap;
3500 if (lpTbInfo->dwMask & TBIF_LPARAM)
3501 lpTbInfo->lParam = btnPtr->dwData;
3502 if (lpTbInfo->dwMask & TBIF_SIZE)
3503 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3504 if (lpTbInfo->dwMask & TBIF_STATE)
3505 lpTbInfo->fsState = btnPtr->fsState;
3506 if (lpTbInfo->dwMask & TBIF_STYLE)
3507 lpTbInfo->fsStyle = btnPtr->fsStyle;
3508 if (lpTbInfo->dwMask & TBIF_TEXT) {
3509 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3510 can't use TOOLBAR_GetText here */
3511 LPWSTR lpText;
3512 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3513 lpText = (LPWSTR)btnPtr->iString;
3514 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3515 } else
3516 lpTbInfo->pszText[0] = '\0';
3518 return nIndex;
3522 static LRESULT
3523 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3525 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3526 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3527 TBUTTON_INFO *btnPtr;
3528 INT nIndex;
3530 if (lpTbInfo == NULL)
3531 return -1;
3532 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3533 return -1;
3535 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3536 lpTbInfo->dwMask & 0x80000000);
3537 if (nIndex == -1)
3538 return -1;
3540 btnPtr = &infoPtr->buttons[nIndex];
3542 if(!btnPtr)
3543 return -1;
3545 if (lpTbInfo->dwMask & TBIF_COMMAND)
3546 lpTbInfo->idCommand = btnPtr->idCommand;
3547 if (lpTbInfo->dwMask & TBIF_IMAGE)
3548 lpTbInfo->iImage = btnPtr->iBitmap;
3549 if (lpTbInfo->dwMask & TBIF_LPARAM)
3550 lpTbInfo->lParam = btnPtr->dwData;
3551 if (lpTbInfo->dwMask & TBIF_SIZE)
3552 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3553 if (lpTbInfo->dwMask & TBIF_STATE)
3554 lpTbInfo->fsState = btnPtr->fsState;
3555 if (lpTbInfo->dwMask & TBIF_STYLE)
3556 lpTbInfo->fsStyle = btnPtr->fsStyle;
3557 if (lpTbInfo->dwMask & TBIF_TEXT) {
3558 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3559 can't use TOOLBAR_GetText here */
3560 LPWSTR lpText;
3561 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3562 lpText = (LPWSTR)btnPtr->iString;
3563 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3564 } else
3565 lpTbInfo->pszText[0] = '\0';
3568 return nIndex;
3572 static LRESULT
3573 TOOLBAR_GetButtonSize (HWND hwnd)
3575 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3577 if (infoPtr->nNumButtons > 0)
3578 return MAKELONG((WORD)infoPtr->nButtonWidth,
3579 (WORD)infoPtr->nButtonHeight);
3580 else
3581 return MAKELONG(23,22);
3585 static LRESULT
3586 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3588 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3589 INT nIndex;
3590 LPWSTR lpText;
3592 if (lParam == 0)
3593 return -1;
3595 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3596 if (nIndex == -1)
3597 return -1;
3599 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3601 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3602 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3606 static LRESULT
3607 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3609 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3610 INT nIndex;
3611 LPWSTR lpText;
3612 LRESULT ret = 0;
3614 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3615 if (nIndex == -1)
3616 return -1;
3618 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3620 if (lpText)
3622 ret = strlenW (lpText);
3624 if (lParam)
3625 strcpyW ((LPWSTR)lParam, lpText);
3628 return ret;
3632 static LRESULT
3633 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3635 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3636 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3637 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3641 inline static LRESULT
3642 TOOLBAR_GetExtendedStyle (HWND hwnd)
3644 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3646 TRACE("\n");
3648 return infoPtr->dwExStyle;
3652 static LRESULT
3653 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3655 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3656 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3657 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3661 static LRESULT
3662 TOOLBAR_GetHotItem (HWND hwnd)
3664 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3666 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3667 return -1;
3669 if (infoPtr->nHotItem < 0)
3670 return -1;
3672 return (LRESULT)infoPtr->nHotItem;
3676 static LRESULT
3677 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3679 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3680 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3681 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3685 static LRESULT
3686 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3688 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3689 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3691 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3693 *lptbim = infoPtr->tbim;
3695 return 0;
3699 static LRESULT
3700 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3702 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3704 TRACE("hwnd = %p\n", hwnd);
3706 return (LRESULT)infoPtr->clrInsertMark;
3710 static LRESULT
3711 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3713 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3714 TBUTTON_INFO *btnPtr;
3715 LPRECT lpRect;
3716 INT nIndex;
3718 nIndex = (INT)wParam;
3719 btnPtr = &infoPtr->buttons[nIndex];
3720 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3721 return FALSE;
3722 lpRect = (LPRECT)lParam;
3723 if (lpRect == NULL)
3724 return FALSE;
3725 if (btnPtr->fsState & TBSTATE_HIDDEN)
3726 return FALSE;
3728 lpRect->left = btnPtr->rect.left;
3729 lpRect->right = btnPtr->rect.right;
3730 lpRect->bottom = btnPtr->rect.bottom;
3731 lpRect->top = btnPtr->rect.top;
3733 return TRUE;
3737 static LRESULT
3738 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3740 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3741 LPSIZE lpSize = (LPSIZE)lParam;
3743 if (lpSize == NULL)
3744 return FALSE;
3746 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3747 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3749 TRACE("maximum size %ld x %ld\n",
3750 infoPtr->rcBound.right - infoPtr->rcBound.left,
3751 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3753 return TRUE;
3757 /* << TOOLBAR_GetObject >> */
3760 static LRESULT
3761 TOOLBAR_GetPadding (HWND hwnd)
3763 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3764 DWORD oldPad;
3766 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3767 return (LRESULT) oldPad;
3771 static LRESULT
3772 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3774 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3775 TBUTTON_INFO *btnPtr;
3776 LPRECT lpRect;
3777 INT nIndex;
3779 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3780 btnPtr = &infoPtr->buttons[nIndex];
3781 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3782 return FALSE;
3783 lpRect = (LPRECT)lParam;
3784 if (lpRect == NULL)
3785 return FALSE;
3787 lpRect->left = btnPtr->rect.left;
3788 lpRect->right = btnPtr->rect.right;
3789 lpRect->bottom = btnPtr->rect.bottom;
3790 lpRect->top = btnPtr->rect.top;
3792 return TRUE;
3796 static LRESULT
3797 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3799 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3801 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3802 return infoPtr->nRows;
3803 else
3804 return 1;
3808 static LRESULT
3809 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3811 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3812 INT nIndex;
3814 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3815 if (nIndex == -1)
3816 return -1;
3818 return infoPtr->buttons[nIndex].fsState;
3822 static LRESULT
3823 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3825 return GetWindowLongW(hwnd, GWL_STYLE);
3829 static LRESULT
3830 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3832 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3834 return infoPtr->nMaxTextRows;
3838 static LRESULT
3839 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3841 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3843 return (LRESULT)infoPtr->hwndToolTip;
3847 static LRESULT
3848 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3850 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3852 TRACE("%s hwnd=%p\n",
3853 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3855 return infoPtr->bUnicode;
3859 inline static LRESULT
3860 TOOLBAR_GetVersion (HWND hwnd)
3862 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3863 return infoPtr->iVersion;
3867 static LRESULT
3868 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3870 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3871 TBUTTON_INFO *btnPtr;
3872 INT nIndex;
3874 TRACE("\n");
3876 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3877 if (nIndex == -1)
3878 return FALSE;
3880 btnPtr = &infoPtr->buttons[nIndex];
3881 if (LOWORD(lParam) == FALSE)
3882 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3883 else
3884 btnPtr->fsState |= TBSTATE_HIDDEN;
3886 TOOLBAR_CalcToolbar (hwnd);
3888 InvalidateRect (hwnd, NULL, TRUE);
3890 return TRUE;
3894 inline static LRESULT
3895 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3897 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3901 static LRESULT
3902 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3904 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3905 TBUTTON_INFO *btnPtr;
3906 INT nIndex;
3907 DWORD oldState;
3909 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3910 if (nIndex == -1)
3911 return FALSE;
3913 btnPtr = &infoPtr->buttons[nIndex];
3914 oldState = btnPtr->fsState;
3915 if (LOWORD(lParam) == FALSE)
3916 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3917 else
3918 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3920 if(oldState != btnPtr->fsState)
3921 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3923 return TRUE;
3927 static LRESULT
3928 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3930 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3931 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3932 INT nIndex = (INT)wParam;
3933 TBUTTON_INFO *oldButtons;
3935 if (lpTbb == NULL)
3936 return FALSE;
3938 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3940 if (nIndex == -1) {
3941 /* EPP: this seems to be an undocumented call (from my IE4)
3942 * I assume in that case that:
3943 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3944 * - index of insertion is at the end of existing buttons
3945 * I only see this happen with nIndex == -1, but it could have a special
3946 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3948 nIndex = infoPtr->nNumButtons;
3950 } else if (nIndex < 0)
3951 return FALSE;
3953 /* If the string passed is not an index, assume address of string
3954 and do our own AddString */
3955 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3956 LPSTR ptr;
3957 INT len;
3959 TRACE("string %s passed instead of index, adding string\n",
3960 debugstr_a((LPSTR)lpTbb->iString));
3961 len = strlen((LPSTR)lpTbb->iString) + 2;
3962 ptr = Alloc(len);
3963 strcpy(ptr, (LPSTR)lpTbb->iString);
3964 ptr[len - 1] = 0; /* ended by two '\0' */
3965 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3966 Free(ptr);
3969 TRACE("inserting button index=%d\n", nIndex);
3970 if (nIndex > infoPtr->nNumButtons) {
3971 nIndex = infoPtr->nNumButtons;
3972 TRACE("adjust index=%d\n", nIndex);
3975 oldButtons = infoPtr->buttons;
3976 infoPtr->nNumButtons++;
3977 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3978 /* pre insert copy */
3979 if (nIndex > 0) {
3980 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3981 nIndex * sizeof(TBUTTON_INFO));
3984 /* insert new button */
3985 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3986 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3987 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3988 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3989 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3990 /* if passed string and not index, then add string */
3991 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3992 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3994 else
3995 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3997 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3998 TTTOOLINFOW ti;
4000 ZeroMemory (&ti, sizeof(ti));
4001 ti.cbSize = sizeof (ti);
4002 ti.hwnd = hwnd;
4003 ti.uId = lpTbb->idCommand;
4004 ti.hinst = 0;
4005 ti.lpszText = LPSTR_TEXTCALLBACKW;
4007 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
4008 0, (LPARAM)&ti);
4011 /* post insert copy */
4012 if (nIndex < infoPtr->nNumButtons - 1) {
4013 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
4014 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
4017 Free (oldButtons);
4019 TOOLBAR_CalcToolbar (hwnd);
4020 TOOLBAR_AutoSize (hwnd);
4022 InvalidateRect (hwnd, NULL, TRUE);
4024 return TRUE;
4028 static LRESULT
4029 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4031 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4032 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
4033 INT nIndex = (INT)wParam;
4034 TBUTTON_INFO *oldButtons;
4036 if (lpTbb == NULL)
4037 return FALSE;
4039 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
4041 if (nIndex == -1) {
4042 /* EPP: this seems to be an undocumented call (from my IE4)
4043 * I assume in that case that:
4044 * - lpTbb->iString is a string pointer (not a string index in strings[] table
4045 * - index of insertion is at the end of existing buttons
4046 * I only see this happen with nIndex == -1, but it could have a special
4047 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
4049 nIndex = infoPtr->nNumButtons;
4051 } else if (nIndex < 0)
4052 return FALSE;
4054 /* If the string passed is not an index, assume address of string
4055 and do our own AddString */
4056 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
4057 LPWSTR ptr;
4058 INT len;
4060 TRACE("string %s passed instead of index, adding string\n",
4061 debugstr_w((LPWSTR)lpTbb->iString));
4062 len = strlenW((LPWSTR)lpTbb->iString) + 2;
4063 ptr = Alloc(len*sizeof(WCHAR));
4064 strcpyW(ptr, (LPWSTR)lpTbb->iString);
4065 ptr[len - 1] = 0; /* ended by two '\0' */
4066 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
4067 Free(ptr);
4070 TRACE("inserting button index=%d\n", nIndex);
4071 if (nIndex > infoPtr->nNumButtons) {
4072 nIndex = infoPtr->nNumButtons;
4073 TRACE("adjust index=%d\n", nIndex);
4076 oldButtons = infoPtr->buttons;
4077 infoPtr->nNumButtons++;
4078 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
4079 /* pre insert copy */
4080 if (nIndex > 0) {
4081 memcpy (&infoPtr->buttons[0], &oldButtons[0],
4082 nIndex * sizeof(TBUTTON_INFO));
4085 /* insert new button */
4086 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
4087 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
4088 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
4089 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
4090 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
4091 /* if passed string and not index, then add string */
4092 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
4093 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
4095 else
4096 infoPtr->buttons[nIndex].iString = lpTbb->iString;
4098 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
4099 TTTOOLINFOW ti;
4101 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
4102 ti.cbSize = sizeof (TTTOOLINFOW);
4103 ti.hwnd = hwnd;
4104 ti.uId = lpTbb->idCommand;
4105 ti.hinst = 0;
4106 ti.lpszText = LPSTR_TEXTCALLBACKW;
4108 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
4109 0, (LPARAM)&ti);
4112 /* post insert copy */
4113 if (nIndex < infoPtr->nNumButtons - 1) {
4114 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
4115 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
4118 Free (oldButtons);
4120 TOOLBAR_CalcToolbar (hwnd);
4121 TOOLBAR_AutoSize (hwnd);
4123 InvalidateRect (hwnd, NULL, TRUE);
4125 return TRUE;
4129 /* << TOOLBAR_InsertMarkHitTest >> */
4132 static LRESULT
4133 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
4135 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4136 INT nIndex;
4138 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4139 if (nIndex == -1)
4140 return FALSE;
4142 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
4146 static LRESULT
4147 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
4149 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4150 INT nIndex;
4152 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4153 if (nIndex == -1)
4154 return FALSE;
4156 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
4160 static LRESULT
4161 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
4163 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4164 INT nIndex;
4166 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4167 if (nIndex == -1)
4168 return TRUE;
4170 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
4174 static LRESULT
4175 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
4177 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4178 INT nIndex;
4180 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4181 if (nIndex == -1)
4182 return FALSE;
4184 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
4188 static LRESULT
4189 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4191 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4192 INT nIndex;
4194 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4195 if (nIndex == -1)
4196 return FALSE;
4198 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
4202 static LRESULT
4203 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
4205 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4206 INT nIndex;
4208 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4209 if (nIndex == -1)
4210 return FALSE;
4212 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
4216 static LRESULT
4217 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
4219 TBADDBITMAP tbab;
4220 tbab.hInst = (HINSTANCE)lParam;
4221 tbab.nID = (UINT_PTR)wParam;
4223 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
4225 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
4229 static LRESULT
4230 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
4232 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4233 WCHAR wAccel = (WCHAR)wParam;
4234 UINT* pIDButton = (UINT*)lParam;
4235 WCHAR wszAccel[] = {'&',wAccel,0};
4236 int i;
4238 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4239 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4241 for (i = 0; i < infoPtr->nNumButtons; i++)
4243 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4244 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4245 !(btnPtr->fsState & TBSTATE_HIDDEN))
4247 int iLen = strlenW(wszAccel);
4248 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4250 if (!lpszStr)
4251 continue;
4253 while (*lpszStr)
4255 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4257 lpszStr += 2;
4258 continue;
4260 if (!strncmpiW(lpszStr, wszAccel, iLen))
4262 *pIDButton = btnPtr->idCommand;
4263 return TRUE;
4265 lpszStr++;
4269 return FALSE;
4273 static LRESULT
4274 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4276 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4277 INT nIndex;
4278 DWORD oldState;
4279 TBUTTON_INFO *btnPtr;
4281 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4283 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4284 if (nIndex == -1)
4285 return FALSE;
4287 btnPtr = &infoPtr->buttons[nIndex];
4288 oldState = btnPtr->fsState;
4290 if (LOWORD(lParam))
4291 btnPtr->fsState |= TBSTATE_MARKED;
4292 else
4293 btnPtr->fsState &= ~TBSTATE_MARKED;
4295 if(oldState != btnPtr->fsState)
4296 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4298 return TRUE;
4302 /* fixes up an index of a button affected by a move */
4303 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4305 if (bMoveUp)
4307 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4308 (*pIndex)--;
4309 else if (*pIndex == nIndex)
4310 *pIndex = nMoveIndex;
4312 else
4314 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4315 (*pIndex)++;
4316 else if (*pIndex == nIndex)
4317 *pIndex = nMoveIndex;
4322 static LRESULT
4323 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4325 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4326 INT nIndex;
4327 INT nCount;
4328 INT nMoveIndex = (INT)lParam;
4329 TBUTTON_INFO button;
4331 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4333 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4334 if ((nIndex == -1) || (nMoveIndex < 0))
4335 return FALSE;
4337 if (nMoveIndex > infoPtr->nNumButtons - 1)
4338 nMoveIndex = infoPtr->nNumButtons - 1;
4340 button = infoPtr->buttons[nIndex];
4342 /* move button right */
4343 if (nIndex < nMoveIndex)
4345 nCount = nMoveIndex - nIndex;
4346 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4347 infoPtr->buttons[nMoveIndex] = button;
4349 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4350 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4351 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4352 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4354 else if (nIndex > nMoveIndex) /* move button left */
4356 nCount = nIndex - nMoveIndex;
4357 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4358 infoPtr->buttons[nMoveIndex] = button;
4360 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4361 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4362 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4363 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4366 TOOLBAR_CalcToolbar(hwnd);
4367 TOOLBAR_AutoSize(hwnd);
4368 InvalidateRect(hwnd, NULL, TRUE);
4370 return TRUE;
4374 static LRESULT
4375 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4377 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4378 TBUTTON_INFO *btnPtr;
4379 INT nIndex;
4380 DWORD oldState;
4382 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4383 if (nIndex == -1)
4384 return FALSE;
4386 btnPtr = &infoPtr->buttons[nIndex];
4387 oldState = btnPtr->fsState;
4388 if (LOWORD(lParam) == FALSE)
4389 btnPtr->fsState &= ~TBSTATE_PRESSED;
4390 else
4391 btnPtr->fsState |= TBSTATE_PRESSED;
4393 if(oldState != btnPtr->fsState)
4394 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4396 return TRUE;
4399 /* FIXME: there might still be some confusion her between number of buttons
4400 * and number of bitmaps */
4401 static LRESULT
4402 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4404 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4405 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4406 HBITMAP hBitmap;
4407 HBITMAP hbmLoad = NULL;
4408 int i = 0, nOldButtons = 0, pos = 0;
4409 int nOldBitmaps, nNewBitmaps = 0;
4410 HIMAGELIST himlDef = 0;
4412 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4413 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4414 lpReplace->nButtons);
4416 if (lpReplace->hInstOld == HINST_COMMCTRL)
4418 FIXME("changing standard bitmaps not implemented\n");
4419 return FALSE;
4421 else if (lpReplace->hInstOld != 0)
4422 FIXME("resources not in the current module not implemented\n");
4424 if (lpReplace->hInstNew)
4426 hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4427 hBitmap = hbmLoad;
4429 else
4431 hBitmap = (HBITMAP) lpReplace->nIDNew;
4434 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4435 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4436 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4437 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4438 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4440 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4441 nOldButtons = tbi->nButtons;
4442 tbi->nButtons = lpReplace->nButtons;
4443 tbi->hInst = lpReplace->hInstNew;
4444 tbi->nID = lpReplace->nIDNew;
4445 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4446 break;
4448 pos += tbi->nButtons;
4451 if (nOldButtons == 0)
4453 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4454 if (hbmLoad)
4455 DeleteObject (hbmLoad);
4456 return FALSE;
4459 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4460 nOldBitmaps = ImageList_GetImageCount(himlDef);
4462 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4464 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4465 ImageList_Remove(himlDef, i);
4467 if (hBitmap)
4469 BITMAP bmp;
4470 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4471 HDC hdcImage, hdcBitmap;
4473 /* copy the bitmap before adding it so that the user's bitmap
4474 * doesn't get modified.
4476 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4478 hdcImage = CreateCompatibleDC(0);
4479 hdcBitmap = CreateCompatibleDC(0);
4481 /* create new bitmap */
4482 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4483 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4484 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4486 /* Copy the user's image */
4487 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4488 hdcBitmap, 0, 0, SRCCOPY);
4490 SelectObject (hdcImage, hOldBitmapLoad);
4491 SelectObject (hdcBitmap, hOldBitmapBitmap);
4492 DeleteDC (hdcImage);
4493 DeleteDC (hdcBitmap);
4495 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4496 nNewBitmaps = ImageList_GetImageCount(himlDef);
4497 DeleteObject (hbmLoad);
4500 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4502 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4503 pos, nOldBitmaps, nNewBitmaps);
4505 InvalidateRect(hwnd, NULL, TRUE);
4507 if (hbmLoad)
4508 DeleteObject (hbmLoad);
4509 return TRUE;
4513 /* helper for TOOLBAR_SaveRestoreW */
4514 static BOOL
4515 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4517 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4518 debugstr_w(lpSave->pszValueName));
4520 return FALSE;
4524 /* helper for TOOLBAR_Restore */
4525 static void
4526 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4528 INT i;
4529 TTTOOLINFOW ti;
4531 ZeroMemory(&ti, sizeof(ti));
4532 ti.cbSize = sizeof(ti);
4533 ti.hwnd = infoPtr->hwndSelf;
4535 for (i = 0; i < infoPtr->nNumButtons; i++)
4537 if ((infoPtr->hwndToolTip) &&
4538 !(infoPtr->buttons[i].fsStyle & BTNS_SEP))
4540 ti.uId = infoPtr->buttons[i].idCommand;
4541 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
4545 Free(infoPtr->buttons);
4546 infoPtr->buttons = NULL;
4547 infoPtr->nNumButtons = 0;
4551 /* helper for TOOLBAR_SaveRestoreW */
4552 static BOOL
4553 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4555 LONG res;
4556 HKEY hkey = NULL;
4557 BOOL ret = FALSE;
4558 DWORD dwType;
4559 DWORD dwSize = 0;
4560 NMTBRESTORE nmtbr;
4562 /* restore toolbar information */
4563 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4564 debugstr_w(lpSave->pszValueName));
4566 memset(&nmtbr, 0, sizeof(nmtbr));
4568 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4569 KEY_QUERY_VALUE, &hkey);
4570 if (!res)
4571 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4572 NULL, &dwSize);
4573 if (!res && dwType != REG_BINARY)
4574 res = ERROR_FILE_NOT_FOUND;
4575 if (!res)
4577 nmtbr.pData = Alloc(dwSize);
4578 nmtbr.cbData = (UINT)dwSize;
4579 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4581 if (!res)
4582 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4583 (LPBYTE)nmtbr.pData, &dwSize);
4584 if (!res)
4586 nmtbr.pCurrent = nmtbr.pData;
4587 nmtbr.iItem = -1;
4588 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4589 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4591 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4593 INT i;
4595 /* remove all existing buttons as this function is designed to
4596 * restore the toolbar to a previously saved state */
4597 TOOLBAR_DeleteAllButtons(infoPtr);
4599 for (i = 0; i < nmtbr.cButtons; i++)
4601 nmtbr.iItem = i;
4602 nmtbr.tbButton.iBitmap = -1;
4603 nmtbr.tbButton.fsState = 0;
4604 nmtbr.tbButton.fsStyle = 0;
4605 nmtbr.tbButton.idCommand = 0;
4606 if (*nmtbr.pCurrent == (DWORD)-1)
4608 /* separator */
4609 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4610 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4612 else if (*nmtbr.pCurrent == (DWORD)-2)
4613 /* hidden button */
4614 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4615 else
4616 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4618 nmtbr.pCurrent++;
4620 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4622 /* can't contain real string as we don't know whether
4623 * the client put an ANSI or Unicode string in there */
4624 if (HIWORD(nmtbr.tbButton.iString))
4625 nmtbr.tbButton.iString = 0;
4627 TOOLBAR_InsertButtonW(infoPtr->hwndSelf, -1,
4628 (LPARAM)&nmtbr.tbButton);
4631 /* do legacy notifications */
4632 if (infoPtr->iVersion < 5)
4634 /* FIXME: send TBN_BEGINADJUST */
4635 FIXME("send TBN_GETBUTTONINFO for each button\n");
4636 /* FIXME: send TBN_ENDADJUST */
4639 /* remove all uninitialised buttons
4640 * note: loop backwards to avoid having to fixup i on a
4641 * delete */
4642 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4643 if (infoPtr->buttons[i].iBitmap == -1)
4644 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4646 /* only indicate success if at least one button survived */
4647 if (infoPtr->nNumButtons > 0) ret = TRUE;
4650 Free (nmtbr.pData);
4651 RegCloseKey(hkey);
4653 return ret;
4657 static LRESULT
4658 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4660 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4662 if (lpSave == NULL) return 0;
4664 if (wParam)
4665 return TOOLBAR_Save(infoPtr, lpSave);
4666 else
4667 return TOOLBAR_Restore(infoPtr, lpSave);
4671 static LRESULT
4672 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4674 LPWSTR pszValueName = 0, pszSubKey = 0;
4675 TBSAVEPARAMSW SaveW;
4676 LRESULT result = 0;
4677 int len;
4679 if (lpSave == NULL) return 0;
4681 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4682 pszSubKey = Alloc(len * sizeof(WCHAR));
4683 if (pszSubKey) goto exit;
4684 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4686 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4687 pszValueName = Alloc(len * sizeof(WCHAR));
4688 if (!pszValueName) goto exit;
4689 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4691 SaveW.pszValueName = pszValueName;
4692 SaveW.pszSubKey = pszSubKey;
4693 SaveW.hkr = lpSave->hkr;
4694 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4696 exit:
4697 Free (pszValueName);
4698 Free (pszSubKey);
4700 return result;
4704 static LRESULT
4705 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4707 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4708 BOOL bOldAnchor = infoPtr->bAnchor;
4710 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4712 infoPtr->bAnchor = (BOOL)wParam;
4714 /* Native does not remove the hot effect from an already hot button */
4716 return (LRESULT)bOldAnchor;
4720 static LRESULT
4721 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4723 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4724 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4726 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4728 if (wParam != 0)
4729 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4731 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4732 lParam = MAKELPARAM(16, 15);
4734 if (infoPtr->nNumButtons > 0)
4735 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4736 infoPtr->nNumButtons,
4737 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4738 LOWORD(lParam), HIWORD(lParam));
4740 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4741 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4744 if ((himlDef == infoPtr->himlInt) &&
4745 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4747 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4748 infoPtr->nBitmapHeight);
4751 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4752 return TRUE;
4756 static LRESULT
4757 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4759 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4760 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4761 TBUTTON_INFO *btnPtr;
4762 INT nIndex;
4763 RECT oldBtnRect;
4765 if (lptbbi == NULL)
4766 return FALSE;
4767 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4768 return FALSE;
4770 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4771 lptbbi->dwMask & 0x80000000);
4772 if (nIndex == -1)
4773 return FALSE;
4775 btnPtr = &infoPtr->buttons[nIndex];
4776 if (lptbbi->dwMask & TBIF_COMMAND)
4777 btnPtr->idCommand = lptbbi->idCommand;
4778 if (lptbbi->dwMask & TBIF_IMAGE)
4779 btnPtr->iBitmap = lptbbi->iImage;
4780 if (lptbbi->dwMask & TBIF_LPARAM)
4781 btnPtr->dwData = lptbbi->lParam;
4782 if (lptbbi->dwMask & TBIF_SIZE)
4783 btnPtr->cx = lptbbi->cx;
4784 if (lptbbi->dwMask & TBIF_STATE)
4785 btnPtr->fsState = lptbbi->fsState;
4786 if (lptbbi->dwMask & TBIF_STYLE)
4787 btnPtr->fsStyle = lptbbi->fsStyle;
4789 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4790 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4791 /* iString is index, zero it to make Str_SetPtr succeed */
4792 btnPtr->iString=0;
4794 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4797 /* save the button rect to see if we need to redraw the whole toolbar */
4798 oldBtnRect = btnPtr->rect;
4799 TOOLBAR_CalcToolbar(hwnd);
4801 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4802 InvalidateRect(hwnd, NULL, TRUE);
4803 else
4804 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4806 return TRUE;
4810 static LRESULT
4811 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4813 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4814 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4815 TBUTTON_INFO *btnPtr;
4816 INT nIndex;
4817 RECT oldBtnRect;
4819 if (lptbbi == NULL)
4820 return FALSE;
4821 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4822 return FALSE;
4824 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4825 lptbbi->dwMask & 0x80000000);
4826 if (nIndex == -1)
4827 return FALSE;
4829 btnPtr = &infoPtr->buttons[nIndex];
4830 if (lptbbi->dwMask & TBIF_COMMAND)
4831 btnPtr->idCommand = lptbbi->idCommand;
4832 if (lptbbi->dwMask & TBIF_IMAGE)
4833 btnPtr->iBitmap = lptbbi->iImage;
4834 if (lptbbi->dwMask & TBIF_LPARAM)
4835 btnPtr->dwData = lptbbi->lParam;
4836 if (lptbbi->dwMask & TBIF_SIZE)
4837 btnPtr->cx = lptbbi->cx;
4838 if (lptbbi->dwMask & TBIF_STATE)
4839 btnPtr->fsState = lptbbi->fsState;
4840 if (lptbbi->dwMask & TBIF_STYLE)
4841 btnPtr->fsStyle = lptbbi->fsStyle;
4843 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4844 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4845 /* iString is index, zero it to make Str_SetPtr succeed */
4846 btnPtr->iString=0;
4847 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4850 /* save the button rect to see if we need to redraw the whole toolbar */
4851 oldBtnRect = btnPtr->rect;
4852 TOOLBAR_CalcToolbar(hwnd);
4854 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4855 InvalidateRect(hwnd, NULL, TRUE);
4856 else
4857 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4859 return TRUE;
4863 static LRESULT
4864 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4866 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4867 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4869 if ((cx < 0) || (cy < 0))
4871 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4872 return FALSE;
4875 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4877 /* The documentation claims you can only change the button size before
4878 * any button has been added. But this is wrong.
4879 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4880 * it to the toolbar, and it checks that the return value is nonzero - mjm
4881 * Further testing shows that we must actually perform the change too.
4884 * The documentation also does not mention that if 0 is supplied for
4885 * either size, the system changes it to the default of 24 wide and
4886 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4888 infoPtr->nButtonWidth = (cx) ? cx : 24;
4889 infoPtr->nButtonHeight = (cy) ? cy : 22;
4890 return TRUE;
4894 static LRESULT
4895 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4897 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4899 /* if setting to current values, ignore */
4900 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4901 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4902 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4903 infoPtr->cxMin, infoPtr->cxMax);
4904 return TRUE;
4907 /* save new values */
4908 infoPtr->cxMin = (INT)LOWORD(lParam);
4909 infoPtr->cxMax = (INT)HIWORD(lParam);
4911 /* otherwise we need to recalc the toolbar and in some cases
4912 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4913 which doesn't actually draw - GA). */
4914 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4915 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4917 TOOLBAR_CalcToolbar (hwnd);
4919 InvalidateRect (hwnd, NULL, TRUE);
4921 return TRUE;
4925 static LRESULT
4926 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4928 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4929 INT nIndex = (INT)wParam;
4931 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4932 return FALSE;
4934 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4936 if (infoPtr->hwndToolTip) {
4938 FIXME("change tool tip!\n");
4942 return TRUE;
4946 static LRESULT
4947 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4949 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4950 HIMAGELIST himl = (HIMAGELIST)lParam;
4951 HIMAGELIST himlTemp;
4952 INT id = 0;
4954 if (infoPtr->iVersion >= 5)
4955 id = wParam;
4957 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4958 &infoPtr->cimlDis, himl, id);
4960 /* FIXME: redraw ? */
4962 return (LRESULT)himlTemp;
4966 static LRESULT
4967 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4969 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4970 DWORD dwTemp;
4972 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4974 dwTemp = infoPtr->dwDTFlags;
4975 infoPtr->dwDTFlags =
4976 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4978 return (LRESULT)dwTemp;
4981 /* This function differs a bit from what MSDN says it does:
4982 * 1. lParam contains extended style flags to OR with current style
4983 * (MSDN isn't clear on the OR bit)
4984 * 2. wParam appears to contain extended style flags to be reset
4985 * (MSDN says that this parameter is reserved)
4987 static LRESULT
4988 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4990 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4991 DWORD dwTemp;
4993 dwTemp = infoPtr->dwExStyle;
4994 infoPtr->dwExStyle &= ~wParam;
4995 infoPtr->dwExStyle |= (DWORD)lParam;
4997 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4999 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
5000 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
5001 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
5003 TOOLBAR_CalcToolbar (hwnd);
5005 TOOLBAR_AutoSize(hwnd);
5007 InvalidateRect(hwnd, NULL, TRUE);
5009 return (LRESULT)dwTemp;
5013 static LRESULT
5014 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
5016 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5017 HIMAGELIST himlTemp;
5018 HIMAGELIST himl = (HIMAGELIST)lParam;
5019 INT id = 0;
5021 if (infoPtr->iVersion >= 5)
5022 id = wParam;
5024 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
5026 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
5027 &infoPtr->cimlHot, himl, id);
5029 /* FIXME: redraw ? */
5031 return (LRESULT)himlTemp;
5035 /* Makes previous hot button no longer hot, makes the specified
5036 * button hot and sends appropriate notifications. dwReason is one or
5037 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
5038 * NOTE 1: this function does not validate nHit
5039 * NOTE 2: the name of this function is completely made up and
5040 * not based on any documentation from Microsoft. */
5041 static void
5042 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
5044 if (infoPtr->nHotItem != nHit)
5046 NMTBHOTITEM nmhotitem;
5047 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
5048 LRESULT no_highlight;
5050 /* Remove the effect of an old hot button if the button was
5051 drawn with the hot button effect */
5052 if(infoPtr->nHotItem >= 0)
5054 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5055 oldBtnPtr->bHot = FALSE;
5058 infoPtr->nHotItem = nHit;
5060 /* It's not a separator or in nowhere. It's a hot button. */
5061 if (nHit >= 0)
5062 btnPtr = &infoPtr->buttons[nHit];
5064 nmhotitem.dwFlags = dwReason;
5065 if (oldBtnPtr)
5066 nmhotitem.idOld = oldBtnPtr->idCommand;
5067 else
5068 nmhotitem.dwFlags |= HICF_ENTERING;
5069 if (btnPtr)
5070 nmhotitem.idNew = btnPtr->idCommand;
5071 else
5072 nmhotitem.dwFlags |= HICF_LEAVING;
5074 no_highlight = TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE);
5076 /* now invalidate the old and new buttons so they will be painted,
5077 * but only if they are enabled - disabled buttons cannot become hot */
5078 if (oldBtnPtr && (oldBtnPtr->fsState & TBSTATE_ENABLED))
5079 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
5080 if (btnPtr && !no_highlight && (btnPtr->fsState & TBSTATE_ENABLED))
5082 btnPtr->bHot = TRUE;
5083 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5088 static LRESULT
5089 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
5091 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5092 INT nOldHotItem = infoPtr->nHotItem;
5094 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
5096 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5097 wParam = -1;
5099 /* NOTE: an application can still remove the hot item even if anchor
5100 * highlighting is enabled */
5102 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
5103 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
5105 if (nOldHotItem < 0)
5106 return -1;
5108 return (LRESULT)nOldHotItem;
5112 static LRESULT
5113 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
5115 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5116 HIMAGELIST himlTemp;
5117 HIMAGELIST himl = (HIMAGELIST)lParam;
5118 INT i, id = 0;
5120 if (infoPtr->iVersion >= 5)
5121 id = wParam;
5123 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
5124 &infoPtr->cimlDef, himl, id);
5126 infoPtr->nNumBitmaps = 0;
5127 for (i = 0; i < infoPtr->cimlDef; i++)
5128 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
5130 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
5131 &infoPtr->nBitmapHeight))
5133 infoPtr->nBitmapWidth = 1;
5134 infoPtr->nBitmapHeight = 1;
5137 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
5138 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
5139 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
5141 InvalidateRect(hwnd, NULL, TRUE);
5143 return (LRESULT)himlTemp;
5147 static LRESULT
5148 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5150 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5152 infoPtr->nIndent = (INT)wParam;
5154 TRACE("\n");
5156 /* process only on indent changing */
5157 if(infoPtr->nIndent != (INT)wParam)
5159 infoPtr->nIndent = (INT)wParam;
5160 TOOLBAR_CalcToolbar (hwnd);
5161 InvalidateRect(hwnd, NULL, FALSE);
5164 return TRUE;
5168 static LRESULT
5169 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
5171 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5172 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
5174 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
5176 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
5178 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
5179 return 0;
5182 if ((lptbim->iButton == -1) ||
5183 ((lptbim->iButton < infoPtr->nNumButtons) &&
5184 (lptbim->iButton >= 0)))
5186 infoPtr->tbim = *lptbim;
5187 /* FIXME: don't need to update entire toolbar */
5188 InvalidateRect(hwnd, NULL, TRUE);
5190 else
5191 ERR("Invalid button index %d\n", lptbim->iButton);
5193 return 0;
5197 static LRESULT
5198 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
5200 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5202 infoPtr->clrInsertMark = (COLORREF)lParam;
5204 /* FIXME: don't need to update entire toolbar */
5205 InvalidateRect(hwnd, NULL, TRUE);
5207 return 0;
5211 static LRESULT
5212 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5214 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5216 infoPtr->nMaxTextRows = (INT)wParam;
5218 TOOLBAR_CalcToolbar(hwnd);
5219 return TRUE;
5223 /* MSDN gives slightly wrong info on padding.
5224 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
5225 * 2. It is not used to create a blank area between the edge of the button
5226 * and the text or image if TBSTYLE_LIST is set. It is used to control
5227 * the gap between the image and text.
5228 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
5229 * to control the bottom and right borders [with the border being
5230 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
5231 * is shared evenly on both sides of the button.
5232 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
5234 static LRESULT
5235 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
5237 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5238 DWORD oldPad;
5240 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5241 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
5242 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
5243 TRACE("cx=%ld, cy=%ld\n",
5244 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5245 return (LRESULT) oldPad;
5249 static LRESULT
5250 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5252 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5253 HWND hwndOldNotify;
5255 TRACE("\n");
5257 hwndOldNotify = infoPtr->hwndNotify;
5258 infoPtr->hwndNotify = (HWND)wParam;
5260 return (LRESULT)hwndOldNotify;
5264 static LRESULT
5265 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5267 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5268 LPRECT lprc = (LPRECT)lParam;
5270 TRACE("\n");
5272 if (LOWORD(wParam) > 1) {
5273 FIXME("multiple rows not supported!\n");
5276 if(infoPtr->nRows != LOWORD(wParam))
5278 infoPtr->nRows = LOWORD(wParam);
5280 /* recalculate toolbar */
5281 TOOLBAR_CalcToolbar (hwnd);
5283 /* repaint toolbar */
5284 InvalidateRect(hwnd, NULL, TRUE);
5287 /* return bounding rectangle */
5288 if (lprc) {
5289 lprc->left = infoPtr->rcBound.left;
5290 lprc->right = infoPtr->rcBound.right;
5291 lprc->top = infoPtr->rcBound.top;
5292 lprc->bottom = infoPtr->rcBound.bottom;
5295 return 0;
5299 static LRESULT
5300 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5302 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5303 TBUTTON_INFO *btnPtr;
5304 INT nIndex;
5306 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5307 if (nIndex == -1)
5308 return FALSE;
5310 btnPtr = &infoPtr->buttons[nIndex];
5312 /* if hidden state has changed the invalidate entire window and recalc */
5313 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5314 btnPtr->fsState = LOWORD(lParam);
5315 TOOLBAR_CalcToolbar (hwnd);
5316 InvalidateRect(hwnd, 0, TRUE);
5317 return TRUE;
5320 /* process state changing if current state doesn't match new state */
5321 if(btnPtr->fsState != LOWORD(lParam))
5323 btnPtr->fsState = LOWORD(lParam);
5324 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5327 return TRUE;
5331 static LRESULT
5332 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5334 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5336 return TRUE;
5340 inline static LRESULT
5341 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5343 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5345 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5347 infoPtr->hwndToolTip = (HWND)wParam;
5348 return 0;
5352 static LRESULT
5353 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5355 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5356 BOOL bTemp;
5358 TRACE("%s hwnd=%p\n",
5359 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5361 bTemp = infoPtr->bUnicode;
5362 infoPtr->bUnicode = (BOOL)wParam;
5364 return bTemp;
5368 static LRESULT
5369 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5371 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5373 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5374 comctl32_color.clrBtnHighlight :
5375 infoPtr->clrBtnHighlight;
5376 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5377 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5378 return 1;
5382 static LRESULT
5383 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5385 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5387 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5388 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5389 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5391 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5392 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5393 InvalidateRect(hwnd, NULL, TRUE);
5394 return 0;
5398 static LRESULT
5399 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5401 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5402 INT iOldVersion = infoPtr->iVersion;
5404 infoPtr->iVersion = iVersion;
5406 if (infoPtr->iVersion >= 5)
5407 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5409 return iOldVersion;
5413 static LRESULT
5414 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5416 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5417 WORD iString = HIWORD(wParam);
5418 WORD buffersize = LOWORD(wParam);
5419 LPSTR str = (LPSTR)lParam;
5420 LRESULT ret = -1;
5422 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5424 if (iString < infoPtr->nNumStrings)
5426 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5428 TRACE("returning %s\n", debugstr_a(str));
5430 else
5431 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5433 return ret;
5437 static LRESULT
5438 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5440 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5441 WORD iString = HIWORD(wParam);
5442 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5443 LPWSTR str = (LPWSTR)lParam;
5444 LRESULT ret = -1;
5446 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5448 if (iString < infoPtr->nNumStrings)
5450 len = min(len, strlenW(infoPtr->strings[iString]));
5451 ret = (len+1)*sizeof(WCHAR);
5452 memcpy(str, infoPtr->strings[iString], ret);
5453 str[len] = '\0';
5455 TRACE("returning %s\n", debugstr_w(str));
5457 else
5458 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5460 return ret;
5463 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5464 * is the maximum size of the toolbar? */
5465 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5467 SIZE * pSize = (SIZE*)lParam;
5468 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5469 return 0;
5473 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5474 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5475 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5476 * sends). */
5477 static LRESULT
5478 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5480 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5481 INT nOldHotItem = infoPtr->nHotItem;
5483 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5484 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5486 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5487 wParam = -1;
5489 /* NOTE: an application can still remove the hot item even if anchor
5490 * highlighting is enabled */
5492 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5494 GetFocus();
5496 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5499 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5500 * which controls the amount of spacing between the image and the text
5501 * of buttons for TBSTYLE_LIST toolbars. */
5502 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5504 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5506 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5508 if (lParam != 0)
5509 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5511 infoPtr->iListGap = (INT)wParam;
5513 InvalidateRect(hwnd, NULL, TRUE);
5515 return 0;
5518 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5519 * of image lists associated with the various states. */
5520 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5522 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5524 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5526 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5529 static LRESULT
5530 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5532 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5533 LPSIZE lpsize = (LPSIZE)lParam;
5535 if (lpsize == NULL)
5536 return FALSE;
5539 * Testing shows the following:
5540 * wParam = 0 adjust cx value
5541 * = 1 set cy value to max size.
5542 * lParam pointer to SIZE structure
5545 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5546 wParam, lParam, lpsize->cx, lpsize->cy);
5548 switch(wParam) {
5549 case 0:
5550 if (lpsize->cx == -1) {
5551 /* **** this is wrong, native measures each button and sets it */
5552 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5554 else if(HIWORD(lpsize->cx)) {
5555 RECT rc;
5556 HWND hwndParent = GetParent(hwnd);
5558 GetWindowRect(hwnd, &rc);
5559 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5560 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5561 rc.left, rc.top, rc.right, rc.bottom);
5562 lpsize->cx = max(rc.right-rc.left,
5563 infoPtr->rcBound.right - infoPtr->rcBound.left);
5565 else {
5566 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5568 break;
5569 case 1:
5570 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5571 break;
5572 default:
5573 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5574 wParam);
5575 return 0;
5577 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5578 lpsize->cx, lpsize->cy);
5579 return 1;
5582 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5584 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5586 InvalidateRect(hwnd, NULL, TRUE);
5587 return 1;
5591 static LRESULT
5592 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5594 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5595 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5596 LOGFONTW logFont;
5598 TRACE("hwnd = %p\n", hwnd);
5600 /* initialize info structure */
5601 infoPtr->nButtonHeight = 22;
5602 infoPtr->nButtonWidth = 24;
5603 infoPtr->nBitmapHeight = 15;
5604 infoPtr->nBitmapWidth = 16;
5606 infoPtr->nMaxTextRows = 1;
5607 infoPtr->cxMin = -1;
5608 infoPtr->cxMax = -1;
5609 infoPtr->nNumBitmaps = 0;
5610 infoPtr->nNumStrings = 0;
5612 infoPtr->bCaptured = FALSE;
5613 infoPtr->nButtonDown = -1;
5614 infoPtr->nButtonDrag = -1;
5615 infoPtr->nOldHit = -1;
5616 infoPtr->nHotItem = -1;
5617 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5618 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5619 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5620 infoPtr->bDragOutSent = FALSE;
5621 infoPtr->iVersion = 0;
5622 infoPtr->hwndSelf = hwnd;
5623 infoPtr->bDoRedraw = TRUE;
5624 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5625 infoPtr->clrBtnShadow = CLR_DEFAULT;
5626 infoPtr->szPadding.cx = DEFPAD_CX;
5627 infoPtr->szPadding.cy = DEFPAD_CY;
5628 infoPtr->iListGap = DEFLISTGAP;
5629 infoPtr->dwStyle = dwStyle;
5630 infoPtr->tbim.iButton = -1;
5631 GetClientRect(hwnd, &infoPtr->client_rect);
5632 infoPtr->bUnicode = infoPtr->hwndNotify &&
5633 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5635 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5636 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5638 if (dwStyle & TBSTYLE_TOOLTIPS) {
5639 /* Create tooltip control */
5640 infoPtr->hwndToolTip =
5641 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
5642 CW_USEDEFAULT, CW_USEDEFAULT,
5643 CW_USEDEFAULT, CW_USEDEFAULT,
5644 hwnd, 0, 0, 0);
5646 /* Send NM_TOOLTIPSCREATED notification */
5647 if (infoPtr->hwndToolTip)
5649 NMTOOLTIPSCREATED nmttc;
5651 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5653 TOOLBAR_SendNotify (&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
5657 OpenThemeData (hwnd, themeClass);
5659 TOOLBAR_CheckStyle (hwnd, dwStyle);
5661 TOOLBAR_CalcToolbar(hwnd);
5663 return 0;
5667 static LRESULT
5668 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5670 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5672 /* delete tooltip control */
5673 if (infoPtr->hwndToolTip)
5674 DestroyWindow (infoPtr->hwndToolTip);
5676 /* delete temporary buffer for tooltip text */
5677 Free (infoPtr->pszTooltipText);
5678 Free (infoPtr->bitmaps); /* bitmaps list */
5680 /* delete button data */
5681 if (infoPtr->buttons)
5682 Free (infoPtr->buttons);
5684 /* delete strings */
5685 if (infoPtr->strings) {
5686 INT i;
5687 for (i = 0; i < infoPtr->nNumStrings; i++)
5688 if (infoPtr->strings[i])
5689 Free (infoPtr->strings[i]);
5691 Free (infoPtr->strings);
5694 /* destroy internal image list */
5695 if (infoPtr->himlInt)
5696 ImageList_Destroy (infoPtr->himlInt);
5698 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5699 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5700 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5702 /* delete default font */
5703 if (infoPtr->hFont)
5704 DeleteObject (infoPtr->hDefaultFont);
5706 CloseThemeData (GetWindowTheme (hwnd));
5708 /* free toolbar info data */
5709 Free (infoPtr);
5710 SetWindowLongPtrW (hwnd, 0, 0);
5712 return 0;
5716 static LRESULT
5717 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5719 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5720 NMTBCUSTOMDRAW tbcd;
5721 INT ret = FALSE;
5722 DWORD ntfret;
5723 HTHEME theme = GetWindowTheme (hwnd);
5725 /* the app has told us not to redraw the toolbar */
5726 if (!infoPtr->bDoRedraw)
5727 return FALSE;
5729 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5730 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5731 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5732 tbcd.nmcd.hdc = (HDC)wParam;
5733 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5734 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5736 /* FIXME: in general the return flags *can* be or'ed together */
5737 switch (infoPtr->dwBaseCustDraw)
5739 case CDRF_DODEFAULT:
5740 break;
5741 case CDRF_SKIPDEFAULT:
5742 return TRUE;
5743 default:
5744 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5745 hwnd, ntfret);
5749 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5750 * to my parent for processing.
5752 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5753 POINT pt, ptorig;
5754 HDC hdc = (HDC)wParam;
5755 HWND parent;
5757 pt.x = 0;
5758 pt.y = 0;
5759 parent = GetParent(hwnd);
5760 MapWindowPoints(hwnd, parent, &pt, 1);
5761 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5762 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5763 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5765 if (!ret)
5766 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5768 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5769 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5770 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5771 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5772 tbcd.nmcd.hdc = (HDC)wParam;
5773 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5774 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5775 switch (infoPtr->dwBaseCustDraw)
5777 case CDRF_DODEFAULT:
5778 break;
5779 case CDRF_SKIPDEFAULT:
5780 return TRUE;
5781 default:
5782 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5783 hwnd, ntfret);
5786 return ret;
5790 static LRESULT
5791 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5793 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5795 return (LRESULT)infoPtr->hFont;
5799 static void
5800 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5802 INT i;
5803 INT nNewHotItem = infoPtr->nHotItem;
5805 for (i = 0; i < infoPtr->nNumButtons; i++)
5807 /* did we wrap? */
5808 if ((nNewHotItem + iDirection < 0) ||
5809 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5811 NMTBWRAPHOTITEM nmtbwhi;
5812 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5813 nmtbwhi.iDirection = iDirection;
5814 nmtbwhi.dwReason = dwReason;
5816 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5817 return;
5820 nNewHotItem += iDirection;
5821 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5823 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5824 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5826 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5827 break;
5832 static LRESULT
5833 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5835 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5836 NMKEY nmkey;
5838 nmkey.nVKey = (UINT)wParam;
5839 nmkey.uFlags = HIWORD(lParam);
5841 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5842 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5844 switch ((UINT)wParam)
5846 case VK_LEFT:
5847 case VK_UP:
5848 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5849 break;
5850 case VK_RIGHT:
5851 case VK_DOWN:
5852 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5853 break;
5854 case VK_SPACE:
5855 case VK_RETURN:
5856 if ((infoPtr->nHotItem >= 0) &&
5857 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5859 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5860 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5861 (LPARAM)hwnd);
5863 break;
5866 return 0;
5870 static LRESULT
5871 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5873 POINT pt;
5874 INT nHit;
5876 pt.x = (INT)LOWORD(lParam);
5877 pt.y = (INT)HIWORD(lParam);
5878 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5880 if (nHit >= 0)
5881 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5882 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5883 TOOLBAR_Customize (hwnd);
5885 return 0;
5889 static LRESULT
5890 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5892 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5893 TBUTTON_INFO *btnPtr;
5894 POINT pt;
5895 INT nHit;
5896 NMTOOLBARA nmtb;
5897 NMMOUSE nmmouse;
5898 BOOL bDragKeyPressed;
5900 TRACE("\n");
5902 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5903 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5904 else
5905 bDragKeyPressed = (wParam & MK_SHIFT);
5907 if (infoPtr->hwndToolTip)
5908 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5909 WM_LBUTTONDOWN, wParam, lParam);
5911 pt.x = (INT)LOWORD(lParam);
5912 pt.y = (INT)HIWORD(lParam);
5913 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5915 btnPtr = &infoPtr->buttons[nHit];
5917 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5919 infoPtr->nButtonDrag = nHit;
5920 SetCapture (hwnd);
5922 /* If drag cursor has not been loaded, load it.
5923 * Note: it doesn't need to be freed */
5924 if (!hCursorDrag)
5925 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5926 SetCursor(hCursorDrag);
5928 else if (nHit >= 0)
5930 RECT arrowRect;
5931 infoPtr->nOldHit = nHit;
5933 CopyRect(&arrowRect, &btnPtr->rect);
5934 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5936 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5937 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5938 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5939 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5940 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5941 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5943 LRESULT res;
5945 /* draw in pressed state */
5946 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5947 btnPtr->fsState |= TBSTATE_PRESSED;
5948 else
5949 btnPtr->bDropDownPressed = TRUE;
5950 RedrawWindow(hwnd,&btnPtr->rect,0,
5951 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5953 memset(&nmtb, 0, sizeof(nmtb));
5954 nmtb.iItem = btnPtr->idCommand;
5955 nmtb.rcButton = btnPtr->rect;
5956 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5957 TBN_DROPDOWN);
5958 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5960 if (res != TBDDRET_TREATPRESSED)
5962 MSG msg;
5964 /* redraw button in unpressed state */
5965 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5966 btnPtr->fsState &= ~TBSTATE_PRESSED;
5967 else
5968 btnPtr->bDropDownPressed = FALSE;
5969 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5971 /* find and set hot item
5972 * NOTE: native doesn't do this, but that is a bug */
5973 GetCursorPos(&pt);
5974 ScreenToClient(hwnd, &pt);
5975 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5976 if (!infoPtr->bAnchor || (nHit >= 0))
5977 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5979 /* remove any left mouse button down or double-click messages
5980 * so that we can get a toggle effect on the button */
5981 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5982 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5985 return 0;
5987 /* otherwise drop through and process as pushed */
5989 infoPtr->bCaptured = TRUE;
5990 infoPtr->nButtonDown = nHit;
5991 infoPtr->bDragOutSent = FALSE;
5993 btnPtr->fsState |= TBSTATE_PRESSED;
5995 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5997 if (btnPtr->fsState & TBSTATE_ENABLED)
5998 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5999 UpdateWindow(hwnd);
6000 SetCapture (hwnd);
6003 if (nHit >=0)
6005 memset(&nmtb, 0, sizeof(nmtb));
6006 nmtb.iItem = btnPtr->idCommand;
6007 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
6010 nmmouse.dwHitInfo = nHit;
6012 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
6013 if (nHit < 0)
6014 nmmouse.dwItemSpec = -1;
6015 else
6017 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6018 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6021 ClientToScreen(hwnd, &pt);
6022 nmmouse.pt = pt;
6024 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
6025 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
6027 return 0;
6030 static LRESULT
6031 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
6033 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6034 TBUTTON_INFO *btnPtr;
6035 POINT pt;
6036 INT nHit;
6037 INT nOldIndex = -1;
6038 BOOL bSendMessage = TRUE;
6039 NMHDR hdr;
6040 NMMOUSE nmmouse;
6041 NMTOOLBARA nmtb;
6043 if (infoPtr->hwndToolTip)
6044 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6045 WM_LBUTTONUP, wParam, lParam);
6047 pt.x = (INT)LOWORD(lParam);
6048 pt.y = (INT)HIWORD(lParam);
6049 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6051 if (!infoPtr->bAnchor || (nHit >= 0))
6052 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
6054 if (infoPtr->nButtonDrag >= 0) {
6055 RECT rcClient;
6056 NMHDR hdr;
6058 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
6059 ReleaseCapture();
6060 /* reset cursor */
6061 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
6063 GetClientRect(hwnd, &rcClient);
6064 if (PtInRect(&rcClient, pt))
6066 INT nButton = -1;
6067 if (nHit >= 0)
6068 nButton = nHit;
6069 else if (nHit < -1)
6070 nButton = -nHit;
6071 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
6072 nButton = -nHit;
6074 if (nButton == infoPtr->nButtonDrag)
6076 /* if the button is moved sightly left and we have a
6077 * separator there then remove it */
6078 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
6080 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
6081 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
6083 else /* else insert a separator before the dragged button */
6085 TBBUTTON tbb;
6086 memset(&tbb, 0, sizeof(tbb));
6087 tbb.fsStyle = BTNS_SEP;
6088 tbb.iString = -1;
6089 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
6092 else
6094 if (nButton == -1)
6096 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
6097 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
6098 else
6099 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
6101 else
6102 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
6105 else
6107 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
6108 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
6111 /* button under cursor changed so need to re-set hot item */
6112 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
6113 infoPtr->nButtonDrag = -1;
6115 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
6117 else if (infoPtr->nButtonDown >= 0) {
6118 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6119 btnPtr->fsState &= ~TBSTATE_PRESSED;
6121 if (btnPtr->fsStyle & BTNS_CHECK) {
6122 if (btnPtr->fsStyle & BTNS_GROUP) {
6123 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
6124 nHit);
6125 if (nOldIndex == nHit)
6126 bSendMessage = FALSE;
6127 if ((nOldIndex != nHit) &&
6128 (nOldIndex != -1))
6129 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
6130 btnPtr->fsState |= TBSTATE_CHECKED;
6132 else {
6133 if (btnPtr->fsState & TBSTATE_CHECKED)
6134 btnPtr->fsState &= ~TBSTATE_CHECKED;
6135 else
6136 btnPtr->fsState |= TBSTATE_CHECKED;
6140 if (nOldIndex != -1)
6141 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
6144 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
6145 * that resets bCaptured and btn TBSTATE_PRESSED flags,
6146 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
6148 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
6149 ReleaseCapture ();
6150 infoPtr->nButtonDown = -1;
6152 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
6153 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
6154 NM_RELEASEDCAPTURE);
6156 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
6157 * TBN_BEGINDRAG
6159 memset(&nmtb, 0, sizeof(nmtb));
6160 nmtb.iItem = btnPtr->idCommand;
6161 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
6162 TBN_ENDDRAG);
6164 if (btnPtr->fsState & TBSTATE_ENABLED)
6166 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
6167 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
6171 /* !!! Undocumented - toolbar at 4.71 level and above sends
6172 * NM_CLICK with the NMMOUSE structure. */
6173 nmmouse.dwHitInfo = nHit;
6175 if (nHit < 0)
6176 nmmouse.dwItemSpec = -1;
6177 else
6179 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6180 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6183 ClientToScreen(hwnd, &pt);
6184 nmmouse.pt = pt;
6186 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
6187 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
6189 return 0;
6192 static LRESULT
6193 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
6195 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6196 INT nHit;
6197 NMMOUSE nmmouse;
6198 POINT pt;
6200 pt.x = LOWORD(lParam);
6201 pt.y = HIWORD(lParam);
6203 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
6204 nmmouse.dwHitInfo = nHit;
6206 if (nHit < 0) {
6207 nmmouse.dwItemSpec = -1;
6208 } else {
6209 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6210 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6213 ClientToScreen(hwnd, &pt);
6214 nmmouse.pt = pt;
6216 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
6217 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
6219 return 0;
6222 static LRESULT
6223 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
6225 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6226 NMHDR nmhdr;
6228 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
6229 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
6231 return 0;
6234 static LRESULT
6235 TOOLBAR_CaptureChanged(HWND hwnd)
6237 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6238 TBUTTON_INFO *btnPtr;
6240 infoPtr->bCaptured = FALSE;
6242 if (infoPtr->nButtonDown >= 0)
6244 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6245 btnPtr->fsState &= ~TBSTATE_PRESSED;
6247 infoPtr->nOldHit = -1;
6249 if (btnPtr->fsState & TBSTATE_ENABLED)
6250 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6252 return 0;
6255 static LRESULT
6256 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6258 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6259 TBUTTON_INFO *hotBtnPtr;
6261 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
6263 /* don't remove hot effects when in anchor highlighting mode or when a
6264 * drop-down button is pressed */
6265 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
6266 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6268 if (infoPtr->nOldHit < 0)
6269 return TRUE;
6271 /* If the last button we were over is depressed then make it not */
6272 /* depressed and redraw it */
6273 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6275 TBUTTON_INFO *btnPtr;
6276 RECT rc1;
6278 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6280 btnPtr->fsState &= ~TBSTATE_PRESSED;
6282 rc1 = hotBtnPtr->rect;
6283 InflateRect (&rc1, 1, 1);
6284 InvalidateRect (hwnd, &rc1, TRUE);
6287 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6289 NMTOOLBARW nmt;
6290 ZeroMemory(&nmt, sizeof(nmt));
6291 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6292 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6293 infoPtr->bDragOutSent = TRUE;
6296 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6298 return TRUE;
6301 static LRESULT
6302 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6304 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6305 POINT pt;
6306 TRACKMOUSEEVENT trackinfo;
6307 INT nHit;
6308 TBUTTON_INFO *btnPtr;
6310 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6311 /* fill in the TRACKMOUSEEVENT struct */
6312 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6313 trackinfo.dwFlags = TME_QUERY;
6314 trackinfo.hwndTrack = hwnd;
6315 trackinfo.dwHoverTime = HOVER_DEFAULT;
6317 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6318 _TrackMouseEvent(&trackinfo);
6320 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6321 if(!(trackinfo.dwFlags & TME_LEAVE)) {
6322 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6324 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6325 /* and can properly deactivate the hot toolbar button */
6326 _TrackMouseEvent(&trackinfo);
6330 if (infoPtr->hwndToolTip)
6331 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6332 WM_MOUSEMOVE, wParam, lParam);
6334 pt.x = (INT)LOWORD(lParam);
6335 pt.y = (INT)HIWORD(lParam);
6337 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6339 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6340 && (!infoPtr->bAnchor || (nHit >= 0)))
6341 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6343 if (infoPtr->nOldHit != nHit)
6345 if (infoPtr->bCaptured)
6347 if (!infoPtr->bDragOutSent)
6349 NMTOOLBARW nmt;
6350 ZeroMemory(&nmt, sizeof(nmt));
6351 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6352 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6353 infoPtr->bDragOutSent = TRUE;
6356 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6357 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6358 btnPtr->fsState &= ~TBSTATE_PRESSED;
6359 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6361 else if (nHit == infoPtr->nButtonDown) {
6362 btnPtr->fsState |= TBSTATE_PRESSED;
6363 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6365 infoPtr->nOldHit = nHit;
6369 return 0;
6373 inline static LRESULT
6374 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6376 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6377 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6378 /* else */
6379 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6383 inline static LRESULT
6384 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6386 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6387 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6389 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6393 static LRESULT
6394 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6396 TOOLBAR_INFO *infoPtr;
6397 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6398 DWORD styleadd = 0;
6400 /* allocate memory for info structure */
6401 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6402 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6404 /* paranoid!! */
6405 infoPtr->dwStructSize = sizeof(TBBUTTON);
6406 infoPtr->nRows = 1;
6407 infoPtr->nWidth = 0;
6409 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6410 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6411 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6412 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6415 /* native control does:
6416 * Get a lot of colors and brushes
6417 * WM_NOTIFYFORMAT
6418 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6419 * CreateFontIndirectW(adr1)
6420 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6421 * hdc = GetDC(toolbar)
6422 * GetSystemMetrics(0x48)
6423 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6424 * 0, 0, 0, 0, "MARLETT")
6425 * oldfnt = SelectObject(hdc, fnt2)
6426 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6427 * GetTextMetricsW(hdc, adr3)
6428 * SelectObject(hdc, oldfnt)
6429 * DeleteObject(fnt2)
6430 * ReleaseDC(hdc)
6431 * InvalidateRect(toolbar, 0, 1)
6432 * SetWindowLongW(toolbar, 0, addr)
6433 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6434 * WM_STYLECHANGING
6435 * CallWinEx old new
6436 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6437 * ie 2 0x4600094c 0x4600094c 0x4600894d
6438 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6439 * rebar 0x50008844 0x40008844 0x50008845
6440 * pager 0x50000844 0x40000844 0x50008845
6441 * IC35mgr 0x5400084e **nochange**
6442 * on entry to _NCCREATE 0x5400084e
6443 * rowlist 0x5400004e **nochange**
6444 * on entry to _NCCREATE 0x5400004e
6448 /* I think the code below is a bug, but it is the way that the native
6449 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6450 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6451 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6452 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6453 * Somehow, the only cases of this seem to be MFC programs.
6455 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6456 * does not occur in the WM_STYLECHANGING routine.
6457 * (Guy Albertelli 9/2001)
6460 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6461 && !(cs->style & TBSTYLE_TRANSPARENT))
6462 styleadd |= TBSTYLE_TRANSPARENT;
6463 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6464 styleadd |= CCS_TOP; /* default to top */
6465 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6468 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6472 static LRESULT
6473 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6475 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6476 RECT rcWindow;
6477 HDC hdc;
6479 if (dwStyle & WS_MINIMIZE)
6480 return 0; /* Nothing to do */
6482 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6484 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6485 return 0;
6487 if (!(dwStyle & CCS_NODIVIDER))
6489 GetWindowRect (hwnd, &rcWindow);
6490 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6491 if( dwStyle & WS_BORDER )
6492 OffsetRect (&rcWindow, 1, 1);
6493 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6496 ReleaseDC( hwnd, hdc );
6498 return 0;
6502 /* handles requests from the tooltip control on what text to display */
6503 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6505 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6507 TRACE("button index = %d\n", index);
6509 Free (infoPtr->pszTooltipText);
6510 infoPtr->pszTooltipText = NULL;
6512 if (index < 0)
6513 return 0;
6515 if (infoPtr->bUnicode)
6517 WCHAR wszBuffer[INFOTIPSIZE+1];
6518 NMTBGETINFOTIPW tbgit;
6519 unsigned int len; /* in chars */
6521 wszBuffer[0] = '\0';
6522 wszBuffer[INFOTIPSIZE] = '\0';
6524 tbgit.pszText = wszBuffer;
6525 tbgit.cchTextMax = INFOTIPSIZE;
6526 tbgit.iItem = lpnmtdi->hdr.idFrom;
6527 tbgit.lParam = infoPtr->buttons[index].dwData;
6529 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6531 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6533 len = strlenW(tbgit.pszText);
6534 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6536 /* need to allocate temporary buffer in infoPtr as there
6537 * isn't enough space in buffer passed to us by the
6538 * tooltip control */
6539 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6540 if (infoPtr->pszTooltipText)
6542 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6543 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6544 return 0;
6547 else if (len > 0)
6549 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6550 return 0;
6553 else
6555 CHAR szBuffer[INFOTIPSIZE+1];
6556 NMTBGETINFOTIPA tbgit;
6557 unsigned int len; /* in chars */
6559 szBuffer[0] = '\0';
6560 szBuffer[INFOTIPSIZE] = '\0';
6562 tbgit.pszText = szBuffer;
6563 tbgit.cchTextMax = INFOTIPSIZE;
6564 tbgit.iItem = lpnmtdi->hdr.idFrom;
6565 tbgit.lParam = infoPtr->buttons[index].dwData;
6567 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6569 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6571 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6572 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6574 /* need to allocate temporary buffer in infoPtr as there
6575 * isn't enough space in buffer passed to us by the
6576 * tooltip control */
6577 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6578 if (infoPtr->pszTooltipText)
6580 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6581 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6582 return 0;
6585 else if (len > 0)
6587 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6588 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6589 return 0;
6593 /* if button has text, but it is not shown then automatically
6594 * use that text as tooltip */
6595 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6596 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6598 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6599 unsigned int len = pszText ? strlenW(pszText) : 0;
6601 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6603 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6605 /* need to allocate temporary buffer in infoPtr as there
6606 * isn't enough space in buffer passed to us by the
6607 * tooltip control */
6608 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6609 if (infoPtr->pszTooltipText)
6611 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6612 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6613 return 0;
6616 else if (len > 0)
6618 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6619 return 0;
6623 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6625 /* last resort: send notification on to app */
6626 /* FIXME: find out what is really used here */
6627 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6631 inline static LRESULT
6632 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6634 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6635 LPNMHDR lpnmh = (LPNMHDR)lParam;
6637 switch (lpnmh->code)
6639 case PGN_CALCSIZE:
6641 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6643 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6644 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6645 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6646 lppgc->iWidth);
6648 else {
6649 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6650 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6651 lppgc->iHeight);
6653 return 0;
6656 case PGN_SCROLL:
6658 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6660 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6661 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6662 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6663 lppgs->iScroll, lppgs->iDir);
6664 return 0;
6667 case TTN_GETDISPINFOW:
6668 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6670 case TTN_GETDISPINFOA:
6671 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6672 return 0;
6674 default:
6675 return 0;
6680 static LRESULT
6681 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6683 LRESULT format;
6685 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6687 if (lParam == NF_QUERY)
6688 return NFR_UNICODE;
6690 if (lParam == NF_REQUERY) {
6691 format = SendMessageW(infoPtr->hwndNotify,
6692 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6693 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6694 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6695 format);
6696 format = NFR_ANSI;
6698 return format;
6700 return 0;
6704 static LRESULT
6705 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6707 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6708 HDC hdc;
6709 PAINTSTRUCT ps;
6711 /* fill ps.rcPaint with a default rect */
6712 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6714 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6716 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6717 ps.rcPaint.left, ps.rcPaint.top,
6718 ps.rcPaint.right, ps.rcPaint.bottom);
6720 TOOLBAR_Refresh (hwnd, hdc, &ps);
6721 if (!wParam) EndPaint (hwnd, &ps);
6723 return 0;
6727 static LRESULT
6728 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6730 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6732 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6734 /* make first item hot */
6735 if (infoPtr->nNumButtons > 0)
6736 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6738 return 0;
6742 static LRESULT
6743 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6744 /*****************************************************
6746 * Function;
6747 * Handles the WM_SETREDRAW message.
6749 * Documentation:
6750 * According to testing V4.71 of COMCTL32 returns the
6751 * *previous* status of the redraw flag (either 0 or 1)
6752 * instead of the MSDN documented value of 0 if handled.
6753 * (For laughs see the "consistency" with same function
6754 * in rebar.)
6756 *****************************************************/
6758 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6759 BOOL oldredraw = infoPtr->bDoRedraw;
6761 TRACE("set to %s\n",
6762 (wParam) ? "TRUE" : "FALSE");
6763 infoPtr->bDoRedraw = (BOOL) wParam;
6764 if (wParam) {
6765 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6767 return (oldredraw) ? 1 : 0;
6771 static LRESULT
6772 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6774 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6776 TRACE("sizing toolbar!\n");
6778 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6780 RECT delta_width, delta_height, client, dummy;
6781 DWORD min_x, max_x, min_y, max_y;
6782 TBUTTON_INFO *btnPtr;
6783 INT i;
6785 GetClientRect(hwnd, &client);
6786 if(client.right > infoPtr->client_rect.right)
6788 min_x = infoPtr->client_rect.right;
6789 max_x = client.right;
6791 else
6793 max_x = infoPtr->client_rect.right;
6794 min_x = client.right;
6796 if(client.bottom > infoPtr->client_rect.bottom)
6798 min_y = infoPtr->client_rect.bottom;
6799 max_y = client.bottom;
6801 else
6803 max_y = infoPtr->client_rect.bottom;
6804 min_y = client.bottom;
6807 SetRect(&delta_width, min_x, 0, max_x, min_y);
6808 SetRect(&delta_height, 0, min_y, max_x, max_y);
6810 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6811 btnPtr = infoPtr->buttons;
6812 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6813 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6814 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6815 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6817 GetClientRect(hwnd, &infoPtr->client_rect);
6818 TOOLBAR_AutoSize(hwnd);
6819 return 0;
6823 static LRESULT
6824 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6826 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6828 if (nType == GWL_STYLE)
6830 if (lpStyle->styleNew & TBSTYLE_LIST)
6831 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6832 else
6833 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6835 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6837 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6839 infoPtr->dwStyle = lpStyle->styleNew;
6841 /* only resize if one of the CCS_* styles was changed */
6842 if ((infoPtr->dwStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6844 TOOLBAR_AutoSize (hwnd);
6846 InvalidateRect(hwnd, NULL, TRUE);
6850 return 0;
6854 static LRESULT
6855 TOOLBAR_SysColorChange (HWND hwnd)
6857 COMCTL32_RefreshSysColors();
6859 return 0;
6863 /* update theme after a WM_THEMECHANGED message */
6864 static LRESULT theme_changed (HWND hwnd)
6866 HTHEME theme = GetWindowTheme (hwnd);
6867 CloseThemeData (theme);
6868 OpenThemeData (hwnd, themeClass);
6869 return 0;
6873 static LRESULT WINAPI
6874 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6876 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6878 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6879 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6881 if (!infoPtr && (uMsg != WM_NCCREATE))
6882 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6884 switch (uMsg)
6886 case TB_ADDBITMAP:
6887 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6889 case TB_ADDBUTTONSA:
6890 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6892 case TB_ADDBUTTONSW:
6893 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6895 case TB_ADDSTRINGA:
6896 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6898 case TB_ADDSTRINGW:
6899 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6901 case TB_AUTOSIZE:
6902 return TOOLBAR_AutoSize (hwnd);
6904 case TB_BUTTONCOUNT:
6905 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6907 case TB_BUTTONSTRUCTSIZE:
6908 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6910 case TB_CHANGEBITMAP:
6911 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6913 case TB_CHECKBUTTON:
6914 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6916 case TB_COMMANDTOINDEX:
6917 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6919 case TB_CUSTOMIZE:
6920 return TOOLBAR_Customize (hwnd);
6922 case TB_DELETEBUTTON:
6923 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6925 case TB_ENABLEBUTTON:
6926 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6928 case TB_GETANCHORHIGHLIGHT:
6929 return TOOLBAR_GetAnchorHighlight (hwnd);
6931 case TB_GETBITMAP:
6932 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6934 case TB_GETBITMAPFLAGS:
6935 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6937 case TB_GETBUTTON:
6938 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6940 case TB_GETBUTTONINFOA:
6941 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6943 case TB_GETBUTTONINFOW:
6944 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6946 case TB_GETBUTTONSIZE:
6947 return TOOLBAR_GetButtonSize (hwnd);
6949 case TB_GETBUTTONTEXTA:
6950 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6952 case TB_GETBUTTONTEXTW:
6953 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6955 case TB_GETDISABLEDIMAGELIST:
6956 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6958 case TB_GETEXTENDEDSTYLE:
6959 return TOOLBAR_GetExtendedStyle (hwnd);
6961 case TB_GETHOTIMAGELIST:
6962 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6964 case TB_GETHOTITEM:
6965 return TOOLBAR_GetHotItem (hwnd);
6967 case TB_GETIMAGELIST:
6968 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6970 case TB_GETINSERTMARK:
6971 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6973 case TB_GETINSERTMARKCOLOR:
6974 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6976 case TB_GETITEMRECT:
6977 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6979 case TB_GETMAXSIZE:
6980 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6982 /* case TB_GETOBJECT: */ /* 4.71 */
6984 case TB_GETPADDING:
6985 return TOOLBAR_GetPadding (hwnd);
6987 case TB_GETRECT:
6988 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6990 case TB_GETROWS:
6991 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6993 case TB_GETSTATE:
6994 return TOOLBAR_GetState (hwnd, wParam, lParam);
6996 case TB_GETSTRINGA:
6997 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6999 case TB_GETSTRINGW:
7000 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
7002 case TB_GETSTYLE:
7003 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
7005 case TB_GETTEXTROWS:
7006 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
7008 case TB_GETTOOLTIPS:
7009 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
7011 case TB_GETUNICODEFORMAT:
7012 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
7014 case TB_HIDEBUTTON:
7015 return TOOLBAR_HideButton (hwnd, wParam, lParam);
7017 case TB_HITTEST:
7018 return TOOLBAR_HitTest (hwnd, wParam, lParam);
7020 case TB_INDETERMINATE:
7021 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
7023 case TB_INSERTBUTTONA:
7024 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
7026 case TB_INSERTBUTTONW:
7027 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
7029 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
7031 case TB_ISBUTTONCHECKED:
7032 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
7034 case TB_ISBUTTONENABLED:
7035 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
7037 case TB_ISBUTTONHIDDEN:
7038 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
7040 case TB_ISBUTTONHIGHLIGHTED:
7041 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
7043 case TB_ISBUTTONINDETERMINATE:
7044 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
7046 case TB_ISBUTTONPRESSED:
7047 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
7049 case TB_LOADIMAGES:
7050 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
7052 case TB_MAPACCELERATORA:
7053 case TB_MAPACCELERATORW:
7054 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
7056 case TB_MARKBUTTON:
7057 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
7059 case TB_MOVEBUTTON:
7060 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
7062 case TB_PRESSBUTTON:
7063 return TOOLBAR_PressButton (hwnd, wParam, lParam);
7065 case TB_REPLACEBITMAP:
7066 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
7068 case TB_SAVERESTOREA:
7069 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
7071 case TB_SAVERESTOREW:
7072 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
7074 case TB_SETANCHORHIGHLIGHT:
7075 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
7077 case TB_SETBITMAPSIZE:
7078 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
7080 case TB_SETBUTTONINFOA:
7081 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
7083 case TB_SETBUTTONINFOW:
7084 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
7086 case TB_SETBUTTONSIZE:
7087 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
7089 case TB_SETBUTTONWIDTH:
7090 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
7092 case TB_SETCMDID:
7093 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
7095 case TB_SETDISABLEDIMAGELIST:
7096 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
7098 case TB_SETDRAWTEXTFLAGS:
7099 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
7101 case TB_SETEXTENDEDSTYLE:
7102 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
7104 case TB_SETHOTIMAGELIST:
7105 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
7107 case TB_SETHOTITEM:
7108 return TOOLBAR_SetHotItem (hwnd, wParam);
7110 case TB_SETIMAGELIST:
7111 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
7113 case TB_SETINDENT:
7114 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
7116 case TB_SETINSERTMARK:
7117 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
7119 case TB_SETINSERTMARKCOLOR:
7120 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
7122 case TB_SETMAXTEXTROWS:
7123 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
7125 case TB_SETPADDING:
7126 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
7128 case TB_SETPARENT:
7129 return TOOLBAR_SetParent (hwnd, wParam, lParam);
7131 case TB_SETROWS:
7132 return TOOLBAR_SetRows (hwnd, wParam, lParam);
7134 case TB_SETSTATE:
7135 return TOOLBAR_SetState (hwnd, wParam, lParam);
7137 case TB_SETSTYLE:
7138 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
7140 case TB_SETTOOLTIPS:
7141 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
7143 case TB_SETUNICODEFORMAT:
7144 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
7146 case TB_UNKWN45D:
7147 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
7149 case TB_UNKWN45E:
7150 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
7152 case TB_UNKWN460:
7153 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
7155 case TB_UNKWN462:
7156 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
7158 case TB_UNKWN463:
7159 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
7161 case TB_UNKWN464:
7162 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
7164 /* Common Control Messages */
7166 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
7167 case CCM_GETCOLORSCHEME:
7168 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7170 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
7171 case CCM_SETCOLORSCHEME:
7172 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7174 case CCM_GETVERSION:
7175 return TOOLBAR_GetVersion (hwnd);
7177 case CCM_SETVERSION:
7178 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
7181 /* case WM_CHAR: */
7183 case WM_CREATE:
7184 return TOOLBAR_Create (hwnd, wParam, lParam);
7186 case WM_DESTROY:
7187 return TOOLBAR_Destroy (hwnd, wParam, lParam);
7189 case WM_ERASEBKGND:
7190 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
7192 case WM_GETFONT:
7193 return TOOLBAR_GetFont (hwnd, wParam, lParam);
7195 case WM_KEYDOWN:
7196 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
7198 /* case WM_KILLFOCUS: */
7200 case WM_LBUTTONDBLCLK:
7201 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
7203 case WM_LBUTTONDOWN:
7204 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
7206 case WM_LBUTTONUP:
7207 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
7209 case WM_RBUTTONUP:
7210 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
7212 case WM_RBUTTONDBLCLK:
7213 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
7215 case WM_MOUSEMOVE:
7216 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
7218 case WM_MOUSELEAVE:
7219 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
7221 case WM_CAPTURECHANGED:
7222 return TOOLBAR_CaptureChanged(hwnd);
7224 case WM_NCACTIVATE:
7225 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7227 case WM_NCCALCSIZE:
7228 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7230 case WM_NCCREATE:
7231 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7233 case WM_NCPAINT:
7234 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7236 case WM_NOTIFY:
7237 return TOOLBAR_Notify (hwnd, wParam, lParam);
7239 case WM_NOTIFYFORMAT:
7240 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7242 case WM_PRINTCLIENT:
7243 case WM_PAINT:
7244 return TOOLBAR_Paint (hwnd, wParam);
7246 case WM_SETFOCUS:
7247 return TOOLBAR_SetFocus (hwnd, wParam);
7249 case WM_SETREDRAW:
7250 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7252 case WM_SIZE:
7253 return TOOLBAR_Size (hwnd, wParam, lParam);
7255 case WM_STYLECHANGED:
7256 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7258 case WM_SYSCOLORCHANGE:
7259 return TOOLBAR_SysColorChange (hwnd);
7261 case WM_THEMECHANGED:
7262 return theme_changed (hwnd);
7264 /* case WM_WININICHANGE: */
7266 case WM_CHARTOITEM:
7267 case WM_COMMAND:
7268 case WM_DRAWITEM:
7269 case WM_MEASUREITEM:
7270 case WM_VKEYTOITEM:
7271 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7273 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7274 case PGM_FORWARDMOUSE:
7275 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7277 default:
7278 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7279 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7280 uMsg, wParam, lParam);
7281 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7286 VOID
7287 TOOLBAR_Register (void)
7289 WNDCLASSW wndClass;
7291 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7292 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7293 wndClass.lpfnWndProc = ToolbarWindowProc;
7294 wndClass.cbClsExtra = 0;
7295 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7296 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7297 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7298 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7300 RegisterClassW (&wndClass);
7304 VOID
7305 TOOLBAR_Unregister (void)
7307 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7310 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7312 HIMAGELIST himlold;
7313 PIMLENTRY c = NULL;
7315 /* Check if the entry already exists */
7316 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7318 /* If this is a new entry we must create it and insert into the array */
7319 if (!c)
7321 PIMLENTRY *pnies;
7323 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7324 c->id = id;
7326 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7327 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7328 pnies[*cies] = c;
7329 (*cies)++;
7331 Free(*pies);
7332 *pies = pnies;
7335 himlold = c->himl;
7336 c->himl = himl;
7338 return himlold;
7342 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7344 int i;
7346 for (i = 0; i < *cies; i++)
7347 Free((*pies)[i]);
7349 Free(*pies);
7351 *cies = 0;
7352 *pies = NULL;
7356 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7358 PIMLENTRY c = NULL;
7360 if (pies != NULL)
7362 int i;
7364 for (i = 0; i < cies; i++)
7366 if (pies[i]->id == id)
7368 c = pies[i];
7369 break;
7374 return c;
7378 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7380 HIMAGELIST himlDef = 0;
7381 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7383 if (pie)
7384 himlDef = pie->himl;
7386 return himlDef;
7390 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7392 if (infoPtr->bUnicode)
7393 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7394 else
7396 CHAR Buffer[256];
7397 NMTOOLBARA nmtba;
7398 BOOL bRet = FALSE;
7400 nmtba.iItem = nmtb->iItem;
7401 nmtba.pszText = Buffer;
7402 nmtba.cchText = 256;
7403 ZeroMemory(nmtba.pszText, nmtba.cchText);
7405 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7407 int ccht = strlen(nmtba.pszText);
7408 if (ccht)
7409 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7410 nmtb->pszText, nmtb->cchText);
7412 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7413 bRet = TRUE;
7416 return bRet;
7421 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7422 int iItem, PCUSTOMBUTTON btnInfo)
7424 NMTOOLBARW nmtb;
7426 /* MSDN states that iItem is the index of the button, rather than the
7427 * command ID as used by every other NMTOOLBAR notification */
7428 nmtb.iItem = iItem;
7429 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7431 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);