push a18c97e3310ae68c9cf1d09430f25ca292f320eb
[wine/hacks.git] / dlls / comctl32 / toolbar.c
blob6d88461456eb53f5ef773b8216e212854ae26329
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 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
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 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(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);
5190 TRACE("returning %s\n", debugstr_a(str));
5192 else
5193 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5195 return ret;
5199 static LRESULT
5200 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5202 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5203 WORD iString = HIWORD(wParam);
5204 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5205 LPWSTR str = (LPWSTR)lParam;
5206 LRESULT ret = -1;
5208 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5210 if (iString < infoPtr->nNumStrings)
5212 len = min(len, strlenW(infoPtr->strings[iString]));
5213 ret = (len+1)*sizeof(WCHAR);
5214 memcpy(str, infoPtr->strings[iString], ret);
5215 str[len] = '\0';
5217 TRACE("returning %s\n", debugstr_w(str));
5219 else
5220 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5222 return ret;
5225 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5226 * is the maximum size of the toolbar? */
5227 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5229 SIZE * pSize = (SIZE*)lParam;
5230 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5231 return 0;
5235 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5236 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5237 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5238 * sends). */
5239 static LRESULT
5240 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5242 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5243 INT nOldHotItem = infoPtr->nHotItem;
5245 TRACE("old item=%d, new item=%d, flags=%08x\n",
5246 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5248 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5249 wParam = -1;
5251 /* NOTE: an application can still remove the hot item even if anchor
5252 * highlighting is enabled */
5254 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5256 GetFocus();
5258 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5261 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5262 * which controls the amount of spacing between the image and the text
5263 * of buttons for TBSTYLE_LIST toolbars. */
5264 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5266 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5268 TRACE("hwnd=%p iListGap=%ld\n", hwnd, wParam);
5270 if (lParam != 0)
5271 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5273 infoPtr->iListGap = (INT)wParam;
5275 InvalidateRect(hwnd, NULL, TRUE);
5277 return 0;
5280 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5281 * of image lists associated with the various states. */
5282 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5284 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5286 TRACE("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5288 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5291 static LRESULT
5292 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5294 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5295 LPSIZE lpsize = (LPSIZE)lParam;
5297 if (lpsize == NULL)
5298 return FALSE;
5301 * Testing shows the following:
5302 * wParam = 0 adjust cx value
5303 * = 1 set cy value to max size.
5304 * lParam pointer to SIZE structure
5307 TRACE("[0463] wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5308 wParam, lParam, lpsize->cx, lpsize->cy);
5310 switch(wParam) {
5311 case 0:
5312 if (lpsize->cx == -1) {
5313 /* **** this is wrong, native measures each button and sets it */
5314 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5316 else if(HIWORD(lpsize->cx)) {
5317 RECT rc;
5318 HWND hwndParent = GetParent(hwnd);
5320 GetWindowRect(hwnd, &rc);
5321 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5322 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc));
5323 lpsize->cx = max(rc.right-rc.left,
5324 infoPtr->rcBound.right - infoPtr->rcBound.left);
5326 else {
5327 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5329 break;
5330 case 1:
5331 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5332 break;
5333 default:
5334 ERR("Unknown wParam %ld for Toolbar message [0463]. Please report\n",
5335 wParam);
5336 return 0;
5338 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5339 lpsize->cx, lpsize->cy);
5340 return 1;
5343 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5345 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5347 InvalidateRect(hwnd, NULL, TRUE);
5348 return 1;
5352 static LRESULT
5353 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5355 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5356 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5357 LOGFONTW logFont;
5359 TRACE("hwnd = %p\n", hwnd);
5361 /* initialize info structure */
5362 infoPtr->nButtonWidth = 23;
5363 infoPtr->nButtonHeight = 22;
5364 infoPtr->nBitmapHeight = 16;
5365 infoPtr->nBitmapWidth = 16;
5367 infoPtr->nMaxTextRows = 1;
5368 infoPtr->cxMin = -1;
5369 infoPtr->cxMax = -1;
5370 infoPtr->nNumBitmaps = 0;
5371 infoPtr->nNumStrings = 0;
5373 infoPtr->bCaptured = FALSE;
5374 infoPtr->nButtonDown = -1;
5375 infoPtr->nButtonDrag = -1;
5376 infoPtr->nOldHit = -1;
5377 infoPtr->nHotItem = -1;
5378 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5379 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5380 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5381 infoPtr->bDragOutSent = FALSE;
5382 infoPtr->iVersion = 0;
5383 infoPtr->hwndSelf = hwnd;
5384 infoPtr->bDoRedraw = TRUE;
5385 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5386 infoPtr->clrBtnShadow = CLR_DEFAULT;
5387 infoPtr->szPadding.cx = DEFPAD_CX;
5388 infoPtr->szPadding.cy = DEFPAD_CY;
5389 infoPtr->iListGap = DEFLISTGAP;
5390 infoPtr->iTopMargin = default_top_margin(infoPtr);
5391 infoPtr->dwStyle = dwStyle;
5392 infoPtr->tbim.iButton = -1;
5393 GetClientRect(hwnd, &infoPtr->client_rect);
5394 infoPtr->bUnicode = infoPtr->hwndNotify &&
5395 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5396 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5398 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5399 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5401 OpenThemeData (hwnd, themeClass);
5403 TOOLBAR_CheckStyle (hwnd, dwStyle);
5405 return 0;
5409 static LRESULT
5410 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5412 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5414 /* delete tooltip control */
5415 if (infoPtr->hwndToolTip)
5416 DestroyWindow (infoPtr->hwndToolTip);
5418 /* delete temporary buffer for tooltip text */
5419 Free (infoPtr->pszTooltipText);
5420 Free (infoPtr->bitmaps); /* bitmaps list */
5422 /* delete button data */
5423 Free (infoPtr->buttons);
5425 /* delete strings */
5426 if (infoPtr->strings) {
5427 INT i;
5428 for (i = 0; i < infoPtr->nNumStrings; i++)
5429 Free (infoPtr->strings[i]);
5431 Free (infoPtr->strings);
5434 /* destroy internal image list */
5435 if (infoPtr->himlInt)
5436 ImageList_Destroy (infoPtr->himlInt);
5438 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5439 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5440 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5442 /* delete default font */
5443 DeleteObject (infoPtr->hDefaultFont);
5445 CloseThemeData (GetWindowTheme (hwnd));
5447 /* free toolbar info data */
5448 Free (infoPtr);
5449 SetWindowLongPtrW (hwnd, 0, 0);
5451 return 0;
5455 static LRESULT
5456 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5458 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5459 NMTBCUSTOMDRAW tbcd;
5460 INT ret = FALSE;
5461 DWORD ntfret;
5462 HTHEME theme = GetWindowTheme (hwnd);
5463 DWORD dwEraseCustDraw = 0;
5465 /* the app has told us not to redraw the toolbar */
5466 if (!infoPtr->bDoRedraw)
5467 return FALSE;
5469 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5470 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5471 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5472 tbcd.nmcd.hdc = (HDC)wParam;
5473 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5474 dwEraseCustDraw = ntfret & 0xffff;
5476 /* FIXME: in general the return flags *can* be or'ed together */
5477 switch (dwEraseCustDraw)
5479 case CDRF_DODEFAULT:
5480 break;
5481 case CDRF_SKIPDEFAULT:
5482 return TRUE;
5483 default:
5484 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5485 hwnd, ntfret);
5489 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5490 * to my parent for processing.
5492 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5493 POINT pt, ptorig;
5494 HDC hdc = (HDC)wParam;
5495 HWND parent;
5497 pt.x = 0;
5498 pt.y = 0;
5499 parent = GetParent(hwnd);
5500 MapWindowPoints(hwnd, parent, &pt, 1);
5501 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5502 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5503 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5505 if (!ret)
5506 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5508 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5509 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5510 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5511 tbcd.nmcd.hdc = (HDC)wParam;
5512 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5513 dwEraseCustDraw = ntfret & 0xffff;
5514 switch (dwEraseCustDraw)
5516 case CDRF_DODEFAULT:
5517 break;
5518 case CDRF_SKIPDEFAULT:
5519 return TRUE;
5520 default:
5521 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5522 hwnd, ntfret);
5525 return ret;
5529 static LRESULT
5530 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5532 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5534 return (LRESULT)infoPtr->hFont;
5538 static void
5539 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5541 INT i;
5542 INT nNewHotItem = infoPtr->nHotItem;
5544 for (i = 0; i < infoPtr->nNumButtons; i++)
5546 /* did we wrap? */
5547 if ((nNewHotItem + iDirection < 0) ||
5548 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5550 NMTBWRAPHOTITEM nmtbwhi;
5551 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5552 nmtbwhi.iDirection = iDirection;
5553 nmtbwhi.dwReason = dwReason;
5555 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5556 return;
5559 nNewHotItem += iDirection;
5560 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5562 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5563 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5565 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5566 break;
5571 static LRESULT
5572 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5574 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5575 NMKEY nmkey;
5577 nmkey.nVKey = (UINT)wParam;
5578 nmkey.uFlags = HIWORD(lParam);
5580 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5581 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5583 switch ((UINT)wParam)
5585 case VK_LEFT:
5586 case VK_UP:
5587 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5588 break;
5589 case VK_RIGHT:
5590 case VK_DOWN:
5591 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5592 break;
5593 case VK_SPACE:
5594 case VK_RETURN:
5595 if ((infoPtr->nHotItem >= 0) &&
5596 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5598 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5599 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5600 (LPARAM)hwnd);
5602 break;
5605 return 0;
5609 static LRESULT
5610 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5612 POINT pt;
5613 INT nHit;
5615 pt.x = (short)LOWORD(lParam);
5616 pt.y = (short)HIWORD(lParam);
5617 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5619 if (nHit >= 0)
5620 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5621 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5622 TOOLBAR_Customize (hwnd);
5624 return 0;
5628 static LRESULT
5629 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5631 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5632 TBUTTON_INFO *btnPtr;
5633 POINT pt;
5634 INT nHit;
5635 NMTOOLBARA nmtb;
5636 NMMOUSE nmmouse;
5637 BOOL bDragKeyPressed;
5639 TRACE("\n");
5641 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5642 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5643 else
5644 bDragKeyPressed = (wParam & MK_SHIFT);
5646 if (infoPtr->hwndToolTip)
5647 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5648 WM_LBUTTONDOWN, wParam, lParam);
5650 pt.x = (short)LOWORD(lParam);
5651 pt.y = (short)HIWORD(lParam);
5652 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5654 btnPtr = &infoPtr->buttons[nHit];
5656 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5658 infoPtr->nButtonDrag = nHit;
5659 SetCapture (hwnd);
5661 /* If drag cursor has not been loaded, load it.
5662 * Note: it doesn't need to be freed */
5663 if (!hCursorDrag)
5664 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5665 SetCursor(hCursorDrag);
5667 else if (nHit >= 0)
5669 RECT arrowRect;
5670 infoPtr->nOldHit = nHit;
5672 CopyRect(&arrowRect, &btnPtr->rect);
5673 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5675 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5676 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5677 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5678 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5679 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5680 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5682 LRESULT res;
5684 /* draw in pressed state */
5685 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5686 btnPtr->fsState |= TBSTATE_PRESSED;
5687 else
5688 btnPtr->bDropDownPressed = TRUE;
5689 RedrawWindow(hwnd,&btnPtr->rect,0,
5690 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5692 memset(&nmtb, 0, sizeof(nmtb));
5693 nmtb.iItem = btnPtr->idCommand;
5694 nmtb.rcButton = btnPtr->rect;
5695 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5696 TBN_DROPDOWN);
5697 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5699 if (res != TBDDRET_TREATPRESSED)
5701 MSG msg;
5703 /* redraw button in unpressed state */
5704 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5705 btnPtr->fsState &= ~TBSTATE_PRESSED;
5706 else
5707 btnPtr->bDropDownPressed = FALSE;
5708 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5710 /* find and set hot item
5711 * NOTE: native doesn't do this, but that is a bug */
5712 GetCursorPos(&pt);
5713 ScreenToClient(hwnd, &pt);
5714 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5715 if (!infoPtr->bAnchor || (nHit >= 0))
5716 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5718 /* remove any left mouse button down or double-click messages
5719 * so that we can get a toggle effect on the button */
5720 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5721 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5724 return 0;
5726 /* otherwise drop through and process as pushed */
5728 infoPtr->bCaptured = TRUE;
5729 infoPtr->nButtonDown = nHit;
5730 infoPtr->bDragOutSent = FALSE;
5732 btnPtr->fsState |= TBSTATE_PRESSED;
5734 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5736 if (btnPtr->fsState & TBSTATE_ENABLED)
5737 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5738 UpdateWindow(hwnd);
5739 SetCapture (hwnd);
5742 if (nHit >=0)
5744 memset(&nmtb, 0, sizeof(nmtb));
5745 nmtb.iItem = btnPtr->idCommand;
5746 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5749 nmmouse.dwHitInfo = nHit;
5751 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5752 if (nHit < 0)
5753 nmmouse.dwItemSpec = -1;
5754 else
5756 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5757 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5760 ClientToScreen(hwnd, &pt);
5761 nmmouse.pt = pt;
5763 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5764 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5766 return 0;
5769 static LRESULT
5770 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5772 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5773 TBUTTON_INFO *btnPtr;
5774 POINT pt;
5775 INT nHit;
5776 INT nOldIndex = -1;
5777 BOOL bSendMessage = TRUE;
5778 NMHDR hdr;
5779 NMMOUSE nmmouse;
5780 NMTOOLBARA nmtb;
5782 if (infoPtr->hwndToolTip)
5783 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5784 WM_LBUTTONUP, wParam, lParam);
5786 pt.x = (short)LOWORD(lParam);
5787 pt.y = (short)HIWORD(lParam);
5788 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5790 if (!infoPtr->bAnchor || (nHit >= 0))
5791 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5793 if (infoPtr->nButtonDrag >= 0) {
5794 RECT rcClient;
5795 NMHDR hdr;
5797 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5798 ReleaseCapture();
5799 /* reset cursor */
5800 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5802 GetClientRect(hwnd, &rcClient);
5803 if (PtInRect(&rcClient, pt))
5805 INT nButton = -1;
5806 if (nHit >= 0)
5807 nButton = nHit;
5808 else if (nHit < -1)
5809 nButton = -nHit;
5810 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5811 nButton = -nHit;
5813 if (nButton == infoPtr->nButtonDrag)
5815 /* if the button is moved sightly left and we have a
5816 * separator there then remove it */
5817 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5819 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5820 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5822 else /* else insert a separator before the dragged button */
5824 TBBUTTON tbb;
5825 memset(&tbb, 0, sizeof(tbb));
5826 tbb.fsStyle = BTNS_SEP;
5827 tbb.iString = -1;
5828 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5831 else
5833 if (nButton == -1)
5835 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5836 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5837 else
5838 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5840 else
5841 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5844 else
5846 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5847 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5850 /* button under cursor changed so need to re-set hot item */
5851 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5852 infoPtr->nButtonDrag = -1;
5854 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5856 else if (infoPtr->nButtonDown >= 0) {
5857 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5858 btnPtr->fsState &= ~TBSTATE_PRESSED;
5860 if (btnPtr->fsStyle & BTNS_CHECK) {
5861 if (btnPtr->fsStyle & BTNS_GROUP) {
5862 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5863 nHit);
5864 if (nOldIndex == nHit)
5865 bSendMessage = FALSE;
5866 if ((nOldIndex != nHit) &&
5867 (nOldIndex != -1))
5868 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5869 btnPtr->fsState |= TBSTATE_CHECKED;
5871 else {
5872 if (btnPtr->fsState & TBSTATE_CHECKED)
5873 btnPtr->fsState &= ~TBSTATE_CHECKED;
5874 else
5875 btnPtr->fsState |= TBSTATE_CHECKED;
5879 if (nOldIndex != -1)
5880 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5883 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5884 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5885 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5887 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5888 ReleaseCapture ();
5889 infoPtr->nButtonDown = -1;
5891 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5892 TOOLBAR_SendNotify (&hdr, infoPtr,
5893 NM_RELEASEDCAPTURE);
5895 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5896 * TBN_BEGINDRAG
5898 memset(&nmtb, 0, sizeof(nmtb));
5899 nmtb.iItem = btnPtr->idCommand;
5900 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5901 TBN_ENDDRAG);
5903 if (btnPtr->fsState & TBSTATE_ENABLED)
5905 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5906 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5908 /* In case we have just been destroyed... */
5909 if(!IsWindow(hwnd))
5910 return 0;
5914 /* !!! Undocumented - toolbar at 4.71 level and above sends
5915 * NM_CLICK with the NMMOUSE structure. */
5916 nmmouse.dwHitInfo = nHit;
5918 if (nHit < 0)
5919 nmmouse.dwItemSpec = -1;
5920 else
5922 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5923 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5926 ClientToScreen(hwnd, &pt);
5927 nmmouse.pt = pt;
5929 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5930 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5932 return 0;
5935 static LRESULT
5936 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5938 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5939 INT nHit;
5940 NMMOUSE nmmouse;
5941 POINT pt;
5943 pt.x = (short)LOWORD(lParam);
5944 pt.y = (short)HIWORD(lParam);
5946 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5947 nmmouse.dwHitInfo = nHit;
5949 if (nHit < 0) {
5950 nmmouse.dwItemSpec = -1;
5951 } else {
5952 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5953 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5956 ClientToScreen(hwnd, &pt);
5957 nmmouse.pt = pt;
5959 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5960 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5962 return 0;
5965 static LRESULT
5966 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5968 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5969 NMHDR nmhdr;
5971 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5972 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5974 return 0;
5977 static LRESULT
5978 TOOLBAR_CaptureChanged(HWND hwnd)
5980 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5981 TBUTTON_INFO *btnPtr;
5983 infoPtr->bCaptured = FALSE;
5985 if (infoPtr->nButtonDown >= 0)
5987 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5988 btnPtr->fsState &= ~TBSTATE_PRESSED;
5990 infoPtr->nOldHit = -1;
5992 if (btnPtr->fsState & TBSTATE_ENABLED)
5993 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5995 return 0;
5998 static LRESULT
5999 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6001 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6003 /* don't remove hot effects when in anchor highlighting mode or when a
6004 * drop-down button is pressed */
6005 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
6007 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
6008 if (!hotBtnPtr->bDropDownPressed)
6009 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6012 if (infoPtr->nOldHit < 0)
6013 return TRUE;
6015 /* If the last button we were over is depressed then make it not */
6016 /* depressed and redraw it */
6017 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6019 TBUTTON_INFO *btnPtr;
6020 RECT rc1;
6022 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6024 btnPtr->fsState &= ~TBSTATE_PRESSED;
6026 rc1 = btnPtr->rect;
6027 InflateRect (&rc1, 1, 1);
6028 InvalidateRect (hwnd, &rc1, TRUE);
6031 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6033 NMTOOLBARW nmt;
6034 ZeroMemory(&nmt, sizeof(nmt));
6035 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6036 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6037 infoPtr->bDragOutSent = TRUE;
6040 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6042 return TRUE;
6045 static LRESULT
6046 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6048 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6049 POINT pt;
6050 TRACKMOUSEEVENT trackinfo;
6051 INT nHit;
6052 TBUTTON_INFO *btnPtr;
6054 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6055 TOOLBAR_TooltipCreateControl(infoPtr);
6057 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6058 /* fill in the TRACKMOUSEEVENT struct */
6059 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6060 trackinfo.dwFlags = TME_QUERY;
6062 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6063 _TrackMouseEvent(&trackinfo);
6065 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6066 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6067 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6068 trackinfo.hwndTrack = hwnd;
6070 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6071 /* and can properly deactivate the hot toolbar button */
6072 _TrackMouseEvent(&trackinfo);
6076 if (infoPtr->hwndToolTip)
6077 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6078 WM_MOUSEMOVE, wParam, lParam);
6080 pt.x = (short)LOWORD(lParam);
6081 pt.y = (short)HIWORD(lParam);
6083 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6085 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6086 && (!infoPtr->bAnchor || (nHit >= 0)))
6087 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6089 if (infoPtr->nOldHit != nHit)
6091 if (infoPtr->bCaptured)
6093 if (!infoPtr->bDragOutSent)
6095 NMTOOLBARW nmt;
6096 ZeroMemory(&nmt, sizeof(nmt));
6097 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6098 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6099 infoPtr->bDragOutSent = TRUE;
6102 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6103 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6104 btnPtr->fsState &= ~TBSTATE_PRESSED;
6105 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6107 else if (nHit == infoPtr->nButtonDown) {
6108 btnPtr->fsState |= TBSTATE_PRESSED;
6109 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6111 infoPtr->nOldHit = nHit;
6115 return 0;
6119 static inline LRESULT
6120 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6122 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6123 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6124 /* else */
6125 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6129 static inline LRESULT
6130 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6132 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6133 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6135 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6139 static LRESULT
6140 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6142 TOOLBAR_INFO *infoPtr;
6143 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6144 DWORD styleadd = 0;
6146 /* allocate memory for info structure */
6147 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6148 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6150 /* paranoid!! */
6151 infoPtr->dwStructSize = sizeof(TBBUTTON);
6152 infoPtr->nRows = 1;
6153 infoPtr->nWidth = 0;
6155 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6156 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6157 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6158 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6161 /* native control does:
6162 * Get a lot of colors and brushes
6163 * WM_NOTIFYFORMAT
6164 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6165 * CreateFontIndirectW(adr1)
6166 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6167 * hdc = GetDC(toolbar)
6168 * GetSystemMetrics(0x48)
6169 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6170 * 0, 0, 0, 0, "MARLETT")
6171 * oldfnt = SelectObject(hdc, fnt2)
6172 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6173 * GetTextMetricsW(hdc, adr3)
6174 * SelectObject(hdc, oldfnt)
6175 * DeleteObject(fnt2)
6176 * ReleaseDC(hdc)
6177 * InvalidateRect(toolbar, 0, 1)
6178 * SetWindowLongW(toolbar, 0, addr)
6179 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6180 * WM_STYLECHANGING
6181 * CallWinEx old new
6182 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6183 * ie 2 0x4600094c 0x4600094c 0x4600894d
6184 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6185 * rebar 0x50008844 0x40008844 0x50008845
6186 * pager 0x50000844 0x40000844 0x50008845
6187 * IC35mgr 0x5400084e **nochange**
6188 * on entry to _NCCREATE 0x5400084e
6189 * rowlist 0x5400004e **nochange**
6190 * on entry to _NCCREATE 0x5400004e
6194 /* I think the code below is a bug, but it is the way that the native
6195 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6196 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6197 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6198 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6199 * Somehow, the only cases of this seem to be MFC programs.
6201 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6202 * does not occur in the WM_STYLECHANGING routine.
6203 * (Guy Albertelli 9/2001)
6206 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6207 && !(cs->style & TBSTYLE_TRANSPARENT))
6208 styleadd |= TBSTYLE_TRANSPARENT;
6209 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6210 styleadd |= CCS_TOP; /* default to top */
6211 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6214 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6218 static LRESULT
6219 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6221 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6222 RECT rcWindow;
6223 HDC hdc;
6225 if (dwStyle & WS_MINIMIZE)
6226 return 0; /* Nothing to do */
6228 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6230 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6231 return 0;
6233 if (!(dwStyle & CCS_NODIVIDER))
6235 GetWindowRect (hwnd, &rcWindow);
6236 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6237 if( dwStyle & WS_BORDER )
6238 OffsetRect (&rcWindow, 1, 1);
6239 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6242 ReleaseDC( hwnd, hdc );
6244 return 0;
6248 /* handles requests from the tooltip control on what text to display */
6249 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6251 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6253 TRACE("button index = %d\n", index);
6255 Free (infoPtr->pszTooltipText);
6256 infoPtr->pszTooltipText = NULL;
6258 if (index < 0)
6259 return 0;
6261 if (infoPtr->bUnicode)
6263 WCHAR wszBuffer[INFOTIPSIZE+1];
6264 NMTBGETINFOTIPW tbgit;
6265 unsigned int len; /* in chars */
6267 wszBuffer[0] = '\0';
6268 wszBuffer[INFOTIPSIZE] = '\0';
6270 tbgit.pszText = wszBuffer;
6271 tbgit.cchTextMax = INFOTIPSIZE;
6272 tbgit.iItem = lpnmtdi->hdr.idFrom;
6273 tbgit.lParam = infoPtr->buttons[index].dwData;
6275 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6277 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6279 len = strlenW(tbgit.pszText);
6280 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6282 /* need to allocate temporary buffer in infoPtr as there
6283 * isn't enough space in buffer passed to us by the
6284 * tooltip control */
6285 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6286 if (infoPtr->pszTooltipText)
6288 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6289 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6290 return 0;
6293 else if (len > 0)
6295 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6296 return 0;
6299 else
6301 CHAR szBuffer[INFOTIPSIZE+1];
6302 NMTBGETINFOTIPA tbgit;
6303 unsigned int len; /* in chars */
6305 szBuffer[0] = '\0';
6306 szBuffer[INFOTIPSIZE] = '\0';
6308 tbgit.pszText = szBuffer;
6309 tbgit.cchTextMax = INFOTIPSIZE;
6310 tbgit.iItem = lpnmtdi->hdr.idFrom;
6311 tbgit.lParam = infoPtr->buttons[index].dwData;
6313 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6315 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6317 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6318 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6320 /* need to allocate temporary buffer in infoPtr as there
6321 * isn't enough space in buffer passed to us by the
6322 * tooltip control */
6323 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6324 if (infoPtr->pszTooltipText)
6326 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6327 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6328 return 0;
6331 else if (tbgit.pszText[0])
6333 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6334 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6335 return 0;
6339 /* if button has text, but it is not shown then automatically
6340 * use that text as tooltip */
6341 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6342 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6344 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6345 unsigned int len = pszText ? strlenW(pszText) : 0;
6347 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6349 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6351 /* need to allocate temporary buffer in infoPtr as there
6352 * isn't enough space in buffer passed to us by the
6353 * tooltip control */
6354 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6355 if (infoPtr->pszTooltipText)
6357 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6358 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6359 return 0;
6362 else if (len > 0)
6364 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6365 return 0;
6369 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6371 /* last resort: send notification on to app */
6372 /* FIXME: find out what is really used here */
6373 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, lpnmtdi->hdr.idFrom, (LPARAM)lpnmtdi);
6377 static inline LRESULT
6378 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6380 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6381 LPNMHDR lpnmh = (LPNMHDR)lParam;
6383 switch (lpnmh->code)
6385 case PGN_CALCSIZE:
6387 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6389 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6390 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6391 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6392 lppgc->iWidth);
6394 else {
6395 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6396 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6397 lppgc->iHeight);
6399 return 0;
6402 case PGN_SCROLL:
6404 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6406 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6407 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6408 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6409 lppgs->iScroll, lppgs->iDir);
6410 return 0;
6413 case TTN_GETDISPINFOW:
6414 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6416 case TTN_GETDISPINFOA:
6417 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6418 return 0;
6420 default:
6421 return 0;
6426 static LRESULT
6427 TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6429 LRESULT format;
6431 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam, lParam);
6433 if (lParam == NF_QUERY)
6434 return NFR_UNICODE;
6436 if (lParam == NF_REQUERY) {
6437 format = SendMessageW(infoPtr->hwndNotify,
6438 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6439 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6440 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6441 format);
6442 format = NFR_ANSI;
6444 return format;
6446 return 0;
6450 static LRESULT
6451 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6453 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6454 HDC hdc;
6455 PAINTSTRUCT ps;
6457 /* fill ps.rcPaint with a default rect */
6458 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6460 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6462 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps.rcPaint));
6464 TOOLBAR_Refresh (hwnd, hdc, &ps);
6465 if (!wParam) EndPaint (hwnd, &ps);
6467 return 0;
6471 static LRESULT
6472 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6474 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6476 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6478 /* make first item hot */
6479 if (infoPtr->nNumButtons > 0)
6480 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6482 return 0;
6485 static LRESULT
6486 TOOLBAR_SetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
6488 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6490 TRACE("font=%p redraw=%ld\n", (HFONT)wParam, lParam);
6492 if (wParam == 0)
6493 infoPtr->hFont = infoPtr->hDefaultFont;
6494 else
6495 infoPtr->hFont = (HFONT)wParam;
6497 TOOLBAR_CalcToolbar(hwnd);
6499 if (lParam)
6500 InvalidateRect(hwnd, NULL, TRUE);
6501 return 1;
6504 static LRESULT
6505 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6506 /*****************************************************
6508 * Function;
6509 * Handles the WM_SETREDRAW message.
6511 * Documentation:
6512 * According to testing V4.71 of COMCTL32 returns the
6513 * *previous* status of the redraw flag (either 0 or 1)
6514 * instead of the MSDN documented value of 0 if handled.
6515 * (For laughs see the "consistency" with same function
6516 * in rebar.)
6518 *****************************************************/
6520 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6521 BOOL oldredraw = infoPtr->bDoRedraw;
6523 TRACE("set to %s\n",
6524 (wParam) ? "TRUE" : "FALSE");
6525 infoPtr->bDoRedraw = (BOOL) wParam;
6526 if (wParam) {
6527 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6529 return (oldredraw) ? 1 : 0;
6533 static LRESULT
6534 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6536 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6538 TRACE("sizing toolbar!\n");
6540 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6542 RECT delta_width, delta_height, client, dummy;
6543 DWORD min_x, max_x, min_y, max_y;
6544 TBUTTON_INFO *btnPtr;
6545 INT i;
6547 GetClientRect(hwnd, &client);
6548 if(client.right > infoPtr->client_rect.right)
6550 min_x = infoPtr->client_rect.right;
6551 max_x = client.right;
6553 else
6555 max_x = infoPtr->client_rect.right;
6556 min_x = client.right;
6558 if(client.bottom > infoPtr->client_rect.bottom)
6560 min_y = infoPtr->client_rect.bottom;
6561 max_y = client.bottom;
6563 else
6565 max_y = infoPtr->client_rect.bottom;
6566 min_y = client.bottom;
6569 SetRect(&delta_width, min_x, 0, max_x, min_y);
6570 SetRect(&delta_height, 0, min_y, max_x, max_y);
6572 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6573 btnPtr = infoPtr->buttons;
6574 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6575 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6576 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6577 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6579 GetClientRect(hwnd, &infoPtr->client_rect);
6580 TOOLBAR_AutoSize(hwnd);
6581 return 0;
6585 static LRESULT
6586 TOOLBAR_StyleChanged (HWND hwnd, INT nType, const STYLESTRUCT *lpStyle)
6588 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6590 if (nType == GWL_STYLE)
6592 DWORD dwOldStyle = infoPtr->dwStyle;
6594 if (lpStyle->styleNew & TBSTYLE_LIST)
6595 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6596 else
6597 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6599 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6601 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6603 infoPtr->dwStyle = lpStyle->styleNew;
6605 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6606 TOOLBAR_LayoutToolbar(hwnd);
6608 /* only resize if one of the CCS_* styles was changed */
6609 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6611 TOOLBAR_AutoSize (hwnd);
6613 InvalidateRect(hwnd, NULL, TRUE);
6617 return 0;
6621 static LRESULT
6622 TOOLBAR_SysColorChange (HWND hwnd)
6624 COMCTL32_RefreshSysColors();
6626 return 0;
6630 /* update theme after a WM_THEMECHANGED message */
6631 static LRESULT theme_changed (HWND hwnd)
6633 HTHEME theme = GetWindowTheme (hwnd);
6634 CloseThemeData (theme);
6635 OpenThemeData (hwnd, themeClass);
6636 return 0;
6640 static LRESULT WINAPI
6641 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6643 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6645 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6646 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6648 if (!infoPtr && (uMsg != WM_NCCREATE))
6649 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6651 switch (uMsg)
6653 case TB_ADDBITMAP:
6654 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6656 case TB_ADDBUTTONSA:
6657 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6659 case TB_ADDBUTTONSW:
6660 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6662 case TB_ADDSTRINGA:
6663 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6665 case TB_ADDSTRINGW:
6666 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6668 case TB_AUTOSIZE:
6669 return TOOLBAR_AutoSize (hwnd);
6671 case TB_BUTTONCOUNT:
6672 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6674 case TB_BUTTONSTRUCTSIZE:
6675 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6677 case TB_CHANGEBITMAP:
6678 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6680 case TB_CHECKBUTTON:
6681 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6683 case TB_COMMANDTOINDEX:
6684 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6686 case TB_CUSTOMIZE:
6687 return TOOLBAR_Customize (hwnd);
6689 case TB_DELETEBUTTON:
6690 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6692 case TB_ENABLEBUTTON:
6693 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6695 case TB_GETANCHORHIGHLIGHT:
6696 return TOOLBAR_GetAnchorHighlight (hwnd);
6698 case TB_GETBITMAP:
6699 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6701 case TB_GETBITMAPFLAGS:
6702 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6704 case TB_GETBUTTON:
6705 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6707 case TB_GETBUTTONINFOA:
6708 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, FALSE);
6710 case TB_GETBUTTONINFOW:
6711 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, TRUE);
6713 case TB_GETBUTTONSIZE:
6714 return TOOLBAR_GetButtonSize (hwnd);
6716 case TB_GETBUTTONTEXTA:
6717 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6719 case TB_GETBUTTONTEXTW:
6720 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6722 case TB_GETDISABLEDIMAGELIST:
6723 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6725 case TB_GETEXTENDEDSTYLE:
6726 return TOOLBAR_GetExtendedStyle (hwnd);
6728 case TB_GETHOTIMAGELIST:
6729 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6731 case TB_GETHOTITEM:
6732 return TOOLBAR_GetHotItem (hwnd);
6734 case TB_GETIMAGELIST:
6735 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6737 case TB_GETINSERTMARK:
6738 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6740 case TB_GETINSERTMARKCOLOR:
6741 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6743 case TB_GETITEMRECT:
6744 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6746 case TB_GETMAXSIZE:
6747 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6749 /* case TB_GETOBJECT: */ /* 4.71 */
6751 case TB_GETPADDING:
6752 return TOOLBAR_GetPadding (hwnd);
6754 case TB_GETRECT:
6755 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6757 case TB_GETROWS:
6758 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6760 case TB_GETSTATE:
6761 return TOOLBAR_GetState (hwnd, wParam, lParam);
6763 case TB_GETSTRINGA:
6764 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6766 case TB_GETSTRINGW:
6767 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6769 case TB_GETSTYLE:
6770 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6772 case TB_GETTEXTROWS:
6773 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6775 case TB_GETTOOLTIPS:
6776 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6778 case TB_GETUNICODEFORMAT:
6779 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6781 case TB_HIDEBUTTON:
6782 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6784 case TB_HITTEST:
6785 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6787 case TB_INDETERMINATE:
6788 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6790 case TB_INSERTBUTTONA:
6791 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6793 case TB_INSERTBUTTONW:
6794 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6796 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6798 case TB_ISBUTTONCHECKED:
6799 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6801 case TB_ISBUTTONENABLED:
6802 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6804 case TB_ISBUTTONHIDDEN:
6805 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6807 case TB_ISBUTTONHIGHLIGHTED:
6808 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6810 case TB_ISBUTTONINDETERMINATE:
6811 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6813 case TB_ISBUTTONPRESSED:
6814 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6816 case TB_LOADIMAGES:
6817 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6819 case TB_MAPACCELERATORA:
6820 case TB_MAPACCELERATORW:
6821 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6823 case TB_MARKBUTTON:
6824 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6826 case TB_MOVEBUTTON:
6827 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6829 case TB_PRESSBUTTON:
6830 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6832 case TB_REPLACEBITMAP:
6833 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6835 case TB_SAVERESTOREA:
6836 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6838 case TB_SAVERESTOREW:
6839 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6841 case TB_SETANCHORHIGHLIGHT:
6842 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6844 case TB_SETBITMAPSIZE:
6845 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6847 case TB_SETBUTTONINFOA:
6848 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6850 case TB_SETBUTTONINFOW:
6851 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6853 case TB_SETBUTTONSIZE:
6854 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6856 case TB_SETBUTTONWIDTH:
6857 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6859 case TB_SETCMDID:
6860 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6862 case TB_SETDISABLEDIMAGELIST:
6863 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6865 case TB_SETDRAWTEXTFLAGS:
6866 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6868 case TB_SETEXTENDEDSTYLE:
6869 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6871 case TB_SETHOTIMAGELIST:
6872 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6874 case TB_SETHOTITEM:
6875 return TOOLBAR_SetHotItem (hwnd, wParam);
6877 case TB_SETIMAGELIST:
6878 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6880 case TB_SETINDENT:
6881 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6883 case TB_SETINSERTMARK:
6884 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6886 case TB_SETINSERTMARKCOLOR:
6887 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6889 case TB_SETMAXTEXTROWS:
6890 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6892 case TB_SETPADDING:
6893 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6895 case TB_SETPARENT:
6896 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6898 case TB_SETROWS:
6899 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6901 case TB_SETSTATE:
6902 return TOOLBAR_SetState (hwnd, wParam, lParam);
6904 case TB_SETSTYLE:
6905 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6907 case TB_SETTOOLTIPS:
6908 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6910 case TB_SETUNICODEFORMAT:
6911 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6913 case TB_UNKWN45D:
6914 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6916 case TB_UNKWN45E:
6917 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6919 case TB_UNKWN460:
6920 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6922 case TB_UNKWN462:
6923 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6925 case TB_UNKWN463:
6926 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6928 case TB_UNKWN464:
6929 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6931 /* Common Control Messages */
6933 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6934 case CCM_GETCOLORSCHEME:
6935 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6937 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6938 case CCM_SETCOLORSCHEME:
6939 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6941 case CCM_GETVERSION:
6942 return TOOLBAR_GetVersion (hwnd);
6944 case CCM_SETVERSION:
6945 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6948 /* case WM_CHAR: */
6950 case WM_CREATE:
6951 return TOOLBAR_Create (hwnd, wParam, lParam);
6953 case WM_DESTROY:
6954 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6956 case WM_ERASEBKGND:
6957 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6959 case WM_GETFONT:
6960 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6962 case WM_KEYDOWN:
6963 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6965 /* case WM_KILLFOCUS: */
6967 case WM_LBUTTONDBLCLK:
6968 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6970 case WM_LBUTTONDOWN:
6971 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6973 case WM_LBUTTONUP:
6974 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6976 case WM_RBUTTONUP:
6977 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6979 case WM_RBUTTONDBLCLK:
6980 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6982 case WM_MOUSEMOVE:
6983 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6985 case WM_MOUSELEAVE:
6986 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6988 case WM_CAPTURECHANGED:
6989 return TOOLBAR_CaptureChanged(hwnd);
6991 case WM_NCACTIVATE:
6992 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6994 case WM_NCCALCSIZE:
6995 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6997 case WM_NCCREATE:
6998 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7000 case WM_NCPAINT:
7001 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7003 case WM_NOTIFY:
7004 return TOOLBAR_Notify (hwnd, wParam, lParam);
7006 case WM_NOTIFYFORMAT:
7007 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7009 case WM_PRINTCLIENT:
7010 case WM_PAINT:
7011 return TOOLBAR_Paint (hwnd, wParam);
7013 case WM_SETFOCUS:
7014 return TOOLBAR_SetFocus (hwnd, wParam);
7016 case WM_SETFONT:
7017 return TOOLBAR_SetFont(hwnd, wParam, lParam);
7019 case WM_SETREDRAW:
7020 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7022 case WM_SIZE:
7023 return TOOLBAR_Size (hwnd, wParam, lParam);
7025 case WM_STYLECHANGED:
7026 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7028 case WM_SYSCOLORCHANGE:
7029 return TOOLBAR_SysColorChange (hwnd);
7031 case WM_THEMECHANGED:
7032 return theme_changed (hwnd);
7034 /* case WM_WININICHANGE: */
7036 case WM_CHARTOITEM:
7037 case WM_COMMAND:
7038 case WM_DRAWITEM:
7039 case WM_MEASUREITEM:
7040 case WM_VKEYTOITEM:
7041 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7043 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7044 case PGM_FORWARDMOUSE:
7045 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7047 default:
7048 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7049 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
7050 uMsg, wParam, lParam);
7051 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7056 VOID
7057 TOOLBAR_Register (void)
7059 WNDCLASSW wndClass;
7061 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7062 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7063 wndClass.lpfnWndProc = ToolbarWindowProc;
7064 wndClass.cbClsExtra = 0;
7065 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7066 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7067 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7068 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7070 RegisterClassW (&wndClass);
7074 VOID
7075 TOOLBAR_Unregister (void)
7077 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7080 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7082 HIMAGELIST himlold;
7083 PIMLENTRY c = NULL;
7085 /* Check if the entry already exists */
7086 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7088 /* If this is a new entry we must create it and insert into the array */
7089 if (!c)
7091 PIMLENTRY *pnies;
7093 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7094 c->id = id;
7096 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7097 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7098 pnies[*cies] = c;
7099 (*cies)++;
7101 Free(*pies);
7102 *pies = pnies;
7105 himlold = c->himl;
7106 c->himl = himl;
7108 return himlold;
7112 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7114 int i;
7116 for (i = 0; i < *cies; i++)
7117 Free((*pies)[i]);
7119 Free(*pies);
7121 *cies = 0;
7122 *pies = NULL;
7126 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id)
7128 PIMLENTRY c = NULL;
7130 if (pies != NULL)
7132 int i;
7134 for (i = 0; i < cies; i++)
7136 if (pies[i]->id == id)
7138 c = pies[i];
7139 break;
7144 return c;
7148 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id)
7150 HIMAGELIST himlDef = 0;
7151 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7153 if (pie)
7154 himlDef = pie->himl;
7156 return himlDef;
7160 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7162 if (infoPtr->bUnicode)
7163 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7164 else
7166 CHAR Buffer[256];
7167 NMTOOLBARA nmtba;
7168 BOOL bRet = FALSE;
7170 nmtba.iItem = nmtb->iItem;
7171 nmtba.pszText = Buffer;
7172 nmtba.cchText = 256;
7173 ZeroMemory(nmtba.pszText, nmtba.cchText);
7175 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7177 int ccht = strlen(nmtba.pszText);
7178 if (ccht)
7179 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7180 nmtb->pszText, nmtb->cchText);
7182 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7183 bRet = TRUE;
7186 return bRet;
7191 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo)
7193 NMTOOLBARW nmtb;
7195 /* MSDN states that iItem is the index of the button, rather than the
7196 * command ID as used by every other NMTOOLBAR notification */
7197 nmtb.iItem = iItem;
7198 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7200 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);