shell32/tests: Hack SHGetFileInfo() so it does not crash and add a test for it.
[wine/hacks.git] / dlls / comctl32 / toolbar.c
blobbda17e927a93b7a84f158c334d504ff3687ec8be
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 nVBitmapHeight; /* see TOOLBAR_Create for an explanation */
129 INT nBitmapWidth;
130 INT nIndent;
131 INT nRows; /* number of button rows */
132 INT nMaxTextRows; /* maximum number of text rows */
133 INT cxMin; /* minimum button width */
134 INT cxMax; /* maximum button width */
135 INT nNumButtons; /* number of buttons */
136 INT nNumBitmaps; /* number of bitmaps */
137 INT nNumStrings; /* number of strings */
138 INT nNumBitmapInfos;
139 INT nButtonDown; /* toolbar button being pressed or -1 if none */
140 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
141 INT nOldHit;
142 INT nHotItem; /* index of the "hot" item */
143 SIZE szPadding; /* padding values around button */
144 INT iTopMargin; /* the top margin */
145 INT iListGap; /* default gap between text and image for toolbar with list style */
146 HFONT hDefaultFont;
147 HFONT hFont; /* text font */
148 HIMAGELIST himlInt; /* image list created internally */
149 PIMLENTRY *himlDef; /* default image list array */
150 INT cimlDef; /* default image list array count */
151 PIMLENTRY *himlHot; /* hot image list array */
152 INT cimlHot; /* hot image list array count */
153 PIMLENTRY *himlDis; /* disabled image list array */
154 INT cimlDis; /* disabled image list array count */
155 HWND hwndToolTip; /* handle to tool tip control */
156 HWND hwndNotify; /* handle to the window that gets notifications */
157 HWND hwndSelf; /* my own handle */
158 BOOL bAnchor; /* anchor highlight enabled */
159 BOOL bDoRedraw; /* Redraw status */
160 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
161 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
162 BOOL bCaptured; /* mouse captured? */
163 DWORD dwStyle; /* regular toolbar style */
164 DWORD dwExStyle; /* extended toolbar style */
165 DWORD dwDTFlags; /* DrawText flags */
167 COLORREF clrInsertMark; /* insert mark color */
168 COLORREF clrBtnHighlight; /* color for Flat Separator */
169 COLORREF clrBtnShadow; /* color for Flag Separator */
170 INT iVersion;
171 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
172 * for TTN_GETDISPINFOW notification */
173 TBINSERTMARK tbim; /* info on insertion mark */
174 TBUTTON_INFO *buttons; /* pointer to button array */
175 LPWSTR *strings; /* pointer to string array */
176 TBITMAP_INFO *bitmaps;
177 } TOOLBAR_INFO, *PTOOLBAR_INFO;
180 /* used by customization dialog */
181 typedef struct
183 PTOOLBAR_INFO tbInfo;
184 HWND tbHwnd;
185 } CUSTDLG_INFO, *PCUSTDLG_INFO;
187 typedef struct
189 TBBUTTON btn;
190 BOOL bVirtual;
191 BOOL bRemovable;
192 WCHAR text[64];
193 } CUSTOMBUTTON, *PCUSTOMBUTTON;
195 typedef enum
197 IMAGE_LIST_DEFAULT,
198 IMAGE_LIST_HOT,
199 IMAGE_LIST_DISABLED
200 } IMAGE_LIST_TYPE;
202 #define SEPARATOR_WIDTH 8
203 #define TOP_BORDER 2
204 #define BOTTOM_BORDER 2
205 #define DDARROW_WIDTH 11
206 #define ARROW_HEIGHT 3
207 #define INSERTMARK_WIDTH 2
209 #define DEFPAD_CX 7
210 #define DEFPAD_CY 6
211 #define DEFLISTGAP 4
213 /* vertical padding used in list mode when image is present */
214 #define LISTPAD_CY 9
216 /* how wide to treat the bitmap if it isn't present */
217 #define NONLIST_NOTEXT_OFFSET 2
219 #define TOOLBAR_NOWHERE (-1)
221 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
222 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
223 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
225 /* Used to find undocumented extended styles */
226 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
227 TBSTYLE_EX_UNDOC1 | \
228 TBSTYLE_EX_MIXEDBUTTONS | \
229 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
231 /* all of the CCS_ styles */
232 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
233 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
235 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
236 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
237 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
238 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
239 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
241 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
243 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
244 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
245 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
246 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
247 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
248 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
249 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
250 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
251 static void TOOLBAR_LayoutToolbar(HWND hwnd);
252 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
253 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
254 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button);
256 static LRESULT
257 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
259 inline static int default_top_margin(TOOLBAR_INFO *infoPtr)
261 return (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
264 static LPWSTR
265 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
267 LPWSTR lpText = NULL;
269 /* NOTE: iString == -1 is undocumented */
270 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
271 lpText = (LPWSTR)btnPtr->iString;
272 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
273 lpText = infoPtr->strings[btnPtr->iString];
275 return lpText;
278 static void
279 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
281 if (TRACE_ON(toolbar)){
282 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
283 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
284 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
285 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
286 if (internal)
287 TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n",
288 btn_num, bP->idCommand,
289 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
290 bP->rect.left, bP->rect.top,
291 bP->rect.right, bP->rect.bottom);
296 static void
297 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
299 if (TRACE_ON(toolbar)) {
300 INT i;
302 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
303 iP->hwndSelf, line,
304 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
305 iP->nNumStrings, iP->dwStyle);
306 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
307 iP->hwndSelf, line,
308 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
309 (iP->bDoRedraw) ? "TRUE" : "FALSE");
310 for(i=0; i<iP->nNumButtons; i++) {
311 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
317 /***********************************************************************
318 * TOOLBAR_CheckStyle
320 * This function validates that the styles set are implemented and
321 * issues FIXME's warning of possible problems. In a perfect world this
322 * function should be null.
324 static void
325 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
327 if (dwStyle & TBSTYLE_REGISTERDROP)
328 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
332 static INT
333 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
335 if(!IsWindow(infoPtr->hwndSelf))
336 return 0; /* we have just been destroyed */
338 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
339 nmhdr->hwndFrom = infoPtr->hwndSelf;
340 nmhdr->code = code;
342 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
343 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
345 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
346 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
349 /***********************************************************************
350 * TOOLBAR_GetBitmapIndex
352 * This function returns the bitmap index associated with a button.
353 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
354 * is issued to retrieve the index.
356 static INT
357 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
359 INT ret = btnPtr->iBitmap;
361 if (ret == I_IMAGECALLBACK)
363 /* issue TBN_GETDISPINFO */
364 NMTBDISPINFOA nmgd;
366 memset(&nmgd, 0, sizeof(nmgd));
367 nmgd.idCommand = btnPtr->idCommand;
368 nmgd.lParam = btnPtr->dwData;
369 nmgd.dwMask = TBNF_IMAGE;
370 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
371 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
372 if (nmgd.dwMask & TBNF_DI_SETITEM)
373 btnPtr->iBitmap = nmgd.iImage;
374 ret = nmgd.iImage;
375 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
376 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
379 if (ret != I_IMAGENONE)
380 ret = GETIBITMAP(infoPtr, ret);
382 return ret;
386 static BOOL
387 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
389 HIMAGELIST himl;
390 INT id = GETHIMLID(infoPtr, index);
391 INT iBitmap = GETIBITMAP(infoPtr, index);
393 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
394 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
395 (index == I_IMAGECALLBACK))
396 return TRUE;
397 else
398 return FALSE;
402 static inline BOOL
403 TOOLBAR_IsValidImageList(TOOLBAR_INFO *infoPtr, INT index)
405 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
406 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
410 /***********************************************************************
411 * TOOLBAR_GetImageListForDrawing
413 * This function validates the bitmap index (including I_IMAGECALLBACK
414 * functionality) and returns the corresponding image list.
416 static HIMAGELIST
417 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
419 HIMAGELIST himl;
421 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
422 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
423 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
424 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
425 return NULL;
428 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
429 if ((*index == I_IMAGECALLBACK) ||
430 (*index == I_IMAGENONE)) return NULL;
431 ERR("TBN_GETDISPINFO returned invalid index %d\n",
432 *index);
433 return NULL;
436 switch(imagelist)
438 case IMAGE_LIST_DEFAULT:
439 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
440 break;
441 case IMAGE_LIST_HOT:
442 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
443 break;
444 case IMAGE_LIST_DISABLED:
445 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
446 break;
447 default:
448 himl = NULL;
449 FIXME("Shouldn't reach here\n");
452 if (!himl)
453 TRACE("no image list\n");
455 return himl;
459 static void
460 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
462 RECT myrect;
463 COLORREF oldcolor, newcolor;
465 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
466 myrect.right = myrect.left + 1;
467 myrect.top = lpRect->top + 2;
468 myrect.bottom = lpRect->bottom - 2;
470 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
471 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
472 oldcolor = SetBkColor (hdc, newcolor);
473 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
475 myrect.left = myrect.right;
476 myrect.right = myrect.left + 1;
478 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
479 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
480 SetBkColor (hdc, newcolor);
481 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
483 SetBkColor (hdc, oldcolor);
487 /***********************************************************************
488 * TOOLBAR_DrawDDFlatSeparator
490 * This function draws the separator that was flagged as BTNS_DROPDOWN.
491 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
492 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
493 * are horizontal as opposed to the vertical separators for not dropdown
494 * type.
496 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
498 static void
499 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
501 RECT myrect;
502 COLORREF oldcolor, newcolor;
504 myrect.left = lpRect->left;
505 myrect.right = lpRect->right;
506 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
507 myrect.bottom = myrect.top + 1;
509 InflateRect (&myrect, -2, 0);
511 TRACE("rect=(%d,%d)-(%d,%d)\n",
512 myrect.left, myrect.top, myrect.right, myrect.bottom);
514 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
515 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
516 oldcolor = SetBkColor (hdc, newcolor);
517 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
519 myrect.top = myrect.bottom;
520 myrect.bottom = myrect.top + 1;
522 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
523 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
524 SetBkColor (hdc, newcolor);
525 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
527 SetBkColor (hdc, oldcolor);
531 static void
532 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
534 INT x, y;
535 HPEN hPen, hOldPen;
537 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
538 hOldPen = SelectObject ( hdc, hPen );
539 x = left + 2;
540 y = top;
541 MoveToEx (hdc, x, y, NULL);
542 LineTo (hdc, x+5, y++); x++;
543 MoveToEx (hdc, x, y, NULL);
544 LineTo (hdc, x+3, y++); x++;
545 MoveToEx (hdc, x, y, NULL);
546 LineTo (hdc, x+1, y++);
547 SelectObject( hdc, hOldPen );
548 DeleteObject( hPen );
552 * Draw the text string for this button.
553 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
554 * is non-zero, so we can simply check himlDef to see if we have
555 * an image list
557 static void
558 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
559 NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
561 HDC hdc = tbcd->nmcd.hdc;
562 HFONT hOldFont = 0;
563 COLORREF clrOld = 0;
564 COLORREF clrOldBk = 0;
565 int oldBkMode = 0;
566 UINT state = tbcd->nmcd.uItemState;
568 /* draw text */
569 if (lpText) {
570 TRACE("string=%s rect=(%d,%d)-(%d,%d)\n", debugstr_w(lpText),
571 rcText->left, rcText->top, rcText->right, rcText->bottom);
573 hOldFont = SelectObject (hdc, infoPtr->hFont);
574 if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
575 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
577 else if (state & CDIS_DISABLED) {
578 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
579 OffsetRect (rcText, 1, 1);
580 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
581 SetTextColor (hdc, comctl32_color.clr3dShadow);
582 OffsetRect (rcText, -1, -1);
584 else if (state & CDIS_INDETERMINATE) {
585 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
587 else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
588 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
589 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
590 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
592 else {
593 clrOld = SetTextColor (hdc, tbcd->clrText);
596 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
597 SetTextColor (hdc, clrOld);
598 if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
600 SetBkColor (hdc, clrOldBk);
601 SetBkMode (hdc, oldBkMode);
603 SelectObject (hdc, hOldFont);
608 static void
609 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
611 HDC hdc = tbcd->nmcd.hdc;
612 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
613 COLORREF clrTextOld;
614 COLORREF clrBkOld;
615 INT cx = lpRect->right - lpRect->left;
616 INT cy = lpRect->bottom - lpRect->top;
617 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
618 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
619 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
620 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
621 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
622 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
623 SetBkColor(hdc, clrBkOld);
624 SetTextColor(hdc, clrTextOld);
625 SelectObject (hdc, hbr);
629 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
631 INT cx, cy;
632 HBITMAP hbmMask, hbmImage;
633 HDC hdcMask, hdcImage;
635 ImageList_GetIconSize(himl, &cx, &cy);
637 /* Create src image */
638 hdcImage = CreateCompatibleDC(hdc);
639 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
640 SelectObject(hdcImage, hbmImage);
641 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
642 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
644 /* Create Mask */
645 hdcMask = CreateCompatibleDC(0);
646 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
647 SelectObject(hdcMask, hbmMask);
649 /* Remove the background and all white pixels */
650 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
651 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
652 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
653 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
655 /* draw the new mask 'etched' to hdc */
656 SetBkColor(hdc, RGB(255, 255, 255));
657 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
658 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
659 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
660 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
661 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
663 /* Cleanup */
664 DeleteObject(hbmImage);
665 DeleteDC(hdcImage);
666 DeleteObject (hbmMask);
667 DeleteDC(hdcMask);
671 static UINT
672 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
674 UINT retstate = 0;
676 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
677 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
678 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
679 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
680 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
681 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
682 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
683 return retstate;
686 /* draws the image on a toolbar button */
687 static void
688 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
689 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
691 HIMAGELIST himl = NULL;
692 BOOL draw_masked = FALSE;
693 INT index;
694 INT offset = 0;
695 UINT draw_flags = ILD_TRANSPARENT;
697 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
699 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
700 if (!himl)
702 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
703 draw_masked = TRUE;
706 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
707 ((tbcd->nmcd.uItemState & CDIS_HOT)
708 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
710 /* if hot, attempt to draw with hot image list, if fails,
711 use default image list */
712 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
713 if (!himl)
714 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
716 else
717 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
719 if (!himl)
720 return;
722 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
723 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
724 offset = 1;
726 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
727 (tbcd->nmcd.uItemState & CDIS_MARKED))
728 draw_flags |= ILD_BLEND50;
730 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
731 index, himl, left, top, offset);
733 if (draw_masked)
734 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
735 else
736 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
739 /* draws a blank frame for a toolbar button */
740 static void
741 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
743 HDC hdc = tbcd->nmcd.hdc;
744 RECT rc = tbcd->nmcd.rc;
745 /* if the state is disabled or indeterminate then the button
746 * cannot have an interactive look like pressed or hot */
747 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
748 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
749 BOOL pressed_look = !non_interactive_state &&
750 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
751 (tbcd->nmcd.uItemState & CDIS_CHECKED));
753 /* app don't want us to draw any edges */
754 if (dwItemCDFlag & TBCDRF_NOEDGES)
755 return;
757 if (infoPtr->dwStyle & TBSTYLE_FLAT)
759 if (pressed_look)
760 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
761 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
762 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
764 else
766 if (pressed_look)
767 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
768 else
769 DrawEdge (hdc, &rc, EDGE_RAISED,
770 BF_SOFT | BF_RECT | BF_MIDDLE);
774 static void
775 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
777 HDC hdc = tbcd->nmcd.hdc;
778 int offset = 0;
779 BOOL pressed = bDropDownPressed ||
780 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
782 if (infoPtr->dwStyle & TBSTYLE_FLAT)
784 if (pressed)
785 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
786 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
787 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
788 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
789 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
791 else
793 if (pressed)
794 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
795 else
796 DrawEdge (hdc, rcArrow, EDGE_RAISED,
797 BF_SOFT | BF_RECT | BF_MIDDLE);
800 if (pressed)
801 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
803 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
805 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
806 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
808 else
809 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
812 /* draws a complete toolbar button */
813 static void
814 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
816 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
817 DWORD dwStyle = infoPtr->dwStyle;
818 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
819 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
820 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
821 BOOL drawSepDropDownArrow = hasDropDownArrow &&
822 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
823 RECT rc, rcArrow, rcBitmap, rcText;
824 LPWSTR lpText = NULL;
825 NMTBCUSTOMDRAW tbcd;
826 DWORD ntfret;
827 INT offset;
828 INT oldBkMode;
829 DWORD dwItemCustDraw;
830 DWORD dwItemCDFlag;
831 HTHEME theme = GetWindowTheme (hwnd);
833 rc = btnPtr->rect;
834 CopyRect (&rcArrow, &rc);
836 /* separator - doesn't send NM_CUSTOMDRAW */
837 if (btnPtr->fsStyle & BTNS_SEP) {
838 if (theme)
840 DrawThemeBackground (theme, hdc,
841 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
842 &rc, NULL);
844 else
845 /* with the FLAT style, iBitmap is the width and has already */
846 /* been taken into consideration in calculating the width */
847 /* so now we need to draw the vertical separator */
848 /* empirical tests show that iBitmap can/will be non-zero */
849 /* when drawing the vertical bar... */
850 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
851 if (btnPtr->fsStyle & BTNS_DROPDOWN)
852 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
853 else
854 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
856 else if (btnPtr->fsStyle != BTNS_SEP) {
857 FIXME("Draw some kind of separator: fsStyle=%x\n",
858 btnPtr->fsStyle);
860 return;
863 /* get a pointer to the text */
864 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
866 if (hasDropDownArrow)
868 int right;
870 if (dwStyle & TBSTYLE_FLAT)
871 right = max(rc.left, rc.right - DDARROW_WIDTH);
872 else
873 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
875 if (drawSepDropDownArrow)
876 rc.right = right;
878 rcArrow.left = right;
881 /* copy text & bitmap rects after adjusting for drop-down arrow
882 * so that text & bitmap is centred in the rectangle not containing
883 * the arrow */
884 CopyRect(&rcText, &rc);
885 CopyRect(&rcBitmap, &rc);
887 /* Center the bitmap horizontally and vertically */
888 if (dwStyle & TBSTYLE_LIST)
890 if (lpText &&
891 infoPtr->nMaxTextRows > 0 &&
892 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
893 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
894 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
895 else
896 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
898 else
899 rcBitmap.left += ((rc.right - rc.left) - infoPtr->nBitmapWidth) / 2;
901 rcBitmap.top += infoPtr->szPadding.cy / 2;
903 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
904 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
905 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
906 TRACE("Text=%s\n", debugstr_w(lpText));
907 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
909 /* calculate text position */
910 if (lpText)
912 rcText.left += GetSystemMetrics(SM_CXEDGE);
913 rcText.right -= GetSystemMetrics(SM_CXEDGE);
914 if (dwStyle & TBSTYLE_LIST)
916 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
917 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
919 else
921 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
922 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
923 else
924 rcText.top += infoPtr->szPadding.cy/2 + 2;
928 /* Initialize fields in all cases, because we use these later
929 * NOTE: applications can and do alter these to customize their
930 * toolbars */
931 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
932 tbcd.clrText = comctl32_color.clrBtnText;
933 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
934 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
935 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
936 tbcd.clrMark = comctl32_color.clrHighlight;
937 tbcd.clrHighlightHotTrack = 0;
938 tbcd.nStringBkMode = TRANSPARENT;
939 tbcd.nHLStringBkMode = OPAQUE;
940 /* MSDN says that this is the text rectangle.
941 * But (why always a but) tracing of v5.7 of native shows
942 * that this is really a *relative* rectangle based on the
943 * the nmcd.rc. Also the left and top are always 0 ignoring
944 * any bitmap that might be present. */
945 tbcd.rcText.left = 0;
946 tbcd.rcText.top = 0;
947 tbcd.rcText.right = rcText.right - rc.left;
948 tbcd.rcText.bottom = rcText.bottom - rc.top;
949 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
950 tbcd.nmcd.hdc = hdc;
951 tbcd.nmcd.rc = rc;
952 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
954 /* FIXME: what are these used for? */
955 tbcd.hbrLines = 0;
956 tbcd.hpenLines = 0;
958 /* Issue Item Prepaint notify */
959 dwItemCustDraw = 0;
960 dwItemCDFlag = 0;
961 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
963 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
964 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
965 tbcd.nmcd.lItemlParam = btnPtr->dwData;
966 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
967 /* reset these fields so the user can't alter the behaviour like native */
968 tbcd.nmcd.hdc = hdc;
969 tbcd.nmcd.rc = rc;
971 dwItemCustDraw = ntfret & 0xffff;
972 dwItemCDFlag = ntfret & 0xffff0000;
973 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
974 return;
975 /* save the only part of the rect that the user can change */
976 rcText.right = tbcd.rcText.right + rc.left;
977 rcText.bottom = tbcd.rcText.bottom + rc.top;
980 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
981 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
982 OffsetRect(&rcText, 1, 1);
984 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
985 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
986 TOOLBAR_DrawPattern (&rc, &tbcd);
988 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
989 && (tbcd.nmcd.uItemState & CDIS_HOT))
991 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
993 COLORREF oldclr;
995 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
996 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
997 if (hasDropDownArrow)
998 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
999 SetBkColor(hdc, oldclr);
1003 if (theme)
1005 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1006 int stateId = TS_NORMAL;
1008 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1009 stateId = TS_DISABLED;
1010 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1011 stateId = TS_PRESSED;
1012 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1013 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1014 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1015 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1016 stateId = TS_HOT;
1018 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1020 else
1021 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1023 if (drawSepDropDownArrow)
1025 if (theme)
1027 int stateId = TS_NORMAL;
1029 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1030 stateId = TS_DISABLED;
1031 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1032 stateId = TS_PRESSED;
1033 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1034 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1035 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1036 stateId = TS_HOT;
1038 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1039 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1041 else
1042 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1045 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1046 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1047 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1048 SetBkMode (hdc, oldBkMode);
1050 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1052 if (hasDropDownArrow && !drawSepDropDownArrow)
1054 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1056 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1057 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1059 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1061 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1062 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1064 else
1065 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1068 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1070 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1071 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1077 static void
1078 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1080 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1081 TBUTTON_INFO *btnPtr;
1082 INT i;
1083 RECT rcTemp, rcClient;
1084 NMTBCUSTOMDRAW tbcd;
1085 DWORD ntfret;
1086 DWORD dwBaseCustDraw;
1088 /* the app has told us not to redraw the toolbar */
1089 if (!infoPtr->bDoRedraw)
1090 return;
1092 /* if imagelist belongs to the app, it can be changed
1093 by the app after setting it */
1094 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1096 infoPtr->nNumBitmaps = 0;
1097 for (i = 0; i < infoPtr->cimlDef; i++)
1098 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1101 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1103 /* change the imagelist icon size if we manage the list and it is necessary */
1104 TOOLBAR_CheckImageListIconSize(infoPtr);
1106 /* Send initial notify */
1107 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1108 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1109 tbcd.nmcd.hdc = hdc;
1110 tbcd.nmcd.rc = ps->rcPaint;
1111 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1112 dwBaseCustDraw = ntfret & 0xffff;
1114 GetClientRect(hwnd, &rcClient);
1116 /* redraw necessary buttons */
1117 btnPtr = infoPtr->buttons;
1118 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1120 BOOL bDraw;
1121 if (!RectVisible(hdc, &btnPtr->rect))
1122 continue;
1123 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1125 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1126 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1128 else
1129 bDraw = TRUE;
1130 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1131 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1132 if (bDraw)
1133 TOOLBAR_DrawButton(hwnd, btnPtr, hdc, dwBaseCustDraw);
1136 /* draw insert mark if required */
1137 if (infoPtr->tbim.iButton != -1)
1139 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1140 RECT rcInsertMark;
1141 rcInsertMark.top = rcButton.top;
1142 rcInsertMark.bottom = rcButton.bottom;
1143 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1144 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1145 else
1146 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1147 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1150 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1152 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1153 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1154 tbcd.nmcd.hdc = hdc;
1155 tbcd.nmcd.rc = ps->rcPaint;
1156 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1160 /***********************************************************************
1161 * TOOLBAR_MeasureString
1163 * This function gets the width and height of a string in pixels. This
1164 * is done first by using GetTextExtentPoint to get the basic width
1165 * and height. The DrawText is called with DT_CALCRECT to get the exact
1166 * width. The reason is because the text may have more than one "&" (or
1167 * prefix characters as M$ likes to call them). The prefix character
1168 * indicates where the underline goes, except for the string "&&" which
1169 * is reduced to a single "&". GetTextExtentPoint does not process these
1170 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1172 static void
1173 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1174 HDC hdc, LPSIZE lpSize)
1176 RECT myrect;
1178 lpSize->cx = 0;
1179 lpSize->cy = 0;
1181 if (infoPtr->nMaxTextRows > 0 &&
1182 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1183 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1184 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1186 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1188 if(lpText != NULL) {
1189 /* first get size of all the text */
1190 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1192 /* feed above size into the rectangle for DrawText */
1193 myrect.left = myrect.top = 0;
1194 myrect.right = lpSize->cx;
1195 myrect.bottom = lpSize->cy;
1197 /* Use DrawText to get true size as drawn (less pesky "&") */
1198 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1199 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1200 DT_NOPREFIX : 0));
1202 /* feed back to caller */
1203 lpSize->cx = myrect.right;
1204 lpSize->cy = myrect.bottom;
1208 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1211 /***********************************************************************
1212 * TOOLBAR_CalcStrings
1214 * This function walks through each string and measures it and returns
1215 * the largest height and width to caller.
1217 static void
1218 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1220 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1221 TBUTTON_INFO *btnPtr;
1222 INT i;
1223 SIZE sz;
1224 HDC hdc;
1225 HFONT hOldFont;
1227 lpSize->cx = 0;
1228 lpSize->cy = 0;
1230 if (infoPtr->nMaxTextRows == 0)
1231 return;
1233 hdc = GetDC (hwnd);
1234 hOldFont = SelectObject (hdc, infoPtr->hFont);
1236 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1238 TEXTMETRICW tm;
1240 GetTextMetricsW(hdc, &tm);
1241 lpSize->cy = tm.tmHeight;
1244 btnPtr = infoPtr->buttons;
1245 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1246 if(TOOLBAR_HasText(infoPtr, btnPtr))
1248 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1249 if (sz.cx > lpSize->cx)
1250 lpSize->cx = sz.cx;
1251 if (sz.cy > lpSize->cy)
1252 lpSize->cy = sz.cy;
1256 SelectObject (hdc, hOldFont);
1257 ReleaseDC (hwnd, hdc);
1259 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1262 /***********************************************************************
1263 * TOOLBAR_WrapToolbar
1265 * This function walks through the buttons and separators in the
1266 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1267 * wrapping should occur based on the width of the toolbar window.
1268 * It does *not* calculate button placement itself. That task
1269 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1270 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1271 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1273 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1274 * vertical toolbar lists.
1277 static void
1278 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1280 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1281 TBUTTON_INFO *btnPtr;
1282 INT x, cx, i, j;
1283 RECT rc;
1284 BOOL bWrap, bButtonWrap;
1286 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1287 /* no layout is necessary. Applications may use this style */
1288 /* to perform their own layout on the toolbar. */
1289 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1290 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1292 btnPtr = infoPtr->buttons;
1293 x = infoPtr->nIndent;
1295 if (GetParent(hwnd))
1297 /* this can get the parents width, to know how far we can extend
1298 * this toolbar. We cannot use its height, as there may be multiple
1299 * toolbars in a rebar control
1301 GetClientRect( GetParent(hwnd), &rc );
1302 infoPtr->nWidth = rc.right - rc.left;
1304 else
1306 GetWindowRect( hwnd, &rc );
1307 infoPtr->nWidth = rc.right - rc.left;
1310 bButtonWrap = FALSE;
1312 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1313 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1314 infoPtr->nIndent);
1316 for (i = 0; i < infoPtr->nNumButtons; i++ )
1318 bWrap = FALSE;
1319 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1321 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1322 continue;
1324 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1325 /* it is the actual width of the separator. This is used for */
1326 /* custom controls in toolbars. */
1327 /* */
1328 /* BTNS_DROPDOWN separators are treated as buttons for */
1329 /* width. - GA 8/01 */
1330 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1331 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1332 cx = (btnPtr[i].iBitmap > 0) ?
1333 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1334 else
1335 cx = infoPtr->nButtonWidth;
1337 /* Two or more adjacent separators form a separator group. */
1338 /* The first separator in a group should be wrapped to the */
1339 /* next row if the previous wrapping is on a button. */
1340 if( bButtonWrap &&
1341 (btnPtr[i].fsStyle & BTNS_SEP) &&
1342 (i + 1 < infoPtr->nNumButtons ) &&
1343 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1345 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1346 btnPtr[i].fsState |= TBSTATE_WRAP;
1347 x = infoPtr->nIndent;
1348 i++;
1349 bButtonWrap = FALSE;
1350 continue;
1353 /* The layout makes sure the bitmap is visible, but not the button. */
1354 /* Test added to also wrap after a button that starts a row but */
1355 /* is bigger than the area. - GA 8/01 */
1356 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1357 > infoPtr->nWidth ) ||
1358 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1360 BOOL bFound = FALSE;
1362 /* If the current button is a separator and not hidden, */
1363 /* go to the next until it reaches a non separator. */
1364 /* Wrap the last separator if it is before a button. */
1365 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1366 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1367 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1368 i < infoPtr->nNumButtons )
1370 i++;
1371 bFound = TRUE;
1374 if( bFound && i < infoPtr->nNumButtons )
1376 i--;
1377 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1378 i, btnPtr[i].fsStyle, x, cx);
1379 btnPtr[i].fsState |= TBSTATE_WRAP;
1380 x = infoPtr->nIndent;
1381 bButtonWrap = FALSE;
1382 continue;
1384 else if ( i >= infoPtr->nNumButtons)
1385 break;
1387 /* If the current button is not a separator, find the last */
1388 /* separator and wrap it. */
1389 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1391 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1392 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1394 bFound = TRUE;
1395 i = j;
1396 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1397 i, btnPtr[i].fsStyle, x, cx);
1398 x = infoPtr->nIndent;
1399 btnPtr[j].fsState |= TBSTATE_WRAP;
1400 bButtonWrap = FALSE;
1401 break;
1405 /* If no separator available for wrapping, wrap one of */
1406 /* non-hidden previous button. */
1407 if (!bFound)
1409 for ( j = i - 1;
1410 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1412 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1413 continue;
1415 bFound = TRUE;
1416 i = j;
1417 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1418 i, btnPtr[i].fsStyle, x, cx);
1419 x = infoPtr->nIndent;
1420 btnPtr[j].fsState |= TBSTATE_WRAP;
1421 bButtonWrap = TRUE;
1422 break;
1426 /* If all above failed, wrap the current button. */
1427 if (!bFound)
1429 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1430 i, btnPtr[i].fsStyle, x, cx);
1431 btnPtr[i].fsState |= TBSTATE_WRAP;
1432 bFound = TRUE;
1433 x = infoPtr->nIndent;
1434 if (btnPtr[i].fsStyle & BTNS_SEP )
1435 bButtonWrap = FALSE;
1436 else
1437 bButtonWrap = TRUE;
1440 else {
1441 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1442 i, btnPtr[i].fsStyle, x, cx);
1443 x += cx;
1449 /***********************************************************************
1450 * TOOLBAR_MeasureButton
1452 * Calculates the width and height required for a button. Used in
1453 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1454 * the width of buttons that are autosized.
1456 * Note that it would have been rather elegant to use one piece of code for
1457 * both the laying out of the toolbar and for controlling where button parts
1458 * are drawn, but the native control has inconsistencies between the two that
1459 * prevent this from being effectively. These inconsistencies can be seen as
1460 * artefacts where parts of the button appear outside of the bounding button
1461 * rectangle.
1463 * There are several cases for the calculation of the button dimensions and
1464 * button part positioning:
1466 * List
1467 * ====
1469 * With Bitmap:
1471 * +--------------------------------------------------------+ ^
1472 * | ^ ^ | |
1473 * | | pad.cy / 2 | centred | |
1474 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1475 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1476 * | |<------------>| | | | |
1477 * | +--------------+ +------------+ | |
1478 * |<-------------------------------------->| | |
1479 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1480 * | szText.cx | |
1481 * +--------------------------------------------------------+ -
1482 * <-------------------------------------------------------->
1483 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1485 * Without Bitmap (I_IMAGENONE):
1487 * +-----------------------------------+ ^
1488 * | ^ | |
1489 * | | centred | | LISTPAD_CY +
1490 * | +------------+ | | szText.cy
1491 * | | Text | | |
1492 * | | | | |
1493 * | +------------+ | |
1494 * |<----------------->| | |
1495 * | cxedge |<-----------> | |
1496 * | szText.cx | |
1497 * +-----------------------------------+ -
1498 * <----------------------------------->
1499 * szText.cx + pad.cx
1501 * Without text:
1503 * +--------------------------------------+ ^
1504 * | ^ | |
1505 * | | padding.cy/2 | | DEFPAD_CY +
1506 * | +------------+ | | nBitmapHeight
1507 * | | Bitmap | | |
1508 * | | | | |
1509 * | +------------+ | |
1510 * |<------------------->| | |
1511 * | cxedge + iListGap/2 |<-----------> | |
1512 * | nBitmapWidth | |
1513 * +--------------------------------------+ -
1514 * <-------------------------------------->
1515 * 2*cxedge + nBitmapWidth + iListGap
1517 * Non-List
1518 * ========
1520 * With bitmap:
1522 * +-----------------------------------+ ^
1523 * | ^ | |
1524 * | | pad.cy / 2 | | nBitmapHeight +
1525 * | - | | szText.cy +
1526 * | +------------+ | | DEFPAD_CY + 1
1527 * | centred | Bitmap | | |
1528 * |<----------------->| | | |
1529 * | +------------+ | |
1530 * | ^ | |
1531 * | 1 | | |
1532 * | - | |
1533 * | centred +---------------+ | |
1534 * |<--------------->| Text | | |
1535 * | +---------------+ | |
1536 * +-----------------------------------+ -
1537 * <----------------------------------->
1538 * pad.cx + max(nBitmapWidth, szText.cx)
1540 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1542 * +---------------------------------------+ ^
1543 * | ^ | |
1544 * | | 2 + pad.cy / 2 | |
1545 * | - | | szText.cy +
1546 * | centred +-----------------+ | | pad.cy + 2
1547 * |<--------------->| Text | | |
1548 * | +-----------------+ | |
1549 * | | |
1550 * +---------------------------------------+ -
1551 * <--------------------------------------->
1552 * 2*cxedge + pad.cx + szText.cx
1554 * Without text:
1555 * As for with bitmaps, but with szText.cx zero.
1557 static inline SIZE TOOLBAR_MeasureButton(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1559 SIZE sizeButton;
1560 if (infoPtr->dwStyle & TBSTYLE_LIST)
1562 /* set button height from bitmap / text height... */
1563 sizeButton.cy = max((bHasBitmap ? infoPtr->nVBitmapHeight : 0),
1564 sizeString.cy);
1566 /* ... add on the necessary padding */
1567 if (bValidImageList)
1569 if (bHasBitmap)
1570 sizeButton.cy += DEFPAD_CY;
1571 else
1572 sizeButton.cy += LISTPAD_CY;
1574 else
1575 sizeButton.cy += infoPtr->szPadding.cy;
1577 /* calculate button width */
1578 if (bHasBitmap)
1580 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1581 infoPtr->nBitmapWidth + infoPtr->iListGap;
1582 if (sizeString.cx > 0)
1583 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1585 else
1586 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1588 else
1590 if (bHasBitmap)
1592 sizeButton.cy = infoPtr->nVBitmapHeight + DEFPAD_CY;
1593 if (sizeString.cy > 0)
1594 sizeButton.cy += 1 + sizeString.cy;
1595 sizeButton.cx = infoPtr->szPadding.cx +
1596 max(sizeString.cx, infoPtr->nBitmapWidth);
1598 else
1600 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1601 NONLIST_NOTEXT_OFFSET;
1602 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1603 infoPtr->szPadding.cx + sizeString.cx;
1606 return sizeButton;
1610 /***********************************************************************
1611 * TOOLBAR_CalcToolbar
1613 * This function calculates button and separator placement. It first
1614 * calculates the button sizes, gets the toolbar window width and then
1615 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1616 * on. It assigns a new location to each item and sends this location to
1617 * the tooltip window if appropriate. Finally, it updates the rcBound
1618 * rect and calculates the new required toolbar window height.
1620 static void
1621 TOOLBAR_CalcToolbar (HWND hwnd)
1623 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1624 SIZE sizeString, sizeButton;
1625 BOOL validImageList = FALSE;
1627 TOOLBAR_CalcStrings (hwnd, &sizeString);
1629 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1631 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1632 validImageList = TRUE;
1633 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1634 infoPtr->nButtonWidth = sizeButton.cx;
1635 infoPtr->nButtonHeight = sizeButton.cy;
1636 infoPtr->iTopMargin = default_top_margin(infoPtr);
1638 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1639 infoPtr->nButtonWidth = infoPtr->cxMin;
1640 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1641 infoPtr->nButtonWidth = infoPtr->cxMax;
1643 TOOLBAR_LayoutToolbar(hwnd);
1646 static void
1647 TOOLBAR_LayoutToolbar(HWND hwnd)
1649 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1650 TBUTTON_INFO *btnPtr;
1651 SIZE sizeButton;
1652 INT i, nRows, nSepRows;
1653 INT x, y, cx, cy;
1654 BOOL bWrap;
1655 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1656 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1658 TOOLBAR_WrapToolbar(hwnd, infoPtr->dwStyle);
1660 x = infoPtr->nIndent;
1661 y = infoPtr->iTopMargin;
1662 cx = infoPtr->nButtonWidth;
1663 cy = infoPtr->nButtonHeight;
1665 nRows = nSepRows = 0;
1667 infoPtr->rcBound.top = y;
1668 infoPtr->rcBound.left = x;
1669 infoPtr->rcBound.bottom = y + cy;
1670 infoPtr->rcBound.right = x;
1672 btnPtr = infoPtr->buttons;
1674 TRACE("cy=%d\n", cy);
1676 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1678 bWrap = FALSE;
1679 if (btnPtr->fsState & TBSTATE_HIDDEN)
1681 SetRectEmpty (&btnPtr->rect);
1682 continue;
1685 cy = infoPtr->nButtonHeight;
1687 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1688 /* it is the actual width of the separator. This is used for */
1689 /* custom controls in toolbars. */
1690 if (btnPtr->fsStyle & BTNS_SEP) {
1691 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1692 cy = (btnPtr->iBitmap > 0) ?
1693 btnPtr->iBitmap : SEPARATOR_WIDTH;
1694 cx = infoPtr->nButtonWidth;
1696 else
1697 cx = (btnPtr->iBitmap > 0) ?
1698 btnPtr->iBitmap : SEPARATOR_WIDTH;
1700 else
1702 if (btnPtr->cx)
1703 cx = btnPtr->cx;
1704 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1705 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1707 SIZE sz;
1708 HDC hdc;
1709 HFONT hOldFont;
1711 hdc = GetDC (hwnd);
1712 hOldFont = SelectObject (hdc, infoPtr->hFont);
1714 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1716 SelectObject (hdc, hOldFont);
1717 ReleaseDC (hwnd, hdc);
1719 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1720 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1721 validImageList);
1722 cx = sizeButton.cx;
1724 else
1725 cx = infoPtr->nButtonWidth;
1727 /* if size has been set manually then don't add on extra space
1728 * for the drop down arrow */
1729 if (!btnPtr->cx && hasDropDownArrows &&
1730 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1731 cx += DDARROW_WIDTH;
1733 if (btnPtr->fsState & TBSTATE_WRAP )
1734 bWrap = TRUE;
1736 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1738 if (infoPtr->rcBound.left > x)
1739 infoPtr->rcBound.left = x;
1740 if (infoPtr->rcBound.right < x + cx)
1741 infoPtr->rcBound.right = x + cx;
1742 if (infoPtr->rcBound.bottom < y + cy)
1743 infoPtr->rcBound.bottom = y + cy;
1745 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1747 /* btnPtr->nRow is zero based. The space between the rows is */
1748 /* also considered as a row. */
1749 btnPtr->nRow = nRows + nSepRows;
1751 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1752 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1753 x, y, x+cx, y+cy);
1755 if( bWrap )
1757 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1758 y += cy;
1759 else
1761 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1762 /* it is the actual width of the separator. This is used for */
1763 /* custom controls in toolbars. */
1764 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1765 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1766 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1767 else
1768 y += cy;
1770 /* nSepRows is used to calculate the extra height follwoing */
1771 /* the last row. */
1772 nSepRows++;
1774 x = infoPtr->nIndent;
1776 /* Increment row number unless this is the last button */
1777 /* and it has Wrap set. */
1778 if (i != infoPtr->nNumButtons-1)
1779 nRows++;
1781 else
1782 x += cx;
1785 /* infoPtr->nRows is the number of rows on the toolbar */
1786 infoPtr->nRows = nRows + nSepRows + 1;
1788 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1792 static INT
1793 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1795 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1796 TBUTTON_INFO *btnPtr;
1797 INT i;
1799 btnPtr = infoPtr->buttons;
1800 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1801 if (btnPtr->fsState & TBSTATE_HIDDEN)
1802 continue;
1804 if (btnPtr->fsStyle & BTNS_SEP) {
1805 if (PtInRect (&btnPtr->rect, *lpPt)) {
1806 TRACE(" ON SEPARATOR %d!\n", i);
1807 return -i;
1810 else {
1811 if (PtInRect (&btnPtr->rect, *lpPt)) {
1812 TRACE(" ON BUTTON %d!\n", i);
1813 return i;
1818 TRACE(" NOWHERE!\n");
1819 return TOOLBAR_NOWHERE;
1823 static INT
1824 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1826 TBUTTON_INFO *btnPtr;
1827 INT i;
1829 if (CommandIsIndex) {
1830 TRACE("command is really index command=%d\n", idCommand);
1831 if (idCommand >= infoPtr->nNumButtons) return -1;
1832 return idCommand;
1834 btnPtr = infoPtr->buttons;
1835 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1836 if (btnPtr->idCommand == idCommand) {
1837 TRACE("command=%d index=%d\n", idCommand, i);
1838 return i;
1841 TRACE("no index found for command=%d\n", idCommand);
1842 return -1;
1846 static INT
1847 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1849 TBUTTON_INFO *btnPtr;
1850 INT nRunIndex;
1852 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1853 return -1;
1855 /* check index button */
1856 btnPtr = &infoPtr->buttons[nIndex];
1857 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1858 if (btnPtr->fsState & TBSTATE_CHECKED)
1859 return nIndex;
1862 /* check previous buttons */
1863 nRunIndex = nIndex - 1;
1864 while (nRunIndex >= 0) {
1865 btnPtr = &infoPtr->buttons[nRunIndex];
1866 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1867 if (btnPtr->fsState & TBSTATE_CHECKED)
1868 return nRunIndex;
1870 else
1871 break;
1872 nRunIndex--;
1875 /* check next buttons */
1876 nRunIndex = nIndex + 1;
1877 while (nRunIndex < infoPtr->nNumButtons) {
1878 btnPtr = &infoPtr->buttons[nRunIndex];
1879 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1880 if (btnPtr->fsState & TBSTATE_CHECKED)
1881 return nRunIndex;
1883 else
1884 break;
1885 nRunIndex++;
1888 return -1;
1892 static VOID
1893 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1894 WPARAM wParam, LPARAM lParam)
1896 MSG msg;
1898 msg.hwnd = hwndMsg;
1899 msg.message = uMsg;
1900 msg.wParam = wParam;
1901 msg.lParam = lParam;
1902 msg.time = GetMessageTime ();
1903 msg.pt.x = (short)LOWORD(GetMessagePos ());
1904 msg.pt.y = (short)HIWORD(GetMessagePos ());
1906 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1909 static void
1910 TOOLBAR_TooltipAddTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1912 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1913 TTTOOLINFOW ti;
1915 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1916 ti.cbSize = sizeof (TTTOOLINFOW);
1917 ti.hwnd = infoPtr->hwndSelf;
1918 ti.uId = button->idCommand;
1919 ti.hinst = 0;
1920 ti.lpszText = LPSTR_TEXTCALLBACKW;
1921 /* ti.lParam = random value from the stack? */
1923 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1924 0, (LPARAM)&ti);
1928 static void
1929 TOOLBAR_TooltipDelTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1931 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1932 TTTOOLINFOW ti;
1934 ZeroMemory(&ti, sizeof(ti));
1935 ti.cbSize = sizeof(ti);
1936 ti.hwnd = infoPtr->hwndSelf;
1937 ti.uId = button->idCommand;
1939 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1943 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1945 /* Set the toolTip only for non-hidden, non-separator button */
1946 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1948 TTTOOLINFOW ti;
1950 ZeroMemory(&ti, sizeof(ti));
1951 ti.cbSize = sizeof(ti);
1952 ti.hwnd = infoPtr->hwndSelf;
1953 ti.uId = button->idCommand;
1954 ti.rect = button->rect;
1955 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1959 /* Creates the tooltip control */
1960 static void
1961 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
1963 int i;
1964 NMTOOLTIPSCREATED nmttc;
1966 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1967 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1968 infoPtr->hwndSelf, 0, 0, 0);
1970 if (!infoPtr->hwndToolTip)
1971 return;
1973 /* Send NM_TOOLTIPSCREATED notification */
1974 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1975 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
1977 for (i = 0; i < infoPtr->nNumButtons; i++)
1979 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
1980 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
1984 /* keeps available button list box sorted by button id */
1985 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1987 int i;
1988 int count;
1989 PCUSTOMBUTTON btnInfo;
1990 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1992 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1994 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1996 /* position 0 is always separator */
1997 for (i = 1; i < count; i++)
1999 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
2000 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2002 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2003 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2004 return;
2007 /* id higher than all others add to end */
2008 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2009 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2012 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2014 NMTOOLBARW nmtb;
2016 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2018 if (nIndexFrom == nIndexTo)
2019 return;
2021 /* MSDN states that iItem is the index of the button, rather than the
2022 * command ID as used by every other NMTOOLBAR notification */
2023 nmtb.iItem = nIndexFrom;
2024 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2026 PCUSTOMBUTTON btnInfo;
2027 NMHDR hdr;
2028 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2029 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2031 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2033 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2034 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2035 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2036 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2038 if (nIndexTo <= 0)
2039 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2040 else
2041 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2043 /* last item is always separator, so -2 instead of -1 */
2044 if (nIndexTo >= (count - 2))
2045 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2046 else
2047 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2049 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2050 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2052 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2056 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2058 NMTOOLBARW nmtb;
2060 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2062 /* MSDN states that iItem is the index of the button, rather than the
2063 * command ID as used by every other NMTOOLBAR notification */
2064 nmtb.iItem = nIndexAvail;
2065 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2067 PCUSTOMBUTTON btnInfo;
2068 NMHDR hdr;
2069 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2070 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2071 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2073 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2075 if (nIndexAvail != 0) /* index == 0 indicates separator */
2077 /* remove from 'available buttons' list */
2078 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2079 if (nIndexAvail == count-1)
2080 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2081 else
2082 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2084 else
2086 PCUSTOMBUTTON btnNew;
2088 /* duplicate 'separator' button */
2089 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2090 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2091 btnInfo = btnNew;
2094 /* insert into 'toolbar button' list */
2095 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2096 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2098 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2100 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2104 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
2106 PCUSTOMBUTTON btnInfo;
2107 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2109 TRACE("Remove: index %d\n", index);
2111 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2113 /* send TBN_QUERYDELETE notification */
2114 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2116 NMHDR hdr;
2118 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2119 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2121 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2123 /* insert into 'available button' list */
2124 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2125 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2126 else
2127 Free(btnInfo);
2129 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2133 /* drag list notification function for toolbar buttons list box */
2134 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2136 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2137 switch (pDLI->uNotification)
2139 case DL_BEGINDRAG:
2141 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2142 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2143 /* no dragging for last item (separator) */
2144 if (nCurrentItem >= (nCount - 1)) return FALSE;
2145 return TRUE;
2147 case DL_DRAGGING:
2149 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2150 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2151 /* no dragging past last item (separator) */
2152 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2154 DrawInsert(hwnd, hwndList, nCurrentItem);
2155 /* FIXME: native uses "move button" cursor */
2156 return DL_COPYCURSOR;
2159 /* not over toolbar buttons list */
2160 if (nCurrentItem < 0)
2162 POINT ptWindow = pDLI->ptCursor;
2163 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2164 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2165 /* over available buttons list? */
2166 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2167 /* FIXME: native uses "move button" cursor */
2168 return DL_COPYCURSOR;
2170 /* clear drag arrow */
2171 DrawInsert(hwnd, hwndList, -1);
2172 return DL_STOPCURSOR;
2174 case DL_DROPPED:
2176 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2177 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2178 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2179 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2181 /* clear drag arrow */
2182 DrawInsert(hwnd, hwndList, -1);
2183 /* move item */
2184 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2186 /* not over toolbar buttons list */
2187 if (nIndexTo < 0)
2189 POINT ptWindow = pDLI->ptCursor;
2190 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2191 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2192 /* over available buttons list? */
2193 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2194 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2196 break;
2198 case DL_CANCELDRAG:
2199 /* Clear drag arrow */
2200 DrawInsert(hwnd, hwndList, -1);
2201 break;
2204 return 0;
2207 /* drag list notification function for available buttons list box */
2208 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2210 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2211 switch (pDLI->uNotification)
2213 case DL_BEGINDRAG:
2214 return TRUE;
2215 case DL_DRAGGING:
2217 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2218 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2219 /* no dragging past last item (separator) */
2220 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2222 DrawInsert(hwnd, hwndList, nCurrentItem);
2223 /* FIXME: native uses "move button" cursor */
2224 return DL_COPYCURSOR;
2227 /* not over toolbar buttons list */
2228 if (nCurrentItem < 0)
2230 POINT ptWindow = pDLI->ptCursor;
2231 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2232 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2233 /* over available buttons list? */
2234 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2235 /* FIXME: native uses "move button" cursor */
2236 return DL_COPYCURSOR;
2238 /* clear drag arrow */
2239 DrawInsert(hwnd, hwndList, -1);
2240 return DL_STOPCURSOR;
2242 case DL_DROPPED:
2244 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2245 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2246 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2247 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2249 /* clear drag arrow */
2250 DrawInsert(hwnd, hwndList, -1);
2251 /* add item */
2252 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2255 case DL_CANCELDRAG:
2256 /* Clear drag arrow */
2257 DrawInsert(hwnd, hwndList, -1);
2258 break;
2260 return 0;
2263 extern UINT uDragListMessage;
2265 /***********************************************************************
2266 * TOOLBAR_CustomizeDialogProc
2267 * This function implements the toolbar customization dialog.
2269 static INT_PTR CALLBACK
2270 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2272 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2273 PCUSTOMBUTTON btnInfo;
2274 NMTOOLBARA nmtb;
2275 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2277 switch (uMsg)
2279 case WM_INITDIALOG:
2280 custInfo = (PCUSTDLG_INFO)lParam;
2281 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2283 if (custInfo)
2285 WCHAR Buffer[256];
2286 int i = 0;
2287 int index;
2288 NMTBINITCUSTOMIZE nmtbic;
2290 infoPtr = custInfo->tbInfo;
2292 /* send TBN_QUERYINSERT notification */
2293 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2295 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2296 return FALSE;
2298 nmtbic.hwndDialog = hwnd;
2299 /* Send TBN_INITCUSTOMIZE notification */
2300 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2301 TBNRF_HIDEHELP)
2303 TRACE("TBNRF_HIDEHELP requested\n");
2304 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2307 /* add items to 'toolbar buttons' list and check if removable */
2308 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2310 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2311 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2312 btnInfo->btn.fsStyle = BTNS_SEP;
2313 btnInfo->bVirtual = FALSE;
2314 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2316 /* send TBN_QUERYDELETE notification */
2317 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2319 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2320 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2323 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2325 /* insert separator button into 'available buttons' list */
2326 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2327 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2328 btnInfo->btn.fsStyle = BTNS_SEP;
2329 btnInfo->bVirtual = FALSE;
2330 btnInfo->bRemovable = TRUE;
2331 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2332 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2333 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2335 /* insert all buttons into dsa */
2336 for (i = 0;; i++)
2338 /* send TBN_GETBUTTONINFO notification */
2339 NMTOOLBARW nmtb;
2340 nmtb.iItem = i;
2341 nmtb.pszText = Buffer;
2342 nmtb.cchText = 256;
2344 /* Clear previous button's text */
2345 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2347 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2348 break;
2350 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2351 nmtb.tbButton.fsStyle, i,
2352 nmtb.tbButton.idCommand,
2353 nmtb.tbButton.iString,
2354 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2355 : "");
2357 /* insert button into the apropriate list */
2358 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2359 if (index == -1)
2361 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2362 btnInfo->bVirtual = FALSE;
2363 btnInfo->bRemovable = TRUE;
2365 else
2367 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2368 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2371 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2372 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2374 if (lstrlenW(nmtb.pszText))
2375 lstrcpyW(btnInfo->text, nmtb.pszText);
2376 else if (nmtb.tbButton.iString >= 0 &&
2377 nmtb.tbButton.iString < infoPtr->nNumStrings)
2379 lstrcpyW(btnInfo->text,
2380 infoPtr->strings[nmtb.tbButton.iString]);
2384 if (index == -1)
2385 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2388 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2390 /* select first item in the 'available' list */
2391 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2393 /* append 'virtual' separator button to the 'toolbar buttons' list */
2394 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2395 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2396 btnInfo->btn.fsStyle = BTNS_SEP;
2397 btnInfo->bVirtual = TRUE;
2398 btnInfo->bRemovable = FALSE;
2399 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2400 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2401 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2403 /* select last item in the 'toolbar' list */
2404 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2405 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2407 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2408 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2410 /* set focus and disable buttons */
2411 PostMessageW (hwnd, WM_USER, 0, 0);
2413 return TRUE;
2415 case WM_USER:
2416 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2417 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2418 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2419 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2420 return TRUE;
2422 case WM_CLOSE:
2423 EndDialog(hwnd, FALSE);
2424 return TRUE;
2426 case WM_COMMAND:
2427 switch (LOWORD(wParam))
2429 case IDC_TOOLBARBTN_LBOX:
2430 if (HIWORD(wParam) == LBN_SELCHANGE)
2432 PCUSTOMBUTTON btnInfo;
2433 NMTOOLBARA nmtb;
2434 int count;
2435 int index;
2437 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2438 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2440 /* send TBN_QUERYINSERT notification */
2441 nmtb.iItem = index;
2442 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2444 /* get list box item */
2445 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2447 if (index == (count - 1))
2449 /* last item (virtual separator) */
2450 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2451 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2453 else if (index == (count - 2))
2455 /* second last item (last non-virtual item) */
2456 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2457 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2459 else if (index == 0)
2461 /* first item */
2462 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2463 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2465 else
2467 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2468 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2471 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2473 break;
2475 case IDC_MOVEUP_BTN:
2477 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2478 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2480 break;
2482 case IDC_MOVEDN_BTN: /* move down */
2484 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2485 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2487 break;
2489 case IDC_REMOVE_BTN: /* remove button */
2491 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2493 if (LB_ERR == index)
2494 break;
2496 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2498 break;
2499 case IDC_HELP_BTN:
2500 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2501 break;
2502 case IDC_RESET_BTN:
2503 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2504 break;
2506 case IDOK: /* Add button */
2508 int index;
2509 int indexto;
2511 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2512 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2514 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2516 break;
2518 case IDCANCEL:
2519 EndDialog(hwnd, FALSE);
2520 break;
2522 return TRUE;
2524 case WM_DESTROY:
2526 int count;
2527 int i;
2529 /* delete items from 'toolbar buttons' listbox*/
2530 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2531 for (i = 0; i < count; i++)
2533 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2534 Free(btnInfo);
2535 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2537 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2540 /* delete items from 'available buttons' listbox*/
2541 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2542 for (i = 0; i < count; i++)
2544 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2545 Free(btnInfo);
2546 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2548 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2550 return TRUE;
2552 case WM_DRAWITEM:
2553 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2555 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2556 RECT rcButton;
2557 RECT rcText;
2558 HPEN hPen, hOldPen;
2559 HBRUSH hOldBrush;
2560 COLORREF oldText = 0;
2561 COLORREF oldBk = 0;
2563 /* get item data */
2564 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2565 if (btnInfo == NULL)
2567 FIXME("btnInfo invalid!\n");
2568 return TRUE;
2571 /* set colors and select objects */
2572 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2573 if (btnInfo->bVirtual)
2574 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2575 else
2576 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2577 hPen = CreatePen( PS_SOLID, 1,
2578 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2579 hOldPen = SelectObject (lpdis->hDC, hPen );
2580 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2582 /* fill background rectangle */
2583 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2584 lpdis->rcItem.right, lpdis->rcItem.bottom);
2586 /* calculate button and text rectangles */
2587 CopyRect (&rcButton, &lpdis->rcItem);
2588 InflateRect (&rcButton, -1, -1);
2589 CopyRect (&rcText, &rcButton);
2590 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2591 rcText.left = rcButton.right + 2;
2593 /* draw focus rectangle */
2594 if (lpdis->itemState & ODS_FOCUS)
2595 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2597 /* draw button */
2598 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2599 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2601 /* draw image and text */
2602 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2603 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2604 btnInfo->btn.iBitmap));
2605 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2606 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2608 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2609 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2611 /* delete objects and reset colors */
2612 SelectObject (lpdis->hDC, hOldBrush);
2613 SelectObject (lpdis->hDC, hOldPen);
2614 SetBkColor (lpdis->hDC, oldBk);
2615 SetTextColor (lpdis->hDC, oldText);
2616 DeleteObject( hPen );
2617 return TRUE;
2619 return FALSE;
2621 case WM_MEASUREITEM:
2622 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2624 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2626 lpmis->itemHeight = 15 + 8; /* default height */
2628 return TRUE;
2630 return FALSE;
2632 default:
2633 if (uDragListMessage && (uMsg == uDragListMessage))
2635 if (wParam == IDC_TOOLBARBTN_LBOX)
2637 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2638 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2639 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2640 return TRUE;
2642 else if (wParam == IDC_AVAILBTN_LBOX)
2644 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2645 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2646 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2647 return TRUE;
2650 return FALSE;
2654 static BOOL
2655 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2657 HBITMAP hbmLoad;
2658 INT nCountBefore = ImageList_GetImageCount(himlDef);
2659 INT nCountAfter;
2660 INT cxIcon, cyIcon;
2661 INT nAdded;
2662 INT nIndex;
2664 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2665 /* Add bitmaps to the default image list */
2666 if (bitmap->hInst == NULL) /* a handle was passed */
2668 BITMAP bmp;
2669 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2670 HDC hdcImage, hdcBitmap;
2672 /* copy the bitmap before adding it so that the user's bitmap
2673 * doesn't get modified.
2675 GetObjectW ((HBITMAP)bitmap->nID, sizeof(BITMAP), (LPVOID)&bmp);
2677 hdcImage = CreateCompatibleDC(0);
2678 hdcBitmap = CreateCompatibleDC(0);
2680 /* create new bitmap */
2681 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2682 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)bitmap->nID);
2683 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2685 /* Copy the user's image */
2686 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2687 hdcBitmap, 0, 0, SRCCOPY);
2689 SelectObject (hdcImage, hOldBitmapLoad);
2690 SelectObject (hdcBitmap, hOldBitmapBitmap);
2691 DeleteDC (hdcImage);
2692 DeleteDC (hdcBitmap);
2694 else
2695 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2697 /* enlarge the bitmap if needed */
2698 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2699 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2701 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2702 DeleteObject(hbmLoad);
2703 if (nIndex == -1)
2704 return FALSE;
2706 nCountAfter = ImageList_GetImageCount(himlDef);
2707 nAdded = nCountAfter - nCountBefore;
2708 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2710 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2711 } else if (nAdded > (INT)bitmap->nButtons) {
2712 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2713 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2716 infoPtr->nNumBitmaps += nAdded;
2717 return TRUE;
2720 static void
2721 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2723 HIMAGELIST himlDef;
2724 HIMAGELIST himlNew;
2725 INT cx, cy;
2726 INT i;
2728 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2729 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2730 return;
2731 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2732 return;
2733 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2734 return;
2736 TRACE("Update icon size: %dx%d -> %dx%d\n",
2737 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2739 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2740 ILC_COLORDDB|ILC_MASK, 8, 2);
2741 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2742 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2743 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2744 infoPtr->himlInt = himlNew;
2746 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2747 ImageList_Destroy(himlDef);
2750 /***********************************************************************
2751 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2754 static LRESULT
2755 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2757 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2758 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2759 TBITMAP_INFO info;
2760 INT iSumButtons, i;
2761 HIMAGELIST himlDef;
2763 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2764 if (!lpAddBmp)
2765 return -1;
2767 if (lpAddBmp->hInst == HINST_COMMCTRL)
2769 info.hInst = COMCTL32_hModule;
2770 switch (lpAddBmp->nID)
2772 case IDB_STD_SMALL_COLOR:
2773 info.nButtons = 15;
2774 info.nID = IDB_STD_SMALL;
2775 break;
2776 case IDB_STD_LARGE_COLOR:
2777 info.nButtons = 15;
2778 info.nID = IDB_STD_LARGE;
2779 break;
2780 case IDB_VIEW_SMALL_COLOR:
2781 info.nButtons = 12;
2782 info.nID = IDB_VIEW_SMALL;
2783 break;
2784 case IDB_VIEW_LARGE_COLOR:
2785 info.nButtons = 12;
2786 info.nID = IDB_VIEW_LARGE;
2787 break;
2788 case IDB_HIST_SMALL_COLOR:
2789 info.nButtons = 5;
2790 info.nID = IDB_HIST_SMALL;
2791 break;
2792 case IDB_HIST_LARGE_COLOR:
2793 info.nButtons = 5;
2794 info.nID = IDB_HIST_LARGE;
2795 break;
2796 default:
2797 return -1;
2800 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2802 /* Windows resize all the buttons to the size of a newly added standard image */
2803 if (lpAddBmp->nID & 1)
2805 /* large icons */
2806 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2807 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2809 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2810 MAKELPARAM((WORD)24, (WORD)24));
2811 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2812 MAKELPARAM((WORD)31, (WORD)30));
2814 else
2816 /* small icons */
2817 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2818 MAKELPARAM((WORD)16, (WORD)16));
2819 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2820 MAKELPARAM((WORD)22, (WORD)22));
2823 TOOLBAR_CalcToolbar (hwnd);
2825 else
2827 info.nButtons = (INT)wParam;
2828 info.hInst = lpAddBmp->hInst;
2829 info.nID = lpAddBmp->nID;
2830 TRACE("adding %d bitmaps!\n", info.nButtons);
2833 /* check if the bitmap is already loaded and compute iSumButtons */
2834 iSumButtons = 0;
2835 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2837 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2838 infoPtr->bitmaps[i].nID == info.nID)
2839 return iSumButtons;
2840 iSumButtons += infoPtr->bitmaps[i].nButtons;
2843 if (!infoPtr->cimlDef) {
2844 /* create new default image list */
2845 TRACE ("creating default image list!\n");
2847 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2848 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2849 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2850 infoPtr->himlInt = himlDef;
2852 else {
2853 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2856 if (!himlDef) {
2857 WARN("No default image list available\n");
2858 return -1;
2861 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2862 return -1;
2864 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2865 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2866 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2867 infoPtr->nNumBitmapInfos++;
2868 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2870 InvalidateRect(hwnd, NULL, TRUE);
2871 return iSumButtons;
2875 static LRESULT
2876 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2878 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2879 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2880 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2881 BOOL fHasString = FALSE;
2883 TRACE("adding %d buttons (unicode=%d)!\n", wParam, fUnicode);
2885 nAddButtons = (UINT)wParam;
2886 nOldButtons = infoPtr->nNumButtons;
2887 nNewButtons = nOldButtons + nAddButtons;
2889 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
2890 infoPtr->nNumButtons = nNewButtons;
2892 /* insert new button data */
2893 for (nCount = 0; nCount < nAddButtons; nCount++) {
2894 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2895 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2896 btnPtr->idCommand = lpTbb[nCount].idCommand;
2897 btnPtr->fsState = lpTbb[nCount].fsState;
2898 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2899 btnPtr->dwData = lpTbb[nCount].dwData;
2900 btnPtr->bHot = FALSE;
2901 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2903 if (fUnicode)
2904 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2905 else
2906 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString);
2907 fHasString = TRUE;
2909 else
2910 btnPtr->iString = lpTbb[nCount].iString;
2912 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
2915 if (infoPtr->nNumStrings > 0 || fHasString)
2916 TOOLBAR_CalcToolbar(hwnd);
2917 else
2918 TOOLBAR_LayoutToolbar(hwnd);
2919 TOOLBAR_AutoSize (hwnd);
2921 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2923 InvalidateRect(hwnd, NULL, TRUE);
2925 return TRUE;
2929 static LRESULT
2930 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2932 #define MAX_RESOURCE_STRING_LENGTH 512
2933 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2934 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2935 INT nIndex = infoPtr->nNumStrings;
2937 if ((wParam) && (HIWORD(lParam) == 0)) {
2938 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2939 WCHAR delimiter;
2940 WCHAR *next_delim;
2941 WCHAR *p;
2942 INT len;
2943 TRACE("adding string from resource!\n");
2945 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2946 szString, MAX_RESOURCE_STRING_LENGTH);
2948 TRACE("len=%d %s\n", len, debugstr_w(szString));
2949 if (len == 0 || len == 1)
2950 return nIndex;
2952 TRACE("Delimiter: 0x%x\n", *szString);
2953 delimiter = *szString;
2954 p = szString + 1;
2956 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2957 *next_delim = 0;
2958 if (next_delim + 1 >= szString + len)
2960 /* this may happen if delimiter == '\0' or if the last char is a
2961 * delimiter (then it is ignored like the native does) */
2962 break;
2965 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2966 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2967 infoPtr->nNumStrings++;
2969 p = next_delim + 1;
2972 else {
2973 LPWSTR p = (LPWSTR)lParam;
2974 INT len;
2976 if (p == NULL)
2977 return -1;
2978 TRACE("adding string(s) from array!\n");
2979 while (*p) {
2980 len = strlenW (p);
2982 TRACE("len=%d %s\n", len, debugstr_w(p));
2983 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2984 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2985 infoPtr->nNumStrings++;
2987 p += (len+1);
2991 if (fFirstString)
2992 TOOLBAR_CalcToolbar(hwnd);
2993 return nIndex;
2997 static LRESULT
2998 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3000 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3001 BOOL fFirstString = (infoPtr->nNumStrings == 0);
3002 LPSTR p;
3003 INT nIndex;
3004 INT len;
3006 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
3007 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
3009 p = (LPSTR)lParam;
3010 if (p == NULL)
3011 return -1;
3013 TRACE("adding string(s) from array!\n");
3014 nIndex = infoPtr->nNumStrings;
3015 while (*p) {
3016 len = strlen (p);
3017 TRACE("len=%d \"%s\"\n", len, p);
3019 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
3020 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
3021 infoPtr->nNumStrings++;
3023 p += (len+1);
3026 if (fFirstString)
3027 TOOLBAR_CalcToolbar(hwnd);
3028 return nIndex;
3032 static LRESULT
3033 TOOLBAR_AutoSize (HWND hwnd)
3035 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3036 RECT parent_rect;
3037 HWND parent;
3038 INT x, y;
3039 INT cx, cy;
3041 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3043 parent = GetParent (hwnd);
3045 if (!parent || !infoPtr->bDoRedraw)
3046 return 0;
3048 GetClientRect(parent, &parent_rect);
3050 x = parent_rect.left;
3051 y = parent_rect.top;
3053 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3055 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3056 cx = parent_rect.right - parent_rect.left;
3058 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3060 TOOLBAR_LayoutToolbar(hwnd);
3061 InvalidateRect( hwnd, NULL, TRUE );
3064 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3066 RECT window_rect;
3067 UINT uPosFlags = SWP_NOZORDER;
3069 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3071 GetWindowRect(hwnd, &window_rect);
3072 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3073 y = window_rect.top;
3075 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3077 GetWindowRect(hwnd, &window_rect);
3078 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3081 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3082 uPosFlags |= SWP_NOMOVE;
3084 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3085 cy += GetSystemMetrics(SM_CYEDGE);
3087 if (infoPtr->dwStyle & WS_BORDER)
3089 x = y = 1; /* FIXME: this looks wrong */
3090 cy += GetSystemMetrics(SM_CYEDGE);
3091 cx += GetSystemMetrics(SM_CXEDGE);
3094 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3097 return 0;
3101 static LRESULT
3102 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3104 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3106 return infoPtr->nNumButtons;
3110 static LRESULT
3111 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3113 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3115 infoPtr->dwStructSize = (DWORD)wParam;
3117 return 0;
3121 static LRESULT
3122 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3124 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3125 TBUTTON_INFO *btnPtr;
3126 INT nIndex;
3128 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3130 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3131 if (nIndex == -1)
3132 return FALSE;
3134 btnPtr = &infoPtr->buttons[nIndex];
3135 btnPtr->iBitmap = LOWORD(lParam);
3137 /* we HAVE to erase the background, the new bitmap could be */
3138 /* transparent */
3139 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3141 return TRUE;
3145 static LRESULT
3146 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3148 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3149 TBUTTON_INFO *btnPtr;
3150 INT nIndex;
3151 INT nOldIndex = -1;
3152 BOOL bChecked = FALSE;
3154 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3156 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3158 if (nIndex == -1)
3159 return FALSE;
3161 btnPtr = &infoPtr->buttons[nIndex];
3163 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3165 if (LOWORD(lParam) == FALSE)
3166 btnPtr->fsState &= ~TBSTATE_CHECKED;
3167 else {
3168 if (btnPtr->fsStyle & BTNS_GROUP) {
3169 nOldIndex =
3170 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3171 if (nOldIndex == nIndex)
3172 return 0;
3173 if (nOldIndex != -1)
3174 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3176 btnPtr->fsState |= TBSTATE_CHECKED;
3179 if( bChecked != LOWORD(lParam) )
3181 if (nOldIndex != -1)
3182 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3183 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3186 /* FIXME: Send a WM_NOTIFY?? */
3188 return TRUE;
3192 static LRESULT
3193 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3195 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3197 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3201 static LRESULT
3202 TOOLBAR_Customize (HWND hwnd)
3204 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3205 CUSTDLG_INFO custInfo;
3206 LRESULT ret;
3207 LPCVOID template;
3208 HRSRC hRes;
3209 NMHDR nmhdr;
3211 custInfo.tbInfo = infoPtr;
3212 custInfo.tbHwnd = hwnd;
3214 /* send TBN_BEGINADJUST notification */
3215 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3217 if (!(hRes = FindResourceW (COMCTL32_hModule,
3218 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3219 (LPWSTR)RT_DIALOG)))
3220 return FALSE;
3222 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3223 return FALSE;
3225 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3226 (LPCDLGTEMPLATEW)template,
3227 hwnd,
3228 TOOLBAR_CustomizeDialogProc,
3229 (LPARAM)&custInfo);
3231 /* send TBN_ENDADJUST notification */
3232 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3234 return ret;
3238 static LRESULT
3239 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3241 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3242 INT nIndex = (INT)wParam;
3243 NMTOOLBARW nmtb;
3244 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3246 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3247 return FALSE;
3249 memset(&nmtb, 0, sizeof(nmtb));
3250 nmtb.iItem = btnPtr->idCommand;
3251 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3252 nmtb.tbButton.idCommand = btnPtr->idCommand;
3253 nmtb.tbButton.fsState = btnPtr->fsState;
3254 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3255 nmtb.tbButton.dwData = btnPtr->dwData;
3256 nmtb.tbButton.iString = btnPtr->iString;
3257 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3259 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3261 if (infoPtr->nNumButtons == 1) {
3262 TRACE(" simple delete!\n");
3263 Free (infoPtr->buttons);
3264 infoPtr->buttons = NULL;
3265 infoPtr->nNumButtons = 0;
3267 else {
3268 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3269 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3271 infoPtr->nNumButtons--;
3272 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3273 if (nIndex > 0) {
3274 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3275 nIndex * sizeof(TBUTTON_INFO));
3278 if (nIndex < infoPtr->nNumButtons) {
3279 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3280 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3283 Free (oldButtons);
3286 TOOLBAR_LayoutToolbar(hwnd);
3288 InvalidateRect (hwnd, NULL, TRUE);
3290 return TRUE;
3294 static LRESULT
3295 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3297 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3298 TBUTTON_INFO *btnPtr;
3299 INT nIndex;
3300 DWORD bState;
3302 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3304 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3306 if (nIndex == -1)
3307 return FALSE;
3309 btnPtr = &infoPtr->buttons[nIndex];
3311 bState = btnPtr->fsState & TBSTATE_ENABLED;
3313 /* update the toolbar button state */
3314 if(LOWORD(lParam) == FALSE) {
3315 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3316 } else {
3317 btnPtr->fsState |= TBSTATE_ENABLED;
3320 /* redraw the button only if the state of the button changed */
3321 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3322 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3324 return TRUE;
3328 static inline LRESULT
3329 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3331 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3333 return infoPtr->bAnchor;
3337 static LRESULT
3338 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3340 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3341 INT nIndex;
3343 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3344 if (nIndex == -1)
3345 return -1;
3347 return infoPtr->buttons[nIndex].iBitmap;
3351 static inline LRESULT
3352 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3354 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3358 static LRESULT
3359 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3361 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3362 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3363 INT nIndex = (INT)wParam;
3364 TBUTTON_INFO *btnPtr;
3366 if (lpTbb == NULL)
3367 return FALSE;
3369 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3370 return FALSE;
3372 btnPtr = &infoPtr->buttons[nIndex];
3373 lpTbb->iBitmap = btnPtr->iBitmap;
3374 lpTbb->idCommand = btnPtr->idCommand;
3375 lpTbb->fsState = btnPtr->fsState;
3376 lpTbb->fsStyle = btnPtr->fsStyle;
3377 lpTbb->bReserved[0] = 0;
3378 lpTbb->bReserved[1] = 0;
3379 lpTbb->dwData = btnPtr->dwData;
3380 lpTbb->iString = btnPtr->iString;
3382 return TRUE;
3386 static LRESULT
3387 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3389 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3390 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3391 TBUTTON_INFO *btnPtr;
3392 INT nIndex;
3394 if (lpTbInfo == NULL)
3395 return -1;
3396 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3397 return -1;
3399 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3400 lpTbInfo->dwMask & 0x80000000);
3401 if (nIndex == -1)
3402 return -1;
3404 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3406 if (lpTbInfo->dwMask & TBIF_COMMAND)
3407 lpTbInfo->idCommand = btnPtr->idCommand;
3408 if (lpTbInfo->dwMask & TBIF_IMAGE)
3409 lpTbInfo->iImage = btnPtr->iBitmap;
3410 if (lpTbInfo->dwMask & TBIF_LPARAM)
3411 lpTbInfo->lParam = btnPtr->dwData;
3412 if (lpTbInfo->dwMask & TBIF_SIZE)
3413 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3414 if (lpTbInfo->dwMask & TBIF_STATE)
3415 lpTbInfo->fsState = btnPtr->fsState;
3416 if (lpTbInfo->dwMask & TBIF_STYLE)
3417 lpTbInfo->fsStyle = btnPtr->fsStyle;
3418 if (lpTbInfo->dwMask & TBIF_TEXT) {
3419 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3420 can't use TOOLBAR_GetText here */
3421 LPWSTR lpText;
3422 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3423 lpText = (LPWSTR)btnPtr->iString;
3424 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3425 } else
3426 lpTbInfo->pszText[0] = '\0';
3428 return nIndex;
3432 static LRESULT
3433 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3435 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3436 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3437 TBUTTON_INFO *btnPtr;
3438 INT nIndex;
3440 if (lpTbInfo == NULL)
3441 return -1;
3442 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3443 return -1;
3445 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3446 lpTbInfo->dwMask & 0x80000000);
3447 if (nIndex == -1)
3448 return -1;
3450 btnPtr = &infoPtr->buttons[nIndex];
3452 if(!btnPtr)
3453 return -1;
3455 if (lpTbInfo->dwMask & TBIF_COMMAND)
3456 lpTbInfo->idCommand = btnPtr->idCommand;
3457 if (lpTbInfo->dwMask & TBIF_IMAGE)
3458 lpTbInfo->iImage = btnPtr->iBitmap;
3459 if (lpTbInfo->dwMask & TBIF_LPARAM)
3460 lpTbInfo->lParam = btnPtr->dwData;
3461 if (lpTbInfo->dwMask & TBIF_SIZE)
3462 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3463 if (lpTbInfo->dwMask & TBIF_STATE)
3464 lpTbInfo->fsState = btnPtr->fsState;
3465 if (lpTbInfo->dwMask & TBIF_STYLE)
3466 lpTbInfo->fsStyle = btnPtr->fsStyle;
3467 if (lpTbInfo->dwMask & TBIF_TEXT) {
3468 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3469 can't use TOOLBAR_GetText here */
3470 LPWSTR lpText;
3471 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3472 lpText = (LPWSTR)btnPtr->iString;
3473 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3474 } else
3475 lpTbInfo->pszText[0] = '\0';
3478 return nIndex;
3482 static LRESULT
3483 TOOLBAR_GetButtonSize (HWND hwnd)
3485 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3487 return MAKELONG((WORD)infoPtr->nButtonWidth,
3488 (WORD)infoPtr->nButtonHeight);
3492 static LRESULT
3493 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3495 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3496 INT nIndex;
3497 LPWSTR lpText;
3499 if (lParam == 0)
3500 return -1;
3502 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3503 if (nIndex == -1)
3504 return -1;
3506 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3508 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3509 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3513 static LRESULT
3514 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3516 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3517 INT nIndex;
3518 LPWSTR lpText;
3519 LRESULT ret = 0;
3521 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3522 if (nIndex == -1)
3523 return -1;
3525 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3527 if (lpText)
3529 ret = strlenW (lpText);
3531 if (lParam)
3532 strcpyW ((LPWSTR)lParam, lpText);
3535 return ret;
3539 static LRESULT
3540 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3542 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3543 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3544 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3548 inline static LRESULT
3549 TOOLBAR_GetExtendedStyle (HWND hwnd)
3551 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3553 TRACE("\n");
3555 return infoPtr->dwExStyle;
3559 static LRESULT
3560 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3562 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3563 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3564 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3568 static LRESULT
3569 TOOLBAR_GetHotItem (HWND hwnd)
3571 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3573 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3574 return -1;
3576 if (infoPtr->nHotItem < 0)
3577 return -1;
3579 return (LRESULT)infoPtr->nHotItem;
3583 static LRESULT
3584 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3586 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3587 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3588 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3592 static LRESULT
3593 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3595 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3596 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3598 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3600 *lptbim = infoPtr->tbim;
3602 return 0;
3606 static LRESULT
3607 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3609 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3611 TRACE("hwnd = %p\n", hwnd);
3613 return (LRESULT)infoPtr->clrInsertMark;
3617 static LRESULT
3618 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3620 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3621 TBUTTON_INFO *btnPtr;
3622 LPRECT lpRect;
3623 INT nIndex;
3625 nIndex = (INT)wParam;
3626 btnPtr = &infoPtr->buttons[nIndex];
3627 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3628 return FALSE;
3629 lpRect = (LPRECT)lParam;
3630 if (lpRect == NULL)
3631 return FALSE;
3632 if (btnPtr->fsState & TBSTATE_HIDDEN)
3633 return FALSE;
3635 lpRect->left = btnPtr->rect.left;
3636 lpRect->right = btnPtr->rect.right;
3637 lpRect->bottom = btnPtr->rect.bottom;
3638 lpRect->top = btnPtr->rect.top;
3640 return TRUE;
3644 static LRESULT
3645 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3647 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3648 LPSIZE lpSize = (LPSIZE)lParam;
3650 if (lpSize == NULL)
3651 return FALSE;
3653 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3654 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3656 TRACE("maximum size %d x %d\n",
3657 infoPtr->rcBound.right - infoPtr->rcBound.left,
3658 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3660 return TRUE;
3664 /* << TOOLBAR_GetObject >> */
3667 static LRESULT
3668 TOOLBAR_GetPadding (HWND hwnd)
3670 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3671 DWORD oldPad;
3673 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3674 return (LRESULT) oldPad;
3678 static LRESULT
3679 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3681 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3682 TBUTTON_INFO *btnPtr;
3683 LPRECT lpRect;
3684 INT nIndex;
3686 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3687 btnPtr = &infoPtr->buttons[nIndex];
3688 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3689 return FALSE;
3690 lpRect = (LPRECT)lParam;
3691 if (lpRect == NULL)
3692 return FALSE;
3694 lpRect->left = btnPtr->rect.left;
3695 lpRect->right = btnPtr->rect.right;
3696 lpRect->bottom = btnPtr->rect.bottom;
3697 lpRect->top = btnPtr->rect.top;
3699 return TRUE;
3703 static LRESULT
3704 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3706 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3708 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3709 return infoPtr->nRows;
3710 else
3711 return 1;
3715 static LRESULT
3716 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3718 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3719 INT nIndex;
3721 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3722 if (nIndex == -1)
3723 return -1;
3725 return infoPtr->buttons[nIndex].fsState;
3729 static LRESULT
3730 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3732 return GetWindowLongW(hwnd, GWL_STYLE);
3736 static LRESULT
3737 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3739 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3741 return infoPtr->nMaxTextRows;
3745 static LRESULT
3746 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3748 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3750 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3751 TOOLBAR_TooltipCreateControl(infoPtr);
3752 return (LRESULT)infoPtr->hwndToolTip;
3756 static LRESULT
3757 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3759 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3761 TRACE("%s hwnd=%p\n",
3762 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3764 return infoPtr->bUnicode;
3768 inline static LRESULT
3769 TOOLBAR_GetVersion (HWND hwnd)
3771 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3772 return infoPtr->iVersion;
3776 static LRESULT
3777 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3779 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3780 TBUTTON_INFO *btnPtr;
3781 INT nIndex;
3783 TRACE("\n");
3785 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3786 if (nIndex == -1)
3787 return FALSE;
3789 btnPtr = &infoPtr->buttons[nIndex];
3790 if (LOWORD(lParam) == FALSE)
3791 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3792 else
3793 btnPtr->fsState |= TBSTATE_HIDDEN;
3795 TOOLBAR_CalcToolbar (hwnd);
3797 InvalidateRect (hwnd, NULL, TRUE);
3799 return TRUE;
3803 inline static LRESULT
3804 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3806 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3810 static LRESULT
3811 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3813 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3814 TBUTTON_INFO *btnPtr;
3815 INT nIndex;
3816 DWORD oldState;
3818 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3819 if (nIndex == -1)
3820 return FALSE;
3822 btnPtr = &infoPtr->buttons[nIndex];
3823 oldState = btnPtr->fsState;
3824 if (LOWORD(lParam) == FALSE)
3825 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3826 else
3827 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3829 if(oldState != btnPtr->fsState)
3830 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3832 return TRUE;
3836 static LRESULT
3837 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3839 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3840 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3841 INT nIndex = (INT)wParam;
3843 if (lpTbb == NULL)
3844 return FALSE;
3846 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3848 if (nIndex == -1) {
3849 /* EPP: this seems to be an undocumented call (from my IE4)
3850 * I assume in that case that:
3851 * - index of insertion is at the end of existing buttons
3852 * I only see this happen with nIndex == -1, but it could have a special
3853 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3855 nIndex = infoPtr->nNumButtons;
3857 } else if (nIndex < 0)
3858 return FALSE;
3860 TRACE("inserting button index=%d\n", nIndex);
3861 if (nIndex > infoPtr->nNumButtons) {
3862 nIndex = infoPtr->nNumButtons;
3863 TRACE("adjust index=%d\n", nIndex);
3866 infoPtr->nNumButtons++;
3867 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO) * infoPtr->nNumButtons);
3868 memmove(&infoPtr->buttons[nIndex+1], &infoPtr->buttons[nIndex],
3869 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3871 /* insert new button */
3872 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3873 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3874 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3875 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3876 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3877 /* if passed string and not index, then add string */
3878 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3879 if (fUnicode)
3880 Str_SetPtrW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3881 else
3882 Str_SetPtrAtoW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3884 else
3885 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3887 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
3889 if (infoPtr->nNumStrings > 0)
3890 TOOLBAR_CalcToolbar(hwnd);
3891 else
3892 TOOLBAR_LayoutToolbar(hwnd);
3893 TOOLBAR_AutoSize (hwnd);
3895 InvalidateRect (hwnd, NULL, TRUE);
3897 return TRUE;
3900 /* << TOOLBAR_InsertMarkHitTest >> */
3903 static LRESULT
3904 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3906 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3907 INT nIndex;
3909 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3910 if (nIndex == -1)
3911 return FALSE;
3913 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3917 static LRESULT
3918 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3920 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3921 INT nIndex;
3923 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3924 if (nIndex == -1)
3925 return FALSE;
3927 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3931 static LRESULT
3932 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3934 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3935 INT nIndex;
3937 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3938 if (nIndex == -1)
3939 return TRUE;
3941 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3945 static LRESULT
3946 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3948 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3949 INT nIndex;
3951 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3952 if (nIndex == -1)
3953 return FALSE;
3955 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3959 static LRESULT
3960 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3962 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3963 INT nIndex;
3965 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3966 if (nIndex == -1)
3967 return FALSE;
3969 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3973 static LRESULT
3974 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3976 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3977 INT nIndex;
3979 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3980 if (nIndex == -1)
3981 return FALSE;
3983 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3987 static LRESULT
3988 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3990 TBADDBITMAP tbab;
3991 tbab.hInst = (HINSTANCE)lParam;
3992 tbab.nID = (UINT_PTR)wParam;
3994 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3996 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
4000 static LRESULT
4001 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
4003 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4004 WCHAR wAccel = (WCHAR)wParam;
4005 UINT* pIDButton = (UINT*)lParam;
4006 WCHAR wszAccel[] = {'&',wAccel,0};
4007 int i;
4009 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4010 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4012 for (i = 0; i < infoPtr->nNumButtons; i++)
4014 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4015 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4016 !(btnPtr->fsState & TBSTATE_HIDDEN))
4018 int iLen = strlenW(wszAccel);
4019 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4021 if (!lpszStr)
4022 continue;
4024 while (*lpszStr)
4026 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4028 lpszStr += 2;
4029 continue;
4031 if (!strncmpiW(lpszStr, wszAccel, iLen))
4033 *pIDButton = btnPtr->idCommand;
4034 return TRUE;
4036 lpszStr++;
4040 return FALSE;
4044 static LRESULT
4045 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4047 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4048 INT nIndex;
4049 DWORD oldState;
4050 TBUTTON_INFO *btnPtr;
4052 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4054 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4055 if (nIndex == -1)
4056 return FALSE;
4058 btnPtr = &infoPtr->buttons[nIndex];
4059 oldState = btnPtr->fsState;
4061 if (LOWORD(lParam))
4062 btnPtr->fsState |= TBSTATE_MARKED;
4063 else
4064 btnPtr->fsState &= ~TBSTATE_MARKED;
4066 if(oldState != btnPtr->fsState)
4067 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4069 return TRUE;
4073 /* fixes up an index of a button affected by a move */
4074 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4076 if (bMoveUp)
4078 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4079 (*pIndex)--;
4080 else if (*pIndex == nIndex)
4081 *pIndex = nMoveIndex;
4083 else
4085 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4086 (*pIndex)++;
4087 else if (*pIndex == nIndex)
4088 *pIndex = nMoveIndex;
4093 static LRESULT
4094 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4096 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4097 INT nIndex;
4098 INT nCount;
4099 INT nMoveIndex = (INT)lParam;
4100 TBUTTON_INFO button;
4102 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4104 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4105 if ((nIndex == -1) || (nMoveIndex < 0))
4106 return FALSE;
4108 if (nMoveIndex > infoPtr->nNumButtons - 1)
4109 nMoveIndex = infoPtr->nNumButtons - 1;
4111 button = infoPtr->buttons[nIndex];
4113 /* move button right */
4114 if (nIndex < nMoveIndex)
4116 nCount = nMoveIndex - nIndex;
4117 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4118 infoPtr->buttons[nMoveIndex] = button;
4120 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4121 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4122 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4123 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4125 else if (nIndex > nMoveIndex) /* move button left */
4127 nCount = nIndex - nMoveIndex;
4128 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4129 infoPtr->buttons[nMoveIndex] = button;
4131 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4132 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4133 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4134 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4137 TOOLBAR_CalcToolbar(hwnd);
4138 TOOLBAR_AutoSize(hwnd);
4139 InvalidateRect(hwnd, NULL, TRUE);
4141 return TRUE;
4145 static LRESULT
4146 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4148 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4149 TBUTTON_INFO *btnPtr;
4150 INT nIndex;
4151 DWORD oldState;
4153 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4154 if (nIndex == -1)
4155 return FALSE;
4157 btnPtr = &infoPtr->buttons[nIndex];
4158 oldState = btnPtr->fsState;
4159 if (LOWORD(lParam) == FALSE)
4160 btnPtr->fsState &= ~TBSTATE_PRESSED;
4161 else
4162 btnPtr->fsState |= TBSTATE_PRESSED;
4164 if(oldState != btnPtr->fsState)
4165 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4167 return TRUE;
4170 /* FIXME: there might still be some confusion her between number of buttons
4171 * and number of bitmaps */
4172 static LRESULT
4173 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4175 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4176 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4177 HBITMAP hBitmap;
4178 HBITMAP hbmLoad = NULL;
4179 int i = 0, nOldButtons = 0, pos = 0;
4180 int nOldBitmaps, nNewBitmaps = 0;
4181 HIMAGELIST himlDef = 0;
4183 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4184 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4185 lpReplace->nButtons);
4187 if (lpReplace->hInstOld == HINST_COMMCTRL)
4189 FIXME("changing standard bitmaps not implemented\n");
4190 return FALSE;
4192 else if (lpReplace->hInstOld != 0)
4193 FIXME("resources not in the current module not implemented\n");
4195 if (lpReplace->hInstNew)
4197 hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4198 hBitmap = hbmLoad;
4200 else
4202 hBitmap = (HBITMAP) lpReplace->nIDNew;
4205 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4206 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4207 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4208 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4209 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4211 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4212 nOldButtons = tbi->nButtons;
4213 tbi->nButtons = lpReplace->nButtons;
4214 tbi->hInst = lpReplace->hInstNew;
4215 tbi->nID = lpReplace->nIDNew;
4216 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4217 break;
4219 pos += tbi->nButtons;
4222 if (nOldButtons == 0)
4224 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4225 if (hbmLoad)
4226 DeleteObject (hbmLoad);
4227 return FALSE;
4230 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4231 nOldBitmaps = ImageList_GetImageCount(himlDef);
4233 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4235 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4236 ImageList_Remove(himlDef, i);
4238 if (hBitmap)
4240 BITMAP bmp;
4241 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4242 HDC hdcImage, hdcBitmap;
4244 /* copy the bitmap before adding it so that the user's bitmap
4245 * doesn't get modified.
4247 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4249 hdcImage = CreateCompatibleDC(0);
4250 hdcBitmap = CreateCompatibleDC(0);
4252 /* create new bitmap */
4253 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4254 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4255 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4257 /* Copy the user's image */
4258 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4259 hdcBitmap, 0, 0, SRCCOPY);
4261 SelectObject (hdcImage, hOldBitmapLoad);
4262 SelectObject (hdcBitmap, hOldBitmapBitmap);
4263 DeleteDC (hdcImage);
4264 DeleteDC (hdcBitmap);
4266 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4267 nNewBitmaps = ImageList_GetImageCount(himlDef);
4268 DeleteObject (hbmLoad);
4271 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4273 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4274 pos, nOldBitmaps, nNewBitmaps);
4276 InvalidateRect(hwnd, NULL, TRUE);
4278 if (hbmLoad)
4279 DeleteObject (hbmLoad);
4280 return TRUE;
4284 /* helper for TOOLBAR_SaveRestoreW */
4285 static BOOL
4286 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4288 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4289 debugstr_w(lpSave->pszValueName));
4291 return FALSE;
4295 /* helper for TOOLBAR_Restore */
4296 static void
4297 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4299 INT i;
4301 for (i = 0; i < infoPtr->nNumButtons; i++)
4303 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4306 Free(infoPtr->buttons);
4307 infoPtr->buttons = NULL;
4308 infoPtr->nNumButtons = 0;
4312 /* helper for TOOLBAR_SaveRestoreW */
4313 static BOOL
4314 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4316 LONG res;
4317 HKEY hkey = NULL;
4318 BOOL ret = FALSE;
4319 DWORD dwType;
4320 DWORD dwSize = 0;
4321 NMTBRESTORE nmtbr;
4323 /* restore toolbar information */
4324 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4325 debugstr_w(lpSave->pszValueName));
4327 memset(&nmtbr, 0, sizeof(nmtbr));
4329 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4330 KEY_QUERY_VALUE, &hkey);
4331 if (!res)
4332 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4333 NULL, &dwSize);
4334 if (!res && dwType != REG_BINARY)
4335 res = ERROR_FILE_NOT_FOUND;
4336 if (!res)
4338 nmtbr.pData = Alloc(dwSize);
4339 nmtbr.cbData = (UINT)dwSize;
4340 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4342 if (!res)
4343 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4344 (LPBYTE)nmtbr.pData, &dwSize);
4345 if (!res)
4347 nmtbr.pCurrent = nmtbr.pData;
4348 nmtbr.iItem = -1;
4349 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4350 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4352 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4354 INT i;
4356 /* remove all existing buttons as this function is designed to
4357 * restore the toolbar to a previously saved state */
4358 TOOLBAR_DeleteAllButtons(infoPtr);
4360 for (i = 0; i < nmtbr.cButtons; i++)
4362 nmtbr.iItem = i;
4363 nmtbr.tbButton.iBitmap = -1;
4364 nmtbr.tbButton.fsState = 0;
4365 nmtbr.tbButton.fsStyle = 0;
4366 nmtbr.tbButton.idCommand = 0;
4367 if (*nmtbr.pCurrent == (DWORD)-1)
4369 /* separator */
4370 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4371 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4373 else if (*nmtbr.pCurrent == (DWORD)-2)
4374 /* hidden button */
4375 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4376 else
4377 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4379 nmtbr.pCurrent++;
4381 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4383 /* can't contain real string as we don't know whether
4384 * the client put an ANSI or Unicode string in there */
4385 if (HIWORD(nmtbr.tbButton.iString))
4386 nmtbr.tbButton.iString = 0;
4388 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4389 (LPARAM)&nmtbr.tbButton, TRUE);
4392 /* do legacy notifications */
4393 if (infoPtr->iVersion < 5)
4395 /* FIXME: send TBN_BEGINADJUST */
4396 FIXME("send TBN_GETBUTTONINFO for each button\n");
4397 /* FIXME: send TBN_ENDADJUST */
4400 /* remove all uninitialised buttons
4401 * note: loop backwards to avoid having to fixup i on a
4402 * delete */
4403 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4404 if (infoPtr->buttons[i].iBitmap == -1)
4405 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4407 /* only indicate success if at least one button survived */
4408 if (infoPtr->nNumButtons > 0) ret = TRUE;
4411 Free (nmtbr.pData);
4412 RegCloseKey(hkey);
4414 return ret;
4418 static LRESULT
4419 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4421 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4423 if (lpSave == NULL) return 0;
4425 if (wParam)
4426 return TOOLBAR_Save(infoPtr, lpSave);
4427 else
4428 return TOOLBAR_Restore(infoPtr, lpSave);
4432 static LRESULT
4433 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4435 LPWSTR pszValueName = 0, pszSubKey = 0;
4436 TBSAVEPARAMSW SaveW;
4437 LRESULT result = 0;
4438 int len;
4440 if (lpSave == NULL) return 0;
4442 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4443 pszSubKey = Alloc(len * sizeof(WCHAR));
4444 if (pszSubKey) goto exit;
4445 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4447 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4448 pszValueName = Alloc(len * sizeof(WCHAR));
4449 if (!pszValueName) goto exit;
4450 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4452 SaveW.pszValueName = pszValueName;
4453 SaveW.pszSubKey = pszSubKey;
4454 SaveW.hkr = lpSave->hkr;
4455 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4457 exit:
4458 Free (pszValueName);
4459 Free (pszSubKey);
4461 return result;
4465 static LRESULT
4466 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4468 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4469 BOOL bOldAnchor = infoPtr->bAnchor;
4471 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4473 infoPtr->bAnchor = (BOOL)wParam;
4475 /* Native does not remove the hot effect from an already hot button */
4477 return (LRESULT)bOldAnchor;
4481 static LRESULT
4482 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4484 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4485 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4487 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4489 if (wParam != 0)
4490 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4492 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4493 lParam = MAKELPARAM(16, 15);
4495 if (infoPtr->nNumButtons > 0)
4496 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4497 infoPtr->nNumButtons,
4498 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4499 LOWORD(lParam), HIWORD(lParam));
4501 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4502 infoPtr->nVBitmapHeight = infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4504 if ((himlDef == infoPtr->himlInt) &&
4505 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4507 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4508 infoPtr->nBitmapHeight);
4511 TOOLBAR_CalcToolbar(hwnd);
4512 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4513 return TRUE;
4517 static LRESULT
4518 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4520 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4521 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4522 TBUTTON_INFO *btnPtr;
4523 INT nIndex;
4524 RECT oldBtnRect;
4526 if (lptbbi == NULL)
4527 return FALSE;
4528 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4529 return FALSE;
4531 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4532 lptbbi->dwMask & 0x80000000);
4533 if (nIndex == -1)
4534 return FALSE;
4536 btnPtr = &infoPtr->buttons[nIndex];
4537 if (lptbbi->dwMask & TBIF_COMMAND)
4538 btnPtr->idCommand = lptbbi->idCommand;
4539 if (lptbbi->dwMask & TBIF_IMAGE)
4540 btnPtr->iBitmap = lptbbi->iImage;
4541 if (lptbbi->dwMask & TBIF_LPARAM)
4542 btnPtr->dwData = lptbbi->lParam;
4543 if (lptbbi->dwMask & TBIF_SIZE)
4544 btnPtr->cx = lptbbi->cx;
4545 if (lptbbi->dwMask & TBIF_STATE)
4546 btnPtr->fsState = lptbbi->fsState;
4547 if (lptbbi->dwMask & TBIF_STYLE)
4548 btnPtr->fsStyle = lptbbi->fsStyle;
4550 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4551 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4552 /* iString is index, zero it to make Str_SetPtr succeed */
4553 btnPtr->iString=0;
4555 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4558 /* save the button rect to see if we need to redraw the whole toolbar */
4559 oldBtnRect = btnPtr->rect;
4560 TOOLBAR_CalcToolbar(hwnd);
4562 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4563 InvalidateRect(hwnd, NULL, TRUE);
4564 else
4565 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4567 return TRUE;
4571 static LRESULT
4572 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4574 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4575 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4576 TBUTTON_INFO *btnPtr;
4577 INT nIndex;
4578 RECT oldBtnRect;
4580 if (lptbbi == NULL)
4581 return FALSE;
4582 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4583 return FALSE;
4585 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4586 lptbbi->dwMask & 0x80000000);
4587 if (nIndex == -1)
4588 return FALSE;
4590 btnPtr = &infoPtr->buttons[nIndex];
4591 if (lptbbi->dwMask & TBIF_COMMAND)
4592 btnPtr->idCommand = lptbbi->idCommand;
4593 if (lptbbi->dwMask & TBIF_IMAGE)
4594 btnPtr->iBitmap = lptbbi->iImage;
4595 if (lptbbi->dwMask & TBIF_LPARAM)
4596 btnPtr->dwData = lptbbi->lParam;
4597 if (lptbbi->dwMask & TBIF_SIZE)
4598 btnPtr->cx = lptbbi->cx;
4599 if (lptbbi->dwMask & TBIF_STATE)
4600 btnPtr->fsState = lptbbi->fsState;
4601 if (lptbbi->dwMask & TBIF_STYLE)
4602 btnPtr->fsStyle = lptbbi->fsStyle;
4604 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4605 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4606 /* iString is index, zero it to make Str_SetPtr succeed */
4607 btnPtr->iString=0;
4608 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4611 /* save the button rect to see if we need to redraw the whole toolbar */
4612 oldBtnRect = btnPtr->rect;
4613 TOOLBAR_CalcToolbar(hwnd);
4615 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4616 InvalidateRect(hwnd, NULL, TRUE);
4617 else
4618 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4620 return TRUE;
4624 static LRESULT
4625 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4627 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4628 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4630 if ((cx < 0) || (cy < 0))
4632 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4633 return FALSE;
4636 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4638 /* The documentation claims you can only change the button size before
4639 * any button has been added. But this is wrong.
4640 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4641 * it to the toolbar, and it checks that the return value is nonzero - mjm
4642 * Further testing shows that we must actually perform the change too.
4645 * The documentation also does not mention that if 0 is supplied for
4646 * either size, the system changes it to the default of 24 wide and
4647 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4649 if (cx == 0) cx = 24;
4650 if (cy == 0) cx = 22;
4652 cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
4653 cy = max(cy, infoPtr->szPadding.cy + infoPtr->nVBitmapHeight);
4655 infoPtr->nButtonWidth = cx;
4656 infoPtr->nButtonHeight = cy;
4658 infoPtr->iTopMargin = default_top_margin(infoPtr);
4659 TOOLBAR_LayoutToolbar(hwnd);
4660 return TRUE;
4664 static LRESULT
4665 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4667 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4669 /* if setting to current values, ignore */
4670 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4671 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4672 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4673 infoPtr->cxMin, infoPtr->cxMax);
4674 return TRUE;
4677 /* save new values */
4678 infoPtr->cxMin = (short)LOWORD(lParam);
4679 infoPtr->cxMax = (short)HIWORD(lParam);
4681 /* otherwise we need to recalc the toolbar and in some cases
4682 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4683 which doesn't actually draw - GA). */
4684 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4685 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4687 TOOLBAR_CalcToolbar (hwnd);
4689 InvalidateRect (hwnd, NULL, TRUE);
4691 return TRUE;
4695 static LRESULT
4696 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4698 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4699 INT nIndex = (INT)wParam;
4701 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4702 return FALSE;
4704 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4706 if (infoPtr->hwndToolTip) {
4708 FIXME("change tool tip!\n");
4712 return TRUE;
4716 static LRESULT
4717 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4719 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4720 HIMAGELIST himl = (HIMAGELIST)lParam;
4721 HIMAGELIST himlTemp;
4722 INT id = 0;
4724 if (infoPtr->iVersion >= 5)
4725 id = wParam;
4727 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4728 &infoPtr->cimlDis, himl, id);
4730 /* FIXME: redraw ? */
4732 return (LRESULT)himlTemp;
4736 static LRESULT
4737 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4739 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4740 DWORD dwTemp;
4742 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4744 dwTemp = infoPtr->dwDTFlags;
4745 infoPtr->dwDTFlags =
4746 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4748 return (LRESULT)dwTemp;
4751 /* This function differs a bit from what MSDN says it does:
4752 * 1. lParam contains extended style flags to OR with current style
4753 * (MSDN isn't clear on the OR bit)
4754 * 2. wParam appears to contain extended style flags to be reset
4755 * (MSDN says that this parameter is reserved)
4757 static LRESULT
4758 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4760 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4761 DWORD dwTemp;
4763 dwTemp = infoPtr->dwExStyle;
4764 infoPtr->dwExStyle &= ~wParam;
4765 infoPtr->dwExStyle |= (DWORD)lParam;
4767 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4769 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4770 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4771 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4773 TOOLBAR_CalcToolbar (hwnd);
4775 TOOLBAR_AutoSize(hwnd);
4777 InvalidateRect(hwnd, NULL, TRUE);
4779 return (LRESULT)dwTemp;
4783 static LRESULT
4784 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4786 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4787 HIMAGELIST himlTemp;
4788 HIMAGELIST himl = (HIMAGELIST)lParam;
4789 INT id = 0;
4791 if (infoPtr->iVersion >= 5)
4792 id = wParam;
4794 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4796 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4797 &infoPtr->cimlHot, himl, id);
4799 /* FIXME: redraw ? */
4801 return (LRESULT)himlTemp;
4805 /* Makes previous hot button no longer hot, makes the specified
4806 * button hot and sends appropriate notifications. dwReason is one or
4807 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4808 * NOTE 1: this function does not validate nHit
4809 * NOTE 2: the name of this function is completely made up and
4810 * not based on any documentation from Microsoft. */
4811 static void
4812 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4814 if (infoPtr->nHotItem != nHit)
4816 NMTBHOTITEM nmhotitem;
4817 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4819 nmhotitem.dwFlags = dwReason;
4820 if(infoPtr->nHotItem >= 0)
4822 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4823 nmhotitem.idOld = oldBtnPtr->idCommand;
4825 else
4827 nmhotitem.dwFlags |= HICF_ENTERING;
4828 nmhotitem.idOld = 0;
4831 if (nHit >= 0)
4833 btnPtr = &infoPtr->buttons[nHit];
4834 nmhotitem.idNew = btnPtr->idCommand;
4836 else
4838 nmhotitem.dwFlags |= HICF_LEAVING;
4839 nmhotitem.idNew = 0;
4842 /* now change the hot and invalidate the old and new buttons - if the
4843 * parent agrees */
4844 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4846 if (oldBtnPtr) {
4847 oldBtnPtr->bHot = FALSE;
4848 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4850 /* setting disabled buttons as hot fails even if the notify contains the button id */
4851 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4852 btnPtr->bHot = TRUE;
4853 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4854 infoPtr->nHotItem = nHit;
4856 else
4857 infoPtr->nHotItem = -1;
4862 static LRESULT
4863 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4865 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4866 INT nOldHotItem = infoPtr->nHotItem;
4868 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4870 if ((INT)wParam > infoPtr->nNumButtons)
4871 return infoPtr->nHotItem;
4873 if ((INT)wParam < 0)
4874 wParam = -1;
4876 /* NOTE: an application can still remove the hot item even if anchor
4877 * highlighting is enabled */
4879 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4881 if (nOldHotItem < 0)
4882 return -1;
4884 return (LRESULT)nOldHotItem;
4888 static LRESULT
4889 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4891 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4892 HIMAGELIST himlTemp;
4893 HIMAGELIST himl = (HIMAGELIST)lParam;
4894 INT i, id = 0;
4896 if (infoPtr->iVersion >= 5)
4897 id = wParam;
4899 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4900 &infoPtr->cimlDef, himl, id);
4902 infoPtr->nNumBitmaps = 0;
4903 for (i = 0; i < infoPtr->cimlDef; i++)
4904 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4906 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4907 &infoPtr->nBitmapHeight))
4909 infoPtr->nBitmapWidth = 1;
4910 infoPtr->nBitmapHeight = 1;
4912 infoPtr->nVBitmapHeight = infoPtr->nBitmapHeight;
4914 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4915 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4916 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4918 InvalidateRect(hwnd, NULL, TRUE);
4920 return (LRESULT)himlTemp;
4924 static LRESULT
4925 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4927 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4929 infoPtr->nIndent = (INT)wParam;
4931 TRACE("\n");
4933 /* process only on indent changing */
4934 if(infoPtr->nIndent != (INT)wParam)
4936 infoPtr->nIndent = (INT)wParam;
4937 TOOLBAR_CalcToolbar (hwnd);
4938 InvalidateRect(hwnd, NULL, FALSE);
4941 return TRUE;
4945 static LRESULT
4946 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4948 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4949 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4951 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4953 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4955 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4956 return 0;
4959 if ((lptbim->iButton == -1) ||
4960 ((lptbim->iButton < infoPtr->nNumButtons) &&
4961 (lptbim->iButton >= 0)))
4963 infoPtr->tbim = *lptbim;
4964 /* FIXME: don't need to update entire toolbar */
4965 InvalidateRect(hwnd, NULL, TRUE);
4967 else
4968 ERR("Invalid button index %d\n", lptbim->iButton);
4970 return 0;
4974 static LRESULT
4975 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4977 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4979 infoPtr->clrInsertMark = (COLORREF)lParam;
4981 /* FIXME: don't need to update entire toolbar */
4982 InvalidateRect(hwnd, NULL, TRUE);
4984 return 0;
4988 static LRESULT
4989 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4991 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4993 infoPtr->nMaxTextRows = (INT)wParam;
4995 TOOLBAR_CalcToolbar(hwnd);
4996 return TRUE;
5000 /* MSDN gives slightly wrong info on padding.
5001 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
5002 * 2. It is not used to create a blank area between the edge of the button
5003 * and the text or image if TBSTYLE_LIST is set. It is used to control
5004 * the gap between the image and text.
5005 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
5006 * to control the bottom and right borders [with the border being
5007 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
5008 * is shared evenly on both sides of the button.
5009 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
5011 static LRESULT
5012 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
5014 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5015 DWORD oldPad;
5017 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5018 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
5019 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
5020 TRACE("cx=%d, cy=%d\n",
5021 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5022 return (LRESULT) oldPad;
5026 static LRESULT
5027 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5029 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5030 HWND hwndOldNotify;
5032 TRACE("\n");
5034 hwndOldNotify = infoPtr->hwndNotify;
5035 infoPtr->hwndNotify = (HWND)wParam;
5037 return (LRESULT)hwndOldNotify;
5041 static LRESULT
5042 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5044 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5045 LPRECT lprc = (LPRECT)lParam;
5047 TRACE("\n");
5049 if (LOWORD(wParam) > 1) {
5050 FIXME("multiple rows not supported!\n");
5053 if(infoPtr->nRows != LOWORD(wParam))
5055 infoPtr->nRows = LOWORD(wParam);
5057 /* recalculate toolbar */
5058 TOOLBAR_CalcToolbar (hwnd);
5060 /* repaint toolbar */
5061 InvalidateRect(hwnd, NULL, TRUE);
5064 /* return bounding rectangle */
5065 if (lprc) {
5066 lprc->left = infoPtr->rcBound.left;
5067 lprc->right = infoPtr->rcBound.right;
5068 lprc->top = infoPtr->rcBound.top;
5069 lprc->bottom = infoPtr->rcBound.bottom;
5072 return 0;
5076 static LRESULT
5077 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5079 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5080 TBUTTON_INFO *btnPtr;
5081 INT nIndex;
5083 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5084 if (nIndex == -1)
5085 return FALSE;
5087 btnPtr = &infoPtr->buttons[nIndex];
5089 /* if hidden state has changed the invalidate entire window and recalc */
5090 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5091 btnPtr->fsState = LOWORD(lParam);
5092 TOOLBAR_CalcToolbar (hwnd);
5093 InvalidateRect(hwnd, 0, TRUE);
5094 return TRUE;
5097 /* process state changing if current state doesn't match new state */
5098 if(btnPtr->fsState != LOWORD(lParam))
5100 btnPtr->fsState = LOWORD(lParam);
5101 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5104 return TRUE;
5108 static LRESULT
5109 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5111 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5113 return TRUE;
5117 inline static LRESULT
5118 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5120 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5122 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5124 infoPtr->hwndToolTip = (HWND)wParam;
5125 return 0;
5129 static LRESULT
5130 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5132 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5133 BOOL bTemp;
5135 TRACE("%s hwnd=%p\n",
5136 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5138 bTemp = infoPtr->bUnicode;
5139 infoPtr->bUnicode = (BOOL)wParam;
5141 return bTemp;
5145 static LRESULT
5146 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5148 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5150 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5151 comctl32_color.clrBtnHighlight :
5152 infoPtr->clrBtnHighlight;
5153 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5154 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5155 return 1;
5159 static LRESULT
5160 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5162 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5164 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5165 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5166 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5168 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5169 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5170 InvalidateRect(hwnd, NULL, TRUE);
5171 return 0;
5175 static LRESULT
5176 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5178 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5179 INT iOldVersion = infoPtr->iVersion;
5181 infoPtr->iVersion = iVersion;
5183 if (infoPtr->iVersion >= 5)
5184 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5186 return iOldVersion;
5190 static LRESULT
5191 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5193 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5194 WORD iString = HIWORD(wParam);
5195 WORD buffersize = LOWORD(wParam);
5196 LPSTR str = (LPSTR)lParam;
5197 LRESULT ret = -1;
5199 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5201 if (iString < infoPtr->nNumStrings)
5203 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5205 TRACE("returning %s\n", debugstr_a(str));
5207 else
5208 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5210 return ret;
5214 static LRESULT
5215 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5217 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5218 WORD iString = HIWORD(wParam);
5219 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5220 LPWSTR str = (LPWSTR)lParam;
5221 LRESULT ret = -1;
5223 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5225 if (iString < infoPtr->nNumStrings)
5227 len = min(len, strlenW(infoPtr->strings[iString]));
5228 ret = (len+1)*sizeof(WCHAR);
5229 memcpy(str, infoPtr->strings[iString], ret);
5230 str[len] = '\0';
5232 TRACE("returning %s\n", debugstr_w(str));
5234 else
5235 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5237 return ret;
5240 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5241 * is the maximum size of the toolbar? */
5242 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5244 SIZE * pSize = (SIZE*)lParam;
5245 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5246 return 0;
5250 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5251 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5252 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5253 * sends). */
5254 static LRESULT
5255 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5257 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5258 INT nOldHotItem = infoPtr->nHotItem;
5260 TRACE("old item=%d, new item=%d, flags=%08x\n",
5261 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5263 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5264 wParam = -1;
5266 /* NOTE: an application can still remove the hot item even if anchor
5267 * highlighting is enabled */
5269 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5271 GetFocus();
5273 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5276 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5277 * which controls the amount of spacing between the image and the text
5278 * of buttons for TBSTYLE_LIST toolbars. */
5279 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5281 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5283 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5285 if (lParam != 0)
5286 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5288 infoPtr->iListGap = (INT)wParam;
5290 InvalidateRect(hwnd, NULL, TRUE);
5292 return 0;
5295 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5296 * of image lists associated with the various states. */
5297 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5299 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5301 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5303 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5306 static LRESULT
5307 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5309 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5310 LPSIZE lpsize = (LPSIZE)lParam;
5312 if (lpsize == NULL)
5313 return FALSE;
5316 * Testing shows the following:
5317 * wParam = 0 adjust cx value
5318 * = 1 set cy value to max size.
5319 * lParam pointer to SIZE structure
5322 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5323 wParam, lParam, lpsize->cx, lpsize->cy);
5325 switch(wParam) {
5326 case 0:
5327 if (lpsize->cx == -1) {
5328 /* **** this is wrong, native measures each button and sets it */
5329 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5331 else if(HIWORD(lpsize->cx)) {
5332 RECT rc;
5333 HWND hwndParent = GetParent(hwnd);
5335 GetWindowRect(hwnd, &rc);
5336 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5337 TRACE("mapped to (%d,%d)-(%d,%d)\n",
5338 rc.left, rc.top, rc.right, rc.bottom);
5339 lpsize->cx = max(rc.right-rc.left,
5340 infoPtr->rcBound.right - infoPtr->rcBound.left);
5342 else {
5343 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5345 break;
5346 case 1:
5347 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5348 break;
5349 default:
5350 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5351 wParam);
5352 return 0;
5354 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5355 lpsize->cx, lpsize->cy);
5356 return 1;
5359 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5361 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5363 InvalidateRect(hwnd, NULL, TRUE);
5364 return 1;
5368 static LRESULT
5369 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5371 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5372 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5373 LOGFONTW logFont;
5375 TRACE("hwnd = %p\n", hwnd);
5377 /* initialize info structure */
5378 infoPtr->nButtonWidth = 23;
5379 infoPtr->nButtonHeight = 22;
5380 infoPtr->nBitmapHeight = 15;
5381 infoPtr->nBitmapWidth = 16;
5382 /* By default Windows creates an image list with 16x15 icons but computes the button size as
5383 * if the icons were 16x16. That's why we keep infoPtr->nVBitmapHeight. After a call to
5384 * TB_SETBITMAPSIZE or TB_SETIMAGELIST the nVBitmapHeight = nBitmapHeight.
5386 infoPtr->nVBitmapHeight = 16;
5388 infoPtr->nMaxTextRows = 1;
5389 infoPtr->cxMin = -1;
5390 infoPtr->cxMax = -1;
5391 infoPtr->nNumBitmaps = 0;
5392 infoPtr->nNumStrings = 0;
5394 infoPtr->bCaptured = FALSE;
5395 infoPtr->nButtonDown = -1;
5396 infoPtr->nButtonDrag = -1;
5397 infoPtr->nOldHit = -1;
5398 infoPtr->nHotItem = -1;
5399 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5400 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5401 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5402 infoPtr->bDragOutSent = FALSE;
5403 infoPtr->iVersion = 0;
5404 infoPtr->hwndSelf = hwnd;
5405 infoPtr->bDoRedraw = TRUE;
5406 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5407 infoPtr->clrBtnShadow = CLR_DEFAULT;
5408 infoPtr->szPadding.cx = DEFPAD_CX;
5409 infoPtr->szPadding.cy = DEFPAD_CY;
5410 infoPtr->iListGap = DEFLISTGAP;
5411 infoPtr->iTopMargin = default_top_margin(infoPtr);
5412 infoPtr->dwStyle = dwStyle;
5413 infoPtr->tbim.iButton = -1;
5414 GetClientRect(hwnd, &infoPtr->client_rect);
5415 infoPtr->bUnicode = infoPtr->hwndNotify &&
5416 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5417 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5419 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5420 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5422 OpenThemeData (hwnd, themeClass);
5424 TOOLBAR_CheckStyle (hwnd, dwStyle);
5426 return 0;
5430 static LRESULT
5431 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5433 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5435 /* delete tooltip control */
5436 if (infoPtr->hwndToolTip)
5437 DestroyWindow (infoPtr->hwndToolTip);
5439 /* delete temporary buffer for tooltip text */
5440 Free (infoPtr->pszTooltipText);
5441 Free (infoPtr->bitmaps); /* bitmaps list */
5443 /* delete button data */
5444 if (infoPtr->buttons)
5445 Free (infoPtr->buttons);
5447 /* delete strings */
5448 if (infoPtr->strings) {
5449 INT i;
5450 for (i = 0; i < infoPtr->nNumStrings; i++)
5451 if (infoPtr->strings[i])
5452 Free (infoPtr->strings[i]);
5454 Free (infoPtr->strings);
5457 /* destroy internal image list */
5458 if (infoPtr->himlInt)
5459 ImageList_Destroy (infoPtr->himlInt);
5461 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5462 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5463 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5465 /* delete default font */
5466 DeleteObject (infoPtr->hDefaultFont);
5468 CloseThemeData (GetWindowTheme (hwnd));
5470 /* free toolbar info data */
5471 Free (infoPtr);
5472 SetWindowLongPtrW (hwnd, 0, 0);
5474 return 0;
5478 static LRESULT
5479 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5481 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5482 NMTBCUSTOMDRAW tbcd;
5483 INT ret = FALSE;
5484 DWORD ntfret;
5485 HTHEME theme = GetWindowTheme (hwnd);
5486 DWORD dwEraseCustDraw = 0;
5488 /* the app has told us not to redraw the toolbar */
5489 if (!infoPtr->bDoRedraw)
5490 return FALSE;
5492 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5493 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5494 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5495 tbcd.nmcd.hdc = (HDC)wParam;
5496 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5497 dwEraseCustDraw = ntfret & 0xffff;
5499 /* FIXME: in general the return flags *can* be or'ed together */
5500 switch (dwEraseCustDraw)
5502 case CDRF_DODEFAULT:
5503 break;
5504 case CDRF_SKIPDEFAULT:
5505 return TRUE;
5506 default:
5507 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5508 hwnd, ntfret);
5512 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5513 * to my parent for processing.
5515 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5516 POINT pt, ptorig;
5517 HDC hdc = (HDC)wParam;
5518 HWND parent;
5520 pt.x = 0;
5521 pt.y = 0;
5522 parent = GetParent(hwnd);
5523 MapWindowPoints(hwnd, parent, &pt, 1);
5524 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5525 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5526 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5528 if (!ret)
5529 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5531 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5532 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5533 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5534 tbcd.nmcd.hdc = (HDC)wParam;
5535 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5536 dwEraseCustDraw = ntfret & 0xffff;
5537 switch (dwEraseCustDraw)
5539 case CDRF_DODEFAULT:
5540 break;
5541 case CDRF_SKIPDEFAULT:
5542 return TRUE;
5543 default:
5544 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5545 hwnd, ntfret);
5548 return ret;
5552 static LRESULT
5553 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5555 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5557 return (LRESULT)infoPtr->hFont;
5561 static void
5562 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5564 INT i;
5565 INT nNewHotItem = infoPtr->nHotItem;
5567 for (i = 0; i < infoPtr->nNumButtons; i++)
5569 /* did we wrap? */
5570 if ((nNewHotItem + iDirection < 0) ||
5571 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5573 NMTBWRAPHOTITEM nmtbwhi;
5574 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5575 nmtbwhi.iDirection = iDirection;
5576 nmtbwhi.dwReason = dwReason;
5578 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5579 return;
5582 nNewHotItem += iDirection;
5583 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5585 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5586 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5588 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5589 break;
5594 static LRESULT
5595 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5597 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5598 NMKEY nmkey;
5600 nmkey.nVKey = (UINT)wParam;
5601 nmkey.uFlags = HIWORD(lParam);
5603 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5604 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5606 switch ((UINT)wParam)
5608 case VK_LEFT:
5609 case VK_UP:
5610 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5611 break;
5612 case VK_RIGHT:
5613 case VK_DOWN:
5614 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5615 break;
5616 case VK_SPACE:
5617 case VK_RETURN:
5618 if ((infoPtr->nHotItem >= 0) &&
5619 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5621 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5622 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5623 (LPARAM)hwnd);
5625 break;
5628 return 0;
5632 static LRESULT
5633 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5635 POINT pt;
5636 INT nHit;
5638 pt.x = (short)LOWORD(lParam);
5639 pt.y = (short)HIWORD(lParam);
5640 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5642 if (nHit >= 0)
5643 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5644 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5645 TOOLBAR_Customize (hwnd);
5647 return 0;
5651 static LRESULT
5652 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5654 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5655 TBUTTON_INFO *btnPtr;
5656 POINT pt;
5657 INT nHit;
5658 NMTOOLBARA nmtb;
5659 NMMOUSE nmmouse;
5660 BOOL bDragKeyPressed;
5662 TRACE("\n");
5664 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5665 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5666 else
5667 bDragKeyPressed = (wParam & MK_SHIFT);
5669 if (infoPtr->hwndToolTip)
5670 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5671 WM_LBUTTONDOWN, wParam, lParam);
5673 pt.x = (short)LOWORD(lParam);
5674 pt.y = (short)HIWORD(lParam);
5675 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5677 btnPtr = &infoPtr->buttons[nHit];
5679 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5681 infoPtr->nButtonDrag = nHit;
5682 SetCapture (hwnd);
5684 /* If drag cursor has not been loaded, load it.
5685 * Note: it doesn't need to be freed */
5686 if (!hCursorDrag)
5687 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5688 SetCursor(hCursorDrag);
5690 else if (nHit >= 0)
5692 RECT arrowRect;
5693 infoPtr->nOldHit = nHit;
5695 CopyRect(&arrowRect, &btnPtr->rect);
5696 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5698 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5699 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5700 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5701 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5702 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5703 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5705 LRESULT res;
5707 /* draw in pressed state */
5708 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5709 btnPtr->fsState |= TBSTATE_PRESSED;
5710 else
5711 btnPtr->bDropDownPressed = TRUE;
5712 RedrawWindow(hwnd,&btnPtr->rect,0,
5713 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5715 memset(&nmtb, 0, sizeof(nmtb));
5716 nmtb.iItem = btnPtr->idCommand;
5717 nmtb.rcButton = btnPtr->rect;
5718 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5719 TBN_DROPDOWN);
5720 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5722 if (res != TBDDRET_TREATPRESSED)
5724 MSG msg;
5726 /* redraw button in unpressed state */
5727 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5728 btnPtr->fsState &= ~TBSTATE_PRESSED;
5729 else
5730 btnPtr->bDropDownPressed = FALSE;
5731 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5733 /* find and set hot item
5734 * NOTE: native doesn't do this, but that is a bug */
5735 GetCursorPos(&pt);
5736 ScreenToClient(hwnd, &pt);
5737 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5738 if (!infoPtr->bAnchor || (nHit >= 0))
5739 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5741 /* remove any left mouse button down or double-click messages
5742 * so that we can get a toggle effect on the button */
5743 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5744 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5747 return 0;
5749 /* otherwise drop through and process as pushed */
5751 infoPtr->bCaptured = TRUE;
5752 infoPtr->nButtonDown = nHit;
5753 infoPtr->bDragOutSent = FALSE;
5755 btnPtr->fsState |= TBSTATE_PRESSED;
5757 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5759 if (btnPtr->fsState & TBSTATE_ENABLED)
5760 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5761 UpdateWindow(hwnd);
5762 SetCapture (hwnd);
5765 if (nHit >=0)
5767 memset(&nmtb, 0, sizeof(nmtb));
5768 nmtb.iItem = btnPtr->idCommand;
5769 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5772 nmmouse.dwHitInfo = nHit;
5774 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5775 if (nHit < 0)
5776 nmmouse.dwItemSpec = -1;
5777 else
5779 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5780 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5783 ClientToScreen(hwnd, &pt);
5784 nmmouse.pt = pt;
5786 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5787 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5789 return 0;
5792 static LRESULT
5793 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5795 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5796 TBUTTON_INFO *btnPtr;
5797 POINT pt;
5798 INT nHit;
5799 INT nOldIndex = -1;
5800 BOOL bSendMessage = TRUE;
5801 NMHDR hdr;
5802 NMMOUSE nmmouse;
5803 NMTOOLBARA nmtb;
5805 if (infoPtr->hwndToolTip)
5806 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5807 WM_LBUTTONUP, wParam, lParam);
5809 pt.x = (short)LOWORD(lParam);
5810 pt.y = (short)HIWORD(lParam);
5811 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5813 if (!infoPtr->bAnchor || (nHit >= 0))
5814 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5816 if (infoPtr->nButtonDrag >= 0) {
5817 RECT rcClient;
5818 NMHDR hdr;
5820 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5821 ReleaseCapture();
5822 /* reset cursor */
5823 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5825 GetClientRect(hwnd, &rcClient);
5826 if (PtInRect(&rcClient, pt))
5828 INT nButton = -1;
5829 if (nHit >= 0)
5830 nButton = nHit;
5831 else if (nHit < -1)
5832 nButton = -nHit;
5833 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5834 nButton = -nHit;
5836 if (nButton == infoPtr->nButtonDrag)
5838 /* if the button is moved sightly left and we have a
5839 * separator there then remove it */
5840 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5842 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5843 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5845 else /* else insert a separator before the dragged button */
5847 TBBUTTON tbb;
5848 memset(&tbb, 0, sizeof(tbb));
5849 tbb.fsStyle = BTNS_SEP;
5850 tbb.iString = -1;
5851 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5854 else
5856 if (nButton == -1)
5858 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5859 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5860 else
5861 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5863 else
5864 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5867 else
5869 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5870 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5873 /* button under cursor changed so need to re-set hot item */
5874 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5875 infoPtr->nButtonDrag = -1;
5877 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5879 else if (infoPtr->nButtonDown >= 0) {
5880 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5881 btnPtr->fsState &= ~TBSTATE_PRESSED;
5883 if (btnPtr->fsStyle & BTNS_CHECK) {
5884 if (btnPtr->fsStyle & BTNS_GROUP) {
5885 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5886 nHit);
5887 if (nOldIndex == nHit)
5888 bSendMessage = FALSE;
5889 if ((nOldIndex != nHit) &&
5890 (nOldIndex != -1))
5891 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5892 btnPtr->fsState |= TBSTATE_CHECKED;
5894 else {
5895 if (btnPtr->fsState & TBSTATE_CHECKED)
5896 btnPtr->fsState &= ~TBSTATE_CHECKED;
5897 else
5898 btnPtr->fsState |= TBSTATE_CHECKED;
5902 if (nOldIndex != -1)
5903 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5906 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5907 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5908 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5910 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5911 ReleaseCapture ();
5912 infoPtr->nButtonDown = -1;
5914 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5915 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5916 NM_RELEASEDCAPTURE);
5918 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5919 * TBN_BEGINDRAG
5921 memset(&nmtb, 0, sizeof(nmtb));
5922 nmtb.iItem = btnPtr->idCommand;
5923 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5924 TBN_ENDDRAG);
5926 if (btnPtr->fsState & TBSTATE_ENABLED)
5928 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5929 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5933 /* !!! Undocumented - toolbar at 4.71 level and above sends
5934 * NM_CLICK with the NMMOUSE structure. */
5935 nmmouse.dwHitInfo = nHit;
5937 if (nHit < 0)
5938 nmmouse.dwItemSpec = -1;
5939 else
5941 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5942 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5945 ClientToScreen(hwnd, &pt);
5946 nmmouse.pt = pt;
5948 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5949 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5951 return 0;
5954 static LRESULT
5955 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5957 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5958 INT nHit;
5959 NMMOUSE nmmouse;
5960 POINT pt;
5962 pt.x = (short)LOWORD(lParam);
5963 pt.y = (short)HIWORD(lParam);
5965 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5966 nmmouse.dwHitInfo = nHit;
5968 if (nHit < 0) {
5969 nmmouse.dwItemSpec = -1;
5970 } else {
5971 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5972 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5975 ClientToScreen(hwnd, &pt);
5976 nmmouse.pt = pt;
5978 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5979 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5981 return 0;
5984 static LRESULT
5985 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5987 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5988 NMHDR nmhdr;
5990 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5991 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5993 return 0;
5996 static LRESULT
5997 TOOLBAR_CaptureChanged(HWND hwnd)
5999 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6000 TBUTTON_INFO *btnPtr;
6002 infoPtr->bCaptured = FALSE;
6004 if (infoPtr->nButtonDown >= 0)
6006 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6007 btnPtr->fsState &= ~TBSTATE_PRESSED;
6009 infoPtr->nOldHit = -1;
6011 if (btnPtr->fsState & TBSTATE_ENABLED)
6012 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6014 return 0;
6017 static LRESULT
6018 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6020 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6022 /* don't remove hot effects when in anchor highlighting mode or when a
6023 * drop-down button is pressed */
6024 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
6026 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
6027 if (!hotBtnPtr->bDropDownPressed)
6028 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6031 if (infoPtr->nOldHit < 0)
6032 return TRUE;
6034 /* If the last button we were over is depressed then make it not */
6035 /* depressed and redraw it */
6036 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6038 TBUTTON_INFO *btnPtr;
6039 RECT rc1;
6041 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6043 btnPtr->fsState &= ~TBSTATE_PRESSED;
6045 rc1 = btnPtr->rect;
6046 InflateRect (&rc1, 1, 1);
6047 InvalidateRect (hwnd, &rc1, TRUE);
6050 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6052 NMTOOLBARW nmt;
6053 ZeroMemory(&nmt, sizeof(nmt));
6054 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6055 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6056 infoPtr->bDragOutSent = TRUE;
6059 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6061 return TRUE;
6064 static LRESULT
6065 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6067 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6068 POINT pt;
6069 TRACKMOUSEEVENT trackinfo;
6070 INT nHit;
6071 TBUTTON_INFO *btnPtr;
6073 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6074 TOOLBAR_TooltipCreateControl(infoPtr);
6076 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6077 /* fill in the TRACKMOUSEEVENT struct */
6078 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6079 trackinfo.dwFlags = TME_QUERY;
6081 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6082 _TrackMouseEvent(&trackinfo);
6084 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6085 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6086 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6087 trackinfo.hwndTrack = hwnd;
6089 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6090 /* and can properly deactivate the hot toolbar button */
6091 _TrackMouseEvent(&trackinfo);
6095 if (infoPtr->hwndToolTip)
6096 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6097 WM_MOUSEMOVE, wParam, lParam);
6099 pt.x = (short)LOWORD(lParam);
6100 pt.y = (short)HIWORD(lParam);
6102 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6104 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6105 && (!infoPtr->bAnchor || (nHit >= 0)))
6106 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6108 if (infoPtr->nOldHit != nHit)
6110 if (infoPtr->bCaptured)
6112 if (!infoPtr->bDragOutSent)
6114 NMTOOLBARW nmt;
6115 ZeroMemory(&nmt, sizeof(nmt));
6116 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6117 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6118 infoPtr->bDragOutSent = TRUE;
6121 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6122 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6123 btnPtr->fsState &= ~TBSTATE_PRESSED;
6124 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6126 else if (nHit == infoPtr->nButtonDown) {
6127 btnPtr->fsState |= TBSTATE_PRESSED;
6128 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6130 infoPtr->nOldHit = nHit;
6134 return 0;
6138 inline static LRESULT
6139 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6141 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6142 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6143 /* else */
6144 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6148 inline static LRESULT
6149 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6151 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6152 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6154 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6158 static LRESULT
6159 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6161 TOOLBAR_INFO *infoPtr;
6162 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6163 DWORD styleadd = 0;
6165 /* allocate memory for info structure */
6166 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6167 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6169 /* paranoid!! */
6170 infoPtr->dwStructSize = sizeof(TBBUTTON);
6171 infoPtr->nRows = 1;
6172 infoPtr->nWidth = 0;
6174 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6175 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6176 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6177 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6180 /* native control does:
6181 * Get a lot of colors and brushes
6182 * WM_NOTIFYFORMAT
6183 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6184 * CreateFontIndirectW(adr1)
6185 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6186 * hdc = GetDC(toolbar)
6187 * GetSystemMetrics(0x48)
6188 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6189 * 0, 0, 0, 0, "MARLETT")
6190 * oldfnt = SelectObject(hdc, fnt2)
6191 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6192 * GetTextMetricsW(hdc, adr3)
6193 * SelectObject(hdc, oldfnt)
6194 * DeleteObject(fnt2)
6195 * ReleaseDC(hdc)
6196 * InvalidateRect(toolbar, 0, 1)
6197 * SetWindowLongW(toolbar, 0, addr)
6198 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6199 * WM_STYLECHANGING
6200 * CallWinEx old new
6201 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6202 * ie 2 0x4600094c 0x4600094c 0x4600894d
6203 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6204 * rebar 0x50008844 0x40008844 0x50008845
6205 * pager 0x50000844 0x40000844 0x50008845
6206 * IC35mgr 0x5400084e **nochange**
6207 * on entry to _NCCREATE 0x5400084e
6208 * rowlist 0x5400004e **nochange**
6209 * on entry to _NCCREATE 0x5400004e
6213 /* I think the code below is a bug, but it is the way that the native
6214 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6215 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6216 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6217 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6218 * Somehow, the only cases of this seem to be MFC programs.
6220 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6221 * does not occur in the WM_STYLECHANGING routine.
6222 * (Guy Albertelli 9/2001)
6225 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6226 && !(cs->style & TBSTYLE_TRANSPARENT))
6227 styleadd |= TBSTYLE_TRANSPARENT;
6228 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6229 styleadd |= CCS_TOP; /* default to top */
6230 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6233 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6237 static LRESULT
6238 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6240 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6241 RECT rcWindow;
6242 HDC hdc;
6244 if (dwStyle & WS_MINIMIZE)
6245 return 0; /* Nothing to do */
6247 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6249 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6250 return 0;
6252 if (!(dwStyle & CCS_NODIVIDER))
6254 GetWindowRect (hwnd, &rcWindow);
6255 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6256 if( dwStyle & WS_BORDER )
6257 OffsetRect (&rcWindow, 1, 1);
6258 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6261 ReleaseDC( hwnd, hdc );
6263 return 0;
6267 /* handles requests from the tooltip control on what text to display */
6268 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6270 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6272 TRACE("button index = %d\n", index);
6274 Free (infoPtr->pszTooltipText);
6275 infoPtr->pszTooltipText = NULL;
6277 if (index < 0)
6278 return 0;
6280 if (infoPtr->bUnicode)
6282 WCHAR wszBuffer[INFOTIPSIZE+1];
6283 NMTBGETINFOTIPW tbgit;
6284 unsigned int len; /* in chars */
6286 wszBuffer[0] = '\0';
6287 wszBuffer[INFOTIPSIZE] = '\0';
6289 tbgit.pszText = wszBuffer;
6290 tbgit.cchTextMax = INFOTIPSIZE;
6291 tbgit.iItem = lpnmtdi->hdr.idFrom;
6292 tbgit.lParam = infoPtr->buttons[index].dwData;
6294 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6296 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6298 len = strlenW(tbgit.pszText);
6299 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6301 /* need to allocate temporary buffer in infoPtr as there
6302 * isn't enough space in buffer passed to us by the
6303 * tooltip control */
6304 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6305 if (infoPtr->pszTooltipText)
6307 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6308 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6309 return 0;
6312 else if (len > 0)
6314 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6315 return 0;
6318 else
6320 CHAR szBuffer[INFOTIPSIZE+1];
6321 NMTBGETINFOTIPA tbgit;
6322 unsigned int len; /* in chars */
6324 szBuffer[0] = '\0';
6325 szBuffer[INFOTIPSIZE] = '\0';
6327 tbgit.pszText = szBuffer;
6328 tbgit.cchTextMax = INFOTIPSIZE;
6329 tbgit.iItem = lpnmtdi->hdr.idFrom;
6330 tbgit.lParam = infoPtr->buttons[index].dwData;
6332 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6334 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6336 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6337 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6339 /* need to allocate temporary buffer in infoPtr as there
6340 * isn't enough space in buffer passed to us by the
6341 * tooltip control */
6342 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6343 if (infoPtr->pszTooltipText)
6345 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6346 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6347 return 0;
6350 else if (len > 0)
6352 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6353 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6354 return 0;
6358 /* if button has text, but it is not shown then automatically
6359 * use that text as tooltip */
6360 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6361 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6363 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6364 unsigned int len = pszText ? strlenW(pszText) : 0;
6366 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6368 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6370 /* need to allocate temporary buffer in infoPtr as there
6371 * isn't enough space in buffer passed to us by the
6372 * tooltip control */
6373 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6374 if (infoPtr->pszTooltipText)
6376 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6377 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6378 return 0;
6381 else if (len > 0)
6383 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6384 return 0;
6388 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6390 /* last resort: send notification on to app */
6391 /* FIXME: find out what is really used here */
6392 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6396 inline static LRESULT
6397 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6399 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6400 LPNMHDR lpnmh = (LPNMHDR)lParam;
6402 switch (lpnmh->code)
6404 case PGN_CALCSIZE:
6406 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6408 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6409 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6410 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6411 lppgc->iWidth);
6413 else {
6414 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6415 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6416 lppgc->iHeight);
6418 return 0;
6421 case PGN_SCROLL:
6423 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6425 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6426 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6427 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6428 lppgs->iScroll, lppgs->iDir);
6429 return 0;
6432 case TTN_GETDISPINFOW:
6433 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6435 case TTN_GETDISPINFOA:
6436 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6437 return 0;
6439 default:
6440 return 0;
6445 static LRESULT
6446 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6448 LRESULT format;
6450 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6452 if (lParam == NF_QUERY)
6453 return NFR_UNICODE;
6455 if (lParam == NF_REQUERY) {
6456 format = SendMessageW(infoPtr->hwndNotify,
6457 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6458 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6459 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6460 format);
6461 format = NFR_ANSI;
6463 return format;
6465 return 0;
6469 static LRESULT
6470 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6472 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6473 HDC hdc;
6474 PAINTSTRUCT ps;
6476 /* fill ps.rcPaint with a default rect */
6477 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6479 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6481 TRACE("psrect=(%d,%d)-(%d,%d)\n",
6482 ps.rcPaint.left, ps.rcPaint.top,
6483 ps.rcPaint.right, ps.rcPaint.bottom);
6485 TOOLBAR_Refresh (hwnd, hdc, &ps);
6486 if (!wParam) EndPaint (hwnd, &ps);
6488 return 0;
6492 static LRESULT
6493 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6495 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6497 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6499 /* make first item hot */
6500 if (infoPtr->nNumButtons > 0)
6501 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6503 return 0;
6506 static LRESULT
6507 TOOLBAR_SetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
6509 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6511 TRACE("font=%p redraw=%ld\n", (HFONT)wParam, lParam);
6513 if (wParam == 0)
6514 infoPtr->hFont = infoPtr->hDefaultFont;
6515 else
6516 infoPtr->hFont = (HFONT)wParam;
6518 TOOLBAR_CalcToolbar(hwnd);
6520 if (lParam)
6521 InvalidateRect(hwnd, NULL, TRUE);
6522 return 1;
6525 static LRESULT
6526 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6527 /*****************************************************
6529 * Function;
6530 * Handles the WM_SETREDRAW message.
6532 * Documentation:
6533 * According to testing V4.71 of COMCTL32 returns the
6534 * *previous* status of the redraw flag (either 0 or 1)
6535 * instead of the MSDN documented value of 0 if handled.
6536 * (For laughs see the "consistency" with same function
6537 * in rebar.)
6539 *****************************************************/
6541 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6542 BOOL oldredraw = infoPtr->bDoRedraw;
6544 TRACE("set to %s\n",
6545 (wParam) ? "TRUE" : "FALSE");
6546 infoPtr->bDoRedraw = (BOOL) wParam;
6547 if (wParam) {
6548 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6550 return (oldredraw) ? 1 : 0;
6554 static LRESULT
6555 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6557 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6559 TRACE("sizing toolbar!\n");
6561 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6563 RECT delta_width, delta_height, client, dummy;
6564 DWORD min_x, max_x, min_y, max_y;
6565 TBUTTON_INFO *btnPtr;
6566 INT i;
6568 GetClientRect(hwnd, &client);
6569 if(client.right > infoPtr->client_rect.right)
6571 min_x = infoPtr->client_rect.right;
6572 max_x = client.right;
6574 else
6576 max_x = infoPtr->client_rect.right;
6577 min_x = client.right;
6579 if(client.bottom > infoPtr->client_rect.bottom)
6581 min_y = infoPtr->client_rect.bottom;
6582 max_y = client.bottom;
6584 else
6586 max_y = infoPtr->client_rect.bottom;
6587 min_y = client.bottom;
6590 SetRect(&delta_width, min_x, 0, max_x, min_y);
6591 SetRect(&delta_height, 0, min_y, max_x, max_y);
6593 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6594 btnPtr = infoPtr->buttons;
6595 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6596 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6597 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6598 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6600 GetClientRect(hwnd, &infoPtr->client_rect);
6601 TOOLBAR_AutoSize(hwnd);
6602 return 0;
6606 static LRESULT
6607 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6609 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6611 if (nType == GWL_STYLE)
6613 DWORD dwOldStyle = infoPtr->dwStyle;
6615 if (lpStyle->styleNew & TBSTYLE_LIST)
6616 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6617 else
6618 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6620 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6622 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6624 infoPtr->dwStyle = lpStyle->styleNew;
6626 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6627 TOOLBAR_LayoutToolbar(hwnd);
6629 /* only resize if one of the CCS_* styles was changed */
6630 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6632 TOOLBAR_AutoSize (hwnd);
6634 InvalidateRect(hwnd, NULL, TRUE);
6638 return 0;
6642 static LRESULT
6643 TOOLBAR_SysColorChange (HWND hwnd)
6645 COMCTL32_RefreshSysColors();
6647 return 0;
6651 /* update theme after a WM_THEMECHANGED message */
6652 static LRESULT theme_changed (HWND hwnd)
6654 HTHEME theme = GetWindowTheme (hwnd);
6655 CloseThemeData (theme);
6656 OpenThemeData (hwnd, themeClass);
6657 return 0;
6661 static LRESULT WINAPI
6662 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6664 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6666 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6667 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6669 if (!infoPtr && (uMsg != WM_NCCREATE))
6670 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6672 switch (uMsg)
6674 case TB_ADDBITMAP:
6675 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6677 case TB_ADDBUTTONSA:
6678 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6680 case TB_ADDBUTTONSW:
6681 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6683 case TB_ADDSTRINGA:
6684 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6686 case TB_ADDSTRINGW:
6687 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6689 case TB_AUTOSIZE:
6690 return TOOLBAR_AutoSize (hwnd);
6692 case TB_BUTTONCOUNT:
6693 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6695 case TB_BUTTONSTRUCTSIZE:
6696 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6698 case TB_CHANGEBITMAP:
6699 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6701 case TB_CHECKBUTTON:
6702 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6704 case TB_COMMANDTOINDEX:
6705 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6707 case TB_CUSTOMIZE:
6708 return TOOLBAR_Customize (hwnd);
6710 case TB_DELETEBUTTON:
6711 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6713 case TB_ENABLEBUTTON:
6714 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6716 case TB_GETANCHORHIGHLIGHT:
6717 return TOOLBAR_GetAnchorHighlight (hwnd);
6719 case TB_GETBITMAP:
6720 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6722 case TB_GETBITMAPFLAGS:
6723 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6725 case TB_GETBUTTON:
6726 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6728 case TB_GETBUTTONINFOA:
6729 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6731 case TB_GETBUTTONINFOW:
6732 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6734 case TB_GETBUTTONSIZE:
6735 return TOOLBAR_GetButtonSize (hwnd);
6737 case TB_GETBUTTONTEXTA:
6738 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6740 case TB_GETBUTTONTEXTW:
6741 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6743 case TB_GETDISABLEDIMAGELIST:
6744 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6746 case TB_GETEXTENDEDSTYLE:
6747 return TOOLBAR_GetExtendedStyle (hwnd);
6749 case TB_GETHOTIMAGELIST:
6750 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6752 case TB_GETHOTITEM:
6753 return TOOLBAR_GetHotItem (hwnd);
6755 case TB_GETIMAGELIST:
6756 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6758 case TB_GETINSERTMARK:
6759 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6761 case TB_GETINSERTMARKCOLOR:
6762 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6764 case TB_GETITEMRECT:
6765 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6767 case TB_GETMAXSIZE:
6768 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6770 /* case TB_GETOBJECT: */ /* 4.71 */
6772 case TB_GETPADDING:
6773 return TOOLBAR_GetPadding (hwnd);
6775 case TB_GETRECT:
6776 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6778 case TB_GETROWS:
6779 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6781 case TB_GETSTATE:
6782 return TOOLBAR_GetState (hwnd, wParam, lParam);
6784 case TB_GETSTRINGA:
6785 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6787 case TB_GETSTRINGW:
6788 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6790 case TB_GETSTYLE:
6791 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6793 case TB_GETTEXTROWS:
6794 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6796 case TB_GETTOOLTIPS:
6797 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6799 case TB_GETUNICODEFORMAT:
6800 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6802 case TB_HIDEBUTTON:
6803 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6805 case TB_HITTEST:
6806 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6808 case TB_INDETERMINATE:
6809 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6811 case TB_INSERTBUTTONA:
6812 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6814 case TB_INSERTBUTTONW:
6815 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6817 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6819 case TB_ISBUTTONCHECKED:
6820 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6822 case TB_ISBUTTONENABLED:
6823 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6825 case TB_ISBUTTONHIDDEN:
6826 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6828 case TB_ISBUTTONHIGHLIGHTED:
6829 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6831 case TB_ISBUTTONINDETERMINATE:
6832 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6834 case TB_ISBUTTONPRESSED:
6835 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6837 case TB_LOADIMAGES:
6838 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6840 case TB_MAPACCELERATORA:
6841 case TB_MAPACCELERATORW:
6842 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6844 case TB_MARKBUTTON:
6845 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6847 case TB_MOVEBUTTON:
6848 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6850 case TB_PRESSBUTTON:
6851 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6853 case TB_REPLACEBITMAP:
6854 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6856 case TB_SAVERESTOREA:
6857 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6859 case TB_SAVERESTOREW:
6860 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6862 case TB_SETANCHORHIGHLIGHT:
6863 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6865 case TB_SETBITMAPSIZE:
6866 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6868 case TB_SETBUTTONINFOA:
6869 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6871 case TB_SETBUTTONINFOW:
6872 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6874 case TB_SETBUTTONSIZE:
6875 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6877 case TB_SETBUTTONWIDTH:
6878 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6880 case TB_SETCMDID:
6881 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6883 case TB_SETDISABLEDIMAGELIST:
6884 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6886 case TB_SETDRAWTEXTFLAGS:
6887 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6889 case TB_SETEXTENDEDSTYLE:
6890 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6892 case TB_SETHOTIMAGELIST:
6893 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6895 case TB_SETHOTITEM:
6896 return TOOLBAR_SetHotItem (hwnd, wParam);
6898 case TB_SETIMAGELIST:
6899 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6901 case TB_SETINDENT:
6902 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6904 case TB_SETINSERTMARK:
6905 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6907 case TB_SETINSERTMARKCOLOR:
6908 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6910 case TB_SETMAXTEXTROWS:
6911 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6913 case TB_SETPADDING:
6914 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6916 case TB_SETPARENT:
6917 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6919 case TB_SETROWS:
6920 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6922 case TB_SETSTATE:
6923 return TOOLBAR_SetState (hwnd, wParam, lParam);
6925 case TB_SETSTYLE:
6926 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6928 case TB_SETTOOLTIPS:
6929 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6931 case TB_SETUNICODEFORMAT:
6932 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6934 case TB_UNKWN45D:
6935 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6937 case TB_UNKWN45E:
6938 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6940 case TB_UNKWN460:
6941 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6943 case TB_UNKWN462:
6944 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6946 case TB_UNKWN463:
6947 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6949 case TB_UNKWN464:
6950 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6952 /* Common Control Messages */
6954 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6955 case CCM_GETCOLORSCHEME:
6956 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6958 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6959 case CCM_SETCOLORSCHEME:
6960 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6962 case CCM_GETVERSION:
6963 return TOOLBAR_GetVersion (hwnd);
6965 case CCM_SETVERSION:
6966 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6969 /* case WM_CHAR: */
6971 case WM_CREATE:
6972 return TOOLBAR_Create (hwnd, wParam, lParam);
6974 case WM_DESTROY:
6975 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6977 case WM_ERASEBKGND:
6978 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6980 case WM_GETFONT:
6981 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6983 case WM_KEYDOWN:
6984 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6986 /* case WM_KILLFOCUS: */
6988 case WM_LBUTTONDBLCLK:
6989 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6991 case WM_LBUTTONDOWN:
6992 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6994 case WM_LBUTTONUP:
6995 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6997 case WM_RBUTTONUP:
6998 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
7000 case WM_RBUTTONDBLCLK:
7001 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
7003 case WM_MOUSEMOVE:
7004 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
7006 case WM_MOUSELEAVE:
7007 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
7009 case WM_CAPTURECHANGED:
7010 return TOOLBAR_CaptureChanged(hwnd);
7012 case WM_NCACTIVATE:
7013 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7015 case WM_NCCALCSIZE:
7016 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7018 case WM_NCCREATE:
7019 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7021 case WM_NCPAINT:
7022 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7024 case WM_NOTIFY:
7025 return TOOLBAR_Notify (hwnd, wParam, lParam);
7027 case WM_NOTIFYFORMAT:
7028 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7030 case WM_PRINTCLIENT:
7031 case WM_PAINT:
7032 return TOOLBAR_Paint (hwnd, wParam);
7034 case WM_SETFOCUS:
7035 return TOOLBAR_SetFocus (hwnd, wParam);
7037 case WM_SETFONT:
7038 return TOOLBAR_SetFont(hwnd, wParam, lParam);
7040 case WM_SETREDRAW:
7041 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7043 case WM_SIZE:
7044 return TOOLBAR_Size (hwnd, wParam, lParam);
7046 case WM_STYLECHANGED:
7047 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7049 case WM_SYSCOLORCHANGE:
7050 return TOOLBAR_SysColorChange (hwnd);
7052 case WM_THEMECHANGED:
7053 return theme_changed (hwnd);
7055 /* case WM_WININICHANGE: */
7057 case WM_CHARTOITEM:
7058 case WM_COMMAND:
7059 case WM_DRAWITEM:
7060 case WM_MEASUREITEM:
7061 case WM_VKEYTOITEM:
7062 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7064 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7065 case PGM_FORWARDMOUSE:
7066 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7068 default:
7069 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7070 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7071 uMsg, wParam, lParam);
7072 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7077 VOID
7078 TOOLBAR_Register (void)
7080 WNDCLASSW wndClass;
7082 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7083 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7084 wndClass.lpfnWndProc = ToolbarWindowProc;
7085 wndClass.cbClsExtra = 0;
7086 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7087 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7088 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7089 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7091 RegisterClassW (&wndClass);
7095 VOID
7096 TOOLBAR_Unregister (void)
7098 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7101 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7103 HIMAGELIST himlold;
7104 PIMLENTRY c = NULL;
7106 /* Check if the entry already exists */
7107 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7109 /* If this is a new entry we must create it and insert into the array */
7110 if (!c)
7112 PIMLENTRY *pnies;
7114 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7115 c->id = id;
7117 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7118 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7119 pnies[*cies] = c;
7120 (*cies)++;
7122 Free(*pies);
7123 *pies = pnies;
7126 himlold = c->himl;
7127 c->himl = himl;
7129 return himlold;
7133 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7135 int i;
7137 for (i = 0; i < *cies; i++)
7138 Free((*pies)[i]);
7140 Free(*pies);
7142 *cies = 0;
7143 *pies = NULL;
7147 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7149 PIMLENTRY c = NULL;
7151 if (pies != NULL)
7153 int i;
7155 for (i = 0; i < cies; i++)
7157 if (pies[i]->id == id)
7159 c = pies[i];
7160 break;
7165 return c;
7169 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7171 HIMAGELIST himlDef = 0;
7172 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7174 if (pie)
7175 himlDef = pie->himl;
7177 return himlDef;
7181 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7183 if (infoPtr->bUnicode)
7184 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7185 else
7187 CHAR Buffer[256];
7188 NMTOOLBARA nmtba;
7189 BOOL bRet = FALSE;
7191 nmtba.iItem = nmtb->iItem;
7192 nmtba.pszText = Buffer;
7193 nmtba.cchText = 256;
7194 ZeroMemory(nmtba.pszText, nmtba.cchText);
7196 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7198 int ccht = strlen(nmtba.pszText);
7199 if (ccht)
7200 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7201 nmtb->pszText, nmtb->cchText);
7203 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7204 bRet = TRUE;
7207 return bRet;
7212 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7213 int iItem, PCUSTOMBUTTON btnInfo)
7215 NMTOOLBARW nmtb;
7217 /* MSDN states that iItem is the index of the button, rather than the
7218 * command ID as used by every other NMTOOLBAR notification */
7219 nmtb.iItem = iItem;
7220 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7222 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);