comctl32: toolbar: Test and improve TB_SETHOTITEM.
[wine/wine64.git] / dlls / comctl32 / toolbar.c
blob92ded23707733bc4e5f920fdcd5e99ab8d2a460e
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 iListGap; /* default gap between text and image for toolbar with list style */
144 HFONT hDefaultFont;
145 HFONT hFont; /* text font */
146 HIMAGELIST himlInt; /* image list created internally */
147 PIMLENTRY *himlDef; /* default image list array */
148 INT cimlDef; /* default image list array count */
149 PIMLENTRY *himlHot; /* hot image list array */
150 INT cimlHot; /* hot image list array count */
151 PIMLENTRY *himlDis; /* disabled image list array */
152 INT cimlDis; /* disabled image list array count */
153 HWND hwndToolTip; /* handle to tool tip control */
154 HWND hwndNotify; /* handle to the window that gets notifications */
155 HWND hwndSelf; /* my own handle */
156 BOOL bAnchor; /* anchor highlight enabled */
157 BOOL bDoRedraw; /* Redraw status */
158 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
159 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
160 BOOL bCaptured; /* mouse captured? */
161 DWORD dwStyle; /* regular toolbar style */
162 DWORD dwExStyle; /* extended toolbar style */
163 DWORD dwDTFlags; /* DrawText flags */
165 COLORREF clrInsertMark; /* insert mark color */
166 COLORREF clrBtnHighlight; /* color for Flat Separator */
167 COLORREF clrBtnShadow; /* color for Flag Separator */
168 INT iVersion;
169 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
170 * for TTN_GETDISPINFOW notification */
171 TBINSERTMARK tbim; /* info on insertion mark */
172 TBUTTON_INFO *buttons; /* pointer to button array */
173 LPWSTR *strings; /* pointer to string array */
174 TBITMAP_INFO *bitmaps;
175 } TOOLBAR_INFO, *PTOOLBAR_INFO;
178 /* used by customization dialog */
179 typedef struct
181 PTOOLBAR_INFO tbInfo;
182 HWND tbHwnd;
183 } CUSTDLG_INFO, *PCUSTDLG_INFO;
185 typedef struct
187 TBBUTTON btn;
188 BOOL bVirtual;
189 BOOL bRemovable;
190 WCHAR text[64];
191 } CUSTOMBUTTON, *PCUSTOMBUTTON;
193 typedef enum
195 IMAGE_LIST_DEFAULT,
196 IMAGE_LIST_HOT,
197 IMAGE_LIST_DISABLED
198 } IMAGE_LIST_TYPE;
200 #define SEPARATOR_WIDTH 8
201 #define TOP_BORDER 2
202 #define BOTTOM_BORDER 2
203 #define DDARROW_WIDTH 11
204 #define ARROW_HEIGHT 3
205 #define INSERTMARK_WIDTH 2
207 #define DEFPAD_CX 7
208 #define DEFPAD_CY 6
209 #define DEFLISTGAP 4
211 /* vertical padding used in list mode when image is present */
212 #define LISTPAD_CY 9
214 /* how wide to treat the bitmap if it isn't present */
215 #define NONLIST_NOTEXT_OFFSET 2
217 #define TOOLBAR_NOWHERE (-1)
219 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
220 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
221 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
223 /* Used to find undocumented extended styles */
224 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
225 TBSTYLE_EX_UNDOC1 | \
226 TBSTYLE_EX_MIXEDBUTTONS | \
227 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
229 /* all of the CCS_ styles */
230 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
231 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
233 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
234 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
235 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
236 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
237 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
239 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
241 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
242 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
243 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
244 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
245 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
246 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
247 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
248 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
249 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
250 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
251 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button);
253 static LRESULT
254 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
257 static LPWSTR
258 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
260 LPWSTR lpText = NULL;
262 /* NOTE: iString == -1 is undocumented */
263 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
264 lpText = (LPWSTR)btnPtr->iString;
265 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
266 lpText = infoPtr->strings[btnPtr->iString];
268 return lpText;
271 static void
272 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
274 if (TRACE_ON(toolbar)){
275 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
276 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
277 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
278 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
279 if (internal)
280 TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n",
281 btn_num, bP->idCommand,
282 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
283 bP->rect.left, bP->rect.top,
284 bP->rect.right, bP->rect.bottom);
289 static void
290 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
292 if (TRACE_ON(toolbar)) {
293 INT i;
295 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
296 iP->hwndSelf, line,
297 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
298 iP->nNumStrings, iP->dwStyle);
299 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
300 iP->hwndSelf, line,
301 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
302 (iP->bDoRedraw) ? "TRUE" : "FALSE");
303 for(i=0; i<iP->nNumButtons; i++) {
304 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
310 /***********************************************************************
311 * TOOLBAR_CheckStyle
313 * This function validates that the styles set are implemented and
314 * issues FIXME's warning of possible problems. In a perfect world this
315 * function should be null.
317 static void
318 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
320 if (dwStyle & TBSTYLE_REGISTERDROP)
321 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
325 static INT
326 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
328 if(!IsWindow(infoPtr->hwndSelf))
329 return 0; /* we have just been destroyed */
331 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
332 nmhdr->hwndFrom = infoPtr->hwndSelf;
333 nmhdr->code = code;
335 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
336 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
338 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
339 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
342 /***********************************************************************
343 * TOOLBAR_GetBitmapIndex
345 * This function returns the bitmap index associated with a button.
346 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
347 * is issued to retrieve the index.
349 static INT
350 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
352 INT ret = btnPtr->iBitmap;
354 if (ret == I_IMAGECALLBACK)
356 /* issue TBN_GETDISPINFO */
357 NMTBDISPINFOA nmgd;
359 memset(&nmgd, 0, sizeof(nmgd));
360 nmgd.idCommand = btnPtr->idCommand;
361 nmgd.lParam = btnPtr->dwData;
362 nmgd.dwMask = TBNF_IMAGE;
363 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
364 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
365 if (nmgd.dwMask & TBNF_DI_SETITEM)
366 btnPtr->iBitmap = nmgd.iImage;
367 ret = nmgd.iImage;
368 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
369 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
372 if (ret != I_IMAGENONE)
373 ret = GETIBITMAP(infoPtr, ret);
375 return ret;
379 static BOOL
380 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
382 HIMAGELIST himl;
383 INT id = GETHIMLID(infoPtr, index);
384 INT iBitmap = GETIBITMAP(infoPtr, index);
386 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
387 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
388 (index == I_IMAGECALLBACK))
389 return TRUE;
390 else
391 return FALSE;
395 static inline BOOL
396 TOOLBAR_IsValidImageList(TOOLBAR_INFO *infoPtr, INT index)
398 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
399 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
403 /***********************************************************************
404 * TOOLBAR_GetImageListForDrawing
406 * This function validates the bitmap index (including I_IMAGECALLBACK
407 * functionality) and returns the corresponding image list.
409 static HIMAGELIST
410 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
412 HIMAGELIST himl;
414 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
415 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
416 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
417 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
418 return NULL;
421 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
422 if ((*index == I_IMAGECALLBACK) ||
423 (*index == I_IMAGENONE)) return NULL;
424 ERR("TBN_GETDISPINFO returned invalid index %d\n",
425 *index);
426 return NULL;
429 switch(imagelist)
431 case IMAGE_LIST_DEFAULT:
432 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
433 break;
434 case IMAGE_LIST_HOT:
435 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
436 break;
437 case IMAGE_LIST_DISABLED:
438 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
439 break;
440 default:
441 himl = NULL;
442 FIXME("Shouldn't reach here\n");
445 if (!himl)
446 TRACE("no image list\n");
448 return himl;
452 static void
453 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
455 RECT myrect;
456 COLORREF oldcolor, newcolor;
458 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
459 myrect.right = myrect.left + 1;
460 myrect.top = lpRect->top + 2;
461 myrect.bottom = lpRect->bottom - 2;
463 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
464 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
465 oldcolor = SetBkColor (hdc, newcolor);
466 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
468 myrect.left = myrect.right;
469 myrect.right = myrect.left + 1;
471 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
472 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
473 SetBkColor (hdc, newcolor);
474 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
476 SetBkColor (hdc, oldcolor);
480 /***********************************************************************
481 * TOOLBAR_DrawDDFlatSeparator
483 * This function draws the separator that was flagged as BTNS_DROPDOWN.
484 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
485 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
486 * are horizontal as opposed to the vertical separators for not dropdown
487 * type.
489 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
491 static void
492 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
494 RECT myrect;
495 COLORREF oldcolor, newcolor;
497 myrect.left = lpRect->left;
498 myrect.right = lpRect->right;
499 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
500 myrect.bottom = myrect.top + 1;
502 InflateRect (&myrect, -2, 0);
504 TRACE("rect=(%d,%d)-(%d,%d)\n",
505 myrect.left, myrect.top, myrect.right, myrect.bottom);
507 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
508 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
509 oldcolor = SetBkColor (hdc, newcolor);
510 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
512 myrect.top = myrect.bottom;
513 myrect.bottom = myrect.top + 1;
515 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
516 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
517 SetBkColor (hdc, newcolor);
518 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
520 SetBkColor (hdc, oldcolor);
524 static void
525 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
527 INT x, y;
528 HPEN hPen, hOldPen;
530 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
531 hOldPen = SelectObject ( hdc, hPen );
532 x = left + 2;
533 y = top;
534 MoveToEx (hdc, x, y, NULL);
535 LineTo (hdc, x+5, y++); x++;
536 MoveToEx (hdc, x, y, NULL);
537 LineTo (hdc, x+3, y++); x++;
538 MoveToEx (hdc, x, y, NULL);
539 LineTo (hdc, x+1, y++);
540 SelectObject( hdc, hOldPen );
541 DeleteObject( hPen );
545 * Draw the text string for this button.
546 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
547 * is non-zero, so we can simply check himlDef to see if we have
548 * an image list
550 static void
551 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
552 NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
554 HDC hdc = tbcd->nmcd.hdc;
555 HFONT hOldFont = 0;
556 COLORREF clrOld = 0;
557 COLORREF clrOldBk = 0;
558 int oldBkMode = 0;
559 UINT state = tbcd->nmcd.uItemState;
561 /* draw text */
562 if (lpText) {
563 TRACE("string=%s rect=(%d,%d)-(%d,%d)\n", debugstr_w(lpText),
564 rcText->left, rcText->top, rcText->right, rcText->bottom);
566 hOldFont = SelectObject (hdc, infoPtr->hFont);
567 if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
568 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
570 else if (state & CDIS_DISABLED) {
571 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
572 OffsetRect (rcText, 1, 1);
573 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
574 SetTextColor (hdc, comctl32_color.clr3dShadow);
575 OffsetRect (rcText, -1, -1);
577 else if (state & CDIS_INDETERMINATE) {
578 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
580 else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
581 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
582 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
583 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
585 else {
586 clrOld = SetTextColor (hdc, tbcd->clrText);
589 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
590 SetTextColor (hdc, clrOld);
591 if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
593 SetBkColor (hdc, clrOldBk);
594 SetBkMode (hdc, oldBkMode);
596 SelectObject (hdc, hOldFont);
601 static void
602 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
604 HDC hdc = tbcd->nmcd.hdc;
605 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
606 COLORREF clrTextOld;
607 COLORREF clrBkOld;
608 INT cx = lpRect->right - lpRect->left;
609 INT cy = lpRect->bottom - lpRect->top;
610 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
611 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
612 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
613 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
614 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
615 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
616 SetBkColor(hdc, clrBkOld);
617 SetTextColor(hdc, clrTextOld);
618 SelectObject (hdc, hbr);
622 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
624 INT cx, cy;
625 HBITMAP hbmMask, hbmImage;
626 HDC hdcMask, hdcImage;
628 ImageList_GetIconSize(himl, &cx, &cy);
630 /* Create src image */
631 hdcImage = CreateCompatibleDC(hdc);
632 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
633 SelectObject(hdcImage, hbmImage);
634 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
635 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
637 /* Create Mask */
638 hdcMask = CreateCompatibleDC(0);
639 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
640 SelectObject(hdcMask, hbmMask);
642 /* Remove the background and all white pixels */
643 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
644 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
645 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
646 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
648 /* draw the new mask 'etched' to hdc */
649 SetBkColor(hdc, RGB(255, 255, 255));
650 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
651 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
652 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
653 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
654 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
656 /* Cleanup */
657 DeleteObject(hbmImage);
658 DeleteDC(hdcImage);
659 DeleteObject (hbmMask);
660 DeleteDC(hdcMask);
664 static UINT
665 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
667 UINT retstate = 0;
669 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
670 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
671 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
672 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
673 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
674 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
675 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
676 return retstate;
679 /* draws the image on a toolbar button */
680 static void
681 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
682 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
684 HIMAGELIST himl = NULL;
685 BOOL draw_masked = FALSE;
686 INT index;
687 INT offset = 0;
688 UINT draw_flags = ILD_TRANSPARENT;
690 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
692 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
693 if (!himl)
695 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
696 draw_masked = TRUE;
699 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
700 ((tbcd->nmcd.uItemState & CDIS_HOT)
701 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
703 /* if hot, attempt to draw with hot image list, if fails,
704 use default image list */
705 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
706 if (!himl)
707 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
709 else
710 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
712 if (!himl)
713 return;
715 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
716 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
717 offset = 1;
719 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
720 (tbcd->nmcd.uItemState & CDIS_MARKED))
721 draw_flags |= ILD_BLEND50;
723 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
724 index, himl, left, top, offset);
726 if (draw_masked)
727 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
728 else
729 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
732 /* draws a blank frame for a toolbar button */
733 static void
734 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
736 HDC hdc = tbcd->nmcd.hdc;
737 RECT rc = tbcd->nmcd.rc;
738 /* if the state is disabled or indeterminate then the button
739 * cannot have an interactive look like pressed or hot */
740 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
741 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
742 BOOL pressed_look = !non_interactive_state &&
743 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
744 (tbcd->nmcd.uItemState & CDIS_CHECKED));
746 /* app don't want us to draw any edges */
747 if (dwItemCDFlag & TBCDRF_NOEDGES)
748 return;
750 if (infoPtr->dwStyle & TBSTYLE_FLAT)
752 if (pressed_look)
753 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
754 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
755 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
757 else
759 if (pressed_look)
760 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
761 else
762 DrawEdge (hdc, &rc, EDGE_RAISED,
763 BF_SOFT | BF_RECT | BF_MIDDLE);
767 static void
768 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
770 HDC hdc = tbcd->nmcd.hdc;
771 int offset = 0;
772 BOOL pressed = bDropDownPressed ||
773 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
775 if (infoPtr->dwStyle & TBSTYLE_FLAT)
777 if (pressed)
778 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
779 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
780 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
781 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
782 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
784 else
786 if (pressed)
787 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
788 else
789 DrawEdge (hdc, rcArrow, EDGE_RAISED,
790 BF_SOFT | BF_RECT | BF_MIDDLE);
793 if (pressed)
794 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
796 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
798 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
799 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
801 else
802 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
805 /* draws a complete toolbar button */
806 static void
807 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
809 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
810 DWORD dwStyle = infoPtr->dwStyle;
811 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
812 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
813 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
814 BOOL drawSepDropDownArrow = hasDropDownArrow &&
815 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
816 RECT rc, rcArrow, rcBitmap, rcText;
817 LPWSTR lpText = NULL;
818 NMTBCUSTOMDRAW tbcd;
819 DWORD ntfret;
820 INT offset;
821 INT oldBkMode;
822 DWORD dwItemCustDraw;
823 DWORD dwItemCDFlag;
824 HTHEME theme = GetWindowTheme (hwnd);
826 rc = btnPtr->rect;
827 CopyRect (&rcArrow, &rc);
829 /* separator - doesn't send NM_CUSTOMDRAW */
830 if (btnPtr->fsStyle & BTNS_SEP) {
831 if (theme)
833 DrawThemeBackground (theme, hdc,
834 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
835 &rc, NULL);
837 else
838 /* with the FLAT style, iBitmap is the width and has already */
839 /* been taken into consideration in calculating the width */
840 /* so now we need to draw the vertical separator */
841 /* empirical tests show that iBitmap can/will be non-zero */
842 /* when drawing the vertical bar... */
843 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
844 if (btnPtr->fsStyle & BTNS_DROPDOWN)
845 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
846 else
847 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
849 else if (btnPtr->fsStyle != BTNS_SEP) {
850 FIXME("Draw some kind of separator: fsStyle=%x\n",
851 btnPtr->fsStyle);
853 return;
856 /* get a pointer to the text */
857 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
859 if (hasDropDownArrow)
861 int right;
863 if (dwStyle & TBSTYLE_FLAT)
864 right = max(rc.left, rc.right - DDARROW_WIDTH);
865 else
866 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
868 if (drawSepDropDownArrow)
869 rc.right = right;
871 rcArrow.left = right;
874 /* copy text & bitmap rects after adjusting for drop-down arrow
875 * so that text & bitmap is centred in the rectangle not containing
876 * the arrow */
877 CopyRect(&rcText, &rc);
878 CopyRect(&rcBitmap, &rc);
880 /* Center the bitmap horizontally and vertically */
881 if (dwStyle & TBSTYLE_LIST)
883 if (lpText &&
884 infoPtr->nMaxTextRows > 0 &&
885 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
886 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
887 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
888 else
889 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
891 else
892 rcBitmap.left += (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
894 rcBitmap.top += infoPtr->szPadding.cy / 2;
896 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
897 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
898 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
899 TRACE("Text=%s\n", debugstr_w(lpText));
900 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
902 /* calculate text position */
903 if (lpText)
905 rcText.left += GetSystemMetrics(SM_CXEDGE);
906 rcText.right -= GetSystemMetrics(SM_CXEDGE);
907 if (dwStyle & TBSTYLE_LIST)
909 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
910 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
912 else
914 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
915 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
916 else
917 rcText.top += infoPtr->szPadding.cy/2 + 2;
921 /* Initialize fields in all cases, because we use these later
922 * NOTE: applications can and do alter these to customize their
923 * toolbars */
924 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
925 tbcd.clrText = comctl32_color.clrBtnText;
926 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
927 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
928 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
929 tbcd.clrMark = comctl32_color.clrHighlight;
930 tbcd.clrHighlightHotTrack = 0;
931 tbcd.nStringBkMode = TRANSPARENT;
932 tbcd.nHLStringBkMode = OPAQUE;
933 /* MSDN says that this is the text rectangle.
934 * But (why always a but) tracing of v5.7 of native shows
935 * that this is really a *relative* rectangle based on the
936 * the nmcd.rc. Also the left and top are always 0 ignoring
937 * any bitmap that might be present. */
938 tbcd.rcText.left = 0;
939 tbcd.rcText.top = 0;
940 tbcd.rcText.right = rcText.right - rc.left;
941 tbcd.rcText.bottom = rcText.bottom - rc.top;
942 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
943 tbcd.nmcd.hdc = hdc;
944 tbcd.nmcd.rc = rc;
945 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
947 /* FIXME: what are these used for? */
948 tbcd.hbrLines = 0;
949 tbcd.hpenLines = 0;
951 /* Issue Item Prepaint notify */
952 dwItemCustDraw = 0;
953 dwItemCDFlag = 0;
954 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
956 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
957 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
958 tbcd.nmcd.lItemlParam = btnPtr->dwData;
959 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
960 /* reset these fields so the user can't alter the behaviour like native */
961 tbcd.nmcd.hdc = hdc;
962 tbcd.nmcd.rc = rc;
964 dwItemCustDraw = ntfret & 0xffff;
965 dwItemCDFlag = ntfret & 0xffff0000;
966 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
967 return;
968 /* save the only part of the rect that the user can change */
969 rcText.right = tbcd.rcText.right + rc.left;
970 rcText.bottom = tbcd.rcText.bottom + rc.top;
973 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
974 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
975 OffsetRect(&rcText, 1, 1);
977 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
978 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
979 TOOLBAR_DrawPattern (&rc, &tbcd);
981 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
982 && (tbcd.nmcd.uItemState & CDIS_HOT))
984 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
986 COLORREF oldclr;
988 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
989 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
990 if (hasDropDownArrow)
991 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
992 SetBkColor(hdc, oldclr);
996 if (theme)
998 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
999 int stateId = TS_NORMAL;
1001 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1002 stateId = TS_DISABLED;
1003 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1004 stateId = TS_PRESSED;
1005 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1006 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1007 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1008 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1009 stateId = TS_HOT;
1011 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1013 else
1014 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1016 if (drawSepDropDownArrow)
1018 if (theme)
1020 int stateId = TS_NORMAL;
1022 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1023 stateId = TS_DISABLED;
1024 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1025 stateId = TS_PRESSED;
1026 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1027 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1028 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1029 stateId = TS_HOT;
1031 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1032 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1034 else
1035 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1038 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1039 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1040 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1041 SetBkMode (hdc, oldBkMode);
1043 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1045 if (hasDropDownArrow && !drawSepDropDownArrow)
1047 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1049 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1050 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1052 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1054 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1055 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1057 else
1058 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1061 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1063 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1064 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1070 static void
1071 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1073 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1074 TBUTTON_INFO *btnPtr;
1075 INT i;
1076 RECT rcTemp, rcClient;
1077 NMTBCUSTOMDRAW tbcd;
1078 DWORD ntfret;
1079 DWORD dwBaseCustDraw;
1081 /* the app has told us not to redraw the toolbar */
1082 if (!infoPtr->bDoRedraw)
1083 return;
1085 /* if imagelist belongs to the app, it can be changed
1086 by the app after setting it */
1087 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1089 infoPtr->nNumBitmaps = 0;
1090 for (i = 0; i < infoPtr->cimlDef; i++)
1091 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1094 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1096 /* change the imagelist icon size if we manage the list and it is necessary */
1097 TOOLBAR_CheckImageListIconSize(infoPtr);
1099 /* Send initial notify */
1100 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1101 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1102 tbcd.nmcd.hdc = hdc;
1103 tbcd.nmcd.rc = ps->rcPaint;
1104 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1105 dwBaseCustDraw = ntfret & 0xffff;
1107 GetClientRect(hwnd, &rcClient);
1109 /* redraw necessary buttons */
1110 btnPtr = infoPtr->buttons;
1111 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1113 BOOL bDraw;
1114 if (!RectVisible(hdc, &btnPtr->rect))
1115 continue;
1116 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1118 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1119 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1121 else
1122 bDraw = TRUE;
1123 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1124 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1125 if (bDraw)
1126 TOOLBAR_DrawButton(hwnd, btnPtr, hdc, dwBaseCustDraw);
1129 /* draw insert mark if required */
1130 if (infoPtr->tbim.iButton != -1)
1132 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1133 RECT rcInsertMark;
1134 rcInsertMark.top = rcButton.top;
1135 rcInsertMark.bottom = rcButton.bottom;
1136 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1137 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1138 else
1139 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1140 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1143 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1145 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1146 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1147 tbcd.nmcd.hdc = hdc;
1148 tbcd.nmcd.rc = ps->rcPaint;
1149 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1153 /***********************************************************************
1154 * TOOLBAR_MeasureString
1156 * This function gets the width and height of a string in pixels. This
1157 * is done first by using GetTextExtentPoint to get the basic width
1158 * and height. The DrawText is called with DT_CALCRECT to get the exact
1159 * width. The reason is because the text may have more than one "&" (or
1160 * prefix characters as M$ likes to call them). The prefix character
1161 * indicates where the underline goes, except for the string "&&" which
1162 * is reduced to a single "&". GetTextExtentPoint does not process these
1163 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1165 static void
1166 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1167 HDC hdc, LPSIZE lpSize)
1169 RECT myrect;
1171 lpSize->cx = 0;
1172 lpSize->cy = 0;
1174 if (infoPtr->nMaxTextRows > 0 &&
1175 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1176 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1177 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1179 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1181 if(lpText != NULL) {
1182 /* first get size of all the text */
1183 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1185 /* feed above size into the rectangle for DrawText */
1186 myrect.left = myrect.top = 0;
1187 myrect.right = lpSize->cx;
1188 myrect.bottom = lpSize->cy;
1190 /* Use DrawText to get true size as drawn (less pesky "&") */
1191 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1192 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1193 DT_NOPREFIX : 0));
1195 /* feed back to caller */
1196 lpSize->cx = myrect.right;
1197 lpSize->cy = myrect.bottom;
1201 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1204 /***********************************************************************
1205 * TOOLBAR_CalcStrings
1207 * This function walks through each string and measures it and returns
1208 * the largest height and width to caller.
1210 static void
1211 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1213 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1214 TBUTTON_INFO *btnPtr;
1215 INT i;
1216 SIZE sz;
1217 HDC hdc;
1218 HFONT hOldFont;
1220 lpSize->cx = 0;
1221 lpSize->cy = 0;
1223 if (infoPtr->nMaxTextRows == 0)
1224 return;
1226 hdc = GetDC (hwnd);
1227 hOldFont = SelectObject (hdc, infoPtr->hFont);
1229 if (infoPtr->nNumButtons == 0)
1231 TEXTMETRICW tm;
1233 GetTextMetricsW(hdc, &tm);
1234 lpSize->cy = tm.tmHeight;
1237 btnPtr = infoPtr->buttons;
1238 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1239 if(TOOLBAR_HasText(infoPtr, btnPtr))
1241 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1242 if (sz.cx > lpSize->cx)
1243 lpSize->cx = sz.cx;
1244 if (sz.cy > lpSize->cy)
1245 lpSize->cy = sz.cy;
1249 SelectObject (hdc, hOldFont);
1250 ReleaseDC (hwnd, hdc);
1252 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1255 /***********************************************************************
1256 * TOOLBAR_WrapToolbar
1258 * This function walks through the buttons and separators in the
1259 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1260 * wrapping should occur based on the width of the toolbar window.
1261 * It does *not* calculate button placement itself. That task
1262 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1263 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1264 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1266 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1267 * vertical toolbar lists.
1270 static void
1271 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1273 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1274 TBUTTON_INFO *btnPtr;
1275 INT x, cx, i, j;
1276 RECT rc;
1277 BOOL bWrap, bButtonWrap;
1279 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1280 /* no layout is necessary. Applications may use this style */
1281 /* to perform their own layout on the toolbar. */
1282 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1283 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1285 btnPtr = infoPtr->buttons;
1286 x = infoPtr->nIndent;
1288 if (GetParent(hwnd))
1290 /* this can get the parents width, to know how far we can extend
1291 * this toolbar. We cannot use its height, as there may be multiple
1292 * toolbars in a rebar control
1294 GetClientRect( GetParent(hwnd), &rc );
1295 infoPtr->nWidth = rc.right - rc.left;
1297 else
1299 GetWindowRect( hwnd, &rc );
1300 infoPtr->nWidth = rc.right - rc.left;
1303 bButtonWrap = FALSE;
1305 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1306 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1307 infoPtr->nIndent);
1309 for (i = 0; i < infoPtr->nNumButtons; i++ )
1311 bWrap = FALSE;
1312 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1314 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1315 continue;
1317 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1318 /* it is the actual width of the separator. This is used for */
1319 /* custom controls in toolbars. */
1320 /* */
1321 /* BTNS_DROPDOWN separators are treated as buttons for */
1322 /* width. - GA 8/01 */
1323 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1324 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1325 cx = (btnPtr[i].iBitmap > 0) ?
1326 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1327 else
1328 cx = infoPtr->nButtonWidth;
1330 /* Two or more adjacent separators form a separator group. */
1331 /* The first separator in a group should be wrapped to the */
1332 /* next row if the previous wrapping is on a button. */
1333 if( bButtonWrap &&
1334 (btnPtr[i].fsStyle & BTNS_SEP) &&
1335 (i + 1 < infoPtr->nNumButtons ) &&
1336 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1338 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1339 btnPtr[i].fsState |= TBSTATE_WRAP;
1340 x = infoPtr->nIndent;
1341 i++;
1342 bButtonWrap = FALSE;
1343 continue;
1346 /* The layout makes sure the bitmap is visible, but not the button. */
1347 /* Test added to also wrap after a button that starts a row but */
1348 /* is bigger than the area. - GA 8/01 */
1349 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1350 > infoPtr->nWidth ) ||
1351 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1353 BOOL bFound = FALSE;
1355 /* If the current button is a separator and not hidden, */
1356 /* go to the next until it reaches a non separator. */
1357 /* Wrap the last separator if it is before a button. */
1358 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1359 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1360 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1361 i < infoPtr->nNumButtons )
1363 i++;
1364 bFound = TRUE;
1367 if( bFound && i < infoPtr->nNumButtons )
1369 i--;
1370 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1371 i, btnPtr[i].fsStyle, x, cx);
1372 btnPtr[i].fsState |= TBSTATE_WRAP;
1373 x = infoPtr->nIndent;
1374 bButtonWrap = FALSE;
1375 continue;
1377 else if ( i >= infoPtr->nNumButtons)
1378 break;
1380 /* If the current button is not a separator, find the last */
1381 /* separator and wrap it. */
1382 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1384 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1385 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1387 bFound = TRUE;
1388 i = j;
1389 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1390 i, btnPtr[i].fsStyle, x, cx);
1391 x = infoPtr->nIndent;
1392 btnPtr[j].fsState |= TBSTATE_WRAP;
1393 bButtonWrap = FALSE;
1394 break;
1398 /* If no separator available for wrapping, wrap one of */
1399 /* non-hidden previous button. */
1400 if (!bFound)
1402 for ( j = i - 1;
1403 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1405 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1406 continue;
1408 bFound = TRUE;
1409 i = j;
1410 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1411 i, btnPtr[i].fsStyle, x, cx);
1412 x = infoPtr->nIndent;
1413 btnPtr[j].fsState |= TBSTATE_WRAP;
1414 bButtonWrap = TRUE;
1415 break;
1419 /* If all above failed, wrap the current button. */
1420 if (!bFound)
1422 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1423 i, btnPtr[i].fsStyle, x, cx);
1424 btnPtr[i].fsState |= TBSTATE_WRAP;
1425 bFound = TRUE;
1426 x = infoPtr->nIndent;
1427 if (btnPtr[i].fsStyle & BTNS_SEP )
1428 bButtonWrap = FALSE;
1429 else
1430 bButtonWrap = TRUE;
1433 else {
1434 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1435 i, btnPtr[i].fsStyle, x, cx);
1436 x += cx;
1442 /***********************************************************************
1443 * TOOLBAR_MeasureButton
1445 * Calculates the width and height required for a button. Used in
1446 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1447 * the width of buttons that are autosized.
1449 * Note that it would have been rather elegant to use one piece of code for
1450 * both the laying out of the toolbar and for controlling where button parts
1451 * are drawn, but the native control has inconsistencies between the two that
1452 * prevent this from being effectively. These inconsistencies can be seen as
1453 * artefacts where parts of the button appear outside of the bounding button
1454 * rectangle.
1456 * There are several cases for the calculation of the button dimensions and
1457 * button part positioning:
1459 * List
1460 * ====
1462 * With Bitmap:
1464 * +--------------------------------------------------------+ ^
1465 * | ^ ^ | |
1466 * | | pad.cy / 2 | centred | |
1467 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1468 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1469 * | |<------------>| | | | |
1470 * | +--------------+ +------------+ | |
1471 * |<-------------------------------------->| | |
1472 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1473 * | szText.cx | |
1474 * +--------------------------------------------------------+ -
1475 * <-------------------------------------------------------->
1476 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1478 * Without Bitmap (I_IMAGENONE):
1480 * +-----------------------------------+ ^
1481 * | ^ | |
1482 * | | centred | | LISTPAD_CY +
1483 * | +------------+ | | szText.cy
1484 * | | Text | | |
1485 * | | | | |
1486 * | +------------+ | |
1487 * |<----------------->| | |
1488 * | cxedge |<-----------> | |
1489 * | szText.cx | |
1490 * +-----------------------------------+ -
1491 * <----------------------------------->
1492 * szText.cx + pad.cx
1494 * Without text:
1496 * +--------------------------------------+ ^
1497 * | ^ | |
1498 * | | padding.cy/2 | | DEFPAD_CY +
1499 * | +------------+ | | nBitmapHeight
1500 * | | Bitmap | | |
1501 * | | | | |
1502 * | +------------+ | |
1503 * |<------------------->| | |
1504 * | cxedge + iListGap/2 |<-----------> | |
1505 * | nBitmapWidth | |
1506 * +--------------------------------------+ -
1507 * <-------------------------------------->
1508 * 2*cxedge + nBitmapWidth + iListGap
1510 * Non-List
1511 * ========
1513 * With bitmap:
1515 * +-----------------------------------+ ^
1516 * | ^ | |
1517 * | | pad.cy / 2 | | nBitmapHeight +
1518 * | - | | szText.cy +
1519 * | +------------+ | | DEFPAD_CY + 1
1520 * | centred | Bitmap | | |
1521 * |<----------------->| | | |
1522 * | +------------+ | |
1523 * | ^ | |
1524 * | 1 | | |
1525 * | - | |
1526 * | centred +---------------+ | |
1527 * |<--------------->| Text | | |
1528 * | +---------------+ | |
1529 * +-----------------------------------+ -
1530 * <----------------------------------->
1531 * pad.cx + max(nBitmapWidth, szText.cx)
1533 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1535 * +---------------------------------------+ ^
1536 * | ^ | |
1537 * | | 2 + pad.cy / 2 | |
1538 * | - | | szText.cy +
1539 * | centred +-----------------+ | | pad.cy + 2
1540 * |<--------------->| Text | | |
1541 * | +-----------------+ | |
1542 * | | |
1543 * +---------------------------------------+ -
1544 * <--------------------------------------->
1545 * 2*cxedge + pad.cx + szText.cx
1547 * Without text:
1548 * As for with bitmaps, but with szText.cx zero.
1550 static inline SIZE TOOLBAR_MeasureButton(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1552 SIZE sizeButton;
1553 if (infoPtr->dwStyle & TBSTYLE_LIST)
1555 /* set button height from bitmap / text height... */
1556 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1557 sizeString.cy);
1559 /* ... add on the necessary padding */
1560 if (bValidImageList)
1562 if (bHasBitmap)
1563 sizeButton.cy += DEFPAD_CY;
1564 else
1565 sizeButton.cy += LISTPAD_CY;
1567 else
1568 sizeButton.cy += infoPtr->szPadding.cy;
1570 /* calculate button width */
1571 if (bHasBitmap)
1573 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1574 infoPtr->nBitmapWidth + infoPtr->iListGap;
1575 if (sizeString.cx > 0)
1576 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1578 else
1579 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1581 else
1583 if (bHasBitmap)
1585 sizeButton.cy = infoPtr->nBitmapHeight + 1 +
1586 sizeString.cy + DEFPAD_CY;
1587 sizeButton.cx = infoPtr->szPadding.cx +
1588 max(sizeString.cx, infoPtr->nBitmapWidth);
1590 else
1592 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1593 NONLIST_NOTEXT_OFFSET;
1594 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1595 infoPtr->szPadding.cx + sizeString.cx;
1598 return sizeButton;
1602 /***********************************************************************
1603 * TOOLBAR_CalcToolbar
1605 * This function calculates button and separator placement. It first
1606 * calculates the button sizes, gets the toolbar window width and then
1607 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1608 * on. It assigns a new location to each item and sends this location to
1609 * the tooltip window if appropriate. Finally, it updates the rcBound
1610 * rect and calculates the new required toolbar window height.
1612 static void
1613 TOOLBAR_CalcToolbar (HWND hwnd)
1615 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1616 DWORD dwStyle = infoPtr->dwStyle;
1617 TBUTTON_INFO *btnPtr;
1618 INT i, nRows, nSepRows;
1619 INT x, y, cx, cy;
1620 SIZE sizeString, sizeButton;
1621 BOOL bWrap;
1622 BOOL validImageList = FALSE;
1623 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1625 TOOLBAR_CalcStrings (hwnd, &sizeString);
1627 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1629 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1630 validImageList = TRUE;
1631 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1632 infoPtr->nButtonWidth = sizeButton.cx;
1633 infoPtr->nButtonHeight = sizeButton.cy;
1635 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1636 infoPtr->nButtonWidth = infoPtr->cxMin;
1637 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1638 infoPtr->nButtonWidth = infoPtr->cxMax;
1640 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1642 x = infoPtr->nIndent;
1643 if (infoPtr->dwStyle & TBSTYLE_FLAT)
1644 y = 0;
1645 else
1646 y = TOP_BORDER;
1648 /* from above, minimum is a button, and possible text */
1649 cx = infoPtr->nButtonWidth;
1650 cy = infoPtr->nButtonHeight;
1652 nRows = nSepRows = 0;
1654 infoPtr->rcBound.top = y;
1655 infoPtr->rcBound.left = x;
1656 infoPtr->rcBound.bottom = y + cy;
1657 infoPtr->rcBound.right = x;
1659 btnPtr = infoPtr->buttons;
1661 TRACE("cy=%d\n", cy);
1663 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1665 bWrap = FALSE;
1666 if (btnPtr->fsState & TBSTATE_HIDDEN)
1668 SetRectEmpty (&btnPtr->rect);
1669 continue;
1672 cy = infoPtr->nButtonHeight;
1674 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1675 /* it is the actual width of the separator. This is used for */
1676 /* custom controls in toolbars. */
1677 if (btnPtr->fsStyle & BTNS_SEP) {
1678 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1679 cy = (btnPtr->iBitmap > 0) ?
1680 btnPtr->iBitmap : SEPARATOR_WIDTH;
1681 cx = infoPtr->nButtonWidth;
1683 else
1684 cx = (btnPtr->iBitmap > 0) ?
1685 btnPtr->iBitmap : SEPARATOR_WIDTH;
1687 else
1689 if (btnPtr->cx)
1690 cx = btnPtr->cx;
1691 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1692 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1694 SIZE sz;
1695 HDC hdc;
1696 HFONT hOldFont;
1698 hdc = GetDC (hwnd);
1699 hOldFont = SelectObject (hdc, infoPtr->hFont);
1701 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1703 SelectObject (hdc, hOldFont);
1704 ReleaseDC (hwnd, hdc);
1706 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1707 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1708 validImageList);
1709 cx = sizeButton.cx;
1711 else
1712 cx = infoPtr->nButtonWidth;
1714 /* if size has been set manually then don't add on extra space
1715 * for the drop down arrow */
1716 if (!btnPtr->cx && hasDropDownArrows &&
1717 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1718 cx += DDARROW_WIDTH;
1720 if (btnPtr->fsState & TBSTATE_WRAP )
1721 bWrap = TRUE;
1723 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1725 if (infoPtr->rcBound.left > x)
1726 infoPtr->rcBound.left = x;
1727 if (infoPtr->rcBound.right < x + cx)
1728 infoPtr->rcBound.right = x + cx;
1729 if (infoPtr->rcBound.bottom < y + cy)
1730 infoPtr->rcBound.bottom = y + cy;
1732 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1734 /* btnPtr->nRow is zero based. The space between the rows is */
1735 /* also considered as a row. */
1736 btnPtr->nRow = nRows + nSepRows;
1738 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1739 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1740 x, y, x+cx, y+cy);
1742 if( bWrap )
1744 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1745 y += cy;
1746 else
1748 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1749 /* it is the actual width of the separator. This is used for */
1750 /* custom controls in toolbars. */
1751 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1752 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1753 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1754 else
1755 y += cy;
1757 /* nSepRows is used to calculate the extra height follwoing */
1758 /* the last row. */
1759 nSepRows++;
1761 x = infoPtr->nIndent;
1763 /* Increment row number unless this is the last button */
1764 /* and it has Wrap set. */
1765 if (i != infoPtr->nNumButtons-1)
1766 nRows++;
1768 else
1769 x += cx;
1772 /* infoPtr->nRows is the number of rows on the toolbar */
1773 infoPtr->nRows = nRows + nSepRows + 1;
1775 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1779 static INT
1780 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1782 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1783 TBUTTON_INFO *btnPtr;
1784 INT i;
1786 btnPtr = infoPtr->buttons;
1787 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1788 if (btnPtr->fsState & TBSTATE_HIDDEN)
1789 continue;
1791 if (btnPtr->fsStyle & BTNS_SEP) {
1792 if (PtInRect (&btnPtr->rect, *lpPt)) {
1793 TRACE(" ON SEPARATOR %d!\n", i);
1794 return -i;
1797 else {
1798 if (PtInRect (&btnPtr->rect, *lpPt)) {
1799 TRACE(" ON BUTTON %d!\n", i);
1800 return i;
1805 TRACE(" NOWHERE!\n");
1806 return TOOLBAR_NOWHERE;
1810 static INT
1811 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1813 TBUTTON_INFO *btnPtr;
1814 INT i;
1816 if (CommandIsIndex) {
1817 TRACE("command is really index command=%d\n", idCommand);
1818 if (idCommand >= infoPtr->nNumButtons) return -1;
1819 return idCommand;
1821 btnPtr = infoPtr->buttons;
1822 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1823 if (btnPtr->idCommand == idCommand) {
1824 TRACE("command=%d index=%d\n", idCommand, i);
1825 return i;
1828 TRACE("no index found for command=%d\n", idCommand);
1829 return -1;
1833 static INT
1834 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1836 TBUTTON_INFO *btnPtr;
1837 INT nRunIndex;
1839 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1840 return -1;
1842 /* check index button */
1843 btnPtr = &infoPtr->buttons[nIndex];
1844 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1845 if (btnPtr->fsState & TBSTATE_CHECKED)
1846 return nIndex;
1849 /* check previous buttons */
1850 nRunIndex = nIndex - 1;
1851 while (nRunIndex >= 0) {
1852 btnPtr = &infoPtr->buttons[nRunIndex];
1853 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1854 if (btnPtr->fsState & TBSTATE_CHECKED)
1855 return nRunIndex;
1857 else
1858 break;
1859 nRunIndex--;
1862 /* check next buttons */
1863 nRunIndex = nIndex + 1;
1864 while (nRunIndex < infoPtr->nNumButtons) {
1865 btnPtr = &infoPtr->buttons[nRunIndex];
1866 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1867 if (btnPtr->fsState & TBSTATE_CHECKED)
1868 return nRunIndex;
1870 else
1871 break;
1872 nRunIndex++;
1875 return -1;
1879 static VOID
1880 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1881 WPARAM wParam, LPARAM lParam)
1883 MSG msg;
1885 msg.hwnd = hwndMsg;
1886 msg.message = uMsg;
1887 msg.wParam = wParam;
1888 msg.lParam = lParam;
1889 msg.time = GetMessageTime ();
1890 msg.pt.x = LOWORD(GetMessagePos ());
1891 msg.pt.y = HIWORD(GetMessagePos ());
1893 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1896 static void
1897 TOOLBAR_TooltipAddTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1899 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1900 TTTOOLINFOW ti;
1902 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1903 ti.cbSize = sizeof (TTTOOLINFOW);
1904 ti.hwnd = infoPtr->hwndSelf;
1905 ti.uId = button->idCommand;
1906 ti.hinst = 0;
1907 ti.lpszText = LPSTR_TEXTCALLBACKW;
1908 /* ti.lParam = random value from the stack? */
1910 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1911 0, (LPARAM)&ti);
1915 static void
1916 TOOLBAR_TooltipDelTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1918 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1919 TTTOOLINFOW ti;
1921 ZeroMemory(&ti, sizeof(ti));
1922 ti.cbSize = sizeof(ti);
1923 ti.hwnd = infoPtr->hwndSelf;
1924 ti.uId = button->idCommand;
1926 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1930 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1932 /* Set the toolTip only for non-hidden, non-separator button */
1933 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1935 TTTOOLINFOW ti;
1937 ZeroMemory(&ti, sizeof(ti));
1938 ti.cbSize = sizeof(ti);
1939 ti.hwnd = infoPtr->hwndSelf;
1940 ti.uId = button->idCommand;
1941 ti.rect = button->rect;
1942 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1946 /* Creates the tooltip control */
1947 static void
1948 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
1950 int i;
1951 NMTOOLTIPSCREATED nmttc;
1953 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, 0,
1954 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1955 infoPtr->hwndSelf, 0, 0, 0);
1957 if (!infoPtr->hwndToolTip)
1958 return;
1960 /* Send NM_TOOLTIPSCREATED notification */
1961 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1962 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
1964 for (i = 0; i < infoPtr->nNumButtons; i++)
1966 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
1967 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
1971 /* keeps available button list box sorted by button id */
1972 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1974 int i;
1975 int count;
1976 PCUSTOMBUTTON btnInfo;
1977 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1979 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1981 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1983 /* position 0 is always separator */
1984 for (i = 1; i < count; i++)
1986 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1987 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1989 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1990 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1991 return;
1994 /* id higher than all others add to end */
1995 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
1996 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1999 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2001 NMTOOLBARW nmtb;
2003 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2005 if (nIndexFrom == nIndexTo)
2006 return;
2008 /* MSDN states that iItem is the index of the button, rather than the
2009 * command ID as used by every other NMTOOLBAR notification */
2010 nmtb.iItem = nIndexFrom;
2011 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2013 PCUSTOMBUTTON btnInfo;
2014 NMHDR hdr;
2015 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2016 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2018 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2020 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2021 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2022 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2023 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2025 if (nIndexTo <= 0)
2026 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2027 else
2028 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2030 /* last item is always separator, so -2 instead of -1 */
2031 if (nIndexTo >= (count - 2))
2032 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2033 else
2034 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2036 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2037 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2039 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2043 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2045 NMTOOLBARW nmtb;
2047 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2049 /* MSDN states that iItem is the index of the button, rather than the
2050 * command ID as used by every other NMTOOLBAR notification */
2051 nmtb.iItem = nIndexAvail;
2052 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2054 PCUSTOMBUTTON btnInfo;
2055 NMHDR hdr;
2056 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2057 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2058 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2060 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2062 if (nIndexAvail != 0) /* index == 0 indicates separator */
2064 /* remove from 'available buttons' list */
2065 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2066 if (nIndexAvail == count-1)
2067 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2068 else
2069 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2071 else
2073 PCUSTOMBUTTON btnNew;
2075 /* duplicate 'separator' button */
2076 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2077 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2078 btnInfo = btnNew;
2081 /* insert into 'toolbar button' list */
2082 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2083 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2085 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2087 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2091 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
2093 PCUSTOMBUTTON btnInfo;
2094 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2096 TRACE("Remove: index %d\n", index);
2098 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2100 /* send TBN_QUERYDELETE notification */
2101 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2103 NMHDR hdr;
2105 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2106 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2108 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2110 /* insert into 'available button' list */
2111 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2112 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2113 else
2114 Free(btnInfo);
2116 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2120 /* drag list notification function for toolbar buttons list box */
2121 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2123 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2124 switch (pDLI->uNotification)
2126 case DL_BEGINDRAG:
2128 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2129 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2130 /* no dragging for last item (separator) */
2131 if (nCurrentItem >= (nCount - 1)) return FALSE;
2132 return TRUE;
2134 case DL_DRAGGING:
2136 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2137 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2138 /* no dragging past last item (separator) */
2139 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2141 DrawInsert(hwnd, hwndList, nCurrentItem);
2142 /* FIXME: native uses "move button" cursor */
2143 return DL_COPYCURSOR;
2146 /* not over toolbar buttons list */
2147 if (nCurrentItem < 0)
2149 POINT ptWindow = pDLI->ptCursor;
2150 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2151 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2152 /* over available buttons list? */
2153 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2154 /* FIXME: native uses "move button" cursor */
2155 return DL_COPYCURSOR;
2157 /* clear drag arrow */
2158 DrawInsert(hwnd, hwndList, -1);
2159 return DL_STOPCURSOR;
2161 case DL_DROPPED:
2163 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2164 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2165 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2166 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2168 /* clear drag arrow */
2169 DrawInsert(hwnd, hwndList, -1);
2170 /* move item */
2171 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2173 /* not over toolbar buttons list */
2174 if (nIndexTo < 0)
2176 POINT ptWindow = pDLI->ptCursor;
2177 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2178 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2179 /* over available buttons list? */
2180 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2181 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2183 break;
2185 case DL_CANCELDRAG:
2186 /* Clear drag arrow */
2187 DrawInsert(hwnd, hwndList, -1);
2188 break;
2191 return 0;
2194 /* drag list notification function for available buttons list box */
2195 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2197 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2198 switch (pDLI->uNotification)
2200 case DL_BEGINDRAG:
2201 return TRUE;
2202 case DL_DRAGGING:
2204 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2205 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2206 /* no dragging past last item (separator) */
2207 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2209 DrawInsert(hwnd, hwndList, nCurrentItem);
2210 /* FIXME: native uses "move button" cursor */
2211 return DL_COPYCURSOR;
2214 /* not over toolbar buttons list */
2215 if (nCurrentItem < 0)
2217 POINT ptWindow = pDLI->ptCursor;
2218 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2219 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2220 /* over available buttons list? */
2221 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2222 /* FIXME: native uses "move button" cursor */
2223 return DL_COPYCURSOR;
2225 /* clear drag arrow */
2226 DrawInsert(hwnd, hwndList, -1);
2227 return DL_STOPCURSOR;
2229 case DL_DROPPED:
2231 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2232 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2233 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2234 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2236 /* clear drag arrow */
2237 DrawInsert(hwnd, hwndList, -1);
2238 /* add item */
2239 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2242 case DL_CANCELDRAG:
2243 /* Clear drag arrow */
2244 DrawInsert(hwnd, hwndList, -1);
2245 break;
2247 return 0;
2250 extern UINT uDragListMessage;
2252 /***********************************************************************
2253 * TOOLBAR_CustomizeDialogProc
2254 * This function implements the toolbar customization dialog.
2256 static INT_PTR CALLBACK
2257 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2259 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2260 PCUSTOMBUTTON btnInfo;
2261 NMTOOLBARA nmtb;
2262 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2264 switch (uMsg)
2266 case WM_INITDIALOG:
2267 custInfo = (PCUSTDLG_INFO)lParam;
2268 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2270 if (custInfo)
2272 WCHAR Buffer[256];
2273 int i = 0;
2274 int index;
2275 NMTBINITCUSTOMIZE nmtbic;
2277 infoPtr = custInfo->tbInfo;
2279 /* send TBN_QUERYINSERT notification */
2280 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2282 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2283 return FALSE;
2285 nmtbic.hwndDialog = hwnd;
2286 /* Send TBN_INITCUSTOMIZE notification */
2287 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2288 TBNRF_HIDEHELP)
2290 TRACE("TBNRF_HIDEHELP requested\n");
2291 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2294 /* add items to 'toolbar buttons' list and check if removable */
2295 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2297 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2298 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2299 btnInfo->btn.fsStyle = BTNS_SEP;
2300 btnInfo->bVirtual = FALSE;
2301 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2303 /* send TBN_QUERYDELETE notification */
2304 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2306 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2307 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2310 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2312 /* insert separator button into 'available buttons' list */
2313 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2314 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2315 btnInfo->btn.fsStyle = BTNS_SEP;
2316 btnInfo->bVirtual = FALSE;
2317 btnInfo->bRemovable = TRUE;
2318 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2319 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2320 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2322 /* insert all buttons into dsa */
2323 for (i = 0;; i++)
2325 /* send TBN_GETBUTTONINFO notification */
2326 NMTOOLBARW nmtb;
2327 nmtb.iItem = i;
2328 nmtb.pszText = Buffer;
2329 nmtb.cchText = 256;
2331 /* Clear previous button's text */
2332 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2334 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2335 break;
2337 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2338 nmtb.tbButton.fsStyle, i,
2339 nmtb.tbButton.idCommand,
2340 nmtb.tbButton.iString,
2341 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2342 : "");
2344 /* insert button into the apropriate list */
2345 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2346 if (index == -1)
2348 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2349 btnInfo->bVirtual = FALSE;
2350 btnInfo->bRemovable = TRUE;
2352 else
2354 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2355 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2358 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2359 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2361 if (lstrlenW(nmtb.pszText))
2362 lstrcpyW(btnInfo->text, nmtb.pszText);
2363 else if (nmtb.tbButton.iString >= 0 &&
2364 nmtb.tbButton.iString < infoPtr->nNumStrings)
2366 lstrcpyW(btnInfo->text,
2367 infoPtr->strings[nmtb.tbButton.iString]);
2371 if (index == -1)
2372 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2375 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2377 /* select first item in the 'available' list */
2378 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2380 /* append 'virtual' separator button to the 'toolbar buttons' list */
2381 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2382 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2383 btnInfo->btn.fsStyle = BTNS_SEP;
2384 btnInfo->bVirtual = TRUE;
2385 btnInfo->bRemovable = FALSE;
2386 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2387 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2388 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2390 /* select last item in the 'toolbar' list */
2391 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2392 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2394 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2395 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2397 /* set focus and disable buttons */
2398 PostMessageW (hwnd, WM_USER, 0, 0);
2400 return TRUE;
2402 case WM_USER:
2403 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2404 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2405 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2406 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2407 return TRUE;
2409 case WM_CLOSE:
2410 EndDialog(hwnd, FALSE);
2411 return TRUE;
2413 case WM_COMMAND:
2414 switch (LOWORD(wParam))
2416 case IDC_TOOLBARBTN_LBOX:
2417 if (HIWORD(wParam) == LBN_SELCHANGE)
2419 PCUSTOMBUTTON btnInfo;
2420 NMTOOLBARA nmtb;
2421 int count;
2422 int index;
2424 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2425 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2427 /* send TBN_QUERYINSERT notification */
2428 nmtb.iItem = index;
2429 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2431 /* get list box item */
2432 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2434 if (index == (count - 1))
2436 /* last item (virtual separator) */
2437 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2438 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2440 else if (index == (count - 2))
2442 /* second last item (last non-virtual item) */
2443 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2444 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2446 else if (index == 0)
2448 /* first item */
2449 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2450 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2452 else
2454 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2455 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2458 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2460 break;
2462 case IDC_MOVEUP_BTN:
2464 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2465 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2467 break;
2469 case IDC_MOVEDN_BTN: /* move down */
2471 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2472 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2474 break;
2476 case IDC_REMOVE_BTN: /* remove button */
2478 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2480 if (LB_ERR == index)
2481 break;
2483 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2485 break;
2486 case IDC_HELP_BTN:
2487 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2488 break;
2489 case IDC_RESET_BTN:
2490 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2491 break;
2493 case IDOK: /* Add button */
2495 int index;
2496 int indexto;
2498 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2499 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2501 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2503 break;
2505 case IDCANCEL:
2506 EndDialog(hwnd, FALSE);
2507 break;
2509 return TRUE;
2511 case WM_DESTROY:
2513 int count;
2514 int i;
2516 /* delete items from 'toolbar buttons' listbox*/
2517 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2518 for (i = 0; i < count; i++)
2520 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2521 Free(btnInfo);
2522 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2524 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2527 /* delete items from 'available buttons' listbox*/
2528 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2529 for (i = 0; i < count; i++)
2531 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2532 Free(btnInfo);
2533 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2535 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2537 return TRUE;
2539 case WM_DRAWITEM:
2540 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2542 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2543 RECT rcButton;
2544 RECT rcText;
2545 HPEN hPen, hOldPen;
2546 HBRUSH hOldBrush;
2547 COLORREF oldText = 0;
2548 COLORREF oldBk = 0;
2550 /* get item data */
2551 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2552 if (btnInfo == NULL)
2554 FIXME("btnInfo invalid!\n");
2555 return TRUE;
2558 /* set colors and select objects */
2559 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2560 if (btnInfo->bVirtual)
2561 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2562 else
2563 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2564 hPen = CreatePen( PS_SOLID, 1,
2565 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2566 hOldPen = SelectObject (lpdis->hDC, hPen );
2567 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2569 /* fill background rectangle */
2570 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2571 lpdis->rcItem.right, lpdis->rcItem.bottom);
2573 /* calculate button and text rectangles */
2574 CopyRect (&rcButton, &lpdis->rcItem);
2575 InflateRect (&rcButton, -1, -1);
2576 CopyRect (&rcText, &rcButton);
2577 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2578 rcText.left = rcButton.right + 2;
2580 /* draw focus rectangle */
2581 if (lpdis->itemState & ODS_FOCUS)
2582 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2584 /* draw button */
2585 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2586 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2588 /* draw image and text */
2589 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2590 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2591 btnInfo->btn.iBitmap));
2592 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2593 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2595 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2596 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2598 /* delete objects and reset colors */
2599 SelectObject (lpdis->hDC, hOldBrush);
2600 SelectObject (lpdis->hDC, hOldPen);
2601 SetBkColor (lpdis->hDC, oldBk);
2602 SetTextColor (lpdis->hDC, oldText);
2603 DeleteObject( hPen );
2604 return TRUE;
2606 return FALSE;
2608 case WM_MEASUREITEM:
2609 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2611 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2613 lpmis->itemHeight = 15 + 8; /* default height */
2615 return TRUE;
2617 return FALSE;
2619 default:
2620 if (uDragListMessage && (uMsg == uDragListMessage))
2622 if (wParam == IDC_TOOLBARBTN_LBOX)
2624 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2625 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2626 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2627 return TRUE;
2629 else if (wParam == IDC_AVAILBTN_LBOX)
2631 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2632 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2633 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2634 return TRUE;
2637 return FALSE;
2641 static BOOL
2642 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2644 HBITMAP hbmLoad;
2645 INT nCountBefore = ImageList_GetImageCount(himlDef);
2646 INT nCountAfter;
2647 INT cxIcon, cyIcon;
2648 INT nAdded;
2649 INT nIndex;
2651 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2652 /* Add bitmaps to the default image list */
2653 if (bitmap->hInst == NULL) /* a handle was passed */
2655 BITMAP bmp;
2656 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2657 HDC hdcImage, hdcBitmap;
2659 /* copy the bitmap before adding it so that the user's bitmap
2660 * doesn't get modified.
2662 GetObjectW ((HBITMAP)bitmap->nID, sizeof(BITMAP), (LPVOID)&bmp);
2664 hdcImage = CreateCompatibleDC(0);
2665 hdcBitmap = CreateCompatibleDC(0);
2667 /* create new bitmap */
2668 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2669 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)bitmap->nID);
2670 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2672 /* Copy the user's image */
2673 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2674 hdcBitmap, 0, 0, SRCCOPY);
2676 SelectObject (hdcImage, hOldBitmapLoad);
2677 SelectObject (hdcBitmap, hOldBitmapBitmap);
2678 DeleteDC (hdcImage);
2679 DeleteDC (hdcBitmap);
2681 else
2682 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2684 /* enlarge the bitmap if needed */
2685 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2686 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2688 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2689 DeleteObject(hbmLoad);
2690 if (nIndex == -1)
2691 return FALSE;
2693 nCountAfter = ImageList_GetImageCount(himlDef);
2694 nAdded = nCountAfter - nCountBefore;
2695 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2697 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2698 } else if (nAdded > (INT)bitmap->nButtons) {
2699 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2700 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2703 infoPtr->nNumBitmaps += nAdded;
2704 return TRUE;
2707 static void
2708 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2710 HIMAGELIST himlDef;
2711 HIMAGELIST himlNew;
2712 INT cx, cy;
2713 INT i;
2715 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2716 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2717 return;
2718 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2719 return;
2720 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2721 return;
2723 TRACE("Update icon size: %dx%d -> %dx%d\n",
2724 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2726 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2727 ILC_COLORDDB|ILC_MASK, 8, 2);
2728 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2729 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2730 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2731 infoPtr->himlInt = himlNew;
2733 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2734 ImageList_Destroy(himlDef);
2737 /***********************************************************************
2738 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2741 static LRESULT
2742 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2744 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2745 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2746 TBITMAP_INFO info;
2747 INT iSumButtons, i;
2748 HIMAGELIST himlDef;
2750 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2751 if (!lpAddBmp)
2752 return -1;
2754 if (lpAddBmp->hInst == HINST_COMMCTRL)
2756 info.hInst = COMCTL32_hModule;
2757 switch (lpAddBmp->nID)
2759 case IDB_STD_SMALL_COLOR:
2760 info.nButtons = 15;
2761 info.nID = IDB_STD_SMALL;
2762 break;
2763 case IDB_STD_LARGE_COLOR:
2764 info.nButtons = 15;
2765 info.nID = IDB_STD_LARGE;
2766 break;
2767 case IDB_VIEW_SMALL_COLOR:
2768 info.nButtons = 12;
2769 info.nID = IDB_VIEW_SMALL;
2770 break;
2771 case IDB_VIEW_LARGE_COLOR:
2772 info.nButtons = 12;
2773 info.nID = IDB_VIEW_LARGE;
2774 break;
2775 case IDB_HIST_SMALL_COLOR:
2776 info.nButtons = 5;
2777 info.nID = IDB_HIST_SMALL;
2778 break;
2779 case IDB_HIST_LARGE_COLOR:
2780 info.nButtons = 5;
2781 info.nID = IDB_HIST_LARGE;
2782 break;
2783 default:
2784 return -1;
2787 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2789 /* Windows resize all the buttons to the size of a newly added standard image */
2790 if (lpAddBmp->nID & 1)
2792 /* large icons */
2793 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2794 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2796 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2797 MAKELPARAM((WORD)24, (WORD)24));
2798 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2799 MAKELPARAM((WORD)31, (WORD)30));
2801 else
2803 /* small icons */
2804 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2805 MAKELPARAM((WORD)16, (WORD)16));
2806 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2807 MAKELPARAM((WORD)22, (WORD)22));
2810 TOOLBAR_CalcToolbar (hwnd);
2812 else
2814 info.nButtons = (INT)wParam;
2815 info.hInst = lpAddBmp->hInst;
2816 info.nID = lpAddBmp->nID;
2817 TRACE("adding %d bitmaps!\n", info.nButtons);
2820 /* check if the bitmap is already loaded and compute iSumButtons */
2821 iSumButtons = 0;
2822 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2824 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2825 infoPtr->bitmaps[i].nID == info.nID)
2826 return iSumButtons;
2827 iSumButtons += infoPtr->bitmaps[i].nButtons;
2830 if (!infoPtr->cimlDef) {
2831 /* create new default image list */
2832 TRACE ("creating default image list!\n");
2834 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2835 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2836 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2837 infoPtr->himlInt = himlDef;
2839 else {
2840 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2843 if (!himlDef) {
2844 WARN("No default image list available\n");
2845 return -1;
2848 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2849 return -1;
2851 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2852 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2853 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2854 infoPtr->nNumBitmapInfos++;
2855 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2857 InvalidateRect(hwnd, NULL, TRUE);
2858 return iSumButtons;
2862 static LRESULT
2863 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2865 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2866 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2867 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2869 TRACE("adding %d buttons (unicode=%d)!\n", wParam, fUnicode);
2871 nAddButtons = (UINT)wParam;
2872 nOldButtons = infoPtr->nNumButtons;
2873 nNewButtons = nOldButtons + nAddButtons;
2875 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
2876 infoPtr->nNumButtons = nNewButtons;
2878 /* insert new button data */
2879 for (nCount = 0; nCount < nAddButtons; nCount++) {
2880 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2881 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2882 btnPtr->idCommand = lpTbb[nCount].idCommand;
2883 btnPtr->fsState = lpTbb[nCount].fsState;
2884 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2885 btnPtr->dwData = lpTbb[nCount].dwData;
2886 btnPtr->bHot = FALSE;
2887 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2889 if (fUnicode)
2890 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2891 else
2892 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString);
2894 else
2895 btnPtr->iString = lpTbb[nCount].iString;
2897 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
2900 TOOLBAR_CalcToolbar (hwnd);
2901 TOOLBAR_AutoSize (hwnd);
2903 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2905 InvalidateRect(hwnd, NULL, TRUE);
2907 return TRUE;
2911 static LRESULT
2912 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2914 #define MAX_RESOURCE_STRING_LENGTH 512
2915 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2916 INT nIndex = infoPtr->nNumStrings;
2918 if ((wParam) && (HIWORD(lParam) == 0)) {
2919 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2920 WCHAR delimiter;
2921 WCHAR *next_delim;
2922 WCHAR *p;
2923 INT len;
2924 TRACE("adding string from resource!\n");
2926 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2927 szString, MAX_RESOURCE_STRING_LENGTH);
2929 TRACE("len=%d %s\n", len, debugstr_w(szString));
2930 if (len == 0 || len == 1)
2931 return nIndex;
2933 TRACE("Delimiter: 0x%x\n", *szString);
2934 delimiter = *szString;
2935 p = szString + 1;
2937 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2938 *next_delim = 0;
2939 if (next_delim + 1 >= szString + len)
2941 /* this may happen if delimiter == '\0' or if the last char is a
2942 * delimiter (then it is ignored like the native does) */
2943 break;
2946 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2947 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2948 infoPtr->nNumStrings++;
2950 p = next_delim + 1;
2953 else {
2954 LPWSTR p = (LPWSTR)lParam;
2955 INT len;
2957 if (p == NULL)
2958 return -1;
2959 TRACE("adding string(s) from array!\n");
2960 while (*p) {
2961 len = strlenW (p);
2963 TRACE("len=%d %s\n", len, debugstr_w(p));
2964 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2965 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2966 infoPtr->nNumStrings++;
2968 p += (len+1);
2972 return nIndex;
2976 static LRESULT
2977 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2979 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2980 LPSTR p;
2981 INT nIndex;
2982 INT len;
2984 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
2985 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
2987 p = (LPSTR)lParam;
2988 if (p == NULL)
2989 return -1;
2991 TRACE("adding string(s) from array!\n");
2992 nIndex = infoPtr->nNumStrings;
2993 while (*p) {
2994 len = strlen (p);
2995 TRACE("len=%d \"%s\"\n", len, p);
2997 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2998 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
2999 infoPtr->nNumStrings++;
3001 p += (len+1);
3004 return nIndex;
3008 static LRESULT
3009 TOOLBAR_AutoSize (HWND hwnd)
3011 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3012 RECT parent_rect;
3013 HWND parent;
3014 INT x, y;
3015 INT cx, cy;
3017 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3019 parent = GetParent (hwnd);
3021 if (!parent || !infoPtr->bDoRedraw)
3022 return 0;
3024 GetClientRect(parent, &parent_rect);
3026 x = parent_rect.left;
3027 y = parent_rect.top;
3029 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3031 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3032 cx = parent_rect.right - parent_rect.left;
3034 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3036 TOOLBAR_CalcToolbar(hwnd);
3037 InvalidateRect( hwnd, NULL, TRUE );
3040 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3042 RECT window_rect;
3043 UINT uPosFlags = SWP_NOZORDER;
3045 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3047 GetWindowRect(hwnd, &window_rect);
3048 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3049 y = window_rect.top;
3051 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3053 GetWindowRect(hwnd, &window_rect);
3054 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3057 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3058 uPosFlags |= SWP_NOMOVE;
3060 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3061 cy += GetSystemMetrics(SM_CYEDGE);
3063 if (infoPtr->dwStyle & WS_BORDER)
3065 x = y = 1; /* FIXME: this looks wrong */
3066 cy += GetSystemMetrics(SM_CYEDGE);
3067 cx += GetSystemMetrics(SM_CXEDGE);
3070 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3073 return 0;
3077 static LRESULT
3078 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3080 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3082 return infoPtr->nNumButtons;
3086 static LRESULT
3087 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3089 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3091 infoPtr->dwStructSize = (DWORD)wParam;
3093 return 0;
3097 static LRESULT
3098 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3100 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3101 TBUTTON_INFO *btnPtr;
3102 INT nIndex;
3104 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3106 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3107 if (nIndex == -1)
3108 return FALSE;
3110 btnPtr = &infoPtr->buttons[nIndex];
3111 btnPtr->iBitmap = LOWORD(lParam);
3113 /* we HAVE to erase the background, the new bitmap could be */
3114 /* transparent */
3115 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3117 return TRUE;
3121 static LRESULT
3122 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3124 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3125 TBUTTON_INFO *btnPtr;
3126 INT nIndex;
3127 INT nOldIndex = -1;
3128 BOOL bChecked = FALSE;
3130 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3132 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3134 if (nIndex == -1)
3135 return FALSE;
3137 btnPtr = &infoPtr->buttons[nIndex];
3139 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3141 if (LOWORD(lParam) == FALSE)
3142 btnPtr->fsState &= ~TBSTATE_CHECKED;
3143 else {
3144 if (btnPtr->fsStyle & BTNS_GROUP) {
3145 nOldIndex =
3146 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3147 if (nOldIndex == nIndex)
3148 return 0;
3149 if (nOldIndex != -1)
3150 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3152 btnPtr->fsState |= TBSTATE_CHECKED;
3155 if( bChecked != LOWORD(lParam) )
3157 if (nOldIndex != -1)
3158 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3159 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3162 /* FIXME: Send a WM_NOTIFY?? */
3164 return TRUE;
3168 static LRESULT
3169 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3171 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3173 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3177 static LRESULT
3178 TOOLBAR_Customize (HWND hwnd)
3180 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3181 CUSTDLG_INFO custInfo;
3182 LRESULT ret;
3183 LPCVOID template;
3184 HRSRC hRes;
3185 NMHDR nmhdr;
3187 custInfo.tbInfo = infoPtr;
3188 custInfo.tbHwnd = hwnd;
3190 /* send TBN_BEGINADJUST notification */
3191 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3193 if (!(hRes = FindResourceW (COMCTL32_hModule,
3194 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3195 (LPWSTR)RT_DIALOG)))
3196 return FALSE;
3198 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3199 return FALSE;
3201 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3202 (LPCDLGTEMPLATEW)template,
3203 hwnd,
3204 TOOLBAR_CustomizeDialogProc,
3205 (LPARAM)&custInfo);
3207 /* send TBN_ENDADJUST notification */
3208 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3210 return ret;
3214 static LRESULT
3215 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3217 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3218 INT nIndex = (INT)wParam;
3219 NMTOOLBARW nmtb;
3220 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3222 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3223 return FALSE;
3225 memset(&nmtb, 0, sizeof(nmtb));
3226 nmtb.iItem = btnPtr->idCommand;
3227 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3228 nmtb.tbButton.idCommand = btnPtr->idCommand;
3229 nmtb.tbButton.fsState = btnPtr->fsState;
3230 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3231 nmtb.tbButton.dwData = btnPtr->dwData;
3232 nmtb.tbButton.iString = btnPtr->iString;
3233 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3235 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3237 if (infoPtr->nNumButtons == 1) {
3238 TRACE(" simple delete!\n");
3239 Free (infoPtr->buttons);
3240 infoPtr->buttons = NULL;
3241 infoPtr->nNumButtons = 0;
3243 else {
3244 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3245 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3247 infoPtr->nNumButtons--;
3248 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3249 if (nIndex > 0) {
3250 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3251 nIndex * sizeof(TBUTTON_INFO));
3254 if (nIndex < infoPtr->nNumButtons) {
3255 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3256 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3259 Free (oldButtons);
3262 TOOLBAR_CalcToolbar (hwnd);
3264 InvalidateRect (hwnd, NULL, TRUE);
3266 return TRUE;
3270 static LRESULT
3271 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3273 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3274 TBUTTON_INFO *btnPtr;
3275 INT nIndex;
3276 DWORD bState;
3278 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3280 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3282 if (nIndex == -1)
3283 return FALSE;
3285 btnPtr = &infoPtr->buttons[nIndex];
3287 bState = btnPtr->fsState & TBSTATE_ENABLED;
3289 /* update the toolbar button state */
3290 if(LOWORD(lParam) == FALSE) {
3291 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3292 } else {
3293 btnPtr->fsState |= TBSTATE_ENABLED;
3296 /* redraw the button only if the state of the button changed */
3297 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3298 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3300 return TRUE;
3304 static inline LRESULT
3305 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3307 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3309 return infoPtr->bAnchor;
3313 static LRESULT
3314 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3316 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3317 INT nIndex;
3319 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3320 if (nIndex == -1)
3321 return -1;
3323 return infoPtr->buttons[nIndex].iBitmap;
3327 static inline LRESULT
3328 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3330 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3334 static LRESULT
3335 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3337 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3338 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3339 INT nIndex = (INT)wParam;
3340 TBUTTON_INFO *btnPtr;
3342 if (lpTbb == NULL)
3343 return FALSE;
3345 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3346 return FALSE;
3348 btnPtr = &infoPtr->buttons[nIndex];
3349 lpTbb->iBitmap = btnPtr->iBitmap;
3350 lpTbb->idCommand = btnPtr->idCommand;
3351 lpTbb->fsState = btnPtr->fsState;
3352 lpTbb->fsStyle = btnPtr->fsStyle;
3353 lpTbb->bReserved[0] = 0;
3354 lpTbb->bReserved[1] = 0;
3355 lpTbb->dwData = btnPtr->dwData;
3356 lpTbb->iString = btnPtr->iString;
3358 return TRUE;
3362 static LRESULT
3363 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3365 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3366 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3367 TBUTTON_INFO *btnPtr;
3368 INT nIndex;
3370 if (lpTbInfo == NULL)
3371 return -1;
3372 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3373 return -1;
3375 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3376 lpTbInfo->dwMask & 0x80000000);
3377 if (nIndex == -1)
3378 return -1;
3380 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3382 if (lpTbInfo->dwMask & TBIF_COMMAND)
3383 lpTbInfo->idCommand = btnPtr->idCommand;
3384 if (lpTbInfo->dwMask & TBIF_IMAGE)
3385 lpTbInfo->iImage = btnPtr->iBitmap;
3386 if (lpTbInfo->dwMask & TBIF_LPARAM)
3387 lpTbInfo->lParam = btnPtr->dwData;
3388 if (lpTbInfo->dwMask & TBIF_SIZE)
3389 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3390 if (lpTbInfo->dwMask & TBIF_STATE)
3391 lpTbInfo->fsState = btnPtr->fsState;
3392 if (lpTbInfo->dwMask & TBIF_STYLE)
3393 lpTbInfo->fsStyle = btnPtr->fsStyle;
3394 if (lpTbInfo->dwMask & TBIF_TEXT) {
3395 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3396 can't use TOOLBAR_GetText here */
3397 LPWSTR lpText;
3398 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3399 lpText = (LPWSTR)btnPtr->iString;
3400 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3401 } else
3402 lpTbInfo->pszText[0] = '\0';
3404 return nIndex;
3408 static LRESULT
3409 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3411 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3412 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3413 TBUTTON_INFO *btnPtr;
3414 INT nIndex;
3416 if (lpTbInfo == NULL)
3417 return -1;
3418 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3419 return -1;
3421 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3422 lpTbInfo->dwMask & 0x80000000);
3423 if (nIndex == -1)
3424 return -1;
3426 btnPtr = &infoPtr->buttons[nIndex];
3428 if(!btnPtr)
3429 return -1;
3431 if (lpTbInfo->dwMask & TBIF_COMMAND)
3432 lpTbInfo->idCommand = btnPtr->idCommand;
3433 if (lpTbInfo->dwMask & TBIF_IMAGE)
3434 lpTbInfo->iImage = btnPtr->iBitmap;
3435 if (lpTbInfo->dwMask & TBIF_LPARAM)
3436 lpTbInfo->lParam = btnPtr->dwData;
3437 if (lpTbInfo->dwMask & TBIF_SIZE)
3438 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3439 if (lpTbInfo->dwMask & TBIF_STATE)
3440 lpTbInfo->fsState = btnPtr->fsState;
3441 if (lpTbInfo->dwMask & TBIF_STYLE)
3442 lpTbInfo->fsStyle = btnPtr->fsStyle;
3443 if (lpTbInfo->dwMask & TBIF_TEXT) {
3444 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3445 can't use TOOLBAR_GetText here */
3446 LPWSTR lpText;
3447 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3448 lpText = (LPWSTR)btnPtr->iString;
3449 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3450 } else
3451 lpTbInfo->pszText[0] = '\0';
3454 return nIndex;
3458 static LRESULT
3459 TOOLBAR_GetButtonSize (HWND hwnd)
3461 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3463 if (infoPtr->nNumButtons > 0)
3464 return MAKELONG((WORD)infoPtr->nButtonWidth,
3465 (WORD)infoPtr->nButtonHeight);
3466 else
3467 return MAKELONG(23,22);
3471 static LRESULT
3472 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3474 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3475 INT nIndex;
3476 LPWSTR lpText;
3478 if (lParam == 0)
3479 return -1;
3481 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3482 if (nIndex == -1)
3483 return -1;
3485 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3487 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3488 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3492 static LRESULT
3493 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3495 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3496 INT nIndex;
3497 LPWSTR lpText;
3498 LRESULT ret = 0;
3500 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3501 if (nIndex == -1)
3502 return -1;
3504 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3506 if (lpText)
3508 ret = strlenW (lpText);
3510 if (lParam)
3511 strcpyW ((LPWSTR)lParam, lpText);
3514 return ret;
3518 static LRESULT
3519 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3521 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3522 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3523 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3527 inline static LRESULT
3528 TOOLBAR_GetExtendedStyle (HWND hwnd)
3530 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3532 TRACE("\n");
3534 return infoPtr->dwExStyle;
3538 static LRESULT
3539 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3541 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3542 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3543 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3547 static LRESULT
3548 TOOLBAR_GetHotItem (HWND hwnd)
3550 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3552 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3553 return -1;
3555 if (infoPtr->nHotItem < 0)
3556 return -1;
3558 return (LRESULT)infoPtr->nHotItem;
3562 static LRESULT
3563 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3565 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3566 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3567 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3571 static LRESULT
3572 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3574 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3575 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3577 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3579 *lptbim = infoPtr->tbim;
3581 return 0;
3585 static LRESULT
3586 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3588 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3590 TRACE("hwnd = %p\n", hwnd);
3592 return (LRESULT)infoPtr->clrInsertMark;
3596 static LRESULT
3597 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3599 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3600 TBUTTON_INFO *btnPtr;
3601 LPRECT lpRect;
3602 INT nIndex;
3604 nIndex = (INT)wParam;
3605 btnPtr = &infoPtr->buttons[nIndex];
3606 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3607 return FALSE;
3608 lpRect = (LPRECT)lParam;
3609 if (lpRect == NULL)
3610 return FALSE;
3611 if (btnPtr->fsState & TBSTATE_HIDDEN)
3612 return FALSE;
3614 lpRect->left = btnPtr->rect.left;
3615 lpRect->right = btnPtr->rect.right;
3616 lpRect->bottom = btnPtr->rect.bottom;
3617 lpRect->top = btnPtr->rect.top;
3619 return TRUE;
3623 static LRESULT
3624 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3626 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3627 LPSIZE lpSize = (LPSIZE)lParam;
3629 if (lpSize == NULL)
3630 return FALSE;
3632 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3633 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3635 TRACE("maximum size %d x %d\n",
3636 infoPtr->rcBound.right - infoPtr->rcBound.left,
3637 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3639 return TRUE;
3643 /* << TOOLBAR_GetObject >> */
3646 static LRESULT
3647 TOOLBAR_GetPadding (HWND hwnd)
3649 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3650 DWORD oldPad;
3652 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3653 return (LRESULT) oldPad;
3657 static LRESULT
3658 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3660 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3661 TBUTTON_INFO *btnPtr;
3662 LPRECT lpRect;
3663 INT nIndex;
3665 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3666 btnPtr = &infoPtr->buttons[nIndex];
3667 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3668 return FALSE;
3669 lpRect = (LPRECT)lParam;
3670 if (lpRect == NULL)
3671 return FALSE;
3673 lpRect->left = btnPtr->rect.left;
3674 lpRect->right = btnPtr->rect.right;
3675 lpRect->bottom = btnPtr->rect.bottom;
3676 lpRect->top = btnPtr->rect.top;
3678 return TRUE;
3682 static LRESULT
3683 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3685 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3687 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3688 return infoPtr->nRows;
3689 else
3690 return 1;
3694 static LRESULT
3695 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3697 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3698 INT nIndex;
3700 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3701 if (nIndex == -1)
3702 return -1;
3704 return infoPtr->buttons[nIndex].fsState;
3708 static LRESULT
3709 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3711 return GetWindowLongW(hwnd, GWL_STYLE);
3715 static LRESULT
3716 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3718 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3720 return infoPtr->nMaxTextRows;
3724 static LRESULT
3725 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3727 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3729 return (LRESULT)infoPtr->hwndToolTip;
3733 static LRESULT
3734 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3736 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3738 TRACE("%s hwnd=%p\n",
3739 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3741 return infoPtr->bUnicode;
3745 inline static LRESULT
3746 TOOLBAR_GetVersion (HWND hwnd)
3748 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3749 return infoPtr->iVersion;
3753 static LRESULT
3754 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3756 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3757 TBUTTON_INFO *btnPtr;
3758 INT nIndex;
3760 TRACE("\n");
3762 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3763 if (nIndex == -1)
3764 return FALSE;
3766 btnPtr = &infoPtr->buttons[nIndex];
3767 if (LOWORD(lParam) == FALSE)
3768 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3769 else
3770 btnPtr->fsState |= TBSTATE_HIDDEN;
3772 TOOLBAR_CalcToolbar (hwnd);
3774 InvalidateRect (hwnd, NULL, TRUE);
3776 return TRUE;
3780 inline static LRESULT
3781 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3783 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3787 static LRESULT
3788 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3790 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3791 TBUTTON_INFO *btnPtr;
3792 INT nIndex;
3793 DWORD oldState;
3795 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3796 if (nIndex == -1)
3797 return FALSE;
3799 btnPtr = &infoPtr->buttons[nIndex];
3800 oldState = btnPtr->fsState;
3801 if (LOWORD(lParam) == FALSE)
3802 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3803 else
3804 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3806 if(oldState != btnPtr->fsState)
3807 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3809 return TRUE;
3813 static LRESULT
3814 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3816 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3817 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3818 INT nIndex = (INT)wParam;
3820 if (lpTbb == NULL)
3821 return FALSE;
3823 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3825 if (nIndex == -1) {
3826 /* EPP: this seems to be an undocumented call (from my IE4)
3827 * I assume in that case that:
3828 * - index of insertion is at the end of existing buttons
3829 * I only see this happen with nIndex == -1, but it could have a special
3830 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3832 nIndex = infoPtr->nNumButtons;
3834 } else if (nIndex < 0)
3835 return FALSE;
3837 TRACE("inserting button index=%d\n", nIndex);
3838 if (nIndex > infoPtr->nNumButtons) {
3839 nIndex = infoPtr->nNumButtons;
3840 TRACE("adjust index=%d\n", nIndex);
3843 infoPtr->nNumButtons++;
3844 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO) * infoPtr->nNumButtons);
3845 memmove(&infoPtr->buttons[nIndex+1], &infoPtr->buttons[nIndex],
3846 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3848 /* insert new button */
3849 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3850 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3851 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3852 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3853 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3854 /* if passed string and not index, then add string */
3855 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3856 if (fUnicode)
3857 Str_SetPtrW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3858 else
3859 Str_SetPtrAtoW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3861 else
3862 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3864 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
3866 TOOLBAR_CalcToolbar (hwnd);
3867 TOOLBAR_AutoSize (hwnd);
3869 InvalidateRect (hwnd, NULL, TRUE);
3871 return TRUE;
3874 /* << TOOLBAR_InsertMarkHitTest >> */
3877 static LRESULT
3878 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3880 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3881 INT nIndex;
3883 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3884 if (nIndex == -1)
3885 return FALSE;
3887 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3891 static LRESULT
3892 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3894 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3895 INT nIndex;
3897 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3898 if (nIndex == -1)
3899 return FALSE;
3901 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3905 static LRESULT
3906 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3908 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3909 INT nIndex;
3911 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3912 if (nIndex == -1)
3913 return TRUE;
3915 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3919 static LRESULT
3920 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3922 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3923 INT nIndex;
3925 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3926 if (nIndex == -1)
3927 return FALSE;
3929 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3933 static LRESULT
3934 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3936 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3937 INT nIndex;
3939 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3940 if (nIndex == -1)
3941 return FALSE;
3943 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3947 static LRESULT
3948 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3950 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3951 INT nIndex;
3953 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3954 if (nIndex == -1)
3955 return FALSE;
3957 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3961 static LRESULT
3962 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3964 TBADDBITMAP tbab;
3965 tbab.hInst = (HINSTANCE)lParam;
3966 tbab.nID = (UINT_PTR)wParam;
3968 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3970 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3974 static LRESULT
3975 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3977 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3978 WCHAR wAccel = (WCHAR)wParam;
3979 UINT* pIDButton = (UINT*)lParam;
3980 WCHAR wszAccel[] = {'&',wAccel,0};
3981 int i;
3983 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3984 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3986 for (i = 0; i < infoPtr->nNumButtons; i++)
3988 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3989 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3990 !(btnPtr->fsState & TBSTATE_HIDDEN))
3992 int iLen = strlenW(wszAccel);
3993 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3995 if (!lpszStr)
3996 continue;
3998 while (*lpszStr)
4000 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4002 lpszStr += 2;
4003 continue;
4005 if (!strncmpiW(lpszStr, wszAccel, iLen))
4007 *pIDButton = btnPtr->idCommand;
4008 return TRUE;
4010 lpszStr++;
4014 return FALSE;
4018 static LRESULT
4019 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4021 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4022 INT nIndex;
4023 DWORD oldState;
4024 TBUTTON_INFO *btnPtr;
4026 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4028 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4029 if (nIndex == -1)
4030 return FALSE;
4032 btnPtr = &infoPtr->buttons[nIndex];
4033 oldState = btnPtr->fsState;
4035 if (LOWORD(lParam))
4036 btnPtr->fsState |= TBSTATE_MARKED;
4037 else
4038 btnPtr->fsState &= ~TBSTATE_MARKED;
4040 if(oldState != btnPtr->fsState)
4041 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4043 return TRUE;
4047 /* fixes up an index of a button affected by a move */
4048 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4050 if (bMoveUp)
4052 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4053 (*pIndex)--;
4054 else if (*pIndex == nIndex)
4055 *pIndex = nMoveIndex;
4057 else
4059 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4060 (*pIndex)++;
4061 else if (*pIndex == nIndex)
4062 *pIndex = nMoveIndex;
4067 static LRESULT
4068 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4070 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4071 INT nIndex;
4072 INT nCount;
4073 INT nMoveIndex = (INT)lParam;
4074 TBUTTON_INFO button;
4076 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4078 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4079 if ((nIndex == -1) || (nMoveIndex < 0))
4080 return FALSE;
4082 if (nMoveIndex > infoPtr->nNumButtons - 1)
4083 nMoveIndex = infoPtr->nNumButtons - 1;
4085 button = infoPtr->buttons[nIndex];
4087 /* move button right */
4088 if (nIndex < nMoveIndex)
4090 nCount = nMoveIndex - nIndex;
4091 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4092 infoPtr->buttons[nMoveIndex] = button;
4094 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4095 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4096 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4097 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4099 else if (nIndex > nMoveIndex) /* move button left */
4101 nCount = nIndex - nMoveIndex;
4102 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4103 infoPtr->buttons[nMoveIndex] = button;
4105 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4106 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4107 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4108 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4111 TOOLBAR_CalcToolbar(hwnd);
4112 TOOLBAR_AutoSize(hwnd);
4113 InvalidateRect(hwnd, NULL, TRUE);
4115 return TRUE;
4119 static LRESULT
4120 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4122 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4123 TBUTTON_INFO *btnPtr;
4124 INT nIndex;
4125 DWORD oldState;
4127 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4128 if (nIndex == -1)
4129 return FALSE;
4131 btnPtr = &infoPtr->buttons[nIndex];
4132 oldState = btnPtr->fsState;
4133 if (LOWORD(lParam) == FALSE)
4134 btnPtr->fsState &= ~TBSTATE_PRESSED;
4135 else
4136 btnPtr->fsState |= TBSTATE_PRESSED;
4138 if(oldState != btnPtr->fsState)
4139 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4141 return TRUE;
4144 /* FIXME: there might still be some confusion her between number of buttons
4145 * and number of bitmaps */
4146 static LRESULT
4147 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4149 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4150 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4151 HBITMAP hBitmap;
4152 HBITMAP hbmLoad = NULL;
4153 int i = 0, nOldButtons = 0, pos = 0;
4154 int nOldBitmaps, nNewBitmaps = 0;
4155 HIMAGELIST himlDef = 0;
4157 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4158 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4159 lpReplace->nButtons);
4161 if (lpReplace->hInstOld == HINST_COMMCTRL)
4163 FIXME("changing standard bitmaps not implemented\n");
4164 return FALSE;
4166 else if (lpReplace->hInstOld != 0)
4167 FIXME("resources not in the current module not implemented\n");
4169 if (lpReplace->hInstNew)
4171 hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4172 hBitmap = hbmLoad;
4174 else
4176 hBitmap = (HBITMAP) lpReplace->nIDNew;
4179 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4180 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4181 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4182 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4183 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4185 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4186 nOldButtons = tbi->nButtons;
4187 tbi->nButtons = lpReplace->nButtons;
4188 tbi->hInst = lpReplace->hInstNew;
4189 tbi->nID = lpReplace->nIDNew;
4190 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4191 break;
4193 pos += tbi->nButtons;
4196 if (nOldButtons == 0)
4198 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4199 if (hbmLoad)
4200 DeleteObject (hbmLoad);
4201 return FALSE;
4204 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4205 nOldBitmaps = ImageList_GetImageCount(himlDef);
4207 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4209 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4210 ImageList_Remove(himlDef, i);
4212 if (hBitmap)
4214 BITMAP bmp;
4215 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4216 HDC hdcImage, hdcBitmap;
4218 /* copy the bitmap before adding it so that the user's bitmap
4219 * doesn't get modified.
4221 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4223 hdcImage = CreateCompatibleDC(0);
4224 hdcBitmap = CreateCompatibleDC(0);
4226 /* create new bitmap */
4227 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4228 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4229 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4231 /* Copy the user's image */
4232 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4233 hdcBitmap, 0, 0, SRCCOPY);
4235 SelectObject (hdcImage, hOldBitmapLoad);
4236 SelectObject (hdcBitmap, hOldBitmapBitmap);
4237 DeleteDC (hdcImage);
4238 DeleteDC (hdcBitmap);
4240 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4241 nNewBitmaps = ImageList_GetImageCount(himlDef);
4242 DeleteObject (hbmLoad);
4245 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4247 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4248 pos, nOldBitmaps, nNewBitmaps);
4250 InvalidateRect(hwnd, NULL, TRUE);
4252 if (hbmLoad)
4253 DeleteObject (hbmLoad);
4254 return TRUE;
4258 /* helper for TOOLBAR_SaveRestoreW */
4259 static BOOL
4260 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4262 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4263 debugstr_w(lpSave->pszValueName));
4265 return FALSE;
4269 /* helper for TOOLBAR_Restore */
4270 static void
4271 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4273 INT i;
4275 for (i = 0; i < infoPtr->nNumButtons; i++)
4277 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4280 Free(infoPtr->buttons);
4281 infoPtr->buttons = NULL;
4282 infoPtr->nNumButtons = 0;
4286 /* helper for TOOLBAR_SaveRestoreW */
4287 static BOOL
4288 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4290 LONG res;
4291 HKEY hkey = NULL;
4292 BOOL ret = FALSE;
4293 DWORD dwType;
4294 DWORD dwSize = 0;
4295 NMTBRESTORE nmtbr;
4297 /* restore toolbar information */
4298 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4299 debugstr_w(lpSave->pszValueName));
4301 memset(&nmtbr, 0, sizeof(nmtbr));
4303 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4304 KEY_QUERY_VALUE, &hkey);
4305 if (!res)
4306 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4307 NULL, &dwSize);
4308 if (!res && dwType != REG_BINARY)
4309 res = ERROR_FILE_NOT_FOUND;
4310 if (!res)
4312 nmtbr.pData = Alloc(dwSize);
4313 nmtbr.cbData = (UINT)dwSize;
4314 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4316 if (!res)
4317 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4318 (LPBYTE)nmtbr.pData, &dwSize);
4319 if (!res)
4321 nmtbr.pCurrent = nmtbr.pData;
4322 nmtbr.iItem = -1;
4323 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4324 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4326 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4328 INT i;
4330 /* remove all existing buttons as this function is designed to
4331 * restore the toolbar to a previously saved state */
4332 TOOLBAR_DeleteAllButtons(infoPtr);
4334 for (i = 0; i < nmtbr.cButtons; i++)
4336 nmtbr.iItem = i;
4337 nmtbr.tbButton.iBitmap = -1;
4338 nmtbr.tbButton.fsState = 0;
4339 nmtbr.tbButton.fsStyle = 0;
4340 nmtbr.tbButton.idCommand = 0;
4341 if (*nmtbr.pCurrent == (DWORD)-1)
4343 /* separator */
4344 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4345 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4347 else if (*nmtbr.pCurrent == (DWORD)-2)
4348 /* hidden button */
4349 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4350 else
4351 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4353 nmtbr.pCurrent++;
4355 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4357 /* can't contain real string as we don't know whether
4358 * the client put an ANSI or Unicode string in there */
4359 if (HIWORD(nmtbr.tbButton.iString))
4360 nmtbr.tbButton.iString = 0;
4362 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4363 (LPARAM)&nmtbr.tbButton, TRUE);
4366 /* do legacy notifications */
4367 if (infoPtr->iVersion < 5)
4369 /* FIXME: send TBN_BEGINADJUST */
4370 FIXME("send TBN_GETBUTTONINFO for each button\n");
4371 /* FIXME: send TBN_ENDADJUST */
4374 /* remove all uninitialised buttons
4375 * note: loop backwards to avoid having to fixup i on a
4376 * delete */
4377 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4378 if (infoPtr->buttons[i].iBitmap == -1)
4379 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4381 /* only indicate success if at least one button survived */
4382 if (infoPtr->nNumButtons > 0) ret = TRUE;
4385 Free (nmtbr.pData);
4386 RegCloseKey(hkey);
4388 return ret;
4392 static LRESULT
4393 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4395 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4397 if (lpSave == NULL) return 0;
4399 if (wParam)
4400 return TOOLBAR_Save(infoPtr, lpSave);
4401 else
4402 return TOOLBAR_Restore(infoPtr, lpSave);
4406 static LRESULT
4407 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4409 LPWSTR pszValueName = 0, pszSubKey = 0;
4410 TBSAVEPARAMSW SaveW;
4411 LRESULT result = 0;
4412 int len;
4414 if (lpSave == NULL) return 0;
4416 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4417 pszSubKey = Alloc(len * sizeof(WCHAR));
4418 if (pszSubKey) goto exit;
4419 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4421 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4422 pszValueName = Alloc(len * sizeof(WCHAR));
4423 if (!pszValueName) goto exit;
4424 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4426 SaveW.pszValueName = pszValueName;
4427 SaveW.pszSubKey = pszSubKey;
4428 SaveW.hkr = lpSave->hkr;
4429 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4431 exit:
4432 Free (pszValueName);
4433 Free (pszSubKey);
4435 return result;
4439 static LRESULT
4440 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4442 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4443 BOOL bOldAnchor = infoPtr->bAnchor;
4445 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4447 infoPtr->bAnchor = (BOOL)wParam;
4449 /* Native does not remove the hot effect from an already hot button */
4451 return (LRESULT)bOldAnchor;
4455 static LRESULT
4456 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4458 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4459 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4461 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4463 if (wParam != 0)
4464 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4466 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4467 lParam = MAKELPARAM(16, 15);
4469 if (infoPtr->nNumButtons > 0)
4470 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4471 infoPtr->nNumButtons,
4472 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4473 LOWORD(lParam), HIWORD(lParam));
4475 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4476 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4479 if ((himlDef == infoPtr->himlInt) &&
4480 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4482 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4483 infoPtr->nBitmapHeight);
4486 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4487 return TRUE;
4491 static LRESULT
4492 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4494 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4495 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4496 TBUTTON_INFO *btnPtr;
4497 INT nIndex;
4498 RECT oldBtnRect;
4500 if (lptbbi == NULL)
4501 return FALSE;
4502 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4503 return FALSE;
4505 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4506 lptbbi->dwMask & 0x80000000);
4507 if (nIndex == -1)
4508 return FALSE;
4510 btnPtr = &infoPtr->buttons[nIndex];
4511 if (lptbbi->dwMask & TBIF_COMMAND)
4512 btnPtr->idCommand = lptbbi->idCommand;
4513 if (lptbbi->dwMask & TBIF_IMAGE)
4514 btnPtr->iBitmap = lptbbi->iImage;
4515 if (lptbbi->dwMask & TBIF_LPARAM)
4516 btnPtr->dwData = lptbbi->lParam;
4517 if (lptbbi->dwMask & TBIF_SIZE)
4518 btnPtr->cx = lptbbi->cx;
4519 if (lptbbi->dwMask & TBIF_STATE)
4520 btnPtr->fsState = lptbbi->fsState;
4521 if (lptbbi->dwMask & TBIF_STYLE)
4522 btnPtr->fsStyle = lptbbi->fsStyle;
4524 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4525 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4526 /* iString is index, zero it to make Str_SetPtr succeed */
4527 btnPtr->iString=0;
4529 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4532 /* save the button rect to see if we need to redraw the whole toolbar */
4533 oldBtnRect = btnPtr->rect;
4534 TOOLBAR_CalcToolbar(hwnd);
4536 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4537 InvalidateRect(hwnd, NULL, TRUE);
4538 else
4539 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4541 return TRUE;
4545 static LRESULT
4546 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4548 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4549 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4550 TBUTTON_INFO *btnPtr;
4551 INT nIndex;
4552 RECT oldBtnRect;
4554 if (lptbbi == NULL)
4555 return FALSE;
4556 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4557 return FALSE;
4559 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4560 lptbbi->dwMask & 0x80000000);
4561 if (nIndex == -1)
4562 return FALSE;
4564 btnPtr = &infoPtr->buttons[nIndex];
4565 if (lptbbi->dwMask & TBIF_COMMAND)
4566 btnPtr->idCommand = lptbbi->idCommand;
4567 if (lptbbi->dwMask & TBIF_IMAGE)
4568 btnPtr->iBitmap = lptbbi->iImage;
4569 if (lptbbi->dwMask & TBIF_LPARAM)
4570 btnPtr->dwData = lptbbi->lParam;
4571 if (lptbbi->dwMask & TBIF_SIZE)
4572 btnPtr->cx = lptbbi->cx;
4573 if (lptbbi->dwMask & TBIF_STATE)
4574 btnPtr->fsState = lptbbi->fsState;
4575 if (lptbbi->dwMask & TBIF_STYLE)
4576 btnPtr->fsStyle = lptbbi->fsStyle;
4578 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4579 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4580 /* iString is index, zero it to make Str_SetPtr succeed */
4581 btnPtr->iString=0;
4582 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4585 /* save the button rect to see if we need to redraw the whole toolbar */
4586 oldBtnRect = btnPtr->rect;
4587 TOOLBAR_CalcToolbar(hwnd);
4589 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4590 InvalidateRect(hwnd, NULL, TRUE);
4591 else
4592 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4594 return TRUE;
4598 static LRESULT
4599 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4601 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4602 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4604 if ((cx < 0) || (cy < 0))
4606 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4607 return FALSE;
4610 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4612 /* The documentation claims you can only change the button size before
4613 * any button has been added. But this is wrong.
4614 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4615 * it to the toolbar, and it checks that the return value is nonzero - mjm
4616 * Further testing shows that we must actually perform the change too.
4619 * The documentation also does not mention that if 0 is supplied for
4620 * either size, the system changes it to the default of 24 wide and
4621 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4623 infoPtr->nButtonWidth = (cx) ? cx : 24;
4624 infoPtr->nButtonHeight = (cy) ? cy : 22;
4625 return TRUE;
4629 static LRESULT
4630 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4632 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4634 /* if setting to current values, ignore */
4635 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4636 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4637 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4638 infoPtr->cxMin, infoPtr->cxMax);
4639 return TRUE;
4642 /* save new values */
4643 infoPtr->cxMin = (INT)LOWORD(lParam);
4644 infoPtr->cxMax = (INT)HIWORD(lParam);
4646 /* otherwise we need to recalc the toolbar and in some cases
4647 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4648 which doesn't actually draw - GA). */
4649 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4650 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4652 TOOLBAR_CalcToolbar (hwnd);
4654 InvalidateRect (hwnd, NULL, TRUE);
4656 return TRUE;
4660 static LRESULT
4661 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4663 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4664 INT nIndex = (INT)wParam;
4666 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4667 return FALSE;
4669 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4671 if (infoPtr->hwndToolTip) {
4673 FIXME("change tool tip!\n");
4677 return TRUE;
4681 static LRESULT
4682 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4684 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4685 HIMAGELIST himl = (HIMAGELIST)lParam;
4686 HIMAGELIST himlTemp;
4687 INT id = 0;
4689 if (infoPtr->iVersion >= 5)
4690 id = wParam;
4692 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4693 &infoPtr->cimlDis, himl, id);
4695 /* FIXME: redraw ? */
4697 return (LRESULT)himlTemp;
4701 static LRESULT
4702 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4704 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4705 DWORD dwTemp;
4707 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4709 dwTemp = infoPtr->dwDTFlags;
4710 infoPtr->dwDTFlags =
4711 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4713 return (LRESULT)dwTemp;
4716 /* This function differs a bit from what MSDN says it does:
4717 * 1. lParam contains extended style flags to OR with current style
4718 * (MSDN isn't clear on the OR bit)
4719 * 2. wParam appears to contain extended style flags to be reset
4720 * (MSDN says that this parameter is reserved)
4722 static LRESULT
4723 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4725 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4726 DWORD dwTemp;
4728 dwTemp = infoPtr->dwExStyle;
4729 infoPtr->dwExStyle &= ~wParam;
4730 infoPtr->dwExStyle |= (DWORD)lParam;
4732 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4734 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4735 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4736 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4738 TOOLBAR_CalcToolbar (hwnd);
4740 TOOLBAR_AutoSize(hwnd);
4742 InvalidateRect(hwnd, NULL, TRUE);
4744 return (LRESULT)dwTemp;
4748 static LRESULT
4749 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4751 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4752 HIMAGELIST himlTemp;
4753 HIMAGELIST himl = (HIMAGELIST)lParam;
4754 INT id = 0;
4756 if (infoPtr->iVersion >= 5)
4757 id = wParam;
4759 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4761 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4762 &infoPtr->cimlHot, himl, id);
4764 /* FIXME: redraw ? */
4766 return (LRESULT)himlTemp;
4770 /* Makes previous hot button no longer hot, makes the specified
4771 * button hot and sends appropriate notifications. dwReason is one or
4772 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4773 * NOTE 1: this function does not validate nHit
4774 * NOTE 2: the name of this function is completely made up and
4775 * not based on any documentation from Microsoft. */
4776 static void
4777 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4779 if (infoPtr->nHotItem != nHit)
4781 NMTBHOTITEM nmhotitem;
4782 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4784 if(infoPtr->nHotItem >= 0)
4786 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4787 nmhotitem.idOld = oldBtnPtr->idCommand;
4789 else
4790 nmhotitem.dwFlags |= HICF_ENTERING;
4792 if (nHit >= 0)
4794 btnPtr = &infoPtr->buttons[nHit];
4795 nmhotitem.idNew = btnPtr->idCommand;
4796 /* setting disabled buttons as hot fails */
4797 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4798 return;
4800 else
4801 nmhotitem.dwFlags |= HICF_LEAVING;
4803 nmhotitem.dwFlags = dwReason;
4805 /* now change the hot and invalidate the old and new buttons - if the
4806 * parent agrees */
4807 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4809 infoPtr->nHotItem = nHit;
4810 if (btnPtr) {
4811 btnPtr->bHot = TRUE;
4812 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4814 if (oldBtnPtr) {
4815 oldBtnPtr->bHot = FALSE;
4816 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4822 static LRESULT
4823 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4825 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4826 INT nOldHotItem = infoPtr->nHotItem;
4828 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4830 if ((INT)wParam > infoPtr->nNumButtons)
4831 return infoPtr->nHotItem;
4833 if ((INT)wParam < 0)
4834 wParam = -1;
4836 /* NOTE: an application can still remove the hot item even if anchor
4837 * highlighting is enabled */
4839 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4841 if (nOldHotItem < 0)
4842 return -1;
4844 return (LRESULT)nOldHotItem;
4848 static LRESULT
4849 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4851 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4852 HIMAGELIST himlTemp;
4853 HIMAGELIST himl = (HIMAGELIST)lParam;
4854 INT i, id = 0;
4856 if (infoPtr->iVersion >= 5)
4857 id = wParam;
4859 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4860 &infoPtr->cimlDef, himl, id);
4862 infoPtr->nNumBitmaps = 0;
4863 for (i = 0; i < infoPtr->cimlDef; i++)
4864 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4866 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4867 &infoPtr->nBitmapHeight))
4869 infoPtr->nBitmapWidth = 1;
4870 infoPtr->nBitmapHeight = 1;
4873 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4874 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4875 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4877 InvalidateRect(hwnd, NULL, TRUE);
4879 return (LRESULT)himlTemp;
4883 static LRESULT
4884 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4886 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4888 infoPtr->nIndent = (INT)wParam;
4890 TRACE("\n");
4892 /* process only on indent changing */
4893 if(infoPtr->nIndent != (INT)wParam)
4895 infoPtr->nIndent = (INT)wParam;
4896 TOOLBAR_CalcToolbar (hwnd);
4897 InvalidateRect(hwnd, NULL, FALSE);
4900 return TRUE;
4904 static LRESULT
4905 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4907 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4908 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4910 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4912 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4914 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4915 return 0;
4918 if ((lptbim->iButton == -1) ||
4919 ((lptbim->iButton < infoPtr->nNumButtons) &&
4920 (lptbim->iButton >= 0)))
4922 infoPtr->tbim = *lptbim;
4923 /* FIXME: don't need to update entire toolbar */
4924 InvalidateRect(hwnd, NULL, TRUE);
4926 else
4927 ERR("Invalid button index %d\n", lptbim->iButton);
4929 return 0;
4933 static LRESULT
4934 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4936 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4938 infoPtr->clrInsertMark = (COLORREF)lParam;
4940 /* FIXME: don't need to update entire toolbar */
4941 InvalidateRect(hwnd, NULL, TRUE);
4943 return 0;
4947 static LRESULT
4948 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4950 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4952 infoPtr->nMaxTextRows = (INT)wParam;
4954 TOOLBAR_CalcToolbar(hwnd);
4955 return TRUE;
4959 /* MSDN gives slightly wrong info on padding.
4960 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4961 * 2. It is not used to create a blank area between the edge of the button
4962 * and the text or image if TBSTYLE_LIST is set. It is used to control
4963 * the gap between the image and text.
4964 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4965 * to control the bottom and right borders [with the border being
4966 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4967 * is shared evenly on both sides of the button.
4968 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4970 static LRESULT
4971 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4973 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4974 DWORD oldPad;
4976 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4977 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4978 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4979 TRACE("cx=%d, cy=%d\n",
4980 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4981 return (LRESULT) oldPad;
4985 static LRESULT
4986 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4988 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4989 HWND hwndOldNotify;
4991 TRACE("\n");
4993 hwndOldNotify = infoPtr->hwndNotify;
4994 infoPtr->hwndNotify = (HWND)wParam;
4996 return (LRESULT)hwndOldNotify;
5000 static LRESULT
5001 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5003 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5004 LPRECT lprc = (LPRECT)lParam;
5006 TRACE("\n");
5008 if (LOWORD(wParam) > 1) {
5009 FIXME("multiple rows not supported!\n");
5012 if(infoPtr->nRows != LOWORD(wParam))
5014 infoPtr->nRows = LOWORD(wParam);
5016 /* recalculate toolbar */
5017 TOOLBAR_CalcToolbar (hwnd);
5019 /* repaint toolbar */
5020 InvalidateRect(hwnd, NULL, TRUE);
5023 /* return bounding rectangle */
5024 if (lprc) {
5025 lprc->left = infoPtr->rcBound.left;
5026 lprc->right = infoPtr->rcBound.right;
5027 lprc->top = infoPtr->rcBound.top;
5028 lprc->bottom = infoPtr->rcBound.bottom;
5031 return 0;
5035 static LRESULT
5036 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5038 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5039 TBUTTON_INFO *btnPtr;
5040 INT nIndex;
5042 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5043 if (nIndex == -1)
5044 return FALSE;
5046 btnPtr = &infoPtr->buttons[nIndex];
5048 /* if hidden state has changed the invalidate entire window and recalc */
5049 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5050 btnPtr->fsState = LOWORD(lParam);
5051 TOOLBAR_CalcToolbar (hwnd);
5052 InvalidateRect(hwnd, 0, TRUE);
5053 return TRUE;
5056 /* process state changing if current state doesn't match new state */
5057 if(btnPtr->fsState != LOWORD(lParam))
5059 btnPtr->fsState = LOWORD(lParam);
5060 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5063 return TRUE;
5067 static LRESULT
5068 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5070 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5072 return TRUE;
5076 inline static LRESULT
5077 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5079 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5081 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5083 infoPtr->hwndToolTip = (HWND)wParam;
5084 return 0;
5088 static LRESULT
5089 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5091 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5092 BOOL bTemp;
5094 TRACE("%s hwnd=%p\n",
5095 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5097 bTemp = infoPtr->bUnicode;
5098 infoPtr->bUnicode = (BOOL)wParam;
5100 return bTemp;
5104 static LRESULT
5105 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5107 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5109 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5110 comctl32_color.clrBtnHighlight :
5111 infoPtr->clrBtnHighlight;
5112 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5113 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5114 return 1;
5118 static LRESULT
5119 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5121 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5123 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5124 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5125 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5127 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5128 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5129 InvalidateRect(hwnd, NULL, TRUE);
5130 return 0;
5134 static LRESULT
5135 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5137 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5138 INT iOldVersion = infoPtr->iVersion;
5140 infoPtr->iVersion = iVersion;
5142 if (infoPtr->iVersion >= 5)
5143 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5145 return iOldVersion;
5149 static LRESULT
5150 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5152 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5153 WORD iString = HIWORD(wParam);
5154 WORD buffersize = LOWORD(wParam);
5155 LPSTR str = (LPSTR)lParam;
5156 LRESULT ret = -1;
5158 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5160 if (iString < infoPtr->nNumStrings)
5162 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5164 TRACE("returning %s\n", debugstr_a(str));
5166 else
5167 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5169 return ret;
5173 static LRESULT
5174 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5176 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5177 WORD iString = HIWORD(wParam);
5178 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5179 LPWSTR str = (LPWSTR)lParam;
5180 LRESULT ret = -1;
5182 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5184 if (iString < infoPtr->nNumStrings)
5186 len = min(len, strlenW(infoPtr->strings[iString]));
5187 ret = (len+1)*sizeof(WCHAR);
5188 memcpy(str, infoPtr->strings[iString], ret);
5189 str[len] = '\0';
5191 TRACE("returning %s\n", debugstr_w(str));
5193 else
5194 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5196 return ret;
5199 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5200 * is the maximum size of the toolbar? */
5201 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5203 SIZE * pSize = (SIZE*)lParam;
5204 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5205 return 0;
5209 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5210 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5211 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5212 * sends). */
5213 static LRESULT
5214 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5216 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5217 INT nOldHotItem = infoPtr->nHotItem;
5219 TRACE("old item=%d, new item=%d, flags=%08x\n",
5220 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5222 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5223 wParam = -1;
5225 /* NOTE: an application can still remove the hot item even if anchor
5226 * highlighting is enabled */
5228 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5230 GetFocus();
5232 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5235 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5236 * which controls the amount of spacing between the image and the text
5237 * of buttons for TBSTYLE_LIST toolbars. */
5238 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5240 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5242 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5244 if (lParam != 0)
5245 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5247 infoPtr->iListGap = (INT)wParam;
5249 InvalidateRect(hwnd, NULL, TRUE);
5251 return 0;
5254 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5255 * of image lists associated with the various states. */
5256 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5258 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5260 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5262 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5265 static LRESULT
5266 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5268 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5269 LPSIZE lpsize = (LPSIZE)lParam;
5271 if (lpsize == NULL)
5272 return FALSE;
5275 * Testing shows the following:
5276 * wParam = 0 adjust cx value
5277 * = 1 set cy value to max size.
5278 * lParam pointer to SIZE structure
5281 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5282 wParam, lParam, lpsize->cx, lpsize->cy);
5284 switch(wParam) {
5285 case 0:
5286 if (lpsize->cx == -1) {
5287 /* **** this is wrong, native measures each button and sets it */
5288 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5290 else if(HIWORD(lpsize->cx)) {
5291 RECT rc;
5292 HWND hwndParent = GetParent(hwnd);
5294 GetWindowRect(hwnd, &rc);
5295 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5296 TRACE("mapped to (%d,%d)-(%d,%d)\n",
5297 rc.left, rc.top, rc.right, rc.bottom);
5298 lpsize->cx = max(rc.right-rc.left,
5299 infoPtr->rcBound.right - infoPtr->rcBound.left);
5301 else {
5302 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5304 break;
5305 case 1:
5306 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5307 break;
5308 default:
5309 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5310 wParam);
5311 return 0;
5313 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5314 lpsize->cx, lpsize->cy);
5315 return 1;
5318 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5320 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5322 InvalidateRect(hwnd, NULL, TRUE);
5323 return 1;
5327 static LRESULT
5328 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5330 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5331 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5332 LOGFONTW logFont;
5334 TRACE("hwnd = %p\n", hwnd);
5336 /* initialize info structure */
5337 infoPtr->nButtonHeight = 22;
5338 infoPtr->nButtonWidth = 24;
5339 infoPtr->nBitmapHeight = 15;
5340 infoPtr->nBitmapWidth = 16;
5342 infoPtr->nMaxTextRows = 1;
5343 infoPtr->cxMin = -1;
5344 infoPtr->cxMax = -1;
5345 infoPtr->nNumBitmaps = 0;
5346 infoPtr->nNumStrings = 0;
5348 infoPtr->bCaptured = FALSE;
5349 infoPtr->nButtonDown = -1;
5350 infoPtr->nButtonDrag = -1;
5351 infoPtr->nOldHit = -1;
5352 infoPtr->nHotItem = -1;
5353 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5354 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5355 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5356 infoPtr->bDragOutSent = FALSE;
5357 infoPtr->iVersion = 0;
5358 infoPtr->hwndSelf = hwnd;
5359 infoPtr->bDoRedraw = TRUE;
5360 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5361 infoPtr->clrBtnShadow = CLR_DEFAULT;
5362 infoPtr->szPadding.cx = DEFPAD_CX;
5363 infoPtr->szPadding.cy = DEFPAD_CY;
5364 infoPtr->iListGap = DEFLISTGAP;
5365 infoPtr->dwStyle = dwStyle;
5366 infoPtr->tbim.iButton = -1;
5367 GetClientRect(hwnd, &infoPtr->client_rect);
5368 infoPtr->bUnicode = infoPtr->hwndNotify &&
5369 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5370 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5372 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5373 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5375 OpenThemeData (hwnd, themeClass);
5377 TOOLBAR_CheckStyle (hwnd, dwStyle);
5379 TOOLBAR_CalcToolbar(hwnd);
5381 return 0;
5385 static LRESULT
5386 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5388 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5390 /* delete tooltip control */
5391 if (infoPtr->hwndToolTip)
5392 DestroyWindow (infoPtr->hwndToolTip);
5394 /* delete temporary buffer for tooltip text */
5395 Free (infoPtr->pszTooltipText);
5396 Free (infoPtr->bitmaps); /* bitmaps list */
5398 /* delete button data */
5399 if (infoPtr->buttons)
5400 Free (infoPtr->buttons);
5402 /* delete strings */
5403 if (infoPtr->strings) {
5404 INT i;
5405 for (i = 0; i < infoPtr->nNumStrings; i++)
5406 if (infoPtr->strings[i])
5407 Free (infoPtr->strings[i]);
5409 Free (infoPtr->strings);
5412 /* destroy internal image list */
5413 if (infoPtr->himlInt)
5414 ImageList_Destroy (infoPtr->himlInt);
5416 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5417 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5418 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5420 /* delete default font */
5421 if (infoPtr->hFont)
5422 DeleteObject (infoPtr->hDefaultFont);
5424 CloseThemeData (GetWindowTheme (hwnd));
5426 /* free toolbar info data */
5427 Free (infoPtr);
5428 SetWindowLongPtrW (hwnd, 0, 0);
5430 return 0;
5434 static LRESULT
5435 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5437 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5438 NMTBCUSTOMDRAW tbcd;
5439 INT ret = FALSE;
5440 DWORD ntfret;
5441 HTHEME theme = GetWindowTheme (hwnd);
5442 DWORD dwEraseCustDraw = 0;
5444 /* the app has told us not to redraw the toolbar */
5445 if (!infoPtr->bDoRedraw)
5446 return FALSE;
5448 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5449 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5450 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5451 tbcd.nmcd.hdc = (HDC)wParam;
5452 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5453 dwEraseCustDraw = ntfret & 0xffff;
5455 /* FIXME: in general the return flags *can* be or'ed together */
5456 switch (dwEraseCustDraw)
5458 case CDRF_DODEFAULT:
5459 break;
5460 case CDRF_SKIPDEFAULT:
5461 return TRUE;
5462 default:
5463 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5464 hwnd, ntfret);
5468 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5469 * to my parent for processing.
5471 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5472 POINT pt, ptorig;
5473 HDC hdc = (HDC)wParam;
5474 HWND parent;
5476 pt.x = 0;
5477 pt.y = 0;
5478 parent = GetParent(hwnd);
5479 MapWindowPoints(hwnd, parent, &pt, 1);
5480 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5481 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5482 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5484 if (!ret)
5485 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5487 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5488 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5489 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5490 tbcd.nmcd.hdc = (HDC)wParam;
5491 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5492 dwEraseCustDraw = ntfret & 0xffff;
5493 switch (dwEraseCustDraw)
5495 case CDRF_DODEFAULT:
5496 break;
5497 case CDRF_SKIPDEFAULT:
5498 return TRUE;
5499 default:
5500 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5501 hwnd, ntfret);
5504 return ret;
5508 static LRESULT
5509 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5511 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5513 return (LRESULT)infoPtr->hFont;
5517 static void
5518 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5520 INT i;
5521 INT nNewHotItem = infoPtr->nHotItem;
5523 for (i = 0; i < infoPtr->nNumButtons; i++)
5525 /* did we wrap? */
5526 if ((nNewHotItem + iDirection < 0) ||
5527 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5529 NMTBWRAPHOTITEM nmtbwhi;
5530 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5531 nmtbwhi.iDirection = iDirection;
5532 nmtbwhi.dwReason = dwReason;
5534 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5535 return;
5538 nNewHotItem += iDirection;
5539 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5541 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5542 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5544 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5545 break;
5550 static LRESULT
5551 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5553 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5554 NMKEY nmkey;
5556 nmkey.nVKey = (UINT)wParam;
5557 nmkey.uFlags = HIWORD(lParam);
5559 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5560 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5562 switch ((UINT)wParam)
5564 case VK_LEFT:
5565 case VK_UP:
5566 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5567 break;
5568 case VK_RIGHT:
5569 case VK_DOWN:
5570 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5571 break;
5572 case VK_SPACE:
5573 case VK_RETURN:
5574 if ((infoPtr->nHotItem >= 0) &&
5575 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5577 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5578 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5579 (LPARAM)hwnd);
5581 break;
5584 return 0;
5588 static LRESULT
5589 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5591 POINT pt;
5592 INT nHit;
5594 pt.x = (INT)LOWORD(lParam);
5595 pt.y = (INT)HIWORD(lParam);
5596 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5598 if (nHit >= 0)
5599 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5600 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5601 TOOLBAR_Customize (hwnd);
5603 return 0;
5607 static LRESULT
5608 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5610 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5611 TBUTTON_INFO *btnPtr;
5612 POINT pt;
5613 INT nHit;
5614 NMTOOLBARA nmtb;
5615 NMMOUSE nmmouse;
5616 BOOL bDragKeyPressed;
5618 TRACE("\n");
5620 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5621 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5622 else
5623 bDragKeyPressed = (wParam & MK_SHIFT);
5625 if (infoPtr->hwndToolTip)
5626 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5627 WM_LBUTTONDOWN, wParam, lParam);
5629 pt.x = (INT)LOWORD(lParam);
5630 pt.y = (INT)HIWORD(lParam);
5631 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5633 btnPtr = &infoPtr->buttons[nHit];
5635 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5637 infoPtr->nButtonDrag = nHit;
5638 SetCapture (hwnd);
5640 /* If drag cursor has not been loaded, load it.
5641 * Note: it doesn't need to be freed */
5642 if (!hCursorDrag)
5643 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5644 SetCursor(hCursorDrag);
5646 else if (nHit >= 0)
5648 RECT arrowRect;
5649 infoPtr->nOldHit = nHit;
5651 CopyRect(&arrowRect, &btnPtr->rect);
5652 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5654 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5655 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5656 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5657 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5658 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5659 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5661 LRESULT res;
5663 /* draw in pressed state */
5664 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5665 btnPtr->fsState |= TBSTATE_PRESSED;
5666 else
5667 btnPtr->bDropDownPressed = TRUE;
5668 RedrawWindow(hwnd,&btnPtr->rect,0,
5669 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5671 memset(&nmtb, 0, sizeof(nmtb));
5672 nmtb.iItem = btnPtr->idCommand;
5673 nmtb.rcButton = btnPtr->rect;
5674 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5675 TBN_DROPDOWN);
5676 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5678 if (res != TBDDRET_TREATPRESSED)
5680 MSG msg;
5682 /* redraw button in unpressed state */
5683 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5684 btnPtr->fsState &= ~TBSTATE_PRESSED;
5685 else
5686 btnPtr->bDropDownPressed = FALSE;
5687 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5689 /* find and set hot item
5690 * NOTE: native doesn't do this, but that is a bug */
5691 GetCursorPos(&pt);
5692 ScreenToClient(hwnd, &pt);
5693 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5694 if (!infoPtr->bAnchor || (nHit >= 0))
5695 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5697 /* remove any left mouse button down or double-click messages
5698 * so that we can get a toggle effect on the button */
5699 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5700 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5703 return 0;
5705 /* otherwise drop through and process as pushed */
5707 infoPtr->bCaptured = TRUE;
5708 infoPtr->nButtonDown = nHit;
5709 infoPtr->bDragOutSent = FALSE;
5711 btnPtr->fsState |= TBSTATE_PRESSED;
5713 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5715 if (btnPtr->fsState & TBSTATE_ENABLED)
5716 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5717 UpdateWindow(hwnd);
5718 SetCapture (hwnd);
5721 if (nHit >=0)
5723 memset(&nmtb, 0, sizeof(nmtb));
5724 nmtb.iItem = btnPtr->idCommand;
5725 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5728 nmmouse.dwHitInfo = nHit;
5730 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5731 if (nHit < 0)
5732 nmmouse.dwItemSpec = -1;
5733 else
5735 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5736 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5739 ClientToScreen(hwnd, &pt);
5740 nmmouse.pt = pt;
5742 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5743 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5745 return 0;
5748 static LRESULT
5749 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5751 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5752 TBUTTON_INFO *btnPtr;
5753 POINT pt;
5754 INT nHit;
5755 INT nOldIndex = -1;
5756 BOOL bSendMessage = TRUE;
5757 NMHDR hdr;
5758 NMMOUSE nmmouse;
5759 NMTOOLBARA nmtb;
5761 if (infoPtr->hwndToolTip)
5762 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5763 WM_LBUTTONUP, wParam, lParam);
5765 pt.x = (INT)LOWORD(lParam);
5766 pt.y = (INT)HIWORD(lParam);
5767 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5769 if (!infoPtr->bAnchor || (nHit >= 0))
5770 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5772 if (infoPtr->nButtonDrag >= 0) {
5773 RECT rcClient;
5774 NMHDR hdr;
5776 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5777 ReleaseCapture();
5778 /* reset cursor */
5779 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5781 GetClientRect(hwnd, &rcClient);
5782 if (PtInRect(&rcClient, pt))
5784 INT nButton = -1;
5785 if (nHit >= 0)
5786 nButton = nHit;
5787 else if (nHit < -1)
5788 nButton = -nHit;
5789 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5790 nButton = -nHit;
5792 if (nButton == infoPtr->nButtonDrag)
5794 /* if the button is moved sightly left and we have a
5795 * separator there then remove it */
5796 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5798 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5799 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5801 else /* else insert a separator before the dragged button */
5803 TBBUTTON tbb;
5804 memset(&tbb, 0, sizeof(tbb));
5805 tbb.fsStyle = BTNS_SEP;
5806 tbb.iString = -1;
5807 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5810 else
5812 if (nButton == -1)
5814 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5815 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5816 else
5817 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5819 else
5820 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5823 else
5825 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5826 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5829 /* button under cursor changed so need to re-set hot item */
5830 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5831 infoPtr->nButtonDrag = -1;
5833 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5835 else if (infoPtr->nButtonDown >= 0) {
5836 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5837 btnPtr->fsState &= ~TBSTATE_PRESSED;
5839 if (btnPtr->fsStyle & BTNS_CHECK) {
5840 if (btnPtr->fsStyle & BTNS_GROUP) {
5841 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5842 nHit);
5843 if (nOldIndex == nHit)
5844 bSendMessage = FALSE;
5845 if ((nOldIndex != nHit) &&
5846 (nOldIndex != -1))
5847 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5848 btnPtr->fsState |= TBSTATE_CHECKED;
5850 else {
5851 if (btnPtr->fsState & TBSTATE_CHECKED)
5852 btnPtr->fsState &= ~TBSTATE_CHECKED;
5853 else
5854 btnPtr->fsState |= TBSTATE_CHECKED;
5858 if (nOldIndex != -1)
5859 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5862 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5863 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5864 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5866 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5867 ReleaseCapture ();
5868 infoPtr->nButtonDown = -1;
5870 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5871 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5872 NM_RELEASEDCAPTURE);
5874 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5875 * TBN_BEGINDRAG
5877 memset(&nmtb, 0, sizeof(nmtb));
5878 nmtb.iItem = btnPtr->idCommand;
5879 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5880 TBN_ENDDRAG);
5882 if (btnPtr->fsState & TBSTATE_ENABLED)
5884 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5885 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5889 /* !!! Undocumented - toolbar at 4.71 level and above sends
5890 * NM_CLICK with the NMMOUSE structure. */
5891 nmmouse.dwHitInfo = nHit;
5893 if (nHit < 0)
5894 nmmouse.dwItemSpec = -1;
5895 else
5897 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5898 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5901 ClientToScreen(hwnd, &pt);
5902 nmmouse.pt = pt;
5904 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5905 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5907 return 0;
5910 static LRESULT
5911 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5913 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5914 INT nHit;
5915 NMMOUSE nmmouse;
5916 POINT pt;
5918 pt.x = LOWORD(lParam);
5919 pt.y = HIWORD(lParam);
5921 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5922 nmmouse.dwHitInfo = nHit;
5924 if (nHit < 0) {
5925 nmmouse.dwItemSpec = -1;
5926 } else {
5927 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5928 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5931 ClientToScreen(hwnd, &pt);
5932 nmmouse.pt = pt;
5934 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5935 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5937 return 0;
5940 static LRESULT
5941 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5943 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5944 NMHDR nmhdr;
5946 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5947 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5949 return 0;
5952 static LRESULT
5953 TOOLBAR_CaptureChanged(HWND hwnd)
5955 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5956 TBUTTON_INFO *btnPtr;
5958 infoPtr->bCaptured = FALSE;
5960 if (infoPtr->nButtonDown >= 0)
5962 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5963 btnPtr->fsState &= ~TBSTATE_PRESSED;
5965 infoPtr->nOldHit = -1;
5967 if (btnPtr->fsState & TBSTATE_ENABLED)
5968 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5970 return 0;
5973 static LRESULT
5974 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5976 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5978 /* don't remove hot effects when in anchor highlighting mode or when a
5979 * drop-down button is pressed */
5980 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
5982 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5983 if (!hotBtnPtr->bDropDownPressed)
5984 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
5987 if (infoPtr->nOldHit < 0)
5988 return TRUE;
5990 /* If the last button we were over is depressed then make it not */
5991 /* depressed and redraw it */
5992 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5994 TBUTTON_INFO *btnPtr;
5995 RECT rc1;
5997 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5999 btnPtr->fsState &= ~TBSTATE_PRESSED;
6001 rc1 = btnPtr->rect;
6002 InflateRect (&rc1, 1, 1);
6003 InvalidateRect (hwnd, &rc1, TRUE);
6006 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6008 NMTOOLBARW nmt;
6009 ZeroMemory(&nmt, sizeof(nmt));
6010 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6011 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6012 infoPtr->bDragOutSent = TRUE;
6015 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6017 return TRUE;
6020 static LRESULT
6021 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6023 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6024 POINT pt;
6025 TRACKMOUSEEVENT trackinfo;
6026 INT nHit;
6027 TBUTTON_INFO *btnPtr;
6029 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6030 TOOLBAR_TooltipCreateControl(infoPtr);
6032 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6033 /* fill in the TRACKMOUSEEVENT struct */
6034 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6035 trackinfo.dwFlags = TME_QUERY;
6037 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6038 _TrackMouseEvent(&trackinfo);
6040 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6041 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6042 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6043 trackinfo.hwndTrack = hwnd;
6045 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6046 /* and can properly deactivate the hot toolbar button */
6047 _TrackMouseEvent(&trackinfo);
6051 if (infoPtr->hwndToolTip)
6052 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6053 WM_MOUSEMOVE, wParam, lParam);
6055 pt.x = (INT)LOWORD(lParam);
6056 pt.y = (INT)HIWORD(lParam);
6058 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6060 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6061 && (!infoPtr->bAnchor || (nHit >= 0)))
6062 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6064 if (infoPtr->nOldHit != nHit)
6066 if (infoPtr->bCaptured)
6068 if (!infoPtr->bDragOutSent)
6070 NMTOOLBARW nmt;
6071 ZeroMemory(&nmt, sizeof(nmt));
6072 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6073 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6074 infoPtr->bDragOutSent = TRUE;
6077 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6078 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6079 btnPtr->fsState &= ~TBSTATE_PRESSED;
6080 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6082 else if (nHit == infoPtr->nButtonDown) {
6083 btnPtr->fsState |= TBSTATE_PRESSED;
6084 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6086 infoPtr->nOldHit = nHit;
6090 return 0;
6094 inline static LRESULT
6095 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6097 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6098 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6099 /* else */
6100 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6104 inline static LRESULT
6105 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6107 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6108 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6110 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6114 static LRESULT
6115 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6117 TOOLBAR_INFO *infoPtr;
6118 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6119 DWORD styleadd = 0;
6121 /* allocate memory for info structure */
6122 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6123 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6125 /* paranoid!! */
6126 infoPtr->dwStructSize = sizeof(TBBUTTON);
6127 infoPtr->nRows = 1;
6128 infoPtr->nWidth = 0;
6130 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6131 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6132 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6133 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6136 /* native control does:
6137 * Get a lot of colors and brushes
6138 * WM_NOTIFYFORMAT
6139 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6140 * CreateFontIndirectW(adr1)
6141 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6142 * hdc = GetDC(toolbar)
6143 * GetSystemMetrics(0x48)
6144 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6145 * 0, 0, 0, 0, "MARLETT")
6146 * oldfnt = SelectObject(hdc, fnt2)
6147 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6148 * GetTextMetricsW(hdc, adr3)
6149 * SelectObject(hdc, oldfnt)
6150 * DeleteObject(fnt2)
6151 * ReleaseDC(hdc)
6152 * InvalidateRect(toolbar, 0, 1)
6153 * SetWindowLongW(toolbar, 0, addr)
6154 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6155 * WM_STYLECHANGING
6156 * CallWinEx old new
6157 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6158 * ie 2 0x4600094c 0x4600094c 0x4600894d
6159 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6160 * rebar 0x50008844 0x40008844 0x50008845
6161 * pager 0x50000844 0x40000844 0x50008845
6162 * IC35mgr 0x5400084e **nochange**
6163 * on entry to _NCCREATE 0x5400084e
6164 * rowlist 0x5400004e **nochange**
6165 * on entry to _NCCREATE 0x5400004e
6169 /* I think the code below is a bug, but it is the way that the native
6170 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6171 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6172 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6173 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6174 * Somehow, the only cases of this seem to be MFC programs.
6176 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6177 * does not occur in the WM_STYLECHANGING routine.
6178 * (Guy Albertelli 9/2001)
6181 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6182 && !(cs->style & TBSTYLE_TRANSPARENT))
6183 styleadd |= TBSTYLE_TRANSPARENT;
6184 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6185 styleadd |= CCS_TOP; /* default to top */
6186 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6189 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6193 static LRESULT
6194 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6196 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6197 RECT rcWindow;
6198 HDC hdc;
6200 if (dwStyle & WS_MINIMIZE)
6201 return 0; /* Nothing to do */
6203 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6205 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6206 return 0;
6208 if (!(dwStyle & CCS_NODIVIDER))
6210 GetWindowRect (hwnd, &rcWindow);
6211 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6212 if( dwStyle & WS_BORDER )
6213 OffsetRect (&rcWindow, 1, 1);
6214 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6217 ReleaseDC( hwnd, hdc );
6219 return 0;
6223 /* handles requests from the tooltip control on what text to display */
6224 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6226 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6228 TRACE("button index = %d\n", index);
6230 Free (infoPtr->pszTooltipText);
6231 infoPtr->pszTooltipText = NULL;
6233 if (index < 0)
6234 return 0;
6236 if (infoPtr->bUnicode)
6238 WCHAR wszBuffer[INFOTIPSIZE+1];
6239 NMTBGETINFOTIPW tbgit;
6240 unsigned int len; /* in chars */
6242 wszBuffer[0] = '\0';
6243 wszBuffer[INFOTIPSIZE] = '\0';
6245 tbgit.pszText = wszBuffer;
6246 tbgit.cchTextMax = INFOTIPSIZE;
6247 tbgit.iItem = lpnmtdi->hdr.idFrom;
6248 tbgit.lParam = infoPtr->buttons[index].dwData;
6250 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6252 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6254 len = strlenW(tbgit.pszText);
6255 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6257 /* need to allocate temporary buffer in infoPtr as there
6258 * isn't enough space in buffer passed to us by the
6259 * tooltip control */
6260 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6261 if (infoPtr->pszTooltipText)
6263 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6264 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6265 return 0;
6268 else if (len > 0)
6270 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6271 return 0;
6274 else
6276 CHAR szBuffer[INFOTIPSIZE+1];
6277 NMTBGETINFOTIPA tbgit;
6278 unsigned int len; /* in chars */
6280 szBuffer[0] = '\0';
6281 szBuffer[INFOTIPSIZE] = '\0';
6283 tbgit.pszText = szBuffer;
6284 tbgit.cchTextMax = INFOTIPSIZE;
6285 tbgit.iItem = lpnmtdi->hdr.idFrom;
6286 tbgit.lParam = infoPtr->buttons[index].dwData;
6288 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6290 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6292 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6293 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6295 /* need to allocate temporary buffer in infoPtr as there
6296 * isn't enough space in buffer passed to us by the
6297 * tooltip control */
6298 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6299 if (infoPtr->pszTooltipText)
6301 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6302 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6303 return 0;
6306 else if (len > 0)
6308 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6309 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6310 return 0;
6314 /* if button has text, but it is not shown then automatically
6315 * use that text as tooltip */
6316 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6317 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6319 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6320 unsigned int len = pszText ? strlenW(pszText) : 0;
6322 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6324 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6326 /* need to allocate temporary buffer in infoPtr as there
6327 * isn't enough space in buffer passed to us by the
6328 * tooltip control */
6329 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6330 if (infoPtr->pszTooltipText)
6332 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6333 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6334 return 0;
6337 else if (len > 0)
6339 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6340 return 0;
6344 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6346 /* last resort: send notification on to app */
6347 /* FIXME: find out what is really used here */
6348 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6352 inline static LRESULT
6353 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6355 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6356 LPNMHDR lpnmh = (LPNMHDR)lParam;
6358 switch (lpnmh->code)
6360 case PGN_CALCSIZE:
6362 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6364 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6365 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6366 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6367 lppgc->iWidth);
6369 else {
6370 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6371 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6372 lppgc->iHeight);
6374 return 0;
6377 case PGN_SCROLL:
6379 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6381 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6382 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6383 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6384 lppgs->iScroll, lppgs->iDir);
6385 return 0;
6388 case TTN_GETDISPINFOW:
6389 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6391 case TTN_GETDISPINFOA:
6392 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6393 return 0;
6395 default:
6396 return 0;
6401 static LRESULT
6402 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6404 LRESULT format;
6406 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6408 if (lParam == NF_QUERY)
6409 return NFR_UNICODE;
6411 if (lParam == NF_REQUERY) {
6412 format = SendMessageW(infoPtr->hwndNotify,
6413 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6414 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6415 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6416 format);
6417 format = NFR_ANSI;
6419 return format;
6421 return 0;
6425 static LRESULT
6426 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6428 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6429 HDC hdc;
6430 PAINTSTRUCT ps;
6432 /* fill ps.rcPaint with a default rect */
6433 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6435 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6437 TRACE("psrect=(%d,%d)-(%d,%d)\n",
6438 ps.rcPaint.left, ps.rcPaint.top,
6439 ps.rcPaint.right, ps.rcPaint.bottom);
6441 TOOLBAR_Refresh (hwnd, hdc, &ps);
6442 if (!wParam) EndPaint (hwnd, &ps);
6444 return 0;
6448 static LRESULT
6449 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6451 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6453 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6455 /* make first item hot */
6456 if (infoPtr->nNumButtons > 0)
6457 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6459 return 0;
6463 static LRESULT
6464 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6465 /*****************************************************
6467 * Function;
6468 * Handles the WM_SETREDRAW message.
6470 * Documentation:
6471 * According to testing V4.71 of COMCTL32 returns the
6472 * *previous* status of the redraw flag (either 0 or 1)
6473 * instead of the MSDN documented value of 0 if handled.
6474 * (For laughs see the "consistency" with same function
6475 * in rebar.)
6477 *****************************************************/
6479 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6480 BOOL oldredraw = infoPtr->bDoRedraw;
6482 TRACE("set to %s\n",
6483 (wParam) ? "TRUE" : "FALSE");
6484 infoPtr->bDoRedraw = (BOOL) wParam;
6485 if (wParam) {
6486 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6488 return (oldredraw) ? 1 : 0;
6492 static LRESULT
6493 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6495 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6497 TRACE("sizing toolbar!\n");
6499 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6501 RECT delta_width, delta_height, client, dummy;
6502 DWORD min_x, max_x, min_y, max_y;
6503 TBUTTON_INFO *btnPtr;
6504 INT i;
6506 GetClientRect(hwnd, &client);
6507 if(client.right > infoPtr->client_rect.right)
6509 min_x = infoPtr->client_rect.right;
6510 max_x = client.right;
6512 else
6514 max_x = infoPtr->client_rect.right;
6515 min_x = client.right;
6517 if(client.bottom > infoPtr->client_rect.bottom)
6519 min_y = infoPtr->client_rect.bottom;
6520 max_y = client.bottom;
6522 else
6524 max_y = infoPtr->client_rect.bottom;
6525 min_y = client.bottom;
6528 SetRect(&delta_width, min_x, 0, max_x, min_y);
6529 SetRect(&delta_height, 0, min_y, max_x, max_y);
6531 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6532 btnPtr = infoPtr->buttons;
6533 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6534 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6535 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6536 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6538 GetClientRect(hwnd, &infoPtr->client_rect);
6539 TOOLBAR_AutoSize(hwnd);
6540 return 0;
6544 static LRESULT
6545 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6547 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6549 if (nType == GWL_STYLE)
6551 DWORD dwOldStyle = infoPtr->dwStyle;
6553 if (lpStyle->styleNew & TBSTYLE_LIST)
6554 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6555 else
6556 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6558 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6560 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6562 infoPtr->dwStyle = lpStyle->styleNew;
6564 /* only resize if one of the CCS_* styles was changed */
6565 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6567 TOOLBAR_AutoSize (hwnd);
6569 InvalidateRect(hwnd, NULL, TRUE);
6573 return 0;
6577 static LRESULT
6578 TOOLBAR_SysColorChange (HWND hwnd)
6580 COMCTL32_RefreshSysColors();
6582 return 0;
6586 /* update theme after a WM_THEMECHANGED message */
6587 static LRESULT theme_changed (HWND hwnd)
6589 HTHEME theme = GetWindowTheme (hwnd);
6590 CloseThemeData (theme);
6591 OpenThemeData (hwnd, themeClass);
6592 return 0;
6596 static LRESULT WINAPI
6597 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6599 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6601 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6602 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6604 if (!infoPtr && (uMsg != WM_NCCREATE))
6605 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6607 switch (uMsg)
6609 case TB_ADDBITMAP:
6610 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6612 case TB_ADDBUTTONSA:
6613 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6615 case TB_ADDBUTTONSW:
6616 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6618 case TB_ADDSTRINGA:
6619 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6621 case TB_ADDSTRINGW:
6622 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6624 case TB_AUTOSIZE:
6625 return TOOLBAR_AutoSize (hwnd);
6627 case TB_BUTTONCOUNT:
6628 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6630 case TB_BUTTONSTRUCTSIZE:
6631 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6633 case TB_CHANGEBITMAP:
6634 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6636 case TB_CHECKBUTTON:
6637 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6639 case TB_COMMANDTOINDEX:
6640 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6642 case TB_CUSTOMIZE:
6643 return TOOLBAR_Customize (hwnd);
6645 case TB_DELETEBUTTON:
6646 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6648 case TB_ENABLEBUTTON:
6649 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6651 case TB_GETANCHORHIGHLIGHT:
6652 return TOOLBAR_GetAnchorHighlight (hwnd);
6654 case TB_GETBITMAP:
6655 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6657 case TB_GETBITMAPFLAGS:
6658 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6660 case TB_GETBUTTON:
6661 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6663 case TB_GETBUTTONINFOA:
6664 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6666 case TB_GETBUTTONINFOW:
6667 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6669 case TB_GETBUTTONSIZE:
6670 return TOOLBAR_GetButtonSize (hwnd);
6672 case TB_GETBUTTONTEXTA:
6673 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6675 case TB_GETBUTTONTEXTW:
6676 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6678 case TB_GETDISABLEDIMAGELIST:
6679 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6681 case TB_GETEXTENDEDSTYLE:
6682 return TOOLBAR_GetExtendedStyle (hwnd);
6684 case TB_GETHOTIMAGELIST:
6685 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6687 case TB_GETHOTITEM:
6688 return TOOLBAR_GetHotItem (hwnd);
6690 case TB_GETIMAGELIST:
6691 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6693 case TB_GETINSERTMARK:
6694 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6696 case TB_GETINSERTMARKCOLOR:
6697 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6699 case TB_GETITEMRECT:
6700 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6702 case TB_GETMAXSIZE:
6703 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6705 /* case TB_GETOBJECT: */ /* 4.71 */
6707 case TB_GETPADDING:
6708 return TOOLBAR_GetPadding (hwnd);
6710 case TB_GETRECT:
6711 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6713 case TB_GETROWS:
6714 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6716 case TB_GETSTATE:
6717 return TOOLBAR_GetState (hwnd, wParam, lParam);
6719 case TB_GETSTRINGA:
6720 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6722 case TB_GETSTRINGW:
6723 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6725 case TB_GETSTYLE:
6726 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6728 case TB_GETTEXTROWS:
6729 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6731 case TB_GETTOOLTIPS:
6732 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6734 case TB_GETUNICODEFORMAT:
6735 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6737 case TB_HIDEBUTTON:
6738 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6740 case TB_HITTEST:
6741 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6743 case TB_INDETERMINATE:
6744 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6746 case TB_INSERTBUTTONA:
6747 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6749 case TB_INSERTBUTTONW:
6750 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6752 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6754 case TB_ISBUTTONCHECKED:
6755 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6757 case TB_ISBUTTONENABLED:
6758 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6760 case TB_ISBUTTONHIDDEN:
6761 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6763 case TB_ISBUTTONHIGHLIGHTED:
6764 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6766 case TB_ISBUTTONINDETERMINATE:
6767 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6769 case TB_ISBUTTONPRESSED:
6770 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6772 case TB_LOADIMAGES:
6773 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6775 case TB_MAPACCELERATORA:
6776 case TB_MAPACCELERATORW:
6777 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6779 case TB_MARKBUTTON:
6780 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6782 case TB_MOVEBUTTON:
6783 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6785 case TB_PRESSBUTTON:
6786 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6788 case TB_REPLACEBITMAP:
6789 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6791 case TB_SAVERESTOREA:
6792 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6794 case TB_SAVERESTOREW:
6795 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6797 case TB_SETANCHORHIGHLIGHT:
6798 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6800 case TB_SETBITMAPSIZE:
6801 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6803 case TB_SETBUTTONINFOA:
6804 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6806 case TB_SETBUTTONINFOW:
6807 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6809 case TB_SETBUTTONSIZE:
6810 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6812 case TB_SETBUTTONWIDTH:
6813 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6815 case TB_SETCMDID:
6816 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6818 case TB_SETDISABLEDIMAGELIST:
6819 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6821 case TB_SETDRAWTEXTFLAGS:
6822 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6824 case TB_SETEXTENDEDSTYLE:
6825 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6827 case TB_SETHOTIMAGELIST:
6828 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6830 case TB_SETHOTITEM:
6831 return TOOLBAR_SetHotItem (hwnd, wParam);
6833 case TB_SETIMAGELIST:
6834 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6836 case TB_SETINDENT:
6837 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6839 case TB_SETINSERTMARK:
6840 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6842 case TB_SETINSERTMARKCOLOR:
6843 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6845 case TB_SETMAXTEXTROWS:
6846 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6848 case TB_SETPADDING:
6849 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6851 case TB_SETPARENT:
6852 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6854 case TB_SETROWS:
6855 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6857 case TB_SETSTATE:
6858 return TOOLBAR_SetState (hwnd, wParam, lParam);
6860 case TB_SETSTYLE:
6861 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6863 case TB_SETTOOLTIPS:
6864 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6866 case TB_SETUNICODEFORMAT:
6867 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6869 case TB_UNKWN45D:
6870 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6872 case TB_UNKWN45E:
6873 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6875 case TB_UNKWN460:
6876 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6878 case TB_UNKWN462:
6879 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6881 case TB_UNKWN463:
6882 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6884 case TB_UNKWN464:
6885 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6887 /* Common Control Messages */
6889 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6890 case CCM_GETCOLORSCHEME:
6891 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6893 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6894 case CCM_SETCOLORSCHEME:
6895 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6897 case CCM_GETVERSION:
6898 return TOOLBAR_GetVersion (hwnd);
6900 case CCM_SETVERSION:
6901 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6904 /* case WM_CHAR: */
6906 case WM_CREATE:
6907 return TOOLBAR_Create (hwnd, wParam, lParam);
6909 case WM_DESTROY:
6910 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6912 case WM_ERASEBKGND:
6913 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6915 case WM_GETFONT:
6916 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6918 case WM_KEYDOWN:
6919 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6921 /* case WM_KILLFOCUS: */
6923 case WM_LBUTTONDBLCLK:
6924 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6926 case WM_LBUTTONDOWN:
6927 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6929 case WM_LBUTTONUP:
6930 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6932 case WM_RBUTTONUP:
6933 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6935 case WM_RBUTTONDBLCLK:
6936 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6938 case WM_MOUSEMOVE:
6939 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6941 case WM_MOUSELEAVE:
6942 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6944 case WM_CAPTURECHANGED:
6945 return TOOLBAR_CaptureChanged(hwnd);
6947 case WM_NCACTIVATE:
6948 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6950 case WM_NCCALCSIZE:
6951 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6953 case WM_NCCREATE:
6954 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6956 case WM_NCPAINT:
6957 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6959 case WM_NOTIFY:
6960 return TOOLBAR_Notify (hwnd, wParam, lParam);
6962 case WM_NOTIFYFORMAT:
6963 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
6965 case WM_PRINTCLIENT:
6966 case WM_PAINT:
6967 return TOOLBAR_Paint (hwnd, wParam);
6969 case WM_SETFOCUS:
6970 return TOOLBAR_SetFocus (hwnd, wParam);
6972 case WM_SETREDRAW:
6973 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6975 case WM_SIZE:
6976 return TOOLBAR_Size (hwnd, wParam, lParam);
6978 case WM_STYLECHANGED:
6979 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6981 case WM_SYSCOLORCHANGE:
6982 return TOOLBAR_SysColorChange (hwnd);
6984 case WM_THEMECHANGED:
6985 return theme_changed (hwnd);
6987 /* case WM_WININICHANGE: */
6989 case WM_CHARTOITEM:
6990 case WM_COMMAND:
6991 case WM_DRAWITEM:
6992 case WM_MEASUREITEM:
6993 case WM_VKEYTOITEM:
6994 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
6996 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6997 case PGM_FORWARDMOUSE:
6998 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7000 default:
7001 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7002 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7003 uMsg, wParam, lParam);
7004 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7009 VOID
7010 TOOLBAR_Register (void)
7012 WNDCLASSW wndClass;
7014 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7015 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7016 wndClass.lpfnWndProc = ToolbarWindowProc;
7017 wndClass.cbClsExtra = 0;
7018 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7019 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7020 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7021 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7023 RegisterClassW (&wndClass);
7027 VOID
7028 TOOLBAR_Unregister (void)
7030 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7033 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7035 HIMAGELIST himlold;
7036 PIMLENTRY c = NULL;
7038 /* Check if the entry already exists */
7039 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7041 /* If this is a new entry we must create it and insert into the array */
7042 if (!c)
7044 PIMLENTRY *pnies;
7046 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7047 c->id = id;
7049 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7050 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7051 pnies[*cies] = c;
7052 (*cies)++;
7054 Free(*pies);
7055 *pies = pnies;
7058 himlold = c->himl;
7059 c->himl = himl;
7061 return himlold;
7065 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7067 int i;
7069 for (i = 0; i < *cies; i++)
7070 Free((*pies)[i]);
7072 Free(*pies);
7074 *cies = 0;
7075 *pies = NULL;
7079 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7081 PIMLENTRY c = NULL;
7083 if (pies != NULL)
7085 int i;
7087 for (i = 0; i < cies; i++)
7089 if (pies[i]->id == id)
7091 c = pies[i];
7092 break;
7097 return c;
7101 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7103 HIMAGELIST himlDef = 0;
7104 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7106 if (pie)
7107 himlDef = pie->himl;
7109 return himlDef;
7113 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7115 if (infoPtr->bUnicode)
7116 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7117 else
7119 CHAR Buffer[256];
7120 NMTOOLBARA nmtba;
7121 BOOL bRet = FALSE;
7123 nmtba.iItem = nmtb->iItem;
7124 nmtba.pszText = Buffer;
7125 nmtba.cchText = 256;
7126 ZeroMemory(nmtba.pszText, nmtba.cchText);
7128 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7130 int ccht = strlen(nmtba.pszText);
7131 if (ccht)
7132 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7133 nmtb->pszText, nmtb->cchText);
7135 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7136 bRet = TRUE;
7139 return bRet;
7144 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7145 int iItem, PCUSTOMBUTTON btnInfo)
7147 NMTOOLBARW nmtb;
7149 /* MSDN states that iItem is the index of the button, rather than the
7150 * command ID as used by every other NMTOOLBAR notification */
7151 nmtb.iItem = iItem;
7152 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7154 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);