Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / dlls / comctl32 / toolbar.c
blob56dde257d39fd680ab9564dc69ff81c80e7c7867
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.
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(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
243 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
244 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
245 static PIMLENTRY TOOLBAR_GetImageListEntry(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(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button);
255 static LRESULT
256 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
258 static inline int default_top_margin(TOOLBAR_INFO *infoPtr)
260 return (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
263 static LPWSTR
264 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, 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(TOOLBAR_INFO *infoPtr, 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%08x\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=(%d,%d)-(%d,%d)\n",
287 btn_num, bP->idCommand,
288 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
289 bP->rect.left, bP->rect.top,
290 bP->rect.right, bP->rect.bottom);
295 static void
296 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
298 if (TRACE_ON(toolbar)) {
299 INT i;
301 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
302 iP->hwndSelf, line,
303 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
304 iP->nNumStrings, iP->dwStyle);
305 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
306 iP->hwndSelf, line,
307 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
308 (iP->bDoRedraw) ? "TRUE" : "FALSE");
309 for(i=0; i<iP->nNumButtons; i++) {
310 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
316 /***********************************************************************
317 * TOOLBAR_CheckStyle
319 * This function validates that the styles set are implemented and
320 * issues FIXME's warning of possible problems. In a perfect world this
321 * function should be null.
323 static void
324 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
326 if (dwStyle & TBSTYLE_REGISTERDROP)
327 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
331 static INT
332 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
334 if(!IsWindow(infoPtr->hwndSelf))
335 return 0; /* we have just been destroyed */
337 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
338 nmhdr->hwndFrom = infoPtr->hwndSelf;
339 nmhdr->code = code;
341 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
342 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
344 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
345 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
348 /***********************************************************************
349 * TOOLBAR_GetBitmapIndex
351 * This function returns the bitmap index associated with a button.
352 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
353 * is issued to retrieve the index.
355 static INT
356 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
358 INT ret = btnPtr->iBitmap;
360 if (ret == I_IMAGECALLBACK)
362 /* issue TBN_GETDISPINFO */
363 NMTBDISPINFOA nmgd;
365 memset(&nmgd, 0, sizeof(nmgd));
366 nmgd.idCommand = btnPtr->idCommand;
367 nmgd.lParam = btnPtr->dwData;
368 nmgd.dwMask = TBNF_IMAGE;
369 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
370 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
371 if (nmgd.dwMask & TBNF_DI_SETITEM)
372 btnPtr->iBitmap = nmgd.iImage;
373 ret = nmgd.iImage;
374 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
375 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
378 if (ret != I_IMAGENONE)
379 ret = GETIBITMAP(infoPtr, ret);
381 return ret;
385 static BOOL
386 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
388 HIMAGELIST himl;
389 INT id = GETHIMLID(infoPtr, index);
390 INT iBitmap = GETIBITMAP(infoPtr, index);
392 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
393 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
394 (index == I_IMAGECALLBACK))
395 return TRUE;
396 else
397 return FALSE;
401 static inline BOOL
402 TOOLBAR_IsValidImageList(TOOLBAR_INFO *infoPtr, INT index)
404 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
405 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
409 /***********************************************************************
410 * TOOLBAR_GetImageListForDrawing
412 * This function validates the bitmap index (including I_IMAGECALLBACK
413 * functionality) and returns the corresponding image list.
415 static HIMAGELIST
416 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, 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 (LPRECT lpRect, HDC hdc, 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 (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
500 RECT myrect;
501 COLORREF oldcolor, newcolor;
503 myrect.left = lpRect->left;
504 myrect.right = lpRect->right;
505 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
506 myrect.bottom = myrect.top + 1;
508 InflateRect (&myrect, -2, 0);
510 TRACE("rect=(%d,%d)-(%d,%d)\n",
511 myrect.left, myrect.top, myrect.right, myrect.bottom);
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 (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
558 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=(%d,%d)-(%d,%d)\n", debugstr_w(lpText),
570 rcText->left, rcText->top, rcText->right, rcText->bottom);
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 (LPRECT lpRect, 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(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(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 centred in the rectangle not containing
882 * the arrow */
883 CopyRect(&rcText, &rc);
884 CopyRect(&rcBitmap, &rc);
886 /* Center the bitmap horizontally and vertically */
887 if (dwStyle & TBSTYLE_LIST)
889 if (lpText &&
890 infoPtr->nMaxTextRows > 0 &&
891 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
892 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
893 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
894 else
895 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
897 else
898 rcBitmap.left += ((rc.right - rc.left) - infoPtr->nBitmapWidth) / 2;
900 rcBitmap.top += infoPtr->szPadding.cy / 2;
902 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
903 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
904 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
905 TRACE("Text=%s\n", debugstr_w(lpText));
906 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
908 /* calculate text position */
909 if (lpText)
911 rcText.left += GetSystemMetrics(SM_CXEDGE);
912 rcText.right -= GetSystemMetrics(SM_CXEDGE);
913 if (dwStyle & TBSTYLE_LIST)
915 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
916 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
918 else
920 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
921 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
922 else
923 rcText.top += infoPtr->szPadding.cy/2 + 2;
927 /* Initialize fields in all cases, because we use these later
928 * NOTE: applications can and do alter these to customize their
929 * toolbars */
930 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
931 tbcd.clrText = comctl32_color.clrBtnText;
932 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
933 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
934 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
935 tbcd.clrMark = comctl32_color.clrHighlight;
936 tbcd.clrHighlightHotTrack = 0;
937 tbcd.nStringBkMode = TRANSPARENT;
938 tbcd.nHLStringBkMode = OPAQUE;
939 /* MSDN says that this is the text rectangle.
940 * But (why always a but) tracing of v5.7 of native shows
941 * that this is really a *relative* rectangle based on the
942 * the nmcd.rc. Also the left and top are always 0 ignoring
943 * any bitmap that might be present. */
944 tbcd.rcText.left = 0;
945 tbcd.rcText.top = 0;
946 tbcd.rcText.right = rcText.right - rc.left;
947 tbcd.rcText.bottom = rcText.bottom - rc.top;
948 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
949 tbcd.nmcd.hdc = hdc;
950 tbcd.nmcd.rc = rc;
951 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
953 /* FIXME: what are these used for? */
954 tbcd.hbrLines = 0;
955 tbcd.hpenLines = 0;
957 /* Issue Item Prepaint notify */
958 dwItemCustDraw = 0;
959 dwItemCDFlag = 0;
960 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
962 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
963 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
964 tbcd.nmcd.lItemlParam = btnPtr->dwData;
965 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
966 /* reset these fields so the user can't alter the behaviour like native */
967 tbcd.nmcd.hdc = hdc;
968 tbcd.nmcd.rc = rc;
970 dwItemCustDraw = ntfret & 0xffff;
971 dwItemCDFlag = ntfret & 0xffff0000;
972 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
973 return;
974 /* save the only part of the rect that the user can change */
975 rcText.right = tbcd.rcText.right + rc.left;
976 rcText.bottom = tbcd.rcText.bottom + rc.top;
979 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
980 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
981 OffsetRect(&rcText, 1, 1);
983 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
984 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
985 TOOLBAR_DrawPattern (&rc, &tbcd);
987 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
988 && (tbcd.nmcd.uItemState & CDIS_HOT))
990 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
992 COLORREF oldclr;
994 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
995 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
996 if (hasDropDownArrow)
997 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
998 SetBkColor(hdc, oldclr);
1002 if (theme)
1004 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1005 int stateId = TS_NORMAL;
1007 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1008 stateId = TS_DISABLED;
1009 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1010 stateId = TS_PRESSED;
1011 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1012 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1013 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1014 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1015 stateId = TS_HOT;
1017 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1019 else
1020 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1022 if (drawSepDropDownArrow)
1024 if (theme)
1026 int stateId = TS_NORMAL;
1028 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1029 stateId = TS_DISABLED;
1030 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1031 stateId = TS_PRESSED;
1032 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1033 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1034 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1035 stateId = TS_HOT;
1037 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1038 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1040 else
1041 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1044 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1045 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1046 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1047 SetBkMode (hdc, oldBkMode);
1049 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1051 if (hasDropDownArrow && !drawSepDropDownArrow)
1053 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1055 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1056 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1058 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1060 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1061 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1063 else
1064 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1067 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1069 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1070 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1076 static void
1077 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1079 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1080 TBUTTON_INFO *btnPtr;
1081 INT i;
1082 RECT rcTemp, rcClient;
1083 NMTBCUSTOMDRAW tbcd;
1084 DWORD ntfret;
1085 DWORD dwBaseCustDraw;
1087 /* the app has told us not to redraw the toolbar */
1088 if (!infoPtr->bDoRedraw)
1089 return;
1091 /* if imagelist belongs to the app, it can be changed
1092 by the app after setting it */
1093 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1095 infoPtr->nNumBitmaps = 0;
1096 for (i = 0; i < infoPtr->cimlDef; i++)
1097 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1100 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1102 /* change the imagelist icon size if we manage the list and it is necessary */
1103 TOOLBAR_CheckImageListIconSize(infoPtr);
1105 /* Send initial notify */
1106 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1107 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1108 tbcd.nmcd.hdc = hdc;
1109 tbcd.nmcd.rc = ps->rcPaint;
1110 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1111 dwBaseCustDraw = ntfret & 0xffff;
1113 GetClientRect(hwnd, &rcClient);
1115 /* redraw necessary buttons */
1116 btnPtr = infoPtr->buttons;
1117 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1119 BOOL bDraw;
1120 if (!RectVisible(hdc, &btnPtr->rect))
1121 continue;
1122 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1124 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1125 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1127 else
1128 bDraw = TRUE;
1129 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1130 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1131 if (bDraw)
1132 TOOLBAR_DrawButton(hwnd, btnPtr, hdc, dwBaseCustDraw);
1135 /* draw insert mark if required */
1136 if (infoPtr->tbim.iButton != -1)
1138 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1139 RECT rcInsertMark;
1140 rcInsertMark.top = rcButton.top;
1141 rcInsertMark.bottom = rcButton.bottom;
1142 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1143 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1144 else
1145 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1146 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1149 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1151 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1152 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1153 tbcd.nmcd.hdc = hdc;
1154 tbcd.nmcd.rc = ps->rcPaint;
1155 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1159 /***********************************************************************
1160 * TOOLBAR_MeasureString
1162 * This function gets the width and height of a string in pixels. This
1163 * is done first by using GetTextExtentPoint to get the basic width
1164 * and height. The DrawText is called with DT_CALCRECT to get the exact
1165 * width. The reason is because the text may have more than one "&" (or
1166 * prefix characters as M$ likes to call them). The prefix character
1167 * indicates where the underline goes, except for the string "&&" which
1168 * is reduced to a single "&". GetTextExtentPoint does not process these
1169 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1171 static void
1172 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1173 HDC hdc, LPSIZE lpSize)
1175 RECT myrect;
1177 lpSize->cx = 0;
1178 lpSize->cy = 0;
1180 if (infoPtr->nMaxTextRows > 0 &&
1181 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1182 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1183 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1185 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1187 if(lpText != NULL) {
1188 /* first get size of all the text */
1189 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1191 /* feed above size into the rectangle for DrawText */
1192 myrect.left = myrect.top = 0;
1193 myrect.right = lpSize->cx;
1194 myrect.bottom = lpSize->cy;
1196 /* Use DrawText to get true size as drawn (less pesky "&") */
1197 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1198 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1199 DT_NOPREFIX : 0));
1201 /* feed back to caller */
1202 lpSize->cx = myrect.right;
1203 lpSize->cy = myrect.bottom;
1207 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1210 /***********************************************************************
1211 * TOOLBAR_CalcStrings
1213 * This function walks through each string and measures it and returns
1214 * the largest height and width to caller.
1216 static void
1217 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1219 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1220 TBUTTON_INFO *btnPtr;
1221 INT i;
1222 SIZE sz;
1223 HDC hdc;
1224 HFONT hOldFont;
1226 lpSize->cx = 0;
1227 lpSize->cy = 0;
1229 if (infoPtr->nMaxTextRows == 0)
1230 return;
1232 hdc = GetDC (hwnd);
1233 hOldFont = SelectObject (hdc, infoPtr->hFont);
1235 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1237 TEXTMETRICW tm;
1239 GetTextMetricsW(hdc, &tm);
1240 lpSize->cy = tm.tmHeight;
1243 btnPtr = infoPtr->buttons;
1244 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1245 if(TOOLBAR_HasText(infoPtr, btnPtr))
1247 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1248 if (sz.cx > lpSize->cx)
1249 lpSize->cx = sz.cx;
1250 if (sz.cy > lpSize->cy)
1251 lpSize->cy = sz.cy;
1255 SelectObject (hdc, hOldFont);
1256 ReleaseDC (hwnd, hdc);
1258 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1261 /***********************************************************************
1262 * TOOLBAR_WrapToolbar
1264 * This function walks through the buttons and separators in the
1265 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1266 * wrapping should occur based on the width of the toolbar window.
1267 * It does *not* calculate button placement itself. That task
1268 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1269 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1270 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1272 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1273 * vertical toolbar lists.
1276 static void
1277 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1279 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1280 TBUTTON_INFO *btnPtr;
1281 INT x, cx, i, j;
1282 RECT rc;
1283 BOOL bWrap, bButtonWrap;
1285 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1286 /* no layout is necessary. Applications may use this style */
1287 /* to perform their own layout on the toolbar. */
1288 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1289 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1291 btnPtr = infoPtr->buttons;
1292 x = infoPtr->nIndent;
1294 if (GetParent(hwnd))
1296 /* this can get the parents width, to know how far we can extend
1297 * this toolbar. We cannot use its height, as there may be multiple
1298 * toolbars in a rebar control
1300 GetClientRect( GetParent(hwnd), &rc );
1301 infoPtr->nWidth = rc.right - rc.left;
1303 else
1305 GetWindowRect( hwnd, &rc );
1306 infoPtr->nWidth = rc.right - rc.left;
1309 bButtonWrap = FALSE;
1311 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1312 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1313 infoPtr->nIndent);
1315 for (i = 0; i < infoPtr->nNumButtons; i++ )
1317 bWrap = FALSE;
1318 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1320 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1321 continue;
1323 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1324 /* it is the actual width of the separator. This is used for */
1325 /* custom controls in toolbars. */
1326 /* */
1327 /* BTNS_DROPDOWN separators are treated as buttons for */
1328 /* width. - GA 8/01 */
1329 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1330 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1331 cx = (btnPtr[i].iBitmap > 0) ?
1332 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1333 else
1334 cx = infoPtr->nButtonWidth;
1336 /* Two or more adjacent separators form a separator group. */
1337 /* The first separator in a group should be wrapped to the */
1338 /* next row if the previous wrapping is on a button. */
1339 if( bButtonWrap &&
1340 (btnPtr[i].fsStyle & BTNS_SEP) &&
1341 (i + 1 < infoPtr->nNumButtons ) &&
1342 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1344 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1345 btnPtr[i].fsState |= TBSTATE_WRAP;
1346 x = infoPtr->nIndent;
1347 i++;
1348 bButtonWrap = FALSE;
1349 continue;
1352 /* The layout makes sure the bitmap is visible, but not the button. */
1353 /* Test added to also wrap after a button that starts a row but */
1354 /* is bigger than the area. - GA 8/01 */
1355 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1356 > infoPtr->nWidth ) ||
1357 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1359 BOOL bFound = FALSE;
1361 /* If the current button is a separator and not hidden, */
1362 /* go to the next until it reaches a non separator. */
1363 /* Wrap the last separator if it is before a button. */
1364 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1365 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1366 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1367 i < infoPtr->nNumButtons )
1369 i++;
1370 bFound = TRUE;
1373 if( bFound && i < infoPtr->nNumButtons )
1375 i--;
1376 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1377 i, btnPtr[i].fsStyle, x, cx);
1378 btnPtr[i].fsState |= TBSTATE_WRAP;
1379 x = infoPtr->nIndent;
1380 bButtonWrap = FALSE;
1381 continue;
1383 else if ( i >= infoPtr->nNumButtons)
1384 break;
1386 /* If the current button is not a separator, find the last */
1387 /* separator and wrap it. */
1388 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1390 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1391 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1393 bFound = TRUE;
1394 i = j;
1395 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1396 i, btnPtr[i].fsStyle, x, cx);
1397 x = infoPtr->nIndent;
1398 btnPtr[j].fsState |= TBSTATE_WRAP;
1399 bButtonWrap = FALSE;
1400 break;
1404 /* If no separator available for wrapping, wrap one of */
1405 /* non-hidden previous button. */
1406 if (!bFound)
1408 for ( j = i - 1;
1409 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1411 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1412 continue;
1414 bFound = TRUE;
1415 i = j;
1416 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1417 i, btnPtr[i].fsStyle, x, cx);
1418 x = infoPtr->nIndent;
1419 btnPtr[j].fsState |= TBSTATE_WRAP;
1420 bButtonWrap = TRUE;
1421 break;
1425 /* If all above failed, wrap the current button. */
1426 if (!bFound)
1428 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1429 i, btnPtr[i].fsStyle, x, cx);
1430 btnPtr[i].fsState |= TBSTATE_WRAP;
1431 bFound = TRUE;
1432 x = infoPtr->nIndent;
1433 if (btnPtr[i].fsStyle & BTNS_SEP )
1434 bButtonWrap = FALSE;
1435 else
1436 bButtonWrap = TRUE;
1439 else {
1440 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1441 i, btnPtr[i].fsStyle, x, cx);
1442 x += cx;
1448 /***********************************************************************
1449 * TOOLBAR_MeasureButton
1451 * Calculates the width and height required for a button. Used in
1452 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1453 * the width of buttons that are autosized.
1455 * Note that it would have been rather elegant to use one piece of code for
1456 * both the laying out of the toolbar and for controlling where button parts
1457 * are drawn, but the native control has inconsistencies between the two that
1458 * prevent this from being effectively. These inconsistencies can be seen as
1459 * artefacts where parts of the button appear outside of the bounding button
1460 * rectangle.
1462 * There are several cases for the calculation of the button dimensions and
1463 * button part positioning:
1465 * List
1466 * ====
1468 * With Bitmap:
1470 * +--------------------------------------------------------+ ^
1471 * | ^ ^ | |
1472 * | | pad.cy / 2 | centred | |
1473 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1474 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1475 * | |<------------>| | | | |
1476 * | +--------------+ +------------+ | |
1477 * |<-------------------------------------->| | |
1478 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1479 * | szText.cx | |
1480 * +--------------------------------------------------------+ -
1481 * <-------------------------------------------------------->
1482 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1484 * Without Bitmap (I_IMAGENONE):
1486 * +-----------------------------------+ ^
1487 * | ^ | |
1488 * | | centred | | LISTPAD_CY +
1489 * | +------------+ | | szText.cy
1490 * | | Text | | |
1491 * | | | | |
1492 * | +------------+ | |
1493 * |<----------------->| | |
1494 * | cxedge |<-----------> | |
1495 * | szText.cx | |
1496 * +-----------------------------------+ -
1497 * <----------------------------------->
1498 * szText.cx + pad.cx
1500 * Without text:
1502 * +--------------------------------------+ ^
1503 * | ^ | |
1504 * | | padding.cy/2 | | DEFPAD_CY +
1505 * | +------------+ | | nBitmapHeight
1506 * | | Bitmap | | |
1507 * | | | | |
1508 * | +------------+ | |
1509 * |<------------------->| | |
1510 * | cxedge + iListGap/2 |<-----------> | |
1511 * | nBitmapWidth | |
1512 * +--------------------------------------+ -
1513 * <-------------------------------------->
1514 * 2*cxedge + nBitmapWidth + iListGap
1516 * Non-List
1517 * ========
1519 * With bitmap:
1521 * +-----------------------------------+ ^
1522 * | ^ | |
1523 * | | pad.cy / 2 | | nBitmapHeight +
1524 * | - | | szText.cy +
1525 * | +------------+ | | DEFPAD_CY + 1
1526 * | centred | Bitmap | | |
1527 * |<----------------->| | | |
1528 * | +------------+ | |
1529 * | ^ | |
1530 * | 1 | | |
1531 * | - | |
1532 * | centred +---------------+ | |
1533 * |<--------------->| Text | | |
1534 * | +---------------+ | |
1535 * +-----------------------------------+ -
1536 * <----------------------------------->
1537 * pad.cx + max(nBitmapWidth, szText.cx)
1539 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1541 * +---------------------------------------+ ^
1542 * | ^ | |
1543 * | | 2 + pad.cy / 2 | |
1544 * | - | | szText.cy +
1545 * | centred +-----------------+ | | pad.cy + 2
1546 * |<--------------->| Text | | |
1547 * | +-----------------+ | |
1548 * | | |
1549 * +---------------------------------------+ -
1550 * <--------------------------------------->
1551 * 2*cxedge + pad.cx + szText.cx
1553 * Without text:
1554 * As for with bitmaps, but with szText.cx zero.
1556 static inline SIZE TOOLBAR_MeasureButton(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1558 SIZE sizeButton;
1559 if (infoPtr->dwStyle & TBSTYLE_LIST)
1561 /* set button height from bitmap / text height... */
1562 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1563 sizeString.cy);
1565 /* ... add on the necessary padding */
1566 if (bValidImageList)
1568 if (bHasBitmap)
1569 sizeButton.cy += DEFPAD_CY;
1570 else
1571 sizeButton.cy += LISTPAD_CY;
1573 else
1574 sizeButton.cy += infoPtr->szPadding.cy;
1576 /* calculate button width */
1577 if (bHasBitmap)
1579 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1580 infoPtr->nBitmapWidth + infoPtr->iListGap;
1581 if (sizeString.cx > 0)
1582 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1584 else
1585 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1587 else
1589 if (bHasBitmap)
1591 sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
1592 if (sizeString.cy > 0)
1593 sizeButton.cy += 1 + sizeString.cy;
1594 sizeButton.cx = infoPtr->szPadding.cx +
1595 max(sizeString.cx, infoPtr->nBitmapWidth);
1597 else
1599 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1600 NONLIST_NOTEXT_OFFSET;
1601 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1602 infoPtr->szPadding.cx + sizeString.cx;
1605 return sizeButton;
1609 /***********************************************************************
1610 * TOOLBAR_CalcToolbar
1612 * This function calculates button and separator placement. It first
1613 * calculates the button sizes, gets the toolbar window width and then
1614 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1615 * on. It assigns a new location to each item and sends this location to
1616 * the tooltip window if appropriate. Finally, it updates the rcBound
1617 * rect and calculates the new required toolbar window height.
1619 static void
1620 TOOLBAR_CalcToolbar (HWND hwnd)
1622 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1623 SIZE sizeString, sizeButton;
1624 BOOL validImageList = FALSE;
1626 TOOLBAR_CalcStrings (hwnd, &sizeString);
1628 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1630 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1631 validImageList = TRUE;
1632 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1633 infoPtr->nButtonWidth = sizeButton.cx;
1634 infoPtr->nButtonHeight = sizeButton.cy;
1635 infoPtr->iTopMargin = default_top_margin(infoPtr);
1637 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1638 infoPtr->nButtonWidth = infoPtr->cxMin;
1639 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1640 infoPtr->nButtonWidth = infoPtr->cxMax;
1642 TOOLBAR_LayoutToolbar(hwnd);
1645 static void
1646 TOOLBAR_LayoutToolbar(HWND hwnd)
1648 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1649 TBUTTON_INFO *btnPtr;
1650 SIZE sizeButton;
1651 INT i, nRows, nSepRows;
1652 INT x, y, cx, cy;
1653 BOOL bWrap;
1654 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1655 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1657 TOOLBAR_WrapToolbar(hwnd, infoPtr->dwStyle);
1659 x = infoPtr->nIndent;
1660 y = infoPtr->iTopMargin;
1661 cx = infoPtr->nButtonWidth;
1662 cy = infoPtr->nButtonHeight;
1664 nRows = nSepRows = 0;
1666 infoPtr->rcBound.top = y;
1667 infoPtr->rcBound.left = x;
1668 infoPtr->rcBound.bottom = y + cy;
1669 infoPtr->rcBound.right = x;
1671 btnPtr = infoPtr->buttons;
1673 TRACE("cy=%d\n", cy);
1675 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1677 bWrap = FALSE;
1678 if (btnPtr->fsState & TBSTATE_HIDDEN)
1680 SetRectEmpty (&btnPtr->rect);
1681 continue;
1684 cy = infoPtr->nButtonHeight;
1686 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1687 /* it is the actual width of the separator. This is used for */
1688 /* custom controls in toolbars. */
1689 if (btnPtr->fsStyle & BTNS_SEP) {
1690 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1691 cy = (btnPtr->iBitmap > 0) ?
1692 btnPtr->iBitmap : SEPARATOR_WIDTH;
1693 cx = infoPtr->nButtonWidth;
1695 else
1696 cx = (btnPtr->iBitmap > 0) ?
1697 btnPtr->iBitmap : SEPARATOR_WIDTH;
1699 else
1701 if (btnPtr->cx)
1702 cx = btnPtr->cx;
1703 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1704 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1706 SIZE sz;
1707 HDC hdc;
1708 HFONT hOldFont;
1710 hdc = GetDC (hwnd);
1711 hOldFont = SelectObject (hdc, infoPtr->hFont);
1713 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1715 SelectObject (hdc, hOldFont);
1716 ReleaseDC (hwnd, hdc);
1718 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1719 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1720 validImageList);
1721 cx = sizeButton.cx;
1723 else
1724 cx = infoPtr->nButtonWidth;
1726 /* if size has been set manually then don't add on extra space
1727 * for the drop down arrow */
1728 if (!btnPtr->cx && hasDropDownArrows &&
1729 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1730 cx += DDARROW_WIDTH;
1732 if (btnPtr->fsState & TBSTATE_WRAP )
1733 bWrap = TRUE;
1735 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1737 if (infoPtr->rcBound.left > x)
1738 infoPtr->rcBound.left = x;
1739 if (infoPtr->rcBound.right < x + cx)
1740 infoPtr->rcBound.right = x + cx;
1741 if (infoPtr->rcBound.bottom < y + cy)
1742 infoPtr->rcBound.bottom = y + cy;
1744 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1746 /* btnPtr->nRow is zero based. The space between the rows is */
1747 /* also considered as a row. */
1748 btnPtr->nRow = nRows + nSepRows;
1750 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1751 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1752 x, y, x+cx, y+cy);
1754 if( bWrap )
1756 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1757 y += cy;
1758 else
1760 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1761 /* it is the actual width of the separator. This is used for */
1762 /* custom controls in toolbars. */
1763 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1764 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1765 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1766 else
1767 y += cy;
1769 /* nSepRows is used to calculate the extra height follwoing */
1770 /* the last row. */
1771 nSepRows++;
1773 x = infoPtr->nIndent;
1775 /* Increment row number unless this is the last button */
1776 /* and it has Wrap set. */
1777 if (i != infoPtr->nNumButtons-1)
1778 nRows++;
1780 else
1781 x += cx;
1784 /* infoPtr->nRows is the number of rows on the toolbar */
1785 infoPtr->nRows = nRows + nSepRows + 1;
1787 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1791 static INT
1792 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1794 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1795 TBUTTON_INFO *btnPtr;
1796 INT i;
1798 btnPtr = infoPtr->buttons;
1799 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1800 if (btnPtr->fsState & TBSTATE_HIDDEN)
1801 continue;
1803 if (btnPtr->fsStyle & BTNS_SEP) {
1804 if (PtInRect (&btnPtr->rect, *lpPt)) {
1805 TRACE(" ON SEPARATOR %d!\n", i);
1806 return -i;
1809 else {
1810 if (PtInRect (&btnPtr->rect, *lpPt)) {
1811 TRACE(" ON BUTTON %d!\n", i);
1812 return i;
1817 TRACE(" NOWHERE!\n");
1818 return TOOLBAR_NOWHERE;
1822 static INT
1823 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1825 TBUTTON_INFO *btnPtr;
1826 INT i;
1828 if (CommandIsIndex) {
1829 TRACE("command is really index command=%d\n", idCommand);
1830 if (idCommand >= infoPtr->nNumButtons) return -1;
1831 return idCommand;
1833 btnPtr = infoPtr->buttons;
1834 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1835 if (btnPtr->idCommand == idCommand) {
1836 TRACE("command=%d index=%d\n", idCommand, i);
1837 return i;
1840 TRACE("no index found for command=%d\n", idCommand);
1841 return -1;
1845 static INT
1846 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1848 TBUTTON_INFO *btnPtr;
1849 INT nRunIndex;
1851 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1852 return -1;
1854 /* check index button */
1855 btnPtr = &infoPtr->buttons[nIndex];
1856 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1857 if (btnPtr->fsState & TBSTATE_CHECKED)
1858 return nIndex;
1861 /* check previous buttons */
1862 nRunIndex = nIndex - 1;
1863 while (nRunIndex >= 0) {
1864 btnPtr = &infoPtr->buttons[nRunIndex];
1865 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1866 if (btnPtr->fsState & TBSTATE_CHECKED)
1867 return nRunIndex;
1869 else
1870 break;
1871 nRunIndex--;
1874 /* check next buttons */
1875 nRunIndex = nIndex + 1;
1876 while (nRunIndex < infoPtr->nNumButtons) {
1877 btnPtr = &infoPtr->buttons[nRunIndex];
1878 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1879 if (btnPtr->fsState & TBSTATE_CHECKED)
1880 return nRunIndex;
1882 else
1883 break;
1884 nRunIndex++;
1887 return -1;
1891 static VOID
1892 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1893 WPARAM wParam, LPARAM lParam)
1895 MSG msg;
1897 msg.hwnd = hwndMsg;
1898 msg.message = uMsg;
1899 msg.wParam = wParam;
1900 msg.lParam = lParam;
1901 msg.time = GetMessageTime ();
1902 msg.pt.x = (short)LOWORD(GetMessagePos ());
1903 msg.pt.y = (short)HIWORD(GetMessagePos ());
1905 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1908 static void
1909 TOOLBAR_TooltipAddTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1911 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1912 TTTOOLINFOW ti;
1914 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1915 ti.cbSize = sizeof (TTTOOLINFOW);
1916 ti.hwnd = infoPtr->hwndSelf;
1917 ti.uId = button->idCommand;
1918 ti.hinst = 0;
1919 ti.lpszText = LPSTR_TEXTCALLBACKW;
1920 /* ti.lParam = random value from the stack? */
1922 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1923 0, (LPARAM)&ti);
1927 static void
1928 TOOLBAR_TooltipDelTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1930 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1931 TTTOOLINFOW ti;
1933 ZeroMemory(&ti, sizeof(ti));
1934 ti.cbSize = sizeof(ti);
1935 ti.hwnd = infoPtr->hwndSelf;
1936 ti.uId = button->idCommand;
1938 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1942 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1944 /* Set the toolTip only for non-hidden, non-separator button */
1945 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1947 TTTOOLINFOW ti;
1949 ZeroMemory(&ti, sizeof(ti));
1950 ti.cbSize = sizeof(ti);
1951 ti.hwnd = infoPtr->hwndSelf;
1952 ti.uId = button->idCommand;
1953 ti.rect = button->rect;
1954 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1958 /* Creates the tooltip control */
1959 static void
1960 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
1962 int i;
1963 NMTOOLTIPSCREATED nmttc;
1965 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1966 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1967 infoPtr->hwndSelf, 0, 0, 0);
1969 if (!infoPtr->hwndToolTip)
1970 return;
1972 /* Send NM_TOOLTIPSCREATED notification */
1973 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1974 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
1976 for (i = 0; i < infoPtr->nNumButtons; i++)
1978 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
1979 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
1983 /* keeps available button list box sorted by button id */
1984 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1986 int i;
1987 int count;
1988 PCUSTOMBUTTON btnInfo;
1989 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1991 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1993 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1995 /* position 0 is always separator */
1996 for (i = 1; i < count; i++)
1998 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1999 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2001 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2002 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2003 return;
2006 /* id higher than all others add to end */
2007 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2008 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2011 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2013 NMTOOLBARW nmtb;
2015 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2017 if (nIndexFrom == nIndexTo)
2018 return;
2020 /* MSDN states that iItem is the index of the button, rather than the
2021 * command ID as used by every other NMTOOLBAR notification */
2022 nmtb.iItem = nIndexFrom;
2023 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2025 PCUSTOMBUTTON btnInfo;
2026 NMHDR hdr;
2027 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2028 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2030 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2032 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2033 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2034 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2035 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2037 if (nIndexTo <= 0)
2038 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2039 else
2040 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2042 /* last item is always separator, so -2 instead of -1 */
2043 if (nIndexTo >= (count - 2))
2044 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2045 else
2046 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2048 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2049 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2051 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2055 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2057 NMTOOLBARW nmtb;
2059 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2061 /* MSDN states that iItem is the index of the button, rather than the
2062 * command ID as used by every other NMTOOLBAR notification */
2063 nmtb.iItem = nIndexAvail;
2064 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2066 PCUSTOMBUTTON btnInfo;
2067 NMHDR hdr;
2068 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2069 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2070 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2072 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2074 if (nIndexAvail != 0) /* index == 0 indicates separator */
2076 /* remove from 'available buttons' list */
2077 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2078 if (nIndexAvail == count-1)
2079 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2080 else
2081 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2083 else
2085 PCUSTOMBUTTON btnNew;
2087 /* duplicate 'separator' button */
2088 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2089 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2090 btnInfo = btnNew;
2093 /* insert into 'toolbar button' list */
2094 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2095 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2097 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2099 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2103 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
2105 PCUSTOMBUTTON btnInfo;
2106 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2108 TRACE("Remove: index %d\n", index);
2110 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2112 /* send TBN_QUERYDELETE notification */
2113 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2115 NMHDR hdr;
2117 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2118 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2120 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2122 /* insert into 'available button' list */
2123 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2124 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2125 else
2126 Free(btnInfo);
2128 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2132 /* drag list notification function for toolbar buttons list box */
2133 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2135 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2136 switch (pDLI->uNotification)
2138 case DL_BEGINDRAG:
2140 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2141 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2142 /* no dragging for last item (separator) */
2143 if (nCurrentItem >= (nCount - 1)) return FALSE;
2144 return TRUE;
2146 case DL_DRAGGING:
2148 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2149 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2150 /* no dragging past last item (separator) */
2151 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2153 DrawInsert(hwnd, hwndList, nCurrentItem);
2154 /* FIXME: native uses "move button" cursor */
2155 return DL_COPYCURSOR;
2158 /* not over toolbar buttons list */
2159 if (nCurrentItem < 0)
2161 POINT ptWindow = pDLI->ptCursor;
2162 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2163 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2164 /* over available buttons list? */
2165 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2166 /* FIXME: native uses "move button" cursor */
2167 return DL_COPYCURSOR;
2169 /* clear drag arrow */
2170 DrawInsert(hwnd, hwndList, -1);
2171 return DL_STOPCURSOR;
2173 case DL_DROPPED:
2175 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2176 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2177 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2178 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2180 /* clear drag arrow */
2181 DrawInsert(hwnd, hwndList, -1);
2182 /* move item */
2183 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2185 /* not over toolbar buttons list */
2186 if (nIndexTo < 0)
2188 POINT ptWindow = pDLI->ptCursor;
2189 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2190 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2191 /* over available buttons list? */
2192 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2193 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2195 break;
2197 case DL_CANCELDRAG:
2198 /* Clear drag arrow */
2199 DrawInsert(hwnd, hwndList, -1);
2200 break;
2203 return 0;
2206 /* drag list notification function for available buttons list box */
2207 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2209 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2210 switch (pDLI->uNotification)
2212 case DL_BEGINDRAG:
2213 return TRUE;
2214 case DL_DRAGGING:
2216 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2217 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2218 /* no dragging past last item (separator) */
2219 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2221 DrawInsert(hwnd, hwndList, nCurrentItem);
2222 /* FIXME: native uses "move button" cursor */
2223 return DL_COPYCURSOR;
2226 /* not over toolbar buttons list */
2227 if (nCurrentItem < 0)
2229 POINT ptWindow = pDLI->ptCursor;
2230 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2231 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2232 /* over available buttons list? */
2233 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2234 /* FIXME: native uses "move button" cursor */
2235 return DL_COPYCURSOR;
2237 /* clear drag arrow */
2238 DrawInsert(hwnd, hwndList, -1);
2239 return DL_STOPCURSOR;
2241 case DL_DROPPED:
2243 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2244 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2245 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2246 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2248 /* clear drag arrow */
2249 DrawInsert(hwnd, hwndList, -1);
2250 /* add item */
2251 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2254 case DL_CANCELDRAG:
2255 /* Clear drag arrow */
2256 DrawInsert(hwnd, hwndList, -1);
2257 break;
2259 return 0;
2262 extern UINT uDragListMessage;
2264 /***********************************************************************
2265 * TOOLBAR_CustomizeDialogProc
2266 * This function implements the toolbar customization dialog.
2268 static INT_PTR CALLBACK
2269 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2271 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2272 PCUSTOMBUTTON btnInfo;
2273 NMTOOLBARA nmtb;
2274 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2276 switch (uMsg)
2278 case WM_INITDIALOG:
2279 custInfo = (PCUSTDLG_INFO)lParam;
2280 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2282 if (custInfo)
2284 WCHAR Buffer[256];
2285 int i = 0;
2286 int index;
2287 NMTBINITCUSTOMIZE nmtbic;
2289 infoPtr = custInfo->tbInfo;
2291 /* send TBN_QUERYINSERT notification */
2292 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2294 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2295 return FALSE;
2297 nmtbic.hwndDialog = hwnd;
2298 /* Send TBN_INITCUSTOMIZE notification */
2299 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2300 TBNRF_HIDEHELP)
2302 TRACE("TBNRF_HIDEHELP requested\n");
2303 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2306 /* add items to 'toolbar buttons' list and check if removable */
2307 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2309 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2310 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2311 btnInfo->btn.fsStyle = BTNS_SEP;
2312 btnInfo->bVirtual = FALSE;
2313 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2315 /* send TBN_QUERYDELETE notification */
2316 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2318 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2319 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2322 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2324 /* insert separator button into 'available buttons' list */
2325 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2326 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2327 btnInfo->btn.fsStyle = BTNS_SEP;
2328 btnInfo->bVirtual = FALSE;
2329 btnInfo->bRemovable = TRUE;
2330 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2331 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2332 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2334 /* insert all buttons into dsa */
2335 for (i = 0;; i++)
2337 /* send TBN_GETBUTTONINFO notification */
2338 NMTOOLBARW nmtb;
2339 nmtb.iItem = i;
2340 nmtb.pszText = Buffer;
2341 nmtb.cchText = 256;
2343 /* Clear previous button's text */
2344 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2346 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2347 break;
2349 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2350 nmtb.tbButton.fsStyle, i,
2351 nmtb.tbButton.idCommand,
2352 nmtb.tbButton.iString,
2353 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2354 : "");
2356 /* insert button into the apropriate list */
2357 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2358 if (index == -1)
2360 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2361 btnInfo->bVirtual = FALSE;
2362 btnInfo->bRemovable = TRUE;
2364 else
2366 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2367 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2370 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2371 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2373 if (lstrlenW(nmtb.pszText))
2374 lstrcpyW(btnInfo->text, nmtb.pszText);
2375 else if (nmtb.tbButton.iString >= 0 &&
2376 nmtb.tbButton.iString < infoPtr->nNumStrings)
2378 lstrcpyW(btnInfo->text,
2379 infoPtr->strings[nmtb.tbButton.iString]);
2383 if (index == -1)
2384 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2387 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2389 /* select first item in the 'available' list */
2390 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2392 /* append 'virtual' separator button to the 'toolbar buttons' list */
2393 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2394 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2395 btnInfo->btn.fsStyle = BTNS_SEP;
2396 btnInfo->bVirtual = TRUE;
2397 btnInfo->bRemovable = FALSE;
2398 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2399 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2400 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2402 /* select last item in the 'toolbar' list */
2403 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2404 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2406 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2407 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2409 /* set focus and disable buttons */
2410 PostMessageW (hwnd, WM_USER, 0, 0);
2412 return TRUE;
2414 case WM_USER:
2415 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2416 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2417 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2418 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2419 return TRUE;
2421 case WM_CLOSE:
2422 EndDialog(hwnd, FALSE);
2423 return TRUE;
2425 case WM_COMMAND:
2426 switch (LOWORD(wParam))
2428 case IDC_TOOLBARBTN_LBOX:
2429 if (HIWORD(wParam) == LBN_SELCHANGE)
2431 PCUSTOMBUTTON btnInfo;
2432 NMTOOLBARA nmtb;
2433 int count;
2434 int index;
2436 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2437 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2439 /* send TBN_QUERYINSERT notification */
2440 nmtb.iItem = index;
2441 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2443 /* get list box item */
2444 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2446 if (index == (count - 1))
2448 /* last item (virtual separator) */
2449 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2450 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2452 else if (index == (count - 2))
2454 /* second last item (last non-virtual item) */
2455 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2456 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2458 else if (index == 0)
2460 /* first item */
2461 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2462 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2464 else
2466 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2467 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2470 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2472 break;
2474 case IDC_MOVEUP_BTN:
2476 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2477 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2479 break;
2481 case IDC_MOVEDN_BTN: /* move down */
2483 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2484 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2486 break;
2488 case IDC_REMOVE_BTN: /* remove button */
2490 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2492 if (LB_ERR == index)
2493 break;
2495 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2497 break;
2498 case IDC_HELP_BTN:
2499 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2500 break;
2501 case IDC_RESET_BTN:
2502 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2503 break;
2505 case IDOK: /* Add button */
2507 int index;
2508 int indexto;
2510 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2511 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2513 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2515 break;
2517 case IDCANCEL:
2518 EndDialog(hwnd, FALSE);
2519 break;
2521 return TRUE;
2523 case WM_DESTROY:
2525 int count;
2526 int i;
2528 /* delete items from 'toolbar buttons' listbox*/
2529 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2530 for (i = 0; i < count; i++)
2532 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2533 Free(btnInfo);
2534 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2536 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2539 /* delete items from 'available buttons' listbox*/
2540 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2541 for (i = 0; i < count; i++)
2543 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2544 Free(btnInfo);
2545 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2547 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2549 return TRUE;
2551 case WM_DRAWITEM:
2552 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2554 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2555 RECT rcButton;
2556 RECT rcText;
2557 HPEN hPen, hOldPen;
2558 HBRUSH hOldBrush;
2559 COLORREF oldText = 0;
2560 COLORREF oldBk = 0;
2562 /* get item data */
2563 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2564 if (btnInfo == NULL)
2566 FIXME("btnInfo invalid!\n");
2567 return TRUE;
2570 /* set colors and select objects */
2571 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2572 if (btnInfo->bVirtual)
2573 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2574 else
2575 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2576 hPen = CreatePen( PS_SOLID, 1,
2577 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2578 hOldPen = SelectObject (lpdis->hDC, hPen );
2579 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2581 /* fill background rectangle */
2582 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2583 lpdis->rcItem.right, lpdis->rcItem.bottom);
2585 /* calculate button and text rectangles */
2586 CopyRect (&rcButton, &lpdis->rcItem);
2587 InflateRect (&rcButton, -1, -1);
2588 CopyRect (&rcText, &rcButton);
2589 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2590 rcText.left = rcButton.right + 2;
2592 /* draw focus rectangle */
2593 if (lpdis->itemState & ODS_FOCUS)
2594 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2596 /* draw button */
2597 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2598 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2600 /* draw image and text */
2601 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2602 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2603 btnInfo->btn.iBitmap));
2604 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2605 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2607 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2608 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2610 /* delete objects and reset colors */
2611 SelectObject (lpdis->hDC, hOldBrush);
2612 SelectObject (lpdis->hDC, hOldPen);
2613 SetBkColor (lpdis->hDC, oldBk);
2614 SetTextColor (lpdis->hDC, oldText);
2615 DeleteObject( hPen );
2616 return TRUE;
2618 return FALSE;
2620 case WM_MEASUREITEM:
2621 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2623 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2625 lpmis->itemHeight = 15 + 8; /* default height */
2627 return TRUE;
2629 return FALSE;
2631 default:
2632 if (uDragListMessage && (uMsg == uDragListMessage))
2634 if (wParam == IDC_TOOLBARBTN_LBOX)
2636 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2637 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2638 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2639 return TRUE;
2641 else if (wParam == IDC_AVAILBTN_LBOX)
2643 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2644 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2645 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2646 return TRUE;
2649 return FALSE;
2653 static BOOL
2654 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2656 HBITMAP hbmLoad;
2657 INT nCountBefore = ImageList_GetImageCount(himlDef);
2658 INT nCountAfter;
2659 INT cxIcon, cyIcon;
2660 INT nAdded;
2661 INT nIndex;
2663 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2664 /* Add bitmaps to the default image list */
2665 if (bitmap->hInst == NULL) /* a handle was passed */
2666 hbmLoad = (HBITMAP)CopyImage((HBITMAP)bitmap->nID, IMAGE_BITMAP, 0, 0, 0);
2667 else
2668 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2670 /* enlarge the bitmap if needed */
2671 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2672 if (bitmap->hInst != COMCTL32_hModule)
2673 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2675 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2676 DeleteObject(hbmLoad);
2677 if (nIndex == -1)
2678 return FALSE;
2680 nCountAfter = ImageList_GetImageCount(himlDef);
2681 nAdded = nCountAfter - nCountBefore;
2682 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2684 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2685 } else if (nAdded > (INT)bitmap->nButtons) {
2686 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2687 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2690 infoPtr->nNumBitmaps += nAdded;
2691 return TRUE;
2694 static void
2695 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2697 HIMAGELIST himlDef;
2698 HIMAGELIST himlNew;
2699 INT cx, cy;
2700 INT i;
2702 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2703 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2704 return;
2705 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2706 return;
2707 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2708 return;
2710 TRACE("Update icon size: %dx%d -> %dx%d\n",
2711 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2713 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2714 ILC_COLORDDB|ILC_MASK, 8, 2);
2715 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2716 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2717 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2718 infoPtr->himlInt = himlNew;
2720 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2721 ImageList_Destroy(himlDef);
2724 /***********************************************************************
2725 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2728 static LRESULT
2729 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2731 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2732 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2733 TBITMAP_INFO info;
2734 INT iSumButtons, i;
2735 HIMAGELIST himlDef;
2737 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2738 if (!lpAddBmp)
2739 return -1;
2741 if (lpAddBmp->hInst == HINST_COMMCTRL)
2743 info.hInst = COMCTL32_hModule;
2744 switch (lpAddBmp->nID)
2746 case IDB_STD_SMALL_COLOR:
2747 info.nButtons = 15;
2748 info.nID = IDB_STD_SMALL;
2749 break;
2750 case IDB_STD_LARGE_COLOR:
2751 info.nButtons = 15;
2752 info.nID = IDB_STD_LARGE;
2753 break;
2754 case IDB_VIEW_SMALL_COLOR:
2755 info.nButtons = 12;
2756 info.nID = IDB_VIEW_SMALL;
2757 break;
2758 case IDB_VIEW_LARGE_COLOR:
2759 info.nButtons = 12;
2760 info.nID = IDB_VIEW_LARGE;
2761 break;
2762 case IDB_HIST_SMALL_COLOR:
2763 info.nButtons = 5;
2764 info.nID = IDB_HIST_SMALL;
2765 break;
2766 case IDB_HIST_LARGE_COLOR:
2767 info.nButtons = 5;
2768 info.nID = IDB_HIST_LARGE;
2769 break;
2770 default:
2771 return -1;
2774 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2776 /* Windows resize all the buttons to the size of a newly added standard image */
2777 if (lpAddBmp->nID & 1)
2779 /* large icons: 24x24. Will make the button 31x30 */
2780 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
2782 else
2784 /* small icons: 16x16. Will make the buttons 23x22 */
2785 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
2788 TOOLBAR_CalcToolbar (hwnd);
2790 else
2792 info.nButtons = (INT)wParam;
2793 info.hInst = lpAddBmp->hInst;
2794 info.nID = lpAddBmp->nID;
2795 TRACE("adding %d bitmaps!\n", info.nButtons);
2798 /* check if the bitmap is already loaded and compute iSumButtons */
2799 iSumButtons = 0;
2800 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2802 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2803 infoPtr->bitmaps[i].nID == info.nID)
2804 return iSumButtons;
2805 iSumButtons += infoPtr->bitmaps[i].nButtons;
2808 if (!infoPtr->cimlDef) {
2809 /* create new default image list */
2810 TRACE ("creating default image list!\n");
2812 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2813 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2814 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2815 infoPtr->himlInt = himlDef;
2817 else {
2818 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2821 if (!himlDef) {
2822 WARN("No default image list available\n");
2823 return -1;
2826 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2827 return -1;
2829 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2830 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2831 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2832 infoPtr->nNumBitmapInfos++;
2833 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2835 InvalidateRect(hwnd, NULL, TRUE);
2836 return iSumButtons;
2840 static LRESULT
2841 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2843 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2844 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2845 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2846 BOOL fHasString = FALSE;
2848 TRACE("adding %d buttons (unicode=%d)!\n", wParam, fUnicode);
2850 nAddButtons = (UINT)wParam;
2851 nOldButtons = infoPtr->nNumButtons;
2852 nNewButtons = nOldButtons + nAddButtons;
2854 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
2855 infoPtr->nNumButtons = nNewButtons;
2857 /* insert new button data */
2858 for (nCount = 0; nCount < nAddButtons; nCount++) {
2859 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2860 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2861 btnPtr->idCommand = lpTbb[nCount].idCommand;
2862 btnPtr->fsState = lpTbb[nCount].fsState;
2863 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2864 btnPtr->dwData = lpTbb[nCount].dwData;
2865 btnPtr->bHot = FALSE;
2866 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2868 if (fUnicode)
2869 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2870 else
2871 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString);
2872 fHasString = TRUE;
2874 else
2875 btnPtr->iString = lpTbb[nCount].iString;
2877 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
2880 if (infoPtr->nNumStrings > 0 || fHasString)
2881 TOOLBAR_CalcToolbar(hwnd);
2882 else
2883 TOOLBAR_LayoutToolbar(hwnd);
2884 TOOLBAR_AutoSize (hwnd);
2886 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2888 InvalidateRect(hwnd, NULL, TRUE);
2890 return TRUE;
2894 static LRESULT
2895 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2897 #define MAX_RESOURCE_STRING_LENGTH 512
2898 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2899 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2900 INT nIndex = infoPtr->nNumStrings;
2902 if ((wParam) && (HIWORD(lParam) == 0)) {
2903 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2904 WCHAR delimiter;
2905 WCHAR *next_delim;
2906 WCHAR *p;
2907 INT len;
2908 TRACE("adding string from resource!\n");
2910 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2911 szString, MAX_RESOURCE_STRING_LENGTH);
2913 TRACE("len=%d %s\n", len, debugstr_w(szString));
2914 if (len == 0 || len == 1)
2915 return nIndex;
2917 TRACE("Delimiter: 0x%x\n", *szString);
2918 delimiter = *szString;
2919 p = szString + 1;
2921 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2922 *next_delim = 0;
2923 if (next_delim + 1 >= szString + len)
2925 /* this may happen if delimiter == '\0' or if the last char is a
2926 * delimiter (then it is ignored like the native does) */
2927 break;
2930 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2931 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2932 infoPtr->nNumStrings++;
2934 p = next_delim + 1;
2937 else {
2938 LPWSTR p = (LPWSTR)lParam;
2939 INT len;
2941 if (p == NULL)
2942 return -1;
2943 TRACE("adding string(s) from array!\n");
2944 while (*p) {
2945 len = strlenW (p);
2947 TRACE("len=%d %s\n", len, debugstr_w(p));
2948 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2949 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2950 infoPtr->nNumStrings++;
2952 p += (len+1);
2956 if (fFirstString)
2957 TOOLBAR_CalcToolbar(hwnd);
2958 return nIndex;
2962 static LRESULT
2963 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2965 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2966 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2967 LPSTR p;
2968 INT nIndex;
2969 INT len;
2971 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
2972 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
2974 p = (LPSTR)lParam;
2975 if (p == NULL)
2976 return -1;
2978 TRACE("adding string(s) from array!\n");
2979 nIndex = infoPtr->nNumStrings;
2980 while (*p) {
2981 len = strlen (p);
2982 TRACE("len=%d \"%s\"\n", len, p);
2984 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2985 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
2986 infoPtr->nNumStrings++;
2988 p += (len+1);
2991 if (fFirstString)
2992 TOOLBAR_CalcToolbar(hwnd);
2993 return nIndex;
2997 static LRESULT
2998 TOOLBAR_AutoSize (HWND hwnd)
3000 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3001 RECT parent_rect;
3002 HWND parent;
3003 INT x, y;
3004 INT cx, cy;
3006 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3008 parent = GetParent (hwnd);
3010 if (!parent || !infoPtr->bDoRedraw)
3011 return 0;
3013 GetClientRect(parent, &parent_rect);
3015 x = parent_rect.left;
3016 y = parent_rect.top;
3018 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3020 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3021 cx = parent_rect.right - parent_rect.left;
3023 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3025 TOOLBAR_LayoutToolbar(hwnd);
3026 InvalidateRect( hwnd, NULL, TRUE );
3029 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3031 RECT window_rect;
3032 UINT uPosFlags = SWP_NOZORDER;
3034 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3036 GetWindowRect(hwnd, &window_rect);
3037 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3038 y = window_rect.top;
3040 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3042 GetWindowRect(hwnd, &window_rect);
3043 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3046 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3047 uPosFlags |= SWP_NOMOVE;
3049 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3050 cy += GetSystemMetrics(SM_CYEDGE);
3052 if (infoPtr->dwStyle & WS_BORDER)
3054 x = y = 1; /* FIXME: this looks wrong */
3055 cy += GetSystemMetrics(SM_CYEDGE);
3056 cx += GetSystemMetrics(SM_CXEDGE);
3059 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3062 return 0;
3066 static LRESULT
3067 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3069 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3071 return infoPtr->nNumButtons;
3075 static LRESULT
3076 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3078 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3080 infoPtr->dwStructSize = (DWORD)wParam;
3082 return 0;
3086 static LRESULT
3087 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3089 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3090 TBUTTON_INFO *btnPtr;
3091 INT nIndex;
3093 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3095 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3096 if (nIndex == -1)
3097 return FALSE;
3099 btnPtr = &infoPtr->buttons[nIndex];
3100 btnPtr->iBitmap = LOWORD(lParam);
3102 /* we HAVE to erase the background, the new bitmap could be */
3103 /* transparent */
3104 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3106 return TRUE;
3110 static LRESULT
3111 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3113 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3114 TBUTTON_INFO *btnPtr;
3115 INT nIndex;
3116 INT nOldIndex = -1;
3117 BOOL bChecked = FALSE;
3119 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3121 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3123 if (nIndex == -1)
3124 return FALSE;
3126 btnPtr = &infoPtr->buttons[nIndex];
3128 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3130 if (LOWORD(lParam) == FALSE)
3131 btnPtr->fsState &= ~TBSTATE_CHECKED;
3132 else {
3133 if (btnPtr->fsStyle & BTNS_GROUP) {
3134 nOldIndex =
3135 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3136 if (nOldIndex == nIndex)
3137 return 0;
3138 if (nOldIndex != -1)
3139 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3141 btnPtr->fsState |= TBSTATE_CHECKED;
3144 if( bChecked != LOWORD(lParam) )
3146 if (nOldIndex != -1)
3147 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3148 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3151 /* FIXME: Send a WM_NOTIFY?? */
3153 return TRUE;
3157 static LRESULT
3158 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3160 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3162 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3166 static LRESULT
3167 TOOLBAR_Customize (HWND hwnd)
3169 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3170 CUSTDLG_INFO custInfo;
3171 LRESULT ret;
3172 LPCVOID template;
3173 HRSRC hRes;
3174 NMHDR nmhdr;
3176 custInfo.tbInfo = infoPtr;
3177 custInfo.tbHwnd = hwnd;
3179 /* send TBN_BEGINADJUST notification */
3180 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3182 if (!(hRes = FindResourceW (COMCTL32_hModule,
3183 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3184 (LPWSTR)RT_DIALOG)))
3185 return FALSE;
3187 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3188 return FALSE;
3190 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3191 (LPCDLGTEMPLATEW)template,
3192 hwnd,
3193 TOOLBAR_CustomizeDialogProc,
3194 (LPARAM)&custInfo);
3196 /* send TBN_ENDADJUST notification */
3197 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3199 return ret;
3203 static LRESULT
3204 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3206 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3207 INT nIndex = (INT)wParam;
3208 NMTOOLBARW nmtb;
3209 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3211 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3212 return FALSE;
3214 memset(&nmtb, 0, sizeof(nmtb));
3215 nmtb.iItem = btnPtr->idCommand;
3216 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3217 nmtb.tbButton.idCommand = btnPtr->idCommand;
3218 nmtb.tbButton.fsState = btnPtr->fsState;
3219 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3220 nmtb.tbButton.dwData = btnPtr->dwData;
3221 nmtb.tbButton.iString = btnPtr->iString;
3222 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3224 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3226 if (infoPtr->nNumButtons == 1) {
3227 TRACE(" simple delete!\n");
3228 Free (infoPtr->buttons);
3229 infoPtr->buttons = NULL;
3230 infoPtr->nNumButtons = 0;
3232 else {
3233 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3234 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3236 infoPtr->nNumButtons--;
3237 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3238 if (nIndex > 0) {
3239 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3240 nIndex * sizeof(TBUTTON_INFO));
3243 if (nIndex < infoPtr->nNumButtons) {
3244 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3245 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3248 Free (oldButtons);
3251 TOOLBAR_LayoutToolbar(hwnd);
3253 InvalidateRect (hwnd, NULL, TRUE);
3255 return TRUE;
3259 static LRESULT
3260 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3262 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3263 TBUTTON_INFO *btnPtr;
3264 INT nIndex;
3265 DWORD bState;
3267 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3269 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3271 if (nIndex == -1)
3272 return FALSE;
3274 btnPtr = &infoPtr->buttons[nIndex];
3276 bState = btnPtr->fsState & TBSTATE_ENABLED;
3278 /* update the toolbar button state */
3279 if(LOWORD(lParam) == FALSE) {
3280 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3281 } else {
3282 btnPtr->fsState |= TBSTATE_ENABLED;
3285 /* redraw the button only if the state of the button changed */
3286 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3287 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3289 return TRUE;
3293 static inline LRESULT
3294 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3296 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3298 return infoPtr->bAnchor;
3302 static LRESULT
3303 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3305 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3306 INT nIndex;
3308 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3309 if (nIndex == -1)
3310 return -1;
3312 return infoPtr->buttons[nIndex].iBitmap;
3316 static inline LRESULT
3317 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3319 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3323 static LRESULT
3324 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3326 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3327 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3328 INT nIndex = (INT)wParam;
3329 TBUTTON_INFO *btnPtr;
3331 if (lpTbb == NULL)
3332 return FALSE;
3334 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3335 return FALSE;
3337 btnPtr = &infoPtr->buttons[nIndex];
3338 lpTbb->iBitmap = btnPtr->iBitmap;
3339 lpTbb->idCommand = btnPtr->idCommand;
3340 lpTbb->fsState = btnPtr->fsState;
3341 lpTbb->fsStyle = btnPtr->fsStyle;
3342 lpTbb->bReserved[0] = 0;
3343 lpTbb->bReserved[1] = 0;
3344 lpTbb->dwData = btnPtr->dwData;
3345 lpTbb->iString = btnPtr->iString;
3347 return TRUE;
3351 static LRESULT
3352 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3354 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3355 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3356 TBUTTON_INFO *btnPtr;
3357 INT nIndex;
3359 if (lpTbInfo == NULL)
3360 return -1;
3361 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3362 return -1;
3364 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3365 lpTbInfo->dwMask & 0x80000000);
3366 if (nIndex == -1)
3367 return -1;
3369 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3371 if (lpTbInfo->dwMask & TBIF_COMMAND)
3372 lpTbInfo->idCommand = btnPtr->idCommand;
3373 if (lpTbInfo->dwMask & TBIF_IMAGE)
3374 lpTbInfo->iImage = btnPtr->iBitmap;
3375 if (lpTbInfo->dwMask & TBIF_LPARAM)
3376 lpTbInfo->lParam = btnPtr->dwData;
3377 if (lpTbInfo->dwMask & TBIF_SIZE)
3378 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3379 if (lpTbInfo->dwMask & TBIF_STATE)
3380 lpTbInfo->fsState = btnPtr->fsState;
3381 if (lpTbInfo->dwMask & TBIF_STYLE)
3382 lpTbInfo->fsStyle = btnPtr->fsStyle;
3383 if (lpTbInfo->dwMask & TBIF_TEXT) {
3384 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3385 can't use TOOLBAR_GetText here */
3386 LPWSTR lpText;
3387 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3388 lpText = (LPWSTR)btnPtr->iString;
3389 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3390 } else
3391 lpTbInfo->pszText[0] = '\0';
3393 return nIndex;
3397 static LRESULT
3398 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3400 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3401 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3402 TBUTTON_INFO *btnPtr;
3403 INT nIndex;
3405 if (lpTbInfo == NULL)
3406 return -1;
3407 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3408 return -1;
3410 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3411 lpTbInfo->dwMask & 0x80000000);
3412 if (nIndex == -1)
3413 return -1;
3415 btnPtr = &infoPtr->buttons[nIndex];
3417 if(!btnPtr)
3418 return -1;
3420 if (lpTbInfo->dwMask & TBIF_COMMAND)
3421 lpTbInfo->idCommand = btnPtr->idCommand;
3422 if (lpTbInfo->dwMask & TBIF_IMAGE)
3423 lpTbInfo->iImage = btnPtr->iBitmap;
3424 if (lpTbInfo->dwMask & TBIF_LPARAM)
3425 lpTbInfo->lParam = btnPtr->dwData;
3426 if (lpTbInfo->dwMask & TBIF_SIZE)
3427 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3428 if (lpTbInfo->dwMask & TBIF_STATE)
3429 lpTbInfo->fsState = btnPtr->fsState;
3430 if (lpTbInfo->dwMask & TBIF_STYLE)
3431 lpTbInfo->fsStyle = btnPtr->fsStyle;
3432 if (lpTbInfo->dwMask & TBIF_TEXT) {
3433 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3434 can't use TOOLBAR_GetText here */
3435 LPWSTR lpText;
3436 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3437 lpText = (LPWSTR)btnPtr->iString;
3438 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3439 } else
3440 lpTbInfo->pszText[0] = '\0';
3443 return nIndex;
3447 static LRESULT
3448 TOOLBAR_GetButtonSize (HWND hwnd)
3450 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3452 return MAKELONG((WORD)infoPtr->nButtonWidth,
3453 (WORD)infoPtr->nButtonHeight);
3457 static LRESULT
3458 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3460 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3461 INT nIndex;
3462 LPWSTR lpText;
3464 if (lParam == 0)
3465 return -1;
3467 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3468 if (nIndex == -1)
3469 return -1;
3471 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3473 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3474 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3478 static LRESULT
3479 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3481 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3482 INT nIndex;
3483 LPWSTR lpText;
3484 LRESULT ret = 0;
3486 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3487 if (nIndex == -1)
3488 return -1;
3490 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3492 if (lpText)
3494 ret = strlenW (lpText);
3496 if (lParam)
3497 strcpyW ((LPWSTR)lParam, lpText);
3500 return ret;
3504 static LRESULT
3505 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3507 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3508 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3509 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3513 static inline LRESULT
3514 TOOLBAR_GetExtendedStyle (HWND hwnd)
3516 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3518 TRACE("\n");
3520 return infoPtr->dwExStyle;
3524 static LRESULT
3525 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3527 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3528 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3529 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3533 static LRESULT
3534 TOOLBAR_GetHotItem (HWND hwnd)
3536 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3538 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3539 return -1;
3541 if (infoPtr->nHotItem < 0)
3542 return -1;
3544 return (LRESULT)infoPtr->nHotItem;
3548 static LRESULT
3549 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3551 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3552 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3553 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3557 static LRESULT
3558 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3560 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3561 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3563 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3565 *lptbim = infoPtr->tbim;
3567 return 0;
3571 static LRESULT
3572 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3574 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3576 TRACE("hwnd = %p\n", hwnd);
3578 return (LRESULT)infoPtr->clrInsertMark;
3582 static LRESULT
3583 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3585 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3586 TBUTTON_INFO *btnPtr;
3587 LPRECT lpRect;
3588 INT nIndex;
3590 nIndex = (INT)wParam;
3591 btnPtr = &infoPtr->buttons[nIndex];
3592 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3593 return FALSE;
3594 lpRect = (LPRECT)lParam;
3595 if (lpRect == NULL)
3596 return FALSE;
3597 if (btnPtr->fsState & TBSTATE_HIDDEN)
3598 return FALSE;
3600 lpRect->left = btnPtr->rect.left;
3601 lpRect->right = btnPtr->rect.right;
3602 lpRect->bottom = btnPtr->rect.bottom;
3603 lpRect->top = btnPtr->rect.top;
3605 return TRUE;
3609 static LRESULT
3610 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3612 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3613 LPSIZE lpSize = (LPSIZE)lParam;
3615 if (lpSize == NULL)
3616 return FALSE;
3618 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3619 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3621 TRACE("maximum size %d x %d\n",
3622 infoPtr->rcBound.right - infoPtr->rcBound.left,
3623 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3625 return TRUE;
3629 /* << TOOLBAR_GetObject >> */
3632 static LRESULT
3633 TOOLBAR_GetPadding (HWND hwnd)
3635 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3636 DWORD oldPad;
3638 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3639 return (LRESULT) oldPad;
3643 static LRESULT
3644 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3646 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3647 TBUTTON_INFO *btnPtr;
3648 LPRECT lpRect;
3649 INT nIndex;
3651 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3652 btnPtr = &infoPtr->buttons[nIndex];
3653 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3654 return FALSE;
3655 lpRect = (LPRECT)lParam;
3656 if (lpRect == NULL)
3657 return FALSE;
3659 lpRect->left = btnPtr->rect.left;
3660 lpRect->right = btnPtr->rect.right;
3661 lpRect->bottom = btnPtr->rect.bottom;
3662 lpRect->top = btnPtr->rect.top;
3664 return TRUE;
3668 static LRESULT
3669 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3671 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3673 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3674 return infoPtr->nRows;
3675 else
3676 return 1;
3680 static LRESULT
3681 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3683 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3684 INT nIndex;
3686 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3687 if (nIndex == -1)
3688 return -1;
3690 return infoPtr->buttons[nIndex].fsState;
3694 static LRESULT
3695 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3697 return GetWindowLongW(hwnd, GWL_STYLE);
3701 static LRESULT
3702 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3704 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3706 return infoPtr->nMaxTextRows;
3710 static LRESULT
3711 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3713 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3715 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3716 TOOLBAR_TooltipCreateControl(infoPtr);
3717 return (LRESULT)infoPtr->hwndToolTip;
3721 static LRESULT
3722 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3724 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3726 TRACE("%s hwnd=%p\n",
3727 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3729 return infoPtr->bUnicode;
3733 static inline LRESULT
3734 TOOLBAR_GetVersion (HWND hwnd)
3736 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3737 return infoPtr->iVersion;
3741 static LRESULT
3742 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3744 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3745 TBUTTON_INFO *btnPtr;
3746 INT nIndex;
3748 TRACE("\n");
3750 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3751 if (nIndex == -1)
3752 return FALSE;
3754 btnPtr = &infoPtr->buttons[nIndex];
3755 if (LOWORD(lParam) == FALSE)
3756 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3757 else
3758 btnPtr->fsState |= TBSTATE_HIDDEN;
3760 TOOLBAR_LayoutToolbar (hwnd);
3762 InvalidateRect (hwnd, NULL, TRUE);
3764 return TRUE;
3768 static inline LRESULT
3769 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3771 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3775 static LRESULT
3776 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3778 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3779 TBUTTON_INFO *btnPtr;
3780 INT nIndex;
3781 DWORD oldState;
3783 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3784 if (nIndex == -1)
3785 return FALSE;
3787 btnPtr = &infoPtr->buttons[nIndex];
3788 oldState = btnPtr->fsState;
3789 if (LOWORD(lParam) == FALSE)
3790 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3791 else
3792 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3794 if(oldState != btnPtr->fsState)
3795 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3797 return TRUE;
3801 static LRESULT
3802 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3804 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3805 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3806 INT nIndex = (INT)wParam;
3808 if (lpTbb == NULL)
3809 return FALSE;
3811 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3813 if (nIndex == -1) {
3814 /* EPP: this seems to be an undocumented call (from my IE4)
3815 * I assume in that case that:
3816 * - index of insertion is at the end of existing buttons
3817 * I only see this happen with nIndex == -1, but it could have a special
3818 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3820 nIndex = infoPtr->nNumButtons;
3822 } else if (nIndex < 0)
3823 return FALSE;
3825 TRACE("inserting button index=%d\n", nIndex);
3826 if (nIndex > infoPtr->nNumButtons) {
3827 nIndex = infoPtr->nNumButtons;
3828 TRACE("adjust index=%d\n", nIndex);
3831 infoPtr->nNumButtons++;
3832 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO) * infoPtr->nNumButtons);
3833 memmove(&infoPtr->buttons[nIndex+1], &infoPtr->buttons[nIndex],
3834 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3836 /* insert new button */
3837 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3838 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3839 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3840 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3841 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3842 /* if passed string and not index, then add string */
3843 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3844 if (fUnicode)
3845 Str_SetPtrW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3846 else
3847 Str_SetPtrAtoW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3849 else
3850 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3852 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
3854 if (infoPtr->nNumStrings > 0)
3855 TOOLBAR_CalcToolbar(hwnd);
3856 else
3857 TOOLBAR_LayoutToolbar(hwnd);
3858 TOOLBAR_AutoSize (hwnd);
3860 InvalidateRect (hwnd, NULL, TRUE);
3862 return TRUE;
3865 /* << TOOLBAR_InsertMarkHitTest >> */
3868 static LRESULT
3869 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3871 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3872 INT nIndex;
3874 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3875 if (nIndex == -1)
3876 return FALSE;
3878 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3882 static LRESULT
3883 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3885 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3886 INT nIndex;
3888 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3889 if (nIndex == -1)
3890 return FALSE;
3892 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3896 static LRESULT
3897 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3899 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3900 INT nIndex;
3902 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3903 if (nIndex == -1)
3904 return TRUE;
3906 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3910 static LRESULT
3911 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3913 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3914 INT nIndex;
3916 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3917 if (nIndex == -1)
3918 return FALSE;
3920 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3924 static LRESULT
3925 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3927 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3928 INT nIndex;
3930 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3931 if (nIndex == -1)
3932 return FALSE;
3934 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3938 static LRESULT
3939 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3941 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3942 INT nIndex;
3944 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3945 if (nIndex == -1)
3946 return FALSE;
3948 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3952 static LRESULT
3953 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3955 TBADDBITMAP tbab;
3956 tbab.hInst = (HINSTANCE)lParam;
3957 tbab.nID = (UINT_PTR)wParam;
3959 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3961 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3965 static LRESULT
3966 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3968 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3969 WCHAR wAccel = (WCHAR)wParam;
3970 UINT* pIDButton = (UINT*)lParam;
3971 WCHAR wszAccel[] = {'&',wAccel,0};
3972 int i;
3974 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3975 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3977 for (i = 0; i < infoPtr->nNumButtons; i++)
3979 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3980 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3981 !(btnPtr->fsState & TBSTATE_HIDDEN))
3983 int iLen = strlenW(wszAccel);
3984 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3986 if (!lpszStr)
3987 continue;
3989 while (*lpszStr)
3991 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3993 lpszStr += 2;
3994 continue;
3996 if (!strncmpiW(lpszStr, wszAccel, iLen))
3998 *pIDButton = btnPtr->idCommand;
3999 return TRUE;
4001 lpszStr++;
4005 return FALSE;
4009 static LRESULT
4010 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4012 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4013 INT nIndex;
4014 DWORD oldState;
4015 TBUTTON_INFO *btnPtr;
4017 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4019 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4020 if (nIndex == -1)
4021 return FALSE;
4023 btnPtr = &infoPtr->buttons[nIndex];
4024 oldState = btnPtr->fsState;
4026 if (LOWORD(lParam))
4027 btnPtr->fsState |= TBSTATE_MARKED;
4028 else
4029 btnPtr->fsState &= ~TBSTATE_MARKED;
4031 if(oldState != btnPtr->fsState)
4032 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4034 return TRUE;
4038 /* fixes up an index of a button affected by a move */
4039 static inline void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4041 if (bMoveUp)
4043 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4044 (*pIndex)--;
4045 else if (*pIndex == nIndex)
4046 *pIndex = nMoveIndex;
4048 else
4050 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4051 (*pIndex)++;
4052 else if (*pIndex == nIndex)
4053 *pIndex = nMoveIndex;
4058 static LRESULT
4059 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4061 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4062 INT nIndex;
4063 INT nCount;
4064 INT nMoveIndex = (INT)lParam;
4065 TBUTTON_INFO button;
4067 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4069 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4070 if ((nIndex == -1) || (nMoveIndex < 0))
4071 return FALSE;
4073 if (nMoveIndex > infoPtr->nNumButtons - 1)
4074 nMoveIndex = infoPtr->nNumButtons - 1;
4076 button = infoPtr->buttons[nIndex];
4078 /* move button right */
4079 if (nIndex < nMoveIndex)
4081 nCount = nMoveIndex - nIndex;
4082 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4083 infoPtr->buttons[nMoveIndex] = button;
4085 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4086 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4087 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4088 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4090 else if (nIndex > nMoveIndex) /* move button left */
4092 nCount = nIndex - nMoveIndex;
4093 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4094 infoPtr->buttons[nMoveIndex] = button;
4096 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4097 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4098 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4099 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4102 TOOLBAR_LayoutToolbar(hwnd);
4103 TOOLBAR_AutoSize(hwnd);
4104 InvalidateRect(hwnd, NULL, TRUE);
4106 return TRUE;
4110 static LRESULT
4111 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4113 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4114 TBUTTON_INFO *btnPtr;
4115 INT nIndex;
4116 DWORD oldState;
4118 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4119 if (nIndex == -1)
4120 return FALSE;
4122 btnPtr = &infoPtr->buttons[nIndex];
4123 oldState = btnPtr->fsState;
4124 if (LOWORD(lParam) == FALSE)
4125 btnPtr->fsState &= ~TBSTATE_PRESSED;
4126 else
4127 btnPtr->fsState |= TBSTATE_PRESSED;
4129 if(oldState != btnPtr->fsState)
4130 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4132 return TRUE;
4135 /* FIXME: there might still be some confusion her between number of buttons
4136 * and number of bitmaps */
4137 static LRESULT
4138 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4140 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4141 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4142 HBITMAP hBitmap;
4143 int i = 0, nOldButtons = 0, pos = 0;
4144 int nOldBitmaps, nNewBitmaps = 0;
4145 HIMAGELIST himlDef = 0;
4147 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4148 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4149 lpReplace->nButtons);
4151 if (lpReplace->hInstOld == HINST_COMMCTRL)
4153 FIXME("changing standard bitmaps not implemented\n");
4154 return FALSE;
4156 else if (lpReplace->hInstOld != 0)
4157 FIXME("resources not in the current module not implemented\n");
4159 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4160 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4161 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4162 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4163 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4165 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4166 nOldButtons = tbi->nButtons;
4167 tbi->nButtons = lpReplace->nButtons;
4168 tbi->hInst = lpReplace->hInstNew;
4169 tbi->nID = lpReplace->nIDNew;
4170 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4171 break;
4173 pos += tbi->nButtons;
4176 if (nOldButtons == 0)
4178 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4179 return FALSE;
4182 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4183 * bitmap
4185 if (lpReplace->hInstNew)
4186 hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4187 else
4188 hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
4190 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4191 nOldBitmaps = ImageList_GetImageCount(himlDef);
4193 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4195 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4196 ImageList_Remove(himlDef, i);
4198 if (hBitmap)
4200 ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
4201 nNewBitmaps = ImageList_GetImageCount(himlDef);
4202 DeleteObject(hBitmap);
4205 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4207 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4208 pos, nOldBitmaps, nNewBitmaps);
4210 InvalidateRect(hwnd, NULL, TRUE);
4211 return TRUE;
4215 /* helper for TOOLBAR_SaveRestoreW */
4216 static BOOL
4217 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4219 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4220 debugstr_w(lpSave->pszValueName));
4222 return FALSE;
4226 /* helper for TOOLBAR_Restore */
4227 static void
4228 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4230 INT i;
4232 for (i = 0; i < infoPtr->nNumButtons; i++)
4234 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4237 Free(infoPtr->buttons);
4238 infoPtr->buttons = NULL;
4239 infoPtr->nNumButtons = 0;
4243 /* helper for TOOLBAR_SaveRestoreW */
4244 static BOOL
4245 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4247 LONG res;
4248 HKEY hkey = NULL;
4249 BOOL ret = FALSE;
4250 DWORD dwType;
4251 DWORD dwSize = 0;
4252 NMTBRESTORE nmtbr;
4254 /* restore toolbar information */
4255 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4256 debugstr_w(lpSave->pszValueName));
4258 memset(&nmtbr, 0, sizeof(nmtbr));
4260 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4261 KEY_QUERY_VALUE, &hkey);
4262 if (!res)
4263 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4264 NULL, &dwSize);
4265 if (!res && dwType != REG_BINARY)
4266 res = ERROR_FILE_NOT_FOUND;
4267 if (!res)
4269 nmtbr.pData = Alloc(dwSize);
4270 nmtbr.cbData = (UINT)dwSize;
4271 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4273 if (!res)
4274 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4275 (LPBYTE)nmtbr.pData, &dwSize);
4276 if (!res)
4278 nmtbr.pCurrent = nmtbr.pData;
4279 nmtbr.iItem = -1;
4280 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4281 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4283 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4285 INT i;
4287 /* remove all existing buttons as this function is designed to
4288 * restore the toolbar to a previously saved state */
4289 TOOLBAR_DeleteAllButtons(infoPtr);
4291 for (i = 0; i < nmtbr.cButtons; i++)
4293 nmtbr.iItem = i;
4294 nmtbr.tbButton.iBitmap = -1;
4295 nmtbr.tbButton.fsState = 0;
4296 nmtbr.tbButton.fsStyle = 0;
4297 nmtbr.tbButton.idCommand = 0;
4298 if (*nmtbr.pCurrent == (DWORD)-1)
4300 /* separator */
4301 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4302 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4304 else if (*nmtbr.pCurrent == (DWORD)-2)
4305 /* hidden button */
4306 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4307 else
4308 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4310 nmtbr.pCurrent++;
4312 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4314 /* can't contain real string as we don't know whether
4315 * the client put an ANSI or Unicode string in there */
4316 if (HIWORD(nmtbr.tbButton.iString))
4317 nmtbr.tbButton.iString = 0;
4319 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4320 (LPARAM)&nmtbr.tbButton, TRUE);
4323 /* do legacy notifications */
4324 if (infoPtr->iVersion < 5)
4326 /* FIXME: send TBN_BEGINADJUST */
4327 FIXME("send TBN_GETBUTTONINFO for each button\n");
4328 /* FIXME: send TBN_ENDADJUST */
4331 /* remove all uninitialised buttons
4332 * note: loop backwards to avoid having to fixup i on a
4333 * delete */
4334 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4335 if (infoPtr->buttons[i].iBitmap == -1)
4336 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4338 /* only indicate success if at least one button survived */
4339 if (infoPtr->nNumButtons > 0) ret = TRUE;
4342 Free (nmtbr.pData);
4343 RegCloseKey(hkey);
4345 return ret;
4349 static LRESULT
4350 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4352 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4354 if (lpSave == NULL) return 0;
4356 if (wParam)
4357 return TOOLBAR_Save(infoPtr, lpSave);
4358 else
4359 return TOOLBAR_Restore(infoPtr, lpSave);
4363 static LRESULT
4364 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4366 LPWSTR pszValueName = 0, pszSubKey = 0;
4367 TBSAVEPARAMSW SaveW;
4368 LRESULT result = 0;
4369 int len;
4371 if (lpSave == NULL) return 0;
4373 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4374 pszSubKey = Alloc(len * sizeof(WCHAR));
4375 if (pszSubKey) goto exit;
4376 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4378 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4379 pszValueName = Alloc(len * sizeof(WCHAR));
4380 if (!pszValueName) goto exit;
4381 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4383 SaveW.pszValueName = pszValueName;
4384 SaveW.pszSubKey = pszSubKey;
4385 SaveW.hkr = lpSave->hkr;
4386 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4388 exit:
4389 Free (pszValueName);
4390 Free (pszSubKey);
4392 return result;
4396 static LRESULT
4397 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4399 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4400 BOOL bOldAnchor = infoPtr->bAnchor;
4402 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4404 infoPtr->bAnchor = (BOOL)wParam;
4406 /* Native does not remove the hot effect from an already hot button */
4408 return (LRESULT)bOldAnchor;
4412 static LRESULT
4413 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4415 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4416 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4418 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4420 if (wParam != 0)
4421 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4423 if (LOWORD(lParam) == 0)
4424 lParam = MAKELPARAM(1, HIWORD(lParam));
4426 if (HIWORD(lParam)==0)
4427 lParam = MAKELPARAM(LOWORD(lParam), 1);
4429 if (infoPtr->nNumButtons > 0)
4430 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4431 infoPtr->nNumButtons,
4432 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4433 LOWORD(lParam), HIWORD(lParam));
4435 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4436 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4438 if ((himlDef == infoPtr->himlInt) &&
4439 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4441 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4442 infoPtr->nBitmapHeight);
4445 TOOLBAR_CalcToolbar(hwnd);
4446 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4447 return TRUE;
4451 static LRESULT
4452 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4454 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4455 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4456 TBUTTON_INFO *btnPtr;
4457 INT nIndex;
4458 RECT oldBtnRect;
4460 if (lptbbi == NULL)
4461 return FALSE;
4462 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4463 return FALSE;
4465 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4466 lptbbi->dwMask & 0x80000000);
4467 if (nIndex == -1)
4468 return FALSE;
4470 btnPtr = &infoPtr->buttons[nIndex];
4471 if (lptbbi->dwMask & TBIF_COMMAND)
4472 btnPtr->idCommand = lptbbi->idCommand;
4473 if (lptbbi->dwMask & TBIF_IMAGE)
4474 btnPtr->iBitmap = lptbbi->iImage;
4475 if (lptbbi->dwMask & TBIF_LPARAM)
4476 btnPtr->dwData = lptbbi->lParam;
4477 if (lptbbi->dwMask & TBIF_SIZE)
4478 btnPtr->cx = lptbbi->cx;
4479 if (lptbbi->dwMask & TBIF_STATE)
4480 btnPtr->fsState = lptbbi->fsState;
4481 if (lptbbi->dwMask & TBIF_STYLE)
4482 btnPtr->fsStyle = lptbbi->fsStyle;
4484 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4485 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4486 /* iString is index, zero it to make Str_SetPtr succeed */
4487 btnPtr->iString=0;
4489 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4492 /* save the button rect to see if we need to redraw the whole toolbar */
4493 oldBtnRect = btnPtr->rect;
4494 TOOLBAR_CalcToolbar(hwnd);
4496 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4497 InvalidateRect(hwnd, NULL, TRUE);
4498 else
4499 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4501 return TRUE;
4505 static LRESULT
4506 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4508 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4509 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4510 TBUTTON_INFO *btnPtr;
4511 INT nIndex;
4512 RECT oldBtnRect;
4514 if (lptbbi == NULL)
4515 return FALSE;
4516 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4517 return FALSE;
4519 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4520 lptbbi->dwMask & 0x80000000);
4521 if (nIndex == -1)
4522 return FALSE;
4524 btnPtr = &infoPtr->buttons[nIndex];
4525 if (lptbbi->dwMask & TBIF_COMMAND)
4526 btnPtr->idCommand = lptbbi->idCommand;
4527 if (lptbbi->dwMask & TBIF_IMAGE)
4528 btnPtr->iBitmap = lptbbi->iImage;
4529 if (lptbbi->dwMask & TBIF_LPARAM)
4530 btnPtr->dwData = lptbbi->lParam;
4531 if (lptbbi->dwMask & TBIF_SIZE)
4532 btnPtr->cx = lptbbi->cx;
4533 if (lptbbi->dwMask & TBIF_STATE)
4534 btnPtr->fsState = lptbbi->fsState;
4535 if (lptbbi->dwMask & TBIF_STYLE)
4536 btnPtr->fsStyle = lptbbi->fsStyle;
4538 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4539 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4540 /* iString is index, zero it to make Str_SetPtr succeed */
4541 btnPtr->iString=0;
4542 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4545 /* save the button rect to see if we need to redraw the whole toolbar */
4546 oldBtnRect = btnPtr->rect;
4547 TOOLBAR_CalcToolbar(hwnd);
4549 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4550 InvalidateRect(hwnd, NULL, TRUE);
4551 else
4552 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4554 return TRUE;
4558 static LRESULT
4559 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4561 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4562 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4564 if ((cx < 0) || (cy < 0))
4566 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4567 return FALSE;
4570 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4572 /* The documentation claims you can only change the button size before
4573 * any button has been added. But this is wrong.
4574 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4575 * it to the toolbar, and it checks that the return value is nonzero - mjm
4576 * Further testing shows that we must actually perform the change too.
4579 * The documentation also does not mention that if 0 is supplied for
4580 * either size, the system changes it to the default of 24 wide and
4581 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4583 if (cx == 0) cx = 24;
4584 if (cy == 0) cx = 22;
4586 cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
4587 cy = max(cy, infoPtr->szPadding.cy + infoPtr->nBitmapHeight);
4589 infoPtr->nButtonWidth = cx;
4590 infoPtr->nButtonHeight = cy;
4592 infoPtr->iTopMargin = default_top_margin(infoPtr);
4593 TOOLBAR_LayoutToolbar(hwnd);
4594 return TRUE;
4598 static LRESULT
4599 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4601 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4603 /* if setting to current values, ignore */
4604 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4605 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4606 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4607 infoPtr->cxMin, infoPtr->cxMax);
4608 return TRUE;
4611 /* save new values */
4612 infoPtr->cxMin = (short)LOWORD(lParam);
4613 infoPtr->cxMax = (short)HIWORD(lParam);
4615 /* otherwise we need to recalc the toolbar and in some cases
4616 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4617 which doesn't actually draw - GA). */
4618 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4619 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4621 TOOLBAR_CalcToolbar (hwnd);
4623 InvalidateRect (hwnd, NULL, TRUE);
4625 return TRUE;
4629 static LRESULT
4630 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4632 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4633 INT nIndex = (INT)wParam;
4635 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4636 return FALSE;
4638 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4640 if (infoPtr->hwndToolTip) {
4642 FIXME("change tool tip!\n");
4646 return TRUE;
4650 static LRESULT
4651 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4653 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4654 HIMAGELIST himl = (HIMAGELIST)lParam;
4655 HIMAGELIST himlTemp;
4656 INT id = 0;
4658 if (infoPtr->iVersion >= 5)
4659 id = wParam;
4661 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4662 &infoPtr->cimlDis, himl, id);
4664 /* FIXME: redraw ? */
4666 return (LRESULT)himlTemp;
4670 static LRESULT
4671 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4673 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4674 DWORD dwTemp;
4676 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4678 dwTemp = infoPtr->dwDTFlags;
4679 infoPtr->dwDTFlags =
4680 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4682 return (LRESULT)dwTemp;
4685 /* This function differs a bit from what MSDN says it does:
4686 * 1. lParam contains extended style flags to OR with current style
4687 * (MSDN isn't clear on the OR bit)
4688 * 2. wParam appears to contain extended style flags to be reset
4689 * (MSDN says that this parameter is reserved)
4691 static LRESULT
4692 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4694 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4695 DWORD dwTemp;
4697 dwTemp = infoPtr->dwExStyle;
4698 infoPtr->dwExStyle &= ~wParam;
4699 infoPtr->dwExStyle |= (DWORD)lParam;
4701 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4703 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4704 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4705 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4707 TOOLBAR_CalcToolbar (hwnd);
4709 TOOLBAR_AutoSize(hwnd);
4711 InvalidateRect(hwnd, NULL, TRUE);
4713 return (LRESULT)dwTemp;
4717 static LRESULT
4718 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4720 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4721 HIMAGELIST himlTemp;
4722 HIMAGELIST himl = (HIMAGELIST)lParam;
4723 INT id = 0;
4725 if (infoPtr->iVersion >= 5)
4726 id = wParam;
4728 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4730 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4731 &infoPtr->cimlHot, himl, id);
4733 /* FIXME: redraw ? */
4735 return (LRESULT)himlTemp;
4739 /* Makes previous hot button no longer hot, makes the specified
4740 * button hot and sends appropriate notifications. dwReason is one or
4741 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4742 * NOTE 1: this function does not validate nHit
4743 * NOTE 2: the name of this function is completely made up and
4744 * not based on any documentation from Microsoft. */
4745 static void
4746 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4748 if (infoPtr->nHotItem != nHit)
4750 NMTBHOTITEM nmhotitem;
4751 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4753 nmhotitem.dwFlags = dwReason;
4754 if(infoPtr->nHotItem >= 0)
4756 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4757 nmhotitem.idOld = oldBtnPtr->idCommand;
4759 else
4761 nmhotitem.dwFlags |= HICF_ENTERING;
4762 nmhotitem.idOld = 0;
4765 if (nHit >= 0)
4767 btnPtr = &infoPtr->buttons[nHit];
4768 nmhotitem.idNew = btnPtr->idCommand;
4770 else
4772 nmhotitem.dwFlags |= HICF_LEAVING;
4773 nmhotitem.idNew = 0;
4776 /* now change the hot and invalidate the old and new buttons - if the
4777 * parent agrees */
4778 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4780 if (oldBtnPtr) {
4781 oldBtnPtr->bHot = FALSE;
4782 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4784 /* setting disabled buttons as hot fails even if the notify contains the button id */
4785 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4786 btnPtr->bHot = TRUE;
4787 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4788 infoPtr->nHotItem = nHit;
4790 else
4791 infoPtr->nHotItem = -1;
4796 static LRESULT
4797 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4799 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4800 INT nOldHotItem = infoPtr->nHotItem;
4802 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4804 if ((INT)wParam > infoPtr->nNumButtons)
4805 return infoPtr->nHotItem;
4807 if ((INT)wParam < 0)
4808 wParam = -1;
4810 /* NOTE: an application can still remove the hot item even if anchor
4811 * highlighting is enabled */
4813 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4815 if (nOldHotItem < 0)
4816 return -1;
4818 return (LRESULT)nOldHotItem;
4822 static LRESULT
4823 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4825 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4826 HIMAGELIST himlTemp;
4827 HIMAGELIST himl = (HIMAGELIST)lParam;
4828 INT i, id = 0;
4830 if (infoPtr->iVersion >= 5)
4831 id = wParam;
4833 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4834 &infoPtr->cimlDef, himl, id);
4836 infoPtr->nNumBitmaps = 0;
4837 for (i = 0; i < infoPtr->cimlDef; i++)
4838 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4840 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4841 &infoPtr->nBitmapHeight))
4843 infoPtr->nBitmapWidth = 1;
4844 infoPtr->nBitmapHeight = 1;
4846 TOOLBAR_CalcToolbar(hwnd);
4848 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4849 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4850 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4852 InvalidateRect(hwnd, NULL, TRUE);
4854 return (LRESULT)himlTemp;
4858 static LRESULT
4859 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4861 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4863 infoPtr->nIndent = (INT)wParam;
4865 TRACE("\n");
4867 /* process only on indent changing */
4868 if(infoPtr->nIndent != (INT)wParam)
4870 infoPtr->nIndent = (INT)wParam;
4871 TOOLBAR_CalcToolbar (hwnd);
4872 InvalidateRect(hwnd, NULL, FALSE);
4875 return TRUE;
4879 static LRESULT
4880 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4882 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4883 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4885 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4887 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4889 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4890 return 0;
4893 if ((lptbim->iButton == -1) ||
4894 ((lptbim->iButton < infoPtr->nNumButtons) &&
4895 (lptbim->iButton >= 0)))
4897 infoPtr->tbim = *lptbim;
4898 /* FIXME: don't need to update entire toolbar */
4899 InvalidateRect(hwnd, NULL, TRUE);
4901 else
4902 ERR("Invalid button index %d\n", lptbim->iButton);
4904 return 0;
4908 static LRESULT
4909 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4911 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4913 infoPtr->clrInsertMark = (COLORREF)lParam;
4915 /* FIXME: don't need to update entire toolbar */
4916 InvalidateRect(hwnd, NULL, TRUE);
4918 return 0;
4922 static LRESULT
4923 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4925 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4927 infoPtr->nMaxTextRows = (INT)wParam;
4929 TOOLBAR_CalcToolbar(hwnd);
4930 return TRUE;
4934 /* MSDN gives slightly wrong info on padding.
4935 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4936 * 2. It is not used to create a blank area between the edge of the button
4937 * and the text or image if TBSTYLE_LIST is set. It is used to control
4938 * the gap between the image and text.
4939 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4940 * to control the bottom and right borders [with the border being
4941 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4942 * is shared evenly on both sides of the button.
4943 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4945 static LRESULT
4946 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4948 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4949 DWORD oldPad;
4951 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4952 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4953 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4954 TRACE("cx=%d, cy=%d\n",
4955 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4956 return (LRESULT) oldPad;
4960 static LRESULT
4961 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4963 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4964 HWND hwndOldNotify;
4966 TRACE("\n");
4968 hwndOldNotify = infoPtr->hwndNotify;
4969 infoPtr->hwndNotify = (HWND)wParam;
4971 return (LRESULT)hwndOldNotify;
4975 static LRESULT
4976 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4978 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4979 LPRECT lprc = (LPRECT)lParam;
4981 TRACE("\n");
4983 if (LOWORD(wParam) > 1) {
4984 FIXME("multiple rows not supported!\n");
4987 if(infoPtr->nRows != LOWORD(wParam))
4989 infoPtr->nRows = LOWORD(wParam);
4991 /* recalculate toolbar */
4992 TOOLBAR_CalcToolbar (hwnd);
4994 /* repaint toolbar */
4995 InvalidateRect(hwnd, NULL, TRUE);
4998 /* return bounding rectangle */
4999 if (lprc) {
5000 lprc->left = infoPtr->rcBound.left;
5001 lprc->right = infoPtr->rcBound.right;
5002 lprc->top = infoPtr->rcBound.top;
5003 lprc->bottom = infoPtr->rcBound.bottom;
5006 return 0;
5010 static LRESULT
5011 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5013 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5014 TBUTTON_INFO *btnPtr;
5015 INT nIndex;
5017 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5018 if (nIndex == -1)
5019 return FALSE;
5021 btnPtr = &infoPtr->buttons[nIndex];
5023 /* if hidden state has changed the invalidate entire window and recalc */
5024 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5025 btnPtr->fsState = LOWORD(lParam);
5026 TOOLBAR_CalcToolbar (hwnd);
5027 InvalidateRect(hwnd, 0, TRUE);
5028 return TRUE;
5031 /* process state changing if current state doesn't match new state */
5032 if(btnPtr->fsState != LOWORD(lParam))
5034 btnPtr->fsState = LOWORD(lParam);
5035 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5038 return TRUE;
5042 static LRESULT
5043 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5045 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5047 return TRUE;
5051 static inline LRESULT
5052 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5054 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5056 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5058 infoPtr->hwndToolTip = (HWND)wParam;
5059 return 0;
5063 static LRESULT
5064 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5066 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5067 BOOL bTemp;
5069 TRACE("%s hwnd=%p\n",
5070 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5072 bTemp = infoPtr->bUnicode;
5073 infoPtr->bUnicode = (BOOL)wParam;
5075 return bTemp;
5079 static LRESULT
5080 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5082 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5084 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5085 comctl32_color.clrBtnHighlight :
5086 infoPtr->clrBtnHighlight;
5087 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5088 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5089 return 1;
5093 static LRESULT
5094 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5096 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5098 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5099 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5100 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5102 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5103 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5104 InvalidateRect(hwnd, NULL, TRUE);
5105 return 0;
5109 static LRESULT
5110 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5112 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5113 INT iOldVersion = infoPtr->iVersion;
5115 infoPtr->iVersion = iVersion;
5117 if (infoPtr->iVersion >= 5)
5118 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5120 return iOldVersion;
5124 static LRESULT
5125 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5127 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5128 WORD iString = HIWORD(wParam);
5129 WORD buffersize = LOWORD(wParam);
5130 LPSTR str = (LPSTR)lParam;
5131 LRESULT ret = -1;
5133 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5135 if (iString < infoPtr->nNumStrings)
5137 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5139 TRACE("returning %s\n", debugstr_a(str));
5141 else
5142 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5144 return ret;
5148 static LRESULT
5149 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5151 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5152 WORD iString = HIWORD(wParam);
5153 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5154 LPWSTR str = (LPWSTR)lParam;
5155 LRESULT ret = -1;
5157 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5159 if (iString < infoPtr->nNumStrings)
5161 len = min(len, strlenW(infoPtr->strings[iString]));
5162 ret = (len+1)*sizeof(WCHAR);
5163 memcpy(str, infoPtr->strings[iString], ret);
5164 str[len] = '\0';
5166 TRACE("returning %s\n", debugstr_w(str));
5168 else
5169 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5171 return ret;
5174 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5175 * is the maximum size of the toolbar? */
5176 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5178 SIZE * pSize = (SIZE*)lParam;
5179 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5180 return 0;
5184 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5185 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5186 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5187 * sends). */
5188 static LRESULT
5189 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5191 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5192 INT nOldHotItem = infoPtr->nHotItem;
5194 TRACE("old item=%d, new item=%d, flags=%08x\n",
5195 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5197 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5198 wParam = -1;
5200 /* NOTE: an application can still remove the hot item even if anchor
5201 * highlighting is enabled */
5203 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5205 GetFocus();
5207 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5210 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5211 * which controls the amount of spacing between the image and the text
5212 * of buttons for TBSTYLE_LIST toolbars. */
5213 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5215 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5217 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5219 if (lParam != 0)
5220 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5222 infoPtr->iListGap = (INT)wParam;
5224 InvalidateRect(hwnd, NULL, TRUE);
5226 return 0;
5229 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5230 * of image lists associated with the various states. */
5231 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5233 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5235 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5237 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5240 static LRESULT
5241 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5243 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5244 LPSIZE lpsize = (LPSIZE)lParam;
5246 if (lpsize == NULL)
5247 return FALSE;
5250 * Testing shows the following:
5251 * wParam = 0 adjust cx value
5252 * = 1 set cy value to max size.
5253 * lParam pointer to SIZE structure
5256 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5257 wParam, lParam, lpsize->cx, lpsize->cy);
5259 switch(wParam) {
5260 case 0:
5261 if (lpsize->cx == -1) {
5262 /* **** this is wrong, native measures each button and sets it */
5263 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5265 else if(HIWORD(lpsize->cx)) {
5266 RECT rc;
5267 HWND hwndParent = GetParent(hwnd);
5269 GetWindowRect(hwnd, &rc);
5270 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5271 TRACE("mapped to (%d,%d)-(%d,%d)\n",
5272 rc.left, rc.top, rc.right, rc.bottom);
5273 lpsize->cx = max(rc.right-rc.left,
5274 infoPtr->rcBound.right - infoPtr->rcBound.left);
5276 else {
5277 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5279 break;
5280 case 1:
5281 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5282 break;
5283 default:
5284 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5285 wParam);
5286 return 0;
5288 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5289 lpsize->cx, lpsize->cy);
5290 return 1;
5293 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5295 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5297 InvalidateRect(hwnd, NULL, TRUE);
5298 return 1;
5302 static LRESULT
5303 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5305 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5306 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5307 LOGFONTW logFont;
5309 TRACE("hwnd = %p\n", hwnd);
5311 /* initialize info structure */
5312 infoPtr->nButtonWidth = 23;
5313 infoPtr->nButtonHeight = 22;
5314 infoPtr->nBitmapHeight = 16;
5315 infoPtr->nBitmapWidth = 16;
5317 infoPtr->nMaxTextRows = 1;
5318 infoPtr->cxMin = -1;
5319 infoPtr->cxMax = -1;
5320 infoPtr->nNumBitmaps = 0;
5321 infoPtr->nNumStrings = 0;
5323 infoPtr->bCaptured = FALSE;
5324 infoPtr->nButtonDown = -1;
5325 infoPtr->nButtonDrag = -1;
5326 infoPtr->nOldHit = -1;
5327 infoPtr->nHotItem = -1;
5328 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5329 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5330 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5331 infoPtr->bDragOutSent = FALSE;
5332 infoPtr->iVersion = 0;
5333 infoPtr->hwndSelf = hwnd;
5334 infoPtr->bDoRedraw = TRUE;
5335 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5336 infoPtr->clrBtnShadow = CLR_DEFAULT;
5337 infoPtr->szPadding.cx = DEFPAD_CX;
5338 infoPtr->szPadding.cy = DEFPAD_CY;
5339 infoPtr->iListGap = DEFLISTGAP;
5340 infoPtr->iTopMargin = default_top_margin(infoPtr);
5341 infoPtr->dwStyle = dwStyle;
5342 infoPtr->tbim.iButton = -1;
5343 GetClientRect(hwnd, &infoPtr->client_rect);
5344 infoPtr->bUnicode = infoPtr->hwndNotify &&
5345 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5346 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5348 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5349 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5351 OpenThemeData (hwnd, themeClass);
5353 TOOLBAR_CheckStyle (hwnd, dwStyle);
5355 return 0;
5359 static LRESULT
5360 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5362 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5364 /* delete tooltip control */
5365 if (infoPtr->hwndToolTip)
5366 DestroyWindow (infoPtr->hwndToolTip);
5368 /* delete temporary buffer for tooltip text */
5369 Free (infoPtr->pszTooltipText);
5370 Free (infoPtr->bitmaps); /* bitmaps list */
5372 /* delete button data */
5373 Free (infoPtr->buttons);
5375 /* delete strings */
5376 if (infoPtr->strings) {
5377 INT i;
5378 for (i = 0; i < infoPtr->nNumStrings; i++)
5379 if (infoPtr->strings[i])
5380 Free (infoPtr->strings[i]);
5382 Free (infoPtr->strings);
5385 /* destroy internal image list */
5386 if (infoPtr->himlInt)
5387 ImageList_Destroy (infoPtr->himlInt);
5389 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5390 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5391 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5393 /* delete default font */
5394 DeleteObject (infoPtr->hDefaultFont);
5396 CloseThemeData (GetWindowTheme (hwnd));
5398 /* free toolbar info data */
5399 Free (infoPtr);
5400 SetWindowLongPtrW (hwnd, 0, 0);
5402 return 0;
5406 static LRESULT
5407 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5409 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5410 NMTBCUSTOMDRAW tbcd;
5411 INT ret = FALSE;
5412 DWORD ntfret;
5413 HTHEME theme = GetWindowTheme (hwnd);
5414 DWORD dwEraseCustDraw = 0;
5416 /* the app has told us not to redraw the toolbar */
5417 if (!infoPtr->bDoRedraw)
5418 return FALSE;
5420 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5421 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5422 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5423 tbcd.nmcd.hdc = (HDC)wParam;
5424 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5425 dwEraseCustDraw = ntfret & 0xffff;
5427 /* FIXME: in general the return flags *can* be or'ed together */
5428 switch (dwEraseCustDraw)
5430 case CDRF_DODEFAULT:
5431 break;
5432 case CDRF_SKIPDEFAULT:
5433 return TRUE;
5434 default:
5435 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5436 hwnd, ntfret);
5440 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5441 * to my parent for processing.
5443 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5444 POINT pt, ptorig;
5445 HDC hdc = (HDC)wParam;
5446 HWND parent;
5448 pt.x = 0;
5449 pt.y = 0;
5450 parent = GetParent(hwnd);
5451 MapWindowPoints(hwnd, parent, &pt, 1);
5452 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5453 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5454 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5456 if (!ret)
5457 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5459 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5460 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5461 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5462 tbcd.nmcd.hdc = (HDC)wParam;
5463 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5464 dwEraseCustDraw = ntfret & 0xffff;
5465 switch (dwEraseCustDraw)
5467 case CDRF_DODEFAULT:
5468 break;
5469 case CDRF_SKIPDEFAULT:
5470 return TRUE;
5471 default:
5472 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5473 hwnd, ntfret);
5476 return ret;
5480 static LRESULT
5481 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5483 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5485 return (LRESULT)infoPtr->hFont;
5489 static void
5490 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5492 INT i;
5493 INT nNewHotItem = infoPtr->nHotItem;
5495 for (i = 0; i < infoPtr->nNumButtons; i++)
5497 /* did we wrap? */
5498 if ((nNewHotItem + iDirection < 0) ||
5499 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5501 NMTBWRAPHOTITEM nmtbwhi;
5502 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5503 nmtbwhi.iDirection = iDirection;
5504 nmtbwhi.dwReason = dwReason;
5506 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5507 return;
5510 nNewHotItem += iDirection;
5511 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5513 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5514 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5516 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5517 break;
5522 static LRESULT
5523 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5525 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5526 NMKEY nmkey;
5528 nmkey.nVKey = (UINT)wParam;
5529 nmkey.uFlags = HIWORD(lParam);
5531 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5532 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5534 switch ((UINT)wParam)
5536 case VK_LEFT:
5537 case VK_UP:
5538 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5539 break;
5540 case VK_RIGHT:
5541 case VK_DOWN:
5542 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5543 break;
5544 case VK_SPACE:
5545 case VK_RETURN:
5546 if ((infoPtr->nHotItem >= 0) &&
5547 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5549 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5550 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5551 (LPARAM)hwnd);
5553 break;
5556 return 0;
5560 static LRESULT
5561 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5563 POINT pt;
5564 INT nHit;
5566 pt.x = (short)LOWORD(lParam);
5567 pt.y = (short)HIWORD(lParam);
5568 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5570 if (nHit >= 0)
5571 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5572 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5573 TOOLBAR_Customize (hwnd);
5575 return 0;
5579 static LRESULT
5580 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5582 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5583 TBUTTON_INFO *btnPtr;
5584 POINT pt;
5585 INT nHit;
5586 NMTOOLBARA nmtb;
5587 NMMOUSE nmmouse;
5588 BOOL bDragKeyPressed;
5590 TRACE("\n");
5592 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5593 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5594 else
5595 bDragKeyPressed = (wParam & MK_SHIFT);
5597 if (infoPtr->hwndToolTip)
5598 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5599 WM_LBUTTONDOWN, wParam, lParam);
5601 pt.x = (short)LOWORD(lParam);
5602 pt.y = (short)HIWORD(lParam);
5603 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5605 btnPtr = &infoPtr->buttons[nHit];
5607 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5609 infoPtr->nButtonDrag = nHit;
5610 SetCapture (hwnd);
5612 /* If drag cursor has not been loaded, load it.
5613 * Note: it doesn't need to be freed */
5614 if (!hCursorDrag)
5615 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5616 SetCursor(hCursorDrag);
5618 else if (nHit >= 0)
5620 RECT arrowRect;
5621 infoPtr->nOldHit = nHit;
5623 CopyRect(&arrowRect, &btnPtr->rect);
5624 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5626 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5627 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5628 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5629 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5630 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5631 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5633 LRESULT res;
5635 /* draw in pressed state */
5636 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5637 btnPtr->fsState |= TBSTATE_PRESSED;
5638 else
5639 btnPtr->bDropDownPressed = TRUE;
5640 RedrawWindow(hwnd,&btnPtr->rect,0,
5641 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5643 memset(&nmtb, 0, sizeof(nmtb));
5644 nmtb.iItem = btnPtr->idCommand;
5645 nmtb.rcButton = btnPtr->rect;
5646 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5647 TBN_DROPDOWN);
5648 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5650 if (res != TBDDRET_TREATPRESSED)
5652 MSG msg;
5654 /* redraw button in unpressed state */
5655 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5656 btnPtr->fsState &= ~TBSTATE_PRESSED;
5657 else
5658 btnPtr->bDropDownPressed = FALSE;
5659 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5661 /* find and set hot item
5662 * NOTE: native doesn't do this, but that is a bug */
5663 GetCursorPos(&pt);
5664 ScreenToClient(hwnd, &pt);
5665 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5666 if (!infoPtr->bAnchor || (nHit >= 0))
5667 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5669 /* remove any left mouse button down or double-click messages
5670 * so that we can get a toggle effect on the button */
5671 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5672 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5675 return 0;
5677 /* otherwise drop through and process as pushed */
5679 infoPtr->bCaptured = TRUE;
5680 infoPtr->nButtonDown = nHit;
5681 infoPtr->bDragOutSent = FALSE;
5683 btnPtr->fsState |= TBSTATE_PRESSED;
5685 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5687 if (btnPtr->fsState & TBSTATE_ENABLED)
5688 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5689 UpdateWindow(hwnd);
5690 SetCapture (hwnd);
5693 if (nHit >=0)
5695 memset(&nmtb, 0, sizeof(nmtb));
5696 nmtb.iItem = btnPtr->idCommand;
5697 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5700 nmmouse.dwHitInfo = nHit;
5702 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5703 if (nHit < 0)
5704 nmmouse.dwItemSpec = -1;
5705 else
5707 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5708 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5711 ClientToScreen(hwnd, &pt);
5712 nmmouse.pt = pt;
5714 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5715 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5717 return 0;
5720 static LRESULT
5721 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5723 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5724 TBUTTON_INFO *btnPtr;
5725 POINT pt;
5726 INT nHit;
5727 INT nOldIndex = -1;
5728 BOOL bSendMessage = TRUE;
5729 NMHDR hdr;
5730 NMMOUSE nmmouse;
5731 NMTOOLBARA nmtb;
5733 if (infoPtr->hwndToolTip)
5734 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5735 WM_LBUTTONUP, wParam, lParam);
5737 pt.x = (short)LOWORD(lParam);
5738 pt.y = (short)HIWORD(lParam);
5739 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5741 if (!infoPtr->bAnchor || (nHit >= 0))
5742 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5744 if (infoPtr->nButtonDrag >= 0) {
5745 RECT rcClient;
5746 NMHDR hdr;
5748 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5749 ReleaseCapture();
5750 /* reset cursor */
5751 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5753 GetClientRect(hwnd, &rcClient);
5754 if (PtInRect(&rcClient, pt))
5756 INT nButton = -1;
5757 if (nHit >= 0)
5758 nButton = nHit;
5759 else if (nHit < -1)
5760 nButton = -nHit;
5761 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5762 nButton = -nHit;
5764 if (nButton == infoPtr->nButtonDrag)
5766 /* if the button is moved sightly left and we have a
5767 * separator there then remove it */
5768 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5770 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5771 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5773 else /* else insert a separator before the dragged button */
5775 TBBUTTON tbb;
5776 memset(&tbb, 0, sizeof(tbb));
5777 tbb.fsStyle = BTNS_SEP;
5778 tbb.iString = -1;
5779 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5782 else
5784 if (nButton == -1)
5786 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5787 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5788 else
5789 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5791 else
5792 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5795 else
5797 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5798 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5801 /* button under cursor changed so need to re-set hot item */
5802 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5803 infoPtr->nButtonDrag = -1;
5805 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5807 else if (infoPtr->nButtonDown >= 0) {
5808 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5809 btnPtr->fsState &= ~TBSTATE_PRESSED;
5811 if (btnPtr->fsStyle & BTNS_CHECK) {
5812 if (btnPtr->fsStyle & BTNS_GROUP) {
5813 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5814 nHit);
5815 if (nOldIndex == nHit)
5816 bSendMessage = FALSE;
5817 if ((nOldIndex != nHit) &&
5818 (nOldIndex != -1))
5819 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5820 btnPtr->fsState |= TBSTATE_CHECKED;
5822 else {
5823 if (btnPtr->fsState & TBSTATE_CHECKED)
5824 btnPtr->fsState &= ~TBSTATE_CHECKED;
5825 else
5826 btnPtr->fsState |= TBSTATE_CHECKED;
5830 if (nOldIndex != -1)
5831 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5834 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5835 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5836 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5838 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5839 ReleaseCapture ();
5840 infoPtr->nButtonDown = -1;
5842 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5843 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5844 NM_RELEASEDCAPTURE);
5846 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5847 * TBN_BEGINDRAG
5849 memset(&nmtb, 0, sizeof(nmtb));
5850 nmtb.iItem = btnPtr->idCommand;
5851 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5852 TBN_ENDDRAG);
5854 if (btnPtr->fsState & TBSTATE_ENABLED)
5856 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5857 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5861 /* !!! Undocumented - toolbar at 4.71 level and above sends
5862 * NM_CLICK with the NMMOUSE structure. */
5863 nmmouse.dwHitInfo = nHit;
5865 if (nHit < 0)
5866 nmmouse.dwItemSpec = -1;
5867 else
5869 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5870 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5873 ClientToScreen(hwnd, &pt);
5874 nmmouse.pt = pt;
5876 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5877 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5879 return 0;
5882 static LRESULT
5883 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5885 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5886 INT nHit;
5887 NMMOUSE nmmouse;
5888 POINT pt;
5890 pt.x = (short)LOWORD(lParam);
5891 pt.y = (short)HIWORD(lParam);
5893 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5894 nmmouse.dwHitInfo = nHit;
5896 if (nHit < 0) {
5897 nmmouse.dwItemSpec = -1;
5898 } else {
5899 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5900 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5903 ClientToScreen(hwnd, &pt);
5904 nmmouse.pt = pt;
5906 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5907 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5909 return 0;
5912 static LRESULT
5913 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5915 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5916 NMHDR nmhdr;
5918 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5919 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5921 return 0;
5924 static LRESULT
5925 TOOLBAR_CaptureChanged(HWND hwnd)
5927 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5928 TBUTTON_INFO *btnPtr;
5930 infoPtr->bCaptured = FALSE;
5932 if (infoPtr->nButtonDown >= 0)
5934 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5935 btnPtr->fsState &= ~TBSTATE_PRESSED;
5937 infoPtr->nOldHit = -1;
5939 if (btnPtr->fsState & TBSTATE_ENABLED)
5940 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5942 return 0;
5945 static LRESULT
5946 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5948 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5950 /* don't remove hot effects when in anchor highlighting mode or when a
5951 * drop-down button is pressed */
5952 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
5954 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5955 if (!hotBtnPtr->bDropDownPressed)
5956 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
5959 if (infoPtr->nOldHit < 0)
5960 return TRUE;
5962 /* If the last button we were over is depressed then make it not */
5963 /* depressed and redraw it */
5964 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5966 TBUTTON_INFO *btnPtr;
5967 RECT rc1;
5969 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5971 btnPtr->fsState &= ~TBSTATE_PRESSED;
5973 rc1 = btnPtr->rect;
5974 InflateRect (&rc1, 1, 1);
5975 InvalidateRect (hwnd, &rc1, TRUE);
5978 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
5980 NMTOOLBARW nmt;
5981 ZeroMemory(&nmt, sizeof(nmt));
5982 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5983 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5984 infoPtr->bDragOutSent = TRUE;
5987 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5989 return TRUE;
5992 static LRESULT
5993 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5995 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5996 POINT pt;
5997 TRACKMOUSEEVENT trackinfo;
5998 INT nHit;
5999 TBUTTON_INFO *btnPtr;
6001 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6002 TOOLBAR_TooltipCreateControl(infoPtr);
6004 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6005 /* fill in the TRACKMOUSEEVENT struct */
6006 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6007 trackinfo.dwFlags = TME_QUERY;
6009 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6010 _TrackMouseEvent(&trackinfo);
6012 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6013 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6014 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6015 trackinfo.hwndTrack = hwnd;
6017 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6018 /* and can properly deactivate the hot toolbar button */
6019 _TrackMouseEvent(&trackinfo);
6023 if (infoPtr->hwndToolTip)
6024 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6025 WM_MOUSEMOVE, wParam, lParam);
6027 pt.x = (short)LOWORD(lParam);
6028 pt.y = (short)HIWORD(lParam);
6030 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6032 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6033 && (!infoPtr->bAnchor || (nHit >= 0)))
6034 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6036 if (infoPtr->nOldHit != nHit)
6038 if (infoPtr->bCaptured)
6040 if (!infoPtr->bDragOutSent)
6042 NMTOOLBARW nmt;
6043 ZeroMemory(&nmt, sizeof(nmt));
6044 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6045 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6046 infoPtr->bDragOutSent = TRUE;
6049 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6050 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6051 btnPtr->fsState &= ~TBSTATE_PRESSED;
6052 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6054 else if (nHit == infoPtr->nButtonDown) {
6055 btnPtr->fsState |= TBSTATE_PRESSED;
6056 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6058 infoPtr->nOldHit = nHit;
6062 return 0;
6066 static inline LRESULT
6067 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6069 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6070 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6071 /* else */
6072 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6076 static inline LRESULT
6077 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6079 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6080 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6082 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6086 static LRESULT
6087 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6089 TOOLBAR_INFO *infoPtr;
6090 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6091 DWORD styleadd = 0;
6093 /* allocate memory for info structure */
6094 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6095 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6097 /* paranoid!! */
6098 infoPtr->dwStructSize = sizeof(TBBUTTON);
6099 infoPtr->nRows = 1;
6100 infoPtr->nWidth = 0;
6102 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6103 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6104 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6105 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6108 /* native control does:
6109 * Get a lot of colors and brushes
6110 * WM_NOTIFYFORMAT
6111 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6112 * CreateFontIndirectW(adr1)
6113 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6114 * hdc = GetDC(toolbar)
6115 * GetSystemMetrics(0x48)
6116 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6117 * 0, 0, 0, 0, "MARLETT")
6118 * oldfnt = SelectObject(hdc, fnt2)
6119 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6120 * GetTextMetricsW(hdc, adr3)
6121 * SelectObject(hdc, oldfnt)
6122 * DeleteObject(fnt2)
6123 * ReleaseDC(hdc)
6124 * InvalidateRect(toolbar, 0, 1)
6125 * SetWindowLongW(toolbar, 0, addr)
6126 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6127 * WM_STYLECHANGING
6128 * CallWinEx old new
6129 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6130 * ie 2 0x4600094c 0x4600094c 0x4600894d
6131 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6132 * rebar 0x50008844 0x40008844 0x50008845
6133 * pager 0x50000844 0x40000844 0x50008845
6134 * IC35mgr 0x5400084e **nochange**
6135 * on entry to _NCCREATE 0x5400084e
6136 * rowlist 0x5400004e **nochange**
6137 * on entry to _NCCREATE 0x5400004e
6141 /* I think the code below is a bug, but it is the way that the native
6142 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6143 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6144 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6145 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6146 * Somehow, the only cases of this seem to be MFC programs.
6148 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6149 * does not occur in the WM_STYLECHANGING routine.
6150 * (Guy Albertelli 9/2001)
6153 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6154 && !(cs->style & TBSTYLE_TRANSPARENT))
6155 styleadd |= TBSTYLE_TRANSPARENT;
6156 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6157 styleadd |= CCS_TOP; /* default to top */
6158 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6161 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6165 static LRESULT
6166 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6168 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6169 RECT rcWindow;
6170 HDC hdc;
6172 if (dwStyle & WS_MINIMIZE)
6173 return 0; /* Nothing to do */
6175 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6177 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6178 return 0;
6180 if (!(dwStyle & CCS_NODIVIDER))
6182 GetWindowRect (hwnd, &rcWindow);
6183 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6184 if( dwStyle & WS_BORDER )
6185 OffsetRect (&rcWindow, 1, 1);
6186 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6189 ReleaseDC( hwnd, hdc );
6191 return 0;
6195 /* handles requests from the tooltip control on what text to display */
6196 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6198 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6200 TRACE("button index = %d\n", index);
6202 Free (infoPtr->pszTooltipText);
6203 infoPtr->pszTooltipText = NULL;
6205 if (index < 0)
6206 return 0;
6208 if (infoPtr->bUnicode)
6210 WCHAR wszBuffer[INFOTIPSIZE+1];
6211 NMTBGETINFOTIPW tbgit;
6212 unsigned int len; /* in chars */
6214 wszBuffer[0] = '\0';
6215 wszBuffer[INFOTIPSIZE] = '\0';
6217 tbgit.pszText = wszBuffer;
6218 tbgit.cchTextMax = INFOTIPSIZE;
6219 tbgit.iItem = lpnmtdi->hdr.idFrom;
6220 tbgit.lParam = infoPtr->buttons[index].dwData;
6222 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6224 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6226 len = strlenW(tbgit.pszText);
6227 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6229 /* need to allocate temporary buffer in infoPtr as there
6230 * isn't enough space in buffer passed to us by the
6231 * tooltip control */
6232 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6233 if (infoPtr->pszTooltipText)
6235 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6236 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6237 return 0;
6240 else if (len > 0)
6242 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6243 return 0;
6246 else
6248 CHAR szBuffer[INFOTIPSIZE+1];
6249 NMTBGETINFOTIPA tbgit;
6250 unsigned int len; /* in chars */
6252 szBuffer[0] = '\0';
6253 szBuffer[INFOTIPSIZE] = '\0';
6255 tbgit.pszText = szBuffer;
6256 tbgit.cchTextMax = INFOTIPSIZE;
6257 tbgit.iItem = lpnmtdi->hdr.idFrom;
6258 tbgit.lParam = infoPtr->buttons[index].dwData;
6260 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6262 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6264 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6265 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6267 /* need to allocate temporary buffer in infoPtr as there
6268 * isn't enough space in buffer passed to us by the
6269 * tooltip control */
6270 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6271 if (infoPtr->pszTooltipText)
6273 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6274 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6275 return 0;
6278 else if (len > 0)
6280 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6281 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6282 return 0;
6286 /* if button has text, but it is not shown then automatically
6287 * use that text as tooltip */
6288 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6289 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6291 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6292 unsigned int len = pszText ? strlenW(pszText) : 0;
6294 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6296 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6298 /* need to allocate temporary buffer in infoPtr as there
6299 * isn't enough space in buffer passed to us by the
6300 * tooltip control */
6301 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6302 if (infoPtr->pszTooltipText)
6304 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6305 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6306 return 0;
6309 else if (len > 0)
6311 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6312 return 0;
6316 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6318 /* last resort: send notification on to app */
6319 /* FIXME: find out what is really used here */
6320 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6324 static inline LRESULT
6325 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6327 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6328 LPNMHDR lpnmh = (LPNMHDR)lParam;
6330 switch (lpnmh->code)
6332 case PGN_CALCSIZE:
6334 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6336 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6337 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6338 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6339 lppgc->iWidth);
6341 else {
6342 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6343 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6344 lppgc->iHeight);
6346 return 0;
6349 case PGN_SCROLL:
6351 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6353 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6354 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6355 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6356 lppgs->iScroll, lppgs->iDir);
6357 return 0;
6360 case TTN_GETDISPINFOW:
6361 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6363 case TTN_GETDISPINFOA:
6364 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6365 return 0;
6367 default:
6368 return 0;
6373 static LRESULT
6374 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6376 LRESULT format;
6378 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6380 if (lParam == NF_QUERY)
6381 return NFR_UNICODE;
6383 if (lParam == NF_REQUERY) {
6384 format = SendMessageW(infoPtr->hwndNotify,
6385 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6386 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6387 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6388 format);
6389 format = NFR_ANSI;
6391 return format;
6393 return 0;
6397 static LRESULT
6398 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6400 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6401 HDC hdc;
6402 PAINTSTRUCT ps;
6404 /* fill ps.rcPaint with a default rect */
6405 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6407 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6409 TRACE("psrect=(%d,%d)-(%d,%d)\n",
6410 ps.rcPaint.left, ps.rcPaint.top,
6411 ps.rcPaint.right, ps.rcPaint.bottom);
6413 TOOLBAR_Refresh (hwnd, hdc, &ps);
6414 if (!wParam) EndPaint (hwnd, &ps);
6416 return 0;
6420 static LRESULT
6421 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6423 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6425 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6427 /* make first item hot */
6428 if (infoPtr->nNumButtons > 0)
6429 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6431 return 0;
6434 static LRESULT
6435 TOOLBAR_SetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
6437 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6439 TRACE("font=%p redraw=%ld\n", (HFONT)wParam, lParam);
6441 if (wParam == 0)
6442 infoPtr->hFont = infoPtr->hDefaultFont;
6443 else
6444 infoPtr->hFont = (HFONT)wParam;
6446 TOOLBAR_CalcToolbar(hwnd);
6448 if (lParam)
6449 InvalidateRect(hwnd, NULL, TRUE);
6450 return 1;
6453 static LRESULT
6454 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6455 /*****************************************************
6457 * Function;
6458 * Handles the WM_SETREDRAW message.
6460 * Documentation:
6461 * According to testing V4.71 of COMCTL32 returns the
6462 * *previous* status of the redraw flag (either 0 or 1)
6463 * instead of the MSDN documented value of 0 if handled.
6464 * (For laughs see the "consistency" with same function
6465 * in rebar.)
6467 *****************************************************/
6469 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6470 BOOL oldredraw = infoPtr->bDoRedraw;
6472 TRACE("set to %s\n",
6473 (wParam) ? "TRUE" : "FALSE");
6474 infoPtr->bDoRedraw = (BOOL) wParam;
6475 if (wParam) {
6476 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6478 return (oldredraw) ? 1 : 0;
6482 static LRESULT
6483 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6485 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6487 TRACE("sizing toolbar!\n");
6489 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6491 RECT delta_width, delta_height, client, dummy;
6492 DWORD min_x, max_x, min_y, max_y;
6493 TBUTTON_INFO *btnPtr;
6494 INT i;
6496 GetClientRect(hwnd, &client);
6497 if(client.right > infoPtr->client_rect.right)
6499 min_x = infoPtr->client_rect.right;
6500 max_x = client.right;
6502 else
6504 max_x = infoPtr->client_rect.right;
6505 min_x = client.right;
6507 if(client.bottom > infoPtr->client_rect.bottom)
6509 min_y = infoPtr->client_rect.bottom;
6510 max_y = client.bottom;
6512 else
6514 max_y = infoPtr->client_rect.bottom;
6515 min_y = client.bottom;
6518 SetRect(&delta_width, min_x, 0, max_x, min_y);
6519 SetRect(&delta_height, 0, min_y, max_x, max_y);
6521 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6522 btnPtr = infoPtr->buttons;
6523 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6524 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6525 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6526 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6528 GetClientRect(hwnd, &infoPtr->client_rect);
6529 TOOLBAR_AutoSize(hwnd);
6530 return 0;
6534 static LRESULT
6535 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6537 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6539 if (nType == GWL_STYLE)
6541 DWORD dwOldStyle = infoPtr->dwStyle;
6543 if (lpStyle->styleNew & TBSTYLE_LIST)
6544 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6545 else
6546 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6548 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6550 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6552 infoPtr->dwStyle = lpStyle->styleNew;
6554 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6555 TOOLBAR_LayoutToolbar(hwnd);
6557 /* only resize if one of the CCS_* styles was changed */
6558 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6560 TOOLBAR_AutoSize (hwnd);
6562 InvalidateRect(hwnd, NULL, TRUE);
6566 return 0;
6570 static LRESULT
6571 TOOLBAR_SysColorChange (HWND hwnd)
6573 COMCTL32_RefreshSysColors();
6575 return 0;
6579 /* update theme after a WM_THEMECHANGED message */
6580 static LRESULT theme_changed (HWND hwnd)
6582 HTHEME theme = GetWindowTheme (hwnd);
6583 CloseThemeData (theme);
6584 OpenThemeData (hwnd, themeClass);
6585 return 0;
6589 static LRESULT WINAPI
6590 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6592 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6594 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6595 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6597 if (!infoPtr && (uMsg != WM_NCCREATE))
6598 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6600 switch (uMsg)
6602 case TB_ADDBITMAP:
6603 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6605 case TB_ADDBUTTONSA:
6606 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6608 case TB_ADDBUTTONSW:
6609 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6611 case TB_ADDSTRINGA:
6612 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6614 case TB_ADDSTRINGW:
6615 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6617 case TB_AUTOSIZE:
6618 return TOOLBAR_AutoSize (hwnd);
6620 case TB_BUTTONCOUNT:
6621 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6623 case TB_BUTTONSTRUCTSIZE:
6624 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6626 case TB_CHANGEBITMAP:
6627 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6629 case TB_CHECKBUTTON:
6630 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6632 case TB_COMMANDTOINDEX:
6633 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6635 case TB_CUSTOMIZE:
6636 return TOOLBAR_Customize (hwnd);
6638 case TB_DELETEBUTTON:
6639 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6641 case TB_ENABLEBUTTON:
6642 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6644 case TB_GETANCHORHIGHLIGHT:
6645 return TOOLBAR_GetAnchorHighlight (hwnd);
6647 case TB_GETBITMAP:
6648 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6650 case TB_GETBITMAPFLAGS:
6651 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6653 case TB_GETBUTTON:
6654 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6656 case TB_GETBUTTONINFOA:
6657 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6659 case TB_GETBUTTONINFOW:
6660 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6662 case TB_GETBUTTONSIZE:
6663 return TOOLBAR_GetButtonSize (hwnd);
6665 case TB_GETBUTTONTEXTA:
6666 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6668 case TB_GETBUTTONTEXTW:
6669 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6671 case TB_GETDISABLEDIMAGELIST:
6672 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6674 case TB_GETEXTENDEDSTYLE:
6675 return TOOLBAR_GetExtendedStyle (hwnd);
6677 case TB_GETHOTIMAGELIST:
6678 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6680 case TB_GETHOTITEM:
6681 return TOOLBAR_GetHotItem (hwnd);
6683 case TB_GETIMAGELIST:
6684 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6686 case TB_GETINSERTMARK:
6687 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6689 case TB_GETINSERTMARKCOLOR:
6690 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6692 case TB_GETITEMRECT:
6693 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6695 case TB_GETMAXSIZE:
6696 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6698 /* case TB_GETOBJECT: */ /* 4.71 */
6700 case TB_GETPADDING:
6701 return TOOLBAR_GetPadding (hwnd);
6703 case TB_GETRECT:
6704 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6706 case TB_GETROWS:
6707 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6709 case TB_GETSTATE:
6710 return TOOLBAR_GetState (hwnd, wParam, lParam);
6712 case TB_GETSTRINGA:
6713 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6715 case TB_GETSTRINGW:
6716 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6718 case TB_GETSTYLE:
6719 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6721 case TB_GETTEXTROWS:
6722 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6724 case TB_GETTOOLTIPS:
6725 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6727 case TB_GETUNICODEFORMAT:
6728 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6730 case TB_HIDEBUTTON:
6731 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6733 case TB_HITTEST:
6734 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6736 case TB_INDETERMINATE:
6737 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6739 case TB_INSERTBUTTONA:
6740 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6742 case TB_INSERTBUTTONW:
6743 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6745 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6747 case TB_ISBUTTONCHECKED:
6748 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6750 case TB_ISBUTTONENABLED:
6751 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6753 case TB_ISBUTTONHIDDEN:
6754 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6756 case TB_ISBUTTONHIGHLIGHTED:
6757 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6759 case TB_ISBUTTONINDETERMINATE:
6760 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6762 case TB_ISBUTTONPRESSED:
6763 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6765 case TB_LOADIMAGES:
6766 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6768 case TB_MAPACCELERATORA:
6769 case TB_MAPACCELERATORW:
6770 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6772 case TB_MARKBUTTON:
6773 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6775 case TB_MOVEBUTTON:
6776 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6778 case TB_PRESSBUTTON:
6779 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6781 case TB_REPLACEBITMAP:
6782 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6784 case TB_SAVERESTOREA:
6785 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6787 case TB_SAVERESTOREW:
6788 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6790 case TB_SETANCHORHIGHLIGHT:
6791 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6793 case TB_SETBITMAPSIZE:
6794 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6796 case TB_SETBUTTONINFOA:
6797 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6799 case TB_SETBUTTONINFOW:
6800 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6802 case TB_SETBUTTONSIZE:
6803 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6805 case TB_SETBUTTONWIDTH:
6806 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6808 case TB_SETCMDID:
6809 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6811 case TB_SETDISABLEDIMAGELIST:
6812 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6814 case TB_SETDRAWTEXTFLAGS:
6815 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6817 case TB_SETEXTENDEDSTYLE:
6818 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6820 case TB_SETHOTIMAGELIST:
6821 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6823 case TB_SETHOTITEM:
6824 return TOOLBAR_SetHotItem (hwnd, wParam);
6826 case TB_SETIMAGELIST:
6827 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6829 case TB_SETINDENT:
6830 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6832 case TB_SETINSERTMARK:
6833 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6835 case TB_SETINSERTMARKCOLOR:
6836 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6838 case TB_SETMAXTEXTROWS:
6839 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6841 case TB_SETPADDING:
6842 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6844 case TB_SETPARENT:
6845 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6847 case TB_SETROWS:
6848 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6850 case TB_SETSTATE:
6851 return TOOLBAR_SetState (hwnd, wParam, lParam);
6853 case TB_SETSTYLE:
6854 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6856 case TB_SETTOOLTIPS:
6857 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6859 case TB_SETUNICODEFORMAT:
6860 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6862 case TB_UNKWN45D:
6863 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6865 case TB_UNKWN45E:
6866 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6868 case TB_UNKWN460:
6869 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6871 case TB_UNKWN462:
6872 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6874 case TB_UNKWN463:
6875 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6877 case TB_UNKWN464:
6878 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6880 /* Common Control Messages */
6882 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6883 case CCM_GETCOLORSCHEME:
6884 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6886 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6887 case CCM_SETCOLORSCHEME:
6888 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6890 case CCM_GETVERSION:
6891 return TOOLBAR_GetVersion (hwnd);
6893 case CCM_SETVERSION:
6894 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6897 /* case WM_CHAR: */
6899 case WM_CREATE:
6900 return TOOLBAR_Create (hwnd, wParam, lParam);
6902 case WM_DESTROY:
6903 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6905 case WM_ERASEBKGND:
6906 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6908 case WM_GETFONT:
6909 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6911 case WM_KEYDOWN:
6912 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6914 /* case WM_KILLFOCUS: */
6916 case WM_LBUTTONDBLCLK:
6917 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6919 case WM_LBUTTONDOWN:
6920 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6922 case WM_LBUTTONUP:
6923 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6925 case WM_RBUTTONUP:
6926 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6928 case WM_RBUTTONDBLCLK:
6929 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6931 case WM_MOUSEMOVE:
6932 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6934 case WM_MOUSELEAVE:
6935 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6937 case WM_CAPTURECHANGED:
6938 return TOOLBAR_CaptureChanged(hwnd);
6940 case WM_NCACTIVATE:
6941 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6943 case WM_NCCALCSIZE:
6944 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6946 case WM_NCCREATE:
6947 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6949 case WM_NCPAINT:
6950 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6952 case WM_NOTIFY:
6953 return TOOLBAR_Notify (hwnd, wParam, lParam);
6955 case WM_NOTIFYFORMAT:
6956 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
6958 case WM_PRINTCLIENT:
6959 case WM_PAINT:
6960 return TOOLBAR_Paint (hwnd, wParam);
6962 case WM_SETFOCUS:
6963 return TOOLBAR_SetFocus (hwnd, wParam);
6965 case WM_SETFONT:
6966 return TOOLBAR_SetFont(hwnd, wParam, lParam);
6968 case WM_SETREDRAW:
6969 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6971 case WM_SIZE:
6972 return TOOLBAR_Size (hwnd, wParam, lParam);
6974 case WM_STYLECHANGED:
6975 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6977 case WM_SYSCOLORCHANGE:
6978 return TOOLBAR_SysColorChange (hwnd);
6980 case WM_THEMECHANGED:
6981 return theme_changed (hwnd);
6983 /* case WM_WININICHANGE: */
6985 case WM_CHARTOITEM:
6986 case WM_COMMAND:
6987 case WM_DRAWITEM:
6988 case WM_MEASUREITEM:
6989 case WM_VKEYTOITEM:
6990 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
6992 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6993 case PGM_FORWARDMOUSE:
6994 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
6996 default:
6997 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6998 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6999 uMsg, wParam, lParam);
7000 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7005 VOID
7006 TOOLBAR_Register (void)
7008 WNDCLASSW wndClass;
7010 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7011 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7012 wndClass.lpfnWndProc = ToolbarWindowProc;
7013 wndClass.cbClsExtra = 0;
7014 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7015 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7016 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7017 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7019 RegisterClassW (&wndClass);
7023 VOID
7024 TOOLBAR_Unregister (void)
7026 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7029 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7031 HIMAGELIST himlold;
7032 PIMLENTRY c = NULL;
7034 /* Check if the entry already exists */
7035 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7037 /* If this is a new entry we must create it and insert into the array */
7038 if (!c)
7040 PIMLENTRY *pnies;
7042 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7043 c->id = id;
7045 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7046 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7047 pnies[*cies] = c;
7048 (*cies)++;
7050 Free(*pies);
7051 *pies = pnies;
7054 himlold = c->himl;
7055 c->himl = himl;
7057 return himlold;
7061 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7063 int i;
7065 for (i = 0; i < *cies; i++)
7066 Free((*pies)[i]);
7068 Free(*pies);
7070 *cies = 0;
7071 *pies = NULL;
7075 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7077 PIMLENTRY c = NULL;
7079 if (pies != NULL)
7081 int i;
7083 for (i = 0; i < cies; i++)
7085 if (pies[i]->id == id)
7087 c = pies[i];
7088 break;
7093 return c;
7097 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7099 HIMAGELIST himlDef = 0;
7100 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7102 if (pie)
7103 himlDef = pie->himl;
7105 return himlDef;
7109 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7111 if (infoPtr->bUnicode)
7112 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7113 else
7115 CHAR Buffer[256];
7116 NMTOOLBARA nmtba;
7117 BOOL bRet = FALSE;
7119 nmtba.iItem = nmtb->iItem;
7120 nmtba.pszText = Buffer;
7121 nmtba.cchText = 256;
7122 ZeroMemory(nmtba.pszText, nmtba.cchText);
7124 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7126 int ccht = strlen(nmtba.pszText);
7127 if (ccht)
7128 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7129 nmtb->pszText, nmtb->cchText);
7131 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7132 bRet = TRUE;
7135 return bRet;
7140 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7141 int iItem, PCUSTOMBUTTON btnInfo)
7143 NMTOOLBARW nmtb;
7145 /* MSDN states that iItem is the index of the button, rather than the
7146 * command ID as used by every other NMTOOLBAR notification */
7147 nmtb.iItem = iItem;
7148 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7150 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);