wined3d: Get rid of the useless "fragcolor" variable in shader_glsl_generate_pshader().
[wine.git] / dlls / comctl32 / toolbar.c
blobc6cf83e2d87b8f0844c32f163b5c59167fee9f33
1 /*
2 * Toolbar control
4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * NOTES
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
31 * TODO:
32 * - Styles:
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
35 * - Messages:
36 * - TB_GETMETRICS
37 * - TB_GETOBJECT
38 * - TB_INSERTMARKHITTEST
39 * - TB_SAVERESTORE
40 * - TB_SETMETRICS
41 * - WM_WININICHANGE
42 * - Notifications:
43 * - NM_CHAR
44 * - TBN_GETOBJECT
45 * - TBN_SAVE
46 * - Button wrapping (under construction).
47 * - Fix TB_SETROWS and Separators.
48 * - iListGap custom draw support.
50 * Testing:
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
71 #include <stdarg.h>
72 #include <string.h>
74 #include "windef.h"
75 #include "winbase.h"
76 #include "winreg.h"
77 #include "wingdi.h"
78 #include "winuser.h"
79 #include "wine/unicode.h"
80 #include "winnls.h"
81 #include "commctrl.h"
82 #include "comctl32.h"
83 #include "uxtheme.h"
84 #include "tmschema.h"
85 #include "wine/debug.h"
87 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
89 static HCURSOR hCursorDrag = NULL;
91 typedef struct
93 INT iBitmap;
94 INT idCommand;
95 BYTE fsState;
96 BYTE fsStyle;
97 BYTE bHot;
98 BYTE bDropDownPressed;
99 DWORD_PTR dwData;
100 INT_PTR iString;
101 INT nRow;
102 RECT rect;
103 INT cx; /* manually set size */
104 } TBUTTON_INFO;
106 typedef struct
108 UINT nButtons;
109 HINSTANCE hInst;
110 UINT nID;
111 } TBITMAP_INFO;
113 typedef struct
115 HIMAGELIST himl;
116 INT id;
117 } IMLENTRY, *PIMLENTRY;
119 typedef struct
121 DWORD dwStructSize; /* size of TBBUTTON struct */
122 INT nWidth; /* width of the toolbar */
123 RECT client_rect;
124 RECT rcBound; /* bounding rectangle */
125 INT nButtonHeight;
126 INT nButtonWidth;
127 INT nBitmapHeight;
128 INT nBitmapWidth;
129 INT nIndent;
130 INT nRows; /* number of button rows */
131 INT nMaxTextRows; /* maximum number of text rows */
132 INT cxMin; /* minimum button width */
133 INT cxMax; /* maximum button width */
134 INT nNumButtons; /* number of buttons */
135 INT nNumBitmaps; /* number of bitmaps */
136 INT nNumStrings; /* number of strings */
137 INT nNumBitmapInfos;
138 INT nButtonDown; /* toolbar button being pressed or -1 if none */
139 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
140 INT nOldHit;
141 INT nHotItem; /* index of the "hot" item */
142 SIZE szPadding; /* padding values around button */
143 INT iTopMargin; /* the top margin */
144 INT iListGap; /* default gap between text and image for toolbar with list style */
145 HFONT hDefaultFont;
146 HFONT hFont; /* text font */
147 HIMAGELIST himlInt; /* image list created internally */
148 PIMLENTRY *himlDef; /* default image list array */
149 INT cimlDef; /* default image list array count */
150 PIMLENTRY *himlHot; /* hot image list array */
151 INT cimlHot; /* hot image list array count */
152 PIMLENTRY *himlDis; /* disabled image list array */
153 INT cimlDis; /* disabled image list array count */
154 HWND hwndToolTip; /* handle to tool tip control */
155 HWND hwndNotify; /* handle to the window that gets notifications */
156 HWND hwndSelf; /* my own handle */
157 BOOL bAnchor; /* anchor highlight enabled */
158 BOOL bDoRedraw; /* Redraw status */
159 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
160 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
161 BOOL bCaptured; /* mouse captured? */
162 DWORD dwStyle; /* regular toolbar style */
163 DWORD dwExStyle; /* extended toolbar style */
164 DWORD dwDTFlags; /* DrawText flags */
166 COLORREF clrInsertMark; /* insert mark color */
167 COLORREF clrBtnHighlight; /* color for Flat Separator */
168 COLORREF clrBtnShadow; /* color for Flag Separator */
169 INT iVersion;
170 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
171 * for TTN_GETDISPINFOW notification */
172 TBINSERTMARK tbim; /* info on insertion mark */
173 TBUTTON_INFO *buttons; /* pointer to button array */
174 LPWSTR *strings; /* pointer to string array */
175 TBITMAP_INFO *bitmaps;
176 } TOOLBAR_INFO, *PTOOLBAR_INFO;
179 /* used by customization dialog */
180 typedef struct
182 PTOOLBAR_INFO tbInfo;
183 HWND tbHwnd;
184 } CUSTDLG_INFO, *PCUSTDLG_INFO;
186 typedef struct
188 TBBUTTON btn;
189 BOOL bVirtual;
190 BOOL bRemovable;
191 WCHAR text[64];
192 } CUSTOMBUTTON, *PCUSTOMBUTTON;
194 typedef enum
196 IMAGE_LIST_DEFAULT,
197 IMAGE_LIST_HOT,
198 IMAGE_LIST_DISABLED
199 } IMAGE_LIST_TYPE;
201 #define SEPARATOR_WIDTH 8
202 #define TOP_BORDER 2
203 #define BOTTOM_BORDER 2
204 #define DDARROW_WIDTH 11
205 #define ARROW_HEIGHT 3
206 #define INSERTMARK_WIDTH 2
208 #define DEFPAD_CX 7
209 #define DEFPAD_CY 6
210 #define DEFLISTGAP 4
212 /* vertical padding used in list mode when image is present */
213 #define LISTPAD_CY 9
215 /* how wide to treat the bitmap if it isn't present */
216 #define NONLIST_NOTEXT_OFFSET 2
218 #define TOOLBAR_NOWHERE (-1)
220 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
221 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
223 /* Used to find undocumented extended styles */
224 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
225 TBSTYLE_EX_UNDOC1 | \
226 TBSTYLE_EX_MIXEDBUTTONS | \
227 TBSTYLE_EX_DOUBLEBUFFER | \
228 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
230 /* all of the CCS_ styles */
231 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
232 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
234 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
235 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
236 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
237 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
238 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
240 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
242 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
243 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, const CUSTOMBUTTON *btnInfo);
244 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id);
245 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id);
246 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
247 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
248 static LRESULT TOOLBAR_LButtonDown(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
249 static void TOOLBAR_LayoutToolbar(TOOLBAR_INFO *infoPtr);
250 static LRESULT TOOLBAR_AutoSize(TOOLBAR_INFO *infoPtr);
251 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
252 static void TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
253 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
256 static inline int default_top_margin(const TOOLBAR_INFO *infoPtr)
258 return (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
261 static LPWSTR
262 TOOLBAR_GetText(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr)
264 LPWSTR lpText = NULL;
266 /* NOTE: iString == -1 is undocumented */
267 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
268 lpText = (LPWSTR)btnPtr->iString;
269 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
270 lpText = infoPtr->strings[btnPtr->iString];
272 return lpText;
275 static void
276 TOOLBAR_DumpTBButton(const TBBUTTON *tbb, BOOL fUnicode)
278 TRACE("TBBUTTON: id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx (%s)\n",
279 tbb->idCommand,tbb->iBitmap, tbb->fsState, tbb->fsStyle, tbb->dwData, tbb->iString,
280 (fUnicode ? wine_dbgstr_w((LPWSTR)tbb->iString) : wine_dbgstr_a((LPSTR)tbb->iString)));
283 static void
284 TOOLBAR_DumpButton(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *bP, INT btn_num)
286 if (TRACE_ON(toolbar)){
287 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
288 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
289 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
290 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
291 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n",
292 btn_num, bP->idCommand, (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
293 wine_dbgstr_rect(&bP->rect));
298 static void
299 TOOLBAR_DumpToolbar(const TOOLBAR_INFO *iP, INT line)
301 if (TRACE_ON(toolbar)) {
302 INT i;
304 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
305 iP->hwndSelf, line,
306 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
307 iP->nNumStrings, iP->dwStyle);
308 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
309 iP->hwndSelf, line,
310 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
311 (iP->bDoRedraw) ? "TRUE" : "FALSE");
312 for(i=0; i<iP->nNumButtons; i++) {
313 TOOLBAR_DumpButton(iP, &iP->buttons[i], i);
319 /***********************************************************************
320 * TOOLBAR_CheckStyle
322 * This function validates that the styles set are implemented and
323 * issues FIXME's warning of possible problems. In a perfect world this
324 * function should be null.
326 static void
327 TOOLBAR_CheckStyle (const TOOLBAR_INFO *infoPtr, DWORD dwStyle)
329 if (dwStyle & TBSTYLE_REGISTERDROP)
330 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", infoPtr->hwndSelf);
334 static INT
335 TOOLBAR_SendNotify (NMHDR *nmhdr, const TOOLBAR_INFO *infoPtr, UINT code)
337 if(!IsWindow(infoPtr->hwndSelf))
338 return 0; /* we have just been destroyed */
340 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
341 nmhdr->hwndFrom = infoPtr->hwndSelf;
342 nmhdr->code = code;
344 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
345 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
347 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
350 /***********************************************************************
351 * TOOLBAR_GetBitmapIndex
353 * This function returns the bitmap index associated with a button.
354 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
355 * is issued to retrieve the index.
357 static INT
358 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
360 INT ret = btnPtr->iBitmap;
362 if (ret == I_IMAGECALLBACK)
364 /* issue TBN_GETDISPINFO */
365 NMTBDISPINFOW nmgd;
367 memset(&nmgd, 0, sizeof(nmgd));
368 nmgd.idCommand = btnPtr->idCommand;
369 nmgd.lParam = btnPtr->dwData;
370 nmgd.dwMask = TBNF_IMAGE;
371 nmgd.iImage = -1;
372 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
373 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr, TBN_GETDISPINFOW);
374 if (nmgd.dwMask & TBNF_DI_SETITEM)
375 btnPtr->iBitmap = nmgd.iImage;
376 ret = nmgd.iImage;
377 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
378 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
381 if (ret != I_IMAGENONE)
382 ret = GETIBITMAP(infoPtr, ret);
384 return ret;
388 static BOOL
389 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO *infoPtr, INT index)
391 HIMAGELIST himl;
392 INT id = GETHIMLID(infoPtr, index);
393 INT iBitmap = GETIBITMAP(infoPtr, index);
395 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
396 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
397 (index == I_IMAGECALLBACK))
398 return TRUE;
399 else
400 return FALSE;
404 static inline BOOL
405 TOOLBAR_IsValidImageList(const TOOLBAR_INFO *infoPtr, INT index)
407 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
408 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
412 /***********************************************************************
413 * TOOLBAR_GetImageListForDrawing
415 * This function validates the bitmap index (including I_IMAGECALLBACK
416 * functionality) and returns the corresponding image list.
418 static HIMAGELIST
419 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
420 IMAGE_LIST_TYPE imagelist, INT * index)
422 HIMAGELIST himl;
424 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
425 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
426 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
427 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
428 return NULL;
431 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
432 if ((*index == I_IMAGECALLBACK) ||
433 (*index == I_IMAGENONE)) return NULL;
434 ERR("TBN_GETDISPINFO returned invalid index %d\n",
435 *index);
436 return NULL;
439 switch(imagelist)
441 case IMAGE_LIST_DEFAULT:
442 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
443 break;
444 case IMAGE_LIST_HOT:
445 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
446 break;
447 case IMAGE_LIST_DISABLED:
448 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
449 break;
450 default:
451 himl = NULL;
452 FIXME("Shouldn't reach here\n");
455 if (!himl)
456 TRACE("no image list\n");
458 return himl;
462 static void
463 TOOLBAR_DrawFlatSeparator (const RECT *lpRect, HDC hdc, const TOOLBAR_INFO *infoPtr)
465 RECT myrect;
466 COLORREF oldcolor, newcolor;
468 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
469 myrect.right = myrect.left + 1;
470 myrect.top = lpRect->top + 2;
471 myrect.bottom = lpRect->bottom - 2;
473 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
474 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
475 oldcolor = SetBkColor (hdc, newcolor);
476 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
478 myrect.left = myrect.right;
479 myrect.right = myrect.left + 1;
481 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
482 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
483 SetBkColor (hdc, newcolor);
484 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
486 SetBkColor (hdc, oldcolor);
490 /***********************************************************************
491 * TOOLBAR_DrawFlatHorizontalSeparator
493 * This function draws horizontal separator for toolbars having CCS_VERT style.
494 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
495 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
496 * are horizontal as opposed to the vertical separators for not dropdown
497 * type.
499 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
501 static void
502 TOOLBAR_DrawFlatHorizontalSeparator (const RECT *lpRect, HDC hdc,
503 const TOOLBAR_INFO *infoPtr)
505 RECT myrect;
506 COLORREF oldcolor, newcolor;
508 myrect.left = lpRect->left;
509 myrect.right = lpRect->right;
510 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
511 myrect.bottom = myrect.top + 1;
513 InflateRect (&myrect, -2, 0);
515 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect));
517 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
518 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
519 oldcolor = SetBkColor (hdc, newcolor);
520 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
522 myrect.top = myrect.bottom;
523 myrect.bottom = myrect.top + 1;
525 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
526 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
527 SetBkColor (hdc, newcolor);
528 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
530 SetBkColor (hdc, oldcolor);
534 static void
535 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
537 INT x, y;
538 HPEN hPen, hOldPen;
540 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
541 hOldPen = SelectObject ( hdc, hPen );
542 x = left + 2;
543 y = top;
544 MoveToEx (hdc, x, y, NULL);
545 LineTo (hdc, x+5, y++); x++;
546 MoveToEx (hdc, x, y, NULL);
547 LineTo (hdc, x+3, y++); x++;
548 MoveToEx (hdc, x, y, NULL);
549 LineTo (hdc, x+1, y);
550 SelectObject( hdc, hOldPen );
551 DeleteObject( hPen );
555 * Draw the text string for this button.
556 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
557 * is non-zero, so we can simply check himlDef to see if we have
558 * an image list
560 static void
561 TOOLBAR_DrawString (const TOOLBAR_INFO *infoPtr, RECT *rcText, LPCWSTR lpText,
562 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
564 HDC hdc = tbcd->nmcd.hdc;
565 HFONT hOldFont = 0;
566 COLORREF clrOld = 0;
567 COLORREF clrOldBk = 0;
568 int oldBkMode = 0;
569 UINT state = tbcd->nmcd.uItemState;
571 /* draw text */
572 if (lpText) {
573 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText),
574 wine_dbgstr_rect(rcText));
576 hOldFont = SelectObject (hdc, infoPtr->hFont);
577 if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
578 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
580 else if (state & CDIS_DISABLED) {
581 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
582 OffsetRect (rcText, 1, 1);
583 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
584 SetTextColor (hdc, comctl32_color.clr3dShadow);
585 OffsetRect (rcText, -1, -1);
587 else if (state & CDIS_INDETERMINATE) {
588 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
590 else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
591 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
592 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
593 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
595 else {
596 clrOld = SetTextColor (hdc, tbcd->clrText);
599 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
600 SetTextColor (hdc, clrOld);
601 if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
603 SetBkColor (hdc, clrOldBk);
604 SetBkMode (hdc, oldBkMode);
606 SelectObject (hdc, hOldFont);
611 static void
612 TOOLBAR_DrawPattern (const RECT *lpRect, const NMTBCUSTOMDRAW *tbcd)
614 HDC hdc = tbcd->nmcd.hdc;
615 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
616 COLORREF clrTextOld;
617 COLORREF clrBkOld;
618 INT cx = lpRect->right - lpRect->left;
619 INT cy = lpRect->bottom - lpRect->top;
620 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
621 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
622 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
623 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
624 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
625 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
626 SetBkColor(hdc, clrBkOld);
627 SetTextColor(hdc, clrTextOld);
628 SelectObject (hdc, hbr);
632 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
634 INT cx, cy;
635 HBITMAP hbmMask, hbmImage;
636 HDC hdcMask, hdcImage;
638 ImageList_GetIconSize(himl, &cx, &cy);
640 /* Create src image */
641 hdcImage = CreateCompatibleDC(hdc);
642 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
643 SelectObject(hdcImage, hbmImage);
644 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
645 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
647 /* Create Mask */
648 hdcMask = CreateCompatibleDC(0);
649 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
650 SelectObject(hdcMask, hbmMask);
652 /* Remove the background and all white pixels */
653 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
654 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
655 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
656 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
658 /* draw the new mask 'etched' to hdc */
659 SetBkColor(hdc, RGB(255, 255, 255));
660 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
661 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
662 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
663 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
664 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
666 /* Cleanup */
667 DeleteObject(hbmImage);
668 DeleteDC(hdcImage);
669 DeleteObject (hbmMask);
670 DeleteDC(hdcMask);
674 static UINT
675 TOOLBAR_TranslateState(const TBUTTON_INFO *btnPtr)
677 UINT retstate = 0;
679 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
680 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
681 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
682 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
683 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
684 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
685 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
686 return retstate;
689 /* draws the image on a toolbar button */
690 static void
691 TOOLBAR_DrawImage(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
692 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
694 HIMAGELIST himl = NULL;
695 BOOL draw_masked = FALSE;
696 INT index;
697 INT offset = 0;
698 UINT draw_flags = ILD_TRANSPARENT;
700 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
702 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
703 if (!himl)
705 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
706 draw_masked = TRUE;
709 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
710 ((tbcd->nmcd.uItemState & CDIS_HOT)
711 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
713 /* if hot, attempt to draw with hot image list, if fails,
714 use default image list */
715 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
716 if (!himl)
717 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
719 else
720 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
722 if (!himl)
723 return;
725 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
726 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
727 offset = 1;
729 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
730 (tbcd->nmcd.uItemState & CDIS_MARKED))
731 draw_flags |= ILD_BLEND50;
733 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
734 index, himl, left, top, offset);
736 if (draw_masked)
737 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
738 else
739 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
742 /* draws a blank frame for a toolbar button */
743 static void
744 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
746 HDC hdc = tbcd->nmcd.hdc;
747 RECT rc = tbcd->nmcd.rc;
748 /* if the state is disabled or indeterminate then the button
749 * cannot have an interactive look like pressed or hot */
750 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
751 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
752 BOOL pressed_look = !non_interactive_state &&
753 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
754 (tbcd->nmcd.uItemState & CDIS_CHECKED));
756 /* app don't want us to draw any edges */
757 if (dwItemCDFlag & TBCDRF_NOEDGES)
758 return;
760 if (infoPtr->dwStyle & TBSTYLE_FLAT)
762 if (pressed_look)
763 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
764 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
765 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
767 else
769 if (pressed_look)
770 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
771 else
772 DrawEdge (hdc, &rc, EDGE_RAISED,
773 BF_SOFT | BF_RECT | BF_MIDDLE);
777 static void
778 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
780 HDC hdc = tbcd->nmcd.hdc;
781 int offset = 0;
782 BOOL pressed = bDropDownPressed ||
783 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
785 if (infoPtr->dwStyle & TBSTYLE_FLAT)
787 if (pressed)
788 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
789 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
790 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
791 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
792 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
794 else
796 if (pressed)
797 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
798 else
799 DrawEdge (hdc, rcArrow, EDGE_RAISED,
800 BF_SOFT | BF_RECT | BF_MIDDLE);
803 if (pressed)
804 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
806 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
808 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
809 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
811 else
812 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
815 /* draws a complete toolbar button */
816 static void
817 TOOLBAR_DrawButton (const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
819 DWORD dwStyle = infoPtr->dwStyle;
820 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
821 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
822 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
823 BOOL drawSepDropDownArrow = hasDropDownArrow &&
824 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
825 RECT rc, rcArrow, rcBitmap, rcText;
826 LPWSTR lpText = NULL;
827 NMTBCUSTOMDRAW tbcd;
828 DWORD ntfret;
829 INT offset;
830 INT oldBkMode;
831 DWORD dwItemCustDraw;
832 DWORD dwItemCDFlag;
833 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
835 rc = btnPtr->rect;
836 CopyRect (&rcArrow, &rc);
838 /* separator - doesn't send NM_CUSTOMDRAW */
839 if (btnPtr->fsStyle & BTNS_SEP) {
840 if (theme)
842 DrawThemeBackground (theme, hdc,
843 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
844 &rc, NULL);
846 else
847 /* with the FLAT style, iBitmap is the width and has already */
848 /* been taken into consideration in calculating the width */
849 /* so now we need to draw the vertical separator */
850 /* empirical tests show that iBitmap can/will be non-zero */
851 /* when drawing the vertical bar... */
852 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
853 if (dwStyle & CCS_VERT)
854 TOOLBAR_DrawFlatHorizontalSeparator (&rc, hdc, infoPtr);
855 else
856 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
858 else if (btnPtr->fsStyle != BTNS_SEP) {
859 FIXME("Draw some kind of separator: fsStyle=%x\n",
860 btnPtr->fsStyle);
862 return;
865 /* get a pointer to the text */
866 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
868 if (hasDropDownArrow)
870 int right;
872 if (dwStyle & TBSTYLE_FLAT)
873 right = max(rc.left, rc.right - DDARROW_WIDTH);
874 else
875 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
877 if (drawSepDropDownArrow)
878 rc.right = right;
880 rcArrow.left = right;
883 /* copy text & bitmap rects after adjusting for drop-down arrow
884 * so that text & bitmap is centered in the rectangle not containing
885 * the arrow */
886 CopyRect(&rcText, &rc);
887 CopyRect(&rcBitmap, &rc);
889 /* Center the bitmap horizontally and vertically */
890 if (dwStyle & TBSTYLE_LIST)
892 if (lpText &&
893 infoPtr->nMaxTextRows > 0 &&
894 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
895 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
896 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
897 else
898 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
900 else
901 rcBitmap.left += ((rc.right - rc.left) - infoPtr->nBitmapWidth) / 2;
903 rcBitmap.top += infoPtr->szPadding.cy / 2;
905 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
906 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
907 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
908 TRACE("Text=%s\n", debugstr_w(lpText));
909 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
911 /* calculate text position */
912 if (lpText)
914 rcText.left += GetSystemMetrics(SM_CXEDGE);
915 rcText.right -= GetSystemMetrics(SM_CXEDGE);
916 if (dwStyle & TBSTYLE_LIST)
918 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
920 else
922 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
923 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
924 else
925 rcText.top += infoPtr->szPadding.cy/2 + 2;
929 /* Initialize fields in all cases, because we use these later
930 * NOTE: applications can and do alter these to customize their
931 * toolbars */
932 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
933 tbcd.clrText = comctl32_color.clrBtnText;
934 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
935 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
936 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
937 tbcd.clrMark = comctl32_color.clrHighlight;
938 tbcd.clrHighlightHotTrack = 0;
939 tbcd.nStringBkMode = TRANSPARENT;
940 tbcd.nHLStringBkMode = OPAQUE;
941 /* MSDN says that this is the text rectangle.
942 * But (why always a but) tracing of v5.7 of native shows
943 * that this is really a *relative* rectangle based on the
944 * the nmcd.rc. Also the left and top are always 0 ignoring
945 * any bitmap that might be present. */
946 tbcd.rcText.left = 0;
947 tbcd.rcText.top = 0;
948 tbcd.rcText.right = rcText.right - rc.left;
949 tbcd.rcText.bottom = rcText.bottom - rc.top;
950 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
951 tbcd.nmcd.hdc = hdc;
952 tbcd.nmcd.rc = rc;
953 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
955 /* FIXME: what are these used for? */
956 tbcd.hbrLines = 0;
957 tbcd.hpenLines = 0;
959 /* Issue Item Prepaint notify */
960 dwItemCustDraw = 0;
961 dwItemCDFlag = 0;
962 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
964 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
965 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
966 tbcd.nmcd.lItemlParam = btnPtr->dwData;
967 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
968 /* reset these fields so the user can't alter the behaviour like native */
969 tbcd.nmcd.hdc = hdc;
970 tbcd.nmcd.rc = rc;
972 dwItemCustDraw = ntfret & 0xffff;
973 dwItemCDFlag = ntfret & 0xffff0000;
974 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
975 return;
976 /* save the only part of the rect that the user can change */
977 rcText.right = tbcd.rcText.right + rc.left;
978 rcText.bottom = tbcd.rcText.bottom + rc.top;
981 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
982 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
983 OffsetRect(&rcText, 1, 1);
985 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
986 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
987 TOOLBAR_DrawPattern (&rc, &tbcd);
989 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
990 && (tbcd.nmcd.uItemState & CDIS_HOT))
992 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
994 COLORREF oldclr;
996 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
997 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
998 if (hasDropDownArrow)
999 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
1000 SetBkColor(hdc, oldclr);
1004 if (theme)
1006 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1007 int stateId = TS_NORMAL;
1009 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1010 stateId = TS_DISABLED;
1011 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1012 stateId = TS_PRESSED;
1013 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1014 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1015 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1016 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1017 stateId = TS_HOT;
1019 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1021 else
1022 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1024 if (drawSepDropDownArrow)
1026 if (theme)
1028 int stateId = TS_NORMAL;
1030 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1031 stateId = TS_DISABLED;
1032 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1033 stateId = TS_PRESSED;
1034 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1035 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1036 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1037 stateId = TS_HOT;
1039 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1040 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1042 else
1043 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1046 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1047 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1048 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1049 SetBkMode (hdc, oldBkMode);
1051 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1053 if (hasDropDownArrow && !drawSepDropDownArrow)
1055 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1057 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1058 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1060 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1062 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1063 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1065 else
1066 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1069 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1071 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1072 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1078 static void
1079 TOOLBAR_Refresh (TOOLBAR_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
1081 TBUTTON_INFO *btnPtr;
1082 INT i;
1083 RECT rcTemp, rcClient;
1084 NMTBCUSTOMDRAW tbcd;
1085 DWORD ntfret;
1086 DWORD dwBaseCustDraw;
1088 /* the app has told us not to redraw the toolbar */
1089 if (!infoPtr->bDoRedraw)
1090 return;
1092 /* if imagelist belongs to the app, it can be changed
1093 by the app after setting it */
1094 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1096 infoPtr->nNumBitmaps = 0;
1097 for (i = 0; i < infoPtr->cimlDef; i++)
1098 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1101 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1103 /* change the imagelist icon size if we manage the list and it is necessary */
1104 TOOLBAR_CheckImageListIconSize(infoPtr);
1106 /* Send initial notify */
1107 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1108 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1109 tbcd.nmcd.hdc = hdc;
1110 tbcd.nmcd.rc = ps->rcPaint;
1111 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1112 dwBaseCustDraw = ntfret & 0xffff;
1114 GetClientRect(infoPtr->hwndSelf, &rcClient);
1116 /* redraw necessary buttons */
1117 btnPtr = infoPtr->buttons;
1118 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1120 BOOL bDraw;
1121 if (!RectVisible(hdc, &btnPtr->rect))
1122 continue;
1123 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1125 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1126 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1128 else
1129 bDraw = TRUE;
1130 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1131 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1132 if (bDraw)
1133 TOOLBAR_DrawButton(infoPtr, btnPtr, hdc, dwBaseCustDraw);
1136 /* draw insert mark if required */
1137 if (infoPtr->tbim.iButton != -1)
1139 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1140 RECT rcInsertMark;
1141 rcInsertMark.top = rcButton.top;
1142 rcInsertMark.bottom = rcButton.bottom;
1143 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1144 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1145 else
1146 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1147 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1150 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1152 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1153 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1154 tbcd.nmcd.hdc = hdc;
1155 tbcd.nmcd.rc = ps->rcPaint;
1156 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1160 /***********************************************************************
1161 * TOOLBAR_MeasureString
1163 * This function gets the width and height of a string in pixels. This
1164 * is done first by using GetTextExtentPoint to get the basic width
1165 * and height. The DrawText is called with DT_CALCRECT to get the exact
1166 * width. The reason is because the text may have more than one "&" (or
1167 * prefix characters as M$ likes to call them). The prefix character
1168 * indicates where the underline goes, except for the string "&&" which
1169 * is reduced to a single "&". GetTextExtentPoint does not process these
1170 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1172 static void
1173 TOOLBAR_MeasureString(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr,
1174 HDC hdc, LPSIZE lpSize)
1176 RECT myrect;
1178 lpSize->cx = 0;
1179 lpSize->cy = 0;
1181 if (infoPtr->nMaxTextRows > 0 &&
1182 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1183 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1184 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1186 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1188 if(lpText != NULL) {
1189 /* first get size of all the text */
1190 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1192 /* feed above size into the rectangle for DrawText */
1193 myrect.left = myrect.top = 0;
1194 myrect.right = lpSize->cx;
1195 myrect.bottom = lpSize->cy;
1197 /* Use DrawText to get true size as drawn (less pesky "&") */
1198 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1199 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1200 DT_NOPREFIX : 0));
1202 /* feed back to caller */
1203 lpSize->cx = myrect.right;
1204 lpSize->cy = myrect.bottom;
1208 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1211 /***********************************************************************
1212 * TOOLBAR_CalcStrings
1214 * This function walks through each string and measures it and returns
1215 * the largest height and width to caller.
1217 static void
1218 TOOLBAR_CalcStrings (const TOOLBAR_INFO *infoPtr, LPSIZE lpSize)
1220 TBUTTON_INFO *btnPtr;
1221 INT i;
1222 SIZE sz;
1223 HDC hdc;
1224 HFONT hOldFont;
1226 lpSize->cx = 0;
1227 lpSize->cy = 0;
1229 if (infoPtr->nMaxTextRows == 0)
1230 return;
1232 hdc = GetDC (infoPtr->hwndSelf);
1233 hOldFont = SelectObject (hdc, infoPtr->hFont);
1235 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1237 TEXTMETRICW tm;
1239 GetTextMetricsW(hdc, &tm);
1240 lpSize->cy = tm.tmHeight;
1243 btnPtr = infoPtr->buttons;
1244 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1245 if(TOOLBAR_HasText(infoPtr, btnPtr))
1247 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1248 if (sz.cx > lpSize->cx)
1249 lpSize->cx = sz.cx;
1250 if (sz.cy > lpSize->cy)
1251 lpSize->cy = sz.cy;
1255 SelectObject (hdc, hOldFont);
1256 ReleaseDC (infoPtr->hwndSelf, hdc);
1258 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1261 /***********************************************************************
1262 * TOOLBAR_WrapToolbar
1264 * This function walks through the buttons and separators in the
1265 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1266 * wrapping should occur based on the width of the toolbar window.
1267 * It does *not* calculate button placement itself. That task
1268 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1269 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1270 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1272 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1273 * vertical toolbar lists.
1276 static void
1277 TOOLBAR_WrapToolbar(TOOLBAR_INFO *infoPtr)
1279 TBUTTON_INFO *btnPtr;
1280 INT x, cx, i, j;
1281 RECT rc;
1282 BOOL bButtonWrap;
1284 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1285 /* no layout is necessary. Applications may use this style */
1286 /* to perform their own layout on the toolbar. */
1287 if( !(infoPtr->dwStyle & TBSTYLE_WRAPABLE) &&
1288 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1290 btnPtr = infoPtr->buttons;
1291 x = infoPtr->nIndent;
1293 if (GetParent(infoPtr->hwndSelf))
1295 /* this can get the parents width, to know how far we can extend
1296 * this toolbar. We cannot use its height, as there may be multiple
1297 * toolbars in a rebar control
1299 GetClientRect( GetParent(infoPtr->hwndSelf), &rc );
1300 infoPtr->nWidth = rc.right - rc.left;
1302 else
1304 GetWindowRect( infoPtr->hwndSelf, &rc );
1305 infoPtr->nWidth = rc.right - rc.left;
1308 bButtonWrap = FALSE;
1310 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1311 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1312 infoPtr->nIndent);
1314 for (i = 0; i < infoPtr->nNumButtons; i++ )
1316 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1318 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1319 continue;
1321 if (btnPtr[i].cx > 0)
1322 cx = btnPtr[i].cx;
1323 /* horizontal separators are treated as buttons for width */
1324 else if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1325 !(infoPtr->dwStyle & CCS_VERT))
1326 cx = (btnPtr[i].iBitmap > 0) ? btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1327 else
1328 cx = infoPtr->nButtonWidth;
1330 /* Two or more adjacent separators form a separator group. */
1331 /* The first separator in a group should be wrapped to the */
1332 /* next row if the previous wrapping is on a button. */
1333 if( bButtonWrap &&
1334 (btnPtr[i].fsStyle & BTNS_SEP) &&
1335 (i + 1 < infoPtr->nNumButtons ) &&
1336 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1338 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1339 btnPtr[i].fsState |= TBSTATE_WRAP;
1340 x = infoPtr->nIndent;
1341 i++;
1342 bButtonWrap = FALSE;
1343 continue;
1346 /* The layout makes sure the bitmap is visible, but not the button. */
1347 /* Test added to also wrap after a button that starts a row but */
1348 /* is bigger than the area. - GA 8/01 */
1349 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1350 > infoPtr->nWidth ) ||
1351 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1353 BOOL bFound = FALSE;
1355 /* If the current button is a separator and not hidden, */
1356 /* go to the next until it reaches a non separator. */
1357 /* Wrap the last separator if it is before a button. */
1358 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1359 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1360 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1361 i < infoPtr->nNumButtons )
1363 i++;
1364 bFound = TRUE;
1367 if( bFound && i < infoPtr->nNumButtons )
1369 i--;
1370 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1371 i, btnPtr[i].fsStyle, x, cx);
1372 btnPtr[i].fsState |= TBSTATE_WRAP;
1373 x = infoPtr->nIndent;
1374 bButtonWrap = FALSE;
1375 continue;
1377 else if ( i >= infoPtr->nNumButtons)
1378 break;
1380 /* If the current button is not a separator, find the last */
1381 /* separator and wrap it. */
1382 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1384 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1385 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1387 bFound = TRUE;
1388 i = j;
1389 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1390 i, btnPtr[i].fsStyle, x, cx);
1391 x = infoPtr->nIndent;
1392 btnPtr[j].fsState |= TBSTATE_WRAP;
1393 bButtonWrap = FALSE;
1394 break;
1398 /* If no separator available for wrapping, wrap one of */
1399 /* non-hidden previous button. */
1400 if (!bFound)
1402 for ( j = i - 1;
1403 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1405 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1406 continue;
1408 bFound = TRUE;
1409 i = j;
1410 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1411 i, btnPtr[i].fsStyle, x, cx);
1412 x = infoPtr->nIndent;
1413 btnPtr[j].fsState |= TBSTATE_WRAP;
1414 bButtonWrap = TRUE;
1415 break;
1419 /* If all above failed, wrap the current button. */
1420 if (!bFound)
1422 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1423 i, btnPtr[i].fsStyle, x, cx);
1424 btnPtr[i].fsState |= TBSTATE_WRAP;
1425 x = infoPtr->nIndent;
1426 if (btnPtr[i].fsStyle & BTNS_SEP )
1427 bButtonWrap = FALSE;
1428 else
1429 bButtonWrap = TRUE;
1432 else {
1433 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1434 i, btnPtr[i].fsStyle, x, cx);
1435 x += cx;
1441 /***********************************************************************
1442 * TOOLBAR_MeasureButton
1444 * Calculates the width and height required for a button. Used in
1445 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1446 * the width of buttons that are autosized.
1448 * Note that it would have been rather elegant to use one piece of code for
1449 * both the laying out of the toolbar and for controlling where button parts
1450 * are drawn, but the native control has inconsistencies between the two that
1451 * prevent this from being effectively. These inconsistencies can be seen as
1452 * artefacts where parts of the button appear outside of the bounding button
1453 * rectangle.
1455 * There are several cases for the calculation of the button dimensions and
1456 * button part positioning:
1458 * List
1459 * ====
1461 * With Bitmap:
1463 * +--------------------------------------------------------+ ^
1464 * | ^ ^ | |
1465 * | | pad.cy / 2 | centred | |
1466 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1467 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1468 * | |<------------>| | | | |
1469 * | +--------------+ +------------+ | |
1470 * |<-------------------------------------->| | |
1471 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1472 * | szText.cx | |
1473 * +--------------------------------------------------------+ -
1474 * <-------------------------------------------------------->
1475 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1477 * Without Bitmap (I_IMAGENONE):
1479 * +-----------------------------------+ ^
1480 * | ^ | |
1481 * | | centred | | LISTPAD_CY +
1482 * | +------------+ | | szText.cy
1483 * | | Text | | |
1484 * | | | | |
1485 * | +------------+ | |
1486 * |<----------------->| | |
1487 * | cxedge |<-----------> | |
1488 * | szText.cx | |
1489 * +-----------------------------------+ -
1490 * <----------------------------------->
1491 * szText.cx + pad.cx
1493 * Without text:
1495 * +--------------------------------------+ ^
1496 * | ^ | |
1497 * | | padding.cy/2 | | DEFPAD_CY +
1498 * | +------------+ | | nBitmapHeight
1499 * | | Bitmap | | |
1500 * | | | | |
1501 * | +------------+ | |
1502 * |<------------------->| | |
1503 * | cxedge + iListGap/2 |<-----------> | |
1504 * | nBitmapWidth | |
1505 * +--------------------------------------+ -
1506 * <-------------------------------------->
1507 * 2*cxedge + nBitmapWidth + iListGap
1509 * Non-List
1510 * ========
1512 * With bitmap:
1514 * +-----------------------------------+ ^
1515 * | ^ | |
1516 * | | pad.cy / 2 | | nBitmapHeight +
1517 * | - | | szText.cy +
1518 * | +------------+ | | DEFPAD_CY + 1
1519 * | centred | Bitmap | | |
1520 * |<----------------->| | | |
1521 * | +------------+ | |
1522 * | ^ | |
1523 * | 1 | | |
1524 * | - | |
1525 * | centred +---------------+ | |
1526 * |<--------------->| Text | | |
1527 * | +---------------+ | |
1528 * +-----------------------------------+ -
1529 * <----------------------------------->
1530 * pad.cx + max(nBitmapWidth, szText.cx)
1532 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1534 * +---------------------------------------+ ^
1535 * | ^ | |
1536 * | | 2 + pad.cy / 2 | |
1537 * | - | | szText.cy +
1538 * | centred +-----------------+ | | pad.cy + 2
1539 * |<--------------->| Text | | |
1540 * | +-----------------+ | |
1541 * | | |
1542 * +---------------------------------------+ -
1543 * <--------------------------------------->
1544 * 2*cxedge + pad.cx + szText.cx
1546 * Without text:
1547 * As for with bitmaps, but with szText.cx zero.
1549 static inline SIZE TOOLBAR_MeasureButton(const TOOLBAR_INFO *infoPtr, SIZE sizeString,
1550 BOOL bHasBitmap, BOOL bValidImageList)
1552 SIZE sizeButton;
1553 if (infoPtr->dwStyle & TBSTYLE_LIST)
1555 /* set button height from bitmap / text height... */
1556 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1557 sizeString.cy);
1559 /* ... add on the necessary padding */
1560 if (bValidImageList)
1562 if (bHasBitmap)
1563 sizeButton.cy += DEFPAD_CY;
1564 else
1565 sizeButton.cy += LISTPAD_CY;
1567 else
1568 sizeButton.cy += infoPtr->szPadding.cy;
1570 /* calculate button width */
1571 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1572 infoPtr->nBitmapWidth + infoPtr->iListGap;
1573 if (sizeString.cx > 0)
1574 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1577 else
1579 if (bHasBitmap)
1581 sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
1582 if (sizeString.cy > 0)
1583 sizeButton.cy += 1 + sizeString.cy;
1584 sizeButton.cx = infoPtr->szPadding.cx +
1585 max(sizeString.cx, infoPtr->nBitmapWidth);
1587 else
1589 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1590 NONLIST_NOTEXT_OFFSET;
1591 sizeButton.cx = infoPtr->szPadding.cx +
1592 max(2*GetSystemMetrics(SM_CXEDGE) + sizeString.cx, infoPtr->nBitmapWidth);
1595 return sizeButton;
1599 /***********************************************************************
1600 * TOOLBAR_CalcToolbar
1602 * This function calculates button and separator placement. It first
1603 * calculates the button sizes, gets the toolbar window width and then
1604 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1605 * on. It assigns a new location to each item and sends this location to
1606 * the tooltip window if appropriate. Finally, it updates the rcBound
1607 * rect and calculates the new required toolbar window height.
1609 static void
1610 TOOLBAR_CalcToolbar (TOOLBAR_INFO *infoPtr)
1612 SIZE sizeString, sizeButton;
1613 BOOL validImageList = FALSE;
1615 TOOLBAR_CalcStrings (infoPtr, &sizeString);
1617 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1619 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1620 validImageList = TRUE;
1621 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1622 infoPtr->nButtonWidth = sizeButton.cx;
1623 infoPtr->nButtonHeight = sizeButton.cy;
1624 infoPtr->iTopMargin = default_top_margin(infoPtr);
1626 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1627 infoPtr->nButtonWidth = infoPtr->cxMin;
1628 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1629 infoPtr->nButtonWidth = infoPtr->cxMax;
1631 TOOLBAR_LayoutToolbar(infoPtr);
1634 static void
1635 TOOLBAR_LayoutToolbar(TOOLBAR_INFO *infoPtr)
1637 TBUTTON_INFO *btnPtr;
1638 SIZE sizeButton;
1639 INT i, nRows, nSepRows;
1640 INT x, y, cx, cy;
1641 BOOL bWrap;
1642 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1643 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1645 TOOLBAR_WrapToolbar(infoPtr);
1647 x = infoPtr->nIndent;
1648 y = infoPtr->iTopMargin;
1649 cx = infoPtr->nButtonWidth;
1650 cy = infoPtr->nButtonHeight;
1652 nRows = nSepRows = 0;
1654 infoPtr->rcBound.top = y;
1655 infoPtr->rcBound.left = x;
1656 infoPtr->rcBound.bottom = y + cy;
1657 infoPtr->rcBound.right = x;
1659 btnPtr = infoPtr->buttons;
1661 TRACE("cy=%d\n", cy);
1663 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1665 bWrap = FALSE;
1666 if (btnPtr->fsState & TBSTATE_HIDDEN)
1668 SetRectEmpty (&btnPtr->rect);
1669 continue;
1672 cy = infoPtr->nButtonHeight;
1674 if (btnPtr->fsStyle & BTNS_SEP) {
1675 if (infoPtr->dwStyle & CCS_VERT) {
1676 cy = (btnPtr->iBitmap > 0) ? btnPtr->iBitmap : SEPARATOR_WIDTH;
1677 cx = (btnPtr->cx > 0) ? btnPtr->cx : infoPtr->nWidth;
1679 else
1680 cx = (btnPtr->cx > 0) ? btnPtr->cx :
1681 (btnPtr->iBitmap > 0) ? btnPtr->iBitmap : SEPARATOR_WIDTH;
1683 else
1685 if (btnPtr->cx)
1686 cx = btnPtr->cx;
1687 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1688 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1690 SIZE sz;
1691 HDC hdc;
1692 HFONT hOldFont;
1694 hdc = GetDC (infoPtr->hwndSelf);
1695 hOldFont = SelectObject (hdc, infoPtr->hFont);
1697 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1699 SelectObject (hdc, hOldFont);
1700 ReleaseDC (infoPtr->hwndSelf, hdc);
1702 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1703 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1704 validImageList);
1705 cx = sizeButton.cx;
1707 else
1708 cx = infoPtr->nButtonWidth;
1710 /* if size has been set manually then don't add on extra space
1711 * for the drop down arrow */
1712 if (!btnPtr->cx && hasDropDownArrows &&
1713 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1714 cx += DDARROW_WIDTH;
1716 if (btnPtr->fsState & TBSTATE_WRAP )
1717 bWrap = TRUE;
1719 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1721 if (infoPtr->rcBound.left > x)
1722 infoPtr->rcBound.left = x;
1723 if (infoPtr->rcBound.right < x + cx)
1724 infoPtr->rcBound.right = x + cx;
1725 if (infoPtr->rcBound.bottom < y + cy)
1726 infoPtr->rcBound.bottom = y + cy;
1728 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1730 /* btnPtr->nRow is zero based. The space between the rows is */
1731 /* also considered as a row. */
1732 btnPtr->nRow = nRows + nSepRows;
1734 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1735 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1736 x, y, x+cx, y+cy);
1738 if( bWrap )
1740 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1741 y += cy;
1742 else
1744 if ( !(infoPtr->dwStyle & CCS_VERT))
1745 y += cy + ( (btnPtr->cx > 0 ) ?
1746 btnPtr->cx : SEPARATOR_WIDTH) * 2 /3;
1747 else
1748 y += cy;
1750 /* nSepRows is used to calculate the extra height following */
1751 /* the last row. */
1752 nSepRows++;
1754 x = infoPtr->nIndent;
1756 /* Increment row number unless this is the last button */
1757 /* and it has Wrap set. */
1758 if (i != infoPtr->nNumButtons-1)
1759 nRows++;
1761 else
1762 x += cx;
1765 /* infoPtr->nRows is the number of rows on the toolbar */
1766 infoPtr->nRows = nRows + nSepRows + 1;
1768 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1772 static INT
1773 TOOLBAR_InternalHitTest (const TOOLBAR_INFO *infoPtr, const POINT *lpPt)
1775 TBUTTON_INFO *btnPtr;
1776 INT i;
1778 btnPtr = infoPtr->buttons;
1779 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1780 if (btnPtr->fsState & TBSTATE_HIDDEN)
1781 continue;
1783 if (btnPtr->fsStyle & BTNS_SEP) {
1784 if (PtInRect (&btnPtr->rect, *lpPt)) {
1785 TRACE(" ON SEPARATOR %d!\n", i);
1786 return -i;
1789 else {
1790 if (PtInRect (&btnPtr->rect, *lpPt)) {
1791 TRACE(" ON BUTTON %d!\n", i);
1792 return i;
1797 TRACE(" NOWHERE!\n");
1798 return TOOLBAR_NOWHERE;
1802 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1803 static BOOL
1804 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO *infoPtr, INT iIndex, UINT nAddButtons, const TBBUTTON *lpTbb, BOOL fUnicode)
1806 INT nOldButtons, nNewButtons, iButton;
1807 BOOL fHasString = FALSE;
1809 if (iIndex < 0) /* iIndex can be negative, what means adding at the end */
1810 iIndex = infoPtr->nNumButtons;
1812 nOldButtons = infoPtr->nNumButtons;
1813 nNewButtons = nOldButtons + nAddButtons;
1815 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
1816 memmove(&infoPtr->buttons[iIndex + nAddButtons], &infoPtr->buttons[iIndex],
1817 (nOldButtons - iIndex) * sizeof(TBUTTON_INFO));
1818 infoPtr->nNumButtons += nAddButtons;
1820 /* insert new buttons data */
1821 for (iButton = 0; iButton < nAddButtons; iButton++) {
1822 TBUTTON_INFO *btnPtr = &infoPtr->buttons[iIndex + iButton];
1824 TOOLBAR_DumpTBButton(lpTbb + iButton, fUnicode);
1826 ZeroMemory(btnPtr, sizeof(*btnPtr));
1828 btnPtr->iBitmap = lpTbb[iButton].iBitmap;
1829 btnPtr->idCommand = lpTbb[iButton].idCommand;
1830 btnPtr->fsState = lpTbb[iButton].fsState;
1831 btnPtr->fsStyle = lpTbb[iButton].fsStyle;
1832 btnPtr->dwData = lpTbb[iButton].dwData;
1833 if (btnPtr->fsStyle & BTNS_SEP)
1834 btnPtr->iString = -1;
1835 else if(HIWORD(lpTbb[iButton].iString) && lpTbb[iButton].iString != -1)
1837 if (fUnicode)
1838 Str_SetPtrW((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[iButton].iString );
1839 else
1840 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[iButton].iString);
1841 fHasString = TRUE;
1843 else
1844 btnPtr->iString = lpTbb[iButton].iString;
1846 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
1849 if (infoPtr->nNumStrings > 0 || fHasString)
1850 TOOLBAR_CalcToolbar(infoPtr);
1851 else
1852 TOOLBAR_LayoutToolbar(infoPtr);
1853 TOOLBAR_AutoSize(infoPtr);
1855 TOOLBAR_DumpToolbar(infoPtr, __LINE__);
1856 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1857 return TRUE;
1861 static INT
1862 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1864 TBUTTON_INFO *btnPtr;
1865 INT i;
1867 if (CommandIsIndex) {
1868 TRACE("command is really index command=%d\n", idCommand);
1869 if (idCommand >= infoPtr->nNumButtons) return -1;
1870 return idCommand;
1872 btnPtr = infoPtr->buttons;
1873 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1874 if (btnPtr->idCommand == idCommand) {
1875 TRACE("command=%d index=%d\n", idCommand, i);
1876 return i;
1879 TRACE("no index found for command=%d\n", idCommand);
1880 return -1;
1884 static INT
1885 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO *infoPtr, INT nIndex)
1887 TBUTTON_INFO *btnPtr;
1888 INT nRunIndex;
1890 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1891 return -1;
1893 /* check index button */
1894 btnPtr = &infoPtr->buttons[nIndex];
1895 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1896 if (btnPtr->fsState & TBSTATE_CHECKED)
1897 return nIndex;
1900 /* check previous buttons */
1901 nRunIndex = nIndex - 1;
1902 while (nRunIndex >= 0) {
1903 btnPtr = &infoPtr->buttons[nRunIndex];
1904 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1905 if (btnPtr->fsState & TBSTATE_CHECKED)
1906 return nRunIndex;
1908 else
1909 break;
1910 nRunIndex--;
1913 /* check next buttons */
1914 nRunIndex = nIndex + 1;
1915 while (nRunIndex < infoPtr->nNumButtons) {
1916 btnPtr = &infoPtr->buttons[nRunIndex];
1917 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1918 if (btnPtr->fsState & TBSTATE_CHECKED)
1919 return nRunIndex;
1921 else
1922 break;
1923 nRunIndex++;
1926 return -1;
1930 static VOID
1931 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1932 WPARAM wParam, LPARAM lParam)
1934 MSG msg;
1936 msg.hwnd = hwndMsg;
1937 msg.message = uMsg;
1938 msg.wParam = wParam;
1939 msg.lParam = lParam;
1940 msg.time = GetMessageTime ();
1941 msg.pt.x = (short)LOWORD(GetMessagePos ());
1942 msg.pt.y = (short)HIWORD(GetMessagePos ());
1944 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1947 static void
1948 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1950 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1951 TTTOOLINFOW ti;
1953 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1954 ti.cbSize = sizeof (TTTOOLINFOW);
1955 ti.hwnd = infoPtr->hwndSelf;
1956 ti.uId = button->idCommand;
1957 ti.hinst = 0;
1958 ti.lpszText = LPSTR_TEXTCALLBACKW;
1959 /* ti.lParam = random value from the stack? */
1961 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1962 0, (LPARAM)&ti);
1966 static void
1967 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1969 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1970 TTTOOLINFOW ti;
1972 ZeroMemory(&ti, sizeof(ti));
1973 ti.cbSize = sizeof(ti);
1974 ti.hwnd = infoPtr->hwndSelf;
1975 ti.uId = button->idCommand;
1977 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1981 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1983 /* Set the toolTip only for non-hidden, non-separator button */
1984 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1986 TTTOOLINFOW ti;
1988 ZeroMemory(&ti, sizeof(ti));
1989 ti.cbSize = sizeof(ti);
1990 ti.hwnd = infoPtr->hwndSelf;
1991 ti.uId = button->idCommand;
1992 ti.rect = button->rect;
1993 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1997 /* Creates the tooltip control */
1998 static void
1999 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
2001 int i;
2002 NMTOOLTIPSCREATED nmttc;
2004 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
2005 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2006 infoPtr->hwndSelf, 0, 0, 0);
2008 if (!infoPtr->hwndToolTip)
2009 return;
2011 /* Send NM_TOOLTIPSCREATED notification */
2012 nmttc.hwndToolTips = infoPtr->hwndToolTip;
2013 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
2015 for (i = 0; i < infoPtr->nNumButtons; i++)
2017 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
2018 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
2022 /* keeps available button list box sorted by button id */
2023 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
2025 int i;
2026 int count;
2027 PCUSTOMBUTTON btnInfo;
2028 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2030 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
2032 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2034 /* position 0 is always separator */
2035 for (i = 1; i < count; i++)
2037 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
2038 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2040 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2041 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2042 return;
2045 /* id higher than all others add to end */
2046 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2047 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2050 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2052 NMTOOLBARW nmtb;
2054 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2056 if (nIndexFrom == nIndexTo)
2057 return;
2059 /* MSDN states that iItem is the index of the button, rather than the
2060 * command ID as used by every other NMTOOLBAR notification */
2061 nmtb.iItem = nIndexFrom;
2062 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2064 PCUSTOMBUTTON btnInfo;
2065 NMHDR hdr;
2066 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2067 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2069 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2071 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2072 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2073 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2074 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2076 if (nIndexTo <= 0)
2077 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2078 else
2079 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2081 /* last item is always separator, so -2 instead of -1 */
2082 if (nIndexTo >= (count - 2))
2083 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2084 else
2085 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2087 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2088 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2090 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2094 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2096 NMTOOLBARW nmtb;
2098 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2100 /* MSDN states that iItem is the index of the button, rather than the
2101 * command ID as used by every other NMTOOLBAR notification */
2102 nmtb.iItem = nIndexAvail;
2103 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2105 PCUSTOMBUTTON btnInfo;
2106 NMHDR hdr;
2107 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2108 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2109 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2111 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2113 if (nIndexAvail != 0) /* index == 0 indicates separator */
2115 /* remove from 'available buttons' list */
2116 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2117 if (nIndexAvail == count-1)
2118 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2119 else
2120 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2122 else
2124 PCUSTOMBUTTON btnNew;
2126 /* duplicate 'separator' button */
2127 btnNew = Alloc(sizeof(CUSTOMBUTTON));
2128 *btnNew = *btnInfo;
2129 btnInfo = btnNew;
2132 /* insert into 'toolbar button' list */
2133 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2134 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2136 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2138 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2142 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT index)
2144 PCUSTOMBUTTON btnInfo;
2145 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2147 TRACE("Remove: index %d\n", index);
2149 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2151 /* send TBN_QUERYDELETE notification */
2152 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2154 NMHDR hdr;
2156 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2157 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2159 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2161 /* insert into 'available button' list */
2162 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2163 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2164 else
2165 Free(btnInfo);
2167 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2171 /* drag list notification function for toolbar buttons list box */
2172 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2173 const DRAGLISTINFO *pDLI)
2175 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2176 switch (pDLI->uNotification)
2178 case DL_BEGINDRAG:
2180 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2181 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2182 /* no dragging for last item (separator) */
2183 if (nCurrentItem >= (nCount - 1)) return FALSE;
2184 return TRUE;
2186 case DL_DRAGGING:
2188 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2189 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2190 /* no dragging past last item (separator) */
2191 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2193 DrawInsert(hwnd, hwndList, nCurrentItem);
2194 /* FIXME: native uses "move button" cursor */
2195 return DL_COPYCURSOR;
2198 /* not over toolbar buttons list */
2199 if (nCurrentItem < 0)
2201 POINT ptWindow = pDLI->ptCursor;
2202 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2203 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2204 /* over available buttons list? */
2205 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2206 /* FIXME: native uses "move button" cursor */
2207 return DL_COPYCURSOR;
2209 /* clear drag arrow */
2210 DrawInsert(hwnd, hwndList, -1);
2211 return DL_STOPCURSOR;
2213 case DL_DROPPED:
2215 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2216 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2217 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2218 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2220 /* clear drag arrow */
2221 DrawInsert(hwnd, hwndList, -1);
2222 /* move item */
2223 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2225 /* not over toolbar buttons list */
2226 if (nIndexTo < 0)
2228 POINT ptWindow = pDLI->ptCursor;
2229 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2230 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2231 /* over available buttons list? */
2232 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2233 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2235 break;
2237 case DL_CANCELDRAG:
2238 /* Clear drag arrow */
2239 DrawInsert(hwnd, hwndList, -1);
2240 break;
2243 return 0;
2246 /* drag list notification function for available buttons list box */
2247 static LRESULT TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2248 const DRAGLISTINFO *pDLI)
2250 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2251 switch (pDLI->uNotification)
2253 case DL_BEGINDRAG:
2254 return TRUE;
2255 case DL_DRAGGING:
2257 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2258 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2259 /* no dragging past last item (separator) */
2260 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2262 DrawInsert(hwnd, hwndList, nCurrentItem);
2263 /* FIXME: native uses "move button" cursor */
2264 return DL_COPYCURSOR;
2267 /* not over toolbar buttons list */
2268 if (nCurrentItem < 0)
2270 POINT ptWindow = pDLI->ptCursor;
2271 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2272 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2273 /* over available buttons list? */
2274 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2275 /* FIXME: native uses "move button" cursor */
2276 return DL_COPYCURSOR;
2278 /* clear drag arrow */
2279 DrawInsert(hwnd, hwndList, -1);
2280 return DL_STOPCURSOR;
2282 case DL_DROPPED:
2284 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2285 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2286 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2287 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2289 /* clear drag arrow */
2290 DrawInsert(hwnd, hwndList, -1);
2291 /* add item */
2292 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2295 case DL_CANCELDRAG:
2296 /* Clear drag arrow */
2297 DrawInsert(hwnd, hwndList, -1);
2298 break;
2300 return 0;
2303 extern UINT uDragListMessage;
2305 /***********************************************************************
2306 * TOOLBAR_CustomizeDialogProc
2307 * This function implements the toolbar customization dialog.
2309 static INT_PTR CALLBACK
2310 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2312 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2313 PCUSTOMBUTTON btnInfo;
2314 NMTOOLBARA nmtb;
2315 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2317 switch (uMsg)
2319 case WM_INITDIALOG:
2320 custInfo = (PCUSTDLG_INFO)lParam;
2321 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2323 if (custInfo)
2325 WCHAR Buffer[256];
2326 int i = 0;
2327 int index;
2328 NMTBINITCUSTOMIZE nmtbic;
2330 infoPtr = custInfo->tbInfo;
2332 /* send TBN_QUERYINSERT notification */
2333 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2335 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2336 return FALSE;
2338 nmtbic.hwndDialog = hwnd;
2339 /* Send TBN_INITCUSTOMIZE notification */
2340 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2341 TBNRF_HIDEHELP)
2343 TRACE("TBNRF_HIDEHELP requested\n");
2344 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2347 /* add items to 'toolbar buttons' list and check if removable */
2348 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2350 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2351 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2352 btnInfo->btn.fsStyle = BTNS_SEP;
2353 btnInfo->bVirtual = FALSE;
2354 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2356 /* send TBN_QUERYDELETE notification */
2357 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2359 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2360 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2363 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2365 /* insert separator button into 'available buttons' list */
2366 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2367 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2368 btnInfo->btn.fsStyle = BTNS_SEP;
2369 btnInfo->bVirtual = FALSE;
2370 btnInfo->bRemovable = TRUE;
2371 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2372 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2373 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2375 /* insert all buttons into dsa */
2376 for (i = 0;; i++)
2378 /* send TBN_GETBUTTONINFO notification */
2379 NMTOOLBARW nmtb;
2380 nmtb.iItem = i;
2381 nmtb.pszText = Buffer;
2382 nmtb.cchText = 256;
2384 /* Clear previous button's text */
2385 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2387 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2388 break;
2390 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2391 nmtb.tbButton.fsStyle, i,
2392 nmtb.tbButton.idCommand,
2393 nmtb.tbButton.iString,
2394 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2395 : "");
2397 /* insert button into the apropriate list */
2398 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2399 if (index == -1)
2401 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2402 btnInfo->bVirtual = FALSE;
2403 btnInfo->bRemovable = TRUE;
2405 else
2407 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2408 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2411 btnInfo->btn = nmtb.tbButton;
2412 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2414 if (lstrlenW(nmtb.pszText))
2415 lstrcpyW(btnInfo->text, nmtb.pszText);
2416 else if (nmtb.tbButton.iString >= 0 &&
2417 nmtb.tbButton.iString < infoPtr->nNumStrings)
2419 lstrcpyW(btnInfo->text,
2420 infoPtr->strings[nmtb.tbButton.iString]);
2424 if (index == -1)
2425 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2428 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2430 /* select first item in the 'available' list */
2431 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2433 /* append 'virtual' separator button to the 'toolbar buttons' list */
2434 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2435 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2436 btnInfo->btn.fsStyle = BTNS_SEP;
2437 btnInfo->bVirtual = TRUE;
2438 btnInfo->bRemovable = FALSE;
2439 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2440 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2441 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2443 /* select last item in the 'toolbar' list */
2444 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2445 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2447 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2448 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2450 /* set focus and disable buttons */
2451 PostMessageW (hwnd, WM_USER, 0, 0);
2453 return TRUE;
2455 case WM_USER:
2456 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2457 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2458 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2459 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2460 return TRUE;
2462 case WM_CLOSE:
2463 EndDialog(hwnd, FALSE);
2464 return TRUE;
2466 case WM_COMMAND:
2467 switch (LOWORD(wParam))
2469 case IDC_TOOLBARBTN_LBOX:
2470 if (HIWORD(wParam) == LBN_SELCHANGE)
2472 PCUSTOMBUTTON btnInfo;
2473 NMTOOLBARA nmtb;
2474 int count;
2475 int index;
2477 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2478 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2480 /* send TBN_QUERYINSERT notification */
2481 nmtb.iItem = index;
2482 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2484 /* get list box item */
2485 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2487 if (index == (count - 1))
2489 /* last item (virtual separator) */
2490 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2491 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2493 else if (index == (count - 2))
2495 /* second last item (last non-virtual item) */
2496 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2497 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2499 else if (index == 0)
2501 /* first item */
2502 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2503 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2505 else
2507 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2508 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2511 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2513 break;
2515 case IDC_MOVEUP_BTN:
2517 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2518 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2520 break;
2522 case IDC_MOVEDN_BTN: /* move down */
2524 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2525 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2527 break;
2529 case IDC_REMOVE_BTN: /* remove button */
2531 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2533 if (LB_ERR == index)
2534 break;
2536 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2538 break;
2539 case IDC_HELP_BTN:
2540 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2541 break;
2542 case IDC_RESET_BTN:
2543 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2544 break;
2546 case IDOK: /* Add button */
2548 int index;
2549 int indexto;
2551 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2552 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2554 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2556 break;
2558 case IDCANCEL:
2559 EndDialog(hwnd, FALSE);
2560 break;
2562 return TRUE;
2564 case WM_DESTROY:
2566 int count;
2567 int i;
2569 /* delete items from 'toolbar buttons' listbox*/
2570 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2571 for (i = 0; i < count; i++)
2573 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2574 Free(btnInfo);
2575 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2577 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2580 /* delete items from 'available buttons' listbox*/
2581 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2582 for (i = 0; i < count; i++)
2584 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2585 Free(btnInfo);
2586 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2588 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2590 return TRUE;
2592 case WM_DRAWITEM:
2593 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2595 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2596 RECT rcButton;
2597 RECT rcText;
2598 HPEN hPen, hOldPen;
2599 HBRUSH hOldBrush;
2600 COLORREF oldText = 0;
2601 COLORREF oldBk = 0;
2603 /* get item data */
2604 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2605 if (btnInfo == NULL)
2607 FIXME("btnInfo invalid!\n");
2608 return TRUE;
2611 /* set colors and select objects */
2612 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2613 if (btnInfo->bVirtual)
2614 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2615 else
2616 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2617 hPen = CreatePen( PS_SOLID, 1,
2618 (lpdis->itemState & ODS_SELECTED)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2619 hOldPen = SelectObject (lpdis->hDC, hPen );
2620 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2622 /* fill background rectangle */
2623 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2624 lpdis->rcItem.right, lpdis->rcItem.bottom);
2626 /* calculate button and text rectangles */
2627 CopyRect (&rcButton, &lpdis->rcItem);
2628 InflateRect (&rcButton, -1, -1);
2629 CopyRect (&rcText, &rcButton);
2630 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2631 rcText.left = rcButton.right + 2;
2633 /* draw focus rectangle */
2634 if (lpdis->itemState & ODS_FOCUS)
2635 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2637 /* draw button */
2638 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2639 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2641 /* draw image and text */
2642 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2643 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2644 btnInfo->btn.iBitmap));
2645 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2646 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2648 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2649 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2651 /* delete objects and reset colors */
2652 SelectObject (lpdis->hDC, hOldBrush);
2653 SelectObject (lpdis->hDC, hOldPen);
2654 SetBkColor (lpdis->hDC, oldBk);
2655 SetTextColor (lpdis->hDC, oldText);
2656 DeleteObject( hPen );
2657 return TRUE;
2659 return FALSE;
2661 case WM_MEASUREITEM:
2662 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2664 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2666 lpmis->itemHeight = 15 + 8; /* default height */
2668 return TRUE;
2670 return FALSE;
2672 default:
2673 if (uDragListMessage && (uMsg == uDragListMessage))
2675 if (wParam == IDC_TOOLBARBTN_LBOX)
2677 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2678 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2679 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2680 return TRUE;
2682 else if (wParam == IDC_AVAILBTN_LBOX)
2684 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2685 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2686 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2687 return TRUE;
2690 return FALSE;
2694 static BOOL
2695 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2697 HBITMAP hbmLoad;
2698 INT nCountBefore = ImageList_GetImageCount(himlDef);
2699 INT nCountAfter;
2700 INT cxIcon, cyIcon;
2701 INT nAdded;
2702 INT nIndex;
2704 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2705 /* Add bitmaps to the default image list */
2706 if (bitmap->hInst == NULL) /* a handle was passed */
2707 hbmLoad = CopyImage(ULongToHandle(bitmap->nID), IMAGE_BITMAP, 0, 0, 0);
2708 else
2709 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2711 /* enlarge the bitmap if needed */
2712 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2713 if (bitmap->hInst != COMCTL32_hModule)
2714 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2716 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2717 DeleteObject(hbmLoad);
2718 if (nIndex == -1)
2719 return FALSE;
2721 nCountAfter = ImageList_GetImageCount(himlDef);
2722 nAdded = nCountAfter - nCountBefore;
2723 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2725 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2726 } else if (nAdded > (INT)bitmap->nButtons) {
2727 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2728 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2731 infoPtr->nNumBitmaps += nAdded;
2732 return TRUE;
2735 static void
2736 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2738 HIMAGELIST himlDef;
2739 HIMAGELIST himlNew;
2740 INT cx, cy;
2741 INT i;
2743 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2744 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2745 return;
2746 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2747 return;
2748 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2749 return;
2751 TRACE("Update icon size: %dx%d -> %dx%d\n",
2752 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2754 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2755 ILC_COLORDDB|ILC_MASK, 8, 2);
2756 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2757 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2758 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2759 infoPtr->himlInt = himlNew;
2761 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2762 ImageList_Destroy(himlDef);
2765 /***********************************************************************
2766 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2769 static LRESULT
2770 TOOLBAR_AddBitmap (TOOLBAR_INFO *infoPtr, INT count, const TBADDBITMAP *lpAddBmp)
2772 TBITMAP_INFO info;
2773 INT iSumButtons, i;
2774 HIMAGELIST himlDef;
2776 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr->hwndSelf, count, lpAddBmp);
2777 if (!lpAddBmp)
2778 return -1;
2780 if (lpAddBmp->hInst == HINST_COMMCTRL)
2782 info.hInst = COMCTL32_hModule;
2783 switch (lpAddBmp->nID)
2785 case IDB_STD_SMALL_COLOR:
2786 info.nButtons = 15;
2787 info.nID = IDB_STD_SMALL;
2788 break;
2789 case IDB_STD_LARGE_COLOR:
2790 info.nButtons = 15;
2791 info.nID = IDB_STD_LARGE;
2792 break;
2793 case IDB_VIEW_SMALL_COLOR:
2794 info.nButtons = 12;
2795 info.nID = IDB_VIEW_SMALL;
2796 break;
2797 case IDB_VIEW_LARGE_COLOR:
2798 info.nButtons = 12;
2799 info.nID = IDB_VIEW_LARGE;
2800 break;
2801 case IDB_HIST_SMALL_COLOR:
2802 info.nButtons = 5;
2803 info.nID = IDB_HIST_SMALL;
2804 break;
2805 case IDB_HIST_LARGE_COLOR:
2806 info.nButtons = 5;
2807 info.nID = IDB_HIST_LARGE;
2808 break;
2809 default:
2810 return -1;
2813 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2815 /* Windows resize all the buttons to the size of a newly added standard image */
2816 if (lpAddBmp->nID & 1)
2818 /* large icons: 24x24. Will make the button 31x30 */
2819 SendMessageW (infoPtr->hwndSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
2821 else
2823 /* small icons: 16x16. Will make the buttons 23x22 */
2824 SendMessageW (infoPtr->hwndSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
2827 TOOLBAR_CalcToolbar (infoPtr);
2829 else
2831 info.nButtons = count;
2832 info.hInst = lpAddBmp->hInst;
2833 info.nID = lpAddBmp->nID;
2834 TRACE("adding %d bitmaps!\n", info.nButtons);
2837 /* check if the bitmap is already loaded and compute iSumButtons */
2838 iSumButtons = 0;
2839 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2841 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2842 infoPtr->bitmaps[i].nID == info.nID)
2843 return iSumButtons;
2844 iSumButtons += infoPtr->bitmaps[i].nButtons;
2847 if (!infoPtr->cimlDef) {
2848 /* create new default image list */
2849 TRACE ("creating default image list!\n");
2851 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2852 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2853 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2854 infoPtr->himlInt = himlDef;
2856 else {
2857 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2860 if (!himlDef) {
2861 WARN("No default image list available\n");
2862 return -1;
2865 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2866 return -1;
2868 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2869 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2870 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2871 infoPtr->nNumBitmapInfos++;
2872 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2874 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2875 return iSumButtons;
2879 static LRESULT
2880 TOOLBAR_AddButtonsT(TOOLBAR_INFO *infoPtr, INT nAddButtons, const TBBUTTON* lpTbb, BOOL fUnicode)
2882 TRACE("adding %d buttons (unicode=%d)!\n", nAddButtons, fUnicode);
2884 return TOOLBAR_InternalInsertButtonsT(infoPtr, -1, nAddButtons, lpTbb, fUnicode);
2888 static LRESULT
2889 TOOLBAR_AddStringW (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
2891 #define MAX_RESOURCE_STRING_LENGTH 512
2892 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2893 INT nIndex = infoPtr->nNumStrings;
2895 if (hInstance && (HIWORD(lParam) == 0)) {
2896 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2897 WCHAR delimiter;
2898 WCHAR *next_delim;
2899 WCHAR *p;
2900 INT len;
2901 TRACE("adding string from resource!\n");
2903 len = LoadStringW (hInstance, (UINT)lParam,
2904 szString, MAX_RESOURCE_STRING_LENGTH);
2906 TRACE("len=%d %s\n", len, debugstr_w(szString));
2907 if (len == 0 || len == 1)
2908 return nIndex;
2910 TRACE("Delimiter: 0x%x\n", *szString);
2911 delimiter = *szString;
2912 p = szString + 1;
2914 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2915 *next_delim = 0;
2916 if (next_delim + 1 >= szString + len)
2918 /* this may happen if delimiter == '\0' or if the last char is a
2919 * delimiter (then it is ignored like the native does) */
2920 break;
2923 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2924 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2925 infoPtr->nNumStrings++;
2927 p = next_delim + 1;
2930 else {
2931 LPWSTR p = (LPWSTR)lParam;
2932 INT len;
2934 if (p == NULL)
2935 return -1;
2936 TRACE("adding string(s) from array!\n");
2937 while (*p) {
2938 len = strlenW (p);
2940 TRACE("len=%d %s\n", len, debugstr_w(p));
2941 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2942 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2943 infoPtr->nNumStrings++;
2945 p += (len+1);
2949 if (fFirstString)
2950 TOOLBAR_CalcToolbar(infoPtr);
2951 return nIndex;
2955 static LRESULT
2956 TOOLBAR_AddStringA (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
2958 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2959 LPSTR p;
2960 INT nIndex;
2961 INT len;
2963 if (hInstance && (HIWORD(lParam) == 0)) /* load from resources */
2964 return TOOLBAR_AddStringW(infoPtr, hInstance, lParam);
2966 p = (LPSTR)lParam;
2967 if (p == NULL)
2968 return -1;
2970 TRACE("adding string(s) from array!\n");
2971 nIndex = infoPtr->nNumStrings;
2972 while (*p) {
2973 len = strlen (p);
2974 TRACE("len=%d \"%s\"\n", len, p);
2976 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2977 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
2978 infoPtr->nNumStrings++;
2980 p += (len+1);
2983 if (fFirstString)
2984 TOOLBAR_CalcToolbar(infoPtr);
2985 return nIndex;
2989 static LRESULT
2990 TOOLBAR_AutoSize (TOOLBAR_INFO *infoPtr)
2992 RECT parent_rect;
2993 HWND parent;
2994 INT x, y;
2995 INT cx, cy;
2997 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
2999 parent = GetParent (infoPtr->hwndSelf);
3001 if (!parent || !infoPtr->bDoRedraw)
3002 return 0;
3004 GetClientRect(parent, &parent_rect);
3006 x = parent_rect.left;
3007 y = parent_rect.top;
3009 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3011 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3012 cx = parent_rect.right - parent_rect.left;
3014 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3016 TOOLBAR_LayoutToolbar(infoPtr);
3017 InvalidateRect( infoPtr->hwndSelf, NULL, TRUE );
3020 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3022 RECT window_rect;
3023 UINT uPosFlags = SWP_NOZORDER;
3025 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3027 GetWindowRect(infoPtr->hwndSelf, &window_rect);
3028 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3029 y = window_rect.top;
3031 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3033 GetWindowRect(infoPtr->hwndSelf, &window_rect);
3034 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3037 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3038 uPosFlags |= SWP_NOMOVE;
3040 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3041 cy += GetSystemMetrics(SM_CYEDGE);
3043 if (infoPtr->dwStyle & WS_BORDER)
3045 x = y = 1; /* FIXME: this looks wrong */
3046 cy += GetSystemMetrics(SM_CYEDGE);
3047 cx += GetSystemMetrics(SM_CXEDGE);
3050 SetWindowPos(infoPtr->hwndSelf, NULL, x, y, cx, cy, uPosFlags);
3053 return 0;
3057 static inline LRESULT
3058 TOOLBAR_ButtonCount (const TOOLBAR_INFO *infoPtr)
3060 return infoPtr->nNumButtons;
3064 static inline LRESULT
3065 TOOLBAR_ButtonStructSize (TOOLBAR_INFO *infoPtr, DWORD Size)
3067 infoPtr->dwStructSize = Size;
3069 return 0;
3073 static LRESULT
3074 TOOLBAR_ChangeBitmap (TOOLBAR_INFO *infoPtr, INT Id, INT Index)
3076 TBUTTON_INFO *btnPtr;
3077 INT nIndex;
3079 TRACE("button %d, iBitmap now %d\n", Id, Index);
3081 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3082 if (nIndex == -1)
3083 return FALSE;
3085 btnPtr = &infoPtr->buttons[nIndex];
3086 btnPtr->iBitmap = Index;
3088 /* we HAVE to erase the background, the new bitmap could be */
3089 /* transparent */
3090 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3092 return TRUE;
3096 static LRESULT
3097 TOOLBAR_CheckButton (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
3099 TBUTTON_INFO *btnPtr;
3100 INT nIndex;
3101 INT nOldIndex = -1;
3102 BOOL bChecked = FALSE;
3104 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3106 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", infoPtr->hwndSelf, nIndex, lParam);
3108 if (nIndex == -1)
3109 return FALSE;
3111 btnPtr = &infoPtr->buttons[nIndex];
3113 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3115 if (LOWORD(lParam) == FALSE)
3116 btnPtr->fsState &= ~TBSTATE_CHECKED;
3117 else {
3118 if (btnPtr->fsStyle & BTNS_GROUP) {
3119 nOldIndex =
3120 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3121 if (nOldIndex == nIndex)
3122 return 0;
3123 if (nOldIndex != -1)
3124 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3126 btnPtr->fsState |= TBSTATE_CHECKED;
3129 if( bChecked != LOWORD(lParam) )
3131 if (nOldIndex != -1)
3132 InvalidateRect(infoPtr->hwndSelf, &infoPtr->buttons[nOldIndex].rect, TRUE);
3133 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3136 /* FIXME: Send a WM_NOTIFY?? */
3138 return TRUE;
3142 static LRESULT
3143 TOOLBAR_CommandToIndex (const TOOLBAR_INFO *infoPtr, INT Id)
3145 return TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3149 static LRESULT
3150 TOOLBAR_Customize (TOOLBAR_INFO *infoPtr)
3152 CUSTDLG_INFO custInfo;
3153 LRESULT ret;
3154 LPCVOID template;
3155 HRSRC hRes;
3156 NMHDR nmhdr;
3158 custInfo.tbInfo = infoPtr;
3159 custInfo.tbHwnd = infoPtr->hwndSelf;
3161 /* send TBN_BEGINADJUST notification */
3162 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3164 if (!(hRes = FindResourceW (COMCTL32_hModule,
3165 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3166 (LPWSTR)RT_DIALOG)))
3167 return FALSE;
3169 if(!(template = LoadResource (COMCTL32_hModule, hRes)))
3170 return FALSE;
3172 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_HINSTANCE),
3173 template, infoPtr->hwndSelf, TOOLBAR_CustomizeDialogProc,
3174 (LPARAM)&custInfo);
3176 /* send TBN_ENDADJUST notification */
3177 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3179 return ret;
3183 static LRESULT
3184 TOOLBAR_DeleteButton (TOOLBAR_INFO *infoPtr, INT nIndex)
3186 NMTOOLBARW nmtb;
3187 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3189 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3190 return FALSE;
3192 memset(&nmtb, 0, sizeof(nmtb));
3193 nmtb.iItem = btnPtr->idCommand;
3194 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3195 nmtb.tbButton.idCommand = btnPtr->idCommand;
3196 nmtb.tbButton.fsState = btnPtr->fsState;
3197 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3198 nmtb.tbButton.dwData = btnPtr->dwData;
3199 nmtb.tbButton.iString = btnPtr->iString;
3200 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3202 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3204 if (infoPtr->nNumButtons == 1) {
3205 TRACE(" simple delete!\n");
3206 Free (infoPtr->buttons);
3207 infoPtr->buttons = NULL;
3208 infoPtr->nNumButtons = 0;
3210 else {
3211 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3212 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3214 infoPtr->nNumButtons--;
3215 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3216 if (nIndex > 0) {
3217 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3218 nIndex * sizeof(TBUTTON_INFO));
3221 if (nIndex < infoPtr->nNumButtons) {
3222 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3223 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3226 Free (oldButtons);
3229 TOOLBAR_LayoutToolbar(infoPtr);
3231 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3233 return TRUE;
3237 static LRESULT
3238 TOOLBAR_EnableButton (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
3240 TBUTTON_INFO *btnPtr;
3241 INT nIndex;
3242 DWORD bState;
3244 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3246 TRACE("hwnd=%p, btn id=%d, lParam=0x%08lx\n", infoPtr->hwndSelf, Id, lParam);
3248 if (nIndex == -1)
3249 return FALSE;
3251 btnPtr = &infoPtr->buttons[nIndex];
3253 bState = btnPtr->fsState & TBSTATE_ENABLED;
3255 /* update the toolbar button state */
3256 if(LOWORD(lParam) == FALSE) {
3257 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3258 } else {
3259 btnPtr->fsState |= TBSTATE_ENABLED;
3262 /* redraw the button only if the state of the button changed */
3263 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3264 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3266 return TRUE;
3270 static inline LRESULT
3271 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO *infoPtr)
3273 return infoPtr->bAnchor;
3277 static LRESULT
3278 TOOLBAR_GetBitmap (const TOOLBAR_INFO *infoPtr, INT Id)
3280 INT nIndex;
3282 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3283 if (nIndex == -1)
3284 return -1;
3286 return infoPtr->buttons[nIndex].iBitmap;
3290 static inline LRESULT
3291 TOOLBAR_GetBitmapFlags (void)
3293 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3297 static LRESULT
3298 TOOLBAR_GetButton (const TOOLBAR_INFO *infoPtr, INT nIndex, TBBUTTON *lpTbb)
3300 TBUTTON_INFO *btnPtr;
3302 if (lpTbb == NULL)
3303 return FALSE;
3305 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3306 return FALSE;
3308 btnPtr = &infoPtr->buttons[nIndex];
3309 lpTbb->iBitmap = btnPtr->iBitmap;
3310 lpTbb->idCommand = btnPtr->idCommand;
3311 lpTbb->fsState = btnPtr->fsState;
3312 lpTbb->fsStyle = btnPtr->fsStyle;
3313 lpTbb->bReserved[0] = 0;
3314 lpTbb->bReserved[1] = 0;
3315 lpTbb->dwData = btnPtr->dwData;
3316 lpTbb->iString = btnPtr->iString;
3318 return TRUE;
3322 static LRESULT
3323 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO *infoPtr, INT Id, LPTBBUTTONINFOW lpTbInfo, BOOL bUnicode)
3325 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3326 TBUTTON_INFO *btnPtr;
3327 INT nIndex;
3329 if (lpTbInfo == NULL)
3330 return -1;
3332 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3333 * the headers and tests shows that even with comctl 6 Vista accepts only the
3334 * original TBBUTTONINFO size
3336 if (lpTbInfo->cbSize != sizeof(TBBUTTONINFOW))
3338 WARN("Invalid button size\n");
3339 return -1;
3342 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, lpTbInfo->dwMask & TBIF_BYINDEX);
3343 if (nIndex == -1)
3344 return -1;
3346 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3348 if (lpTbInfo->dwMask & TBIF_COMMAND)
3349 lpTbInfo->idCommand = btnPtr->idCommand;
3350 if (lpTbInfo->dwMask & TBIF_IMAGE)
3351 lpTbInfo->iImage = btnPtr->iBitmap;
3352 if (lpTbInfo->dwMask & TBIF_LPARAM)
3353 lpTbInfo->lParam = btnPtr->dwData;
3354 if (lpTbInfo->dwMask & TBIF_SIZE)
3355 /* tests show that for separators TBIF_SIZE returns not calculated width,
3356 but cx property, that differs from 0 only if application have
3357 specifically set it */
3358 lpTbInfo->cx = (btnPtr->fsStyle & BTNS_SEP)
3359 ? btnPtr->cx : (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3360 if (lpTbInfo->dwMask & TBIF_STATE)
3361 lpTbInfo->fsState = btnPtr->fsState;
3362 if (lpTbInfo->dwMask & TBIF_STYLE)
3363 lpTbInfo->fsStyle = btnPtr->fsStyle;
3364 if (lpTbInfo->dwMask & TBIF_TEXT) {
3365 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3366 can't use TOOLBAR_GetText here */
3367 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3368 LPWSTR lpText = (LPWSTR)btnPtr->iString;
3369 if (bUnicode)
3370 Str_GetPtrW(lpText, lpTbInfo->pszText, lpTbInfo->cchText);
3371 else
3372 Str_GetPtrWtoA(lpText, (LPSTR)lpTbInfo->pszText, lpTbInfo->cchText);
3373 } else
3374 lpTbInfo->pszText[0] = '\0';
3376 return nIndex;
3380 static inline LRESULT
3381 TOOLBAR_GetButtonSize (const TOOLBAR_INFO *infoPtr)
3383 return MAKELONG((WORD)infoPtr->nButtonWidth,
3384 (WORD)infoPtr->nButtonHeight);
3388 static LRESULT
3389 TOOLBAR_GetButtonTextA (const TOOLBAR_INFO *infoPtr, INT Id, LPSTR lpText)
3391 INT nIndex;
3392 LPWSTR lpTextW;
3394 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3395 if (nIndex == -1)
3396 return -1;
3398 lpTextW = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3400 return WideCharToMultiByte( CP_ACP, 0, lpTextW, -1,
3401 lpText, lpText ? 0x7fffffff : 0, NULL, NULL ) - 1;
3405 static LRESULT
3406 TOOLBAR_GetButtonTextW (const TOOLBAR_INFO *infoPtr, INT Id, LPWSTR lpStr)
3408 INT nIndex;
3409 LPWSTR lpText;
3410 LRESULT ret = 0;
3412 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3413 if (nIndex == -1)
3414 return -1;
3416 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3418 if (lpText)
3420 ret = strlenW (lpText);
3422 if (lpStr)
3423 strcpyW (lpStr, lpText);
3426 return ret;
3430 static LRESULT
3431 TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO *infoPtr, WPARAM wParam)
3433 TRACE("hwnd=%p, wParam=%ld\n", infoPtr->hwndSelf, wParam);
3434 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3435 return (LRESULT)GETDISIMAGELIST(infoPtr, wParam);
3439 static inline LRESULT
3440 TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO *infoPtr)
3442 TRACE("\n");
3444 return infoPtr->dwExStyle;
3448 static LRESULT
3449 TOOLBAR_GetHotImageList (const TOOLBAR_INFO *infoPtr, WPARAM wParam)
3451 TRACE("hwnd=%p, wParam=%ld\n", infoPtr->hwndSelf, wParam);
3452 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3453 return (LRESULT)GETHOTIMAGELIST(infoPtr, wParam);
3457 static LRESULT
3458 TOOLBAR_GetHotItem (const TOOLBAR_INFO *infoPtr)
3460 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3461 return -1;
3463 if (infoPtr->nHotItem < 0)
3464 return -1;
3466 return (LRESULT)infoPtr->nHotItem;
3470 static LRESULT
3471 TOOLBAR_GetDefImageList (const TOOLBAR_INFO *infoPtr, WPARAM wParam)
3473 TRACE("hwnd=%p, wParam=%ld\n", infoPtr->hwndSelf, wParam);
3474 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3475 return (LRESULT) GETDEFIMAGELIST(infoPtr, wParam);
3479 static LRESULT
3480 TOOLBAR_GetInsertMark (const TOOLBAR_INFO *infoPtr, TBINSERTMARK *lptbim)
3482 TRACE("hwnd = %p, lptbim = %p\n", infoPtr->hwndSelf, lptbim);
3484 *lptbim = infoPtr->tbim;
3486 return 0;
3490 static inline LRESULT
3491 TOOLBAR_GetInsertMarkColor (const TOOLBAR_INFO *infoPtr)
3493 TRACE("hwnd = %p\n", infoPtr->hwndSelf);
3495 return (LRESULT)infoPtr->clrInsertMark;
3499 static LRESULT
3500 TOOLBAR_GetItemRect (const TOOLBAR_INFO *infoPtr, INT nIndex, LPRECT lpRect)
3502 TBUTTON_INFO *btnPtr;
3504 btnPtr = &infoPtr->buttons[nIndex];
3505 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3506 return FALSE;
3508 if (lpRect == NULL)
3509 return FALSE;
3510 if (btnPtr->fsState & TBSTATE_HIDDEN)
3511 return FALSE;
3513 lpRect->left = btnPtr->rect.left;
3514 lpRect->right = btnPtr->rect.right;
3515 lpRect->bottom = btnPtr->rect.bottom;
3516 lpRect->top = btnPtr->rect.top;
3518 return TRUE;
3522 static LRESULT
3523 TOOLBAR_GetMaxSize (const TOOLBAR_INFO *infoPtr, LPSIZE lpSize)
3525 if (lpSize == NULL)
3526 return FALSE;
3528 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3529 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3531 TRACE("maximum size %d x %d\n",
3532 infoPtr->rcBound.right - infoPtr->rcBound.left,
3533 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3535 return TRUE;
3539 /* << TOOLBAR_GetObject >> */
3542 static inline LRESULT
3543 TOOLBAR_GetPadding (const TOOLBAR_INFO *infoPtr)
3545 return MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3549 static LRESULT
3550 TOOLBAR_GetRect (const TOOLBAR_INFO *infoPtr, INT Id, LPRECT lpRect)
3552 TBUTTON_INFO *btnPtr;
3553 INT nIndex;
3555 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3556 btnPtr = &infoPtr->buttons[nIndex];
3557 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3558 return FALSE;
3560 if (lpRect == NULL)
3561 return FALSE;
3563 lpRect->left = btnPtr->rect.left;
3564 lpRect->right = btnPtr->rect.right;
3565 lpRect->bottom = btnPtr->rect.bottom;
3566 lpRect->top = btnPtr->rect.top;
3568 return TRUE;
3572 static inline LRESULT
3573 TOOLBAR_GetRows (const TOOLBAR_INFO *infoPtr)
3575 return infoPtr->nRows;
3579 static LRESULT
3580 TOOLBAR_GetState (const TOOLBAR_INFO *infoPtr, INT Id)
3582 INT nIndex;
3584 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3585 if (nIndex == -1)
3586 return -1;
3588 return infoPtr->buttons[nIndex].fsState;
3592 static inline LRESULT
3593 TOOLBAR_GetStyle (const TOOLBAR_INFO *infoPtr)
3595 return infoPtr->dwStyle;
3599 static inline LRESULT
3600 TOOLBAR_GetTextRows (const TOOLBAR_INFO *infoPtr)
3602 return infoPtr->nMaxTextRows;
3606 static LRESULT
3607 TOOLBAR_GetToolTips (TOOLBAR_INFO *infoPtr)
3609 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3610 TOOLBAR_TooltipCreateControl(infoPtr);
3611 return (LRESULT)infoPtr->hwndToolTip;
3615 static LRESULT
3616 TOOLBAR_GetUnicodeFormat (const TOOLBAR_INFO *infoPtr)
3618 TRACE("%s hwnd=%p\n",
3619 infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
3621 return infoPtr->bUnicode;
3625 static inline LRESULT
3626 TOOLBAR_GetVersion (const TOOLBAR_INFO *infoPtr)
3628 return infoPtr->iVersion;
3632 static LRESULT
3633 TOOLBAR_HideButton (TOOLBAR_INFO *infoPtr, INT Id, BOOL fHide)
3635 TBUTTON_INFO *btnPtr;
3636 INT nIndex;
3638 TRACE("\n");
3640 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3641 if (nIndex == -1)
3642 return FALSE;
3644 btnPtr = &infoPtr->buttons[nIndex];
3646 if (fHide)
3647 btnPtr->fsState |= TBSTATE_HIDDEN;
3648 else
3649 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3651 TOOLBAR_LayoutToolbar (infoPtr);
3653 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3655 return TRUE;
3659 static inline LRESULT
3660 TOOLBAR_HitTest (const TOOLBAR_INFO *infoPtr, const POINT* lpPt)
3662 return TOOLBAR_InternalHitTest (infoPtr, lpPt);
3666 static LRESULT
3667 TOOLBAR_Indeterminate (const TOOLBAR_INFO *infoPtr, INT Id, BOOL fIndeterminate)
3669 TBUTTON_INFO *btnPtr;
3670 INT nIndex;
3671 DWORD oldState;
3673 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3674 if (nIndex == -1)
3675 return FALSE;
3677 btnPtr = &infoPtr->buttons[nIndex];
3678 oldState = btnPtr->fsState;
3680 if (fIndeterminate)
3681 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3682 else
3683 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3685 if(oldState != btnPtr->fsState)
3686 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3688 return TRUE;
3692 static LRESULT
3693 TOOLBAR_InsertButtonT(TOOLBAR_INFO *infoPtr, INT nIndex, const TBBUTTON *lpTbb, BOOL fUnicode)
3695 if (lpTbb == NULL)
3696 return FALSE;
3698 if (nIndex == -1) {
3699 /* EPP: this seems to be an undocumented call (from my IE4)
3700 * I assume in that case that:
3701 * - index of insertion is at the end of existing buttons
3702 * I only see this happen with nIndex == -1, but it could have a special
3703 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3705 nIndex = infoPtr->nNumButtons;
3707 } else if (nIndex < 0)
3708 return FALSE;
3710 TRACE("inserting button index=%d\n", nIndex);
3711 if (nIndex > infoPtr->nNumButtons) {
3712 nIndex = infoPtr->nNumButtons;
3713 TRACE("adjust index=%d\n", nIndex);
3716 return TOOLBAR_InternalInsertButtonsT(infoPtr, nIndex, 1, lpTbb, fUnicode);
3719 /* << TOOLBAR_InsertMarkHitTest >> */
3722 static LRESULT
3723 TOOLBAR_IsButtonChecked (const TOOLBAR_INFO *infoPtr, INT Id)
3725 INT nIndex;
3727 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3728 if (nIndex == -1)
3729 return -1;
3731 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3735 static LRESULT
3736 TOOLBAR_IsButtonEnabled (const TOOLBAR_INFO *infoPtr, INT Id)
3738 INT nIndex;
3740 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3741 if (nIndex == -1)
3742 return -1;
3744 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3748 static LRESULT
3749 TOOLBAR_IsButtonHidden (const TOOLBAR_INFO *infoPtr, INT Id)
3751 INT nIndex;
3753 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3754 if (nIndex == -1)
3755 return -1;
3757 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3761 static LRESULT
3762 TOOLBAR_IsButtonHighlighted (const TOOLBAR_INFO *infoPtr, INT Id)
3764 INT nIndex;
3766 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3767 if (nIndex == -1)
3768 return -1;
3770 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3774 static LRESULT
3775 TOOLBAR_IsButtonIndeterminate (const TOOLBAR_INFO *infoPtr, INT Id)
3777 INT nIndex;
3779 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3780 if (nIndex == -1)
3781 return -1;
3783 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3787 static LRESULT
3788 TOOLBAR_IsButtonPressed (const TOOLBAR_INFO *infoPtr, INT Id)
3790 INT nIndex;
3792 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3793 if (nIndex == -1)
3794 return -1;
3796 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3800 static LRESULT
3801 TOOLBAR_LoadImages (TOOLBAR_INFO *infoPtr, WPARAM wParam, HINSTANCE hInstance)
3803 TBADDBITMAP tbab;
3804 tbab.hInst = hInstance;
3805 tbab.nID = wParam;
3807 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", infoPtr->hwndSelf, tbab.hInst, tbab.nID);
3809 return TOOLBAR_AddBitmap(infoPtr, 0, &tbab);
3813 static LRESULT
3814 TOOLBAR_MapAccelerator (const TOOLBAR_INFO *infoPtr, WCHAR wAccel, UINT *pIDButton)
3816 WCHAR wszAccel[] = {'&',wAccel,0};
3817 int i;
3819 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3820 infoPtr->hwndSelf, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3822 for (i = 0; i < infoPtr->nNumButtons; i++)
3824 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3825 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3826 !(btnPtr->fsState & TBSTATE_HIDDEN))
3828 int iLen = strlenW(wszAccel);
3829 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3831 if (!lpszStr)
3832 continue;
3834 while (*lpszStr)
3836 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3838 lpszStr += 2;
3839 continue;
3841 if (!strncmpiW(lpszStr, wszAccel, iLen))
3843 *pIDButton = btnPtr->idCommand;
3844 return TRUE;
3846 lpszStr++;
3850 return FALSE;
3854 static LRESULT
3855 TOOLBAR_MarkButton (const TOOLBAR_INFO *infoPtr, INT Id, BOOL fMark)
3857 INT nIndex;
3858 DWORD oldState;
3859 TBUTTON_INFO *btnPtr;
3861 TRACE("hwnd = %p, Id = %d, fMark = 0%d\n", infoPtr->hwndSelf, Id, fMark);
3863 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3864 if (nIndex == -1)
3865 return FALSE;
3867 btnPtr = &infoPtr->buttons[nIndex];
3868 oldState = btnPtr->fsState;
3870 if (fMark)
3871 btnPtr->fsState |= TBSTATE_MARKED;
3872 else
3873 btnPtr->fsState &= ~TBSTATE_MARKED;
3875 if(oldState != btnPtr->fsState)
3876 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3878 return TRUE;
3882 /* fixes up an index of a button affected by a move */
3883 static inline void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
3885 if (bMoveUp)
3887 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
3888 (*pIndex)--;
3889 else if (*pIndex == nIndex)
3890 *pIndex = nMoveIndex;
3892 else
3894 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
3895 (*pIndex)++;
3896 else if (*pIndex == nIndex)
3897 *pIndex = nMoveIndex;
3902 static LRESULT
3903 TOOLBAR_MoveButton (TOOLBAR_INFO *infoPtr, INT Id, INT nMoveIndex)
3905 INT nIndex;
3906 INT nCount;
3907 TBUTTON_INFO button;
3909 TRACE("hwnd=%p, Id=%d, nMoveIndex=%d\n", infoPtr->hwndSelf, Id, nMoveIndex);
3911 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, TRUE);
3912 if ((nIndex == -1) || (nMoveIndex < 0))
3913 return FALSE;
3915 if (nMoveIndex > infoPtr->nNumButtons - 1)
3916 nMoveIndex = infoPtr->nNumButtons - 1;
3918 button = infoPtr->buttons[nIndex];
3920 /* move button right */
3921 if (nIndex < nMoveIndex)
3923 nCount = nMoveIndex - nIndex;
3924 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
3925 infoPtr->buttons[nMoveIndex] = button;
3927 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
3928 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
3929 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
3930 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
3932 else if (nIndex > nMoveIndex) /* move button left */
3934 nCount = nIndex - nMoveIndex;
3935 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
3936 infoPtr->buttons[nMoveIndex] = button;
3938 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
3939 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
3940 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
3941 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
3944 TOOLBAR_LayoutToolbar(infoPtr);
3945 TOOLBAR_AutoSize(infoPtr);
3946 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3948 return TRUE;
3952 static LRESULT
3953 TOOLBAR_PressButton (const TOOLBAR_INFO *infoPtr, INT Id, BOOL fPress)
3955 TBUTTON_INFO *btnPtr;
3956 INT nIndex;
3957 DWORD oldState;
3959 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3960 if (nIndex == -1)
3961 return FALSE;
3963 btnPtr = &infoPtr->buttons[nIndex];
3964 oldState = btnPtr->fsState;
3966 if (fPress)
3967 btnPtr->fsState |= TBSTATE_PRESSED;
3968 else
3969 btnPtr->fsState &= ~TBSTATE_PRESSED;
3971 if(oldState != btnPtr->fsState)
3972 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3974 return TRUE;
3977 /* FIXME: there might still be some confusion her between number of buttons
3978 * and number of bitmaps */
3979 static LRESULT
3980 TOOLBAR_ReplaceBitmap (TOOLBAR_INFO *infoPtr, const TBREPLACEBITMAP *lpReplace)
3982 HBITMAP hBitmap;
3983 int i = 0, nOldButtons = 0, pos = 0;
3984 int nOldBitmaps, nNewBitmaps = 0;
3985 HIMAGELIST himlDef = 0;
3987 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
3988 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
3989 lpReplace->nButtons);
3991 if (lpReplace->hInstOld == HINST_COMMCTRL)
3993 FIXME("changing standard bitmaps not implemented\n");
3994 return FALSE;
3996 else if (lpReplace->hInstOld != 0)
3997 FIXME("resources not in the current module not implemented\n");
3999 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4000 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4001 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4002 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4003 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4005 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4006 nOldButtons = tbi->nButtons;
4007 tbi->nButtons = lpReplace->nButtons;
4008 tbi->hInst = lpReplace->hInstNew;
4009 tbi->nID = lpReplace->nIDNew;
4010 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4011 break;
4013 pos += tbi->nButtons;
4016 if (nOldButtons == 0)
4018 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4019 return FALSE;
4022 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4023 * bitmap
4025 if (lpReplace->hInstNew)
4026 hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4027 else
4028 hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
4030 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4031 nOldBitmaps = ImageList_GetImageCount(himlDef);
4033 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4035 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4036 ImageList_Remove(himlDef, i);
4038 if (hBitmap)
4040 ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
4041 nNewBitmaps = ImageList_GetImageCount(himlDef);
4042 DeleteObject(hBitmap);
4045 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4047 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4048 pos, nOldBitmaps, nNewBitmaps);
4050 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4051 return TRUE;
4055 /* helper for TOOLBAR_SaveRestoreW */
4056 static BOOL
4057 TOOLBAR_Save(const TBSAVEPARAMSW *lpSave)
4059 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4060 debugstr_w(lpSave->pszValueName));
4062 return FALSE;
4066 /* helper for TOOLBAR_Restore */
4067 static void
4068 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4070 INT i;
4072 for (i = 0; i < infoPtr->nNumButtons; i++)
4074 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4077 Free(infoPtr->buttons);
4078 infoPtr->buttons = NULL;
4079 infoPtr->nNumButtons = 0;
4083 /* helper for TOOLBAR_SaveRestoreW */
4084 static BOOL
4085 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
4087 LONG res;
4088 HKEY hkey = NULL;
4089 BOOL ret = FALSE;
4090 DWORD dwType;
4091 DWORD dwSize = 0;
4092 NMTBRESTORE nmtbr;
4094 /* restore toolbar information */
4095 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4096 debugstr_w(lpSave->pszValueName));
4098 memset(&nmtbr, 0, sizeof(nmtbr));
4100 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4101 KEY_QUERY_VALUE, &hkey);
4102 if (!res)
4103 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4104 NULL, &dwSize);
4105 if (!res && dwType != REG_BINARY)
4106 res = ERROR_FILE_NOT_FOUND;
4107 if (!res)
4109 nmtbr.pData = Alloc(dwSize);
4110 nmtbr.cbData = dwSize;
4111 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4113 if (!res)
4114 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4115 (LPBYTE)nmtbr.pData, &dwSize);
4116 if (!res)
4118 nmtbr.pCurrent = nmtbr.pData;
4119 nmtbr.iItem = -1;
4120 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4121 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4123 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4125 INT i;
4127 /* remove all existing buttons as this function is designed to
4128 * restore the toolbar to a previously saved state */
4129 TOOLBAR_DeleteAllButtons(infoPtr);
4131 for (i = 0; i < nmtbr.cButtons; i++)
4133 nmtbr.iItem = i;
4134 nmtbr.tbButton.iBitmap = -1;
4135 nmtbr.tbButton.fsState = 0;
4136 nmtbr.tbButton.fsStyle = 0;
4137 nmtbr.tbButton.idCommand = 0;
4138 if (*nmtbr.pCurrent == (DWORD)-1)
4140 /* separator */
4141 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4142 /* when inserting separators, iBitmap controls it's size.
4143 0 sets default size (width) */
4144 nmtbr.tbButton.iBitmap = 0;
4146 else if (*nmtbr.pCurrent == (DWORD)-2)
4147 /* hidden button */
4148 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4149 else
4150 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4152 nmtbr.pCurrent++;
4154 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4156 /* can't contain real string as we don't know whether
4157 * the client put an ANSI or Unicode string in there */
4158 if (HIWORD(nmtbr.tbButton.iString))
4159 nmtbr.tbButton.iString = 0;
4161 TOOLBAR_InsertButtonT(infoPtr, -1, &nmtbr.tbButton, TRUE);
4164 /* do legacy notifications */
4165 if (infoPtr->iVersion < 5)
4167 /* FIXME: send TBN_BEGINADJUST */
4168 FIXME("send TBN_GETBUTTONINFO for each button\n");
4169 /* FIXME: send TBN_ENDADJUST */
4172 /* remove all uninitialised buttons
4173 * note: loop backwards to avoid having to fixup i on a
4174 * delete */
4175 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4176 if (infoPtr->buttons[i].iBitmap == -1)
4177 TOOLBAR_DeleteButton(infoPtr, i);
4179 /* only indicate success if at least one button survived */
4180 if (infoPtr->nNumButtons > 0) ret = TRUE;
4183 Free (nmtbr.pData);
4184 RegCloseKey(hkey);
4186 return ret;
4190 static LRESULT
4191 TOOLBAR_SaveRestoreW (TOOLBAR_INFO *infoPtr, WPARAM wParam, const TBSAVEPARAMSW *lpSave)
4193 if (lpSave == NULL) return 0;
4195 if (wParam)
4196 return TOOLBAR_Save(lpSave);
4197 else
4198 return TOOLBAR_Restore(infoPtr, lpSave);
4202 static LRESULT
4203 TOOLBAR_SaveRestoreA (TOOLBAR_INFO *infoPtr, WPARAM wParam, const TBSAVEPARAMSA *lpSave)
4205 LPWSTR pszValueName = 0, pszSubKey = 0;
4206 TBSAVEPARAMSW SaveW;
4207 LRESULT result = 0;
4208 int len;
4210 if (lpSave == NULL) return 0;
4212 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4213 pszSubKey = Alloc(len * sizeof(WCHAR));
4214 if (pszSubKey) goto exit;
4215 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4217 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4218 pszValueName = Alloc(len * sizeof(WCHAR));
4219 if (!pszValueName) goto exit;
4220 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4222 SaveW.pszValueName = pszValueName;
4223 SaveW.pszSubKey = pszSubKey;
4224 SaveW.hkr = lpSave->hkr;
4225 result = TOOLBAR_SaveRestoreW(infoPtr, wParam, &SaveW);
4227 exit:
4228 Free (pszValueName);
4229 Free (pszSubKey);
4231 return result;
4235 static LRESULT
4236 TOOLBAR_SetAnchorHighlight (TOOLBAR_INFO *infoPtr, BOOL bAnchor)
4238 BOOL bOldAnchor = infoPtr->bAnchor;
4240 TRACE("hwnd=%p, bAnchor = %s\n", infoPtr->hwndSelf, bAnchor ? "TRUE" : "FALSE");
4242 infoPtr->bAnchor = bAnchor;
4244 /* Native does not remove the hot effect from an already hot button */
4246 return (LRESULT)bOldAnchor;
4250 static LRESULT
4251 TOOLBAR_SetBitmapSize (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4253 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4254 short width = (short)LOWORD(lParam);
4255 short height = (short)HIWORD(lParam);
4257 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", infoPtr->hwndSelf, wParam, lParam);
4259 if (wParam != 0)
4260 FIXME("wParam is %ld. Perhaps image list index?\n", wParam);
4262 /* 0 width or height is changed to 1 */
4263 if (width == 0)
4264 width = 1;
4265 if (height == 0)
4266 height = 1;
4268 if (infoPtr->nNumButtons > 0)
4269 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4270 infoPtr->nNumButtons,
4271 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight, width, height);
4273 if (width < -1 || height < -1)
4275 /* Windows destroys the imagelist and seems to actually use negative
4276 * values to compute button sizes */
4277 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width, height);
4278 return FALSE;
4281 /* width or height of -1 means no change */
4282 if (width != -1)
4283 infoPtr->nBitmapWidth = width;
4284 if (height != -1)
4285 infoPtr->nBitmapHeight = height;
4287 if ((himlDef == infoPtr->himlInt) &&
4288 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4290 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4291 infoPtr->nBitmapHeight);
4294 TOOLBAR_CalcToolbar(infoPtr);
4295 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4296 return TRUE;
4300 static LRESULT
4301 TOOLBAR_SetButtonInfoA (TOOLBAR_INFO *infoPtr, INT Id, const TBBUTTONINFOA *lptbbi)
4303 TBUTTON_INFO *btnPtr;
4304 INT nIndex;
4305 RECT oldBtnRect;
4307 if (lptbbi == NULL)
4308 return FALSE;
4309 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4310 return FALSE;
4312 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, lptbbi->dwMask & TBIF_BYINDEX);
4313 if (nIndex == -1)
4314 return FALSE;
4316 btnPtr = &infoPtr->buttons[nIndex];
4317 if (lptbbi->dwMask & TBIF_COMMAND)
4318 btnPtr->idCommand = lptbbi->idCommand;
4319 if (lptbbi->dwMask & TBIF_IMAGE)
4320 btnPtr->iBitmap = lptbbi->iImage;
4321 if (lptbbi->dwMask & TBIF_LPARAM)
4322 btnPtr->dwData = lptbbi->lParam;
4323 if (lptbbi->dwMask & TBIF_SIZE)
4324 btnPtr->cx = lptbbi->cx;
4325 if (lptbbi->dwMask & TBIF_STATE)
4326 btnPtr->fsState = lptbbi->fsState;
4327 if (lptbbi->dwMask & TBIF_STYLE)
4328 btnPtr->fsStyle = lptbbi->fsStyle;
4330 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4331 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4332 /* iString is index, zero it to make Str_SetPtr succeed */
4333 btnPtr->iString=0;
4335 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4338 /* save the button rect to see if we need to redraw the whole toolbar */
4339 oldBtnRect = btnPtr->rect;
4340 TOOLBAR_LayoutToolbar(infoPtr);
4342 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4343 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4344 else
4345 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4347 return TRUE;
4351 static LRESULT
4352 TOOLBAR_SetButtonInfoW (TOOLBAR_INFO *infoPtr, INT Id, const TBBUTTONINFOW *lptbbi)
4354 TBUTTON_INFO *btnPtr;
4355 INT nIndex;
4356 RECT oldBtnRect;
4358 if (lptbbi == NULL)
4359 return FALSE;
4360 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4361 return FALSE;
4363 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, lptbbi->dwMask & TBIF_BYINDEX);
4364 if (nIndex == -1)
4365 return FALSE;
4367 btnPtr = &infoPtr->buttons[nIndex];
4368 if (lptbbi->dwMask & TBIF_COMMAND)
4369 btnPtr->idCommand = lptbbi->idCommand;
4370 if (lptbbi->dwMask & TBIF_IMAGE)
4371 btnPtr->iBitmap = lptbbi->iImage;
4372 if (lptbbi->dwMask & TBIF_LPARAM)
4373 btnPtr->dwData = lptbbi->lParam;
4374 if (lptbbi->dwMask & TBIF_SIZE)
4375 btnPtr->cx = lptbbi->cx;
4376 if (lptbbi->dwMask & TBIF_STATE)
4377 btnPtr->fsState = lptbbi->fsState;
4378 if (lptbbi->dwMask & TBIF_STYLE)
4379 btnPtr->fsStyle = lptbbi->fsStyle;
4381 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4382 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4383 /* iString is index, zero it to make Str_SetPtr succeed */
4384 btnPtr->iString=0;
4385 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4388 /* save the button rect to see if we need to redraw the whole toolbar */
4389 oldBtnRect = btnPtr->rect;
4390 TOOLBAR_LayoutToolbar(infoPtr);
4392 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4393 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4394 else
4395 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4397 return TRUE;
4401 static LRESULT
4402 TOOLBAR_SetButtonSize (TOOLBAR_INFO *infoPtr, LPARAM lParam)
4404 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4406 if ((cx < 0) || (cy < 0))
4408 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4409 return FALSE;
4412 TRACE("%p, cx = %d, cy = %d\n", infoPtr->hwndSelf, cx, cy);
4414 /* The documentation claims you can only change the button size before
4415 * any button has been added. But this is wrong.
4416 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4417 * it to the toolbar, and it checks that the return value is nonzero - mjm
4418 * Further testing shows that we must actually perform the change too.
4421 * The documentation also does not mention that if 0 is supplied for
4422 * either size, the system changes it to the default of 24 wide and
4423 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4425 if (cx == 0) cx = 24;
4426 if (cy == 0) cy = 22;
4428 cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
4429 cy = max(cy, infoPtr->szPadding.cy + infoPtr->nBitmapHeight);
4431 infoPtr->nButtonWidth = cx;
4432 infoPtr->nButtonHeight = cy;
4434 infoPtr->iTopMargin = default_top_margin(infoPtr);
4435 TOOLBAR_LayoutToolbar(infoPtr);
4436 return TRUE;
4440 static LRESULT
4441 TOOLBAR_SetButtonWidth (TOOLBAR_INFO *infoPtr, LPARAM lParam)
4443 /* if setting to current values, ignore */
4444 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4445 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4446 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4447 infoPtr->cxMin, infoPtr->cxMax);
4448 return TRUE;
4451 /* save new values */
4452 infoPtr->cxMin = (short)LOWORD(lParam);
4453 infoPtr->cxMax = (short)HIWORD(lParam);
4455 /* otherwise we need to recalc the toolbar and in some cases
4456 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4457 which doesn't actually draw - GA). */
4458 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4459 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4461 TOOLBAR_CalcToolbar (infoPtr);
4463 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
4465 return TRUE;
4469 static LRESULT
4470 TOOLBAR_SetCmdId (TOOLBAR_INFO *infoPtr, INT nIndex, INT nId)
4472 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4473 return FALSE;
4475 infoPtr->buttons[nIndex].idCommand = nId;
4477 if (infoPtr->hwndToolTip) {
4479 FIXME("change tool tip!\n");
4483 return TRUE;
4487 static LRESULT
4488 TOOLBAR_SetDisabledImageList (TOOLBAR_INFO *infoPtr, WPARAM wParam, HIMAGELIST himl)
4490 HIMAGELIST himlTemp;
4491 INT id = 0;
4493 if (infoPtr->iVersion >= 5)
4494 id = wParam;
4496 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4497 &infoPtr->cimlDis, himl, id);
4499 /* FIXME: redraw ? */
4501 return (LRESULT)himlTemp;
4505 static LRESULT
4506 TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4508 DWORD dwTemp;
4510 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", infoPtr->hwndSelf, (DWORD)wParam, (DWORD)lParam);
4512 dwTemp = infoPtr->dwDTFlags;
4513 infoPtr->dwDTFlags =
4514 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4516 return (LRESULT)dwTemp;
4519 /* This function differs a bit from what MSDN says it does:
4520 * 1. lParam contains extended style flags to OR with current style
4521 * (MSDN isn't clear on the OR bit)
4522 * 2. wParam appears to contain extended style flags to be reset
4523 * (MSDN says that this parameter is reserved)
4525 static LRESULT
4526 TOOLBAR_SetExtendedStyle (TOOLBAR_INFO *infoPtr, LPARAM lParam)
4528 DWORD dwOldStyle;
4530 dwOldStyle = infoPtr->dwExStyle;
4531 infoPtr->dwExStyle = (DWORD)lParam;
4533 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4535 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4536 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4537 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4539 if ((dwOldStyle ^ infoPtr->dwExStyle) & TBSTYLE_EX_MIXEDBUTTONS)
4540 TOOLBAR_CalcToolbar(infoPtr);
4541 else
4542 TOOLBAR_LayoutToolbar(infoPtr);
4544 TOOLBAR_AutoSize(infoPtr);
4545 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4547 return (LRESULT)dwOldStyle;
4551 static LRESULT
4552 TOOLBAR_SetHotImageList (TOOLBAR_INFO *infoPtr, WPARAM wParam, HIMAGELIST himl)
4554 HIMAGELIST himlTemp;
4555 INT id = 0;
4557 if (infoPtr->iVersion >= 5)
4558 id = wParam;
4560 TRACE("hwnd = %p, himl = %p, id = %d\n", infoPtr->hwndSelf, himl, id);
4562 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4563 &infoPtr->cimlHot, himl, id);
4565 /* FIXME: redraw ? */
4567 return (LRESULT)himlTemp;
4571 /* Makes previous hot button no longer hot, makes the specified
4572 * button hot and sends appropriate notifications. dwReason is one or
4573 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4574 * NOTE 1: this function does not validate nHit
4575 * NOTE 2: the name of this function is completely made up and
4576 * not based on any documentation from Microsoft. */
4577 static void
4578 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4580 if (infoPtr->nHotItem != nHit)
4582 NMTBHOTITEM nmhotitem;
4583 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4585 nmhotitem.dwFlags = dwReason;
4586 if(infoPtr->nHotItem >= 0)
4588 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4589 nmhotitem.idOld = oldBtnPtr->idCommand;
4591 else
4593 nmhotitem.dwFlags |= HICF_ENTERING;
4594 nmhotitem.idOld = 0;
4597 if (nHit >= 0)
4599 btnPtr = &infoPtr->buttons[nHit];
4600 nmhotitem.idNew = btnPtr->idCommand;
4602 else
4604 nmhotitem.dwFlags |= HICF_LEAVING;
4605 nmhotitem.idNew = 0;
4608 /* now change the hot and invalidate the old and new buttons - if the
4609 * parent agrees */
4610 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4612 if (oldBtnPtr) {
4613 oldBtnPtr->bHot = FALSE;
4614 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4616 /* setting disabled buttons as hot fails even if the notify contains the button id */
4617 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4618 btnPtr->bHot = TRUE;
4619 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4620 infoPtr->nHotItem = nHit;
4622 else
4623 infoPtr->nHotItem = -1;
4628 static LRESULT
4629 TOOLBAR_SetHotItem (TOOLBAR_INFO *infoPtr, INT nHotItem)
4631 INT nOldHotItem = infoPtr->nHotItem;
4633 TRACE("hwnd = %p, nHotItem = %d\n", infoPtr->hwndSelf, nHotItem);
4635 if (nHotItem >= infoPtr->nNumButtons)
4636 return infoPtr->nHotItem;
4638 if (nHotItem < 0)
4639 nHotItem = -1;
4641 /* NOTE: an application can still remove the hot item even if anchor
4642 * highlighting is enabled */
4644 TOOLBAR_SetHotItemEx(infoPtr, nHotItem, HICF_OTHER);
4646 if (nOldHotItem < 0)
4647 return -1;
4649 return (LRESULT)nOldHotItem;
4653 static LRESULT
4654 TOOLBAR_SetImageList (TOOLBAR_INFO *infoPtr, WPARAM wParam, HIMAGELIST himl)
4656 HIMAGELIST himlTemp;
4657 INT oldButtonWidth = infoPtr->nButtonWidth;
4658 INT oldBitmapWidth = infoPtr->nBitmapWidth;
4659 INT oldBitmapHeight = infoPtr->nBitmapHeight;
4660 INT i, id = 0;
4662 if (infoPtr->iVersion >= 5)
4663 id = wParam;
4665 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4666 &infoPtr->cimlDef, himl, id);
4668 infoPtr->nNumBitmaps = 0;
4669 for (i = 0; i < infoPtr->cimlDef; i++)
4670 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4672 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4673 &infoPtr->nBitmapHeight))
4675 infoPtr->nBitmapWidth = 1;
4676 infoPtr->nBitmapHeight = 1;
4678 if ((oldBitmapWidth != infoPtr->nBitmapWidth) || (oldBitmapHeight != infoPtr->nBitmapHeight))
4680 TOOLBAR_CalcToolbar(infoPtr);
4681 if (infoPtr->nButtonWidth < oldButtonWidth)
4682 TOOLBAR_SetButtonSize(infoPtr, MAKELONG(oldButtonWidth, infoPtr->nButtonHeight));
4685 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4686 infoPtr->hwndSelf, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4687 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4689 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4691 return (LRESULT)himlTemp;
4695 static LRESULT
4696 TOOLBAR_SetIndent (TOOLBAR_INFO *infoPtr, INT nIndent)
4698 infoPtr->nIndent = nIndent;
4700 TRACE("\n");
4702 /* process only on indent changing */
4703 if(infoPtr->nIndent != nIndent)
4705 infoPtr->nIndent = nIndent;
4706 TOOLBAR_CalcToolbar (infoPtr);
4707 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4710 return TRUE;
4714 static LRESULT
4715 TOOLBAR_SetInsertMark (TOOLBAR_INFO *infoPtr, const TBINSERTMARK *lptbim)
4717 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", infoPtr->hwndSelf, lptbim->iButton, lptbim->dwFlags);
4719 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4721 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4722 return 0;
4725 if ((lptbim->iButton == -1) ||
4726 ((lptbim->iButton < infoPtr->nNumButtons) &&
4727 (lptbim->iButton >= 0)))
4729 infoPtr->tbim = *lptbim;
4730 /* FIXME: don't need to update entire toolbar */
4731 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4733 else
4734 ERR("Invalid button index %d\n", lptbim->iButton);
4736 return 0;
4740 static LRESULT
4741 TOOLBAR_SetInsertMarkColor (TOOLBAR_INFO *infoPtr, COLORREF clr)
4743 infoPtr->clrInsertMark = clr;
4745 /* FIXME: don't need to update entire toolbar */
4746 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4748 return 0;
4752 static LRESULT
4753 TOOLBAR_SetMaxTextRows (TOOLBAR_INFO *infoPtr, INT nMaxRows)
4755 infoPtr->nMaxTextRows = nMaxRows;
4757 TOOLBAR_CalcToolbar(infoPtr);
4758 return TRUE;
4762 /* MSDN gives slightly wrong info on padding.
4763 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4764 * 2. It is not used to create a blank area between the edge of the button
4765 * and the text or image if TBSTYLE_LIST is set. It is used to control
4766 * the gap between the image and text.
4767 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4768 * to control the bottom and right borders [with the border being
4769 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4770 * is shared evenly on both sides of the button.
4771 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4773 static LRESULT
4774 TOOLBAR_SetPadding (TOOLBAR_INFO *infoPtr, LPARAM lParam)
4776 DWORD oldPad;
4778 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4779 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4780 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4781 TRACE("cx=%d, cy=%d\n",
4782 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4783 return (LRESULT) oldPad;
4787 static LRESULT
4788 TOOLBAR_SetParent (TOOLBAR_INFO *infoPtr, HWND hParent)
4790 HWND hwndOldNotify;
4792 TRACE("\n");
4794 hwndOldNotify = infoPtr->hwndNotify;
4795 infoPtr->hwndNotify = hParent;
4797 return (LRESULT)hwndOldNotify;
4801 static LRESULT
4802 TOOLBAR_SetRows (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPRECT lprc)
4804 int rows = LOWORD(wParam);
4805 BOOL bLarger = HIWORD(wParam);
4807 TRACE("\n");
4809 TRACE("Setting rows to %d (%d)\n", rows, bLarger);
4811 if(infoPtr->nRows != rows)
4813 TBUTTON_INFO *btnPtr = infoPtr->buttons;
4814 int curColumn = 0; /* Current column */
4815 int curRow = 0; /* Current row */
4816 int hidden = 0; /* Number of hidden buttons */
4817 int seps = 0; /* Number of separators */
4818 int idealWrap = 0; /* Ideal wrap point */
4819 int i;
4820 BOOL wrap;
4823 Calculate new size and wrap points - Under windows, setrows will
4824 change the dimensions if needed to show the number of requested
4825 rows (if CCS_NORESIZE is set), or will take up the whole window
4826 (if no CCS_NORESIZE).
4828 Basic algorithm - If N buttons, and y rows requested, each row
4829 contains N/y buttons.
4831 FIXME: Handling of separators not obvious from testing results
4832 FIXME: Take width of window into account?
4835 /* Loop through the buttons one by one counting key items */
4836 for (i = 0; i < infoPtr->nNumButtons; i++ )
4838 btnPtr[i].fsState &= ~TBSTATE_WRAP;
4839 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
4840 hidden++;
4841 else if (btnPtr[i].fsStyle & BTNS_SEP)
4842 seps++;
4845 /* FIXME: Separators make this quite complex */
4846 if (seps) FIXME("Separators unhandled\n");
4848 /* Round up so more per line, i.e., less rows */
4849 idealWrap = (infoPtr->nNumButtons - hidden + (rows-1)) / rows;
4851 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4852 achieve the requested number of rows. */
4853 if (bLarger && idealWrap > 1)
4855 int resRows = (infoPtr->nNumButtons + (idealWrap-1)) / idealWrap;
4856 int moreRows = (infoPtr->nNumButtons + (idealWrap-2)) / (idealWrap-1);
4858 if (resRows < rows && moreRows > rows)
4860 idealWrap--;
4861 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap);
4865 curColumn = curRow = 0;
4866 wrap = FALSE;
4867 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap,
4868 infoPtr->nNumButtons, hidden, rows);
4870 for (i = 0; i < infoPtr->nNumButtons; i++ )
4872 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
4873 continue;
4875 /* Step on, wrap if necessary or flag next to wrap */
4876 if (!wrap) {
4877 curColumn++;
4878 } else {
4879 wrap = FALSE;
4880 curColumn = 1;
4881 curRow++;
4884 if (curColumn > (idealWrap-1)) {
4885 wrap = TRUE;
4886 btnPtr[i].fsState |= TBSTATE_WRAP;
4890 TRACE("Result - %d rows\n", curRow + 1);
4892 /* recalculate toolbar */
4893 TOOLBAR_CalcToolbar (infoPtr);
4895 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
4896 if NORESIZE is NOT set, then the toolbar will always be resized to
4897 take up the whole window. With it set, sizing needs to be manual. */
4898 if (infoPtr->dwStyle & CCS_NORESIZE) {
4899 SetWindowPos(infoPtr->hwndSelf, NULL, 0, 0,
4900 infoPtr->rcBound.right - infoPtr->rcBound.left,
4901 infoPtr->rcBound.bottom - infoPtr->rcBound.top,
4902 SWP_NOMOVE);
4905 /* repaint toolbar */
4906 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4909 /* return bounding rectangle */
4910 if (lprc) {
4911 lprc->left = infoPtr->rcBound.left;
4912 lprc->right = infoPtr->rcBound.right;
4913 lprc->top = infoPtr->rcBound.top;
4914 lprc->bottom = infoPtr->rcBound.bottom;
4917 return 0;
4921 static LRESULT
4922 TOOLBAR_SetState (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
4924 TBUTTON_INFO *btnPtr;
4925 INT nIndex;
4927 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
4928 if (nIndex == -1)
4929 return FALSE;
4931 btnPtr = &infoPtr->buttons[nIndex];
4933 /* if hidden state has changed the invalidate entire window and recalc */
4934 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4935 btnPtr->fsState = LOWORD(lParam);
4936 TOOLBAR_CalcToolbar (infoPtr);
4937 InvalidateRect(infoPtr->hwndSelf, 0, TRUE);
4938 return TRUE;
4941 /* process state changing if current state doesn't match new state */
4942 if(btnPtr->fsState != LOWORD(lParam))
4944 btnPtr->fsState = LOWORD(lParam);
4945 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4948 return TRUE;
4952 static LRESULT
4953 TOOLBAR_SetStyle (TOOLBAR_INFO *infoPtr, LPARAM lParam)
4955 SetWindowLongW(infoPtr->hwndSelf, GWL_STYLE, lParam);
4957 return TRUE;
4961 static inline LRESULT
4962 TOOLBAR_SetToolTips (TOOLBAR_INFO *infoPtr, HWND hwndTooltip)
4964 TRACE("hwnd=%p, hwndTooltip=%p\n", infoPtr->hwndSelf, hwndTooltip);
4966 infoPtr->hwndToolTip = hwndTooltip;
4967 return 0;
4971 static LRESULT
4972 TOOLBAR_SetUnicodeFormat (TOOLBAR_INFO *infoPtr, WPARAM wParam)
4974 BOOL bTemp;
4976 TRACE("%s hwnd=%p\n",
4977 ((BOOL)wParam) ? "TRUE" : "FALSE", infoPtr->hwndSelf);
4979 bTemp = infoPtr->bUnicode;
4980 infoPtr->bUnicode = (BOOL)wParam;
4982 return bTemp;
4986 static LRESULT
4987 TOOLBAR_GetColorScheme (const TOOLBAR_INFO *infoPtr, LPCOLORSCHEME lParam)
4989 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4990 comctl32_color.clrBtnHighlight :
4991 infoPtr->clrBtnHighlight;
4992 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4993 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4994 return 1;
4998 static LRESULT
4999 TOOLBAR_SetColorScheme (TOOLBAR_INFO *infoPtr, const COLORSCHEME *lParam)
5001 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5002 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5003 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5005 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5006 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5007 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
5008 return 0;
5012 static LRESULT
5013 TOOLBAR_SetVersion (TOOLBAR_INFO *infoPtr, INT iVersion)
5015 INT iOldVersion = infoPtr->iVersion;
5017 infoPtr->iVersion = iVersion;
5019 if (infoPtr->iVersion >= 5)
5020 TOOLBAR_SetUnicodeFormat(infoPtr, TRUE);
5022 return iOldVersion;
5026 static LRESULT
5027 TOOLBAR_GetStringA (const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPSTR str)
5029 WORD iString = HIWORD(wParam);
5030 WORD buffersize = LOWORD(wParam);
5031 LRESULT ret = -1;
5033 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr->hwndSelf, iString, buffersize, str);
5035 if (iString < infoPtr->nNumStrings)
5037 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5038 ret--;
5040 TRACE("returning %s\n", debugstr_a(str));
5042 else
5043 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5045 return ret;
5049 static LRESULT
5050 TOOLBAR_GetStringW (const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPWSTR str)
5052 WORD iString = HIWORD(wParam);
5053 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5054 LRESULT ret = -1;
5056 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr->hwndSelf, iString, LOWORD(wParam), str);
5058 if (iString < infoPtr->nNumStrings)
5060 len = min(len, strlenW(infoPtr->strings[iString]));
5061 ret = (len+1)*sizeof(WCHAR);
5062 if (str)
5064 memcpy(str, infoPtr->strings[iString], ret);
5065 str[len] = '\0';
5067 ret = len;
5069 TRACE("returning %s\n", debugstr_w(str));
5071 else
5072 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5074 return ret;
5077 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5078 * is the maximum size of the toolbar? */
5079 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5081 SIZE * pSize = (SIZE*)lParam;
5082 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5083 return 0;
5087 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5088 * caller to specify a reason why the hot item changed (rather than just the
5089 * HICF_OTHER that TB_SETHOTITEM sends). */
5090 static LRESULT
5091 TOOLBAR_SetHotItem2 (TOOLBAR_INFO *infoPtr, INT nHotItem, LPARAM lParam)
5093 INT nOldHotItem = infoPtr->nHotItem;
5095 TRACE("old item=%d, new item=%d, flags=%08x\n",
5096 nOldHotItem, nHotItem, (DWORD)lParam);
5098 if (nHotItem < 0 || nHotItem > infoPtr->nNumButtons)
5099 nHotItem = -1;
5101 /* NOTE: an application can still remove the hot item even if anchor
5102 * highlighting is enabled */
5104 TOOLBAR_SetHotItemEx(infoPtr, nHotItem, lParam);
5106 GetFocus();
5108 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5111 /* Sets the toolbar global iListGap parameter which controls the amount of
5112 * spacing between the image and the text of buttons for TBSTYLE_LIST
5113 * toolbars. */
5114 static LRESULT TOOLBAR_SetListGap(TOOLBAR_INFO *infoPtr, INT iListGap)
5116 TRACE("hwnd=%p iListGap=%d\n", infoPtr->hwndSelf, iListGap);
5118 infoPtr->iListGap = iListGap;
5120 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
5122 return 0;
5125 /* Returns the number of maximum number of image lists associated with the
5126 * various states. */
5127 static LRESULT TOOLBAR_GetImageListCount(const TOOLBAR_INFO *infoPtr)
5129 TRACE("hwnd=%p\n", infoPtr->hwndSelf);
5131 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5134 static LRESULT
5135 TOOLBAR_GetIdealSize (const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5137 LPSIZE lpsize = (LPSIZE)lParam;
5139 if (lpsize == NULL)
5140 return FALSE;
5143 * Testing shows the following:
5144 * wParam = 0 adjust cx value
5145 * = 1 set cy value to max size.
5146 * lParam pointer to SIZE structure
5149 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5150 wParam, lParam, lpsize->cx, lpsize->cy);
5152 switch(wParam) {
5153 case 0:
5154 if (lpsize->cx == -1) {
5155 /* **** this is wrong, native measures each button and sets it */
5156 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5158 else if(HIWORD(lpsize->cx)) {
5159 RECT rc;
5160 HWND hwndParent = GetParent(infoPtr->hwndSelf);
5162 GetWindowRect(infoPtr->hwndSelf, &rc);
5163 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5164 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc));
5165 lpsize->cx = max(rc.right-rc.left,
5166 infoPtr->rcBound.right - infoPtr->rcBound.left);
5168 else {
5169 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5171 break;
5172 case 1:
5173 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5174 break;
5175 default:
5176 FIXME("Unknown wParam %ld\n", wParam);
5177 return 0;
5179 TRACE("set to -> 0x%08x 0x%08x\n",
5180 lpsize->cx, lpsize->cy);
5181 return 1;
5184 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5186 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5188 InvalidateRect(hwnd, NULL, TRUE);
5189 return 1;
5193 static LRESULT
5194 TOOLBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
5196 TOOLBAR_INFO *infoPtr = (TOOLBAR_INFO *)GetWindowLongPtrW(hwnd, 0);
5197 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5198 LOGFONTW logFont;
5200 TRACE("hwnd = %p\n", hwnd);
5202 infoPtr->dwStyle = dwStyle;
5203 GetClientRect(hwnd, &infoPtr->client_rect);
5204 infoPtr->bUnicode = infoPtr->hwndNotify &&
5205 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5206 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5208 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5209 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5211 OpenThemeData (hwnd, themeClass);
5213 TOOLBAR_CheckStyle (infoPtr, dwStyle);
5215 return 0;
5219 static LRESULT
5220 TOOLBAR_Destroy (TOOLBAR_INFO *infoPtr)
5222 /* delete tooltip control */
5223 if (infoPtr->hwndToolTip)
5224 DestroyWindow (infoPtr->hwndToolTip);
5226 /* delete temporary buffer for tooltip text */
5227 Free (infoPtr->pszTooltipText);
5228 Free (infoPtr->bitmaps); /* bitmaps list */
5230 /* delete button data */
5231 Free (infoPtr->buttons);
5233 /* delete strings */
5234 if (infoPtr->strings) {
5235 INT i;
5236 for (i = 0; i < infoPtr->nNumStrings; i++)
5237 Free (infoPtr->strings[i]);
5239 Free (infoPtr->strings);
5242 /* destroy internal image list */
5243 if (infoPtr->himlInt)
5244 ImageList_Destroy (infoPtr->himlInt);
5246 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5247 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5248 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5250 /* delete default font */
5251 DeleteObject (infoPtr->hDefaultFont);
5253 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
5255 /* free toolbar info data */
5256 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
5257 Free (infoPtr);
5259 return 0;
5263 static LRESULT
5264 TOOLBAR_EraseBackground (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5266 NMTBCUSTOMDRAW tbcd;
5267 INT ret = FALSE;
5268 DWORD ntfret;
5269 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
5270 DWORD dwEraseCustDraw = 0;
5272 /* the app has told us not to redraw the toolbar */
5273 if (!infoPtr->bDoRedraw)
5274 return FALSE;
5276 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5277 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5278 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5279 tbcd.nmcd.hdc = (HDC)wParam;
5280 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5281 dwEraseCustDraw = ntfret & 0xffff;
5283 /* FIXME: in general the return flags *can* be or'ed together */
5284 switch (dwEraseCustDraw)
5286 case CDRF_DODEFAULT:
5287 break;
5288 case CDRF_SKIPDEFAULT:
5289 return TRUE;
5290 default:
5291 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5292 infoPtr->hwndSelf, ntfret);
5296 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5297 * to my parent for processing.
5299 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5300 POINT pt, ptorig;
5301 HDC hdc = (HDC)wParam;
5302 HWND parent;
5304 pt.x = 0;
5305 pt.y = 0;
5306 parent = GetParent(infoPtr->hwndSelf);
5307 MapWindowPoints(infoPtr->hwndSelf, parent, &pt, 1);
5308 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5309 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5310 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5312 if (!ret)
5313 ret = DefWindowProcW (infoPtr->hwndSelf, WM_ERASEBKGND, wParam, lParam);
5315 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5316 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5317 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5318 tbcd.nmcd.hdc = (HDC)wParam;
5319 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5320 dwEraseCustDraw = ntfret & 0xffff;
5321 switch (dwEraseCustDraw)
5323 case CDRF_DODEFAULT:
5324 break;
5325 case CDRF_SKIPDEFAULT:
5326 return TRUE;
5327 default:
5328 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5329 infoPtr->hwndSelf, ntfret);
5332 return ret;
5336 static inline LRESULT
5337 TOOLBAR_GetFont (const TOOLBAR_INFO *infoPtr)
5339 return (LRESULT)infoPtr->hFont;
5343 static void
5344 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5346 INT i;
5347 INT nNewHotItem = infoPtr->nHotItem;
5349 for (i = 0; i < infoPtr->nNumButtons; i++)
5351 /* did we wrap? */
5352 if ((nNewHotItem + iDirection < 0) ||
5353 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5355 NMTBWRAPHOTITEM nmtbwhi;
5356 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5357 nmtbwhi.iDirection = iDirection;
5358 nmtbwhi.dwReason = dwReason;
5360 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5361 return;
5364 nNewHotItem += iDirection;
5365 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5367 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5368 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5370 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5371 break;
5376 static LRESULT
5377 TOOLBAR_KeyDown (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5379 NMKEY nmkey;
5381 nmkey.nVKey = (UINT)wParam;
5382 nmkey.uFlags = HIWORD(lParam);
5384 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5385 return DefWindowProcW(infoPtr->hwndSelf, WM_KEYDOWN, wParam, lParam);
5387 switch ((UINT)wParam)
5389 case VK_LEFT:
5390 case VK_UP:
5391 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5392 break;
5393 case VK_RIGHT:
5394 case VK_DOWN:
5395 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5396 break;
5397 case VK_SPACE:
5398 case VK_RETURN:
5399 if ((infoPtr->nHotItem >= 0) &&
5400 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5402 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5403 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5404 (LPARAM)infoPtr->hwndSelf);
5406 break;
5409 return 0;
5413 static LRESULT
5414 TOOLBAR_LButtonDblClk (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5416 POINT pt;
5417 INT nHit;
5419 pt.x = (short)LOWORD(lParam);
5420 pt.y = (short)HIWORD(lParam);
5421 nHit = TOOLBAR_InternalHitTest (infoPtr, &pt);
5423 if (nHit >= 0)
5424 TOOLBAR_LButtonDown (infoPtr, wParam, lParam);
5425 else if (infoPtr->dwStyle & CCS_ADJUSTABLE)
5426 TOOLBAR_Customize (infoPtr);
5428 return 0;
5432 static LRESULT
5433 TOOLBAR_LButtonDown (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5435 TBUTTON_INFO *btnPtr;
5436 POINT pt;
5437 INT nHit;
5438 NMTOOLBARA nmtb;
5439 NMMOUSE nmmouse;
5440 BOOL bDragKeyPressed;
5442 TRACE("\n");
5444 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5445 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5446 else
5447 bDragKeyPressed = (wParam & MK_SHIFT);
5449 if (infoPtr->hwndToolTip)
5450 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwndSelf,
5451 WM_LBUTTONDOWN, wParam, lParam);
5453 pt.x = (short)LOWORD(lParam);
5454 pt.y = (short)HIWORD(lParam);
5455 nHit = TOOLBAR_InternalHitTest (infoPtr, &pt);
5457 btnPtr = &infoPtr->buttons[nHit];
5459 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5461 infoPtr->nButtonDrag = nHit;
5462 SetCapture (infoPtr->hwndSelf);
5464 /* If drag cursor has not been loaded, load it.
5465 * Note: it doesn't need to be freed */
5466 if (!hCursorDrag)
5467 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5468 SetCursor(hCursorDrag);
5470 else if (nHit >= 0)
5472 RECT arrowRect;
5473 infoPtr->nOldHit = nHit;
5475 CopyRect(&arrowRect, &btnPtr->rect);
5476 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5478 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5479 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5480 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5481 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5482 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5483 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5485 LRESULT res;
5487 /* draw in pressed state */
5488 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5489 btnPtr->fsState |= TBSTATE_PRESSED;
5490 else
5491 btnPtr->bDropDownPressed = TRUE;
5492 RedrawWindow(infoPtr->hwndSelf,&btnPtr->rect,0,
5493 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5495 memset(&nmtb, 0, sizeof(nmtb));
5496 nmtb.iItem = btnPtr->idCommand;
5497 nmtb.rcButton = btnPtr->rect;
5498 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5499 TBN_DROPDOWN);
5500 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5502 if (res != TBDDRET_TREATPRESSED)
5504 MSG msg;
5506 /* redraw button in unpressed state */
5507 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5508 btnPtr->fsState &= ~TBSTATE_PRESSED;
5509 else
5510 btnPtr->bDropDownPressed = FALSE;
5511 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5513 /* find and set hot item
5514 * NOTE: native doesn't do this, but that is a bug */
5515 GetCursorPos(&pt);
5516 ScreenToClient(infoPtr->hwndSelf, &pt);
5517 nHit = TOOLBAR_InternalHitTest(infoPtr, &pt);
5518 if (!infoPtr->bAnchor || (nHit >= 0))
5519 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5521 /* remove any left mouse button down or double-click messages
5522 * so that we can get a toggle effect on the button */
5523 while (PeekMessageW(&msg, infoPtr->hwndSelf, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5524 PeekMessageW(&msg, infoPtr->hwndSelf, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5527 return 0;
5529 /* otherwise drop through and process as pushed */
5531 infoPtr->bCaptured = TRUE;
5532 infoPtr->nButtonDown = nHit;
5533 infoPtr->bDragOutSent = FALSE;
5535 btnPtr->fsState |= TBSTATE_PRESSED;
5537 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5539 if (btnPtr->fsState & TBSTATE_ENABLED)
5540 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5541 UpdateWindow(infoPtr->hwndSelf);
5542 SetCapture (infoPtr->hwndSelf);
5545 if (nHit >=0)
5547 memset(&nmtb, 0, sizeof(nmtb));
5548 nmtb.iItem = btnPtr->idCommand;
5549 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5552 nmmouse.dwHitInfo = nHit;
5554 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5555 if (nHit < 0)
5556 nmmouse.dwItemSpec = -1;
5557 else
5559 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5560 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5563 ClientToScreen(infoPtr->hwndSelf, &pt);
5564 nmmouse.pt = pt;
5566 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5567 return DefWindowProcW(infoPtr->hwndSelf, WM_LBUTTONDOWN, wParam, lParam);
5569 return 0;
5572 static LRESULT
5573 TOOLBAR_LButtonUp (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5575 TBUTTON_INFO *btnPtr;
5576 POINT pt;
5577 INT nHit;
5578 INT nOldIndex = -1;
5579 NMHDR hdr;
5580 NMMOUSE nmmouse;
5581 NMTOOLBARA nmtb;
5583 if (infoPtr->hwndToolTip)
5584 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwndSelf,
5585 WM_LBUTTONUP, wParam, lParam);
5587 pt.x = (short)LOWORD(lParam);
5588 pt.y = (short)HIWORD(lParam);
5589 nHit = TOOLBAR_InternalHitTest (infoPtr, &pt);
5591 if (!infoPtr->bAnchor || (nHit >= 0))
5592 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5594 if (infoPtr->nButtonDrag >= 0) {
5595 RECT rcClient;
5596 NMHDR hdr;
5598 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5599 ReleaseCapture();
5600 /* reset cursor */
5601 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5603 GetClientRect(infoPtr->hwndSelf, &rcClient);
5604 if (PtInRect(&rcClient, pt))
5606 INT nButton = -1;
5607 if (nHit >= 0)
5608 nButton = nHit;
5609 else if (nHit < -1)
5610 nButton = -nHit;
5611 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5612 nButton = -nHit;
5614 if (nButton == infoPtr->nButtonDrag)
5616 /* if the button is moved sightly left and we have a
5617 * separator there then remove it */
5618 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5620 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5621 TOOLBAR_DeleteButton(infoPtr, nButton - 1);
5623 else /* else insert a separator before the dragged button */
5625 TBBUTTON tbb;
5626 memset(&tbb, 0, sizeof(tbb));
5627 tbb.fsStyle = BTNS_SEP;
5628 tbb.iString = -1;
5629 TOOLBAR_InsertButtonT(infoPtr, nButton, &tbb, TRUE);
5632 else
5634 if (nButton == -1)
5636 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5637 TOOLBAR_MoveButton(infoPtr, infoPtr->nButtonDrag, 0);
5638 else
5639 TOOLBAR_MoveButton(infoPtr, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5641 else
5642 TOOLBAR_MoveButton(infoPtr, infoPtr->nButtonDrag, nButton);
5645 else
5647 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5648 TOOLBAR_DeleteButton(infoPtr, (WPARAM)infoPtr->nButtonDrag);
5651 /* button under cursor changed so need to re-set hot item */
5652 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5653 infoPtr->nButtonDrag = -1;
5655 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5657 else if (infoPtr->nButtonDown >= 0) {
5658 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5659 btnPtr->fsState &= ~TBSTATE_PRESSED;
5661 if (btnPtr->fsStyle & BTNS_CHECK) {
5662 if (btnPtr->fsStyle & BTNS_GROUP) {
5663 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5664 nHit);
5665 if ((nOldIndex != nHit) &&
5666 (nOldIndex != -1))
5667 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5668 btnPtr->fsState |= TBSTATE_CHECKED;
5670 else {
5671 if (btnPtr->fsState & TBSTATE_CHECKED)
5672 btnPtr->fsState &= ~TBSTATE_CHECKED;
5673 else
5674 btnPtr->fsState |= TBSTATE_CHECKED;
5678 if (nOldIndex != -1)
5679 InvalidateRect(infoPtr->hwndSelf, &infoPtr->buttons[nOldIndex].rect, TRUE);
5682 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5683 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5684 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5686 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5687 ReleaseCapture ();
5688 infoPtr->nButtonDown = -1;
5690 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5691 TOOLBAR_SendNotify (&hdr, infoPtr,
5692 NM_RELEASEDCAPTURE);
5694 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5695 * TBN_BEGINDRAG
5697 memset(&nmtb, 0, sizeof(nmtb));
5698 nmtb.iItem = btnPtr->idCommand;
5699 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5700 TBN_ENDDRAG);
5702 if (btnPtr->fsState & TBSTATE_ENABLED)
5704 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5705 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)infoPtr->hwndSelf);
5707 /* In case we have just been destroyed... */
5708 if(!IsWindow(infoPtr->hwndSelf))
5709 return 0;
5713 /* !!! Undocumented - toolbar at 4.71 level and above sends
5714 * NM_CLICK with the NMMOUSE structure. */
5715 nmmouse.dwHitInfo = nHit;
5717 if (nHit < 0)
5718 nmmouse.dwItemSpec = -1;
5719 else
5721 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5722 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5725 ClientToScreen(infoPtr->hwndSelf, &pt);
5726 nmmouse.pt = pt;
5728 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5729 return DefWindowProcW(infoPtr->hwndSelf, WM_LBUTTONUP, wParam, lParam);
5731 return 0;
5734 static LRESULT
5735 TOOLBAR_RButtonUp(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5737 INT nHit;
5738 NMMOUSE nmmouse;
5739 POINT pt;
5741 pt.x = (short)LOWORD(lParam);
5742 pt.y = (short)HIWORD(lParam);
5744 nHit = TOOLBAR_InternalHitTest(infoPtr, &pt);
5745 nmmouse.dwHitInfo = nHit;
5747 if (nHit < 0) {
5748 nmmouse.dwItemSpec = -1;
5749 } else {
5750 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5751 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5754 ClientToScreen(infoPtr->hwndSelf, &pt);
5755 nmmouse.pt = pt;
5757 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5758 return DefWindowProcW(infoPtr->hwndSelf, WM_RBUTTONUP, wParam, lParam);
5760 return 0;
5763 static LRESULT
5764 TOOLBAR_RButtonDblClk( TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5766 NMHDR nmhdr;
5768 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5769 return DefWindowProcW(infoPtr->hwndSelf, WM_RBUTTONDBLCLK, wParam, lParam);
5771 return 0;
5774 static LRESULT
5775 TOOLBAR_CaptureChanged(TOOLBAR_INFO *infoPtr)
5777 TBUTTON_INFO *btnPtr;
5779 infoPtr->bCaptured = FALSE;
5781 if (infoPtr->nButtonDown >= 0)
5783 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5784 btnPtr->fsState &= ~TBSTATE_PRESSED;
5786 infoPtr->nOldHit = -1;
5788 if (btnPtr->fsState & TBSTATE_ENABLED)
5789 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5791 return 0;
5794 static LRESULT
5795 TOOLBAR_MouseLeave (TOOLBAR_INFO *infoPtr)
5797 /* don't remove hot effects when in anchor highlighting mode or when a
5798 * drop-down button is pressed */
5799 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
5801 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5802 if (!hotBtnPtr->bDropDownPressed)
5803 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
5806 if (infoPtr->nOldHit < 0)
5807 return TRUE;
5809 /* If the last button we were over is depressed then make it not */
5810 /* depressed and redraw it */
5811 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5813 TBUTTON_INFO *btnPtr;
5814 RECT rc1;
5816 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5818 btnPtr->fsState &= ~TBSTATE_PRESSED;
5820 rc1 = btnPtr->rect;
5821 InflateRect (&rc1, 1, 1);
5822 InvalidateRect (infoPtr->hwndSelf, &rc1, TRUE);
5825 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
5827 NMTOOLBARW nmt;
5828 ZeroMemory(&nmt, sizeof(nmt));
5829 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5830 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5831 infoPtr->bDragOutSent = TRUE;
5834 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5836 return TRUE;
5839 static LRESULT
5840 TOOLBAR_MouseMove (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5842 POINT pt;
5843 TRACKMOUSEEVENT trackinfo;
5844 INT nHit;
5845 TBUTTON_INFO *btnPtr;
5847 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
5848 TOOLBAR_TooltipCreateControl(infoPtr);
5850 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
5851 /* fill in the TRACKMOUSEEVENT struct */
5852 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5853 trackinfo.dwFlags = TME_QUERY;
5855 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5856 _TrackMouseEvent(&trackinfo);
5858 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5859 if(trackinfo.hwndTrack != infoPtr->hwndSelf || !(trackinfo.dwFlags & TME_LEAVE)) {
5860 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5861 trackinfo.hwndTrack = infoPtr->hwndSelf;
5863 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5864 /* and can properly deactivate the hot toolbar button */
5865 _TrackMouseEvent(&trackinfo);
5869 if (infoPtr->hwndToolTip)
5870 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwndSelf,
5871 WM_MOUSEMOVE, wParam, lParam);
5873 pt.x = (short)LOWORD(lParam);
5874 pt.y = (short)HIWORD(lParam);
5876 nHit = TOOLBAR_InternalHitTest (infoPtr, &pt);
5878 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
5879 && (!infoPtr->bAnchor || (nHit >= 0)))
5880 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
5882 if (infoPtr->nOldHit != nHit)
5884 if (infoPtr->bCaptured)
5886 if (!infoPtr->bDragOutSent)
5888 NMTOOLBARW nmt;
5889 ZeroMemory(&nmt, sizeof(nmt));
5890 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5891 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5892 infoPtr->bDragOutSent = TRUE;
5895 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5896 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5897 btnPtr->fsState &= ~TBSTATE_PRESSED;
5898 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5900 else if (nHit == infoPtr->nButtonDown) {
5901 btnPtr->fsState |= TBSTATE_PRESSED;
5902 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5904 infoPtr->nOldHit = nHit;
5908 return 0;
5912 static inline LRESULT
5913 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5915 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5916 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
5917 /* else */
5918 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5922 static inline LRESULT
5923 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5925 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
5926 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5928 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
5932 static LRESULT
5933 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, const CREATESTRUCTW *lpcs)
5935 TOOLBAR_INFO *infoPtr;
5936 DWORD styleadd = 0;
5938 /* allocate memory for info structure */
5939 infoPtr = Alloc (sizeof(TOOLBAR_INFO));
5940 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
5942 /* paranoid!! */
5943 infoPtr->dwStructSize = sizeof(TBBUTTON);
5944 infoPtr->nRows = 1;
5945 infoPtr->nWidth = 0;
5947 /* initialize info structure */
5948 infoPtr->nButtonWidth = 23;
5949 infoPtr->nButtonHeight = 22;
5950 infoPtr->nBitmapHeight = 16;
5951 infoPtr->nBitmapWidth = 16;
5953 infoPtr->nMaxTextRows = 1;
5954 infoPtr->cxMin = -1;
5955 infoPtr->cxMax = -1;
5956 infoPtr->nNumBitmaps = 0;
5957 infoPtr->nNumStrings = 0;
5959 infoPtr->bCaptured = FALSE;
5960 infoPtr->nButtonDown = -1;
5961 infoPtr->nButtonDrag = -1;
5962 infoPtr->nOldHit = -1;
5963 infoPtr->nHotItem = -1;
5964 infoPtr->hwndNotify = lpcs->hwndParent;
5965 infoPtr->dwDTFlags = (lpcs->style & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5966 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5967 infoPtr->bDragOutSent = FALSE;
5968 infoPtr->iVersion = 0;
5969 infoPtr->hwndSelf = hwnd;
5970 infoPtr->bDoRedraw = TRUE;
5971 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5972 infoPtr->clrBtnShadow = CLR_DEFAULT;
5973 infoPtr->szPadding.cx = DEFPAD_CX;
5974 infoPtr->szPadding.cy = DEFPAD_CY;
5975 infoPtr->iListGap = DEFLISTGAP;
5976 infoPtr->iTopMargin = default_top_margin(infoPtr);
5977 infoPtr->dwStyle = lpcs->style;
5978 infoPtr->tbim.iButton = -1;
5980 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5981 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
5982 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
5983 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
5986 /* native control does:
5987 * Get a lot of colors and brushes
5988 * WM_NOTIFYFORMAT
5989 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
5990 * CreateFontIndirectW(adr1)
5991 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5992 * hdc = GetDC(toolbar)
5993 * GetSystemMetrics(0x48)
5994 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5995 * 0, 0, 0, 0, "MARLETT")
5996 * oldfnt = SelectObject(hdc, fnt2)
5997 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
5998 * GetTextMetricsW(hdc, adr3)
5999 * SelectObject(hdc, oldfnt)
6000 * DeleteObject(fnt2)
6001 * ReleaseDC(hdc)
6002 * InvalidateRect(toolbar, 0, 1)
6003 * SetWindowLongW(toolbar, 0, addr)
6004 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6005 * WM_STYLECHANGING
6006 * CallWinEx old new
6007 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6008 * ie 2 0x4600094c 0x4600094c 0x4600894d
6009 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6010 * rebar 0x50008844 0x40008844 0x50008845
6011 * pager 0x50000844 0x40000844 0x50008845
6012 * IC35mgr 0x5400084e **nochange**
6013 * on entry to _NCCREATE 0x5400084e
6014 * rowlist 0x5400004e **nochange**
6015 * on entry to _NCCREATE 0x5400004e
6019 /* I think the code below is a bug, but it is the way that the native
6020 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6021 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6022 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6023 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6024 * Somehow, the only cases of this seem to be MFC programs.
6026 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6027 * does not occur in the WM_STYLECHANGING routine.
6028 * (Guy Albertelli 9/2001)
6031 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6032 && !(lpcs->style & TBSTYLE_TRANSPARENT))
6033 styleadd |= TBSTYLE_TRANSPARENT;
6034 if (!(lpcs->style & (CCS_TOP | CCS_NOMOVEY))) {
6035 styleadd |= CCS_TOP; /* default to top */
6036 SetWindowLongW (hwnd, GWL_STYLE, lpcs->style | styleadd);
6039 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, (LPARAM)lpcs);
6043 static LRESULT
6044 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6046 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6047 RECT rcWindow;
6048 HDC hdc;
6050 if (dwStyle & WS_MINIMIZE)
6051 return 0; /* Nothing to do */
6053 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6055 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6056 return 0;
6058 if (!(dwStyle & CCS_NODIVIDER))
6060 GetWindowRect (hwnd, &rcWindow);
6061 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6062 if( dwStyle & WS_BORDER )
6063 OffsetRect (&rcWindow, 1, 1);
6064 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6067 ReleaseDC( hwnd, hdc );
6069 return 0;
6073 /* handles requests from the tooltip control on what text to display */
6074 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6076 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6078 TRACE("button index = %d\n", index);
6080 Free (infoPtr->pszTooltipText);
6081 infoPtr->pszTooltipText = NULL;
6083 if (index < 0)
6084 return 0;
6086 if (infoPtr->bUnicode)
6088 WCHAR wszBuffer[INFOTIPSIZE+1];
6089 NMTBGETINFOTIPW tbgit;
6090 unsigned int len; /* in chars */
6092 wszBuffer[0] = '\0';
6093 wszBuffer[INFOTIPSIZE] = '\0';
6095 tbgit.pszText = wszBuffer;
6096 tbgit.cchTextMax = INFOTIPSIZE;
6097 tbgit.iItem = lpnmtdi->hdr.idFrom;
6098 tbgit.lParam = infoPtr->buttons[index].dwData;
6100 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6102 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6104 len = strlenW(tbgit.pszText);
6105 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6107 /* need to allocate temporary buffer in infoPtr as there
6108 * isn't enough space in buffer passed to us by the
6109 * tooltip control */
6110 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6111 if (infoPtr->pszTooltipText)
6113 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6114 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6115 return 0;
6118 else if (len > 0)
6120 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6121 return 0;
6124 else
6126 CHAR szBuffer[INFOTIPSIZE+1];
6127 NMTBGETINFOTIPA tbgit;
6128 unsigned int len; /* in chars */
6130 szBuffer[0] = '\0';
6131 szBuffer[INFOTIPSIZE] = '\0';
6133 tbgit.pszText = szBuffer;
6134 tbgit.cchTextMax = INFOTIPSIZE;
6135 tbgit.iItem = lpnmtdi->hdr.idFrom;
6136 tbgit.lParam = infoPtr->buttons[index].dwData;
6138 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6140 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6142 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6143 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6145 /* need to allocate temporary buffer in infoPtr as there
6146 * isn't enough space in buffer passed to us by the
6147 * tooltip control */
6148 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6149 if (infoPtr->pszTooltipText)
6151 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6152 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6153 return 0;
6156 else if (tbgit.pszText[0])
6158 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6159 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6160 return 0;
6164 /* if button has text, but it is not shown then automatically
6165 * use that text as tooltip */
6166 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6167 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6169 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6170 unsigned int len = pszText ? strlenW(pszText) : 0;
6172 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6174 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6176 /* need to allocate temporary buffer in infoPtr as there
6177 * isn't enough space in buffer passed to us by the
6178 * tooltip control */
6179 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6180 if (infoPtr->pszTooltipText)
6182 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6183 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6184 return 0;
6187 else if (len > 0)
6189 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6190 return 0;
6194 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6196 /* last resort: send notification on to app */
6197 /* FIXME: find out what is really used here */
6198 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, lpnmtdi->hdr.idFrom, (LPARAM)lpnmtdi);
6202 static inline LRESULT
6203 TOOLBAR_Notify (TOOLBAR_INFO *infoPtr, LPNMHDR lpnmh)
6205 switch (lpnmh->code)
6207 case PGN_CALCSIZE:
6209 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lpnmh;
6211 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6212 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6213 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6214 lppgc->iWidth);
6216 else {
6217 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6218 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6219 lppgc->iHeight);
6221 return 0;
6224 case PGN_SCROLL:
6226 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lpnmh;
6228 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6229 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6230 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6231 lppgs->iScroll, lppgs->iDir);
6232 return 0;
6235 case TTN_GETDISPINFOW:
6236 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lpnmh);
6238 case TTN_GETDISPINFOA:
6239 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6240 return 0;
6242 default:
6243 return 0;
6248 static LRESULT
6249 TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6251 LRESULT format;
6253 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam, lParam);
6255 if (lParam == NF_QUERY)
6256 return NFR_UNICODE;
6258 if (lParam == NF_REQUERY) {
6259 format = SendMessageW(infoPtr->hwndNotify,
6260 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6261 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6262 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6263 format);
6264 format = NFR_ANSI;
6266 return format;
6268 return 0;
6272 static LRESULT
6273 TOOLBAR_Paint (TOOLBAR_INFO *infoPtr, WPARAM wParam)
6275 HDC hdc;
6276 PAINTSTRUCT ps;
6278 /* fill ps.rcPaint with a default rect */
6279 ps.rcPaint = infoPtr->rcBound;
6281 hdc = wParam==0 ? BeginPaint(infoPtr->hwndSelf, &ps) : (HDC)wParam;
6283 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps.rcPaint));
6285 TOOLBAR_Refresh (infoPtr, hdc, &ps);
6286 if (!wParam) EndPaint (infoPtr->hwndSelf, &ps);
6288 return 0;
6292 static LRESULT
6293 TOOLBAR_SetFocus (TOOLBAR_INFO *infoPtr)
6295 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6297 /* make first item hot */
6298 if (infoPtr->nNumButtons > 0)
6299 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6301 return 0;
6304 static LRESULT
6305 TOOLBAR_SetFont(TOOLBAR_INFO *infoPtr, HFONT hFont, WORD Redraw)
6307 TRACE("font=%p redraw=%d\n", hFont, Redraw);
6309 if (hFont == 0)
6310 infoPtr->hFont = infoPtr->hDefaultFont;
6311 else
6312 infoPtr->hFont = hFont;
6314 TOOLBAR_CalcToolbar(infoPtr);
6316 if (Redraw)
6317 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
6318 return 1;
6321 static LRESULT
6322 TOOLBAR_SetRedraw (TOOLBAR_INFO *infoPtr, WPARAM wParam)
6323 /*****************************************************
6325 * Function;
6326 * Handles the WM_SETREDRAW message.
6328 * Documentation:
6329 * According to testing V4.71 of COMCTL32 returns the
6330 * *previous* status of the redraw flag (either 0 or 1)
6331 * instead of the MSDN documented value of 0 if handled.
6332 * (For laughs see the "consistency" with same function
6333 * in rebar.)
6335 *****************************************************/
6337 BOOL oldredraw = infoPtr->bDoRedraw;
6339 TRACE("set to %s\n",
6340 (wParam) ? "TRUE" : "FALSE");
6341 infoPtr->bDoRedraw = (BOOL) wParam;
6342 if (wParam) {
6343 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6345 return (oldredraw) ? 1 : 0;
6349 static LRESULT
6350 TOOLBAR_Size (TOOLBAR_INFO *infoPtr)
6352 TRACE("sizing toolbar!\n");
6354 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6356 RECT delta_width, delta_height, client, dummy;
6357 DWORD min_x, max_x, min_y, max_y;
6358 TBUTTON_INFO *btnPtr;
6359 INT i;
6361 GetClientRect(infoPtr->hwndSelf, &client);
6362 if(client.right > infoPtr->client_rect.right)
6364 min_x = infoPtr->client_rect.right;
6365 max_x = client.right;
6367 else
6369 max_x = infoPtr->client_rect.right;
6370 min_x = client.right;
6372 if(client.bottom > infoPtr->client_rect.bottom)
6374 min_y = infoPtr->client_rect.bottom;
6375 max_y = client.bottom;
6377 else
6379 max_y = infoPtr->client_rect.bottom;
6380 min_y = client.bottom;
6383 SetRect(&delta_width, min_x, 0, max_x, min_y);
6384 SetRect(&delta_height, 0, min_y, max_x, max_y);
6386 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6387 btnPtr = infoPtr->buttons;
6388 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6389 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6390 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6391 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
6393 GetClientRect(infoPtr->hwndSelf, &infoPtr->client_rect);
6394 TOOLBAR_AutoSize(infoPtr);
6395 return 0;
6399 static LRESULT
6400 TOOLBAR_StyleChanged (TOOLBAR_INFO *infoPtr, INT nType, const STYLESTRUCT *lpStyle)
6402 if (nType == GWL_STYLE)
6404 DWORD dwOldStyle = infoPtr->dwStyle;
6406 if (lpStyle->styleNew & TBSTYLE_LIST)
6407 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6408 else
6409 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6411 TOOLBAR_CheckStyle (infoPtr, lpStyle->styleNew);
6413 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6415 infoPtr->dwStyle = lpStyle->styleNew;
6417 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6418 TOOLBAR_LayoutToolbar(infoPtr);
6420 /* only resize if one of the CCS_* styles was changed */
6421 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6423 TOOLBAR_AutoSize (infoPtr);
6425 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
6429 return 0;
6433 static LRESULT
6434 TOOLBAR_SysColorChange ()
6436 COMCTL32_RefreshSysColors();
6438 return 0;
6442 /* update theme after a WM_THEMECHANGED message */
6443 static LRESULT theme_changed (HWND hwnd)
6445 HTHEME theme = GetWindowTheme (hwnd);
6446 CloseThemeData (theme);
6447 OpenThemeData (hwnd, themeClass);
6448 return 0;
6452 static LRESULT WINAPI
6453 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6455 TOOLBAR_INFO *infoPtr = (TOOLBAR_INFO *)GetWindowLongPtrW(hwnd, 0);
6457 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6458 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6460 if (!infoPtr && (uMsg != WM_NCCREATE))
6461 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6463 switch (uMsg)
6465 case TB_ADDBITMAP:
6466 return TOOLBAR_AddBitmap (infoPtr, (INT)wParam, (TBADDBITMAP*)lParam);
6468 case TB_ADDBUTTONSA:
6469 return TOOLBAR_AddButtonsT(infoPtr, wParam, (LPTBBUTTON)lParam, FALSE);
6471 case TB_ADDBUTTONSW:
6472 return TOOLBAR_AddButtonsT(infoPtr, wParam, (LPTBBUTTON)lParam, TRUE);
6474 case TB_ADDSTRINGA:
6475 return TOOLBAR_AddStringA (infoPtr, (HINSTANCE)wParam, lParam);
6477 case TB_ADDSTRINGW:
6478 return TOOLBAR_AddStringW (infoPtr, (HINSTANCE)wParam, lParam);
6480 case TB_AUTOSIZE:
6481 return TOOLBAR_AutoSize (infoPtr);
6483 case TB_BUTTONCOUNT:
6484 return TOOLBAR_ButtonCount (infoPtr);
6486 case TB_BUTTONSTRUCTSIZE:
6487 return TOOLBAR_ButtonStructSize (infoPtr, wParam);
6489 case TB_CHANGEBITMAP:
6490 return TOOLBAR_ChangeBitmap (infoPtr, wParam, LOWORD(lParam));
6492 case TB_CHECKBUTTON:
6493 return TOOLBAR_CheckButton (infoPtr, wParam, lParam);
6495 case TB_COMMANDTOINDEX:
6496 return TOOLBAR_CommandToIndex (infoPtr, wParam);
6498 case TB_CUSTOMIZE:
6499 return TOOLBAR_Customize (infoPtr);
6501 case TB_DELETEBUTTON:
6502 return TOOLBAR_DeleteButton (infoPtr, wParam);
6504 case TB_ENABLEBUTTON:
6505 return TOOLBAR_EnableButton (infoPtr, wParam, lParam);
6507 case TB_GETANCHORHIGHLIGHT:
6508 return TOOLBAR_GetAnchorHighlight (infoPtr);
6510 case TB_GETBITMAP:
6511 return TOOLBAR_GetBitmap (infoPtr, wParam);
6513 case TB_GETBITMAPFLAGS:
6514 return TOOLBAR_GetBitmapFlags ();
6516 case TB_GETBUTTON:
6517 return TOOLBAR_GetButton (infoPtr, wParam, (TBBUTTON*)lParam);
6519 case TB_GETBUTTONINFOA:
6520 return TOOLBAR_GetButtonInfoT(infoPtr, wParam, (LPTBBUTTONINFOW)lParam, FALSE);
6522 case TB_GETBUTTONINFOW:
6523 return TOOLBAR_GetButtonInfoT(infoPtr, wParam, (LPTBBUTTONINFOW)lParam, TRUE);
6525 case TB_GETBUTTONSIZE:
6526 return TOOLBAR_GetButtonSize (infoPtr);
6528 case TB_GETBUTTONTEXTA:
6529 return TOOLBAR_GetButtonTextA (infoPtr, wParam, (LPSTR)lParam);
6531 case TB_GETBUTTONTEXTW:
6532 return TOOLBAR_GetButtonTextW (infoPtr, wParam, (LPWSTR)lParam);
6534 case TB_GETDISABLEDIMAGELIST:
6535 return TOOLBAR_GetDisabledImageList (infoPtr, wParam);
6537 case TB_GETEXTENDEDSTYLE:
6538 return TOOLBAR_GetExtendedStyle (infoPtr);
6540 case TB_GETHOTIMAGELIST:
6541 return TOOLBAR_GetHotImageList (infoPtr, wParam);
6543 case TB_GETHOTITEM:
6544 return TOOLBAR_GetHotItem (infoPtr);
6546 case TB_GETIMAGELIST:
6547 return TOOLBAR_GetDefImageList (infoPtr, wParam);
6549 case TB_GETINSERTMARK:
6550 return TOOLBAR_GetInsertMark (infoPtr, (TBINSERTMARK*)lParam);
6552 case TB_GETINSERTMARKCOLOR:
6553 return TOOLBAR_GetInsertMarkColor (infoPtr);
6555 case TB_GETITEMRECT:
6556 return TOOLBAR_GetItemRect (infoPtr, wParam, (LPRECT)lParam);
6558 case TB_GETMAXSIZE:
6559 return TOOLBAR_GetMaxSize (infoPtr, (LPSIZE)lParam);
6561 /* case TB_GETOBJECT: */ /* 4.71 */
6563 case TB_GETPADDING:
6564 return TOOLBAR_GetPadding (infoPtr);
6566 case TB_GETRECT:
6567 return TOOLBAR_GetRect (infoPtr, wParam, (LPRECT)lParam);
6569 case TB_GETROWS:
6570 return TOOLBAR_GetRows (infoPtr);
6572 case TB_GETSTATE:
6573 return TOOLBAR_GetState (infoPtr, wParam);
6575 case TB_GETSTRINGA:
6576 return TOOLBAR_GetStringA (infoPtr, wParam, (LPSTR)lParam);
6578 case TB_GETSTRINGW:
6579 return TOOLBAR_GetStringW (infoPtr, wParam, (LPWSTR)lParam);
6581 case TB_GETSTYLE:
6582 return TOOLBAR_GetStyle (infoPtr);
6584 case TB_GETTEXTROWS:
6585 return TOOLBAR_GetTextRows (infoPtr);
6587 case TB_GETTOOLTIPS:
6588 return TOOLBAR_GetToolTips (infoPtr);
6590 case TB_GETUNICODEFORMAT:
6591 return TOOLBAR_GetUnicodeFormat (infoPtr);
6593 case TB_HIDEBUTTON:
6594 return TOOLBAR_HideButton (infoPtr, wParam, LOWORD(lParam));
6596 case TB_HITTEST:
6597 return TOOLBAR_HitTest (infoPtr, (LPPOINT)lParam);
6599 case TB_INDETERMINATE:
6600 return TOOLBAR_Indeterminate (infoPtr, wParam, LOWORD(lParam));
6602 case TB_INSERTBUTTONA:
6603 return TOOLBAR_InsertButtonT(infoPtr, wParam, (TBBUTTON*)lParam, FALSE);
6605 case TB_INSERTBUTTONW:
6606 return TOOLBAR_InsertButtonT(infoPtr, wParam, (TBBUTTON*)lParam, TRUE);
6608 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6610 case TB_ISBUTTONCHECKED:
6611 return TOOLBAR_IsButtonChecked (infoPtr, wParam);
6613 case TB_ISBUTTONENABLED:
6614 return TOOLBAR_IsButtonEnabled (infoPtr, wParam);
6616 case TB_ISBUTTONHIDDEN:
6617 return TOOLBAR_IsButtonHidden (infoPtr, wParam);
6619 case TB_ISBUTTONHIGHLIGHTED:
6620 return TOOLBAR_IsButtonHighlighted (infoPtr, wParam);
6622 case TB_ISBUTTONINDETERMINATE:
6623 return TOOLBAR_IsButtonIndeterminate (infoPtr, wParam);
6625 case TB_ISBUTTONPRESSED:
6626 return TOOLBAR_IsButtonPressed (infoPtr, wParam);
6628 case TB_LOADIMAGES:
6629 return TOOLBAR_LoadImages (infoPtr, wParam, (HINSTANCE)lParam);
6631 case TB_MAPACCELERATORA:
6632 case TB_MAPACCELERATORW:
6633 return TOOLBAR_MapAccelerator (infoPtr, wParam, (UINT*)lParam);
6635 case TB_MARKBUTTON:
6636 return TOOLBAR_MarkButton (infoPtr, wParam, LOWORD(lParam));
6638 case TB_MOVEBUTTON:
6639 return TOOLBAR_MoveButton (infoPtr, wParam, lParam);
6641 case TB_PRESSBUTTON:
6642 return TOOLBAR_PressButton (infoPtr, wParam, LOWORD(lParam));
6644 case TB_REPLACEBITMAP:
6645 return TOOLBAR_ReplaceBitmap (infoPtr, (LPTBREPLACEBITMAP)lParam);
6647 case TB_SAVERESTOREA:
6648 return TOOLBAR_SaveRestoreA (infoPtr, wParam, (LPTBSAVEPARAMSA)lParam);
6650 case TB_SAVERESTOREW:
6651 return TOOLBAR_SaveRestoreW (infoPtr, wParam, (LPTBSAVEPARAMSW)lParam);
6653 case TB_SETANCHORHIGHLIGHT:
6654 return TOOLBAR_SetAnchorHighlight (infoPtr, (BOOL)wParam);
6656 case TB_SETBITMAPSIZE:
6657 return TOOLBAR_SetBitmapSize (infoPtr, wParam, lParam);
6659 case TB_SETBUTTONINFOA:
6660 return TOOLBAR_SetButtonInfoA (infoPtr, wParam, (LPTBBUTTONINFOA)lParam);
6662 case TB_SETBUTTONINFOW:
6663 return TOOLBAR_SetButtonInfoW (infoPtr, wParam, (LPTBBUTTONINFOW)lParam);
6665 case TB_SETBUTTONSIZE:
6666 return TOOLBAR_SetButtonSize (infoPtr, lParam);
6668 case TB_SETBUTTONWIDTH:
6669 return TOOLBAR_SetButtonWidth (infoPtr, lParam);
6671 case TB_SETCMDID:
6672 return TOOLBAR_SetCmdId (infoPtr, wParam, lParam);
6674 case TB_SETDISABLEDIMAGELIST:
6675 return TOOLBAR_SetDisabledImageList (infoPtr, wParam, (HIMAGELIST)lParam);
6677 case TB_SETDRAWTEXTFLAGS:
6678 return TOOLBAR_SetDrawTextFlags (infoPtr, wParam, lParam);
6680 case TB_SETEXTENDEDSTYLE:
6681 return TOOLBAR_SetExtendedStyle (infoPtr, lParam);
6683 case TB_SETHOTIMAGELIST:
6684 return TOOLBAR_SetHotImageList (infoPtr, wParam, (HIMAGELIST)lParam);
6686 case TB_SETHOTITEM:
6687 return TOOLBAR_SetHotItem (infoPtr, wParam);
6689 case TB_SETIMAGELIST:
6690 return TOOLBAR_SetImageList (infoPtr, wParam, (HIMAGELIST)lParam);
6692 case TB_SETINDENT:
6693 return TOOLBAR_SetIndent (infoPtr, wParam);
6695 case TB_SETINSERTMARK:
6696 return TOOLBAR_SetInsertMark (infoPtr, (TBINSERTMARK*)lParam);
6698 case TB_SETINSERTMARKCOLOR:
6699 return TOOLBAR_SetInsertMarkColor (infoPtr, lParam);
6701 case TB_SETMAXTEXTROWS:
6702 return TOOLBAR_SetMaxTextRows (infoPtr, wParam);
6704 case TB_SETPADDING:
6705 return TOOLBAR_SetPadding (infoPtr, lParam);
6707 case TB_SETPARENT:
6708 return TOOLBAR_SetParent (infoPtr, (HWND)wParam);
6710 case TB_SETROWS:
6711 return TOOLBAR_SetRows (infoPtr, wParam, (LPRECT)lParam);
6713 case TB_SETSTATE:
6714 return TOOLBAR_SetState (infoPtr, wParam, lParam);
6716 case TB_SETSTYLE:
6717 return TOOLBAR_SetStyle (infoPtr, lParam);
6719 case TB_SETTOOLTIPS:
6720 return TOOLBAR_SetToolTips (infoPtr, (HWND)wParam);
6722 case TB_SETUNICODEFORMAT:
6723 return TOOLBAR_SetUnicodeFormat (infoPtr, wParam);
6725 case TB_UNKWN45D:
6726 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6728 case TB_SETHOTITEM2:
6729 return TOOLBAR_SetHotItem2 (infoPtr, wParam, lParam);
6731 case TB_SETLISTGAP:
6732 return TOOLBAR_SetListGap(infoPtr, wParam);
6734 case TB_GETIMAGELISTCOUNT:
6735 return TOOLBAR_GetImageListCount(infoPtr);
6737 case TB_GETIDEALSIZE:
6738 return TOOLBAR_GetIdealSize (infoPtr, wParam, lParam);
6740 case TB_UNKWN464:
6741 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6743 /* Common Control Messages */
6745 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6746 case CCM_GETCOLORSCHEME:
6747 return TOOLBAR_GetColorScheme (infoPtr, (LPCOLORSCHEME)lParam);
6749 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6750 case CCM_SETCOLORSCHEME:
6751 return TOOLBAR_SetColorScheme (infoPtr, (LPCOLORSCHEME)lParam);
6753 case CCM_GETVERSION:
6754 return TOOLBAR_GetVersion (infoPtr);
6756 case CCM_SETVERSION:
6757 return TOOLBAR_SetVersion (infoPtr, (INT)wParam);
6760 /* case WM_CHAR: */
6762 case WM_CREATE:
6763 return TOOLBAR_Create (hwnd, (CREATESTRUCTW*)lParam);
6765 case WM_DESTROY:
6766 return TOOLBAR_Destroy (infoPtr);
6768 case WM_ERASEBKGND:
6769 return TOOLBAR_EraseBackground (infoPtr, wParam, lParam);
6771 case WM_GETFONT:
6772 return TOOLBAR_GetFont (infoPtr);
6774 case WM_KEYDOWN:
6775 return TOOLBAR_KeyDown (infoPtr, wParam, lParam);
6777 /* case WM_KILLFOCUS: */
6779 case WM_LBUTTONDBLCLK:
6780 return TOOLBAR_LButtonDblClk (infoPtr, wParam, lParam);
6782 case WM_LBUTTONDOWN:
6783 return TOOLBAR_LButtonDown (infoPtr, wParam, lParam);
6785 case WM_LBUTTONUP:
6786 return TOOLBAR_LButtonUp (infoPtr, wParam, lParam);
6788 case WM_RBUTTONUP:
6789 return TOOLBAR_RButtonUp (infoPtr, wParam, lParam);
6791 case WM_RBUTTONDBLCLK:
6792 return TOOLBAR_RButtonDblClk (infoPtr, wParam, lParam);
6794 case WM_MOUSEMOVE:
6795 return TOOLBAR_MouseMove (infoPtr, wParam, lParam);
6797 case WM_MOUSELEAVE:
6798 return TOOLBAR_MouseLeave (infoPtr);
6800 case WM_CAPTURECHANGED:
6801 return TOOLBAR_CaptureChanged(infoPtr);
6803 case WM_NCACTIVATE:
6804 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6806 case WM_NCCALCSIZE:
6807 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6809 case WM_NCCREATE:
6810 return TOOLBAR_NCCreate (hwnd, wParam, (CREATESTRUCTW*)lParam);
6812 case WM_NCPAINT:
6813 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6815 case WM_NOTIFY:
6816 return TOOLBAR_Notify (infoPtr, (LPNMHDR)lParam);
6818 case WM_NOTIFYFORMAT:
6819 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
6821 case WM_PRINTCLIENT:
6822 case WM_PAINT:
6823 return TOOLBAR_Paint (infoPtr, wParam);
6825 case WM_SETFOCUS:
6826 return TOOLBAR_SetFocus (infoPtr);
6828 case WM_SETFONT:
6829 return TOOLBAR_SetFont(infoPtr, (HFONT)wParam, (WORD)lParam);
6831 case WM_SETREDRAW:
6832 return TOOLBAR_SetRedraw (infoPtr, wParam);
6834 case WM_SIZE:
6835 return TOOLBAR_Size (infoPtr);
6837 case WM_STYLECHANGED:
6838 return TOOLBAR_StyleChanged (infoPtr, (INT)wParam, (LPSTYLESTRUCT)lParam);
6840 case WM_SYSCOLORCHANGE:
6841 return TOOLBAR_SysColorChange ();
6843 case WM_THEMECHANGED:
6844 return theme_changed (hwnd);
6846 /* case WM_WININICHANGE: */
6848 case WM_CHARTOITEM:
6849 case WM_COMMAND:
6850 case WM_DRAWITEM:
6851 case WM_MEASUREITEM:
6852 case WM_VKEYTOITEM:
6853 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
6855 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6856 case PGM_FORWARDMOUSE:
6857 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
6859 default:
6860 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
6861 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
6862 uMsg, wParam, lParam);
6863 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
6868 VOID
6869 TOOLBAR_Register (void)
6871 WNDCLASSW wndClass;
6873 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
6874 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6875 wndClass.lpfnWndProc = ToolbarWindowProc;
6876 wndClass.cbClsExtra = 0;
6877 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6878 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
6879 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
6880 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
6882 RegisterClassW (&wndClass);
6886 VOID
6887 TOOLBAR_Unregister (void)
6889 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
6892 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6894 HIMAGELIST himlold;
6895 PIMLENTRY c = NULL;
6897 /* Check if the entry already exists */
6898 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6900 /* If this is a new entry we must create it and insert into the array */
6901 if (!c)
6903 PIMLENTRY *pnies;
6905 c = Alloc(sizeof(IMLENTRY));
6906 c->id = id;
6908 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
6909 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6910 pnies[*cies] = c;
6911 (*cies)++;
6913 Free(*pies);
6914 *pies = pnies;
6917 himlold = c->himl;
6918 c->himl = himl;
6920 return himlold;
6924 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6926 int i;
6928 for (i = 0; i < *cies; i++)
6929 Free((*pies)[i]);
6931 Free(*pies);
6933 *cies = 0;
6934 *pies = NULL;
6938 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id)
6940 PIMLENTRY c = NULL;
6942 if (pies != NULL)
6944 int i;
6946 for (i = 0; i < cies; i++)
6948 if (pies[i]->id == id)
6950 c = pies[i];
6951 break;
6956 return c;
6960 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id)
6962 HIMAGELIST himlDef = 0;
6963 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6965 if (pie)
6966 himlDef = pie->himl;
6968 return himlDef;
6972 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6974 if (infoPtr->bUnicode)
6975 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
6976 else
6978 CHAR Buffer[256];
6979 NMTOOLBARA nmtba;
6980 BOOL bRet = FALSE;
6982 nmtba.iItem = nmtb->iItem;
6983 nmtba.pszText = Buffer;
6984 nmtba.cchText = 256;
6985 ZeroMemory(nmtba.pszText, nmtba.cchText);
6987 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
6989 int ccht = strlen(nmtba.pszText);
6990 if (ccht)
6991 MultiByteToWideChar(CP_ACP, 0, nmtba.pszText, -1,
6992 nmtb->pszText, nmtb->cchText);
6994 nmtb->tbButton = nmtba.tbButton;
6995 bRet = TRUE;
6998 return bRet;
7003 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, const CUSTOMBUTTON *btnInfo)
7005 NMTOOLBARW nmtb;
7007 /* MSDN states that iItem is the index of the button, rather than the
7008 * command ID as used by every other NMTOOLBAR notification */
7009 nmtb.iItem = iItem;
7010 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7012 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);