cryptui: Implement specifying the destination store in CryptUIWizImport.
[wine/wine64.git] / dlls / comctl32 / toolbar.c
blob797260573c330fc6671c473690553872ac8816ed
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 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
917 else
919 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
920 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
921 else
922 rcText.top += infoPtr->szPadding.cy/2 + 2;
926 /* Initialize fields in all cases, because we use these later
927 * NOTE: applications can and do alter these to customize their
928 * toolbars */
929 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
930 tbcd.clrText = comctl32_color.clrBtnText;
931 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
932 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
933 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
934 tbcd.clrMark = comctl32_color.clrHighlight;
935 tbcd.clrHighlightHotTrack = 0;
936 tbcd.nStringBkMode = TRANSPARENT;
937 tbcd.nHLStringBkMode = OPAQUE;
938 /* MSDN says that this is the text rectangle.
939 * But (why always a but) tracing of v5.7 of native shows
940 * that this is really a *relative* rectangle based on the
941 * the nmcd.rc. Also the left and top are always 0 ignoring
942 * any bitmap that might be present. */
943 tbcd.rcText.left = 0;
944 tbcd.rcText.top = 0;
945 tbcd.rcText.right = rcText.right - rc.left;
946 tbcd.rcText.bottom = rcText.bottom - rc.top;
947 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
948 tbcd.nmcd.hdc = hdc;
949 tbcd.nmcd.rc = rc;
950 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
952 /* FIXME: what are these used for? */
953 tbcd.hbrLines = 0;
954 tbcd.hpenLines = 0;
956 /* Issue Item Prepaint notify */
957 dwItemCustDraw = 0;
958 dwItemCDFlag = 0;
959 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
961 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
962 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
963 tbcd.nmcd.lItemlParam = btnPtr->dwData;
964 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
965 /* reset these fields so the user can't alter the behaviour like native */
966 tbcd.nmcd.hdc = hdc;
967 tbcd.nmcd.rc = rc;
969 dwItemCustDraw = ntfret & 0xffff;
970 dwItemCDFlag = ntfret & 0xffff0000;
971 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
972 return;
973 /* save the only part of the rect that the user can change */
974 rcText.right = tbcd.rcText.right + rc.left;
975 rcText.bottom = tbcd.rcText.bottom + rc.top;
978 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
979 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
980 OffsetRect(&rcText, 1, 1);
982 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
983 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
984 TOOLBAR_DrawPattern (&rc, &tbcd);
986 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
987 && (tbcd.nmcd.uItemState & CDIS_HOT))
989 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
991 COLORREF oldclr;
993 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
994 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
995 if (hasDropDownArrow)
996 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
997 SetBkColor(hdc, oldclr);
1001 if (theme)
1003 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1004 int stateId = TS_NORMAL;
1006 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1007 stateId = TS_DISABLED;
1008 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1009 stateId = TS_PRESSED;
1010 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1011 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1012 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1013 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1014 stateId = TS_HOT;
1016 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1018 else
1019 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1021 if (drawSepDropDownArrow)
1023 if (theme)
1025 int stateId = TS_NORMAL;
1027 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1028 stateId = TS_DISABLED;
1029 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1030 stateId = TS_PRESSED;
1031 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1032 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1033 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1034 stateId = TS_HOT;
1036 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1037 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1039 else
1040 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1043 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1044 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1045 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1046 SetBkMode (hdc, oldBkMode);
1048 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1050 if (hasDropDownArrow && !drawSepDropDownArrow)
1052 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1054 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1055 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1057 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1059 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1060 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1062 else
1063 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1066 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1068 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1069 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1075 static void
1076 TOOLBAR_Refresh (HWND hwnd, HDC hdc, const PAINTSTRUCT *ps)
1078 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1079 TBUTTON_INFO *btnPtr;
1080 INT i;
1081 RECT rcTemp, rcClient;
1082 NMTBCUSTOMDRAW tbcd;
1083 DWORD ntfret;
1084 DWORD dwBaseCustDraw;
1086 /* the app has told us not to redraw the toolbar */
1087 if (!infoPtr->bDoRedraw)
1088 return;
1090 /* if imagelist belongs to the app, it can be changed
1091 by the app after setting it */
1092 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1094 infoPtr->nNumBitmaps = 0;
1095 for (i = 0; i < infoPtr->cimlDef; i++)
1096 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1099 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1101 /* change the imagelist icon size if we manage the list and it is necessary */
1102 TOOLBAR_CheckImageListIconSize(infoPtr);
1104 /* Send initial notify */
1105 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1106 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1107 tbcd.nmcd.hdc = hdc;
1108 tbcd.nmcd.rc = ps->rcPaint;
1109 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1110 dwBaseCustDraw = ntfret & 0xffff;
1112 GetClientRect(hwnd, &rcClient);
1114 /* redraw necessary buttons */
1115 btnPtr = infoPtr->buttons;
1116 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1118 BOOL bDraw;
1119 if (!RectVisible(hdc, &btnPtr->rect))
1120 continue;
1121 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1123 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1124 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1126 else
1127 bDraw = TRUE;
1128 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1129 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1130 if (bDraw)
1131 TOOLBAR_DrawButton(hwnd, btnPtr, hdc, dwBaseCustDraw);
1134 /* draw insert mark if required */
1135 if (infoPtr->tbim.iButton != -1)
1137 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1138 RECT rcInsertMark;
1139 rcInsertMark.top = rcButton.top;
1140 rcInsertMark.bottom = rcButton.bottom;
1141 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1142 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1143 else
1144 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1145 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1148 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1150 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1151 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1152 tbcd.nmcd.hdc = hdc;
1153 tbcd.nmcd.rc = ps->rcPaint;
1154 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1158 /***********************************************************************
1159 * TOOLBAR_MeasureString
1161 * This function gets the width and height of a string in pixels. This
1162 * is done first by using GetTextExtentPoint to get the basic width
1163 * and height. The DrawText is called with DT_CALCRECT to get the exact
1164 * width. The reason is because the text may have more than one "&" (or
1165 * prefix characters as M$ likes to call them). The prefix character
1166 * indicates where the underline goes, except for the string "&&" which
1167 * is reduced to a single "&". GetTextExtentPoint does not process these
1168 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1170 static void
1171 TOOLBAR_MeasureString(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr,
1172 HDC hdc, LPSIZE lpSize)
1174 RECT myrect;
1176 lpSize->cx = 0;
1177 lpSize->cy = 0;
1179 if (infoPtr->nMaxTextRows > 0 &&
1180 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1181 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1182 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1184 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1186 if(lpText != NULL) {
1187 /* first get size of all the text */
1188 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1190 /* feed above size into the rectangle for DrawText */
1191 myrect.left = myrect.top = 0;
1192 myrect.right = lpSize->cx;
1193 myrect.bottom = lpSize->cy;
1195 /* Use DrawText to get true size as drawn (less pesky "&") */
1196 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1197 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1198 DT_NOPREFIX : 0));
1200 /* feed back to caller */
1201 lpSize->cx = myrect.right;
1202 lpSize->cy = myrect.bottom;
1206 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1209 /***********************************************************************
1210 * TOOLBAR_CalcStrings
1212 * This function walks through each string and measures it and returns
1213 * the largest height and width to caller.
1215 static void
1216 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1218 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1219 TBUTTON_INFO *btnPtr;
1220 INT i;
1221 SIZE sz;
1222 HDC hdc;
1223 HFONT hOldFont;
1225 lpSize->cx = 0;
1226 lpSize->cy = 0;
1228 if (infoPtr->nMaxTextRows == 0)
1229 return;
1231 hdc = GetDC (hwnd);
1232 hOldFont = SelectObject (hdc, infoPtr->hFont);
1234 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1236 TEXTMETRICW tm;
1238 GetTextMetricsW(hdc, &tm);
1239 lpSize->cy = tm.tmHeight;
1242 btnPtr = infoPtr->buttons;
1243 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1244 if(TOOLBAR_HasText(infoPtr, btnPtr))
1246 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1247 if (sz.cx > lpSize->cx)
1248 lpSize->cx = sz.cx;
1249 if (sz.cy > lpSize->cy)
1250 lpSize->cy = sz.cy;
1254 SelectObject (hdc, hOldFont);
1255 ReleaseDC (hwnd, hdc);
1257 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1260 /***********************************************************************
1261 * TOOLBAR_WrapToolbar
1263 * This function walks through the buttons and separators in the
1264 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1265 * wrapping should occur based on the width of the toolbar window.
1266 * It does *not* calculate button placement itself. That task
1267 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1268 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1269 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1271 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1272 * vertical toolbar lists.
1275 static void
1276 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1278 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1279 TBUTTON_INFO *btnPtr;
1280 INT x, cx, i, j;
1281 RECT rc;
1282 BOOL bButtonWrap;
1284 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1285 /* no layout is necessary. Applications may use this style */
1286 /* to perform their own layout on the toolbar. */
1287 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1288 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1290 btnPtr = infoPtr->buttons;
1291 x = infoPtr->nIndent;
1293 if (GetParent(hwnd))
1295 /* this can get the parents width, to know how far we can extend
1296 * this toolbar. We cannot use its height, as there may be multiple
1297 * toolbars in a rebar control
1299 GetClientRect( GetParent(hwnd), &rc );
1300 infoPtr->nWidth = rc.right - rc.left;
1302 else
1304 GetWindowRect( hwnd, &rc );
1305 infoPtr->nWidth = rc.right - rc.left;
1308 bButtonWrap = FALSE;
1310 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1311 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1312 infoPtr->nIndent);
1314 for (i = 0; i < infoPtr->nNumButtons; i++ )
1316 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1318 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1319 continue;
1321 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1322 /* it is the actual width of the separator. This is used for */
1323 /* custom controls in toolbars. */
1324 /* */
1325 /* BTNS_DROPDOWN separators are treated as buttons for */
1326 /* width. - GA 8/01 */
1327 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1328 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1329 cx = (btnPtr[i].iBitmap > 0) ?
1330 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1331 else
1332 cx = (btnPtr[i].cx) ? btnPtr[i].cx : infoPtr->nButtonWidth;
1334 /* Two or more adjacent separators form a separator group. */
1335 /* The first separator in a group should be wrapped to the */
1336 /* next row if the previous wrapping is on a button. */
1337 if( bButtonWrap &&
1338 (btnPtr[i].fsStyle & BTNS_SEP) &&
1339 (i + 1 < infoPtr->nNumButtons ) &&
1340 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1342 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1343 btnPtr[i].fsState |= TBSTATE_WRAP;
1344 x = infoPtr->nIndent;
1345 i++;
1346 bButtonWrap = FALSE;
1347 continue;
1350 /* The layout makes sure the bitmap is visible, but not the button. */
1351 /* Test added to also wrap after a button that starts a row but */
1352 /* is bigger than the area. - GA 8/01 */
1353 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1354 > infoPtr->nWidth ) ||
1355 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1357 BOOL bFound = FALSE;
1359 /* If the current button is a separator and not hidden, */
1360 /* go to the next until it reaches a non separator. */
1361 /* Wrap the last separator if it is before a button. */
1362 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1363 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1364 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1365 i < infoPtr->nNumButtons )
1367 i++;
1368 bFound = TRUE;
1371 if( bFound && i < infoPtr->nNumButtons )
1373 i--;
1374 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1375 i, btnPtr[i].fsStyle, x, cx);
1376 btnPtr[i].fsState |= TBSTATE_WRAP;
1377 x = infoPtr->nIndent;
1378 bButtonWrap = FALSE;
1379 continue;
1381 else if ( i >= infoPtr->nNumButtons)
1382 break;
1384 /* If the current button is not a separator, find the last */
1385 /* separator and wrap it. */
1386 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1388 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1389 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1391 bFound = TRUE;
1392 i = j;
1393 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1394 i, btnPtr[i].fsStyle, x, cx);
1395 x = infoPtr->nIndent;
1396 btnPtr[j].fsState |= TBSTATE_WRAP;
1397 bButtonWrap = FALSE;
1398 break;
1402 /* If no separator available for wrapping, wrap one of */
1403 /* non-hidden previous button. */
1404 if (!bFound)
1406 for ( j = i - 1;
1407 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1409 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1410 continue;
1412 bFound = TRUE;
1413 i = j;
1414 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1415 i, btnPtr[i].fsStyle, x, cx);
1416 x = infoPtr->nIndent;
1417 btnPtr[j].fsState |= TBSTATE_WRAP;
1418 bButtonWrap = TRUE;
1419 break;
1423 /* If all above failed, wrap the current button. */
1424 if (!bFound)
1426 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1427 i, btnPtr[i].fsStyle, x, cx);
1428 btnPtr[i].fsState |= TBSTATE_WRAP;
1429 x = infoPtr->nIndent;
1430 if (btnPtr[i].fsStyle & BTNS_SEP )
1431 bButtonWrap = FALSE;
1432 else
1433 bButtonWrap = TRUE;
1436 else {
1437 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1438 i, btnPtr[i].fsStyle, x, cx);
1439 x += cx;
1445 /***********************************************************************
1446 * TOOLBAR_MeasureButton
1448 * Calculates the width and height required for a button. Used in
1449 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1450 * the width of buttons that are autosized.
1452 * Note that it would have been rather elegant to use one piece of code for
1453 * both the laying out of the toolbar and for controlling where button parts
1454 * are drawn, but the native control has inconsistencies between the two that
1455 * prevent this from being effectively. These inconsistencies can be seen as
1456 * artefacts where parts of the button appear outside of the bounding button
1457 * rectangle.
1459 * There are several cases for the calculation of the button dimensions and
1460 * button part positioning:
1462 * List
1463 * ====
1465 * With Bitmap:
1467 * +--------------------------------------------------------+ ^
1468 * | ^ ^ | |
1469 * | | pad.cy / 2 | centred | |
1470 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1471 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1472 * | |<------------>| | | | |
1473 * | +--------------+ +------------+ | |
1474 * |<-------------------------------------->| | |
1475 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1476 * | szText.cx | |
1477 * +--------------------------------------------------------+ -
1478 * <-------------------------------------------------------->
1479 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1481 * Without Bitmap (I_IMAGENONE):
1483 * +-----------------------------------+ ^
1484 * | ^ | |
1485 * | | centred | | LISTPAD_CY +
1486 * | +------------+ | | szText.cy
1487 * | | Text | | |
1488 * | | | | |
1489 * | +------------+ | |
1490 * |<----------------->| | |
1491 * | cxedge |<-----------> | |
1492 * | szText.cx | |
1493 * +-----------------------------------+ -
1494 * <----------------------------------->
1495 * szText.cx + pad.cx
1497 * Without text:
1499 * +--------------------------------------+ ^
1500 * | ^ | |
1501 * | | padding.cy/2 | | DEFPAD_CY +
1502 * | +------------+ | | nBitmapHeight
1503 * | | Bitmap | | |
1504 * | | | | |
1505 * | +------------+ | |
1506 * |<------------------->| | |
1507 * | cxedge + iListGap/2 |<-----------> | |
1508 * | nBitmapWidth | |
1509 * +--------------------------------------+ -
1510 * <-------------------------------------->
1511 * 2*cxedge + nBitmapWidth + iListGap
1513 * Non-List
1514 * ========
1516 * With bitmap:
1518 * +-----------------------------------+ ^
1519 * | ^ | |
1520 * | | pad.cy / 2 | | nBitmapHeight +
1521 * | - | | szText.cy +
1522 * | +------------+ | | DEFPAD_CY + 1
1523 * | centred | Bitmap | | |
1524 * |<----------------->| | | |
1525 * | +------------+ | |
1526 * | ^ | |
1527 * | 1 | | |
1528 * | - | |
1529 * | centred +---------------+ | |
1530 * |<--------------->| Text | | |
1531 * | +---------------+ | |
1532 * +-----------------------------------+ -
1533 * <----------------------------------->
1534 * pad.cx + max(nBitmapWidth, szText.cx)
1536 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1538 * +---------------------------------------+ ^
1539 * | ^ | |
1540 * | | 2 + pad.cy / 2 | |
1541 * | - | | szText.cy +
1542 * | centred +-----------------+ | | pad.cy + 2
1543 * |<--------------->| Text | | |
1544 * | +-----------------+ | |
1545 * | | |
1546 * +---------------------------------------+ -
1547 * <--------------------------------------->
1548 * 2*cxedge + pad.cx + szText.cx
1550 * Without text:
1551 * As for with bitmaps, but with szText.cx zero.
1553 static inline SIZE TOOLBAR_MeasureButton(const TOOLBAR_INFO *infoPtr, SIZE sizeString,
1554 BOOL bHasBitmap, BOOL bValidImageList)
1556 SIZE sizeButton;
1557 if (infoPtr->dwStyle & TBSTYLE_LIST)
1559 /* set button height from bitmap / text height... */
1560 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1561 sizeString.cy);
1563 /* ... add on the necessary padding */
1564 if (bValidImageList)
1566 if (bHasBitmap)
1567 sizeButton.cy += DEFPAD_CY;
1568 else
1569 sizeButton.cy += LISTPAD_CY;
1571 else
1572 sizeButton.cy += infoPtr->szPadding.cy;
1574 /* calculate button width */
1575 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1576 infoPtr->nBitmapWidth + infoPtr->iListGap;
1577 if (sizeString.cx > 0)
1578 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1581 else
1583 if (bHasBitmap)
1585 sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
1586 if (sizeString.cy > 0)
1587 sizeButton.cy += 1 + sizeString.cy;
1588 sizeButton.cx = infoPtr->szPadding.cx +
1589 max(sizeString.cx, infoPtr->nBitmapWidth);
1591 else
1593 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1594 NONLIST_NOTEXT_OFFSET;
1595 sizeButton.cx = infoPtr->szPadding.cx +
1596 max(2*GetSystemMetrics(SM_CXEDGE) + sizeString.cx, infoPtr->nBitmapWidth);
1599 return sizeButton;
1603 /***********************************************************************
1604 * TOOLBAR_CalcToolbar
1606 * This function calculates button and separator placement. It first
1607 * calculates the button sizes, gets the toolbar window width and then
1608 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1609 * on. It assigns a new location to each item and sends this location to
1610 * the tooltip window if appropriate. Finally, it updates the rcBound
1611 * rect and calculates the new required toolbar window height.
1613 static void
1614 TOOLBAR_CalcToolbar (HWND hwnd)
1616 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1617 SIZE sizeString, sizeButton;
1618 BOOL validImageList = FALSE;
1620 TOOLBAR_CalcStrings (hwnd, &sizeString);
1622 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1624 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1625 validImageList = TRUE;
1626 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1627 infoPtr->nButtonWidth = sizeButton.cx;
1628 infoPtr->nButtonHeight = sizeButton.cy;
1629 infoPtr->iTopMargin = default_top_margin(infoPtr);
1631 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1632 infoPtr->nButtonWidth = infoPtr->cxMin;
1633 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1634 infoPtr->nButtonWidth = infoPtr->cxMax;
1636 TOOLBAR_LayoutToolbar(hwnd);
1639 static void
1640 TOOLBAR_LayoutToolbar(HWND hwnd)
1642 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1643 TBUTTON_INFO *btnPtr;
1644 SIZE sizeButton;
1645 INT i, nRows, nSepRows;
1646 INT x, y, cx, cy;
1647 BOOL bWrap;
1648 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1649 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1651 TOOLBAR_WrapToolbar(hwnd, infoPtr->dwStyle);
1653 x = infoPtr->nIndent;
1654 y = infoPtr->iTopMargin;
1655 cx = infoPtr->nButtonWidth;
1656 cy = infoPtr->nButtonHeight;
1658 nRows = nSepRows = 0;
1660 infoPtr->rcBound.top = y;
1661 infoPtr->rcBound.left = x;
1662 infoPtr->rcBound.bottom = y + cy;
1663 infoPtr->rcBound.right = x;
1665 btnPtr = infoPtr->buttons;
1667 TRACE("cy=%d\n", cy);
1669 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1671 bWrap = FALSE;
1672 if (btnPtr->fsState & TBSTATE_HIDDEN)
1674 SetRectEmpty (&btnPtr->rect);
1675 continue;
1678 cy = infoPtr->nButtonHeight;
1680 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1681 /* it is the actual width of the separator. This is used for */
1682 /* custom controls in toolbars. */
1683 if (btnPtr->fsStyle & BTNS_SEP) {
1684 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1685 cy = (btnPtr->iBitmap > 0) ?
1686 btnPtr->iBitmap : SEPARATOR_WIDTH;
1687 cx = infoPtr->nButtonWidth;
1689 else
1690 cx = (btnPtr->iBitmap > 0) ?
1691 btnPtr->iBitmap : SEPARATOR_WIDTH;
1693 else
1695 if (btnPtr->cx)
1696 cx = btnPtr->cx;
1697 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1698 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1700 SIZE sz;
1701 HDC hdc;
1702 HFONT hOldFont;
1704 hdc = GetDC (hwnd);
1705 hOldFont = SelectObject (hdc, infoPtr->hFont);
1707 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1709 SelectObject (hdc, hOldFont);
1710 ReleaseDC (hwnd, hdc);
1712 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1713 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1714 validImageList);
1715 cx = sizeButton.cx;
1717 else
1718 cx = infoPtr->nButtonWidth;
1720 /* if size has been set manually then don't add on extra space
1721 * for the drop down arrow */
1722 if (!btnPtr->cx && hasDropDownArrows &&
1723 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1724 cx += DDARROW_WIDTH;
1726 if (btnPtr->fsState & TBSTATE_WRAP )
1727 bWrap = TRUE;
1729 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1731 if (infoPtr->rcBound.left > x)
1732 infoPtr->rcBound.left = x;
1733 if (infoPtr->rcBound.right < x + cx)
1734 infoPtr->rcBound.right = x + cx;
1735 if (infoPtr->rcBound.bottom < y + cy)
1736 infoPtr->rcBound.bottom = y + cy;
1738 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1740 /* btnPtr->nRow is zero based. The space between the rows is */
1741 /* also considered as a row. */
1742 btnPtr->nRow = nRows + nSepRows;
1744 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1745 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1746 x, y, x+cx, y+cy);
1748 if( bWrap )
1750 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1751 y += cy;
1752 else
1754 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1755 /* it is the actual width of the separator. This is used for */
1756 /* custom controls in toolbars. */
1757 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1758 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1759 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1760 else
1761 y += cy;
1763 /* nSepRows is used to calculate the extra height following */
1764 /* the last row. */
1765 nSepRows++;
1767 x = infoPtr->nIndent;
1769 /* Increment row number unless this is the last button */
1770 /* and it has Wrap set. */
1771 if (i != infoPtr->nNumButtons-1)
1772 nRows++;
1774 else
1775 x += cx;
1778 /* infoPtr->nRows is the number of rows on the toolbar */
1779 infoPtr->nRows = nRows + nSepRows + 1;
1781 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1785 static INT
1786 TOOLBAR_InternalHitTest (HWND hwnd, const POINT *lpPt)
1788 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1789 TBUTTON_INFO *btnPtr;
1790 INT i;
1792 btnPtr = infoPtr->buttons;
1793 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1794 if (btnPtr->fsState & TBSTATE_HIDDEN)
1795 continue;
1797 if (btnPtr->fsStyle & BTNS_SEP) {
1798 if (PtInRect (&btnPtr->rect, *lpPt)) {
1799 TRACE(" ON SEPARATOR %d!\n", i);
1800 return -i;
1803 else {
1804 if (PtInRect (&btnPtr->rect, *lpPt)) {
1805 TRACE(" ON BUTTON %d!\n", i);
1806 return i;
1811 TRACE(" NOWHERE!\n");
1812 return TOOLBAR_NOWHERE;
1816 static INT
1817 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1819 TBUTTON_INFO *btnPtr;
1820 INT i;
1822 if (CommandIsIndex) {
1823 TRACE("command is really index command=%d\n", idCommand);
1824 if (idCommand >= infoPtr->nNumButtons) return -1;
1825 return idCommand;
1827 btnPtr = infoPtr->buttons;
1828 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1829 if (btnPtr->idCommand == idCommand) {
1830 TRACE("command=%d index=%d\n", idCommand, i);
1831 return i;
1834 TRACE("no index found for command=%d\n", idCommand);
1835 return -1;
1839 static INT
1840 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO *infoPtr, INT nIndex)
1842 TBUTTON_INFO *btnPtr;
1843 INT nRunIndex;
1845 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1846 return -1;
1848 /* check index button */
1849 btnPtr = &infoPtr->buttons[nIndex];
1850 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1851 if (btnPtr->fsState & TBSTATE_CHECKED)
1852 return nIndex;
1855 /* check previous buttons */
1856 nRunIndex = nIndex - 1;
1857 while (nRunIndex >= 0) {
1858 btnPtr = &infoPtr->buttons[nRunIndex];
1859 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1860 if (btnPtr->fsState & TBSTATE_CHECKED)
1861 return nRunIndex;
1863 else
1864 break;
1865 nRunIndex--;
1868 /* check next buttons */
1869 nRunIndex = nIndex + 1;
1870 while (nRunIndex < infoPtr->nNumButtons) {
1871 btnPtr = &infoPtr->buttons[nRunIndex];
1872 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1873 if (btnPtr->fsState & TBSTATE_CHECKED)
1874 return nRunIndex;
1876 else
1877 break;
1878 nRunIndex++;
1881 return -1;
1885 static VOID
1886 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1887 WPARAM wParam, LPARAM lParam)
1889 MSG msg;
1891 msg.hwnd = hwndMsg;
1892 msg.message = uMsg;
1893 msg.wParam = wParam;
1894 msg.lParam = lParam;
1895 msg.time = GetMessageTime ();
1896 msg.pt.x = (short)LOWORD(GetMessagePos ());
1897 msg.pt.y = (short)HIWORD(GetMessagePos ());
1899 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1902 static void
1903 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1905 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1906 TTTOOLINFOW ti;
1908 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1909 ti.cbSize = sizeof (TTTOOLINFOW);
1910 ti.hwnd = infoPtr->hwndSelf;
1911 ti.uId = button->idCommand;
1912 ti.hinst = 0;
1913 ti.lpszText = LPSTR_TEXTCALLBACKW;
1914 /* ti.lParam = random value from the stack? */
1916 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1917 0, (LPARAM)&ti);
1921 static void
1922 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1924 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1925 TTTOOLINFOW ti;
1927 ZeroMemory(&ti, sizeof(ti));
1928 ti.cbSize = sizeof(ti);
1929 ti.hwnd = infoPtr->hwndSelf;
1930 ti.uId = button->idCommand;
1932 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1936 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1938 /* Set the toolTip only for non-hidden, non-separator button */
1939 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1941 TTTOOLINFOW ti;
1943 ZeroMemory(&ti, sizeof(ti));
1944 ti.cbSize = sizeof(ti);
1945 ti.hwnd = infoPtr->hwndSelf;
1946 ti.uId = button->idCommand;
1947 ti.rect = button->rect;
1948 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1952 /* Creates the tooltip control */
1953 static void
1954 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
1956 int i;
1957 NMTOOLTIPSCREATED nmttc;
1959 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1960 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1961 infoPtr->hwndSelf, 0, 0, 0);
1963 if (!infoPtr->hwndToolTip)
1964 return;
1966 /* Send NM_TOOLTIPSCREATED notification */
1967 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1968 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
1970 for (i = 0; i < infoPtr->nNumButtons; i++)
1972 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
1973 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
1977 /* keeps available button list box sorted by button id */
1978 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1980 int i;
1981 int count;
1982 PCUSTOMBUTTON btnInfo;
1983 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1985 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1987 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1989 /* position 0 is always separator */
1990 for (i = 1; i < count; i++)
1992 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1993 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1995 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1996 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1997 return;
2000 /* id higher than all others add to end */
2001 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2002 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2005 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2007 NMTOOLBARW nmtb;
2009 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2011 if (nIndexFrom == nIndexTo)
2012 return;
2014 /* MSDN states that iItem is the index of the button, rather than the
2015 * command ID as used by every other NMTOOLBAR notification */
2016 nmtb.iItem = nIndexFrom;
2017 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2019 PCUSTOMBUTTON btnInfo;
2020 NMHDR hdr;
2021 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2022 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2024 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2026 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2027 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2028 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2029 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2031 if (nIndexTo <= 0)
2032 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2033 else
2034 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2036 /* last item is always separator, so -2 instead of -1 */
2037 if (nIndexTo >= (count - 2))
2038 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2039 else
2040 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2042 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2043 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2045 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2049 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2051 NMTOOLBARW nmtb;
2053 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2055 /* MSDN states that iItem is the index of the button, rather than the
2056 * command ID as used by every other NMTOOLBAR notification */
2057 nmtb.iItem = nIndexAvail;
2058 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2060 PCUSTOMBUTTON btnInfo;
2061 NMHDR hdr;
2062 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2063 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2064 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2066 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2068 if (nIndexAvail != 0) /* index == 0 indicates separator */
2070 /* remove from 'available buttons' list */
2071 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2072 if (nIndexAvail == count-1)
2073 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2074 else
2075 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2077 else
2079 PCUSTOMBUTTON btnNew;
2081 /* duplicate 'separator' button */
2082 btnNew = Alloc(sizeof(CUSTOMBUTTON));
2083 *btnNew = *btnInfo;
2084 btnInfo = btnNew;
2087 /* insert into 'toolbar button' list */
2088 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2089 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2091 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2093 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2097 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT index)
2099 PCUSTOMBUTTON btnInfo;
2100 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2102 TRACE("Remove: index %d\n", index);
2104 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2106 /* send TBN_QUERYDELETE notification */
2107 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2109 NMHDR hdr;
2111 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2112 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2114 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2116 /* insert into 'available button' list */
2117 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2118 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2119 else
2120 Free(btnInfo);
2122 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2126 /* drag list notification function for toolbar buttons list box */
2127 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2128 const DRAGLISTINFO *pDLI)
2130 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2131 switch (pDLI->uNotification)
2133 case DL_BEGINDRAG:
2135 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2136 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2137 /* no dragging for last item (separator) */
2138 if (nCurrentItem >= (nCount - 1)) return FALSE;
2139 return TRUE;
2141 case DL_DRAGGING:
2143 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2144 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2145 /* no dragging past last item (separator) */
2146 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2148 DrawInsert(hwnd, hwndList, nCurrentItem);
2149 /* FIXME: native uses "move button" cursor */
2150 return DL_COPYCURSOR;
2153 /* not over toolbar buttons list */
2154 if (nCurrentItem < 0)
2156 POINT ptWindow = pDLI->ptCursor;
2157 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2158 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2159 /* over available buttons list? */
2160 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2161 /* FIXME: native uses "move button" cursor */
2162 return DL_COPYCURSOR;
2164 /* clear drag arrow */
2165 DrawInsert(hwnd, hwndList, -1);
2166 return DL_STOPCURSOR;
2168 case DL_DROPPED:
2170 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2171 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2172 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2173 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2175 /* clear drag arrow */
2176 DrawInsert(hwnd, hwndList, -1);
2177 /* move item */
2178 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2180 /* not over toolbar buttons list */
2181 if (nIndexTo < 0)
2183 POINT ptWindow = pDLI->ptCursor;
2184 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2185 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2186 /* over available buttons list? */
2187 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2188 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2190 break;
2192 case DL_CANCELDRAG:
2193 /* Clear drag arrow */
2194 DrawInsert(hwnd, hwndList, -1);
2195 break;
2198 return 0;
2201 /* drag list notification function for available buttons list box */
2202 static LRESULT TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2203 const DRAGLISTINFO *pDLI)
2205 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2206 switch (pDLI->uNotification)
2208 case DL_BEGINDRAG:
2209 return TRUE;
2210 case DL_DRAGGING:
2212 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2213 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2214 /* no dragging past last item (separator) */
2215 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2217 DrawInsert(hwnd, hwndList, nCurrentItem);
2218 /* FIXME: native uses "move button" cursor */
2219 return DL_COPYCURSOR;
2222 /* not over toolbar buttons list */
2223 if (nCurrentItem < 0)
2225 POINT ptWindow = pDLI->ptCursor;
2226 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2227 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2228 /* over available buttons list? */
2229 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2230 /* FIXME: native uses "move button" cursor */
2231 return DL_COPYCURSOR;
2233 /* clear drag arrow */
2234 DrawInsert(hwnd, hwndList, -1);
2235 return DL_STOPCURSOR;
2237 case DL_DROPPED:
2239 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2240 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2241 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2242 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2244 /* clear drag arrow */
2245 DrawInsert(hwnd, hwndList, -1);
2246 /* add item */
2247 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2250 case DL_CANCELDRAG:
2251 /* Clear drag arrow */
2252 DrawInsert(hwnd, hwndList, -1);
2253 break;
2255 return 0;
2258 extern UINT uDragListMessage;
2260 /***********************************************************************
2261 * TOOLBAR_CustomizeDialogProc
2262 * This function implements the toolbar customization dialog.
2264 static INT_PTR CALLBACK
2265 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2267 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2268 PCUSTOMBUTTON btnInfo;
2269 NMTOOLBARA nmtb;
2270 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2272 switch (uMsg)
2274 case WM_INITDIALOG:
2275 custInfo = (PCUSTDLG_INFO)lParam;
2276 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2278 if (custInfo)
2280 WCHAR Buffer[256];
2281 int i = 0;
2282 int index;
2283 NMTBINITCUSTOMIZE nmtbic;
2285 infoPtr = custInfo->tbInfo;
2287 /* send TBN_QUERYINSERT notification */
2288 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2290 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2291 return FALSE;
2293 nmtbic.hwndDialog = hwnd;
2294 /* Send TBN_INITCUSTOMIZE notification */
2295 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2296 TBNRF_HIDEHELP)
2298 TRACE("TBNRF_HIDEHELP requested\n");
2299 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2302 /* add items to 'toolbar buttons' list and check if removable */
2303 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2305 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2306 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2307 btnInfo->btn.fsStyle = BTNS_SEP;
2308 btnInfo->bVirtual = FALSE;
2309 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2311 /* send TBN_QUERYDELETE notification */
2312 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2314 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2315 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2318 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2320 /* insert separator button into 'available buttons' list */
2321 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2322 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2323 btnInfo->btn.fsStyle = BTNS_SEP;
2324 btnInfo->bVirtual = FALSE;
2325 btnInfo->bRemovable = TRUE;
2326 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2327 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2328 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2330 /* insert all buttons into dsa */
2331 for (i = 0;; i++)
2333 /* send TBN_GETBUTTONINFO notification */
2334 NMTOOLBARW nmtb;
2335 nmtb.iItem = i;
2336 nmtb.pszText = Buffer;
2337 nmtb.cchText = 256;
2339 /* Clear previous button's text */
2340 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2342 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2343 break;
2345 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2346 nmtb.tbButton.fsStyle, i,
2347 nmtb.tbButton.idCommand,
2348 nmtb.tbButton.iString,
2349 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2350 : "");
2352 /* insert button into the apropriate list */
2353 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2354 if (index == -1)
2356 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2357 btnInfo->bVirtual = FALSE;
2358 btnInfo->bRemovable = TRUE;
2360 else
2362 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2363 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2366 btnInfo->btn = nmtb.tbButton;
2367 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2369 if (lstrlenW(nmtb.pszText))
2370 lstrcpyW(btnInfo->text, nmtb.pszText);
2371 else if (nmtb.tbButton.iString >= 0 &&
2372 nmtb.tbButton.iString < infoPtr->nNumStrings)
2374 lstrcpyW(btnInfo->text,
2375 infoPtr->strings[nmtb.tbButton.iString]);
2379 if (index == -1)
2380 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2383 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2385 /* select first item in the 'available' list */
2386 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2388 /* append 'virtual' separator button to the 'toolbar buttons' list */
2389 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2390 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2391 btnInfo->btn.fsStyle = BTNS_SEP;
2392 btnInfo->bVirtual = TRUE;
2393 btnInfo->bRemovable = FALSE;
2394 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2395 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2396 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2398 /* select last item in the 'toolbar' list */
2399 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2400 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2402 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2403 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2405 /* set focus and disable buttons */
2406 PostMessageW (hwnd, WM_USER, 0, 0);
2408 return TRUE;
2410 case WM_USER:
2411 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2412 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2413 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2414 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2415 return TRUE;
2417 case WM_CLOSE:
2418 EndDialog(hwnd, FALSE);
2419 return TRUE;
2421 case WM_COMMAND:
2422 switch (LOWORD(wParam))
2424 case IDC_TOOLBARBTN_LBOX:
2425 if (HIWORD(wParam) == LBN_SELCHANGE)
2427 PCUSTOMBUTTON btnInfo;
2428 NMTOOLBARA nmtb;
2429 int count;
2430 int index;
2432 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2433 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2435 /* send TBN_QUERYINSERT notification */
2436 nmtb.iItem = index;
2437 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2439 /* get list box item */
2440 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2442 if (index == (count - 1))
2444 /* last item (virtual separator) */
2445 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2446 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2448 else if (index == (count - 2))
2450 /* second last item (last non-virtual item) */
2451 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2452 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2454 else if (index == 0)
2456 /* first item */
2457 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2458 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2460 else
2462 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2463 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2466 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2468 break;
2470 case IDC_MOVEUP_BTN:
2472 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2473 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2475 break;
2477 case IDC_MOVEDN_BTN: /* move down */
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_REMOVE_BTN: /* remove button */
2486 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2488 if (LB_ERR == index)
2489 break;
2491 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2493 break;
2494 case IDC_HELP_BTN:
2495 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2496 break;
2497 case IDC_RESET_BTN:
2498 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2499 break;
2501 case IDOK: /* Add button */
2503 int index;
2504 int indexto;
2506 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2507 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2509 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2511 break;
2513 case IDCANCEL:
2514 EndDialog(hwnd, FALSE);
2515 break;
2517 return TRUE;
2519 case WM_DESTROY:
2521 int count;
2522 int i;
2524 /* delete items from 'toolbar buttons' listbox*/
2525 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2526 for (i = 0; i < count; i++)
2528 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2529 Free(btnInfo);
2530 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2532 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2535 /* delete items from 'available buttons' listbox*/
2536 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2537 for (i = 0; i < count; i++)
2539 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2540 Free(btnInfo);
2541 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2543 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2545 return TRUE;
2547 case WM_DRAWITEM:
2548 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2550 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2551 RECT rcButton;
2552 RECT rcText;
2553 HPEN hPen, hOldPen;
2554 HBRUSH hOldBrush;
2555 COLORREF oldText = 0;
2556 COLORREF oldBk = 0;
2558 /* get item data */
2559 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2560 if (btnInfo == NULL)
2562 FIXME("btnInfo invalid!\n");
2563 return TRUE;
2566 /* set colors and select objects */
2567 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2568 if (btnInfo->bVirtual)
2569 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2570 else
2571 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2572 hPen = CreatePen( PS_SOLID, 1,
2573 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2574 hOldPen = SelectObject (lpdis->hDC, hPen );
2575 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2577 /* fill background rectangle */
2578 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2579 lpdis->rcItem.right, lpdis->rcItem.bottom);
2581 /* calculate button and text rectangles */
2582 CopyRect (&rcButton, &lpdis->rcItem);
2583 InflateRect (&rcButton, -1, -1);
2584 CopyRect (&rcText, &rcButton);
2585 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2586 rcText.left = rcButton.right + 2;
2588 /* draw focus rectangle */
2589 if (lpdis->itemState & ODS_FOCUS)
2590 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2592 /* draw button */
2593 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2594 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2596 /* draw image and text */
2597 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2598 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2599 btnInfo->btn.iBitmap));
2600 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2601 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2603 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2604 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2606 /* delete objects and reset colors */
2607 SelectObject (lpdis->hDC, hOldBrush);
2608 SelectObject (lpdis->hDC, hOldPen);
2609 SetBkColor (lpdis->hDC, oldBk);
2610 SetTextColor (lpdis->hDC, oldText);
2611 DeleteObject( hPen );
2612 return TRUE;
2614 return FALSE;
2616 case WM_MEASUREITEM:
2617 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2619 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2621 lpmis->itemHeight = 15 + 8; /* default height */
2623 return TRUE;
2625 return FALSE;
2627 default:
2628 if (uDragListMessage && (uMsg == uDragListMessage))
2630 if (wParam == IDC_TOOLBARBTN_LBOX)
2632 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2633 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2634 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2635 return TRUE;
2637 else if (wParam == IDC_AVAILBTN_LBOX)
2639 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2640 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2641 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2642 return TRUE;
2645 return FALSE;
2649 static BOOL
2650 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2652 HBITMAP hbmLoad;
2653 INT nCountBefore = ImageList_GetImageCount(himlDef);
2654 INT nCountAfter;
2655 INT cxIcon, cyIcon;
2656 INT nAdded;
2657 INT nIndex;
2659 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2660 /* Add bitmaps to the default image list */
2661 if (bitmap->hInst == NULL) /* a handle was passed */
2662 hbmLoad = CopyImage(ULongToHandle(bitmap->nID), IMAGE_BITMAP, 0, 0, 0);
2663 else
2664 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2666 /* enlarge the bitmap if needed */
2667 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2668 if (bitmap->hInst != COMCTL32_hModule)
2669 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2671 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2672 DeleteObject(hbmLoad);
2673 if (nIndex == -1)
2674 return FALSE;
2676 nCountAfter = ImageList_GetImageCount(himlDef);
2677 nAdded = nCountAfter - nCountBefore;
2678 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2680 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2681 } else if (nAdded > (INT)bitmap->nButtons) {
2682 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2683 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2686 infoPtr->nNumBitmaps += nAdded;
2687 return TRUE;
2690 static void
2691 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2693 HIMAGELIST himlDef;
2694 HIMAGELIST himlNew;
2695 INT cx, cy;
2696 INT i;
2698 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2699 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2700 return;
2701 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2702 return;
2703 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2704 return;
2706 TRACE("Update icon size: %dx%d -> %dx%d\n",
2707 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2709 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2710 ILC_COLORDDB|ILC_MASK, 8, 2);
2711 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2712 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2713 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2714 infoPtr->himlInt = himlNew;
2716 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2717 ImageList_Destroy(himlDef);
2720 /***********************************************************************
2721 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2724 static LRESULT
2725 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2727 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2728 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2729 TBITMAP_INFO info;
2730 INT iSumButtons, i;
2731 HIMAGELIST himlDef;
2733 TRACE("hwnd=%p wParam=%lx lParam=%lx\n", hwnd, wParam, lParam);
2734 if (!lpAddBmp)
2735 return -1;
2737 if (lpAddBmp->hInst == HINST_COMMCTRL)
2739 info.hInst = COMCTL32_hModule;
2740 switch (lpAddBmp->nID)
2742 case IDB_STD_SMALL_COLOR:
2743 info.nButtons = 15;
2744 info.nID = IDB_STD_SMALL;
2745 break;
2746 case IDB_STD_LARGE_COLOR:
2747 info.nButtons = 15;
2748 info.nID = IDB_STD_LARGE;
2749 break;
2750 case IDB_VIEW_SMALL_COLOR:
2751 info.nButtons = 12;
2752 info.nID = IDB_VIEW_SMALL;
2753 break;
2754 case IDB_VIEW_LARGE_COLOR:
2755 info.nButtons = 12;
2756 info.nID = IDB_VIEW_LARGE;
2757 break;
2758 case IDB_HIST_SMALL_COLOR:
2759 info.nButtons = 5;
2760 info.nID = IDB_HIST_SMALL;
2761 break;
2762 case IDB_HIST_LARGE_COLOR:
2763 info.nButtons = 5;
2764 info.nID = IDB_HIST_LARGE;
2765 break;
2766 default:
2767 return -1;
2770 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2772 /* Windows resize all the buttons to the size of a newly added standard image */
2773 if (lpAddBmp->nID & 1)
2775 /* large icons: 24x24. Will make the button 31x30 */
2776 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
2778 else
2780 /* small icons: 16x16. Will make the buttons 23x22 */
2781 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
2784 TOOLBAR_CalcToolbar (hwnd);
2786 else
2788 info.nButtons = (INT)wParam;
2789 info.hInst = lpAddBmp->hInst;
2790 info.nID = lpAddBmp->nID;
2791 TRACE("adding %d bitmaps!\n", info.nButtons);
2794 /* check if the bitmap is already loaded and compute iSumButtons */
2795 iSumButtons = 0;
2796 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2798 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2799 infoPtr->bitmaps[i].nID == info.nID)
2800 return iSumButtons;
2801 iSumButtons += infoPtr->bitmaps[i].nButtons;
2804 if (!infoPtr->cimlDef) {
2805 /* create new default image list */
2806 TRACE ("creating default image list!\n");
2808 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2809 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2810 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2811 infoPtr->himlInt = himlDef;
2813 else {
2814 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2817 if (!himlDef) {
2818 WARN("No default image list available\n");
2819 return -1;
2822 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2823 return -1;
2825 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2826 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2827 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2828 infoPtr->nNumBitmapInfos++;
2829 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2831 InvalidateRect(hwnd, NULL, TRUE);
2832 return iSumButtons;
2836 static LRESULT
2837 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2839 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2840 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2841 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2842 BOOL fHasString = FALSE;
2844 TRACE("adding %ld buttons (unicode=%d)!\n", wParam, fUnicode);
2846 nAddButtons = (UINT)wParam;
2847 nOldButtons = infoPtr->nNumButtons;
2848 nNewButtons = nOldButtons + nAddButtons;
2850 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
2851 infoPtr->nNumButtons = nNewButtons;
2853 /* insert new button data */
2854 for (nCount = 0; nCount < nAddButtons; nCount++) {
2855 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2856 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2857 btnPtr->idCommand = lpTbb[nCount].idCommand;
2858 btnPtr->fsState = lpTbb[nCount].fsState;
2859 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2860 btnPtr->dwData = lpTbb[nCount].dwData;
2861 btnPtr->bHot = FALSE;
2862 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2864 if (fUnicode)
2865 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2866 else
2867 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString);
2868 fHasString = TRUE;
2870 else
2871 btnPtr->iString = lpTbb[nCount].iString;
2873 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
2876 if (infoPtr->nNumStrings > 0 || fHasString)
2877 TOOLBAR_CalcToolbar(hwnd);
2878 else
2879 TOOLBAR_LayoutToolbar(hwnd);
2880 TOOLBAR_AutoSize (hwnd);
2882 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2884 InvalidateRect(hwnd, NULL, TRUE);
2886 return TRUE;
2890 static LRESULT
2891 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2893 #define MAX_RESOURCE_STRING_LENGTH 512
2894 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2895 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2896 INT nIndex = infoPtr->nNumStrings;
2898 if ((wParam) && (HIWORD(lParam) == 0)) {
2899 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2900 WCHAR delimiter;
2901 WCHAR *next_delim;
2902 WCHAR *p;
2903 INT len;
2904 TRACE("adding string from resource!\n");
2906 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2907 szString, MAX_RESOURCE_STRING_LENGTH);
2909 TRACE("len=%d %s\n", len, debugstr_w(szString));
2910 if (len == 0 || len == 1)
2911 return nIndex;
2913 TRACE("Delimiter: 0x%x\n", *szString);
2914 delimiter = *szString;
2915 p = szString + 1;
2917 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2918 *next_delim = 0;
2919 if (next_delim + 1 >= szString + len)
2921 /* this may happen if delimiter == '\0' or if the last char is a
2922 * delimiter (then it is ignored like the native does) */
2923 break;
2926 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2927 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2928 infoPtr->nNumStrings++;
2930 p = next_delim + 1;
2933 else {
2934 LPWSTR p = (LPWSTR)lParam;
2935 INT len;
2937 if (p == NULL)
2938 return -1;
2939 TRACE("adding string(s) from array!\n");
2940 while (*p) {
2941 len = strlenW (p);
2943 TRACE("len=%d %s\n", len, debugstr_w(p));
2944 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2945 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2946 infoPtr->nNumStrings++;
2948 p += (len+1);
2952 if (fFirstString)
2953 TOOLBAR_CalcToolbar(hwnd);
2954 return nIndex;
2958 static LRESULT
2959 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2961 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2962 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2963 LPSTR p;
2964 INT nIndex;
2965 INT len;
2967 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
2968 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
2970 p = (LPSTR)lParam;
2971 if (p == NULL)
2972 return -1;
2974 TRACE("adding string(s) from array!\n");
2975 nIndex = infoPtr->nNumStrings;
2976 while (*p) {
2977 len = strlen (p);
2978 TRACE("len=%d \"%s\"\n", len, p);
2980 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2981 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
2982 infoPtr->nNumStrings++;
2984 p += (len+1);
2987 if (fFirstString)
2988 TOOLBAR_CalcToolbar(hwnd);
2989 return nIndex;
2993 static LRESULT
2994 TOOLBAR_AutoSize (HWND hwnd)
2996 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2997 RECT parent_rect;
2998 HWND parent;
2999 INT x, y;
3000 INT cx, cy;
3002 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3004 parent = GetParent (hwnd);
3006 if (!parent || !infoPtr->bDoRedraw)
3007 return 0;
3009 GetClientRect(parent, &parent_rect);
3011 x = parent_rect.left;
3012 y = parent_rect.top;
3014 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3016 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3017 cx = parent_rect.right - parent_rect.left;
3019 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3021 TOOLBAR_LayoutToolbar(hwnd);
3022 InvalidateRect( hwnd, NULL, TRUE );
3025 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3027 RECT window_rect;
3028 UINT uPosFlags = SWP_NOZORDER;
3030 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3032 GetWindowRect(hwnd, &window_rect);
3033 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3034 y = window_rect.top;
3036 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3038 GetWindowRect(hwnd, &window_rect);
3039 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3042 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3043 uPosFlags |= SWP_NOMOVE;
3045 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3046 cy += GetSystemMetrics(SM_CYEDGE);
3048 if (infoPtr->dwStyle & WS_BORDER)
3050 x = y = 1; /* FIXME: this looks wrong */
3051 cy += GetSystemMetrics(SM_CYEDGE);
3052 cx += GetSystemMetrics(SM_CXEDGE);
3055 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3058 return 0;
3062 static LRESULT
3063 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3065 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3067 return infoPtr->nNumButtons;
3071 static LRESULT
3072 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3074 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3076 infoPtr->dwStructSize = (DWORD)wParam;
3078 return 0;
3082 static LRESULT
3083 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3085 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3086 TBUTTON_INFO *btnPtr;
3087 INT nIndex;
3089 TRACE("button %ld, iBitmap now %d\n", wParam, LOWORD(lParam));
3091 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3092 if (nIndex == -1)
3093 return FALSE;
3095 btnPtr = &infoPtr->buttons[nIndex];
3096 btnPtr->iBitmap = LOWORD(lParam);
3098 /* we HAVE to erase the background, the new bitmap could be */
3099 /* transparent */
3100 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3102 return TRUE;
3106 static LRESULT
3107 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3109 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3110 TBUTTON_INFO *btnPtr;
3111 INT nIndex;
3112 INT nOldIndex = -1;
3113 BOOL bChecked = FALSE;
3115 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3117 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3119 if (nIndex == -1)
3120 return FALSE;
3122 btnPtr = &infoPtr->buttons[nIndex];
3124 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3126 if (LOWORD(lParam) == FALSE)
3127 btnPtr->fsState &= ~TBSTATE_CHECKED;
3128 else {
3129 if (btnPtr->fsStyle & BTNS_GROUP) {
3130 nOldIndex =
3131 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3132 if (nOldIndex == nIndex)
3133 return 0;
3134 if (nOldIndex != -1)
3135 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3137 btnPtr->fsState |= TBSTATE_CHECKED;
3140 if( bChecked != LOWORD(lParam) )
3142 if (nOldIndex != -1)
3143 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3144 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3147 /* FIXME: Send a WM_NOTIFY?? */
3149 return TRUE;
3153 static LRESULT
3154 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3156 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3158 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3162 static LRESULT
3163 TOOLBAR_Customize (HWND hwnd)
3165 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3166 CUSTDLG_INFO custInfo;
3167 LRESULT ret;
3168 LPCVOID template;
3169 HRSRC hRes;
3170 NMHDR nmhdr;
3172 custInfo.tbInfo = infoPtr;
3173 custInfo.tbHwnd = hwnd;
3175 /* send TBN_BEGINADJUST notification */
3176 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3178 if (!(hRes = FindResourceW (COMCTL32_hModule,
3179 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3180 (LPWSTR)RT_DIALOG)))
3181 return FALSE;
3183 if(!(template = LoadResource (COMCTL32_hModule, hRes)))
3184 return FALSE;
3186 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3187 (LPCDLGTEMPLATEW)template,
3188 hwnd,
3189 TOOLBAR_CustomizeDialogProc,
3190 (LPARAM)&custInfo);
3192 /* send TBN_ENDADJUST notification */
3193 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3195 return ret;
3199 static LRESULT
3200 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3202 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3203 INT nIndex = (INT)wParam;
3204 NMTOOLBARW nmtb;
3205 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3207 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3208 return FALSE;
3210 memset(&nmtb, 0, sizeof(nmtb));
3211 nmtb.iItem = btnPtr->idCommand;
3212 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3213 nmtb.tbButton.idCommand = btnPtr->idCommand;
3214 nmtb.tbButton.fsState = btnPtr->fsState;
3215 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3216 nmtb.tbButton.dwData = btnPtr->dwData;
3217 nmtb.tbButton.iString = btnPtr->iString;
3218 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3220 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3222 if (infoPtr->nNumButtons == 1) {
3223 TRACE(" simple delete!\n");
3224 Free (infoPtr->buttons);
3225 infoPtr->buttons = NULL;
3226 infoPtr->nNumButtons = 0;
3228 else {
3229 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3230 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3232 infoPtr->nNumButtons--;
3233 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3234 if (nIndex > 0) {
3235 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3236 nIndex * sizeof(TBUTTON_INFO));
3239 if (nIndex < infoPtr->nNumButtons) {
3240 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3241 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3244 Free (oldButtons);
3247 TOOLBAR_LayoutToolbar(hwnd);
3249 InvalidateRect (hwnd, NULL, TRUE);
3251 return TRUE;
3255 static LRESULT
3256 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3258 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3259 TBUTTON_INFO *btnPtr;
3260 INT nIndex;
3261 DWORD bState;
3263 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3265 TRACE("hwnd=%p, btn index=%ld, lParam=0x%08lx\n", hwnd, wParam, lParam);
3267 if (nIndex == -1)
3268 return FALSE;
3270 btnPtr = &infoPtr->buttons[nIndex];
3272 bState = btnPtr->fsState & TBSTATE_ENABLED;
3274 /* update the toolbar button state */
3275 if(LOWORD(lParam) == FALSE) {
3276 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3277 } else {
3278 btnPtr->fsState |= TBSTATE_ENABLED;
3281 /* redraw the button only if the state of the button changed */
3282 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3283 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3285 return TRUE;
3289 static inline LRESULT
3290 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3292 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3294 return infoPtr->bAnchor;
3298 static LRESULT
3299 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3301 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3302 INT nIndex;
3304 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3305 if (nIndex == -1)
3306 return -1;
3308 return infoPtr->buttons[nIndex].iBitmap;
3312 static inline LRESULT
3313 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3315 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3319 static LRESULT
3320 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3322 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3323 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3324 INT nIndex = (INT)wParam;
3325 TBUTTON_INFO *btnPtr;
3327 if (lpTbb == NULL)
3328 return FALSE;
3330 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3331 return FALSE;
3333 btnPtr = &infoPtr->buttons[nIndex];
3334 lpTbb->iBitmap = btnPtr->iBitmap;
3335 lpTbb->idCommand = btnPtr->idCommand;
3336 lpTbb->fsState = btnPtr->fsState;
3337 lpTbb->fsStyle = btnPtr->fsStyle;
3338 lpTbb->bReserved[0] = 0;
3339 lpTbb->bReserved[1] = 0;
3340 lpTbb->dwData = btnPtr->dwData;
3341 lpTbb->iString = btnPtr->iString;
3343 return TRUE;
3347 static LRESULT
3348 TOOLBAR_GetButtonInfoT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL bUnicode)
3350 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3351 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3352 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3353 TBUTTON_INFO *btnPtr;
3354 INT nIndex;
3356 if (lpTbInfo == NULL)
3357 return -1;
3359 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3360 * the headers and tests shows that even with comctl 6 Vista accepts only the
3361 * original TBBUTTONINFO size
3363 if (lpTbInfo->cbSize != sizeof(TBBUTTONINFOW))
3365 WARN("Invalid button size\n");
3366 return -1;
3369 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3370 lpTbInfo->dwMask & 0x80000000);
3371 if (nIndex == -1)
3372 return -1;
3374 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3376 if (lpTbInfo->dwMask & TBIF_COMMAND)
3377 lpTbInfo->idCommand = btnPtr->idCommand;
3378 if (lpTbInfo->dwMask & TBIF_IMAGE)
3379 lpTbInfo->iImage = btnPtr->iBitmap;
3380 if (lpTbInfo->dwMask & TBIF_LPARAM)
3381 lpTbInfo->lParam = btnPtr->dwData;
3382 if (lpTbInfo->dwMask & TBIF_SIZE)
3383 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3384 if (lpTbInfo->dwMask & TBIF_STATE)
3385 lpTbInfo->fsState = btnPtr->fsState;
3386 if (lpTbInfo->dwMask & TBIF_STYLE)
3387 lpTbInfo->fsStyle = btnPtr->fsStyle;
3388 if (lpTbInfo->dwMask & TBIF_TEXT) {
3389 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3390 can't use TOOLBAR_GetText here */
3391 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3392 LPWSTR lpText = (LPWSTR)btnPtr->iString;
3393 if (bUnicode)
3394 Str_GetPtrW(lpText, lpTbInfo->pszText, lpTbInfo->cchText);
3395 else
3396 Str_GetPtrWtoA(lpText, (LPSTR)lpTbInfo->pszText, lpTbInfo->cchText);
3397 } else
3398 lpTbInfo->pszText[0] = '\0';
3400 return nIndex;
3404 static LRESULT
3405 TOOLBAR_GetButtonSize (HWND hwnd)
3407 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3409 return MAKELONG((WORD)infoPtr->nButtonWidth,
3410 (WORD)infoPtr->nButtonHeight);
3414 static LRESULT
3415 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3417 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3418 INT nIndex;
3419 LPWSTR lpText;
3421 if (lParam == 0)
3422 return -1;
3424 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3425 if (nIndex == -1)
3426 return -1;
3428 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3430 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3431 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3435 static LRESULT
3436 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3438 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3439 INT nIndex;
3440 LPWSTR lpText;
3441 LRESULT ret = 0;
3443 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3444 if (nIndex == -1)
3445 return -1;
3447 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3449 if (lpText)
3451 ret = strlenW (lpText);
3453 if (lParam)
3454 strcpyW ((LPWSTR)lParam, lpText);
3457 return ret;
3461 static LRESULT
3462 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3464 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3465 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3466 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3470 static inline LRESULT
3471 TOOLBAR_GetExtendedStyle (HWND hwnd)
3473 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3475 TRACE("\n");
3477 return infoPtr->dwExStyle;
3481 static LRESULT
3482 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3484 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3485 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3486 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3490 static LRESULT
3491 TOOLBAR_GetHotItem (HWND hwnd)
3493 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3495 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3496 return -1;
3498 if (infoPtr->nHotItem < 0)
3499 return -1;
3501 return (LRESULT)infoPtr->nHotItem;
3505 static LRESULT
3506 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3508 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3509 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3510 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3514 static LRESULT
3515 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3517 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3518 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3520 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3522 *lptbim = infoPtr->tbim;
3524 return 0;
3528 static LRESULT
3529 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3531 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3533 TRACE("hwnd = %p\n", hwnd);
3535 return (LRESULT)infoPtr->clrInsertMark;
3539 static LRESULT
3540 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3542 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3543 TBUTTON_INFO *btnPtr;
3544 LPRECT lpRect;
3545 INT nIndex;
3547 nIndex = (INT)wParam;
3548 btnPtr = &infoPtr->buttons[nIndex];
3549 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3550 return FALSE;
3551 lpRect = (LPRECT)lParam;
3552 if (lpRect == NULL)
3553 return FALSE;
3554 if (btnPtr->fsState & TBSTATE_HIDDEN)
3555 return FALSE;
3557 lpRect->left = btnPtr->rect.left;
3558 lpRect->right = btnPtr->rect.right;
3559 lpRect->bottom = btnPtr->rect.bottom;
3560 lpRect->top = btnPtr->rect.top;
3562 return TRUE;
3566 static LRESULT
3567 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3569 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3570 LPSIZE lpSize = (LPSIZE)lParam;
3572 if (lpSize == NULL)
3573 return FALSE;
3575 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3576 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3578 TRACE("maximum size %d x %d\n",
3579 infoPtr->rcBound.right - infoPtr->rcBound.left,
3580 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3582 return TRUE;
3586 /* << TOOLBAR_GetObject >> */
3589 static LRESULT
3590 TOOLBAR_GetPadding (HWND hwnd)
3592 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3593 DWORD oldPad;
3595 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3596 return (LRESULT) oldPad;
3600 static LRESULT
3601 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3603 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3604 TBUTTON_INFO *btnPtr;
3605 LPRECT lpRect;
3606 INT nIndex;
3608 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3609 btnPtr = &infoPtr->buttons[nIndex];
3610 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3611 return FALSE;
3612 lpRect = (LPRECT)lParam;
3613 if (lpRect == NULL)
3614 return FALSE;
3616 lpRect->left = btnPtr->rect.left;
3617 lpRect->right = btnPtr->rect.right;
3618 lpRect->bottom = btnPtr->rect.bottom;
3619 lpRect->top = btnPtr->rect.top;
3621 return TRUE;
3625 static LRESULT
3626 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3628 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3630 return infoPtr->nRows;
3634 static LRESULT
3635 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3637 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3638 INT nIndex;
3640 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3641 if (nIndex == -1)
3642 return -1;
3644 return infoPtr->buttons[nIndex].fsState;
3648 static LRESULT
3649 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3651 return GetWindowLongW(hwnd, GWL_STYLE);
3655 static LRESULT
3656 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3658 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3660 return infoPtr->nMaxTextRows;
3664 static LRESULT
3665 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3667 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3669 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3670 TOOLBAR_TooltipCreateControl(infoPtr);
3671 return (LRESULT)infoPtr->hwndToolTip;
3675 static LRESULT
3676 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3678 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3680 TRACE("%s hwnd=%p\n",
3681 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3683 return infoPtr->bUnicode;
3687 static inline LRESULT
3688 TOOLBAR_GetVersion (HWND hwnd)
3690 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3691 return infoPtr->iVersion;
3695 static LRESULT
3696 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3698 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3699 TBUTTON_INFO *btnPtr;
3700 INT nIndex;
3702 TRACE("\n");
3704 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3705 if (nIndex == -1)
3706 return FALSE;
3708 btnPtr = &infoPtr->buttons[nIndex];
3709 if (LOWORD(lParam) == FALSE)
3710 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3711 else
3712 btnPtr->fsState |= TBSTATE_HIDDEN;
3714 TOOLBAR_LayoutToolbar (hwnd);
3716 InvalidateRect (hwnd, NULL, TRUE);
3718 return TRUE;
3722 static inline LRESULT
3723 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3725 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3729 static LRESULT
3730 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3732 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3733 TBUTTON_INFO *btnPtr;
3734 INT nIndex;
3735 DWORD oldState;
3737 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3738 if (nIndex == -1)
3739 return FALSE;
3741 btnPtr = &infoPtr->buttons[nIndex];
3742 oldState = btnPtr->fsState;
3743 if (LOWORD(lParam) == FALSE)
3744 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3745 else
3746 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3748 if(oldState != btnPtr->fsState)
3749 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3751 return TRUE;
3755 static LRESULT
3756 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3758 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3759 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3760 INT nIndex = (INT)wParam;
3762 if (lpTbb == NULL)
3763 return FALSE;
3765 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3767 if (nIndex == -1) {
3768 /* EPP: this seems to be an undocumented call (from my IE4)
3769 * I assume in that case that:
3770 * - index of insertion is at the end of existing buttons
3771 * I only see this happen with nIndex == -1, but it could have a special
3772 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3774 nIndex = infoPtr->nNumButtons;
3776 } else if (nIndex < 0)
3777 return FALSE;
3779 TRACE("inserting button index=%d\n", nIndex);
3780 if (nIndex > infoPtr->nNumButtons) {
3781 nIndex = infoPtr->nNumButtons;
3782 TRACE("adjust index=%d\n", nIndex);
3785 infoPtr->nNumButtons++;
3786 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO) * infoPtr->nNumButtons);
3787 memmove(&infoPtr->buttons[nIndex+1], &infoPtr->buttons[nIndex],
3788 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3790 /* insert new button */
3791 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3792 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3793 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3794 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3795 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3796 /* if passed string and not index, then add string */
3797 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3798 if (fUnicode)
3799 Str_SetPtrW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3800 else
3801 Str_SetPtrAtoW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3803 else
3804 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3806 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
3808 if (infoPtr->nNumStrings > 0)
3809 TOOLBAR_CalcToolbar(hwnd);
3810 else
3811 TOOLBAR_LayoutToolbar(hwnd);
3812 TOOLBAR_AutoSize (hwnd);
3814 InvalidateRect (hwnd, NULL, TRUE);
3816 return TRUE;
3819 /* << TOOLBAR_InsertMarkHitTest >> */
3822 static LRESULT
3823 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3825 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3826 INT nIndex;
3828 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3829 if (nIndex == -1)
3830 return -1;
3832 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3836 static LRESULT
3837 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3839 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3840 INT nIndex;
3842 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3843 if (nIndex == -1)
3844 return -1;
3846 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3850 static LRESULT
3851 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3853 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3854 INT nIndex;
3856 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3857 if (nIndex == -1)
3858 return -1;
3860 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3864 static LRESULT
3865 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3867 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3868 INT nIndex;
3870 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3871 if (nIndex == -1)
3872 return -1;
3874 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3878 static LRESULT
3879 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3881 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3882 INT nIndex;
3884 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3885 if (nIndex == -1)
3886 return -1;
3888 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3892 static LRESULT
3893 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3895 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3896 INT nIndex;
3898 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3899 if (nIndex == -1)
3900 return -1;
3902 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3906 static LRESULT
3907 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3909 TBADDBITMAP tbab;
3910 tbab.hInst = (HINSTANCE)lParam;
3911 tbab.nID = wParam;
3913 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", hwnd, tbab.hInst, tbab.nID);
3915 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3919 static LRESULT
3920 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3922 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3923 WCHAR wAccel = (WCHAR)wParam;
3924 UINT* pIDButton = (UINT*)lParam;
3925 WCHAR wszAccel[] = {'&',wAccel,0};
3926 int i;
3928 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3929 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3931 for (i = 0; i < infoPtr->nNumButtons; i++)
3933 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3934 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3935 !(btnPtr->fsState & TBSTATE_HIDDEN))
3937 int iLen = strlenW(wszAccel);
3938 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3940 if (!lpszStr)
3941 continue;
3943 while (*lpszStr)
3945 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3947 lpszStr += 2;
3948 continue;
3950 if (!strncmpiW(lpszStr, wszAccel, iLen))
3952 *pIDButton = btnPtr->idCommand;
3953 return TRUE;
3955 lpszStr++;
3959 return FALSE;
3963 static LRESULT
3964 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3966 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3967 INT nIndex;
3968 DWORD oldState;
3969 TBUTTON_INFO *btnPtr;
3971 TRACE("hwnd = %p, wParam = %ld, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3973 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3974 if (nIndex == -1)
3975 return FALSE;
3977 btnPtr = &infoPtr->buttons[nIndex];
3978 oldState = btnPtr->fsState;
3980 if (LOWORD(lParam))
3981 btnPtr->fsState |= TBSTATE_MARKED;
3982 else
3983 btnPtr->fsState &= ~TBSTATE_MARKED;
3985 if(oldState != btnPtr->fsState)
3986 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3988 return TRUE;
3992 /* fixes up an index of a button affected by a move */
3993 static inline void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
3995 if (bMoveUp)
3997 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
3998 (*pIndex)--;
3999 else if (*pIndex == nIndex)
4000 *pIndex = nMoveIndex;
4002 else
4004 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4005 (*pIndex)++;
4006 else if (*pIndex == nIndex)
4007 *pIndex = nMoveIndex;
4012 static LRESULT
4013 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4015 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4016 INT nIndex;
4017 INT nCount;
4018 INT nMoveIndex = (INT)lParam;
4019 TBUTTON_INFO button;
4021 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
4023 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4024 if ((nIndex == -1) || (nMoveIndex < 0))
4025 return FALSE;
4027 if (nMoveIndex > infoPtr->nNumButtons - 1)
4028 nMoveIndex = infoPtr->nNumButtons - 1;
4030 button = infoPtr->buttons[nIndex];
4032 /* move button right */
4033 if (nIndex < nMoveIndex)
4035 nCount = nMoveIndex - nIndex;
4036 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4037 infoPtr->buttons[nMoveIndex] = button;
4039 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4040 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4041 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4042 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4044 else if (nIndex > nMoveIndex) /* move button left */
4046 nCount = nIndex - nMoveIndex;
4047 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4048 infoPtr->buttons[nMoveIndex] = button;
4050 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4051 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4052 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4053 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4056 TOOLBAR_LayoutToolbar(hwnd);
4057 TOOLBAR_AutoSize(hwnd);
4058 InvalidateRect(hwnd, NULL, TRUE);
4060 return TRUE;
4064 static LRESULT
4065 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4067 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4068 TBUTTON_INFO *btnPtr;
4069 INT nIndex;
4070 DWORD oldState;
4072 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4073 if (nIndex == -1)
4074 return FALSE;
4076 btnPtr = &infoPtr->buttons[nIndex];
4077 oldState = btnPtr->fsState;
4078 if (LOWORD(lParam) == FALSE)
4079 btnPtr->fsState &= ~TBSTATE_PRESSED;
4080 else
4081 btnPtr->fsState |= TBSTATE_PRESSED;
4083 if(oldState != btnPtr->fsState)
4084 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4086 return TRUE;
4089 /* FIXME: there might still be some confusion her between number of buttons
4090 * and number of bitmaps */
4091 static LRESULT
4092 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4094 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4095 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4096 HBITMAP hBitmap;
4097 int i = 0, nOldButtons = 0, pos = 0;
4098 int nOldBitmaps, nNewBitmaps = 0;
4099 HIMAGELIST himlDef = 0;
4101 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4102 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4103 lpReplace->nButtons);
4105 if (lpReplace->hInstOld == HINST_COMMCTRL)
4107 FIXME("changing standard bitmaps not implemented\n");
4108 return FALSE;
4110 else if (lpReplace->hInstOld != 0)
4111 FIXME("resources not in the current module not implemented\n");
4113 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4114 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4115 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4116 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4117 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4119 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4120 nOldButtons = tbi->nButtons;
4121 tbi->nButtons = lpReplace->nButtons;
4122 tbi->hInst = lpReplace->hInstNew;
4123 tbi->nID = lpReplace->nIDNew;
4124 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4125 break;
4127 pos += tbi->nButtons;
4130 if (nOldButtons == 0)
4132 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4133 return FALSE;
4136 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4137 * bitmap
4139 if (lpReplace->hInstNew)
4140 hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4141 else
4142 hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
4144 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4145 nOldBitmaps = ImageList_GetImageCount(himlDef);
4147 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4149 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4150 ImageList_Remove(himlDef, i);
4152 if (hBitmap)
4154 ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
4155 nNewBitmaps = ImageList_GetImageCount(himlDef);
4156 DeleteObject(hBitmap);
4159 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4161 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4162 pos, nOldBitmaps, nNewBitmaps);
4164 InvalidateRect(hwnd, NULL, TRUE);
4165 return TRUE;
4169 /* helper for TOOLBAR_SaveRestoreW */
4170 static BOOL
4171 TOOLBAR_Save(const TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
4173 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4174 debugstr_w(lpSave->pszValueName));
4176 return FALSE;
4180 /* helper for TOOLBAR_Restore */
4181 static void
4182 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4184 INT i;
4186 for (i = 0; i < infoPtr->nNumButtons; i++)
4188 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4191 Free(infoPtr->buttons);
4192 infoPtr->buttons = NULL;
4193 infoPtr->nNumButtons = 0;
4197 /* helper for TOOLBAR_SaveRestoreW */
4198 static BOOL
4199 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
4201 LONG res;
4202 HKEY hkey = NULL;
4203 BOOL ret = FALSE;
4204 DWORD dwType;
4205 DWORD dwSize = 0;
4206 NMTBRESTORE nmtbr;
4208 /* restore toolbar information */
4209 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4210 debugstr_w(lpSave->pszValueName));
4212 memset(&nmtbr, 0, sizeof(nmtbr));
4214 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4215 KEY_QUERY_VALUE, &hkey);
4216 if (!res)
4217 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4218 NULL, &dwSize);
4219 if (!res && dwType != REG_BINARY)
4220 res = ERROR_FILE_NOT_FOUND;
4221 if (!res)
4223 nmtbr.pData = Alloc(dwSize);
4224 nmtbr.cbData = dwSize;
4225 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4227 if (!res)
4228 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4229 (LPBYTE)nmtbr.pData, &dwSize);
4230 if (!res)
4232 nmtbr.pCurrent = nmtbr.pData;
4233 nmtbr.iItem = -1;
4234 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4235 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4237 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4239 INT i;
4241 /* remove all existing buttons as this function is designed to
4242 * restore the toolbar to a previously saved state */
4243 TOOLBAR_DeleteAllButtons(infoPtr);
4245 for (i = 0; i < nmtbr.cButtons; i++)
4247 nmtbr.iItem = i;
4248 nmtbr.tbButton.iBitmap = -1;
4249 nmtbr.tbButton.fsState = 0;
4250 nmtbr.tbButton.fsStyle = 0;
4251 nmtbr.tbButton.idCommand = 0;
4252 if (*nmtbr.pCurrent == (DWORD)-1)
4254 /* separator */
4255 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4256 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4258 else if (*nmtbr.pCurrent == (DWORD)-2)
4259 /* hidden button */
4260 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4261 else
4262 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4264 nmtbr.pCurrent++;
4266 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4268 /* can't contain real string as we don't know whether
4269 * the client put an ANSI or Unicode string in there */
4270 if (HIWORD(nmtbr.tbButton.iString))
4271 nmtbr.tbButton.iString = 0;
4273 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4274 (LPARAM)&nmtbr.tbButton, TRUE);
4277 /* do legacy notifications */
4278 if (infoPtr->iVersion < 5)
4280 /* FIXME: send TBN_BEGINADJUST */
4281 FIXME("send TBN_GETBUTTONINFO for each button\n");
4282 /* FIXME: send TBN_ENDADJUST */
4285 /* remove all uninitialised buttons
4286 * note: loop backwards to avoid having to fixup i on a
4287 * delete */
4288 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4289 if (infoPtr->buttons[i].iBitmap == -1)
4290 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4292 /* only indicate success if at least one button survived */
4293 if (infoPtr->nNumButtons > 0) ret = TRUE;
4296 Free (nmtbr.pData);
4297 RegCloseKey(hkey);
4299 return ret;
4303 static LRESULT
4304 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, const TBSAVEPARAMSW *lpSave)
4306 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4308 if (lpSave == NULL) return 0;
4310 if (wParam)
4311 return TOOLBAR_Save(infoPtr, lpSave);
4312 else
4313 return TOOLBAR_Restore(infoPtr, lpSave);
4317 static LRESULT
4318 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, const TBSAVEPARAMSA *lpSave)
4320 LPWSTR pszValueName = 0, pszSubKey = 0;
4321 TBSAVEPARAMSW SaveW;
4322 LRESULT result = 0;
4323 int len;
4325 if (lpSave == NULL) return 0;
4327 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4328 pszSubKey = Alloc(len * sizeof(WCHAR));
4329 if (pszSubKey) goto exit;
4330 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4332 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4333 pszValueName = Alloc(len * sizeof(WCHAR));
4334 if (!pszValueName) goto exit;
4335 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4337 SaveW.pszValueName = pszValueName;
4338 SaveW.pszSubKey = pszSubKey;
4339 SaveW.hkr = lpSave->hkr;
4340 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4342 exit:
4343 Free (pszValueName);
4344 Free (pszSubKey);
4346 return result;
4350 static LRESULT
4351 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4353 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4354 BOOL bOldAnchor = infoPtr->bAnchor;
4356 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4358 infoPtr->bAnchor = (BOOL)wParam;
4360 /* Native does not remove the hot effect from an already hot button */
4362 return (LRESULT)bOldAnchor;
4366 static LRESULT
4367 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4369 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4370 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4371 short width = (short)LOWORD(lParam);
4372 short height = (short)HIWORD(lParam);
4374 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
4376 if (wParam != 0)
4377 FIXME("wParam is %ld. Perhaps image list index?\n", wParam);
4379 /* 0 width or height is changed to 1 */
4380 if (width == 0)
4381 width = 1;
4382 if (height == 0)
4383 height = 1;
4385 if (infoPtr->nNumButtons > 0)
4386 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4387 infoPtr->nNumButtons,
4388 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight, width, height);
4390 if (width < -1 || height < -1)
4392 /* Windows destroys the imagelist and seems to actually use negative
4393 * values to compute button sizes */
4394 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width, height);
4395 return FALSE;
4398 /* width or height of -1 means no change */
4399 if (width != -1)
4400 infoPtr->nBitmapWidth = width;
4401 if (height != -1)
4402 infoPtr->nBitmapHeight = height;
4404 if ((himlDef == infoPtr->himlInt) &&
4405 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4407 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4408 infoPtr->nBitmapHeight);
4411 TOOLBAR_CalcToolbar(hwnd);
4412 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4413 return TRUE;
4417 static LRESULT
4418 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4420 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4421 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4422 TBUTTON_INFO *btnPtr;
4423 INT nIndex;
4424 RECT oldBtnRect;
4426 if (lptbbi == NULL)
4427 return FALSE;
4428 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4429 return FALSE;
4431 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4432 lptbbi->dwMask & 0x80000000);
4433 if (nIndex == -1)
4434 return FALSE;
4436 btnPtr = &infoPtr->buttons[nIndex];
4437 if (lptbbi->dwMask & TBIF_COMMAND)
4438 btnPtr->idCommand = lptbbi->idCommand;
4439 if (lptbbi->dwMask & TBIF_IMAGE)
4440 btnPtr->iBitmap = lptbbi->iImage;
4441 if (lptbbi->dwMask & TBIF_LPARAM)
4442 btnPtr->dwData = lptbbi->lParam;
4443 if (lptbbi->dwMask & TBIF_SIZE)
4444 btnPtr->cx = lptbbi->cx;
4445 if (lptbbi->dwMask & TBIF_STATE)
4446 btnPtr->fsState = lptbbi->fsState;
4447 if (lptbbi->dwMask & TBIF_STYLE)
4448 btnPtr->fsStyle = lptbbi->fsStyle;
4450 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4451 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4452 /* iString is index, zero it to make Str_SetPtr succeed */
4453 btnPtr->iString=0;
4455 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4458 /* save the button rect to see if we need to redraw the whole toolbar */
4459 oldBtnRect = btnPtr->rect;
4460 TOOLBAR_CalcToolbar(hwnd);
4462 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4463 InvalidateRect(hwnd, NULL, TRUE);
4464 else
4465 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4467 return TRUE;
4471 static LRESULT
4472 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4474 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4475 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4476 TBUTTON_INFO *btnPtr;
4477 INT nIndex;
4478 RECT oldBtnRect;
4480 if (lptbbi == NULL)
4481 return FALSE;
4482 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4483 return FALSE;
4485 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4486 lptbbi->dwMask & 0x80000000);
4487 if (nIndex == -1)
4488 return FALSE;
4490 btnPtr = &infoPtr->buttons[nIndex];
4491 if (lptbbi->dwMask & TBIF_COMMAND)
4492 btnPtr->idCommand = lptbbi->idCommand;
4493 if (lptbbi->dwMask & TBIF_IMAGE)
4494 btnPtr->iBitmap = lptbbi->iImage;
4495 if (lptbbi->dwMask & TBIF_LPARAM)
4496 btnPtr->dwData = lptbbi->lParam;
4497 if (lptbbi->dwMask & TBIF_SIZE)
4498 btnPtr->cx = lptbbi->cx;
4499 if (lptbbi->dwMask & TBIF_STATE)
4500 btnPtr->fsState = lptbbi->fsState;
4501 if (lptbbi->dwMask & TBIF_STYLE)
4502 btnPtr->fsStyle = lptbbi->fsStyle;
4504 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4505 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4506 /* iString is index, zero it to make Str_SetPtr succeed */
4507 btnPtr->iString=0;
4508 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4511 /* save the button rect to see if we need to redraw the whole toolbar */
4512 oldBtnRect = btnPtr->rect;
4513 TOOLBAR_CalcToolbar(hwnd);
4515 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4516 InvalidateRect(hwnd, NULL, TRUE);
4517 else
4518 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4520 return TRUE;
4524 static LRESULT
4525 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4527 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4528 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4530 if ((cx < 0) || (cy < 0))
4532 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4533 return FALSE;
4536 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4538 /* The documentation claims you can only change the button size before
4539 * any button has been added. But this is wrong.
4540 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4541 * it to the toolbar, and it checks that the return value is nonzero - mjm
4542 * Further testing shows that we must actually perform the change too.
4545 * The documentation also does not mention that if 0 is supplied for
4546 * either size, the system changes it to the default of 24 wide and
4547 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4549 if (cx == 0) cx = 24;
4550 if (cy == 0) cx = 22;
4552 cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
4553 cy = max(cy, infoPtr->szPadding.cy + infoPtr->nBitmapHeight);
4555 infoPtr->nButtonWidth = cx;
4556 infoPtr->nButtonHeight = cy;
4558 infoPtr->iTopMargin = default_top_margin(infoPtr);
4559 TOOLBAR_LayoutToolbar(hwnd);
4560 return TRUE;
4564 static LRESULT
4565 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4567 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4569 /* if setting to current values, ignore */
4570 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4571 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4572 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4573 infoPtr->cxMin, infoPtr->cxMax);
4574 return TRUE;
4577 /* save new values */
4578 infoPtr->cxMin = (short)LOWORD(lParam);
4579 infoPtr->cxMax = (short)HIWORD(lParam);
4581 /* otherwise we need to recalc the toolbar and in some cases
4582 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4583 which doesn't actually draw - GA). */
4584 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4585 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4587 TOOLBAR_CalcToolbar (hwnd);
4589 InvalidateRect (hwnd, NULL, TRUE);
4591 return TRUE;
4595 static LRESULT
4596 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4598 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4599 INT nIndex = (INT)wParam;
4601 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4602 return FALSE;
4604 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4606 if (infoPtr->hwndToolTip) {
4608 FIXME("change tool tip!\n");
4612 return TRUE;
4616 static LRESULT
4617 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4619 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4620 HIMAGELIST himl = (HIMAGELIST)lParam;
4621 HIMAGELIST himlTemp;
4622 INT id = 0;
4624 if (infoPtr->iVersion >= 5)
4625 id = wParam;
4627 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4628 &infoPtr->cimlDis, himl, id);
4630 /* FIXME: redraw ? */
4632 return (LRESULT)himlTemp;
4636 static LRESULT
4637 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4639 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4640 DWORD dwTemp;
4642 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4644 dwTemp = infoPtr->dwDTFlags;
4645 infoPtr->dwDTFlags =
4646 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4648 return (LRESULT)dwTemp;
4651 /* This function differs a bit from what MSDN says it does:
4652 * 1. lParam contains extended style flags to OR with current style
4653 * (MSDN isn't clear on the OR bit)
4654 * 2. wParam appears to contain extended style flags to be reset
4655 * (MSDN says that this parameter is reserved)
4657 static LRESULT
4658 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4660 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4661 DWORD dwTemp;
4663 dwTemp = infoPtr->dwExStyle;
4664 infoPtr->dwExStyle &= ~wParam;
4665 infoPtr->dwExStyle |= (DWORD)lParam;
4667 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4669 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4670 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4671 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4673 TOOLBAR_CalcToolbar (hwnd);
4675 TOOLBAR_AutoSize(hwnd);
4677 InvalidateRect(hwnd, NULL, TRUE);
4679 return (LRESULT)dwTemp;
4683 static LRESULT
4684 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4686 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4687 HIMAGELIST himlTemp;
4688 HIMAGELIST himl = (HIMAGELIST)lParam;
4689 INT id = 0;
4691 if (infoPtr->iVersion >= 5)
4692 id = wParam;
4694 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4696 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4697 &infoPtr->cimlHot, himl, id);
4699 /* FIXME: redraw ? */
4701 return (LRESULT)himlTemp;
4705 /* Makes previous hot button no longer hot, makes the specified
4706 * button hot and sends appropriate notifications. dwReason is one or
4707 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4708 * NOTE 1: this function does not validate nHit
4709 * NOTE 2: the name of this function is completely made up and
4710 * not based on any documentation from Microsoft. */
4711 static void
4712 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4714 if (infoPtr->nHotItem != nHit)
4716 NMTBHOTITEM nmhotitem;
4717 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4719 nmhotitem.dwFlags = dwReason;
4720 if(infoPtr->nHotItem >= 0)
4722 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4723 nmhotitem.idOld = oldBtnPtr->idCommand;
4725 else
4727 nmhotitem.dwFlags |= HICF_ENTERING;
4728 nmhotitem.idOld = 0;
4731 if (nHit >= 0)
4733 btnPtr = &infoPtr->buttons[nHit];
4734 nmhotitem.idNew = btnPtr->idCommand;
4736 else
4738 nmhotitem.dwFlags |= HICF_LEAVING;
4739 nmhotitem.idNew = 0;
4742 /* now change the hot and invalidate the old and new buttons - if the
4743 * parent agrees */
4744 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4746 if (oldBtnPtr) {
4747 oldBtnPtr->bHot = FALSE;
4748 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4750 /* setting disabled buttons as hot fails even if the notify contains the button id */
4751 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4752 btnPtr->bHot = TRUE;
4753 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4754 infoPtr->nHotItem = nHit;
4756 else
4757 infoPtr->nHotItem = -1;
4762 static LRESULT
4763 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4765 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4766 INT nOldHotItem = infoPtr->nHotItem;
4768 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4770 if ((INT)wParam >= infoPtr->nNumButtons)
4771 return infoPtr->nHotItem;
4773 if ((INT)wParam < 0)
4774 wParam = -1;
4776 /* NOTE: an application can still remove the hot item even if anchor
4777 * highlighting is enabled */
4779 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4781 if (nOldHotItem < 0)
4782 return -1;
4784 return (LRESULT)nOldHotItem;
4788 static LRESULT
4789 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4791 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4792 HIMAGELIST himlTemp;
4793 HIMAGELIST himl = (HIMAGELIST)lParam;
4794 INT oldButtonWidth = infoPtr->nButtonWidth;
4795 INT i, id = 0;
4797 if (infoPtr->iVersion >= 5)
4798 id = wParam;
4800 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4801 &infoPtr->cimlDef, himl, id);
4803 infoPtr->nNumBitmaps = 0;
4804 for (i = 0; i < infoPtr->cimlDef; i++)
4805 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4807 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4808 &infoPtr->nBitmapHeight))
4810 infoPtr->nBitmapWidth = 1;
4811 infoPtr->nBitmapHeight = 1;
4813 TOOLBAR_CalcToolbar(hwnd);
4814 if (infoPtr->nButtonWidth < oldButtonWidth)
4815 TOOLBAR_SetButtonSize(hwnd, 0, MAKELONG(oldButtonWidth, infoPtr->nButtonHeight));
4817 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4818 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4819 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4821 InvalidateRect(hwnd, NULL, TRUE);
4823 return (LRESULT)himlTemp;
4827 static LRESULT
4828 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4830 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4832 infoPtr->nIndent = (INT)wParam;
4834 TRACE("\n");
4836 /* process only on indent changing */
4837 if(infoPtr->nIndent != (INT)wParam)
4839 infoPtr->nIndent = (INT)wParam;
4840 TOOLBAR_CalcToolbar (hwnd);
4841 InvalidateRect(hwnd, NULL, FALSE);
4844 return TRUE;
4848 static LRESULT
4849 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4851 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4852 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4854 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4856 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4858 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4859 return 0;
4862 if ((lptbim->iButton == -1) ||
4863 ((lptbim->iButton < infoPtr->nNumButtons) &&
4864 (lptbim->iButton >= 0)))
4866 infoPtr->tbim = *lptbim;
4867 /* FIXME: don't need to update entire toolbar */
4868 InvalidateRect(hwnd, NULL, TRUE);
4870 else
4871 ERR("Invalid button index %d\n", lptbim->iButton);
4873 return 0;
4877 static LRESULT
4878 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4880 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4882 infoPtr->clrInsertMark = (COLORREF)lParam;
4884 /* FIXME: don't need to update entire toolbar */
4885 InvalidateRect(hwnd, NULL, TRUE);
4887 return 0;
4891 static LRESULT
4892 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4894 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4896 infoPtr->nMaxTextRows = (INT)wParam;
4898 TOOLBAR_CalcToolbar(hwnd);
4899 return TRUE;
4903 /* MSDN gives slightly wrong info on padding.
4904 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4905 * 2. It is not used to create a blank area between the edge of the button
4906 * and the text or image if TBSTYLE_LIST is set. It is used to control
4907 * the gap between the image and text.
4908 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4909 * to control the bottom and right borders [with the border being
4910 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4911 * is shared evenly on both sides of the button.
4912 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4914 static LRESULT
4915 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4917 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4918 DWORD oldPad;
4920 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4921 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4922 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4923 TRACE("cx=%d, cy=%d\n",
4924 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4925 return (LRESULT) oldPad;
4929 static LRESULT
4930 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4932 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4933 HWND hwndOldNotify;
4935 TRACE("\n");
4937 hwndOldNotify = infoPtr->hwndNotify;
4938 infoPtr->hwndNotify = (HWND)wParam;
4940 return (LRESULT)hwndOldNotify;
4944 static LRESULT
4945 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4947 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4948 LPRECT lprc = (LPRECT)lParam;
4949 int rows = LOWORD(wParam);
4950 BOOL bLarger = HIWORD(wParam);
4952 TRACE("\n");
4954 TRACE("Setting rows to %d (%d)\n", rows, bLarger);
4956 if(infoPtr->nRows != rows)
4958 TBUTTON_INFO *btnPtr = infoPtr->buttons;
4959 int curColumn = 0; /* Current column */
4960 int curRow = 0; /* Current row */
4961 int hidden = 0; /* Number of hidden buttons */
4962 int seps = 0; /* Number of separators */
4963 int idealWrap = 0; /* Ideal wrap point */
4964 int i;
4965 BOOL wrap;
4968 Calculate new size and wrap points - Under windows, setrows will
4969 change the dimensions if needed to show the number of requested
4970 rows (if CCS_NORESIZE is set), or will take up the whole window
4971 (if no CCS_NORESIZE).
4973 Basic algorithm - If N buttons, and y rows requested, each row
4974 contains N/y buttons.
4976 FIXME: Handling of separators not obvious from testing results
4977 FIXME: Take width of window into account?
4980 /* Loop through the buttons one by one counting key items */
4981 for (i = 0; i < infoPtr->nNumButtons; i++ )
4983 btnPtr[i].fsState &= ~TBSTATE_WRAP;
4984 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
4985 hidden++;
4986 else if (btnPtr[i].fsStyle & BTNS_SEP)
4987 seps++;
4990 /* FIXME: Separators make this quite complex */
4991 if (seps) FIXME("Separators unhandled\n");
4993 /* Round up so more per line, i.e., less rows */
4994 idealWrap = (infoPtr->nNumButtons - hidden + (rows-1)) / rows;
4996 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4997 achieve the requested number of rows. */
4998 if (bLarger && idealWrap > 1)
5000 int resRows = (infoPtr->nNumButtons + (idealWrap-1)) / idealWrap;
5001 int moreRows = (infoPtr->nNumButtons + (idealWrap-2)) / (idealWrap-1);
5003 if (resRows < rows && moreRows > rows)
5005 idealWrap--;
5006 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap);
5010 curColumn = curRow = 0;
5011 wrap = FALSE;
5012 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap,
5013 infoPtr->nNumButtons, hidden, rows);
5015 for (i = 0; i < infoPtr->nNumButtons; i++ )
5017 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
5018 continue;
5020 /* Step on, wrap if necessary or flag next to wrap */
5021 if (!wrap) {
5022 curColumn++;
5023 } else {
5024 wrap = FALSE;
5025 curColumn = 1;
5026 curRow++;
5029 if (curColumn > (idealWrap-1)) {
5030 wrap = TRUE;
5031 btnPtr[i].fsState |= TBSTATE_WRAP;
5035 TRACE("Result - %d rows\n", curRow + 1);
5037 /* recalculate toolbar */
5038 TOOLBAR_CalcToolbar (hwnd);
5040 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
5041 if NORESIZE is NOT set, then the toolbar will always be resized to
5042 take up the whole window. With it set, sizing needs to be manual. */
5043 if (infoPtr->dwStyle & CCS_NORESIZE) {
5044 SetWindowPos(hwnd, NULL, 0, 0,
5045 infoPtr->rcBound.right - infoPtr->rcBound.left,
5046 infoPtr->rcBound.bottom - infoPtr->rcBound.top,
5047 SWP_NOMOVE);
5050 /* repaint toolbar */
5051 InvalidateRect(hwnd, NULL, TRUE);
5054 /* return bounding rectangle */
5055 if (lprc) {
5056 lprc->left = infoPtr->rcBound.left;
5057 lprc->right = infoPtr->rcBound.right;
5058 lprc->top = infoPtr->rcBound.top;
5059 lprc->bottom = infoPtr->rcBound.bottom;
5062 return 0;
5066 static LRESULT
5067 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5069 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5070 TBUTTON_INFO *btnPtr;
5071 INT nIndex;
5073 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5074 if (nIndex == -1)
5075 return FALSE;
5077 btnPtr = &infoPtr->buttons[nIndex];
5079 /* if hidden state has changed the invalidate entire window and recalc */
5080 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5081 btnPtr->fsState = LOWORD(lParam);
5082 TOOLBAR_CalcToolbar (hwnd);
5083 InvalidateRect(hwnd, 0, TRUE);
5084 return TRUE;
5087 /* process state changing if current state doesn't match new state */
5088 if(btnPtr->fsState != LOWORD(lParam))
5090 btnPtr->fsState = LOWORD(lParam);
5091 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5094 return TRUE;
5098 static LRESULT
5099 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5101 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5103 return TRUE;
5107 static inline LRESULT
5108 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5110 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5112 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5114 infoPtr->hwndToolTip = (HWND)wParam;
5115 return 0;
5119 static LRESULT
5120 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5122 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5123 BOOL bTemp;
5125 TRACE("%s hwnd=%p\n",
5126 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5128 bTemp = infoPtr->bUnicode;
5129 infoPtr->bUnicode = (BOOL)wParam;
5131 return bTemp;
5135 static LRESULT
5136 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5138 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5140 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5141 comctl32_color.clrBtnHighlight :
5142 infoPtr->clrBtnHighlight;
5143 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5144 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5145 return 1;
5149 static LRESULT
5150 TOOLBAR_SetColorScheme (HWND hwnd, const COLORSCHEME *lParam)
5152 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5154 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5155 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5156 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5158 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5159 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5160 InvalidateRect(hwnd, NULL, TRUE);
5161 return 0;
5165 static LRESULT
5166 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5168 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5169 INT iOldVersion = infoPtr->iVersion;
5171 infoPtr->iVersion = iVersion;
5173 if (infoPtr->iVersion >= 5)
5174 TOOLBAR_SetUnicodeFormat(hwnd, TRUE, 0);
5176 return iOldVersion;
5180 static LRESULT
5181 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5183 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5184 WORD iString = HIWORD(wParam);
5185 WORD buffersize = LOWORD(wParam);
5186 LPSTR str = (LPSTR)lParam;
5187 LRESULT ret = -1;
5189 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5191 if (iString < infoPtr->nNumStrings)
5193 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5194 ret--;
5196 TRACE("returning %s\n", debugstr_a(str));
5198 else
5199 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5201 return ret;
5205 static LRESULT
5206 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5208 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5209 WORD iString = HIWORD(wParam);
5210 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5211 LPWSTR str = (LPWSTR)lParam;
5212 LRESULT ret = -1;
5214 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5216 if (iString < infoPtr->nNumStrings)
5218 len = min(len, strlenW(infoPtr->strings[iString]));
5219 ret = (len+1)*sizeof(WCHAR);
5220 if (str)
5222 memcpy(str, infoPtr->strings[iString], ret);
5223 str[len] = '\0';
5225 ret = len;
5227 TRACE("returning %s\n", debugstr_w(str));
5229 else
5230 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5232 return ret;
5235 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5236 * is the maximum size of the toolbar? */
5237 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5239 SIZE * pSize = (SIZE*)lParam;
5240 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5241 return 0;
5245 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5246 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5247 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5248 * sends). */
5249 static LRESULT
5250 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5252 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5253 INT nOldHotItem = infoPtr->nHotItem;
5255 TRACE("old item=%d, new item=%d, flags=%08x\n",
5256 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5258 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5259 wParam = -1;
5261 /* NOTE: an application can still remove the hot item even if anchor
5262 * highlighting is enabled */
5264 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5266 GetFocus();
5268 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5271 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5272 * which controls the amount of spacing between the image and the text
5273 * of buttons for TBSTYLE_LIST toolbars. */
5274 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5276 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5278 TRACE("hwnd=%p iListGap=%ld\n", hwnd, wParam);
5280 if (lParam != 0)
5281 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5283 infoPtr->iListGap = (INT)wParam;
5285 InvalidateRect(hwnd, NULL, TRUE);
5287 return 0;
5290 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5291 * of image lists associated with the various states. */
5292 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5294 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5296 TRACE("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5298 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5301 static LRESULT
5302 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5304 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5305 LPSIZE lpsize = (LPSIZE)lParam;
5307 if (lpsize == NULL)
5308 return FALSE;
5311 * Testing shows the following:
5312 * wParam = 0 adjust cx value
5313 * = 1 set cy value to max size.
5314 * lParam pointer to SIZE structure
5317 TRACE("[0463] wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5318 wParam, lParam, lpsize->cx, lpsize->cy);
5320 switch(wParam) {
5321 case 0:
5322 if (lpsize->cx == -1) {
5323 /* **** this is wrong, native measures each button and sets it */
5324 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5326 else if(HIWORD(lpsize->cx)) {
5327 RECT rc;
5328 HWND hwndParent = GetParent(hwnd);
5330 GetWindowRect(hwnd, &rc);
5331 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5332 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc));
5333 lpsize->cx = max(rc.right-rc.left,
5334 infoPtr->rcBound.right - infoPtr->rcBound.left);
5336 else {
5337 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5339 break;
5340 case 1:
5341 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5342 break;
5343 default:
5344 ERR("Unknown wParam %ld for Toolbar message [0463]. Please report\n",
5345 wParam);
5346 return 0;
5348 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5349 lpsize->cx, lpsize->cy);
5350 return 1;
5353 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5355 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5357 InvalidateRect(hwnd, NULL, TRUE);
5358 return 1;
5362 static LRESULT
5363 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5365 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5366 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5367 LOGFONTW logFont;
5369 TRACE("hwnd = %p\n", hwnd);
5371 /* initialize info structure */
5372 infoPtr->nButtonWidth = 23;
5373 infoPtr->nButtonHeight = 22;
5374 infoPtr->nBitmapHeight = 16;
5375 infoPtr->nBitmapWidth = 16;
5377 infoPtr->nMaxTextRows = 1;
5378 infoPtr->cxMin = -1;
5379 infoPtr->cxMax = -1;
5380 infoPtr->nNumBitmaps = 0;
5381 infoPtr->nNumStrings = 0;
5383 infoPtr->bCaptured = FALSE;
5384 infoPtr->nButtonDown = -1;
5385 infoPtr->nButtonDrag = -1;
5386 infoPtr->nOldHit = -1;
5387 infoPtr->nHotItem = -1;
5388 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5389 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5390 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5391 infoPtr->bDragOutSent = FALSE;
5392 infoPtr->iVersion = 0;
5393 infoPtr->hwndSelf = hwnd;
5394 infoPtr->bDoRedraw = TRUE;
5395 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5396 infoPtr->clrBtnShadow = CLR_DEFAULT;
5397 infoPtr->szPadding.cx = DEFPAD_CX;
5398 infoPtr->szPadding.cy = DEFPAD_CY;
5399 infoPtr->iListGap = DEFLISTGAP;
5400 infoPtr->iTopMargin = default_top_margin(infoPtr);
5401 infoPtr->dwStyle = dwStyle;
5402 infoPtr->tbim.iButton = -1;
5403 GetClientRect(hwnd, &infoPtr->client_rect);
5404 infoPtr->bUnicode = infoPtr->hwndNotify &&
5405 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5406 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5408 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5409 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5411 OpenThemeData (hwnd, themeClass);
5413 TOOLBAR_CheckStyle (hwnd, dwStyle);
5415 return 0;
5419 static LRESULT
5420 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5422 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5424 /* delete tooltip control */
5425 if (infoPtr->hwndToolTip)
5426 DestroyWindow (infoPtr->hwndToolTip);
5428 /* delete temporary buffer for tooltip text */
5429 Free (infoPtr->pszTooltipText);
5430 Free (infoPtr->bitmaps); /* bitmaps list */
5432 /* delete button data */
5433 Free (infoPtr->buttons);
5435 /* delete strings */
5436 if (infoPtr->strings) {
5437 INT i;
5438 for (i = 0; i < infoPtr->nNumStrings; i++)
5439 Free (infoPtr->strings[i]);
5441 Free (infoPtr->strings);
5444 /* destroy internal image list */
5445 if (infoPtr->himlInt)
5446 ImageList_Destroy (infoPtr->himlInt);
5448 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5449 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5450 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5452 /* delete default font */
5453 DeleteObject (infoPtr->hDefaultFont);
5455 CloseThemeData (GetWindowTheme (hwnd));
5457 /* free toolbar info data */
5458 Free (infoPtr);
5459 SetWindowLongPtrW (hwnd, 0, 0);
5461 return 0;
5465 static LRESULT
5466 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5468 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5469 NMTBCUSTOMDRAW tbcd;
5470 INT ret = FALSE;
5471 DWORD ntfret;
5472 HTHEME theme = GetWindowTheme (hwnd);
5473 DWORD dwEraseCustDraw = 0;
5475 /* the app has told us not to redraw the toolbar */
5476 if (!infoPtr->bDoRedraw)
5477 return FALSE;
5479 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5480 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5481 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5482 tbcd.nmcd.hdc = (HDC)wParam;
5483 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5484 dwEraseCustDraw = ntfret & 0xffff;
5486 /* FIXME: in general the return flags *can* be or'ed together */
5487 switch (dwEraseCustDraw)
5489 case CDRF_DODEFAULT:
5490 break;
5491 case CDRF_SKIPDEFAULT:
5492 return TRUE;
5493 default:
5494 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5495 hwnd, ntfret);
5499 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5500 * to my parent for processing.
5502 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5503 POINT pt, ptorig;
5504 HDC hdc = (HDC)wParam;
5505 HWND parent;
5507 pt.x = 0;
5508 pt.y = 0;
5509 parent = GetParent(hwnd);
5510 MapWindowPoints(hwnd, parent, &pt, 1);
5511 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5512 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5513 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5515 if (!ret)
5516 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5518 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5519 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5520 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5521 tbcd.nmcd.hdc = (HDC)wParam;
5522 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5523 dwEraseCustDraw = ntfret & 0xffff;
5524 switch (dwEraseCustDraw)
5526 case CDRF_DODEFAULT:
5527 break;
5528 case CDRF_SKIPDEFAULT:
5529 return TRUE;
5530 default:
5531 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5532 hwnd, ntfret);
5535 return ret;
5539 static LRESULT
5540 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5542 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5544 return (LRESULT)infoPtr->hFont;
5548 static void
5549 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5551 INT i;
5552 INT nNewHotItem = infoPtr->nHotItem;
5554 for (i = 0; i < infoPtr->nNumButtons; i++)
5556 /* did we wrap? */
5557 if ((nNewHotItem + iDirection < 0) ||
5558 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5560 NMTBWRAPHOTITEM nmtbwhi;
5561 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5562 nmtbwhi.iDirection = iDirection;
5563 nmtbwhi.dwReason = dwReason;
5565 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5566 return;
5569 nNewHotItem += iDirection;
5570 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5572 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5573 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5575 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5576 break;
5581 static LRESULT
5582 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5584 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5585 NMKEY nmkey;
5587 nmkey.nVKey = (UINT)wParam;
5588 nmkey.uFlags = HIWORD(lParam);
5590 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5591 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5593 switch ((UINT)wParam)
5595 case VK_LEFT:
5596 case VK_UP:
5597 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5598 break;
5599 case VK_RIGHT:
5600 case VK_DOWN:
5601 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5602 break;
5603 case VK_SPACE:
5604 case VK_RETURN:
5605 if ((infoPtr->nHotItem >= 0) &&
5606 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5608 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5609 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5610 (LPARAM)hwnd);
5612 break;
5615 return 0;
5619 static LRESULT
5620 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5622 POINT pt;
5623 INT nHit;
5625 pt.x = (short)LOWORD(lParam);
5626 pt.y = (short)HIWORD(lParam);
5627 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5629 if (nHit >= 0)
5630 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5631 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5632 TOOLBAR_Customize (hwnd);
5634 return 0;
5638 static LRESULT
5639 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5641 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5642 TBUTTON_INFO *btnPtr;
5643 POINT pt;
5644 INT nHit;
5645 NMTOOLBARA nmtb;
5646 NMMOUSE nmmouse;
5647 BOOL bDragKeyPressed;
5649 TRACE("\n");
5651 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5652 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5653 else
5654 bDragKeyPressed = (wParam & MK_SHIFT);
5656 if (infoPtr->hwndToolTip)
5657 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5658 WM_LBUTTONDOWN, wParam, lParam);
5660 pt.x = (short)LOWORD(lParam);
5661 pt.y = (short)HIWORD(lParam);
5662 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5664 btnPtr = &infoPtr->buttons[nHit];
5666 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5668 infoPtr->nButtonDrag = nHit;
5669 SetCapture (hwnd);
5671 /* If drag cursor has not been loaded, load it.
5672 * Note: it doesn't need to be freed */
5673 if (!hCursorDrag)
5674 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5675 SetCursor(hCursorDrag);
5677 else if (nHit >= 0)
5679 RECT arrowRect;
5680 infoPtr->nOldHit = nHit;
5682 CopyRect(&arrowRect, &btnPtr->rect);
5683 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5685 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5686 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5687 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5688 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5689 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5690 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5692 LRESULT res;
5694 /* draw in pressed state */
5695 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5696 btnPtr->fsState |= TBSTATE_PRESSED;
5697 else
5698 btnPtr->bDropDownPressed = TRUE;
5699 RedrawWindow(hwnd,&btnPtr->rect,0,
5700 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5702 memset(&nmtb, 0, sizeof(nmtb));
5703 nmtb.iItem = btnPtr->idCommand;
5704 nmtb.rcButton = btnPtr->rect;
5705 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5706 TBN_DROPDOWN);
5707 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5709 if (res != TBDDRET_TREATPRESSED)
5711 MSG msg;
5713 /* redraw button in unpressed state */
5714 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5715 btnPtr->fsState &= ~TBSTATE_PRESSED;
5716 else
5717 btnPtr->bDropDownPressed = FALSE;
5718 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5720 /* find and set hot item
5721 * NOTE: native doesn't do this, but that is a bug */
5722 GetCursorPos(&pt);
5723 ScreenToClient(hwnd, &pt);
5724 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5725 if (!infoPtr->bAnchor || (nHit >= 0))
5726 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5728 /* remove any left mouse button down or double-click messages
5729 * so that we can get a toggle effect on the button */
5730 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5731 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5734 return 0;
5736 /* otherwise drop through and process as pushed */
5738 infoPtr->bCaptured = TRUE;
5739 infoPtr->nButtonDown = nHit;
5740 infoPtr->bDragOutSent = FALSE;
5742 btnPtr->fsState |= TBSTATE_PRESSED;
5744 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5746 if (btnPtr->fsState & TBSTATE_ENABLED)
5747 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5748 UpdateWindow(hwnd);
5749 SetCapture (hwnd);
5752 if (nHit >=0)
5754 memset(&nmtb, 0, sizeof(nmtb));
5755 nmtb.iItem = btnPtr->idCommand;
5756 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5759 nmmouse.dwHitInfo = nHit;
5761 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5762 if (nHit < 0)
5763 nmmouse.dwItemSpec = -1;
5764 else
5766 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5767 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5770 ClientToScreen(hwnd, &pt);
5771 nmmouse.pt = pt;
5773 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5774 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5776 return 0;
5779 static LRESULT
5780 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5782 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5783 TBUTTON_INFO *btnPtr;
5784 POINT pt;
5785 INT nHit;
5786 INT nOldIndex = -1;
5787 NMHDR hdr;
5788 NMMOUSE nmmouse;
5789 NMTOOLBARA nmtb;
5791 if (infoPtr->hwndToolTip)
5792 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5793 WM_LBUTTONUP, wParam, lParam);
5795 pt.x = (short)LOWORD(lParam);
5796 pt.y = (short)HIWORD(lParam);
5797 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5799 if (!infoPtr->bAnchor || (nHit >= 0))
5800 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5802 if (infoPtr->nButtonDrag >= 0) {
5803 RECT rcClient;
5804 NMHDR hdr;
5806 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5807 ReleaseCapture();
5808 /* reset cursor */
5809 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5811 GetClientRect(hwnd, &rcClient);
5812 if (PtInRect(&rcClient, pt))
5814 INT nButton = -1;
5815 if (nHit >= 0)
5816 nButton = nHit;
5817 else if (nHit < -1)
5818 nButton = -nHit;
5819 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5820 nButton = -nHit;
5822 if (nButton == infoPtr->nButtonDrag)
5824 /* if the button is moved sightly left and we have a
5825 * separator there then remove it */
5826 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5828 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5829 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5831 else /* else insert a separator before the dragged button */
5833 TBBUTTON tbb;
5834 memset(&tbb, 0, sizeof(tbb));
5835 tbb.fsStyle = BTNS_SEP;
5836 tbb.iString = -1;
5837 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5840 else
5842 if (nButton == -1)
5844 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5845 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5846 else
5847 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5849 else
5850 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5853 else
5855 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5856 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5859 /* button under cursor changed so need to re-set hot item */
5860 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5861 infoPtr->nButtonDrag = -1;
5863 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5865 else if (infoPtr->nButtonDown >= 0) {
5866 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5867 btnPtr->fsState &= ~TBSTATE_PRESSED;
5869 if (btnPtr->fsStyle & BTNS_CHECK) {
5870 if (btnPtr->fsStyle & BTNS_GROUP) {
5871 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5872 nHit);
5873 if ((nOldIndex != nHit) &&
5874 (nOldIndex != -1))
5875 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5876 btnPtr->fsState |= TBSTATE_CHECKED;
5878 else {
5879 if (btnPtr->fsState & TBSTATE_CHECKED)
5880 btnPtr->fsState &= ~TBSTATE_CHECKED;
5881 else
5882 btnPtr->fsState |= TBSTATE_CHECKED;
5886 if (nOldIndex != -1)
5887 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5890 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5891 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5892 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5894 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5895 ReleaseCapture ();
5896 infoPtr->nButtonDown = -1;
5898 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5899 TOOLBAR_SendNotify (&hdr, infoPtr,
5900 NM_RELEASEDCAPTURE);
5902 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5903 * TBN_BEGINDRAG
5905 memset(&nmtb, 0, sizeof(nmtb));
5906 nmtb.iItem = btnPtr->idCommand;
5907 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5908 TBN_ENDDRAG);
5910 if (btnPtr->fsState & TBSTATE_ENABLED)
5912 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5913 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5915 /* In case we have just been destroyed... */
5916 if(!IsWindow(hwnd))
5917 return 0;
5921 /* !!! Undocumented - toolbar at 4.71 level and above sends
5922 * NM_CLICK with the NMMOUSE structure. */
5923 nmmouse.dwHitInfo = nHit;
5925 if (nHit < 0)
5926 nmmouse.dwItemSpec = -1;
5927 else
5929 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5930 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5933 ClientToScreen(hwnd, &pt);
5934 nmmouse.pt = pt;
5936 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5937 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5939 return 0;
5942 static LRESULT
5943 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5945 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5946 INT nHit;
5947 NMMOUSE nmmouse;
5948 POINT pt;
5950 pt.x = (short)LOWORD(lParam);
5951 pt.y = (short)HIWORD(lParam);
5953 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5954 nmmouse.dwHitInfo = nHit;
5956 if (nHit < 0) {
5957 nmmouse.dwItemSpec = -1;
5958 } else {
5959 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5960 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5963 ClientToScreen(hwnd, &pt);
5964 nmmouse.pt = pt;
5966 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5967 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5969 return 0;
5972 static LRESULT
5973 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5975 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5976 NMHDR nmhdr;
5978 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5979 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5981 return 0;
5984 static LRESULT
5985 TOOLBAR_CaptureChanged(HWND hwnd)
5987 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5988 TBUTTON_INFO *btnPtr;
5990 infoPtr->bCaptured = FALSE;
5992 if (infoPtr->nButtonDown >= 0)
5994 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5995 btnPtr->fsState &= ~TBSTATE_PRESSED;
5997 infoPtr->nOldHit = -1;
5999 if (btnPtr->fsState & TBSTATE_ENABLED)
6000 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6002 return 0;
6005 static LRESULT
6006 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6008 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6010 /* don't remove hot effects when in anchor highlighting mode or when a
6011 * drop-down button is pressed */
6012 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
6014 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
6015 if (!hotBtnPtr->bDropDownPressed)
6016 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6019 if (infoPtr->nOldHit < 0)
6020 return TRUE;
6022 /* If the last button we were over is depressed then make it not */
6023 /* depressed and redraw it */
6024 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6026 TBUTTON_INFO *btnPtr;
6027 RECT rc1;
6029 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6031 btnPtr->fsState &= ~TBSTATE_PRESSED;
6033 rc1 = btnPtr->rect;
6034 InflateRect (&rc1, 1, 1);
6035 InvalidateRect (hwnd, &rc1, TRUE);
6038 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6040 NMTOOLBARW nmt;
6041 ZeroMemory(&nmt, sizeof(nmt));
6042 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6043 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6044 infoPtr->bDragOutSent = TRUE;
6047 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6049 return TRUE;
6052 static LRESULT
6053 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6055 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6056 POINT pt;
6057 TRACKMOUSEEVENT trackinfo;
6058 INT nHit;
6059 TBUTTON_INFO *btnPtr;
6061 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6062 TOOLBAR_TooltipCreateControl(infoPtr);
6064 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6065 /* fill in the TRACKMOUSEEVENT struct */
6066 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6067 trackinfo.dwFlags = TME_QUERY;
6069 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6070 _TrackMouseEvent(&trackinfo);
6072 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6073 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6074 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6075 trackinfo.hwndTrack = hwnd;
6077 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6078 /* and can properly deactivate the hot toolbar button */
6079 _TrackMouseEvent(&trackinfo);
6083 if (infoPtr->hwndToolTip)
6084 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6085 WM_MOUSEMOVE, wParam, lParam);
6087 pt.x = (short)LOWORD(lParam);
6088 pt.y = (short)HIWORD(lParam);
6090 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6092 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6093 && (!infoPtr->bAnchor || (nHit >= 0)))
6094 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6096 if (infoPtr->nOldHit != nHit)
6098 if (infoPtr->bCaptured)
6100 if (!infoPtr->bDragOutSent)
6102 NMTOOLBARW nmt;
6103 ZeroMemory(&nmt, sizeof(nmt));
6104 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6105 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6106 infoPtr->bDragOutSent = TRUE;
6109 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6110 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6111 btnPtr->fsState &= ~TBSTATE_PRESSED;
6112 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6114 else if (nHit == infoPtr->nButtonDown) {
6115 btnPtr->fsState |= TBSTATE_PRESSED;
6116 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6118 infoPtr->nOldHit = nHit;
6122 return 0;
6126 static inline LRESULT
6127 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6129 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6130 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6131 /* else */
6132 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6136 static inline LRESULT
6137 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6139 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6140 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6142 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6146 static LRESULT
6147 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6149 TOOLBAR_INFO *infoPtr;
6150 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6151 DWORD styleadd = 0;
6153 /* allocate memory for info structure */
6154 infoPtr = Alloc (sizeof(TOOLBAR_INFO));
6155 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6157 /* paranoid!! */
6158 infoPtr->dwStructSize = sizeof(TBBUTTON);
6159 infoPtr->nRows = 1;
6160 infoPtr->nWidth = 0;
6162 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6163 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6164 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6165 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6168 /* native control does:
6169 * Get a lot of colors and brushes
6170 * WM_NOTIFYFORMAT
6171 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6172 * CreateFontIndirectW(adr1)
6173 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6174 * hdc = GetDC(toolbar)
6175 * GetSystemMetrics(0x48)
6176 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6177 * 0, 0, 0, 0, "MARLETT")
6178 * oldfnt = SelectObject(hdc, fnt2)
6179 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6180 * GetTextMetricsW(hdc, adr3)
6181 * SelectObject(hdc, oldfnt)
6182 * DeleteObject(fnt2)
6183 * ReleaseDC(hdc)
6184 * InvalidateRect(toolbar, 0, 1)
6185 * SetWindowLongW(toolbar, 0, addr)
6186 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6187 * WM_STYLECHANGING
6188 * CallWinEx old new
6189 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6190 * ie 2 0x4600094c 0x4600094c 0x4600894d
6191 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6192 * rebar 0x50008844 0x40008844 0x50008845
6193 * pager 0x50000844 0x40000844 0x50008845
6194 * IC35mgr 0x5400084e **nochange**
6195 * on entry to _NCCREATE 0x5400084e
6196 * rowlist 0x5400004e **nochange**
6197 * on entry to _NCCREATE 0x5400004e
6201 /* I think the code below is a bug, but it is the way that the native
6202 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6203 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6204 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6205 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6206 * Somehow, the only cases of this seem to be MFC programs.
6208 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6209 * does not occur in the WM_STYLECHANGING routine.
6210 * (Guy Albertelli 9/2001)
6213 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6214 && !(cs->style & TBSTYLE_TRANSPARENT))
6215 styleadd |= TBSTYLE_TRANSPARENT;
6216 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6217 styleadd |= CCS_TOP; /* default to top */
6218 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6221 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6225 static LRESULT
6226 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6228 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6229 RECT rcWindow;
6230 HDC hdc;
6232 if (dwStyle & WS_MINIMIZE)
6233 return 0; /* Nothing to do */
6235 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6237 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6238 return 0;
6240 if (!(dwStyle & CCS_NODIVIDER))
6242 GetWindowRect (hwnd, &rcWindow);
6243 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6244 if( dwStyle & WS_BORDER )
6245 OffsetRect (&rcWindow, 1, 1);
6246 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6249 ReleaseDC( hwnd, hdc );
6251 return 0;
6255 /* handles requests from the tooltip control on what text to display */
6256 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6258 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6260 TRACE("button index = %d\n", index);
6262 Free (infoPtr->pszTooltipText);
6263 infoPtr->pszTooltipText = NULL;
6265 if (index < 0)
6266 return 0;
6268 if (infoPtr->bUnicode)
6270 WCHAR wszBuffer[INFOTIPSIZE+1];
6271 NMTBGETINFOTIPW tbgit;
6272 unsigned int len; /* in chars */
6274 wszBuffer[0] = '\0';
6275 wszBuffer[INFOTIPSIZE] = '\0';
6277 tbgit.pszText = wszBuffer;
6278 tbgit.cchTextMax = INFOTIPSIZE;
6279 tbgit.iItem = lpnmtdi->hdr.idFrom;
6280 tbgit.lParam = infoPtr->buttons[index].dwData;
6282 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6284 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6286 len = strlenW(tbgit.pszText);
6287 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6289 /* need to allocate temporary buffer in infoPtr as there
6290 * isn't enough space in buffer passed to us by the
6291 * tooltip control */
6292 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6293 if (infoPtr->pszTooltipText)
6295 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6296 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6297 return 0;
6300 else if (len > 0)
6302 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6303 return 0;
6306 else
6308 CHAR szBuffer[INFOTIPSIZE+1];
6309 NMTBGETINFOTIPA tbgit;
6310 unsigned int len; /* in chars */
6312 szBuffer[0] = '\0';
6313 szBuffer[INFOTIPSIZE] = '\0';
6315 tbgit.pszText = szBuffer;
6316 tbgit.cchTextMax = INFOTIPSIZE;
6317 tbgit.iItem = lpnmtdi->hdr.idFrom;
6318 tbgit.lParam = infoPtr->buttons[index].dwData;
6320 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6322 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6324 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6325 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6327 /* need to allocate temporary buffer in infoPtr as there
6328 * isn't enough space in buffer passed to us by the
6329 * tooltip control */
6330 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6331 if (infoPtr->pszTooltipText)
6333 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6334 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6335 return 0;
6338 else if (tbgit.pszText[0])
6340 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6341 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6342 return 0;
6346 /* if button has text, but it is not shown then automatically
6347 * use that text as tooltip */
6348 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6349 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6351 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6352 unsigned int len = pszText ? strlenW(pszText) : 0;
6354 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6356 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6358 /* need to allocate temporary buffer in infoPtr as there
6359 * isn't enough space in buffer passed to us by the
6360 * tooltip control */
6361 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6362 if (infoPtr->pszTooltipText)
6364 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6365 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6366 return 0;
6369 else if (len > 0)
6371 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6372 return 0;
6376 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6378 /* last resort: send notification on to app */
6379 /* FIXME: find out what is really used here */
6380 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, lpnmtdi->hdr.idFrom, (LPARAM)lpnmtdi);
6384 static inline LRESULT
6385 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6387 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6388 LPNMHDR lpnmh = (LPNMHDR)lParam;
6390 switch (lpnmh->code)
6392 case PGN_CALCSIZE:
6394 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6396 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6397 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6398 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6399 lppgc->iWidth);
6401 else {
6402 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6403 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6404 lppgc->iHeight);
6406 return 0;
6409 case PGN_SCROLL:
6411 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6413 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6414 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6415 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6416 lppgs->iScroll, lppgs->iDir);
6417 return 0;
6420 case TTN_GETDISPINFOW:
6421 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6423 case TTN_GETDISPINFOA:
6424 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6425 return 0;
6427 default:
6428 return 0;
6433 static LRESULT
6434 TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6436 LRESULT format;
6438 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam, lParam);
6440 if (lParam == NF_QUERY)
6441 return NFR_UNICODE;
6443 if (lParam == NF_REQUERY) {
6444 format = SendMessageW(infoPtr->hwndNotify,
6445 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6446 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6447 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6448 format);
6449 format = NFR_ANSI;
6451 return format;
6453 return 0;
6457 static LRESULT
6458 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6460 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6461 HDC hdc;
6462 PAINTSTRUCT ps;
6464 /* fill ps.rcPaint with a default rect */
6465 ps.rcPaint = infoPtr->rcBound;
6467 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6469 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps.rcPaint));
6471 TOOLBAR_Refresh (hwnd, hdc, &ps);
6472 if (!wParam) EndPaint (hwnd, &ps);
6474 return 0;
6478 static LRESULT
6479 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6481 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6483 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6485 /* make first item hot */
6486 if (infoPtr->nNumButtons > 0)
6487 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6489 return 0;
6492 static LRESULT
6493 TOOLBAR_SetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
6495 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6497 TRACE("font=%p redraw=%ld\n", (HFONT)wParam, lParam);
6499 if (wParam == 0)
6500 infoPtr->hFont = infoPtr->hDefaultFont;
6501 else
6502 infoPtr->hFont = (HFONT)wParam;
6504 TOOLBAR_CalcToolbar(hwnd);
6506 if (lParam)
6507 InvalidateRect(hwnd, NULL, TRUE);
6508 return 1;
6511 static LRESULT
6512 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6513 /*****************************************************
6515 * Function;
6516 * Handles the WM_SETREDRAW message.
6518 * Documentation:
6519 * According to testing V4.71 of COMCTL32 returns the
6520 * *previous* status of the redraw flag (either 0 or 1)
6521 * instead of the MSDN documented value of 0 if handled.
6522 * (For laughs see the "consistency" with same function
6523 * in rebar.)
6525 *****************************************************/
6527 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6528 BOOL oldredraw = infoPtr->bDoRedraw;
6530 TRACE("set to %s\n",
6531 (wParam) ? "TRUE" : "FALSE");
6532 infoPtr->bDoRedraw = (BOOL) wParam;
6533 if (wParam) {
6534 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6536 return (oldredraw) ? 1 : 0;
6540 static LRESULT
6541 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6543 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6545 TRACE("sizing toolbar!\n");
6547 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6549 RECT delta_width, delta_height, client, dummy;
6550 DWORD min_x, max_x, min_y, max_y;
6551 TBUTTON_INFO *btnPtr;
6552 INT i;
6554 GetClientRect(hwnd, &client);
6555 if(client.right > infoPtr->client_rect.right)
6557 min_x = infoPtr->client_rect.right;
6558 max_x = client.right;
6560 else
6562 max_x = infoPtr->client_rect.right;
6563 min_x = client.right;
6565 if(client.bottom > infoPtr->client_rect.bottom)
6567 min_y = infoPtr->client_rect.bottom;
6568 max_y = client.bottom;
6570 else
6572 max_y = infoPtr->client_rect.bottom;
6573 min_y = client.bottom;
6576 SetRect(&delta_width, min_x, 0, max_x, min_y);
6577 SetRect(&delta_height, 0, min_y, max_x, max_y);
6579 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6580 btnPtr = infoPtr->buttons;
6581 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6582 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6583 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6584 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6586 GetClientRect(hwnd, &infoPtr->client_rect);
6587 TOOLBAR_AutoSize(hwnd);
6588 return 0;
6592 static LRESULT
6593 TOOLBAR_StyleChanged (HWND hwnd, INT nType, const STYLESTRUCT *lpStyle)
6595 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6597 if (nType == GWL_STYLE)
6599 DWORD dwOldStyle = infoPtr->dwStyle;
6601 if (lpStyle->styleNew & TBSTYLE_LIST)
6602 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6603 else
6604 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6606 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6608 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6610 infoPtr->dwStyle = lpStyle->styleNew;
6612 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6613 TOOLBAR_LayoutToolbar(hwnd);
6615 /* only resize if one of the CCS_* styles was changed */
6616 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6618 TOOLBAR_AutoSize (hwnd);
6620 InvalidateRect(hwnd, NULL, TRUE);
6624 return 0;
6628 static LRESULT
6629 TOOLBAR_SysColorChange (HWND hwnd)
6631 COMCTL32_RefreshSysColors();
6633 return 0;
6637 /* update theme after a WM_THEMECHANGED message */
6638 static LRESULT theme_changed (HWND hwnd)
6640 HTHEME theme = GetWindowTheme (hwnd);
6641 CloseThemeData (theme);
6642 OpenThemeData (hwnd, themeClass);
6643 return 0;
6647 static LRESULT WINAPI
6648 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6650 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6652 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6653 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6655 if (!infoPtr && (uMsg != WM_NCCREATE))
6656 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6658 switch (uMsg)
6660 case TB_ADDBITMAP:
6661 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6663 case TB_ADDBUTTONSA:
6664 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6666 case TB_ADDBUTTONSW:
6667 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6669 case TB_ADDSTRINGA:
6670 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6672 case TB_ADDSTRINGW:
6673 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6675 case TB_AUTOSIZE:
6676 return TOOLBAR_AutoSize (hwnd);
6678 case TB_BUTTONCOUNT:
6679 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6681 case TB_BUTTONSTRUCTSIZE:
6682 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6684 case TB_CHANGEBITMAP:
6685 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6687 case TB_CHECKBUTTON:
6688 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6690 case TB_COMMANDTOINDEX:
6691 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6693 case TB_CUSTOMIZE:
6694 return TOOLBAR_Customize (hwnd);
6696 case TB_DELETEBUTTON:
6697 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6699 case TB_ENABLEBUTTON:
6700 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6702 case TB_GETANCHORHIGHLIGHT:
6703 return TOOLBAR_GetAnchorHighlight (hwnd);
6705 case TB_GETBITMAP:
6706 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6708 case TB_GETBITMAPFLAGS:
6709 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6711 case TB_GETBUTTON:
6712 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6714 case TB_GETBUTTONINFOA:
6715 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, FALSE);
6717 case TB_GETBUTTONINFOW:
6718 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, TRUE);
6720 case TB_GETBUTTONSIZE:
6721 return TOOLBAR_GetButtonSize (hwnd);
6723 case TB_GETBUTTONTEXTA:
6724 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6726 case TB_GETBUTTONTEXTW:
6727 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6729 case TB_GETDISABLEDIMAGELIST:
6730 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6732 case TB_GETEXTENDEDSTYLE:
6733 return TOOLBAR_GetExtendedStyle (hwnd);
6735 case TB_GETHOTIMAGELIST:
6736 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6738 case TB_GETHOTITEM:
6739 return TOOLBAR_GetHotItem (hwnd);
6741 case TB_GETIMAGELIST:
6742 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6744 case TB_GETINSERTMARK:
6745 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6747 case TB_GETINSERTMARKCOLOR:
6748 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6750 case TB_GETITEMRECT:
6751 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6753 case TB_GETMAXSIZE:
6754 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6756 /* case TB_GETOBJECT: */ /* 4.71 */
6758 case TB_GETPADDING:
6759 return TOOLBAR_GetPadding (hwnd);
6761 case TB_GETRECT:
6762 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6764 case TB_GETROWS:
6765 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6767 case TB_GETSTATE:
6768 return TOOLBAR_GetState (hwnd, wParam, lParam);
6770 case TB_GETSTRINGA:
6771 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6773 case TB_GETSTRINGW:
6774 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6776 case TB_GETSTYLE:
6777 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6779 case TB_GETTEXTROWS:
6780 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6782 case TB_GETTOOLTIPS:
6783 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6785 case TB_GETUNICODEFORMAT:
6786 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6788 case TB_HIDEBUTTON:
6789 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6791 case TB_HITTEST:
6792 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6794 case TB_INDETERMINATE:
6795 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6797 case TB_INSERTBUTTONA:
6798 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6800 case TB_INSERTBUTTONW:
6801 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6803 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6805 case TB_ISBUTTONCHECKED:
6806 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6808 case TB_ISBUTTONENABLED:
6809 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6811 case TB_ISBUTTONHIDDEN:
6812 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6814 case TB_ISBUTTONHIGHLIGHTED:
6815 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6817 case TB_ISBUTTONINDETERMINATE:
6818 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6820 case TB_ISBUTTONPRESSED:
6821 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6823 case TB_LOADIMAGES:
6824 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6826 case TB_MAPACCELERATORA:
6827 case TB_MAPACCELERATORW:
6828 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6830 case TB_MARKBUTTON:
6831 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6833 case TB_MOVEBUTTON:
6834 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6836 case TB_PRESSBUTTON:
6837 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6839 case TB_REPLACEBITMAP:
6840 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6842 case TB_SAVERESTOREA:
6843 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6845 case TB_SAVERESTOREW:
6846 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6848 case TB_SETANCHORHIGHLIGHT:
6849 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6851 case TB_SETBITMAPSIZE:
6852 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6854 case TB_SETBUTTONINFOA:
6855 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6857 case TB_SETBUTTONINFOW:
6858 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6860 case TB_SETBUTTONSIZE:
6861 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6863 case TB_SETBUTTONWIDTH:
6864 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6866 case TB_SETCMDID:
6867 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6869 case TB_SETDISABLEDIMAGELIST:
6870 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6872 case TB_SETDRAWTEXTFLAGS:
6873 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6875 case TB_SETEXTENDEDSTYLE:
6876 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6878 case TB_SETHOTIMAGELIST:
6879 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6881 case TB_SETHOTITEM:
6882 return TOOLBAR_SetHotItem (hwnd, wParam);
6884 case TB_SETIMAGELIST:
6885 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6887 case TB_SETINDENT:
6888 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6890 case TB_SETINSERTMARK:
6891 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6893 case TB_SETINSERTMARKCOLOR:
6894 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6896 case TB_SETMAXTEXTROWS:
6897 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6899 case TB_SETPADDING:
6900 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6902 case TB_SETPARENT:
6903 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6905 case TB_SETROWS:
6906 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6908 case TB_SETSTATE:
6909 return TOOLBAR_SetState (hwnd, wParam, lParam);
6911 case TB_SETSTYLE:
6912 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6914 case TB_SETTOOLTIPS:
6915 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6917 case TB_SETUNICODEFORMAT:
6918 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6920 case TB_UNKWN45D:
6921 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6923 case TB_UNKWN45E:
6924 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6926 case TB_UNKWN460:
6927 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6929 case TB_UNKWN462:
6930 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6932 case TB_UNKWN463:
6933 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6935 case TB_UNKWN464:
6936 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6938 /* Common Control Messages */
6940 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6941 case CCM_GETCOLORSCHEME:
6942 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6944 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6945 case CCM_SETCOLORSCHEME:
6946 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6948 case CCM_GETVERSION:
6949 return TOOLBAR_GetVersion (hwnd);
6951 case CCM_SETVERSION:
6952 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6955 /* case WM_CHAR: */
6957 case WM_CREATE:
6958 return TOOLBAR_Create (hwnd, wParam, lParam);
6960 case WM_DESTROY:
6961 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6963 case WM_ERASEBKGND:
6964 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6966 case WM_GETFONT:
6967 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6969 case WM_KEYDOWN:
6970 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6972 /* case WM_KILLFOCUS: */
6974 case WM_LBUTTONDBLCLK:
6975 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6977 case WM_LBUTTONDOWN:
6978 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6980 case WM_LBUTTONUP:
6981 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6983 case WM_RBUTTONUP:
6984 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6986 case WM_RBUTTONDBLCLK:
6987 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6989 case WM_MOUSEMOVE:
6990 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6992 case WM_MOUSELEAVE:
6993 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6995 case WM_CAPTURECHANGED:
6996 return TOOLBAR_CaptureChanged(hwnd);
6998 case WM_NCACTIVATE:
6999 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7001 case WM_NCCALCSIZE:
7002 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7004 case WM_NCCREATE:
7005 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7007 case WM_NCPAINT:
7008 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7010 case WM_NOTIFY:
7011 return TOOLBAR_Notify (hwnd, wParam, lParam);
7013 case WM_NOTIFYFORMAT:
7014 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7016 case WM_PRINTCLIENT:
7017 case WM_PAINT:
7018 return TOOLBAR_Paint (hwnd, wParam);
7020 case WM_SETFOCUS:
7021 return TOOLBAR_SetFocus (hwnd, wParam);
7023 case WM_SETFONT:
7024 return TOOLBAR_SetFont(hwnd, wParam, lParam);
7026 case WM_SETREDRAW:
7027 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7029 case WM_SIZE:
7030 return TOOLBAR_Size (hwnd, wParam, lParam);
7032 case WM_STYLECHANGED:
7033 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7035 case WM_SYSCOLORCHANGE:
7036 return TOOLBAR_SysColorChange (hwnd);
7038 case WM_THEMECHANGED:
7039 return theme_changed (hwnd);
7041 /* case WM_WININICHANGE: */
7043 case WM_CHARTOITEM:
7044 case WM_COMMAND:
7045 case WM_DRAWITEM:
7046 case WM_MEASUREITEM:
7047 case WM_VKEYTOITEM:
7048 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7050 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7051 case PGM_FORWARDMOUSE:
7052 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7054 default:
7055 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
7056 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
7057 uMsg, wParam, lParam);
7058 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7063 VOID
7064 TOOLBAR_Register (void)
7066 WNDCLASSW wndClass;
7068 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7069 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7070 wndClass.lpfnWndProc = ToolbarWindowProc;
7071 wndClass.cbClsExtra = 0;
7072 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7073 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7074 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7075 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7077 RegisterClassW (&wndClass);
7081 VOID
7082 TOOLBAR_Unregister (void)
7084 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7087 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7089 HIMAGELIST himlold;
7090 PIMLENTRY c = NULL;
7092 /* Check if the entry already exists */
7093 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7095 /* If this is a new entry we must create it and insert into the array */
7096 if (!c)
7098 PIMLENTRY *pnies;
7100 c = Alloc(sizeof(IMLENTRY));
7101 c->id = id;
7103 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7104 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7105 pnies[*cies] = c;
7106 (*cies)++;
7108 Free(*pies);
7109 *pies = pnies;
7112 himlold = c->himl;
7113 c->himl = himl;
7115 return himlold;
7119 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7121 int i;
7123 for (i = 0; i < *cies; i++)
7124 Free((*pies)[i]);
7126 Free(*pies);
7128 *cies = 0;
7129 *pies = NULL;
7133 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id)
7135 PIMLENTRY c = NULL;
7137 if (pies != NULL)
7139 int i;
7141 for (i = 0; i < cies; i++)
7143 if (pies[i]->id == id)
7145 c = pies[i];
7146 break;
7151 return c;
7155 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id)
7157 HIMAGELIST himlDef = 0;
7158 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7160 if (pie)
7161 himlDef = pie->himl;
7163 return himlDef;
7167 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7169 if (infoPtr->bUnicode)
7170 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7171 else
7173 CHAR Buffer[256];
7174 NMTOOLBARA nmtba;
7175 BOOL bRet = FALSE;
7177 nmtba.iItem = nmtb->iItem;
7178 nmtba.pszText = Buffer;
7179 nmtba.cchText = 256;
7180 ZeroMemory(nmtba.pszText, nmtba.cchText);
7182 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7184 int ccht = strlen(nmtba.pszText);
7185 if (ccht)
7186 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7187 nmtb->pszText, nmtb->cchText);
7189 nmtb->tbButton = nmtba.tbButton;
7190 bRet = TRUE;
7193 return bRet;
7198 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo)
7200 NMTOOLBARW nmtb;
7202 /* MSDN states that iItem is the index of the button, rather than the
7203 * command ID as used by every other NMTOOLBAR notification */
7204 nmtb.iItem = iItem;
7205 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7207 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);