comctl32: toolbar: Add a LayoutToolbar that works like CalcToolbar but doesn't overwr...
[wine/hacks.git] / dlls / comctl32 / toolbar.c
blob99c329e9d02937e4446a796417094f91981965ae
1 /*
2 * Toolbar control
4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * NOTES
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
31 * TODO:
32 * - Styles:
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
35 * - Messages:
36 * - TB_GETMETRICS
37 * - TB_GETOBJECT
38 * - TB_INSERTMARKHITTEST
39 * - TB_SAVERESTORE
40 * - TB_SETMETRICS
41 * - WM_WININICHANGE
42 * - Notifications:
43 * - NM_CHAR
44 * - TBN_GETOBJECT
45 * - TBN_SAVE
46 * - Button wrapping (under construction).
47 * - Fix TB_SETROWS.
48 * - iListGap custom draw support.
50 * Testing:
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
71 #include <stdarg.h>
72 #include <string.h>
74 #include "windef.h"
75 #include "winbase.h"
76 #include "winreg.h"
77 #include "wingdi.h"
78 #include "winuser.h"
79 #include "wine/unicode.h"
80 #include "winnls.h"
81 #include "commctrl.h"
82 #include "comctl32.h"
83 #include "uxtheme.h"
84 #include "tmschema.h"
85 #include "wine/debug.h"
87 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
89 static HCURSOR hCursorDrag = NULL;
91 typedef struct
93 INT iBitmap;
94 INT idCommand;
95 BYTE fsState;
96 BYTE fsStyle;
97 BYTE bHot;
98 BYTE bDropDownPressed;
99 DWORD_PTR dwData;
100 INT_PTR iString;
101 INT nRow;
102 RECT rect;
103 INT cx; /* manually set size */
104 } TBUTTON_INFO;
106 typedef struct
108 UINT nButtons;
109 HINSTANCE hInst;
110 UINT nID;
111 } TBITMAP_INFO;
113 typedef struct
115 HIMAGELIST himl;
116 INT id;
117 } IMLENTRY, *PIMLENTRY;
119 typedef struct
121 DWORD dwStructSize; /* size of TBBUTTON struct */
122 INT nWidth; /* width of the toolbar */
123 RECT client_rect;
124 RECT rcBound; /* bounding rectangle */
125 INT nButtonHeight;
126 INT nButtonWidth;
127 INT nBitmapHeight;
128 INT nVBitmapHeight; /* see TOOLBAR_Create for an explanation */
129 INT nBitmapWidth;
130 INT nIndent;
131 INT nRows; /* number of button rows */
132 INT nMaxTextRows; /* maximum number of text rows */
133 INT cxMin; /* minimum button width */
134 INT cxMax; /* maximum button width */
135 INT nNumButtons; /* number of buttons */
136 INT nNumBitmaps; /* number of bitmaps */
137 INT nNumStrings; /* number of strings */
138 INT nNumBitmapInfos;
139 INT nButtonDown; /* toolbar button being pressed or -1 if none */
140 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
141 INT nOldHit;
142 INT nHotItem; /* index of the "hot" item */
143 SIZE szPadding; /* padding values around button */
144 INT iListGap; /* default gap between text and image for toolbar with list style */
145 HFONT hDefaultFont;
146 HFONT hFont; /* text font */
147 HIMAGELIST himlInt; /* image list created internally */
148 PIMLENTRY *himlDef; /* default image list array */
149 INT cimlDef; /* default image list array count */
150 PIMLENTRY *himlHot; /* hot image list array */
151 INT cimlHot; /* hot image list array count */
152 PIMLENTRY *himlDis; /* disabled image list array */
153 INT cimlDis; /* disabled image list array count */
154 HWND hwndToolTip; /* handle to tool tip control */
155 HWND hwndNotify; /* handle to the window that gets notifications */
156 HWND hwndSelf; /* my own handle */
157 BOOL bAnchor; /* anchor highlight enabled */
158 BOOL bDoRedraw; /* Redraw status */
159 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
160 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
161 BOOL bCaptured; /* mouse captured? */
162 DWORD dwStyle; /* regular toolbar style */
163 DWORD dwExStyle; /* extended toolbar style */
164 DWORD dwDTFlags; /* DrawText flags */
166 COLORREF clrInsertMark; /* insert mark color */
167 COLORREF clrBtnHighlight; /* color for Flat Separator */
168 COLORREF clrBtnShadow; /* color for Flag Separator */
169 INT iVersion;
170 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
171 * for TTN_GETDISPINFOW notification */
172 TBINSERTMARK tbim; /* info on insertion mark */
173 TBUTTON_INFO *buttons; /* pointer to button array */
174 LPWSTR *strings; /* pointer to string array */
175 TBITMAP_INFO *bitmaps;
176 } TOOLBAR_INFO, *PTOOLBAR_INFO;
179 /* used by customization dialog */
180 typedef struct
182 PTOOLBAR_INFO tbInfo;
183 HWND tbHwnd;
184 } CUSTDLG_INFO, *PCUSTDLG_INFO;
186 typedef struct
188 TBBUTTON btn;
189 BOOL bVirtual;
190 BOOL bRemovable;
191 WCHAR text[64];
192 } CUSTOMBUTTON, *PCUSTOMBUTTON;
194 typedef enum
196 IMAGE_LIST_DEFAULT,
197 IMAGE_LIST_HOT,
198 IMAGE_LIST_DISABLED
199 } IMAGE_LIST_TYPE;
201 #define SEPARATOR_WIDTH 8
202 #define TOP_BORDER 2
203 #define BOTTOM_BORDER 2
204 #define DDARROW_WIDTH 11
205 #define ARROW_HEIGHT 3
206 #define INSERTMARK_WIDTH 2
208 #define DEFPAD_CX 7
209 #define DEFPAD_CY 6
210 #define DEFLISTGAP 4
212 /* vertical padding used in list mode when image is present */
213 #define LISTPAD_CY 9
215 /* how wide to treat the bitmap if it isn't present */
216 #define NONLIST_NOTEXT_OFFSET 2
218 #define TOOLBAR_NOWHERE (-1)
220 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
221 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
222 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
224 /* Used to find undocumented extended styles */
225 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
226 TBSTYLE_EX_UNDOC1 | \
227 TBSTYLE_EX_MIXEDBUTTONS | \
228 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
230 /* all of the CCS_ styles */
231 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
232 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
234 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
235 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
236 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
237 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
238 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
240 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
242 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
243 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
244 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
245 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
246 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
247 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
248 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
249 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
250 static void TOOLBAR_LayoutToolbar(HWND hwnd);
251 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
252 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
253 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button);
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=(%d,%d)-(%d,%d)\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=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\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=%08x, 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=(%d,%d)-(%d,%d)\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, DWORD dwItemCDFlag)
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=(%d,%d)-(%d,%d)\n", debugstr_w(lpText),
566 rcText->left, rcText->top, rcText->right, rcText->bottom);
568 hOldFont = SelectObject (hdc, infoPtr->hFont);
569 if ((state & CDIS_HOT) && (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) && !(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) && !(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,
684 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
686 HIMAGELIST himl = NULL;
687 BOOL draw_masked = FALSE;
688 INT index;
689 INT offset = 0;
690 UINT draw_flags = ILD_TRANSPARENT;
692 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
694 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
695 if (!himl)
697 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
698 draw_masked = TRUE;
701 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
702 ((tbcd->nmcd.uItemState & CDIS_HOT)
703 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
705 /* if hot, attempt to draw with hot image list, if fails,
706 use default image list */
707 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
708 if (!himl)
709 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
711 else
712 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
714 if (!himl)
715 return;
717 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
718 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
719 offset = 1;
721 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
722 (tbcd->nmcd.uItemState & CDIS_MARKED))
723 draw_flags |= ILD_BLEND50;
725 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
726 index, himl, left, top, offset);
728 if (draw_masked)
729 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
730 else
731 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
734 /* draws a blank frame for a toolbar button */
735 static void
736 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
738 HDC hdc = tbcd->nmcd.hdc;
739 RECT rc = tbcd->nmcd.rc;
740 /* if the state is disabled or indeterminate then the button
741 * cannot have an interactive look like pressed or hot */
742 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
743 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
744 BOOL pressed_look = !non_interactive_state &&
745 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
746 (tbcd->nmcd.uItemState & CDIS_CHECKED));
748 /* app don't want us to draw any edges */
749 if (dwItemCDFlag & TBCDRF_NOEDGES)
750 return;
752 if (infoPtr->dwStyle & TBSTYLE_FLAT)
754 if (pressed_look)
755 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
756 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
757 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
759 else
761 if (pressed_look)
762 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
763 else
764 DrawEdge (hdc, &rc, EDGE_RAISED,
765 BF_SOFT | BF_RECT | BF_MIDDLE);
769 static void
770 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
772 HDC hdc = tbcd->nmcd.hdc;
773 int offset = 0;
774 BOOL pressed = bDropDownPressed ||
775 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
777 if (infoPtr->dwStyle & TBSTYLE_FLAT)
779 if (pressed)
780 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
781 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
782 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
783 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
784 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
786 else
788 if (pressed)
789 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
790 else
791 DrawEdge (hdc, rcArrow, EDGE_RAISED,
792 BF_SOFT | BF_RECT | BF_MIDDLE);
795 if (pressed)
796 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
798 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
800 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
801 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
803 else
804 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
807 /* draws a complete toolbar button */
808 static void
809 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
811 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
812 DWORD dwStyle = infoPtr->dwStyle;
813 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
814 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
815 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
816 BOOL drawSepDropDownArrow = hasDropDownArrow &&
817 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
818 RECT rc, rcArrow, rcBitmap, rcText;
819 LPWSTR lpText = NULL;
820 NMTBCUSTOMDRAW tbcd;
821 DWORD ntfret;
822 INT offset;
823 INT oldBkMode;
824 DWORD dwItemCustDraw;
825 DWORD dwItemCDFlag;
826 HTHEME theme = GetWindowTheme (hwnd);
828 rc = btnPtr->rect;
829 CopyRect (&rcArrow, &rc);
831 /* separator - doesn't send NM_CUSTOMDRAW */
832 if (btnPtr->fsStyle & BTNS_SEP) {
833 if (theme)
835 DrawThemeBackground (theme, hdc,
836 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
837 &rc, NULL);
839 else
840 /* with the FLAT style, iBitmap is the width and has already */
841 /* been taken into consideration in calculating the width */
842 /* so now we need to draw the vertical separator */
843 /* empirical tests show that iBitmap can/will be non-zero */
844 /* when drawing the vertical bar... */
845 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
846 if (btnPtr->fsStyle & BTNS_DROPDOWN)
847 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
848 else
849 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
851 else if (btnPtr->fsStyle != BTNS_SEP) {
852 FIXME("Draw some kind of separator: fsStyle=%x\n",
853 btnPtr->fsStyle);
855 return;
858 /* get a pointer to the text */
859 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
861 if (hasDropDownArrow)
863 int right;
865 if (dwStyle & TBSTYLE_FLAT)
866 right = max(rc.left, rc.right - DDARROW_WIDTH);
867 else
868 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
870 if (drawSepDropDownArrow)
871 rc.right = right;
873 rcArrow.left = right;
876 /* copy text & bitmap rects after adjusting for drop-down arrow
877 * so that text & bitmap is centred in the rectangle not containing
878 * the arrow */
879 CopyRect(&rcText, &rc);
880 CopyRect(&rcBitmap, &rc);
882 /* Center the bitmap horizontally and vertically */
883 if (dwStyle & TBSTYLE_LIST)
885 if (lpText &&
886 infoPtr->nMaxTextRows > 0 &&
887 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
888 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
889 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
890 else
891 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
893 else
894 rcBitmap.left += (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
896 rcBitmap.top += infoPtr->szPadding.cy / 2;
898 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
899 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
900 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
901 TRACE("Text=%s\n", debugstr_w(lpText));
902 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
904 /* calculate text position */
905 if (lpText)
907 rcText.left += GetSystemMetrics(SM_CXEDGE);
908 rcText.right -= GetSystemMetrics(SM_CXEDGE);
909 if (dwStyle & TBSTYLE_LIST)
911 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
912 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
914 else
916 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
917 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
918 else
919 rcText.top += infoPtr->szPadding.cy/2 + 2;
923 /* Initialize fields in all cases, because we use these later
924 * NOTE: applications can and do alter these to customize their
925 * toolbars */
926 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
927 tbcd.clrText = comctl32_color.clrBtnText;
928 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
929 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
930 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
931 tbcd.clrMark = comctl32_color.clrHighlight;
932 tbcd.clrHighlightHotTrack = 0;
933 tbcd.nStringBkMode = TRANSPARENT;
934 tbcd.nHLStringBkMode = OPAQUE;
935 /* MSDN says that this is the text rectangle.
936 * But (why always a but) tracing of v5.7 of native shows
937 * that this is really a *relative* rectangle based on the
938 * the nmcd.rc. Also the left and top are always 0 ignoring
939 * any bitmap that might be present. */
940 tbcd.rcText.left = 0;
941 tbcd.rcText.top = 0;
942 tbcd.rcText.right = rcText.right - rc.left;
943 tbcd.rcText.bottom = rcText.bottom - rc.top;
944 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
945 tbcd.nmcd.hdc = hdc;
946 tbcd.nmcd.rc = rc;
947 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
949 /* FIXME: what are these used for? */
950 tbcd.hbrLines = 0;
951 tbcd.hpenLines = 0;
953 /* Issue Item Prepaint notify */
954 dwItemCustDraw = 0;
955 dwItemCDFlag = 0;
956 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
958 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
959 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
960 tbcd.nmcd.lItemlParam = btnPtr->dwData;
961 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
962 /* reset these fields so the user can't alter the behaviour like native */
963 tbcd.nmcd.hdc = hdc;
964 tbcd.nmcd.rc = rc;
966 dwItemCustDraw = ntfret & 0xffff;
967 dwItemCDFlag = ntfret & 0xffff0000;
968 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
969 return;
970 /* save the only part of the rect that the user can change */
971 rcText.right = tbcd.rcText.right + rc.left;
972 rcText.bottom = tbcd.rcText.bottom + rc.top;
975 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
976 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
977 OffsetRect(&rcText, 1, 1);
979 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
980 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
981 TOOLBAR_DrawPattern (&rc, &tbcd);
983 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
984 && (tbcd.nmcd.uItemState & CDIS_HOT))
986 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
988 COLORREF oldclr;
990 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
991 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
992 if (hasDropDownArrow)
993 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
994 SetBkColor(hdc, oldclr);
998 if (theme)
1000 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1001 int stateId = TS_NORMAL;
1003 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1004 stateId = TS_DISABLED;
1005 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1006 stateId = TS_PRESSED;
1007 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1008 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1009 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1010 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1011 stateId = TS_HOT;
1013 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1015 else
1016 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1018 if (drawSepDropDownArrow)
1020 if (theme)
1022 int stateId = TS_NORMAL;
1024 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1025 stateId = TS_DISABLED;
1026 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1027 stateId = TS_PRESSED;
1028 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1029 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1030 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1031 stateId = TS_HOT;
1033 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1034 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1036 else
1037 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1040 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1041 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1042 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1043 SetBkMode (hdc, oldBkMode);
1045 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1047 if (hasDropDownArrow && !drawSepDropDownArrow)
1049 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1051 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1052 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1054 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1056 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1057 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1059 else
1060 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1063 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1065 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1066 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1072 static void
1073 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1075 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1076 TBUTTON_INFO *btnPtr;
1077 INT i;
1078 RECT rcTemp, rcClient;
1079 NMTBCUSTOMDRAW tbcd;
1080 DWORD ntfret;
1081 DWORD dwBaseCustDraw;
1083 /* the app has told us not to redraw the toolbar */
1084 if (!infoPtr->bDoRedraw)
1085 return;
1087 /* if imagelist belongs to the app, it can be changed
1088 by the app after setting it */
1089 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1091 infoPtr->nNumBitmaps = 0;
1092 for (i = 0; i < infoPtr->cimlDef; i++)
1093 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1096 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1098 /* change the imagelist icon size if we manage the list and it is necessary */
1099 TOOLBAR_CheckImageListIconSize(infoPtr);
1101 /* Send initial notify */
1102 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1103 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1104 tbcd.nmcd.hdc = hdc;
1105 tbcd.nmcd.rc = ps->rcPaint;
1106 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1107 dwBaseCustDraw = ntfret & 0xffff;
1109 GetClientRect(hwnd, &rcClient);
1111 /* redraw necessary buttons */
1112 btnPtr = infoPtr->buttons;
1113 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1115 BOOL bDraw;
1116 if (!RectVisible(hdc, &btnPtr->rect))
1117 continue;
1118 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1120 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1121 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1123 else
1124 bDraw = TRUE;
1125 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1126 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1127 if (bDraw)
1128 TOOLBAR_DrawButton(hwnd, btnPtr, hdc, dwBaseCustDraw);
1131 /* draw insert mark if required */
1132 if (infoPtr->tbim.iButton != -1)
1134 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1135 RECT rcInsertMark;
1136 rcInsertMark.top = rcButton.top;
1137 rcInsertMark.bottom = rcButton.bottom;
1138 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1139 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1140 else
1141 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1142 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1145 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1147 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1148 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1149 tbcd.nmcd.hdc = hdc;
1150 tbcd.nmcd.rc = ps->rcPaint;
1151 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1155 /***********************************************************************
1156 * TOOLBAR_MeasureString
1158 * This function gets the width and height of a string in pixels. This
1159 * is done first by using GetTextExtentPoint to get the basic width
1160 * and height. The DrawText is called with DT_CALCRECT to get the exact
1161 * width. The reason is because the text may have more than one "&" (or
1162 * prefix characters as M$ likes to call them). The prefix character
1163 * indicates where the underline goes, except for the string "&&" which
1164 * is reduced to a single "&". GetTextExtentPoint does not process these
1165 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1167 static void
1168 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1169 HDC hdc, LPSIZE lpSize)
1171 RECT myrect;
1173 lpSize->cx = 0;
1174 lpSize->cy = 0;
1176 if (infoPtr->nMaxTextRows > 0 &&
1177 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1178 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1179 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1181 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1183 if(lpText != NULL) {
1184 /* first get size of all the text */
1185 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1187 /* feed above size into the rectangle for DrawText */
1188 myrect.left = myrect.top = 0;
1189 myrect.right = lpSize->cx;
1190 myrect.bottom = lpSize->cy;
1192 /* Use DrawText to get true size as drawn (less pesky "&") */
1193 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1194 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1195 DT_NOPREFIX : 0));
1197 /* feed back to caller */
1198 lpSize->cx = myrect.right;
1199 lpSize->cy = myrect.bottom;
1203 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1206 /***********************************************************************
1207 * TOOLBAR_CalcStrings
1209 * This function walks through each string and measures it and returns
1210 * the largest height and width to caller.
1212 static void
1213 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1215 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1216 TBUTTON_INFO *btnPtr;
1217 INT i;
1218 SIZE sz;
1219 HDC hdc;
1220 HFONT hOldFont;
1222 lpSize->cx = 0;
1223 lpSize->cy = 0;
1225 if (infoPtr->nMaxTextRows == 0)
1226 return;
1228 hdc = GetDC (hwnd);
1229 hOldFont = SelectObject (hdc, infoPtr->hFont);
1231 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1233 TEXTMETRICW tm;
1235 GetTextMetricsW(hdc, &tm);
1236 lpSize->cy = tm.tmHeight;
1239 btnPtr = infoPtr->buttons;
1240 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1241 if(TOOLBAR_HasText(infoPtr, btnPtr))
1243 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1244 if (sz.cx > lpSize->cx)
1245 lpSize->cx = sz.cx;
1246 if (sz.cy > lpSize->cy)
1247 lpSize->cy = sz.cy;
1251 SelectObject (hdc, hOldFont);
1252 ReleaseDC (hwnd, hdc);
1254 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1257 /***********************************************************************
1258 * TOOLBAR_WrapToolbar
1260 * This function walks through the buttons and separators in the
1261 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1262 * wrapping should occur based on the width of the toolbar window.
1263 * It does *not* calculate button placement itself. That task
1264 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1265 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1266 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1268 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1269 * vertical toolbar lists.
1272 static void
1273 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1275 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1276 TBUTTON_INFO *btnPtr;
1277 INT x, cx, i, j;
1278 RECT rc;
1279 BOOL bWrap, bButtonWrap;
1281 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1282 /* no layout is necessary. Applications may use this style */
1283 /* to perform their own layout on the toolbar. */
1284 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1285 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1287 btnPtr = infoPtr->buttons;
1288 x = infoPtr->nIndent;
1290 if (GetParent(hwnd))
1292 /* this can get the parents width, to know how far we can extend
1293 * this toolbar. We cannot use its height, as there may be multiple
1294 * toolbars in a rebar control
1296 GetClientRect( GetParent(hwnd), &rc );
1297 infoPtr->nWidth = rc.right - rc.left;
1299 else
1301 GetWindowRect( hwnd, &rc );
1302 infoPtr->nWidth = rc.right - rc.left;
1305 bButtonWrap = FALSE;
1307 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1308 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1309 infoPtr->nIndent);
1311 for (i = 0; i < infoPtr->nNumButtons; i++ )
1313 bWrap = FALSE;
1314 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1316 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1317 continue;
1319 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1320 /* it is the actual width of the separator. This is used for */
1321 /* custom controls in toolbars. */
1322 /* */
1323 /* BTNS_DROPDOWN separators are treated as buttons for */
1324 /* width. - GA 8/01 */
1325 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1326 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1327 cx = (btnPtr[i].iBitmap > 0) ?
1328 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1329 else
1330 cx = infoPtr->nButtonWidth;
1332 /* Two or more adjacent separators form a separator group. */
1333 /* The first separator in a group should be wrapped to the */
1334 /* next row if the previous wrapping is on a button. */
1335 if( bButtonWrap &&
1336 (btnPtr[i].fsStyle & BTNS_SEP) &&
1337 (i + 1 < infoPtr->nNumButtons ) &&
1338 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1340 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1341 btnPtr[i].fsState |= TBSTATE_WRAP;
1342 x = infoPtr->nIndent;
1343 i++;
1344 bButtonWrap = FALSE;
1345 continue;
1348 /* The layout makes sure the bitmap is visible, but not the button. */
1349 /* Test added to also wrap after a button that starts a row but */
1350 /* is bigger than the area. - GA 8/01 */
1351 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1352 > infoPtr->nWidth ) ||
1353 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1355 BOOL bFound = FALSE;
1357 /* If the current button is a separator and not hidden, */
1358 /* go to the next until it reaches a non separator. */
1359 /* Wrap the last separator if it is before a button. */
1360 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1361 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1362 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1363 i < infoPtr->nNumButtons )
1365 i++;
1366 bFound = TRUE;
1369 if( bFound && i < infoPtr->nNumButtons )
1371 i--;
1372 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1373 i, btnPtr[i].fsStyle, x, cx);
1374 btnPtr[i].fsState |= TBSTATE_WRAP;
1375 x = infoPtr->nIndent;
1376 bButtonWrap = FALSE;
1377 continue;
1379 else if ( i >= infoPtr->nNumButtons)
1380 break;
1382 /* If the current button is not a separator, find the last */
1383 /* separator and wrap it. */
1384 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1386 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1387 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1389 bFound = TRUE;
1390 i = j;
1391 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1392 i, btnPtr[i].fsStyle, x, cx);
1393 x = infoPtr->nIndent;
1394 btnPtr[j].fsState |= TBSTATE_WRAP;
1395 bButtonWrap = FALSE;
1396 break;
1400 /* If no separator available for wrapping, wrap one of */
1401 /* non-hidden previous button. */
1402 if (!bFound)
1404 for ( j = i - 1;
1405 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1407 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1408 continue;
1410 bFound = TRUE;
1411 i = j;
1412 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1413 i, btnPtr[i].fsStyle, x, cx);
1414 x = infoPtr->nIndent;
1415 btnPtr[j].fsState |= TBSTATE_WRAP;
1416 bButtonWrap = TRUE;
1417 break;
1421 /* If all above failed, wrap the current button. */
1422 if (!bFound)
1424 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1425 i, btnPtr[i].fsStyle, x, cx);
1426 btnPtr[i].fsState |= TBSTATE_WRAP;
1427 bFound = TRUE;
1428 x = infoPtr->nIndent;
1429 if (btnPtr[i].fsStyle & BTNS_SEP )
1430 bButtonWrap = FALSE;
1431 else
1432 bButtonWrap = TRUE;
1435 else {
1436 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1437 i, btnPtr[i].fsStyle, x, cx);
1438 x += cx;
1444 /***********************************************************************
1445 * TOOLBAR_MeasureButton
1447 * Calculates the width and height required for a button. Used in
1448 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1449 * the width of buttons that are autosized.
1451 * Note that it would have been rather elegant to use one piece of code for
1452 * both the laying out of the toolbar and for controlling where button parts
1453 * are drawn, but the native control has inconsistencies between the two that
1454 * prevent this from being effectively. These inconsistencies can be seen as
1455 * artefacts where parts of the button appear outside of the bounding button
1456 * rectangle.
1458 * There are several cases for the calculation of the button dimensions and
1459 * button part positioning:
1461 * List
1462 * ====
1464 * With Bitmap:
1466 * +--------------------------------------------------------+ ^
1467 * | ^ ^ | |
1468 * | | pad.cy / 2 | centred | |
1469 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1470 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1471 * | |<------------>| | | | |
1472 * | +--------------+ +------------+ | |
1473 * |<-------------------------------------->| | |
1474 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1475 * | szText.cx | |
1476 * +--------------------------------------------------------+ -
1477 * <-------------------------------------------------------->
1478 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1480 * Without Bitmap (I_IMAGENONE):
1482 * +-----------------------------------+ ^
1483 * | ^ | |
1484 * | | centred | | LISTPAD_CY +
1485 * | +------------+ | | szText.cy
1486 * | | Text | | |
1487 * | | | | |
1488 * | +------------+ | |
1489 * |<----------------->| | |
1490 * | cxedge |<-----------> | |
1491 * | szText.cx | |
1492 * +-----------------------------------+ -
1493 * <----------------------------------->
1494 * szText.cx + pad.cx
1496 * Without text:
1498 * +--------------------------------------+ ^
1499 * | ^ | |
1500 * | | padding.cy/2 | | DEFPAD_CY +
1501 * | +------------+ | | nBitmapHeight
1502 * | | Bitmap | | |
1503 * | | | | |
1504 * | +------------+ | |
1505 * |<------------------->| | |
1506 * | cxedge + iListGap/2 |<-----------> | |
1507 * | nBitmapWidth | |
1508 * +--------------------------------------+ -
1509 * <-------------------------------------->
1510 * 2*cxedge + nBitmapWidth + iListGap
1512 * Non-List
1513 * ========
1515 * With bitmap:
1517 * +-----------------------------------+ ^
1518 * | ^ | |
1519 * | | pad.cy / 2 | | nBitmapHeight +
1520 * | - | | szText.cy +
1521 * | +------------+ | | DEFPAD_CY + 1
1522 * | centred | Bitmap | | |
1523 * |<----------------->| | | |
1524 * | +------------+ | |
1525 * | ^ | |
1526 * | 1 | | |
1527 * | - | |
1528 * | centred +---------------+ | |
1529 * |<--------------->| Text | | |
1530 * | +---------------+ | |
1531 * +-----------------------------------+ -
1532 * <----------------------------------->
1533 * pad.cx + max(nBitmapWidth, szText.cx)
1535 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1537 * +---------------------------------------+ ^
1538 * | ^ | |
1539 * | | 2 + pad.cy / 2 | |
1540 * | - | | szText.cy +
1541 * | centred +-----------------+ | | pad.cy + 2
1542 * |<--------------->| Text | | |
1543 * | +-----------------+ | |
1544 * | | |
1545 * +---------------------------------------+ -
1546 * <--------------------------------------->
1547 * 2*cxedge + pad.cx + szText.cx
1549 * Without text:
1550 * As for with bitmaps, but with szText.cx zero.
1552 static inline SIZE TOOLBAR_MeasureButton(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1554 SIZE sizeButton;
1555 if (infoPtr->dwStyle & TBSTYLE_LIST)
1557 /* set button height from bitmap / text height... */
1558 sizeButton.cy = max((bHasBitmap ? infoPtr->nVBitmapHeight : 0),
1559 sizeString.cy);
1561 /* ... add on the necessary padding */
1562 if (bValidImageList)
1564 if (bHasBitmap)
1565 sizeButton.cy += DEFPAD_CY;
1566 else
1567 sizeButton.cy += LISTPAD_CY;
1569 else
1570 sizeButton.cy += infoPtr->szPadding.cy;
1572 /* calculate button width */
1573 if (bHasBitmap)
1575 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1576 infoPtr->nBitmapWidth + infoPtr->iListGap;
1577 if (sizeString.cx > 0)
1578 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1580 else
1581 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1583 else
1585 if (bHasBitmap)
1587 sizeButton.cy = infoPtr->nVBitmapHeight + DEFPAD_CY;
1588 if (sizeString.cy > 0)
1589 sizeButton.cy += 1 + sizeString.cy;
1590 sizeButton.cx = infoPtr->szPadding.cx +
1591 max(sizeString.cx, infoPtr->nBitmapWidth);
1593 else
1595 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1596 NONLIST_NOTEXT_OFFSET;
1597 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1598 infoPtr->szPadding.cx + sizeString.cx;
1601 return sizeButton;
1605 /***********************************************************************
1606 * TOOLBAR_CalcToolbar
1608 * This function calculates button and separator placement. It first
1609 * calculates the button sizes, gets the toolbar window width and then
1610 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1611 * on. It assigns a new location to each item and sends this location to
1612 * the tooltip window if appropriate. Finally, it updates the rcBound
1613 * rect and calculates the new required toolbar window height.
1615 static void
1616 TOOLBAR_CalcToolbar (HWND hwnd)
1618 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1619 SIZE sizeString, sizeButton;
1620 BOOL validImageList = FALSE;
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_LayoutToolbar(hwnd);
1640 static void
1641 TOOLBAR_LayoutToolbar(HWND hwnd)
1643 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1644 TBUTTON_INFO *btnPtr;
1645 SIZE sizeButton;
1646 INT i, nRows, nSepRows;
1647 INT x, y, cx, cy;
1648 BOOL bWrap;
1649 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1650 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1652 TOOLBAR_WrapToolbar(hwnd, infoPtr->dwStyle);
1654 x = infoPtr->nIndent;
1655 y = (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
1656 cx = infoPtr->nButtonWidth;
1657 cy = infoPtr->nButtonHeight;
1659 nRows = nSepRows = 0;
1661 infoPtr->rcBound.top = y;
1662 infoPtr->rcBound.left = x;
1663 infoPtr->rcBound.bottom = y + cy;
1664 infoPtr->rcBound.right = x;
1666 btnPtr = infoPtr->buttons;
1668 TRACE("cy=%d\n", cy);
1670 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1672 bWrap = FALSE;
1673 if (btnPtr->fsState & TBSTATE_HIDDEN)
1675 SetRectEmpty (&btnPtr->rect);
1676 continue;
1679 cy = infoPtr->nButtonHeight;
1681 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1682 /* it is the actual width of the separator. This is used for */
1683 /* custom controls in toolbars. */
1684 if (btnPtr->fsStyle & BTNS_SEP) {
1685 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1686 cy = (btnPtr->iBitmap > 0) ?
1687 btnPtr->iBitmap : SEPARATOR_WIDTH;
1688 cx = infoPtr->nButtonWidth;
1690 else
1691 cx = (btnPtr->iBitmap > 0) ?
1692 btnPtr->iBitmap : SEPARATOR_WIDTH;
1694 else
1696 if (btnPtr->cx)
1697 cx = btnPtr->cx;
1698 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1699 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1701 SIZE sz;
1702 HDC hdc;
1703 HFONT hOldFont;
1705 hdc = GetDC (hwnd);
1706 hOldFont = SelectObject (hdc, infoPtr->hFont);
1708 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1710 SelectObject (hdc, hOldFont);
1711 ReleaseDC (hwnd, hdc);
1713 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1714 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1715 validImageList);
1716 cx = sizeButton.cx;
1718 else
1719 cx = infoPtr->nButtonWidth;
1721 /* if size has been set manually then don't add on extra space
1722 * for the drop down arrow */
1723 if (!btnPtr->cx && hasDropDownArrows &&
1724 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1725 cx += DDARROW_WIDTH;
1727 if (btnPtr->fsState & TBSTATE_WRAP )
1728 bWrap = TRUE;
1730 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1732 if (infoPtr->rcBound.left > x)
1733 infoPtr->rcBound.left = x;
1734 if (infoPtr->rcBound.right < x + cx)
1735 infoPtr->rcBound.right = x + cx;
1736 if (infoPtr->rcBound.bottom < y + cy)
1737 infoPtr->rcBound.bottom = y + cy;
1739 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1741 /* btnPtr->nRow is zero based. The space between the rows is */
1742 /* also considered as a row. */
1743 btnPtr->nRow = nRows + nSepRows;
1745 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1746 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1747 x, y, x+cx, y+cy);
1749 if( bWrap )
1751 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1752 y += cy;
1753 else
1755 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1756 /* it is the actual width of the separator. This is used for */
1757 /* custom controls in toolbars. */
1758 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1759 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1760 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1761 else
1762 y += cy;
1764 /* nSepRows is used to calculate the extra height follwoing */
1765 /* the last row. */
1766 nSepRows++;
1768 x = infoPtr->nIndent;
1770 /* Increment row number unless this is the last button */
1771 /* and it has Wrap set. */
1772 if (i != infoPtr->nNumButtons-1)
1773 nRows++;
1775 else
1776 x += cx;
1779 /* infoPtr->nRows is the number of rows on the toolbar */
1780 infoPtr->nRows = nRows + nSepRows + 1;
1782 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1786 static INT
1787 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1789 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1790 TBUTTON_INFO *btnPtr;
1791 INT i;
1793 btnPtr = infoPtr->buttons;
1794 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1795 if (btnPtr->fsState & TBSTATE_HIDDEN)
1796 continue;
1798 if (btnPtr->fsStyle & BTNS_SEP) {
1799 if (PtInRect (&btnPtr->rect, *lpPt)) {
1800 TRACE(" ON SEPARATOR %d!\n", i);
1801 return -i;
1804 else {
1805 if (PtInRect (&btnPtr->rect, *lpPt)) {
1806 TRACE(" ON BUTTON %d!\n", i);
1807 return i;
1812 TRACE(" NOWHERE!\n");
1813 return TOOLBAR_NOWHERE;
1817 static INT
1818 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1820 TBUTTON_INFO *btnPtr;
1821 INT i;
1823 if (CommandIsIndex) {
1824 TRACE("command is really index command=%d\n", idCommand);
1825 if (idCommand >= infoPtr->nNumButtons) return -1;
1826 return idCommand;
1828 btnPtr = infoPtr->buttons;
1829 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1830 if (btnPtr->idCommand == idCommand) {
1831 TRACE("command=%d index=%d\n", idCommand, i);
1832 return i;
1835 TRACE("no index found for command=%d\n", idCommand);
1836 return -1;
1840 static INT
1841 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1843 TBUTTON_INFO *btnPtr;
1844 INT nRunIndex;
1846 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1847 return -1;
1849 /* check index button */
1850 btnPtr = &infoPtr->buttons[nIndex];
1851 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1852 if (btnPtr->fsState & TBSTATE_CHECKED)
1853 return nIndex;
1856 /* check previous buttons */
1857 nRunIndex = nIndex - 1;
1858 while (nRunIndex >= 0) {
1859 btnPtr = &infoPtr->buttons[nRunIndex];
1860 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1861 if (btnPtr->fsState & TBSTATE_CHECKED)
1862 return nRunIndex;
1864 else
1865 break;
1866 nRunIndex--;
1869 /* check next buttons */
1870 nRunIndex = nIndex + 1;
1871 while (nRunIndex < infoPtr->nNumButtons) {
1872 btnPtr = &infoPtr->buttons[nRunIndex];
1873 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1874 if (btnPtr->fsState & TBSTATE_CHECKED)
1875 return nRunIndex;
1877 else
1878 break;
1879 nRunIndex++;
1882 return -1;
1886 static VOID
1887 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1888 WPARAM wParam, LPARAM lParam)
1890 MSG msg;
1892 msg.hwnd = hwndMsg;
1893 msg.message = uMsg;
1894 msg.wParam = wParam;
1895 msg.lParam = lParam;
1896 msg.time = GetMessageTime ();
1897 msg.pt.x = (short)LOWORD(GetMessagePos ());
1898 msg.pt.y = (short)HIWORD(GetMessagePos ());
1900 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1903 static void
1904 TOOLBAR_TooltipAddTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1906 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1907 TTTOOLINFOW ti;
1909 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1910 ti.cbSize = sizeof (TTTOOLINFOW);
1911 ti.hwnd = infoPtr->hwndSelf;
1912 ti.uId = button->idCommand;
1913 ti.hinst = 0;
1914 ti.lpszText = LPSTR_TEXTCALLBACKW;
1915 /* ti.lParam = random value from the stack? */
1917 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1918 0, (LPARAM)&ti);
1922 static void
1923 TOOLBAR_TooltipDelTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1925 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1926 TTTOOLINFOW ti;
1928 ZeroMemory(&ti, sizeof(ti));
1929 ti.cbSize = sizeof(ti);
1930 ti.hwnd = infoPtr->hwndSelf;
1931 ti.uId = button->idCommand;
1933 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1937 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1939 /* Set the toolTip only for non-hidden, non-separator button */
1940 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1942 TTTOOLINFOW ti;
1944 ZeroMemory(&ti, sizeof(ti));
1945 ti.cbSize = sizeof(ti);
1946 ti.hwnd = infoPtr->hwndSelf;
1947 ti.uId = button->idCommand;
1948 ti.rect = button->rect;
1949 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1953 /* Creates the tooltip control */
1954 static void
1955 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
1957 int i;
1958 NMTOOLTIPSCREATED nmttc;
1960 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1961 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1962 infoPtr->hwndSelf, 0, 0, 0);
1964 if (!infoPtr->hwndToolTip)
1965 return;
1967 /* Send NM_TOOLTIPSCREATED notification */
1968 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1969 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
1971 for (i = 0; i < infoPtr->nNumButtons; i++)
1973 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
1974 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
1978 /* keeps available button list box sorted by button id */
1979 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1981 int i;
1982 int count;
1983 PCUSTOMBUTTON btnInfo;
1984 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1986 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1988 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1990 /* position 0 is always separator */
1991 for (i = 1; i < count; i++)
1993 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1994 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1996 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1997 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1998 return;
2001 /* id higher than all others add to end */
2002 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2003 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2006 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2008 NMTOOLBARW nmtb;
2010 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2012 if (nIndexFrom == nIndexTo)
2013 return;
2015 /* MSDN states that iItem is the index of the button, rather than the
2016 * command ID as used by every other NMTOOLBAR notification */
2017 nmtb.iItem = nIndexFrom;
2018 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2020 PCUSTOMBUTTON btnInfo;
2021 NMHDR hdr;
2022 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2023 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2025 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2027 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2028 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2029 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2030 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2032 if (nIndexTo <= 0)
2033 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2034 else
2035 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2037 /* last item is always separator, so -2 instead of -1 */
2038 if (nIndexTo >= (count - 2))
2039 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2040 else
2041 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2043 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2044 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2046 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2050 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2052 NMTOOLBARW nmtb;
2054 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2056 /* MSDN states that iItem is the index of the button, rather than the
2057 * command ID as used by every other NMTOOLBAR notification */
2058 nmtb.iItem = nIndexAvail;
2059 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2061 PCUSTOMBUTTON btnInfo;
2062 NMHDR hdr;
2063 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2064 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2065 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2067 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2069 if (nIndexAvail != 0) /* index == 0 indicates separator */
2071 /* remove from 'available buttons' list */
2072 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2073 if (nIndexAvail == count-1)
2074 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2075 else
2076 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2078 else
2080 PCUSTOMBUTTON btnNew;
2082 /* duplicate 'separator' button */
2083 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2084 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2085 btnInfo = btnNew;
2088 /* insert into 'toolbar button' list */
2089 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2090 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2092 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2094 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2098 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
2100 PCUSTOMBUTTON btnInfo;
2101 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2103 TRACE("Remove: index %d\n", index);
2105 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2107 /* send TBN_QUERYDELETE notification */
2108 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2110 NMHDR hdr;
2112 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2113 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2115 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2117 /* insert into 'available button' list */
2118 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2119 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2120 else
2121 Free(btnInfo);
2123 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2127 /* drag list notification function for toolbar buttons list box */
2128 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2130 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2131 switch (pDLI->uNotification)
2133 case DL_BEGINDRAG:
2135 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2136 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2137 /* no dragging for last item (separator) */
2138 if (nCurrentItem >= (nCount - 1)) return FALSE;
2139 return TRUE;
2141 case DL_DRAGGING:
2143 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2144 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2145 /* no dragging past last item (separator) */
2146 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2148 DrawInsert(hwnd, hwndList, nCurrentItem);
2149 /* FIXME: native uses "move button" cursor */
2150 return DL_COPYCURSOR;
2153 /* not over toolbar buttons list */
2154 if (nCurrentItem < 0)
2156 POINT ptWindow = pDLI->ptCursor;
2157 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2158 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2159 /* over available buttons list? */
2160 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2161 /* FIXME: native uses "move button" cursor */
2162 return DL_COPYCURSOR;
2164 /* clear drag arrow */
2165 DrawInsert(hwnd, hwndList, -1);
2166 return DL_STOPCURSOR;
2168 case DL_DROPPED:
2170 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2171 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2172 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2173 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2175 /* clear drag arrow */
2176 DrawInsert(hwnd, hwndList, -1);
2177 /* move item */
2178 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2180 /* not over toolbar buttons list */
2181 if (nIndexTo < 0)
2183 POINT ptWindow = pDLI->ptCursor;
2184 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2185 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2186 /* over available buttons list? */
2187 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2188 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2190 break;
2192 case DL_CANCELDRAG:
2193 /* Clear drag arrow */
2194 DrawInsert(hwnd, hwndList, -1);
2195 break;
2198 return 0;
2201 /* drag list notification function for available buttons list box */
2202 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2204 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2205 switch (pDLI->uNotification)
2207 case DL_BEGINDRAG:
2208 return TRUE;
2209 case DL_DRAGGING:
2211 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2212 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2213 /* no dragging past last item (separator) */
2214 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2216 DrawInsert(hwnd, hwndList, nCurrentItem);
2217 /* FIXME: native uses "move button" cursor */
2218 return DL_COPYCURSOR;
2221 /* not over toolbar buttons list */
2222 if (nCurrentItem < 0)
2224 POINT ptWindow = pDLI->ptCursor;
2225 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2226 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2227 /* over available buttons list? */
2228 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2229 /* FIXME: native uses "move button" cursor */
2230 return DL_COPYCURSOR;
2232 /* clear drag arrow */
2233 DrawInsert(hwnd, hwndList, -1);
2234 return DL_STOPCURSOR;
2236 case DL_DROPPED:
2238 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2239 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2240 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2241 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2243 /* clear drag arrow */
2244 DrawInsert(hwnd, hwndList, -1);
2245 /* add item */
2246 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2249 case DL_CANCELDRAG:
2250 /* Clear drag arrow */
2251 DrawInsert(hwnd, hwndList, -1);
2252 break;
2254 return 0;
2257 extern UINT uDragListMessage;
2259 /***********************************************************************
2260 * TOOLBAR_CustomizeDialogProc
2261 * This function implements the toolbar customization dialog.
2263 static INT_PTR CALLBACK
2264 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2266 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2267 PCUSTOMBUTTON btnInfo;
2268 NMTOOLBARA nmtb;
2269 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2271 switch (uMsg)
2273 case WM_INITDIALOG:
2274 custInfo = (PCUSTDLG_INFO)lParam;
2275 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2277 if (custInfo)
2279 WCHAR Buffer[256];
2280 int i = 0;
2281 int index;
2282 NMTBINITCUSTOMIZE nmtbic;
2284 infoPtr = custInfo->tbInfo;
2286 /* send TBN_QUERYINSERT notification */
2287 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2289 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2290 return FALSE;
2292 nmtbic.hwndDialog = hwnd;
2293 /* Send TBN_INITCUSTOMIZE notification */
2294 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2295 TBNRF_HIDEHELP)
2297 TRACE("TBNRF_HIDEHELP requested\n");
2298 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2301 /* add items to 'toolbar buttons' list and check if removable */
2302 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2304 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2305 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2306 btnInfo->btn.fsStyle = BTNS_SEP;
2307 btnInfo->bVirtual = FALSE;
2308 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2310 /* send TBN_QUERYDELETE notification */
2311 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2313 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2314 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2317 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2319 /* insert separator button into 'available buttons' list */
2320 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2321 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2322 btnInfo->btn.fsStyle = BTNS_SEP;
2323 btnInfo->bVirtual = FALSE;
2324 btnInfo->bRemovable = TRUE;
2325 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2326 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2327 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2329 /* insert all buttons into dsa */
2330 for (i = 0;; i++)
2332 /* send TBN_GETBUTTONINFO notification */
2333 NMTOOLBARW nmtb;
2334 nmtb.iItem = i;
2335 nmtb.pszText = Buffer;
2336 nmtb.cchText = 256;
2338 /* Clear previous button's text */
2339 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2341 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2342 break;
2344 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2345 nmtb.tbButton.fsStyle, i,
2346 nmtb.tbButton.idCommand,
2347 nmtb.tbButton.iString,
2348 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2349 : "");
2351 /* insert button into the apropriate list */
2352 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2353 if (index == -1)
2355 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2356 btnInfo->bVirtual = FALSE;
2357 btnInfo->bRemovable = TRUE;
2359 else
2361 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2362 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2365 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2366 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2368 if (lstrlenW(nmtb.pszText))
2369 lstrcpyW(btnInfo->text, nmtb.pszText);
2370 else if (nmtb.tbButton.iString >= 0 &&
2371 nmtb.tbButton.iString < infoPtr->nNumStrings)
2373 lstrcpyW(btnInfo->text,
2374 infoPtr->strings[nmtb.tbButton.iString]);
2378 if (index == -1)
2379 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2382 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2384 /* select first item in the 'available' list */
2385 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2387 /* append 'virtual' separator button to the 'toolbar buttons' list */
2388 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2389 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2390 btnInfo->btn.fsStyle = BTNS_SEP;
2391 btnInfo->bVirtual = TRUE;
2392 btnInfo->bRemovable = FALSE;
2393 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2394 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2395 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2397 /* select last item in the 'toolbar' list */
2398 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2399 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2401 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2402 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2404 /* set focus and disable buttons */
2405 PostMessageW (hwnd, WM_USER, 0, 0);
2407 return TRUE;
2409 case WM_USER:
2410 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2411 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2412 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2413 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2414 return TRUE;
2416 case WM_CLOSE:
2417 EndDialog(hwnd, FALSE);
2418 return TRUE;
2420 case WM_COMMAND:
2421 switch (LOWORD(wParam))
2423 case IDC_TOOLBARBTN_LBOX:
2424 if (HIWORD(wParam) == LBN_SELCHANGE)
2426 PCUSTOMBUTTON btnInfo;
2427 NMTOOLBARA nmtb;
2428 int count;
2429 int index;
2431 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2432 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2434 /* send TBN_QUERYINSERT notification */
2435 nmtb.iItem = index;
2436 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2438 /* get list box item */
2439 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2441 if (index == (count - 1))
2443 /* last item (virtual separator) */
2444 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2445 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2447 else if (index == (count - 2))
2449 /* second last item (last non-virtual item) */
2450 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2451 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2453 else if (index == 0)
2455 /* first item */
2456 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2457 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2459 else
2461 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2462 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2465 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2467 break;
2469 case IDC_MOVEUP_BTN:
2471 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2472 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2474 break;
2476 case IDC_MOVEDN_BTN: /* move down */
2478 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2479 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2481 break;
2483 case IDC_REMOVE_BTN: /* remove button */
2485 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2487 if (LB_ERR == index)
2488 break;
2490 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2492 break;
2493 case IDC_HELP_BTN:
2494 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2495 break;
2496 case IDC_RESET_BTN:
2497 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2498 break;
2500 case IDOK: /* Add button */
2502 int index;
2503 int indexto;
2505 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2506 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2508 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2510 break;
2512 case IDCANCEL:
2513 EndDialog(hwnd, FALSE);
2514 break;
2516 return TRUE;
2518 case WM_DESTROY:
2520 int count;
2521 int i;
2523 /* delete items from 'toolbar buttons' listbox*/
2524 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2525 for (i = 0; i < count; i++)
2527 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2528 Free(btnInfo);
2529 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2531 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2534 /* delete items from 'available buttons' listbox*/
2535 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2536 for (i = 0; i < count; i++)
2538 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2539 Free(btnInfo);
2540 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2542 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2544 return TRUE;
2546 case WM_DRAWITEM:
2547 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2549 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2550 RECT rcButton;
2551 RECT rcText;
2552 HPEN hPen, hOldPen;
2553 HBRUSH hOldBrush;
2554 COLORREF oldText = 0;
2555 COLORREF oldBk = 0;
2557 /* get item data */
2558 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2559 if (btnInfo == NULL)
2561 FIXME("btnInfo invalid!\n");
2562 return TRUE;
2565 /* set colors and select objects */
2566 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2567 if (btnInfo->bVirtual)
2568 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2569 else
2570 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2571 hPen = CreatePen( PS_SOLID, 1,
2572 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2573 hOldPen = SelectObject (lpdis->hDC, hPen );
2574 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2576 /* fill background rectangle */
2577 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2578 lpdis->rcItem.right, lpdis->rcItem.bottom);
2580 /* calculate button and text rectangles */
2581 CopyRect (&rcButton, &lpdis->rcItem);
2582 InflateRect (&rcButton, -1, -1);
2583 CopyRect (&rcText, &rcButton);
2584 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2585 rcText.left = rcButton.right + 2;
2587 /* draw focus rectangle */
2588 if (lpdis->itemState & ODS_FOCUS)
2589 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2591 /* draw button */
2592 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2593 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2595 /* draw image and text */
2596 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2597 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2598 btnInfo->btn.iBitmap));
2599 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2600 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2602 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2603 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2605 /* delete objects and reset colors */
2606 SelectObject (lpdis->hDC, hOldBrush);
2607 SelectObject (lpdis->hDC, hOldPen);
2608 SetBkColor (lpdis->hDC, oldBk);
2609 SetTextColor (lpdis->hDC, oldText);
2610 DeleteObject( hPen );
2611 return TRUE;
2613 return FALSE;
2615 case WM_MEASUREITEM:
2616 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2618 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2620 lpmis->itemHeight = 15 + 8; /* default height */
2622 return TRUE;
2624 return FALSE;
2626 default:
2627 if (uDragListMessage && (uMsg == uDragListMessage))
2629 if (wParam == IDC_TOOLBARBTN_LBOX)
2631 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2632 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2633 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2634 return TRUE;
2636 else if (wParam == IDC_AVAILBTN_LBOX)
2638 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2639 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2640 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2641 return TRUE;
2644 return FALSE;
2648 static BOOL
2649 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2651 HBITMAP hbmLoad;
2652 INT nCountBefore = ImageList_GetImageCount(himlDef);
2653 INT nCountAfter;
2654 INT cxIcon, cyIcon;
2655 INT nAdded;
2656 INT nIndex;
2658 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2659 /* Add bitmaps to the default image list */
2660 if (bitmap->hInst == NULL) /* a handle was passed */
2662 BITMAP bmp;
2663 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2664 HDC hdcImage, hdcBitmap;
2666 /* copy the bitmap before adding it so that the user's bitmap
2667 * doesn't get modified.
2669 GetObjectW ((HBITMAP)bitmap->nID, sizeof(BITMAP), (LPVOID)&bmp);
2671 hdcImage = CreateCompatibleDC(0);
2672 hdcBitmap = CreateCompatibleDC(0);
2674 /* create new bitmap */
2675 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2676 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)bitmap->nID);
2677 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2679 /* Copy the user's image */
2680 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2681 hdcBitmap, 0, 0, SRCCOPY);
2683 SelectObject (hdcImage, hOldBitmapLoad);
2684 SelectObject (hdcBitmap, hOldBitmapBitmap);
2685 DeleteDC (hdcImage);
2686 DeleteDC (hdcBitmap);
2688 else
2689 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2691 /* enlarge the bitmap if needed */
2692 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2693 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2695 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2696 DeleteObject(hbmLoad);
2697 if (nIndex == -1)
2698 return FALSE;
2700 nCountAfter = ImageList_GetImageCount(himlDef);
2701 nAdded = nCountAfter - nCountBefore;
2702 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2704 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2705 } else if (nAdded > (INT)bitmap->nButtons) {
2706 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2707 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2710 infoPtr->nNumBitmaps += nAdded;
2711 return TRUE;
2714 static void
2715 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2717 HIMAGELIST himlDef;
2718 HIMAGELIST himlNew;
2719 INT cx, cy;
2720 INT i;
2722 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2723 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2724 return;
2725 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2726 return;
2727 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2728 return;
2730 TRACE("Update icon size: %dx%d -> %dx%d\n",
2731 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2733 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2734 ILC_COLORDDB|ILC_MASK, 8, 2);
2735 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2736 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2737 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2738 infoPtr->himlInt = himlNew;
2740 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2741 ImageList_Destroy(himlDef);
2744 /***********************************************************************
2745 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2748 static LRESULT
2749 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2751 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2752 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2753 TBITMAP_INFO info;
2754 INT iSumButtons, i;
2755 HIMAGELIST himlDef;
2757 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2758 if (!lpAddBmp)
2759 return -1;
2761 if (lpAddBmp->hInst == HINST_COMMCTRL)
2763 info.hInst = COMCTL32_hModule;
2764 switch (lpAddBmp->nID)
2766 case IDB_STD_SMALL_COLOR:
2767 info.nButtons = 15;
2768 info.nID = IDB_STD_SMALL;
2769 break;
2770 case IDB_STD_LARGE_COLOR:
2771 info.nButtons = 15;
2772 info.nID = IDB_STD_LARGE;
2773 break;
2774 case IDB_VIEW_SMALL_COLOR:
2775 info.nButtons = 12;
2776 info.nID = IDB_VIEW_SMALL;
2777 break;
2778 case IDB_VIEW_LARGE_COLOR:
2779 info.nButtons = 12;
2780 info.nID = IDB_VIEW_LARGE;
2781 break;
2782 case IDB_HIST_SMALL_COLOR:
2783 info.nButtons = 5;
2784 info.nID = IDB_HIST_SMALL;
2785 break;
2786 case IDB_HIST_LARGE_COLOR:
2787 info.nButtons = 5;
2788 info.nID = IDB_HIST_LARGE;
2789 break;
2790 default:
2791 return -1;
2794 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2796 /* Windows resize all the buttons to the size of a newly added standard image */
2797 if (lpAddBmp->nID & 1)
2799 /* large icons */
2800 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2801 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2803 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2804 MAKELPARAM((WORD)24, (WORD)24));
2805 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2806 MAKELPARAM((WORD)31, (WORD)30));
2808 else
2810 /* small icons */
2811 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2812 MAKELPARAM((WORD)16, (WORD)16));
2813 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2814 MAKELPARAM((WORD)22, (WORD)22));
2817 TOOLBAR_CalcToolbar (hwnd);
2819 else
2821 info.nButtons = (INT)wParam;
2822 info.hInst = lpAddBmp->hInst;
2823 info.nID = lpAddBmp->nID;
2824 TRACE("adding %d bitmaps!\n", info.nButtons);
2827 /* check if the bitmap is already loaded and compute iSumButtons */
2828 iSumButtons = 0;
2829 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2831 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2832 infoPtr->bitmaps[i].nID == info.nID)
2833 return iSumButtons;
2834 iSumButtons += infoPtr->bitmaps[i].nButtons;
2837 if (!infoPtr->cimlDef) {
2838 /* create new default image list */
2839 TRACE ("creating default image list!\n");
2841 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2842 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2843 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2844 infoPtr->himlInt = himlDef;
2846 else {
2847 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2850 if (!himlDef) {
2851 WARN("No default image list available\n");
2852 return -1;
2855 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2856 return -1;
2858 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2859 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2860 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2861 infoPtr->nNumBitmapInfos++;
2862 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2864 InvalidateRect(hwnd, NULL, TRUE);
2865 return iSumButtons;
2869 static LRESULT
2870 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2872 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2873 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2874 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2875 BOOL fHasString = FALSE;
2877 TRACE("adding %d buttons (unicode=%d)!\n", wParam, fUnicode);
2879 nAddButtons = (UINT)wParam;
2880 nOldButtons = infoPtr->nNumButtons;
2881 nNewButtons = nOldButtons + nAddButtons;
2883 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
2884 infoPtr->nNumButtons = nNewButtons;
2886 /* insert new button data */
2887 for (nCount = 0; nCount < nAddButtons; nCount++) {
2888 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2889 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2890 btnPtr->idCommand = lpTbb[nCount].idCommand;
2891 btnPtr->fsState = lpTbb[nCount].fsState;
2892 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2893 btnPtr->dwData = lpTbb[nCount].dwData;
2894 btnPtr->bHot = FALSE;
2895 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2897 if (fUnicode)
2898 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2899 else
2900 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString);
2901 fHasString = TRUE;
2903 else
2904 btnPtr->iString = lpTbb[nCount].iString;
2906 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
2909 if (infoPtr->nNumStrings > 0 || fHasString)
2910 TOOLBAR_CalcToolbar(hwnd);
2911 else
2912 TOOLBAR_LayoutToolbar(hwnd);
2913 TOOLBAR_AutoSize (hwnd);
2915 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2917 InvalidateRect(hwnd, NULL, TRUE);
2919 return TRUE;
2923 static LRESULT
2924 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2926 #define MAX_RESOURCE_STRING_LENGTH 512
2927 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2928 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2929 INT nIndex = infoPtr->nNumStrings;
2931 if ((wParam) && (HIWORD(lParam) == 0)) {
2932 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2933 WCHAR delimiter;
2934 WCHAR *next_delim;
2935 WCHAR *p;
2936 INT len;
2937 TRACE("adding string from resource!\n");
2939 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2940 szString, MAX_RESOURCE_STRING_LENGTH);
2942 TRACE("len=%d %s\n", len, debugstr_w(szString));
2943 if (len == 0 || len == 1)
2944 return nIndex;
2946 TRACE("Delimiter: 0x%x\n", *szString);
2947 delimiter = *szString;
2948 p = szString + 1;
2950 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2951 *next_delim = 0;
2952 if (next_delim + 1 >= szString + len)
2954 /* this may happen if delimiter == '\0' or if the last char is a
2955 * delimiter (then it is ignored like the native does) */
2956 break;
2959 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2960 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2961 infoPtr->nNumStrings++;
2963 p = next_delim + 1;
2966 else {
2967 LPWSTR p = (LPWSTR)lParam;
2968 INT len;
2970 if (p == NULL)
2971 return -1;
2972 TRACE("adding string(s) from array!\n");
2973 while (*p) {
2974 len = strlenW (p);
2976 TRACE("len=%d %s\n", len, debugstr_w(p));
2977 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2978 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2979 infoPtr->nNumStrings++;
2981 p += (len+1);
2985 if (fFirstString)
2986 TOOLBAR_CalcToolbar(hwnd);
2987 return nIndex;
2991 static LRESULT
2992 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2994 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2995 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2996 LPSTR p;
2997 INT nIndex;
2998 INT len;
3000 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
3001 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
3003 p = (LPSTR)lParam;
3004 if (p == NULL)
3005 return -1;
3007 TRACE("adding string(s) from array!\n");
3008 nIndex = infoPtr->nNumStrings;
3009 while (*p) {
3010 len = strlen (p);
3011 TRACE("len=%d \"%s\"\n", len, p);
3013 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
3014 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
3015 infoPtr->nNumStrings++;
3017 p += (len+1);
3020 if (fFirstString)
3021 TOOLBAR_CalcToolbar(hwnd);
3022 return nIndex;
3026 static LRESULT
3027 TOOLBAR_AutoSize (HWND hwnd)
3029 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3030 RECT parent_rect;
3031 HWND parent;
3032 INT x, y;
3033 INT cx, cy;
3035 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3037 parent = GetParent (hwnd);
3039 if (!parent || !infoPtr->bDoRedraw)
3040 return 0;
3042 GetClientRect(parent, &parent_rect);
3044 x = parent_rect.left;
3045 y = parent_rect.top;
3047 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3049 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3050 cx = parent_rect.right - parent_rect.left;
3052 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3054 TOOLBAR_LayoutToolbar(hwnd);
3055 InvalidateRect( hwnd, NULL, TRUE );
3058 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3060 RECT window_rect;
3061 UINT uPosFlags = SWP_NOZORDER;
3063 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3065 GetWindowRect(hwnd, &window_rect);
3066 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3067 y = window_rect.top;
3069 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3071 GetWindowRect(hwnd, &window_rect);
3072 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3075 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3076 uPosFlags |= SWP_NOMOVE;
3078 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3079 cy += GetSystemMetrics(SM_CYEDGE);
3081 if (infoPtr->dwStyle & WS_BORDER)
3083 x = y = 1; /* FIXME: this looks wrong */
3084 cy += GetSystemMetrics(SM_CYEDGE);
3085 cx += GetSystemMetrics(SM_CXEDGE);
3088 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3091 return 0;
3095 static LRESULT
3096 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3098 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3100 return infoPtr->nNumButtons;
3104 static LRESULT
3105 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3107 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3109 infoPtr->dwStructSize = (DWORD)wParam;
3111 return 0;
3115 static LRESULT
3116 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3118 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3119 TBUTTON_INFO *btnPtr;
3120 INT nIndex;
3122 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3124 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3125 if (nIndex == -1)
3126 return FALSE;
3128 btnPtr = &infoPtr->buttons[nIndex];
3129 btnPtr->iBitmap = LOWORD(lParam);
3131 /* we HAVE to erase the background, the new bitmap could be */
3132 /* transparent */
3133 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3135 return TRUE;
3139 static LRESULT
3140 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3142 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3143 TBUTTON_INFO *btnPtr;
3144 INT nIndex;
3145 INT nOldIndex = -1;
3146 BOOL bChecked = FALSE;
3148 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3150 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3152 if (nIndex == -1)
3153 return FALSE;
3155 btnPtr = &infoPtr->buttons[nIndex];
3157 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3159 if (LOWORD(lParam) == FALSE)
3160 btnPtr->fsState &= ~TBSTATE_CHECKED;
3161 else {
3162 if (btnPtr->fsStyle & BTNS_GROUP) {
3163 nOldIndex =
3164 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3165 if (nOldIndex == nIndex)
3166 return 0;
3167 if (nOldIndex != -1)
3168 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3170 btnPtr->fsState |= TBSTATE_CHECKED;
3173 if( bChecked != LOWORD(lParam) )
3175 if (nOldIndex != -1)
3176 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3177 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3180 /* FIXME: Send a WM_NOTIFY?? */
3182 return TRUE;
3186 static LRESULT
3187 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3189 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3191 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3195 static LRESULT
3196 TOOLBAR_Customize (HWND hwnd)
3198 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3199 CUSTDLG_INFO custInfo;
3200 LRESULT ret;
3201 LPCVOID template;
3202 HRSRC hRes;
3203 NMHDR nmhdr;
3205 custInfo.tbInfo = infoPtr;
3206 custInfo.tbHwnd = hwnd;
3208 /* send TBN_BEGINADJUST notification */
3209 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3211 if (!(hRes = FindResourceW (COMCTL32_hModule,
3212 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3213 (LPWSTR)RT_DIALOG)))
3214 return FALSE;
3216 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3217 return FALSE;
3219 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3220 (LPCDLGTEMPLATEW)template,
3221 hwnd,
3222 TOOLBAR_CustomizeDialogProc,
3223 (LPARAM)&custInfo);
3225 /* send TBN_ENDADJUST notification */
3226 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3228 return ret;
3232 static LRESULT
3233 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3235 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3236 INT nIndex = (INT)wParam;
3237 NMTOOLBARW nmtb;
3238 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3240 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3241 return FALSE;
3243 memset(&nmtb, 0, sizeof(nmtb));
3244 nmtb.iItem = btnPtr->idCommand;
3245 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3246 nmtb.tbButton.idCommand = btnPtr->idCommand;
3247 nmtb.tbButton.fsState = btnPtr->fsState;
3248 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3249 nmtb.tbButton.dwData = btnPtr->dwData;
3250 nmtb.tbButton.iString = btnPtr->iString;
3251 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3253 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3255 if (infoPtr->nNumButtons == 1) {
3256 TRACE(" simple delete!\n");
3257 Free (infoPtr->buttons);
3258 infoPtr->buttons = NULL;
3259 infoPtr->nNumButtons = 0;
3261 else {
3262 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3263 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3265 infoPtr->nNumButtons--;
3266 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3267 if (nIndex > 0) {
3268 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3269 nIndex * sizeof(TBUTTON_INFO));
3272 if (nIndex < infoPtr->nNumButtons) {
3273 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3274 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3277 Free (oldButtons);
3280 TOOLBAR_LayoutToolbar(hwnd);
3282 InvalidateRect (hwnd, NULL, TRUE);
3284 return TRUE;
3288 static LRESULT
3289 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3291 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3292 TBUTTON_INFO *btnPtr;
3293 INT nIndex;
3294 DWORD bState;
3296 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3298 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3300 if (nIndex == -1)
3301 return FALSE;
3303 btnPtr = &infoPtr->buttons[nIndex];
3305 bState = btnPtr->fsState & TBSTATE_ENABLED;
3307 /* update the toolbar button state */
3308 if(LOWORD(lParam) == FALSE) {
3309 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3310 } else {
3311 btnPtr->fsState |= TBSTATE_ENABLED;
3314 /* redraw the button only if the state of the button changed */
3315 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3316 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3318 return TRUE;
3322 static inline LRESULT
3323 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3325 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3327 return infoPtr->bAnchor;
3331 static LRESULT
3332 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3334 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3335 INT nIndex;
3337 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3338 if (nIndex == -1)
3339 return -1;
3341 return infoPtr->buttons[nIndex].iBitmap;
3345 static inline LRESULT
3346 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3348 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3352 static LRESULT
3353 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3355 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3356 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3357 INT nIndex = (INT)wParam;
3358 TBUTTON_INFO *btnPtr;
3360 if (lpTbb == NULL)
3361 return FALSE;
3363 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3364 return FALSE;
3366 btnPtr = &infoPtr->buttons[nIndex];
3367 lpTbb->iBitmap = btnPtr->iBitmap;
3368 lpTbb->idCommand = btnPtr->idCommand;
3369 lpTbb->fsState = btnPtr->fsState;
3370 lpTbb->fsStyle = btnPtr->fsStyle;
3371 lpTbb->bReserved[0] = 0;
3372 lpTbb->bReserved[1] = 0;
3373 lpTbb->dwData = btnPtr->dwData;
3374 lpTbb->iString = btnPtr->iString;
3376 return TRUE;
3380 static LRESULT
3381 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3383 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3384 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3385 TBUTTON_INFO *btnPtr;
3386 INT nIndex;
3388 if (lpTbInfo == NULL)
3389 return -1;
3390 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3391 return -1;
3393 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3394 lpTbInfo->dwMask & 0x80000000);
3395 if (nIndex == -1)
3396 return -1;
3398 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3400 if (lpTbInfo->dwMask & TBIF_COMMAND)
3401 lpTbInfo->idCommand = btnPtr->idCommand;
3402 if (lpTbInfo->dwMask & TBIF_IMAGE)
3403 lpTbInfo->iImage = btnPtr->iBitmap;
3404 if (lpTbInfo->dwMask & TBIF_LPARAM)
3405 lpTbInfo->lParam = btnPtr->dwData;
3406 if (lpTbInfo->dwMask & TBIF_SIZE)
3407 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3408 if (lpTbInfo->dwMask & TBIF_STATE)
3409 lpTbInfo->fsState = btnPtr->fsState;
3410 if (lpTbInfo->dwMask & TBIF_STYLE)
3411 lpTbInfo->fsStyle = btnPtr->fsStyle;
3412 if (lpTbInfo->dwMask & TBIF_TEXT) {
3413 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3414 can't use TOOLBAR_GetText here */
3415 LPWSTR lpText;
3416 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3417 lpText = (LPWSTR)btnPtr->iString;
3418 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3419 } else
3420 lpTbInfo->pszText[0] = '\0';
3422 return nIndex;
3426 static LRESULT
3427 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3429 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3430 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3431 TBUTTON_INFO *btnPtr;
3432 INT nIndex;
3434 if (lpTbInfo == NULL)
3435 return -1;
3436 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3437 return -1;
3439 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3440 lpTbInfo->dwMask & 0x80000000);
3441 if (nIndex == -1)
3442 return -1;
3444 btnPtr = &infoPtr->buttons[nIndex];
3446 if(!btnPtr)
3447 return -1;
3449 if (lpTbInfo->dwMask & TBIF_COMMAND)
3450 lpTbInfo->idCommand = btnPtr->idCommand;
3451 if (lpTbInfo->dwMask & TBIF_IMAGE)
3452 lpTbInfo->iImage = btnPtr->iBitmap;
3453 if (lpTbInfo->dwMask & TBIF_LPARAM)
3454 lpTbInfo->lParam = btnPtr->dwData;
3455 if (lpTbInfo->dwMask & TBIF_SIZE)
3456 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3457 if (lpTbInfo->dwMask & TBIF_STATE)
3458 lpTbInfo->fsState = btnPtr->fsState;
3459 if (lpTbInfo->dwMask & TBIF_STYLE)
3460 lpTbInfo->fsStyle = btnPtr->fsStyle;
3461 if (lpTbInfo->dwMask & TBIF_TEXT) {
3462 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3463 can't use TOOLBAR_GetText here */
3464 LPWSTR lpText;
3465 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3466 lpText = (LPWSTR)btnPtr->iString;
3467 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3468 } else
3469 lpTbInfo->pszText[0] = '\0';
3472 return nIndex;
3476 static LRESULT
3477 TOOLBAR_GetButtonSize (HWND hwnd)
3479 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3481 return MAKELONG((WORD)infoPtr->nButtonWidth,
3482 (WORD)infoPtr->nButtonHeight);
3486 static LRESULT
3487 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3489 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3490 INT nIndex;
3491 LPWSTR lpText;
3493 if (lParam == 0)
3494 return -1;
3496 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3497 if (nIndex == -1)
3498 return -1;
3500 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3502 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3503 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3507 static LRESULT
3508 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3510 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3511 INT nIndex;
3512 LPWSTR lpText;
3513 LRESULT ret = 0;
3515 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3516 if (nIndex == -1)
3517 return -1;
3519 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3521 if (lpText)
3523 ret = strlenW (lpText);
3525 if (lParam)
3526 strcpyW ((LPWSTR)lParam, lpText);
3529 return ret;
3533 static LRESULT
3534 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3536 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3537 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3538 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3542 inline static LRESULT
3543 TOOLBAR_GetExtendedStyle (HWND hwnd)
3545 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3547 TRACE("\n");
3549 return infoPtr->dwExStyle;
3553 static LRESULT
3554 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3556 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3557 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3558 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3562 static LRESULT
3563 TOOLBAR_GetHotItem (HWND hwnd)
3565 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3567 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3568 return -1;
3570 if (infoPtr->nHotItem < 0)
3571 return -1;
3573 return (LRESULT)infoPtr->nHotItem;
3577 static LRESULT
3578 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3580 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3581 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3582 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3586 static LRESULT
3587 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3589 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3590 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3592 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3594 *lptbim = infoPtr->tbim;
3596 return 0;
3600 static LRESULT
3601 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3603 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3605 TRACE("hwnd = %p\n", hwnd);
3607 return (LRESULT)infoPtr->clrInsertMark;
3611 static LRESULT
3612 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3614 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3615 TBUTTON_INFO *btnPtr;
3616 LPRECT lpRect;
3617 INT nIndex;
3619 nIndex = (INT)wParam;
3620 btnPtr = &infoPtr->buttons[nIndex];
3621 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3622 return FALSE;
3623 lpRect = (LPRECT)lParam;
3624 if (lpRect == NULL)
3625 return FALSE;
3626 if (btnPtr->fsState & TBSTATE_HIDDEN)
3627 return FALSE;
3629 lpRect->left = btnPtr->rect.left;
3630 lpRect->right = btnPtr->rect.right;
3631 lpRect->bottom = btnPtr->rect.bottom;
3632 lpRect->top = btnPtr->rect.top;
3634 return TRUE;
3638 static LRESULT
3639 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3641 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3642 LPSIZE lpSize = (LPSIZE)lParam;
3644 if (lpSize == NULL)
3645 return FALSE;
3647 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3648 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3650 TRACE("maximum size %d x %d\n",
3651 infoPtr->rcBound.right - infoPtr->rcBound.left,
3652 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3654 return TRUE;
3658 /* << TOOLBAR_GetObject >> */
3661 static LRESULT
3662 TOOLBAR_GetPadding (HWND hwnd)
3664 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3665 DWORD oldPad;
3667 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3668 return (LRESULT) oldPad;
3672 static LRESULT
3673 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3675 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3676 TBUTTON_INFO *btnPtr;
3677 LPRECT lpRect;
3678 INT nIndex;
3680 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3681 btnPtr = &infoPtr->buttons[nIndex];
3682 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3683 return FALSE;
3684 lpRect = (LPRECT)lParam;
3685 if (lpRect == NULL)
3686 return FALSE;
3688 lpRect->left = btnPtr->rect.left;
3689 lpRect->right = btnPtr->rect.right;
3690 lpRect->bottom = btnPtr->rect.bottom;
3691 lpRect->top = btnPtr->rect.top;
3693 return TRUE;
3697 static LRESULT
3698 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3700 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3702 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3703 return infoPtr->nRows;
3704 else
3705 return 1;
3709 static LRESULT
3710 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3712 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3713 INT nIndex;
3715 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3716 if (nIndex == -1)
3717 return -1;
3719 return infoPtr->buttons[nIndex].fsState;
3723 static LRESULT
3724 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3726 return GetWindowLongW(hwnd, GWL_STYLE);
3730 static LRESULT
3731 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3733 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3735 return infoPtr->nMaxTextRows;
3739 static LRESULT
3740 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3742 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3744 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3745 TOOLBAR_TooltipCreateControl(infoPtr);
3746 return (LRESULT)infoPtr->hwndToolTip;
3750 static LRESULT
3751 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3753 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3755 TRACE("%s hwnd=%p\n",
3756 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3758 return infoPtr->bUnicode;
3762 inline static LRESULT
3763 TOOLBAR_GetVersion (HWND hwnd)
3765 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3766 return infoPtr->iVersion;
3770 static LRESULT
3771 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3773 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3774 TBUTTON_INFO *btnPtr;
3775 INT nIndex;
3777 TRACE("\n");
3779 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3780 if (nIndex == -1)
3781 return FALSE;
3783 btnPtr = &infoPtr->buttons[nIndex];
3784 if (LOWORD(lParam) == FALSE)
3785 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3786 else
3787 btnPtr->fsState |= TBSTATE_HIDDEN;
3789 TOOLBAR_CalcToolbar (hwnd);
3791 InvalidateRect (hwnd, NULL, TRUE);
3793 return TRUE;
3797 inline static LRESULT
3798 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3800 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3804 static LRESULT
3805 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3807 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3808 TBUTTON_INFO *btnPtr;
3809 INT nIndex;
3810 DWORD oldState;
3812 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3813 if (nIndex == -1)
3814 return FALSE;
3816 btnPtr = &infoPtr->buttons[nIndex];
3817 oldState = btnPtr->fsState;
3818 if (LOWORD(lParam) == FALSE)
3819 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3820 else
3821 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3823 if(oldState != btnPtr->fsState)
3824 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3826 return TRUE;
3830 static LRESULT
3831 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3833 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3834 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3835 INT nIndex = (INT)wParam;
3837 if (lpTbb == NULL)
3838 return FALSE;
3840 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3842 if (nIndex == -1) {
3843 /* EPP: this seems to be an undocumented call (from my IE4)
3844 * I assume in that case that:
3845 * - index of insertion is at the end of existing buttons
3846 * I only see this happen with nIndex == -1, but it could have a special
3847 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3849 nIndex = infoPtr->nNumButtons;
3851 } else if (nIndex < 0)
3852 return FALSE;
3854 TRACE("inserting button index=%d\n", nIndex);
3855 if (nIndex > infoPtr->nNumButtons) {
3856 nIndex = infoPtr->nNumButtons;
3857 TRACE("adjust index=%d\n", nIndex);
3860 infoPtr->nNumButtons++;
3861 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO) * infoPtr->nNumButtons);
3862 memmove(&infoPtr->buttons[nIndex+1], &infoPtr->buttons[nIndex],
3863 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3865 /* insert new button */
3866 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3867 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3868 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3869 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3870 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3871 /* if passed string and not index, then add string */
3872 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3873 if (fUnicode)
3874 Str_SetPtrW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3875 else
3876 Str_SetPtrAtoW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3878 else
3879 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3881 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
3883 if (infoPtr->nNumStrings > 0)
3884 TOOLBAR_CalcToolbar(hwnd);
3885 else
3886 TOOLBAR_LayoutToolbar(hwnd);
3887 TOOLBAR_AutoSize (hwnd);
3889 InvalidateRect (hwnd, NULL, TRUE);
3891 return TRUE;
3894 /* << TOOLBAR_InsertMarkHitTest >> */
3897 static LRESULT
3898 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3900 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3901 INT nIndex;
3903 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3904 if (nIndex == -1)
3905 return FALSE;
3907 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3911 static LRESULT
3912 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3914 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3915 INT nIndex;
3917 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3918 if (nIndex == -1)
3919 return FALSE;
3921 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3925 static LRESULT
3926 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3928 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3929 INT nIndex;
3931 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3932 if (nIndex == -1)
3933 return TRUE;
3935 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3939 static LRESULT
3940 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3942 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3943 INT nIndex;
3945 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3946 if (nIndex == -1)
3947 return FALSE;
3949 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3953 static LRESULT
3954 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3956 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3957 INT nIndex;
3959 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3960 if (nIndex == -1)
3961 return FALSE;
3963 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3967 static LRESULT
3968 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3970 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3971 INT nIndex;
3973 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3974 if (nIndex == -1)
3975 return FALSE;
3977 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3981 static LRESULT
3982 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3984 TBADDBITMAP tbab;
3985 tbab.hInst = (HINSTANCE)lParam;
3986 tbab.nID = (UINT_PTR)wParam;
3988 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3990 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3994 static LRESULT
3995 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3997 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3998 WCHAR wAccel = (WCHAR)wParam;
3999 UINT* pIDButton = (UINT*)lParam;
4000 WCHAR wszAccel[] = {'&',wAccel,0};
4001 int i;
4003 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4004 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4006 for (i = 0; i < infoPtr->nNumButtons; i++)
4008 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4009 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4010 !(btnPtr->fsState & TBSTATE_HIDDEN))
4012 int iLen = strlenW(wszAccel);
4013 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4015 if (!lpszStr)
4016 continue;
4018 while (*lpszStr)
4020 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4022 lpszStr += 2;
4023 continue;
4025 if (!strncmpiW(lpszStr, wszAccel, iLen))
4027 *pIDButton = btnPtr->idCommand;
4028 return TRUE;
4030 lpszStr++;
4034 return FALSE;
4038 static LRESULT
4039 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4041 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4042 INT nIndex;
4043 DWORD oldState;
4044 TBUTTON_INFO *btnPtr;
4046 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4048 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4049 if (nIndex == -1)
4050 return FALSE;
4052 btnPtr = &infoPtr->buttons[nIndex];
4053 oldState = btnPtr->fsState;
4055 if (LOWORD(lParam))
4056 btnPtr->fsState |= TBSTATE_MARKED;
4057 else
4058 btnPtr->fsState &= ~TBSTATE_MARKED;
4060 if(oldState != btnPtr->fsState)
4061 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4063 return TRUE;
4067 /* fixes up an index of a button affected by a move */
4068 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4070 if (bMoveUp)
4072 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4073 (*pIndex)--;
4074 else if (*pIndex == nIndex)
4075 *pIndex = nMoveIndex;
4077 else
4079 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4080 (*pIndex)++;
4081 else if (*pIndex == nIndex)
4082 *pIndex = nMoveIndex;
4087 static LRESULT
4088 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4090 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4091 INT nIndex;
4092 INT nCount;
4093 INT nMoveIndex = (INT)lParam;
4094 TBUTTON_INFO button;
4096 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4098 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4099 if ((nIndex == -1) || (nMoveIndex < 0))
4100 return FALSE;
4102 if (nMoveIndex > infoPtr->nNumButtons - 1)
4103 nMoveIndex = infoPtr->nNumButtons - 1;
4105 button = infoPtr->buttons[nIndex];
4107 /* move button right */
4108 if (nIndex < nMoveIndex)
4110 nCount = nMoveIndex - nIndex;
4111 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4112 infoPtr->buttons[nMoveIndex] = button;
4114 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4115 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4116 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4117 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4119 else if (nIndex > nMoveIndex) /* move button left */
4121 nCount = nIndex - nMoveIndex;
4122 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4123 infoPtr->buttons[nMoveIndex] = button;
4125 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4126 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4127 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4128 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4131 TOOLBAR_CalcToolbar(hwnd);
4132 TOOLBAR_AutoSize(hwnd);
4133 InvalidateRect(hwnd, NULL, TRUE);
4135 return TRUE;
4139 static LRESULT
4140 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4142 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4143 TBUTTON_INFO *btnPtr;
4144 INT nIndex;
4145 DWORD oldState;
4147 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4148 if (nIndex == -1)
4149 return FALSE;
4151 btnPtr = &infoPtr->buttons[nIndex];
4152 oldState = btnPtr->fsState;
4153 if (LOWORD(lParam) == FALSE)
4154 btnPtr->fsState &= ~TBSTATE_PRESSED;
4155 else
4156 btnPtr->fsState |= TBSTATE_PRESSED;
4158 if(oldState != btnPtr->fsState)
4159 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4161 return TRUE;
4164 /* FIXME: there might still be some confusion her between number of buttons
4165 * and number of bitmaps */
4166 static LRESULT
4167 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4169 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4170 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4171 HBITMAP hBitmap;
4172 HBITMAP hbmLoad = NULL;
4173 int i = 0, nOldButtons = 0, pos = 0;
4174 int nOldBitmaps, nNewBitmaps = 0;
4175 HIMAGELIST himlDef = 0;
4177 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4178 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4179 lpReplace->nButtons);
4181 if (lpReplace->hInstOld == HINST_COMMCTRL)
4183 FIXME("changing standard bitmaps not implemented\n");
4184 return FALSE;
4186 else if (lpReplace->hInstOld != 0)
4187 FIXME("resources not in the current module not implemented\n");
4189 if (lpReplace->hInstNew)
4191 hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4192 hBitmap = hbmLoad;
4194 else
4196 hBitmap = (HBITMAP) lpReplace->nIDNew;
4199 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4200 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4201 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4202 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4203 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4205 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4206 nOldButtons = tbi->nButtons;
4207 tbi->nButtons = lpReplace->nButtons;
4208 tbi->hInst = lpReplace->hInstNew;
4209 tbi->nID = lpReplace->nIDNew;
4210 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4211 break;
4213 pos += tbi->nButtons;
4216 if (nOldButtons == 0)
4218 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4219 if (hbmLoad)
4220 DeleteObject (hbmLoad);
4221 return FALSE;
4224 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4225 nOldBitmaps = ImageList_GetImageCount(himlDef);
4227 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4229 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4230 ImageList_Remove(himlDef, i);
4232 if (hBitmap)
4234 BITMAP bmp;
4235 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4236 HDC hdcImage, hdcBitmap;
4238 /* copy the bitmap before adding it so that the user's bitmap
4239 * doesn't get modified.
4241 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4243 hdcImage = CreateCompatibleDC(0);
4244 hdcBitmap = CreateCompatibleDC(0);
4246 /* create new bitmap */
4247 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4248 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4249 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4251 /* Copy the user's image */
4252 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4253 hdcBitmap, 0, 0, SRCCOPY);
4255 SelectObject (hdcImage, hOldBitmapLoad);
4256 SelectObject (hdcBitmap, hOldBitmapBitmap);
4257 DeleteDC (hdcImage);
4258 DeleteDC (hdcBitmap);
4260 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4261 nNewBitmaps = ImageList_GetImageCount(himlDef);
4262 DeleteObject (hbmLoad);
4265 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4267 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4268 pos, nOldBitmaps, nNewBitmaps);
4270 InvalidateRect(hwnd, NULL, TRUE);
4272 if (hbmLoad)
4273 DeleteObject (hbmLoad);
4274 return TRUE;
4278 /* helper for TOOLBAR_SaveRestoreW */
4279 static BOOL
4280 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4282 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4283 debugstr_w(lpSave->pszValueName));
4285 return FALSE;
4289 /* helper for TOOLBAR_Restore */
4290 static void
4291 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4293 INT i;
4295 for (i = 0; i < infoPtr->nNumButtons; i++)
4297 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4300 Free(infoPtr->buttons);
4301 infoPtr->buttons = NULL;
4302 infoPtr->nNumButtons = 0;
4306 /* helper for TOOLBAR_SaveRestoreW */
4307 static BOOL
4308 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4310 LONG res;
4311 HKEY hkey = NULL;
4312 BOOL ret = FALSE;
4313 DWORD dwType;
4314 DWORD dwSize = 0;
4315 NMTBRESTORE nmtbr;
4317 /* restore toolbar information */
4318 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4319 debugstr_w(lpSave->pszValueName));
4321 memset(&nmtbr, 0, sizeof(nmtbr));
4323 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4324 KEY_QUERY_VALUE, &hkey);
4325 if (!res)
4326 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4327 NULL, &dwSize);
4328 if (!res && dwType != REG_BINARY)
4329 res = ERROR_FILE_NOT_FOUND;
4330 if (!res)
4332 nmtbr.pData = Alloc(dwSize);
4333 nmtbr.cbData = (UINT)dwSize;
4334 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4336 if (!res)
4337 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4338 (LPBYTE)nmtbr.pData, &dwSize);
4339 if (!res)
4341 nmtbr.pCurrent = nmtbr.pData;
4342 nmtbr.iItem = -1;
4343 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4344 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4346 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4348 INT i;
4350 /* remove all existing buttons as this function is designed to
4351 * restore the toolbar to a previously saved state */
4352 TOOLBAR_DeleteAllButtons(infoPtr);
4354 for (i = 0; i < nmtbr.cButtons; i++)
4356 nmtbr.iItem = i;
4357 nmtbr.tbButton.iBitmap = -1;
4358 nmtbr.tbButton.fsState = 0;
4359 nmtbr.tbButton.fsStyle = 0;
4360 nmtbr.tbButton.idCommand = 0;
4361 if (*nmtbr.pCurrent == (DWORD)-1)
4363 /* separator */
4364 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4365 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4367 else if (*nmtbr.pCurrent == (DWORD)-2)
4368 /* hidden button */
4369 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4370 else
4371 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4373 nmtbr.pCurrent++;
4375 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4377 /* can't contain real string as we don't know whether
4378 * the client put an ANSI or Unicode string in there */
4379 if (HIWORD(nmtbr.tbButton.iString))
4380 nmtbr.tbButton.iString = 0;
4382 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4383 (LPARAM)&nmtbr.tbButton, TRUE);
4386 /* do legacy notifications */
4387 if (infoPtr->iVersion < 5)
4389 /* FIXME: send TBN_BEGINADJUST */
4390 FIXME("send TBN_GETBUTTONINFO for each button\n");
4391 /* FIXME: send TBN_ENDADJUST */
4394 /* remove all uninitialised buttons
4395 * note: loop backwards to avoid having to fixup i on a
4396 * delete */
4397 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4398 if (infoPtr->buttons[i].iBitmap == -1)
4399 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4401 /* only indicate success if at least one button survived */
4402 if (infoPtr->nNumButtons > 0) ret = TRUE;
4405 Free (nmtbr.pData);
4406 RegCloseKey(hkey);
4408 return ret;
4412 static LRESULT
4413 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4415 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4417 if (lpSave == NULL) return 0;
4419 if (wParam)
4420 return TOOLBAR_Save(infoPtr, lpSave);
4421 else
4422 return TOOLBAR_Restore(infoPtr, lpSave);
4426 static LRESULT
4427 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4429 LPWSTR pszValueName = 0, pszSubKey = 0;
4430 TBSAVEPARAMSW SaveW;
4431 LRESULT result = 0;
4432 int len;
4434 if (lpSave == NULL) return 0;
4436 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4437 pszSubKey = Alloc(len * sizeof(WCHAR));
4438 if (pszSubKey) goto exit;
4439 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4441 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4442 pszValueName = Alloc(len * sizeof(WCHAR));
4443 if (!pszValueName) goto exit;
4444 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4446 SaveW.pszValueName = pszValueName;
4447 SaveW.pszSubKey = pszSubKey;
4448 SaveW.hkr = lpSave->hkr;
4449 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4451 exit:
4452 Free (pszValueName);
4453 Free (pszSubKey);
4455 return result;
4459 static LRESULT
4460 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4462 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4463 BOOL bOldAnchor = infoPtr->bAnchor;
4465 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4467 infoPtr->bAnchor = (BOOL)wParam;
4469 /* Native does not remove the hot effect from an already hot button */
4471 return (LRESULT)bOldAnchor;
4475 static LRESULT
4476 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4478 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4479 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4481 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4483 if (wParam != 0)
4484 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4486 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4487 lParam = MAKELPARAM(16, 15);
4489 if (infoPtr->nNumButtons > 0)
4490 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4491 infoPtr->nNumButtons,
4492 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4493 LOWORD(lParam), HIWORD(lParam));
4495 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4496 infoPtr->nVBitmapHeight = infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4498 if ((himlDef == infoPtr->himlInt) &&
4499 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4501 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4502 infoPtr->nBitmapHeight);
4505 TOOLBAR_CalcToolbar(hwnd);
4506 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4507 return TRUE;
4511 static LRESULT
4512 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4514 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4515 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4516 TBUTTON_INFO *btnPtr;
4517 INT nIndex;
4518 RECT oldBtnRect;
4520 if (lptbbi == NULL)
4521 return FALSE;
4522 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4523 return FALSE;
4525 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4526 lptbbi->dwMask & 0x80000000);
4527 if (nIndex == -1)
4528 return FALSE;
4530 btnPtr = &infoPtr->buttons[nIndex];
4531 if (lptbbi->dwMask & TBIF_COMMAND)
4532 btnPtr->idCommand = lptbbi->idCommand;
4533 if (lptbbi->dwMask & TBIF_IMAGE)
4534 btnPtr->iBitmap = lptbbi->iImage;
4535 if (lptbbi->dwMask & TBIF_LPARAM)
4536 btnPtr->dwData = lptbbi->lParam;
4537 if (lptbbi->dwMask & TBIF_SIZE)
4538 btnPtr->cx = lptbbi->cx;
4539 if (lptbbi->dwMask & TBIF_STATE)
4540 btnPtr->fsState = lptbbi->fsState;
4541 if (lptbbi->dwMask & TBIF_STYLE)
4542 btnPtr->fsStyle = lptbbi->fsStyle;
4544 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4545 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4546 /* iString is index, zero it to make Str_SetPtr succeed */
4547 btnPtr->iString=0;
4549 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4552 /* save the button rect to see if we need to redraw the whole toolbar */
4553 oldBtnRect = btnPtr->rect;
4554 TOOLBAR_CalcToolbar(hwnd);
4556 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4557 InvalidateRect(hwnd, NULL, TRUE);
4558 else
4559 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4561 return TRUE;
4565 static LRESULT
4566 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4568 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4569 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4570 TBUTTON_INFO *btnPtr;
4571 INT nIndex;
4572 RECT oldBtnRect;
4574 if (lptbbi == NULL)
4575 return FALSE;
4576 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4577 return FALSE;
4579 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4580 lptbbi->dwMask & 0x80000000);
4581 if (nIndex == -1)
4582 return FALSE;
4584 btnPtr = &infoPtr->buttons[nIndex];
4585 if (lptbbi->dwMask & TBIF_COMMAND)
4586 btnPtr->idCommand = lptbbi->idCommand;
4587 if (lptbbi->dwMask & TBIF_IMAGE)
4588 btnPtr->iBitmap = lptbbi->iImage;
4589 if (lptbbi->dwMask & TBIF_LPARAM)
4590 btnPtr->dwData = lptbbi->lParam;
4591 if (lptbbi->dwMask & TBIF_SIZE)
4592 btnPtr->cx = lptbbi->cx;
4593 if (lptbbi->dwMask & TBIF_STATE)
4594 btnPtr->fsState = lptbbi->fsState;
4595 if (lptbbi->dwMask & TBIF_STYLE)
4596 btnPtr->fsStyle = lptbbi->fsStyle;
4598 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4599 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4600 /* iString is index, zero it to make Str_SetPtr succeed */
4601 btnPtr->iString=0;
4602 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4605 /* save the button rect to see if we need to redraw the whole toolbar */
4606 oldBtnRect = btnPtr->rect;
4607 TOOLBAR_CalcToolbar(hwnd);
4609 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4610 InvalidateRect(hwnd, NULL, TRUE);
4611 else
4612 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4614 return TRUE;
4618 static LRESULT
4619 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4621 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4622 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4624 if ((cx < 0) || (cy < 0))
4626 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4627 return FALSE;
4630 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4632 /* The documentation claims you can only change the button size before
4633 * any button has been added. But this is wrong.
4634 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4635 * it to the toolbar, and it checks that the return value is nonzero - mjm
4636 * Further testing shows that we must actually perform the change too.
4639 * The documentation also does not mention that if 0 is supplied for
4640 * either size, the system changes it to the default of 24 wide and
4641 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4643 infoPtr->nButtonWidth = (cx) ? cx : 24;
4644 infoPtr->nButtonHeight = (cy) ? cy : 22;
4645 return TRUE;
4649 static LRESULT
4650 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4652 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4654 /* if setting to current values, ignore */
4655 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4656 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4657 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4658 infoPtr->cxMin, infoPtr->cxMax);
4659 return TRUE;
4662 /* save new values */
4663 infoPtr->cxMin = (short)LOWORD(lParam);
4664 infoPtr->cxMax = (short)HIWORD(lParam);
4666 /* otherwise we need to recalc the toolbar and in some cases
4667 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4668 which doesn't actually draw - GA). */
4669 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4670 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4672 TOOLBAR_CalcToolbar (hwnd);
4674 InvalidateRect (hwnd, NULL, TRUE);
4676 return TRUE;
4680 static LRESULT
4681 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4683 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4684 INT nIndex = (INT)wParam;
4686 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4687 return FALSE;
4689 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4691 if (infoPtr->hwndToolTip) {
4693 FIXME("change tool tip!\n");
4697 return TRUE;
4701 static LRESULT
4702 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4704 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4705 HIMAGELIST himl = (HIMAGELIST)lParam;
4706 HIMAGELIST himlTemp;
4707 INT id = 0;
4709 if (infoPtr->iVersion >= 5)
4710 id = wParam;
4712 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4713 &infoPtr->cimlDis, himl, id);
4715 /* FIXME: redraw ? */
4717 return (LRESULT)himlTemp;
4721 static LRESULT
4722 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4724 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4725 DWORD dwTemp;
4727 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4729 dwTemp = infoPtr->dwDTFlags;
4730 infoPtr->dwDTFlags =
4731 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4733 return (LRESULT)dwTemp;
4736 /* This function differs a bit from what MSDN says it does:
4737 * 1. lParam contains extended style flags to OR with current style
4738 * (MSDN isn't clear on the OR bit)
4739 * 2. wParam appears to contain extended style flags to be reset
4740 * (MSDN says that this parameter is reserved)
4742 static LRESULT
4743 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4745 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4746 DWORD dwTemp;
4748 dwTemp = infoPtr->dwExStyle;
4749 infoPtr->dwExStyle &= ~wParam;
4750 infoPtr->dwExStyle |= (DWORD)lParam;
4752 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4754 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4755 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4756 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4758 TOOLBAR_CalcToolbar (hwnd);
4760 TOOLBAR_AutoSize(hwnd);
4762 InvalidateRect(hwnd, NULL, TRUE);
4764 return (LRESULT)dwTemp;
4768 static LRESULT
4769 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4771 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4772 HIMAGELIST himlTemp;
4773 HIMAGELIST himl = (HIMAGELIST)lParam;
4774 INT id = 0;
4776 if (infoPtr->iVersion >= 5)
4777 id = wParam;
4779 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4781 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4782 &infoPtr->cimlHot, himl, id);
4784 /* FIXME: redraw ? */
4786 return (LRESULT)himlTemp;
4790 /* Makes previous hot button no longer hot, makes the specified
4791 * button hot and sends appropriate notifications. dwReason is one or
4792 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4793 * NOTE 1: this function does not validate nHit
4794 * NOTE 2: the name of this function is completely made up and
4795 * not based on any documentation from Microsoft. */
4796 static void
4797 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4799 if (infoPtr->nHotItem != nHit)
4801 NMTBHOTITEM nmhotitem;
4802 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4804 nmhotitem.dwFlags = dwReason;
4805 if(infoPtr->nHotItem >= 0)
4807 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4808 nmhotitem.idOld = oldBtnPtr->idCommand;
4810 else
4812 nmhotitem.dwFlags |= HICF_ENTERING;
4813 nmhotitem.idOld = 0;
4816 if (nHit >= 0)
4818 btnPtr = &infoPtr->buttons[nHit];
4819 nmhotitem.idNew = btnPtr->idCommand;
4821 else
4823 nmhotitem.dwFlags |= HICF_LEAVING;
4824 nmhotitem.idNew = 0;
4827 /* now change the hot and invalidate the old and new buttons - if the
4828 * parent agrees */
4829 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4831 if (oldBtnPtr) {
4832 oldBtnPtr->bHot = FALSE;
4833 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4835 /* setting disabled buttons as hot fails even if the notify contains the button id */
4836 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4837 btnPtr->bHot = TRUE;
4838 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4839 infoPtr->nHotItem = nHit;
4841 else
4842 infoPtr->nHotItem = -1;
4847 static LRESULT
4848 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4850 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4851 INT nOldHotItem = infoPtr->nHotItem;
4853 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4855 if ((INT)wParam > infoPtr->nNumButtons)
4856 return infoPtr->nHotItem;
4858 if ((INT)wParam < 0)
4859 wParam = -1;
4861 /* NOTE: an application can still remove the hot item even if anchor
4862 * highlighting is enabled */
4864 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4866 if (nOldHotItem < 0)
4867 return -1;
4869 return (LRESULT)nOldHotItem;
4873 static LRESULT
4874 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4876 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4877 HIMAGELIST himlTemp;
4878 HIMAGELIST himl = (HIMAGELIST)lParam;
4879 INT i, id = 0;
4881 if (infoPtr->iVersion >= 5)
4882 id = wParam;
4884 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4885 &infoPtr->cimlDef, himl, id);
4887 infoPtr->nNumBitmaps = 0;
4888 for (i = 0; i < infoPtr->cimlDef; i++)
4889 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4891 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4892 &infoPtr->nBitmapHeight))
4894 infoPtr->nBitmapWidth = 1;
4895 infoPtr->nBitmapHeight = 1;
4897 infoPtr->nVBitmapHeight = infoPtr->nBitmapHeight;
4899 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4900 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4901 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4903 InvalidateRect(hwnd, NULL, TRUE);
4905 return (LRESULT)himlTemp;
4909 static LRESULT
4910 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4912 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4914 infoPtr->nIndent = (INT)wParam;
4916 TRACE("\n");
4918 /* process only on indent changing */
4919 if(infoPtr->nIndent != (INT)wParam)
4921 infoPtr->nIndent = (INT)wParam;
4922 TOOLBAR_CalcToolbar (hwnd);
4923 InvalidateRect(hwnd, NULL, FALSE);
4926 return TRUE;
4930 static LRESULT
4931 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4933 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4934 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4936 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4938 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4940 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4941 return 0;
4944 if ((lptbim->iButton == -1) ||
4945 ((lptbim->iButton < infoPtr->nNumButtons) &&
4946 (lptbim->iButton >= 0)))
4948 infoPtr->tbim = *lptbim;
4949 /* FIXME: don't need to update entire toolbar */
4950 InvalidateRect(hwnd, NULL, TRUE);
4952 else
4953 ERR("Invalid button index %d\n", lptbim->iButton);
4955 return 0;
4959 static LRESULT
4960 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4962 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4964 infoPtr->clrInsertMark = (COLORREF)lParam;
4966 /* FIXME: don't need to update entire toolbar */
4967 InvalidateRect(hwnd, NULL, TRUE);
4969 return 0;
4973 static LRESULT
4974 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4976 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4978 infoPtr->nMaxTextRows = (INT)wParam;
4980 TOOLBAR_CalcToolbar(hwnd);
4981 return TRUE;
4985 /* MSDN gives slightly wrong info on padding.
4986 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4987 * 2. It is not used to create a blank area between the edge of the button
4988 * and the text or image if TBSTYLE_LIST is set. It is used to control
4989 * the gap between the image and text.
4990 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4991 * to control the bottom and right borders [with the border being
4992 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4993 * is shared evenly on both sides of the button.
4994 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4996 static LRESULT
4997 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4999 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5000 DWORD oldPad;
5002 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5003 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
5004 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
5005 TRACE("cx=%d, cy=%d\n",
5006 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5007 return (LRESULT) oldPad;
5011 static LRESULT
5012 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5014 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5015 HWND hwndOldNotify;
5017 TRACE("\n");
5019 hwndOldNotify = infoPtr->hwndNotify;
5020 infoPtr->hwndNotify = (HWND)wParam;
5022 return (LRESULT)hwndOldNotify;
5026 static LRESULT
5027 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5029 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5030 LPRECT lprc = (LPRECT)lParam;
5032 TRACE("\n");
5034 if (LOWORD(wParam) > 1) {
5035 FIXME("multiple rows not supported!\n");
5038 if(infoPtr->nRows != LOWORD(wParam))
5040 infoPtr->nRows = LOWORD(wParam);
5042 /* recalculate toolbar */
5043 TOOLBAR_CalcToolbar (hwnd);
5045 /* repaint toolbar */
5046 InvalidateRect(hwnd, NULL, TRUE);
5049 /* return bounding rectangle */
5050 if (lprc) {
5051 lprc->left = infoPtr->rcBound.left;
5052 lprc->right = infoPtr->rcBound.right;
5053 lprc->top = infoPtr->rcBound.top;
5054 lprc->bottom = infoPtr->rcBound.bottom;
5057 return 0;
5061 static LRESULT
5062 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5064 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5065 TBUTTON_INFO *btnPtr;
5066 INT nIndex;
5068 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5069 if (nIndex == -1)
5070 return FALSE;
5072 btnPtr = &infoPtr->buttons[nIndex];
5074 /* if hidden state has changed the invalidate entire window and recalc */
5075 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5076 btnPtr->fsState = LOWORD(lParam);
5077 TOOLBAR_CalcToolbar (hwnd);
5078 InvalidateRect(hwnd, 0, TRUE);
5079 return TRUE;
5082 /* process state changing if current state doesn't match new state */
5083 if(btnPtr->fsState != LOWORD(lParam))
5085 btnPtr->fsState = LOWORD(lParam);
5086 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5089 return TRUE;
5093 static LRESULT
5094 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5096 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5098 return TRUE;
5102 inline static LRESULT
5103 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5105 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5107 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5109 infoPtr->hwndToolTip = (HWND)wParam;
5110 return 0;
5114 static LRESULT
5115 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5117 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5118 BOOL bTemp;
5120 TRACE("%s hwnd=%p\n",
5121 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5123 bTemp = infoPtr->bUnicode;
5124 infoPtr->bUnicode = (BOOL)wParam;
5126 return bTemp;
5130 static LRESULT
5131 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5133 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5135 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5136 comctl32_color.clrBtnHighlight :
5137 infoPtr->clrBtnHighlight;
5138 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5139 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5140 return 1;
5144 static LRESULT
5145 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5147 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5149 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5150 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5151 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5153 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5154 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5155 InvalidateRect(hwnd, NULL, TRUE);
5156 return 0;
5160 static LRESULT
5161 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5163 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5164 INT iOldVersion = infoPtr->iVersion;
5166 infoPtr->iVersion = iVersion;
5168 if (infoPtr->iVersion >= 5)
5169 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5171 return iOldVersion;
5175 static LRESULT
5176 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5178 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5179 WORD iString = HIWORD(wParam);
5180 WORD buffersize = LOWORD(wParam);
5181 LPSTR str = (LPSTR)lParam;
5182 LRESULT ret = -1;
5184 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5186 if (iString < infoPtr->nNumStrings)
5188 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5190 TRACE("returning %s\n", debugstr_a(str));
5192 else
5193 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5195 return ret;
5199 static LRESULT
5200 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5202 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5203 WORD iString = HIWORD(wParam);
5204 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5205 LPWSTR str = (LPWSTR)lParam;
5206 LRESULT ret = -1;
5208 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5210 if (iString < infoPtr->nNumStrings)
5212 len = min(len, strlenW(infoPtr->strings[iString]));
5213 ret = (len+1)*sizeof(WCHAR);
5214 memcpy(str, infoPtr->strings[iString], ret);
5215 str[len] = '\0';
5217 TRACE("returning %s\n", debugstr_w(str));
5219 else
5220 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5222 return ret;
5225 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5226 * is the maximum size of the toolbar? */
5227 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5229 SIZE * pSize = (SIZE*)lParam;
5230 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5231 return 0;
5235 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5236 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5237 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5238 * sends). */
5239 static LRESULT
5240 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5242 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5243 INT nOldHotItem = infoPtr->nHotItem;
5245 TRACE("old item=%d, new item=%d, flags=%08x\n",
5246 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5248 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5249 wParam = -1;
5251 /* NOTE: an application can still remove the hot item even if anchor
5252 * highlighting is enabled */
5254 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5256 GetFocus();
5258 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5261 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5262 * which controls the amount of spacing between the image and the text
5263 * of buttons for TBSTYLE_LIST toolbars. */
5264 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5266 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5268 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5270 if (lParam != 0)
5271 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5273 infoPtr->iListGap = (INT)wParam;
5275 InvalidateRect(hwnd, NULL, TRUE);
5277 return 0;
5280 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5281 * of image lists associated with the various states. */
5282 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5284 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5286 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5288 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5291 static LRESULT
5292 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5294 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5295 LPSIZE lpsize = (LPSIZE)lParam;
5297 if (lpsize == NULL)
5298 return FALSE;
5301 * Testing shows the following:
5302 * wParam = 0 adjust cx value
5303 * = 1 set cy value to max size.
5304 * lParam pointer to SIZE structure
5307 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5308 wParam, lParam, lpsize->cx, lpsize->cy);
5310 switch(wParam) {
5311 case 0:
5312 if (lpsize->cx == -1) {
5313 /* **** this is wrong, native measures each button and sets it */
5314 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5316 else if(HIWORD(lpsize->cx)) {
5317 RECT rc;
5318 HWND hwndParent = GetParent(hwnd);
5320 GetWindowRect(hwnd, &rc);
5321 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5322 TRACE("mapped to (%d,%d)-(%d,%d)\n",
5323 rc.left, rc.top, rc.right, rc.bottom);
5324 lpsize->cx = max(rc.right-rc.left,
5325 infoPtr->rcBound.right - infoPtr->rcBound.left);
5327 else {
5328 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5330 break;
5331 case 1:
5332 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5333 break;
5334 default:
5335 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5336 wParam);
5337 return 0;
5339 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5340 lpsize->cx, lpsize->cy);
5341 return 1;
5344 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5346 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5348 InvalidateRect(hwnd, NULL, TRUE);
5349 return 1;
5353 static LRESULT
5354 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5356 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5357 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5358 LOGFONTW logFont;
5360 TRACE("hwnd = %p\n", hwnd);
5362 /* initialize info structure */
5363 infoPtr->nButtonWidth = 23;
5364 infoPtr->nButtonHeight = 22;
5365 infoPtr->nBitmapHeight = 15;
5366 infoPtr->nBitmapWidth = 16;
5367 /* By default Windows creates an image list with 16x15 icons but computes the button size as
5368 * if the icons were 16x16. That's why we keep infoPtr->nVBitmapHeight. After a call to
5369 * TB_SETBITMAPSIZE or TB_SETIMAGELIST the nVBitmapHeight = nBitmapHeight.
5371 infoPtr->nVBitmapHeight = 16;
5373 infoPtr->nMaxTextRows = 1;
5374 infoPtr->cxMin = -1;
5375 infoPtr->cxMax = -1;
5376 infoPtr->nNumBitmaps = 0;
5377 infoPtr->nNumStrings = 0;
5379 infoPtr->bCaptured = FALSE;
5380 infoPtr->nButtonDown = -1;
5381 infoPtr->nButtonDrag = -1;
5382 infoPtr->nOldHit = -1;
5383 infoPtr->nHotItem = -1;
5384 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5385 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5386 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5387 infoPtr->bDragOutSent = FALSE;
5388 infoPtr->iVersion = 0;
5389 infoPtr->hwndSelf = hwnd;
5390 infoPtr->bDoRedraw = TRUE;
5391 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5392 infoPtr->clrBtnShadow = CLR_DEFAULT;
5393 infoPtr->szPadding.cx = DEFPAD_CX;
5394 infoPtr->szPadding.cy = DEFPAD_CY;
5395 infoPtr->iListGap = DEFLISTGAP;
5396 infoPtr->dwStyle = dwStyle;
5397 infoPtr->tbim.iButton = -1;
5398 GetClientRect(hwnd, &infoPtr->client_rect);
5399 infoPtr->bUnicode = infoPtr->hwndNotify &&
5400 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5401 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5403 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5404 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5406 OpenThemeData (hwnd, themeClass);
5408 TOOLBAR_CheckStyle (hwnd, dwStyle);
5410 return 0;
5414 static LRESULT
5415 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5417 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5419 /* delete tooltip control */
5420 if (infoPtr->hwndToolTip)
5421 DestroyWindow (infoPtr->hwndToolTip);
5423 /* delete temporary buffer for tooltip text */
5424 Free (infoPtr->pszTooltipText);
5425 Free (infoPtr->bitmaps); /* bitmaps list */
5427 /* delete button data */
5428 if (infoPtr->buttons)
5429 Free (infoPtr->buttons);
5431 /* delete strings */
5432 if (infoPtr->strings) {
5433 INT i;
5434 for (i = 0; i < infoPtr->nNumStrings; i++)
5435 if (infoPtr->strings[i])
5436 Free (infoPtr->strings[i]);
5438 Free (infoPtr->strings);
5441 /* destroy internal image list */
5442 if (infoPtr->himlInt)
5443 ImageList_Destroy (infoPtr->himlInt);
5445 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5446 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5447 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5449 /* delete default font */
5450 DeleteObject (infoPtr->hDefaultFont);
5452 CloseThemeData (GetWindowTheme (hwnd));
5454 /* free toolbar info data */
5455 Free (infoPtr);
5456 SetWindowLongPtrW (hwnd, 0, 0);
5458 return 0;
5462 static LRESULT
5463 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5465 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5466 NMTBCUSTOMDRAW tbcd;
5467 INT ret = FALSE;
5468 DWORD ntfret;
5469 HTHEME theme = GetWindowTheme (hwnd);
5470 DWORD dwEraseCustDraw = 0;
5472 /* the app has told us not to redraw the toolbar */
5473 if (!infoPtr->bDoRedraw)
5474 return FALSE;
5476 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5477 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5478 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5479 tbcd.nmcd.hdc = (HDC)wParam;
5480 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5481 dwEraseCustDraw = ntfret & 0xffff;
5483 /* FIXME: in general the return flags *can* be or'ed together */
5484 switch (dwEraseCustDraw)
5486 case CDRF_DODEFAULT:
5487 break;
5488 case CDRF_SKIPDEFAULT:
5489 return TRUE;
5490 default:
5491 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5492 hwnd, ntfret);
5496 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5497 * to my parent for processing.
5499 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5500 POINT pt, ptorig;
5501 HDC hdc = (HDC)wParam;
5502 HWND parent;
5504 pt.x = 0;
5505 pt.y = 0;
5506 parent = GetParent(hwnd);
5507 MapWindowPoints(hwnd, parent, &pt, 1);
5508 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5509 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5510 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5512 if (!ret)
5513 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5515 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5516 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5517 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5518 tbcd.nmcd.hdc = (HDC)wParam;
5519 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5520 dwEraseCustDraw = ntfret & 0xffff;
5521 switch (dwEraseCustDraw)
5523 case CDRF_DODEFAULT:
5524 break;
5525 case CDRF_SKIPDEFAULT:
5526 return TRUE;
5527 default:
5528 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5529 hwnd, ntfret);
5532 return ret;
5536 static LRESULT
5537 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5539 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5541 return (LRESULT)infoPtr->hFont;
5545 static void
5546 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5548 INT i;
5549 INT nNewHotItem = infoPtr->nHotItem;
5551 for (i = 0; i < infoPtr->nNumButtons; i++)
5553 /* did we wrap? */
5554 if ((nNewHotItem + iDirection < 0) ||
5555 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5557 NMTBWRAPHOTITEM nmtbwhi;
5558 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5559 nmtbwhi.iDirection = iDirection;
5560 nmtbwhi.dwReason = dwReason;
5562 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5563 return;
5566 nNewHotItem += iDirection;
5567 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5569 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5570 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5572 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5573 break;
5578 static LRESULT
5579 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5581 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5582 NMKEY nmkey;
5584 nmkey.nVKey = (UINT)wParam;
5585 nmkey.uFlags = HIWORD(lParam);
5587 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5588 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5590 switch ((UINT)wParam)
5592 case VK_LEFT:
5593 case VK_UP:
5594 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5595 break;
5596 case VK_RIGHT:
5597 case VK_DOWN:
5598 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5599 break;
5600 case VK_SPACE:
5601 case VK_RETURN:
5602 if ((infoPtr->nHotItem >= 0) &&
5603 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5605 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5606 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5607 (LPARAM)hwnd);
5609 break;
5612 return 0;
5616 static LRESULT
5617 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5619 POINT pt;
5620 INT nHit;
5622 pt.x = (short)LOWORD(lParam);
5623 pt.y = (short)HIWORD(lParam);
5624 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5626 if (nHit >= 0)
5627 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5628 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5629 TOOLBAR_Customize (hwnd);
5631 return 0;
5635 static LRESULT
5636 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5638 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5639 TBUTTON_INFO *btnPtr;
5640 POINT pt;
5641 INT nHit;
5642 NMTOOLBARA nmtb;
5643 NMMOUSE nmmouse;
5644 BOOL bDragKeyPressed;
5646 TRACE("\n");
5648 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5649 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5650 else
5651 bDragKeyPressed = (wParam & MK_SHIFT);
5653 if (infoPtr->hwndToolTip)
5654 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5655 WM_LBUTTONDOWN, wParam, lParam);
5657 pt.x = (short)LOWORD(lParam);
5658 pt.y = (short)HIWORD(lParam);
5659 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5661 btnPtr = &infoPtr->buttons[nHit];
5663 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5665 infoPtr->nButtonDrag = nHit;
5666 SetCapture (hwnd);
5668 /* If drag cursor has not been loaded, load it.
5669 * Note: it doesn't need to be freed */
5670 if (!hCursorDrag)
5671 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5672 SetCursor(hCursorDrag);
5674 else if (nHit >= 0)
5676 RECT arrowRect;
5677 infoPtr->nOldHit = nHit;
5679 CopyRect(&arrowRect, &btnPtr->rect);
5680 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5682 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5683 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5684 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5685 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5686 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5687 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5689 LRESULT res;
5691 /* draw in pressed state */
5692 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5693 btnPtr->fsState |= TBSTATE_PRESSED;
5694 else
5695 btnPtr->bDropDownPressed = TRUE;
5696 RedrawWindow(hwnd,&btnPtr->rect,0,
5697 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5699 memset(&nmtb, 0, sizeof(nmtb));
5700 nmtb.iItem = btnPtr->idCommand;
5701 nmtb.rcButton = btnPtr->rect;
5702 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5703 TBN_DROPDOWN);
5704 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5706 if (res != TBDDRET_TREATPRESSED)
5708 MSG msg;
5710 /* redraw button in unpressed state */
5711 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5712 btnPtr->fsState &= ~TBSTATE_PRESSED;
5713 else
5714 btnPtr->bDropDownPressed = FALSE;
5715 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5717 /* find and set hot item
5718 * NOTE: native doesn't do this, but that is a bug */
5719 GetCursorPos(&pt);
5720 ScreenToClient(hwnd, &pt);
5721 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5722 if (!infoPtr->bAnchor || (nHit >= 0))
5723 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5725 /* remove any left mouse button down or double-click messages
5726 * so that we can get a toggle effect on the button */
5727 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5728 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5731 return 0;
5733 /* otherwise drop through and process as pushed */
5735 infoPtr->bCaptured = TRUE;
5736 infoPtr->nButtonDown = nHit;
5737 infoPtr->bDragOutSent = FALSE;
5739 btnPtr->fsState |= TBSTATE_PRESSED;
5741 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5743 if (btnPtr->fsState & TBSTATE_ENABLED)
5744 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5745 UpdateWindow(hwnd);
5746 SetCapture (hwnd);
5749 if (nHit >=0)
5751 memset(&nmtb, 0, sizeof(nmtb));
5752 nmtb.iItem = btnPtr->idCommand;
5753 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5756 nmmouse.dwHitInfo = nHit;
5758 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5759 if (nHit < 0)
5760 nmmouse.dwItemSpec = -1;
5761 else
5763 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5764 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5767 ClientToScreen(hwnd, &pt);
5768 nmmouse.pt = pt;
5770 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5771 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5773 return 0;
5776 static LRESULT
5777 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5779 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5780 TBUTTON_INFO *btnPtr;
5781 POINT pt;
5782 INT nHit;
5783 INT nOldIndex = -1;
5784 BOOL bSendMessage = TRUE;
5785 NMHDR hdr;
5786 NMMOUSE nmmouse;
5787 NMTOOLBARA nmtb;
5789 if (infoPtr->hwndToolTip)
5790 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5791 WM_LBUTTONUP, wParam, lParam);
5793 pt.x = (short)LOWORD(lParam);
5794 pt.y = (short)HIWORD(lParam);
5795 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5797 if (!infoPtr->bAnchor || (nHit >= 0))
5798 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5800 if (infoPtr->nButtonDrag >= 0) {
5801 RECT rcClient;
5802 NMHDR hdr;
5804 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5805 ReleaseCapture();
5806 /* reset cursor */
5807 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5809 GetClientRect(hwnd, &rcClient);
5810 if (PtInRect(&rcClient, pt))
5812 INT nButton = -1;
5813 if (nHit >= 0)
5814 nButton = nHit;
5815 else if (nHit < -1)
5816 nButton = -nHit;
5817 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5818 nButton = -nHit;
5820 if (nButton == infoPtr->nButtonDrag)
5822 /* if the button is moved sightly left and we have a
5823 * separator there then remove it */
5824 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5826 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5827 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5829 else /* else insert a separator before the dragged button */
5831 TBBUTTON tbb;
5832 memset(&tbb, 0, sizeof(tbb));
5833 tbb.fsStyle = BTNS_SEP;
5834 tbb.iString = -1;
5835 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5838 else
5840 if (nButton == -1)
5842 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5843 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5844 else
5845 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5847 else
5848 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5851 else
5853 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5854 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5857 /* button under cursor changed so need to re-set hot item */
5858 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5859 infoPtr->nButtonDrag = -1;
5861 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5863 else if (infoPtr->nButtonDown >= 0) {
5864 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5865 btnPtr->fsState &= ~TBSTATE_PRESSED;
5867 if (btnPtr->fsStyle & BTNS_CHECK) {
5868 if (btnPtr->fsStyle & BTNS_GROUP) {
5869 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5870 nHit);
5871 if (nOldIndex == nHit)
5872 bSendMessage = FALSE;
5873 if ((nOldIndex != nHit) &&
5874 (nOldIndex != -1))
5875 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5876 btnPtr->fsState |= TBSTATE_CHECKED;
5878 else {
5879 if (btnPtr->fsState & TBSTATE_CHECKED)
5880 btnPtr->fsState &= ~TBSTATE_CHECKED;
5881 else
5882 btnPtr->fsState |= TBSTATE_CHECKED;
5886 if (nOldIndex != -1)
5887 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5890 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5891 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5892 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5894 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5895 ReleaseCapture ();
5896 infoPtr->nButtonDown = -1;
5898 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5899 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5900 NM_RELEASEDCAPTURE);
5902 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5903 * TBN_BEGINDRAG
5905 memset(&nmtb, 0, sizeof(nmtb));
5906 nmtb.iItem = btnPtr->idCommand;
5907 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5908 TBN_ENDDRAG);
5910 if (btnPtr->fsState & TBSTATE_ENABLED)
5912 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5913 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5917 /* !!! Undocumented - toolbar at 4.71 level and above sends
5918 * NM_CLICK with the NMMOUSE structure. */
5919 nmmouse.dwHitInfo = nHit;
5921 if (nHit < 0)
5922 nmmouse.dwItemSpec = -1;
5923 else
5925 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5926 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5929 ClientToScreen(hwnd, &pt);
5930 nmmouse.pt = pt;
5932 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5933 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5935 return 0;
5938 static LRESULT
5939 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5941 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5942 INT nHit;
5943 NMMOUSE nmmouse;
5944 POINT pt;
5946 pt.x = (short)LOWORD(lParam);
5947 pt.y = (short)HIWORD(lParam);
5949 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5950 nmmouse.dwHitInfo = nHit;
5952 if (nHit < 0) {
5953 nmmouse.dwItemSpec = -1;
5954 } else {
5955 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5956 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5959 ClientToScreen(hwnd, &pt);
5960 nmmouse.pt = pt;
5962 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5963 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5965 return 0;
5968 static LRESULT
5969 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5971 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5972 NMHDR nmhdr;
5974 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5975 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5977 return 0;
5980 static LRESULT
5981 TOOLBAR_CaptureChanged(HWND hwnd)
5983 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5984 TBUTTON_INFO *btnPtr;
5986 infoPtr->bCaptured = FALSE;
5988 if (infoPtr->nButtonDown >= 0)
5990 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5991 btnPtr->fsState &= ~TBSTATE_PRESSED;
5993 infoPtr->nOldHit = -1;
5995 if (btnPtr->fsState & TBSTATE_ENABLED)
5996 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5998 return 0;
6001 static LRESULT
6002 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6004 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6006 /* don't remove hot effects when in anchor highlighting mode or when a
6007 * drop-down button is pressed */
6008 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
6010 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
6011 if (!hotBtnPtr->bDropDownPressed)
6012 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6015 if (infoPtr->nOldHit < 0)
6016 return TRUE;
6018 /* If the last button we were over is depressed then make it not */
6019 /* depressed and redraw it */
6020 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6022 TBUTTON_INFO *btnPtr;
6023 RECT rc1;
6025 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6027 btnPtr->fsState &= ~TBSTATE_PRESSED;
6029 rc1 = btnPtr->rect;
6030 InflateRect (&rc1, 1, 1);
6031 InvalidateRect (hwnd, &rc1, TRUE);
6034 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6036 NMTOOLBARW nmt;
6037 ZeroMemory(&nmt, sizeof(nmt));
6038 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6039 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6040 infoPtr->bDragOutSent = TRUE;
6043 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6045 return TRUE;
6048 static LRESULT
6049 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6051 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6052 POINT pt;
6053 TRACKMOUSEEVENT trackinfo;
6054 INT nHit;
6055 TBUTTON_INFO *btnPtr;
6057 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6058 TOOLBAR_TooltipCreateControl(infoPtr);
6060 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6061 /* fill in the TRACKMOUSEEVENT struct */
6062 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6063 trackinfo.dwFlags = TME_QUERY;
6065 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6066 _TrackMouseEvent(&trackinfo);
6068 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6069 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6070 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6071 trackinfo.hwndTrack = hwnd;
6073 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6074 /* and can properly deactivate the hot toolbar button */
6075 _TrackMouseEvent(&trackinfo);
6079 if (infoPtr->hwndToolTip)
6080 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6081 WM_MOUSEMOVE, wParam, lParam);
6083 pt.x = (short)LOWORD(lParam);
6084 pt.y = (short)HIWORD(lParam);
6086 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6088 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6089 && (!infoPtr->bAnchor || (nHit >= 0)))
6090 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6092 if (infoPtr->nOldHit != nHit)
6094 if (infoPtr->bCaptured)
6096 if (!infoPtr->bDragOutSent)
6098 NMTOOLBARW nmt;
6099 ZeroMemory(&nmt, sizeof(nmt));
6100 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6101 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6102 infoPtr->bDragOutSent = TRUE;
6105 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6106 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6107 btnPtr->fsState &= ~TBSTATE_PRESSED;
6108 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6110 else if (nHit == infoPtr->nButtonDown) {
6111 btnPtr->fsState |= TBSTATE_PRESSED;
6112 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6114 infoPtr->nOldHit = nHit;
6118 return 0;
6122 inline static LRESULT
6123 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6125 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6126 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6127 /* else */
6128 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6132 inline static LRESULT
6133 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6135 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6136 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6138 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6142 static LRESULT
6143 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6145 TOOLBAR_INFO *infoPtr;
6146 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6147 DWORD styleadd = 0;
6149 /* allocate memory for info structure */
6150 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6151 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6153 /* paranoid!! */
6154 infoPtr->dwStructSize = sizeof(TBBUTTON);
6155 infoPtr->nRows = 1;
6156 infoPtr->nWidth = 0;
6158 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6159 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6160 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6161 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6164 /* native control does:
6165 * Get a lot of colors and brushes
6166 * WM_NOTIFYFORMAT
6167 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6168 * CreateFontIndirectW(adr1)
6169 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6170 * hdc = GetDC(toolbar)
6171 * GetSystemMetrics(0x48)
6172 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6173 * 0, 0, 0, 0, "MARLETT")
6174 * oldfnt = SelectObject(hdc, fnt2)
6175 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6176 * GetTextMetricsW(hdc, adr3)
6177 * SelectObject(hdc, oldfnt)
6178 * DeleteObject(fnt2)
6179 * ReleaseDC(hdc)
6180 * InvalidateRect(toolbar, 0, 1)
6181 * SetWindowLongW(toolbar, 0, addr)
6182 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6183 * WM_STYLECHANGING
6184 * CallWinEx old new
6185 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6186 * ie 2 0x4600094c 0x4600094c 0x4600894d
6187 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6188 * rebar 0x50008844 0x40008844 0x50008845
6189 * pager 0x50000844 0x40000844 0x50008845
6190 * IC35mgr 0x5400084e **nochange**
6191 * on entry to _NCCREATE 0x5400084e
6192 * rowlist 0x5400004e **nochange**
6193 * on entry to _NCCREATE 0x5400004e
6197 /* I think the code below is a bug, but it is the way that the native
6198 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6199 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6200 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6201 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6202 * Somehow, the only cases of this seem to be MFC programs.
6204 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6205 * does not occur in the WM_STYLECHANGING routine.
6206 * (Guy Albertelli 9/2001)
6209 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6210 && !(cs->style & TBSTYLE_TRANSPARENT))
6211 styleadd |= TBSTYLE_TRANSPARENT;
6212 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6213 styleadd |= CCS_TOP; /* default to top */
6214 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6217 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6221 static LRESULT
6222 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6224 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6225 RECT rcWindow;
6226 HDC hdc;
6228 if (dwStyle & WS_MINIMIZE)
6229 return 0; /* Nothing to do */
6231 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6233 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6234 return 0;
6236 if (!(dwStyle & CCS_NODIVIDER))
6238 GetWindowRect (hwnd, &rcWindow);
6239 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6240 if( dwStyle & WS_BORDER )
6241 OffsetRect (&rcWindow, 1, 1);
6242 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6245 ReleaseDC( hwnd, hdc );
6247 return 0;
6251 /* handles requests from the tooltip control on what text to display */
6252 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6254 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6256 TRACE("button index = %d\n", index);
6258 Free (infoPtr->pszTooltipText);
6259 infoPtr->pszTooltipText = NULL;
6261 if (index < 0)
6262 return 0;
6264 if (infoPtr->bUnicode)
6266 WCHAR wszBuffer[INFOTIPSIZE+1];
6267 NMTBGETINFOTIPW tbgit;
6268 unsigned int len; /* in chars */
6270 wszBuffer[0] = '\0';
6271 wszBuffer[INFOTIPSIZE] = '\0';
6273 tbgit.pszText = wszBuffer;
6274 tbgit.cchTextMax = INFOTIPSIZE;
6275 tbgit.iItem = lpnmtdi->hdr.idFrom;
6276 tbgit.lParam = infoPtr->buttons[index].dwData;
6278 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6280 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6282 len = strlenW(tbgit.pszText);
6283 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6285 /* need to allocate temporary buffer in infoPtr as there
6286 * isn't enough space in buffer passed to us by the
6287 * tooltip control */
6288 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6289 if (infoPtr->pszTooltipText)
6291 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6292 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6293 return 0;
6296 else if (len > 0)
6298 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6299 return 0;
6302 else
6304 CHAR szBuffer[INFOTIPSIZE+1];
6305 NMTBGETINFOTIPA tbgit;
6306 unsigned int len; /* in chars */
6308 szBuffer[0] = '\0';
6309 szBuffer[INFOTIPSIZE] = '\0';
6311 tbgit.pszText = szBuffer;
6312 tbgit.cchTextMax = INFOTIPSIZE;
6313 tbgit.iItem = lpnmtdi->hdr.idFrom;
6314 tbgit.lParam = infoPtr->buttons[index].dwData;
6316 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6318 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6320 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6321 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6323 /* need to allocate temporary buffer in infoPtr as there
6324 * isn't enough space in buffer passed to us by the
6325 * tooltip control */
6326 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6327 if (infoPtr->pszTooltipText)
6329 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6330 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6331 return 0;
6334 else if (len > 0)
6336 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6337 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6338 return 0;
6342 /* if button has text, but it is not shown then automatically
6343 * use that text as tooltip */
6344 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6345 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6347 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6348 unsigned int len = pszText ? strlenW(pszText) : 0;
6350 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6352 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6354 /* need to allocate temporary buffer in infoPtr as there
6355 * isn't enough space in buffer passed to us by the
6356 * tooltip control */
6357 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6358 if (infoPtr->pszTooltipText)
6360 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6361 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6362 return 0;
6365 else if (len > 0)
6367 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6368 return 0;
6372 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6374 /* last resort: send notification on to app */
6375 /* FIXME: find out what is really used here */
6376 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6380 inline static LRESULT
6381 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6383 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6384 LPNMHDR lpnmh = (LPNMHDR)lParam;
6386 switch (lpnmh->code)
6388 case PGN_CALCSIZE:
6390 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6392 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6393 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6394 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6395 lppgc->iWidth);
6397 else {
6398 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6399 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6400 lppgc->iHeight);
6402 return 0;
6405 case PGN_SCROLL:
6407 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6409 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6410 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6411 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6412 lppgs->iScroll, lppgs->iDir);
6413 return 0;
6416 case TTN_GETDISPINFOW:
6417 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6419 case TTN_GETDISPINFOA:
6420 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6421 return 0;
6423 default:
6424 return 0;
6429 static LRESULT
6430 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6432 LRESULT format;
6434 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6436 if (lParam == NF_QUERY)
6437 return NFR_UNICODE;
6439 if (lParam == NF_REQUERY) {
6440 format = SendMessageW(infoPtr->hwndNotify,
6441 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6442 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6443 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6444 format);
6445 format = NFR_ANSI;
6447 return format;
6449 return 0;
6453 static LRESULT
6454 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6456 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6457 HDC hdc;
6458 PAINTSTRUCT ps;
6460 /* fill ps.rcPaint with a default rect */
6461 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6463 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6465 TRACE("psrect=(%d,%d)-(%d,%d)\n",
6466 ps.rcPaint.left, ps.rcPaint.top,
6467 ps.rcPaint.right, ps.rcPaint.bottom);
6469 TOOLBAR_Refresh (hwnd, hdc, &ps);
6470 if (!wParam) EndPaint (hwnd, &ps);
6472 return 0;
6476 static LRESULT
6477 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6479 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6481 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6483 /* make first item hot */
6484 if (infoPtr->nNumButtons > 0)
6485 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6487 return 0;
6490 static LRESULT
6491 TOOLBAR_SetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
6493 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6495 TRACE("font=%p redraw=%ld\n", (HFONT)wParam, lParam);
6497 if (wParam == 0)
6498 infoPtr->hFont = infoPtr->hDefaultFont;
6499 else
6500 infoPtr->hFont = (HFONT)wParam;
6502 TOOLBAR_CalcToolbar(hwnd);
6504 if (lParam)
6505 InvalidateRect(hwnd, NULL, TRUE);
6506 return 1;
6509 static LRESULT
6510 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6511 /*****************************************************
6513 * Function;
6514 * Handles the WM_SETREDRAW message.
6516 * Documentation:
6517 * According to testing V4.71 of COMCTL32 returns the
6518 * *previous* status of the redraw flag (either 0 or 1)
6519 * instead of the MSDN documented value of 0 if handled.
6520 * (For laughs see the "consistency" with same function
6521 * in rebar.)
6523 *****************************************************/
6525 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6526 BOOL oldredraw = infoPtr->bDoRedraw;
6528 TRACE("set to %s\n",
6529 (wParam) ? "TRUE" : "FALSE");
6530 infoPtr->bDoRedraw = (BOOL) wParam;
6531 if (wParam) {
6532 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6534 return (oldredraw) ? 1 : 0;
6538 static LRESULT
6539 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6541 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6543 TRACE("sizing toolbar!\n");
6545 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6547 RECT delta_width, delta_height, client, dummy;
6548 DWORD min_x, max_x, min_y, max_y;
6549 TBUTTON_INFO *btnPtr;
6550 INT i;
6552 GetClientRect(hwnd, &client);
6553 if(client.right > infoPtr->client_rect.right)
6555 min_x = infoPtr->client_rect.right;
6556 max_x = client.right;
6558 else
6560 max_x = infoPtr->client_rect.right;
6561 min_x = client.right;
6563 if(client.bottom > infoPtr->client_rect.bottom)
6565 min_y = infoPtr->client_rect.bottom;
6566 max_y = client.bottom;
6568 else
6570 max_y = infoPtr->client_rect.bottom;
6571 min_y = client.bottom;
6574 SetRect(&delta_width, min_x, 0, max_x, min_y);
6575 SetRect(&delta_height, 0, min_y, max_x, max_y);
6577 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6578 btnPtr = infoPtr->buttons;
6579 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6580 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6581 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6582 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6584 GetClientRect(hwnd, &infoPtr->client_rect);
6585 TOOLBAR_AutoSize(hwnd);
6586 return 0;
6590 static LRESULT
6591 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6593 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6595 if (nType == GWL_STYLE)
6597 DWORD dwOldStyle = infoPtr->dwStyle;
6599 if (lpStyle->styleNew & TBSTYLE_LIST)
6600 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6601 else
6602 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6604 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6606 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6608 infoPtr->dwStyle = lpStyle->styleNew;
6610 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6611 TOOLBAR_LayoutToolbar(hwnd);
6613 /* only resize if one of the CCS_* styles was changed */
6614 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6616 TOOLBAR_AutoSize (hwnd);
6618 InvalidateRect(hwnd, NULL, TRUE);
6622 return 0;
6626 static LRESULT
6627 TOOLBAR_SysColorChange (HWND hwnd)
6629 COMCTL32_RefreshSysColors();
6631 return 0;
6635 /* update theme after a WM_THEMECHANGED message */
6636 static LRESULT theme_changed (HWND hwnd)
6638 HTHEME theme = GetWindowTheme (hwnd);
6639 CloseThemeData (theme);
6640 OpenThemeData (hwnd, themeClass);
6641 return 0;
6645 static LRESULT WINAPI
6646 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6648 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6650 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6651 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6653 if (!infoPtr && (uMsg != WM_NCCREATE))
6654 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6656 switch (uMsg)
6658 case TB_ADDBITMAP:
6659 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6661 case TB_ADDBUTTONSA:
6662 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6664 case TB_ADDBUTTONSW:
6665 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6667 case TB_ADDSTRINGA:
6668 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6670 case TB_ADDSTRINGW:
6671 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6673 case TB_AUTOSIZE:
6674 return TOOLBAR_AutoSize (hwnd);
6676 case TB_BUTTONCOUNT:
6677 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6679 case TB_BUTTONSTRUCTSIZE:
6680 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6682 case TB_CHANGEBITMAP:
6683 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6685 case TB_CHECKBUTTON:
6686 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6688 case TB_COMMANDTOINDEX:
6689 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6691 case TB_CUSTOMIZE:
6692 return TOOLBAR_Customize (hwnd);
6694 case TB_DELETEBUTTON:
6695 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6697 case TB_ENABLEBUTTON:
6698 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6700 case TB_GETANCHORHIGHLIGHT:
6701 return TOOLBAR_GetAnchorHighlight (hwnd);
6703 case TB_GETBITMAP:
6704 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6706 case TB_GETBITMAPFLAGS:
6707 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6709 case TB_GETBUTTON:
6710 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6712 case TB_GETBUTTONINFOA:
6713 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6715 case TB_GETBUTTONINFOW:
6716 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6718 case TB_GETBUTTONSIZE:
6719 return TOOLBAR_GetButtonSize (hwnd);
6721 case TB_GETBUTTONTEXTA:
6722 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6724 case TB_GETBUTTONTEXTW:
6725 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6727 case TB_GETDISABLEDIMAGELIST:
6728 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6730 case TB_GETEXTENDEDSTYLE:
6731 return TOOLBAR_GetExtendedStyle (hwnd);
6733 case TB_GETHOTIMAGELIST:
6734 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6736 case TB_GETHOTITEM:
6737 return TOOLBAR_GetHotItem (hwnd);
6739 case TB_GETIMAGELIST:
6740 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6742 case TB_GETINSERTMARK:
6743 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6745 case TB_GETINSERTMARKCOLOR:
6746 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6748 case TB_GETITEMRECT:
6749 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6751 case TB_GETMAXSIZE:
6752 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6754 /* case TB_GETOBJECT: */ /* 4.71 */
6756 case TB_GETPADDING:
6757 return TOOLBAR_GetPadding (hwnd);
6759 case TB_GETRECT:
6760 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6762 case TB_GETROWS:
6763 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6765 case TB_GETSTATE:
6766 return TOOLBAR_GetState (hwnd, wParam, lParam);
6768 case TB_GETSTRINGA:
6769 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6771 case TB_GETSTRINGW:
6772 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6774 case TB_GETSTYLE:
6775 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6777 case TB_GETTEXTROWS:
6778 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6780 case TB_GETTOOLTIPS:
6781 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6783 case TB_GETUNICODEFORMAT:
6784 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6786 case TB_HIDEBUTTON:
6787 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6789 case TB_HITTEST:
6790 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6792 case TB_INDETERMINATE:
6793 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6795 case TB_INSERTBUTTONA:
6796 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6798 case TB_INSERTBUTTONW:
6799 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6801 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6803 case TB_ISBUTTONCHECKED:
6804 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6806 case TB_ISBUTTONENABLED:
6807 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6809 case TB_ISBUTTONHIDDEN:
6810 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6812 case TB_ISBUTTONHIGHLIGHTED:
6813 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6815 case TB_ISBUTTONINDETERMINATE:
6816 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6818 case TB_ISBUTTONPRESSED:
6819 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6821 case TB_LOADIMAGES:
6822 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6824 case TB_MAPACCELERATORA:
6825 case TB_MAPACCELERATORW:
6826 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6828 case TB_MARKBUTTON:
6829 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6831 case TB_MOVEBUTTON:
6832 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6834 case TB_PRESSBUTTON:
6835 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6837 case TB_REPLACEBITMAP:
6838 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6840 case TB_SAVERESTOREA:
6841 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6843 case TB_SAVERESTOREW:
6844 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6846 case TB_SETANCHORHIGHLIGHT:
6847 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6849 case TB_SETBITMAPSIZE:
6850 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6852 case TB_SETBUTTONINFOA:
6853 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6855 case TB_SETBUTTONINFOW:
6856 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6858 case TB_SETBUTTONSIZE:
6859 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6861 case TB_SETBUTTONWIDTH:
6862 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6864 case TB_SETCMDID:
6865 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6867 case TB_SETDISABLEDIMAGELIST:
6868 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6870 case TB_SETDRAWTEXTFLAGS:
6871 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6873 case TB_SETEXTENDEDSTYLE:
6874 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6876 case TB_SETHOTIMAGELIST:
6877 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6879 case TB_SETHOTITEM:
6880 return TOOLBAR_SetHotItem (hwnd, wParam);
6882 case TB_SETIMAGELIST:
6883 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6885 case TB_SETINDENT:
6886 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6888 case TB_SETINSERTMARK:
6889 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6891 case TB_SETINSERTMARKCOLOR:
6892 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6894 case TB_SETMAXTEXTROWS:
6895 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6897 case TB_SETPADDING:
6898 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6900 case TB_SETPARENT:
6901 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6903 case TB_SETROWS:
6904 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6906 case TB_SETSTATE:
6907 return TOOLBAR_SetState (hwnd, wParam, lParam);
6909 case TB_SETSTYLE:
6910 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6912 case TB_SETTOOLTIPS:
6913 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6915 case TB_SETUNICODEFORMAT:
6916 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6918 case TB_UNKWN45D:
6919 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6921 case TB_UNKWN45E:
6922 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6924 case TB_UNKWN460:
6925 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6927 case TB_UNKWN462:
6928 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6930 case TB_UNKWN463:
6931 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6933 case TB_UNKWN464:
6934 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6936 /* Common Control Messages */
6938 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6939 case CCM_GETCOLORSCHEME:
6940 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6942 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6943 case CCM_SETCOLORSCHEME:
6944 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6946 case CCM_GETVERSION:
6947 return TOOLBAR_GetVersion (hwnd);
6949 case CCM_SETVERSION:
6950 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6953 /* case WM_CHAR: */
6955 case WM_CREATE:
6956 return TOOLBAR_Create (hwnd, wParam, lParam);
6958 case WM_DESTROY:
6959 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6961 case WM_ERASEBKGND:
6962 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6964 case WM_GETFONT:
6965 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6967 case WM_KEYDOWN:
6968 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6970 /* case WM_KILLFOCUS: */
6972 case WM_LBUTTONDBLCLK:
6973 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6975 case WM_LBUTTONDOWN:
6976 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6978 case WM_LBUTTONUP:
6979 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6981 case WM_RBUTTONUP:
6982 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6984 case WM_RBUTTONDBLCLK:
6985 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6987 case WM_MOUSEMOVE:
6988 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6990 case WM_MOUSELEAVE:
6991 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6993 case WM_CAPTURECHANGED:
6994 return TOOLBAR_CaptureChanged(hwnd);
6996 case WM_NCACTIVATE:
6997 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6999 case WM_NCCALCSIZE:
7000 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7002 case WM_NCCREATE:
7003 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7005 case WM_NCPAINT:
7006 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7008 case WM_NOTIFY:
7009 return TOOLBAR_Notify (hwnd, wParam, lParam);
7011 case WM_NOTIFYFORMAT:
7012 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7014 case WM_PRINTCLIENT:
7015 case WM_PAINT:
7016 return TOOLBAR_Paint (hwnd, wParam);
7018 case WM_SETFOCUS:
7019 return TOOLBAR_SetFocus (hwnd, wParam);
7021 case WM_SETFONT:
7022 return TOOLBAR_SetFont(hwnd, wParam, lParam);
7024 case WM_SETREDRAW:
7025 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7027 case WM_SIZE:
7028 return TOOLBAR_Size (hwnd, wParam, lParam);
7030 case WM_STYLECHANGED:
7031 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7033 case WM_SYSCOLORCHANGE:
7034 return TOOLBAR_SysColorChange (hwnd);
7036 case WM_THEMECHANGED:
7037 return theme_changed (hwnd);
7039 /* case WM_WININICHANGE: */
7041 case WM_CHARTOITEM:
7042 case WM_COMMAND:
7043 case WM_DRAWITEM:
7044 case WM_MEASUREITEM:
7045 case WM_VKEYTOITEM:
7046 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7048 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7049 case PGM_FORWARDMOUSE:
7050 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7052 default:
7053 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7054 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7055 uMsg, wParam, lParam);
7056 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7061 VOID
7062 TOOLBAR_Register (void)
7064 WNDCLASSW wndClass;
7066 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7067 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7068 wndClass.lpfnWndProc = ToolbarWindowProc;
7069 wndClass.cbClsExtra = 0;
7070 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7071 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7072 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7073 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7075 RegisterClassW (&wndClass);
7079 VOID
7080 TOOLBAR_Unregister (void)
7082 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7085 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7087 HIMAGELIST himlold;
7088 PIMLENTRY c = NULL;
7090 /* Check if the entry already exists */
7091 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7093 /* If this is a new entry we must create it and insert into the array */
7094 if (!c)
7096 PIMLENTRY *pnies;
7098 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7099 c->id = id;
7101 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7102 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7103 pnies[*cies] = c;
7104 (*cies)++;
7106 Free(*pies);
7107 *pies = pnies;
7110 himlold = c->himl;
7111 c->himl = himl;
7113 return himlold;
7117 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7119 int i;
7121 for (i = 0; i < *cies; i++)
7122 Free((*pies)[i]);
7124 Free(*pies);
7126 *cies = 0;
7127 *pies = NULL;
7131 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7133 PIMLENTRY c = NULL;
7135 if (pies != NULL)
7137 int i;
7139 for (i = 0; i < cies; i++)
7141 if (pies[i]->id == id)
7143 c = pies[i];
7144 break;
7149 return c;
7153 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7155 HIMAGELIST himlDef = 0;
7156 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7158 if (pie)
7159 himlDef = pie->himl;
7161 return himlDef;
7165 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7167 if (infoPtr->bUnicode)
7168 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7169 else
7171 CHAR Buffer[256];
7172 NMTOOLBARA nmtba;
7173 BOOL bRet = FALSE;
7175 nmtba.iItem = nmtb->iItem;
7176 nmtba.pszText = Buffer;
7177 nmtba.cchText = 256;
7178 ZeroMemory(nmtba.pszText, nmtba.cchText);
7180 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7182 int ccht = strlen(nmtba.pszText);
7183 if (ccht)
7184 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7185 nmtb->pszText, nmtb->cchText);
7187 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7188 bRet = TRUE;
7191 return bRet;
7196 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7197 int iItem, PCUSTOMBUTTON btnInfo)
7199 NMTOOLBARW nmtb;
7201 /* MSDN states that iItem is the index of the button, rather than the
7202 * command ID as used by every other NMTOOLBAR notification */
7203 nmtb.iItem = iItem;
7204 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7206 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);