comctl32: Move up-down msg seq test functions into msg.c.
[wine/dcerpc.git] / dlls / comctl32 / toolbar.c
bloba60bf0976cd0c4205545786302df5659ca9637a0
1 /*
2 * Toolbar control
4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * NOTES
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
31 * TODO:
32 * - Styles:
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
35 * - Messages:
36 * - TB_GETMETRICS
37 * - TB_GETOBJECT
38 * - TB_INSERTMARKHITTEST
39 * - TB_SAVERESTORE
40 * - TB_SETMETRICS
41 * - WM_WININICHANGE
42 * - Notifications:
43 * - NM_CHAR
44 * - TBN_GETOBJECT
45 * - TBN_SAVE
46 * - Button wrapping (under construction).
47 * - Fix TB_SETROWS.
48 * - iListGap custom draw support.
50 * Testing:
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
71 #include <stdarg.h>
72 #include <string.h>
74 #include "windef.h"
75 #include "winbase.h"
76 #include "winreg.h"
77 #include "wingdi.h"
78 #include "winuser.h"
79 #include "wine/unicode.h"
80 #include "winnls.h"
81 #include "commctrl.h"
82 #include "comctl32.h"
83 #include "uxtheme.h"
84 #include "tmschema.h"
85 #include "wine/debug.h"
87 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
89 static HCURSOR hCursorDrag = NULL;
91 typedef struct
93 INT iBitmap;
94 INT idCommand;
95 BYTE fsState;
96 BYTE fsStyle;
97 BYTE bHot;
98 BYTE bDropDownPressed;
99 DWORD_PTR dwData;
100 INT_PTR iString;
101 INT nRow;
102 RECT rect;
103 INT cx; /* manually set size */
104 } TBUTTON_INFO;
106 typedef struct
108 UINT nButtons;
109 HINSTANCE hInst;
110 UINT nID;
111 } TBITMAP_INFO;
113 typedef struct
115 HIMAGELIST himl;
116 INT id;
117 } IMLENTRY, *PIMLENTRY;
119 typedef struct
121 DWORD dwStructSize; /* size of TBBUTTON struct */
122 INT nWidth; /* width of the toolbar */
123 RECT client_rect;
124 RECT rcBound; /* bounding rectangle */
125 INT nButtonHeight;
126 INT nButtonWidth;
127 INT nBitmapHeight;
128 INT nVBitmapHeight; /* see TOOLBAR_Create for an explanation */
129 INT nBitmapWidth;
130 INT nIndent;
131 INT nRows; /* number of button rows */
132 INT nMaxTextRows; /* maximum number of text rows */
133 INT cxMin; /* minimum button width */
134 INT cxMax; /* maximum button width */
135 INT nNumButtons; /* number of buttons */
136 INT nNumBitmaps; /* number of bitmaps */
137 INT nNumStrings; /* number of strings */
138 INT nNumBitmapInfos;
139 INT nButtonDown; /* toolbar button being pressed or -1 if none */
140 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
141 INT nOldHit;
142 INT nHotItem; /* index of the "hot" item */
143 SIZE szPadding; /* padding values around button */
144 INT iTopMargin; /* the top margin */
145 INT iListGap; /* default gap between text and image for toolbar with list style */
146 HFONT hDefaultFont;
147 HFONT hFont; /* text font */
148 HIMAGELIST himlInt; /* image list created internally */
149 PIMLENTRY *himlDef; /* default image list array */
150 INT cimlDef; /* default image list array count */
151 PIMLENTRY *himlHot; /* hot image list array */
152 INT cimlHot; /* hot image list array count */
153 PIMLENTRY *himlDis; /* disabled image list array */
154 INT cimlDis; /* disabled image list array count */
155 HWND hwndToolTip; /* handle to tool tip control */
156 HWND hwndNotify; /* handle to the window that gets notifications */
157 HWND hwndSelf; /* my own handle */
158 BOOL bAnchor; /* anchor highlight enabled */
159 BOOL bDoRedraw; /* Redraw status */
160 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
161 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
162 BOOL bCaptured; /* mouse captured? */
163 DWORD dwStyle; /* regular toolbar style */
164 DWORD dwExStyle; /* extended toolbar style */
165 DWORD dwDTFlags; /* DrawText flags */
167 COLORREF clrInsertMark; /* insert mark color */
168 COLORREF clrBtnHighlight; /* color for Flat Separator */
169 COLORREF clrBtnShadow; /* color for Flag Separator */
170 INT iVersion;
171 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
172 * for TTN_GETDISPINFOW notification */
173 TBINSERTMARK tbim; /* info on insertion mark */
174 TBUTTON_INFO *buttons; /* pointer to button array */
175 LPWSTR *strings; /* pointer to string array */
176 TBITMAP_INFO *bitmaps;
177 } TOOLBAR_INFO, *PTOOLBAR_INFO;
180 /* used by customization dialog */
181 typedef struct
183 PTOOLBAR_INFO tbInfo;
184 HWND tbHwnd;
185 } CUSTDLG_INFO, *PCUSTDLG_INFO;
187 typedef struct
189 TBBUTTON btn;
190 BOOL bVirtual;
191 BOOL bRemovable;
192 WCHAR text[64];
193 } CUSTOMBUTTON, *PCUSTOMBUTTON;
195 typedef enum
197 IMAGE_LIST_DEFAULT,
198 IMAGE_LIST_HOT,
199 IMAGE_LIST_DISABLED
200 } IMAGE_LIST_TYPE;
202 #define SEPARATOR_WIDTH 8
203 #define TOP_BORDER 2
204 #define BOTTOM_BORDER 2
205 #define DDARROW_WIDTH 11
206 #define ARROW_HEIGHT 3
207 #define INSERTMARK_WIDTH 2
209 #define DEFPAD_CX 7
210 #define DEFPAD_CY 6
211 #define DEFLISTGAP 4
213 /* vertical padding used in list mode when image is present */
214 #define LISTPAD_CY 9
216 /* how wide to treat the bitmap if it isn't present */
217 #define NONLIST_NOTEXT_OFFSET 2
219 #define TOOLBAR_NOWHERE (-1)
221 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
222 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
223 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
225 /* Used to find undocumented extended styles */
226 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
227 TBSTYLE_EX_UNDOC1 | \
228 TBSTYLE_EX_MIXEDBUTTONS | \
229 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
231 /* all of the CCS_ styles */
232 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
233 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
235 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
236 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
237 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
238 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
239 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
241 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
243 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
244 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
245 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
246 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
247 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
248 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
249 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
250 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
251 static void TOOLBAR_LayoutToolbar(HWND hwnd);
252 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
253 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
254 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button);
256 static LRESULT
257 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
259 inline static int default_top_margin(TOOLBAR_INFO *infoPtr)
261 return (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
264 static LPWSTR
265 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
267 LPWSTR lpText = NULL;
269 /* NOTE: iString == -1 is undocumented */
270 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
271 lpText = (LPWSTR)btnPtr->iString;
272 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
273 lpText = infoPtr->strings[btnPtr->iString];
275 return lpText;
278 static void
279 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
281 if (TRACE_ON(toolbar)){
282 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
283 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
284 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
285 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
286 if (internal)
287 TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n",
288 btn_num, bP->idCommand,
289 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
290 bP->rect.left, bP->rect.top,
291 bP->rect.right, bP->rect.bottom);
296 static void
297 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
299 if (TRACE_ON(toolbar)) {
300 INT i;
302 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
303 iP->hwndSelf, line,
304 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
305 iP->nNumStrings, iP->dwStyle);
306 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
307 iP->hwndSelf, line,
308 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
309 (iP->bDoRedraw) ? "TRUE" : "FALSE");
310 for(i=0; i<iP->nNumButtons; i++) {
311 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
317 /***********************************************************************
318 * TOOLBAR_CheckStyle
320 * This function validates that the styles set are implemented and
321 * issues FIXME's warning of possible problems. In a perfect world this
322 * function should be null.
324 static void
325 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
327 if (dwStyle & TBSTYLE_REGISTERDROP)
328 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
332 static INT
333 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
335 if(!IsWindow(infoPtr->hwndSelf))
336 return 0; /* we have just been destroyed */
338 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
339 nmhdr->hwndFrom = infoPtr->hwndSelf;
340 nmhdr->code = code;
342 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
343 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
345 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
346 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
349 /***********************************************************************
350 * TOOLBAR_GetBitmapIndex
352 * This function returns the bitmap index associated with a button.
353 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
354 * is issued to retrieve the index.
356 static INT
357 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
359 INT ret = btnPtr->iBitmap;
361 if (ret == I_IMAGECALLBACK)
363 /* issue TBN_GETDISPINFO */
364 NMTBDISPINFOA nmgd;
366 memset(&nmgd, 0, sizeof(nmgd));
367 nmgd.idCommand = btnPtr->idCommand;
368 nmgd.lParam = btnPtr->dwData;
369 nmgd.dwMask = TBNF_IMAGE;
370 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
371 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
372 if (nmgd.dwMask & TBNF_DI_SETITEM)
373 btnPtr->iBitmap = nmgd.iImage;
374 ret = nmgd.iImage;
375 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
376 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
379 if (ret != I_IMAGENONE)
380 ret = GETIBITMAP(infoPtr, ret);
382 return ret;
386 static BOOL
387 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
389 HIMAGELIST himl;
390 INT id = GETHIMLID(infoPtr, index);
391 INT iBitmap = GETIBITMAP(infoPtr, index);
393 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
394 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
395 (index == I_IMAGECALLBACK))
396 return TRUE;
397 else
398 return FALSE;
402 static inline BOOL
403 TOOLBAR_IsValidImageList(TOOLBAR_INFO *infoPtr, INT index)
405 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
406 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
410 /***********************************************************************
411 * TOOLBAR_GetImageListForDrawing
413 * This function validates the bitmap index (including I_IMAGECALLBACK
414 * functionality) and returns the corresponding image list.
416 static HIMAGELIST
417 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
419 HIMAGELIST himl;
421 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
422 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
423 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
424 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
425 return NULL;
428 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
429 if ((*index == I_IMAGECALLBACK) ||
430 (*index == I_IMAGENONE)) return NULL;
431 ERR("TBN_GETDISPINFO returned invalid index %d\n",
432 *index);
433 return NULL;
436 switch(imagelist)
438 case IMAGE_LIST_DEFAULT:
439 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
440 break;
441 case IMAGE_LIST_HOT:
442 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
443 break;
444 case IMAGE_LIST_DISABLED:
445 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
446 break;
447 default:
448 himl = NULL;
449 FIXME("Shouldn't reach here\n");
452 if (!himl)
453 TRACE("no image list\n");
455 return himl;
459 static void
460 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
462 RECT myrect;
463 COLORREF oldcolor, newcolor;
465 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
466 myrect.right = myrect.left + 1;
467 myrect.top = lpRect->top + 2;
468 myrect.bottom = lpRect->bottom - 2;
470 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
471 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
472 oldcolor = SetBkColor (hdc, newcolor);
473 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
475 myrect.left = myrect.right;
476 myrect.right = myrect.left + 1;
478 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
479 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
480 SetBkColor (hdc, newcolor);
481 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
483 SetBkColor (hdc, oldcolor);
487 /***********************************************************************
488 * TOOLBAR_DrawDDFlatSeparator
490 * This function draws the separator that was flagged as BTNS_DROPDOWN.
491 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
492 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
493 * are horizontal as opposed to the vertical separators for not dropdown
494 * type.
496 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
498 static void
499 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
501 RECT myrect;
502 COLORREF oldcolor, newcolor;
504 myrect.left = lpRect->left;
505 myrect.right = lpRect->right;
506 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
507 myrect.bottom = myrect.top + 1;
509 InflateRect (&myrect, -2, 0);
511 TRACE("rect=(%d,%d)-(%d,%d)\n",
512 myrect.left, myrect.top, myrect.right, myrect.bottom);
514 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
515 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
516 oldcolor = SetBkColor (hdc, newcolor);
517 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
519 myrect.top = myrect.bottom;
520 myrect.bottom = myrect.top + 1;
522 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
523 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
524 SetBkColor (hdc, newcolor);
525 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
527 SetBkColor (hdc, oldcolor);
531 static void
532 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
534 INT x, y;
535 HPEN hPen, hOldPen;
537 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
538 hOldPen = SelectObject ( hdc, hPen );
539 x = left + 2;
540 y = top;
541 MoveToEx (hdc, x, y, NULL);
542 LineTo (hdc, x+5, y++); x++;
543 MoveToEx (hdc, x, y, NULL);
544 LineTo (hdc, x+3, y++); x++;
545 MoveToEx (hdc, x, y, NULL);
546 LineTo (hdc, x+1, y++);
547 SelectObject( hdc, hOldPen );
548 DeleteObject( hPen );
552 * Draw the text string for this button.
553 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
554 * is non-zero, so we can simply check himlDef to see if we have
555 * an image list
557 static void
558 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
559 NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
561 HDC hdc = tbcd->nmcd.hdc;
562 HFONT hOldFont = 0;
563 COLORREF clrOld = 0;
564 COLORREF clrOldBk = 0;
565 int oldBkMode = 0;
566 UINT state = tbcd->nmcd.uItemState;
568 /* draw text */
569 if (lpText) {
570 TRACE("string=%s rect=(%d,%d)-(%d,%d)\n", debugstr_w(lpText),
571 rcText->left, rcText->top, rcText->right, rcText->bottom);
573 hOldFont = SelectObject (hdc, infoPtr->hFont);
574 if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
575 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
577 else if (state & CDIS_DISABLED) {
578 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
579 OffsetRect (rcText, 1, 1);
580 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
581 SetTextColor (hdc, comctl32_color.clr3dShadow);
582 OffsetRect (rcText, -1, -1);
584 else if (state & CDIS_INDETERMINATE) {
585 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
587 else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
588 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
589 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
590 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
592 else {
593 clrOld = SetTextColor (hdc, tbcd->clrText);
596 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
597 SetTextColor (hdc, clrOld);
598 if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
600 SetBkColor (hdc, clrOldBk);
601 SetBkMode (hdc, oldBkMode);
603 SelectObject (hdc, hOldFont);
608 static void
609 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
611 HDC hdc = tbcd->nmcd.hdc;
612 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
613 COLORREF clrTextOld;
614 COLORREF clrBkOld;
615 INT cx = lpRect->right - lpRect->left;
616 INT cy = lpRect->bottom - lpRect->top;
617 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
618 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
619 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
620 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
621 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
622 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
623 SetBkColor(hdc, clrBkOld);
624 SetTextColor(hdc, clrTextOld);
625 SelectObject (hdc, hbr);
629 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
631 INT cx, cy;
632 HBITMAP hbmMask, hbmImage;
633 HDC hdcMask, hdcImage;
635 ImageList_GetIconSize(himl, &cx, &cy);
637 /* Create src image */
638 hdcImage = CreateCompatibleDC(hdc);
639 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
640 SelectObject(hdcImage, hbmImage);
641 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
642 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
644 /* Create Mask */
645 hdcMask = CreateCompatibleDC(0);
646 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
647 SelectObject(hdcMask, hbmMask);
649 /* Remove the background and all white pixels */
650 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
651 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
652 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
653 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
655 /* draw the new mask 'etched' to hdc */
656 SetBkColor(hdc, RGB(255, 255, 255));
657 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
658 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
659 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
660 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
661 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
663 /* Cleanup */
664 DeleteObject(hbmImage);
665 DeleteDC(hdcImage);
666 DeleteObject (hbmMask);
667 DeleteDC(hdcMask);
671 static UINT
672 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
674 UINT retstate = 0;
676 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
677 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
678 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
679 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
680 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
681 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
682 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
683 return retstate;
686 /* draws the image on a toolbar button */
687 static void
688 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
689 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
691 HIMAGELIST himl = NULL;
692 BOOL draw_masked = FALSE;
693 INT index;
694 INT offset = 0;
695 UINT draw_flags = ILD_TRANSPARENT;
697 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
699 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
700 if (!himl)
702 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
703 draw_masked = TRUE;
706 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
707 ((tbcd->nmcd.uItemState & CDIS_HOT)
708 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
710 /* if hot, attempt to draw with hot image list, if fails,
711 use default image list */
712 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
713 if (!himl)
714 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
716 else
717 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
719 if (!himl)
720 return;
722 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
723 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
724 offset = 1;
726 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
727 (tbcd->nmcd.uItemState & CDIS_MARKED))
728 draw_flags |= ILD_BLEND50;
730 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
731 index, himl, left, top, offset);
733 if (draw_masked)
734 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
735 else
736 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
739 /* draws a blank frame for a toolbar button */
740 static void
741 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
743 HDC hdc = tbcd->nmcd.hdc;
744 RECT rc = tbcd->nmcd.rc;
745 /* if the state is disabled or indeterminate then the button
746 * cannot have an interactive look like pressed or hot */
747 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
748 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
749 BOOL pressed_look = !non_interactive_state &&
750 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
751 (tbcd->nmcd.uItemState & CDIS_CHECKED));
753 /* app don't want us to draw any edges */
754 if (dwItemCDFlag & TBCDRF_NOEDGES)
755 return;
757 if (infoPtr->dwStyle & TBSTYLE_FLAT)
759 if (pressed_look)
760 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
761 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
762 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
764 else
766 if (pressed_look)
767 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
768 else
769 DrawEdge (hdc, &rc, EDGE_RAISED,
770 BF_SOFT | BF_RECT | BF_MIDDLE);
774 static void
775 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
777 HDC hdc = tbcd->nmcd.hdc;
778 int offset = 0;
779 BOOL pressed = bDropDownPressed ||
780 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
782 if (infoPtr->dwStyle & TBSTYLE_FLAT)
784 if (pressed)
785 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
786 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
787 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
788 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
789 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
791 else
793 if (pressed)
794 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
795 else
796 DrawEdge (hdc, rcArrow, EDGE_RAISED,
797 BF_SOFT | BF_RECT | BF_MIDDLE);
800 if (pressed)
801 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
803 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
805 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
806 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
808 else
809 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
812 /* draws a complete toolbar button */
813 static void
814 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
816 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
817 DWORD dwStyle = infoPtr->dwStyle;
818 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
819 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
820 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
821 BOOL drawSepDropDownArrow = hasDropDownArrow &&
822 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
823 RECT rc, rcArrow, rcBitmap, rcText;
824 LPWSTR lpText = NULL;
825 NMTBCUSTOMDRAW tbcd;
826 DWORD ntfret;
827 INT offset;
828 INT oldBkMode;
829 DWORD dwItemCustDraw;
830 DWORD dwItemCDFlag;
831 HTHEME theme = GetWindowTheme (hwnd);
833 rc = btnPtr->rect;
834 CopyRect (&rcArrow, &rc);
836 /* separator - doesn't send NM_CUSTOMDRAW */
837 if (btnPtr->fsStyle & BTNS_SEP) {
838 if (theme)
840 DrawThemeBackground (theme, hdc,
841 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
842 &rc, NULL);
844 else
845 /* with the FLAT style, iBitmap is the width and has already */
846 /* been taken into consideration in calculating the width */
847 /* so now we need to draw the vertical separator */
848 /* empirical tests show that iBitmap can/will be non-zero */
849 /* when drawing the vertical bar... */
850 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
851 if (btnPtr->fsStyle & BTNS_DROPDOWN)
852 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
853 else
854 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
856 else if (btnPtr->fsStyle != BTNS_SEP) {
857 FIXME("Draw some kind of separator: fsStyle=%x\n",
858 btnPtr->fsStyle);
860 return;
863 /* get a pointer to the text */
864 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
866 if (hasDropDownArrow)
868 int right;
870 if (dwStyle & TBSTYLE_FLAT)
871 right = max(rc.left, rc.right - DDARROW_WIDTH);
872 else
873 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
875 if (drawSepDropDownArrow)
876 rc.right = right;
878 rcArrow.left = right;
881 /* copy text & bitmap rects after adjusting for drop-down arrow
882 * so that text & bitmap is centred in the rectangle not containing
883 * the arrow */
884 CopyRect(&rcText, &rc);
885 CopyRect(&rcBitmap, &rc);
887 /* Center the bitmap horizontally and vertically */
888 if (dwStyle & TBSTYLE_LIST)
890 if (lpText &&
891 infoPtr->nMaxTextRows > 0 &&
892 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
893 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
894 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
895 else
896 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
898 else
899 rcBitmap.left += ((rc.right - rc.left) - infoPtr->nBitmapWidth) / 2;
901 rcBitmap.top += infoPtr->szPadding.cy / 2;
903 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
904 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
905 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
906 TRACE("Text=%s\n", debugstr_w(lpText));
907 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
909 /* calculate text position */
910 if (lpText)
912 rcText.left += GetSystemMetrics(SM_CXEDGE);
913 rcText.right -= GetSystemMetrics(SM_CXEDGE);
914 if (dwStyle & TBSTYLE_LIST)
916 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
917 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
919 else
921 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
922 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
923 else
924 rcText.top += infoPtr->szPadding.cy/2 + 2;
928 /* Initialize fields in all cases, because we use these later
929 * NOTE: applications can and do alter these to customize their
930 * toolbars */
931 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
932 tbcd.clrText = comctl32_color.clrBtnText;
933 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
934 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
935 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
936 tbcd.clrMark = comctl32_color.clrHighlight;
937 tbcd.clrHighlightHotTrack = 0;
938 tbcd.nStringBkMode = TRANSPARENT;
939 tbcd.nHLStringBkMode = OPAQUE;
940 /* MSDN says that this is the text rectangle.
941 * But (why always a but) tracing of v5.7 of native shows
942 * that this is really a *relative* rectangle based on the
943 * the nmcd.rc. Also the left and top are always 0 ignoring
944 * any bitmap that might be present. */
945 tbcd.rcText.left = 0;
946 tbcd.rcText.top = 0;
947 tbcd.rcText.right = rcText.right - rc.left;
948 tbcd.rcText.bottom = rcText.bottom - rc.top;
949 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
950 tbcd.nmcd.hdc = hdc;
951 tbcd.nmcd.rc = rc;
952 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
954 /* FIXME: what are these used for? */
955 tbcd.hbrLines = 0;
956 tbcd.hpenLines = 0;
958 /* Issue Item Prepaint notify */
959 dwItemCustDraw = 0;
960 dwItemCDFlag = 0;
961 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
963 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
964 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
965 tbcd.nmcd.lItemlParam = btnPtr->dwData;
966 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
967 /* reset these fields so the user can't alter the behaviour like native */
968 tbcd.nmcd.hdc = hdc;
969 tbcd.nmcd.rc = rc;
971 dwItemCustDraw = ntfret & 0xffff;
972 dwItemCDFlag = ntfret & 0xffff0000;
973 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
974 return;
975 /* save the only part of the rect that the user can change */
976 rcText.right = tbcd.rcText.right + rc.left;
977 rcText.bottom = tbcd.rcText.bottom + rc.top;
980 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
981 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
982 OffsetRect(&rcText, 1, 1);
984 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
985 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
986 TOOLBAR_DrawPattern (&rc, &tbcd);
988 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
989 && (tbcd.nmcd.uItemState & CDIS_HOT))
991 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
993 COLORREF oldclr;
995 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
996 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
997 if (hasDropDownArrow)
998 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
999 SetBkColor(hdc, oldclr);
1003 if (theme)
1005 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1006 int stateId = TS_NORMAL;
1008 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1009 stateId = TS_DISABLED;
1010 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1011 stateId = TS_PRESSED;
1012 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1013 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1014 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1015 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1016 stateId = TS_HOT;
1018 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1020 else
1021 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1023 if (drawSepDropDownArrow)
1025 if (theme)
1027 int stateId = TS_NORMAL;
1029 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1030 stateId = TS_DISABLED;
1031 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1032 stateId = TS_PRESSED;
1033 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1034 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1035 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1036 stateId = TS_HOT;
1038 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1039 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1041 else
1042 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1045 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1046 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1047 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1048 SetBkMode (hdc, oldBkMode);
1050 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1052 if (hasDropDownArrow && !drawSepDropDownArrow)
1054 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1056 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1057 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1059 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1061 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1062 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1064 else
1065 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1068 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1070 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1071 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1077 static void
1078 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1080 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1081 TBUTTON_INFO *btnPtr;
1082 INT i;
1083 RECT rcTemp, rcClient;
1084 NMTBCUSTOMDRAW tbcd;
1085 DWORD ntfret;
1086 DWORD dwBaseCustDraw;
1088 /* the app has told us not to redraw the toolbar */
1089 if (!infoPtr->bDoRedraw)
1090 return;
1092 /* if imagelist belongs to the app, it can be changed
1093 by the app after setting it */
1094 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1096 infoPtr->nNumBitmaps = 0;
1097 for (i = 0; i < infoPtr->cimlDef; i++)
1098 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1101 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1103 /* change the imagelist icon size if we manage the list and it is necessary */
1104 TOOLBAR_CheckImageListIconSize(infoPtr);
1106 /* Send initial notify */
1107 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1108 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1109 tbcd.nmcd.hdc = hdc;
1110 tbcd.nmcd.rc = ps->rcPaint;
1111 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1112 dwBaseCustDraw = ntfret & 0xffff;
1114 GetClientRect(hwnd, &rcClient);
1116 /* redraw necessary buttons */
1117 btnPtr = infoPtr->buttons;
1118 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1120 BOOL bDraw;
1121 if (!RectVisible(hdc, &btnPtr->rect))
1122 continue;
1123 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1125 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1126 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1128 else
1129 bDraw = TRUE;
1130 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1131 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1132 if (bDraw)
1133 TOOLBAR_DrawButton(hwnd, btnPtr, hdc, dwBaseCustDraw);
1136 /* draw insert mark if required */
1137 if (infoPtr->tbim.iButton != -1)
1139 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1140 RECT rcInsertMark;
1141 rcInsertMark.top = rcButton.top;
1142 rcInsertMark.bottom = rcButton.bottom;
1143 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1144 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1145 else
1146 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1147 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1150 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1152 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1153 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1154 tbcd.nmcd.hdc = hdc;
1155 tbcd.nmcd.rc = ps->rcPaint;
1156 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1160 /***********************************************************************
1161 * TOOLBAR_MeasureString
1163 * This function gets the width and height of a string in pixels. This
1164 * is done first by using GetTextExtentPoint to get the basic width
1165 * and height. The DrawText is called with DT_CALCRECT to get the exact
1166 * width. The reason is because the text may have more than one "&" (or
1167 * prefix characters as M$ likes to call them). The prefix character
1168 * indicates where the underline goes, except for the string "&&" which
1169 * is reduced to a single "&". GetTextExtentPoint does not process these
1170 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1172 static void
1173 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1174 HDC hdc, LPSIZE lpSize)
1176 RECT myrect;
1178 lpSize->cx = 0;
1179 lpSize->cy = 0;
1181 if (infoPtr->nMaxTextRows > 0 &&
1182 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1183 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1184 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1186 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1188 if(lpText != NULL) {
1189 /* first get size of all the text */
1190 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1192 /* feed above size into the rectangle for DrawText */
1193 myrect.left = myrect.top = 0;
1194 myrect.right = lpSize->cx;
1195 myrect.bottom = lpSize->cy;
1197 /* Use DrawText to get true size as drawn (less pesky "&") */
1198 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1199 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1200 DT_NOPREFIX : 0));
1202 /* feed back to caller */
1203 lpSize->cx = myrect.right;
1204 lpSize->cy = myrect.bottom;
1208 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1211 /***********************************************************************
1212 * TOOLBAR_CalcStrings
1214 * This function walks through each string and measures it and returns
1215 * the largest height and width to caller.
1217 static void
1218 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1220 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1221 TBUTTON_INFO *btnPtr;
1222 INT i;
1223 SIZE sz;
1224 HDC hdc;
1225 HFONT hOldFont;
1227 lpSize->cx = 0;
1228 lpSize->cy = 0;
1230 if (infoPtr->nMaxTextRows == 0)
1231 return;
1233 hdc = GetDC (hwnd);
1234 hOldFont = SelectObject (hdc, infoPtr->hFont);
1236 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1238 TEXTMETRICW tm;
1240 GetTextMetricsW(hdc, &tm);
1241 lpSize->cy = tm.tmHeight;
1244 btnPtr = infoPtr->buttons;
1245 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1246 if(TOOLBAR_HasText(infoPtr, btnPtr))
1248 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1249 if (sz.cx > lpSize->cx)
1250 lpSize->cx = sz.cx;
1251 if (sz.cy > lpSize->cy)
1252 lpSize->cy = sz.cy;
1256 SelectObject (hdc, hOldFont);
1257 ReleaseDC (hwnd, hdc);
1259 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1262 /***********************************************************************
1263 * TOOLBAR_WrapToolbar
1265 * This function walks through the buttons and separators in the
1266 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1267 * wrapping should occur based on the width of the toolbar window.
1268 * It does *not* calculate button placement itself. That task
1269 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1270 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1271 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1273 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1274 * vertical toolbar lists.
1277 static void
1278 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1280 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1281 TBUTTON_INFO *btnPtr;
1282 INT x, cx, i, j;
1283 RECT rc;
1284 BOOL bWrap, bButtonWrap;
1286 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1287 /* no layout is necessary. Applications may use this style */
1288 /* to perform their own layout on the toolbar. */
1289 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1290 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1292 btnPtr = infoPtr->buttons;
1293 x = infoPtr->nIndent;
1295 if (GetParent(hwnd))
1297 /* this can get the parents width, to know how far we can extend
1298 * this toolbar. We cannot use its height, as there may be multiple
1299 * toolbars in a rebar control
1301 GetClientRect( GetParent(hwnd), &rc );
1302 infoPtr->nWidth = rc.right - rc.left;
1304 else
1306 GetWindowRect( hwnd, &rc );
1307 infoPtr->nWidth = rc.right - rc.left;
1310 bButtonWrap = FALSE;
1312 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1313 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1314 infoPtr->nIndent);
1316 for (i = 0; i < infoPtr->nNumButtons; i++ )
1318 bWrap = FALSE;
1319 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1321 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1322 continue;
1324 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1325 /* it is the actual width of the separator. This is used for */
1326 /* custom controls in toolbars. */
1327 /* */
1328 /* BTNS_DROPDOWN separators are treated as buttons for */
1329 /* width. - GA 8/01 */
1330 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1331 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1332 cx = (btnPtr[i].iBitmap > 0) ?
1333 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1334 else
1335 cx = infoPtr->nButtonWidth;
1337 /* Two or more adjacent separators form a separator group. */
1338 /* The first separator in a group should be wrapped to the */
1339 /* next row if the previous wrapping is on a button. */
1340 if( bButtonWrap &&
1341 (btnPtr[i].fsStyle & BTNS_SEP) &&
1342 (i + 1 < infoPtr->nNumButtons ) &&
1343 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1345 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1346 btnPtr[i].fsState |= TBSTATE_WRAP;
1347 x = infoPtr->nIndent;
1348 i++;
1349 bButtonWrap = FALSE;
1350 continue;
1353 /* The layout makes sure the bitmap is visible, but not the button. */
1354 /* Test added to also wrap after a button that starts a row but */
1355 /* is bigger than the area. - GA 8/01 */
1356 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1357 > infoPtr->nWidth ) ||
1358 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1360 BOOL bFound = FALSE;
1362 /* If the current button is a separator and not hidden, */
1363 /* go to the next until it reaches a non separator. */
1364 /* Wrap the last separator if it is before a button. */
1365 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1366 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1367 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1368 i < infoPtr->nNumButtons )
1370 i++;
1371 bFound = TRUE;
1374 if( bFound && i < infoPtr->nNumButtons )
1376 i--;
1377 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1378 i, btnPtr[i].fsStyle, x, cx);
1379 btnPtr[i].fsState |= TBSTATE_WRAP;
1380 x = infoPtr->nIndent;
1381 bButtonWrap = FALSE;
1382 continue;
1384 else if ( i >= infoPtr->nNumButtons)
1385 break;
1387 /* If the current button is not a separator, find the last */
1388 /* separator and wrap it. */
1389 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1391 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1392 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1394 bFound = TRUE;
1395 i = j;
1396 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1397 i, btnPtr[i].fsStyle, x, cx);
1398 x = infoPtr->nIndent;
1399 btnPtr[j].fsState |= TBSTATE_WRAP;
1400 bButtonWrap = FALSE;
1401 break;
1405 /* If no separator available for wrapping, wrap one of */
1406 /* non-hidden previous button. */
1407 if (!bFound)
1409 for ( j = i - 1;
1410 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1412 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1413 continue;
1415 bFound = TRUE;
1416 i = j;
1417 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1418 i, btnPtr[i].fsStyle, x, cx);
1419 x = infoPtr->nIndent;
1420 btnPtr[j].fsState |= TBSTATE_WRAP;
1421 bButtonWrap = TRUE;
1422 break;
1426 /* If all above failed, wrap the current button. */
1427 if (!bFound)
1429 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1430 i, btnPtr[i].fsStyle, x, cx);
1431 btnPtr[i].fsState |= TBSTATE_WRAP;
1432 bFound = TRUE;
1433 x = infoPtr->nIndent;
1434 if (btnPtr[i].fsStyle & BTNS_SEP )
1435 bButtonWrap = FALSE;
1436 else
1437 bButtonWrap = TRUE;
1440 else {
1441 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1442 i, btnPtr[i].fsStyle, x, cx);
1443 x += cx;
1449 /***********************************************************************
1450 * TOOLBAR_MeasureButton
1452 * Calculates the width and height required for a button. Used in
1453 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1454 * the width of buttons that are autosized.
1456 * Note that it would have been rather elegant to use one piece of code for
1457 * both the laying out of the toolbar and for controlling where button parts
1458 * are drawn, but the native control has inconsistencies between the two that
1459 * prevent this from being effectively. These inconsistencies can be seen as
1460 * artefacts where parts of the button appear outside of the bounding button
1461 * rectangle.
1463 * There are several cases for the calculation of the button dimensions and
1464 * button part positioning:
1466 * List
1467 * ====
1469 * With Bitmap:
1471 * +--------------------------------------------------------+ ^
1472 * | ^ ^ | |
1473 * | | pad.cy / 2 | centred | |
1474 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1475 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1476 * | |<------------>| | | | |
1477 * | +--------------+ +------------+ | |
1478 * |<-------------------------------------->| | |
1479 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1480 * | szText.cx | |
1481 * +--------------------------------------------------------+ -
1482 * <-------------------------------------------------------->
1483 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1485 * Without Bitmap (I_IMAGENONE):
1487 * +-----------------------------------+ ^
1488 * | ^ | |
1489 * | | centred | | LISTPAD_CY +
1490 * | +------------+ | | szText.cy
1491 * | | Text | | |
1492 * | | | | |
1493 * | +------------+ | |
1494 * |<----------------->| | |
1495 * | cxedge |<-----------> | |
1496 * | szText.cx | |
1497 * +-----------------------------------+ -
1498 * <----------------------------------->
1499 * szText.cx + pad.cx
1501 * Without text:
1503 * +--------------------------------------+ ^
1504 * | ^ | |
1505 * | | padding.cy/2 | | DEFPAD_CY +
1506 * | +------------+ | | nBitmapHeight
1507 * | | Bitmap | | |
1508 * | | | | |
1509 * | +------------+ | |
1510 * |<------------------->| | |
1511 * | cxedge + iListGap/2 |<-----------> | |
1512 * | nBitmapWidth | |
1513 * +--------------------------------------+ -
1514 * <-------------------------------------->
1515 * 2*cxedge + nBitmapWidth + iListGap
1517 * Non-List
1518 * ========
1520 * With bitmap:
1522 * +-----------------------------------+ ^
1523 * | ^ | |
1524 * | | pad.cy / 2 | | nBitmapHeight +
1525 * | - | | szText.cy +
1526 * | +------------+ | | DEFPAD_CY + 1
1527 * | centred | Bitmap | | |
1528 * |<----------------->| | | |
1529 * | +------------+ | |
1530 * | ^ | |
1531 * | 1 | | |
1532 * | - | |
1533 * | centred +---------------+ | |
1534 * |<--------------->| Text | | |
1535 * | +---------------+ | |
1536 * +-----------------------------------+ -
1537 * <----------------------------------->
1538 * pad.cx + max(nBitmapWidth, szText.cx)
1540 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1542 * +---------------------------------------+ ^
1543 * | ^ | |
1544 * | | 2 + pad.cy / 2 | |
1545 * | - | | szText.cy +
1546 * | centred +-----------------+ | | pad.cy + 2
1547 * |<--------------->| Text | | |
1548 * | +-----------------+ | |
1549 * | | |
1550 * +---------------------------------------+ -
1551 * <--------------------------------------->
1552 * 2*cxedge + pad.cx + szText.cx
1554 * Without text:
1555 * As for with bitmaps, but with szText.cx zero.
1557 static inline SIZE TOOLBAR_MeasureButton(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1559 SIZE sizeButton;
1560 if (infoPtr->dwStyle & TBSTYLE_LIST)
1562 /* set button height from bitmap / text height... */
1563 sizeButton.cy = max((bHasBitmap ? infoPtr->nVBitmapHeight : 0),
1564 sizeString.cy);
1566 /* ... add on the necessary padding */
1567 if (bValidImageList)
1569 if (bHasBitmap)
1570 sizeButton.cy += DEFPAD_CY;
1571 else
1572 sizeButton.cy += LISTPAD_CY;
1574 else
1575 sizeButton.cy += infoPtr->szPadding.cy;
1577 /* calculate button width */
1578 if (bHasBitmap)
1580 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1581 infoPtr->nBitmapWidth + infoPtr->iListGap;
1582 if (sizeString.cx > 0)
1583 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1585 else
1586 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1588 else
1590 if (bHasBitmap)
1592 sizeButton.cy = infoPtr->nVBitmapHeight + DEFPAD_CY;
1593 if (sizeString.cy > 0)
1594 sizeButton.cy += 1 + sizeString.cy;
1595 sizeButton.cx = infoPtr->szPadding.cx +
1596 max(sizeString.cx, infoPtr->nBitmapWidth);
1598 else
1600 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1601 NONLIST_NOTEXT_OFFSET;
1602 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1603 infoPtr->szPadding.cx + sizeString.cx;
1606 return sizeButton;
1610 /***********************************************************************
1611 * TOOLBAR_CalcToolbar
1613 * This function calculates button and separator placement. It first
1614 * calculates the button sizes, gets the toolbar window width and then
1615 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1616 * on. It assigns a new location to each item and sends this location to
1617 * the tooltip window if appropriate. Finally, it updates the rcBound
1618 * rect and calculates the new required toolbar window height.
1620 static void
1621 TOOLBAR_CalcToolbar (HWND hwnd)
1623 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1624 SIZE sizeString, sizeButton;
1625 BOOL validImageList = FALSE;
1627 TOOLBAR_CalcStrings (hwnd, &sizeString);
1629 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1631 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1632 validImageList = TRUE;
1633 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1634 infoPtr->nButtonWidth = sizeButton.cx;
1635 infoPtr->nButtonHeight = sizeButton.cy;
1636 infoPtr->iTopMargin = default_top_margin(infoPtr);
1638 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1639 infoPtr->nButtonWidth = infoPtr->cxMin;
1640 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1641 infoPtr->nButtonWidth = infoPtr->cxMax;
1643 TOOLBAR_LayoutToolbar(hwnd);
1646 static void
1647 TOOLBAR_LayoutToolbar(HWND hwnd)
1649 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1650 TBUTTON_INFO *btnPtr;
1651 SIZE sizeButton;
1652 INT i, nRows, nSepRows;
1653 INT x, y, cx, cy;
1654 BOOL bWrap;
1655 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1656 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1658 TOOLBAR_WrapToolbar(hwnd, infoPtr->dwStyle);
1660 x = infoPtr->nIndent;
1661 y = infoPtr->iTopMargin;
1662 cx = infoPtr->nButtonWidth;
1663 cy = infoPtr->nButtonHeight;
1665 nRows = nSepRows = 0;
1667 infoPtr->rcBound.top = y;
1668 infoPtr->rcBound.left = x;
1669 infoPtr->rcBound.bottom = y + cy;
1670 infoPtr->rcBound.right = x;
1672 btnPtr = infoPtr->buttons;
1674 TRACE("cy=%d\n", cy);
1676 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1678 bWrap = FALSE;
1679 if (btnPtr->fsState & TBSTATE_HIDDEN)
1681 SetRectEmpty (&btnPtr->rect);
1682 continue;
1685 cy = infoPtr->nButtonHeight;
1687 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1688 /* it is the actual width of the separator. This is used for */
1689 /* custom controls in toolbars. */
1690 if (btnPtr->fsStyle & BTNS_SEP) {
1691 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1692 cy = (btnPtr->iBitmap > 0) ?
1693 btnPtr->iBitmap : SEPARATOR_WIDTH;
1694 cx = infoPtr->nButtonWidth;
1696 else
1697 cx = (btnPtr->iBitmap > 0) ?
1698 btnPtr->iBitmap : SEPARATOR_WIDTH;
1700 else
1702 if (btnPtr->cx)
1703 cx = btnPtr->cx;
1704 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1705 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1707 SIZE sz;
1708 HDC hdc;
1709 HFONT hOldFont;
1711 hdc = GetDC (hwnd);
1712 hOldFont = SelectObject (hdc, infoPtr->hFont);
1714 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1716 SelectObject (hdc, hOldFont);
1717 ReleaseDC (hwnd, hdc);
1719 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1720 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1721 validImageList);
1722 cx = sizeButton.cx;
1724 else
1725 cx = infoPtr->nButtonWidth;
1727 /* if size has been set manually then don't add on extra space
1728 * for the drop down arrow */
1729 if (!btnPtr->cx && hasDropDownArrows &&
1730 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1731 cx += DDARROW_WIDTH;
1733 if (btnPtr->fsState & TBSTATE_WRAP )
1734 bWrap = TRUE;
1736 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1738 if (infoPtr->rcBound.left > x)
1739 infoPtr->rcBound.left = x;
1740 if (infoPtr->rcBound.right < x + cx)
1741 infoPtr->rcBound.right = x + cx;
1742 if (infoPtr->rcBound.bottom < y + cy)
1743 infoPtr->rcBound.bottom = y + cy;
1745 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1747 /* btnPtr->nRow is zero based. The space between the rows is */
1748 /* also considered as a row. */
1749 btnPtr->nRow = nRows + nSepRows;
1751 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1752 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1753 x, y, x+cx, y+cy);
1755 if( bWrap )
1757 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1758 y += cy;
1759 else
1761 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1762 /* it is the actual width of the separator. This is used for */
1763 /* custom controls in toolbars. */
1764 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1765 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1766 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1767 else
1768 y += cy;
1770 /* nSepRows is used to calculate the extra height follwoing */
1771 /* the last row. */
1772 nSepRows++;
1774 x = infoPtr->nIndent;
1776 /* Increment row number unless this is the last button */
1777 /* and it has Wrap set. */
1778 if (i != infoPtr->nNumButtons-1)
1779 nRows++;
1781 else
1782 x += cx;
1785 /* infoPtr->nRows is the number of rows on the toolbar */
1786 infoPtr->nRows = nRows + nSepRows + 1;
1788 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1792 static INT
1793 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1795 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1796 TBUTTON_INFO *btnPtr;
1797 INT i;
1799 btnPtr = infoPtr->buttons;
1800 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1801 if (btnPtr->fsState & TBSTATE_HIDDEN)
1802 continue;
1804 if (btnPtr->fsStyle & BTNS_SEP) {
1805 if (PtInRect (&btnPtr->rect, *lpPt)) {
1806 TRACE(" ON SEPARATOR %d!\n", i);
1807 return -i;
1810 else {
1811 if (PtInRect (&btnPtr->rect, *lpPt)) {
1812 TRACE(" ON BUTTON %d!\n", i);
1813 return i;
1818 TRACE(" NOWHERE!\n");
1819 return TOOLBAR_NOWHERE;
1823 static INT
1824 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1826 TBUTTON_INFO *btnPtr;
1827 INT i;
1829 if (CommandIsIndex) {
1830 TRACE("command is really index command=%d\n", idCommand);
1831 if (idCommand >= infoPtr->nNumButtons) return -1;
1832 return idCommand;
1834 btnPtr = infoPtr->buttons;
1835 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1836 if (btnPtr->idCommand == idCommand) {
1837 TRACE("command=%d index=%d\n", idCommand, i);
1838 return i;
1841 TRACE("no index found for command=%d\n", idCommand);
1842 return -1;
1846 static INT
1847 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1849 TBUTTON_INFO *btnPtr;
1850 INT nRunIndex;
1852 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1853 return -1;
1855 /* check index button */
1856 btnPtr = &infoPtr->buttons[nIndex];
1857 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1858 if (btnPtr->fsState & TBSTATE_CHECKED)
1859 return nIndex;
1862 /* check previous buttons */
1863 nRunIndex = nIndex - 1;
1864 while (nRunIndex >= 0) {
1865 btnPtr = &infoPtr->buttons[nRunIndex];
1866 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1867 if (btnPtr->fsState & TBSTATE_CHECKED)
1868 return nRunIndex;
1870 else
1871 break;
1872 nRunIndex--;
1875 /* check next buttons */
1876 nRunIndex = nIndex + 1;
1877 while (nRunIndex < infoPtr->nNumButtons) {
1878 btnPtr = &infoPtr->buttons[nRunIndex];
1879 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1880 if (btnPtr->fsState & TBSTATE_CHECKED)
1881 return nRunIndex;
1883 else
1884 break;
1885 nRunIndex++;
1888 return -1;
1892 static VOID
1893 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1894 WPARAM wParam, LPARAM lParam)
1896 MSG msg;
1898 msg.hwnd = hwndMsg;
1899 msg.message = uMsg;
1900 msg.wParam = wParam;
1901 msg.lParam = lParam;
1902 msg.time = GetMessageTime ();
1903 msg.pt.x = (short)LOWORD(GetMessagePos ());
1904 msg.pt.y = (short)HIWORD(GetMessagePos ());
1906 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1909 static void
1910 TOOLBAR_TooltipAddTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1912 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1913 TTTOOLINFOW ti;
1915 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1916 ti.cbSize = sizeof (TTTOOLINFOW);
1917 ti.hwnd = infoPtr->hwndSelf;
1918 ti.uId = button->idCommand;
1919 ti.hinst = 0;
1920 ti.lpszText = LPSTR_TEXTCALLBACKW;
1921 /* ti.lParam = random value from the stack? */
1923 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1924 0, (LPARAM)&ti);
1928 static void
1929 TOOLBAR_TooltipDelTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1931 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1932 TTTOOLINFOW ti;
1934 ZeroMemory(&ti, sizeof(ti));
1935 ti.cbSize = sizeof(ti);
1936 ti.hwnd = infoPtr->hwndSelf;
1937 ti.uId = button->idCommand;
1939 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1943 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1945 /* Set the toolTip only for non-hidden, non-separator button */
1946 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1948 TTTOOLINFOW ti;
1950 ZeroMemory(&ti, sizeof(ti));
1951 ti.cbSize = sizeof(ti);
1952 ti.hwnd = infoPtr->hwndSelf;
1953 ti.uId = button->idCommand;
1954 ti.rect = button->rect;
1955 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1959 /* Creates the tooltip control */
1960 static void
1961 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
1963 int i;
1964 NMTOOLTIPSCREATED nmttc;
1966 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1967 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1968 infoPtr->hwndSelf, 0, 0, 0);
1970 if (!infoPtr->hwndToolTip)
1971 return;
1973 /* Send NM_TOOLTIPSCREATED notification */
1974 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1975 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
1977 for (i = 0; i < infoPtr->nNumButtons; i++)
1979 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
1980 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
1984 /* keeps available button list box sorted by button id */
1985 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1987 int i;
1988 int count;
1989 PCUSTOMBUTTON btnInfo;
1990 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1992 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1994 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1996 /* position 0 is always separator */
1997 for (i = 1; i < count; i++)
1999 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
2000 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2002 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2003 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2004 return;
2007 /* id higher than all others add to end */
2008 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2009 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2012 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2014 NMTOOLBARW nmtb;
2016 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2018 if (nIndexFrom == nIndexTo)
2019 return;
2021 /* MSDN states that iItem is the index of the button, rather than the
2022 * command ID as used by every other NMTOOLBAR notification */
2023 nmtb.iItem = nIndexFrom;
2024 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2026 PCUSTOMBUTTON btnInfo;
2027 NMHDR hdr;
2028 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2029 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2031 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2033 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2034 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2035 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2036 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2038 if (nIndexTo <= 0)
2039 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2040 else
2041 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2043 /* last item is always separator, so -2 instead of -1 */
2044 if (nIndexTo >= (count - 2))
2045 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2046 else
2047 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2049 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2050 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2052 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2056 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2058 NMTOOLBARW nmtb;
2060 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2062 /* MSDN states that iItem is the index of the button, rather than the
2063 * command ID as used by every other NMTOOLBAR notification */
2064 nmtb.iItem = nIndexAvail;
2065 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2067 PCUSTOMBUTTON btnInfo;
2068 NMHDR hdr;
2069 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2070 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2071 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2073 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2075 if (nIndexAvail != 0) /* index == 0 indicates separator */
2077 /* remove from 'available buttons' list */
2078 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2079 if (nIndexAvail == count-1)
2080 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2081 else
2082 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2084 else
2086 PCUSTOMBUTTON btnNew;
2088 /* duplicate 'separator' button */
2089 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2090 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2091 btnInfo = btnNew;
2094 /* insert into 'toolbar button' list */
2095 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2096 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2098 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2100 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2104 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
2106 PCUSTOMBUTTON btnInfo;
2107 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2109 TRACE("Remove: index %d\n", index);
2111 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2113 /* send TBN_QUERYDELETE notification */
2114 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2116 NMHDR hdr;
2118 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2119 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2121 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2123 /* insert into 'available button' list */
2124 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2125 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2126 else
2127 Free(btnInfo);
2129 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2133 /* drag list notification function for toolbar buttons list box */
2134 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2136 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2137 switch (pDLI->uNotification)
2139 case DL_BEGINDRAG:
2141 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2142 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2143 /* no dragging for last item (separator) */
2144 if (nCurrentItem >= (nCount - 1)) return FALSE;
2145 return TRUE;
2147 case DL_DRAGGING:
2149 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2150 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2151 /* no dragging past last item (separator) */
2152 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2154 DrawInsert(hwnd, hwndList, nCurrentItem);
2155 /* FIXME: native uses "move button" cursor */
2156 return DL_COPYCURSOR;
2159 /* not over toolbar buttons list */
2160 if (nCurrentItem < 0)
2162 POINT ptWindow = pDLI->ptCursor;
2163 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2164 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2165 /* over available buttons list? */
2166 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2167 /* FIXME: native uses "move button" cursor */
2168 return DL_COPYCURSOR;
2170 /* clear drag arrow */
2171 DrawInsert(hwnd, hwndList, -1);
2172 return DL_STOPCURSOR;
2174 case DL_DROPPED:
2176 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2177 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2178 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2179 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2181 /* clear drag arrow */
2182 DrawInsert(hwnd, hwndList, -1);
2183 /* move item */
2184 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2186 /* not over toolbar buttons list */
2187 if (nIndexTo < 0)
2189 POINT ptWindow = pDLI->ptCursor;
2190 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2191 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2192 /* over available buttons list? */
2193 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2194 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2196 break;
2198 case DL_CANCELDRAG:
2199 /* Clear drag arrow */
2200 DrawInsert(hwnd, hwndList, -1);
2201 break;
2204 return 0;
2207 /* drag list notification function for available buttons list box */
2208 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2210 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2211 switch (pDLI->uNotification)
2213 case DL_BEGINDRAG:
2214 return TRUE;
2215 case DL_DRAGGING:
2217 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2218 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2219 /* no dragging past last item (separator) */
2220 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2222 DrawInsert(hwnd, hwndList, nCurrentItem);
2223 /* FIXME: native uses "move button" cursor */
2224 return DL_COPYCURSOR;
2227 /* not over toolbar buttons list */
2228 if (nCurrentItem < 0)
2230 POINT ptWindow = pDLI->ptCursor;
2231 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2232 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2233 /* over available buttons list? */
2234 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2235 /* FIXME: native uses "move button" cursor */
2236 return DL_COPYCURSOR;
2238 /* clear drag arrow */
2239 DrawInsert(hwnd, hwndList, -1);
2240 return DL_STOPCURSOR;
2242 case DL_DROPPED:
2244 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2245 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2246 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2247 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2249 /* clear drag arrow */
2250 DrawInsert(hwnd, hwndList, -1);
2251 /* add item */
2252 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2255 case DL_CANCELDRAG:
2256 /* Clear drag arrow */
2257 DrawInsert(hwnd, hwndList, -1);
2258 break;
2260 return 0;
2263 extern UINT uDragListMessage;
2265 /***********************************************************************
2266 * TOOLBAR_CustomizeDialogProc
2267 * This function implements the toolbar customization dialog.
2269 static INT_PTR CALLBACK
2270 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2272 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2273 PCUSTOMBUTTON btnInfo;
2274 NMTOOLBARA nmtb;
2275 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2277 switch (uMsg)
2279 case WM_INITDIALOG:
2280 custInfo = (PCUSTDLG_INFO)lParam;
2281 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2283 if (custInfo)
2285 WCHAR Buffer[256];
2286 int i = 0;
2287 int index;
2288 NMTBINITCUSTOMIZE nmtbic;
2290 infoPtr = custInfo->tbInfo;
2292 /* send TBN_QUERYINSERT notification */
2293 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2295 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2296 return FALSE;
2298 nmtbic.hwndDialog = hwnd;
2299 /* Send TBN_INITCUSTOMIZE notification */
2300 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2301 TBNRF_HIDEHELP)
2303 TRACE("TBNRF_HIDEHELP requested\n");
2304 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2307 /* add items to 'toolbar buttons' list and check if removable */
2308 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2310 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2311 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2312 btnInfo->btn.fsStyle = BTNS_SEP;
2313 btnInfo->bVirtual = FALSE;
2314 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2316 /* send TBN_QUERYDELETE notification */
2317 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2319 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2320 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2323 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2325 /* insert separator button into 'available buttons' list */
2326 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2327 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2328 btnInfo->btn.fsStyle = BTNS_SEP;
2329 btnInfo->bVirtual = FALSE;
2330 btnInfo->bRemovable = TRUE;
2331 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2332 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2333 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2335 /* insert all buttons into dsa */
2336 for (i = 0;; i++)
2338 /* send TBN_GETBUTTONINFO notification */
2339 NMTOOLBARW nmtb;
2340 nmtb.iItem = i;
2341 nmtb.pszText = Buffer;
2342 nmtb.cchText = 256;
2344 /* Clear previous button's text */
2345 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2347 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2348 break;
2350 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2351 nmtb.tbButton.fsStyle, i,
2352 nmtb.tbButton.idCommand,
2353 nmtb.tbButton.iString,
2354 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2355 : "");
2357 /* insert button into the apropriate list */
2358 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2359 if (index == -1)
2361 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2362 btnInfo->bVirtual = FALSE;
2363 btnInfo->bRemovable = TRUE;
2365 else
2367 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2368 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2371 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2372 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2374 if (lstrlenW(nmtb.pszText))
2375 lstrcpyW(btnInfo->text, nmtb.pszText);
2376 else if (nmtb.tbButton.iString >= 0 &&
2377 nmtb.tbButton.iString < infoPtr->nNumStrings)
2379 lstrcpyW(btnInfo->text,
2380 infoPtr->strings[nmtb.tbButton.iString]);
2384 if (index == -1)
2385 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2388 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2390 /* select first item in the 'available' list */
2391 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2393 /* append 'virtual' separator button to the 'toolbar buttons' list */
2394 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2395 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2396 btnInfo->btn.fsStyle = BTNS_SEP;
2397 btnInfo->bVirtual = TRUE;
2398 btnInfo->bRemovable = FALSE;
2399 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2400 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2401 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2403 /* select last item in the 'toolbar' list */
2404 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2405 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2407 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2408 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2410 /* set focus and disable buttons */
2411 PostMessageW (hwnd, WM_USER, 0, 0);
2413 return TRUE;
2415 case WM_USER:
2416 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2417 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2418 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2419 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2420 return TRUE;
2422 case WM_CLOSE:
2423 EndDialog(hwnd, FALSE);
2424 return TRUE;
2426 case WM_COMMAND:
2427 switch (LOWORD(wParam))
2429 case IDC_TOOLBARBTN_LBOX:
2430 if (HIWORD(wParam) == LBN_SELCHANGE)
2432 PCUSTOMBUTTON btnInfo;
2433 NMTOOLBARA nmtb;
2434 int count;
2435 int index;
2437 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2438 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2440 /* send TBN_QUERYINSERT notification */
2441 nmtb.iItem = index;
2442 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2444 /* get list box item */
2445 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2447 if (index == (count - 1))
2449 /* last item (virtual separator) */
2450 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2451 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2453 else if (index == (count - 2))
2455 /* second last item (last non-virtual item) */
2456 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2457 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2459 else if (index == 0)
2461 /* first item */
2462 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2463 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2465 else
2467 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2468 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2471 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2473 break;
2475 case IDC_MOVEUP_BTN:
2477 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2478 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2480 break;
2482 case IDC_MOVEDN_BTN: /* move down */
2484 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2485 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2487 break;
2489 case IDC_REMOVE_BTN: /* remove button */
2491 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2493 if (LB_ERR == index)
2494 break;
2496 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2498 break;
2499 case IDC_HELP_BTN:
2500 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2501 break;
2502 case IDC_RESET_BTN:
2503 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2504 break;
2506 case IDOK: /* Add button */
2508 int index;
2509 int indexto;
2511 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2512 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2514 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2516 break;
2518 case IDCANCEL:
2519 EndDialog(hwnd, FALSE);
2520 break;
2522 return TRUE;
2524 case WM_DESTROY:
2526 int count;
2527 int i;
2529 /* delete items from 'toolbar buttons' listbox*/
2530 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2531 for (i = 0; i < count; i++)
2533 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2534 Free(btnInfo);
2535 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2537 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2540 /* delete items from 'available buttons' listbox*/
2541 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2542 for (i = 0; i < count; i++)
2544 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2545 Free(btnInfo);
2546 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2548 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2550 return TRUE;
2552 case WM_DRAWITEM:
2553 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2555 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2556 RECT rcButton;
2557 RECT rcText;
2558 HPEN hPen, hOldPen;
2559 HBRUSH hOldBrush;
2560 COLORREF oldText = 0;
2561 COLORREF oldBk = 0;
2563 /* get item data */
2564 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2565 if (btnInfo == NULL)
2567 FIXME("btnInfo invalid!\n");
2568 return TRUE;
2571 /* set colors and select objects */
2572 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2573 if (btnInfo->bVirtual)
2574 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2575 else
2576 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2577 hPen = CreatePen( PS_SOLID, 1,
2578 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2579 hOldPen = SelectObject (lpdis->hDC, hPen );
2580 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2582 /* fill background rectangle */
2583 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2584 lpdis->rcItem.right, lpdis->rcItem.bottom);
2586 /* calculate button and text rectangles */
2587 CopyRect (&rcButton, &lpdis->rcItem);
2588 InflateRect (&rcButton, -1, -1);
2589 CopyRect (&rcText, &rcButton);
2590 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2591 rcText.left = rcButton.right + 2;
2593 /* draw focus rectangle */
2594 if (lpdis->itemState & ODS_FOCUS)
2595 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2597 /* draw button */
2598 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2599 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2601 /* draw image and text */
2602 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2603 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2604 btnInfo->btn.iBitmap));
2605 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2606 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2608 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2609 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2611 /* delete objects and reset colors */
2612 SelectObject (lpdis->hDC, hOldBrush);
2613 SelectObject (lpdis->hDC, hOldPen);
2614 SetBkColor (lpdis->hDC, oldBk);
2615 SetTextColor (lpdis->hDC, oldText);
2616 DeleteObject( hPen );
2617 return TRUE;
2619 return FALSE;
2621 case WM_MEASUREITEM:
2622 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2624 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2626 lpmis->itemHeight = 15 + 8; /* default height */
2628 return TRUE;
2630 return FALSE;
2632 default:
2633 if (uDragListMessage && (uMsg == uDragListMessage))
2635 if (wParam == IDC_TOOLBARBTN_LBOX)
2637 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2638 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2639 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2640 return TRUE;
2642 else if (wParam == IDC_AVAILBTN_LBOX)
2644 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2645 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2646 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2647 return TRUE;
2650 return FALSE;
2654 static BOOL
2655 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2657 HBITMAP hbmLoad;
2658 INT nCountBefore = ImageList_GetImageCount(himlDef);
2659 INT nCountAfter;
2660 INT cxIcon, cyIcon;
2661 INT nAdded;
2662 INT nIndex;
2664 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2665 /* Add bitmaps to the default image list */
2666 if (bitmap->hInst == NULL) /* a handle was passed */
2667 hbmLoad = (HBITMAP)CopyImage((HBITMAP)bitmap->nID, IMAGE_BITMAP, 0, 0, 0);
2668 else
2669 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2671 /* enlarge the bitmap if needed */
2672 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2673 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2675 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2676 DeleteObject(hbmLoad);
2677 if (nIndex == -1)
2678 return FALSE;
2680 nCountAfter = ImageList_GetImageCount(himlDef);
2681 nAdded = nCountAfter - nCountBefore;
2682 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2684 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2685 } else if (nAdded > (INT)bitmap->nButtons) {
2686 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2687 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2690 infoPtr->nNumBitmaps += nAdded;
2691 return TRUE;
2694 static void
2695 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2697 HIMAGELIST himlDef;
2698 HIMAGELIST himlNew;
2699 INT cx, cy;
2700 INT i;
2702 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2703 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2704 return;
2705 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2706 return;
2707 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2708 return;
2710 TRACE("Update icon size: %dx%d -> %dx%d\n",
2711 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2713 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2714 ILC_COLORDDB|ILC_MASK, 8, 2);
2715 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2716 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2717 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2718 infoPtr->himlInt = himlNew;
2720 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2721 ImageList_Destroy(himlDef);
2724 /***********************************************************************
2725 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2728 static LRESULT
2729 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2731 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2732 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2733 TBITMAP_INFO info;
2734 INT iSumButtons, i;
2735 HIMAGELIST himlDef;
2737 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2738 if (!lpAddBmp)
2739 return -1;
2741 if (lpAddBmp->hInst == HINST_COMMCTRL)
2743 info.hInst = COMCTL32_hModule;
2744 switch (lpAddBmp->nID)
2746 case IDB_STD_SMALL_COLOR:
2747 info.nButtons = 15;
2748 info.nID = IDB_STD_SMALL;
2749 break;
2750 case IDB_STD_LARGE_COLOR:
2751 info.nButtons = 15;
2752 info.nID = IDB_STD_LARGE;
2753 break;
2754 case IDB_VIEW_SMALL_COLOR:
2755 info.nButtons = 12;
2756 info.nID = IDB_VIEW_SMALL;
2757 break;
2758 case IDB_VIEW_LARGE_COLOR:
2759 info.nButtons = 12;
2760 info.nID = IDB_VIEW_LARGE;
2761 break;
2762 case IDB_HIST_SMALL_COLOR:
2763 info.nButtons = 5;
2764 info.nID = IDB_HIST_SMALL;
2765 break;
2766 case IDB_HIST_LARGE_COLOR:
2767 info.nButtons = 5;
2768 info.nID = IDB_HIST_LARGE;
2769 break;
2770 default:
2771 return -1;
2774 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2776 /* Windows resize all the buttons to the size of a newly added standard image */
2777 if (lpAddBmp->nID & 1)
2779 /* large icons */
2780 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2781 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2783 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2784 MAKELPARAM((WORD)24, (WORD)24));
2785 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2786 MAKELPARAM((WORD)31, (WORD)30));
2788 else
2790 /* small icons */
2791 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2792 MAKELPARAM((WORD)16, (WORD)16));
2793 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2794 MAKELPARAM((WORD)22, (WORD)22));
2797 TOOLBAR_CalcToolbar (hwnd);
2799 else
2801 info.nButtons = (INT)wParam;
2802 info.hInst = lpAddBmp->hInst;
2803 info.nID = lpAddBmp->nID;
2804 TRACE("adding %d bitmaps!\n", info.nButtons);
2807 /* check if the bitmap is already loaded and compute iSumButtons */
2808 iSumButtons = 0;
2809 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2811 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2812 infoPtr->bitmaps[i].nID == info.nID)
2813 return iSumButtons;
2814 iSumButtons += infoPtr->bitmaps[i].nButtons;
2817 if (!infoPtr->cimlDef) {
2818 /* create new default image list */
2819 TRACE ("creating default image list!\n");
2821 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2822 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2823 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2824 infoPtr->himlInt = himlDef;
2826 else {
2827 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2830 if (!himlDef) {
2831 WARN("No default image list available\n");
2832 return -1;
2835 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2836 return -1;
2838 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2839 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2840 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2841 infoPtr->nNumBitmapInfos++;
2842 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2844 InvalidateRect(hwnd, NULL, TRUE);
2845 return iSumButtons;
2849 static LRESULT
2850 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2852 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2853 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2854 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2855 BOOL fHasString = FALSE;
2857 TRACE("adding %d buttons (unicode=%d)!\n", wParam, fUnicode);
2859 nAddButtons = (UINT)wParam;
2860 nOldButtons = infoPtr->nNumButtons;
2861 nNewButtons = nOldButtons + nAddButtons;
2863 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
2864 infoPtr->nNumButtons = nNewButtons;
2866 /* insert new button data */
2867 for (nCount = 0; nCount < nAddButtons; nCount++) {
2868 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2869 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2870 btnPtr->idCommand = lpTbb[nCount].idCommand;
2871 btnPtr->fsState = lpTbb[nCount].fsState;
2872 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2873 btnPtr->dwData = lpTbb[nCount].dwData;
2874 btnPtr->bHot = FALSE;
2875 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2877 if (fUnicode)
2878 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2879 else
2880 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString);
2881 fHasString = TRUE;
2883 else
2884 btnPtr->iString = lpTbb[nCount].iString;
2886 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
2889 if (infoPtr->nNumStrings > 0 || fHasString)
2890 TOOLBAR_CalcToolbar(hwnd);
2891 else
2892 TOOLBAR_LayoutToolbar(hwnd);
2893 TOOLBAR_AutoSize (hwnd);
2895 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2897 InvalidateRect(hwnd, NULL, TRUE);
2899 return TRUE;
2903 static LRESULT
2904 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2906 #define MAX_RESOURCE_STRING_LENGTH 512
2907 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2908 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2909 INT nIndex = infoPtr->nNumStrings;
2911 if ((wParam) && (HIWORD(lParam) == 0)) {
2912 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2913 WCHAR delimiter;
2914 WCHAR *next_delim;
2915 WCHAR *p;
2916 INT len;
2917 TRACE("adding string from resource!\n");
2919 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2920 szString, MAX_RESOURCE_STRING_LENGTH);
2922 TRACE("len=%d %s\n", len, debugstr_w(szString));
2923 if (len == 0 || len == 1)
2924 return nIndex;
2926 TRACE("Delimiter: 0x%x\n", *szString);
2927 delimiter = *szString;
2928 p = szString + 1;
2930 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2931 *next_delim = 0;
2932 if (next_delim + 1 >= szString + len)
2934 /* this may happen if delimiter == '\0' or if the last char is a
2935 * delimiter (then it is ignored like the native does) */
2936 break;
2939 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2940 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2941 infoPtr->nNumStrings++;
2943 p = next_delim + 1;
2946 else {
2947 LPWSTR p = (LPWSTR)lParam;
2948 INT len;
2950 if (p == NULL)
2951 return -1;
2952 TRACE("adding string(s) from array!\n");
2953 while (*p) {
2954 len = strlenW (p);
2956 TRACE("len=%d %s\n", len, debugstr_w(p));
2957 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2958 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2959 infoPtr->nNumStrings++;
2961 p += (len+1);
2965 if (fFirstString)
2966 TOOLBAR_CalcToolbar(hwnd);
2967 return nIndex;
2971 static LRESULT
2972 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2974 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2975 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2976 LPSTR p;
2977 INT nIndex;
2978 INT len;
2980 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
2981 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
2983 p = (LPSTR)lParam;
2984 if (p == NULL)
2985 return -1;
2987 TRACE("adding string(s) from array!\n");
2988 nIndex = infoPtr->nNumStrings;
2989 while (*p) {
2990 len = strlen (p);
2991 TRACE("len=%d \"%s\"\n", len, p);
2993 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2994 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
2995 infoPtr->nNumStrings++;
2997 p += (len+1);
3000 if (fFirstString)
3001 TOOLBAR_CalcToolbar(hwnd);
3002 return nIndex;
3006 static LRESULT
3007 TOOLBAR_AutoSize (HWND hwnd)
3009 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3010 RECT parent_rect;
3011 HWND parent;
3012 INT x, y;
3013 INT cx, cy;
3015 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3017 parent = GetParent (hwnd);
3019 if (!parent || !infoPtr->bDoRedraw)
3020 return 0;
3022 GetClientRect(parent, &parent_rect);
3024 x = parent_rect.left;
3025 y = parent_rect.top;
3027 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3029 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3030 cx = parent_rect.right - parent_rect.left;
3032 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3034 TOOLBAR_LayoutToolbar(hwnd);
3035 InvalidateRect( hwnd, NULL, TRUE );
3038 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3040 RECT window_rect;
3041 UINT uPosFlags = SWP_NOZORDER;
3043 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3045 GetWindowRect(hwnd, &window_rect);
3046 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3047 y = window_rect.top;
3049 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3051 GetWindowRect(hwnd, &window_rect);
3052 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3055 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3056 uPosFlags |= SWP_NOMOVE;
3058 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3059 cy += GetSystemMetrics(SM_CYEDGE);
3061 if (infoPtr->dwStyle & WS_BORDER)
3063 x = y = 1; /* FIXME: this looks wrong */
3064 cy += GetSystemMetrics(SM_CYEDGE);
3065 cx += GetSystemMetrics(SM_CXEDGE);
3068 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3071 return 0;
3075 static LRESULT
3076 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3078 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3080 return infoPtr->nNumButtons;
3084 static LRESULT
3085 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3087 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3089 infoPtr->dwStructSize = (DWORD)wParam;
3091 return 0;
3095 static LRESULT
3096 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3098 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3099 TBUTTON_INFO *btnPtr;
3100 INT nIndex;
3102 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3104 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3105 if (nIndex == -1)
3106 return FALSE;
3108 btnPtr = &infoPtr->buttons[nIndex];
3109 btnPtr->iBitmap = LOWORD(lParam);
3111 /* we HAVE to erase the background, the new bitmap could be */
3112 /* transparent */
3113 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3115 return TRUE;
3119 static LRESULT
3120 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3122 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3123 TBUTTON_INFO *btnPtr;
3124 INT nIndex;
3125 INT nOldIndex = -1;
3126 BOOL bChecked = FALSE;
3128 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3130 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3132 if (nIndex == -1)
3133 return FALSE;
3135 btnPtr = &infoPtr->buttons[nIndex];
3137 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3139 if (LOWORD(lParam) == FALSE)
3140 btnPtr->fsState &= ~TBSTATE_CHECKED;
3141 else {
3142 if (btnPtr->fsStyle & BTNS_GROUP) {
3143 nOldIndex =
3144 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3145 if (nOldIndex == nIndex)
3146 return 0;
3147 if (nOldIndex != -1)
3148 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3150 btnPtr->fsState |= TBSTATE_CHECKED;
3153 if( bChecked != LOWORD(lParam) )
3155 if (nOldIndex != -1)
3156 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3157 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3160 /* FIXME: Send a WM_NOTIFY?? */
3162 return TRUE;
3166 static LRESULT
3167 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3169 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3171 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3175 static LRESULT
3176 TOOLBAR_Customize (HWND hwnd)
3178 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3179 CUSTDLG_INFO custInfo;
3180 LRESULT ret;
3181 LPCVOID template;
3182 HRSRC hRes;
3183 NMHDR nmhdr;
3185 custInfo.tbInfo = infoPtr;
3186 custInfo.tbHwnd = hwnd;
3188 /* send TBN_BEGINADJUST notification */
3189 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3191 if (!(hRes = FindResourceW (COMCTL32_hModule,
3192 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3193 (LPWSTR)RT_DIALOG)))
3194 return FALSE;
3196 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3197 return FALSE;
3199 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3200 (LPCDLGTEMPLATEW)template,
3201 hwnd,
3202 TOOLBAR_CustomizeDialogProc,
3203 (LPARAM)&custInfo);
3205 /* send TBN_ENDADJUST notification */
3206 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3208 return ret;
3212 static LRESULT
3213 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3215 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3216 INT nIndex = (INT)wParam;
3217 NMTOOLBARW nmtb;
3218 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3220 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3221 return FALSE;
3223 memset(&nmtb, 0, sizeof(nmtb));
3224 nmtb.iItem = btnPtr->idCommand;
3225 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3226 nmtb.tbButton.idCommand = btnPtr->idCommand;
3227 nmtb.tbButton.fsState = btnPtr->fsState;
3228 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3229 nmtb.tbButton.dwData = btnPtr->dwData;
3230 nmtb.tbButton.iString = btnPtr->iString;
3231 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3233 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3235 if (infoPtr->nNumButtons == 1) {
3236 TRACE(" simple delete!\n");
3237 Free (infoPtr->buttons);
3238 infoPtr->buttons = NULL;
3239 infoPtr->nNumButtons = 0;
3241 else {
3242 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3243 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3245 infoPtr->nNumButtons--;
3246 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3247 if (nIndex > 0) {
3248 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3249 nIndex * sizeof(TBUTTON_INFO));
3252 if (nIndex < infoPtr->nNumButtons) {
3253 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3254 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3257 Free (oldButtons);
3260 TOOLBAR_LayoutToolbar(hwnd);
3262 InvalidateRect (hwnd, NULL, TRUE);
3264 return TRUE;
3268 static LRESULT
3269 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3271 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3272 TBUTTON_INFO *btnPtr;
3273 INT nIndex;
3274 DWORD bState;
3276 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3278 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3280 if (nIndex == -1)
3281 return FALSE;
3283 btnPtr = &infoPtr->buttons[nIndex];
3285 bState = btnPtr->fsState & TBSTATE_ENABLED;
3287 /* update the toolbar button state */
3288 if(LOWORD(lParam) == FALSE) {
3289 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3290 } else {
3291 btnPtr->fsState |= TBSTATE_ENABLED;
3294 /* redraw the button only if the state of the button changed */
3295 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3296 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3298 return TRUE;
3302 static inline LRESULT
3303 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3305 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3307 return infoPtr->bAnchor;
3311 static LRESULT
3312 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3314 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3315 INT nIndex;
3317 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3318 if (nIndex == -1)
3319 return -1;
3321 return infoPtr->buttons[nIndex].iBitmap;
3325 static inline LRESULT
3326 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3328 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3332 static LRESULT
3333 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3335 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3336 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3337 INT nIndex = (INT)wParam;
3338 TBUTTON_INFO *btnPtr;
3340 if (lpTbb == NULL)
3341 return FALSE;
3343 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3344 return FALSE;
3346 btnPtr = &infoPtr->buttons[nIndex];
3347 lpTbb->iBitmap = btnPtr->iBitmap;
3348 lpTbb->idCommand = btnPtr->idCommand;
3349 lpTbb->fsState = btnPtr->fsState;
3350 lpTbb->fsStyle = btnPtr->fsStyle;
3351 lpTbb->bReserved[0] = 0;
3352 lpTbb->bReserved[1] = 0;
3353 lpTbb->dwData = btnPtr->dwData;
3354 lpTbb->iString = btnPtr->iString;
3356 return TRUE;
3360 static LRESULT
3361 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3363 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3364 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3365 TBUTTON_INFO *btnPtr;
3366 INT nIndex;
3368 if (lpTbInfo == NULL)
3369 return -1;
3370 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3371 return -1;
3373 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3374 lpTbInfo->dwMask & 0x80000000);
3375 if (nIndex == -1)
3376 return -1;
3378 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3380 if (lpTbInfo->dwMask & TBIF_COMMAND)
3381 lpTbInfo->idCommand = btnPtr->idCommand;
3382 if (lpTbInfo->dwMask & TBIF_IMAGE)
3383 lpTbInfo->iImage = btnPtr->iBitmap;
3384 if (lpTbInfo->dwMask & TBIF_LPARAM)
3385 lpTbInfo->lParam = btnPtr->dwData;
3386 if (lpTbInfo->dwMask & TBIF_SIZE)
3387 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3388 if (lpTbInfo->dwMask & TBIF_STATE)
3389 lpTbInfo->fsState = btnPtr->fsState;
3390 if (lpTbInfo->dwMask & TBIF_STYLE)
3391 lpTbInfo->fsStyle = btnPtr->fsStyle;
3392 if (lpTbInfo->dwMask & TBIF_TEXT) {
3393 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3394 can't use TOOLBAR_GetText here */
3395 LPWSTR lpText;
3396 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3397 lpText = (LPWSTR)btnPtr->iString;
3398 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3399 } else
3400 lpTbInfo->pszText[0] = '\0';
3402 return nIndex;
3406 static LRESULT
3407 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3409 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3410 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3411 TBUTTON_INFO *btnPtr;
3412 INT nIndex;
3414 if (lpTbInfo == NULL)
3415 return -1;
3416 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3417 return -1;
3419 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3420 lpTbInfo->dwMask & 0x80000000);
3421 if (nIndex == -1)
3422 return -1;
3424 btnPtr = &infoPtr->buttons[nIndex];
3426 if(!btnPtr)
3427 return -1;
3429 if (lpTbInfo->dwMask & TBIF_COMMAND)
3430 lpTbInfo->idCommand = btnPtr->idCommand;
3431 if (lpTbInfo->dwMask & TBIF_IMAGE)
3432 lpTbInfo->iImage = btnPtr->iBitmap;
3433 if (lpTbInfo->dwMask & TBIF_LPARAM)
3434 lpTbInfo->lParam = btnPtr->dwData;
3435 if (lpTbInfo->dwMask & TBIF_SIZE)
3436 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3437 if (lpTbInfo->dwMask & TBIF_STATE)
3438 lpTbInfo->fsState = btnPtr->fsState;
3439 if (lpTbInfo->dwMask & TBIF_STYLE)
3440 lpTbInfo->fsStyle = btnPtr->fsStyle;
3441 if (lpTbInfo->dwMask & TBIF_TEXT) {
3442 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3443 can't use TOOLBAR_GetText here */
3444 LPWSTR lpText;
3445 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3446 lpText = (LPWSTR)btnPtr->iString;
3447 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3448 } else
3449 lpTbInfo->pszText[0] = '\0';
3452 return nIndex;
3456 static LRESULT
3457 TOOLBAR_GetButtonSize (HWND hwnd)
3459 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3461 return MAKELONG((WORD)infoPtr->nButtonWidth,
3462 (WORD)infoPtr->nButtonHeight);
3466 static LRESULT
3467 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3469 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3470 INT nIndex;
3471 LPWSTR lpText;
3473 if (lParam == 0)
3474 return -1;
3476 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3477 if (nIndex == -1)
3478 return -1;
3480 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3482 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3483 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3487 static LRESULT
3488 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3490 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3491 INT nIndex;
3492 LPWSTR lpText;
3493 LRESULT ret = 0;
3495 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3496 if (nIndex == -1)
3497 return -1;
3499 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3501 if (lpText)
3503 ret = strlenW (lpText);
3505 if (lParam)
3506 strcpyW ((LPWSTR)lParam, lpText);
3509 return ret;
3513 static LRESULT
3514 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3516 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3517 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3518 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3522 inline static LRESULT
3523 TOOLBAR_GetExtendedStyle (HWND hwnd)
3525 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3527 TRACE("\n");
3529 return infoPtr->dwExStyle;
3533 static LRESULT
3534 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3536 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3537 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3538 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3542 static LRESULT
3543 TOOLBAR_GetHotItem (HWND hwnd)
3545 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3547 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3548 return -1;
3550 if (infoPtr->nHotItem < 0)
3551 return -1;
3553 return (LRESULT)infoPtr->nHotItem;
3557 static LRESULT
3558 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3560 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3561 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3562 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3566 static LRESULT
3567 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3569 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3570 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3572 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3574 *lptbim = infoPtr->tbim;
3576 return 0;
3580 static LRESULT
3581 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3583 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3585 TRACE("hwnd = %p\n", hwnd);
3587 return (LRESULT)infoPtr->clrInsertMark;
3591 static LRESULT
3592 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3594 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3595 TBUTTON_INFO *btnPtr;
3596 LPRECT lpRect;
3597 INT nIndex;
3599 nIndex = (INT)wParam;
3600 btnPtr = &infoPtr->buttons[nIndex];
3601 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3602 return FALSE;
3603 lpRect = (LPRECT)lParam;
3604 if (lpRect == NULL)
3605 return FALSE;
3606 if (btnPtr->fsState & TBSTATE_HIDDEN)
3607 return FALSE;
3609 lpRect->left = btnPtr->rect.left;
3610 lpRect->right = btnPtr->rect.right;
3611 lpRect->bottom = btnPtr->rect.bottom;
3612 lpRect->top = btnPtr->rect.top;
3614 return TRUE;
3618 static LRESULT
3619 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3621 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3622 LPSIZE lpSize = (LPSIZE)lParam;
3624 if (lpSize == NULL)
3625 return FALSE;
3627 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3628 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3630 TRACE("maximum size %d x %d\n",
3631 infoPtr->rcBound.right - infoPtr->rcBound.left,
3632 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3634 return TRUE;
3638 /* << TOOLBAR_GetObject >> */
3641 static LRESULT
3642 TOOLBAR_GetPadding (HWND hwnd)
3644 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3645 DWORD oldPad;
3647 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3648 return (LRESULT) oldPad;
3652 static LRESULT
3653 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3655 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3656 TBUTTON_INFO *btnPtr;
3657 LPRECT lpRect;
3658 INT nIndex;
3660 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3661 btnPtr = &infoPtr->buttons[nIndex];
3662 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3663 return FALSE;
3664 lpRect = (LPRECT)lParam;
3665 if (lpRect == NULL)
3666 return FALSE;
3668 lpRect->left = btnPtr->rect.left;
3669 lpRect->right = btnPtr->rect.right;
3670 lpRect->bottom = btnPtr->rect.bottom;
3671 lpRect->top = btnPtr->rect.top;
3673 return TRUE;
3677 static LRESULT
3678 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3680 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3682 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3683 return infoPtr->nRows;
3684 else
3685 return 1;
3689 static LRESULT
3690 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3692 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3693 INT nIndex;
3695 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3696 if (nIndex == -1)
3697 return -1;
3699 return infoPtr->buttons[nIndex].fsState;
3703 static LRESULT
3704 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3706 return GetWindowLongW(hwnd, GWL_STYLE);
3710 static LRESULT
3711 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3713 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3715 return infoPtr->nMaxTextRows;
3719 static LRESULT
3720 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3722 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3724 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3725 TOOLBAR_TooltipCreateControl(infoPtr);
3726 return (LRESULT)infoPtr->hwndToolTip;
3730 static LRESULT
3731 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3733 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3735 TRACE("%s hwnd=%p\n",
3736 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3738 return infoPtr->bUnicode;
3742 inline static LRESULT
3743 TOOLBAR_GetVersion (HWND hwnd)
3745 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3746 return infoPtr->iVersion;
3750 static LRESULT
3751 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3753 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3754 TBUTTON_INFO *btnPtr;
3755 INT nIndex;
3757 TRACE("\n");
3759 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3760 if (nIndex == -1)
3761 return FALSE;
3763 btnPtr = &infoPtr->buttons[nIndex];
3764 if (LOWORD(lParam) == FALSE)
3765 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3766 else
3767 btnPtr->fsState |= TBSTATE_HIDDEN;
3769 TOOLBAR_CalcToolbar (hwnd);
3771 InvalidateRect (hwnd, NULL, TRUE);
3773 return TRUE;
3777 inline static LRESULT
3778 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3780 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3784 static LRESULT
3785 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3787 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3788 TBUTTON_INFO *btnPtr;
3789 INT nIndex;
3790 DWORD oldState;
3792 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3793 if (nIndex == -1)
3794 return FALSE;
3796 btnPtr = &infoPtr->buttons[nIndex];
3797 oldState = btnPtr->fsState;
3798 if (LOWORD(lParam) == FALSE)
3799 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3800 else
3801 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3803 if(oldState != btnPtr->fsState)
3804 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3806 return TRUE;
3810 static LRESULT
3811 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3813 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3814 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3815 INT nIndex = (INT)wParam;
3817 if (lpTbb == NULL)
3818 return FALSE;
3820 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3822 if (nIndex == -1) {
3823 /* EPP: this seems to be an undocumented call (from my IE4)
3824 * I assume in that case that:
3825 * - index of insertion is at the end of existing buttons
3826 * I only see this happen with nIndex == -1, but it could have a special
3827 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3829 nIndex = infoPtr->nNumButtons;
3831 } else if (nIndex < 0)
3832 return FALSE;
3834 TRACE("inserting button index=%d\n", nIndex);
3835 if (nIndex > infoPtr->nNumButtons) {
3836 nIndex = infoPtr->nNumButtons;
3837 TRACE("adjust index=%d\n", nIndex);
3840 infoPtr->nNumButtons++;
3841 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO) * infoPtr->nNumButtons);
3842 memmove(&infoPtr->buttons[nIndex+1], &infoPtr->buttons[nIndex],
3843 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3845 /* insert new button */
3846 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3847 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3848 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3849 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3850 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3851 /* if passed string and not index, then add string */
3852 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3853 if (fUnicode)
3854 Str_SetPtrW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3855 else
3856 Str_SetPtrAtoW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3858 else
3859 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3861 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
3863 if (infoPtr->nNumStrings > 0)
3864 TOOLBAR_CalcToolbar(hwnd);
3865 else
3866 TOOLBAR_LayoutToolbar(hwnd);
3867 TOOLBAR_AutoSize (hwnd);
3869 InvalidateRect (hwnd, NULL, TRUE);
3871 return TRUE;
3874 /* << TOOLBAR_InsertMarkHitTest >> */
3877 static LRESULT
3878 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3880 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3881 INT nIndex;
3883 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3884 if (nIndex == -1)
3885 return FALSE;
3887 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3891 static LRESULT
3892 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3894 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3895 INT nIndex;
3897 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3898 if (nIndex == -1)
3899 return FALSE;
3901 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3905 static LRESULT
3906 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3908 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3909 INT nIndex;
3911 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3912 if (nIndex == -1)
3913 return TRUE;
3915 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3919 static LRESULT
3920 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3922 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3923 INT nIndex;
3925 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3926 if (nIndex == -1)
3927 return FALSE;
3929 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3933 static LRESULT
3934 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3936 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3937 INT nIndex;
3939 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3940 if (nIndex == -1)
3941 return FALSE;
3943 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3947 static LRESULT
3948 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3950 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3951 INT nIndex;
3953 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3954 if (nIndex == -1)
3955 return FALSE;
3957 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3961 static LRESULT
3962 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3964 TBADDBITMAP tbab;
3965 tbab.hInst = (HINSTANCE)lParam;
3966 tbab.nID = (UINT_PTR)wParam;
3968 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3970 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3974 static LRESULT
3975 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3977 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3978 WCHAR wAccel = (WCHAR)wParam;
3979 UINT* pIDButton = (UINT*)lParam;
3980 WCHAR wszAccel[] = {'&',wAccel,0};
3981 int i;
3983 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3984 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3986 for (i = 0; i < infoPtr->nNumButtons; i++)
3988 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3989 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3990 !(btnPtr->fsState & TBSTATE_HIDDEN))
3992 int iLen = strlenW(wszAccel);
3993 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3995 if (!lpszStr)
3996 continue;
3998 while (*lpszStr)
4000 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4002 lpszStr += 2;
4003 continue;
4005 if (!strncmpiW(lpszStr, wszAccel, iLen))
4007 *pIDButton = btnPtr->idCommand;
4008 return TRUE;
4010 lpszStr++;
4014 return FALSE;
4018 static LRESULT
4019 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4021 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4022 INT nIndex;
4023 DWORD oldState;
4024 TBUTTON_INFO *btnPtr;
4026 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4028 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4029 if (nIndex == -1)
4030 return FALSE;
4032 btnPtr = &infoPtr->buttons[nIndex];
4033 oldState = btnPtr->fsState;
4035 if (LOWORD(lParam))
4036 btnPtr->fsState |= TBSTATE_MARKED;
4037 else
4038 btnPtr->fsState &= ~TBSTATE_MARKED;
4040 if(oldState != btnPtr->fsState)
4041 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4043 return TRUE;
4047 /* fixes up an index of a button affected by a move */
4048 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4050 if (bMoveUp)
4052 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4053 (*pIndex)--;
4054 else if (*pIndex == nIndex)
4055 *pIndex = nMoveIndex;
4057 else
4059 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4060 (*pIndex)++;
4061 else if (*pIndex == nIndex)
4062 *pIndex = nMoveIndex;
4067 static LRESULT
4068 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4070 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4071 INT nIndex;
4072 INT nCount;
4073 INT nMoveIndex = (INT)lParam;
4074 TBUTTON_INFO button;
4076 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4078 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4079 if ((nIndex == -1) || (nMoveIndex < 0))
4080 return FALSE;
4082 if (nMoveIndex > infoPtr->nNumButtons - 1)
4083 nMoveIndex = infoPtr->nNumButtons - 1;
4085 button = infoPtr->buttons[nIndex];
4087 /* move button right */
4088 if (nIndex < nMoveIndex)
4090 nCount = nMoveIndex - nIndex;
4091 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4092 infoPtr->buttons[nMoveIndex] = button;
4094 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4095 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4096 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4097 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4099 else if (nIndex > nMoveIndex) /* move button left */
4101 nCount = nIndex - nMoveIndex;
4102 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4103 infoPtr->buttons[nMoveIndex] = button;
4105 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4106 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4107 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4108 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4111 TOOLBAR_CalcToolbar(hwnd);
4112 TOOLBAR_AutoSize(hwnd);
4113 InvalidateRect(hwnd, NULL, TRUE);
4115 return TRUE;
4119 static LRESULT
4120 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4122 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4123 TBUTTON_INFO *btnPtr;
4124 INT nIndex;
4125 DWORD oldState;
4127 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4128 if (nIndex == -1)
4129 return FALSE;
4131 btnPtr = &infoPtr->buttons[nIndex];
4132 oldState = btnPtr->fsState;
4133 if (LOWORD(lParam) == FALSE)
4134 btnPtr->fsState &= ~TBSTATE_PRESSED;
4135 else
4136 btnPtr->fsState |= TBSTATE_PRESSED;
4138 if(oldState != btnPtr->fsState)
4139 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4141 return TRUE;
4144 /* FIXME: there might still be some confusion her between number of buttons
4145 * and number of bitmaps */
4146 static LRESULT
4147 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4149 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4150 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4151 HBITMAP hBitmap;
4152 int i = 0, nOldButtons = 0, pos = 0;
4153 int nOldBitmaps, nNewBitmaps = 0;
4154 HIMAGELIST himlDef = 0;
4156 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4157 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4158 lpReplace->nButtons);
4160 if (lpReplace->hInstOld == HINST_COMMCTRL)
4162 FIXME("changing standard bitmaps not implemented\n");
4163 return FALSE;
4165 else if (lpReplace->hInstOld != 0)
4166 FIXME("resources not in the current module not implemented\n");
4168 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4169 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4170 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4171 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4172 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4174 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4175 nOldButtons = tbi->nButtons;
4176 tbi->nButtons = lpReplace->nButtons;
4177 tbi->hInst = lpReplace->hInstNew;
4178 tbi->nID = lpReplace->nIDNew;
4179 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4180 break;
4182 pos += tbi->nButtons;
4185 if (nOldButtons == 0)
4187 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4188 return FALSE;
4191 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4192 * bitmap
4194 if (lpReplace->hInstNew)
4195 hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4196 else
4197 hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
4199 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4200 nOldBitmaps = ImageList_GetImageCount(himlDef);
4202 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4204 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4205 ImageList_Remove(himlDef, i);
4207 if (hBitmap)
4209 ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
4210 nNewBitmaps = ImageList_GetImageCount(himlDef);
4211 DeleteObject(hBitmap);
4214 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4216 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4217 pos, nOldBitmaps, nNewBitmaps);
4219 InvalidateRect(hwnd, NULL, TRUE);
4220 return TRUE;
4224 /* helper for TOOLBAR_SaveRestoreW */
4225 static BOOL
4226 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4228 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4229 debugstr_w(lpSave->pszValueName));
4231 return FALSE;
4235 /* helper for TOOLBAR_Restore */
4236 static void
4237 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4239 INT i;
4241 for (i = 0; i < infoPtr->nNumButtons; i++)
4243 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4246 Free(infoPtr->buttons);
4247 infoPtr->buttons = NULL;
4248 infoPtr->nNumButtons = 0;
4252 /* helper for TOOLBAR_SaveRestoreW */
4253 static BOOL
4254 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4256 LONG res;
4257 HKEY hkey = NULL;
4258 BOOL ret = FALSE;
4259 DWORD dwType;
4260 DWORD dwSize = 0;
4261 NMTBRESTORE nmtbr;
4263 /* restore toolbar information */
4264 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4265 debugstr_w(lpSave->pszValueName));
4267 memset(&nmtbr, 0, sizeof(nmtbr));
4269 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4270 KEY_QUERY_VALUE, &hkey);
4271 if (!res)
4272 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4273 NULL, &dwSize);
4274 if (!res && dwType != REG_BINARY)
4275 res = ERROR_FILE_NOT_FOUND;
4276 if (!res)
4278 nmtbr.pData = Alloc(dwSize);
4279 nmtbr.cbData = (UINT)dwSize;
4280 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4282 if (!res)
4283 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4284 (LPBYTE)nmtbr.pData, &dwSize);
4285 if (!res)
4287 nmtbr.pCurrent = nmtbr.pData;
4288 nmtbr.iItem = -1;
4289 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4290 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4292 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4294 INT i;
4296 /* remove all existing buttons as this function is designed to
4297 * restore the toolbar to a previously saved state */
4298 TOOLBAR_DeleteAllButtons(infoPtr);
4300 for (i = 0; i < nmtbr.cButtons; i++)
4302 nmtbr.iItem = i;
4303 nmtbr.tbButton.iBitmap = -1;
4304 nmtbr.tbButton.fsState = 0;
4305 nmtbr.tbButton.fsStyle = 0;
4306 nmtbr.tbButton.idCommand = 0;
4307 if (*nmtbr.pCurrent == (DWORD)-1)
4309 /* separator */
4310 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4311 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4313 else if (*nmtbr.pCurrent == (DWORD)-2)
4314 /* hidden button */
4315 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4316 else
4317 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4319 nmtbr.pCurrent++;
4321 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4323 /* can't contain real string as we don't know whether
4324 * the client put an ANSI or Unicode string in there */
4325 if (HIWORD(nmtbr.tbButton.iString))
4326 nmtbr.tbButton.iString = 0;
4328 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4329 (LPARAM)&nmtbr.tbButton, TRUE);
4332 /* do legacy notifications */
4333 if (infoPtr->iVersion < 5)
4335 /* FIXME: send TBN_BEGINADJUST */
4336 FIXME("send TBN_GETBUTTONINFO for each button\n");
4337 /* FIXME: send TBN_ENDADJUST */
4340 /* remove all uninitialised buttons
4341 * note: loop backwards to avoid having to fixup i on a
4342 * delete */
4343 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4344 if (infoPtr->buttons[i].iBitmap == -1)
4345 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4347 /* only indicate success if at least one button survived */
4348 if (infoPtr->nNumButtons > 0) ret = TRUE;
4351 Free (nmtbr.pData);
4352 RegCloseKey(hkey);
4354 return ret;
4358 static LRESULT
4359 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4361 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4363 if (lpSave == NULL) return 0;
4365 if (wParam)
4366 return TOOLBAR_Save(infoPtr, lpSave);
4367 else
4368 return TOOLBAR_Restore(infoPtr, lpSave);
4372 static LRESULT
4373 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4375 LPWSTR pszValueName = 0, pszSubKey = 0;
4376 TBSAVEPARAMSW SaveW;
4377 LRESULT result = 0;
4378 int len;
4380 if (lpSave == NULL) return 0;
4382 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4383 pszSubKey = Alloc(len * sizeof(WCHAR));
4384 if (pszSubKey) goto exit;
4385 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4387 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4388 pszValueName = Alloc(len * sizeof(WCHAR));
4389 if (!pszValueName) goto exit;
4390 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4392 SaveW.pszValueName = pszValueName;
4393 SaveW.pszSubKey = pszSubKey;
4394 SaveW.hkr = lpSave->hkr;
4395 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4397 exit:
4398 Free (pszValueName);
4399 Free (pszSubKey);
4401 return result;
4405 static LRESULT
4406 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4408 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4409 BOOL bOldAnchor = infoPtr->bAnchor;
4411 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4413 infoPtr->bAnchor = (BOOL)wParam;
4415 /* Native does not remove the hot effect from an already hot button */
4417 return (LRESULT)bOldAnchor;
4421 static LRESULT
4422 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4424 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4425 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4427 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4429 if (wParam != 0)
4430 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4432 if (LOWORD(lParam) == 0)
4433 lParam = MAKELPARAM(1, HIWORD(lParam));
4435 if (HIWORD(lParam)==0)
4436 lParam = MAKELPARAM(LOWORD(lParam), 1);
4438 if (infoPtr->nNumButtons > 0)
4439 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4440 infoPtr->nNumButtons,
4441 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4442 LOWORD(lParam), HIWORD(lParam));
4444 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4445 infoPtr->nVBitmapHeight = infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4447 if ((himlDef == infoPtr->himlInt) &&
4448 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4450 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4451 infoPtr->nBitmapHeight);
4454 TOOLBAR_CalcToolbar(hwnd);
4455 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4456 return TRUE;
4460 static LRESULT
4461 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4463 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4464 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4465 TBUTTON_INFO *btnPtr;
4466 INT nIndex;
4467 RECT oldBtnRect;
4469 if (lptbbi == NULL)
4470 return FALSE;
4471 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4472 return FALSE;
4474 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4475 lptbbi->dwMask & 0x80000000);
4476 if (nIndex == -1)
4477 return FALSE;
4479 btnPtr = &infoPtr->buttons[nIndex];
4480 if (lptbbi->dwMask & TBIF_COMMAND)
4481 btnPtr->idCommand = lptbbi->idCommand;
4482 if (lptbbi->dwMask & TBIF_IMAGE)
4483 btnPtr->iBitmap = lptbbi->iImage;
4484 if (lptbbi->dwMask & TBIF_LPARAM)
4485 btnPtr->dwData = lptbbi->lParam;
4486 if (lptbbi->dwMask & TBIF_SIZE)
4487 btnPtr->cx = lptbbi->cx;
4488 if (lptbbi->dwMask & TBIF_STATE)
4489 btnPtr->fsState = lptbbi->fsState;
4490 if (lptbbi->dwMask & TBIF_STYLE)
4491 btnPtr->fsStyle = lptbbi->fsStyle;
4493 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4494 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4495 /* iString is index, zero it to make Str_SetPtr succeed */
4496 btnPtr->iString=0;
4498 Str_SetPtrAtoW ((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_CalcToolbar(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_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4517 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4518 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4519 TBUTTON_INFO *btnPtr;
4520 INT nIndex;
4521 RECT oldBtnRect;
4523 if (lptbbi == NULL)
4524 return FALSE;
4525 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4526 return FALSE;
4528 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4529 lptbbi->dwMask & 0x80000000);
4530 if (nIndex == -1)
4531 return FALSE;
4533 btnPtr = &infoPtr->buttons[nIndex];
4534 if (lptbbi->dwMask & TBIF_COMMAND)
4535 btnPtr->idCommand = lptbbi->idCommand;
4536 if (lptbbi->dwMask & TBIF_IMAGE)
4537 btnPtr->iBitmap = lptbbi->iImage;
4538 if (lptbbi->dwMask & TBIF_LPARAM)
4539 btnPtr->dwData = lptbbi->lParam;
4540 if (lptbbi->dwMask & TBIF_SIZE)
4541 btnPtr->cx = lptbbi->cx;
4542 if (lptbbi->dwMask & TBIF_STATE)
4543 btnPtr->fsState = lptbbi->fsState;
4544 if (lptbbi->dwMask & TBIF_STYLE)
4545 btnPtr->fsStyle = lptbbi->fsStyle;
4547 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4548 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4549 /* iString is index, zero it to make Str_SetPtr succeed */
4550 btnPtr->iString=0;
4551 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4554 /* save the button rect to see if we need to redraw the whole toolbar */
4555 oldBtnRect = btnPtr->rect;
4556 TOOLBAR_CalcToolbar(hwnd);
4558 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4559 InvalidateRect(hwnd, NULL, TRUE);
4560 else
4561 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4563 return TRUE;
4567 static LRESULT
4568 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4570 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4571 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4573 if ((cx < 0) || (cy < 0))
4575 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4576 return FALSE;
4579 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4581 /* The documentation claims you can only change the button size before
4582 * any button has been added. But this is wrong.
4583 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4584 * it to the toolbar, and it checks that the return value is nonzero - mjm
4585 * Further testing shows that we must actually perform the change too.
4588 * The documentation also does not mention that if 0 is supplied for
4589 * either size, the system changes it to the default of 24 wide and
4590 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4592 if (cx == 0) cx = 24;
4593 if (cy == 0) cx = 22;
4595 cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
4596 cy = max(cy, infoPtr->szPadding.cy + infoPtr->nVBitmapHeight);
4598 infoPtr->nButtonWidth = cx;
4599 infoPtr->nButtonHeight = cy;
4601 infoPtr->iTopMargin = default_top_margin(infoPtr);
4602 TOOLBAR_LayoutToolbar(hwnd);
4603 return TRUE;
4607 static LRESULT
4608 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4610 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4612 /* if setting to current values, ignore */
4613 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4614 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4615 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4616 infoPtr->cxMin, infoPtr->cxMax);
4617 return TRUE;
4620 /* save new values */
4621 infoPtr->cxMin = (short)LOWORD(lParam);
4622 infoPtr->cxMax = (short)HIWORD(lParam);
4624 /* otherwise we need to recalc the toolbar and in some cases
4625 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4626 which doesn't actually draw - GA). */
4627 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4628 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4630 TOOLBAR_CalcToolbar (hwnd);
4632 InvalidateRect (hwnd, NULL, TRUE);
4634 return TRUE;
4638 static LRESULT
4639 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4641 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4642 INT nIndex = (INT)wParam;
4644 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4645 return FALSE;
4647 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4649 if (infoPtr->hwndToolTip) {
4651 FIXME("change tool tip!\n");
4655 return TRUE;
4659 static LRESULT
4660 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4662 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4663 HIMAGELIST himl = (HIMAGELIST)lParam;
4664 HIMAGELIST himlTemp;
4665 INT id = 0;
4667 if (infoPtr->iVersion >= 5)
4668 id = wParam;
4670 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4671 &infoPtr->cimlDis, himl, id);
4673 /* FIXME: redraw ? */
4675 return (LRESULT)himlTemp;
4679 static LRESULT
4680 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4682 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4683 DWORD dwTemp;
4685 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4687 dwTemp = infoPtr->dwDTFlags;
4688 infoPtr->dwDTFlags =
4689 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4691 return (LRESULT)dwTemp;
4694 /* This function differs a bit from what MSDN says it does:
4695 * 1. lParam contains extended style flags to OR with current style
4696 * (MSDN isn't clear on the OR bit)
4697 * 2. wParam appears to contain extended style flags to be reset
4698 * (MSDN says that this parameter is reserved)
4700 static LRESULT
4701 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4703 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4704 DWORD dwTemp;
4706 dwTemp = infoPtr->dwExStyle;
4707 infoPtr->dwExStyle &= ~wParam;
4708 infoPtr->dwExStyle |= (DWORD)lParam;
4710 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4712 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4713 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4714 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4716 TOOLBAR_CalcToolbar (hwnd);
4718 TOOLBAR_AutoSize(hwnd);
4720 InvalidateRect(hwnd, NULL, TRUE);
4722 return (LRESULT)dwTemp;
4726 static LRESULT
4727 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4729 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4730 HIMAGELIST himlTemp;
4731 HIMAGELIST himl = (HIMAGELIST)lParam;
4732 INT id = 0;
4734 if (infoPtr->iVersion >= 5)
4735 id = wParam;
4737 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4739 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4740 &infoPtr->cimlHot, himl, id);
4742 /* FIXME: redraw ? */
4744 return (LRESULT)himlTemp;
4748 /* Makes previous hot button no longer hot, makes the specified
4749 * button hot and sends appropriate notifications. dwReason is one or
4750 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4751 * NOTE 1: this function does not validate nHit
4752 * NOTE 2: the name of this function is completely made up and
4753 * not based on any documentation from Microsoft. */
4754 static void
4755 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4757 if (infoPtr->nHotItem != nHit)
4759 NMTBHOTITEM nmhotitem;
4760 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4762 nmhotitem.dwFlags = dwReason;
4763 if(infoPtr->nHotItem >= 0)
4765 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4766 nmhotitem.idOld = oldBtnPtr->idCommand;
4768 else
4770 nmhotitem.dwFlags |= HICF_ENTERING;
4771 nmhotitem.idOld = 0;
4774 if (nHit >= 0)
4776 btnPtr = &infoPtr->buttons[nHit];
4777 nmhotitem.idNew = btnPtr->idCommand;
4779 else
4781 nmhotitem.dwFlags |= HICF_LEAVING;
4782 nmhotitem.idNew = 0;
4785 /* now change the hot and invalidate the old and new buttons - if the
4786 * parent agrees */
4787 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4789 if (oldBtnPtr) {
4790 oldBtnPtr->bHot = FALSE;
4791 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4793 /* setting disabled buttons as hot fails even if the notify contains the button id */
4794 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4795 btnPtr->bHot = TRUE;
4796 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4797 infoPtr->nHotItem = nHit;
4799 else
4800 infoPtr->nHotItem = -1;
4805 static LRESULT
4806 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4808 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4809 INT nOldHotItem = infoPtr->nHotItem;
4811 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4813 if ((INT)wParam > infoPtr->nNumButtons)
4814 return infoPtr->nHotItem;
4816 if ((INT)wParam < 0)
4817 wParam = -1;
4819 /* NOTE: an application can still remove the hot item even if anchor
4820 * highlighting is enabled */
4822 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4824 if (nOldHotItem < 0)
4825 return -1;
4827 return (LRESULT)nOldHotItem;
4831 static LRESULT
4832 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4834 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4835 HIMAGELIST himlTemp;
4836 HIMAGELIST himl = (HIMAGELIST)lParam;
4837 INT i, id = 0;
4839 if (infoPtr->iVersion >= 5)
4840 id = wParam;
4842 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4843 &infoPtr->cimlDef, himl, id);
4845 infoPtr->nNumBitmaps = 0;
4846 for (i = 0; i < infoPtr->cimlDef; i++)
4847 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4849 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4850 &infoPtr->nBitmapHeight))
4852 infoPtr->nBitmapWidth = 1;
4853 infoPtr->nBitmapHeight = 1;
4855 infoPtr->nVBitmapHeight = infoPtr->nBitmapHeight;
4856 TOOLBAR_CalcToolbar(hwnd);
4858 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4859 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4860 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4862 InvalidateRect(hwnd, NULL, TRUE);
4864 return (LRESULT)himlTemp;
4868 static LRESULT
4869 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4871 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4873 infoPtr->nIndent = (INT)wParam;
4875 TRACE("\n");
4877 /* process only on indent changing */
4878 if(infoPtr->nIndent != (INT)wParam)
4880 infoPtr->nIndent = (INT)wParam;
4881 TOOLBAR_CalcToolbar (hwnd);
4882 InvalidateRect(hwnd, NULL, FALSE);
4885 return TRUE;
4889 static LRESULT
4890 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4892 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4893 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4895 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4897 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4899 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4900 return 0;
4903 if ((lptbim->iButton == -1) ||
4904 ((lptbim->iButton < infoPtr->nNumButtons) &&
4905 (lptbim->iButton >= 0)))
4907 infoPtr->tbim = *lptbim;
4908 /* FIXME: don't need to update entire toolbar */
4909 InvalidateRect(hwnd, NULL, TRUE);
4911 else
4912 ERR("Invalid button index %d\n", lptbim->iButton);
4914 return 0;
4918 static LRESULT
4919 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4921 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4923 infoPtr->clrInsertMark = (COLORREF)lParam;
4925 /* FIXME: don't need to update entire toolbar */
4926 InvalidateRect(hwnd, NULL, TRUE);
4928 return 0;
4932 static LRESULT
4933 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4935 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4937 infoPtr->nMaxTextRows = (INT)wParam;
4939 TOOLBAR_CalcToolbar(hwnd);
4940 return TRUE;
4944 /* MSDN gives slightly wrong info on padding.
4945 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4946 * 2. It is not used to create a blank area between the edge of the button
4947 * and the text or image if TBSTYLE_LIST is set. It is used to control
4948 * the gap between the image and text.
4949 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4950 * to control the bottom and right borders [with the border being
4951 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4952 * is shared evenly on both sides of the button.
4953 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4955 static LRESULT
4956 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4958 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4959 DWORD oldPad;
4961 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4962 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4963 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4964 TRACE("cx=%d, cy=%d\n",
4965 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4966 return (LRESULT) oldPad;
4970 static LRESULT
4971 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4973 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4974 HWND hwndOldNotify;
4976 TRACE("\n");
4978 hwndOldNotify = infoPtr->hwndNotify;
4979 infoPtr->hwndNotify = (HWND)wParam;
4981 return (LRESULT)hwndOldNotify;
4985 static LRESULT
4986 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4988 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4989 LPRECT lprc = (LPRECT)lParam;
4991 TRACE("\n");
4993 if (LOWORD(wParam) > 1) {
4994 FIXME("multiple rows not supported!\n");
4997 if(infoPtr->nRows != LOWORD(wParam))
4999 infoPtr->nRows = LOWORD(wParam);
5001 /* recalculate toolbar */
5002 TOOLBAR_CalcToolbar (hwnd);
5004 /* repaint toolbar */
5005 InvalidateRect(hwnd, NULL, TRUE);
5008 /* return bounding rectangle */
5009 if (lprc) {
5010 lprc->left = infoPtr->rcBound.left;
5011 lprc->right = infoPtr->rcBound.right;
5012 lprc->top = infoPtr->rcBound.top;
5013 lprc->bottom = infoPtr->rcBound.bottom;
5016 return 0;
5020 static LRESULT
5021 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5023 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5024 TBUTTON_INFO *btnPtr;
5025 INT nIndex;
5027 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5028 if (nIndex == -1)
5029 return FALSE;
5031 btnPtr = &infoPtr->buttons[nIndex];
5033 /* if hidden state has changed the invalidate entire window and recalc */
5034 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5035 btnPtr->fsState = LOWORD(lParam);
5036 TOOLBAR_CalcToolbar (hwnd);
5037 InvalidateRect(hwnd, 0, TRUE);
5038 return TRUE;
5041 /* process state changing if current state doesn't match new state */
5042 if(btnPtr->fsState != LOWORD(lParam))
5044 btnPtr->fsState = LOWORD(lParam);
5045 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5048 return TRUE;
5052 static LRESULT
5053 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5055 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5057 return TRUE;
5061 inline static LRESULT
5062 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5064 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5066 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5068 infoPtr->hwndToolTip = (HWND)wParam;
5069 return 0;
5073 static LRESULT
5074 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5076 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5077 BOOL bTemp;
5079 TRACE("%s hwnd=%p\n",
5080 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5082 bTemp = infoPtr->bUnicode;
5083 infoPtr->bUnicode = (BOOL)wParam;
5085 return bTemp;
5089 static LRESULT
5090 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5092 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5094 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5095 comctl32_color.clrBtnHighlight :
5096 infoPtr->clrBtnHighlight;
5097 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5098 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5099 return 1;
5103 static LRESULT
5104 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5106 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5108 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5109 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5110 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5112 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5113 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5114 InvalidateRect(hwnd, NULL, TRUE);
5115 return 0;
5119 static LRESULT
5120 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5122 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5123 INT iOldVersion = infoPtr->iVersion;
5125 infoPtr->iVersion = iVersion;
5127 if (infoPtr->iVersion >= 5)
5128 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5130 return iOldVersion;
5134 static LRESULT
5135 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5137 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5138 WORD iString = HIWORD(wParam);
5139 WORD buffersize = LOWORD(wParam);
5140 LPSTR str = (LPSTR)lParam;
5141 LRESULT ret = -1;
5143 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5145 if (iString < infoPtr->nNumStrings)
5147 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5149 TRACE("returning %s\n", debugstr_a(str));
5151 else
5152 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5154 return ret;
5158 static LRESULT
5159 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5161 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5162 WORD iString = HIWORD(wParam);
5163 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5164 LPWSTR str = (LPWSTR)lParam;
5165 LRESULT ret = -1;
5167 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5169 if (iString < infoPtr->nNumStrings)
5171 len = min(len, strlenW(infoPtr->strings[iString]));
5172 ret = (len+1)*sizeof(WCHAR);
5173 memcpy(str, infoPtr->strings[iString], ret);
5174 str[len] = '\0';
5176 TRACE("returning %s\n", debugstr_w(str));
5178 else
5179 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5181 return ret;
5184 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5185 * is the maximum size of the toolbar? */
5186 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5188 SIZE * pSize = (SIZE*)lParam;
5189 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5190 return 0;
5194 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5195 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5196 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5197 * sends). */
5198 static LRESULT
5199 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5201 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5202 INT nOldHotItem = infoPtr->nHotItem;
5204 TRACE("old item=%d, new item=%d, flags=%08x\n",
5205 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5207 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5208 wParam = -1;
5210 /* NOTE: an application can still remove the hot item even if anchor
5211 * highlighting is enabled */
5213 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5215 GetFocus();
5217 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5220 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5221 * which controls the amount of spacing between the image and the text
5222 * of buttons for TBSTYLE_LIST toolbars. */
5223 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5225 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5227 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5229 if (lParam != 0)
5230 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5232 infoPtr->iListGap = (INT)wParam;
5234 InvalidateRect(hwnd, NULL, TRUE);
5236 return 0;
5239 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5240 * of image lists associated with the various states. */
5241 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5243 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5245 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5247 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5250 static LRESULT
5251 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5253 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5254 LPSIZE lpsize = (LPSIZE)lParam;
5256 if (lpsize == NULL)
5257 return FALSE;
5260 * Testing shows the following:
5261 * wParam = 0 adjust cx value
5262 * = 1 set cy value to max size.
5263 * lParam pointer to SIZE structure
5266 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5267 wParam, lParam, lpsize->cx, lpsize->cy);
5269 switch(wParam) {
5270 case 0:
5271 if (lpsize->cx == -1) {
5272 /* **** this is wrong, native measures each button and sets it */
5273 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5275 else if(HIWORD(lpsize->cx)) {
5276 RECT rc;
5277 HWND hwndParent = GetParent(hwnd);
5279 GetWindowRect(hwnd, &rc);
5280 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5281 TRACE("mapped to (%d,%d)-(%d,%d)\n",
5282 rc.left, rc.top, rc.right, rc.bottom);
5283 lpsize->cx = max(rc.right-rc.left,
5284 infoPtr->rcBound.right - infoPtr->rcBound.left);
5286 else {
5287 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5289 break;
5290 case 1:
5291 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5292 break;
5293 default:
5294 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5295 wParam);
5296 return 0;
5298 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5299 lpsize->cx, lpsize->cy);
5300 return 1;
5303 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5305 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5307 InvalidateRect(hwnd, NULL, TRUE);
5308 return 1;
5312 static LRESULT
5313 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5315 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5316 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5317 LOGFONTW logFont;
5319 TRACE("hwnd = %p\n", hwnd);
5321 /* initialize info structure */
5322 infoPtr->nButtonWidth = 23;
5323 infoPtr->nButtonHeight = 22;
5324 infoPtr->nBitmapHeight = 15;
5325 infoPtr->nBitmapWidth = 16;
5326 /* By default Windows creates an image list with 16x15 icons but computes the button size as
5327 * if the icons were 16x16. That's why we keep infoPtr->nVBitmapHeight. After a call to
5328 * TB_SETBITMAPSIZE or TB_SETIMAGELIST the nVBitmapHeight = nBitmapHeight.
5330 infoPtr->nVBitmapHeight = 16;
5332 infoPtr->nMaxTextRows = 1;
5333 infoPtr->cxMin = -1;
5334 infoPtr->cxMax = -1;
5335 infoPtr->nNumBitmaps = 0;
5336 infoPtr->nNumStrings = 0;
5338 infoPtr->bCaptured = FALSE;
5339 infoPtr->nButtonDown = -1;
5340 infoPtr->nButtonDrag = -1;
5341 infoPtr->nOldHit = -1;
5342 infoPtr->nHotItem = -1;
5343 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5344 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5345 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5346 infoPtr->bDragOutSent = FALSE;
5347 infoPtr->iVersion = 0;
5348 infoPtr->hwndSelf = hwnd;
5349 infoPtr->bDoRedraw = TRUE;
5350 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5351 infoPtr->clrBtnShadow = CLR_DEFAULT;
5352 infoPtr->szPadding.cx = DEFPAD_CX;
5353 infoPtr->szPadding.cy = DEFPAD_CY;
5354 infoPtr->iListGap = DEFLISTGAP;
5355 infoPtr->iTopMargin = default_top_margin(infoPtr);
5356 infoPtr->dwStyle = dwStyle;
5357 infoPtr->tbim.iButton = -1;
5358 GetClientRect(hwnd, &infoPtr->client_rect);
5359 infoPtr->bUnicode = infoPtr->hwndNotify &&
5360 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5361 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5363 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5364 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5366 OpenThemeData (hwnd, themeClass);
5368 TOOLBAR_CheckStyle (hwnd, dwStyle);
5370 return 0;
5374 static LRESULT
5375 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5377 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5379 /* delete tooltip control */
5380 if (infoPtr->hwndToolTip)
5381 DestroyWindow (infoPtr->hwndToolTip);
5383 /* delete temporary buffer for tooltip text */
5384 Free (infoPtr->pszTooltipText);
5385 Free (infoPtr->bitmaps); /* bitmaps list */
5387 /* delete button data */
5388 if (infoPtr->buttons)
5389 Free (infoPtr->buttons);
5391 /* delete strings */
5392 if (infoPtr->strings) {
5393 INT i;
5394 for (i = 0; i < infoPtr->nNumStrings; i++)
5395 if (infoPtr->strings[i])
5396 Free (infoPtr->strings[i]);
5398 Free (infoPtr->strings);
5401 /* destroy internal image list */
5402 if (infoPtr->himlInt)
5403 ImageList_Destroy (infoPtr->himlInt);
5405 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5406 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5407 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5409 /* delete default font */
5410 DeleteObject (infoPtr->hDefaultFont);
5412 CloseThemeData (GetWindowTheme (hwnd));
5414 /* free toolbar info data */
5415 Free (infoPtr);
5416 SetWindowLongPtrW (hwnd, 0, 0);
5418 return 0;
5422 static LRESULT
5423 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5425 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5426 NMTBCUSTOMDRAW tbcd;
5427 INT ret = FALSE;
5428 DWORD ntfret;
5429 HTHEME theme = GetWindowTheme (hwnd);
5430 DWORD dwEraseCustDraw = 0;
5432 /* the app has told us not to redraw the toolbar */
5433 if (!infoPtr->bDoRedraw)
5434 return FALSE;
5436 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5437 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5438 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5439 tbcd.nmcd.hdc = (HDC)wParam;
5440 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5441 dwEraseCustDraw = ntfret & 0xffff;
5443 /* FIXME: in general the return flags *can* be or'ed together */
5444 switch (dwEraseCustDraw)
5446 case CDRF_DODEFAULT:
5447 break;
5448 case CDRF_SKIPDEFAULT:
5449 return TRUE;
5450 default:
5451 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5452 hwnd, ntfret);
5456 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5457 * to my parent for processing.
5459 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5460 POINT pt, ptorig;
5461 HDC hdc = (HDC)wParam;
5462 HWND parent;
5464 pt.x = 0;
5465 pt.y = 0;
5466 parent = GetParent(hwnd);
5467 MapWindowPoints(hwnd, parent, &pt, 1);
5468 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5469 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5470 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5472 if (!ret)
5473 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5475 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5476 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5477 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5478 tbcd.nmcd.hdc = (HDC)wParam;
5479 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5480 dwEraseCustDraw = ntfret & 0xffff;
5481 switch (dwEraseCustDraw)
5483 case CDRF_DODEFAULT:
5484 break;
5485 case CDRF_SKIPDEFAULT:
5486 return TRUE;
5487 default:
5488 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5489 hwnd, ntfret);
5492 return ret;
5496 static LRESULT
5497 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5499 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5501 return (LRESULT)infoPtr->hFont;
5505 static void
5506 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5508 INT i;
5509 INT nNewHotItem = infoPtr->nHotItem;
5511 for (i = 0; i < infoPtr->nNumButtons; i++)
5513 /* did we wrap? */
5514 if ((nNewHotItem + iDirection < 0) ||
5515 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5517 NMTBWRAPHOTITEM nmtbwhi;
5518 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5519 nmtbwhi.iDirection = iDirection;
5520 nmtbwhi.dwReason = dwReason;
5522 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5523 return;
5526 nNewHotItem += iDirection;
5527 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5529 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5530 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5532 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5533 break;
5538 static LRESULT
5539 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5541 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5542 NMKEY nmkey;
5544 nmkey.nVKey = (UINT)wParam;
5545 nmkey.uFlags = HIWORD(lParam);
5547 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5548 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5550 switch ((UINT)wParam)
5552 case VK_LEFT:
5553 case VK_UP:
5554 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5555 break;
5556 case VK_RIGHT:
5557 case VK_DOWN:
5558 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5559 break;
5560 case VK_SPACE:
5561 case VK_RETURN:
5562 if ((infoPtr->nHotItem >= 0) &&
5563 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5565 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5566 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5567 (LPARAM)hwnd);
5569 break;
5572 return 0;
5576 static LRESULT
5577 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5579 POINT pt;
5580 INT nHit;
5582 pt.x = (short)LOWORD(lParam);
5583 pt.y = (short)HIWORD(lParam);
5584 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5586 if (nHit >= 0)
5587 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5588 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5589 TOOLBAR_Customize (hwnd);
5591 return 0;
5595 static LRESULT
5596 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5598 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5599 TBUTTON_INFO *btnPtr;
5600 POINT pt;
5601 INT nHit;
5602 NMTOOLBARA nmtb;
5603 NMMOUSE nmmouse;
5604 BOOL bDragKeyPressed;
5606 TRACE("\n");
5608 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5609 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5610 else
5611 bDragKeyPressed = (wParam & MK_SHIFT);
5613 if (infoPtr->hwndToolTip)
5614 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5615 WM_LBUTTONDOWN, wParam, lParam);
5617 pt.x = (short)LOWORD(lParam);
5618 pt.y = (short)HIWORD(lParam);
5619 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5621 btnPtr = &infoPtr->buttons[nHit];
5623 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5625 infoPtr->nButtonDrag = nHit;
5626 SetCapture (hwnd);
5628 /* If drag cursor has not been loaded, load it.
5629 * Note: it doesn't need to be freed */
5630 if (!hCursorDrag)
5631 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5632 SetCursor(hCursorDrag);
5634 else if (nHit >= 0)
5636 RECT arrowRect;
5637 infoPtr->nOldHit = nHit;
5639 CopyRect(&arrowRect, &btnPtr->rect);
5640 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5642 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5643 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5644 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5645 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5646 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5647 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5649 LRESULT res;
5651 /* draw in pressed state */
5652 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5653 btnPtr->fsState |= TBSTATE_PRESSED;
5654 else
5655 btnPtr->bDropDownPressed = TRUE;
5656 RedrawWindow(hwnd,&btnPtr->rect,0,
5657 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5659 memset(&nmtb, 0, sizeof(nmtb));
5660 nmtb.iItem = btnPtr->idCommand;
5661 nmtb.rcButton = btnPtr->rect;
5662 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5663 TBN_DROPDOWN);
5664 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5666 if (res != TBDDRET_TREATPRESSED)
5668 MSG msg;
5670 /* redraw button in unpressed state */
5671 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5672 btnPtr->fsState &= ~TBSTATE_PRESSED;
5673 else
5674 btnPtr->bDropDownPressed = FALSE;
5675 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5677 /* find and set hot item
5678 * NOTE: native doesn't do this, but that is a bug */
5679 GetCursorPos(&pt);
5680 ScreenToClient(hwnd, &pt);
5681 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5682 if (!infoPtr->bAnchor || (nHit >= 0))
5683 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5685 /* remove any left mouse button down or double-click messages
5686 * so that we can get a toggle effect on the button */
5687 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5688 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5691 return 0;
5693 /* otherwise drop through and process as pushed */
5695 infoPtr->bCaptured = TRUE;
5696 infoPtr->nButtonDown = nHit;
5697 infoPtr->bDragOutSent = FALSE;
5699 btnPtr->fsState |= TBSTATE_PRESSED;
5701 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5703 if (btnPtr->fsState & TBSTATE_ENABLED)
5704 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5705 UpdateWindow(hwnd);
5706 SetCapture (hwnd);
5709 if (nHit >=0)
5711 memset(&nmtb, 0, sizeof(nmtb));
5712 nmtb.iItem = btnPtr->idCommand;
5713 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5716 nmmouse.dwHitInfo = nHit;
5718 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5719 if (nHit < 0)
5720 nmmouse.dwItemSpec = -1;
5721 else
5723 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5724 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5727 ClientToScreen(hwnd, &pt);
5728 nmmouse.pt = pt;
5730 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5731 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5733 return 0;
5736 static LRESULT
5737 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5739 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5740 TBUTTON_INFO *btnPtr;
5741 POINT pt;
5742 INT nHit;
5743 INT nOldIndex = -1;
5744 BOOL bSendMessage = TRUE;
5745 NMHDR hdr;
5746 NMMOUSE nmmouse;
5747 NMTOOLBARA nmtb;
5749 if (infoPtr->hwndToolTip)
5750 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5751 WM_LBUTTONUP, wParam, lParam);
5753 pt.x = (short)LOWORD(lParam);
5754 pt.y = (short)HIWORD(lParam);
5755 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5757 if (!infoPtr->bAnchor || (nHit >= 0))
5758 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5760 if (infoPtr->nButtonDrag >= 0) {
5761 RECT rcClient;
5762 NMHDR hdr;
5764 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5765 ReleaseCapture();
5766 /* reset cursor */
5767 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5769 GetClientRect(hwnd, &rcClient);
5770 if (PtInRect(&rcClient, pt))
5772 INT nButton = -1;
5773 if (nHit >= 0)
5774 nButton = nHit;
5775 else if (nHit < -1)
5776 nButton = -nHit;
5777 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5778 nButton = -nHit;
5780 if (nButton == infoPtr->nButtonDrag)
5782 /* if the button is moved sightly left and we have a
5783 * separator there then remove it */
5784 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5786 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5787 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5789 else /* else insert a separator before the dragged button */
5791 TBBUTTON tbb;
5792 memset(&tbb, 0, sizeof(tbb));
5793 tbb.fsStyle = BTNS_SEP;
5794 tbb.iString = -1;
5795 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5798 else
5800 if (nButton == -1)
5802 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5803 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5804 else
5805 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5807 else
5808 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5811 else
5813 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5814 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5817 /* button under cursor changed so need to re-set hot item */
5818 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5819 infoPtr->nButtonDrag = -1;
5821 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5823 else if (infoPtr->nButtonDown >= 0) {
5824 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5825 btnPtr->fsState &= ~TBSTATE_PRESSED;
5827 if (btnPtr->fsStyle & BTNS_CHECK) {
5828 if (btnPtr->fsStyle & BTNS_GROUP) {
5829 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5830 nHit);
5831 if (nOldIndex == nHit)
5832 bSendMessage = FALSE;
5833 if ((nOldIndex != nHit) &&
5834 (nOldIndex != -1))
5835 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5836 btnPtr->fsState |= TBSTATE_CHECKED;
5838 else {
5839 if (btnPtr->fsState & TBSTATE_CHECKED)
5840 btnPtr->fsState &= ~TBSTATE_CHECKED;
5841 else
5842 btnPtr->fsState |= TBSTATE_CHECKED;
5846 if (nOldIndex != -1)
5847 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5850 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5851 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5852 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5854 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5855 ReleaseCapture ();
5856 infoPtr->nButtonDown = -1;
5858 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5859 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5860 NM_RELEASEDCAPTURE);
5862 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5863 * TBN_BEGINDRAG
5865 memset(&nmtb, 0, sizeof(nmtb));
5866 nmtb.iItem = btnPtr->idCommand;
5867 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5868 TBN_ENDDRAG);
5870 if (btnPtr->fsState & TBSTATE_ENABLED)
5872 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5873 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5877 /* !!! Undocumented - toolbar at 4.71 level and above sends
5878 * NM_CLICK with the NMMOUSE structure. */
5879 nmmouse.dwHitInfo = nHit;
5881 if (nHit < 0)
5882 nmmouse.dwItemSpec = -1;
5883 else
5885 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5886 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5889 ClientToScreen(hwnd, &pt);
5890 nmmouse.pt = pt;
5892 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5893 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5895 return 0;
5898 static LRESULT
5899 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5901 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5902 INT nHit;
5903 NMMOUSE nmmouse;
5904 POINT pt;
5906 pt.x = (short)LOWORD(lParam);
5907 pt.y = (short)HIWORD(lParam);
5909 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5910 nmmouse.dwHitInfo = nHit;
5912 if (nHit < 0) {
5913 nmmouse.dwItemSpec = -1;
5914 } 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_RCLICK))
5923 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5925 return 0;
5928 static LRESULT
5929 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5931 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5932 NMHDR nmhdr;
5934 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5935 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5937 return 0;
5940 static LRESULT
5941 TOOLBAR_CaptureChanged(HWND hwnd)
5943 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5944 TBUTTON_INFO *btnPtr;
5946 infoPtr->bCaptured = FALSE;
5948 if (infoPtr->nButtonDown >= 0)
5950 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5951 btnPtr->fsState &= ~TBSTATE_PRESSED;
5953 infoPtr->nOldHit = -1;
5955 if (btnPtr->fsState & TBSTATE_ENABLED)
5956 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5958 return 0;
5961 static LRESULT
5962 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5964 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5966 /* don't remove hot effects when in anchor highlighting mode or when a
5967 * drop-down button is pressed */
5968 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
5970 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5971 if (!hotBtnPtr->bDropDownPressed)
5972 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
5975 if (infoPtr->nOldHit < 0)
5976 return TRUE;
5978 /* If the last button we were over is depressed then make it not */
5979 /* depressed and redraw it */
5980 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5982 TBUTTON_INFO *btnPtr;
5983 RECT rc1;
5985 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5987 btnPtr->fsState &= ~TBSTATE_PRESSED;
5989 rc1 = btnPtr->rect;
5990 InflateRect (&rc1, 1, 1);
5991 InvalidateRect (hwnd, &rc1, TRUE);
5994 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
5996 NMTOOLBARW nmt;
5997 ZeroMemory(&nmt, sizeof(nmt));
5998 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5999 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6000 infoPtr->bDragOutSent = TRUE;
6003 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6005 return TRUE;
6008 static LRESULT
6009 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6011 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6012 POINT pt;
6013 TRACKMOUSEEVENT trackinfo;
6014 INT nHit;
6015 TBUTTON_INFO *btnPtr;
6017 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6018 TOOLBAR_TooltipCreateControl(infoPtr);
6020 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6021 /* fill in the TRACKMOUSEEVENT struct */
6022 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6023 trackinfo.dwFlags = TME_QUERY;
6025 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6026 _TrackMouseEvent(&trackinfo);
6028 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6029 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6030 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6031 trackinfo.hwndTrack = hwnd;
6033 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6034 /* and can properly deactivate the hot toolbar button */
6035 _TrackMouseEvent(&trackinfo);
6039 if (infoPtr->hwndToolTip)
6040 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6041 WM_MOUSEMOVE, wParam, lParam);
6043 pt.x = (short)LOWORD(lParam);
6044 pt.y = (short)HIWORD(lParam);
6046 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6048 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6049 && (!infoPtr->bAnchor || (nHit >= 0)))
6050 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6052 if (infoPtr->nOldHit != nHit)
6054 if (infoPtr->bCaptured)
6056 if (!infoPtr->bDragOutSent)
6058 NMTOOLBARW nmt;
6059 ZeroMemory(&nmt, sizeof(nmt));
6060 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6061 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6062 infoPtr->bDragOutSent = TRUE;
6065 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6066 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6067 btnPtr->fsState &= ~TBSTATE_PRESSED;
6068 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6070 else if (nHit == infoPtr->nButtonDown) {
6071 btnPtr->fsState |= TBSTATE_PRESSED;
6072 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6074 infoPtr->nOldHit = nHit;
6078 return 0;
6082 inline static LRESULT
6083 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6085 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6086 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6087 /* else */
6088 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6092 inline static LRESULT
6093 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6095 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6096 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6098 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6102 static LRESULT
6103 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6105 TOOLBAR_INFO *infoPtr;
6106 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6107 DWORD styleadd = 0;
6109 /* allocate memory for info structure */
6110 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6111 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6113 /* paranoid!! */
6114 infoPtr->dwStructSize = sizeof(TBBUTTON);
6115 infoPtr->nRows = 1;
6116 infoPtr->nWidth = 0;
6118 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6119 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6120 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6121 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6124 /* native control does:
6125 * Get a lot of colors and brushes
6126 * WM_NOTIFYFORMAT
6127 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6128 * CreateFontIndirectW(adr1)
6129 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6130 * hdc = GetDC(toolbar)
6131 * GetSystemMetrics(0x48)
6132 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6133 * 0, 0, 0, 0, "MARLETT")
6134 * oldfnt = SelectObject(hdc, fnt2)
6135 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6136 * GetTextMetricsW(hdc, adr3)
6137 * SelectObject(hdc, oldfnt)
6138 * DeleteObject(fnt2)
6139 * ReleaseDC(hdc)
6140 * InvalidateRect(toolbar, 0, 1)
6141 * SetWindowLongW(toolbar, 0, addr)
6142 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6143 * WM_STYLECHANGING
6144 * CallWinEx old new
6145 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6146 * ie 2 0x4600094c 0x4600094c 0x4600894d
6147 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6148 * rebar 0x50008844 0x40008844 0x50008845
6149 * pager 0x50000844 0x40000844 0x50008845
6150 * IC35mgr 0x5400084e **nochange**
6151 * on entry to _NCCREATE 0x5400084e
6152 * rowlist 0x5400004e **nochange**
6153 * on entry to _NCCREATE 0x5400004e
6157 /* I think the code below is a bug, but it is the way that the native
6158 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6159 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6160 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6161 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6162 * Somehow, the only cases of this seem to be MFC programs.
6164 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6165 * does not occur in the WM_STYLECHANGING routine.
6166 * (Guy Albertelli 9/2001)
6169 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6170 && !(cs->style & TBSTYLE_TRANSPARENT))
6171 styleadd |= TBSTYLE_TRANSPARENT;
6172 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6173 styleadd |= CCS_TOP; /* default to top */
6174 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6177 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6181 static LRESULT
6182 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6184 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6185 RECT rcWindow;
6186 HDC hdc;
6188 if (dwStyle & WS_MINIMIZE)
6189 return 0; /* Nothing to do */
6191 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6193 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6194 return 0;
6196 if (!(dwStyle & CCS_NODIVIDER))
6198 GetWindowRect (hwnd, &rcWindow);
6199 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6200 if( dwStyle & WS_BORDER )
6201 OffsetRect (&rcWindow, 1, 1);
6202 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6205 ReleaseDC( hwnd, hdc );
6207 return 0;
6211 /* handles requests from the tooltip control on what text to display */
6212 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6214 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6216 TRACE("button index = %d\n", index);
6218 Free (infoPtr->pszTooltipText);
6219 infoPtr->pszTooltipText = NULL;
6221 if (index < 0)
6222 return 0;
6224 if (infoPtr->bUnicode)
6226 WCHAR wszBuffer[INFOTIPSIZE+1];
6227 NMTBGETINFOTIPW tbgit;
6228 unsigned int len; /* in chars */
6230 wszBuffer[0] = '\0';
6231 wszBuffer[INFOTIPSIZE] = '\0';
6233 tbgit.pszText = wszBuffer;
6234 tbgit.cchTextMax = INFOTIPSIZE;
6235 tbgit.iItem = lpnmtdi->hdr.idFrom;
6236 tbgit.lParam = infoPtr->buttons[index].dwData;
6238 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6240 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6242 len = strlenW(tbgit.pszText);
6243 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6245 /* need to allocate temporary buffer in infoPtr as there
6246 * isn't enough space in buffer passed to us by the
6247 * tooltip control */
6248 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6249 if (infoPtr->pszTooltipText)
6251 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6252 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6253 return 0;
6256 else if (len > 0)
6258 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6259 return 0;
6262 else
6264 CHAR szBuffer[INFOTIPSIZE+1];
6265 NMTBGETINFOTIPA tbgit;
6266 unsigned int len; /* in chars */
6268 szBuffer[0] = '\0';
6269 szBuffer[INFOTIPSIZE] = '\0';
6271 tbgit.pszText = szBuffer;
6272 tbgit.cchTextMax = INFOTIPSIZE;
6273 tbgit.iItem = lpnmtdi->hdr.idFrom;
6274 tbgit.lParam = infoPtr->buttons[index].dwData;
6276 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6278 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6280 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6281 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6283 /* need to allocate temporary buffer in infoPtr as there
6284 * isn't enough space in buffer passed to us by the
6285 * tooltip control */
6286 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6287 if (infoPtr->pszTooltipText)
6289 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6290 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6291 return 0;
6294 else if (len > 0)
6296 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6297 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6298 return 0;
6302 /* if button has text, but it is not shown then automatically
6303 * use that text as tooltip */
6304 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6305 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6307 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6308 unsigned int len = pszText ? strlenW(pszText) : 0;
6310 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6312 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6314 /* need to allocate temporary buffer in infoPtr as there
6315 * isn't enough space in buffer passed to us by the
6316 * tooltip control */
6317 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6318 if (infoPtr->pszTooltipText)
6320 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6321 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6322 return 0;
6325 else if (len > 0)
6327 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6328 return 0;
6332 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6334 /* last resort: send notification on to app */
6335 /* FIXME: find out what is really used here */
6336 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6340 inline static LRESULT
6341 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6343 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6344 LPNMHDR lpnmh = (LPNMHDR)lParam;
6346 switch (lpnmh->code)
6348 case PGN_CALCSIZE:
6350 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6352 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6353 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6354 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6355 lppgc->iWidth);
6357 else {
6358 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6359 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6360 lppgc->iHeight);
6362 return 0;
6365 case PGN_SCROLL:
6367 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6369 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6370 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6371 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6372 lppgs->iScroll, lppgs->iDir);
6373 return 0;
6376 case TTN_GETDISPINFOW:
6377 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6379 case TTN_GETDISPINFOA:
6380 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6381 return 0;
6383 default:
6384 return 0;
6389 static LRESULT
6390 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6392 LRESULT format;
6394 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6396 if (lParam == NF_QUERY)
6397 return NFR_UNICODE;
6399 if (lParam == NF_REQUERY) {
6400 format = SendMessageW(infoPtr->hwndNotify,
6401 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6402 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6403 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6404 format);
6405 format = NFR_ANSI;
6407 return format;
6409 return 0;
6413 static LRESULT
6414 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6416 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6417 HDC hdc;
6418 PAINTSTRUCT ps;
6420 /* fill ps.rcPaint with a default rect */
6421 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6423 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6425 TRACE("psrect=(%d,%d)-(%d,%d)\n",
6426 ps.rcPaint.left, ps.rcPaint.top,
6427 ps.rcPaint.right, ps.rcPaint.bottom);
6429 TOOLBAR_Refresh (hwnd, hdc, &ps);
6430 if (!wParam) EndPaint (hwnd, &ps);
6432 return 0;
6436 static LRESULT
6437 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6439 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6441 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6443 /* make first item hot */
6444 if (infoPtr->nNumButtons > 0)
6445 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6447 return 0;
6450 static LRESULT
6451 TOOLBAR_SetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
6453 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6455 TRACE("font=%p redraw=%ld\n", (HFONT)wParam, lParam);
6457 if (wParam == 0)
6458 infoPtr->hFont = infoPtr->hDefaultFont;
6459 else
6460 infoPtr->hFont = (HFONT)wParam;
6462 TOOLBAR_CalcToolbar(hwnd);
6464 if (lParam)
6465 InvalidateRect(hwnd, NULL, TRUE);
6466 return 1;
6469 static LRESULT
6470 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6471 /*****************************************************
6473 * Function;
6474 * Handles the WM_SETREDRAW message.
6476 * Documentation:
6477 * According to testing V4.71 of COMCTL32 returns the
6478 * *previous* status of the redraw flag (either 0 or 1)
6479 * instead of the MSDN documented value of 0 if handled.
6480 * (For laughs see the "consistency" with same function
6481 * in rebar.)
6483 *****************************************************/
6485 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6486 BOOL oldredraw = infoPtr->bDoRedraw;
6488 TRACE("set to %s\n",
6489 (wParam) ? "TRUE" : "FALSE");
6490 infoPtr->bDoRedraw = (BOOL) wParam;
6491 if (wParam) {
6492 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6494 return (oldredraw) ? 1 : 0;
6498 static LRESULT
6499 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6501 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6503 TRACE("sizing toolbar!\n");
6505 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6507 RECT delta_width, delta_height, client, dummy;
6508 DWORD min_x, max_x, min_y, max_y;
6509 TBUTTON_INFO *btnPtr;
6510 INT i;
6512 GetClientRect(hwnd, &client);
6513 if(client.right > infoPtr->client_rect.right)
6515 min_x = infoPtr->client_rect.right;
6516 max_x = client.right;
6518 else
6520 max_x = infoPtr->client_rect.right;
6521 min_x = client.right;
6523 if(client.bottom > infoPtr->client_rect.bottom)
6525 min_y = infoPtr->client_rect.bottom;
6526 max_y = client.bottom;
6528 else
6530 max_y = infoPtr->client_rect.bottom;
6531 min_y = client.bottom;
6534 SetRect(&delta_width, min_x, 0, max_x, min_y);
6535 SetRect(&delta_height, 0, min_y, max_x, max_y);
6537 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6538 btnPtr = infoPtr->buttons;
6539 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6540 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6541 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6542 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6544 GetClientRect(hwnd, &infoPtr->client_rect);
6545 TOOLBAR_AutoSize(hwnd);
6546 return 0;
6550 static LRESULT
6551 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6553 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6555 if (nType == GWL_STYLE)
6557 DWORD dwOldStyle = infoPtr->dwStyle;
6559 if (lpStyle->styleNew & TBSTYLE_LIST)
6560 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6561 else
6562 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6564 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6566 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6568 infoPtr->dwStyle = lpStyle->styleNew;
6570 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6571 TOOLBAR_LayoutToolbar(hwnd);
6573 /* only resize if one of the CCS_* styles was changed */
6574 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6576 TOOLBAR_AutoSize (hwnd);
6578 InvalidateRect(hwnd, NULL, TRUE);
6582 return 0;
6586 static LRESULT
6587 TOOLBAR_SysColorChange (HWND hwnd)
6589 COMCTL32_RefreshSysColors();
6591 return 0;
6595 /* update theme after a WM_THEMECHANGED message */
6596 static LRESULT theme_changed (HWND hwnd)
6598 HTHEME theme = GetWindowTheme (hwnd);
6599 CloseThemeData (theme);
6600 OpenThemeData (hwnd, themeClass);
6601 return 0;
6605 static LRESULT WINAPI
6606 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6608 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6610 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6611 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6613 if (!infoPtr && (uMsg != WM_NCCREATE))
6614 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6616 switch (uMsg)
6618 case TB_ADDBITMAP:
6619 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6621 case TB_ADDBUTTONSA:
6622 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6624 case TB_ADDBUTTONSW:
6625 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6627 case TB_ADDSTRINGA:
6628 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6630 case TB_ADDSTRINGW:
6631 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6633 case TB_AUTOSIZE:
6634 return TOOLBAR_AutoSize (hwnd);
6636 case TB_BUTTONCOUNT:
6637 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6639 case TB_BUTTONSTRUCTSIZE:
6640 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6642 case TB_CHANGEBITMAP:
6643 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6645 case TB_CHECKBUTTON:
6646 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6648 case TB_COMMANDTOINDEX:
6649 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6651 case TB_CUSTOMIZE:
6652 return TOOLBAR_Customize (hwnd);
6654 case TB_DELETEBUTTON:
6655 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6657 case TB_ENABLEBUTTON:
6658 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6660 case TB_GETANCHORHIGHLIGHT:
6661 return TOOLBAR_GetAnchorHighlight (hwnd);
6663 case TB_GETBITMAP:
6664 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6666 case TB_GETBITMAPFLAGS:
6667 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6669 case TB_GETBUTTON:
6670 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6672 case TB_GETBUTTONINFOA:
6673 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6675 case TB_GETBUTTONINFOW:
6676 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6678 case TB_GETBUTTONSIZE:
6679 return TOOLBAR_GetButtonSize (hwnd);
6681 case TB_GETBUTTONTEXTA:
6682 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6684 case TB_GETBUTTONTEXTW:
6685 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6687 case TB_GETDISABLEDIMAGELIST:
6688 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6690 case TB_GETEXTENDEDSTYLE:
6691 return TOOLBAR_GetExtendedStyle (hwnd);
6693 case TB_GETHOTIMAGELIST:
6694 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6696 case TB_GETHOTITEM:
6697 return TOOLBAR_GetHotItem (hwnd);
6699 case TB_GETIMAGELIST:
6700 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6702 case TB_GETINSERTMARK:
6703 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6705 case TB_GETINSERTMARKCOLOR:
6706 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6708 case TB_GETITEMRECT:
6709 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6711 case TB_GETMAXSIZE:
6712 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6714 /* case TB_GETOBJECT: */ /* 4.71 */
6716 case TB_GETPADDING:
6717 return TOOLBAR_GetPadding (hwnd);
6719 case TB_GETRECT:
6720 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6722 case TB_GETROWS:
6723 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6725 case TB_GETSTATE:
6726 return TOOLBAR_GetState (hwnd, wParam, lParam);
6728 case TB_GETSTRINGA:
6729 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6731 case TB_GETSTRINGW:
6732 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6734 case TB_GETSTYLE:
6735 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6737 case TB_GETTEXTROWS:
6738 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6740 case TB_GETTOOLTIPS:
6741 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6743 case TB_GETUNICODEFORMAT:
6744 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6746 case TB_HIDEBUTTON:
6747 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6749 case TB_HITTEST:
6750 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6752 case TB_INDETERMINATE:
6753 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6755 case TB_INSERTBUTTONA:
6756 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6758 case TB_INSERTBUTTONW:
6759 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6761 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6763 case TB_ISBUTTONCHECKED:
6764 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6766 case TB_ISBUTTONENABLED:
6767 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6769 case TB_ISBUTTONHIDDEN:
6770 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6772 case TB_ISBUTTONHIGHLIGHTED:
6773 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6775 case TB_ISBUTTONINDETERMINATE:
6776 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6778 case TB_ISBUTTONPRESSED:
6779 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6781 case TB_LOADIMAGES:
6782 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6784 case TB_MAPACCELERATORA:
6785 case TB_MAPACCELERATORW:
6786 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6788 case TB_MARKBUTTON:
6789 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6791 case TB_MOVEBUTTON:
6792 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6794 case TB_PRESSBUTTON:
6795 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6797 case TB_REPLACEBITMAP:
6798 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6800 case TB_SAVERESTOREA:
6801 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6803 case TB_SAVERESTOREW:
6804 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6806 case TB_SETANCHORHIGHLIGHT:
6807 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6809 case TB_SETBITMAPSIZE:
6810 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6812 case TB_SETBUTTONINFOA:
6813 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6815 case TB_SETBUTTONINFOW:
6816 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6818 case TB_SETBUTTONSIZE:
6819 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6821 case TB_SETBUTTONWIDTH:
6822 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6824 case TB_SETCMDID:
6825 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6827 case TB_SETDISABLEDIMAGELIST:
6828 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6830 case TB_SETDRAWTEXTFLAGS:
6831 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6833 case TB_SETEXTENDEDSTYLE:
6834 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6836 case TB_SETHOTIMAGELIST:
6837 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6839 case TB_SETHOTITEM:
6840 return TOOLBAR_SetHotItem (hwnd, wParam);
6842 case TB_SETIMAGELIST:
6843 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6845 case TB_SETINDENT:
6846 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6848 case TB_SETINSERTMARK:
6849 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6851 case TB_SETINSERTMARKCOLOR:
6852 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6854 case TB_SETMAXTEXTROWS:
6855 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6857 case TB_SETPADDING:
6858 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6860 case TB_SETPARENT:
6861 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6863 case TB_SETROWS:
6864 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6866 case TB_SETSTATE:
6867 return TOOLBAR_SetState (hwnd, wParam, lParam);
6869 case TB_SETSTYLE:
6870 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6872 case TB_SETTOOLTIPS:
6873 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6875 case TB_SETUNICODEFORMAT:
6876 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6878 case TB_UNKWN45D:
6879 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6881 case TB_UNKWN45E:
6882 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6884 case TB_UNKWN460:
6885 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6887 case TB_UNKWN462:
6888 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6890 case TB_UNKWN463:
6891 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6893 case TB_UNKWN464:
6894 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6896 /* Common Control Messages */
6898 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6899 case CCM_GETCOLORSCHEME:
6900 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6902 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6903 case CCM_SETCOLORSCHEME:
6904 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6906 case CCM_GETVERSION:
6907 return TOOLBAR_GetVersion (hwnd);
6909 case CCM_SETVERSION:
6910 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6913 /* case WM_CHAR: */
6915 case WM_CREATE:
6916 return TOOLBAR_Create (hwnd, wParam, lParam);
6918 case WM_DESTROY:
6919 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6921 case WM_ERASEBKGND:
6922 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6924 case WM_GETFONT:
6925 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6927 case WM_KEYDOWN:
6928 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6930 /* case WM_KILLFOCUS: */
6932 case WM_LBUTTONDBLCLK:
6933 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6935 case WM_LBUTTONDOWN:
6936 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6938 case WM_LBUTTONUP:
6939 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6941 case WM_RBUTTONUP:
6942 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6944 case WM_RBUTTONDBLCLK:
6945 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6947 case WM_MOUSEMOVE:
6948 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6950 case WM_MOUSELEAVE:
6951 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6953 case WM_CAPTURECHANGED:
6954 return TOOLBAR_CaptureChanged(hwnd);
6956 case WM_NCACTIVATE:
6957 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6959 case WM_NCCALCSIZE:
6960 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6962 case WM_NCCREATE:
6963 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6965 case WM_NCPAINT:
6966 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6968 case WM_NOTIFY:
6969 return TOOLBAR_Notify (hwnd, wParam, lParam);
6971 case WM_NOTIFYFORMAT:
6972 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
6974 case WM_PRINTCLIENT:
6975 case WM_PAINT:
6976 return TOOLBAR_Paint (hwnd, wParam);
6978 case WM_SETFOCUS:
6979 return TOOLBAR_SetFocus (hwnd, wParam);
6981 case WM_SETFONT:
6982 return TOOLBAR_SetFont(hwnd, wParam, lParam);
6984 case WM_SETREDRAW:
6985 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6987 case WM_SIZE:
6988 return TOOLBAR_Size (hwnd, wParam, lParam);
6990 case WM_STYLECHANGED:
6991 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6993 case WM_SYSCOLORCHANGE:
6994 return TOOLBAR_SysColorChange (hwnd);
6996 case WM_THEMECHANGED:
6997 return theme_changed (hwnd);
6999 /* case WM_WININICHANGE: */
7001 case WM_CHARTOITEM:
7002 case WM_COMMAND:
7003 case WM_DRAWITEM:
7004 case WM_MEASUREITEM:
7005 case WM_VKEYTOITEM:
7006 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7008 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7009 case PGM_FORWARDMOUSE:
7010 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7012 default:
7013 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7014 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7015 uMsg, wParam, lParam);
7016 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7021 VOID
7022 TOOLBAR_Register (void)
7024 WNDCLASSW wndClass;
7026 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7027 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7028 wndClass.lpfnWndProc = ToolbarWindowProc;
7029 wndClass.cbClsExtra = 0;
7030 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7031 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7032 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7033 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7035 RegisterClassW (&wndClass);
7039 VOID
7040 TOOLBAR_Unregister (void)
7042 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7045 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7047 HIMAGELIST himlold;
7048 PIMLENTRY c = NULL;
7050 /* Check if the entry already exists */
7051 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7053 /* If this is a new entry we must create it and insert into the array */
7054 if (!c)
7056 PIMLENTRY *pnies;
7058 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7059 c->id = id;
7061 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7062 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7063 pnies[*cies] = c;
7064 (*cies)++;
7066 Free(*pies);
7067 *pies = pnies;
7070 himlold = c->himl;
7071 c->himl = himl;
7073 return himlold;
7077 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7079 int i;
7081 for (i = 0; i < *cies; i++)
7082 Free((*pies)[i]);
7084 Free(*pies);
7086 *cies = 0;
7087 *pies = NULL;
7091 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7093 PIMLENTRY c = NULL;
7095 if (pies != NULL)
7097 int i;
7099 for (i = 0; i < cies; i++)
7101 if (pies[i]->id == id)
7103 c = pies[i];
7104 break;
7109 return c;
7113 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7115 HIMAGELIST himlDef = 0;
7116 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7118 if (pie)
7119 himlDef = pie->himl;
7121 return himlDef;
7125 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7127 if (infoPtr->bUnicode)
7128 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7129 else
7131 CHAR Buffer[256];
7132 NMTOOLBARA nmtba;
7133 BOOL bRet = FALSE;
7135 nmtba.iItem = nmtb->iItem;
7136 nmtba.pszText = Buffer;
7137 nmtba.cchText = 256;
7138 ZeroMemory(nmtba.pszText, nmtba.cchText);
7140 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7142 int ccht = strlen(nmtba.pszText);
7143 if (ccht)
7144 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7145 nmtb->pszText, nmtb->cchText);
7147 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7148 bRet = TRUE;
7151 return bRet;
7156 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7157 int iItem, PCUSTOMBUTTON btnInfo)
7159 NMTOOLBARW nmtb;
7161 /* MSDN states that iItem is the index of the button, rather than the
7162 * command ID as used by every other NMTOOLBAR notification */
7163 nmtb.iItem = iItem;
7164 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7166 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);