wordpad: Accept double-click in date and time dialog.
[wine.git] / dlls / comctl32 / toolbar.c
blob8e30df0bdd2590c20669d9d1f2699c47e9c75d26
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 ntfret = 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 bFound = TRUE;
1430 x = infoPtr->nIndent;
1431 if (btnPtr[i].fsStyle & BTNS_SEP )
1432 bButtonWrap = FALSE;
1433 else
1434 bButtonWrap = TRUE;
1437 else {
1438 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1439 i, btnPtr[i].fsStyle, x, cx);
1440 x += cx;
1446 /***********************************************************************
1447 * TOOLBAR_MeasureButton
1449 * Calculates the width and height required for a button. Used in
1450 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1451 * the width of buttons that are autosized.
1453 * Note that it would have been rather elegant to use one piece of code for
1454 * both the laying out of the toolbar and for controlling where button parts
1455 * are drawn, but the native control has inconsistencies between the two that
1456 * prevent this from being effectively. These inconsistencies can be seen as
1457 * artefacts where parts of the button appear outside of the bounding button
1458 * rectangle.
1460 * There are several cases for the calculation of the button dimensions and
1461 * button part positioning:
1463 * List
1464 * ====
1466 * With Bitmap:
1468 * +--------------------------------------------------------+ ^
1469 * | ^ ^ | |
1470 * | | pad.cy / 2 | centred | |
1471 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1472 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1473 * | |<------------>| | | | |
1474 * | +--------------+ +------------+ | |
1475 * |<-------------------------------------->| | |
1476 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1477 * | szText.cx | |
1478 * +--------------------------------------------------------+ -
1479 * <-------------------------------------------------------->
1480 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1482 * Without Bitmap (I_IMAGENONE):
1484 * +-----------------------------------+ ^
1485 * | ^ | |
1486 * | | centred | | LISTPAD_CY +
1487 * | +------------+ | | szText.cy
1488 * | | Text | | |
1489 * | | | | |
1490 * | +------------+ | |
1491 * |<----------------->| | |
1492 * | cxedge |<-----------> | |
1493 * | szText.cx | |
1494 * +-----------------------------------+ -
1495 * <----------------------------------->
1496 * szText.cx + pad.cx
1498 * Without text:
1500 * +--------------------------------------+ ^
1501 * | ^ | |
1502 * | | padding.cy/2 | | DEFPAD_CY +
1503 * | +------------+ | | nBitmapHeight
1504 * | | Bitmap | | |
1505 * | | | | |
1506 * | +------------+ | |
1507 * |<------------------->| | |
1508 * | cxedge + iListGap/2 |<-----------> | |
1509 * | nBitmapWidth | |
1510 * +--------------------------------------+ -
1511 * <-------------------------------------->
1512 * 2*cxedge + nBitmapWidth + iListGap
1514 * Non-List
1515 * ========
1517 * With bitmap:
1519 * +-----------------------------------+ ^
1520 * | ^ | |
1521 * | | pad.cy / 2 | | nBitmapHeight +
1522 * | - | | szText.cy +
1523 * | +------------+ | | DEFPAD_CY + 1
1524 * | centred | Bitmap | | |
1525 * |<----------------->| | | |
1526 * | +------------+ | |
1527 * | ^ | |
1528 * | 1 | | |
1529 * | - | |
1530 * | centred +---------------+ | |
1531 * |<--------------->| Text | | |
1532 * | +---------------+ | |
1533 * +-----------------------------------+ -
1534 * <----------------------------------->
1535 * pad.cx + max(nBitmapWidth, szText.cx)
1537 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1539 * +---------------------------------------+ ^
1540 * | ^ | |
1541 * | | 2 + pad.cy / 2 | |
1542 * | - | | szText.cy +
1543 * | centred +-----------------+ | | pad.cy + 2
1544 * |<--------------->| Text | | |
1545 * | +-----------------+ | |
1546 * | | |
1547 * +---------------------------------------+ -
1548 * <--------------------------------------->
1549 * 2*cxedge + pad.cx + szText.cx
1551 * Without text:
1552 * As for with bitmaps, but with szText.cx zero.
1554 static inline SIZE TOOLBAR_MeasureButton(const TOOLBAR_INFO *infoPtr, SIZE sizeString,
1555 BOOL bHasBitmap, BOOL bValidImageList)
1557 SIZE sizeButton;
1558 if (infoPtr->dwStyle & TBSTYLE_LIST)
1560 /* set button height from bitmap / text height... */
1561 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1562 sizeString.cy);
1564 /* ... add on the necessary padding */
1565 if (bValidImageList)
1567 if (bHasBitmap)
1568 sizeButton.cy += DEFPAD_CY;
1569 else
1570 sizeButton.cy += LISTPAD_CY;
1572 else
1573 sizeButton.cy += infoPtr->szPadding.cy;
1575 /* calculate button width */
1576 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1577 infoPtr->nBitmapWidth + infoPtr->iListGap;
1578 if (sizeString.cx > 0)
1579 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1582 else
1584 if (bHasBitmap)
1586 sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
1587 if (sizeString.cy > 0)
1588 sizeButton.cy += 1 + sizeString.cy;
1589 sizeButton.cx = infoPtr->szPadding.cx +
1590 max(sizeString.cx, infoPtr->nBitmapWidth);
1592 else
1594 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1595 NONLIST_NOTEXT_OFFSET;
1596 sizeButton.cx = infoPtr->szPadding.cx +
1597 max(2*GetSystemMetrics(SM_CXEDGE) + sizeString.cx, infoPtr->nBitmapWidth);
1600 return sizeButton;
1604 /***********************************************************************
1605 * TOOLBAR_CalcToolbar
1607 * This function calculates button and separator placement. It first
1608 * calculates the button sizes, gets the toolbar window width and then
1609 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1610 * on. It assigns a new location to each item and sends this location to
1611 * the tooltip window if appropriate. Finally, it updates the rcBound
1612 * rect and calculates the new required toolbar window height.
1614 static void
1615 TOOLBAR_CalcToolbar (HWND hwnd)
1617 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1618 SIZE sizeString, sizeButton;
1619 BOOL validImageList = FALSE;
1621 TOOLBAR_CalcStrings (hwnd, &sizeString);
1623 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1625 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1626 validImageList = TRUE;
1627 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1628 infoPtr->nButtonWidth = sizeButton.cx;
1629 infoPtr->nButtonHeight = sizeButton.cy;
1630 infoPtr->iTopMargin = default_top_margin(infoPtr);
1632 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1633 infoPtr->nButtonWidth = infoPtr->cxMin;
1634 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1635 infoPtr->nButtonWidth = infoPtr->cxMax;
1637 TOOLBAR_LayoutToolbar(hwnd);
1640 static void
1641 TOOLBAR_LayoutToolbar(HWND hwnd)
1643 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1644 TBUTTON_INFO *btnPtr;
1645 SIZE sizeButton;
1646 INT i, nRows, nSepRows;
1647 INT x, y, cx, cy;
1648 BOOL bWrap;
1649 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1650 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1652 TOOLBAR_WrapToolbar(hwnd, infoPtr->dwStyle);
1654 x = infoPtr->nIndent;
1655 y = infoPtr->iTopMargin;
1656 cx = infoPtr->nButtonWidth;
1657 cy = infoPtr->nButtonHeight;
1659 nRows = nSepRows = 0;
1661 infoPtr->rcBound.top = y;
1662 infoPtr->rcBound.left = x;
1663 infoPtr->rcBound.bottom = y + cy;
1664 infoPtr->rcBound.right = x;
1666 btnPtr = infoPtr->buttons;
1668 TRACE("cy=%d\n", cy);
1670 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1672 bWrap = FALSE;
1673 if (btnPtr->fsState & TBSTATE_HIDDEN)
1675 SetRectEmpty (&btnPtr->rect);
1676 continue;
1679 cy = infoPtr->nButtonHeight;
1681 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1682 /* it is the actual width of the separator. This is used for */
1683 /* custom controls in toolbars. */
1684 if (btnPtr->fsStyle & BTNS_SEP) {
1685 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1686 cy = (btnPtr->iBitmap > 0) ?
1687 btnPtr->iBitmap : SEPARATOR_WIDTH;
1688 cx = infoPtr->nButtonWidth;
1690 else
1691 cx = (btnPtr->iBitmap > 0) ?
1692 btnPtr->iBitmap : SEPARATOR_WIDTH;
1694 else
1696 if (btnPtr->cx)
1697 cx = btnPtr->cx;
1698 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1699 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1701 SIZE sz;
1702 HDC hdc;
1703 HFONT hOldFont;
1705 hdc = GetDC (hwnd);
1706 hOldFont = SelectObject (hdc, infoPtr->hFont);
1708 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1710 SelectObject (hdc, hOldFont);
1711 ReleaseDC (hwnd, hdc);
1713 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1714 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1715 validImageList);
1716 cx = sizeButton.cx;
1718 else
1719 cx = infoPtr->nButtonWidth;
1721 /* if size has been set manually then don't add on extra space
1722 * for the drop down arrow */
1723 if (!btnPtr->cx && hasDropDownArrows &&
1724 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1725 cx += DDARROW_WIDTH;
1727 if (btnPtr->fsState & TBSTATE_WRAP )
1728 bWrap = TRUE;
1730 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1732 if (infoPtr->rcBound.left > x)
1733 infoPtr->rcBound.left = x;
1734 if (infoPtr->rcBound.right < x + cx)
1735 infoPtr->rcBound.right = x + cx;
1736 if (infoPtr->rcBound.bottom < y + cy)
1737 infoPtr->rcBound.bottom = y + cy;
1739 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1741 /* btnPtr->nRow is zero based. The space between the rows is */
1742 /* also considered as a row. */
1743 btnPtr->nRow = nRows + nSepRows;
1745 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1746 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1747 x, y, x+cx, y+cy);
1749 if( bWrap )
1751 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1752 y += cy;
1753 else
1755 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1756 /* it is the actual width of the separator. This is used for */
1757 /* custom controls in toolbars. */
1758 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1759 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1760 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1761 else
1762 y += cy;
1764 /* nSepRows is used to calculate the extra height following */
1765 /* the last row. */
1766 nSepRows++;
1768 x = infoPtr->nIndent;
1770 /* Increment row number unless this is the last button */
1771 /* and it has Wrap set. */
1772 if (i != infoPtr->nNumButtons-1)
1773 nRows++;
1775 else
1776 x += cx;
1779 /* infoPtr->nRows is the number of rows on the toolbar */
1780 infoPtr->nRows = nRows + nSepRows + 1;
1782 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1786 static INT
1787 TOOLBAR_InternalHitTest (HWND hwnd, const POINT *lpPt)
1789 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1790 TBUTTON_INFO *btnPtr;
1791 INT i;
1793 btnPtr = infoPtr->buttons;
1794 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1795 if (btnPtr->fsState & TBSTATE_HIDDEN)
1796 continue;
1798 if (btnPtr->fsStyle & BTNS_SEP) {
1799 if (PtInRect (&btnPtr->rect, *lpPt)) {
1800 TRACE(" ON SEPARATOR %d!\n", i);
1801 return -i;
1804 else {
1805 if (PtInRect (&btnPtr->rect, *lpPt)) {
1806 TRACE(" ON BUTTON %d!\n", i);
1807 return i;
1812 TRACE(" NOWHERE!\n");
1813 return TOOLBAR_NOWHERE;
1817 static INT
1818 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1820 TBUTTON_INFO *btnPtr;
1821 INT i;
1823 if (CommandIsIndex) {
1824 TRACE("command is really index command=%d\n", idCommand);
1825 if (idCommand >= infoPtr->nNumButtons) return -1;
1826 return idCommand;
1828 btnPtr = infoPtr->buttons;
1829 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1830 if (btnPtr->idCommand == idCommand) {
1831 TRACE("command=%d index=%d\n", idCommand, i);
1832 return i;
1835 TRACE("no index found for command=%d\n", idCommand);
1836 return -1;
1840 static INT
1841 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO *infoPtr, INT nIndex)
1843 TBUTTON_INFO *btnPtr;
1844 INT nRunIndex;
1846 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1847 return -1;
1849 /* check index button */
1850 btnPtr = &infoPtr->buttons[nIndex];
1851 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1852 if (btnPtr->fsState & TBSTATE_CHECKED)
1853 return nIndex;
1856 /* check previous buttons */
1857 nRunIndex = nIndex - 1;
1858 while (nRunIndex >= 0) {
1859 btnPtr = &infoPtr->buttons[nRunIndex];
1860 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1861 if (btnPtr->fsState & TBSTATE_CHECKED)
1862 return nRunIndex;
1864 else
1865 break;
1866 nRunIndex--;
1869 /* check next buttons */
1870 nRunIndex = nIndex + 1;
1871 while (nRunIndex < infoPtr->nNumButtons) {
1872 btnPtr = &infoPtr->buttons[nRunIndex];
1873 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1874 if (btnPtr->fsState & TBSTATE_CHECKED)
1875 return nRunIndex;
1877 else
1878 break;
1879 nRunIndex++;
1882 return -1;
1886 static VOID
1887 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1888 WPARAM wParam, LPARAM lParam)
1890 MSG msg;
1892 msg.hwnd = hwndMsg;
1893 msg.message = uMsg;
1894 msg.wParam = wParam;
1895 msg.lParam = lParam;
1896 msg.time = GetMessageTime ();
1897 msg.pt.x = (short)LOWORD(GetMessagePos ());
1898 msg.pt.y = (short)HIWORD(GetMessagePos ());
1900 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1903 static void
1904 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1906 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1907 TTTOOLINFOW ti;
1909 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1910 ti.cbSize = sizeof (TTTOOLINFOW);
1911 ti.hwnd = infoPtr->hwndSelf;
1912 ti.uId = button->idCommand;
1913 ti.hinst = 0;
1914 ti.lpszText = LPSTR_TEXTCALLBACKW;
1915 /* ti.lParam = random value from the stack? */
1917 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1918 0, (LPARAM)&ti);
1922 static void
1923 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1925 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1926 TTTOOLINFOW ti;
1928 ZeroMemory(&ti, sizeof(ti));
1929 ti.cbSize = sizeof(ti);
1930 ti.hwnd = infoPtr->hwndSelf;
1931 ti.uId = button->idCommand;
1933 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1937 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1939 /* Set the toolTip only for non-hidden, non-separator button */
1940 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1942 TTTOOLINFOW ti;
1944 ZeroMemory(&ti, sizeof(ti));
1945 ti.cbSize = sizeof(ti);
1946 ti.hwnd = infoPtr->hwndSelf;
1947 ti.uId = button->idCommand;
1948 ti.rect = button->rect;
1949 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1953 /* Creates the tooltip control */
1954 static void
1955 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
1957 int i;
1958 NMTOOLTIPSCREATED nmttc;
1960 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1961 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1962 infoPtr->hwndSelf, 0, 0, 0);
1964 if (!infoPtr->hwndToolTip)
1965 return;
1967 /* Send NM_TOOLTIPSCREATED notification */
1968 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1969 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
1971 for (i = 0; i < infoPtr->nNumButtons; i++)
1973 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
1974 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
1978 /* keeps available button list box sorted by button id */
1979 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1981 int i;
1982 int count;
1983 PCUSTOMBUTTON btnInfo;
1984 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1986 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1988 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1990 /* position 0 is always separator */
1991 for (i = 1; i < count; i++)
1993 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1994 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1996 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1997 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1998 return;
2001 /* id higher than all others add to end */
2002 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2003 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2006 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2008 NMTOOLBARW nmtb;
2010 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2012 if (nIndexFrom == nIndexTo)
2013 return;
2015 /* MSDN states that iItem is the index of the button, rather than the
2016 * command ID as used by every other NMTOOLBAR notification */
2017 nmtb.iItem = nIndexFrom;
2018 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2020 PCUSTOMBUTTON btnInfo;
2021 NMHDR hdr;
2022 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2023 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2025 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2027 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2028 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2029 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2030 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2032 if (nIndexTo <= 0)
2033 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2034 else
2035 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2037 /* last item is always separator, so -2 instead of -1 */
2038 if (nIndexTo >= (count - 2))
2039 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2040 else
2041 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2043 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2044 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2046 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2050 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2052 NMTOOLBARW nmtb;
2054 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2056 /* MSDN states that iItem is the index of the button, rather than the
2057 * command ID as used by every other NMTOOLBAR notification */
2058 nmtb.iItem = nIndexAvail;
2059 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2061 PCUSTOMBUTTON btnInfo;
2062 NMHDR hdr;
2063 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2064 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2065 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2067 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2069 if (nIndexAvail != 0) /* index == 0 indicates separator */
2071 /* remove from 'available buttons' list */
2072 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2073 if (nIndexAvail == count-1)
2074 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2075 else
2076 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2078 else
2080 PCUSTOMBUTTON btnNew;
2082 /* duplicate 'separator' button */
2083 btnNew = Alloc(sizeof(CUSTOMBUTTON));
2084 *btnNew = *btnInfo;
2085 btnInfo = btnNew;
2088 /* insert into 'toolbar button' list */
2089 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2090 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2092 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2094 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2098 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT index)
2100 PCUSTOMBUTTON btnInfo;
2101 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2103 TRACE("Remove: index %d\n", index);
2105 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2107 /* send TBN_QUERYDELETE notification */
2108 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2110 NMHDR hdr;
2112 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2113 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2115 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2117 /* insert into 'available button' list */
2118 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2119 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2120 else
2121 Free(btnInfo);
2123 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2127 /* drag list notification function for toolbar buttons list box */
2128 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2129 const DRAGLISTINFO *pDLI)
2131 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2132 switch (pDLI->uNotification)
2134 case DL_BEGINDRAG:
2136 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2137 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2138 /* no dragging for last item (separator) */
2139 if (nCurrentItem >= (nCount - 1)) return FALSE;
2140 return TRUE;
2142 case DL_DRAGGING:
2144 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2145 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2146 /* no dragging past last item (separator) */
2147 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2149 DrawInsert(hwnd, hwndList, nCurrentItem);
2150 /* FIXME: native uses "move button" cursor */
2151 return DL_COPYCURSOR;
2154 /* not over toolbar buttons list */
2155 if (nCurrentItem < 0)
2157 POINT ptWindow = pDLI->ptCursor;
2158 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2159 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2160 /* over available buttons list? */
2161 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2162 /* FIXME: native uses "move button" cursor */
2163 return DL_COPYCURSOR;
2165 /* clear drag arrow */
2166 DrawInsert(hwnd, hwndList, -1);
2167 return DL_STOPCURSOR;
2169 case DL_DROPPED:
2171 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2172 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2173 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2174 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2176 /* clear drag arrow */
2177 DrawInsert(hwnd, hwndList, -1);
2178 /* move item */
2179 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2181 /* not over toolbar buttons list */
2182 if (nIndexTo < 0)
2184 POINT ptWindow = pDLI->ptCursor;
2185 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2186 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2187 /* over available buttons list? */
2188 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2189 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2191 break;
2193 case DL_CANCELDRAG:
2194 /* Clear drag arrow */
2195 DrawInsert(hwnd, hwndList, -1);
2196 break;
2199 return 0;
2202 /* drag list notification function for available buttons list box */
2203 static LRESULT TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2204 const DRAGLISTINFO *pDLI)
2206 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2207 switch (pDLI->uNotification)
2209 case DL_BEGINDRAG:
2210 return TRUE;
2211 case DL_DRAGGING:
2213 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2214 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2215 /* no dragging past last item (separator) */
2216 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2218 DrawInsert(hwnd, hwndList, nCurrentItem);
2219 /* FIXME: native uses "move button" cursor */
2220 return DL_COPYCURSOR;
2223 /* not over toolbar buttons list */
2224 if (nCurrentItem < 0)
2226 POINT ptWindow = pDLI->ptCursor;
2227 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2228 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2229 /* over available buttons list? */
2230 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2231 /* FIXME: native uses "move button" cursor */
2232 return DL_COPYCURSOR;
2234 /* clear drag arrow */
2235 DrawInsert(hwnd, hwndList, -1);
2236 return DL_STOPCURSOR;
2238 case DL_DROPPED:
2240 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2241 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2242 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2243 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2245 /* clear drag arrow */
2246 DrawInsert(hwnd, hwndList, -1);
2247 /* add item */
2248 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2251 case DL_CANCELDRAG:
2252 /* Clear drag arrow */
2253 DrawInsert(hwnd, hwndList, -1);
2254 break;
2256 return 0;
2259 extern UINT uDragListMessage;
2261 /***********************************************************************
2262 * TOOLBAR_CustomizeDialogProc
2263 * This function implements the toolbar customization dialog.
2265 static INT_PTR CALLBACK
2266 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2268 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2269 PCUSTOMBUTTON btnInfo;
2270 NMTOOLBARA nmtb;
2271 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2273 switch (uMsg)
2275 case WM_INITDIALOG:
2276 custInfo = (PCUSTDLG_INFO)lParam;
2277 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2279 if (custInfo)
2281 WCHAR Buffer[256];
2282 int i = 0;
2283 int index;
2284 NMTBINITCUSTOMIZE nmtbic;
2286 infoPtr = custInfo->tbInfo;
2288 /* send TBN_QUERYINSERT notification */
2289 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2291 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2292 return FALSE;
2294 nmtbic.hwndDialog = hwnd;
2295 /* Send TBN_INITCUSTOMIZE notification */
2296 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2297 TBNRF_HIDEHELP)
2299 TRACE("TBNRF_HIDEHELP requested\n");
2300 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2303 /* add items to 'toolbar buttons' list and check if removable */
2304 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2306 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2307 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2308 btnInfo->btn.fsStyle = BTNS_SEP;
2309 btnInfo->bVirtual = FALSE;
2310 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2312 /* send TBN_QUERYDELETE notification */
2313 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2315 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2316 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2319 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2321 /* insert separator button into 'available buttons' list */
2322 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2323 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2324 btnInfo->btn.fsStyle = BTNS_SEP;
2325 btnInfo->bVirtual = FALSE;
2326 btnInfo->bRemovable = TRUE;
2327 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2328 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2329 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2331 /* insert all buttons into dsa */
2332 for (i = 0;; i++)
2334 /* send TBN_GETBUTTONINFO notification */
2335 NMTOOLBARW nmtb;
2336 nmtb.iItem = i;
2337 nmtb.pszText = Buffer;
2338 nmtb.cchText = 256;
2340 /* Clear previous button's text */
2341 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2343 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2344 break;
2346 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2347 nmtb.tbButton.fsStyle, i,
2348 nmtb.tbButton.idCommand,
2349 nmtb.tbButton.iString,
2350 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2351 : "");
2353 /* insert button into the apropriate list */
2354 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2355 if (index == -1)
2357 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2358 btnInfo->bVirtual = FALSE;
2359 btnInfo->bRemovable = TRUE;
2361 else
2363 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2364 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2367 btnInfo->btn = nmtb.tbButton;
2368 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2370 if (lstrlenW(nmtb.pszText))
2371 lstrcpyW(btnInfo->text, nmtb.pszText);
2372 else if (nmtb.tbButton.iString >= 0 &&
2373 nmtb.tbButton.iString < infoPtr->nNumStrings)
2375 lstrcpyW(btnInfo->text,
2376 infoPtr->strings[nmtb.tbButton.iString]);
2380 if (index == -1)
2381 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2384 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2386 /* select first item in the 'available' list */
2387 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2389 /* append 'virtual' separator button to the 'toolbar buttons' list */
2390 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2391 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2392 btnInfo->btn.fsStyle = BTNS_SEP;
2393 btnInfo->bVirtual = TRUE;
2394 btnInfo->bRemovable = FALSE;
2395 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2396 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2397 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2399 /* select last item in the 'toolbar' list */
2400 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2401 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2403 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2404 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2406 /* set focus and disable buttons */
2407 PostMessageW (hwnd, WM_USER, 0, 0);
2409 return TRUE;
2411 case WM_USER:
2412 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2413 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2414 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2415 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2416 return TRUE;
2418 case WM_CLOSE:
2419 EndDialog(hwnd, FALSE);
2420 return TRUE;
2422 case WM_COMMAND:
2423 switch (LOWORD(wParam))
2425 case IDC_TOOLBARBTN_LBOX:
2426 if (HIWORD(wParam) == LBN_SELCHANGE)
2428 PCUSTOMBUTTON btnInfo;
2429 NMTOOLBARA nmtb;
2430 int count;
2431 int index;
2433 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2434 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2436 /* send TBN_QUERYINSERT notification */
2437 nmtb.iItem = index;
2438 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2440 /* get list box item */
2441 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2443 if (index == (count - 1))
2445 /* last item (virtual separator) */
2446 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2447 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2449 else if (index == (count - 2))
2451 /* second last item (last non-virtual item) */
2452 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2453 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2455 else if (index == 0)
2457 /* first item */
2458 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2459 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2461 else
2463 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2464 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2467 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2469 break;
2471 case IDC_MOVEUP_BTN:
2473 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2474 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2476 break;
2478 case IDC_MOVEDN_BTN: /* move down */
2480 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2481 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2483 break;
2485 case IDC_REMOVE_BTN: /* remove button */
2487 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2489 if (LB_ERR == index)
2490 break;
2492 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2494 break;
2495 case IDC_HELP_BTN:
2496 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2497 break;
2498 case IDC_RESET_BTN:
2499 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2500 break;
2502 case IDOK: /* Add button */
2504 int index;
2505 int indexto;
2507 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2508 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2510 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2512 break;
2514 case IDCANCEL:
2515 EndDialog(hwnd, FALSE);
2516 break;
2518 return TRUE;
2520 case WM_DESTROY:
2522 int count;
2523 int i;
2525 /* delete items from 'toolbar buttons' listbox*/
2526 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2527 for (i = 0; i < count; i++)
2529 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2530 Free(btnInfo);
2531 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2533 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2536 /* delete items from 'available buttons' listbox*/
2537 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2538 for (i = 0; i < count; i++)
2540 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2541 Free(btnInfo);
2542 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2544 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2546 return TRUE;
2548 case WM_DRAWITEM:
2549 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2551 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2552 RECT rcButton;
2553 RECT rcText;
2554 HPEN hPen, hOldPen;
2555 HBRUSH hOldBrush;
2556 COLORREF oldText = 0;
2557 COLORREF oldBk = 0;
2559 /* get item data */
2560 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2561 if (btnInfo == NULL)
2563 FIXME("btnInfo invalid!\n");
2564 return TRUE;
2567 /* set colors and select objects */
2568 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2569 if (btnInfo->bVirtual)
2570 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2571 else
2572 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2573 hPen = CreatePen( PS_SOLID, 1,
2574 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2575 hOldPen = SelectObject (lpdis->hDC, hPen );
2576 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2578 /* fill background rectangle */
2579 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2580 lpdis->rcItem.right, lpdis->rcItem.bottom);
2582 /* calculate button and text rectangles */
2583 CopyRect (&rcButton, &lpdis->rcItem);
2584 InflateRect (&rcButton, -1, -1);
2585 CopyRect (&rcText, &rcButton);
2586 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2587 rcText.left = rcButton.right + 2;
2589 /* draw focus rectangle */
2590 if (lpdis->itemState & ODS_FOCUS)
2591 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2593 /* draw button */
2594 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2595 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2597 /* draw image and text */
2598 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2599 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2600 btnInfo->btn.iBitmap));
2601 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2602 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2604 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2605 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2607 /* delete objects and reset colors */
2608 SelectObject (lpdis->hDC, hOldBrush);
2609 SelectObject (lpdis->hDC, hOldPen);
2610 SetBkColor (lpdis->hDC, oldBk);
2611 SetTextColor (lpdis->hDC, oldText);
2612 DeleteObject( hPen );
2613 return TRUE;
2615 return FALSE;
2617 case WM_MEASUREITEM:
2618 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2620 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2622 lpmis->itemHeight = 15 + 8; /* default height */
2624 return TRUE;
2626 return FALSE;
2628 default:
2629 if (uDragListMessage && (uMsg == uDragListMessage))
2631 if (wParam == IDC_TOOLBARBTN_LBOX)
2633 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2634 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2635 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2636 return TRUE;
2638 else if (wParam == IDC_AVAILBTN_LBOX)
2640 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2641 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2642 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2643 return TRUE;
2646 return FALSE;
2650 static BOOL
2651 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2653 HBITMAP hbmLoad;
2654 INT nCountBefore = ImageList_GetImageCount(himlDef);
2655 INT nCountAfter;
2656 INT cxIcon, cyIcon;
2657 INT nAdded;
2658 INT nIndex;
2660 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2661 /* Add bitmaps to the default image list */
2662 if (bitmap->hInst == NULL) /* a handle was passed */
2663 hbmLoad = CopyImage(ULongToHandle(bitmap->nID), IMAGE_BITMAP, 0, 0, 0);
2664 else
2665 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2667 /* enlarge the bitmap if needed */
2668 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2669 if (bitmap->hInst != COMCTL32_hModule)
2670 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2672 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2673 DeleteObject(hbmLoad);
2674 if (nIndex == -1)
2675 return FALSE;
2677 nCountAfter = ImageList_GetImageCount(himlDef);
2678 nAdded = nCountAfter - nCountBefore;
2679 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2681 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2682 } else if (nAdded > (INT)bitmap->nButtons) {
2683 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2684 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2687 infoPtr->nNumBitmaps += nAdded;
2688 return TRUE;
2691 static void
2692 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2694 HIMAGELIST himlDef;
2695 HIMAGELIST himlNew;
2696 INT cx, cy;
2697 INT i;
2699 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2700 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2701 return;
2702 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2703 return;
2704 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2705 return;
2707 TRACE("Update icon size: %dx%d -> %dx%d\n",
2708 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2710 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2711 ILC_COLORDDB|ILC_MASK, 8, 2);
2712 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2713 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2714 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2715 infoPtr->himlInt = himlNew;
2717 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2718 ImageList_Destroy(himlDef);
2721 /***********************************************************************
2722 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2725 static LRESULT
2726 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2728 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2729 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2730 TBITMAP_INFO info;
2731 INT iSumButtons, i;
2732 HIMAGELIST himlDef;
2734 TRACE("hwnd=%p wParam=%lx lParam=%lx\n", hwnd, wParam, lParam);
2735 if (!lpAddBmp)
2736 return -1;
2738 if (lpAddBmp->hInst == HINST_COMMCTRL)
2740 info.hInst = COMCTL32_hModule;
2741 switch (lpAddBmp->nID)
2743 case IDB_STD_SMALL_COLOR:
2744 info.nButtons = 15;
2745 info.nID = IDB_STD_SMALL;
2746 break;
2747 case IDB_STD_LARGE_COLOR:
2748 info.nButtons = 15;
2749 info.nID = IDB_STD_LARGE;
2750 break;
2751 case IDB_VIEW_SMALL_COLOR:
2752 info.nButtons = 12;
2753 info.nID = IDB_VIEW_SMALL;
2754 break;
2755 case IDB_VIEW_LARGE_COLOR:
2756 info.nButtons = 12;
2757 info.nID = IDB_VIEW_LARGE;
2758 break;
2759 case IDB_HIST_SMALL_COLOR:
2760 info.nButtons = 5;
2761 info.nID = IDB_HIST_SMALL;
2762 break;
2763 case IDB_HIST_LARGE_COLOR:
2764 info.nButtons = 5;
2765 info.nID = IDB_HIST_LARGE;
2766 break;
2767 default:
2768 return -1;
2771 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2773 /* Windows resize all the buttons to the size of a newly added standard image */
2774 if (lpAddBmp->nID & 1)
2776 /* large icons: 24x24. Will make the button 31x30 */
2777 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
2779 else
2781 /* small icons: 16x16. Will make the buttons 23x22 */
2782 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
2785 TOOLBAR_CalcToolbar (hwnd);
2787 else
2789 info.nButtons = (INT)wParam;
2790 info.hInst = lpAddBmp->hInst;
2791 info.nID = lpAddBmp->nID;
2792 TRACE("adding %d bitmaps!\n", info.nButtons);
2795 /* check if the bitmap is already loaded and compute iSumButtons */
2796 iSumButtons = 0;
2797 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2799 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2800 infoPtr->bitmaps[i].nID == info.nID)
2801 return iSumButtons;
2802 iSumButtons += infoPtr->bitmaps[i].nButtons;
2805 if (!infoPtr->cimlDef) {
2806 /* create new default image list */
2807 TRACE ("creating default image list!\n");
2809 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2810 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2811 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2812 infoPtr->himlInt = himlDef;
2814 else {
2815 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2818 if (!himlDef) {
2819 WARN("No default image list available\n");
2820 return -1;
2823 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2824 return -1;
2826 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2827 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2828 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2829 infoPtr->nNumBitmapInfos++;
2830 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2832 InvalidateRect(hwnd, NULL, TRUE);
2833 return iSumButtons;
2837 static LRESULT
2838 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2840 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2841 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2842 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2843 BOOL fHasString = FALSE;
2845 TRACE("adding %ld buttons (unicode=%d)!\n", wParam, fUnicode);
2847 nAddButtons = (UINT)wParam;
2848 nOldButtons = infoPtr->nNumButtons;
2849 nNewButtons = nOldButtons + nAddButtons;
2851 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
2852 infoPtr->nNumButtons = nNewButtons;
2854 /* insert new button data */
2855 for (nCount = 0; nCount < nAddButtons; nCount++) {
2856 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2857 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2858 btnPtr->idCommand = lpTbb[nCount].idCommand;
2859 btnPtr->fsState = lpTbb[nCount].fsState;
2860 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2861 btnPtr->dwData = lpTbb[nCount].dwData;
2862 btnPtr->bHot = FALSE;
2863 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2865 if (fUnicode)
2866 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2867 else
2868 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString);
2869 fHasString = TRUE;
2871 else
2872 btnPtr->iString = lpTbb[nCount].iString;
2874 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
2877 if (infoPtr->nNumStrings > 0 || fHasString)
2878 TOOLBAR_CalcToolbar(hwnd);
2879 else
2880 TOOLBAR_LayoutToolbar(hwnd);
2881 TOOLBAR_AutoSize (hwnd);
2883 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2885 InvalidateRect(hwnd, NULL, TRUE);
2887 return TRUE;
2891 static LRESULT
2892 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2894 #define MAX_RESOURCE_STRING_LENGTH 512
2895 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2896 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2897 INT nIndex = infoPtr->nNumStrings;
2899 if ((wParam) && (HIWORD(lParam) == 0)) {
2900 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2901 WCHAR delimiter;
2902 WCHAR *next_delim;
2903 WCHAR *p;
2904 INT len;
2905 TRACE("adding string from resource!\n");
2907 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2908 szString, MAX_RESOURCE_STRING_LENGTH);
2910 TRACE("len=%d %s\n", len, debugstr_w(szString));
2911 if (len == 0 || len == 1)
2912 return nIndex;
2914 TRACE("Delimiter: 0x%x\n", *szString);
2915 delimiter = *szString;
2916 p = szString + 1;
2918 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2919 *next_delim = 0;
2920 if (next_delim + 1 >= szString + len)
2922 /* this may happen if delimiter == '\0' or if the last char is a
2923 * delimiter (then it is ignored like the native does) */
2924 break;
2927 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2928 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2929 infoPtr->nNumStrings++;
2931 p = next_delim + 1;
2934 else {
2935 LPWSTR p = (LPWSTR)lParam;
2936 INT len;
2938 if (p == NULL)
2939 return -1;
2940 TRACE("adding string(s) from array!\n");
2941 while (*p) {
2942 len = strlenW (p);
2944 TRACE("len=%d %s\n", len, debugstr_w(p));
2945 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2946 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2947 infoPtr->nNumStrings++;
2949 p += (len+1);
2953 if (fFirstString)
2954 TOOLBAR_CalcToolbar(hwnd);
2955 return nIndex;
2959 static LRESULT
2960 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2962 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2963 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2964 LPSTR p;
2965 INT nIndex;
2966 INT len;
2968 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
2969 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
2971 p = (LPSTR)lParam;
2972 if (p == NULL)
2973 return -1;
2975 TRACE("adding string(s) from array!\n");
2976 nIndex = infoPtr->nNumStrings;
2977 while (*p) {
2978 len = strlen (p);
2979 TRACE("len=%d \"%s\"\n", len, p);
2981 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2982 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
2983 infoPtr->nNumStrings++;
2985 p += (len+1);
2988 if (fFirstString)
2989 TOOLBAR_CalcToolbar(hwnd);
2990 return nIndex;
2994 static LRESULT
2995 TOOLBAR_AutoSize (HWND hwnd)
2997 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2998 RECT parent_rect;
2999 HWND parent;
3000 INT x, y;
3001 INT cx, cy;
3003 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3005 parent = GetParent (hwnd);
3007 if (!parent || !infoPtr->bDoRedraw)
3008 return 0;
3010 GetClientRect(parent, &parent_rect);
3012 x = parent_rect.left;
3013 y = parent_rect.top;
3015 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3017 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3018 cx = parent_rect.right - parent_rect.left;
3020 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3022 TOOLBAR_LayoutToolbar(hwnd);
3023 InvalidateRect( hwnd, NULL, TRUE );
3026 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3028 RECT window_rect;
3029 UINT uPosFlags = SWP_NOZORDER;
3031 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3033 GetWindowRect(hwnd, &window_rect);
3034 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3035 y = window_rect.top;
3037 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3039 GetWindowRect(hwnd, &window_rect);
3040 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3043 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3044 uPosFlags |= SWP_NOMOVE;
3046 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3047 cy += GetSystemMetrics(SM_CYEDGE);
3049 if (infoPtr->dwStyle & WS_BORDER)
3051 x = y = 1; /* FIXME: this looks wrong */
3052 cy += GetSystemMetrics(SM_CYEDGE);
3053 cx += GetSystemMetrics(SM_CXEDGE);
3056 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3059 return 0;
3063 static LRESULT
3064 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3066 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3068 return infoPtr->nNumButtons;
3072 static LRESULT
3073 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3075 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3077 infoPtr->dwStructSize = (DWORD)wParam;
3079 return 0;
3083 static LRESULT
3084 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3086 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3087 TBUTTON_INFO *btnPtr;
3088 INT nIndex;
3090 TRACE("button %ld, iBitmap now %d\n", wParam, LOWORD(lParam));
3092 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3093 if (nIndex == -1)
3094 return FALSE;
3096 btnPtr = &infoPtr->buttons[nIndex];
3097 btnPtr->iBitmap = LOWORD(lParam);
3099 /* we HAVE to erase the background, the new bitmap could be */
3100 /* transparent */
3101 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3103 return TRUE;
3107 static LRESULT
3108 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3110 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3111 TBUTTON_INFO *btnPtr;
3112 INT nIndex;
3113 INT nOldIndex = -1;
3114 BOOL bChecked = FALSE;
3116 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3118 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3120 if (nIndex == -1)
3121 return FALSE;
3123 btnPtr = &infoPtr->buttons[nIndex];
3125 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3127 if (LOWORD(lParam) == FALSE)
3128 btnPtr->fsState &= ~TBSTATE_CHECKED;
3129 else {
3130 if (btnPtr->fsStyle & BTNS_GROUP) {
3131 nOldIndex =
3132 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3133 if (nOldIndex == nIndex)
3134 return 0;
3135 if (nOldIndex != -1)
3136 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3138 btnPtr->fsState |= TBSTATE_CHECKED;
3141 if( bChecked != LOWORD(lParam) )
3143 if (nOldIndex != -1)
3144 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3145 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3148 /* FIXME: Send a WM_NOTIFY?? */
3150 return TRUE;
3154 static LRESULT
3155 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3157 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3159 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3163 static LRESULT
3164 TOOLBAR_Customize (HWND hwnd)
3166 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3167 CUSTDLG_INFO custInfo;
3168 LRESULT ret;
3169 LPCVOID template;
3170 HRSRC hRes;
3171 NMHDR nmhdr;
3173 custInfo.tbInfo = infoPtr;
3174 custInfo.tbHwnd = hwnd;
3176 /* send TBN_BEGINADJUST notification */
3177 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3179 if (!(hRes = FindResourceW (COMCTL32_hModule,
3180 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3181 (LPWSTR)RT_DIALOG)))
3182 return FALSE;
3184 if(!(template = LoadResource (COMCTL32_hModule, hRes)))
3185 return FALSE;
3187 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3188 (LPCDLGTEMPLATEW)template,
3189 hwnd,
3190 TOOLBAR_CustomizeDialogProc,
3191 (LPARAM)&custInfo);
3193 /* send TBN_ENDADJUST notification */
3194 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3196 return ret;
3200 static LRESULT
3201 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3203 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3204 INT nIndex = (INT)wParam;
3205 NMTOOLBARW nmtb;
3206 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3208 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3209 return FALSE;
3211 memset(&nmtb, 0, sizeof(nmtb));
3212 nmtb.iItem = btnPtr->idCommand;
3213 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3214 nmtb.tbButton.idCommand = btnPtr->idCommand;
3215 nmtb.tbButton.fsState = btnPtr->fsState;
3216 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3217 nmtb.tbButton.dwData = btnPtr->dwData;
3218 nmtb.tbButton.iString = btnPtr->iString;
3219 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3221 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3223 if (infoPtr->nNumButtons == 1) {
3224 TRACE(" simple delete!\n");
3225 Free (infoPtr->buttons);
3226 infoPtr->buttons = NULL;
3227 infoPtr->nNumButtons = 0;
3229 else {
3230 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3231 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3233 infoPtr->nNumButtons--;
3234 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3235 if (nIndex > 0) {
3236 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3237 nIndex * sizeof(TBUTTON_INFO));
3240 if (nIndex < infoPtr->nNumButtons) {
3241 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3242 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3245 Free (oldButtons);
3248 TOOLBAR_LayoutToolbar(hwnd);
3250 InvalidateRect (hwnd, NULL, TRUE);
3252 return TRUE;
3256 static LRESULT
3257 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3259 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3260 TBUTTON_INFO *btnPtr;
3261 INT nIndex;
3262 DWORD bState;
3264 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3266 TRACE("hwnd=%p, btn index=%ld, lParam=0x%08lx\n", hwnd, wParam, lParam);
3268 if (nIndex == -1)
3269 return FALSE;
3271 btnPtr = &infoPtr->buttons[nIndex];
3273 bState = btnPtr->fsState & TBSTATE_ENABLED;
3275 /* update the toolbar button state */
3276 if(LOWORD(lParam) == FALSE) {
3277 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3278 } else {
3279 btnPtr->fsState |= TBSTATE_ENABLED;
3282 /* redraw the button only if the state of the button changed */
3283 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3284 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3286 return TRUE;
3290 static inline LRESULT
3291 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3293 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3295 return infoPtr->bAnchor;
3299 static LRESULT
3300 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3302 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3303 INT nIndex;
3305 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3306 if (nIndex == -1)
3307 return -1;
3309 return infoPtr->buttons[nIndex].iBitmap;
3313 static inline LRESULT
3314 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3316 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3320 static LRESULT
3321 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3323 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3324 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3325 INT nIndex = (INT)wParam;
3326 TBUTTON_INFO *btnPtr;
3328 if (lpTbb == NULL)
3329 return FALSE;
3331 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3332 return FALSE;
3334 btnPtr = &infoPtr->buttons[nIndex];
3335 lpTbb->iBitmap = btnPtr->iBitmap;
3336 lpTbb->idCommand = btnPtr->idCommand;
3337 lpTbb->fsState = btnPtr->fsState;
3338 lpTbb->fsStyle = btnPtr->fsStyle;
3339 lpTbb->bReserved[0] = 0;
3340 lpTbb->bReserved[1] = 0;
3341 lpTbb->dwData = btnPtr->dwData;
3342 lpTbb->iString = btnPtr->iString;
3344 return TRUE;
3348 static LRESULT
3349 TOOLBAR_GetButtonInfoT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL bUnicode)
3351 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3352 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3353 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3354 TBUTTON_INFO *btnPtr;
3355 INT nIndex;
3357 if (lpTbInfo == NULL)
3358 return -1;
3360 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3361 * the headers and tests shows that even with comctl 6 Vista accepts only the
3362 * original TBBUTTONINFO size
3364 if (lpTbInfo->cbSize != sizeof(TBBUTTONINFOW))
3366 WARN("Invalid button size\n");
3367 return -1;
3370 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3371 lpTbInfo->dwMask & 0x80000000);
3372 if (nIndex == -1)
3373 return -1;
3375 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3377 if (lpTbInfo->dwMask & TBIF_COMMAND)
3378 lpTbInfo->idCommand = btnPtr->idCommand;
3379 if (lpTbInfo->dwMask & TBIF_IMAGE)
3380 lpTbInfo->iImage = btnPtr->iBitmap;
3381 if (lpTbInfo->dwMask & TBIF_LPARAM)
3382 lpTbInfo->lParam = btnPtr->dwData;
3383 if (lpTbInfo->dwMask & TBIF_SIZE)
3384 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3385 if (lpTbInfo->dwMask & TBIF_STATE)
3386 lpTbInfo->fsState = btnPtr->fsState;
3387 if (lpTbInfo->dwMask & TBIF_STYLE)
3388 lpTbInfo->fsStyle = btnPtr->fsStyle;
3389 if (lpTbInfo->dwMask & TBIF_TEXT) {
3390 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3391 can't use TOOLBAR_GetText here */
3392 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3393 LPWSTR lpText = (LPWSTR)btnPtr->iString;
3394 if (bUnicode)
3395 Str_GetPtrW(lpText, lpTbInfo->pszText, lpTbInfo->cchText);
3396 else
3397 Str_GetPtrWtoA(lpText, (LPSTR)lpTbInfo->pszText, lpTbInfo->cchText);
3398 } else
3399 lpTbInfo->pszText[0] = '\0';
3401 return nIndex;
3405 static LRESULT
3406 TOOLBAR_GetButtonSize (HWND hwnd)
3408 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3410 return MAKELONG((WORD)infoPtr->nButtonWidth,
3411 (WORD)infoPtr->nButtonHeight);
3415 static LRESULT
3416 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3418 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3419 INT nIndex;
3420 LPWSTR lpText;
3422 if (lParam == 0)
3423 return -1;
3425 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3426 if (nIndex == -1)
3427 return -1;
3429 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3431 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3432 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3436 static LRESULT
3437 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3439 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3440 INT nIndex;
3441 LPWSTR lpText;
3442 LRESULT ret = 0;
3444 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3445 if (nIndex == -1)
3446 return -1;
3448 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3450 if (lpText)
3452 ret = strlenW (lpText);
3454 if (lParam)
3455 strcpyW ((LPWSTR)lParam, lpText);
3458 return ret;
3462 static LRESULT
3463 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3465 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3466 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3467 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3471 static inline LRESULT
3472 TOOLBAR_GetExtendedStyle (HWND hwnd)
3474 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3476 TRACE("\n");
3478 return infoPtr->dwExStyle;
3482 static LRESULT
3483 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3485 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3486 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3487 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3491 static LRESULT
3492 TOOLBAR_GetHotItem (HWND hwnd)
3494 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3496 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3497 return -1;
3499 if (infoPtr->nHotItem < 0)
3500 return -1;
3502 return (LRESULT)infoPtr->nHotItem;
3506 static LRESULT
3507 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3509 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3510 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3511 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3515 static LRESULT
3516 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3518 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3519 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3521 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3523 *lptbim = infoPtr->tbim;
3525 return 0;
3529 static LRESULT
3530 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3532 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3534 TRACE("hwnd = %p\n", hwnd);
3536 return (LRESULT)infoPtr->clrInsertMark;
3540 static LRESULT
3541 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3543 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3544 TBUTTON_INFO *btnPtr;
3545 LPRECT lpRect;
3546 INT nIndex;
3548 nIndex = (INT)wParam;
3549 btnPtr = &infoPtr->buttons[nIndex];
3550 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3551 return FALSE;
3552 lpRect = (LPRECT)lParam;
3553 if (lpRect == NULL)
3554 return FALSE;
3555 if (btnPtr->fsState & TBSTATE_HIDDEN)
3556 return FALSE;
3558 lpRect->left = btnPtr->rect.left;
3559 lpRect->right = btnPtr->rect.right;
3560 lpRect->bottom = btnPtr->rect.bottom;
3561 lpRect->top = btnPtr->rect.top;
3563 return TRUE;
3567 static LRESULT
3568 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3570 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3571 LPSIZE lpSize = (LPSIZE)lParam;
3573 if (lpSize == NULL)
3574 return FALSE;
3576 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3577 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3579 TRACE("maximum size %d x %d\n",
3580 infoPtr->rcBound.right - infoPtr->rcBound.left,
3581 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3583 return TRUE;
3587 /* << TOOLBAR_GetObject >> */
3590 static LRESULT
3591 TOOLBAR_GetPadding (HWND hwnd)
3593 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3594 DWORD oldPad;
3596 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3597 return (LRESULT) oldPad;
3601 static LRESULT
3602 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3604 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3605 TBUTTON_INFO *btnPtr;
3606 LPRECT lpRect;
3607 INT nIndex;
3609 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3610 btnPtr = &infoPtr->buttons[nIndex];
3611 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3612 return FALSE;
3613 lpRect = (LPRECT)lParam;
3614 if (lpRect == NULL)
3615 return FALSE;
3617 lpRect->left = btnPtr->rect.left;
3618 lpRect->right = btnPtr->rect.right;
3619 lpRect->bottom = btnPtr->rect.bottom;
3620 lpRect->top = btnPtr->rect.top;
3622 return TRUE;
3626 static LRESULT
3627 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3629 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3631 return infoPtr->nRows;
3635 static LRESULT
3636 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3638 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3639 INT nIndex;
3641 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3642 if (nIndex == -1)
3643 return -1;
3645 return infoPtr->buttons[nIndex].fsState;
3649 static LRESULT
3650 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3652 return GetWindowLongW(hwnd, GWL_STYLE);
3656 static LRESULT
3657 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3659 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3661 return infoPtr->nMaxTextRows;
3665 static LRESULT
3666 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3668 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3670 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3671 TOOLBAR_TooltipCreateControl(infoPtr);
3672 return (LRESULT)infoPtr->hwndToolTip;
3676 static LRESULT
3677 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3679 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3681 TRACE("%s hwnd=%p\n",
3682 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3684 return infoPtr->bUnicode;
3688 static inline LRESULT
3689 TOOLBAR_GetVersion (HWND hwnd)
3691 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3692 return infoPtr->iVersion;
3696 static LRESULT
3697 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3699 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3700 TBUTTON_INFO *btnPtr;
3701 INT nIndex;
3703 TRACE("\n");
3705 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3706 if (nIndex == -1)
3707 return FALSE;
3709 btnPtr = &infoPtr->buttons[nIndex];
3710 if (LOWORD(lParam) == FALSE)
3711 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3712 else
3713 btnPtr->fsState |= TBSTATE_HIDDEN;
3715 TOOLBAR_LayoutToolbar (hwnd);
3717 InvalidateRect (hwnd, NULL, TRUE);
3719 return TRUE;
3723 static inline LRESULT
3724 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3726 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3730 static LRESULT
3731 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3733 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3734 TBUTTON_INFO *btnPtr;
3735 INT nIndex;
3736 DWORD oldState;
3738 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3739 if (nIndex == -1)
3740 return FALSE;
3742 btnPtr = &infoPtr->buttons[nIndex];
3743 oldState = btnPtr->fsState;
3744 if (LOWORD(lParam) == FALSE)
3745 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3746 else
3747 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3749 if(oldState != btnPtr->fsState)
3750 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3752 return TRUE;
3756 static LRESULT
3757 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3759 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3760 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3761 INT nIndex = (INT)wParam;
3763 if (lpTbb == NULL)
3764 return FALSE;
3766 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3768 if (nIndex == -1) {
3769 /* EPP: this seems to be an undocumented call (from my IE4)
3770 * I assume in that case that:
3771 * - index of insertion is at the end of existing buttons
3772 * I only see this happen with nIndex == -1, but it could have a special
3773 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3775 nIndex = infoPtr->nNumButtons;
3777 } else if (nIndex < 0)
3778 return FALSE;
3780 TRACE("inserting button index=%d\n", nIndex);
3781 if (nIndex > infoPtr->nNumButtons) {
3782 nIndex = infoPtr->nNumButtons;
3783 TRACE("adjust index=%d\n", nIndex);
3786 infoPtr->nNumButtons++;
3787 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO) * infoPtr->nNumButtons);
3788 memmove(&infoPtr->buttons[nIndex+1], &infoPtr->buttons[nIndex],
3789 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3791 /* insert new button */
3792 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3793 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3794 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3795 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3796 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3797 /* if passed string and not index, then add string */
3798 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3799 if (fUnicode)
3800 Str_SetPtrW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3801 else
3802 Str_SetPtrAtoW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3804 else
3805 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3807 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
3809 if (infoPtr->nNumStrings > 0)
3810 TOOLBAR_CalcToolbar(hwnd);
3811 else
3812 TOOLBAR_LayoutToolbar(hwnd);
3813 TOOLBAR_AutoSize (hwnd);
3815 InvalidateRect (hwnd, NULL, TRUE);
3817 return TRUE;
3820 /* << TOOLBAR_InsertMarkHitTest >> */
3823 static LRESULT
3824 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3826 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3827 INT nIndex;
3829 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3830 if (nIndex == -1)
3831 return -1;
3833 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3837 static LRESULT
3838 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3840 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3841 INT nIndex;
3843 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3844 if (nIndex == -1)
3845 return -1;
3847 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3851 static LRESULT
3852 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3854 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3855 INT nIndex;
3857 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3858 if (nIndex == -1)
3859 return -1;
3861 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3865 static LRESULT
3866 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3868 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3869 INT nIndex;
3871 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3872 if (nIndex == -1)
3873 return -1;
3875 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3879 static LRESULT
3880 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3882 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3883 INT nIndex;
3885 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3886 if (nIndex == -1)
3887 return -1;
3889 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3893 static LRESULT
3894 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3896 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3897 INT nIndex;
3899 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3900 if (nIndex == -1)
3901 return -1;
3903 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3907 static LRESULT
3908 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3910 TBADDBITMAP tbab;
3911 tbab.hInst = (HINSTANCE)lParam;
3912 tbab.nID = wParam;
3914 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", hwnd, tbab.hInst, tbab.nID);
3916 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3920 static LRESULT
3921 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3923 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3924 WCHAR wAccel = (WCHAR)wParam;
3925 UINT* pIDButton = (UINT*)lParam;
3926 WCHAR wszAccel[] = {'&',wAccel,0};
3927 int i;
3929 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3930 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3932 for (i = 0; i < infoPtr->nNumButtons; i++)
3934 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3935 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3936 !(btnPtr->fsState & TBSTATE_HIDDEN))
3938 int iLen = strlenW(wszAccel);
3939 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3941 if (!lpszStr)
3942 continue;
3944 while (*lpszStr)
3946 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3948 lpszStr += 2;
3949 continue;
3951 if (!strncmpiW(lpszStr, wszAccel, iLen))
3953 *pIDButton = btnPtr->idCommand;
3954 return TRUE;
3956 lpszStr++;
3960 return FALSE;
3964 static LRESULT
3965 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3967 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3968 INT nIndex;
3969 DWORD oldState;
3970 TBUTTON_INFO *btnPtr;
3972 TRACE("hwnd = %p, wParam = %ld, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3974 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3975 if (nIndex == -1)
3976 return FALSE;
3978 btnPtr = &infoPtr->buttons[nIndex];
3979 oldState = btnPtr->fsState;
3981 if (LOWORD(lParam))
3982 btnPtr->fsState |= TBSTATE_MARKED;
3983 else
3984 btnPtr->fsState &= ~TBSTATE_MARKED;
3986 if(oldState != btnPtr->fsState)
3987 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3989 return TRUE;
3993 /* fixes up an index of a button affected by a move */
3994 static inline void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
3996 if (bMoveUp)
3998 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
3999 (*pIndex)--;
4000 else if (*pIndex == nIndex)
4001 *pIndex = nMoveIndex;
4003 else
4005 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4006 (*pIndex)++;
4007 else if (*pIndex == nIndex)
4008 *pIndex = nMoveIndex;
4013 static LRESULT
4014 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4016 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4017 INT nIndex;
4018 INT nCount;
4019 INT nMoveIndex = (INT)lParam;
4020 TBUTTON_INFO button;
4022 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
4024 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4025 if ((nIndex == -1) || (nMoveIndex < 0))
4026 return FALSE;
4028 if (nMoveIndex > infoPtr->nNumButtons - 1)
4029 nMoveIndex = infoPtr->nNumButtons - 1;
4031 button = infoPtr->buttons[nIndex];
4033 /* move button right */
4034 if (nIndex < nMoveIndex)
4036 nCount = nMoveIndex - nIndex;
4037 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4038 infoPtr->buttons[nMoveIndex] = button;
4040 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4041 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4042 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4043 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4045 else if (nIndex > nMoveIndex) /* move button left */
4047 nCount = nIndex - nMoveIndex;
4048 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4049 infoPtr->buttons[nMoveIndex] = button;
4051 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4052 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4053 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4054 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4057 TOOLBAR_LayoutToolbar(hwnd);
4058 TOOLBAR_AutoSize(hwnd);
4059 InvalidateRect(hwnd, NULL, TRUE);
4061 return TRUE;
4065 static LRESULT
4066 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4068 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4069 TBUTTON_INFO *btnPtr;
4070 INT nIndex;
4071 DWORD oldState;
4073 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4074 if (nIndex == -1)
4075 return FALSE;
4077 btnPtr = &infoPtr->buttons[nIndex];
4078 oldState = btnPtr->fsState;
4079 if (LOWORD(lParam) == FALSE)
4080 btnPtr->fsState &= ~TBSTATE_PRESSED;
4081 else
4082 btnPtr->fsState |= TBSTATE_PRESSED;
4084 if(oldState != btnPtr->fsState)
4085 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4087 return TRUE;
4090 /* FIXME: there might still be some confusion her between number of buttons
4091 * and number of bitmaps */
4092 static LRESULT
4093 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4095 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4096 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4097 HBITMAP hBitmap;
4098 int i = 0, nOldButtons = 0, pos = 0;
4099 int nOldBitmaps, nNewBitmaps = 0;
4100 HIMAGELIST himlDef = 0;
4102 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4103 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4104 lpReplace->nButtons);
4106 if (lpReplace->hInstOld == HINST_COMMCTRL)
4108 FIXME("changing standard bitmaps not implemented\n");
4109 return FALSE;
4111 else if (lpReplace->hInstOld != 0)
4112 FIXME("resources not in the current module not implemented\n");
4114 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4115 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4116 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4117 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4118 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4120 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4121 nOldButtons = tbi->nButtons;
4122 tbi->nButtons = lpReplace->nButtons;
4123 tbi->hInst = lpReplace->hInstNew;
4124 tbi->nID = lpReplace->nIDNew;
4125 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4126 break;
4128 pos += tbi->nButtons;
4131 if (nOldButtons == 0)
4133 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4134 return FALSE;
4137 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4138 * bitmap
4140 if (lpReplace->hInstNew)
4141 hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4142 else
4143 hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
4145 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4146 nOldBitmaps = ImageList_GetImageCount(himlDef);
4148 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4150 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4151 ImageList_Remove(himlDef, i);
4153 if (hBitmap)
4155 ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
4156 nNewBitmaps = ImageList_GetImageCount(himlDef);
4157 DeleteObject(hBitmap);
4160 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4162 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4163 pos, nOldBitmaps, nNewBitmaps);
4165 InvalidateRect(hwnd, NULL, TRUE);
4166 return TRUE;
4170 /* helper for TOOLBAR_SaveRestoreW */
4171 static BOOL
4172 TOOLBAR_Save(const TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
4174 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4175 debugstr_w(lpSave->pszValueName));
4177 return FALSE;
4181 /* helper for TOOLBAR_Restore */
4182 static void
4183 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4185 INT i;
4187 for (i = 0; i < infoPtr->nNumButtons; i++)
4189 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4192 Free(infoPtr->buttons);
4193 infoPtr->buttons = NULL;
4194 infoPtr->nNumButtons = 0;
4198 /* helper for TOOLBAR_SaveRestoreW */
4199 static BOOL
4200 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
4202 LONG res;
4203 HKEY hkey = NULL;
4204 BOOL ret = FALSE;
4205 DWORD dwType;
4206 DWORD dwSize = 0;
4207 NMTBRESTORE nmtbr;
4209 /* restore toolbar information */
4210 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4211 debugstr_w(lpSave->pszValueName));
4213 memset(&nmtbr, 0, sizeof(nmtbr));
4215 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4216 KEY_QUERY_VALUE, &hkey);
4217 if (!res)
4218 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4219 NULL, &dwSize);
4220 if (!res && dwType != REG_BINARY)
4221 res = ERROR_FILE_NOT_FOUND;
4222 if (!res)
4224 nmtbr.pData = Alloc(dwSize);
4225 nmtbr.cbData = dwSize;
4226 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4228 if (!res)
4229 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4230 (LPBYTE)nmtbr.pData, &dwSize);
4231 if (!res)
4233 nmtbr.pCurrent = nmtbr.pData;
4234 nmtbr.iItem = -1;
4235 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4236 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4238 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4240 INT i;
4242 /* remove all existing buttons as this function is designed to
4243 * restore the toolbar to a previously saved state */
4244 TOOLBAR_DeleteAllButtons(infoPtr);
4246 for (i = 0; i < nmtbr.cButtons; i++)
4248 nmtbr.iItem = i;
4249 nmtbr.tbButton.iBitmap = -1;
4250 nmtbr.tbButton.fsState = 0;
4251 nmtbr.tbButton.fsStyle = 0;
4252 nmtbr.tbButton.idCommand = 0;
4253 if (*nmtbr.pCurrent == (DWORD)-1)
4255 /* separator */
4256 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4257 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4259 else if (*nmtbr.pCurrent == (DWORD)-2)
4260 /* hidden button */
4261 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4262 else
4263 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4265 nmtbr.pCurrent++;
4267 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4269 /* can't contain real string as we don't know whether
4270 * the client put an ANSI or Unicode string in there */
4271 if (HIWORD(nmtbr.tbButton.iString))
4272 nmtbr.tbButton.iString = 0;
4274 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4275 (LPARAM)&nmtbr.tbButton, TRUE);
4278 /* do legacy notifications */
4279 if (infoPtr->iVersion < 5)
4281 /* FIXME: send TBN_BEGINADJUST */
4282 FIXME("send TBN_GETBUTTONINFO for each button\n");
4283 /* FIXME: send TBN_ENDADJUST */
4286 /* remove all uninitialised buttons
4287 * note: loop backwards to avoid having to fixup i on a
4288 * delete */
4289 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4290 if (infoPtr->buttons[i].iBitmap == -1)
4291 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4293 /* only indicate success if at least one button survived */
4294 if (infoPtr->nNumButtons > 0) ret = TRUE;
4297 Free (nmtbr.pData);
4298 RegCloseKey(hkey);
4300 return ret;
4304 static LRESULT
4305 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, const TBSAVEPARAMSW *lpSave)
4307 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4309 if (lpSave == NULL) return 0;
4311 if (wParam)
4312 return TOOLBAR_Save(infoPtr, lpSave);
4313 else
4314 return TOOLBAR_Restore(infoPtr, lpSave);
4318 static LRESULT
4319 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, const TBSAVEPARAMSA *lpSave)
4321 LPWSTR pszValueName = 0, pszSubKey = 0;
4322 TBSAVEPARAMSW SaveW;
4323 LRESULT result = 0;
4324 int len;
4326 if (lpSave == NULL) return 0;
4328 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4329 pszSubKey = Alloc(len * sizeof(WCHAR));
4330 if (pszSubKey) goto exit;
4331 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4333 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4334 pszValueName = Alloc(len * sizeof(WCHAR));
4335 if (!pszValueName) goto exit;
4336 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4338 SaveW.pszValueName = pszValueName;
4339 SaveW.pszSubKey = pszSubKey;
4340 SaveW.hkr = lpSave->hkr;
4341 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4343 exit:
4344 Free (pszValueName);
4345 Free (pszSubKey);
4347 return result;
4351 static LRESULT
4352 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4354 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4355 BOOL bOldAnchor = infoPtr->bAnchor;
4357 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4359 infoPtr->bAnchor = (BOOL)wParam;
4361 /* Native does not remove the hot effect from an already hot button */
4363 return (LRESULT)bOldAnchor;
4367 static LRESULT
4368 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4370 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4371 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4372 short width = (short)LOWORD(lParam);
4373 short height = (short)HIWORD(lParam);
4375 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
4377 if (wParam != 0)
4378 FIXME("wParam is %ld. Perhaps image list index?\n", wParam);
4380 /* 0 width or height is changed to 1 */
4381 if (width == 0)
4382 width = 1;
4383 if (height == 0)
4384 height = 1;
4386 if (infoPtr->nNumButtons > 0)
4387 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4388 infoPtr->nNumButtons,
4389 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight, width, height);
4391 if (width < -1 || height < -1)
4393 /* Windows destroys the imagelist and seems to actually use negative
4394 * values to compute button sizes */
4395 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width, height);
4396 return FALSE;
4399 /* width or height of -1 means no change */
4400 if (width != -1)
4401 infoPtr->nBitmapWidth = width;
4402 if (height != -1)
4403 infoPtr->nBitmapHeight = height;
4405 if ((himlDef == infoPtr->himlInt) &&
4406 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4408 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4409 infoPtr->nBitmapHeight);
4412 TOOLBAR_CalcToolbar(hwnd);
4413 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4414 return TRUE;
4418 static LRESULT
4419 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4421 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4422 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4423 TBUTTON_INFO *btnPtr;
4424 INT nIndex;
4425 RECT oldBtnRect;
4427 if (lptbbi == NULL)
4428 return FALSE;
4429 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4430 return FALSE;
4432 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4433 lptbbi->dwMask & 0x80000000);
4434 if (nIndex == -1)
4435 return FALSE;
4437 btnPtr = &infoPtr->buttons[nIndex];
4438 if (lptbbi->dwMask & TBIF_COMMAND)
4439 btnPtr->idCommand = lptbbi->idCommand;
4440 if (lptbbi->dwMask & TBIF_IMAGE)
4441 btnPtr->iBitmap = lptbbi->iImage;
4442 if (lptbbi->dwMask & TBIF_LPARAM)
4443 btnPtr->dwData = lptbbi->lParam;
4444 if (lptbbi->dwMask & TBIF_SIZE)
4445 btnPtr->cx = lptbbi->cx;
4446 if (lptbbi->dwMask & TBIF_STATE)
4447 btnPtr->fsState = lptbbi->fsState;
4448 if (lptbbi->dwMask & TBIF_STYLE)
4449 btnPtr->fsStyle = lptbbi->fsStyle;
4451 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4452 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4453 /* iString is index, zero it to make Str_SetPtr succeed */
4454 btnPtr->iString=0;
4456 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4459 /* save the button rect to see if we need to redraw the whole toolbar */
4460 oldBtnRect = btnPtr->rect;
4461 TOOLBAR_CalcToolbar(hwnd);
4463 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4464 InvalidateRect(hwnd, NULL, TRUE);
4465 else
4466 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4468 return TRUE;
4472 static LRESULT
4473 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4475 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4476 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4477 TBUTTON_INFO *btnPtr;
4478 INT nIndex;
4479 RECT oldBtnRect;
4481 if (lptbbi == NULL)
4482 return FALSE;
4483 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4484 return FALSE;
4486 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4487 lptbbi->dwMask & 0x80000000);
4488 if (nIndex == -1)
4489 return FALSE;
4491 btnPtr = &infoPtr->buttons[nIndex];
4492 if (lptbbi->dwMask & TBIF_COMMAND)
4493 btnPtr->idCommand = lptbbi->idCommand;
4494 if (lptbbi->dwMask & TBIF_IMAGE)
4495 btnPtr->iBitmap = lptbbi->iImage;
4496 if (lptbbi->dwMask & TBIF_LPARAM)
4497 btnPtr->dwData = lptbbi->lParam;
4498 if (lptbbi->dwMask & TBIF_SIZE)
4499 btnPtr->cx = lptbbi->cx;
4500 if (lptbbi->dwMask & TBIF_STATE)
4501 btnPtr->fsState = lptbbi->fsState;
4502 if (lptbbi->dwMask & TBIF_STYLE)
4503 btnPtr->fsStyle = lptbbi->fsStyle;
4505 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4506 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4507 /* iString is index, zero it to make Str_SetPtr succeed */
4508 btnPtr->iString=0;
4509 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4512 /* save the button rect to see if we need to redraw the whole toolbar */
4513 oldBtnRect = btnPtr->rect;
4514 TOOLBAR_CalcToolbar(hwnd);
4516 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4517 InvalidateRect(hwnd, NULL, TRUE);
4518 else
4519 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4521 return TRUE;
4525 static LRESULT
4526 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4528 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4529 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4531 if ((cx < 0) || (cy < 0))
4533 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4534 return FALSE;
4537 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4539 /* The documentation claims you can only change the button size before
4540 * any button has been added. But this is wrong.
4541 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4542 * it to the toolbar, and it checks that the return value is nonzero - mjm
4543 * Further testing shows that we must actually perform the change too.
4546 * The documentation also does not mention that if 0 is supplied for
4547 * either size, the system changes it to the default of 24 wide and
4548 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4550 if (cx == 0) cx = 24;
4551 if (cy == 0) cx = 22;
4553 cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
4554 cy = max(cy, infoPtr->szPadding.cy + infoPtr->nBitmapHeight);
4556 infoPtr->nButtonWidth = cx;
4557 infoPtr->nButtonHeight = cy;
4559 infoPtr->iTopMargin = default_top_margin(infoPtr);
4560 TOOLBAR_LayoutToolbar(hwnd);
4561 return TRUE;
4565 static LRESULT
4566 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4568 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4570 /* if setting to current values, ignore */
4571 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4572 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4573 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4574 infoPtr->cxMin, infoPtr->cxMax);
4575 return TRUE;
4578 /* save new values */
4579 infoPtr->cxMin = (short)LOWORD(lParam);
4580 infoPtr->cxMax = (short)HIWORD(lParam);
4582 /* otherwise we need to recalc the toolbar and in some cases
4583 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4584 which doesn't actually draw - GA). */
4585 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4586 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4588 TOOLBAR_CalcToolbar (hwnd);
4590 InvalidateRect (hwnd, NULL, TRUE);
4592 return TRUE;
4596 static LRESULT
4597 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4599 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4600 INT nIndex = (INT)wParam;
4602 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4603 return FALSE;
4605 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4607 if (infoPtr->hwndToolTip) {
4609 FIXME("change tool tip!\n");
4613 return TRUE;
4617 static LRESULT
4618 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4620 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4621 HIMAGELIST himl = (HIMAGELIST)lParam;
4622 HIMAGELIST himlTemp;
4623 INT id = 0;
4625 if (infoPtr->iVersion >= 5)
4626 id = wParam;
4628 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4629 &infoPtr->cimlDis, himl, id);
4631 /* FIXME: redraw ? */
4633 return (LRESULT)himlTemp;
4637 static LRESULT
4638 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4640 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4641 DWORD dwTemp;
4643 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4645 dwTemp = infoPtr->dwDTFlags;
4646 infoPtr->dwDTFlags =
4647 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4649 return (LRESULT)dwTemp;
4652 /* This function differs a bit from what MSDN says it does:
4653 * 1. lParam contains extended style flags to OR with current style
4654 * (MSDN isn't clear on the OR bit)
4655 * 2. wParam appears to contain extended style flags to be reset
4656 * (MSDN says that this parameter is reserved)
4658 static LRESULT
4659 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4661 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4662 DWORD dwTemp;
4664 dwTemp = infoPtr->dwExStyle;
4665 infoPtr->dwExStyle &= ~wParam;
4666 infoPtr->dwExStyle |= (DWORD)lParam;
4668 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4670 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4671 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4672 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4674 TOOLBAR_CalcToolbar (hwnd);
4676 TOOLBAR_AutoSize(hwnd);
4678 InvalidateRect(hwnd, NULL, TRUE);
4680 return (LRESULT)dwTemp;
4684 static LRESULT
4685 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4687 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4688 HIMAGELIST himlTemp;
4689 HIMAGELIST himl = (HIMAGELIST)lParam;
4690 INT id = 0;
4692 if (infoPtr->iVersion >= 5)
4693 id = wParam;
4695 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4697 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4698 &infoPtr->cimlHot, himl, id);
4700 /* FIXME: redraw ? */
4702 return (LRESULT)himlTemp;
4706 /* Makes previous hot button no longer hot, makes the specified
4707 * button hot and sends appropriate notifications. dwReason is one or
4708 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4709 * NOTE 1: this function does not validate nHit
4710 * NOTE 2: the name of this function is completely made up and
4711 * not based on any documentation from Microsoft. */
4712 static void
4713 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4715 if (infoPtr->nHotItem != nHit)
4717 NMTBHOTITEM nmhotitem;
4718 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4720 nmhotitem.dwFlags = dwReason;
4721 if(infoPtr->nHotItem >= 0)
4723 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4724 nmhotitem.idOld = oldBtnPtr->idCommand;
4726 else
4728 nmhotitem.dwFlags |= HICF_ENTERING;
4729 nmhotitem.idOld = 0;
4732 if (nHit >= 0)
4734 btnPtr = &infoPtr->buttons[nHit];
4735 nmhotitem.idNew = btnPtr->idCommand;
4737 else
4739 nmhotitem.dwFlags |= HICF_LEAVING;
4740 nmhotitem.idNew = 0;
4743 /* now change the hot and invalidate the old and new buttons - if the
4744 * parent agrees */
4745 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4747 if (oldBtnPtr) {
4748 oldBtnPtr->bHot = FALSE;
4749 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4751 /* setting disabled buttons as hot fails even if the notify contains the button id */
4752 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4753 btnPtr->bHot = TRUE;
4754 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4755 infoPtr->nHotItem = nHit;
4757 else
4758 infoPtr->nHotItem = -1;
4763 static LRESULT
4764 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4766 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4767 INT nOldHotItem = infoPtr->nHotItem;
4769 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4771 if ((INT)wParam >= infoPtr->nNumButtons)
4772 return infoPtr->nHotItem;
4774 if ((INT)wParam < 0)
4775 wParam = -1;
4777 /* NOTE: an application can still remove the hot item even if anchor
4778 * highlighting is enabled */
4780 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4782 if (nOldHotItem < 0)
4783 return -1;
4785 return (LRESULT)nOldHotItem;
4789 static LRESULT
4790 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4792 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4793 HIMAGELIST himlTemp;
4794 HIMAGELIST himl = (HIMAGELIST)lParam;
4795 INT oldButtonWidth = infoPtr->nButtonWidth;
4796 INT i, id = 0;
4798 if (infoPtr->iVersion >= 5)
4799 id = wParam;
4801 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4802 &infoPtr->cimlDef, himl, id);
4804 infoPtr->nNumBitmaps = 0;
4805 for (i = 0; i < infoPtr->cimlDef; i++)
4806 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4808 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4809 &infoPtr->nBitmapHeight))
4811 infoPtr->nBitmapWidth = 1;
4812 infoPtr->nBitmapHeight = 1;
4814 TOOLBAR_CalcToolbar(hwnd);
4815 if (infoPtr->nButtonWidth < oldButtonWidth)
4816 TOOLBAR_SetButtonSize(hwnd, 0, MAKELONG(oldButtonWidth, infoPtr->nButtonHeight));
4818 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4819 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4820 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4822 InvalidateRect(hwnd, NULL, TRUE);
4824 return (LRESULT)himlTemp;
4828 static LRESULT
4829 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4831 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4833 infoPtr->nIndent = (INT)wParam;
4835 TRACE("\n");
4837 /* process only on indent changing */
4838 if(infoPtr->nIndent != (INT)wParam)
4840 infoPtr->nIndent = (INT)wParam;
4841 TOOLBAR_CalcToolbar (hwnd);
4842 InvalidateRect(hwnd, NULL, FALSE);
4845 return TRUE;
4849 static LRESULT
4850 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4852 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4853 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4855 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4857 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4859 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4860 return 0;
4863 if ((lptbim->iButton == -1) ||
4864 ((lptbim->iButton < infoPtr->nNumButtons) &&
4865 (lptbim->iButton >= 0)))
4867 infoPtr->tbim = *lptbim;
4868 /* FIXME: don't need to update entire toolbar */
4869 InvalidateRect(hwnd, NULL, TRUE);
4871 else
4872 ERR("Invalid button index %d\n", lptbim->iButton);
4874 return 0;
4878 static LRESULT
4879 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4881 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4883 infoPtr->clrInsertMark = (COLORREF)lParam;
4885 /* FIXME: don't need to update entire toolbar */
4886 InvalidateRect(hwnd, NULL, TRUE);
4888 return 0;
4892 static LRESULT
4893 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4895 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4897 infoPtr->nMaxTextRows = (INT)wParam;
4899 TOOLBAR_CalcToolbar(hwnd);
4900 return TRUE;
4904 /* MSDN gives slightly wrong info on padding.
4905 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4906 * 2. It is not used to create a blank area between the edge of the button
4907 * and the text or image if TBSTYLE_LIST is set. It is used to control
4908 * the gap between the image and text.
4909 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4910 * to control the bottom and right borders [with the border being
4911 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4912 * is shared evenly on both sides of the button.
4913 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4915 static LRESULT
4916 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4918 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4919 DWORD oldPad;
4921 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4922 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4923 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4924 TRACE("cx=%d, cy=%d\n",
4925 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4926 return (LRESULT) oldPad;
4930 static LRESULT
4931 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4933 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4934 HWND hwndOldNotify;
4936 TRACE("\n");
4938 hwndOldNotify = infoPtr->hwndNotify;
4939 infoPtr->hwndNotify = (HWND)wParam;
4941 return (LRESULT)hwndOldNotify;
4945 static LRESULT
4946 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4948 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4949 LPRECT lprc = (LPRECT)lParam;
4950 int rows = LOWORD(wParam);
4951 BOOL bLarger = HIWORD(wParam);
4953 TRACE("\n");
4955 TRACE("Setting rows to %d (%d)\n", rows, bLarger);
4957 if(infoPtr->nRows != rows)
4959 TBUTTON_INFO *btnPtr = infoPtr->buttons;
4960 int curColumn = 0; /* Current column */
4961 int curRow = 0; /* Current row */
4962 int hidden = 0; /* Number of hidden buttons */
4963 int seps = 0; /* Number of separators */
4964 int idealWrap = 0; /* Ideal wrap point */
4965 int i;
4966 BOOL wrap;
4969 Calculate new size and wrap points - Under windows, setrows will
4970 change the dimensions if needed to show the number of requested
4971 rows (if CCS_NORESIZE is set), or will take up the whole window
4972 (if no CCS_NORESIZE).
4974 Basic algorithm - If N buttons, and y rows requested, each row
4975 contains N/y buttons.
4977 FIXME: Handling of separators not obvious from testing results
4978 FIXME: Take width of window into account?
4981 /* Loop through the buttons one by one counting key items */
4982 for (i = 0; i < infoPtr->nNumButtons; i++ )
4984 btnPtr[i].fsState &= ~TBSTATE_WRAP;
4985 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
4986 hidden++;
4987 else if (btnPtr[i].fsStyle & BTNS_SEP)
4988 seps++;
4991 /* FIXME: Separators make this quite complex */
4992 if (seps) FIXME("Separators unhandled\n");
4994 /* Round up so more per line, i.e., less rows */
4995 idealWrap = (infoPtr->nNumButtons - hidden + (rows-1)) / rows;
4997 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4998 achieve the requested number of rows. */
4999 if (bLarger && idealWrap > 1)
5001 int resRows = (infoPtr->nNumButtons + (idealWrap-1)) / idealWrap;
5002 int moreRows = (infoPtr->nNumButtons + (idealWrap-2)) / (idealWrap-1);
5004 if (resRows < rows && moreRows > rows)
5006 idealWrap--;
5007 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap);
5011 curColumn = curRow = 0;
5012 wrap = FALSE;
5013 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap,
5014 infoPtr->nNumButtons, hidden, rows);
5016 for (i = 0; i < infoPtr->nNumButtons; i++ )
5018 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
5019 continue;
5021 /* Step on, wrap if necessary or flag next to wrap */
5022 if (!wrap) {
5023 curColumn++;
5024 } else {
5025 wrap = FALSE;
5026 curColumn = 1;
5027 curRow++;
5030 if (curColumn > (idealWrap-1)) {
5031 wrap = TRUE;
5032 btnPtr[i].fsState |= TBSTATE_WRAP;
5036 TRACE("Result - %d rows\n", curRow + 1);
5038 /* recalculate toolbar */
5039 TOOLBAR_CalcToolbar (hwnd);
5041 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
5042 if NORESIZE is NOT set, then the toolbar will always be resized to
5043 take up the whole window. With it set, sizing needs to be manual. */
5044 if (infoPtr->dwStyle & CCS_NORESIZE) {
5045 SetWindowPos(hwnd, NULL, 0, 0,
5046 infoPtr->rcBound.right - infoPtr->rcBound.left,
5047 infoPtr->rcBound.bottom - infoPtr->rcBound.top,
5048 SWP_NOMOVE);
5051 /* repaint toolbar */
5052 InvalidateRect(hwnd, NULL, TRUE);
5055 /* return bounding rectangle */
5056 if (lprc) {
5057 lprc->left = infoPtr->rcBound.left;
5058 lprc->right = infoPtr->rcBound.right;
5059 lprc->top = infoPtr->rcBound.top;
5060 lprc->bottom = infoPtr->rcBound.bottom;
5063 return 0;
5067 static LRESULT
5068 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5070 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5071 TBUTTON_INFO *btnPtr;
5072 INT nIndex;
5074 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5075 if (nIndex == -1)
5076 return FALSE;
5078 btnPtr = &infoPtr->buttons[nIndex];
5080 /* if hidden state has changed the invalidate entire window and recalc */
5081 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5082 btnPtr->fsState = LOWORD(lParam);
5083 TOOLBAR_CalcToolbar (hwnd);
5084 InvalidateRect(hwnd, 0, TRUE);
5085 return TRUE;
5088 /* process state changing if current state doesn't match new state */
5089 if(btnPtr->fsState != LOWORD(lParam))
5091 btnPtr->fsState = LOWORD(lParam);
5092 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5095 return TRUE;
5099 static LRESULT
5100 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5102 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5104 return TRUE;
5108 static inline LRESULT
5109 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5111 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5113 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5115 infoPtr->hwndToolTip = (HWND)wParam;
5116 return 0;
5120 static LRESULT
5121 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5123 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5124 BOOL bTemp;
5126 TRACE("%s hwnd=%p\n",
5127 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5129 bTemp = infoPtr->bUnicode;
5130 infoPtr->bUnicode = (BOOL)wParam;
5132 return bTemp;
5136 static LRESULT
5137 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5139 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5141 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5142 comctl32_color.clrBtnHighlight :
5143 infoPtr->clrBtnHighlight;
5144 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5145 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5146 return 1;
5150 static LRESULT
5151 TOOLBAR_SetColorScheme (HWND hwnd, const COLORSCHEME *lParam)
5153 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5155 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5156 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5157 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5159 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5160 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5161 InvalidateRect(hwnd, NULL, TRUE);
5162 return 0;
5166 static LRESULT
5167 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5169 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5170 INT iOldVersion = infoPtr->iVersion;
5172 infoPtr->iVersion = iVersion;
5174 if (infoPtr->iVersion >= 5)
5175 TOOLBAR_SetUnicodeFormat(hwnd, TRUE, 0);
5177 return iOldVersion;
5181 static LRESULT
5182 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5184 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5185 WORD iString = HIWORD(wParam);
5186 WORD buffersize = LOWORD(wParam);
5187 LPSTR str = (LPSTR)lParam;
5188 LRESULT ret = -1;
5190 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5192 if (iString < infoPtr->nNumStrings)
5194 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5195 ret--;
5197 TRACE("returning %s\n", debugstr_a(str));
5199 else
5200 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5202 return ret;
5206 static LRESULT
5207 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5209 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5210 WORD iString = HIWORD(wParam);
5211 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5212 LPWSTR str = (LPWSTR)lParam;
5213 LRESULT ret = -1;
5215 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5217 if (iString < infoPtr->nNumStrings)
5219 len = min(len, strlenW(infoPtr->strings[iString]));
5220 ret = (len+1)*sizeof(WCHAR);
5221 if (str)
5223 memcpy(str, infoPtr->strings[iString], ret);
5224 str[len] = '\0';
5226 ret = len;
5228 TRACE("returning %s\n", debugstr_w(str));
5230 else
5231 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5233 return ret;
5236 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5237 * is the maximum size of the toolbar? */
5238 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5240 SIZE * pSize = (SIZE*)lParam;
5241 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5242 return 0;
5246 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5247 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5248 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5249 * sends). */
5250 static LRESULT
5251 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5253 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5254 INT nOldHotItem = infoPtr->nHotItem;
5256 TRACE("old item=%d, new item=%d, flags=%08x\n",
5257 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5259 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5260 wParam = -1;
5262 /* NOTE: an application can still remove the hot item even if anchor
5263 * highlighting is enabled */
5265 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5267 GetFocus();
5269 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5272 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5273 * which controls the amount of spacing between the image and the text
5274 * of buttons for TBSTYLE_LIST toolbars. */
5275 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5277 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5279 TRACE("hwnd=%p iListGap=%ld\n", hwnd, wParam);
5281 if (lParam != 0)
5282 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5284 infoPtr->iListGap = (INT)wParam;
5286 InvalidateRect(hwnd, NULL, TRUE);
5288 return 0;
5291 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5292 * of image lists associated with the various states. */
5293 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5295 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5297 TRACE("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5299 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5302 static LRESULT
5303 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5305 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5306 LPSIZE lpsize = (LPSIZE)lParam;
5308 if (lpsize == NULL)
5309 return FALSE;
5312 * Testing shows the following:
5313 * wParam = 0 adjust cx value
5314 * = 1 set cy value to max size.
5315 * lParam pointer to SIZE structure
5318 TRACE("[0463] wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5319 wParam, lParam, lpsize->cx, lpsize->cy);
5321 switch(wParam) {
5322 case 0:
5323 if (lpsize->cx == -1) {
5324 /* **** this is wrong, native measures each button and sets it */
5325 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5327 else if(HIWORD(lpsize->cx)) {
5328 RECT rc;
5329 HWND hwndParent = GetParent(hwnd);
5331 GetWindowRect(hwnd, &rc);
5332 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5333 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc));
5334 lpsize->cx = max(rc.right-rc.left,
5335 infoPtr->rcBound.right - infoPtr->rcBound.left);
5337 else {
5338 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5340 break;
5341 case 1:
5342 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5343 break;
5344 default:
5345 ERR("Unknown wParam %ld for Toolbar message [0463]. Please report\n",
5346 wParam);
5347 return 0;
5349 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5350 lpsize->cx, lpsize->cy);
5351 return 1;
5354 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5356 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5358 InvalidateRect(hwnd, NULL, TRUE);
5359 return 1;
5363 static LRESULT
5364 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5366 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5367 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5368 LOGFONTW logFont;
5370 TRACE("hwnd = %p\n", hwnd);
5372 /* initialize info structure */
5373 infoPtr->nButtonWidth = 23;
5374 infoPtr->nButtonHeight = 22;
5375 infoPtr->nBitmapHeight = 16;
5376 infoPtr->nBitmapWidth = 16;
5378 infoPtr->nMaxTextRows = 1;
5379 infoPtr->cxMin = -1;
5380 infoPtr->cxMax = -1;
5381 infoPtr->nNumBitmaps = 0;
5382 infoPtr->nNumStrings = 0;
5384 infoPtr->bCaptured = FALSE;
5385 infoPtr->nButtonDown = -1;
5386 infoPtr->nButtonDrag = -1;
5387 infoPtr->nOldHit = -1;
5388 infoPtr->nHotItem = -1;
5389 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5390 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5391 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5392 infoPtr->bDragOutSent = FALSE;
5393 infoPtr->iVersion = 0;
5394 infoPtr->hwndSelf = hwnd;
5395 infoPtr->bDoRedraw = TRUE;
5396 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5397 infoPtr->clrBtnShadow = CLR_DEFAULT;
5398 infoPtr->szPadding.cx = DEFPAD_CX;
5399 infoPtr->szPadding.cy = DEFPAD_CY;
5400 infoPtr->iListGap = DEFLISTGAP;
5401 infoPtr->iTopMargin = default_top_margin(infoPtr);
5402 infoPtr->dwStyle = dwStyle;
5403 infoPtr->tbim.iButton = -1;
5404 GetClientRect(hwnd, &infoPtr->client_rect);
5405 infoPtr->bUnicode = infoPtr->hwndNotify &&
5406 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5407 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5409 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5410 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5412 OpenThemeData (hwnd, themeClass);
5414 TOOLBAR_CheckStyle (hwnd, dwStyle);
5416 return 0;
5420 static LRESULT
5421 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5423 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5425 /* delete tooltip control */
5426 if (infoPtr->hwndToolTip)
5427 DestroyWindow (infoPtr->hwndToolTip);
5429 /* delete temporary buffer for tooltip text */
5430 Free (infoPtr->pszTooltipText);
5431 Free (infoPtr->bitmaps); /* bitmaps list */
5433 /* delete button data */
5434 Free (infoPtr->buttons);
5436 /* delete strings */
5437 if (infoPtr->strings) {
5438 INT i;
5439 for (i = 0; i < infoPtr->nNumStrings; i++)
5440 Free (infoPtr->strings[i]);
5442 Free (infoPtr->strings);
5445 /* destroy internal image list */
5446 if (infoPtr->himlInt)
5447 ImageList_Destroy (infoPtr->himlInt);
5449 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5450 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5451 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5453 /* delete default font */
5454 DeleteObject (infoPtr->hDefaultFont);
5456 CloseThemeData (GetWindowTheme (hwnd));
5458 /* free toolbar info data */
5459 Free (infoPtr);
5460 SetWindowLongPtrW (hwnd, 0, 0);
5462 return 0;
5466 static LRESULT
5467 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5469 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5470 NMTBCUSTOMDRAW tbcd;
5471 INT ret = FALSE;
5472 DWORD ntfret;
5473 HTHEME theme = GetWindowTheme (hwnd);
5474 DWORD dwEraseCustDraw = 0;
5476 /* the app has told us not to redraw the toolbar */
5477 if (!infoPtr->bDoRedraw)
5478 return FALSE;
5480 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5481 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5482 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5483 tbcd.nmcd.hdc = (HDC)wParam;
5484 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5485 dwEraseCustDraw = ntfret & 0xffff;
5487 /* FIXME: in general the return flags *can* be or'ed together */
5488 switch (dwEraseCustDraw)
5490 case CDRF_DODEFAULT:
5491 break;
5492 case CDRF_SKIPDEFAULT:
5493 return TRUE;
5494 default:
5495 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5496 hwnd, ntfret);
5500 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5501 * to my parent for processing.
5503 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5504 POINT pt, ptorig;
5505 HDC hdc = (HDC)wParam;
5506 HWND parent;
5508 pt.x = 0;
5509 pt.y = 0;
5510 parent = GetParent(hwnd);
5511 MapWindowPoints(hwnd, parent, &pt, 1);
5512 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5513 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5514 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5516 if (!ret)
5517 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5519 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5520 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5521 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5522 tbcd.nmcd.hdc = (HDC)wParam;
5523 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5524 dwEraseCustDraw = ntfret & 0xffff;
5525 switch (dwEraseCustDraw)
5527 case CDRF_DODEFAULT:
5528 break;
5529 case CDRF_SKIPDEFAULT:
5530 return TRUE;
5531 default:
5532 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5533 hwnd, ntfret);
5536 return ret;
5540 static LRESULT
5541 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5543 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5545 return (LRESULT)infoPtr->hFont;
5549 static void
5550 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5552 INT i;
5553 INT nNewHotItem = infoPtr->nHotItem;
5555 for (i = 0; i < infoPtr->nNumButtons; i++)
5557 /* did we wrap? */
5558 if ((nNewHotItem + iDirection < 0) ||
5559 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5561 NMTBWRAPHOTITEM nmtbwhi;
5562 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5563 nmtbwhi.iDirection = iDirection;
5564 nmtbwhi.dwReason = dwReason;
5566 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5567 return;
5570 nNewHotItem += iDirection;
5571 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5573 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5574 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5576 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5577 break;
5582 static LRESULT
5583 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5585 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5586 NMKEY nmkey;
5588 nmkey.nVKey = (UINT)wParam;
5589 nmkey.uFlags = HIWORD(lParam);
5591 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5592 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5594 switch ((UINT)wParam)
5596 case VK_LEFT:
5597 case VK_UP:
5598 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5599 break;
5600 case VK_RIGHT:
5601 case VK_DOWN:
5602 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5603 break;
5604 case VK_SPACE:
5605 case VK_RETURN:
5606 if ((infoPtr->nHotItem >= 0) &&
5607 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5609 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5610 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5611 (LPARAM)hwnd);
5613 break;
5616 return 0;
5620 static LRESULT
5621 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5623 POINT pt;
5624 INT nHit;
5626 pt.x = (short)LOWORD(lParam);
5627 pt.y = (short)HIWORD(lParam);
5628 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5630 if (nHit >= 0)
5631 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5632 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5633 TOOLBAR_Customize (hwnd);
5635 return 0;
5639 static LRESULT
5640 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5642 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5643 TBUTTON_INFO *btnPtr;
5644 POINT pt;
5645 INT nHit;
5646 NMTOOLBARA nmtb;
5647 NMMOUSE nmmouse;
5648 BOOL bDragKeyPressed;
5650 TRACE("\n");
5652 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5653 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5654 else
5655 bDragKeyPressed = (wParam & MK_SHIFT);
5657 if (infoPtr->hwndToolTip)
5658 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5659 WM_LBUTTONDOWN, wParam, lParam);
5661 pt.x = (short)LOWORD(lParam);
5662 pt.y = (short)HIWORD(lParam);
5663 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5665 btnPtr = &infoPtr->buttons[nHit];
5667 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5669 infoPtr->nButtonDrag = nHit;
5670 SetCapture (hwnd);
5672 /* If drag cursor has not been loaded, load it.
5673 * Note: it doesn't need to be freed */
5674 if (!hCursorDrag)
5675 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5676 SetCursor(hCursorDrag);
5678 else if (nHit >= 0)
5680 RECT arrowRect;
5681 infoPtr->nOldHit = nHit;
5683 CopyRect(&arrowRect, &btnPtr->rect);
5684 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5686 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5687 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5688 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5689 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5690 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5691 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5693 LRESULT res;
5695 /* draw in pressed state */
5696 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5697 btnPtr->fsState |= TBSTATE_PRESSED;
5698 else
5699 btnPtr->bDropDownPressed = TRUE;
5700 RedrawWindow(hwnd,&btnPtr->rect,0,
5701 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5703 memset(&nmtb, 0, sizeof(nmtb));
5704 nmtb.iItem = btnPtr->idCommand;
5705 nmtb.rcButton = btnPtr->rect;
5706 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5707 TBN_DROPDOWN);
5708 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5710 if (res != TBDDRET_TREATPRESSED)
5712 MSG msg;
5714 /* redraw button in unpressed state */
5715 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5716 btnPtr->fsState &= ~TBSTATE_PRESSED;
5717 else
5718 btnPtr->bDropDownPressed = FALSE;
5719 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5721 /* find and set hot item
5722 * NOTE: native doesn't do this, but that is a bug */
5723 GetCursorPos(&pt);
5724 ScreenToClient(hwnd, &pt);
5725 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5726 if (!infoPtr->bAnchor || (nHit >= 0))
5727 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5729 /* remove any left mouse button down or double-click messages
5730 * so that we can get a toggle effect on the button */
5731 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5732 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5735 return 0;
5737 /* otherwise drop through and process as pushed */
5739 infoPtr->bCaptured = TRUE;
5740 infoPtr->nButtonDown = nHit;
5741 infoPtr->bDragOutSent = FALSE;
5743 btnPtr->fsState |= TBSTATE_PRESSED;
5745 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5747 if (btnPtr->fsState & TBSTATE_ENABLED)
5748 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5749 UpdateWindow(hwnd);
5750 SetCapture (hwnd);
5753 if (nHit >=0)
5755 memset(&nmtb, 0, sizeof(nmtb));
5756 nmtb.iItem = btnPtr->idCommand;
5757 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5760 nmmouse.dwHitInfo = nHit;
5762 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5763 if (nHit < 0)
5764 nmmouse.dwItemSpec = -1;
5765 else
5767 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5768 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5771 ClientToScreen(hwnd, &pt);
5772 nmmouse.pt = pt;
5774 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5775 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5777 return 0;
5780 static LRESULT
5781 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5783 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5784 TBUTTON_INFO *btnPtr;
5785 POINT pt;
5786 INT nHit;
5787 INT nOldIndex = -1;
5788 NMHDR hdr;
5789 NMMOUSE nmmouse;
5790 NMTOOLBARA nmtb;
5792 if (infoPtr->hwndToolTip)
5793 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5794 WM_LBUTTONUP, wParam, lParam);
5796 pt.x = (short)LOWORD(lParam);
5797 pt.y = (short)HIWORD(lParam);
5798 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5800 if (!infoPtr->bAnchor || (nHit >= 0))
5801 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5803 if (infoPtr->nButtonDrag >= 0) {
5804 RECT rcClient;
5805 NMHDR hdr;
5807 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5808 ReleaseCapture();
5809 /* reset cursor */
5810 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5812 GetClientRect(hwnd, &rcClient);
5813 if (PtInRect(&rcClient, pt))
5815 INT nButton = -1;
5816 if (nHit >= 0)
5817 nButton = nHit;
5818 else if (nHit < -1)
5819 nButton = -nHit;
5820 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5821 nButton = -nHit;
5823 if (nButton == infoPtr->nButtonDrag)
5825 /* if the button is moved sightly left and we have a
5826 * separator there then remove it */
5827 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5829 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5830 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5832 else /* else insert a separator before the dragged button */
5834 TBBUTTON tbb;
5835 memset(&tbb, 0, sizeof(tbb));
5836 tbb.fsStyle = BTNS_SEP;
5837 tbb.iString = -1;
5838 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5841 else
5843 if (nButton == -1)
5845 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5846 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5847 else
5848 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5850 else
5851 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5854 else
5856 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5857 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5860 /* button under cursor changed so need to re-set hot item */
5861 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5862 infoPtr->nButtonDrag = -1;
5864 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5866 else if (infoPtr->nButtonDown >= 0) {
5867 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5868 btnPtr->fsState &= ~TBSTATE_PRESSED;
5870 if (btnPtr->fsStyle & BTNS_CHECK) {
5871 if (btnPtr->fsStyle & BTNS_GROUP) {
5872 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5873 nHit);
5874 if ((nOldIndex != nHit) &&
5875 (nOldIndex != -1))
5876 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5877 btnPtr->fsState |= TBSTATE_CHECKED;
5879 else {
5880 if (btnPtr->fsState & TBSTATE_CHECKED)
5881 btnPtr->fsState &= ~TBSTATE_CHECKED;
5882 else
5883 btnPtr->fsState |= TBSTATE_CHECKED;
5887 if (nOldIndex != -1)
5888 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5891 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5892 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5893 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5895 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5896 ReleaseCapture ();
5897 infoPtr->nButtonDown = -1;
5899 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5900 TOOLBAR_SendNotify (&hdr, infoPtr,
5901 NM_RELEASEDCAPTURE);
5903 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5904 * TBN_BEGINDRAG
5906 memset(&nmtb, 0, sizeof(nmtb));
5907 nmtb.iItem = btnPtr->idCommand;
5908 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5909 TBN_ENDDRAG);
5911 if (btnPtr->fsState & TBSTATE_ENABLED)
5913 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5914 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5916 /* In case we have just been destroyed... */
5917 if(!IsWindow(hwnd))
5918 return 0;
5922 /* !!! Undocumented - toolbar at 4.71 level and above sends
5923 * NM_CLICK with the NMMOUSE structure. */
5924 nmmouse.dwHitInfo = nHit;
5926 if (nHit < 0)
5927 nmmouse.dwItemSpec = -1;
5928 else
5930 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5931 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5934 ClientToScreen(hwnd, &pt);
5935 nmmouse.pt = pt;
5937 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5938 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5940 return 0;
5943 static LRESULT
5944 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5946 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5947 INT nHit;
5948 NMMOUSE nmmouse;
5949 POINT pt;
5951 pt.x = (short)LOWORD(lParam);
5952 pt.y = (short)HIWORD(lParam);
5954 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5955 nmmouse.dwHitInfo = nHit;
5957 if (nHit < 0) {
5958 nmmouse.dwItemSpec = -1;
5959 } else {
5960 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5961 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5964 ClientToScreen(hwnd, &pt);
5965 nmmouse.pt = pt;
5967 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5968 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5970 return 0;
5973 static LRESULT
5974 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5976 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5977 NMHDR nmhdr;
5979 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5980 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5982 return 0;
5985 static LRESULT
5986 TOOLBAR_CaptureChanged(HWND hwnd)
5988 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5989 TBUTTON_INFO *btnPtr;
5991 infoPtr->bCaptured = FALSE;
5993 if (infoPtr->nButtonDown >= 0)
5995 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5996 btnPtr->fsState &= ~TBSTATE_PRESSED;
5998 infoPtr->nOldHit = -1;
6000 if (btnPtr->fsState & TBSTATE_ENABLED)
6001 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6003 return 0;
6006 static LRESULT
6007 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6009 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6011 /* don't remove hot effects when in anchor highlighting mode or when a
6012 * drop-down button is pressed */
6013 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
6015 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
6016 if (!hotBtnPtr->bDropDownPressed)
6017 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6020 if (infoPtr->nOldHit < 0)
6021 return TRUE;
6023 /* If the last button we were over is depressed then make it not */
6024 /* depressed and redraw it */
6025 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6027 TBUTTON_INFO *btnPtr;
6028 RECT rc1;
6030 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6032 btnPtr->fsState &= ~TBSTATE_PRESSED;
6034 rc1 = btnPtr->rect;
6035 InflateRect (&rc1, 1, 1);
6036 InvalidateRect (hwnd, &rc1, TRUE);
6039 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6041 NMTOOLBARW nmt;
6042 ZeroMemory(&nmt, sizeof(nmt));
6043 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6044 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6045 infoPtr->bDragOutSent = TRUE;
6048 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6050 return TRUE;
6053 static LRESULT
6054 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6056 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6057 POINT pt;
6058 TRACKMOUSEEVENT trackinfo;
6059 INT nHit;
6060 TBUTTON_INFO *btnPtr;
6062 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6063 TOOLBAR_TooltipCreateControl(infoPtr);
6065 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6066 /* fill in the TRACKMOUSEEVENT struct */
6067 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6068 trackinfo.dwFlags = TME_QUERY;
6070 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6071 _TrackMouseEvent(&trackinfo);
6073 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6074 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6075 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6076 trackinfo.hwndTrack = hwnd;
6078 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6079 /* and can properly deactivate the hot toolbar button */
6080 _TrackMouseEvent(&trackinfo);
6084 if (infoPtr->hwndToolTip)
6085 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6086 WM_MOUSEMOVE, wParam, lParam);
6088 pt.x = (short)LOWORD(lParam);
6089 pt.y = (short)HIWORD(lParam);
6091 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6093 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6094 && (!infoPtr->bAnchor || (nHit >= 0)))
6095 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6097 if (infoPtr->nOldHit != nHit)
6099 if (infoPtr->bCaptured)
6101 if (!infoPtr->bDragOutSent)
6103 NMTOOLBARW nmt;
6104 ZeroMemory(&nmt, sizeof(nmt));
6105 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6106 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6107 infoPtr->bDragOutSent = TRUE;
6110 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6111 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6112 btnPtr->fsState &= ~TBSTATE_PRESSED;
6113 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6115 else if (nHit == infoPtr->nButtonDown) {
6116 btnPtr->fsState |= TBSTATE_PRESSED;
6117 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6119 infoPtr->nOldHit = nHit;
6123 return 0;
6127 static inline LRESULT
6128 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6130 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6131 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6132 /* else */
6133 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6137 static inline LRESULT
6138 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6140 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6141 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6143 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6147 static LRESULT
6148 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6150 TOOLBAR_INFO *infoPtr;
6151 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6152 DWORD styleadd = 0;
6154 /* allocate memory for info structure */
6155 infoPtr = Alloc (sizeof(TOOLBAR_INFO));
6156 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6158 /* paranoid!! */
6159 infoPtr->dwStructSize = sizeof(TBBUTTON);
6160 infoPtr->nRows = 1;
6161 infoPtr->nWidth = 0;
6163 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6164 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6165 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6166 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6169 /* native control does:
6170 * Get a lot of colors and brushes
6171 * WM_NOTIFYFORMAT
6172 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6173 * CreateFontIndirectW(adr1)
6174 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6175 * hdc = GetDC(toolbar)
6176 * GetSystemMetrics(0x48)
6177 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6178 * 0, 0, 0, 0, "MARLETT")
6179 * oldfnt = SelectObject(hdc, fnt2)
6180 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6181 * GetTextMetricsW(hdc, adr3)
6182 * SelectObject(hdc, oldfnt)
6183 * DeleteObject(fnt2)
6184 * ReleaseDC(hdc)
6185 * InvalidateRect(toolbar, 0, 1)
6186 * SetWindowLongW(toolbar, 0, addr)
6187 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6188 * WM_STYLECHANGING
6189 * CallWinEx old new
6190 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6191 * ie 2 0x4600094c 0x4600094c 0x4600894d
6192 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6193 * rebar 0x50008844 0x40008844 0x50008845
6194 * pager 0x50000844 0x40000844 0x50008845
6195 * IC35mgr 0x5400084e **nochange**
6196 * on entry to _NCCREATE 0x5400084e
6197 * rowlist 0x5400004e **nochange**
6198 * on entry to _NCCREATE 0x5400004e
6202 /* I think the code below is a bug, but it is the way that the native
6203 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6204 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6205 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6206 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6207 * Somehow, the only cases of this seem to be MFC programs.
6209 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6210 * does not occur in the WM_STYLECHANGING routine.
6211 * (Guy Albertelli 9/2001)
6214 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6215 && !(cs->style & TBSTYLE_TRANSPARENT))
6216 styleadd |= TBSTYLE_TRANSPARENT;
6217 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6218 styleadd |= CCS_TOP; /* default to top */
6219 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6222 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6226 static LRESULT
6227 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6229 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6230 RECT rcWindow;
6231 HDC hdc;
6233 if (dwStyle & WS_MINIMIZE)
6234 return 0; /* Nothing to do */
6236 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6238 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6239 return 0;
6241 if (!(dwStyle & CCS_NODIVIDER))
6243 GetWindowRect (hwnd, &rcWindow);
6244 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6245 if( dwStyle & WS_BORDER )
6246 OffsetRect (&rcWindow, 1, 1);
6247 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6250 ReleaseDC( hwnd, hdc );
6252 return 0;
6256 /* handles requests from the tooltip control on what text to display */
6257 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6259 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6261 TRACE("button index = %d\n", index);
6263 Free (infoPtr->pszTooltipText);
6264 infoPtr->pszTooltipText = NULL;
6266 if (index < 0)
6267 return 0;
6269 if (infoPtr->bUnicode)
6271 WCHAR wszBuffer[INFOTIPSIZE+1];
6272 NMTBGETINFOTIPW tbgit;
6273 unsigned int len; /* in chars */
6275 wszBuffer[0] = '\0';
6276 wszBuffer[INFOTIPSIZE] = '\0';
6278 tbgit.pszText = wszBuffer;
6279 tbgit.cchTextMax = INFOTIPSIZE;
6280 tbgit.iItem = lpnmtdi->hdr.idFrom;
6281 tbgit.lParam = infoPtr->buttons[index].dwData;
6283 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6285 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6287 len = strlenW(tbgit.pszText);
6288 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6290 /* need to allocate temporary buffer in infoPtr as there
6291 * isn't enough space in buffer passed to us by the
6292 * tooltip control */
6293 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6294 if (infoPtr->pszTooltipText)
6296 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6297 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6298 return 0;
6301 else if (len > 0)
6303 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6304 return 0;
6307 else
6309 CHAR szBuffer[INFOTIPSIZE+1];
6310 NMTBGETINFOTIPA tbgit;
6311 unsigned int len; /* in chars */
6313 szBuffer[0] = '\0';
6314 szBuffer[INFOTIPSIZE] = '\0';
6316 tbgit.pszText = szBuffer;
6317 tbgit.cchTextMax = INFOTIPSIZE;
6318 tbgit.iItem = lpnmtdi->hdr.idFrom;
6319 tbgit.lParam = infoPtr->buttons[index].dwData;
6321 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6323 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6325 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6326 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6328 /* need to allocate temporary buffer in infoPtr as there
6329 * isn't enough space in buffer passed to us by the
6330 * tooltip control */
6331 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6332 if (infoPtr->pszTooltipText)
6334 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6335 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6336 return 0;
6339 else if (tbgit.pszText[0])
6341 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6342 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6343 return 0;
6347 /* if button has text, but it is not shown then automatically
6348 * use that text as tooltip */
6349 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6350 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6352 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6353 unsigned int len = pszText ? strlenW(pszText) : 0;
6355 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6357 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6359 /* need to allocate temporary buffer in infoPtr as there
6360 * isn't enough space in buffer passed to us by the
6361 * tooltip control */
6362 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6363 if (infoPtr->pszTooltipText)
6365 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6366 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6367 return 0;
6370 else if (len > 0)
6372 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6373 return 0;
6377 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6379 /* last resort: send notification on to app */
6380 /* FIXME: find out what is really used here */
6381 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, lpnmtdi->hdr.idFrom, (LPARAM)lpnmtdi);
6385 static inline LRESULT
6386 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6388 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6389 LPNMHDR lpnmh = (LPNMHDR)lParam;
6391 switch (lpnmh->code)
6393 case PGN_CALCSIZE:
6395 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6397 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6398 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6399 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6400 lppgc->iWidth);
6402 else {
6403 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6404 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6405 lppgc->iHeight);
6407 return 0;
6410 case PGN_SCROLL:
6412 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6414 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6415 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6416 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6417 lppgs->iScroll, lppgs->iDir);
6418 return 0;
6421 case TTN_GETDISPINFOW:
6422 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6424 case TTN_GETDISPINFOA:
6425 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6426 return 0;
6428 default:
6429 return 0;
6434 static LRESULT
6435 TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6437 LRESULT format;
6439 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam, lParam);
6441 if (lParam == NF_QUERY)
6442 return NFR_UNICODE;
6444 if (lParam == NF_REQUERY) {
6445 format = SendMessageW(infoPtr->hwndNotify,
6446 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6447 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6448 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6449 format);
6450 format = NFR_ANSI;
6452 return format;
6454 return 0;
6458 static LRESULT
6459 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6461 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6462 HDC hdc;
6463 PAINTSTRUCT ps;
6465 /* fill ps.rcPaint with a default rect */
6466 ps.rcPaint = infoPtr->rcBound;
6468 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6470 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps.rcPaint));
6472 TOOLBAR_Refresh (hwnd, hdc, &ps);
6473 if (!wParam) EndPaint (hwnd, &ps);
6475 return 0;
6479 static LRESULT
6480 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6482 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6484 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6486 /* make first item hot */
6487 if (infoPtr->nNumButtons > 0)
6488 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6490 return 0;
6493 static LRESULT
6494 TOOLBAR_SetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
6496 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6498 TRACE("font=%p redraw=%ld\n", (HFONT)wParam, lParam);
6500 if (wParam == 0)
6501 infoPtr->hFont = infoPtr->hDefaultFont;
6502 else
6503 infoPtr->hFont = (HFONT)wParam;
6505 TOOLBAR_CalcToolbar(hwnd);
6507 if (lParam)
6508 InvalidateRect(hwnd, NULL, TRUE);
6509 return 1;
6512 static LRESULT
6513 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6514 /*****************************************************
6516 * Function;
6517 * Handles the WM_SETREDRAW message.
6519 * Documentation:
6520 * According to testing V4.71 of COMCTL32 returns the
6521 * *previous* status of the redraw flag (either 0 or 1)
6522 * instead of the MSDN documented value of 0 if handled.
6523 * (For laughs see the "consistency" with same function
6524 * in rebar.)
6526 *****************************************************/
6528 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6529 BOOL oldredraw = infoPtr->bDoRedraw;
6531 TRACE("set to %s\n",
6532 (wParam) ? "TRUE" : "FALSE");
6533 infoPtr->bDoRedraw = (BOOL) wParam;
6534 if (wParam) {
6535 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6537 return (oldredraw) ? 1 : 0;
6541 static LRESULT
6542 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6544 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6546 TRACE("sizing toolbar!\n");
6548 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6550 RECT delta_width, delta_height, client, dummy;
6551 DWORD min_x, max_x, min_y, max_y;
6552 TBUTTON_INFO *btnPtr;
6553 INT i;
6555 GetClientRect(hwnd, &client);
6556 if(client.right > infoPtr->client_rect.right)
6558 min_x = infoPtr->client_rect.right;
6559 max_x = client.right;
6561 else
6563 max_x = infoPtr->client_rect.right;
6564 min_x = client.right;
6566 if(client.bottom > infoPtr->client_rect.bottom)
6568 min_y = infoPtr->client_rect.bottom;
6569 max_y = client.bottom;
6571 else
6573 max_y = infoPtr->client_rect.bottom;
6574 min_y = client.bottom;
6577 SetRect(&delta_width, min_x, 0, max_x, min_y);
6578 SetRect(&delta_height, 0, min_y, max_x, max_y);
6580 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6581 btnPtr = infoPtr->buttons;
6582 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6583 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6584 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6585 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6587 GetClientRect(hwnd, &infoPtr->client_rect);
6588 TOOLBAR_AutoSize(hwnd);
6589 return 0;
6593 static LRESULT
6594 TOOLBAR_StyleChanged (HWND hwnd, INT nType, const STYLESTRUCT *lpStyle)
6596 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6598 if (nType == GWL_STYLE)
6600 DWORD dwOldStyle = infoPtr->dwStyle;
6602 if (lpStyle->styleNew & TBSTYLE_LIST)
6603 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6604 else
6605 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6607 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6609 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6611 infoPtr->dwStyle = lpStyle->styleNew;
6613 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6614 TOOLBAR_LayoutToolbar(hwnd);
6616 /* only resize if one of the CCS_* styles was changed */
6617 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6619 TOOLBAR_AutoSize (hwnd);
6621 InvalidateRect(hwnd, NULL, TRUE);
6625 return 0;
6629 static LRESULT
6630 TOOLBAR_SysColorChange (HWND hwnd)
6632 COMCTL32_RefreshSysColors();
6634 return 0;
6638 /* update theme after a WM_THEMECHANGED message */
6639 static LRESULT theme_changed (HWND hwnd)
6641 HTHEME theme = GetWindowTheme (hwnd);
6642 CloseThemeData (theme);
6643 OpenThemeData (hwnd, themeClass);
6644 return 0;
6648 static LRESULT WINAPI
6649 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6651 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6653 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6654 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6656 if (!infoPtr && (uMsg != WM_NCCREATE))
6657 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6659 switch (uMsg)
6661 case TB_ADDBITMAP:
6662 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6664 case TB_ADDBUTTONSA:
6665 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6667 case TB_ADDBUTTONSW:
6668 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6670 case TB_ADDSTRINGA:
6671 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6673 case TB_ADDSTRINGW:
6674 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6676 case TB_AUTOSIZE:
6677 return TOOLBAR_AutoSize (hwnd);
6679 case TB_BUTTONCOUNT:
6680 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6682 case TB_BUTTONSTRUCTSIZE:
6683 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6685 case TB_CHANGEBITMAP:
6686 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6688 case TB_CHECKBUTTON:
6689 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6691 case TB_COMMANDTOINDEX:
6692 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6694 case TB_CUSTOMIZE:
6695 return TOOLBAR_Customize (hwnd);
6697 case TB_DELETEBUTTON:
6698 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6700 case TB_ENABLEBUTTON:
6701 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6703 case TB_GETANCHORHIGHLIGHT:
6704 return TOOLBAR_GetAnchorHighlight (hwnd);
6706 case TB_GETBITMAP:
6707 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6709 case TB_GETBITMAPFLAGS:
6710 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6712 case TB_GETBUTTON:
6713 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6715 case TB_GETBUTTONINFOA:
6716 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, FALSE);
6718 case TB_GETBUTTONINFOW:
6719 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, TRUE);
6721 case TB_GETBUTTONSIZE:
6722 return TOOLBAR_GetButtonSize (hwnd);
6724 case TB_GETBUTTONTEXTA:
6725 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6727 case TB_GETBUTTONTEXTW:
6728 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6730 case TB_GETDISABLEDIMAGELIST:
6731 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6733 case TB_GETEXTENDEDSTYLE:
6734 return TOOLBAR_GetExtendedStyle (hwnd);
6736 case TB_GETHOTIMAGELIST:
6737 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6739 case TB_GETHOTITEM:
6740 return TOOLBAR_GetHotItem (hwnd);
6742 case TB_GETIMAGELIST:
6743 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6745 case TB_GETINSERTMARK:
6746 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6748 case TB_GETINSERTMARKCOLOR:
6749 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6751 case TB_GETITEMRECT:
6752 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6754 case TB_GETMAXSIZE:
6755 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6757 /* case TB_GETOBJECT: */ /* 4.71 */
6759 case TB_GETPADDING:
6760 return TOOLBAR_GetPadding (hwnd);
6762 case TB_GETRECT:
6763 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6765 case TB_GETROWS:
6766 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6768 case TB_GETSTATE:
6769 return TOOLBAR_GetState (hwnd, wParam, lParam);
6771 case TB_GETSTRINGA:
6772 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6774 case TB_GETSTRINGW:
6775 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6777 case TB_GETSTYLE:
6778 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6780 case TB_GETTEXTROWS:
6781 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6783 case TB_GETTOOLTIPS:
6784 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6786 case TB_GETUNICODEFORMAT:
6787 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6789 case TB_HIDEBUTTON:
6790 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6792 case TB_HITTEST:
6793 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6795 case TB_INDETERMINATE:
6796 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6798 case TB_INSERTBUTTONA:
6799 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6801 case TB_INSERTBUTTONW:
6802 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6804 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6806 case TB_ISBUTTONCHECKED:
6807 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6809 case TB_ISBUTTONENABLED:
6810 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6812 case TB_ISBUTTONHIDDEN:
6813 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6815 case TB_ISBUTTONHIGHLIGHTED:
6816 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6818 case TB_ISBUTTONINDETERMINATE:
6819 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6821 case TB_ISBUTTONPRESSED:
6822 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6824 case TB_LOADIMAGES:
6825 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6827 case TB_MAPACCELERATORA:
6828 case TB_MAPACCELERATORW:
6829 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6831 case TB_MARKBUTTON:
6832 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6834 case TB_MOVEBUTTON:
6835 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6837 case TB_PRESSBUTTON:
6838 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6840 case TB_REPLACEBITMAP:
6841 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6843 case TB_SAVERESTOREA:
6844 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6846 case TB_SAVERESTOREW:
6847 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6849 case TB_SETANCHORHIGHLIGHT:
6850 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6852 case TB_SETBITMAPSIZE:
6853 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6855 case TB_SETBUTTONINFOA:
6856 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6858 case TB_SETBUTTONINFOW:
6859 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6861 case TB_SETBUTTONSIZE:
6862 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6864 case TB_SETBUTTONWIDTH:
6865 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6867 case TB_SETCMDID:
6868 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6870 case TB_SETDISABLEDIMAGELIST:
6871 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6873 case TB_SETDRAWTEXTFLAGS:
6874 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6876 case TB_SETEXTENDEDSTYLE:
6877 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6879 case TB_SETHOTIMAGELIST:
6880 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6882 case TB_SETHOTITEM:
6883 return TOOLBAR_SetHotItem (hwnd, wParam);
6885 case TB_SETIMAGELIST:
6886 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6888 case TB_SETINDENT:
6889 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6891 case TB_SETINSERTMARK:
6892 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6894 case TB_SETINSERTMARKCOLOR:
6895 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6897 case TB_SETMAXTEXTROWS:
6898 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6900 case TB_SETPADDING:
6901 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6903 case TB_SETPARENT:
6904 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6906 case TB_SETROWS:
6907 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6909 case TB_SETSTATE:
6910 return TOOLBAR_SetState (hwnd, wParam, lParam);
6912 case TB_SETSTYLE:
6913 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6915 case TB_SETTOOLTIPS:
6916 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6918 case TB_SETUNICODEFORMAT:
6919 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6921 case TB_UNKWN45D:
6922 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6924 case TB_UNKWN45E:
6925 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6927 case TB_UNKWN460:
6928 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6930 case TB_UNKWN462:
6931 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6933 case TB_UNKWN463:
6934 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6936 case TB_UNKWN464:
6937 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6939 /* Common Control Messages */
6941 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6942 case CCM_GETCOLORSCHEME:
6943 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6945 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6946 case CCM_SETCOLORSCHEME:
6947 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6949 case CCM_GETVERSION:
6950 return TOOLBAR_GetVersion (hwnd);
6952 case CCM_SETVERSION:
6953 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6956 /* case WM_CHAR: */
6958 case WM_CREATE:
6959 return TOOLBAR_Create (hwnd, wParam, lParam);
6961 case WM_DESTROY:
6962 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6964 case WM_ERASEBKGND:
6965 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6967 case WM_GETFONT:
6968 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6970 case WM_KEYDOWN:
6971 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6973 /* case WM_KILLFOCUS: */
6975 case WM_LBUTTONDBLCLK:
6976 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6978 case WM_LBUTTONDOWN:
6979 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6981 case WM_LBUTTONUP:
6982 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6984 case WM_RBUTTONUP:
6985 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6987 case WM_RBUTTONDBLCLK:
6988 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6990 case WM_MOUSEMOVE:
6991 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6993 case WM_MOUSELEAVE:
6994 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6996 case WM_CAPTURECHANGED:
6997 return TOOLBAR_CaptureChanged(hwnd);
6999 case WM_NCACTIVATE:
7000 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7002 case WM_NCCALCSIZE:
7003 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7005 case WM_NCCREATE:
7006 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7008 case WM_NCPAINT:
7009 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7011 case WM_NOTIFY:
7012 return TOOLBAR_Notify (hwnd, wParam, lParam);
7014 case WM_NOTIFYFORMAT:
7015 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7017 case WM_PRINTCLIENT:
7018 case WM_PAINT:
7019 return TOOLBAR_Paint (hwnd, wParam);
7021 case WM_SETFOCUS:
7022 return TOOLBAR_SetFocus (hwnd, wParam);
7024 case WM_SETFONT:
7025 return TOOLBAR_SetFont(hwnd, wParam, lParam);
7027 case WM_SETREDRAW:
7028 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7030 case WM_SIZE:
7031 return TOOLBAR_Size (hwnd, wParam, lParam);
7033 case WM_STYLECHANGED:
7034 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7036 case WM_SYSCOLORCHANGE:
7037 return TOOLBAR_SysColorChange (hwnd);
7039 case WM_THEMECHANGED:
7040 return theme_changed (hwnd);
7042 /* case WM_WININICHANGE: */
7044 case WM_CHARTOITEM:
7045 case WM_COMMAND:
7046 case WM_DRAWITEM:
7047 case WM_MEASUREITEM:
7048 case WM_VKEYTOITEM:
7049 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7051 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7052 case PGM_FORWARDMOUSE:
7053 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7055 default:
7056 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
7057 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
7058 uMsg, wParam, lParam);
7059 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7064 VOID
7065 TOOLBAR_Register (void)
7067 WNDCLASSW wndClass;
7069 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7070 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7071 wndClass.lpfnWndProc = ToolbarWindowProc;
7072 wndClass.cbClsExtra = 0;
7073 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7074 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7075 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7076 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7078 RegisterClassW (&wndClass);
7082 VOID
7083 TOOLBAR_Unregister (void)
7085 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7088 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7090 HIMAGELIST himlold;
7091 PIMLENTRY c = NULL;
7093 /* Check if the entry already exists */
7094 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7096 /* If this is a new entry we must create it and insert into the array */
7097 if (!c)
7099 PIMLENTRY *pnies;
7101 c = Alloc(sizeof(IMLENTRY));
7102 c->id = id;
7104 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7105 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7106 pnies[*cies] = c;
7107 (*cies)++;
7109 Free(*pies);
7110 *pies = pnies;
7113 himlold = c->himl;
7114 c->himl = himl;
7116 return himlold;
7120 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7122 int i;
7124 for (i = 0; i < *cies; i++)
7125 Free((*pies)[i]);
7127 Free(*pies);
7129 *cies = 0;
7130 *pies = NULL;
7134 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id)
7136 PIMLENTRY c = NULL;
7138 if (pies != NULL)
7140 int i;
7142 for (i = 0; i < cies; i++)
7144 if (pies[i]->id == id)
7146 c = pies[i];
7147 break;
7152 return c;
7156 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id)
7158 HIMAGELIST himlDef = 0;
7159 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7161 if (pie)
7162 himlDef = pie->himl;
7164 return himlDef;
7168 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7170 if (infoPtr->bUnicode)
7171 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7172 else
7174 CHAR Buffer[256];
7175 NMTOOLBARA nmtba;
7176 BOOL bRet = FALSE;
7178 nmtba.iItem = nmtb->iItem;
7179 nmtba.pszText = Buffer;
7180 nmtba.cchText = 256;
7181 ZeroMemory(nmtba.pszText, nmtba.cchText);
7183 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7185 int ccht = strlen(nmtba.pszText);
7186 if (ccht)
7187 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7188 nmtb->pszText, nmtb->cchText);
7190 nmtb->tbButton = nmtba.tbButton;
7191 bRet = TRUE;
7194 return bRet;
7199 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo)
7201 NMTOOLBARW nmtb;
7203 /* MSDN states that iItem is the index of the button, rather than the
7204 * command ID as used by every other NMTOOLBAR notification */
7205 nmtb.iItem = iItem;
7206 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7208 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);