push d1f5df181c120dbe494f7c89b454752c2e0dcc04
[wine/hacks.git] / dlls / comctl32 / toolbar.c
blob3fbbdeca3d04785df60dc5957124ec56335dda2f
1 /*
2 * Toolbar control
4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * NOTES
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
31 * TODO:
32 * - Styles:
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
35 * - Messages:
36 * - TB_GETMETRICS
37 * - TB_GETOBJECT
38 * - TB_INSERTMARKHITTEST
39 * - TB_SAVERESTORE
40 * - TB_SETMETRICS
41 * - WM_WININICHANGE
42 * - Notifications:
43 * - NM_CHAR
44 * - TBN_GETOBJECT
45 * - TBN_SAVE
46 * - Button wrapping (under construction).
47 * - Fix TB_SETROWS and Separators.
48 * - iListGap custom draw support.
50 * Testing:
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
71 #include <stdarg.h>
72 #include <string.h>
74 #include "windef.h"
75 #include "winbase.h"
76 #include "winreg.h"
77 #include "wingdi.h"
78 #include "winuser.h"
79 #include "wine/unicode.h"
80 #include "winnls.h"
81 #include "commctrl.h"
82 #include "comctl32.h"
83 #include "uxtheme.h"
84 #include "tmschema.h"
85 #include "wine/debug.h"
87 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
89 static HCURSOR hCursorDrag = NULL;
91 typedef struct
93 INT iBitmap;
94 INT idCommand;
95 BYTE fsState;
96 BYTE fsStyle;
97 BYTE bHot;
98 BYTE bDropDownPressed;
99 DWORD_PTR dwData;
100 INT_PTR iString;
101 INT nRow;
102 RECT rect;
103 INT cx; /* manually set size */
104 } TBUTTON_INFO;
106 typedef struct
108 UINT nButtons;
109 HINSTANCE hInst;
110 UINT nID;
111 } TBITMAP_INFO;
113 typedef struct
115 HIMAGELIST himl;
116 INT id;
117 } IMLENTRY, *PIMLENTRY;
119 typedef struct
121 DWORD dwStructSize; /* size of TBBUTTON struct */
122 INT nWidth; /* width of the toolbar */
123 RECT client_rect;
124 RECT rcBound; /* bounding rectangle */
125 INT nButtonHeight;
126 INT nButtonWidth;
127 INT nBitmapHeight;
128 INT nBitmapWidth;
129 INT nIndent;
130 INT nRows; /* number of button rows */
131 INT nMaxTextRows; /* maximum number of text rows */
132 INT cxMin; /* minimum button width */
133 INT cxMax; /* maximum button width */
134 INT nNumButtons; /* number of buttons */
135 INT nNumBitmaps; /* number of bitmaps */
136 INT nNumStrings; /* number of strings */
137 INT nNumBitmapInfos;
138 INT nButtonDown; /* toolbar button being pressed or -1 if none */
139 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
140 INT nOldHit;
141 INT nHotItem; /* index of the "hot" item */
142 SIZE szPadding; /* padding values around button */
143 INT iTopMargin; /* the top margin */
144 INT iListGap; /* default gap between text and image for toolbar with list style */
145 HFONT hDefaultFont;
146 HFONT hFont; /* text font */
147 HIMAGELIST himlInt; /* image list created internally */
148 PIMLENTRY *himlDef; /* default image list array */
149 INT cimlDef; /* default image list array count */
150 PIMLENTRY *himlHot; /* hot image list array */
151 INT cimlHot; /* hot image list array count */
152 PIMLENTRY *himlDis; /* disabled image list array */
153 INT cimlDis; /* disabled image list array count */
154 HWND hwndToolTip; /* handle to tool tip control */
155 HWND hwndNotify; /* handle to the window that gets notifications */
156 HWND hwndSelf; /* my own handle */
157 BOOL bAnchor; /* anchor highlight enabled */
158 BOOL bDoRedraw; /* Redraw status */
159 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
160 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
161 BOOL bCaptured; /* mouse captured? */
162 DWORD dwStyle; /* regular toolbar style */
163 DWORD dwExStyle; /* extended toolbar style */
164 DWORD dwDTFlags; /* DrawText flags */
166 COLORREF clrInsertMark; /* insert mark color */
167 COLORREF clrBtnHighlight; /* color for Flat Separator */
168 COLORREF clrBtnShadow; /* color for Flag Separator */
169 INT iVersion;
170 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
171 * for TTN_GETDISPINFOW notification */
172 TBINSERTMARK tbim; /* info on insertion mark */
173 TBUTTON_INFO *buttons; /* pointer to button array */
174 LPWSTR *strings; /* pointer to string array */
175 TBITMAP_INFO *bitmaps;
176 } TOOLBAR_INFO, *PTOOLBAR_INFO;
179 /* used by customization dialog */
180 typedef struct
182 PTOOLBAR_INFO tbInfo;
183 HWND tbHwnd;
184 } CUSTDLG_INFO, *PCUSTDLG_INFO;
186 typedef struct
188 TBBUTTON btn;
189 BOOL bVirtual;
190 BOOL bRemovable;
191 WCHAR text[64];
192 } CUSTOMBUTTON, *PCUSTOMBUTTON;
194 typedef enum
196 IMAGE_LIST_DEFAULT,
197 IMAGE_LIST_HOT,
198 IMAGE_LIST_DISABLED
199 } IMAGE_LIST_TYPE;
201 #define SEPARATOR_WIDTH 8
202 #define TOP_BORDER 2
203 #define BOTTOM_BORDER 2
204 #define DDARROW_WIDTH 11
205 #define ARROW_HEIGHT 3
206 #define INSERTMARK_WIDTH 2
208 #define DEFPAD_CX 7
209 #define DEFPAD_CY 6
210 #define DEFLISTGAP 4
212 /* vertical padding used in list mode when image is present */
213 #define LISTPAD_CY 9
215 /* how wide to treat the bitmap if it isn't present */
216 #define NONLIST_NOTEXT_OFFSET 2
218 #define TOOLBAR_NOWHERE (-1)
220 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
221 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
222 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
224 /* Used to find undocumented extended styles */
225 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
226 TBSTYLE_EX_UNDOC1 | \
227 TBSTYLE_EX_MIXEDBUTTONS | \
228 TBSTYLE_EX_DOUBLEBUFFER | \
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(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
244 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
245 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id);
246 static PIMLENTRY TOOLBAR_GetImageListEntry(const 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_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
255 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
257 static LRESULT
258 TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
260 static inline int default_top_margin(const TOOLBAR_INFO *infoPtr)
262 return (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
265 static LPWSTR
266 TOOLBAR_GetText(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr)
268 LPWSTR lpText = NULL;
270 /* NOTE: iString == -1 is undocumented */
271 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
272 lpText = (LPWSTR)btnPtr->iString;
273 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
274 lpText = infoPtr->strings[btnPtr->iString];
276 return lpText;
279 static void
280 TOOLBAR_DumpTBButton(const TBBUTTON *tbb, BOOL fUnicode)
282 TRACE("TBBUTTON: id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx (%s)\n",
283 tbb->idCommand,tbb->iBitmap, tbb->fsState, tbb->fsStyle, tbb->dwData, tbb->iString,
284 (fUnicode ? wine_dbgstr_w((LPWSTR)tbb->iString) : wine_dbgstr_a((LPSTR)tbb->iString)));
287 static void
288 TOOLBAR_DumpButton(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *bP, INT btn_num)
290 if (TRACE_ON(toolbar)){
291 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
292 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
293 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
294 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
295 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n",
296 btn_num, bP->idCommand, (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
297 wine_dbgstr_rect(&bP->rect));
302 static void
303 TOOLBAR_DumpToolbar(const TOOLBAR_INFO *iP, INT line)
305 if (TRACE_ON(toolbar)) {
306 INT i;
308 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
309 iP->hwndSelf, line,
310 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
311 iP->nNumStrings, iP->dwStyle);
312 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
313 iP->hwndSelf, line,
314 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
315 (iP->bDoRedraw) ? "TRUE" : "FALSE");
316 for(i=0; i<iP->nNumButtons; i++) {
317 TOOLBAR_DumpButton(iP, &iP->buttons[i], i);
323 /***********************************************************************
324 * TOOLBAR_CheckStyle
326 * This function validates that the styles set are implemented and
327 * issues FIXME's warning of possible problems. In a perfect world this
328 * function should be null.
330 static void
331 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
333 if (dwStyle & TBSTYLE_REGISTERDROP)
334 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
338 static INT
339 TOOLBAR_SendNotify (NMHDR *nmhdr, const TOOLBAR_INFO *infoPtr, UINT code)
341 if(!IsWindow(infoPtr->hwndSelf))
342 return 0; /* we have just been destroyed */
344 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
345 nmhdr->hwndFrom = infoPtr->hwndSelf;
346 nmhdr->code = code;
348 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
349 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
351 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
354 /***********************************************************************
355 * TOOLBAR_GetBitmapIndex
357 * This function returns the bitmap index associated with a button.
358 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
359 * is issued to retrieve the index.
361 static INT
362 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
364 INT ret = btnPtr->iBitmap;
366 if (ret == I_IMAGECALLBACK)
368 /* issue TBN_GETDISPINFO */
369 NMTBDISPINFOW nmgd;
371 memset(&nmgd, 0, sizeof(nmgd));
372 nmgd.idCommand = btnPtr->idCommand;
373 nmgd.lParam = btnPtr->dwData;
374 nmgd.dwMask = TBNF_IMAGE;
375 nmgd.iImage = -1;
376 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
377 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr, TBN_GETDISPINFOW);
378 if (nmgd.dwMask & TBNF_DI_SETITEM)
379 btnPtr->iBitmap = nmgd.iImage;
380 ret = nmgd.iImage;
381 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
382 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
385 if (ret != I_IMAGENONE)
386 ret = GETIBITMAP(infoPtr, ret);
388 return ret;
392 static BOOL
393 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO *infoPtr, INT index)
395 HIMAGELIST himl;
396 INT id = GETHIMLID(infoPtr, index);
397 INT iBitmap = GETIBITMAP(infoPtr, index);
399 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
400 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
401 (index == I_IMAGECALLBACK))
402 return TRUE;
403 else
404 return FALSE;
408 static inline BOOL
409 TOOLBAR_IsValidImageList(const TOOLBAR_INFO *infoPtr, INT index)
411 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
412 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
416 /***********************************************************************
417 * TOOLBAR_GetImageListForDrawing
419 * This function validates the bitmap index (including I_IMAGECALLBACK
420 * functionality) and returns the corresponding image list.
422 static HIMAGELIST
423 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
424 IMAGE_LIST_TYPE imagelist, INT * index)
426 HIMAGELIST himl;
428 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
429 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
430 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
431 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
432 return NULL;
435 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
436 if ((*index == I_IMAGECALLBACK) ||
437 (*index == I_IMAGENONE)) return NULL;
438 ERR("TBN_GETDISPINFO returned invalid index %d\n",
439 *index);
440 return NULL;
443 switch(imagelist)
445 case IMAGE_LIST_DEFAULT:
446 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
447 break;
448 case IMAGE_LIST_HOT:
449 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
450 break;
451 case IMAGE_LIST_DISABLED:
452 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
453 break;
454 default:
455 himl = NULL;
456 FIXME("Shouldn't reach here\n");
459 if (!himl)
460 TRACE("no image list\n");
462 return himl;
466 static void
467 TOOLBAR_DrawFlatSeparator (const RECT *lpRect, HDC hdc, const TOOLBAR_INFO *infoPtr)
469 RECT myrect;
470 COLORREF oldcolor, newcolor;
472 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
473 myrect.right = myrect.left + 1;
474 myrect.top = lpRect->top + 2;
475 myrect.bottom = lpRect->bottom - 2;
477 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
478 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
479 oldcolor = SetBkColor (hdc, newcolor);
480 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
482 myrect.left = myrect.right;
483 myrect.right = myrect.left + 1;
485 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
486 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
487 SetBkColor (hdc, newcolor);
488 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
490 SetBkColor (hdc, oldcolor);
494 /***********************************************************************
495 * TOOLBAR_DrawDDFlatSeparator
497 * This function draws the separator that was flagged as BTNS_DROPDOWN.
498 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
499 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
500 * are horizontal as opposed to the vertical separators for not dropdown
501 * type.
503 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
505 static void
506 TOOLBAR_DrawDDFlatSeparator (const RECT *lpRect, HDC hdc,
507 const TOOLBAR_INFO *infoPtr)
509 RECT myrect;
510 COLORREF oldcolor, newcolor;
512 myrect.left = lpRect->left;
513 myrect.right = lpRect->right;
514 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
515 myrect.bottom = myrect.top + 1;
517 InflateRect (&myrect, -2, 0);
519 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect));
521 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
522 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
523 oldcolor = SetBkColor (hdc, newcolor);
524 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
526 myrect.top = myrect.bottom;
527 myrect.bottom = myrect.top + 1;
529 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
530 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
531 SetBkColor (hdc, newcolor);
532 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
534 SetBkColor (hdc, oldcolor);
538 static void
539 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
541 INT x, y;
542 HPEN hPen, hOldPen;
544 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
545 hOldPen = SelectObject ( hdc, hPen );
546 x = left + 2;
547 y = top;
548 MoveToEx (hdc, x, y, NULL);
549 LineTo (hdc, x+5, y++); x++;
550 MoveToEx (hdc, x, y, NULL);
551 LineTo (hdc, x+3, y++); x++;
552 MoveToEx (hdc, x, y, NULL);
553 LineTo (hdc, x+1, y);
554 SelectObject( hdc, hOldPen );
555 DeleteObject( hPen );
559 * Draw the text string for this button.
560 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
561 * is non-zero, so we can simply check himlDef to see if we have
562 * an image list
564 static void
565 TOOLBAR_DrawString (const TOOLBAR_INFO *infoPtr, RECT *rcText, LPCWSTR lpText,
566 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
568 HDC hdc = tbcd->nmcd.hdc;
569 HFONT hOldFont = 0;
570 COLORREF clrOld = 0;
571 COLORREF clrOldBk = 0;
572 int oldBkMode = 0;
573 UINT state = tbcd->nmcd.uItemState;
575 /* draw text */
576 if (lpText) {
577 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText),
578 wine_dbgstr_rect(rcText));
580 hOldFont = SelectObject (hdc, infoPtr->hFont);
581 if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
582 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
584 else if (state & CDIS_DISABLED) {
585 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
586 OffsetRect (rcText, 1, 1);
587 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
588 SetTextColor (hdc, comctl32_color.clr3dShadow);
589 OffsetRect (rcText, -1, -1);
591 else if (state & CDIS_INDETERMINATE) {
592 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
594 else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
595 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
596 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
597 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
599 else {
600 clrOld = SetTextColor (hdc, tbcd->clrText);
603 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
604 SetTextColor (hdc, clrOld);
605 if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
607 SetBkColor (hdc, clrOldBk);
608 SetBkMode (hdc, oldBkMode);
610 SelectObject (hdc, hOldFont);
615 static void
616 TOOLBAR_DrawPattern (const RECT *lpRect, const NMTBCUSTOMDRAW *tbcd)
618 HDC hdc = tbcd->nmcd.hdc;
619 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
620 COLORREF clrTextOld;
621 COLORREF clrBkOld;
622 INT cx = lpRect->right - lpRect->left;
623 INT cy = lpRect->bottom - lpRect->top;
624 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
625 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
626 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
627 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
628 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
629 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
630 SetBkColor(hdc, clrBkOld);
631 SetTextColor(hdc, clrTextOld);
632 SelectObject (hdc, hbr);
636 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
638 INT cx, cy;
639 HBITMAP hbmMask, hbmImage;
640 HDC hdcMask, hdcImage;
642 ImageList_GetIconSize(himl, &cx, &cy);
644 /* Create src image */
645 hdcImage = CreateCompatibleDC(hdc);
646 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
647 SelectObject(hdcImage, hbmImage);
648 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
649 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
651 /* Create Mask */
652 hdcMask = CreateCompatibleDC(0);
653 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
654 SelectObject(hdcMask, hbmMask);
656 /* Remove the background and all white pixels */
657 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
658 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
659 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
660 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
662 /* draw the new mask 'etched' to hdc */
663 SetBkColor(hdc, RGB(255, 255, 255));
664 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
665 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
666 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
667 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
668 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
670 /* Cleanup */
671 DeleteObject(hbmImage);
672 DeleteDC(hdcImage);
673 DeleteObject (hbmMask);
674 DeleteDC(hdcMask);
678 static UINT
679 TOOLBAR_TranslateState(const TBUTTON_INFO *btnPtr)
681 UINT retstate = 0;
683 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
684 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
685 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
686 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
687 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
688 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
689 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
690 return retstate;
693 /* draws the image on a toolbar button */
694 static void
695 TOOLBAR_DrawImage(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
696 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
698 HIMAGELIST himl = NULL;
699 BOOL draw_masked = FALSE;
700 INT index;
701 INT offset = 0;
702 UINT draw_flags = ILD_TRANSPARENT;
704 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
706 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
707 if (!himl)
709 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
710 draw_masked = TRUE;
713 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
714 ((tbcd->nmcd.uItemState & CDIS_HOT)
715 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
717 /* if hot, attempt to draw with hot image list, if fails,
718 use default image list */
719 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
720 if (!himl)
721 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
723 else
724 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
726 if (!himl)
727 return;
729 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
730 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
731 offset = 1;
733 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
734 (tbcd->nmcd.uItemState & CDIS_MARKED))
735 draw_flags |= ILD_BLEND50;
737 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
738 index, himl, left, top, offset);
740 if (draw_masked)
741 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
742 else
743 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
746 /* draws a blank frame for a toolbar button */
747 static void
748 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
750 HDC hdc = tbcd->nmcd.hdc;
751 RECT rc = tbcd->nmcd.rc;
752 /* if the state is disabled or indeterminate then the button
753 * cannot have an interactive look like pressed or hot */
754 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
755 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
756 BOOL pressed_look = !non_interactive_state &&
757 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
758 (tbcd->nmcd.uItemState & CDIS_CHECKED));
760 /* app don't want us to draw any edges */
761 if (dwItemCDFlag & TBCDRF_NOEDGES)
762 return;
764 if (infoPtr->dwStyle & TBSTYLE_FLAT)
766 if (pressed_look)
767 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
768 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
769 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
771 else
773 if (pressed_look)
774 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
775 else
776 DrawEdge (hdc, &rc, EDGE_RAISED,
777 BF_SOFT | BF_RECT | BF_MIDDLE);
781 static void
782 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
784 HDC hdc = tbcd->nmcd.hdc;
785 int offset = 0;
786 BOOL pressed = bDropDownPressed ||
787 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
789 if (infoPtr->dwStyle & TBSTYLE_FLAT)
791 if (pressed)
792 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
793 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
794 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
795 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
796 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
798 else
800 if (pressed)
801 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
802 else
803 DrawEdge (hdc, rcArrow, EDGE_RAISED,
804 BF_SOFT | BF_RECT | BF_MIDDLE);
807 if (pressed)
808 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
810 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
812 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
813 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
815 else
816 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
819 /* draws a complete toolbar button */
820 static void
821 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
823 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
824 DWORD dwStyle = infoPtr->dwStyle;
825 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
826 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
827 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
828 BOOL drawSepDropDownArrow = hasDropDownArrow &&
829 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
830 RECT rc, rcArrow, rcBitmap, rcText;
831 LPWSTR lpText = NULL;
832 NMTBCUSTOMDRAW tbcd;
833 DWORD ntfret;
834 INT offset;
835 INT oldBkMode;
836 DWORD dwItemCustDraw;
837 DWORD dwItemCDFlag;
838 HTHEME theme = GetWindowTheme (hwnd);
840 rc = btnPtr->rect;
841 CopyRect (&rcArrow, &rc);
843 /* separator - doesn't send NM_CUSTOMDRAW */
844 if (btnPtr->fsStyle & BTNS_SEP) {
845 if (theme)
847 DrawThemeBackground (theme, hdc,
848 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
849 &rc, NULL);
851 else
852 /* with the FLAT style, iBitmap is the width and has already */
853 /* been taken into consideration in calculating the width */
854 /* so now we need to draw the vertical separator */
855 /* empirical tests show that iBitmap can/will be non-zero */
856 /* when drawing the vertical bar... */
857 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
858 if (btnPtr->fsStyle & BTNS_DROPDOWN)
859 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, infoPtr);
860 else
861 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
863 else if (btnPtr->fsStyle != BTNS_SEP) {
864 FIXME("Draw some kind of separator: fsStyle=%x\n",
865 btnPtr->fsStyle);
867 return;
870 /* get a pointer to the text */
871 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
873 if (hasDropDownArrow)
875 int right;
877 if (dwStyle & TBSTYLE_FLAT)
878 right = max(rc.left, rc.right - DDARROW_WIDTH);
879 else
880 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
882 if (drawSepDropDownArrow)
883 rc.right = right;
885 rcArrow.left = right;
888 /* copy text & bitmap rects after adjusting for drop-down arrow
889 * so that text & bitmap is centered in the rectangle not containing
890 * the arrow */
891 CopyRect(&rcText, &rc);
892 CopyRect(&rcBitmap, &rc);
894 /* Center the bitmap horizontally and vertically */
895 if (dwStyle & TBSTYLE_LIST)
897 if (lpText &&
898 infoPtr->nMaxTextRows > 0 &&
899 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
900 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
901 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
902 else
903 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
905 else
906 rcBitmap.left += ((rc.right - rc.left) - infoPtr->nBitmapWidth) / 2;
908 rcBitmap.top += infoPtr->szPadding.cy / 2;
910 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
911 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
912 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
913 TRACE("Text=%s\n", debugstr_w(lpText));
914 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
916 /* calculate text position */
917 if (lpText)
919 rcText.left += GetSystemMetrics(SM_CXEDGE);
920 rcText.right -= GetSystemMetrics(SM_CXEDGE);
921 if (dwStyle & TBSTYLE_LIST)
923 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
925 else
927 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
928 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
929 else
930 rcText.top += infoPtr->szPadding.cy/2 + 2;
934 /* Initialize fields in all cases, because we use these later
935 * NOTE: applications can and do alter these to customize their
936 * toolbars */
937 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
938 tbcd.clrText = comctl32_color.clrBtnText;
939 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
940 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
941 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
942 tbcd.clrMark = comctl32_color.clrHighlight;
943 tbcd.clrHighlightHotTrack = 0;
944 tbcd.nStringBkMode = TRANSPARENT;
945 tbcd.nHLStringBkMode = OPAQUE;
946 /* MSDN says that this is the text rectangle.
947 * But (why always a but) tracing of v5.7 of native shows
948 * that this is really a *relative* rectangle based on the
949 * the nmcd.rc. Also the left and top are always 0 ignoring
950 * any bitmap that might be present. */
951 tbcd.rcText.left = 0;
952 tbcd.rcText.top = 0;
953 tbcd.rcText.right = rcText.right - rc.left;
954 tbcd.rcText.bottom = rcText.bottom - rc.top;
955 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
956 tbcd.nmcd.hdc = hdc;
957 tbcd.nmcd.rc = rc;
958 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
960 /* FIXME: what are these used for? */
961 tbcd.hbrLines = 0;
962 tbcd.hpenLines = 0;
964 /* Issue Item Prepaint notify */
965 dwItemCustDraw = 0;
966 dwItemCDFlag = 0;
967 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
969 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
970 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
971 tbcd.nmcd.lItemlParam = btnPtr->dwData;
972 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
973 /* reset these fields so the user can't alter the behaviour like native */
974 tbcd.nmcd.hdc = hdc;
975 tbcd.nmcd.rc = rc;
977 dwItemCustDraw = ntfret & 0xffff;
978 dwItemCDFlag = ntfret & 0xffff0000;
979 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
980 return;
981 /* save the only part of the rect that the user can change */
982 rcText.right = tbcd.rcText.right + rc.left;
983 rcText.bottom = tbcd.rcText.bottom + rc.top;
986 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
987 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
988 OffsetRect(&rcText, 1, 1);
990 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
991 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
992 TOOLBAR_DrawPattern (&rc, &tbcd);
994 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
995 && (tbcd.nmcd.uItemState & CDIS_HOT))
997 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
999 COLORREF oldclr;
1001 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
1002 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
1003 if (hasDropDownArrow)
1004 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
1005 SetBkColor(hdc, oldclr);
1009 if (theme)
1011 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1012 int stateId = TS_NORMAL;
1014 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1015 stateId = TS_DISABLED;
1016 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1017 stateId = TS_PRESSED;
1018 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1019 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1020 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1021 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1022 stateId = TS_HOT;
1024 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1026 else
1027 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1029 if (drawSepDropDownArrow)
1031 if (theme)
1033 int stateId = TS_NORMAL;
1035 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1036 stateId = TS_DISABLED;
1037 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1038 stateId = TS_PRESSED;
1039 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1040 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1041 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1042 stateId = TS_HOT;
1044 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1045 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1047 else
1048 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1051 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1052 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1053 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1054 SetBkMode (hdc, oldBkMode);
1056 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1058 if (hasDropDownArrow && !drawSepDropDownArrow)
1060 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1062 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1063 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1065 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1067 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1068 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1070 else
1071 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1074 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1076 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1077 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1083 static void
1084 TOOLBAR_Refresh (HWND hwnd, HDC hdc, const PAINTSTRUCT *ps)
1086 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1087 TBUTTON_INFO *btnPtr;
1088 INT i;
1089 RECT rcTemp, rcClient;
1090 NMTBCUSTOMDRAW tbcd;
1091 DWORD ntfret;
1092 DWORD dwBaseCustDraw;
1094 /* the app has told us not to redraw the toolbar */
1095 if (!infoPtr->bDoRedraw)
1096 return;
1098 /* if imagelist belongs to the app, it can be changed
1099 by the app after setting it */
1100 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1102 infoPtr->nNumBitmaps = 0;
1103 for (i = 0; i < infoPtr->cimlDef; i++)
1104 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1107 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1109 /* change the imagelist icon size if we manage the list and it is necessary */
1110 TOOLBAR_CheckImageListIconSize(infoPtr);
1112 /* Send initial notify */
1113 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1114 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1115 tbcd.nmcd.hdc = hdc;
1116 tbcd.nmcd.rc = ps->rcPaint;
1117 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1118 dwBaseCustDraw = ntfret & 0xffff;
1120 GetClientRect(hwnd, &rcClient);
1122 /* redraw necessary buttons */
1123 btnPtr = infoPtr->buttons;
1124 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1126 BOOL bDraw;
1127 if (!RectVisible(hdc, &btnPtr->rect))
1128 continue;
1129 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1131 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1132 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1134 else
1135 bDraw = TRUE;
1136 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1137 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1138 if (bDraw)
1139 TOOLBAR_DrawButton(hwnd, btnPtr, hdc, dwBaseCustDraw);
1142 /* draw insert mark if required */
1143 if (infoPtr->tbim.iButton != -1)
1145 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1146 RECT rcInsertMark;
1147 rcInsertMark.top = rcButton.top;
1148 rcInsertMark.bottom = rcButton.bottom;
1149 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1150 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1151 else
1152 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1153 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1156 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1158 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1159 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1160 tbcd.nmcd.hdc = hdc;
1161 tbcd.nmcd.rc = ps->rcPaint;
1162 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1166 /***********************************************************************
1167 * TOOLBAR_MeasureString
1169 * This function gets the width and height of a string in pixels. This
1170 * is done first by using GetTextExtentPoint to get the basic width
1171 * and height. The DrawText is called with DT_CALCRECT to get the exact
1172 * width. The reason is because the text may have more than one "&" (or
1173 * prefix characters as M$ likes to call them). The prefix character
1174 * indicates where the underline goes, except for the string "&&" which
1175 * is reduced to a single "&". GetTextExtentPoint does not process these
1176 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1178 static void
1179 TOOLBAR_MeasureString(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr,
1180 HDC hdc, LPSIZE lpSize)
1182 RECT myrect;
1184 lpSize->cx = 0;
1185 lpSize->cy = 0;
1187 if (infoPtr->nMaxTextRows > 0 &&
1188 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1189 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1190 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1192 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1194 if(lpText != NULL) {
1195 /* first get size of all the text */
1196 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1198 /* feed above size into the rectangle for DrawText */
1199 myrect.left = myrect.top = 0;
1200 myrect.right = lpSize->cx;
1201 myrect.bottom = lpSize->cy;
1203 /* Use DrawText to get true size as drawn (less pesky "&") */
1204 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1205 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1206 DT_NOPREFIX : 0));
1208 /* feed back to caller */
1209 lpSize->cx = myrect.right;
1210 lpSize->cy = myrect.bottom;
1214 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1217 /***********************************************************************
1218 * TOOLBAR_CalcStrings
1220 * This function walks through each string and measures it and returns
1221 * the largest height and width to caller.
1223 static void
1224 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1226 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1227 TBUTTON_INFO *btnPtr;
1228 INT i;
1229 SIZE sz;
1230 HDC hdc;
1231 HFONT hOldFont;
1233 lpSize->cx = 0;
1234 lpSize->cy = 0;
1236 if (infoPtr->nMaxTextRows == 0)
1237 return;
1239 hdc = GetDC (hwnd);
1240 hOldFont = SelectObject (hdc, infoPtr->hFont);
1242 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1244 TEXTMETRICW tm;
1246 GetTextMetricsW(hdc, &tm);
1247 lpSize->cy = tm.tmHeight;
1250 btnPtr = infoPtr->buttons;
1251 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1252 if(TOOLBAR_HasText(infoPtr, btnPtr))
1254 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1255 if (sz.cx > lpSize->cx)
1256 lpSize->cx = sz.cx;
1257 if (sz.cy > lpSize->cy)
1258 lpSize->cy = sz.cy;
1262 SelectObject (hdc, hOldFont);
1263 ReleaseDC (hwnd, hdc);
1265 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1268 /***********************************************************************
1269 * TOOLBAR_WrapToolbar
1271 * This function walks through the buttons and separators in the
1272 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1273 * wrapping should occur based on the width of the toolbar window.
1274 * It does *not* calculate button placement itself. That task
1275 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1276 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1277 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1279 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1280 * vertical toolbar lists.
1283 static void
1284 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1286 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1287 TBUTTON_INFO *btnPtr;
1288 INT x, cx, i, j;
1289 RECT rc;
1290 BOOL bButtonWrap;
1292 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1293 /* no layout is necessary. Applications may use this style */
1294 /* to perform their own layout on the toolbar. */
1295 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1296 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1298 btnPtr = infoPtr->buttons;
1299 x = infoPtr->nIndent;
1301 if (GetParent(hwnd))
1303 /* this can get the parents width, to know how far we can extend
1304 * this toolbar. We cannot use its height, as there may be multiple
1305 * toolbars in a rebar control
1307 GetClientRect( GetParent(hwnd), &rc );
1308 infoPtr->nWidth = rc.right - rc.left;
1310 else
1312 GetWindowRect( hwnd, &rc );
1313 infoPtr->nWidth = rc.right - rc.left;
1316 bButtonWrap = FALSE;
1318 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1319 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1320 infoPtr->nIndent);
1322 for (i = 0; i < infoPtr->nNumButtons; i++ )
1324 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1326 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1327 continue;
1329 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1330 /* it is the actual width of the separator. This is used for */
1331 /* custom controls in toolbars. */
1332 /* */
1333 /* BTNS_DROPDOWN separators are treated as buttons for */
1334 /* width. - GA 8/01 */
1335 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1336 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1337 cx = (btnPtr[i].iBitmap > 0) ?
1338 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1339 else
1340 cx = (btnPtr[i].cx) ? btnPtr[i].cx : infoPtr->nButtonWidth;
1342 /* Two or more adjacent separators form a separator group. */
1343 /* The first separator in a group should be wrapped to the */
1344 /* next row if the previous wrapping is on a button. */
1345 if( bButtonWrap &&
1346 (btnPtr[i].fsStyle & BTNS_SEP) &&
1347 (i + 1 < infoPtr->nNumButtons ) &&
1348 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1350 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1351 btnPtr[i].fsState |= TBSTATE_WRAP;
1352 x = infoPtr->nIndent;
1353 i++;
1354 bButtonWrap = FALSE;
1355 continue;
1358 /* The layout makes sure the bitmap is visible, but not the button. */
1359 /* Test added to also wrap after a button that starts a row but */
1360 /* is bigger than the area. - GA 8/01 */
1361 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1362 > infoPtr->nWidth ) ||
1363 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1365 BOOL bFound = FALSE;
1367 /* If the current button is a separator and not hidden, */
1368 /* go to the next until it reaches a non separator. */
1369 /* Wrap the last separator if it is before a button. */
1370 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1371 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1372 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1373 i < infoPtr->nNumButtons )
1375 i++;
1376 bFound = TRUE;
1379 if( bFound && i < infoPtr->nNumButtons )
1381 i--;
1382 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1383 i, btnPtr[i].fsStyle, x, cx);
1384 btnPtr[i].fsState |= TBSTATE_WRAP;
1385 x = infoPtr->nIndent;
1386 bButtonWrap = FALSE;
1387 continue;
1389 else if ( i >= infoPtr->nNumButtons)
1390 break;
1392 /* If the current button is not a separator, find the last */
1393 /* separator and wrap it. */
1394 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1396 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1397 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1399 bFound = TRUE;
1400 i = j;
1401 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1402 i, btnPtr[i].fsStyle, x, cx);
1403 x = infoPtr->nIndent;
1404 btnPtr[j].fsState |= TBSTATE_WRAP;
1405 bButtonWrap = FALSE;
1406 break;
1410 /* If no separator available for wrapping, wrap one of */
1411 /* non-hidden previous button. */
1412 if (!bFound)
1414 for ( j = i - 1;
1415 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1417 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1418 continue;
1420 bFound = TRUE;
1421 i = j;
1422 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1423 i, btnPtr[i].fsStyle, x, cx);
1424 x = infoPtr->nIndent;
1425 btnPtr[j].fsState |= TBSTATE_WRAP;
1426 bButtonWrap = TRUE;
1427 break;
1431 /* If all above failed, wrap the current button. */
1432 if (!bFound)
1434 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1435 i, btnPtr[i].fsStyle, x, cx);
1436 btnPtr[i].fsState |= TBSTATE_WRAP;
1437 x = infoPtr->nIndent;
1438 if (btnPtr[i].fsStyle & BTNS_SEP )
1439 bButtonWrap = FALSE;
1440 else
1441 bButtonWrap = TRUE;
1444 else {
1445 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1446 i, btnPtr[i].fsStyle, x, cx);
1447 x += cx;
1453 /***********************************************************************
1454 * TOOLBAR_MeasureButton
1456 * Calculates the width and height required for a button. Used in
1457 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1458 * the width of buttons that are autosized.
1460 * Note that it would have been rather elegant to use one piece of code for
1461 * both the laying out of the toolbar and for controlling where button parts
1462 * are drawn, but the native control has inconsistencies between the two that
1463 * prevent this from being effectively. These inconsistencies can be seen as
1464 * artefacts where parts of the button appear outside of the bounding button
1465 * rectangle.
1467 * There are several cases for the calculation of the button dimensions and
1468 * button part positioning:
1470 * List
1471 * ====
1473 * With Bitmap:
1475 * +--------------------------------------------------------+ ^
1476 * | ^ ^ | |
1477 * | | pad.cy / 2 | centred | |
1478 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1479 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1480 * | |<------------>| | | | |
1481 * | +--------------+ +------------+ | |
1482 * |<-------------------------------------->| | |
1483 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1484 * | szText.cx | |
1485 * +--------------------------------------------------------+ -
1486 * <-------------------------------------------------------->
1487 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1489 * Without Bitmap (I_IMAGENONE):
1491 * +-----------------------------------+ ^
1492 * | ^ | |
1493 * | | centred | | LISTPAD_CY +
1494 * | +------------+ | | szText.cy
1495 * | | Text | | |
1496 * | | | | |
1497 * | +------------+ | |
1498 * |<----------------->| | |
1499 * | cxedge |<-----------> | |
1500 * | szText.cx | |
1501 * +-----------------------------------+ -
1502 * <----------------------------------->
1503 * szText.cx + pad.cx
1505 * Without text:
1507 * +--------------------------------------+ ^
1508 * | ^ | |
1509 * | | padding.cy/2 | | DEFPAD_CY +
1510 * | +------------+ | | nBitmapHeight
1511 * | | Bitmap | | |
1512 * | | | | |
1513 * | +------------+ | |
1514 * |<------------------->| | |
1515 * | cxedge + iListGap/2 |<-----------> | |
1516 * | nBitmapWidth | |
1517 * +--------------------------------------+ -
1518 * <-------------------------------------->
1519 * 2*cxedge + nBitmapWidth + iListGap
1521 * Non-List
1522 * ========
1524 * With bitmap:
1526 * +-----------------------------------+ ^
1527 * | ^ | |
1528 * | | pad.cy / 2 | | nBitmapHeight +
1529 * | - | | szText.cy +
1530 * | +------------+ | | DEFPAD_CY + 1
1531 * | centred | Bitmap | | |
1532 * |<----------------->| | | |
1533 * | +------------+ | |
1534 * | ^ | |
1535 * | 1 | | |
1536 * | - | |
1537 * | centred +---------------+ | |
1538 * |<--------------->| Text | | |
1539 * | +---------------+ | |
1540 * +-----------------------------------+ -
1541 * <----------------------------------->
1542 * pad.cx + max(nBitmapWidth, szText.cx)
1544 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1546 * +---------------------------------------+ ^
1547 * | ^ | |
1548 * | | 2 + pad.cy / 2 | |
1549 * | - | | szText.cy +
1550 * | centred +-----------------+ | | pad.cy + 2
1551 * |<--------------->| Text | | |
1552 * | +-----------------+ | |
1553 * | | |
1554 * +---------------------------------------+ -
1555 * <--------------------------------------->
1556 * 2*cxedge + pad.cx + szText.cx
1558 * Without text:
1559 * As for with bitmaps, but with szText.cx zero.
1561 static inline SIZE TOOLBAR_MeasureButton(const TOOLBAR_INFO *infoPtr, SIZE sizeString,
1562 BOOL bHasBitmap, BOOL bValidImageList)
1564 SIZE sizeButton;
1565 if (infoPtr->dwStyle & TBSTYLE_LIST)
1567 /* set button height from bitmap / text height... */
1568 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1569 sizeString.cy);
1571 /* ... add on the necessary padding */
1572 if (bValidImageList)
1574 if (bHasBitmap)
1575 sizeButton.cy += DEFPAD_CY;
1576 else
1577 sizeButton.cy += LISTPAD_CY;
1579 else
1580 sizeButton.cy += infoPtr->szPadding.cy;
1582 /* calculate button width */
1583 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1584 infoPtr->nBitmapWidth + infoPtr->iListGap;
1585 if (sizeString.cx > 0)
1586 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1589 else
1591 if (bHasBitmap)
1593 sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
1594 if (sizeString.cy > 0)
1595 sizeButton.cy += 1 + sizeString.cy;
1596 sizeButton.cx = infoPtr->szPadding.cx +
1597 max(sizeString.cx, infoPtr->nBitmapWidth);
1599 else
1601 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1602 NONLIST_NOTEXT_OFFSET;
1603 sizeButton.cx = infoPtr->szPadding.cx +
1604 max(2*GetSystemMetrics(SM_CXEDGE) + sizeString.cx, infoPtr->nBitmapWidth);
1607 return sizeButton;
1611 /***********************************************************************
1612 * TOOLBAR_CalcToolbar
1614 * This function calculates button and separator placement. It first
1615 * calculates the button sizes, gets the toolbar window width and then
1616 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1617 * on. It assigns a new location to each item and sends this location to
1618 * the tooltip window if appropriate. Finally, it updates the rcBound
1619 * rect and calculates the new required toolbar window height.
1621 static void
1622 TOOLBAR_CalcToolbar (HWND hwnd)
1624 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1625 SIZE sizeString, sizeButton;
1626 BOOL validImageList = FALSE;
1628 TOOLBAR_CalcStrings (hwnd, &sizeString);
1630 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1632 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1633 validImageList = TRUE;
1634 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1635 infoPtr->nButtonWidth = sizeButton.cx;
1636 infoPtr->nButtonHeight = sizeButton.cy;
1637 infoPtr->iTopMargin = default_top_margin(infoPtr);
1639 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1640 infoPtr->nButtonWidth = infoPtr->cxMin;
1641 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1642 infoPtr->nButtonWidth = infoPtr->cxMax;
1644 TOOLBAR_LayoutToolbar(hwnd);
1647 static void
1648 TOOLBAR_LayoutToolbar(HWND hwnd)
1650 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1651 TBUTTON_INFO *btnPtr;
1652 SIZE sizeButton;
1653 INT i, nRows, nSepRows;
1654 INT x, y, cx, cy;
1655 BOOL bWrap;
1656 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1657 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1659 TOOLBAR_WrapToolbar(hwnd, infoPtr->dwStyle);
1661 x = infoPtr->nIndent;
1662 y = infoPtr->iTopMargin;
1663 cx = infoPtr->nButtonWidth;
1664 cy = infoPtr->nButtonHeight;
1666 nRows = nSepRows = 0;
1668 infoPtr->rcBound.top = y;
1669 infoPtr->rcBound.left = x;
1670 infoPtr->rcBound.bottom = y + cy;
1671 infoPtr->rcBound.right = x;
1673 btnPtr = infoPtr->buttons;
1675 TRACE("cy=%d\n", cy);
1677 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1679 bWrap = FALSE;
1680 if (btnPtr->fsState & TBSTATE_HIDDEN)
1682 SetRectEmpty (&btnPtr->rect);
1683 continue;
1686 cy = infoPtr->nButtonHeight;
1688 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1689 /* it is the actual width of the separator. This is used for */
1690 /* custom controls in toolbars. */
1691 if (btnPtr->fsStyle & BTNS_SEP) {
1692 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1693 cy = (btnPtr->iBitmap > 0) ?
1694 btnPtr->iBitmap : SEPARATOR_WIDTH;
1695 cx = infoPtr->nButtonWidth;
1697 else
1698 cx = (btnPtr->iBitmap > 0) ?
1699 btnPtr->iBitmap : SEPARATOR_WIDTH;
1701 else
1703 if (btnPtr->cx)
1704 cx = btnPtr->cx;
1705 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1706 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1708 SIZE sz;
1709 HDC hdc;
1710 HFONT hOldFont;
1712 hdc = GetDC (hwnd);
1713 hOldFont = SelectObject (hdc, infoPtr->hFont);
1715 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1717 SelectObject (hdc, hOldFont);
1718 ReleaseDC (hwnd, hdc);
1720 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1721 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1722 validImageList);
1723 cx = sizeButton.cx;
1725 else
1726 cx = infoPtr->nButtonWidth;
1728 /* if size has been set manually then don't add on extra space
1729 * for the drop down arrow */
1730 if (!btnPtr->cx && hasDropDownArrows &&
1731 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1732 cx += DDARROW_WIDTH;
1734 if (btnPtr->fsState & TBSTATE_WRAP )
1735 bWrap = TRUE;
1737 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1739 if (infoPtr->rcBound.left > x)
1740 infoPtr->rcBound.left = x;
1741 if (infoPtr->rcBound.right < x + cx)
1742 infoPtr->rcBound.right = x + cx;
1743 if (infoPtr->rcBound.bottom < y + cy)
1744 infoPtr->rcBound.bottom = y + cy;
1746 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1748 /* btnPtr->nRow is zero based. The space between the rows is */
1749 /* also considered as a row. */
1750 btnPtr->nRow = nRows + nSepRows;
1752 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1753 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1754 x, y, x+cx, y+cy);
1756 if( bWrap )
1758 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1759 y += cy;
1760 else
1762 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1763 /* it is the actual width of the separator. This is used for */
1764 /* custom controls in toolbars. */
1765 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1766 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1767 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1768 else
1769 y += cy;
1771 /* nSepRows is used to calculate the extra height following */
1772 /* the last row. */
1773 nSepRows++;
1775 x = infoPtr->nIndent;
1777 /* Increment row number unless this is the last button */
1778 /* and it has Wrap set. */
1779 if (i != infoPtr->nNumButtons-1)
1780 nRows++;
1782 else
1783 x += cx;
1786 /* infoPtr->nRows is the number of rows on the toolbar */
1787 infoPtr->nRows = nRows + nSepRows + 1;
1789 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1793 static INT
1794 TOOLBAR_InternalHitTest (HWND hwnd, const POINT *lpPt)
1796 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1797 TBUTTON_INFO *btnPtr;
1798 INT i;
1800 btnPtr = infoPtr->buttons;
1801 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1802 if (btnPtr->fsState & TBSTATE_HIDDEN)
1803 continue;
1805 if (btnPtr->fsStyle & BTNS_SEP) {
1806 if (PtInRect (&btnPtr->rect, *lpPt)) {
1807 TRACE(" ON SEPARATOR %d!\n", i);
1808 return -i;
1811 else {
1812 if (PtInRect (&btnPtr->rect, *lpPt)) {
1813 TRACE(" ON BUTTON %d!\n", i);
1814 return i;
1819 TRACE(" NOWHERE!\n");
1820 return TOOLBAR_NOWHERE;
1824 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1825 static BOOL
1826 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO *infoPtr, INT iIndex, UINT nAddButtons, TBBUTTON *lpTbb, BOOL fUnicode)
1828 INT nOldButtons, nNewButtons, iButton;
1829 BOOL fHasString = FALSE;
1831 if (iIndex < 0) /* iIndex can be negative, what means adding at the end */
1832 iIndex = infoPtr->nNumButtons;
1834 nOldButtons = infoPtr->nNumButtons;
1835 nNewButtons = nOldButtons + nAddButtons;
1837 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
1838 memmove(&infoPtr->buttons[iIndex + nAddButtons], &infoPtr->buttons[iIndex],
1839 (nOldButtons - iIndex) * sizeof(TBUTTON_INFO));
1840 infoPtr->nNumButtons += nAddButtons;
1842 /* insert new buttons data */
1843 for (iButton = 0; iButton < nAddButtons; iButton++) {
1844 TBUTTON_INFO *btnPtr = &infoPtr->buttons[iIndex + iButton];
1846 TOOLBAR_DumpTBButton(lpTbb, fUnicode);
1848 ZeroMemory(btnPtr, sizeof(*btnPtr));
1849 btnPtr->iBitmap = lpTbb[iButton].iBitmap;
1850 btnPtr->idCommand = lpTbb[iButton].idCommand;
1851 btnPtr->fsState = lpTbb[iButton].fsState;
1852 btnPtr->fsStyle = lpTbb[iButton].fsStyle;
1853 btnPtr->dwData = lpTbb[iButton].dwData;
1854 if(HIWORD(lpTbb[iButton].iString) && lpTbb[iButton].iString != -1)
1856 if (fUnicode)
1857 Str_SetPtrW((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[iButton].iString );
1858 else
1859 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[iButton].iString);
1860 fHasString = TRUE;
1862 else
1863 btnPtr->iString = lpTbb[iButton].iString;
1865 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
1868 if (infoPtr->nNumStrings > 0 || fHasString)
1869 TOOLBAR_CalcToolbar(infoPtr->hwndSelf);
1870 else
1871 TOOLBAR_LayoutToolbar(infoPtr->hwndSelf);
1872 TOOLBAR_AutoSize(infoPtr->hwndSelf);
1874 TOOLBAR_DumpToolbar(infoPtr, __LINE__);
1875 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1876 return TRUE;
1880 static INT
1881 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1883 TBUTTON_INFO *btnPtr;
1884 INT i;
1886 if (CommandIsIndex) {
1887 TRACE("command is really index command=%d\n", idCommand);
1888 if (idCommand >= infoPtr->nNumButtons) return -1;
1889 return idCommand;
1891 btnPtr = infoPtr->buttons;
1892 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1893 if (btnPtr->idCommand == idCommand) {
1894 TRACE("command=%d index=%d\n", idCommand, i);
1895 return i;
1898 TRACE("no index found for command=%d\n", idCommand);
1899 return -1;
1903 static INT
1904 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO *infoPtr, INT nIndex)
1906 TBUTTON_INFO *btnPtr;
1907 INT nRunIndex;
1909 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1910 return -1;
1912 /* check index button */
1913 btnPtr = &infoPtr->buttons[nIndex];
1914 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1915 if (btnPtr->fsState & TBSTATE_CHECKED)
1916 return nIndex;
1919 /* check previous buttons */
1920 nRunIndex = nIndex - 1;
1921 while (nRunIndex >= 0) {
1922 btnPtr = &infoPtr->buttons[nRunIndex];
1923 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1924 if (btnPtr->fsState & TBSTATE_CHECKED)
1925 return nRunIndex;
1927 else
1928 break;
1929 nRunIndex--;
1932 /* check next buttons */
1933 nRunIndex = nIndex + 1;
1934 while (nRunIndex < infoPtr->nNumButtons) {
1935 btnPtr = &infoPtr->buttons[nRunIndex];
1936 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1937 if (btnPtr->fsState & TBSTATE_CHECKED)
1938 return nRunIndex;
1940 else
1941 break;
1942 nRunIndex++;
1945 return -1;
1949 static VOID
1950 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1951 WPARAM wParam, LPARAM lParam)
1953 MSG msg;
1955 msg.hwnd = hwndMsg;
1956 msg.message = uMsg;
1957 msg.wParam = wParam;
1958 msg.lParam = lParam;
1959 msg.time = GetMessageTime ();
1960 msg.pt.x = (short)LOWORD(GetMessagePos ());
1961 msg.pt.y = (short)HIWORD(GetMessagePos ());
1963 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1966 static void
1967 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1969 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1970 TTTOOLINFOW ti;
1972 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1973 ti.cbSize = sizeof (TTTOOLINFOW);
1974 ti.hwnd = infoPtr->hwndSelf;
1975 ti.uId = button->idCommand;
1976 ti.hinst = 0;
1977 ti.lpszText = LPSTR_TEXTCALLBACKW;
1978 /* ti.lParam = random value from the stack? */
1980 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1981 0, (LPARAM)&ti);
1985 static void
1986 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1988 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1989 TTTOOLINFOW ti;
1991 ZeroMemory(&ti, sizeof(ti));
1992 ti.cbSize = sizeof(ti);
1993 ti.hwnd = infoPtr->hwndSelf;
1994 ti.uId = button->idCommand;
1996 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
2000 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
2002 /* Set the toolTip only for non-hidden, non-separator button */
2003 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
2005 TTTOOLINFOW ti;
2007 ZeroMemory(&ti, sizeof(ti));
2008 ti.cbSize = sizeof(ti);
2009 ti.hwnd = infoPtr->hwndSelf;
2010 ti.uId = button->idCommand;
2011 ti.rect = button->rect;
2012 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
2016 /* Creates the tooltip control */
2017 static void
2018 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
2020 int i;
2021 NMTOOLTIPSCREATED nmttc;
2023 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
2024 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2025 infoPtr->hwndSelf, 0, 0, 0);
2027 if (!infoPtr->hwndToolTip)
2028 return;
2030 /* Send NM_TOOLTIPSCREATED notification */
2031 nmttc.hwndToolTips = infoPtr->hwndToolTip;
2032 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
2034 for (i = 0; i < infoPtr->nNumButtons; i++)
2036 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
2037 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
2041 /* keeps available button list box sorted by button id */
2042 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
2044 int i;
2045 int count;
2046 PCUSTOMBUTTON btnInfo;
2047 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2049 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
2051 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2053 /* position 0 is always separator */
2054 for (i = 1; i < count; i++)
2056 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
2057 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2059 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2060 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2061 return;
2064 /* id higher than all others add to end */
2065 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2066 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2069 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2071 NMTOOLBARW nmtb;
2073 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2075 if (nIndexFrom == nIndexTo)
2076 return;
2078 /* MSDN states that iItem is the index of the button, rather than the
2079 * command ID as used by every other NMTOOLBAR notification */
2080 nmtb.iItem = nIndexFrom;
2081 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2083 PCUSTOMBUTTON btnInfo;
2084 NMHDR hdr;
2085 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2086 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2088 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2090 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2091 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2092 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2093 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2095 if (nIndexTo <= 0)
2096 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2097 else
2098 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2100 /* last item is always separator, so -2 instead of -1 */
2101 if (nIndexTo >= (count - 2))
2102 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2103 else
2104 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2106 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2107 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2109 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2113 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2115 NMTOOLBARW nmtb;
2117 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2119 /* MSDN states that iItem is the index of the button, rather than the
2120 * command ID as used by every other NMTOOLBAR notification */
2121 nmtb.iItem = nIndexAvail;
2122 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2124 PCUSTOMBUTTON btnInfo;
2125 NMHDR hdr;
2126 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2127 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2128 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2130 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2132 if (nIndexAvail != 0) /* index == 0 indicates separator */
2134 /* remove from 'available buttons' list */
2135 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2136 if (nIndexAvail == count-1)
2137 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2138 else
2139 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2141 else
2143 PCUSTOMBUTTON btnNew;
2145 /* duplicate 'separator' button */
2146 btnNew = Alloc(sizeof(CUSTOMBUTTON));
2147 *btnNew = *btnInfo;
2148 btnInfo = btnNew;
2151 /* insert into 'toolbar button' list */
2152 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2153 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2155 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2157 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2161 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT index)
2163 PCUSTOMBUTTON btnInfo;
2164 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2166 TRACE("Remove: index %d\n", index);
2168 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2170 /* send TBN_QUERYDELETE notification */
2171 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2173 NMHDR hdr;
2175 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2176 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2178 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2180 /* insert into 'available button' list */
2181 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2182 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2183 else
2184 Free(btnInfo);
2186 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2190 /* drag list notification function for toolbar buttons list box */
2191 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2192 const DRAGLISTINFO *pDLI)
2194 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2195 switch (pDLI->uNotification)
2197 case DL_BEGINDRAG:
2199 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2200 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2201 /* no dragging for last item (separator) */
2202 if (nCurrentItem >= (nCount - 1)) return FALSE;
2203 return TRUE;
2205 case DL_DRAGGING:
2207 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2208 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2209 /* no dragging past last item (separator) */
2210 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2212 DrawInsert(hwnd, hwndList, nCurrentItem);
2213 /* FIXME: native uses "move button" cursor */
2214 return DL_COPYCURSOR;
2217 /* not over toolbar buttons list */
2218 if (nCurrentItem < 0)
2220 POINT ptWindow = pDLI->ptCursor;
2221 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2222 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2223 /* over available buttons list? */
2224 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2225 /* FIXME: native uses "move button" cursor */
2226 return DL_COPYCURSOR;
2228 /* clear drag arrow */
2229 DrawInsert(hwnd, hwndList, -1);
2230 return DL_STOPCURSOR;
2232 case DL_DROPPED:
2234 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2235 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2236 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2237 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2239 /* clear drag arrow */
2240 DrawInsert(hwnd, hwndList, -1);
2241 /* move item */
2242 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2244 /* not over toolbar buttons list */
2245 if (nIndexTo < 0)
2247 POINT ptWindow = pDLI->ptCursor;
2248 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2249 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2250 /* over available buttons list? */
2251 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2252 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2254 break;
2256 case DL_CANCELDRAG:
2257 /* Clear drag arrow */
2258 DrawInsert(hwnd, hwndList, -1);
2259 break;
2262 return 0;
2265 /* drag list notification function for available buttons list box */
2266 static LRESULT TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2267 const DRAGLISTINFO *pDLI)
2269 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2270 switch (pDLI->uNotification)
2272 case DL_BEGINDRAG:
2273 return TRUE;
2274 case DL_DRAGGING:
2276 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2277 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2278 /* no dragging past last item (separator) */
2279 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2281 DrawInsert(hwnd, hwndList, nCurrentItem);
2282 /* FIXME: native uses "move button" cursor */
2283 return DL_COPYCURSOR;
2286 /* not over toolbar buttons list */
2287 if (nCurrentItem < 0)
2289 POINT ptWindow = pDLI->ptCursor;
2290 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2291 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2292 /* over available buttons list? */
2293 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2294 /* FIXME: native uses "move button" cursor */
2295 return DL_COPYCURSOR;
2297 /* clear drag arrow */
2298 DrawInsert(hwnd, hwndList, -1);
2299 return DL_STOPCURSOR;
2301 case DL_DROPPED:
2303 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2304 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2305 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2306 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2308 /* clear drag arrow */
2309 DrawInsert(hwnd, hwndList, -1);
2310 /* add item */
2311 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2314 case DL_CANCELDRAG:
2315 /* Clear drag arrow */
2316 DrawInsert(hwnd, hwndList, -1);
2317 break;
2319 return 0;
2322 extern UINT uDragListMessage;
2324 /***********************************************************************
2325 * TOOLBAR_CustomizeDialogProc
2326 * This function implements the toolbar customization dialog.
2328 static INT_PTR CALLBACK
2329 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2331 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2332 PCUSTOMBUTTON btnInfo;
2333 NMTOOLBARA nmtb;
2334 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2336 switch (uMsg)
2338 case WM_INITDIALOG:
2339 custInfo = (PCUSTDLG_INFO)lParam;
2340 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2342 if (custInfo)
2344 WCHAR Buffer[256];
2345 int i = 0;
2346 int index;
2347 NMTBINITCUSTOMIZE nmtbic;
2349 infoPtr = custInfo->tbInfo;
2351 /* send TBN_QUERYINSERT notification */
2352 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2354 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2355 return FALSE;
2357 nmtbic.hwndDialog = hwnd;
2358 /* Send TBN_INITCUSTOMIZE notification */
2359 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2360 TBNRF_HIDEHELP)
2362 TRACE("TBNRF_HIDEHELP requested\n");
2363 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2366 /* add items to 'toolbar buttons' list and check if removable */
2367 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2369 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2370 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2371 btnInfo->btn.fsStyle = BTNS_SEP;
2372 btnInfo->bVirtual = FALSE;
2373 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2375 /* send TBN_QUERYDELETE notification */
2376 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2378 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2379 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2382 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2384 /* insert separator button into 'available buttons' list */
2385 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2386 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2387 btnInfo->btn.fsStyle = BTNS_SEP;
2388 btnInfo->bVirtual = FALSE;
2389 btnInfo->bRemovable = TRUE;
2390 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2391 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2392 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2394 /* insert all buttons into dsa */
2395 for (i = 0;; i++)
2397 /* send TBN_GETBUTTONINFO notification */
2398 NMTOOLBARW nmtb;
2399 nmtb.iItem = i;
2400 nmtb.pszText = Buffer;
2401 nmtb.cchText = 256;
2403 /* Clear previous button's text */
2404 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2406 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2407 break;
2409 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2410 nmtb.tbButton.fsStyle, i,
2411 nmtb.tbButton.idCommand,
2412 nmtb.tbButton.iString,
2413 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2414 : "");
2416 /* insert button into the apropriate list */
2417 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2418 if (index == -1)
2420 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2421 btnInfo->bVirtual = FALSE;
2422 btnInfo->bRemovable = TRUE;
2424 else
2426 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2427 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2430 btnInfo->btn = nmtb.tbButton;
2431 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2433 if (lstrlenW(nmtb.pszText))
2434 lstrcpyW(btnInfo->text, nmtb.pszText);
2435 else if (nmtb.tbButton.iString >= 0 &&
2436 nmtb.tbButton.iString < infoPtr->nNumStrings)
2438 lstrcpyW(btnInfo->text,
2439 infoPtr->strings[nmtb.tbButton.iString]);
2443 if (index == -1)
2444 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2447 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2449 /* select first item in the 'available' list */
2450 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2452 /* append 'virtual' separator button to the 'toolbar buttons' list */
2453 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2454 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2455 btnInfo->btn.fsStyle = BTNS_SEP;
2456 btnInfo->bVirtual = TRUE;
2457 btnInfo->bRemovable = FALSE;
2458 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2459 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2460 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2462 /* select last item in the 'toolbar' list */
2463 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2464 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2466 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2467 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2469 /* set focus and disable buttons */
2470 PostMessageW (hwnd, WM_USER, 0, 0);
2472 return TRUE;
2474 case WM_USER:
2475 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2476 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2477 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2478 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2479 return TRUE;
2481 case WM_CLOSE:
2482 EndDialog(hwnd, FALSE);
2483 return TRUE;
2485 case WM_COMMAND:
2486 switch (LOWORD(wParam))
2488 case IDC_TOOLBARBTN_LBOX:
2489 if (HIWORD(wParam) == LBN_SELCHANGE)
2491 PCUSTOMBUTTON btnInfo;
2492 NMTOOLBARA nmtb;
2493 int count;
2494 int index;
2496 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2497 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2499 /* send TBN_QUERYINSERT notification */
2500 nmtb.iItem = index;
2501 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2503 /* get list box item */
2504 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2506 if (index == (count - 1))
2508 /* last item (virtual separator) */
2509 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2510 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2512 else if (index == (count - 2))
2514 /* second last item (last non-virtual item) */
2515 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2516 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2518 else if (index == 0)
2520 /* first item */
2521 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2522 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2524 else
2526 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2527 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2530 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2532 break;
2534 case IDC_MOVEUP_BTN:
2536 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2537 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2539 break;
2541 case IDC_MOVEDN_BTN: /* move down */
2543 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2544 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2546 break;
2548 case IDC_REMOVE_BTN: /* remove button */
2550 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2552 if (LB_ERR == index)
2553 break;
2555 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2557 break;
2558 case IDC_HELP_BTN:
2559 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2560 break;
2561 case IDC_RESET_BTN:
2562 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2563 break;
2565 case IDOK: /* Add button */
2567 int index;
2568 int indexto;
2570 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2571 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2573 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2575 break;
2577 case IDCANCEL:
2578 EndDialog(hwnd, FALSE);
2579 break;
2581 return TRUE;
2583 case WM_DESTROY:
2585 int count;
2586 int i;
2588 /* delete items from 'toolbar buttons' listbox*/
2589 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2590 for (i = 0; i < count; i++)
2592 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2593 Free(btnInfo);
2594 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2596 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2599 /* delete items from 'available buttons' listbox*/
2600 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2601 for (i = 0; i < count; i++)
2603 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2604 Free(btnInfo);
2605 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2607 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2609 return TRUE;
2611 case WM_DRAWITEM:
2612 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2614 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2615 RECT rcButton;
2616 RECT rcText;
2617 HPEN hPen, hOldPen;
2618 HBRUSH hOldBrush;
2619 COLORREF oldText = 0;
2620 COLORREF oldBk = 0;
2622 /* get item data */
2623 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2624 if (btnInfo == NULL)
2626 FIXME("btnInfo invalid!\n");
2627 return TRUE;
2630 /* set colors and select objects */
2631 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2632 if (btnInfo->bVirtual)
2633 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2634 else
2635 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2636 hPen = CreatePen( PS_SOLID, 1,
2637 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2638 hOldPen = SelectObject (lpdis->hDC, hPen );
2639 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2641 /* fill background rectangle */
2642 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2643 lpdis->rcItem.right, lpdis->rcItem.bottom);
2645 /* calculate button and text rectangles */
2646 CopyRect (&rcButton, &lpdis->rcItem);
2647 InflateRect (&rcButton, -1, -1);
2648 CopyRect (&rcText, &rcButton);
2649 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2650 rcText.left = rcButton.right + 2;
2652 /* draw focus rectangle */
2653 if (lpdis->itemState & ODS_FOCUS)
2654 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2656 /* draw button */
2657 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2658 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2660 /* draw image and text */
2661 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2662 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2663 btnInfo->btn.iBitmap));
2664 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2665 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2667 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2668 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2670 /* delete objects and reset colors */
2671 SelectObject (lpdis->hDC, hOldBrush);
2672 SelectObject (lpdis->hDC, hOldPen);
2673 SetBkColor (lpdis->hDC, oldBk);
2674 SetTextColor (lpdis->hDC, oldText);
2675 DeleteObject( hPen );
2676 return TRUE;
2678 return FALSE;
2680 case WM_MEASUREITEM:
2681 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2683 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2685 lpmis->itemHeight = 15 + 8; /* default height */
2687 return TRUE;
2689 return FALSE;
2691 default:
2692 if (uDragListMessage && (uMsg == uDragListMessage))
2694 if (wParam == IDC_TOOLBARBTN_LBOX)
2696 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2697 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2698 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2699 return TRUE;
2701 else if (wParam == IDC_AVAILBTN_LBOX)
2703 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2704 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2705 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2706 return TRUE;
2709 return FALSE;
2713 static BOOL
2714 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2716 HBITMAP hbmLoad;
2717 INT nCountBefore = ImageList_GetImageCount(himlDef);
2718 INT nCountAfter;
2719 INT cxIcon, cyIcon;
2720 INT nAdded;
2721 INT nIndex;
2723 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2724 /* Add bitmaps to the default image list */
2725 if (bitmap->hInst == NULL) /* a handle was passed */
2726 hbmLoad = CopyImage(ULongToHandle(bitmap->nID), IMAGE_BITMAP, 0, 0, 0);
2727 else
2728 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2730 /* enlarge the bitmap if needed */
2731 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2732 if (bitmap->hInst != COMCTL32_hModule)
2733 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2735 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2736 DeleteObject(hbmLoad);
2737 if (nIndex == -1)
2738 return FALSE;
2740 nCountAfter = ImageList_GetImageCount(himlDef);
2741 nAdded = nCountAfter - nCountBefore;
2742 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2744 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2745 } else if (nAdded > (INT)bitmap->nButtons) {
2746 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2747 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2750 infoPtr->nNumBitmaps += nAdded;
2751 return TRUE;
2754 static void
2755 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2757 HIMAGELIST himlDef;
2758 HIMAGELIST himlNew;
2759 INT cx, cy;
2760 INT i;
2762 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2763 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2764 return;
2765 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2766 return;
2767 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2768 return;
2770 TRACE("Update icon size: %dx%d -> %dx%d\n",
2771 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2773 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2774 ILC_COLORDDB|ILC_MASK, 8, 2);
2775 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2776 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2777 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2778 infoPtr->himlInt = himlNew;
2780 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2781 ImageList_Destroy(himlDef);
2784 /***********************************************************************
2785 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2788 static LRESULT
2789 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2791 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2792 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2793 TBITMAP_INFO info;
2794 INT iSumButtons, i;
2795 HIMAGELIST himlDef;
2797 TRACE("hwnd=%p wParam=%lx lParam=%lx\n", hwnd, wParam, lParam);
2798 if (!lpAddBmp)
2799 return -1;
2801 if (lpAddBmp->hInst == HINST_COMMCTRL)
2803 info.hInst = COMCTL32_hModule;
2804 switch (lpAddBmp->nID)
2806 case IDB_STD_SMALL_COLOR:
2807 info.nButtons = 15;
2808 info.nID = IDB_STD_SMALL;
2809 break;
2810 case IDB_STD_LARGE_COLOR:
2811 info.nButtons = 15;
2812 info.nID = IDB_STD_LARGE;
2813 break;
2814 case IDB_VIEW_SMALL_COLOR:
2815 info.nButtons = 12;
2816 info.nID = IDB_VIEW_SMALL;
2817 break;
2818 case IDB_VIEW_LARGE_COLOR:
2819 info.nButtons = 12;
2820 info.nID = IDB_VIEW_LARGE;
2821 break;
2822 case IDB_HIST_SMALL_COLOR:
2823 info.nButtons = 5;
2824 info.nID = IDB_HIST_SMALL;
2825 break;
2826 case IDB_HIST_LARGE_COLOR:
2827 info.nButtons = 5;
2828 info.nID = IDB_HIST_LARGE;
2829 break;
2830 default:
2831 return -1;
2834 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2836 /* Windows resize all the buttons to the size of a newly added standard image */
2837 if (lpAddBmp->nID & 1)
2839 /* large icons: 24x24. Will make the button 31x30 */
2840 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
2842 else
2844 /* small icons: 16x16. Will make the buttons 23x22 */
2845 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
2848 TOOLBAR_CalcToolbar (hwnd);
2850 else
2852 info.nButtons = (INT)wParam;
2853 info.hInst = lpAddBmp->hInst;
2854 info.nID = lpAddBmp->nID;
2855 TRACE("adding %d bitmaps!\n", info.nButtons);
2858 /* check if the bitmap is already loaded and compute iSumButtons */
2859 iSumButtons = 0;
2860 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2862 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2863 infoPtr->bitmaps[i].nID == info.nID)
2864 return iSumButtons;
2865 iSumButtons += infoPtr->bitmaps[i].nButtons;
2868 if (!infoPtr->cimlDef) {
2869 /* create new default image list */
2870 TRACE ("creating default image list!\n");
2872 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2873 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2874 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2875 infoPtr->himlInt = himlDef;
2877 else {
2878 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2881 if (!himlDef) {
2882 WARN("No default image list available\n");
2883 return -1;
2886 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2887 return -1;
2889 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2890 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2891 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2892 infoPtr->nNumBitmapInfos++;
2893 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2895 InvalidateRect(hwnd, NULL, TRUE);
2896 return iSumButtons;
2900 static LRESULT
2901 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2903 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2904 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2905 INT nAddButtons = (UINT)wParam;
2907 TRACE("adding %ld buttons (unicode=%d)!\n", wParam, fUnicode);
2909 return TOOLBAR_InternalInsertButtonsT(infoPtr, -1, nAddButtons, lpTbb, fUnicode);
2913 static LRESULT
2914 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2916 #define MAX_RESOURCE_STRING_LENGTH 512
2917 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2918 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2919 INT nIndex = infoPtr->nNumStrings;
2921 if ((wParam) && (HIWORD(lParam) == 0)) {
2922 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2923 WCHAR delimiter;
2924 WCHAR *next_delim;
2925 WCHAR *p;
2926 INT len;
2927 TRACE("adding string from resource!\n");
2929 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2930 szString, MAX_RESOURCE_STRING_LENGTH);
2932 TRACE("len=%d %s\n", len, debugstr_w(szString));
2933 if (len == 0 || len == 1)
2934 return nIndex;
2936 TRACE("Delimiter: 0x%x\n", *szString);
2937 delimiter = *szString;
2938 p = szString + 1;
2940 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2941 *next_delim = 0;
2942 if (next_delim + 1 >= szString + len)
2944 /* this may happen if delimiter == '\0' or if the last char is a
2945 * delimiter (then it is ignored like the native does) */
2946 break;
2949 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2950 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2951 infoPtr->nNumStrings++;
2953 p = next_delim + 1;
2956 else {
2957 LPWSTR p = (LPWSTR)lParam;
2958 INT len;
2960 if (p == NULL)
2961 return -1;
2962 TRACE("adding string(s) from array!\n");
2963 while (*p) {
2964 len = strlenW (p);
2966 TRACE("len=%d %s\n", len, debugstr_w(p));
2967 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2968 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2969 infoPtr->nNumStrings++;
2971 p += (len+1);
2975 if (fFirstString)
2976 TOOLBAR_CalcToolbar(hwnd);
2977 return nIndex;
2981 static LRESULT
2982 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2984 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2985 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2986 LPSTR p;
2987 INT nIndex;
2988 INT len;
2990 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
2991 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
2993 p = (LPSTR)lParam;
2994 if (p == NULL)
2995 return -1;
2997 TRACE("adding string(s) from array!\n");
2998 nIndex = infoPtr->nNumStrings;
2999 while (*p) {
3000 len = strlen (p);
3001 TRACE("len=%d \"%s\"\n", len, p);
3003 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
3004 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
3005 infoPtr->nNumStrings++;
3007 p += (len+1);
3010 if (fFirstString)
3011 TOOLBAR_CalcToolbar(hwnd);
3012 return nIndex;
3016 static LRESULT
3017 TOOLBAR_AutoSize (HWND hwnd)
3019 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3020 RECT parent_rect;
3021 HWND parent;
3022 INT x, y;
3023 INT cx, cy;
3025 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3027 parent = GetParent (hwnd);
3029 if (!parent || !infoPtr->bDoRedraw)
3030 return 0;
3032 GetClientRect(parent, &parent_rect);
3034 x = parent_rect.left;
3035 y = parent_rect.top;
3037 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3039 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3040 cx = parent_rect.right - parent_rect.left;
3042 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3044 TOOLBAR_LayoutToolbar(hwnd);
3045 InvalidateRect( hwnd, NULL, TRUE );
3048 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3050 RECT window_rect;
3051 UINT uPosFlags = SWP_NOZORDER;
3053 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3055 GetWindowRect(hwnd, &window_rect);
3056 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3057 y = window_rect.top;
3059 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3061 GetWindowRect(hwnd, &window_rect);
3062 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3065 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3066 uPosFlags |= SWP_NOMOVE;
3068 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3069 cy += GetSystemMetrics(SM_CYEDGE);
3071 if (infoPtr->dwStyle & WS_BORDER)
3073 x = y = 1; /* FIXME: this looks wrong */
3074 cy += GetSystemMetrics(SM_CYEDGE);
3075 cx += GetSystemMetrics(SM_CXEDGE);
3078 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3081 return 0;
3085 static LRESULT
3086 TOOLBAR_ButtonCount (HWND hwnd)
3088 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3090 return infoPtr->nNumButtons;
3094 static LRESULT
3095 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam)
3097 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3099 infoPtr->dwStructSize = (DWORD)wParam;
3101 return 0;
3105 static LRESULT
3106 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3108 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3109 TBUTTON_INFO *btnPtr;
3110 INT nIndex;
3112 TRACE("button %ld, iBitmap now %d\n", wParam, LOWORD(lParam));
3114 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3115 if (nIndex == -1)
3116 return FALSE;
3118 btnPtr = &infoPtr->buttons[nIndex];
3119 btnPtr->iBitmap = LOWORD(lParam);
3121 /* we HAVE to erase the background, the new bitmap could be */
3122 /* transparent */
3123 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3125 return TRUE;
3129 static LRESULT
3130 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3132 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3133 TBUTTON_INFO *btnPtr;
3134 INT nIndex;
3135 INT nOldIndex = -1;
3136 BOOL bChecked = FALSE;
3138 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3140 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3142 if (nIndex == -1)
3143 return FALSE;
3145 btnPtr = &infoPtr->buttons[nIndex];
3147 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3149 if (LOWORD(lParam) == FALSE)
3150 btnPtr->fsState &= ~TBSTATE_CHECKED;
3151 else {
3152 if (btnPtr->fsStyle & BTNS_GROUP) {
3153 nOldIndex =
3154 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3155 if (nOldIndex == nIndex)
3156 return 0;
3157 if (nOldIndex != -1)
3158 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3160 btnPtr->fsState |= TBSTATE_CHECKED;
3163 if( bChecked != LOWORD(lParam) )
3165 if (nOldIndex != -1)
3166 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3167 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3170 /* FIXME: Send a WM_NOTIFY?? */
3172 return TRUE;
3176 static LRESULT
3177 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam)
3179 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3181 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3185 static LRESULT
3186 TOOLBAR_Customize (HWND hwnd)
3188 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3189 CUSTDLG_INFO custInfo;
3190 LRESULT ret;
3191 LPCVOID template;
3192 HRSRC hRes;
3193 NMHDR nmhdr;
3195 custInfo.tbInfo = infoPtr;
3196 custInfo.tbHwnd = hwnd;
3198 /* send TBN_BEGINADJUST notification */
3199 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3201 if (!(hRes = FindResourceW (COMCTL32_hModule,
3202 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3203 (LPWSTR)RT_DIALOG)))
3204 return FALSE;
3206 if(!(template = LoadResource (COMCTL32_hModule, hRes)))
3207 return FALSE;
3209 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3210 (LPCDLGTEMPLATEW)template,
3211 hwnd,
3212 TOOLBAR_CustomizeDialogProc,
3213 (LPARAM)&custInfo);
3215 /* send TBN_ENDADJUST notification */
3216 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3218 return ret;
3222 static LRESULT
3223 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam)
3225 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3226 INT nIndex = (INT)wParam;
3227 NMTOOLBARW nmtb;
3228 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3230 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3231 return FALSE;
3233 memset(&nmtb, 0, sizeof(nmtb));
3234 nmtb.iItem = btnPtr->idCommand;
3235 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3236 nmtb.tbButton.idCommand = btnPtr->idCommand;
3237 nmtb.tbButton.fsState = btnPtr->fsState;
3238 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3239 nmtb.tbButton.dwData = btnPtr->dwData;
3240 nmtb.tbButton.iString = btnPtr->iString;
3241 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3243 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3245 if (infoPtr->nNumButtons == 1) {
3246 TRACE(" simple delete!\n");
3247 Free (infoPtr->buttons);
3248 infoPtr->buttons = NULL;
3249 infoPtr->nNumButtons = 0;
3251 else {
3252 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3253 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3255 infoPtr->nNumButtons--;
3256 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3257 if (nIndex > 0) {
3258 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3259 nIndex * sizeof(TBUTTON_INFO));
3262 if (nIndex < infoPtr->nNumButtons) {
3263 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3264 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3267 Free (oldButtons);
3270 TOOLBAR_LayoutToolbar(hwnd);
3272 InvalidateRect (hwnd, NULL, TRUE);
3274 return TRUE;
3278 static LRESULT
3279 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3281 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3282 TBUTTON_INFO *btnPtr;
3283 INT nIndex;
3284 DWORD bState;
3286 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3288 TRACE("hwnd=%p, btn index=%ld, lParam=0x%08lx\n", hwnd, wParam, lParam);
3290 if (nIndex == -1)
3291 return FALSE;
3293 btnPtr = &infoPtr->buttons[nIndex];
3295 bState = btnPtr->fsState & TBSTATE_ENABLED;
3297 /* update the toolbar button state */
3298 if(LOWORD(lParam) == FALSE) {
3299 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3300 } else {
3301 btnPtr->fsState |= TBSTATE_ENABLED;
3304 /* redraw the button only if the state of the button changed */
3305 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3306 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3308 return TRUE;
3312 static inline LRESULT
3313 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3315 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3317 return infoPtr->bAnchor;
3321 static LRESULT
3322 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam)
3324 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3325 INT nIndex;
3327 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3328 if (nIndex == -1)
3329 return -1;
3331 return infoPtr->buttons[nIndex].iBitmap;
3335 static inline LRESULT
3336 TOOLBAR_GetBitmapFlags (void)
3338 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3342 static LRESULT
3343 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3345 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3346 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3347 INT nIndex = (INT)wParam;
3348 TBUTTON_INFO *btnPtr;
3350 if (lpTbb == NULL)
3351 return FALSE;
3353 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3354 return FALSE;
3356 btnPtr = &infoPtr->buttons[nIndex];
3357 lpTbb->iBitmap = btnPtr->iBitmap;
3358 lpTbb->idCommand = btnPtr->idCommand;
3359 lpTbb->fsState = btnPtr->fsState;
3360 lpTbb->fsStyle = btnPtr->fsStyle;
3361 lpTbb->bReserved[0] = 0;
3362 lpTbb->bReserved[1] = 0;
3363 lpTbb->dwData = btnPtr->dwData;
3364 lpTbb->iString = btnPtr->iString;
3366 return TRUE;
3370 static LRESULT
3371 TOOLBAR_GetButtonInfoT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL bUnicode)
3373 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3374 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3375 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3376 TBUTTON_INFO *btnPtr;
3377 INT nIndex;
3379 if (lpTbInfo == NULL)
3380 return -1;
3382 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3383 * the headers and tests shows that even with comctl 6 Vista accepts only the
3384 * original TBBUTTONINFO size
3386 if (lpTbInfo->cbSize != sizeof(TBBUTTONINFOW))
3388 WARN("Invalid button size\n");
3389 return -1;
3392 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3393 lpTbInfo->dwMask & 0x80000000);
3394 if (nIndex == -1)
3395 return -1;
3397 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3399 if (lpTbInfo->dwMask & TBIF_COMMAND)
3400 lpTbInfo->idCommand = btnPtr->idCommand;
3401 if (lpTbInfo->dwMask & TBIF_IMAGE)
3402 lpTbInfo->iImage = btnPtr->iBitmap;
3403 if (lpTbInfo->dwMask & TBIF_LPARAM)
3404 lpTbInfo->lParam = btnPtr->dwData;
3405 if (lpTbInfo->dwMask & TBIF_SIZE)
3406 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3407 if (lpTbInfo->dwMask & TBIF_STATE)
3408 lpTbInfo->fsState = btnPtr->fsState;
3409 if (lpTbInfo->dwMask & TBIF_STYLE)
3410 lpTbInfo->fsStyle = btnPtr->fsStyle;
3411 if (lpTbInfo->dwMask & TBIF_TEXT) {
3412 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3413 can't use TOOLBAR_GetText here */
3414 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3415 LPWSTR lpText = (LPWSTR)btnPtr->iString;
3416 if (bUnicode)
3417 Str_GetPtrW(lpText, lpTbInfo->pszText, lpTbInfo->cchText);
3418 else
3419 Str_GetPtrWtoA(lpText, (LPSTR)lpTbInfo->pszText, lpTbInfo->cchText);
3420 } else
3421 lpTbInfo->pszText[0] = '\0';
3423 return nIndex;
3427 static LRESULT
3428 TOOLBAR_GetButtonSize (HWND hwnd)
3430 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3432 return MAKELONG((WORD)infoPtr->nButtonWidth,
3433 (WORD)infoPtr->nButtonHeight);
3437 static LRESULT
3438 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3440 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3441 INT nIndex;
3442 LPWSTR lpText;
3444 if (lParam == 0)
3445 return -1;
3447 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3448 if (nIndex == -1)
3449 return -1;
3451 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3453 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3454 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3458 static LRESULT
3459 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3461 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3462 INT nIndex;
3463 LPWSTR lpText;
3464 LRESULT ret = 0;
3466 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3467 if (nIndex == -1)
3468 return -1;
3470 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3472 if (lpText)
3474 ret = strlenW (lpText);
3476 if (lParam)
3477 strcpyW ((LPWSTR)lParam, lpText);
3480 return ret;
3484 static LRESULT
3485 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3487 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3488 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3489 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3493 static inline LRESULT
3494 TOOLBAR_GetExtendedStyle (HWND hwnd)
3496 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3498 TRACE("\n");
3500 return infoPtr->dwExStyle;
3504 static LRESULT
3505 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3507 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3508 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3509 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3513 static LRESULT
3514 TOOLBAR_GetHotItem (HWND hwnd)
3516 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3518 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3519 return -1;
3521 if (infoPtr->nHotItem < 0)
3522 return -1;
3524 return (LRESULT)infoPtr->nHotItem;
3528 static LRESULT
3529 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3531 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3532 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3533 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3537 static LRESULT
3538 TOOLBAR_GetInsertMark (HWND hwnd, LPARAM lParam)
3540 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3541 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3543 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3545 *lptbim = infoPtr->tbim;
3547 return 0;
3551 static LRESULT
3552 TOOLBAR_GetInsertMarkColor (HWND hwnd)
3554 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3556 TRACE("hwnd = %p\n", hwnd);
3558 return (LRESULT)infoPtr->clrInsertMark;
3562 static LRESULT
3563 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3565 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3566 TBUTTON_INFO *btnPtr;
3567 LPRECT lpRect;
3568 INT nIndex;
3570 nIndex = (INT)wParam;
3571 btnPtr = &infoPtr->buttons[nIndex];
3572 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3573 return FALSE;
3574 lpRect = (LPRECT)lParam;
3575 if (lpRect == NULL)
3576 return FALSE;
3577 if (btnPtr->fsState & TBSTATE_HIDDEN)
3578 return FALSE;
3580 lpRect->left = btnPtr->rect.left;
3581 lpRect->right = btnPtr->rect.right;
3582 lpRect->bottom = btnPtr->rect.bottom;
3583 lpRect->top = btnPtr->rect.top;
3585 return TRUE;
3589 static LRESULT
3590 TOOLBAR_GetMaxSize (HWND hwnd, LPARAM lParam)
3592 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3593 LPSIZE lpSize = (LPSIZE)lParam;
3595 if (lpSize == NULL)
3596 return FALSE;
3598 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3599 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3601 TRACE("maximum size %d x %d\n",
3602 infoPtr->rcBound.right - infoPtr->rcBound.left,
3603 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3605 return TRUE;
3609 /* << TOOLBAR_GetObject >> */
3612 static LRESULT
3613 TOOLBAR_GetPadding (HWND hwnd)
3615 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3616 DWORD oldPad;
3618 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3619 return (LRESULT) oldPad;
3623 static LRESULT
3624 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3626 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3627 TBUTTON_INFO *btnPtr;
3628 LPRECT lpRect;
3629 INT nIndex;
3631 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3632 btnPtr = &infoPtr->buttons[nIndex];
3633 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3634 return FALSE;
3635 lpRect = (LPRECT)lParam;
3636 if (lpRect == NULL)
3637 return FALSE;
3639 lpRect->left = btnPtr->rect.left;
3640 lpRect->right = btnPtr->rect.right;
3641 lpRect->bottom = btnPtr->rect.bottom;
3642 lpRect->top = btnPtr->rect.top;
3644 return TRUE;
3648 static LRESULT
3649 TOOLBAR_GetRows (HWND hwnd)
3651 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3653 return infoPtr->nRows;
3657 static LRESULT
3658 TOOLBAR_GetState (HWND hwnd, WPARAM wParam)
3660 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3661 INT nIndex;
3663 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3664 if (nIndex == -1)
3665 return -1;
3667 return infoPtr->buttons[nIndex].fsState;
3671 static LRESULT
3672 TOOLBAR_GetStyle (HWND hwnd)
3674 return GetWindowLongW(hwnd, GWL_STYLE);
3678 static LRESULT
3679 TOOLBAR_GetTextRows (HWND hwnd)
3681 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3683 return infoPtr->nMaxTextRows;
3687 static LRESULT
3688 TOOLBAR_GetToolTips (HWND hwnd)
3690 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3692 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3693 TOOLBAR_TooltipCreateControl(infoPtr);
3694 return (LRESULT)infoPtr->hwndToolTip;
3698 static LRESULT
3699 TOOLBAR_GetUnicodeFormat (HWND hwnd)
3701 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3703 TRACE("%s hwnd=%p\n",
3704 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3706 return infoPtr->bUnicode;
3710 static inline LRESULT
3711 TOOLBAR_GetVersion (HWND hwnd)
3713 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3714 return infoPtr->iVersion;
3718 static LRESULT
3719 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3721 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3722 TBUTTON_INFO *btnPtr;
3723 INT nIndex;
3725 TRACE("\n");
3727 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3728 if (nIndex == -1)
3729 return FALSE;
3731 btnPtr = &infoPtr->buttons[nIndex];
3732 if (LOWORD(lParam) == FALSE)
3733 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3734 else
3735 btnPtr->fsState |= TBSTATE_HIDDEN;
3737 TOOLBAR_LayoutToolbar (hwnd);
3739 InvalidateRect (hwnd, NULL, TRUE);
3741 return TRUE;
3745 static inline LRESULT
3746 TOOLBAR_HitTest (HWND hwnd, LPARAM lParam)
3748 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3752 static LRESULT
3753 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3755 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3756 TBUTTON_INFO *btnPtr;
3757 INT nIndex;
3758 DWORD oldState;
3760 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3761 if (nIndex == -1)
3762 return FALSE;
3764 btnPtr = &infoPtr->buttons[nIndex];
3765 oldState = btnPtr->fsState;
3766 if (LOWORD(lParam) == FALSE)
3767 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3768 else
3769 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3771 if(oldState != btnPtr->fsState)
3772 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3774 return TRUE;
3778 static LRESULT
3779 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3781 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3782 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3783 INT nIndex = (INT)wParam;
3785 if (lpTbb == NULL)
3786 return FALSE;
3788 if (nIndex == -1) {
3789 /* EPP: this seems to be an undocumented call (from my IE4)
3790 * I assume in that case that:
3791 * - index of insertion is at the end of existing buttons
3792 * I only see this happen with nIndex == -1, but it could have a special
3793 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3795 nIndex = infoPtr->nNumButtons;
3797 } else if (nIndex < 0)
3798 return FALSE;
3800 TRACE("inserting button index=%d\n", nIndex);
3801 if (nIndex > infoPtr->nNumButtons) {
3802 nIndex = infoPtr->nNumButtons;
3803 TRACE("adjust index=%d\n", nIndex);
3806 return TOOLBAR_InternalInsertButtonsT(infoPtr, nIndex, 1, lpTbb, fUnicode);
3809 /* << TOOLBAR_InsertMarkHitTest >> */
3812 static LRESULT
3813 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam)
3815 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3816 INT nIndex;
3818 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3819 if (nIndex == -1)
3820 return -1;
3822 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3826 static LRESULT
3827 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam)
3829 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3830 INT nIndex;
3832 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3833 if (nIndex == -1)
3834 return -1;
3836 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3840 static LRESULT
3841 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam)
3843 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3844 INT nIndex;
3846 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3847 if (nIndex == -1)
3848 return -1;
3850 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3854 static LRESULT
3855 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam)
3857 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3858 INT nIndex;
3860 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3861 if (nIndex == -1)
3862 return -1;
3864 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3868 static LRESULT
3869 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam)
3871 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3872 INT nIndex;
3874 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3875 if (nIndex == -1)
3876 return -1;
3878 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3882 static LRESULT
3883 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam)
3885 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3886 INT nIndex;
3888 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3889 if (nIndex == -1)
3890 return -1;
3892 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3896 static LRESULT
3897 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3899 TBADDBITMAP tbab;
3900 tbab.hInst = (HINSTANCE)lParam;
3901 tbab.nID = wParam;
3903 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", hwnd, tbab.hInst, tbab.nID);
3905 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3909 static LRESULT
3910 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3912 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3913 WCHAR wAccel = (WCHAR)wParam;
3914 UINT* pIDButton = (UINT*)lParam;
3915 WCHAR wszAccel[] = {'&',wAccel,0};
3916 int i;
3918 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3919 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3921 for (i = 0; i < infoPtr->nNumButtons; i++)
3923 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3924 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3925 !(btnPtr->fsState & TBSTATE_HIDDEN))
3927 int iLen = strlenW(wszAccel);
3928 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3930 if (!lpszStr)
3931 continue;
3933 while (*lpszStr)
3935 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3937 lpszStr += 2;
3938 continue;
3940 if (!strncmpiW(lpszStr, wszAccel, iLen))
3942 *pIDButton = btnPtr->idCommand;
3943 return TRUE;
3945 lpszStr++;
3949 return FALSE;
3953 static LRESULT
3954 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3956 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3957 INT nIndex;
3958 DWORD oldState;
3959 TBUTTON_INFO *btnPtr;
3961 TRACE("hwnd = %p, wParam = %ld, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3963 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3964 if (nIndex == -1)
3965 return FALSE;
3967 btnPtr = &infoPtr->buttons[nIndex];
3968 oldState = btnPtr->fsState;
3970 if (LOWORD(lParam))
3971 btnPtr->fsState |= TBSTATE_MARKED;
3972 else
3973 btnPtr->fsState &= ~TBSTATE_MARKED;
3975 if(oldState != btnPtr->fsState)
3976 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3978 return TRUE;
3982 /* fixes up an index of a button affected by a move */
3983 static inline void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
3985 if (bMoveUp)
3987 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
3988 (*pIndex)--;
3989 else if (*pIndex == nIndex)
3990 *pIndex = nMoveIndex;
3992 else
3994 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
3995 (*pIndex)++;
3996 else if (*pIndex == nIndex)
3997 *pIndex = nMoveIndex;
4002 static LRESULT
4003 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4005 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4006 INT nIndex;
4007 INT nCount;
4008 INT nMoveIndex = (INT)lParam;
4009 TBUTTON_INFO button;
4011 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
4013 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4014 if ((nIndex == -1) || (nMoveIndex < 0))
4015 return FALSE;
4017 if (nMoveIndex > infoPtr->nNumButtons - 1)
4018 nMoveIndex = infoPtr->nNumButtons - 1;
4020 button = infoPtr->buttons[nIndex];
4022 /* move button right */
4023 if (nIndex < nMoveIndex)
4025 nCount = nMoveIndex - nIndex;
4026 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4027 infoPtr->buttons[nMoveIndex] = button;
4029 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4030 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4031 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4032 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4034 else if (nIndex > nMoveIndex) /* move button left */
4036 nCount = nIndex - nMoveIndex;
4037 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4038 infoPtr->buttons[nMoveIndex] = button;
4040 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4041 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4042 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4043 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4046 TOOLBAR_LayoutToolbar(hwnd);
4047 TOOLBAR_AutoSize(hwnd);
4048 InvalidateRect(hwnd, NULL, TRUE);
4050 return TRUE;
4054 static LRESULT
4055 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4057 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4058 TBUTTON_INFO *btnPtr;
4059 INT nIndex;
4060 DWORD oldState;
4062 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4063 if (nIndex == -1)
4064 return FALSE;
4066 btnPtr = &infoPtr->buttons[nIndex];
4067 oldState = btnPtr->fsState;
4068 if (LOWORD(lParam) == FALSE)
4069 btnPtr->fsState &= ~TBSTATE_PRESSED;
4070 else
4071 btnPtr->fsState |= TBSTATE_PRESSED;
4073 if(oldState != btnPtr->fsState)
4074 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4076 return TRUE;
4079 /* FIXME: there might still be some confusion her between number of buttons
4080 * and number of bitmaps */
4081 static LRESULT
4082 TOOLBAR_ReplaceBitmap (HWND hwnd, LPARAM lParam)
4084 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4085 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4086 HBITMAP hBitmap;
4087 int i = 0, nOldButtons = 0, pos = 0;
4088 int nOldBitmaps, nNewBitmaps = 0;
4089 HIMAGELIST himlDef = 0;
4091 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4092 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4093 lpReplace->nButtons);
4095 if (lpReplace->hInstOld == HINST_COMMCTRL)
4097 FIXME("changing standard bitmaps not implemented\n");
4098 return FALSE;
4100 else if (lpReplace->hInstOld != 0)
4101 FIXME("resources not in the current module not implemented\n");
4103 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4104 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4105 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4106 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4107 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4109 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4110 nOldButtons = tbi->nButtons;
4111 tbi->nButtons = lpReplace->nButtons;
4112 tbi->hInst = lpReplace->hInstNew;
4113 tbi->nID = lpReplace->nIDNew;
4114 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4115 break;
4117 pos += tbi->nButtons;
4120 if (nOldButtons == 0)
4122 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4123 return FALSE;
4126 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4127 * bitmap
4129 if (lpReplace->hInstNew)
4130 hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4131 else
4132 hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
4134 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4135 nOldBitmaps = ImageList_GetImageCount(himlDef);
4137 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4139 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4140 ImageList_Remove(himlDef, i);
4142 if (hBitmap)
4144 ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
4145 nNewBitmaps = ImageList_GetImageCount(himlDef);
4146 DeleteObject(hBitmap);
4149 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4151 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4152 pos, nOldBitmaps, nNewBitmaps);
4154 InvalidateRect(hwnd, NULL, TRUE);
4155 return TRUE;
4159 /* helper for TOOLBAR_SaveRestoreW */
4160 static BOOL
4161 TOOLBAR_Save(const TBSAVEPARAMSW *lpSave)
4163 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4164 debugstr_w(lpSave->pszValueName));
4166 return FALSE;
4170 /* helper for TOOLBAR_Restore */
4171 static void
4172 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4174 INT i;
4176 for (i = 0; i < infoPtr->nNumButtons; i++)
4178 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4181 Free(infoPtr->buttons);
4182 infoPtr->buttons = NULL;
4183 infoPtr->nNumButtons = 0;
4187 /* helper for TOOLBAR_SaveRestoreW */
4188 static BOOL
4189 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
4191 LONG res;
4192 HKEY hkey = NULL;
4193 BOOL ret = FALSE;
4194 DWORD dwType;
4195 DWORD dwSize = 0;
4196 NMTBRESTORE nmtbr;
4198 /* restore toolbar information */
4199 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4200 debugstr_w(lpSave->pszValueName));
4202 memset(&nmtbr, 0, sizeof(nmtbr));
4204 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4205 KEY_QUERY_VALUE, &hkey);
4206 if (!res)
4207 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4208 NULL, &dwSize);
4209 if (!res && dwType != REG_BINARY)
4210 res = ERROR_FILE_NOT_FOUND;
4211 if (!res)
4213 nmtbr.pData = Alloc(dwSize);
4214 nmtbr.cbData = dwSize;
4215 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4217 if (!res)
4218 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4219 (LPBYTE)nmtbr.pData, &dwSize);
4220 if (!res)
4222 nmtbr.pCurrent = nmtbr.pData;
4223 nmtbr.iItem = -1;
4224 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4225 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4227 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4229 INT i;
4231 /* remove all existing buttons as this function is designed to
4232 * restore the toolbar to a previously saved state */
4233 TOOLBAR_DeleteAllButtons(infoPtr);
4235 for (i = 0; i < nmtbr.cButtons; i++)
4237 nmtbr.iItem = i;
4238 nmtbr.tbButton.iBitmap = -1;
4239 nmtbr.tbButton.fsState = 0;
4240 nmtbr.tbButton.fsStyle = 0;
4241 nmtbr.tbButton.idCommand = 0;
4242 if (*nmtbr.pCurrent == (DWORD)-1)
4244 /* separator */
4245 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4246 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4248 else if (*nmtbr.pCurrent == (DWORD)-2)
4249 /* hidden button */
4250 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4251 else
4252 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4254 nmtbr.pCurrent++;
4256 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4258 /* can't contain real string as we don't know whether
4259 * the client put an ANSI or Unicode string in there */
4260 if (HIWORD(nmtbr.tbButton.iString))
4261 nmtbr.tbButton.iString = 0;
4263 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4264 (LPARAM)&nmtbr.tbButton, TRUE);
4267 /* do legacy notifications */
4268 if (infoPtr->iVersion < 5)
4270 /* FIXME: send TBN_BEGINADJUST */
4271 FIXME("send TBN_GETBUTTONINFO for each button\n");
4272 /* FIXME: send TBN_ENDADJUST */
4275 /* remove all uninitialised buttons
4276 * note: loop backwards to avoid having to fixup i on a
4277 * delete */
4278 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4279 if (infoPtr->buttons[i].iBitmap == -1)
4280 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i);
4282 /* only indicate success if at least one button survived */
4283 if (infoPtr->nNumButtons > 0) ret = TRUE;
4286 Free (nmtbr.pData);
4287 RegCloseKey(hkey);
4289 return ret;
4293 static LRESULT
4294 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, const TBSAVEPARAMSW *lpSave)
4296 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4298 if (lpSave == NULL) return 0;
4300 if (wParam)
4301 return TOOLBAR_Save(lpSave);
4302 else
4303 return TOOLBAR_Restore(infoPtr, lpSave);
4307 static LRESULT
4308 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, const TBSAVEPARAMSA *lpSave)
4310 LPWSTR pszValueName = 0, pszSubKey = 0;
4311 TBSAVEPARAMSW SaveW;
4312 LRESULT result = 0;
4313 int len;
4315 if (lpSave == NULL) return 0;
4317 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4318 pszSubKey = Alloc(len * sizeof(WCHAR));
4319 if (pszSubKey) goto exit;
4320 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4322 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4323 pszValueName = Alloc(len * sizeof(WCHAR));
4324 if (!pszValueName) goto exit;
4325 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4327 SaveW.pszValueName = pszValueName;
4328 SaveW.pszSubKey = pszSubKey;
4329 SaveW.hkr = lpSave->hkr;
4330 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4332 exit:
4333 Free (pszValueName);
4334 Free (pszSubKey);
4336 return result;
4340 static LRESULT
4341 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4343 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4344 BOOL bOldAnchor = infoPtr->bAnchor;
4346 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4348 infoPtr->bAnchor = (BOOL)wParam;
4350 /* Native does not remove the hot effect from an already hot button */
4352 return (LRESULT)bOldAnchor;
4356 static LRESULT
4357 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4359 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4360 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4361 short width = (short)LOWORD(lParam);
4362 short height = (short)HIWORD(lParam);
4364 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
4366 if (wParam != 0)
4367 FIXME("wParam is %ld. Perhaps image list index?\n", wParam);
4369 /* 0 width or height is changed to 1 */
4370 if (width == 0)
4371 width = 1;
4372 if (height == 0)
4373 height = 1;
4375 if (infoPtr->nNumButtons > 0)
4376 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4377 infoPtr->nNumButtons,
4378 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight, width, height);
4380 if (width < -1 || height < -1)
4382 /* Windows destroys the imagelist and seems to actually use negative
4383 * values to compute button sizes */
4384 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width, height);
4385 return FALSE;
4388 /* width or height of -1 means no change */
4389 if (width != -1)
4390 infoPtr->nBitmapWidth = width;
4391 if (height != -1)
4392 infoPtr->nBitmapHeight = height;
4394 if ((himlDef == infoPtr->himlInt) &&
4395 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4397 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4398 infoPtr->nBitmapHeight);
4401 TOOLBAR_CalcToolbar(hwnd);
4402 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4403 return TRUE;
4407 static LRESULT
4408 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4410 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4411 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4412 TBUTTON_INFO *btnPtr;
4413 INT nIndex;
4414 RECT oldBtnRect;
4416 if (lptbbi == NULL)
4417 return FALSE;
4418 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4419 return FALSE;
4421 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4422 lptbbi->dwMask & 0x80000000);
4423 if (nIndex == -1)
4424 return FALSE;
4426 btnPtr = &infoPtr->buttons[nIndex];
4427 if (lptbbi->dwMask & TBIF_COMMAND)
4428 btnPtr->idCommand = lptbbi->idCommand;
4429 if (lptbbi->dwMask & TBIF_IMAGE)
4430 btnPtr->iBitmap = lptbbi->iImage;
4431 if (lptbbi->dwMask & TBIF_LPARAM)
4432 btnPtr->dwData = lptbbi->lParam;
4433 if (lptbbi->dwMask & TBIF_SIZE)
4434 btnPtr->cx = lptbbi->cx;
4435 if (lptbbi->dwMask & TBIF_STATE)
4436 btnPtr->fsState = lptbbi->fsState;
4437 if (lptbbi->dwMask & TBIF_STYLE)
4438 btnPtr->fsStyle = lptbbi->fsStyle;
4440 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4441 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4442 /* iString is index, zero it to make Str_SetPtr succeed */
4443 btnPtr->iString=0;
4445 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4448 /* save the button rect to see if we need to redraw the whole toolbar */
4449 oldBtnRect = btnPtr->rect;
4450 TOOLBAR_LayoutToolbar(hwnd);
4452 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4453 InvalidateRect(hwnd, NULL, TRUE);
4454 else
4455 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4457 return TRUE;
4461 static LRESULT
4462 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4464 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4465 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4466 TBUTTON_INFO *btnPtr;
4467 INT nIndex;
4468 RECT oldBtnRect;
4470 if (lptbbi == NULL)
4471 return FALSE;
4472 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4473 return FALSE;
4475 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4476 lptbbi->dwMask & 0x80000000);
4477 if (nIndex == -1)
4478 return FALSE;
4480 btnPtr = &infoPtr->buttons[nIndex];
4481 if (lptbbi->dwMask & TBIF_COMMAND)
4482 btnPtr->idCommand = lptbbi->idCommand;
4483 if (lptbbi->dwMask & TBIF_IMAGE)
4484 btnPtr->iBitmap = lptbbi->iImage;
4485 if (lptbbi->dwMask & TBIF_LPARAM)
4486 btnPtr->dwData = lptbbi->lParam;
4487 if (lptbbi->dwMask & TBIF_SIZE)
4488 btnPtr->cx = lptbbi->cx;
4489 if (lptbbi->dwMask & TBIF_STATE)
4490 btnPtr->fsState = lptbbi->fsState;
4491 if (lptbbi->dwMask & TBIF_STYLE)
4492 btnPtr->fsStyle = lptbbi->fsStyle;
4494 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4495 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4496 /* iString is index, zero it to make Str_SetPtr succeed */
4497 btnPtr->iString=0;
4498 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4501 /* save the button rect to see if we need to redraw the whole toolbar */
4502 oldBtnRect = btnPtr->rect;
4503 TOOLBAR_LayoutToolbar(hwnd);
4505 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4506 InvalidateRect(hwnd, NULL, TRUE);
4507 else
4508 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4510 return TRUE;
4514 static LRESULT
4515 TOOLBAR_SetButtonSize (HWND hwnd, LPARAM lParam)
4517 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4518 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4520 if ((cx < 0) || (cy < 0))
4522 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4523 return FALSE;
4526 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4528 /* The documentation claims you can only change the button size before
4529 * any button has been added. But this is wrong.
4530 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4531 * it to the toolbar, and it checks that the return value is nonzero - mjm
4532 * Further testing shows that we must actually perform the change too.
4535 * The documentation also does not mention that if 0 is supplied for
4536 * either size, the system changes it to the default of 24 wide and
4537 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4539 if (cx == 0) cx = 24;
4540 if (cy == 0) cx = 22;
4542 cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
4543 cy = max(cy, infoPtr->szPadding.cy + infoPtr->nBitmapHeight);
4545 infoPtr->nButtonWidth = cx;
4546 infoPtr->nButtonHeight = cy;
4548 infoPtr->iTopMargin = default_top_margin(infoPtr);
4549 TOOLBAR_LayoutToolbar(hwnd);
4550 return TRUE;
4554 static LRESULT
4555 TOOLBAR_SetButtonWidth (HWND hwnd, LPARAM lParam)
4557 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4559 /* if setting to current values, ignore */
4560 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4561 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4562 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4563 infoPtr->cxMin, infoPtr->cxMax);
4564 return TRUE;
4567 /* save new values */
4568 infoPtr->cxMin = (short)LOWORD(lParam);
4569 infoPtr->cxMax = (short)HIWORD(lParam);
4571 /* otherwise we need to recalc the toolbar and in some cases
4572 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4573 which doesn't actually draw - GA). */
4574 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4575 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4577 TOOLBAR_CalcToolbar (hwnd);
4579 InvalidateRect (hwnd, NULL, TRUE);
4581 return TRUE;
4585 static LRESULT
4586 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4588 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4589 INT nIndex = (INT)wParam;
4591 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4592 return FALSE;
4594 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4596 if (infoPtr->hwndToolTip) {
4598 FIXME("change tool tip!\n");
4602 return TRUE;
4606 static LRESULT
4607 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4609 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4610 HIMAGELIST himl = (HIMAGELIST)lParam;
4611 HIMAGELIST himlTemp;
4612 INT id = 0;
4614 if (infoPtr->iVersion >= 5)
4615 id = wParam;
4617 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4618 &infoPtr->cimlDis, himl, id);
4620 /* FIXME: redraw ? */
4622 return (LRESULT)himlTemp;
4626 static LRESULT
4627 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4629 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4630 DWORD dwTemp;
4632 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4634 dwTemp = infoPtr->dwDTFlags;
4635 infoPtr->dwDTFlags =
4636 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4638 return (LRESULT)dwTemp;
4641 /* This function differs a bit from what MSDN says it does:
4642 * 1. lParam contains extended style flags to OR with current style
4643 * (MSDN isn't clear on the OR bit)
4644 * 2. wParam appears to contain extended style flags to be reset
4645 * (MSDN says that this parameter is reserved)
4647 static LRESULT
4648 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4650 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4651 DWORD dwOldStyle;
4653 dwOldStyle = infoPtr->dwExStyle;
4654 infoPtr->dwExStyle = (DWORD)lParam;
4656 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4658 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4659 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4660 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4662 if ((dwOldStyle ^ infoPtr->dwExStyle) & TBSTYLE_EX_MIXEDBUTTONS)
4663 TOOLBAR_CalcToolbar(hwnd);
4664 else
4665 TOOLBAR_LayoutToolbar(hwnd);
4667 TOOLBAR_AutoSize(hwnd);
4668 InvalidateRect(hwnd, NULL, TRUE);
4670 return (LRESULT)dwOldStyle;
4674 static LRESULT
4675 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4677 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4678 HIMAGELIST himlTemp;
4679 HIMAGELIST himl = (HIMAGELIST)lParam;
4680 INT id = 0;
4682 if (infoPtr->iVersion >= 5)
4683 id = wParam;
4685 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4687 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4688 &infoPtr->cimlHot, himl, id);
4690 /* FIXME: redraw ? */
4692 return (LRESULT)himlTemp;
4696 /* Makes previous hot button no longer hot, makes the specified
4697 * button hot and sends appropriate notifications. dwReason is one or
4698 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4699 * NOTE 1: this function does not validate nHit
4700 * NOTE 2: the name of this function is completely made up and
4701 * not based on any documentation from Microsoft. */
4702 static void
4703 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4705 if (infoPtr->nHotItem != nHit)
4707 NMTBHOTITEM nmhotitem;
4708 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4710 nmhotitem.dwFlags = dwReason;
4711 if(infoPtr->nHotItem >= 0)
4713 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4714 nmhotitem.idOld = oldBtnPtr->idCommand;
4716 else
4718 nmhotitem.dwFlags |= HICF_ENTERING;
4719 nmhotitem.idOld = 0;
4722 if (nHit >= 0)
4724 btnPtr = &infoPtr->buttons[nHit];
4725 nmhotitem.idNew = btnPtr->idCommand;
4727 else
4729 nmhotitem.dwFlags |= HICF_LEAVING;
4730 nmhotitem.idNew = 0;
4733 /* now change the hot and invalidate the old and new buttons - if the
4734 * parent agrees */
4735 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4737 if (oldBtnPtr) {
4738 oldBtnPtr->bHot = FALSE;
4739 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4741 /* setting disabled buttons as hot fails even if the notify contains the button id */
4742 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4743 btnPtr->bHot = TRUE;
4744 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4745 infoPtr->nHotItem = nHit;
4747 else
4748 infoPtr->nHotItem = -1;
4753 static LRESULT
4754 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4756 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4757 INT nOldHotItem = infoPtr->nHotItem;
4759 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4761 if ((INT)wParam >= infoPtr->nNumButtons)
4762 return infoPtr->nHotItem;
4764 if ((INT)wParam < 0)
4765 wParam = -1;
4767 /* NOTE: an application can still remove the hot item even if anchor
4768 * highlighting is enabled */
4770 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4772 if (nOldHotItem < 0)
4773 return -1;
4775 return (LRESULT)nOldHotItem;
4779 static LRESULT
4780 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4782 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4783 HIMAGELIST himlTemp;
4784 HIMAGELIST himl = (HIMAGELIST)lParam;
4785 INT oldButtonWidth = infoPtr->nButtonWidth;
4786 INT i, id = 0;
4788 if (infoPtr->iVersion >= 5)
4789 id = wParam;
4791 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4792 &infoPtr->cimlDef, himl, id);
4794 infoPtr->nNumBitmaps = 0;
4795 for (i = 0; i < infoPtr->cimlDef; i++)
4796 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4798 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4799 &infoPtr->nBitmapHeight))
4801 infoPtr->nBitmapWidth = 1;
4802 infoPtr->nBitmapHeight = 1;
4804 TOOLBAR_CalcToolbar(hwnd);
4805 if (infoPtr->nButtonWidth < oldButtonWidth)
4806 TOOLBAR_SetButtonSize(hwnd, MAKELONG(oldButtonWidth, infoPtr->nButtonHeight));
4808 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4809 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4810 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4812 InvalidateRect(hwnd, NULL, TRUE);
4814 return (LRESULT)himlTemp;
4818 static LRESULT
4819 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam)
4821 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4823 infoPtr->nIndent = (INT)wParam;
4825 TRACE("\n");
4827 /* process only on indent changing */
4828 if(infoPtr->nIndent != (INT)wParam)
4830 infoPtr->nIndent = (INT)wParam;
4831 TOOLBAR_CalcToolbar (hwnd);
4832 InvalidateRect(hwnd, NULL, FALSE);
4835 return TRUE;
4839 static LRESULT
4840 TOOLBAR_SetInsertMark (HWND hwnd, LPARAM lParam)
4842 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4843 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4845 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4847 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4849 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4850 return 0;
4853 if ((lptbim->iButton == -1) ||
4854 ((lptbim->iButton < infoPtr->nNumButtons) &&
4855 (lptbim->iButton >= 0)))
4857 infoPtr->tbim = *lptbim;
4858 /* FIXME: don't need to update entire toolbar */
4859 InvalidateRect(hwnd, NULL, TRUE);
4861 else
4862 ERR("Invalid button index %d\n", lptbim->iButton);
4864 return 0;
4868 static LRESULT
4869 TOOLBAR_SetInsertMarkColor (HWND hwnd, LPARAM lParam)
4871 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4873 infoPtr->clrInsertMark = (COLORREF)lParam;
4875 /* FIXME: don't need to update entire toolbar */
4876 InvalidateRect(hwnd, NULL, TRUE);
4878 return 0;
4882 static LRESULT
4883 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam)
4885 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4887 infoPtr->nMaxTextRows = (INT)wParam;
4889 TOOLBAR_CalcToolbar(hwnd);
4890 return TRUE;
4894 /* MSDN gives slightly wrong info on padding.
4895 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4896 * 2. It is not used to create a blank area between the edge of the button
4897 * and the text or image if TBSTYLE_LIST is set. It is used to control
4898 * the gap between the image and text.
4899 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4900 * to control the bottom and right borders [with the border being
4901 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4902 * is shared evenly on both sides of the button.
4903 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4905 static LRESULT
4906 TOOLBAR_SetPadding (HWND hwnd, LPARAM lParam)
4908 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4909 DWORD oldPad;
4911 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4912 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4913 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4914 TRACE("cx=%d, cy=%d\n",
4915 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4916 return (LRESULT) oldPad;
4920 static LRESULT
4921 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam)
4923 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4924 HWND hwndOldNotify;
4926 TRACE("\n");
4928 hwndOldNotify = infoPtr->hwndNotify;
4929 infoPtr->hwndNotify = (HWND)wParam;
4931 return (LRESULT)hwndOldNotify;
4935 static LRESULT
4936 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4938 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4939 LPRECT lprc = (LPRECT)lParam;
4940 int rows = LOWORD(wParam);
4941 BOOL bLarger = HIWORD(wParam);
4943 TRACE("\n");
4945 TRACE("Setting rows to %d (%d)\n", rows, bLarger);
4947 if(infoPtr->nRows != rows)
4949 TBUTTON_INFO *btnPtr = infoPtr->buttons;
4950 int curColumn = 0; /* Current column */
4951 int curRow = 0; /* Current row */
4952 int hidden = 0; /* Number of hidden buttons */
4953 int seps = 0; /* Number of separators */
4954 int idealWrap = 0; /* Ideal wrap point */
4955 int i;
4956 BOOL wrap;
4959 Calculate new size and wrap points - Under windows, setrows will
4960 change the dimensions if needed to show the number of requested
4961 rows (if CCS_NORESIZE is set), or will take up the whole window
4962 (if no CCS_NORESIZE).
4964 Basic algorithm - If N buttons, and y rows requested, each row
4965 contains N/y buttons.
4967 FIXME: Handling of separators not obvious from testing results
4968 FIXME: Take width of window into account?
4971 /* Loop through the buttons one by one counting key items */
4972 for (i = 0; i < infoPtr->nNumButtons; i++ )
4974 btnPtr[i].fsState &= ~TBSTATE_WRAP;
4975 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
4976 hidden++;
4977 else if (btnPtr[i].fsStyle & BTNS_SEP)
4978 seps++;
4981 /* FIXME: Separators make this quite complex */
4982 if (seps) FIXME("Separators unhandled\n");
4984 /* Round up so more per line, i.e., less rows */
4985 idealWrap = (infoPtr->nNumButtons - hidden + (rows-1)) / rows;
4987 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4988 achieve the requested number of rows. */
4989 if (bLarger && idealWrap > 1)
4991 int resRows = (infoPtr->nNumButtons + (idealWrap-1)) / idealWrap;
4992 int moreRows = (infoPtr->nNumButtons + (idealWrap-2)) / (idealWrap-1);
4994 if (resRows < rows && moreRows > rows)
4996 idealWrap--;
4997 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap);
5001 curColumn = curRow = 0;
5002 wrap = FALSE;
5003 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap,
5004 infoPtr->nNumButtons, hidden, rows);
5006 for (i = 0; i < infoPtr->nNumButtons; i++ )
5008 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
5009 continue;
5011 /* Step on, wrap if necessary or flag next to wrap */
5012 if (!wrap) {
5013 curColumn++;
5014 } else {
5015 wrap = FALSE;
5016 curColumn = 1;
5017 curRow++;
5020 if (curColumn > (idealWrap-1)) {
5021 wrap = TRUE;
5022 btnPtr[i].fsState |= TBSTATE_WRAP;
5026 TRACE("Result - %d rows\n", curRow + 1);
5028 /* recalculate toolbar */
5029 TOOLBAR_CalcToolbar (hwnd);
5031 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
5032 if NORESIZE is NOT set, then the toolbar will always be resized to
5033 take up the whole window. With it set, sizing needs to be manual. */
5034 if (infoPtr->dwStyle & CCS_NORESIZE) {
5035 SetWindowPos(hwnd, NULL, 0, 0,
5036 infoPtr->rcBound.right - infoPtr->rcBound.left,
5037 infoPtr->rcBound.bottom - infoPtr->rcBound.top,
5038 SWP_NOMOVE);
5041 /* repaint toolbar */
5042 InvalidateRect(hwnd, NULL, TRUE);
5045 /* return bounding rectangle */
5046 if (lprc) {
5047 lprc->left = infoPtr->rcBound.left;
5048 lprc->right = infoPtr->rcBound.right;
5049 lprc->top = infoPtr->rcBound.top;
5050 lprc->bottom = infoPtr->rcBound.bottom;
5053 return 0;
5057 static LRESULT
5058 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5060 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5061 TBUTTON_INFO *btnPtr;
5062 INT nIndex;
5064 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5065 if (nIndex == -1)
5066 return FALSE;
5068 btnPtr = &infoPtr->buttons[nIndex];
5070 /* if hidden state has changed the invalidate entire window and recalc */
5071 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5072 btnPtr->fsState = LOWORD(lParam);
5073 TOOLBAR_CalcToolbar (hwnd);
5074 InvalidateRect(hwnd, 0, TRUE);
5075 return TRUE;
5078 /* process state changing if current state doesn't match new state */
5079 if(btnPtr->fsState != LOWORD(lParam))
5081 btnPtr->fsState = LOWORD(lParam);
5082 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5085 return TRUE;
5089 static LRESULT
5090 TOOLBAR_SetStyle (HWND hwnd, LPARAM lParam)
5092 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5094 return TRUE;
5098 static inline LRESULT
5099 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5101 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5103 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5105 infoPtr->hwndToolTip = (HWND)wParam;
5106 return 0;
5110 static LRESULT
5111 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
5113 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5114 BOOL bTemp;
5116 TRACE("%s hwnd=%p\n",
5117 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5119 bTemp = infoPtr->bUnicode;
5120 infoPtr->bUnicode = (BOOL)wParam;
5122 return bTemp;
5126 static LRESULT
5127 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5129 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5131 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5132 comctl32_color.clrBtnHighlight :
5133 infoPtr->clrBtnHighlight;
5134 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5135 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5136 return 1;
5140 static LRESULT
5141 TOOLBAR_SetColorScheme (HWND hwnd, const COLORSCHEME *lParam)
5143 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5145 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5146 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5147 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5149 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5150 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5151 InvalidateRect(hwnd, NULL, TRUE);
5152 return 0;
5156 static LRESULT
5157 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5159 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5160 INT iOldVersion = infoPtr->iVersion;
5162 infoPtr->iVersion = iVersion;
5164 if (infoPtr->iVersion >= 5)
5165 TOOLBAR_SetUnicodeFormat(hwnd, TRUE);
5167 return iOldVersion;
5171 static LRESULT
5172 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5174 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5175 WORD iString = HIWORD(wParam);
5176 WORD buffersize = LOWORD(wParam);
5177 LPSTR str = (LPSTR)lParam;
5178 LRESULT ret = -1;
5180 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5182 if (iString < infoPtr->nNumStrings)
5184 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5185 ret--;
5187 TRACE("returning %s\n", debugstr_a(str));
5189 else
5190 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5192 return ret;
5196 static LRESULT
5197 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5199 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5200 WORD iString = HIWORD(wParam);
5201 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5202 LPWSTR str = (LPWSTR)lParam;
5203 LRESULT ret = -1;
5205 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5207 if (iString < infoPtr->nNumStrings)
5209 len = min(len, strlenW(infoPtr->strings[iString]));
5210 ret = (len+1)*sizeof(WCHAR);
5211 if (str)
5213 memcpy(str, infoPtr->strings[iString], ret);
5214 str[len] = '\0';
5216 ret = len;
5218 TRACE("returning %s\n", debugstr_w(str));
5220 else
5221 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5223 return ret;
5226 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5227 * is the maximum size of the toolbar? */
5228 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5230 SIZE * pSize = (SIZE*)lParam;
5231 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5232 return 0;
5236 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5237 * caller to specify a reason why the hot item changed (rather than just the
5238 * HICF_OTHER that TB_SETHOTITEM sends). */
5239 static LRESULT
5240 TOOLBAR_SetHotItem2 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5242 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5243 INT nOldHotItem = infoPtr->nHotItem;
5245 TRACE("old item=%d, new item=%d, flags=%08x\n",
5246 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5248 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5249 wParam = -1;
5251 /* NOTE: an application can still remove the hot item even if anchor
5252 * highlighting is enabled */
5254 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5256 GetFocus();
5258 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5261 /* Sets the toolbar global iListGap parameter which controls the amount of
5262 * spacing between the image and the text of buttons for TBSTYLE_LIST
5263 * toolbars. */
5264 static LRESULT TOOLBAR_SetListGap(HWND hwnd, WPARAM wParam)
5266 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5268 TRACE("hwnd=%p iListGap=%ld\n", hwnd, wParam);
5270 infoPtr->iListGap = (INT)wParam;
5272 InvalidateRect(hwnd, NULL, TRUE);
5274 return 0;
5277 /* Returns the number of maximum number of image lists associated with the
5278 * various states. */
5279 static LRESULT TOOLBAR_GetImageListCount(HWND hwnd, WPARAM wParam, LPARAM lParam)
5281 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5283 TRACE("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5285 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5288 static LRESULT
5289 TOOLBAR_GetIdealSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5291 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5292 LPSIZE lpsize = (LPSIZE)lParam;
5294 if (lpsize == NULL)
5295 return FALSE;
5298 * Testing shows the following:
5299 * wParam = 0 adjust cx value
5300 * = 1 set cy value to max size.
5301 * lParam pointer to SIZE structure
5304 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5305 wParam, lParam, lpsize->cx, lpsize->cy);
5307 switch(wParam) {
5308 case 0:
5309 if (lpsize->cx == -1) {
5310 /* **** this is wrong, native measures each button and sets it */
5311 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5313 else if(HIWORD(lpsize->cx)) {
5314 RECT rc;
5315 HWND hwndParent = GetParent(hwnd);
5317 GetWindowRect(hwnd, &rc);
5318 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5319 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc));
5320 lpsize->cx = max(rc.right-rc.left,
5321 infoPtr->rcBound.right - infoPtr->rcBound.left);
5323 else {
5324 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5326 break;
5327 case 1:
5328 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5329 break;
5330 default:
5331 FIXME("Unknown wParam %ld\n", wParam);
5332 return 0;
5334 TRACE("set to -> 0x%08x 0x%08x\n",
5335 lpsize->cx, lpsize->cy);
5336 return 1;
5339 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5341 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5343 InvalidateRect(hwnd, NULL, TRUE);
5344 return 1;
5348 static LRESULT
5349 TOOLBAR_Create (HWND hwnd, LPARAM lParam)
5351 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5352 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5353 LOGFONTW logFont;
5355 TRACE("hwnd = %p\n", hwnd);
5357 /* initialize info structure */
5358 infoPtr->nButtonWidth = 23;
5359 infoPtr->nButtonHeight = 22;
5360 infoPtr->nBitmapHeight = 16;
5361 infoPtr->nBitmapWidth = 16;
5363 infoPtr->nMaxTextRows = 1;
5364 infoPtr->cxMin = -1;
5365 infoPtr->cxMax = -1;
5366 infoPtr->nNumBitmaps = 0;
5367 infoPtr->nNumStrings = 0;
5369 infoPtr->bCaptured = FALSE;
5370 infoPtr->nButtonDown = -1;
5371 infoPtr->nButtonDrag = -1;
5372 infoPtr->nOldHit = -1;
5373 infoPtr->nHotItem = -1;
5374 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5375 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5376 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5377 infoPtr->bDragOutSent = FALSE;
5378 infoPtr->iVersion = 0;
5379 infoPtr->hwndSelf = hwnd;
5380 infoPtr->bDoRedraw = TRUE;
5381 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5382 infoPtr->clrBtnShadow = CLR_DEFAULT;
5383 infoPtr->szPadding.cx = DEFPAD_CX;
5384 infoPtr->szPadding.cy = DEFPAD_CY;
5385 infoPtr->iListGap = DEFLISTGAP;
5386 infoPtr->iTopMargin = default_top_margin(infoPtr);
5387 infoPtr->dwStyle = dwStyle;
5388 infoPtr->tbim.iButton = -1;
5389 GetClientRect(hwnd, &infoPtr->client_rect);
5390 infoPtr->bUnicode = infoPtr->hwndNotify &&
5391 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5392 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5394 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5395 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5397 OpenThemeData (hwnd, themeClass);
5399 TOOLBAR_CheckStyle (hwnd, dwStyle);
5401 return 0;
5405 static LRESULT
5406 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5408 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5410 /* delete tooltip control */
5411 if (infoPtr->hwndToolTip)
5412 DestroyWindow (infoPtr->hwndToolTip);
5414 /* delete temporary buffer for tooltip text */
5415 Free (infoPtr->pszTooltipText);
5416 Free (infoPtr->bitmaps); /* bitmaps list */
5418 /* delete button data */
5419 Free (infoPtr->buttons);
5421 /* delete strings */
5422 if (infoPtr->strings) {
5423 INT i;
5424 for (i = 0; i < infoPtr->nNumStrings; i++)
5425 Free (infoPtr->strings[i]);
5427 Free (infoPtr->strings);
5430 /* destroy internal image list */
5431 if (infoPtr->himlInt)
5432 ImageList_Destroy (infoPtr->himlInt);
5434 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5435 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5436 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5438 /* delete default font */
5439 DeleteObject (infoPtr->hDefaultFont);
5441 CloseThemeData (GetWindowTheme (hwnd));
5443 /* free toolbar info data */
5444 Free (infoPtr);
5445 SetWindowLongPtrW (hwnd, 0, 0);
5447 return 0;
5451 static LRESULT
5452 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5454 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5455 NMTBCUSTOMDRAW tbcd;
5456 INT ret = FALSE;
5457 DWORD ntfret;
5458 HTHEME theme = GetWindowTheme (hwnd);
5459 DWORD dwEraseCustDraw = 0;
5461 /* the app has told us not to redraw the toolbar */
5462 if (!infoPtr->bDoRedraw)
5463 return FALSE;
5465 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5466 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5467 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5468 tbcd.nmcd.hdc = (HDC)wParam;
5469 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5470 dwEraseCustDraw = ntfret & 0xffff;
5472 /* FIXME: in general the return flags *can* be or'ed together */
5473 switch (dwEraseCustDraw)
5475 case CDRF_DODEFAULT:
5476 break;
5477 case CDRF_SKIPDEFAULT:
5478 return TRUE;
5479 default:
5480 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5481 hwnd, ntfret);
5485 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5486 * to my parent for processing.
5488 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5489 POINT pt, ptorig;
5490 HDC hdc = (HDC)wParam;
5491 HWND parent;
5493 pt.x = 0;
5494 pt.y = 0;
5495 parent = GetParent(hwnd);
5496 MapWindowPoints(hwnd, parent, &pt, 1);
5497 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5498 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5499 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5501 if (!ret)
5502 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5504 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5505 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5506 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5507 tbcd.nmcd.hdc = (HDC)wParam;
5508 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5509 dwEraseCustDraw = ntfret & 0xffff;
5510 switch (dwEraseCustDraw)
5512 case CDRF_DODEFAULT:
5513 break;
5514 case CDRF_SKIPDEFAULT:
5515 return TRUE;
5516 default:
5517 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5518 hwnd, ntfret);
5521 return ret;
5525 static LRESULT
5526 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5528 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5530 return (LRESULT)infoPtr->hFont;
5534 static void
5535 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5537 INT i;
5538 INT nNewHotItem = infoPtr->nHotItem;
5540 for (i = 0; i < infoPtr->nNumButtons; i++)
5542 /* did we wrap? */
5543 if ((nNewHotItem + iDirection < 0) ||
5544 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5546 NMTBWRAPHOTITEM nmtbwhi;
5547 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5548 nmtbwhi.iDirection = iDirection;
5549 nmtbwhi.dwReason = dwReason;
5551 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5552 return;
5555 nNewHotItem += iDirection;
5556 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5558 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5559 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5561 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5562 break;
5567 static LRESULT
5568 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5570 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5571 NMKEY nmkey;
5573 nmkey.nVKey = (UINT)wParam;
5574 nmkey.uFlags = HIWORD(lParam);
5576 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5577 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5579 switch ((UINT)wParam)
5581 case VK_LEFT:
5582 case VK_UP:
5583 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5584 break;
5585 case VK_RIGHT:
5586 case VK_DOWN:
5587 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5588 break;
5589 case VK_SPACE:
5590 case VK_RETURN:
5591 if ((infoPtr->nHotItem >= 0) &&
5592 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5594 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5595 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5596 (LPARAM)hwnd);
5598 break;
5601 return 0;
5605 static LRESULT
5606 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5608 POINT pt;
5609 INT nHit;
5611 pt.x = (short)LOWORD(lParam);
5612 pt.y = (short)HIWORD(lParam);
5613 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5615 if (nHit >= 0)
5616 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5617 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5618 TOOLBAR_Customize (hwnd);
5620 return 0;
5624 static LRESULT
5625 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5627 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5628 TBUTTON_INFO *btnPtr;
5629 POINT pt;
5630 INT nHit;
5631 NMTOOLBARA nmtb;
5632 NMMOUSE nmmouse;
5633 BOOL bDragKeyPressed;
5635 TRACE("\n");
5637 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5638 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5639 else
5640 bDragKeyPressed = (wParam & MK_SHIFT);
5642 if (infoPtr->hwndToolTip)
5643 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5644 WM_LBUTTONDOWN, wParam, lParam);
5646 pt.x = (short)LOWORD(lParam);
5647 pt.y = (short)HIWORD(lParam);
5648 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5650 btnPtr = &infoPtr->buttons[nHit];
5652 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5654 infoPtr->nButtonDrag = nHit;
5655 SetCapture (hwnd);
5657 /* If drag cursor has not been loaded, load it.
5658 * Note: it doesn't need to be freed */
5659 if (!hCursorDrag)
5660 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5661 SetCursor(hCursorDrag);
5663 else if (nHit >= 0)
5665 RECT arrowRect;
5666 infoPtr->nOldHit = nHit;
5668 CopyRect(&arrowRect, &btnPtr->rect);
5669 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5671 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5672 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5673 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5674 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5675 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5676 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5678 LRESULT res;
5680 /* draw in pressed state */
5681 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5682 btnPtr->fsState |= TBSTATE_PRESSED;
5683 else
5684 btnPtr->bDropDownPressed = TRUE;
5685 RedrawWindow(hwnd,&btnPtr->rect,0,
5686 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5688 memset(&nmtb, 0, sizeof(nmtb));
5689 nmtb.iItem = btnPtr->idCommand;
5690 nmtb.rcButton = btnPtr->rect;
5691 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5692 TBN_DROPDOWN);
5693 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5695 if (res != TBDDRET_TREATPRESSED)
5697 MSG msg;
5699 /* redraw button in unpressed state */
5700 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5701 btnPtr->fsState &= ~TBSTATE_PRESSED;
5702 else
5703 btnPtr->bDropDownPressed = FALSE;
5704 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5706 /* find and set hot item
5707 * NOTE: native doesn't do this, but that is a bug */
5708 GetCursorPos(&pt);
5709 ScreenToClient(hwnd, &pt);
5710 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5711 if (!infoPtr->bAnchor || (nHit >= 0))
5712 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5714 /* remove any left mouse button down or double-click messages
5715 * so that we can get a toggle effect on the button */
5716 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5717 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5720 return 0;
5722 /* otherwise drop through and process as pushed */
5724 infoPtr->bCaptured = TRUE;
5725 infoPtr->nButtonDown = nHit;
5726 infoPtr->bDragOutSent = FALSE;
5728 btnPtr->fsState |= TBSTATE_PRESSED;
5730 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5732 if (btnPtr->fsState & TBSTATE_ENABLED)
5733 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5734 UpdateWindow(hwnd);
5735 SetCapture (hwnd);
5738 if (nHit >=0)
5740 memset(&nmtb, 0, sizeof(nmtb));
5741 nmtb.iItem = btnPtr->idCommand;
5742 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5745 nmmouse.dwHitInfo = nHit;
5747 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5748 if (nHit < 0)
5749 nmmouse.dwItemSpec = -1;
5750 else
5752 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5753 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5756 ClientToScreen(hwnd, &pt);
5757 nmmouse.pt = pt;
5759 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5760 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5762 return 0;
5765 static LRESULT
5766 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5768 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5769 TBUTTON_INFO *btnPtr;
5770 POINT pt;
5771 INT nHit;
5772 INT nOldIndex = -1;
5773 NMHDR hdr;
5774 NMMOUSE nmmouse;
5775 NMTOOLBARA nmtb;
5777 if (infoPtr->hwndToolTip)
5778 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5779 WM_LBUTTONUP, wParam, lParam);
5781 pt.x = (short)LOWORD(lParam);
5782 pt.y = (short)HIWORD(lParam);
5783 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5785 if (!infoPtr->bAnchor || (nHit >= 0))
5786 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5788 if (infoPtr->nButtonDrag >= 0) {
5789 RECT rcClient;
5790 NMHDR hdr;
5792 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5793 ReleaseCapture();
5794 /* reset cursor */
5795 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5797 GetClientRect(hwnd, &rcClient);
5798 if (PtInRect(&rcClient, pt))
5800 INT nButton = -1;
5801 if (nHit >= 0)
5802 nButton = nHit;
5803 else if (nHit < -1)
5804 nButton = -nHit;
5805 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5806 nButton = -nHit;
5808 if (nButton == infoPtr->nButtonDrag)
5810 /* if the button is moved sightly left and we have a
5811 * separator there then remove it */
5812 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5814 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5815 TOOLBAR_DeleteButton(hwnd, nButton - 1);
5817 else /* else insert a separator before the dragged button */
5819 TBBUTTON tbb;
5820 memset(&tbb, 0, sizeof(tbb));
5821 tbb.fsStyle = BTNS_SEP;
5822 tbb.iString = -1;
5823 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5826 else
5828 if (nButton == -1)
5830 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5831 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5832 else
5833 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5835 else
5836 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5839 else
5841 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5842 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag);
5845 /* button under cursor changed so need to re-set hot item */
5846 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5847 infoPtr->nButtonDrag = -1;
5849 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5851 else if (infoPtr->nButtonDown >= 0) {
5852 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5853 btnPtr->fsState &= ~TBSTATE_PRESSED;
5855 if (btnPtr->fsStyle & BTNS_CHECK) {
5856 if (btnPtr->fsStyle & BTNS_GROUP) {
5857 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5858 nHit);
5859 if ((nOldIndex != nHit) &&
5860 (nOldIndex != -1))
5861 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5862 btnPtr->fsState |= TBSTATE_CHECKED;
5864 else {
5865 if (btnPtr->fsState & TBSTATE_CHECKED)
5866 btnPtr->fsState &= ~TBSTATE_CHECKED;
5867 else
5868 btnPtr->fsState |= TBSTATE_CHECKED;
5872 if (nOldIndex != -1)
5873 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5876 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5877 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5878 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5880 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5881 ReleaseCapture ();
5882 infoPtr->nButtonDown = -1;
5884 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5885 TOOLBAR_SendNotify (&hdr, infoPtr,
5886 NM_RELEASEDCAPTURE);
5888 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5889 * TBN_BEGINDRAG
5891 memset(&nmtb, 0, sizeof(nmtb));
5892 nmtb.iItem = btnPtr->idCommand;
5893 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5894 TBN_ENDDRAG);
5896 if (btnPtr->fsState & TBSTATE_ENABLED)
5898 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5899 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5901 /* In case we have just been destroyed... */
5902 if(!IsWindow(hwnd))
5903 return 0;
5907 /* !!! Undocumented - toolbar at 4.71 level and above sends
5908 * NM_CLICK with the NMMOUSE structure. */
5909 nmmouse.dwHitInfo = nHit;
5911 if (nHit < 0)
5912 nmmouse.dwItemSpec = -1;
5913 else
5915 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5916 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5919 ClientToScreen(hwnd, &pt);
5920 nmmouse.pt = pt;
5922 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5923 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5925 return 0;
5928 static LRESULT
5929 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5931 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5932 INT nHit;
5933 NMMOUSE nmmouse;
5934 POINT pt;
5936 pt.x = (short)LOWORD(lParam);
5937 pt.y = (short)HIWORD(lParam);
5939 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5940 nmmouse.dwHitInfo = nHit;
5942 if (nHit < 0) {
5943 nmmouse.dwItemSpec = -1;
5944 } else {
5945 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5946 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5949 ClientToScreen(hwnd, &pt);
5950 nmmouse.pt = pt;
5952 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5953 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5955 return 0;
5958 static LRESULT
5959 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5961 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5962 NMHDR nmhdr;
5964 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5965 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5967 return 0;
5970 static LRESULT
5971 TOOLBAR_CaptureChanged(HWND hwnd)
5973 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5974 TBUTTON_INFO *btnPtr;
5976 infoPtr->bCaptured = FALSE;
5978 if (infoPtr->nButtonDown >= 0)
5980 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5981 btnPtr->fsState &= ~TBSTATE_PRESSED;
5983 infoPtr->nOldHit = -1;
5985 if (btnPtr->fsState & TBSTATE_ENABLED)
5986 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5988 return 0;
5991 static LRESULT
5992 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5994 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5996 /* don't remove hot effects when in anchor highlighting mode or when a
5997 * drop-down button is pressed */
5998 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
6000 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
6001 if (!hotBtnPtr->bDropDownPressed)
6002 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6005 if (infoPtr->nOldHit < 0)
6006 return TRUE;
6008 /* If the last button we were over is depressed then make it not */
6009 /* depressed and redraw it */
6010 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6012 TBUTTON_INFO *btnPtr;
6013 RECT rc1;
6015 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6017 btnPtr->fsState &= ~TBSTATE_PRESSED;
6019 rc1 = btnPtr->rect;
6020 InflateRect (&rc1, 1, 1);
6021 InvalidateRect (hwnd, &rc1, TRUE);
6024 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6026 NMTOOLBARW nmt;
6027 ZeroMemory(&nmt, sizeof(nmt));
6028 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6029 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6030 infoPtr->bDragOutSent = TRUE;
6033 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6035 return TRUE;
6038 static LRESULT
6039 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6041 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6042 POINT pt;
6043 TRACKMOUSEEVENT trackinfo;
6044 INT nHit;
6045 TBUTTON_INFO *btnPtr;
6047 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6048 TOOLBAR_TooltipCreateControl(infoPtr);
6050 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6051 /* fill in the TRACKMOUSEEVENT struct */
6052 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6053 trackinfo.dwFlags = TME_QUERY;
6055 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6056 _TrackMouseEvent(&trackinfo);
6058 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6059 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6060 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6061 trackinfo.hwndTrack = hwnd;
6063 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6064 /* and can properly deactivate the hot toolbar button */
6065 _TrackMouseEvent(&trackinfo);
6069 if (infoPtr->hwndToolTip)
6070 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6071 WM_MOUSEMOVE, wParam, lParam);
6073 pt.x = (short)LOWORD(lParam);
6074 pt.y = (short)HIWORD(lParam);
6076 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6078 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6079 && (!infoPtr->bAnchor || (nHit >= 0)))
6080 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6082 if (infoPtr->nOldHit != nHit)
6084 if (infoPtr->bCaptured)
6086 if (!infoPtr->bDragOutSent)
6088 NMTOOLBARW nmt;
6089 ZeroMemory(&nmt, sizeof(nmt));
6090 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6091 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6092 infoPtr->bDragOutSent = TRUE;
6095 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6096 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6097 btnPtr->fsState &= ~TBSTATE_PRESSED;
6098 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6100 else if (nHit == infoPtr->nButtonDown) {
6101 btnPtr->fsState |= TBSTATE_PRESSED;
6102 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6104 infoPtr->nOldHit = nHit;
6108 return 0;
6112 static inline LRESULT
6113 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6115 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6116 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6117 /* else */
6118 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6122 static inline LRESULT
6123 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6125 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6126 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6128 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6132 static LRESULT
6133 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6135 TOOLBAR_INFO *infoPtr;
6136 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6137 DWORD styleadd = 0;
6139 /* allocate memory for info structure */
6140 infoPtr = Alloc (sizeof(TOOLBAR_INFO));
6141 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6143 /* paranoid!! */
6144 infoPtr->dwStructSize = sizeof(TBBUTTON);
6145 infoPtr->nRows = 1;
6146 infoPtr->nWidth = 0;
6148 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6149 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6150 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6151 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6154 /* native control does:
6155 * Get a lot of colors and brushes
6156 * WM_NOTIFYFORMAT
6157 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6158 * CreateFontIndirectW(adr1)
6159 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6160 * hdc = GetDC(toolbar)
6161 * GetSystemMetrics(0x48)
6162 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6163 * 0, 0, 0, 0, "MARLETT")
6164 * oldfnt = SelectObject(hdc, fnt2)
6165 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6166 * GetTextMetricsW(hdc, adr3)
6167 * SelectObject(hdc, oldfnt)
6168 * DeleteObject(fnt2)
6169 * ReleaseDC(hdc)
6170 * InvalidateRect(toolbar, 0, 1)
6171 * SetWindowLongW(toolbar, 0, addr)
6172 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6173 * WM_STYLECHANGING
6174 * CallWinEx old new
6175 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6176 * ie 2 0x4600094c 0x4600094c 0x4600894d
6177 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6178 * rebar 0x50008844 0x40008844 0x50008845
6179 * pager 0x50000844 0x40000844 0x50008845
6180 * IC35mgr 0x5400084e **nochange**
6181 * on entry to _NCCREATE 0x5400084e
6182 * rowlist 0x5400004e **nochange**
6183 * on entry to _NCCREATE 0x5400004e
6187 /* I think the code below is a bug, but it is the way that the native
6188 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6189 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6190 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6191 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6192 * Somehow, the only cases of this seem to be MFC programs.
6194 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6195 * does not occur in the WM_STYLECHANGING routine.
6196 * (Guy Albertelli 9/2001)
6199 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6200 && !(cs->style & TBSTYLE_TRANSPARENT))
6201 styleadd |= TBSTYLE_TRANSPARENT;
6202 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6203 styleadd |= CCS_TOP; /* default to top */
6204 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6207 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6211 static LRESULT
6212 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6214 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6215 RECT rcWindow;
6216 HDC hdc;
6218 if (dwStyle & WS_MINIMIZE)
6219 return 0; /* Nothing to do */
6221 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6223 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6224 return 0;
6226 if (!(dwStyle & CCS_NODIVIDER))
6228 GetWindowRect (hwnd, &rcWindow);
6229 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6230 if( dwStyle & WS_BORDER )
6231 OffsetRect (&rcWindow, 1, 1);
6232 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6235 ReleaseDC( hwnd, hdc );
6237 return 0;
6241 /* handles requests from the tooltip control on what text to display */
6242 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6244 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6246 TRACE("button index = %d\n", index);
6248 Free (infoPtr->pszTooltipText);
6249 infoPtr->pszTooltipText = NULL;
6251 if (index < 0)
6252 return 0;
6254 if (infoPtr->bUnicode)
6256 WCHAR wszBuffer[INFOTIPSIZE+1];
6257 NMTBGETINFOTIPW tbgit;
6258 unsigned int len; /* in chars */
6260 wszBuffer[0] = '\0';
6261 wszBuffer[INFOTIPSIZE] = '\0';
6263 tbgit.pszText = wszBuffer;
6264 tbgit.cchTextMax = INFOTIPSIZE;
6265 tbgit.iItem = lpnmtdi->hdr.idFrom;
6266 tbgit.lParam = infoPtr->buttons[index].dwData;
6268 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6270 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6272 len = strlenW(tbgit.pszText);
6273 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6275 /* need to allocate temporary buffer in infoPtr as there
6276 * isn't enough space in buffer passed to us by the
6277 * tooltip control */
6278 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6279 if (infoPtr->pszTooltipText)
6281 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6282 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6283 return 0;
6286 else if (len > 0)
6288 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6289 return 0;
6292 else
6294 CHAR szBuffer[INFOTIPSIZE+1];
6295 NMTBGETINFOTIPA tbgit;
6296 unsigned int len; /* in chars */
6298 szBuffer[0] = '\0';
6299 szBuffer[INFOTIPSIZE] = '\0';
6301 tbgit.pszText = szBuffer;
6302 tbgit.cchTextMax = INFOTIPSIZE;
6303 tbgit.iItem = lpnmtdi->hdr.idFrom;
6304 tbgit.lParam = infoPtr->buttons[index].dwData;
6306 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6308 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6310 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6311 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6313 /* need to allocate temporary buffer in infoPtr as there
6314 * isn't enough space in buffer passed to us by the
6315 * tooltip control */
6316 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6317 if (infoPtr->pszTooltipText)
6319 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6320 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6321 return 0;
6324 else if (tbgit.pszText[0])
6326 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6327 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6328 return 0;
6332 /* if button has text, but it is not shown then automatically
6333 * use that text as tooltip */
6334 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6335 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6337 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6338 unsigned int len = pszText ? strlenW(pszText) : 0;
6340 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6342 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6344 /* need to allocate temporary buffer in infoPtr as there
6345 * isn't enough space in buffer passed to us by the
6346 * tooltip control */
6347 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6348 if (infoPtr->pszTooltipText)
6350 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6351 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6352 return 0;
6355 else if (len > 0)
6357 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6358 return 0;
6362 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6364 /* last resort: send notification on to app */
6365 /* FIXME: find out what is really used here */
6366 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, lpnmtdi->hdr.idFrom, (LPARAM)lpnmtdi);
6370 static inline LRESULT
6371 TOOLBAR_Notify (HWND hwnd, LPARAM lParam)
6373 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6374 LPNMHDR lpnmh = (LPNMHDR)lParam;
6376 switch (lpnmh->code)
6378 case PGN_CALCSIZE:
6380 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6382 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6383 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6384 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6385 lppgc->iWidth);
6387 else {
6388 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6389 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6390 lppgc->iHeight);
6392 return 0;
6395 case PGN_SCROLL:
6397 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6399 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6400 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6401 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6402 lppgs->iScroll, lppgs->iDir);
6403 return 0;
6406 case TTN_GETDISPINFOW:
6407 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6409 case TTN_GETDISPINFOA:
6410 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6411 return 0;
6413 default:
6414 return 0;
6419 static LRESULT
6420 TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6422 LRESULT format;
6424 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam, lParam);
6426 if (lParam == NF_QUERY)
6427 return NFR_UNICODE;
6429 if (lParam == NF_REQUERY) {
6430 format = SendMessageW(infoPtr->hwndNotify,
6431 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6432 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6433 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6434 format);
6435 format = NFR_ANSI;
6437 return format;
6439 return 0;
6443 static LRESULT
6444 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6446 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6447 HDC hdc;
6448 PAINTSTRUCT ps;
6450 /* fill ps.rcPaint with a default rect */
6451 ps.rcPaint = infoPtr->rcBound;
6453 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6455 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps.rcPaint));
6457 TOOLBAR_Refresh (hwnd, hdc, &ps);
6458 if (!wParam) EndPaint (hwnd, &ps);
6460 return 0;
6464 static LRESULT
6465 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6467 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6469 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6471 /* make first item hot */
6472 if (infoPtr->nNumButtons > 0)
6473 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6475 return 0;
6478 static LRESULT
6479 TOOLBAR_SetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
6481 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6483 TRACE("font=%p redraw=%ld\n", (HFONT)wParam, lParam);
6485 if (wParam == 0)
6486 infoPtr->hFont = infoPtr->hDefaultFont;
6487 else
6488 infoPtr->hFont = (HFONT)wParam;
6490 TOOLBAR_CalcToolbar(hwnd);
6492 if (lParam)
6493 InvalidateRect(hwnd, NULL, TRUE);
6494 return 1;
6497 static LRESULT
6498 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6499 /*****************************************************
6501 * Function;
6502 * Handles the WM_SETREDRAW message.
6504 * Documentation:
6505 * According to testing V4.71 of COMCTL32 returns the
6506 * *previous* status of the redraw flag (either 0 or 1)
6507 * instead of the MSDN documented value of 0 if handled.
6508 * (For laughs see the "consistency" with same function
6509 * in rebar.)
6511 *****************************************************/
6513 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6514 BOOL oldredraw = infoPtr->bDoRedraw;
6516 TRACE("set to %s\n",
6517 (wParam) ? "TRUE" : "FALSE");
6518 infoPtr->bDoRedraw = (BOOL) wParam;
6519 if (wParam) {
6520 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6522 return (oldredraw) ? 1 : 0;
6526 static LRESULT
6527 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6529 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6531 TRACE("sizing toolbar!\n");
6533 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6535 RECT delta_width, delta_height, client, dummy;
6536 DWORD min_x, max_x, min_y, max_y;
6537 TBUTTON_INFO *btnPtr;
6538 INT i;
6540 GetClientRect(hwnd, &client);
6541 if(client.right > infoPtr->client_rect.right)
6543 min_x = infoPtr->client_rect.right;
6544 max_x = client.right;
6546 else
6548 max_x = infoPtr->client_rect.right;
6549 min_x = client.right;
6551 if(client.bottom > infoPtr->client_rect.bottom)
6553 min_y = infoPtr->client_rect.bottom;
6554 max_y = client.bottom;
6556 else
6558 max_y = infoPtr->client_rect.bottom;
6559 min_y = client.bottom;
6562 SetRect(&delta_width, min_x, 0, max_x, min_y);
6563 SetRect(&delta_height, 0, min_y, max_x, max_y);
6565 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6566 btnPtr = infoPtr->buttons;
6567 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6568 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6569 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6570 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6572 GetClientRect(hwnd, &infoPtr->client_rect);
6573 TOOLBAR_AutoSize(hwnd);
6574 return 0;
6578 static LRESULT
6579 TOOLBAR_StyleChanged (HWND hwnd, INT nType, const STYLESTRUCT *lpStyle)
6581 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6583 if (nType == GWL_STYLE)
6585 DWORD dwOldStyle = infoPtr->dwStyle;
6587 if (lpStyle->styleNew & TBSTYLE_LIST)
6588 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6589 else
6590 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6592 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6594 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6596 infoPtr->dwStyle = lpStyle->styleNew;
6598 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6599 TOOLBAR_LayoutToolbar(hwnd);
6601 /* only resize if one of the CCS_* styles was changed */
6602 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6604 TOOLBAR_AutoSize (hwnd);
6606 InvalidateRect(hwnd, NULL, TRUE);
6610 return 0;
6614 static LRESULT
6615 TOOLBAR_SysColorChange (HWND hwnd)
6617 COMCTL32_RefreshSysColors();
6619 return 0;
6623 /* update theme after a WM_THEMECHANGED message */
6624 static LRESULT theme_changed (HWND hwnd)
6626 HTHEME theme = GetWindowTheme (hwnd);
6627 CloseThemeData (theme);
6628 OpenThemeData (hwnd, themeClass);
6629 return 0;
6633 static LRESULT WINAPI
6634 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6636 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6638 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6639 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6641 if (!infoPtr && (uMsg != WM_NCCREATE))
6642 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6644 switch (uMsg)
6646 case TB_ADDBITMAP:
6647 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6649 case TB_ADDBUTTONSA:
6650 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6652 case TB_ADDBUTTONSW:
6653 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6655 case TB_ADDSTRINGA:
6656 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6658 case TB_ADDSTRINGW:
6659 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6661 case TB_AUTOSIZE:
6662 return TOOLBAR_AutoSize (hwnd);
6664 case TB_BUTTONCOUNT:
6665 return TOOLBAR_ButtonCount (hwnd);
6667 case TB_BUTTONSTRUCTSIZE:
6668 return TOOLBAR_ButtonStructSize (hwnd, wParam);
6670 case TB_CHANGEBITMAP:
6671 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6673 case TB_CHECKBUTTON:
6674 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6676 case TB_COMMANDTOINDEX:
6677 return TOOLBAR_CommandToIndex (hwnd, wParam);
6679 case TB_CUSTOMIZE:
6680 return TOOLBAR_Customize (hwnd);
6682 case TB_DELETEBUTTON:
6683 return TOOLBAR_DeleteButton (hwnd, wParam);
6685 case TB_ENABLEBUTTON:
6686 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6688 case TB_GETANCHORHIGHLIGHT:
6689 return TOOLBAR_GetAnchorHighlight (hwnd);
6691 case TB_GETBITMAP:
6692 return TOOLBAR_GetBitmap (hwnd, wParam);
6694 case TB_GETBITMAPFLAGS:
6695 return TOOLBAR_GetBitmapFlags ();
6697 case TB_GETBUTTON:
6698 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6700 case TB_GETBUTTONINFOA:
6701 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, FALSE);
6703 case TB_GETBUTTONINFOW:
6704 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, TRUE);
6706 case TB_GETBUTTONSIZE:
6707 return TOOLBAR_GetButtonSize (hwnd);
6709 case TB_GETBUTTONTEXTA:
6710 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6712 case TB_GETBUTTONTEXTW:
6713 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6715 case TB_GETDISABLEDIMAGELIST:
6716 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6718 case TB_GETEXTENDEDSTYLE:
6719 return TOOLBAR_GetExtendedStyle (hwnd);
6721 case TB_GETHOTIMAGELIST:
6722 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6724 case TB_GETHOTITEM:
6725 return TOOLBAR_GetHotItem (hwnd);
6727 case TB_GETIMAGELIST:
6728 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6730 case TB_GETINSERTMARK:
6731 return TOOLBAR_GetInsertMark (hwnd, lParam);
6733 case TB_GETINSERTMARKCOLOR:
6734 return TOOLBAR_GetInsertMarkColor (hwnd);
6736 case TB_GETITEMRECT:
6737 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6739 case TB_GETMAXSIZE:
6740 return TOOLBAR_GetMaxSize (hwnd, lParam);
6742 /* case TB_GETOBJECT: */ /* 4.71 */
6744 case TB_GETPADDING:
6745 return TOOLBAR_GetPadding (hwnd);
6747 case TB_GETRECT:
6748 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6750 case TB_GETROWS:
6751 return TOOLBAR_GetRows (hwnd);
6753 case TB_GETSTATE:
6754 return TOOLBAR_GetState (hwnd, wParam);
6756 case TB_GETSTRINGA:
6757 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6759 case TB_GETSTRINGW:
6760 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6762 case TB_GETSTYLE:
6763 return TOOLBAR_GetStyle (hwnd);
6765 case TB_GETTEXTROWS:
6766 return TOOLBAR_GetTextRows (hwnd);
6768 case TB_GETTOOLTIPS:
6769 return TOOLBAR_GetToolTips (hwnd);
6771 case TB_GETUNICODEFORMAT:
6772 return TOOLBAR_GetUnicodeFormat (hwnd);
6774 case TB_HIDEBUTTON:
6775 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6777 case TB_HITTEST:
6778 return TOOLBAR_HitTest (hwnd, lParam);
6780 case TB_INDETERMINATE:
6781 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6783 case TB_INSERTBUTTONA:
6784 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6786 case TB_INSERTBUTTONW:
6787 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6789 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6791 case TB_ISBUTTONCHECKED:
6792 return TOOLBAR_IsButtonChecked (hwnd, wParam);
6794 case TB_ISBUTTONENABLED:
6795 return TOOLBAR_IsButtonEnabled (hwnd, wParam);
6797 case TB_ISBUTTONHIDDEN:
6798 return TOOLBAR_IsButtonHidden (hwnd, wParam);
6800 case TB_ISBUTTONHIGHLIGHTED:
6801 return TOOLBAR_IsButtonHighlighted (hwnd, wParam);
6803 case TB_ISBUTTONINDETERMINATE:
6804 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam);
6806 case TB_ISBUTTONPRESSED:
6807 return TOOLBAR_IsButtonPressed (hwnd, wParam);
6809 case TB_LOADIMAGES:
6810 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6812 case TB_MAPACCELERATORA:
6813 case TB_MAPACCELERATORW:
6814 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6816 case TB_MARKBUTTON:
6817 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6819 case TB_MOVEBUTTON:
6820 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6822 case TB_PRESSBUTTON:
6823 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6825 case TB_REPLACEBITMAP:
6826 return TOOLBAR_ReplaceBitmap (hwnd, lParam);
6828 case TB_SAVERESTOREA:
6829 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6831 case TB_SAVERESTOREW:
6832 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6834 case TB_SETANCHORHIGHLIGHT:
6835 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6837 case TB_SETBITMAPSIZE:
6838 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6840 case TB_SETBUTTONINFOA:
6841 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6843 case TB_SETBUTTONINFOW:
6844 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6846 case TB_SETBUTTONSIZE:
6847 return TOOLBAR_SetButtonSize (hwnd, lParam);
6849 case TB_SETBUTTONWIDTH:
6850 return TOOLBAR_SetButtonWidth (hwnd, lParam);
6852 case TB_SETCMDID:
6853 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6855 case TB_SETDISABLEDIMAGELIST:
6856 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6858 case TB_SETDRAWTEXTFLAGS:
6859 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6861 case TB_SETEXTENDEDSTYLE:
6862 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6864 case TB_SETHOTIMAGELIST:
6865 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6867 case TB_SETHOTITEM:
6868 return TOOLBAR_SetHotItem (hwnd, wParam);
6870 case TB_SETIMAGELIST:
6871 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6873 case TB_SETINDENT:
6874 return TOOLBAR_SetIndent (hwnd, wParam);
6876 case TB_SETINSERTMARK:
6877 return TOOLBAR_SetInsertMark (hwnd, lParam);
6879 case TB_SETINSERTMARKCOLOR:
6880 return TOOLBAR_SetInsertMarkColor (hwnd, lParam);
6882 case TB_SETMAXTEXTROWS:
6883 return TOOLBAR_SetMaxTextRows (hwnd, wParam);
6885 case TB_SETPADDING:
6886 return TOOLBAR_SetPadding (hwnd, lParam);
6888 case TB_SETPARENT:
6889 return TOOLBAR_SetParent (hwnd, wParam);
6891 case TB_SETROWS:
6892 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6894 case TB_SETSTATE:
6895 return TOOLBAR_SetState (hwnd, wParam, lParam);
6897 case TB_SETSTYLE:
6898 return TOOLBAR_SetStyle (hwnd, lParam);
6900 case TB_SETTOOLTIPS:
6901 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6903 case TB_SETUNICODEFORMAT:
6904 return TOOLBAR_SetUnicodeFormat (hwnd, wParam);
6906 case TB_UNKWN45D:
6907 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6909 case TB_SETHOTITEM2:
6910 return TOOLBAR_SetHotItem2 (hwnd, wParam, lParam);
6912 case TB_SETLISTGAP:
6913 return TOOLBAR_SetListGap(hwnd, wParam);
6915 case TB_GETIMAGELISTCOUNT:
6916 return TOOLBAR_GetImageListCount(hwnd, wParam, lParam);
6918 case TB_GETIDEALSIZE:
6919 return TOOLBAR_GetIdealSize (hwnd, wParam, lParam);
6921 case TB_UNKWN464:
6922 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6924 /* Common Control Messages */
6926 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6927 case CCM_GETCOLORSCHEME:
6928 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6930 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6931 case CCM_SETCOLORSCHEME:
6932 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6934 case CCM_GETVERSION:
6935 return TOOLBAR_GetVersion (hwnd);
6937 case CCM_SETVERSION:
6938 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6941 /* case WM_CHAR: */
6943 case WM_CREATE:
6944 return TOOLBAR_Create (hwnd, lParam);
6946 case WM_DESTROY:
6947 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6949 case WM_ERASEBKGND:
6950 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6952 case WM_GETFONT:
6953 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6955 case WM_KEYDOWN:
6956 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6958 /* case WM_KILLFOCUS: */
6960 case WM_LBUTTONDBLCLK:
6961 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6963 case WM_LBUTTONDOWN:
6964 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6966 case WM_LBUTTONUP:
6967 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6969 case WM_RBUTTONUP:
6970 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6972 case WM_RBUTTONDBLCLK:
6973 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6975 case WM_MOUSEMOVE:
6976 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6978 case WM_MOUSELEAVE:
6979 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6981 case WM_CAPTURECHANGED:
6982 return TOOLBAR_CaptureChanged(hwnd);
6984 case WM_NCACTIVATE:
6985 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6987 case WM_NCCALCSIZE:
6988 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6990 case WM_NCCREATE:
6991 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6993 case WM_NCPAINT:
6994 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6996 case WM_NOTIFY:
6997 return TOOLBAR_Notify (hwnd, lParam);
6999 case WM_NOTIFYFORMAT:
7000 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7002 case WM_PRINTCLIENT:
7003 case WM_PAINT:
7004 return TOOLBAR_Paint (hwnd, wParam);
7006 case WM_SETFOCUS:
7007 return TOOLBAR_SetFocus (hwnd, wParam);
7009 case WM_SETFONT:
7010 return TOOLBAR_SetFont(hwnd, wParam, lParam);
7012 case WM_SETREDRAW:
7013 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7015 case WM_SIZE:
7016 return TOOLBAR_Size (hwnd, wParam, lParam);
7018 case WM_STYLECHANGED:
7019 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7021 case WM_SYSCOLORCHANGE:
7022 return TOOLBAR_SysColorChange (hwnd);
7024 case WM_THEMECHANGED:
7025 return theme_changed (hwnd);
7027 /* case WM_WININICHANGE: */
7029 case WM_CHARTOITEM:
7030 case WM_COMMAND:
7031 case WM_DRAWITEM:
7032 case WM_MEASUREITEM:
7033 case WM_VKEYTOITEM:
7034 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7036 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7037 case PGM_FORWARDMOUSE:
7038 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7040 default:
7041 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
7042 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
7043 uMsg, wParam, lParam);
7044 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7049 VOID
7050 TOOLBAR_Register (void)
7052 WNDCLASSW wndClass;
7054 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7055 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7056 wndClass.lpfnWndProc = ToolbarWindowProc;
7057 wndClass.cbClsExtra = 0;
7058 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7059 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7060 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7061 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7063 RegisterClassW (&wndClass);
7067 VOID
7068 TOOLBAR_Unregister (void)
7070 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7073 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7075 HIMAGELIST himlold;
7076 PIMLENTRY c = NULL;
7078 /* Check if the entry already exists */
7079 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7081 /* If this is a new entry we must create it and insert into the array */
7082 if (!c)
7084 PIMLENTRY *pnies;
7086 c = Alloc(sizeof(IMLENTRY));
7087 c->id = id;
7089 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7090 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7091 pnies[*cies] = c;
7092 (*cies)++;
7094 Free(*pies);
7095 *pies = pnies;
7098 himlold = c->himl;
7099 c->himl = himl;
7101 return himlold;
7105 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7107 int i;
7109 for (i = 0; i < *cies; i++)
7110 Free((*pies)[i]);
7112 Free(*pies);
7114 *cies = 0;
7115 *pies = NULL;
7119 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id)
7121 PIMLENTRY c = NULL;
7123 if (pies != NULL)
7125 int i;
7127 for (i = 0; i < cies; i++)
7129 if (pies[i]->id == id)
7131 c = pies[i];
7132 break;
7137 return c;
7141 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id)
7143 HIMAGELIST himlDef = 0;
7144 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7146 if (pie)
7147 himlDef = pie->himl;
7149 return himlDef;
7153 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7155 if (infoPtr->bUnicode)
7156 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7157 else
7159 CHAR Buffer[256];
7160 NMTOOLBARA nmtba;
7161 BOOL bRet = FALSE;
7163 nmtba.iItem = nmtb->iItem;
7164 nmtba.pszText = Buffer;
7165 nmtba.cchText = 256;
7166 ZeroMemory(nmtba.pszText, nmtba.cchText);
7168 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7170 int ccht = strlen(nmtba.pszText);
7171 if (ccht)
7172 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7173 nmtb->pszText, nmtb->cchText);
7175 nmtb->tbButton = nmtba.tbButton;
7176 bRet = TRUE;
7179 return bRet;
7184 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo)
7186 NMTOOLBARW nmtb;
7188 /* MSDN states that iItem is the index of the button, rather than the
7189 * command ID as used by every other NMTOOLBAR notification */
7190 nmtb.iItem = iItem;
7191 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7193 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);