push 73336d9f381967eae40f391d78198b916ed9848d
[wine/hacks.git] / dlls / comctl32 / toolbar.c
blob1bda0ccca631a3f8f6b925c9655c577b36ab6c54
1 /*
2 * Toolbar control
4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * NOTES
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
31 * TODO:
32 * - Styles:
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
35 * - Messages:
36 * - TB_GETMETRICS
37 * - TB_GETOBJECT
38 * - TB_INSERTMARKHITTEST
39 * - TB_SAVERESTORE
40 * - TB_SETMETRICS
41 * - WM_WININICHANGE
42 * - Notifications:
43 * - NM_CHAR
44 * - TBN_GETOBJECT
45 * - TBN_SAVE
46 * - Button wrapping (under construction).
47 * - Fix TB_SETROWS and Separators.
48 * - iListGap custom draw support.
50 * Testing:
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
71 #include <stdarg.h>
72 #include <string.h>
74 #include "windef.h"
75 #include "winbase.h"
76 #include "winreg.h"
77 #include "wingdi.h"
78 #include "winuser.h"
79 #include "wine/unicode.h"
80 #include "winnls.h"
81 #include "commctrl.h"
82 #include "comctl32.h"
83 #include "uxtheme.h"
84 #include "tmschema.h"
85 #include "wine/debug.h"
87 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
89 static HCURSOR hCursorDrag = NULL;
91 typedef struct
93 INT iBitmap;
94 INT idCommand;
95 BYTE fsState;
96 BYTE fsStyle;
97 BYTE bHot;
98 BYTE bDropDownPressed;
99 DWORD_PTR dwData;
100 INT_PTR iString;
101 INT nRow;
102 RECT rect;
103 INT cx; /* manually set size */
104 } TBUTTON_INFO;
106 typedef struct
108 UINT nButtons;
109 HINSTANCE hInst;
110 UINT nID;
111 } TBITMAP_INFO;
113 typedef struct
115 HIMAGELIST himl;
116 INT id;
117 } IMLENTRY, *PIMLENTRY;
119 typedef struct
121 DWORD dwStructSize; /* size of TBBUTTON struct */
122 INT nWidth; /* width of the toolbar */
123 RECT client_rect;
124 RECT rcBound; /* bounding rectangle */
125 INT nButtonHeight;
126 INT nButtonWidth;
127 INT nBitmapHeight;
128 INT nBitmapWidth;
129 INT nIndent;
130 INT nRows; /* number of button rows */
131 INT nMaxTextRows; /* maximum number of text rows */
132 INT cxMin; /* minimum button width */
133 INT cxMax; /* maximum button width */
134 INT nNumButtons; /* number of buttons */
135 INT nNumBitmaps; /* number of bitmaps */
136 INT nNumStrings; /* number of strings */
137 INT nNumBitmapInfos;
138 INT nButtonDown; /* toolbar button being pressed or -1 if none */
139 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
140 INT nOldHit;
141 INT nHotItem; /* index of the "hot" item */
142 SIZE szPadding; /* padding values around button */
143 INT iTopMargin; /* the top margin */
144 INT iListGap; /* default gap between text and image for toolbar with list style */
145 HFONT hDefaultFont;
146 HFONT hFont; /* text font */
147 HIMAGELIST himlInt; /* image list created internally */
148 PIMLENTRY *himlDef; /* default image list array */
149 INT cimlDef; /* default image list array count */
150 PIMLENTRY *himlHot; /* hot image list array */
151 INT cimlHot; /* hot image list array count */
152 PIMLENTRY *himlDis; /* disabled image list array */
153 INT cimlDis; /* disabled image list array count */
154 HWND hwndToolTip; /* handle to tool tip control */
155 HWND hwndNotify; /* handle to the window that gets notifications */
156 HWND hwndSelf; /* my own handle */
157 BOOL bAnchor; /* anchor highlight enabled */
158 BOOL bDoRedraw; /* Redraw status */
159 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
160 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
161 BOOL bCaptured; /* mouse captured? */
162 DWORD dwStyle; /* regular toolbar style */
163 DWORD dwExStyle; /* extended toolbar style */
164 DWORD dwDTFlags; /* DrawText flags */
166 COLORREF clrInsertMark; /* insert mark color */
167 COLORREF clrBtnHighlight; /* color for Flat Separator */
168 COLORREF clrBtnShadow; /* color for Flag Separator */
169 INT iVersion;
170 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
171 * for TTN_GETDISPINFOW notification */
172 TBINSERTMARK tbim; /* info on insertion mark */
173 TBUTTON_INFO *buttons; /* pointer to button array */
174 LPWSTR *strings; /* pointer to string array */
175 TBITMAP_INFO *bitmaps;
176 } TOOLBAR_INFO, *PTOOLBAR_INFO;
179 /* used by customization dialog */
180 typedef struct
182 PTOOLBAR_INFO tbInfo;
183 HWND tbHwnd;
184 } CUSTDLG_INFO, *PCUSTDLG_INFO;
186 typedef struct
188 TBBUTTON btn;
189 BOOL bVirtual;
190 BOOL bRemovable;
191 WCHAR text[64];
192 } CUSTOMBUTTON, *PCUSTOMBUTTON;
194 typedef enum
196 IMAGE_LIST_DEFAULT,
197 IMAGE_LIST_HOT,
198 IMAGE_LIST_DISABLED
199 } IMAGE_LIST_TYPE;
201 #define SEPARATOR_WIDTH 8
202 #define TOP_BORDER 2
203 #define BOTTOM_BORDER 2
204 #define DDARROW_WIDTH 11
205 #define ARROW_HEIGHT 3
206 #define INSERTMARK_WIDTH 2
208 #define DEFPAD_CX 7
209 #define DEFPAD_CY 6
210 #define DEFLISTGAP 4
212 /* vertical padding used in list mode when image is present */
213 #define LISTPAD_CY 9
215 /* how wide to treat the bitmap if it isn't present */
216 #define NONLIST_NOTEXT_OFFSET 2
218 #define TOOLBAR_NOWHERE (-1)
220 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
221 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
222 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
224 /* Used to find undocumented extended styles */
225 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
226 TBSTYLE_EX_UNDOC1 | \
227 TBSTYLE_EX_MIXEDBUTTONS | \
228 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
230 /* all of the CCS_ styles */
231 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
232 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
234 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
235 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
236 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
237 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
238 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
240 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
242 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
243 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
244 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id);
245 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id);
246 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
247 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
248 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
249 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
250 static void TOOLBAR_LayoutToolbar(HWND hwnd);
251 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
252 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
253 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
255 static LRESULT
256 TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
258 static inline int default_top_margin(const TOOLBAR_INFO *infoPtr)
260 return (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
263 static LPWSTR
264 TOOLBAR_GetText(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr)
266 LPWSTR lpText = NULL;
268 /* NOTE: iString == -1 is undocumented */
269 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
270 lpText = (LPWSTR)btnPtr->iString;
271 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
272 lpText = infoPtr->strings[btnPtr->iString];
274 return lpText;
277 static void
278 TOOLBAR_DumpButton(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *bP, INT btn_num, BOOL internal)
280 if (TRACE_ON(toolbar)){
281 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
282 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
283 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
284 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
285 if (internal)
286 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n",
287 btn_num, bP->idCommand,
288 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
289 wine_dbgstr_rect(&bP->rect));
294 static void
295 TOOLBAR_DumpToolbar(const TOOLBAR_INFO *iP, INT line)
297 if (TRACE_ON(toolbar)) {
298 INT i;
300 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
301 iP->hwndSelf, line,
302 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
303 iP->nNumStrings, iP->dwStyle);
304 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
305 iP->hwndSelf, line,
306 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
307 (iP->bDoRedraw) ? "TRUE" : "FALSE");
308 for(i=0; i<iP->nNumButtons; i++) {
309 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
315 /***********************************************************************
316 * TOOLBAR_CheckStyle
318 * This function validates that the styles set are implemented and
319 * issues FIXME's warning of possible problems. In a perfect world this
320 * function should be null.
322 static void
323 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
325 if (dwStyle & TBSTYLE_REGISTERDROP)
326 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
330 static INT
331 TOOLBAR_SendNotify (NMHDR *nmhdr, const TOOLBAR_INFO *infoPtr, UINT code)
333 if(!IsWindow(infoPtr->hwndSelf))
334 return 0; /* we have just been destroyed */
336 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
337 nmhdr->hwndFrom = infoPtr->hwndSelf;
338 nmhdr->code = code;
340 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
341 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
343 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
346 /***********************************************************************
347 * TOOLBAR_GetBitmapIndex
349 * This function returns the bitmap index associated with a button.
350 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
351 * is issued to retrieve the index.
353 static INT
354 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
356 INT ret = btnPtr->iBitmap;
358 if (ret == I_IMAGECALLBACK)
360 /* issue TBN_GETDISPINFO */
361 NMTBDISPINFOW nmgd;
363 memset(&nmgd, 0, sizeof(nmgd));
364 nmgd.idCommand = btnPtr->idCommand;
365 nmgd.lParam = btnPtr->dwData;
366 nmgd.dwMask = TBNF_IMAGE;
367 nmgd.iImage = -1;
368 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
369 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr, TBN_GETDISPINFOW);
370 if (nmgd.dwMask & TBNF_DI_SETITEM)
371 btnPtr->iBitmap = nmgd.iImage;
372 ret = nmgd.iImage;
373 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
374 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
377 if (ret != I_IMAGENONE)
378 ret = GETIBITMAP(infoPtr, ret);
380 return ret;
384 static BOOL
385 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO *infoPtr, INT index)
387 HIMAGELIST himl;
388 INT id = GETHIMLID(infoPtr, index);
389 INT iBitmap = GETIBITMAP(infoPtr, index);
391 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
392 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
393 (index == I_IMAGECALLBACK))
394 return TRUE;
395 else
396 return FALSE;
400 static inline BOOL
401 TOOLBAR_IsValidImageList(const TOOLBAR_INFO *infoPtr, INT index)
403 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
404 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
408 /***********************************************************************
409 * TOOLBAR_GetImageListForDrawing
411 * This function validates the bitmap index (including I_IMAGECALLBACK
412 * functionality) and returns the corresponding image list.
414 static HIMAGELIST
415 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
416 IMAGE_LIST_TYPE imagelist, INT * index)
418 HIMAGELIST himl;
420 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
421 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
422 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
423 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
424 return NULL;
427 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
428 if ((*index == I_IMAGECALLBACK) ||
429 (*index == I_IMAGENONE)) return NULL;
430 ERR("TBN_GETDISPINFO returned invalid index %d\n",
431 *index);
432 return NULL;
435 switch(imagelist)
437 case IMAGE_LIST_DEFAULT:
438 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
439 break;
440 case IMAGE_LIST_HOT:
441 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
442 break;
443 case IMAGE_LIST_DISABLED:
444 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
445 break;
446 default:
447 himl = NULL;
448 FIXME("Shouldn't reach here\n");
451 if (!himl)
452 TRACE("no image list\n");
454 return himl;
458 static void
459 TOOLBAR_DrawFlatSeparator (const RECT *lpRect, HDC hdc, const TOOLBAR_INFO *infoPtr)
461 RECT myrect;
462 COLORREF oldcolor, newcolor;
464 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
465 myrect.right = myrect.left + 1;
466 myrect.top = lpRect->top + 2;
467 myrect.bottom = lpRect->bottom - 2;
469 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
470 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
471 oldcolor = SetBkColor (hdc, newcolor);
472 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
474 myrect.left = myrect.right;
475 myrect.right = myrect.left + 1;
477 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
478 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
479 SetBkColor (hdc, newcolor);
480 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
482 SetBkColor (hdc, oldcolor);
486 /***********************************************************************
487 * TOOLBAR_DrawDDFlatSeparator
489 * This function draws the separator that was flagged as BTNS_DROPDOWN.
490 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
491 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
492 * are horizontal as opposed to the vertical separators for not dropdown
493 * type.
495 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
497 static void
498 TOOLBAR_DrawDDFlatSeparator (const RECT *lpRect, HDC hdc, const TBUTTON_INFO *btnPtr,
499 const TOOLBAR_INFO *infoPtr)
501 RECT myrect;
502 COLORREF oldcolor, newcolor;
504 myrect.left = lpRect->left;
505 myrect.right = lpRect->right;
506 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
507 myrect.bottom = myrect.top + 1;
509 InflateRect (&myrect, -2, 0);
511 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect));
513 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
514 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
515 oldcolor = SetBkColor (hdc, newcolor);
516 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
518 myrect.top = myrect.bottom;
519 myrect.bottom = myrect.top + 1;
521 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
522 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
523 SetBkColor (hdc, newcolor);
524 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
526 SetBkColor (hdc, oldcolor);
530 static void
531 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
533 INT x, y;
534 HPEN hPen, hOldPen;
536 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
537 hOldPen = SelectObject ( hdc, hPen );
538 x = left + 2;
539 y = top;
540 MoveToEx (hdc, x, y, NULL);
541 LineTo (hdc, x+5, y++); x++;
542 MoveToEx (hdc, x, y, NULL);
543 LineTo (hdc, x+3, y++); x++;
544 MoveToEx (hdc, x, y, NULL);
545 LineTo (hdc, x+1, y++);
546 SelectObject( hdc, hOldPen );
547 DeleteObject( hPen );
551 * Draw the text string for this button.
552 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
553 * is non-zero, so we can simply check himlDef to see if we have
554 * an image list
556 static void
557 TOOLBAR_DrawString (const TOOLBAR_INFO *infoPtr, RECT *rcText, LPCWSTR lpText,
558 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
560 HDC hdc = tbcd->nmcd.hdc;
561 HFONT hOldFont = 0;
562 COLORREF clrOld = 0;
563 COLORREF clrOldBk = 0;
564 int oldBkMode = 0;
565 UINT state = tbcd->nmcd.uItemState;
567 /* draw text */
568 if (lpText) {
569 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText),
570 wine_dbgstr_rect(rcText));
572 hOldFont = SelectObject (hdc, infoPtr->hFont);
573 if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
574 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
576 else if (state & CDIS_DISABLED) {
577 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
578 OffsetRect (rcText, 1, 1);
579 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
580 SetTextColor (hdc, comctl32_color.clr3dShadow);
581 OffsetRect (rcText, -1, -1);
583 else if (state & CDIS_INDETERMINATE) {
584 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
586 else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
587 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
588 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
589 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
591 else {
592 clrOld = SetTextColor (hdc, tbcd->clrText);
595 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
596 SetTextColor (hdc, clrOld);
597 if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
599 SetBkColor (hdc, clrOldBk);
600 SetBkMode (hdc, oldBkMode);
602 SelectObject (hdc, hOldFont);
607 static void
608 TOOLBAR_DrawPattern (const RECT *lpRect, const NMTBCUSTOMDRAW *tbcd)
610 HDC hdc = tbcd->nmcd.hdc;
611 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
612 COLORREF clrTextOld;
613 COLORREF clrBkOld;
614 INT cx = lpRect->right - lpRect->left;
615 INT cy = lpRect->bottom - lpRect->top;
616 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
617 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
618 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
619 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
620 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
621 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
622 SetBkColor(hdc, clrBkOld);
623 SetTextColor(hdc, clrTextOld);
624 SelectObject (hdc, hbr);
628 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
630 INT cx, cy;
631 HBITMAP hbmMask, hbmImage;
632 HDC hdcMask, hdcImage;
634 ImageList_GetIconSize(himl, &cx, &cy);
636 /* Create src image */
637 hdcImage = CreateCompatibleDC(hdc);
638 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
639 SelectObject(hdcImage, hbmImage);
640 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
641 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
643 /* Create Mask */
644 hdcMask = CreateCompatibleDC(0);
645 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
646 SelectObject(hdcMask, hbmMask);
648 /* Remove the background and all white pixels */
649 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
650 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
651 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
652 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
654 /* draw the new mask 'etched' to hdc */
655 SetBkColor(hdc, RGB(255, 255, 255));
656 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
657 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
658 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
659 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
660 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
662 /* Cleanup */
663 DeleteObject(hbmImage);
664 DeleteDC(hdcImage);
665 DeleteObject (hbmMask);
666 DeleteDC(hdcMask);
670 static UINT
671 TOOLBAR_TranslateState(const TBUTTON_INFO *btnPtr)
673 UINT retstate = 0;
675 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
676 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
677 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
678 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
679 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
680 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
681 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
682 return retstate;
685 /* draws the image on a toolbar button */
686 static void
687 TOOLBAR_DrawImage(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
688 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
690 HIMAGELIST himl = NULL;
691 BOOL draw_masked = FALSE;
692 INT index;
693 INT offset = 0;
694 UINT draw_flags = ILD_TRANSPARENT;
696 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
698 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
699 if (!himl)
701 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
702 draw_masked = TRUE;
705 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
706 ((tbcd->nmcd.uItemState & CDIS_HOT)
707 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
709 /* if hot, attempt to draw with hot image list, if fails,
710 use default image list */
711 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
712 if (!himl)
713 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
715 else
716 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
718 if (!himl)
719 return;
721 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
722 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
723 offset = 1;
725 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
726 (tbcd->nmcd.uItemState & CDIS_MARKED))
727 draw_flags |= ILD_BLEND50;
729 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
730 index, himl, left, top, offset);
732 if (draw_masked)
733 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
734 else
735 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
738 /* draws a blank frame for a toolbar button */
739 static void
740 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
742 HDC hdc = tbcd->nmcd.hdc;
743 RECT rc = tbcd->nmcd.rc;
744 /* if the state is disabled or indeterminate then the button
745 * cannot have an interactive look like pressed or hot */
746 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
747 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
748 BOOL pressed_look = !non_interactive_state &&
749 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
750 (tbcd->nmcd.uItemState & CDIS_CHECKED));
752 /* app don't want us to draw any edges */
753 if (dwItemCDFlag & TBCDRF_NOEDGES)
754 return;
756 if (infoPtr->dwStyle & TBSTYLE_FLAT)
758 if (pressed_look)
759 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
760 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
761 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
763 else
765 if (pressed_look)
766 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
767 else
768 DrawEdge (hdc, &rc, EDGE_RAISED,
769 BF_SOFT | BF_RECT | BF_MIDDLE);
773 static void
774 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
776 HDC hdc = tbcd->nmcd.hdc;
777 int offset = 0;
778 BOOL pressed = bDropDownPressed ||
779 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
781 if (infoPtr->dwStyle & TBSTYLE_FLAT)
783 if (pressed)
784 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
785 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
786 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
787 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
788 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
790 else
792 if (pressed)
793 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
794 else
795 DrawEdge (hdc, rcArrow, EDGE_RAISED,
796 BF_SOFT | BF_RECT | BF_MIDDLE);
799 if (pressed)
800 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
802 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
804 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
805 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
807 else
808 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
811 /* draws a complete toolbar button */
812 static void
813 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
815 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
816 DWORD dwStyle = infoPtr->dwStyle;
817 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
818 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
819 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
820 BOOL drawSepDropDownArrow = hasDropDownArrow &&
821 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
822 RECT rc, rcArrow, rcBitmap, rcText;
823 LPWSTR lpText = NULL;
824 NMTBCUSTOMDRAW tbcd;
825 DWORD ntfret;
826 INT offset;
827 INT oldBkMode;
828 DWORD dwItemCustDraw;
829 DWORD dwItemCDFlag;
830 HTHEME theme = GetWindowTheme (hwnd);
832 rc = btnPtr->rect;
833 CopyRect (&rcArrow, &rc);
835 /* separator - doesn't send NM_CUSTOMDRAW */
836 if (btnPtr->fsStyle & BTNS_SEP) {
837 if (theme)
839 DrawThemeBackground (theme, hdc,
840 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
841 &rc, NULL);
843 else
844 /* with the FLAT style, iBitmap is the width and has already */
845 /* been taken into consideration in calculating the width */
846 /* so now we need to draw the vertical separator */
847 /* empirical tests show that iBitmap can/will be non-zero */
848 /* when drawing the vertical bar... */
849 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
850 if (btnPtr->fsStyle & BTNS_DROPDOWN)
851 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
852 else
853 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
855 else if (btnPtr->fsStyle != BTNS_SEP) {
856 FIXME("Draw some kind of separator: fsStyle=%x\n",
857 btnPtr->fsStyle);
859 return;
862 /* get a pointer to the text */
863 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
865 if (hasDropDownArrow)
867 int right;
869 if (dwStyle & TBSTYLE_FLAT)
870 right = max(rc.left, rc.right - DDARROW_WIDTH);
871 else
872 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
874 if (drawSepDropDownArrow)
875 rc.right = right;
877 rcArrow.left = right;
880 /* copy text & bitmap rects after adjusting for drop-down arrow
881 * so that text & bitmap is centered in the rectangle not containing
882 * the arrow */
883 CopyRect(&rcText, &rc);
884 CopyRect(&rcBitmap, &rc);
886 /* Center the bitmap horizontally and vertically */
887 if (dwStyle & TBSTYLE_LIST)
889 if (lpText &&
890 infoPtr->nMaxTextRows > 0 &&
891 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
892 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
893 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
894 else
895 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
897 else
898 rcBitmap.left += ((rc.right - rc.left) - infoPtr->nBitmapWidth) / 2;
900 rcBitmap.top += infoPtr->szPadding.cy / 2;
902 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
903 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
904 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
905 TRACE("Text=%s\n", debugstr_w(lpText));
906 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
908 /* calculate text position */
909 if (lpText)
911 rcText.left += GetSystemMetrics(SM_CXEDGE);
912 rcText.right -= GetSystemMetrics(SM_CXEDGE);
913 if (dwStyle & TBSTYLE_LIST)
915 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
916 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
918 else
920 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
921 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
922 else
923 rcText.top += infoPtr->szPadding.cy/2 + 2;
927 /* Initialize fields in all cases, because we use these later
928 * NOTE: applications can and do alter these to customize their
929 * toolbars */
930 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
931 tbcd.clrText = comctl32_color.clrBtnText;
932 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
933 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
934 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
935 tbcd.clrMark = comctl32_color.clrHighlight;
936 tbcd.clrHighlightHotTrack = 0;
937 tbcd.nStringBkMode = TRANSPARENT;
938 tbcd.nHLStringBkMode = OPAQUE;
939 /* MSDN says that this is the text rectangle.
940 * But (why always a but) tracing of v5.7 of native shows
941 * that this is really a *relative* rectangle based on the
942 * the nmcd.rc. Also the left and top are always 0 ignoring
943 * any bitmap that might be present. */
944 tbcd.rcText.left = 0;
945 tbcd.rcText.top = 0;
946 tbcd.rcText.right = rcText.right - rc.left;
947 tbcd.rcText.bottom = rcText.bottom - rc.top;
948 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
949 tbcd.nmcd.hdc = hdc;
950 tbcd.nmcd.rc = rc;
951 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
953 /* FIXME: what are these used for? */
954 tbcd.hbrLines = 0;
955 tbcd.hpenLines = 0;
957 /* Issue Item Prepaint notify */
958 dwItemCustDraw = 0;
959 dwItemCDFlag = 0;
960 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
962 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
963 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
964 tbcd.nmcd.lItemlParam = btnPtr->dwData;
965 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
966 /* reset these fields so the user can't alter the behaviour like native */
967 tbcd.nmcd.hdc = hdc;
968 tbcd.nmcd.rc = rc;
970 dwItemCustDraw = ntfret & 0xffff;
971 dwItemCDFlag = ntfret & 0xffff0000;
972 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
973 return;
974 /* save the only part of the rect that the user can change */
975 rcText.right = tbcd.rcText.right + rc.left;
976 rcText.bottom = tbcd.rcText.bottom + rc.top;
979 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
980 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
981 OffsetRect(&rcText, 1, 1);
983 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
984 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
985 TOOLBAR_DrawPattern (&rc, &tbcd);
987 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
988 && (tbcd.nmcd.uItemState & CDIS_HOT))
990 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
992 COLORREF oldclr;
994 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
995 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
996 if (hasDropDownArrow)
997 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
998 SetBkColor(hdc, oldclr);
1002 if (theme)
1004 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1005 int stateId = TS_NORMAL;
1007 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1008 stateId = TS_DISABLED;
1009 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1010 stateId = TS_PRESSED;
1011 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1012 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1013 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1014 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1015 stateId = TS_HOT;
1017 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1019 else
1020 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1022 if (drawSepDropDownArrow)
1024 if (theme)
1026 int stateId = TS_NORMAL;
1028 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1029 stateId = TS_DISABLED;
1030 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1031 stateId = TS_PRESSED;
1032 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1033 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1034 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1035 stateId = TS_HOT;
1037 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1038 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1040 else
1041 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1044 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1045 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1046 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1047 SetBkMode (hdc, oldBkMode);
1049 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1051 if (hasDropDownArrow && !drawSepDropDownArrow)
1053 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1055 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1056 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1058 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1060 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1061 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1063 else
1064 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1067 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1069 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1070 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1076 static void
1077 TOOLBAR_Refresh (HWND hwnd, HDC hdc, const PAINTSTRUCT *ps)
1079 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1080 TBUTTON_INFO *btnPtr;
1081 INT i;
1082 RECT rcTemp, rcClient;
1083 NMTBCUSTOMDRAW tbcd;
1084 DWORD ntfret;
1085 DWORD dwBaseCustDraw;
1087 /* the app has told us not to redraw the toolbar */
1088 if (!infoPtr->bDoRedraw)
1089 return;
1091 /* if imagelist belongs to the app, it can be changed
1092 by the app after setting it */
1093 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1095 infoPtr->nNumBitmaps = 0;
1096 for (i = 0; i < infoPtr->cimlDef; i++)
1097 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1100 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1102 /* change the imagelist icon size if we manage the list and it is necessary */
1103 TOOLBAR_CheckImageListIconSize(infoPtr);
1105 /* Send initial notify */
1106 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1107 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1108 tbcd.nmcd.hdc = hdc;
1109 tbcd.nmcd.rc = ps->rcPaint;
1110 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1111 dwBaseCustDraw = ntfret & 0xffff;
1113 GetClientRect(hwnd, &rcClient);
1115 /* redraw necessary buttons */
1116 btnPtr = infoPtr->buttons;
1117 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1119 BOOL bDraw;
1120 if (!RectVisible(hdc, &btnPtr->rect))
1121 continue;
1122 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1124 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1125 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1127 else
1128 bDraw = TRUE;
1129 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1130 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1131 if (bDraw)
1132 TOOLBAR_DrawButton(hwnd, btnPtr, hdc, dwBaseCustDraw);
1135 /* draw insert mark if required */
1136 if (infoPtr->tbim.iButton != -1)
1138 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1139 RECT rcInsertMark;
1140 rcInsertMark.top = rcButton.top;
1141 rcInsertMark.bottom = rcButton.bottom;
1142 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1143 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1144 else
1145 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1146 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1149 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1151 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1152 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1153 tbcd.nmcd.hdc = hdc;
1154 tbcd.nmcd.rc = ps->rcPaint;
1155 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1159 /***********************************************************************
1160 * TOOLBAR_MeasureString
1162 * This function gets the width and height of a string in pixels. This
1163 * is done first by using GetTextExtentPoint to get the basic width
1164 * and height. The DrawText is called with DT_CALCRECT to get the exact
1165 * width. The reason is because the text may have more than one "&" (or
1166 * prefix characters as M$ likes to call them). The prefix character
1167 * indicates where the underline goes, except for the string "&&" which
1168 * is reduced to a single "&". GetTextExtentPoint does not process these
1169 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1171 static void
1172 TOOLBAR_MeasureString(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr,
1173 HDC hdc, LPSIZE lpSize)
1175 RECT myrect;
1177 lpSize->cx = 0;
1178 lpSize->cy = 0;
1180 if (infoPtr->nMaxTextRows > 0 &&
1181 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1182 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1183 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1185 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1187 if(lpText != NULL) {
1188 /* first get size of all the text */
1189 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1191 /* feed above size into the rectangle for DrawText */
1192 myrect.left = myrect.top = 0;
1193 myrect.right = lpSize->cx;
1194 myrect.bottom = lpSize->cy;
1196 /* Use DrawText to get true size as drawn (less pesky "&") */
1197 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1198 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1199 DT_NOPREFIX : 0));
1201 /* feed back to caller */
1202 lpSize->cx = myrect.right;
1203 lpSize->cy = myrect.bottom;
1207 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1210 /***********************************************************************
1211 * TOOLBAR_CalcStrings
1213 * This function walks through each string and measures it and returns
1214 * the largest height and width to caller.
1216 static void
1217 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1219 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
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 (hwnd);
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 (hwnd, 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( HWND hwnd, DWORD dwStyle )
1279 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1280 TBUTTON_INFO *btnPtr;
1281 INT x, cx, i, j;
1282 RECT rc;
1283 BOOL bWrap, bButtonWrap;
1285 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1286 /* no layout is necessary. Applications may use this style */
1287 /* to perform their own layout on the toolbar. */
1288 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1289 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1291 btnPtr = infoPtr->buttons;
1292 x = infoPtr->nIndent;
1294 if (GetParent(hwnd))
1296 /* this can get the parents width, to know how far we can extend
1297 * this toolbar. We cannot use its height, as there may be multiple
1298 * toolbars in a rebar control
1300 GetClientRect( GetParent(hwnd), &rc );
1301 infoPtr->nWidth = rc.right - rc.left;
1303 else
1305 GetWindowRect( hwnd, &rc );
1306 infoPtr->nWidth = rc.right - rc.left;
1309 bButtonWrap = FALSE;
1311 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1312 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1313 infoPtr->nIndent);
1315 for (i = 0; i < infoPtr->nNumButtons; i++ )
1317 bWrap = FALSE;
1318 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1320 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1321 continue;
1323 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1324 /* it is the actual width of the separator. This is used for */
1325 /* custom controls in toolbars. */
1326 /* */
1327 /* BTNS_DROPDOWN separators are treated as buttons for */
1328 /* width. - GA 8/01 */
1329 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1330 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1331 cx = (btnPtr[i].iBitmap > 0) ?
1332 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1333 else
1334 cx = infoPtr->nButtonWidth;
1336 /* Two or more adjacent separators form a separator group. */
1337 /* The first separator in a group should be wrapped to the */
1338 /* next row if the previous wrapping is on a button. */
1339 if( bButtonWrap &&
1340 (btnPtr[i].fsStyle & BTNS_SEP) &&
1341 (i + 1 < infoPtr->nNumButtons ) &&
1342 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1344 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1345 btnPtr[i].fsState |= TBSTATE_WRAP;
1346 x = infoPtr->nIndent;
1347 i++;
1348 bButtonWrap = FALSE;
1349 continue;
1352 /* The layout makes sure the bitmap is visible, but not the button. */
1353 /* Test added to also wrap after a button that starts a row but */
1354 /* is bigger than the area. - GA 8/01 */
1355 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1356 > infoPtr->nWidth ) ||
1357 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1359 BOOL bFound = FALSE;
1361 /* If the current button is a separator and not hidden, */
1362 /* go to the next until it reaches a non separator. */
1363 /* Wrap the last separator if it is before a button. */
1364 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1365 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1366 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1367 i < infoPtr->nNumButtons )
1369 i++;
1370 bFound = TRUE;
1373 if( bFound && i < infoPtr->nNumButtons )
1375 i--;
1376 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1377 i, btnPtr[i].fsStyle, x, cx);
1378 btnPtr[i].fsState |= TBSTATE_WRAP;
1379 x = infoPtr->nIndent;
1380 bButtonWrap = FALSE;
1381 continue;
1383 else if ( i >= infoPtr->nNumButtons)
1384 break;
1386 /* If the current button is not a separator, find the last */
1387 /* separator and wrap it. */
1388 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1390 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1391 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1393 bFound = TRUE;
1394 i = j;
1395 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1396 i, btnPtr[i].fsStyle, x, cx);
1397 x = infoPtr->nIndent;
1398 btnPtr[j].fsState |= TBSTATE_WRAP;
1399 bButtonWrap = FALSE;
1400 break;
1404 /* If no separator available for wrapping, wrap one of */
1405 /* non-hidden previous button. */
1406 if (!bFound)
1408 for ( j = i - 1;
1409 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1411 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1412 continue;
1414 bFound = TRUE;
1415 i = j;
1416 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1417 i, btnPtr[i].fsStyle, x, cx);
1418 x = infoPtr->nIndent;
1419 btnPtr[j].fsState |= TBSTATE_WRAP;
1420 bButtonWrap = TRUE;
1421 break;
1425 /* If all above failed, wrap the current button. */
1426 if (!bFound)
1428 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1429 i, btnPtr[i].fsStyle, x, cx);
1430 btnPtr[i].fsState |= TBSTATE_WRAP;
1431 bFound = TRUE;
1432 x = infoPtr->nIndent;
1433 if (btnPtr[i].fsStyle & BTNS_SEP )
1434 bButtonWrap = FALSE;
1435 else
1436 bButtonWrap = TRUE;
1439 else {
1440 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1441 i, btnPtr[i].fsStyle, x, cx);
1442 x += cx;
1448 /***********************************************************************
1449 * TOOLBAR_MeasureButton
1451 * Calculates the width and height required for a button. Used in
1452 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1453 * the width of buttons that are autosized.
1455 * Note that it would have been rather elegant to use one piece of code for
1456 * both the laying out of the toolbar and for controlling where button parts
1457 * are drawn, but the native control has inconsistencies between the two that
1458 * prevent this from being effectively. These inconsistencies can be seen as
1459 * artefacts where parts of the button appear outside of the bounding button
1460 * rectangle.
1462 * There are several cases for the calculation of the button dimensions and
1463 * button part positioning:
1465 * List
1466 * ====
1468 * With Bitmap:
1470 * +--------------------------------------------------------+ ^
1471 * | ^ ^ | |
1472 * | | pad.cy / 2 | centred | |
1473 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1474 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1475 * | |<------------>| | | | |
1476 * | +--------------+ +------------+ | |
1477 * |<-------------------------------------->| | |
1478 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1479 * | szText.cx | |
1480 * +--------------------------------------------------------+ -
1481 * <-------------------------------------------------------->
1482 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1484 * Without Bitmap (I_IMAGENONE):
1486 * +-----------------------------------+ ^
1487 * | ^ | |
1488 * | | centred | | LISTPAD_CY +
1489 * | +------------+ | | szText.cy
1490 * | | Text | | |
1491 * | | | | |
1492 * | +------------+ | |
1493 * |<----------------->| | |
1494 * | cxedge |<-----------> | |
1495 * | szText.cx | |
1496 * +-----------------------------------+ -
1497 * <----------------------------------->
1498 * szText.cx + pad.cx
1500 * Without text:
1502 * +--------------------------------------+ ^
1503 * | ^ | |
1504 * | | padding.cy/2 | | DEFPAD_CY +
1505 * | +------------+ | | nBitmapHeight
1506 * | | Bitmap | | |
1507 * | | | | |
1508 * | +------------+ | |
1509 * |<------------------->| | |
1510 * | cxedge + iListGap/2 |<-----------> | |
1511 * | nBitmapWidth | |
1512 * +--------------------------------------+ -
1513 * <-------------------------------------->
1514 * 2*cxedge + nBitmapWidth + iListGap
1516 * Non-List
1517 * ========
1519 * With bitmap:
1521 * +-----------------------------------+ ^
1522 * | ^ | |
1523 * | | pad.cy / 2 | | nBitmapHeight +
1524 * | - | | szText.cy +
1525 * | +------------+ | | DEFPAD_CY + 1
1526 * | centred | Bitmap | | |
1527 * |<----------------->| | | |
1528 * | +------------+ | |
1529 * | ^ | |
1530 * | 1 | | |
1531 * | - | |
1532 * | centred +---------------+ | |
1533 * |<--------------->| Text | | |
1534 * | +---------------+ | |
1535 * +-----------------------------------+ -
1536 * <----------------------------------->
1537 * pad.cx + max(nBitmapWidth, szText.cx)
1539 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1541 * +---------------------------------------+ ^
1542 * | ^ | |
1543 * | | 2 + pad.cy / 2 | |
1544 * | - | | szText.cy +
1545 * | centred +-----------------+ | | pad.cy + 2
1546 * |<--------------->| Text | | |
1547 * | +-----------------+ | |
1548 * | | |
1549 * +---------------------------------------+ -
1550 * <--------------------------------------->
1551 * 2*cxedge + pad.cx + szText.cx
1553 * Without text:
1554 * As for with bitmaps, but with szText.cx zero.
1556 static inline SIZE TOOLBAR_MeasureButton(const TOOLBAR_INFO *infoPtr, SIZE sizeString,
1557 BOOL bHasBitmap, BOOL bValidImageList)
1559 SIZE sizeButton;
1560 if (infoPtr->dwStyle & TBSTYLE_LIST)
1562 /* set button height from bitmap / text height... */
1563 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1564 sizeString.cy);
1566 /* ... add on the necessary padding */
1567 if (bValidImageList)
1569 if (bHasBitmap)
1570 sizeButton.cy += DEFPAD_CY;
1571 else
1572 sizeButton.cy += LISTPAD_CY;
1574 else
1575 sizeButton.cy += infoPtr->szPadding.cy;
1577 /* calculate button width */
1578 if (bHasBitmap)
1580 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1581 infoPtr->nBitmapWidth + infoPtr->iListGap;
1582 if (sizeString.cx > 0)
1583 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1585 else
1586 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1588 else
1590 if (bHasBitmap)
1592 sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
1593 if (sizeString.cy > 0)
1594 sizeButton.cy += 1 + sizeString.cy;
1595 sizeButton.cx = infoPtr->szPadding.cx +
1596 max(sizeString.cx, infoPtr->nBitmapWidth);
1598 else
1600 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1601 NONLIST_NOTEXT_OFFSET;
1602 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1603 infoPtr->szPadding.cx + sizeString.cx;
1606 return sizeButton;
1610 /***********************************************************************
1611 * TOOLBAR_CalcToolbar
1613 * This function calculates button and separator placement. It first
1614 * calculates the button sizes, gets the toolbar window width and then
1615 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1616 * on. It assigns a new location to each item and sends this location to
1617 * the tooltip window if appropriate. Finally, it updates the rcBound
1618 * rect and calculates the new required toolbar window height.
1620 static void
1621 TOOLBAR_CalcToolbar (HWND hwnd)
1623 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1624 SIZE sizeString, sizeButton;
1625 BOOL validImageList = FALSE;
1627 TOOLBAR_CalcStrings (hwnd, &sizeString);
1629 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1631 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1632 validImageList = TRUE;
1633 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1634 infoPtr->nButtonWidth = sizeButton.cx;
1635 infoPtr->nButtonHeight = sizeButton.cy;
1636 infoPtr->iTopMargin = default_top_margin(infoPtr);
1638 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1639 infoPtr->nButtonWidth = infoPtr->cxMin;
1640 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1641 infoPtr->nButtonWidth = infoPtr->cxMax;
1643 TOOLBAR_LayoutToolbar(hwnd);
1646 static void
1647 TOOLBAR_LayoutToolbar(HWND hwnd)
1649 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1650 TBUTTON_INFO *btnPtr;
1651 SIZE sizeButton;
1652 INT i, nRows, nSepRows;
1653 INT x, y, cx, cy;
1654 BOOL bWrap;
1655 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1656 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1658 TOOLBAR_WrapToolbar(hwnd, infoPtr->dwStyle);
1660 x = infoPtr->nIndent;
1661 y = infoPtr->iTopMargin;
1662 cx = infoPtr->nButtonWidth;
1663 cy = infoPtr->nButtonHeight;
1665 nRows = nSepRows = 0;
1667 infoPtr->rcBound.top = y;
1668 infoPtr->rcBound.left = x;
1669 infoPtr->rcBound.bottom = y + cy;
1670 infoPtr->rcBound.right = x;
1672 btnPtr = infoPtr->buttons;
1674 TRACE("cy=%d\n", cy);
1676 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1678 bWrap = FALSE;
1679 if (btnPtr->fsState & TBSTATE_HIDDEN)
1681 SetRectEmpty (&btnPtr->rect);
1682 continue;
1685 cy = infoPtr->nButtonHeight;
1687 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1688 /* it is the actual width of the separator. This is used for */
1689 /* custom controls in toolbars. */
1690 if (btnPtr->fsStyle & BTNS_SEP) {
1691 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1692 cy = (btnPtr->iBitmap > 0) ?
1693 btnPtr->iBitmap : SEPARATOR_WIDTH;
1694 cx = infoPtr->nButtonWidth;
1696 else
1697 cx = (btnPtr->iBitmap > 0) ?
1698 btnPtr->iBitmap : SEPARATOR_WIDTH;
1700 else
1702 if (btnPtr->cx)
1703 cx = btnPtr->cx;
1704 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1705 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1707 SIZE sz;
1708 HDC hdc;
1709 HFONT hOldFont;
1711 hdc = GetDC (hwnd);
1712 hOldFont = SelectObject (hdc, infoPtr->hFont);
1714 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1716 SelectObject (hdc, hOldFont);
1717 ReleaseDC (hwnd, hdc);
1719 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1720 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1721 validImageList);
1722 cx = sizeButton.cx;
1724 else
1725 cx = infoPtr->nButtonWidth;
1727 /* if size has been set manually then don't add on extra space
1728 * for the drop down arrow */
1729 if (!btnPtr->cx && hasDropDownArrows &&
1730 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1731 cx += DDARROW_WIDTH;
1733 if (btnPtr->fsState & TBSTATE_WRAP )
1734 bWrap = TRUE;
1736 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1738 if (infoPtr->rcBound.left > x)
1739 infoPtr->rcBound.left = x;
1740 if (infoPtr->rcBound.right < x + cx)
1741 infoPtr->rcBound.right = x + cx;
1742 if (infoPtr->rcBound.bottom < y + cy)
1743 infoPtr->rcBound.bottom = y + cy;
1745 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1747 /* btnPtr->nRow is zero based. The space between the rows is */
1748 /* also considered as a row. */
1749 btnPtr->nRow = nRows + nSepRows;
1751 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1752 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1753 x, y, x+cx, y+cy);
1755 if( bWrap )
1757 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1758 y += cy;
1759 else
1761 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1762 /* it is the actual width of the separator. This is used for */
1763 /* custom controls in toolbars. */
1764 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1765 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1766 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1767 else
1768 y += cy;
1770 /* nSepRows is used to calculate the extra height following */
1771 /* the last row. */
1772 nSepRows++;
1774 x = infoPtr->nIndent;
1776 /* Increment row number unless this is the last button */
1777 /* and it has Wrap set. */
1778 if (i != infoPtr->nNumButtons-1)
1779 nRows++;
1781 else
1782 x += cx;
1785 /* infoPtr->nRows is the number of rows on the toolbar */
1786 infoPtr->nRows = nRows + nSepRows + 1;
1788 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1792 static INT
1793 TOOLBAR_InternalHitTest (HWND hwnd, const POINT *lpPt)
1795 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1796 TBUTTON_INFO *btnPtr;
1797 INT i;
1799 btnPtr = infoPtr->buttons;
1800 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1801 if (btnPtr->fsState & TBSTATE_HIDDEN)
1802 continue;
1804 if (btnPtr->fsStyle & BTNS_SEP) {
1805 if (PtInRect (&btnPtr->rect, *lpPt)) {
1806 TRACE(" ON SEPARATOR %d!\n", i);
1807 return -i;
1810 else {
1811 if (PtInRect (&btnPtr->rect, *lpPt)) {
1812 TRACE(" ON BUTTON %d!\n", i);
1813 return i;
1818 TRACE(" NOWHERE!\n");
1819 return TOOLBAR_NOWHERE;
1823 static INT
1824 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1826 TBUTTON_INFO *btnPtr;
1827 INT i;
1829 if (CommandIsIndex) {
1830 TRACE("command is really index command=%d\n", idCommand);
1831 if (idCommand >= infoPtr->nNumButtons) return -1;
1832 return idCommand;
1834 btnPtr = infoPtr->buttons;
1835 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1836 if (btnPtr->idCommand == idCommand) {
1837 TRACE("command=%d index=%d\n", idCommand, i);
1838 return i;
1841 TRACE("no index found for command=%d\n", idCommand);
1842 return -1;
1846 static INT
1847 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO *infoPtr, INT nIndex)
1849 TBUTTON_INFO *btnPtr;
1850 INT nRunIndex;
1852 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1853 return -1;
1855 /* check index button */
1856 btnPtr = &infoPtr->buttons[nIndex];
1857 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1858 if (btnPtr->fsState & TBSTATE_CHECKED)
1859 return nIndex;
1862 /* check previous buttons */
1863 nRunIndex = nIndex - 1;
1864 while (nRunIndex >= 0) {
1865 btnPtr = &infoPtr->buttons[nRunIndex];
1866 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1867 if (btnPtr->fsState & TBSTATE_CHECKED)
1868 return nRunIndex;
1870 else
1871 break;
1872 nRunIndex--;
1875 /* check next buttons */
1876 nRunIndex = nIndex + 1;
1877 while (nRunIndex < infoPtr->nNumButtons) {
1878 btnPtr = &infoPtr->buttons[nRunIndex];
1879 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1880 if (btnPtr->fsState & TBSTATE_CHECKED)
1881 return nRunIndex;
1883 else
1884 break;
1885 nRunIndex++;
1888 return -1;
1892 static VOID
1893 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1894 WPARAM wParam, LPARAM lParam)
1896 MSG msg;
1898 msg.hwnd = hwndMsg;
1899 msg.message = uMsg;
1900 msg.wParam = wParam;
1901 msg.lParam = lParam;
1902 msg.time = GetMessageTime ();
1903 msg.pt.x = (short)LOWORD(GetMessagePos ());
1904 msg.pt.y = (short)HIWORD(GetMessagePos ());
1906 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1909 static void
1910 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1912 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1913 TTTOOLINFOW ti;
1915 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1916 ti.cbSize = sizeof (TTTOOLINFOW);
1917 ti.hwnd = infoPtr->hwndSelf;
1918 ti.uId = button->idCommand;
1919 ti.hinst = 0;
1920 ti.lpszText = LPSTR_TEXTCALLBACKW;
1921 /* ti.lParam = random value from the stack? */
1923 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1924 0, (LPARAM)&ti);
1928 static void
1929 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1931 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1932 TTTOOLINFOW ti;
1934 ZeroMemory(&ti, sizeof(ti));
1935 ti.cbSize = sizeof(ti);
1936 ti.hwnd = infoPtr->hwndSelf;
1937 ti.uId = button->idCommand;
1939 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1943 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1945 /* Set the toolTip only for non-hidden, non-separator button */
1946 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1948 TTTOOLINFOW ti;
1950 ZeroMemory(&ti, sizeof(ti));
1951 ti.cbSize = sizeof(ti);
1952 ti.hwnd = infoPtr->hwndSelf;
1953 ti.uId = button->idCommand;
1954 ti.rect = button->rect;
1955 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1959 /* Creates the tooltip control */
1960 static void
1961 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
1963 int i;
1964 NMTOOLTIPSCREATED nmttc;
1966 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1967 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1968 infoPtr->hwndSelf, 0, 0, 0);
1970 if (!infoPtr->hwndToolTip)
1971 return;
1973 /* Send NM_TOOLTIPSCREATED notification */
1974 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1975 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
1977 for (i = 0; i < infoPtr->nNumButtons; i++)
1979 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
1980 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
1984 /* keeps available button list box sorted by button id */
1985 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1987 int i;
1988 int count;
1989 PCUSTOMBUTTON btnInfo;
1990 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1992 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1994 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1996 /* position 0 is always separator */
1997 for (i = 1; i < count; i++)
1999 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
2000 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2002 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2003 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2004 return;
2007 /* id higher than all others add to end */
2008 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2009 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2012 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2014 NMTOOLBARW nmtb;
2016 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2018 if (nIndexFrom == nIndexTo)
2019 return;
2021 /* MSDN states that iItem is the index of the button, rather than the
2022 * command ID as used by every other NMTOOLBAR notification */
2023 nmtb.iItem = nIndexFrom;
2024 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2026 PCUSTOMBUTTON btnInfo;
2027 NMHDR hdr;
2028 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2029 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2031 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2033 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2034 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2035 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2036 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2038 if (nIndexTo <= 0)
2039 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2040 else
2041 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2043 /* last item is always separator, so -2 instead of -1 */
2044 if (nIndexTo >= (count - 2))
2045 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2046 else
2047 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2049 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2050 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2052 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2056 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2058 NMTOOLBARW nmtb;
2060 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2062 /* MSDN states that iItem is the index of the button, rather than the
2063 * command ID as used by every other NMTOOLBAR notification */
2064 nmtb.iItem = nIndexAvail;
2065 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2067 PCUSTOMBUTTON btnInfo;
2068 NMHDR hdr;
2069 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2070 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2071 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2073 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2075 if (nIndexAvail != 0) /* index == 0 indicates separator */
2077 /* remove from 'available buttons' list */
2078 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2079 if (nIndexAvail == count-1)
2080 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2081 else
2082 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2084 else
2086 PCUSTOMBUTTON btnNew;
2088 /* duplicate 'separator' button */
2089 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2090 *btnNew = *btnInfo;
2091 btnInfo = btnNew;
2094 /* insert into 'toolbar button' list */
2095 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2096 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2098 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2100 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2104 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT index)
2106 PCUSTOMBUTTON btnInfo;
2107 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2109 TRACE("Remove: index %d\n", index);
2111 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2113 /* send TBN_QUERYDELETE notification */
2114 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2116 NMHDR hdr;
2118 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2119 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2121 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2123 /* insert into 'available button' list */
2124 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2125 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2126 else
2127 Free(btnInfo);
2129 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2133 /* drag list notification function for toolbar buttons list box */
2134 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2135 const DRAGLISTINFO *pDLI)
2137 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2138 switch (pDLI->uNotification)
2140 case DL_BEGINDRAG:
2142 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2143 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2144 /* no dragging for last item (separator) */
2145 if (nCurrentItem >= (nCount - 1)) return FALSE;
2146 return TRUE;
2148 case DL_DRAGGING:
2150 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2151 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2152 /* no dragging past last item (separator) */
2153 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2155 DrawInsert(hwnd, hwndList, nCurrentItem);
2156 /* FIXME: native uses "move button" cursor */
2157 return DL_COPYCURSOR;
2160 /* not over toolbar buttons list */
2161 if (nCurrentItem < 0)
2163 POINT ptWindow = pDLI->ptCursor;
2164 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2165 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2166 /* over available buttons list? */
2167 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2168 /* FIXME: native uses "move button" cursor */
2169 return DL_COPYCURSOR;
2171 /* clear drag arrow */
2172 DrawInsert(hwnd, hwndList, -1);
2173 return DL_STOPCURSOR;
2175 case DL_DROPPED:
2177 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2178 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2179 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2180 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2182 /* clear drag arrow */
2183 DrawInsert(hwnd, hwndList, -1);
2184 /* move item */
2185 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2187 /* not over toolbar buttons list */
2188 if (nIndexTo < 0)
2190 POINT ptWindow = pDLI->ptCursor;
2191 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2192 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2193 /* over available buttons list? */
2194 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2195 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2197 break;
2199 case DL_CANCELDRAG:
2200 /* Clear drag arrow */
2201 DrawInsert(hwnd, hwndList, -1);
2202 break;
2205 return 0;
2208 /* drag list notification function for available buttons list box */
2209 static LRESULT TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2210 const DRAGLISTINFO *pDLI)
2212 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2213 switch (pDLI->uNotification)
2215 case DL_BEGINDRAG:
2216 return TRUE;
2217 case DL_DRAGGING:
2219 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2220 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2221 /* no dragging past last item (separator) */
2222 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2224 DrawInsert(hwnd, hwndList, nCurrentItem);
2225 /* FIXME: native uses "move button" cursor */
2226 return DL_COPYCURSOR;
2229 /* not over toolbar buttons list */
2230 if (nCurrentItem < 0)
2232 POINT ptWindow = pDLI->ptCursor;
2233 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2234 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2235 /* over available buttons list? */
2236 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2237 /* FIXME: native uses "move button" cursor */
2238 return DL_COPYCURSOR;
2240 /* clear drag arrow */
2241 DrawInsert(hwnd, hwndList, -1);
2242 return DL_STOPCURSOR;
2244 case DL_DROPPED:
2246 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2247 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2248 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2249 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2251 /* clear drag arrow */
2252 DrawInsert(hwnd, hwndList, -1);
2253 /* add item */
2254 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2257 case DL_CANCELDRAG:
2258 /* Clear drag arrow */
2259 DrawInsert(hwnd, hwndList, -1);
2260 break;
2262 return 0;
2265 extern UINT uDragListMessage;
2267 /***********************************************************************
2268 * TOOLBAR_CustomizeDialogProc
2269 * This function implements the toolbar customization dialog.
2271 static INT_PTR CALLBACK
2272 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2274 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2275 PCUSTOMBUTTON btnInfo;
2276 NMTOOLBARA nmtb;
2277 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2279 switch (uMsg)
2281 case WM_INITDIALOG:
2282 custInfo = (PCUSTDLG_INFO)lParam;
2283 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2285 if (custInfo)
2287 WCHAR Buffer[256];
2288 int i = 0;
2289 int index;
2290 NMTBINITCUSTOMIZE nmtbic;
2292 infoPtr = custInfo->tbInfo;
2294 /* send TBN_QUERYINSERT notification */
2295 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2297 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2298 return FALSE;
2300 nmtbic.hwndDialog = hwnd;
2301 /* Send TBN_INITCUSTOMIZE notification */
2302 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2303 TBNRF_HIDEHELP)
2305 TRACE("TBNRF_HIDEHELP requested\n");
2306 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2309 /* add items to 'toolbar buttons' list and check if removable */
2310 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2312 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2313 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2314 btnInfo->btn.fsStyle = BTNS_SEP;
2315 btnInfo->bVirtual = FALSE;
2316 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2318 /* send TBN_QUERYDELETE notification */
2319 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2321 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2322 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2325 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2327 /* insert separator button into 'available buttons' list */
2328 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2329 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2330 btnInfo->btn.fsStyle = BTNS_SEP;
2331 btnInfo->bVirtual = FALSE;
2332 btnInfo->bRemovable = TRUE;
2333 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2334 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2335 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2337 /* insert all buttons into dsa */
2338 for (i = 0;; i++)
2340 /* send TBN_GETBUTTONINFO notification */
2341 NMTOOLBARW nmtb;
2342 nmtb.iItem = i;
2343 nmtb.pszText = Buffer;
2344 nmtb.cchText = 256;
2346 /* Clear previous button's text */
2347 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2349 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2350 break;
2352 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2353 nmtb.tbButton.fsStyle, i,
2354 nmtb.tbButton.idCommand,
2355 nmtb.tbButton.iString,
2356 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2357 : "");
2359 /* insert button into the apropriate list */
2360 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2361 if (index == -1)
2363 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2364 btnInfo->bVirtual = FALSE;
2365 btnInfo->bRemovable = TRUE;
2367 else
2369 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2370 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2373 btnInfo->btn = nmtb.tbButton;
2374 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2376 if (lstrlenW(nmtb.pszText))
2377 lstrcpyW(btnInfo->text, nmtb.pszText);
2378 else if (nmtb.tbButton.iString >= 0 &&
2379 nmtb.tbButton.iString < infoPtr->nNumStrings)
2381 lstrcpyW(btnInfo->text,
2382 infoPtr->strings[nmtb.tbButton.iString]);
2386 if (index == -1)
2387 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2390 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2392 /* select first item in the 'available' list */
2393 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2395 /* append 'virtual' separator button to the 'toolbar buttons' list */
2396 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2397 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2398 btnInfo->btn.fsStyle = BTNS_SEP;
2399 btnInfo->bVirtual = TRUE;
2400 btnInfo->bRemovable = FALSE;
2401 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2402 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2403 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2405 /* select last item in the 'toolbar' list */
2406 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2407 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2409 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2410 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2412 /* set focus and disable buttons */
2413 PostMessageW (hwnd, WM_USER, 0, 0);
2415 return TRUE;
2417 case WM_USER:
2418 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2419 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2420 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2421 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2422 return TRUE;
2424 case WM_CLOSE:
2425 EndDialog(hwnd, FALSE);
2426 return TRUE;
2428 case WM_COMMAND:
2429 switch (LOWORD(wParam))
2431 case IDC_TOOLBARBTN_LBOX:
2432 if (HIWORD(wParam) == LBN_SELCHANGE)
2434 PCUSTOMBUTTON btnInfo;
2435 NMTOOLBARA nmtb;
2436 int count;
2437 int index;
2439 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2440 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2442 /* send TBN_QUERYINSERT notification */
2443 nmtb.iItem = index;
2444 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2446 /* get list box item */
2447 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2449 if (index == (count - 1))
2451 /* last item (virtual separator) */
2452 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2453 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2455 else if (index == (count - 2))
2457 /* second last item (last non-virtual item) */
2458 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2459 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2461 else if (index == 0)
2463 /* first item */
2464 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2465 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2467 else
2469 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2470 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2473 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2475 break;
2477 case IDC_MOVEUP_BTN:
2479 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2480 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2482 break;
2484 case IDC_MOVEDN_BTN: /* move down */
2486 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2487 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2489 break;
2491 case IDC_REMOVE_BTN: /* remove button */
2493 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2495 if (LB_ERR == index)
2496 break;
2498 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2500 break;
2501 case IDC_HELP_BTN:
2502 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2503 break;
2504 case IDC_RESET_BTN:
2505 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2506 break;
2508 case IDOK: /* Add button */
2510 int index;
2511 int indexto;
2513 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2514 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2516 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2518 break;
2520 case IDCANCEL:
2521 EndDialog(hwnd, FALSE);
2522 break;
2524 return TRUE;
2526 case WM_DESTROY:
2528 int count;
2529 int i;
2531 /* delete items from 'toolbar buttons' listbox*/
2532 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2533 for (i = 0; i < count; i++)
2535 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2536 Free(btnInfo);
2537 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2539 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2542 /* delete items from 'available buttons' listbox*/
2543 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2544 for (i = 0; i < count; i++)
2546 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2547 Free(btnInfo);
2548 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2550 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2552 return TRUE;
2554 case WM_DRAWITEM:
2555 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2557 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2558 RECT rcButton;
2559 RECT rcText;
2560 HPEN hPen, hOldPen;
2561 HBRUSH hOldBrush;
2562 COLORREF oldText = 0;
2563 COLORREF oldBk = 0;
2565 /* get item data */
2566 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2567 if (btnInfo == NULL)
2569 FIXME("btnInfo invalid!\n");
2570 return TRUE;
2573 /* set colors and select objects */
2574 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2575 if (btnInfo->bVirtual)
2576 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2577 else
2578 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2579 hPen = CreatePen( PS_SOLID, 1,
2580 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2581 hOldPen = SelectObject (lpdis->hDC, hPen );
2582 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2584 /* fill background rectangle */
2585 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2586 lpdis->rcItem.right, lpdis->rcItem.bottom);
2588 /* calculate button and text rectangles */
2589 CopyRect (&rcButton, &lpdis->rcItem);
2590 InflateRect (&rcButton, -1, -1);
2591 CopyRect (&rcText, &rcButton);
2592 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2593 rcText.left = rcButton.right + 2;
2595 /* draw focus rectangle */
2596 if (lpdis->itemState & ODS_FOCUS)
2597 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2599 /* draw button */
2600 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2601 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2603 /* draw image and text */
2604 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2605 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2606 btnInfo->btn.iBitmap));
2607 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2608 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2610 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2611 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2613 /* delete objects and reset colors */
2614 SelectObject (lpdis->hDC, hOldBrush);
2615 SelectObject (lpdis->hDC, hOldPen);
2616 SetBkColor (lpdis->hDC, oldBk);
2617 SetTextColor (lpdis->hDC, oldText);
2618 DeleteObject( hPen );
2619 return TRUE;
2621 return FALSE;
2623 case WM_MEASUREITEM:
2624 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2626 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2628 lpmis->itemHeight = 15 + 8; /* default height */
2630 return TRUE;
2632 return FALSE;
2634 default:
2635 if (uDragListMessage && (uMsg == uDragListMessage))
2637 if (wParam == IDC_TOOLBARBTN_LBOX)
2639 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2640 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2641 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2642 return TRUE;
2644 else if (wParam == IDC_AVAILBTN_LBOX)
2646 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2647 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2648 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2649 return TRUE;
2652 return FALSE;
2656 static BOOL
2657 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2659 HBITMAP hbmLoad;
2660 INT nCountBefore = ImageList_GetImageCount(himlDef);
2661 INT nCountAfter;
2662 INT cxIcon, cyIcon;
2663 INT nAdded;
2664 INT nIndex;
2666 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2667 /* Add bitmaps to the default image list */
2668 if (bitmap->hInst == NULL) /* a handle was passed */
2669 hbmLoad = (HBITMAP)CopyImage(ULongToHandle(bitmap->nID), IMAGE_BITMAP, 0, 0, 0);
2670 else
2671 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2673 /* enlarge the bitmap if needed */
2674 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2675 if (bitmap->hInst != COMCTL32_hModule)
2676 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2678 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2679 DeleteObject(hbmLoad);
2680 if (nIndex == -1)
2681 return FALSE;
2683 nCountAfter = ImageList_GetImageCount(himlDef);
2684 nAdded = nCountAfter - nCountBefore;
2685 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2687 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2688 } else if (nAdded > (INT)bitmap->nButtons) {
2689 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2690 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2693 infoPtr->nNumBitmaps += nAdded;
2694 return TRUE;
2697 static void
2698 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2700 HIMAGELIST himlDef;
2701 HIMAGELIST himlNew;
2702 INT cx, cy;
2703 INT i;
2705 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2706 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2707 return;
2708 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2709 return;
2710 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2711 return;
2713 TRACE("Update icon size: %dx%d -> %dx%d\n",
2714 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2716 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2717 ILC_COLORDDB|ILC_MASK, 8, 2);
2718 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2719 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2720 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2721 infoPtr->himlInt = himlNew;
2723 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2724 ImageList_Destroy(himlDef);
2727 /***********************************************************************
2728 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2731 static LRESULT
2732 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2734 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2735 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2736 TBITMAP_INFO info;
2737 INT iSumButtons, i;
2738 HIMAGELIST himlDef;
2740 TRACE("hwnd=%p wParam=%lx lParam=%lx\n", hwnd, wParam, lParam);
2741 if (!lpAddBmp)
2742 return -1;
2744 if (lpAddBmp->hInst == HINST_COMMCTRL)
2746 info.hInst = COMCTL32_hModule;
2747 switch (lpAddBmp->nID)
2749 case IDB_STD_SMALL_COLOR:
2750 info.nButtons = 15;
2751 info.nID = IDB_STD_SMALL;
2752 break;
2753 case IDB_STD_LARGE_COLOR:
2754 info.nButtons = 15;
2755 info.nID = IDB_STD_LARGE;
2756 break;
2757 case IDB_VIEW_SMALL_COLOR:
2758 info.nButtons = 12;
2759 info.nID = IDB_VIEW_SMALL;
2760 break;
2761 case IDB_VIEW_LARGE_COLOR:
2762 info.nButtons = 12;
2763 info.nID = IDB_VIEW_LARGE;
2764 break;
2765 case IDB_HIST_SMALL_COLOR:
2766 info.nButtons = 5;
2767 info.nID = IDB_HIST_SMALL;
2768 break;
2769 case IDB_HIST_LARGE_COLOR:
2770 info.nButtons = 5;
2771 info.nID = IDB_HIST_LARGE;
2772 break;
2773 default:
2774 return -1;
2777 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2779 /* Windows resize all the buttons to the size of a newly added standard image */
2780 if (lpAddBmp->nID & 1)
2782 /* large icons: 24x24. Will make the button 31x30 */
2783 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
2785 else
2787 /* small icons: 16x16. Will make the buttons 23x22 */
2788 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
2791 TOOLBAR_CalcToolbar (hwnd);
2793 else
2795 info.nButtons = (INT)wParam;
2796 info.hInst = lpAddBmp->hInst;
2797 info.nID = lpAddBmp->nID;
2798 TRACE("adding %d bitmaps!\n", info.nButtons);
2801 /* check if the bitmap is already loaded and compute iSumButtons */
2802 iSumButtons = 0;
2803 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2805 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2806 infoPtr->bitmaps[i].nID == info.nID)
2807 return iSumButtons;
2808 iSumButtons += infoPtr->bitmaps[i].nButtons;
2811 if (!infoPtr->cimlDef) {
2812 /* create new default image list */
2813 TRACE ("creating default image list!\n");
2815 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2816 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2817 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2818 infoPtr->himlInt = himlDef;
2820 else {
2821 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2824 if (!himlDef) {
2825 WARN("No default image list available\n");
2826 return -1;
2829 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2830 return -1;
2832 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2833 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2834 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2835 infoPtr->nNumBitmapInfos++;
2836 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2838 InvalidateRect(hwnd, NULL, TRUE);
2839 return iSumButtons;
2843 static LRESULT
2844 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2846 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2847 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2848 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2849 BOOL fHasString = FALSE;
2851 TRACE("adding %ld buttons (unicode=%d)!\n", wParam, fUnicode);
2853 nAddButtons = (UINT)wParam;
2854 nOldButtons = infoPtr->nNumButtons;
2855 nNewButtons = nOldButtons + nAddButtons;
2857 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
2858 infoPtr->nNumButtons = nNewButtons;
2860 /* insert new button data */
2861 for (nCount = 0; nCount < nAddButtons; nCount++) {
2862 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2863 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2864 btnPtr->idCommand = lpTbb[nCount].idCommand;
2865 btnPtr->fsState = lpTbb[nCount].fsState;
2866 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2867 btnPtr->dwData = lpTbb[nCount].dwData;
2868 btnPtr->bHot = FALSE;
2869 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2871 if (fUnicode)
2872 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2873 else
2874 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString);
2875 fHasString = TRUE;
2877 else
2878 btnPtr->iString = lpTbb[nCount].iString;
2880 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
2883 if (infoPtr->nNumStrings > 0 || fHasString)
2884 TOOLBAR_CalcToolbar(hwnd);
2885 else
2886 TOOLBAR_LayoutToolbar(hwnd);
2887 TOOLBAR_AutoSize (hwnd);
2889 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2891 InvalidateRect(hwnd, NULL, TRUE);
2893 return TRUE;
2897 static LRESULT
2898 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2900 #define MAX_RESOURCE_STRING_LENGTH 512
2901 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2902 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2903 INT nIndex = infoPtr->nNumStrings;
2905 if ((wParam) && (HIWORD(lParam) == 0)) {
2906 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2907 WCHAR delimiter;
2908 WCHAR *next_delim;
2909 WCHAR *p;
2910 INT len;
2911 TRACE("adding string from resource!\n");
2913 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2914 szString, MAX_RESOURCE_STRING_LENGTH);
2916 TRACE("len=%d %s\n", len, debugstr_w(szString));
2917 if (len == 0 || len == 1)
2918 return nIndex;
2920 TRACE("Delimiter: 0x%x\n", *szString);
2921 delimiter = *szString;
2922 p = szString + 1;
2924 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2925 *next_delim = 0;
2926 if (next_delim + 1 >= szString + len)
2928 /* this may happen if delimiter == '\0' or if the last char is a
2929 * delimiter (then it is ignored like the native does) */
2930 break;
2933 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2934 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2935 infoPtr->nNumStrings++;
2937 p = next_delim + 1;
2940 else {
2941 LPWSTR p = (LPWSTR)lParam;
2942 INT len;
2944 if (p == NULL)
2945 return -1;
2946 TRACE("adding string(s) from array!\n");
2947 while (*p) {
2948 len = strlenW (p);
2950 TRACE("len=%d %s\n", len, debugstr_w(p));
2951 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2952 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2953 infoPtr->nNumStrings++;
2955 p += (len+1);
2959 if (fFirstString)
2960 TOOLBAR_CalcToolbar(hwnd);
2961 return nIndex;
2965 static LRESULT
2966 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2968 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2969 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2970 LPSTR p;
2971 INT nIndex;
2972 INT len;
2974 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
2975 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
2977 p = (LPSTR)lParam;
2978 if (p == NULL)
2979 return -1;
2981 TRACE("adding string(s) from array!\n");
2982 nIndex = infoPtr->nNumStrings;
2983 while (*p) {
2984 len = strlen (p);
2985 TRACE("len=%d \"%s\"\n", len, p);
2987 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2988 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
2989 infoPtr->nNumStrings++;
2991 p += (len+1);
2994 if (fFirstString)
2995 TOOLBAR_CalcToolbar(hwnd);
2996 return nIndex;
3000 static LRESULT
3001 TOOLBAR_AutoSize (HWND hwnd)
3003 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3004 RECT parent_rect;
3005 HWND parent;
3006 INT x, y;
3007 INT cx, cy;
3009 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3011 parent = GetParent (hwnd);
3013 if (!parent || !infoPtr->bDoRedraw)
3014 return 0;
3016 GetClientRect(parent, &parent_rect);
3018 x = parent_rect.left;
3019 y = parent_rect.top;
3021 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3023 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3024 cx = parent_rect.right - parent_rect.left;
3026 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3028 TOOLBAR_LayoutToolbar(hwnd);
3029 InvalidateRect( hwnd, NULL, TRUE );
3032 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3034 RECT window_rect;
3035 UINT uPosFlags = SWP_NOZORDER;
3037 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3039 GetWindowRect(hwnd, &window_rect);
3040 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3041 y = window_rect.top;
3043 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3045 GetWindowRect(hwnd, &window_rect);
3046 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3049 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3050 uPosFlags |= SWP_NOMOVE;
3052 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3053 cy += GetSystemMetrics(SM_CYEDGE);
3055 if (infoPtr->dwStyle & WS_BORDER)
3057 x = y = 1; /* FIXME: this looks wrong */
3058 cy += GetSystemMetrics(SM_CYEDGE);
3059 cx += GetSystemMetrics(SM_CXEDGE);
3062 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3065 return 0;
3069 static LRESULT
3070 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3072 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3074 return infoPtr->nNumButtons;
3078 static LRESULT
3079 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3081 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3083 infoPtr->dwStructSize = (DWORD)wParam;
3085 return 0;
3089 static LRESULT
3090 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3092 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3093 TBUTTON_INFO *btnPtr;
3094 INT nIndex;
3096 TRACE("button %ld, iBitmap now %d\n", wParam, LOWORD(lParam));
3098 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3099 if (nIndex == -1)
3100 return FALSE;
3102 btnPtr = &infoPtr->buttons[nIndex];
3103 btnPtr->iBitmap = LOWORD(lParam);
3105 /* we HAVE to erase the background, the new bitmap could be */
3106 /* transparent */
3107 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3109 return TRUE;
3113 static LRESULT
3114 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3116 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3117 TBUTTON_INFO *btnPtr;
3118 INT nIndex;
3119 INT nOldIndex = -1;
3120 BOOL bChecked = FALSE;
3122 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3124 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3126 if (nIndex == -1)
3127 return FALSE;
3129 btnPtr = &infoPtr->buttons[nIndex];
3131 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3133 if (LOWORD(lParam) == FALSE)
3134 btnPtr->fsState &= ~TBSTATE_CHECKED;
3135 else {
3136 if (btnPtr->fsStyle & BTNS_GROUP) {
3137 nOldIndex =
3138 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3139 if (nOldIndex == nIndex)
3140 return 0;
3141 if (nOldIndex != -1)
3142 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3144 btnPtr->fsState |= TBSTATE_CHECKED;
3147 if( bChecked != LOWORD(lParam) )
3149 if (nOldIndex != -1)
3150 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3151 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3154 /* FIXME: Send a WM_NOTIFY?? */
3156 return TRUE;
3160 static LRESULT
3161 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3163 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3165 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3169 static LRESULT
3170 TOOLBAR_Customize (HWND hwnd)
3172 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3173 CUSTDLG_INFO custInfo;
3174 LRESULT ret;
3175 LPCVOID template;
3176 HRSRC hRes;
3177 NMHDR nmhdr;
3179 custInfo.tbInfo = infoPtr;
3180 custInfo.tbHwnd = hwnd;
3182 /* send TBN_BEGINADJUST notification */
3183 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3185 if (!(hRes = FindResourceW (COMCTL32_hModule,
3186 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3187 (LPWSTR)RT_DIALOG)))
3188 return FALSE;
3190 if(!(template = LoadResource (COMCTL32_hModule, hRes)))
3191 return FALSE;
3193 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3194 (LPCDLGTEMPLATEW)template,
3195 hwnd,
3196 TOOLBAR_CustomizeDialogProc,
3197 (LPARAM)&custInfo);
3199 /* send TBN_ENDADJUST notification */
3200 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3202 return ret;
3206 static LRESULT
3207 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3209 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3210 INT nIndex = (INT)wParam;
3211 NMTOOLBARW nmtb;
3212 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3214 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3215 return FALSE;
3217 memset(&nmtb, 0, sizeof(nmtb));
3218 nmtb.iItem = btnPtr->idCommand;
3219 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3220 nmtb.tbButton.idCommand = btnPtr->idCommand;
3221 nmtb.tbButton.fsState = btnPtr->fsState;
3222 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3223 nmtb.tbButton.dwData = btnPtr->dwData;
3224 nmtb.tbButton.iString = btnPtr->iString;
3225 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3227 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3229 if (infoPtr->nNumButtons == 1) {
3230 TRACE(" simple delete!\n");
3231 Free (infoPtr->buttons);
3232 infoPtr->buttons = NULL;
3233 infoPtr->nNumButtons = 0;
3235 else {
3236 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3237 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3239 infoPtr->nNumButtons--;
3240 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3241 if (nIndex > 0) {
3242 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3243 nIndex * sizeof(TBUTTON_INFO));
3246 if (nIndex < infoPtr->nNumButtons) {
3247 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3248 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3251 Free (oldButtons);
3254 TOOLBAR_LayoutToolbar(hwnd);
3256 InvalidateRect (hwnd, NULL, TRUE);
3258 return TRUE;
3262 static LRESULT
3263 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3265 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3266 TBUTTON_INFO *btnPtr;
3267 INT nIndex;
3268 DWORD bState;
3270 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3272 TRACE("hwnd=%p, btn index=%ld, lParam=0x%08lx\n", hwnd, wParam, lParam);
3274 if (nIndex == -1)
3275 return FALSE;
3277 btnPtr = &infoPtr->buttons[nIndex];
3279 bState = btnPtr->fsState & TBSTATE_ENABLED;
3281 /* update the toolbar button state */
3282 if(LOWORD(lParam) == FALSE) {
3283 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3284 } else {
3285 btnPtr->fsState |= TBSTATE_ENABLED;
3288 /* redraw the button only if the state of the button changed */
3289 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3290 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3292 return TRUE;
3296 static inline LRESULT
3297 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3299 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3301 return infoPtr->bAnchor;
3305 static LRESULT
3306 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3308 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3309 INT nIndex;
3311 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3312 if (nIndex == -1)
3313 return -1;
3315 return infoPtr->buttons[nIndex].iBitmap;
3319 static inline LRESULT
3320 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3322 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3326 static LRESULT
3327 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3329 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3330 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3331 INT nIndex = (INT)wParam;
3332 TBUTTON_INFO *btnPtr;
3334 if (lpTbb == NULL)
3335 return FALSE;
3337 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3338 return FALSE;
3340 btnPtr = &infoPtr->buttons[nIndex];
3341 lpTbb->iBitmap = btnPtr->iBitmap;
3342 lpTbb->idCommand = btnPtr->idCommand;
3343 lpTbb->fsState = btnPtr->fsState;
3344 lpTbb->fsStyle = btnPtr->fsStyle;
3345 lpTbb->bReserved[0] = 0;
3346 lpTbb->bReserved[1] = 0;
3347 lpTbb->dwData = btnPtr->dwData;
3348 lpTbb->iString = btnPtr->iString;
3350 return TRUE;
3354 static LRESULT
3355 TOOLBAR_GetButtonInfoT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL bUnicode)
3357 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3358 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3359 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3360 TBUTTON_INFO *btnPtr;
3361 INT nIndex;
3363 if (lpTbInfo == NULL)
3364 return -1;
3366 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3367 * the headers and tests shows that even with comctl 6 Vista accepts only the
3368 * original TBBUTTONINFO size
3370 if (lpTbInfo->cbSize != sizeof(TBBUTTONINFOW))
3372 WARN("Invalid button size\n");
3373 return -1;
3376 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3377 lpTbInfo->dwMask & 0x80000000);
3378 if (nIndex == -1)
3379 return -1;
3381 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3383 if (lpTbInfo->dwMask & TBIF_COMMAND)
3384 lpTbInfo->idCommand = btnPtr->idCommand;
3385 if (lpTbInfo->dwMask & TBIF_IMAGE)
3386 lpTbInfo->iImage = btnPtr->iBitmap;
3387 if (lpTbInfo->dwMask & TBIF_LPARAM)
3388 lpTbInfo->lParam = btnPtr->dwData;
3389 if (lpTbInfo->dwMask & TBIF_SIZE)
3390 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3391 if (lpTbInfo->dwMask & TBIF_STATE)
3392 lpTbInfo->fsState = btnPtr->fsState;
3393 if (lpTbInfo->dwMask & TBIF_STYLE)
3394 lpTbInfo->fsStyle = btnPtr->fsStyle;
3395 if (lpTbInfo->dwMask & TBIF_TEXT) {
3396 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3397 can't use TOOLBAR_GetText here */
3398 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3399 LPWSTR lpText = (LPWSTR)btnPtr->iString;
3400 if (bUnicode)
3401 Str_GetPtrW(lpText, lpTbInfo->pszText, lpTbInfo->cchText);
3402 else
3403 Str_GetPtrWtoA(lpText, (LPSTR)lpTbInfo->pszText, lpTbInfo->cchText);
3404 } else
3405 lpTbInfo->pszText[0] = '\0';
3407 return nIndex;
3411 static LRESULT
3412 TOOLBAR_GetButtonSize (HWND hwnd)
3414 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3416 return MAKELONG((WORD)infoPtr->nButtonWidth,
3417 (WORD)infoPtr->nButtonHeight);
3421 static LRESULT
3422 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3424 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3425 INT nIndex;
3426 LPWSTR lpText;
3428 if (lParam == 0)
3429 return -1;
3431 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3432 if (nIndex == -1)
3433 return -1;
3435 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3437 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3438 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3442 static LRESULT
3443 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3445 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3446 INT nIndex;
3447 LPWSTR lpText;
3448 LRESULT ret = 0;
3450 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3451 if (nIndex == -1)
3452 return -1;
3454 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3456 if (lpText)
3458 ret = strlenW (lpText);
3460 if (lParam)
3461 strcpyW ((LPWSTR)lParam, lpText);
3464 return ret;
3468 static LRESULT
3469 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3471 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3472 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3473 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3477 static inline LRESULT
3478 TOOLBAR_GetExtendedStyle (HWND hwnd)
3480 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3482 TRACE("\n");
3484 return infoPtr->dwExStyle;
3488 static LRESULT
3489 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3491 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3492 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3493 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3497 static LRESULT
3498 TOOLBAR_GetHotItem (HWND hwnd)
3500 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3502 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3503 return -1;
3505 if (infoPtr->nHotItem < 0)
3506 return -1;
3508 return (LRESULT)infoPtr->nHotItem;
3512 static LRESULT
3513 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3515 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3516 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3517 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3521 static LRESULT
3522 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3524 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3525 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3527 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3529 *lptbim = infoPtr->tbim;
3531 return 0;
3535 static LRESULT
3536 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3538 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3540 TRACE("hwnd = %p\n", hwnd);
3542 return (LRESULT)infoPtr->clrInsertMark;
3546 static LRESULT
3547 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3549 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3550 TBUTTON_INFO *btnPtr;
3551 LPRECT lpRect;
3552 INT nIndex;
3554 nIndex = (INT)wParam;
3555 btnPtr = &infoPtr->buttons[nIndex];
3556 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3557 return FALSE;
3558 lpRect = (LPRECT)lParam;
3559 if (lpRect == NULL)
3560 return FALSE;
3561 if (btnPtr->fsState & TBSTATE_HIDDEN)
3562 return FALSE;
3564 lpRect->left = btnPtr->rect.left;
3565 lpRect->right = btnPtr->rect.right;
3566 lpRect->bottom = btnPtr->rect.bottom;
3567 lpRect->top = btnPtr->rect.top;
3569 return TRUE;
3573 static LRESULT
3574 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3576 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3577 LPSIZE lpSize = (LPSIZE)lParam;
3579 if (lpSize == NULL)
3580 return FALSE;
3582 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3583 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3585 TRACE("maximum size %d x %d\n",
3586 infoPtr->rcBound.right - infoPtr->rcBound.left,
3587 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3589 return TRUE;
3593 /* << TOOLBAR_GetObject >> */
3596 static LRESULT
3597 TOOLBAR_GetPadding (HWND hwnd)
3599 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3600 DWORD oldPad;
3602 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3603 return (LRESULT) oldPad;
3607 static LRESULT
3608 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3610 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3611 TBUTTON_INFO *btnPtr;
3612 LPRECT lpRect;
3613 INT nIndex;
3615 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3616 btnPtr = &infoPtr->buttons[nIndex];
3617 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3618 return FALSE;
3619 lpRect = (LPRECT)lParam;
3620 if (lpRect == NULL)
3621 return FALSE;
3623 lpRect->left = btnPtr->rect.left;
3624 lpRect->right = btnPtr->rect.right;
3625 lpRect->bottom = btnPtr->rect.bottom;
3626 lpRect->top = btnPtr->rect.top;
3628 return TRUE;
3632 static LRESULT
3633 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3635 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3637 return infoPtr->nRows;
3641 static LRESULT
3642 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3644 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3645 INT nIndex;
3647 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3648 if (nIndex == -1)
3649 return -1;
3651 return infoPtr->buttons[nIndex].fsState;
3655 static LRESULT
3656 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3658 return GetWindowLongW(hwnd, GWL_STYLE);
3662 static LRESULT
3663 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3665 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3667 return infoPtr->nMaxTextRows;
3671 static LRESULT
3672 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3674 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3676 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3677 TOOLBAR_TooltipCreateControl(infoPtr);
3678 return (LRESULT)infoPtr->hwndToolTip;
3682 static LRESULT
3683 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3685 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3687 TRACE("%s hwnd=%p\n",
3688 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3690 return infoPtr->bUnicode;
3694 static inline LRESULT
3695 TOOLBAR_GetVersion (HWND hwnd)
3697 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3698 return infoPtr->iVersion;
3702 static LRESULT
3703 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3705 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3706 TBUTTON_INFO *btnPtr;
3707 INT nIndex;
3709 TRACE("\n");
3711 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3712 if (nIndex == -1)
3713 return FALSE;
3715 btnPtr = &infoPtr->buttons[nIndex];
3716 if (LOWORD(lParam) == FALSE)
3717 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3718 else
3719 btnPtr->fsState |= TBSTATE_HIDDEN;
3721 TOOLBAR_LayoutToolbar (hwnd);
3723 InvalidateRect (hwnd, NULL, TRUE);
3725 return TRUE;
3729 static inline LRESULT
3730 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3732 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3736 static LRESULT
3737 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3739 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3740 TBUTTON_INFO *btnPtr;
3741 INT nIndex;
3742 DWORD oldState;
3744 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3745 if (nIndex == -1)
3746 return FALSE;
3748 btnPtr = &infoPtr->buttons[nIndex];
3749 oldState = btnPtr->fsState;
3750 if (LOWORD(lParam) == FALSE)
3751 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3752 else
3753 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3755 if(oldState != btnPtr->fsState)
3756 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3758 return TRUE;
3762 static LRESULT
3763 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3765 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3766 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3767 INT nIndex = (INT)wParam;
3769 if (lpTbb == NULL)
3770 return FALSE;
3772 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3774 if (nIndex == -1) {
3775 /* EPP: this seems to be an undocumented call (from my IE4)
3776 * I assume in that case that:
3777 * - index of insertion is at the end of existing buttons
3778 * I only see this happen with nIndex == -1, but it could have a special
3779 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3781 nIndex = infoPtr->nNumButtons;
3783 } else if (nIndex < 0)
3784 return FALSE;
3786 TRACE("inserting button index=%d\n", nIndex);
3787 if (nIndex > infoPtr->nNumButtons) {
3788 nIndex = infoPtr->nNumButtons;
3789 TRACE("adjust index=%d\n", nIndex);
3792 infoPtr->nNumButtons++;
3793 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO) * infoPtr->nNumButtons);
3794 memmove(&infoPtr->buttons[nIndex+1], &infoPtr->buttons[nIndex],
3795 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3797 /* insert new button */
3798 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3799 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3800 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3801 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3802 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3803 /* if passed string and not index, then add string */
3804 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3805 if (fUnicode)
3806 Str_SetPtrW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3807 else
3808 Str_SetPtrAtoW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3810 else
3811 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3813 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
3815 if (infoPtr->nNumStrings > 0)
3816 TOOLBAR_CalcToolbar(hwnd);
3817 else
3818 TOOLBAR_LayoutToolbar(hwnd);
3819 TOOLBAR_AutoSize (hwnd);
3821 InvalidateRect (hwnd, NULL, TRUE);
3823 return TRUE;
3826 /* << TOOLBAR_InsertMarkHitTest >> */
3829 static LRESULT
3830 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3832 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3833 INT nIndex;
3835 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3836 if (nIndex == -1)
3837 return -1;
3839 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3843 static LRESULT
3844 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3846 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3847 INT nIndex;
3849 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3850 if (nIndex == -1)
3851 return -1;
3853 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3857 static LRESULT
3858 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3860 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3861 INT nIndex;
3863 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3864 if (nIndex == -1)
3865 return -1;
3867 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3871 static LRESULT
3872 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3874 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3875 INT nIndex;
3877 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3878 if (nIndex == -1)
3879 return -1;
3881 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3885 static LRESULT
3886 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3888 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3889 INT nIndex;
3891 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3892 if (nIndex == -1)
3893 return -1;
3895 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3899 static LRESULT
3900 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3902 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3903 INT nIndex;
3905 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3906 if (nIndex == -1)
3907 return -1;
3909 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3913 static LRESULT
3914 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3916 TBADDBITMAP tbab;
3917 tbab.hInst = (HINSTANCE)lParam;
3918 tbab.nID = wParam;
3920 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", hwnd, tbab.hInst, tbab.nID);
3922 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3926 static LRESULT
3927 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3929 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3930 WCHAR wAccel = (WCHAR)wParam;
3931 UINT* pIDButton = (UINT*)lParam;
3932 WCHAR wszAccel[] = {'&',wAccel,0};
3933 int i;
3935 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3936 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3938 for (i = 0; i < infoPtr->nNumButtons; i++)
3940 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3941 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3942 !(btnPtr->fsState & TBSTATE_HIDDEN))
3944 int iLen = strlenW(wszAccel);
3945 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3947 if (!lpszStr)
3948 continue;
3950 while (*lpszStr)
3952 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3954 lpszStr += 2;
3955 continue;
3957 if (!strncmpiW(lpszStr, wszAccel, iLen))
3959 *pIDButton = btnPtr->idCommand;
3960 return TRUE;
3962 lpszStr++;
3966 return FALSE;
3970 static LRESULT
3971 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3973 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3974 INT nIndex;
3975 DWORD oldState;
3976 TBUTTON_INFO *btnPtr;
3978 TRACE("hwnd = %p, wParam = %ld, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3980 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3981 if (nIndex == -1)
3982 return FALSE;
3984 btnPtr = &infoPtr->buttons[nIndex];
3985 oldState = btnPtr->fsState;
3987 if (LOWORD(lParam))
3988 btnPtr->fsState |= TBSTATE_MARKED;
3989 else
3990 btnPtr->fsState &= ~TBSTATE_MARKED;
3992 if(oldState != btnPtr->fsState)
3993 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3995 return TRUE;
3999 /* fixes up an index of a button affected by a move */
4000 static inline void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4002 if (bMoveUp)
4004 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4005 (*pIndex)--;
4006 else if (*pIndex == nIndex)
4007 *pIndex = nMoveIndex;
4009 else
4011 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4012 (*pIndex)++;
4013 else if (*pIndex == nIndex)
4014 *pIndex = nMoveIndex;
4019 static LRESULT
4020 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4022 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4023 INT nIndex;
4024 INT nCount;
4025 INT nMoveIndex = (INT)lParam;
4026 TBUTTON_INFO button;
4028 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
4030 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4031 if ((nIndex == -1) || (nMoveIndex < 0))
4032 return FALSE;
4034 if (nMoveIndex > infoPtr->nNumButtons - 1)
4035 nMoveIndex = infoPtr->nNumButtons - 1;
4037 button = infoPtr->buttons[nIndex];
4039 /* move button right */
4040 if (nIndex < nMoveIndex)
4042 nCount = nMoveIndex - nIndex;
4043 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4044 infoPtr->buttons[nMoveIndex] = button;
4046 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4047 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4048 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4049 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4051 else if (nIndex > nMoveIndex) /* move button left */
4053 nCount = nIndex - nMoveIndex;
4054 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4055 infoPtr->buttons[nMoveIndex] = button;
4057 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4058 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4059 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4060 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4063 TOOLBAR_LayoutToolbar(hwnd);
4064 TOOLBAR_AutoSize(hwnd);
4065 InvalidateRect(hwnd, NULL, TRUE);
4067 return TRUE;
4071 static LRESULT
4072 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4074 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4075 TBUTTON_INFO *btnPtr;
4076 INT nIndex;
4077 DWORD oldState;
4079 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4080 if (nIndex == -1)
4081 return FALSE;
4083 btnPtr = &infoPtr->buttons[nIndex];
4084 oldState = btnPtr->fsState;
4085 if (LOWORD(lParam) == FALSE)
4086 btnPtr->fsState &= ~TBSTATE_PRESSED;
4087 else
4088 btnPtr->fsState |= TBSTATE_PRESSED;
4090 if(oldState != btnPtr->fsState)
4091 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4093 return TRUE;
4096 /* FIXME: there might still be some confusion her between number of buttons
4097 * and number of bitmaps */
4098 static LRESULT
4099 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4101 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4102 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4103 HBITMAP hBitmap;
4104 int i = 0, nOldButtons = 0, pos = 0;
4105 int nOldBitmaps, nNewBitmaps = 0;
4106 HIMAGELIST himlDef = 0;
4108 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4109 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4110 lpReplace->nButtons);
4112 if (lpReplace->hInstOld == HINST_COMMCTRL)
4114 FIXME("changing standard bitmaps not implemented\n");
4115 return FALSE;
4117 else if (lpReplace->hInstOld != 0)
4118 FIXME("resources not in the current module not implemented\n");
4120 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4121 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4122 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4123 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4124 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4126 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4127 nOldButtons = tbi->nButtons;
4128 tbi->nButtons = lpReplace->nButtons;
4129 tbi->hInst = lpReplace->hInstNew;
4130 tbi->nID = lpReplace->nIDNew;
4131 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4132 break;
4134 pos += tbi->nButtons;
4137 if (nOldButtons == 0)
4139 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4140 return FALSE;
4143 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4144 * bitmap
4146 if (lpReplace->hInstNew)
4147 hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4148 else
4149 hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
4151 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4152 nOldBitmaps = ImageList_GetImageCount(himlDef);
4154 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4156 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4157 ImageList_Remove(himlDef, i);
4159 if (hBitmap)
4161 ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
4162 nNewBitmaps = ImageList_GetImageCount(himlDef);
4163 DeleteObject(hBitmap);
4166 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4168 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4169 pos, nOldBitmaps, nNewBitmaps);
4171 InvalidateRect(hwnd, NULL, TRUE);
4172 return TRUE;
4176 /* helper for TOOLBAR_SaveRestoreW */
4177 static BOOL
4178 TOOLBAR_Save(const TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
4180 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4181 debugstr_w(lpSave->pszValueName));
4183 return FALSE;
4187 /* helper for TOOLBAR_Restore */
4188 static void
4189 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4191 INT i;
4193 for (i = 0; i < infoPtr->nNumButtons; i++)
4195 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4198 Free(infoPtr->buttons);
4199 infoPtr->buttons = NULL;
4200 infoPtr->nNumButtons = 0;
4204 /* helper for TOOLBAR_SaveRestoreW */
4205 static BOOL
4206 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
4208 LONG res;
4209 HKEY hkey = NULL;
4210 BOOL ret = FALSE;
4211 DWORD dwType;
4212 DWORD dwSize = 0;
4213 NMTBRESTORE nmtbr;
4215 /* restore toolbar information */
4216 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4217 debugstr_w(lpSave->pszValueName));
4219 memset(&nmtbr, 0, sizeof(nmtbr));
4221 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4222 KEY_QUERY_VALUE, &hkey);
4223 if (!res)
4224 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4225 NULL, &dwSize);
4226 if (!res && dwType != REG_BINARY)
4227 res = ERROR_FILE_NOT_FOUND;
4228 if (!res)
4230 nmtbr.pData = Alloc(dwSize);
4231 nmtbr.cbData = dwSize;
4232 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4234 if (!res)
4235 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4236 (LPBYTE)nmtbr.pData, &dwSize);
4237 if (!res)
4239 nmtbr.pCurrent = nmtbr.pData;
4240 nmtbr.iItem = -1;
4241 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4242 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4244 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4246 INT i;
4248 /* remove all existing buttons as this function is designed to
4249 * restore the toolbar to a previously saved state */
4250 TOOLBAR_DeleteAllButtons(infoPtr);
4252 for (i = 0; i < nmtbr.cButtons; i++)
4254 nmtbr.iItem = i;
4255 nmtbr.tbButton.iBitmap = -1;
4256 nmtbr.tbButton.fsState = 0;
4257 nmtbr.tbButton.fsStyle = 0;
4258 nmtbr.tbButton.idCommand = 0;
4259 if (*nmtbr.pCurrent == (DWORD)-1)
4261 /* separator */
4262 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4263 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4265 else if (*nmtbr.pCurrent == (DWORD)-2)
4266 /* hidden button */
4267 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4268 else
4269 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4271 nmtbr.pCurrent++;
4273 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4275 /* can't contain real string as we don't know whether
4276 * the client put an ANSI or Unicode string in there */
4277 if (HIWORD(nmtbr.tbButton.iString))
4278 nmtbr.tbButton.iString = 0;
4280 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4281 (LPARAM)&nmtbr.tbButton, TRUE);
4284 /* do legacy notifications */
4285 if (infoPtr->iVersion < 5)
4287 /* FIXME: send TBN_BEGINADJUST */
4288 FIXME("send TBN_GETBUTTONINFO for each button\n");
4289 /* FIXME: send TBN_ENDADJUST */
4292 /* remove all uninitialised buttons
4293 * note: loop backwards to avoid having to fixup i on a
4294 * delete */
4295 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4296 if (infoPtr->buttons[i].iBitmap == -1)
4297 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4299 /* only indicate success if at least one button survived */
4300 if (infoPtr->nNumButtons > 0) ret = TRUE;
4303 Free (nmtbr.pData);
4304 RegCloseKey(hkey);
4306 return ret;
4310 static LRESULT
4311 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, const TBSAVEPARAMSW *lpSave)
4313 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4315 if (lpSave == NULL) return 0;
4317 if (wParam)
4318 return TOOLBAR_Save(infoPtr, lpSave);
4319 else
4320 return TOOLBAR_Restore(infoPtr, lpSave);
4324 static LRESULT
4325 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, const TBSAVEPARAMSA *lpSave)
4327 LPWSTR pszValueName = 0, pszSubKey = 0;
4328 TBSAVEPARAMSW SaveW;
4329 LRESULT result = 0;
4330 int len;
4332 if (lpSave == NULL) return 0;
4334 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4335 pszSubKey = Alloc(len * sizeof(WCHAR));
4336 if (pszSubKey) goto exit;
4337 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4339 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4340 pszValueName = Alloc(len * sizeof(WCHAR));
4341 if (!pszValueName) goto exit;
4342 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4344 SaveW.pszValueName = pszValueName;
4345 SaveW.pszSubKey = pszSubKey;
4346 SaveW.hkr = lpSave->hkr;
4347 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4349 exit:
4350 Free (pszValueName);
4351 Free (pszSubKey);
4353 return result;
4357 static LRESULT
4358 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4360 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4361 BOOL bOldAnchor = infoPtr->bAnchor;
4363 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4365 infoPtr->bAnchor = (BOOL)wParam;
4367 /* Native does not remove the hot effect from an already hot button */
4369 return (LRESULT)bOldAnchor;
4373 static LRESULT
4374 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4376 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4377 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4379 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
4381 if (wParam != 0)
4382 FIXME("wParam is %ld. Perhaps image list index?\n", wParam);
4384 if (LOWORD(lParam) == 0)
4385 lParam = MAKELPARAM(1, HIWORD(lParam));
4387 if (HIWORD(lParam)==0)
4388 lParam = MAKELPARAM(LOWORD(lParam), 1);
4390 if (infoPtr->nNumButtons > 0)
4391 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4392 infoPtr->nNumButtons,
4393 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4394 LOWORD(lParam), HIWORD(lParam));
4396 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4397 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4399 if ((himlDef == infoPtr->himlInt) &&
4400 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4402 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4403 infoPtr->nBitmapHeight);
4406 TOOLBAR_CalcToolbar(hwnd);
4407 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4408 return TRUE;
4412 static LRESULT
4413 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4415 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4416 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4417 TBUTTON_INFO *btnPtr;
4418 INT nIndex;
4419 RECT oldBtnRect;
4421 if (lptbbi == NULL)
4422 return FALSE;
4423 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4424 return FALSE;
4426 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4427 lptbbi->dwMask & 0x80000000);
4428 if (nIndex == -1)
4429 return FALSE;
4431 btnPtr = &infoPtr->buttons[nIndex];
4432 if (lptbbi->dwMask & TBIF_COMMAND)
4433 btnPtr->idCommand = lptbbi->idCommand;
4434 if (lptbbi->dwMask & TBIF_IMAGE)
4435 btnPtr->iBitmap = lptbbi->iImage;
4436 if (lptbbi->dwMask & TBIF_LPARAM)
4437 btnPtr->dwData = lptbbi->lParam;
4438 if (lptbbi->dwMask & TBIF_SIZE)
4439 btnPtr->cx = lptbbi->cx;
4440 if (lptbbi->dwMask & TBIF_STATE)
4441 btnPtr->fsState = lptbbi->fsState;
4442 if (lptbbi->dwMask & TBIF_STYLE)
4443 btnPtr->fsStyle = lptbbi->fsStyle;
4445 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4446 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4447 /* iString is index, zero it to make Str_SetPtr succeed */
4448 btnPtr->iString=0;
4450 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4453 /* save the button rect to see if we need to redraw the whole toolbar */
4454 oldBtnRect = btnPtr->rect;
4455 TOOLBAR_CalcToolbar(hwnd);
4457 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4458 InvalidateRect(hwnd, NULL, TRUE);
4459 else
4460 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4462 return TRUE;
4466 static LRESULT
4467 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4469 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4470 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4471 TBUTTON_INFO *btnPtr;
4472 INT nIndex;
4473 RECT oldBtnRect;
4475 if (lptbbi == NULL)
4476 return FALSE;
4477 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4478 return FALSE;
4480 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4481 lptbbi->dwMask & 0x80000000);
4482 if (nIndex == -1)
4483 return FALSE;
4485 btnPtr = &infoPtr->buttons[nIndex];
4486 if (lptbbi->dwMask & TBIF_COMMAND)
4487 btnPtr->idCommand = lptbbi->idCommand;
4488 if (lptbbi->dwMask & TBIF_IMAGE)
4489 btnPtr->iBitmap = lptbbi->iImage;
4490 if (lptbbi->dwMask & TBIF_LPARAM)
4491 btnPtr->dwData = lptbbi->lParam;
4492 if (lptbbi->dwMask & TBIF_SIZE)
4493 btnPtr->cx = lptbbi->cx;
4494 if (lptbbi->dwMask & TBIF_STATE)
4495 btnPtr->fsState = lptbbi->fsState;
4496 if (lptbbi->dwMask & TBIF_STYLE)
4497 btnPtr->fsStyle = lptbbi->fsStyle;
4499 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4500 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4501 /* iString is index, zero it to make Str_SetPtr succeed */
4502 btnPtr->iString=0;
4503 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4506 /* save the button rect to see if we need to redraw the whole toolbar */
4507 oldBtnRect = btnPtr->rect;
4508 TOOLBAR_CalcToolbar(hwnd);
4510 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4511 InvalidateRect(hwnd, NULL, TRUE);
4512 else
4513 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4515 return TRUE;
4519 static LRESULT
4520 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4522 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4523 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4525 if ((cx < 0) || (cy < 0))
4527 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4528 return FALSE;
4531 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4533 /* The documentation claims you can only change the button size before
4534 * any button has been added. But this is wrong.
4535 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4536 * it to the toolbar, and it checks that the return value is nonzero - mjm
4537 * Further testing shows that we must actually perform the change too.
4540 * The documentation also does not mention that if 0 is supplied for
4541 * either size, the system changes it to the default of 24 wide and
4542 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4544 if (cx == 0) cx = 24;
4545 if (cy == 0) cx = 22;
4547 cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
4548 cy = max(cy, infoPtr->szPadding.cy + infoPtr->nBitmapHeight);
4550 infoPtr->nButtonWidth = cx;
4551 infoPtr->nButtonHeight = cy;
4553 infoPtr->iTopMargin = default_top_margin(infoPtr);
4554 TOOLBAR_LayoutToolbar(hwnd);
4555 return TRUE;
4559 static LRESULT
4560 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4562 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4564 /* if setting to current values, ignore */
4565 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4566 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4567 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4568 infoPtr->cxMin, infoPtr->cxMax);
4569 return TRUE;
4572 /* save new values */
4573 infoPtr->cxMin = (short)LOWORD(lParam);
4574 infoPtr->cxMax = (short)HIWORD(lParam);
4576 /* otherwise we need to recalc the toolbar and in some cases
4577 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4578 which doesn't actually draw - GA). */
4579 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4580 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4582 TOOLBAR_CalcToolbar (hwnd);
4584 InvalidateRect (hwnd, NULL, TRUE);
4586 return TRUE;
4590 static LRESULT
4591 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4593 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4594 INT nIndex = (INT)wParam;
4596 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4597 return FALSE;
4599 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4601 if (infoPtr->hwndToolTip) {
4603 FIXME("change tool tip!\n");
4607 return TRUE;
4611 static LRESULT
4612 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4614 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4615 HIMAGELIST himl = (HIMAGELIST)lParam;
4616 HIMAGELIST himlTemp;
4617 INT id = 0;
4619 if (infoPtr->iVersion >= 5)
4620 id = wParam;
4622 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4623 &infoPtr->cimlDis, himl, id);
4625 /* FIXME: redraw ? */
4627 return (LRESULT)himlTemp;
4631 static LRESULT
4632 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4634 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4635 DWORD dwTemp;
4637 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4639 dwTemp = infoPtr->dwDTFlags;
4640 infoPtr->dwDTFlags =
4641 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4643 return (LRESULT)dwTemp;
4646 /* This function differs a bit from what MSDN says it does:
4647 * 1. lParam contains extended style flags to OR with current style
4648 * (MSDN isn't clear on the OR bit)
4649 * 2. wParam appears to contain extended style flags to be reset
4650 * (MSDN says that this parameter is reserved)
4652 static LRESULT
4653 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4655 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4656 DWORD dwTemp;
4658 dwTemp = infoPtr->dwExStyle;
4659 infoPtr->dwExStyle &= ~wParam;
4660 infoPtr->dwExStyle |= (DWORD)lParam;
4662 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4664 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4665 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4666 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4668 TOOLBAR_CalcToolbar (hwnd);
4670 TOOLBAR_AutoSize(hwnd);
4672 InvalidateRect(hwnd, NULL, TRUE);
4674 return (LRESULT)dwTemp;
4678 static LRESULT
4679 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4681 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4682 HIMAGELIST himlTemp;
4683 HIMAGELIST himl = (HIMAGELIST)lParam;
4684 INT id = 0;
4686 if (infoPtr->iVersion >= 5)
4687 id = wParam;
4689 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4691 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4692 &infoPtr->cimlHot, himl, id);
4694 /* FIXME: redraw ? */
4696 return (LRESULT)himlTemp;
4700 /* Makes previous hot button no longer hot, makes the specified
4701 * button hot and sends appropriate notifications. dwReason is one or
4702 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4703 * NOTE 1: this function does not validate nHit
4704 * NOTE 2: the name of this function is completely made up and
4705 * not based on any documentation from Microsoft. */
4706 static void
4707 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4709 if (infoPtr->nHotItem != nHit)
4711 NMTBHOTITEM nmhotitem;
4712 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4714 nmhotitem.dwFlags = dwReason;
4715 if(infoPtr->nHotItem >= 0)
4717 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4718 nmhotitem.idOld = oldBtnPtr->idCommand;
4720 else
4722 nmhotitem.dwFlags |= HICF_ENTERING;
4723 nmhotitem.idOld = 0;
4726 if (nHit >= 0)
4728 btnPtr = &infoPtr->buttons[nHit];
4729 nmhotitem.idNew = btnPtr->idCommand;
4731 else
4733 nmhotitem.dwFlags |= HICF_LEAVING;
4734 nmhotitem.idNew = 0;
4737 /* now change the hot and invalidate the old and new buttons - if the
4738 * parent agrees */
4739 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4741 if (oldBtnPtr) {
4742 oldBtnPtr->bHot = FALSE;
4743 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4745 /* setting disabled buttons as hot fails even if the notify contains the button id */
4746 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4747 btnPtr->bHot = TRUE;
4748 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4749 infoPtr->nHotItem = nHit;
4751 else
4752 infoPtr->nHotItem = -1;
4757 static LRESULT
4758 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4760 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4761 INT nOldHotItem = infoPtr->nHotItem;
4763 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4765 if ((INT)wParam > infoPtr->nNumButtons)
4766 return infoPtr->nHotItem;
4768 if ((INT)wParam < 0)
4769 wParam = -1;
4771 /* NOTE: an application can still remove the hot item even if anchor
4772 * highlighting is enabled */
4774 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4776 if (nOldHotItem < 0)
4777 return -1;
4779 return (LRESULT)nOldHotItem;
4783 static LRESULT
4784 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4786 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4787 HIMAGELIST himlTemp;
4788 HIMAGELIST himl = (HIMAGELIST)lParam;
4789 INT oldButtonWidth = infoPtr->nButtonWidth;
4790 INT i, id = 0;
4792 if (infoPtr->iVersion >= 5)
4793 id = wParam;
4795 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4796 &infoPtr->cimlDef, himl, id);
4798 infoPtr->nNumBitmaps = 0;
4799 for (i = 0; i < infoPtr->cimlDef; i++)
4800 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4802 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4803 &infoPtr->nBitmapHeight))
4805 infoPtr->nBitmapWidth = 1;
4806 infoPtr->nBitmapHeight = 1;
4808 TOOLBAR_CalcToolbar(hwnd);
4809 if (infoPtr->nButtonWidth < oldButtonWidth)
4810 TOOLBAR_SetButtonSize(hwnd, 0, MAKELONG(oldButtonWidth, infoPtr->nButtonHeight));
4812 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4813 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4814 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4816 InvalidateRect(hwnd, NULL, TRUE);
4818 return (LRESULT)himlTemp;
4822 static LRESULT
4823 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4825 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4827 infoPtr->nIndent = (INT)wParam;
4829 TRACE("\n");
4831 /* process only on indent changing */
4832 if(infoPtr->nIndent != (INT)wParam)
4834 infoPtr->nIndent = (INT)wParam;
4835 TOOLBAR_CalcToolbar (hwnd);
4836 InvalidateRect(hwnd, NULL, FALSE);
4839 return TRUE;
4843 static LRESULT
4844 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4846 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4847 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4849 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4851 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4853 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4854 return 0;
4857 if ((lptbim->iButton == -1) ||
4858 ((lptbim->iButton < infoPtr->nNumButtons) &&
4859 (lptbim->iButton >= 0)))
4861 infoPtr->tbim = *lptbim;
4862 /* FIXME: don't need to update entire toolbar */
4863 InvalidateRect(hwnd, NULL, TRUE);
4865 else
4866 ERR("Invalid button index %d\n", lptbim->iButton);
4868 return 0;
4872 static LRESULT
4873 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4875 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4877 infoPtr->clrInsertMark = (COLORREF)lParam;
4879 /* FIXME: don't need to update entire toolbar */
4880 InvalidateRect(hwnd, NULL, TRUE);
4882 return 0;
4886 static LRESULT
4887 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4889 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4891 infoPtr->nMaxTextRows = (INT)wParam;
4893 TOOLBAR_CalcToolbar(hwnd);
4894 return TRUE;
4898 /* MSDN gives slightly wrong info on padding.
4899 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4900 * 2. It is not used to create a blank area between the edge of the button
4901 * and the text or image if TBSTYLE_LIST is set. It is used to control
4902 * the gap between the image and text.
4903 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4904 * to control the bottom and right borders [with the border being
4905 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4906 * is shared evenly on both sides of the button.
4907 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4909 static LRESULT
4910 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4912 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4913 DWORD oldPad;
4915 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4916 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4917 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4918 TRACE("cx=%d, cy=%d\n",
4919 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4920 return (LRESULT) oldPad;
4924 static LRESULT
4925 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4927 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4928 HWND hwndOldNotify;
4930 TRACE("\n");
4932 hwndOldNotify = infoPtr->hwndNotify;
4933 infoPtr->hwndNotify = (HWND)wParam;
4935 return (LRESULT)hwndOldNotify;
4939 static LRESULT
4940 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4942 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4943 LPRECT lprc = (LPRECT)lParam;
4944 int rows = LOWORD(wParam);
4945 BOOL bLarger = HIWORD(wParam);
4947 TRACE("\n");
4949 TRACE("Setting rows to %d (%d)\n", rows, bLarger);
4951 if(infoPtr->nRows != rows)
4953 TBUTTON_INFO *btnPtr = infoPtr->buttons;
4954 int curColumn = 0; /* Current column */
4955 int curRow = 0; /* Current row */
4956 int hidden = 0; /* Number of hidden buttons */
4957 int seps = 0; /* Number of separators */
4958 int idealWrap = 0; /* Ideal wrap point */
4959 int i;
4960 BOOL wrap;
4963 Calculate new size and wrap points - Under windows, setrows will
4964 change the dimensions if needed to show the number of requested
4965 rows (if CCS_NORESIZE is set), or will take up the whole window
4966 (if no CCS_NORESIZE).
4968 Basic algorithm - If N buttons, and y rows requested, each row
4969 contains N/y buttons.
4971 FIXME: Handling of separators not obvious from testing results
4972 FIXME: Take width of window into account?
4975 /* Loop through the buttons one by one counting key items */
4976 for (i = 0; i < infoPtr->nNumButtons; i++ )
4978 btnPtr[i].fsState &= ~TBSTATE_WRAP;
4979 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
4980 hidden++;
4981 else if (btnPtr[i].fsStyle & BTNS_SEP)
4982 seps++;
4985 /* FIXME: Separators make this quite complex */
4986 if (seps) FIXME("Separators unhandled\n");
4988 /* Round up so more per line, ie less rows */
4989 idealWrap = (infoPtr->nNumButtons - hidden + (rows-1)) / rows;
4991 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4992 achieve the requested number of rows. */
4993 if (bLarger && idealWrap > 1)
4995 int resRows = (infoPtr->nNumButtons + (idealWrap-1)) / idealWrap;
4996 int moreRows = (infoPtr->nNumButtons + (idealWrap-2)) / (idealWrap-1);
4998 if (resRows < rows && moreRows > rows)
5000 idealWrap--;
5001 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap);
5005 curColumn = curRow = 0;
5006 wrap = FALSE;
5007 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap,
5008 infoPtr->nNumButtons, hidden, rows);
5010 for (i = 0; i < infoPtr->nNumButtons; i++ )
5012 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
5013 continue;
5015 /* Step on, wrap if necessary or flag next to wrap */
5016 if (!wrap) {
5017 curColumn++;
5018 } else {
5019 wrap = FALSE;
5020 curColumn = 1;
5021 curRow++;
5024 if (curColumn > (idealWrap-1)) {
5025 wrap = TRUE;
5026 btnPtr[i].fsState |= TBSTATE_WRAP;
5030 TRACE("Result - %d rows\n", curRow + 1);
5032 /* recalculate toolbar */
5033 TOOLBAR_CalcToolbar (hwnd);
5035 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
5036 if NORESIZE is NOT set, then the toolbar will always be resized to
5037 take up the whole window. With it set, sizing needs to be manual. */
5038 if (infoPtr->dwStyle & CCS_NORESIZE) {
5039 SetWindowPos(hwnd, NULL, 0, 0,
5040 infoPtr->rcBound.right - infoPtr->rcBound.left,
5041 infoPtr->rcBound.bottom - infoPtr->rcBound.top,
5042 SWP_NOMOVE);
5045 /* repaint toolbar */
5046 InvalidateRect(hwnd, NULL, TRUE);
5049 /* return bounding rectangle */
5050 if (lprc) {
5051 lprc->left = infoPtr->rcBound.left;
5052 lprc->right = infoPtr->rcBound.right;
5053 lprc->top = infoPtr->rcBound.top;
5054 lprc->bottom = infoPtr->rcBound.bottom;
5057 return 0;
5061 static LRESULT
5062 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5064 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5065 TBUTTON_INFO *btnPtr;
5066 INT nIndex;
5068 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5069 if (nIndex == -1)
5070 return FALSE;
5072 btnPtr = &infoPtr->buttons[nIndex];
5074 /* if hidden state has changed the invalidate entire window and recalc */
5075 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5076 btnPtr->fsState = LOWORD(lParam);
5077 TOOLBAR_CalcToolbar (hwnd);
5078 InvalidateRect(hwnd, 0, TRUE);
5079 return TRUE;
5082 /* process state changing if current state doesn't match new state */
5083 if(btnPtr->fsState != LOWORD(lParam))
5085 btnPtr->fsState = LOWORD(lParam);
5086 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5089 return TRUE;
5093 static LRESULT
5094 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5096 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5098 return TRUE;
5102 static inline LRESULT
5103 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5105 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5107 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5109 infoPtr->hwndToolTip = (HWND)wParam;
5110 return 0;
5114 static LRESULT
5115 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5117 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5118 BOOL bTemp;
5120 TRACE("%s hwnd=%p\n",
5121 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5123 bTemp = infoPtr->bUnicode;
5124 infoPtr->bUnicode = (BOOL)wParam;
5126 return bTemp;
5130 static LRESULT
5131 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5133 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5135 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5136 comctl32_color.clrBtnHighlight :
5137 infoPtr->clrBtnHighlight;
5138 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5139 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5140 return 1;
5144 static LRESULT
5145 TOOLBAR_SetColorScheme (HWND hwnd, const COLORSCHEME *lParam)
5147 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5149 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5150 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5151 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5153 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5154 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5155 InvalidateRect(hwnd, NULL, TRUE);
5156 return 0;
5160 static LRESULT
5161 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5163 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5164 INT iOldVersion = infoPtr->iVersion;
5166 infoPtr->iVersion = iVersion;
5168 if (infoPtr->iVersion >= 5)
5169 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5171 return iOldVersion;
5175 static LRESULT
5176 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5178 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5179 WORD iString = HIWORD(wParam);
5180 WORD buffersize = LOWORD(wParam);
5181 LPSTR str = (LPSTR)lParam;
5182 LRESULT ret = -1;
5184 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5186 if (iString < infoPtr->nNumStrings)
5188 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5189 ret--;
5191 TRACE("returning %s\n", debugstr_a(str));
5193 else
5194 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5196 return ret;
5200 static LRESULT
5201 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5203 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5204 WORD iString = HIWORD(wParam);
5205 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5206 LPWSTR str = (LPWSTR)lParam;
5207 LRESULT ret = -1;
5209 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5211 if (iString < infoPtr->nNumStrings)
5213 len = min(len, strlenW(infoPtr->strings[iString]));
5214 ret = (len+1)*sizeof(WCHAR);
5215 if (str)
5217 memcpy(str, infoPtr->strings[iString], ret);
5218 str[len] = '\0';
5220 ret = len;
5222 TRACE("returning %s\n", debugstr_w(str));
5224 else
5225 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5227 return ret;
5230 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5231 * is the maximum size of the toolbar? */
5232 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5234 SIZE * pSize = (SIZE*)lParam;
5235 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5236 return 0;
5240 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5241 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5242 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5243 * sends). */
5244 static LRESULT
5245 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5247 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5248 INT nOldHotItem = infoPtr->nHotItem;
5250 TRACE("old item=%d, new item=%d, flags=%08x\n",
5251 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5253 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5254 wParam = -1;
5256 /* NOTE: an application can still remove the hot item even if anchor
5257 * highlighting is enabled */
5259 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5261 GetFocus();
5263 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5266 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5267 * which controls the amount of spacing between the image and the text
5268 * of buttons for TBSTYLE_LIST toolbars. */
5269 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5271 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5273 TRACE("hwnd=%p iListGap=%ld\n", hwnd, wParam);
5275 if (lParam != 0)
5276 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5278 infoPtr->iListGap = (INT)wParam;
5280 InvalidateRect(hwnd, NULL, TRUE);
5282 return 0;
5285 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5286 * of image lists associated with the various states. */
5287 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5289 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5291 TRACE("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5293 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5296 static LRESULT
5297 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5299 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5300 LPSIZE lpsize = (LPSIZE)lParam;
5302 if (lpsize == NULL)
5303 return FALSE;
5306 * Testing shows the following:
5307 * wParam = 0 adjust cx value
5308 * = 1 set cy value to max size.
5309 * lParam pointer to SIZE structure
5312 TRACE("[0463] wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5313 wParam, lParam, lpsize->cx, lpsize->cy);
5315 switch(wParam) {
5316 case 0:
5317 if (lpsize->cx == -1) {
5318 /* **** this is wrong, native measures each button and sets it */
5319 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5321 else if(HIWORD(lpsize->cx)) {
5322 RECT rc;
5323 HWND hwndParent = GetParent(hwnd);
5325 GetWindowRect(hwnd, &rc);
5326 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5327 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc));
5328 lpsize->cx = max(rc.right-rc.left,
5329 infoPtr->rcBound.right - infoPtr->rcBound.left);
5331 else {
5332 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5334 break;
5335 case 1:
5336 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5337 break;
5338 default:
5339 ERR("Unknown wParam %ld for Toolbar message [0463]. Please report\n",
5340 wParam);
5341 return 0;
5343 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5344 lpsize->cx, lpsize->cy);
5345 return 1;
5348 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5350 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5352 InvalidateRect(hwnd, NULL, TRUE);
5353 return 1;
5357 static LRESULT
5358 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5360 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5361 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5362 LOGFONTW logFont;
5364 TRACE("hwnd = %p\n", hwnd);
5366 /* initialize info structure */
5367 infoPtr->nButtonWidth = 23;
5368 infoPtr->nButtonHeight = 22;
5369 infoPtr->nBitmapHeight = 16;
5370 infoPtr->nBitmapWidth = 16;
5372 infoPtr->nMaxTextRows = 1;
5373 infoPtr->cxMin = -1;
5374 infoPtr->cxMax = -1;
5375 infoPtr->nNumBitmaps = 0;
5376 infoPtr->nNumStrings = 0;
5378 infoPtr->bCaptured = FALSE;
5379 infoPtr->nButtonDown = -1;
5380 infoPtr->nButtonDrag = -1;
5381 infoPtr->nOldHit = -1;
5382 infoPtr->nHotItem = -1;
5383 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5384 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5385 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5386 infoPtr->bDragOutSent = FALSE;
5387 infoPtr->iVersion = 0;
5388 infoPtr->hwndSelf = hwnd;
5389 infoPtr->bDoRedraw = TRUE;
5390 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5391 infoPtr->clrBtnShadow = CLR_DEFAULT;
5392 infoPtr->szPadding.cx = DEFPAD_CX;
5393 infoPtr->szPadding.cy = DEFPAD_CY;
5394 infoPtr->iListGap = DEFLISTGAP;
5395 infoPtr->iTopMargin = default_top_margin(infoPtr);
5396 infoPtr->dwStyle = dwStyle;
5397 infoPtr->tbim.iButton = -1;
5398 GetClientRect(hwnd, &infoPtr->client_rect);
5399 infoPtr->bUnicode = infoPtr->hwndNotify &&
5400 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5401 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5403 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5404 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5406 OpenThemeData (hwnd, themeClass);
5408 TOOLBAR_CheckStyle (hwnd, dwStyle);
5410 return 0;
5414 static LRESULT
5415 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5417 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5419 /* delete tooltip control */
5420 if (infoPtr->hwndToolTip)
5421 DestroyWindow (infoPtr->hwndToolTip);
5423 /* delete temporary buffer for tooltip text */
5424 Free (infoPtr->pszTooltipText);
5425 Free (infoPtr->bitmaps); /* bitmaps list */
5427 /* delete button data */
5428 Free (infoPtr->buttons);
5430 /* delete strings */
5431 if (infoPtr->strings) {
5432 INT i;
5433 for (i = 0; i < infoPtr->nNumStrings; i++)
5434 Free (infoPtr->strings[i]);
5436 Free (infoPtr->strings);
5439 /* destroy internal image list */
5440 if (infoPtr->himlInt)
5441 ImageList_Destroy (infoPtr->himlInt);
5443 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5444 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5445 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5447 /* delete default font */
5448 DeleteObject (infoPtr->hDefaultFont);
5450 CloseThemeData (GetWindowTheme (hwnd));
5452 /* free toolbar info data */
5453 Free (infoPtr);
5454 SetWindowLongPtrW (hwnd, 0, 0);
5456 return 0;
5460 static LRESULT
5461 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5463 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5464 NMTBCUSTOMDRAW tbcd;
5465 INT ret = FALSE;
5466 DWORD ntfret;
5467 HTHEME theme = GetWindowTheme (hwnd);
5468 DWORD dwEraseCustDraw = 0;
5470 /* the app has told us not to redraw the toolbar */
5471 if (!infoPtr->bDoRedraw)
5472 return FALSE;
5474 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5475 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5476 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5477 tbcd.nmcd.hdc = (HDC)wParam;
5478 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5479 dwEraseCustDraw = ntfret & 0xffff;
5481 /* FIXME: in general the return flags *can* be or'ed together */
5482 switch (dwEraseCustDraw)
5484 case CDRF_DODEFAULT:
5485 break;
5486 case CDRF_SKIPDEFAULT:
5487 return TRUE;
5488 default:
5489 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5490 hwnd, ntfret);
5494 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5495 * to my parent for processing.
5497 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5498 POINT pt, ptorig;
5499 HDC hdc = (HDC)wParam;
5500 HWND parent;
5502 pt.x = 0;
5503 pt.y = 0;
5504 parent = GetParent(hwnd);
5505 MapWindowPoints(hwnd, parent, &pt, 1);
5506 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5507 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5508 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5510 if (!ret)
5511 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5513 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5514 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5515 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5516 tbcd.nmcd.hdc = (HDC)wParam;
5517 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5518 dwEraseCustDraw = ntfret & 0xffff;
5519 switch (dwEraseCustDraw)
5521 case CDRF_DODEFAULT:
5522 break;
5523 case CDRF_SKIPDEFAULT:
5524 return TRUE;
5525 default:
5526 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5527 hwnd, ntfret);
5530 return ret;
5534 static LRESULT
5535 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5537 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5539 return (LRESULT)infoPtr->hFont;
5543 static void
5544 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5546 INT i;
5547 INT nNewHotItem = infoPtr->nHotItem;
5549 for (i = 0; i < infoPtr->nNumButtons; i++)
5551 /* did we wrap? */
5552 if ((nNewHotItem + iDirection < 0) ||
5553 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5555 NMTBWRAPHOTITEM nmtbwhi;
5556 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5557 nmtbwhi.iDirection = iDirection;
5558 nmtbwhi.dwReason = dwReason;
5560 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5561 return;
5564 nNewHotItem += iDirection;
5565 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5567 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5568 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5570 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5571 break;
5576 static LRESULT
5577 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5579 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5580 NMKEY nmkey;
5582 nmkey.nVKey = (UINT)wParam;
5583 nmkey.uFlags = HIWORD(lParam);
5585 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5586 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5588 switch ((UINT)wParam)
5590 case VK_LEFT:
5591 case VK_UP:
5592 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5593 break;
5594 case VK_RIGHT:
5595 case VK_DOWN:
5596 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5597 break;
5598 case VK_SPACE:
5599 case VK_RETURN:
5600 if ((infoPtr->nHotItem >= 0) &&
5601 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5603 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5604 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5605 (LPARAM)hwnd);
5607 break;
5610 return 0;
5614 static LRESULT
5615 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5617 POINT pt;
5618 INT nHit;
5620 pt.x = (short)LOWORD(lParam);
5621 pt.y = (short)HIWORD(lParam);
5622 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5624 if (nHit >= 0)
5625 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5626 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5627 TOOLBAR_Customize (hwnd);
5629 return 0;
5633 static LRESULT
5634 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5636 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5637 TBUTTON_INFO *btnPtr;
5638 POINT pt;
5639 INT nHit;
5640 NMTOOLBARA nmtb;
5641 NMMOUSE nmmouse;
5642 BOOL bDragKeyPressed;
5644 TRACE("\n");
5646 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5647 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5648 else
5649 bDragKeyPressed = (wParam & MK_SHIFT);
5651 if (infoPtr->hwndToolTip)
5652 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5653 WM_LBUTTONDOWN, wParam, lParam);
5655 pt.x = (short)LOWORD(lParam);
5656 pt.y = (short)HIWORD(lParam);
5657 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5659 btnPtr = &infoPtr->buttons[nHit];
5661 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5663 infoPtr->nButtonDrag = nHit;
5664 SetCapture (hwnd);
5666 /* If drag cursor has not been loaded, load it.
5667 * Note: it doesn't need to be freed */
5668 if (!hCursorDrag)
5669 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5670 SetCursor(hCursorDrag);
5672 else if (nHit >= 0)
5674 RECT arrowRect;
5675 infoPtr->nOldHit = nHit;
5677 CopyRect(&arrowRect, &btnPtr->rect);
5678 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5680 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5681 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5682 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5683 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5684 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5685 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5687 LRESULT res;
5689 /* draw in pressed state */
5690 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5691 btnPtr->fsState |= TBSTATE_PRESSED;
5692 else
5693 btnPtr->bDropDownPressed = TRUE;
5694 RedrawWindow(hwnd,&btnPtr->rect,0,
5695 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5697 memset(&nmtb, 0, sizeof(nmtb));
5698 nmtb.iItem = btnPtr->idCommand;
5699 nmtb.rcButton = btnPtr->rect;
5700 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5701 TBN_DROPDOWN);
5702 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5704 if (res != TBDDRET_TREATPRESSED)
5706 MSG msg;
5708 /* redraw button in unpressed state */
5709 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5710 btnPtr->fsState &= ~TBSTATE_PRESSED;
5711 else
5712 btnPtr->bDropDownPressed = FALSE;
5713 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5715 /* find and set hot item
5716 * NOTE: native doesn't do this, but that is a bug */
5717 GetCursorPos(&pt);
5718 ScreenToClient(hwnd, &pt);
5719 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5720 if (!infoPtr->bAnchor || (nHit >= 0))
5721 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5723 /* remove any left mouse button down or double-click messages
5724 * so that we can get a toggle effect on the button */
5725 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5726 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5729 return 0;
5731 /* otherwise drop through and process as pushed */
5733 infoPtr->bCaptured = TRUE;
5734 infoPtr->nButtonDown = nHit;
5735 infoPtr->bDragOutSent = FALSE;
5737 btnPtr->fsState |= TBSTATE_PRESSED;
5739 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5741 if (btnPtr->fsState & TBSTATE_ENABLED)
5742 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5743 UpdateWindow(hwnd);
5744 SetCapture (hwnd);
5747 if (nHit >=0)
5749 memset(&nmtb, 0, sizeof(nmtb));
5750 nmtb.iItem = btnPtr->idCommand;
5751 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5754 nmmouse.dwHitInfo = nHit;
5756 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5757 if (nHit < 0)
5758 nmmouse.dwItemSpec = -1;
5759 else
5761 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5762 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5765 ClientToScreen(hwnd, &pt);
5766 nmmouse.pt = pt;
5768 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5769 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5771 return 0;
5774 static LRESULT
5775 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5777 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5778 TBUTTON_INFO *btnPtr;
5779 POINT pt;
5780 INT nHit;
5781 INT nOldIndex = -1;
5782 BOOL bSendMessage = TRUE;
5783 NMHDR hdr;
5784 NMMOUSE nmmouse;
5785 NMTOOLBARA nmtb;
5787 if (infoPtr->hwndToolTip)
5788 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5789 WM_LBUTTONUP, wParam, lParam);
5791 pt.x = (short)LOWORD(lParam);
5792 pt.y = (short)HIWORD(lParam);
5793 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5795 if (!infoPtr->bAnchor || (nHit >= 0))
5796 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5798 if (infoPtr->nButtonDrag >= 0) {
5799 RECT rcClient;
5800 NMHDR hdr;
5802 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5803 ReleaseCapture();
5804 /* reset cursor */
5805 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5807 GetClientRect(hwnd, &rcClient);
5808 if (PtInRect(&rcClient, pt))
5810 INT nButton = -1;
5811 if (nHit >= 0)
5812 nButton = nHit;
5813 else if (nHit < -1)
5814 nButton = -nHit;
5815 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5816 nButton = -nHit;
5818 if (nButton == infoPtr->nButtonDrag)
5820 /* if the button is moved sightly left and we have a
5821 * separator there then remove it */
5822 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5824 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5825 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5827 else /* else insert a separator before the dragged button */
5829 TBBUTTON tbb;
5830 memset(&tbb, 0, sizeof(tbb));
5831 tbb.fsStyle = BTNS_SEP;
5832 tbb.iString = -1;
5833 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5836 else
5838 if (nButton == -1)
5840 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5841 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5842 else
5843 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5845 else
5846 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5849 else
5851 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5852 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5855 /* button under cursor changed so need to re-set hot item */
5856 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5857 infoPtr->nButtonDrag = -1;
5859 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5861 else if (infoPtr->nButtonDown >= 0) {
5862 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5863 btnPtr->fsState &= ~TBSTATE_PRESSED;
5865 if (btnPtr->fsStyle & BTNS_CHECK) {
5866 if (btnPtr->fsStyle & BTNS_GROUP) {
5867 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5868 nHit);
5869 if (nOldIndex == nHit)
5870 bSendMessage = FALSE;
5871 if ((nOldIndex != nHit) &&
5872 (nOldIndex != -1))
5873 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5874 btnPtr->fsState |= TBSTATE_CHECKED;
5876 else {
5877 if (btnPtr->fsState & TBSTATE_CHECKED)
5878 btnPtr->fsState &= ~TBSTATE_CHECKED;
5879 else
5880 btnPtr->fsState |= TBSTATE_CHECKED;
5884 if (nOldIndex != -1)
5885 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5888 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5889 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5890 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5892 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5893 ReleaseCapture ();
5894 infoPtr->nButtonDown = -1;
5896 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5897 TOOLBAR_SendNotify (&hdr, infoPtr,
5898 NM_RELEASEDCAPTURE);
5900 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5901 * TBN_BEGINDRAG
5903 memset(&nmtb, 0, sizeof(nmtb));
5904 nmtb.iItem = btnPtr->idCommand;
5905 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5906 TBN_ENDDRAG);
5908 if (btnPtr->fsState & TBSTATE_ENABLED)
5910 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5911 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5913 /* In case we have just been destroyed... */
5914 if(!IsWindow(hwnd))
5915 return 0;
5919 /* !!! Undocumented - toolbar at 4.71 level and above sends
5920 * NM_CLICK with the NMMOUSE structure. */
5921 nmmouse.dwHitInfo = nHit;
5923 if (nHit < 0)
5924 nmmouse.dwItemSpec = -1;
5925 else
5927 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5928 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5931 ClientToScreen(hwnd, &pt);
5932 nmmouse.pt = pt;
5934 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5935 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5937 return 0;
5940 static LRESULT
5941 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5943 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5944 INT nHit;
5945 NMMOUSE nmmouse;
5946 POINT pt;
5948 pt.x = (short)LOWORD(lParam);
5949 pt.y = (short)HIWORD(lParam);
5951 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5952 nmmouse.dwHitInfo = nHit;
5954 if (nHit < 0) {
5955 nmmouse.dwItemSpec = -1;
5956 } else {
5957 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5958 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5961 ClientToScreen(hwnd, &pt);
5962 nmmouse.pt = pt;
5964 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5965 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5967 return 0;
5970 static LRESULT
5971 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5973 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5974 NMHDR nmhdr;
5976 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5977 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5979 return 0;
5982 static LRESULT
5983 TOOLBAR_CaptureChanged(HWND hwnd)
5985 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5986 TBUTTON_INFO *btnPtr;
5988 infoPtr->bCaptured = FALSE;
5990 if (infoPtr->nButtonDown >= 0)
5992 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5993 btnPtr->fsState &= ~TBSTATE_PRESSED;
5995 infoPtr->nOldHit = -1;
5997 if (btnPtr->fsState & TBSTATE_ENABLED)
5998 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6000 return 0;
6003 static LRESULT
6004 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6006 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6008 /* don't remove hot effects when in anchor highlighting mode or when a
6009 * drop-down button is pressed */
6010 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
6012 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
6013 if (!hotBtnPtr->bDropDownPressed)
6014 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6017 if (infoPtr->nOldHit < 0)
6018 return TRUE;
6020 /* If the last button we were over is depressed then make it not */
6021 /* depressed and redraw it */
6022 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6024 TBUTTON_INFO *btnPtr;
6025 RECT rc1;
6027 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6029 btnPtr->fsState &= ~TBSTATE_PRESSED;
6031 rc1 = btnPtr->rect;
6032 InflateRect (&rc1, 1, 1);
6033 InvalidateRect (hwnd, &rc1, TRUE);
6036 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6038 NMTOOLBARW nmt;
6039 ZeroMemory(&nmt, sizeof(nmt));
6040 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6041 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6042 infoPtr->bDragOutSent = TRUE;
6045 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6047 return TRUE;
6050 static LRESULT
6051 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6053 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6054 POINT pt;
6055 TRACKMOUSEEVENT trackinfo;
6056 INT nHit;
6057 TBUTTON_INFO *btnPtr;
6059 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6060 TOOLBAR_TooltipCreateControl(infoPtr);
6062 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6063 /* fill in the TRACKMOUSEEVENT struct */
6064 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6065 trackinfo.dwFlags = TME_QUERY;
6067 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6068 _TrackMouseEvent(&trackinfo);
6070 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6071 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6072 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6073 trackinfo.hwndTrack = hwnd;
6075 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6076 /* and can properly deactivate the hot toolbar button */
6077 _TrackMouseEvent(&trackinfo);
6081 if (infoPtr->hwndToolTip)
6082 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6083 WM_MOUSEMOVE, wParam, lParam);
6085 pt.x = (short)LOWORD(lParam);
6086 pt.y = (short)HIWORD(lParam);
6088 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6090 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6091 && (!infoPtr->bAnchor || (nHit >= 0)))
6092 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6094 if (infoPtr->nOldHit != nHit)
6096 if (infoPtr->bCaptured)
6098 if (!infoPtr->bDragOutSent)
6100 NMTOOLBARW nmt;
6101 ZeroMemory(&nmt, sizeof(nmt));
6102 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6103 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6104 infoPtr->bDragOutSent = TRUE;
6107 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6108 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6109 btnPtr->fsState &= ~TBSTATE_PRESSED;
6110 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6112 else if (nHit == infoPtr->nButtonDown) {
6113 btnPtr->fsState |= TBSTATE_PRESSED;
6114 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6116 infoPtr->nOldHit = nHit;
6120 return 0;
6124 static inline LRESULT
6125 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6127 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6128 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6129 /* else */
6130 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6134 static inline LRESULT
6135 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6137 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6138 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6140 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6144 static LRESULT
6145 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6147 TOOLBAR_INFO *infoPtr;
6148 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6149 DWORD styleadd = 0;
6151 /* allocate memory for info structure */
6152 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6153 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6155 /* paranoid!! */
6156 infoPtr->dwStructSize = sizeof(TBBUTTON);
6157 infoPtr->nRows = 1;
6158 infoPtr->nWidth = 0;
6160 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6161 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6162 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6163 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6166 /* native control does:
6167 * Get a lot of colors and brushes
6168 * WM_NOTIFYFORMAT
6169 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6170 * CreateFontIndirectW(adr1)
6171 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6172 * hdc = GetDC(toolbar)
6173 * GetSystemMetrics(0x48)
6174 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6175 * 0, 0, 0, 0, "MARLETT")
6176 * oldfnt = SelectObject(hdc, fnt2)
6177 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6178 * GetTextMetricsW(hdc, adr3)
6179 * SelectObject(hdc, oldfnt)
6180 * DeleteObject(fnt2)
6181 * ReleaseDC(hdc)
6182 * InvalidateRect(toolbar, 0, 1)
6183 * SetWindowLongW(toolbar, 0, addr)
6184 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6185 * WM_STYLECHANGING
6186 * CallWinEx old new
6187 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6188 * ie 2 0x4600094c 0x4600094c 0x4600894d
6189 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6190 * rebar 0x50008844 0x40008844 0x50008845
6191 * pager 0x50000844 0x40000844 0x50008845
6192 * IC35mgr 0x5400084e **nochange**
6193 * on entry to _NCCREATE 0x5400084e
6194 * rowlist 0x5400004e **nochange**
6195 * on entry to _NCCREATE 0x5400004e
6199 /* I think the code below is a bug, but it is the way that the native
6200 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6201 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6202 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6203 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6204 * Somehow, the only cases of this seem to be MFC programs.
6206 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6207 * does not occur in the WM_STYLECHANGING routine.
6208 * (Guy Albertelli 9/2001)
6211 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6212 && !(cs->style & TBSTYLE_TRANSPARENT))
6213 styleadd |= TBSTYLE_TRANSPARENT;
6214 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6215 styleadd |= CCS_TOP; /* default to top */
6216 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6219 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6223 static LRESULT
6224 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6226 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6227 RECT rcWindow;
6228 HDC hdc;
6230 if (dwStyle & WS_MINIMIZE)
6231 return 0; /* Nothing to do */
6233 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6235 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6236 return 0;
6238 if (!(dwStyle & CCS_NODIVIDER))
6240 GetWindowRect (hwnd, &rcWindow);
6241 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6242 if( dwStyle & WS_BORDER )
6243 OffsetRect (&rcWindow, 1, 1);
6244 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6247 ReleaseDC( hwnd, hdc );
6249 return 0;
6253 /* handles requests from the tooltip control on what text to display */
6254 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6256 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6258 TRACE("button index = %d\n", index);
6260 Free (infoPtr->pszTooltipText);
6261 infoPtr->pszTooltipText = NULL;
6263 if (index < 0)
6264 return 0;
6266 if (infoPtr->bUnicode)
6268 WCHAR wszBuffer[INFOTIPSIZE+1];
6269 NMTBGETINFOTIPW tbgit;
6270 unsigned int len; /* in chars */
6272 wszBuffer[0] = '\0';
6273 wszBuffer[INFOTIPSIZE] = '\0';
6275 tbgit.pszText = wszBuffer;
6276 tbgit.cchTextMax = INFOTIPSIZE;
6277 tbgit.iItem = lpnmtdi->hdr.idFrom;
6278 tbgit.lParam = infoPtr->buttons[index].dwData;
6280 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6282 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6284 len = strlenW(tbgit.pszText);
6285 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6287 /* need to allocate temporary buffer in infoPtr as there
6288 * isn't enough space in buffer passed to us by the
6289 * tooltip control */
6290 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6291 if (infoPtr->pszTooltipText)
6293 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6294 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6295 return 0;
6298 else if (len > 0)
6300 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6301 return 0;
6304 else
6306 CHAR szBuffer[INFOTIPSIZE+1];
6307 NMTBGETINFOTIPA tbgit;
6308 unsigned int len; /* in chars */
6310 szBuffer[0] = '\0';
6311 szBuffer[INFOTIPSIZE] = '\0';
6313 tbgit.pszText = szBuffer;
6314 tbgit.cchTextMax = INFOTIPSIZE;
6315 tbgit.iItem = lpnmtdi->hdr.idFrom;
6316 tbgit.lParam = infoPtr->buttons[index].dwData;
6318 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6320 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6322 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6323 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6325 /* need to allocate temporary buffer in infoPtr as there
6326 * isn't enough space in buffer passed to us by the
6327 * tooltip control */
6328 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6329 if (infoPtr->pszTooltipText)
6331 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6332 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6333 return 0;
6336 else if (tbgit.pszText[0])
6338 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6339 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6340 return 0;
6344 /* if button has text, but it is not shown then automatically
6345 * use that text as tooltip */
6346 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6347 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6349 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6350 unsigned int len = pszText ? strlenW(pszText) : 0;
6352 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6354 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6356 /* need to allocate temporary buffer in infoPtr as there
6357 * isn't enough space in buffer passed to us by the
6358 * tooltip control */
6359 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6360 if (infoPtr->pszTooltipText)
6362 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6363 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6364 return 0;
6367 else if (len > 0)
6369 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6370 return 0;
6374 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6376 /* last resort: send notification on to app */
6377 /* FIXME: find out what is really used here */
6378 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, lpnmtdi->hdr.idFrom, (LPARAM)lpnmtdi);
6382 static inline LRESULT
6383 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6385 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6386 LPNMHDR lpnmh = (LPNMHDR)lParam;
6388 switch (lpnmh->code)
6390 case PGN_CALCSIZE:
6392 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6394 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6395 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6396 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6397 lppgc->iWidth);
6399 else {
6400 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6401 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6402 lppgc->iHeight);
6404 return 0;
6407 case PGN_SCROLL:
6409 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6411 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6412 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6413 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6414 lppgs->iScroll, lppgs->iDir);
6415 return 0;
6418 case TTN_GETDISPINFOW:
6419 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6421 case TTN_GETDISPINFOA:
6422 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6423 return 0;
6425 default:
6426 return 0;
6431 static LRESULT
6432 TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6434 LRESULT format;
6436 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam, lParam);
6438 if (lParam == NF_QUERY)
6439 return NFR_UNICODE;
6441 if (lParam == NF_REQUERY) {
6442 format = SendMessageW(infoPtr->hwndNotify,
6443 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6444 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6445 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6446 format);
6447 format = NFR_ANSI;
6449 return format;
6451 return 0;
6455 static LRESULT
6456 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6458 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6459 HDC hdc;
6460 PAINTSTRUCT ps;
6462 /* fill ps.rcPaint with a default rect */
6463 ps.rcPaint = infoPtr->rcBound;
6465 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6467 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps.rcPaint));
6469 TOOLBAR_Refresh (hwnd, hdc, &ps);
6470 if (!wParam) EndPaint (hwnd, &ps);
6472 return 0;
6476 static LRESULT
6477 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6479 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6481 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6483 /* make first item hot */
6484 if (infoPtr->nNumButtons > 0)
6485 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6487 return 0;
6490 static LRESULT
6491 TOOLBAR_SetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
6493 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6495 TRACE("font=%p redraw=%ld\n", (HFONT)wParam, lParam);
6497 if (wParam == 0)
6498 infoPtr->hFont = infoPtr->hDefaultFont;
6499 else
6500 infoPtr->hFont = (HFONT)wParam;
6502 TOOLBAR_CalcToolbar(hwnd);
6504 if (lParam)
6505 InvalidateRect(hwnd, NULL, TRUE);
6506 return 1;
6509 static LRESULT
6510 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6511 /*****************************************************
6513 * Function;
6514 * Handles the WM_SETREDRAW message.
6516 * Documentation:
6517 * According to testing V4.71 of COMCTL32 returns the
6518 * *previous* status of the redraw flag (either 0 or 1)
6519 * instead of the MSDN documented value of 0 if handled.
6520 * (For laughs see the "consistency" with same function
6521 * in rebar.)
6523 *****************************************************/
6525 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6526 BOOL oldredraw = infoPtr->bDoRedraw;
6528 TRACE("set to %s\n",
6529 (wParam) ? "TRUE" : "FALSE");
6530 infoPtr->bDoRedraw = (BOOL) wParam;
6531 if (wParam) {
6532 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6534 return (oldredraw) ? 1 : 0;
6538 static LRESULT
6539 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6541 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6543 TRACE("sizing toolbar!\n");
6545 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6547 RECT delta_width, delta_height, client, dummy;
6548 DWORD min_x, max_x, min_y, max_y;
6549 TBUTTON_INFO *btnPtr;
6550 INT i;
6552 GetClientRect(hwnd, &client);
6553 if(client.right > infoPtr->client_rect.right)
6555 min_x = infoPtr->client_rect.right;
6556 max_x = client.right;
6558 else
6560 max_x = infoPtr->client_rect.right;
6561 min_x = client.right;
6563 if(client.bottom > infoPtr->client_rect.bottom)
6565 min_y = infoPtr->client_rect.bottom;
6566 max_y = client.bottom;
6568 else
6570 max_y = infoPtr->client_rect.bottom;
6571 min_y = client.bottom;
6574 SetRect(&delta_width, min_x, 0, max_x, min_y);
6575 SetRect(&delta_height, 0, min_y, max_x, max_y);
6577 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6578 btnPtr = infoPtr->buttons;
6579 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6580 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6581 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6582 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6584 GetClientRect(hwnd, &infoPtr->client_rect);
6585 TOOLBAR_AutoSize(hwnd);
6586 return 0;
6590 static LRESULT
6591 TOOLBAR_StyleChanged (HWND hwnd, INT nType, const STYLESTRUCT *lpStyle)
6593 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6595 if (nType == GWL_STYLE)
6597 DWORD dwOldStyle = infoPtr->dwStyle;
6599 if (lpStyle->styleNew & TBSTYLE_LIST)
6600 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6601 else
6602 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6604 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6606 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6608 infoPtr->dwStyle = lpStyle->styleNew;
6610 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6611 TOOLBAR_LayoutToolbar(hwnd);
6613 /* only resize if one of the CCS_* styles was changed */
6614 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6616 TOOLBAR_AutoSize (hwnd);
6618 InvalidateRect(hwnd, NULL, TRUE);
6622 return 0;
6626 static LRESULT
6627 TOOLBAR_SysColorChange (HWND hwnd)
6629 COMCTL32_RefreshSysColors();
6631 return 0;
6635 /* update theme after a WM_THEMECHANGED message */
6636 static LRESULT theme_changed (HWND hwnd)
6638 HTHEME theme = GetWindowTheme (hwnd);
6639 CloseThemeData (theme);
6640 OpenThemeData (hwnd, themeClass);
6641 return 0;
6645 static LRESULT WINAPI
6646 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6648 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6650 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6651 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6653 if (!infoPtr && (uMsg != WM_NCCREATE))
6654 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6656 switch (uMsg)
6658 case TB_ADDBITMAP:
6659 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6661 case TB_ADDBUTTONSA:
6662 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6664 case TB_ADDBUTTONSW:
6665 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6667 case TB_ADDSTRINGA:
6668 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6670 case TB_ADDSTRINGW:
6671 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6673 case TB_AUTOSIZE:
6674 return TOOLBAR_AutoSize (hwnd);
6676 case TB_BUTTONCOUNT:
6677 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6679 case TB_BUTTONSTRUCTSIZE:
6680 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6682 case TB_CHANGEBITMAP:
6683 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6685 case TB_CHECKBUTTON:
6686 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6688 case TB_COMMANDTOINDEX:
6689 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6691 case TB_CUSTOMIZE:
6692 return TOOLBAR_Customize (hwnd);
6694 case TB_DELETEBUTTON:
6695 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6697 case TB_ENABLEBUTTON:
6698 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6700 case TB_GETANCHORHIGHLIGHT:
6701 return TOOLBAR_GetAnchorHighlight (hwnd);
6703 case TB_GETBITMAP:
6704 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6706 case TB_GETBITMAPFLAGS:
6707 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6709 case TB_GETBUTTON:
6710 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6712 case TB_GETBUTTONINFOA:
6713 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, FALSE);
6715 case TB_GETBUTTONINFOW:
6716 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, TRUE);
6718 case TB_GETBUTTONSIZE:
6719 return TOOLBAR_GetButtonSize (hwnd);
6721 case TB_GETBUTTONTEXTA:
6722 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6724 case TB_GETBUTTONTEXTW:
6725 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6727 case TB_GETDISABLEDIMAGELIST:
6728 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6730 case TB_GETEXTENDEDSTYLE:
6731 return TOOLBAR_GetExtendedStyle (hwnd);
6733 case TB_GETHOTIMAGELIST:
6734 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6736 case TB_GETHOTITEM:
6737 return TOOLBAR_GetHotItem (hwnd);
6739 case TB_GETIMAGELIST:
6740 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6742 case TB_GETINSERTMARK:
6743 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6745 case TB_GETINSERTMARKCOLOR:
6746 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6748 case TB_GETITEMRECT:
6749 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6751 case TB_GETMAXSIZE:
6752 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6754 /* case TB_GETOBJECT: */ /* 4.71 */
6756 case TB_GETPADDING:
6757 return TOOLBAR_GetPadding (hwnd);
6759 case TB_GETRECT:
6760 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6762 case TB_GETROWS:
6763 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6765 case TB_GETSTATE:
6766 return TOOLBAR_GetState (hwnd, wParam, lParam);
6768 case TB_GETSTRINGA:
6769 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6771 case TB_GETSTRINGW:
6772 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6774 case TB_GETSTYLE:
6775 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6777 case TB_GETTEXTROWS:
6778 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6780 case TB_GETTOOLTIPS:
6781 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6783 case TB_GETUNICODEFORMAT:
6784 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6786 case TB_HIDEBUTTON:
6787 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6789 case TB_HITTEST:
6790 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6792 case TB_INDETERMINATE:
6793 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6795 case TB_INSERTBUTTONA:
6796 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6798 case TB_INSERTBUTTONW:
6799 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6801 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6803 case TB_ISBUTTONCHECKED:
6804 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6806 case TB_ISBUTTONENABLED:
6807 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6809 case TB_ISBUTTONHIDDEN:
6810 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6812 case TB_ISBUTTONHIGHLIGHTED:
6813 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6815 case TB_ISBUTTONINDETERMINATE:
6816 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6818 case TB_ISBUTTONPRESSED:
6819 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6821 case TB_LOADIMAGES:
6822 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6824 case TB_MAPACCELERATORA:
6825 case TB_MAPACCELERATORW:
6826 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6828 case TB_MARKBUTTON:
6829 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6831 case TB_MOVEBUTTON:
6832 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6834 case TB_PRESSBUTTON:
6835 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6837 case TB_REPLACEBITMAP:
6838 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6840 case TB_SAVERESTOREA:
6841 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6843 case TB_SAVERESTOREW:
6844 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6846 case TB_SETANCHORHIGHLIGHT:
6847 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6849 case TB_SETBITMAPSIZE:
6850 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6852 case TB_SETBUTTONINFOA:
6853 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6855 case TB_SETBUTTONINFOW:
6856 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6858 case TB_SETBUTTONSIZE:
6859 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6861 case TB_SETBUTTONWIDTH:
6862 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6864 case TB_SETCMDID:
6865 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6867 case TB_SETDISABLEDIMAGELIST:
6868 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6870 case TB_SETDRAWTEXTFLAGS:
6871 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6873 case TB_SETEXTENDEDSTYLE:
6874 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6876 case TB_SETHOTIMAGELIST:
6877 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6879 case TB_SETHOTITEM:
6880 return TOOLBAR_SetHotItem (hwnd, wParam);
6882 case TB_SETIMAGELIST:
6883 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6885 case TB_SETINDENT:
6886 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6888 case TB_SETINSERTMARK:
6889 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6891 case TB_SETINSERTMARKCOLOR:
6892 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6894 case TB_SETMAXTEXTROWS:
6895 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6897 case TB_SETPADDING:
6898 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6900 case TB_SETPARENT:
6901 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6903 case TB_SETROWS:
6904 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6906 case TB_SETSTATE:
6907 return TOOLBAR_SetState (hwnd, wParam, lParam);
6909 case TB_SETSTYLE:
6910 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6912 case TB_SETTOOLTIPS:
6913 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6915 case TB_SETUNICODEFORMAT:
6916 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6918 case TB_UNKWN45D:
6919 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6921 case TB_UNKWN45E:
6922 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6924 case TB_UNKWN460:
6925 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6927 case TB_UNKWN462:
6928 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6930 case TB_UNKWN463:
6931 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6933 case TB_UNKWN464:
6934 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6936 /* Common Control Messages */
6938 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6939 case CCM_GETCOLORSCHEME:
6940 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6942 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6943 case CCM_SETCOLORSCHEME:
6944 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6946 case CCM_GETVERSION:
6947 return TOOLBAR_GetVersion (hwnd);
6949 case CCM_SETVERSION:
6950 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6953 /* case WM_CHAR: */
6955 case WM_CREATE:
6956 return TOOLBAR_Create (hwnd, wParam, lParam);
6958 case WM_DESTROY:
6959 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6961 case WM_ERASEBKGND:
6962 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6964 case WM_GETFONT:
6965 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6967 case WM_KEYDOWN:
6968 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6970 /* case WM_KILLFOCUS: */
6972 case WM_LBUTTONDBLCLK:
6973 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6975 case WM_LBUTTONDOWN:
6976 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6978 case WM_LBUTTONUP:
6979 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6981 case WM_RBUTTONUP:
6982 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6984 case WM_RBUTTONDBLCLK:
6985 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6987 case WM_MOUSEMOVE:
6988 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6990 case WM_MOUSELEAVE:
6991 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6993 case WM_CAPTURECHANGED:
6994 return TOOLBAR_CaptureChanged(hwnd);
6996 case WM_NCACTIVATE:
6997 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6999 case WM_NCCALCSIZE:
7000 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7002 case WM_NCCREATE:
7003 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7005 case WM_NCPAINT:
7006 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7008 case WM_NOTIFY:
7009 return TOOLBAR_Notify (hwnd, wParam, lParam);
7011 case WM_NOTIFYFORMAT:
7012 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7014 case WM_PRINTCLIENT:
7015 case WM_PAINT:
7016 return TOOLBAR_Paint (hwnd, wParam);
7018 case WM_SETFOCUS:
7019 return TOOLBAR_SetFocus (hwnd, wParam);
7021 case WM_SETFONT:
7022 return TOOLBAR_SetFont(hwnd, wParam, lParam);
7024 case WM_SETREDRAW:
7025 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7027 case WM_SIZE:
7028 return TOOLBAR_Size (hwnd, wParam, lParam);
7030 case WM_STYLECHANGED:
7031 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7033 case WM_SYSCOLORCHANGE:
7034 return TOOLBAR_SysColorChange (hwnd);
7036 case WM_THEMECHANGED:
7037 return theme_changed (hwnd);
7039 /* case WM_WININICHANGE: */
7041 case WM_CHARTOITEM:
7042 case WM_COMMAND:
7043 case WM_DRAWITEM:
7044 case WM_MEASUREITEM:
7045 case WM_VKEYTOITEM:
7046 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7048 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7049 case PGM_FORWARDMOUSE:
7050 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7052 default:
7053 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7054 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
7055 uMsg, wParam, lParam);
7056 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7061 VOID
7062 TOOLBAR_Register (void)
7064 WNDCLASSW wndClass;
7066 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7067 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7068 wndClass.lpfnWndProc = ToolbarWindowProc;
7069 wndClass.cbClsExtra = 0;
7070 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7071 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7072 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7073 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7075 RegisterClassW (&wndClass);
7079 VOID
7080 TOOLBAR_Unregister (void)
7082 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7085 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7087 HIMAGELIST himlold;
7088 PIMLENTRY c = NULL;
7090 /* Check if the entry already exists */
7091 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7093 /* If this is a new entry we must create it and insert into the array */
7094 if (!c)
7096 PIMLENTRY *pnies;
7098 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7099 c->id = id;
7101 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7102 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7103 pnies[*cies] = c;
7104 (*cies)++;
7106 Free(*pies);
7107 *pies = pnies;
7110 himlold = c->himl;
7111 c->himl = himl;
7113 return himlold;
7117 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7119 int i;
7121 for (i = 0; i < *cies; i++)
7122 Free((*pies)[i]);
7124 Free(*pies);
7126 *cies = 0;
7127 *pies = NULL;
7131 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id)
7133 PIMLENTRY c = NULL;
7135 if (pies != NULL)
7137 int i;
7139 for (i = 0; i < cies; i++)
7141 if (pies[i]->id == id)
7143 c = pies[i];
7144 break;
7149 return c;
7153 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id)
7155 HIMAGELIST himlDef = 0;
7156 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7158 if (pie)
7159 himlDef = pie->himl;
7161 return himlDef;
7165 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7167 if (infoPtr->bUnicode)
7168 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7169 else
7171 CHAR Buffer[256];
7172 NMTOOLBARA nmtba;
7173 BOOL bRet = FALSE;
7175 nmtba.iItem = nmtb->iItem;
7176 nmtba.pszText = Buffer;
7177 nmtba.cchText = 256;
7178 ZeroMemory(nmtba.pszText, nmtba.cchText);
7180 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7182 int ccht = strlen(nmtba.pszText);
7183 if (ccht)
7184 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7185 nmtb->pszText, nmtb->cchText);
7187 nmtb->tbButton = nmtba.tbButton;
7188 bRet = TRUE;
7191 return bRet;
7196 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo)
7198 NMTOOLBARW nmtb;
7200 /* MSDN states that iItem is the index of the button, rather than the
7201 * command ID as used by every other NMTOOLBAR notification */
7202 nmtb.iItem = iItem;
7203 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7205 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);