Add support for proper saving of the "FLATMENU" and "GRADIENTCAPION"
[wine/dcerpc.git] / dlls / comctl32 / toolbar.c
blobcd8c0b432488bfe13234c3890621c98ed6eb2bba
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 * - NM_KEYDOWN
45 * - TBN_GETOBJECT
46 * - TBN_SAVE
47 * - Button wrapping (under construction).
48 * - Fix TB_SETROWS.
49 * - iListGap custom draw support.
51 * Testing:
52 * - Run tests using Waite Group Windows95 API Bible Volume 2.
53 * The second cdrom contains executables addstr.exe, btncount.exe,
54 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
55 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
56 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
57 * setparnt.exe, setrows.exe, toolwnd.exe.
58 * - Microsoft's controlspy examples.
59 * - Charles Petzold's 'Programming Windows': gadgets.exe
61 * Differences between MSDN and actual native control operation:
62 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
63 * to the right of the bitmap. Otherwise, this style is
64 * identical to TBSTYLE_FLAT."
65 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
66 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
67 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
68 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
72 #include <stdarg.h>
73 #include <string.h>
75 #include "windef.h"
76 #include "winbase.h"
77 #include "winreg.h"
78 #include "wingdi.h"
79 #include "winuser.h"
80 #include "wine/unicode.h"
81 #include "winnls.h"
82 #include "commctrl.h"
83 #include "comctl32.h"
84 #include "wine/debug.h"
86 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
88 static HCURSOR hCursorDrag = NULL;
90 typedef struct
92 INT iBitmap;
93 INT idCommand;
94 BYTE fsState;
95 BYTE fsStyle;
96 BYTE bHot;
97 BYTE bDropDownPressed;
98 DWORD dwData;
99 INT iString;
100 INT nRow;
101 RECT rect;
102 INT cx; /* manually set size */
103 } TBUTTON_INFO;
105 typedef struct
107 UINT nButtons;
108 HINSTANCE hInst;
109 UINT nID;
110 } TBITMAP_INFO;
112 typedef struct
114 HIMAGELIST himl;
115 INT id;
116 } IMLENTRY, *PIMLENTRY;
118 typedef struct
120 DWORD dwStructSize; /* size of TBBUTTON struct */
121 INT nHeight; /* height of the toolbar */
122 INT nWidth; /* width of the toolbar */
123 RECT client_rect;
124 RECT rcBound; /* bounding rectangle */
125 INT nButtonHeight;
126 INT nButtonWidth;
127 INT nBitmapHeight;
128 INT nBitmapWidth;
129 INT nIndent;
130 INT nRows; /* number of button rows */
131 INT nMaxTextRows; /* maximum number of text rows */
132 INT cxMin; /* minimum button width */
133 INT cxMax; /* maximum button width */
134 INT nNumButtons; /* number of buttons */
135 INT nNumBitmaps; /* number of bitmaps */
136 INT nNumStrings; /* number of strings */
137 INT nNumBitmapInfos;
138 INT nButtonDown; /* toolbar button being pressed or -1 if none */
139 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
140 INT nOldHit;
141 INT nHotItem; /* index of the "hot" item */
142 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
143 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
144 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
145 SIZE szPadding; /* padding values around button */
146 INT iListGap; /* default gap between text and image for toolbar with list style */
147 HFONT hDefaultFont;
148 HFONT hFont; /* text font */
149 HIMAGELIST himlInt; /* image list created internally */
150 PIMLENTRY *himlDef; /* default image list array */
151 INT cimlDef; /* default image list array count */
152 PIMLENTRY *himlHot; /* hot image list array */
153 INT cimlHot; /* hot image list array count */
154 PIMLENTRY *himlDis; /* disabled image list array */
155 INT cimlDis; /* disabled image list array count */
156 HWND hwndToolTip; /* handle to tool tip control */
157 HWND hwndNotify; /* handle to the window that gets notifications */
158 HWND hwndSelf; /* my own handle */
159 BOOL bBtnTranspnt; /* button transparency flag */
160 BOOL bAutoSize; /* auto size deadlock indicator */
161 BOOL bAnchor; /* anchor highlight enabled */
162 BOOL bDoRedraw; /* Redraw status */
163 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
164 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
165 BOOL bCaptured; /* mouse captured? */
166 DWORD dwStyle; /* regular toolbar style */
167 DWORD dwExStyle; /* extended toolbar style */
168 DWORD dwDTFlags; /* DrawText flags */
170 COLORREF clrInsertMark; /* insert mark color */
171 COLORREF clrBtnHighlight; /* color for Flat Separator */
172 COLORREF clrBtnShadow; /* color for Flag Separator */
173 INT iVersion;
174 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
175 * for TTN_GETDISPINFOW notification */
176 TBINSERTMARK tbim; /* info on insertion mark */
177 TBUTTON_INFO *buttons; /* pointer to button array */
178 LPWSTR *strings; /* pointer to string array */
179 TBITMAP_INFO *bitmaps;
180 } TOOLBAR_INFO, *PTOOLBAR_INFO;
183 /* used by customization dialog */
184 typedef struct
186 PTOOLBAR_INFO tbInfo;
187 HWND tbHwnd;
188 } CUSTDLG_INFO, *PCUSTDLG_INFO;
190 typedef struct
192 TBBUTTON btn;
193 BOOL bVirtual;
194 BOOL bRemovable;
195 WCHAR text[64];
196 } CUSTOMBUTTON, *PCUSTOMBUTTON;
198 typedef enum
200 IMAGE_LIST_DEFAULT,
201 IMAGE_LIST_HOT,
202 IMAGE_LIST_DISABLED
203 } IMAGE_LIST_TYPE;
205 #define SEPARATOR_WIDTH 8
206 #define TOP_BORDER 2
207 #define BOTTOM_BORDER 2
208 #define DDARROW_WIDTH 11
209 #define ARROW_HEIGHT 3
210 #define INSERTMARK_WIDTH 2
212 #define DEFPAD_CX 7
213 #define DEFPAD_CY 6
214 #define DEFLISTGAP 4
216 /* vertical padding used in list mode when image is present */
217 #define LISTPAD_CY 9
219 /* how wide to treat the bitmap if it isn't present */
220 #define NONLIST_NOTEXT_OFFSET 2
222 #define TOOLBAR_NOWHERE (-1)
224 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
225 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
226 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
228 /* Used to find undocumented extended styles */
229 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
230 TBSTYLE_EX_UNDOC1 | \
231 TBSTYLE_EX_MIXEDBUTTONS | \
232 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
234 /* all of the CCS_ styles */
235 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
236 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
238 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
239 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
240 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
241 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
242 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
244 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
245 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
246 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
247 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
248 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
249 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
250 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
251 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
253 static LRESULT
254 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
257 static LPWSTR
258 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
260 LPWSTR lpText = NULL;
262 /* NOTE: iString == -1 is undocumented */
263 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
264 lpText = (LPWSTR)btnPtr->iString;
265 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
266 lpText = infoPtr->strings[btnPtr->iString];
268 return lpText;
271 static void
272 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
274 if (TRACE_ON(toolbar)){
275 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
276 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
277 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
278 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
279 if (internal)
280 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
281 btn_num, bP->idCommand,
282 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
283 bP->rect.left, bP->rect.top,
284 bP->rect.right, bP->rect.bottom);
289 static void
290 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
292 if (TRACE_ON(toolbar)) {
293 INT i;
295 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
296 iP->hwndSelf, line,
297 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
298 iP->nNumStrings, iP->dwStyle);
299 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
300 iP->hwndSelf, line,
301 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
302 (iP->bDoRedraw) ? "TRUE" : "FALSE");
303 for(i=0; i<iP->nNumButtons; i++) {
304 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
310 /***********************************************************************
311 * TOOLBAR_CheckStyle
313 * This function validates that the styles set are implemented and
314 * issues FIXME's warning of possible problems. In a perfect world this
315 * function should be null.
317 static void
318 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
320 if (dwStyle & TBSTYLE_REGISTERDROP)
321 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
325 static INT
326 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
328 if(!IsWindow(infoPtr->hwndSelf))
329 return 0; /* we have just been destroyed */
331 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
332 nmhdr->hwndFrom = infoPtr->hwndSelf;
333 nmhdr->code = code;
335 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
336 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
338 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
339 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
342 /***********************************************************************
343 * TOOLBAR_GetBitmapIndex
345 * This function returns the bitmap index associated with a button.
346 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
347 * is issued to retrieve the index.
349 static INT
350 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
352 INT ret = btnPtr->iBitmap;
354 if (ret == I_IMAGECALLBACK)
356 /* issue TBN_GETDISPINFO */
357 NMTBDISPINFOA nmgd;
359 memset(&nmgd, 0, sizeof(nmgd));
360 nmgd.idCommand = btnPtr->idCommand;
361 nmgd.lParam = btnPtr->dwData;
362 nmgd.dwMask = TBNF_IMAGE;
363 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
364 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
365 if (nmgd.dwMask & TBNF_DI_SETITEM)
366 btnPtr->iBitmap = nmgd.iImage;
367 ret = nmgd.iImage;
368 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
369 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
372 if (ret != I_IMAGENONE)
373 ret = GETIBITMAP(infoPtr, ret);
375 return ret;
379 static BOOL
380 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
382 HIMAGELIST himl;
383 INT id = GETHIMLID(infoPtr, index);
384 INT iBitmap = GETIBITMAP(infoPtr, index);
386 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
387 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
388 (index == I_IMAGECALLBACK))
389 return TRUE;
390 else
391 return FALSE;
395 static inline BOOL
396 TOOLBAR_IsValidImageList(TOOLBAR_INFO *infoPtr, INT index)
398 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
399 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
403 /***********************************************************************
404 * TOOLBAR_GetImageListForDrawing
406 * This function validates the bitmap index (including I_IMAGECALLBACK
407 * functionality) and returns the corresponding image list.
409 static HIMAGELIST
410 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
412 HIMAGELIST himl;
414 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
415 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
416 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
417 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
418 return NULL;
421 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
422 if ((*index == I_IMAGECALLBACK) ||
423 (*index == I_IMAGENONE)) return NULL;
424 ERR("TBN_GETDISPINFO returned invalid index %d\n",
425 *index);
426 return NULL;
429 switch(imagelist)
431 case IMAGE_LIST_DEFAULT:
432 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
433 break;
434 case IMAGE_LIST_HOT:
435 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
436 break;
437 case IMAGE_LIST_DISABLED:
438 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
439 break;
440 default:
441 himl = NULL;
442 FIXME("Shouldn't reach here\n");
445 if (!himl)
446 TRACE("no image list\n");
448 return himl;
452 static void
453 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
455 RECT myrect;
456 COLORREF oldcolor, newcolor;
458 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
459 myrect.right = myrect.left + 1;
460 myrect.top = lpRect->top + 2;
461 myrect.bottom = lpRect->bottom - 2;
463 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
464 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
465 oldcolor = SetBkColor (hdc, newcolor);
466 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
468 myrect.left = myrect.right;
469 myrect.right = myrect.left + 1;
471 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
472 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
473 SetBkColor (hdc, newcolor);
474 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
476 SetBkColor (hdc, oldcolor);
480 /***********************************************************************
481 * TOOLBAR_DrawDDFlatSeparator
483 * This function draws the separator that was flagged as BTNS_DROPDOWN.
484 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
485 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
486 * are horizontal as opposed to the vertical separators for not dropdown
487 * type.
489 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
491 static void
492 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
494 RECT myrect;
495 COLORREF oldcolor, newcolor;
497 myrect.left = lpRect->left;
498 myrect.right = lpRect->right;
499 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
500 myrect.bottom = myrect.top + 1;
502 InflateRect (&myrect, -2, 0);
504 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
505 myrect.left, myrect.top, myrect.right, myrect.bottom);
507 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
508 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
509 oldcolor = SetBkColor (hdc, newcolor);
510 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
512 myrect.top = myrect.bottom;
513 myrect.bottom = myrect.top + 1;
515 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
516 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
517 SetBkColor (hdc, newcolor);
518 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
520 SetBkColor (hdc, oldcolor);
524 static void
525 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
527 INT x, y;
528 HPEN hPen, hOldPen;
530 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
531 hOldPen = SelectObject ( hdc, hPen );
532 x = left + 2;
533 y = top;
534 MoveToEx (hdc, x, y, NULL);
535 LineTo (hdc, x+5, y++); x++;
536 MoveToEx (hdc, x, y, NULL);
537 LineTo (hdc, x+3, y++); x++;
538 MoveToEx (hdc, x, y, NULL);
539 LineTo (hdc, x+1, y++);
540 SelectObject( hdc, hOldPen );
541 DeleteObject( hPen );
545 * Draw the text string for this button.
546 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
547 * is non-zero, so we can simply check himlDef to see if we have
548 * an image list
550 static void
551 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
552 NMTBCUSTOMDRAW *tbcd)
554 HDC hdc = tbcd->nmcd.hdc;
555 HFONT hOldFont = 0;
556 COLORREF clrOld = 0;
557 COLORREF clrOldBk = 0;
558 int oldBkMode = 0;
559 UINT state = tbcd->nmcd.uItemState;
561 /* draw text */
562 if (lpText) {
563 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
564 rcText->left, rcText->top, rcText->right, rcText->bottom);
566 hOldFont = SelectObject (hdc, infoPtr->hFont);
567 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
568 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
570 else if (state & CDIS_DISABLED) {
571 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
572 OffsetRect (rcText, 1, 1);
573 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
574 SetTextColor (hdc, comctl32_color.clr3dShadow);
575 OffsetRect (rcText, -1, -1);
577 else if (state & CDIS_INDETERMINATE) {
578 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
580 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
581 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
582 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
583 oldBkMode = SetBkMode (hdc, OPAQUE); /* FIXME: should this be in the NMTBCUSTOMDRAW structure? */
585 else {
586 clrOld = SetTextColor (hdc, tbcd->clrText);
589 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
590 SetTextColor (hdc, clrOld);
591 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
593 SetBkColor (hdc, clrOldBk);
594 SetBkMode (hdc, oldBkMode);
596 SelectObject (hdc, hOldFont);
601 static void
602 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
604 HDC hdc = tbcd->nmcd.hdc;
605 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
606 COLORREF clrTextOld;
607 COLORREF clrBkOld;
608 INT cx = lpRect->right - lpRect->left;
609 INT cy = lpRect->bottom - lpRect->top;
610 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
611 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
612 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
613 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
614 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
615 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
616 SetBkColor(hdc, clrBkOld);
617 SetTextColor(hdc, clrTextOld);
618 SelectObject (hdc, hbr);
622 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
624 INT cx, cy;
625 HBITMAP hbmMask, hbmImage;
626 HDC hdcMask, hdcImage;
628 ImageList_GetIconSize(himl, &cx, &cy);
630 /* Create src image */
631 hdcImage = CreateCompatibleDC(hdc);
632 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
633 SelectObject(hdcImage, hbmImage);
634 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
635 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
637 /* Create Mask */
638 hdcMask = CreateCompatibleDC(0);
639 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
640 SelectObject(hdcMask, hbmMask);
642 /* Remove the background and all white pixels */
643 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
644 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
645 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
646 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
648 /* draw the new mask 'etched' to hdc */
649 SetBkColor(hdc, RGB(255, 255, 255));
650 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
651 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
652 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
653 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
654 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
656 /* Cleanup */
657 DeleteObject(hbmImage);
658 DeleteDC(hdcImage);
659 DeleteObject (hbmMask);
660 DeleteDC(hdcMask);
664 static UINT
665 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
667 UINT retstate = 0;
669 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
670 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
671 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
672 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
673 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
674 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
675 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
676 return retstate;
679 /* draws the image on a toolbar button */
680 static void
681 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
683 HIMAGELIST himl = NULL;
684 BOOL draw_masked = FALSE;
685 INT index;
686 INT offset = 0;
687 UINT draw_flags = ILD_TRANSPARENT;
689 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
691 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
692 if (!himl)
694 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
695 draw_masked = TRUE;
698 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && (infoPtr->dwStyle & TBSTYLE_FLAT))
700 /* if hot, attempt to draw with hot image list, if fails,
701 use default image list */
702 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
703 if (!himl)
704 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
706 else
707 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
709 if (!himl)
710 return;
712 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
713 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
714 offset = 1;
716 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
717 (tbcd->nmcd.uItemState & CDIS_MARKED))
718 draw_flags |= ILD_BLEND50;
720 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
721 index, himl, left, top, offset);
723 if (draw_masked)
724 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
725 else
726 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
729 /* draws a blank frame for a toolbar button */
730 static void
731 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd)
733 HDC hdc = tbcd->nmcd.hdc;
734 RECT rc = tbcd->nmcd.rc;
735 /* if the state is disabled or indeterminate then the button
736 * cannot have an interactive look like pressed or hot */
737 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
738 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
739 BOOL pressed_look = !non_interactive_state &&
740 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
741 (tbcd->nmcd.uItemState & CDIS_CHECKED));
743 /* app don't want us to draw any edges */
744 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
745 return;
747 if (infoPtr->dwStyle & TBSTYLE_FLAT)
749 if (pressed_look)
750 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
751 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
752 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
754 else
756 if (pressed_look)
757 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
758 else
759 DrawEdge (hdc, &rc, EDGE_RAISED,
760 BF_SOFT | BF_RECT | BF_MIDDLE);
764 static void
765 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed)
767 HDC hdc = tbcd->nmcd.hdc;
768 int offset = 0;
769 BOOL pressed = bDropDownPressed ||
770 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
772 if (infoPtr->dwStyle & TBSTYLE_FLAT)
774 if (pressed)
775 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
776 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
777 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
778 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
779 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
781 else
783 if (pressed)
784 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
785 else
786 DrawEdge (hdc, rcArrow, EDGE_RAISED,
787 BF_SOFT | BF_RECT | BF_MIDDLE);
790 if (pressed)
791 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
793 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
795 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
796 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
798 else
799 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
802 /* draws a complete toolbar button */
803 static void
804 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
806 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
807 DWORD dwStyle = infoPtr->dwStyle;
808 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
809 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
810 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
811 BOOL drawSepDropDownArrow = hasDropDownArrow &&
812 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
813 RECT rc, rcArrow, rcBitmap, rcText;
814 LPWSTR lpText = NULL;
815 NMTBCUSTOMDRAW tbcd;
816 DWORD ntfret;
817 INT offset;
819 rc = btnPtr->rect;
820 CopyRect (&rcArrow, &rc);
822 /* get a pointer to the text */
823 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
825 if (hasDropDownArrow)
827 int right;
829 if (dwStyle & TBSTYLE_FLAT)
830 right = max(rc.left, rc.right - DDARROW_WIDTH);
831 else
832 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
834 if (drawSepDropDownArrow)
835 rc.right = right;
837 rcArrow.left = right;
840 /* copy text & bitmap rects after adjusting for drop-down arrow
841 * so that text & bitmap is centred in the rectangle not containing
842 * the arrow */
843 CopyRect(&rcText, &rc);
844 CopyRect(&rcBitmap, &rc);
846 /* Center the bitmap horizontally and vertically */
847 if (dwStyle & TBSTYLE_LIST)
849 if (lpText &&
850 infoPtr->nMaxTextRows > 0 &&
851 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
852 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
853 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
854 else
855 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
857 else
858 rcBitmap.left += (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
860 rcBitmap.top += infoPtr->szPadding.cy / 2;
862 TRACE("iBitmap=%d, start=(%ld,%ld) w=%d, h=%d\n",
863 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
864 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
865 TRACE("Text=%s\n", debugstr_w(lpText));
866 TRACE("iListGap=%d, padding = { %ld, %ld }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
868 /* calculate text position */
869 if (lpText)
871 rcText.left += GetSystemMetrics(SM_CXEDGE);
872 rcText.right -= GetSystemMetrics(SM_CXEDGE);
873 if (dwStyle & TBSTYLE_LIST)
875 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
876 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
878 else
880 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
881 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
882 else
883 rcText.top += infoPtr->szPadding.cy/2 + 2;
887 /* Initialize fields in all cases, because we use these later
888 * NOTE: applications can and do alter these to customize their
889 * toolbars */
890 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
891 tbcd.clrText = comctl32_color.clrBtnText;
892 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
893 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
894 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
895 tbcd.clrMark = comctl32_color.clrHighlight;
896 tbcd.clrHighlightHotTrack = 0;
897 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
898 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
899 /* MSDN says that this is the text rectangle.
900 * But (why always a but) tracing of v5.7 of native shows
901 * that this is really a *relative* rectangle based on the
902 * the nmcd.rc. Also the left and top are always 0 ignoring
903 * any bitmap that might be present. */
904 tbcd.rcText.left = 0;
905 tbcd.rcText.top = 0;
906 tbcd.rcText.right = rcText.right - rc.left;
907 tbcd.rcText.bottom = rcText.bottom - rc.top;
908 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
909 tbcd.nmcd.hdc = hdc;
910 tbcd.nmcd.rc = rc;
911 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
913 /* FIXME: what are these used for? */
914 tbcd.hbrLines = 0;
915 tbcd.hpenLines = 0;
917 /* Issue Item Prepaint notify */
918 infoPtr->dwItemCustDraw = 0;
919 infoPtr->dwItemCDFlag = 0;
920 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
922 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
923 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
924 tbcd.nmcd.lItemlParam = btnPtr->dwData;
925 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
926 /* reset these fields so the user can't alter the behaviour like native */
927 tbcd.nmcd.hdc = hdc;
928 tbcd.nmcd.rc = rc;
930 infoPtr->dwItemCustDraw = ntfret & 0xffff;
931 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
932 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
933 return;
934 /* save the only part of the rect that the user can change */
935 rcText.right = tbcd.rcText.right + rc.left;
936 rcText.bottom = tbcd.rcText.bottom + rc.top;
939 /* separator */
940 if (btnPtr->fsStyle & BTNS_SEP) {
941 /* with the FLAT style, iBitmap is the width and has already */
942 /* been taken into consideration in calculating the width */
943 /* so now we need to draw the vertical separator */
944 /* empirical tests show that iBitmap can/will be non-zero */
945 /* when drawing the vertical bar... */
946 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
947 if (btnPtr->fsStyle & BTNS_DROPDOWN)
948 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
949 else
950 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
952 else if (btnPtr->fsStyle != BTNS_SEP) {
953 FIXME("Draw some kind of separator: fsStyle=%x\n",
954 btnPtr->fsStyle);
956 goto FINALNOTIFY;
959 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
960 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
961 OffsetRect(&rcText, 1, 1);
963 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
964 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
965 TOOLBAR_DrawPattern (&rc, &tbcd);
967 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
969 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
971 COLORREF oldclr;
973 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
974 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
975 if (hasDropDownArrow)
976 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
977 SetBkColor(hdc, oldclr);
981 TOOLBAR_DrawFrame(infoPtr, &tbcd);
983 if (drawSepDropDownArrow)
984 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
986 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
987 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
989 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
991 if (hasDropDownArrow && !drawSepDropDownArrow)
993 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
995 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
996 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
998 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1000 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1001 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1003 else
1004 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1007 FINALNOTIFY:
1008 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1010 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1011 tbcd.nmcd.hdc = hdc;
1012 tbcd.nmcd.rc = rc;
1013 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1014 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1015 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1016 tbcd.rcText = rcText;
1017 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1018 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1019 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1025 static void
1026 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1028 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1029 TBUTTON_INFO *btnPtr;
1030 INT i, oldBKmode = 0;
1031 RECT rcTemp, rcClient;
1032 NMTBCUSTOMDRAW tbcd;
1033 DWORD ntfret;
1035 /* the app has told us not to redraw the toolbar */
1036 if (!infoPtr->bDoRedraw)
1037 return;
1039 /* if imagelist belongs to the app, it can be changed
1040 by the app after setting it */
1041 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1043 infoPtr->nNumBitmaps = 0;
1044 for (i = 0; i < infoPtr->cimlDef; i++)
1045 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1048 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1050 /* Send initial notify */
1051 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1052 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1053 tbcd.nmcd.hdc = hdc;
1054 tbcd.nmcd.rc = ps->rcPaint;
1055 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1056 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1058 if (infoPtr->bBtnTranspnt)
1059 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1061 GetClientRect(hwnd, &rcClient);
1063 /* redraw necessary buttons */
1064 btnPtr = infoPtr->buttons;
1065 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1067 BOOL bDraw;
1068 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1070 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1071 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1073 else
1074 bDraw = TRUE;
1075 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1076 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1077 if (bDraw)
1078 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1081 /* draw insert mark if required */
1082 if (infoPtr->tbim.iButton != -1)
1084 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1085 RECT rcInsertMark;
1086 rcInsertMark.top = rcButton.top;
1087 rcInsertMark.bottom = rcButton.bottom;
1088 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1089 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1090 else
1091 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1092 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1095 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1096 SetBkMode (hdc, oldBKmode);
1098 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1100 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1101 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1102 tbcd.nmcd.hdc = hdc;
1103 tbcd.nmcd.rc = ps->rcPaint;
1104 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1108 /***********************************************************************
1109 * TOOLBAR_MeasureString
1111 * This function gets the width and height of a string in pixels. This
1112 * is done first by using GetTextExtentPoint to get the basic width
1113 * and height. The DrawText is called with DT_CALCRECT to get the exact
1114 * width. The reason is because the text may have more than one "&" (or
1115 * prefix characters as M$ likes to call them). The prefix character
1116 * indicates where the underline goes, except for the string "&&" which
1117 * is reduced to a single "&". GetTextExtentPoint does not process these
1118 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1120 static void
1121 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1122 HDC hdc, LPSIZE lpSize)
1124 RECT myrect;
1126 lpSize->cx = 0;
1127 lpSize->cy = 0;
1129 if (infoPtr->nMaxTextRows > 0 &&
1130 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1131 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1132 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1134 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1136 if(lpText != NULL) {
1137 /* first get size of all the text */
1138 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1140 /* feed above size into the rectangle for DrawText */
1141 myrect.left = myrect.top = 0;
1142 myrect.right = lpSize->cx;
1143 myrect.bottom = lpSize->cy;
1145 /* Use DrawText to get true size as drawn (less pesky "&") */
1146 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1147 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1148 DT_NOPREFIX : 0));
1150 /* feed back to caller */
1151 lpSize->cx = myrect.right;
1152 lpSize->cy = myrect.bottom;
1156 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1159 /***********************************************************************
1160 * TOOLBAR_CalcStrings
1162 * This function walks through each string and measures it and returns
1163 * the largest height and width to caller.
1165 static void
1166 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1168 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1169 TBUTTON_INFO *btnPtr;
1170 INT i;
1171 SIZE sz;
1172 HDC hdc;
1173 HFONT hOldFont;
1175 lpSize->cx = 0;
1176 lpSize->cy = 0;
1178 if(infoPtr->nMaxTextRows == 0)
1179 return;
1181 hdc = GetDC (hwnd);
1182 hOldFont = SelectObject (hdc, infoPtr->hFont);
1184 btnPtr = infoPtr->buttons;
1185 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1186 if(TOOLBAR_HasText(infoPtr, btnPtr))
1188 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1189 if (sz.cx > lpSize->cx)
1190 lpSize->cx = sz.cx;
1191 if (sz.cy > lpSize->cy)
1192 lpSize->cy = sz.cy;
1196 SelectObject (hdc, hOldFont);
1197 ReleaseDC (hwnd, hdc);
1199 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1202 /***********************************************************************
1203 * TOOLBAR_WrapToolbar
1205 * This function walks through the buttons and separators in the
1206 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1207 * wrapping should occur based on the width of the toolbar window.
1208 * It does *not* calculate button placement itself. That task
1209 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1210 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1211 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1213 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1214 * vertical toolbar lists.
1217 static void
1218 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1220 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1221 TBUTTON_INFO *btnPtr;
1222 INT x, cx, i, j;
1223 RECT rc;
1224 BOOL bWrap, bButtonWrap;
1226 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1227 /* no layout is necessary. Applications may use this style */
1228 /* to perform their own layout on the toolbar. */
1229 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1230 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1232 btnPtr = infoPtr->buttons;
1233 x = infoPtr->nIndent;
1235 /* this can get the parents width, to know how far we can extend
1236 * this toolbar. We cannot use its height, as there may be multiple
1237 * toolbars in a rebar control
1239 GetClientRect( GetParent(hwnd), &rc );
1240 infoPtr->nWidth = rc.right - rc.left;
1241 bButtonWrap = FALSE;
1243 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1244 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1245 infoPtr->nIndent);
1247 for (i = 0; i < infoPtr->nNumButtons; i++ )
1249 bWrap = FALSE;
1250 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1252 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1253 continue;
1255 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1256 /* it is the actual width of the separator. This is used for */
1257 /* custom controls in toolbars. */
1258 /* */
1259 /* BTNS_DROPDOWN separators are treated as buttons for */
1260 /* width. - GA 8/01 */
1261 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1262 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1263 cx = (btnPtr[i].iBitmap > 0) ?
1264 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1265 else
1266 cx = infoPtr->nButtonWidth;
1268 /* Two or more adjacent separators form a separator group. */
1269 /* The first separator in a group should be wrapped to the */
1270 /* next row if the previous wrapping is on a button. */
1271 if( bButtonWrap &&
1272 (btnPtr[i].fsStyle & BTNS_SEP) &&
1273 (i + 1 < infoPtr->nNumButtons ) &&
1274 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1276 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1277 btnPtr[i].fsState |= TBSTATE_WRAP;
1278 x = infoPtr->nIndent;
1279 i++;
1280 bButtonWrap = FALSE;
1281 continue;
1284 /* The layout makes sure the bitmap is visible, but not the button. */
1285 /* Test added to also wrap after a button that starts a row but */
1286 /* is bigger than the area. - GA 8/01 */
1287 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1288 > infoPtr->nWidth ) ||
1289 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1291 BOOL bFound = FALSE;
1293 /* If the current button is a separator and not hidden, */
1294 /* go to the next until it reaches a non separator. */
1295 /* Wrap the last separator if it is before a button. */
1296 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1297 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1298 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1299 i < infoPtr->nNumButtons )
1301 i++;
1302 bFound = TRUE;
1305 if( bFound && i < infoPtr->nNumButtons )
1307 i--;
1308 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1309 i, btnPtr[i].fsStyle, x, cx);
1310 btnPtr[i].fsState |= TBSTATE_WRAP;
1311 x = infoPtr->nIndent;
1312 bButtonWrap = FALSE;
1313 continue;
1315 else if ( i >= infoPtr->nNumButtons)
1316 break;
1318 /* If the current button is not a separator, find the last */
1319 /* separator and wrap it. */
1320 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1322 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1323 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1325 bFound = TRUE;
1326 i = j;
1327 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1328 i, btnPtr[i].fsStyle, x, cx);
1329 x = infoPtr->nIndent;
1330 btnPtr[j].fsState |= TBSTATE_WRAP;
1331 bButtonWrap = FALSE;
1332 break;
1336 /* If no separator available for wrapping, wrap one of */
1337 /* non-hidden previous button. */
1338 if (!bFound)
1340 for ( j = i - 1;
1341 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1343 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1344 continue;
1346 bFound = TRUE;
1347 i = j;
1348 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1349 i, btnPtr[i].fsStyle, x, cx);
1350 x = infoPtr->nIndent;
1351 btnPtr[j].fsState |= TBSTATE_WRAP;
1352 bButtonWrap = TRUE;
1353 break;
1357 /* If all above failed, wrap the current button. */
1358 if (!bFound)
1360 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1361 i, btnPtr[i].fsStyle, x, cx);
1362 btnPtr[i].fsState |= TBSTATE_WRAP;
1363 bFound = TRUE;
1364 x = infoPtr->nIndent;
1365 if (btnPtr[i].fsStyle & BTNS_SEP )
1366 bButtonWrap = FALSE;
1367 else
1368 bButtonWrap = TRUE;
1371 else {
1372 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1373 i, btnPtr[i].fsStyle, x, cx);
1374 x += cx;
1380 /***********************************************************************
1381 * TOOLBAR_MeasureButton
1383 * Calculates the width and height required for a button. Used in
1384 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1385 * the width of buttons that are autosized.
1387 * Note that it would have been rather elegant to use one piece of code for
1388 * both the laying out of the toolbar and for controlling where button parts
1389 * are drawn, but the native control has inconsistencies between the two that
1390 * prevent this from being effectively. These inconsistencies can be seen as
1391 * artefacts where parts of the button appear outside of the bounding button
1392 * rectangle.
1394 * There are several cases for the calculation of the button dimensions and
1395 * button part positioning:
1397 * List
1398 * ====
1400 * With Bitmap:
1402 * +--------------------------------------------------------+ ^
1403 * | ^ ^ | |
1404 * | | pad.cy / 2 | centred | |
1405 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1406 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1407 * | |<------------>| | | | |
1408 * | +--------------+ +------------+ | |
1409 * |<-------------------------------------->| | |
1410 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1411 * | szText.cx | |
1412 * +--------------------------------------------------------+ -
1413 * <-------------------------------------------------------->
1414 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1416 * Without Bitmap (I_IMAGENONE):
1418 * +-----------------------------------+ ^
1419 * | ^ | |
1420 * | | centred | | LISTPAD_CY +
1421 * | +------------+ | | szText.cy
1422 * | | Text | | |
1423 * | | | | |
1424 * | +------------+ | |
1425 * |<----------------->| | |
1426 * | cxedge |<-----------> | |
1427 * | szText.cx | |
1428 * +-----------------------------------+ -
1429 * <----------------------------------->
1430 * szText.cx + pad.cx
1432 * Without text:
1434 * +--------------------------------------+ ^
1435 * | ^ | |
1436 * | | padding.cy/2 | | DEFPAD_CY +
1437 * | +------------+ | | nBitmapHeight
1438 * | | Bitmap | | |
1439 * | | | | |
1440 * | +------------+ | |
1441 * |<------------------->| | |
1442 * | cxedge + iListGap/2 |<-----------> | |
1443 * | nBitmapWidth | |
1444 * +--------------------------------------+ -
1445 * <-------------------------------------->
1446 * 2*cxedge + nBitmapWidth + iListGap
1448 * Non-List
1449 * ========
1451 * With bitmap:
1453 * +-----------------------------------+ ^
1454 * | ^ | |
1455 * | | pad.cy / 2 | | nBitmapHeight +
1456 * | - | | szText.cy +
1457 * | +------------+ | | DEFPAD_CY + 1
1458 * | centred | Bitmap | | |
1459 * |<----------------->| | | |
1460 * | +------------+ | |
1461 * | ^ | |
1462 * | 1 | | |
1463 * | - | |
1464 * | centred +---------------+ | |
1465 * |<--------------->| Text | | |
1466 * | +---------------+ | |
1467 * +-----------------------------------+ -
1468 * <----------------------------------->
1469 * pad.cx + max(nBitmapWidth, szText.cx)
1471 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1473 * +---------------------------------------+ ^
1474 * | ^ | |
1475 * | | 2 + pad.cy / 2 | |
1476 * | - | | szText.cy +
1477 * | centred +-----------------+ | | pad.cy + 2
1478 * |<--------------->| Text | | |
1479 * | +-----------------+ | |
1480 * | | |
1481 * +---------------------------------------+ -
1482 * <--------------------------------------->
1483 * 2*cxedge + pad.cx + szText.cx
1485 * Without text:
1486 * As for with bitmaps, but with szText.cx zero.
1488 static inline SIZE TOOLBAR_MeasureButton(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1490 SIZE sizeButton;
1491 if (infoPtr->dwStyle & TBSTYLE_LIST)
1493 /* set button height from bitmap / text height... */
1494 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1495 sizeString.cy);
1497 /* ... add on the necessary padding */
1498 if (bValidImageList)
1500 if (bHasBitmap)
1501 sizeButton.cy += DEFPAD_CY;
1502 else
1503 sizeButton.cy += LISTPAD_CY;
1505 else
1506 sizeButton.cy += infoPtr->szPadding.cy;
1508 /* calculate button width */
1509 if (bHasBitmap)
1511 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1512 infoPtr->nBitmapWidth + infoPtr->iListGap;
1513 if (sizeString.cx > 0)
1514 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1516 else
1517 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1519 else
1521 if (bHasBitmap)
1523 sizeButton.cy = infoPtr->nBitmapHeight + 1 +
1524 sizeString.cy + DEFPAD_CY;
1525 sizeButton.cx = infoPtr->szPadding.cx +
1526 max(sizeString.cx, infoPtr->nBitmapWidth);
1528 else
1530 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1531 NONLIST_NOTEXT_OFFSET;
1532 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1533 infoPtr->szPadding.cx + sizeString.cx;
1536 return sizeButton;
1540 /***********************************************************************
1541 * TOOLBAR_CalcToolbar
1543 * This function calculates button and separator placement. It first
1544 * calculates the button sizes, gets the toolbar window width and then
1545 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1546 * on. It assigns a new location to each item and sends this location to
1547 * the tooltip window if appropriate. Finally, it updates the rcBound
1548 * rect and calculates the new required toolbar window height.
1550 static void
1551 TOOLBAR_CalcToolbar (HWND hwnd)
1553 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1554 DWORD dwStyle = infoPtr->dwStyle;
1555 TBUTTON_INFO *btnPtr;
1556 INT i, nRows, nSepRows;
1557 INT x, y, cx, cy;
1558 SIZE sizeString, sizeButton;
1559 BOOL bWrap;
1560 BOOL usesBitmaps = FALSE;
1561 BOOL validImageList = FALSE;
1562 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1564 TOOLBAR_CalcStrings (hwnd, &sizeString);
1566 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1568 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1570 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1571 usesBitmaps = TRUE;
1573 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1574 validImageList = TRUE;
1575 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, usesBitmaps, validImageList);
1576 infoPtr->nButtonWidth = sizeButton.cx;
1577 infoPtr->nButtonHeight = sizeButton.cy;
1579 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1580 infoPtr->nButtonWidth = infoPtr->cxMin;
1581 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1582 infoPtr->nButtonWidth = infoPtr->cxMax;
1584 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1586 x = infoPtr->nIndent;
1587 y = 0;
1589 /* from above, minimum is a button, and possible text */
1590 cx = infoPtr->nButtonWidth;
1592 infoPtr->nHeight = infoPtr->nButtonHeight;
1594 cy = infoPtr->nHeight;
1596 nRows = nSepRows = 0;
1598 infoPtr->rcBound.top = y;
1599 infoPtr->rcBound.left = x;
1600 infoPtr->rcBound.bottom = y + cy;
1601 infoPtr->rcBound.right = x;
1603 btnPtr = infoPtr->buttons;
1605 TRACE("cy=%d\n", cy);
1607 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1609 bWrap = FALSE;
1610 if (btnPtr->fsState & TBSTATE_HIDDEN)
1612 SetRectEmpty (&btnPtr->rect);
1613 continue;
1616 cy = infoPtr->nHeight;
1618 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1619 /* it is the actual width of the separator. This is used for */
1620 /* custom controls in toolbars. */
1621 if (btnPtr->fsStyle & BTNS_SEP) {
1622 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1623 cy = (btnPtr->iBitmap > 0) ?
1624 btnPtr->iBitmap : SEPARATOR_WIDTH;
1625 cx = infoPtr->nButtonWidth;
1627 else
1628 cx = (btnPtr->iBitmap > 0) ?
1629 btnPtr->iBitmap : SEPARATOR_WIDTH;
1631 else
1633 if (btnPtr->cx)
1634 cx = btnPtr->cx;
1635 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1636 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1638 SIZE sz;
1639 HDC hdc;
1640 HFONT hOldFont;
1642 hdc = GetDC (hwnd);
1643 hOldFont = SelectObject (hdc, infoPtr->hFont);
1645 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1647 SelectObject (hdc, hOldFont);
1648 ReleaseDC (hwnd, hdc);
1650 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1651 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1652 validImageList);
1653 cx = sizeButton.cx;
1655 else
1656 cx = infoPtr->nButtonWidth;
1658 /* if size has been set manually then don't add on extra space
1659 * for the drop down arrow */
1660 if (!btnPtr->cx && hasDropDownArrows &&
1661 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1662 cx += DDARROW_WIDTH;
1664 if (btnPtr->fsState & TBSTATE_WRAP )
1665 bWrap = TRUE;
1667 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1669 if (infoPtr->rcBound.left > x)
1670 infoPtr->rcBound.left = x;
1671 if (infoPtr->rcBound.right < x + cx)
1672 infoPtr->rcBound.right = x + cx;
1673 if (infoPtr->rcBound.bottom < y + cy)
1674 infoPtr->rcBound.bottom = y + cy;
1676 /* Set the toolTip only for non-hidden, non-separator button */
1677 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1679 TTTOOLINFOW ti;
1681 ZeroMemory (&ti, sizeof(ti));
1682 ti.cbSize = sizeof(ti);
1683 ti.hwnd = hwnd;
1684 ti.uId = btnPtr->idCommand;
1685 ti.rect = btnPtr->rect;
1686 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
1687 0, (LPARAM)&ti);
1690 /* btnPtr->nRow is zero based. The space between the rows is */
1691 /* also considered as a row. */
1692 btnPtr->nRow = nRows + nSepRows;
1694 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1695 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1696 x, y, x+cx, y+cy);
1698 if( bWrap )
1700 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1701 y += cy;
1702 else
1704 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1705 /* it is the actual width of the separator. This is used for */
1706 /* custom controls in toolbars. */
1707 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1708 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1709 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1710 else
1711 y += cy;
1713 /* nSepRows is used to calculate the extra height follwoing */
1714 /* the last row. */
1715 nSepRows++;
1717 x = infoPtr->nIndent;
1719 /* Increment row number unless this is the last button */
1720 /* and it has Wrap set. */
1721 if (i != infoPtr->nNumButtons-1)
1722 nRows++;
1724 else
1725 x += cx;
1728 /* infoPtr->nRows is the number of rows on the toolbar */
1729 infoPtr->nRows = nRows + nSepRows + 1;
1731 #if 0
1732 /********************************************************************
1733 * The following while interesting, does not match the values *
1734 * created above for the button rectangles, nor the rcBound rect. *
1735 * We will comment it out and remove it later. *
1737 * The problem showed up as heights in the pager control that was *
1738 * wrong. *
1739 ********************************************************************/
1741 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1742 /* the last row. */
1743 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1744 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1745 nSepRows * (infoPtr->nBitmapHeight + 1) +
1746 BOTTOM_BORDER;
1747 #endif
1749 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1751 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1755 static INT
1756 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1758 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1759 TBUTTON_INFO *btnPtr;
1760 INT i;
1762 btnPtr = infoPtr->buttons;
1763 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1764 if (btnPtr->fsState & TBSTATE_HIDDEN)
1765 continue;
1767 if (btnPtr->fsStyle & BTNS_SEP) {
1768 if (PtInRect (&btnPtr->rect, *lpPt)) {
1769 TRACE(" ON SEPARATOR %d!\n", i);
1770 return -i;
1773 else {
1774 if (PtInRect (&btnPtr->rect, *lpPt)) {
1775 TRACE(" ON BUTTON %d!\n", i);
1776 return i;
1781 TRACE(" NOWHERE!\n");
1782 return TOOLBAR_NOWHERE;
1786 static INT
1787 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1789 TBUTTON_INFO *btnPtr;
1790 INT i;
1792 if (CommandIsIndex) {
1793 TRACE("command is really index command=%d\n", idCommand);
1794 if (idCommand >= infoPtr->nNumButtons) return -1;
1795 return idCommand;
1797 btnPtr = infoPtr->buttons;
1798 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1799 if (btnPtr->idCommand == idCommand) {
1800 TRACE("command=%d index=%d\n", idCommand, i);
1801 return i;
1804 TRACE("no index found for command=%d\n", idCommand);
1805 return -1;
1809 static INT
1810 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1812 TBUTTON_INFO *btnPtr;
1813 INT nRunIndex;
1815 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1816 return -1;
1818 /* check index button */
1819 btnPtr = &infoPtr->buttons[nIndex];
1820 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1821 if (btnPtr->fsState & TBSTATE_CHECKED)
1822 return nIndex;
1825 /* check previous buttons */
1826 nRunIndex = nIndex - 1;
1827 while (nRunIndex >= 0) {
1828 btnPtr = &infoPtr->buttons[nRunIndex];
1829 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1830 if (btnPtr->fsState & TBSTATE_CHECKED)
1831 return nRunIndex;
1833 else
1834 break;
1835 nRunIndex--;
1838 /* check next buttons */
1839 nRunIndex = nIndex + 1;
1840 while (nRunIndex < infoPtr->nNumButtons) {
1841 btnPtr = &infoPtr->buttons[nRunIndex];
1842 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1843 if (btnPtr->fsState & TBSTATE_CHECKED)
1844 return nRunIndex;
1846 else
1847 break;
1848 nRunIndex++;
1851 return -1;
1855 static VOID
1856 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1857 WPARAM wParam, LPARAM lParam)
1859 MSG msg;
1861 msg.hwnd = hwndMsg;
1862 msg.message = uMsg;
1863 msg.wParam = wParam;
1864 msg.lParam = lParam;
1865 msg.time = GetMessageTime ();
1866 msg.pt.x = LOWORD(GetMessagePos ());
1867 msg.pt.y = HIWORD(GetMessagePos ());
1869 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1872 /* keeps available button list box sorted by button id */
1873 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1875 int i;
1876 int count;
1877 PCUSTOMBUTTON btnInfo;
1878 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1880 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1882 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1884 /* position 0 is always separator */
1885 for (i = 1; i < count; i++)
1887 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1888 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1890 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1891 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1892 return;
1895 /* id higher than all others add to end */
1896 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
1897 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1900 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
1902 NMTOOLBARW nmtb;
1904 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
1906 if (nIndexFrom == nIndexTo)
1907 return;
1909 /* MSDN states that iItem is the index of the button, rather than the
1910 * command ID as used by every other NMTOOLBAR notification */
1911 nmtb.iItem = nIndexFrom;
1912 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1914 PCUSTOMBUTTON btnInfo;
1915 NMHDR hdr;
1916 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1917 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1919 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
1921 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
1922 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1923 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1924 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
1926 if (nIndexTo <= 0)
1927 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
1928 else
1929 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
1931 /* last item is always separator, so -2 instead of -1 */
1932 if (nIndexTo >= (count - 2))
1933 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
1934 else
1935 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
1937 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
1938 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1940 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1944 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
1946 NMTOOLBARW nmtb;
1948 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
1950 /* MSDN states that iItem is the index of the button, rather than the
1951 * command ID as used by every other NMTOOLBAR notification */
1952 nmtb.iItem = nIndexAvail;
1953 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1955 PCUSTOMBUTTON btnInfo;
1956 NMHDR hdr;
1957 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1958 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1959 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1961 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
1963 if (nIndexAvail != 0) /* index == 0 indicates separator */
1965 /* remove from 'available buttons' list */
1966 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
1967 if (nIndexAvail == count-1)
1968 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
1969 else
1970 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
1972 else
1974 PCUSTOMBUTTON btnNew;
1976 /* duplicate 'separator' button */
1977 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1978 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
1979 btnInfo = btnNew;
1982 /* insert into 'toolbar button' list */
1983 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1984 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1986 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1988 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1992 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
1994 PCUSTOMBUTTON btnInfo;
1995 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1997 TRACE("Remove: index %d\n", index);
1999 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2001 /* send TBN_QUERYDELETE notification */
2002 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2004 NMHDR hdr;
2006 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2007 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2009 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2011 /* insert into 'available button' list */
2012 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2013 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2014 else
2015 Free(btnInfo);
2017 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2021 /* drag list notification function for toolbar buttons list box */
2022 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2024 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2025 switch (pDLI->uNotification)
2027 case DL_BEGINDRAG:
2029 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2030 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2031 /* no dragging for last item (separator) */
2032 if (nCurrentItem >= (nCount - 1)) return FALSE;
2033 return TRUE;
2035 case DL_DRAGGING:
2037 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2038 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2039 /* no dragging past last item (separator) */
2040 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2042 DrawInsert(hwnd, hwndList, nCurrentItem);
2043 /* FIXME: native uses "move button" cursor */
2044 return DL_COPYCURSOR;
2047 /* not over toolbar buttons list */
2048 if (nCurrentItem < 0)
2050 POINT ptWindow = pDLI->ptCursor;
2051 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2052 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2053 /* over available buttons list? */
2054 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2055 /* FIXME: native uses "move button" cursor */
2056 return DL_COPYCURSOR;
2058 /* clear drag arrow */
2059 DrawInsert(hwnd, hwndList, -1);
2060 return DL_STOPCURSOR;
2062 case DL_DROPPED:
2064 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2065 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2066 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2067 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2069 /* clear drag arrow */
2070 DrawInsert(hwnd, hwndList, -1);
2071 /* move item */
2072 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2074 /* not over toolbar buttons list */
2075 if (nIndexTo < 0)
2077 POINT ptWindow = pDLI->ptCursor;
2078 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2079 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2080 /* over available buttons list? */
2081 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2082 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2084 break;
2086 case DL_CANCELDRAG:
2087 /* Clear drag arrow */
2088 DrawInsert(hwnd, hwndList, -1);
2089 break;
2092 return 0;
2095 /* drag list notification function for available buttons list box */
2096 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2098 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2099 switch (pDLI->uNotification)
2101 case DL_BEGINDRAG:
2102 return TRUE;
2103 case DL_DRAGGING:
2105 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2106 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2107 /* no dragging past last item (separator) */
2108 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2110 DrawInsert(hwnd, hwndList, nCurrentItem);
2111 /* FIXME: native uses "move button" cursor */
2112 return DL_COPYCURSOR;
2115 /* not over toolbar buttons list */
2116 if (nCurrentItem < 0)
2118 POINT ptWindow = pDLI->ptCursor;
2119 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2120 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2121 /* over available buttons list? */
2122 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2123 /* FIXME: native uses "move button" cursor */
2124 return DL_COPYCURSOR;
2126 /* clear drag arrow */
2127 DrawInsert(hwnd, hwndList, -1);
2128 return DL_STOPCURSOR;
2130 case DL_DROPPED:
2132 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2133 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2134 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2135 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2137 /* clear drag arrow */
2138 DrawInsert(hwnd, hwndList, -1);
2139 /* add item */
2140 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2143 case DL_CANCELDRAG:
2144 /* Clear drag arrow */
2145 DrawInsert(hwnd, hwndList, -1);
2146 break;
2148 return 0;
2151 extern UINT uDragListMessage;
2153 /***********************************************************************
2154 * TOOLBAR_CustomizeDialogProc
2155 * This function implements the toolbar customization dialog.
2157 static INT_PTR CALLBACK
2158 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2160 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2161 PCUSTOMBUTTON btnInfo;
2162 NMTOOLBARA nmtb;
2163 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2165 switch (uMsg)
2167 case WM_INITDIALOG:
2168 custInfo = (PCUSTDLG_INFO)lParam;
2169 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2171 if (custInfo)
2173 WCHAR Buffer[256];
2174 int i = 0;
2175 int index;
2177 infoPtr = custInfo->tbInfo;
2179 /* send TBN_QUERYINSERT notification */
2180 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2182 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2183 return FALSE;
2185 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
2186 /* FIXME: this hack won't work on 64-bit - we need to declare a structure for this */
2187 nmtb.iItem = (int)hwnd;
2188 /* Send TBN_INITCUSTOMIZE notification */
2189 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
2190 TBNRF_HIDEHELP)
2192 TRACE("TBNRF_HIDEHELP requested\n");
2193 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2196 /* add items to 'toolbar buttons' list and check if removable */
2197 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2199 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2200 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2201 btnInfo->btn.fsStyle = BTNS_SEP;
2202 btnInfo->bVirtual = FALSE;
2203 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2205 /* send TBN_QUERYDELETE notification */
2206 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2208 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2209 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2212 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2214 /* insert separator button into 'available buttons' list */
2215 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2216 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2217 btnInfo->btn.fsStyle = BTNS_SEP;
2218 btnInfo->bVirtual = FALSE;
2219 btnInfo->bRemovable = TRUE;
2220 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2221 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2222 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2224 /* insert all buttons into dsa */
2225 for (i = 0;; i++)
2227 /* send TBN_GETBUTTONINFO notification */
2228 NMTOOLBARW nmtb;
2229 nmtb.iItem = i;
2230 nmtb.pszText = Buffer;
2231 nmtb.cchText = 256;
2233 /* Clear previous button's text */
2234 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2236 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2237 break;
2239 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2240 nmtb.tbButton.fsStyle, i,
2241 nmtb.tbButton.idCommand,
2242 nmtb.tbButton.iString,
2243 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2244 : "");
2246 /* insert button into the apropriate list */
2247 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2248 if (index == -1)
2250 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2251 btnInfo->bVirtual = FALSE;
2252 btnInfo->bRemovable = TRUE;
2254 else
2256 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2257 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2260 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2261 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2263 if (lstrlenW(nmtb.pszText))
2264 lstrcpyW(btnInfo->text, nmtb.pszText);
2265 else if (nmtb.tbButton.iString >= 0 &&
2266 nmtb.tbButton.iString < infoPtr->nNumStrings)
2268 lstrcpyW(btnInfo->text,
2269 infoPtr->strings[nmtb.tbButton.iString]);
2273 if (index == -1)
2274 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2277 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2279 /* select first item in the 'available' list */
2280 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2282 /* append 'virtual' separator button to the 'toolbar buttons' list */
2283 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2284 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2285 btnInfo->btn.fsStyle = BTNS_SEP;
2286 btnInfo->bVirtual = TRUE;
2287 btnInfo->bRemovable = FALSE;
2288 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2289 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2290 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2292 /* select last item in the 'toolbar' list */
2293 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2294 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2296 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2297 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2299 /* set focus and disable buttons */
2300 PostMessageW (hwnd, WM_USER, 0, 0);
2302 return TRUE;
2304 case WM_USER:
2305 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2306 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2307 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2308 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2309 return TRUE;
2311 case WM_CLOSE:
2312 EndDialog(hwnd, FALSE);
2313 return TRUE;
2315 case WM_COMMAND:
2316 switch (LOWORD(wParam))
2318 case IDC_TOOLBARBTN_LBOX:
2319 if (HIWORD(wParam) == LBN_SELCHANGE)
2321 PCUSTOMBUTTON btnInfo;
2322 NMTOOLBARA nmtb;
2323 int count;
2324 int index;
2326 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2327 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2329 /* send TBN_QUERYINSERT notification */
2330 nmtb.iItem = index;
2331 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2333 /* get list box item */
2334 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2336 if (index == (count - 1))
2338 /* last item (virtual separator) */
2339 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2340 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2342 else if (index == (count - 2))
2344 /* second last item (last non-virtual item) */
2345 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2346 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2348 else if (index == 0)
2350 /* first item */
2351 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2352 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2354 else
2356 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2357 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2360 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2362 break;
2364 case IDC_MOVEUP_BTN:
2366 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2367 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2369 break;
2371 case IDC_MOVEDN_BTN: /* move down */
2373 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2374 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2376 break;
2378 case IDC_REMOVE_BTN: /* remove button */
2380 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2382 if (LB_ERR == index)
2383 break;
2385 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2387 break;
2388 case IDC_HELP_BTN:
2389 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2390 break;
2391 case IDC_RESET_BTN:
2392 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2393 break;
2395 case IDOK: /* Add button */
2397 int index;
2398 int indexto;
2400 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2401 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2403 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2405 break;
2407 case IDCANCEL:
2408 EndDialog(hwnd, FALSE);
2409 break;
2411 return TRUE;
2413 case WM_DESTROY:
2415 int count;
2416 int i;
2418 /* delete items from 'toolbar buttons' listbox*/
2419 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2420 for (i = 0; i < count; i++)
2422 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2423 Free(btnInfo);
2424 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2426 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2429 /* delete items from 'available buttons' listbox*/
2430 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2431 for (i = 0; i < count; i++)
2433 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2434 Free(btnInfo);
2435 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2437 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2439 return TRUE;
2441 case WM_DRAWITEM:
2442 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2444 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2445 RECT rcButton;
2446 RECT rcText;
2447 HPEN hPen, hOldPen;
2448 HBRUSH hOldBrush;
2449 COLORREF oldText = 0;
2450 COLORREF oldBk = 0;
2452 /* get item data */
2453 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2454 if (btnInfo == NULL)
2456 FIXME("btnInfo invalid!\n");
2457 return TRUE;
2460 /* set colors and select objects */
2461 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2462 if (btnInfo->bVirtual)
2463 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2464 else
2465 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2466 hPen = CreatePen( PS_SOLID, 1,
2467 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2468 hOldPen = SelectObject (lpdis->hDC, hPen );
2469 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2471 /* fill background rectangle */
2472 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2473 lpdis->rcItem.right, lpdis->rcItem.bottom);
2475 /* calculate button and text rectangles */
2476 CopyRect (&rcButton, &lpdis->rcItem);
2477 InflateRect (&rcButton, -1, -1);
2478 CopyRect (&rcText, &rcButton);
2479 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2480 rcText.left = rcButton.right + 2;
2482 /* draw focus rectangle */
2483 if (lpdis->itemState & ODS_FOCUS)
2484 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2486 /* draw button */
2487 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2488 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2490 /* draw image and text */
2491 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2492 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2493 btnInfo->btn.iBitmap));
2494 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2495 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2497 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2498 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2500 /* delete objects and reset colors */
2501 SelectObject (lpdis->hDC, hOldBrush);
2502 SelectObject (lpdis->hDC, hOldPen);
2503 SetBkColor (lpdis->hDC, oldBk);
2504 SetTextColor (lpdis->hDC, oldText);
2505 DeleteObject( hPen );
2506 return TRUE;
2508 return FALSE;
2510 case WM_MEASUREITEM:
2511 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2513 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2515 lpmis->itemHeight = 15 + 8; /* default height */
2517 return TRUE;
2519 return FALSE;
2521 default:
2522 if (uDragListMessage && (uMsg == uDragListMessage))
2524 if (wParam == IDC_TOOLBARBTN_LBOX)
2526 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2527 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2528 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2529 return TRUE;
2531 else if (wParam == IDC_AVAILBTN_LBOX)
2533 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2534 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2535 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2536 return TRUE;
2539 return FALSE;
2544 /***********************************************************************
2545 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2548 static LRESULT
2549 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2551 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2552 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2553 INT nIndex = 0, nButtons, nCount;
2554 HBITMAP hbmLoad;
2555 HIMAGELIST himlDef;
2557 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2558 if (!lpAddBmp)
2559 return -1;
2561 if (lpAddBmp->hInst == HINST_COMMCTRL)
2563 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2564 nButtons = 15;
2565 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2566 nButtons = 13;
2567 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2568 nButtons = 5;
2569 else
2570 return -1;
2572 TRACE ("adding %d internal bitmaps!\n", nButtons);
2574 /* Windows resize all the buttons to the size of a newly added standard image */
2575 if (lpAddBmp->nID & 1)
2577 /* large icons */
2578 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2579 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2581 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2582 MAKELPARAM((WORD)24, (WORD)24));
2583 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2584 MAKELPARAM((WORD)31, (WORD)30));
2586 else
2588 /* small icons */
2589 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2590 MAKELPARAM((WORD)16, (WORD)16));
2591 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2592 MAKELPARAM((WORD)22, (WORD)22));
2595 TOOLBAR_CalcToolbar (hwnd);
2597 else
2599 nButtons = (INT)wParam;
2600 if (nButtons <= 0)
2601 return -1;
2603 TRACE ("adding %d bitmaps!\n", nButtons);
2606 if (!infoPtr->cimlDef) {
2607 /* create new default image list */
2608 TRACE ("creating default image list!\n");
2610 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2611 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2612 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2613 infoPtr->himlInt = himlDef;
2615 else {
2616 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2619 if (!himlDef) {
2620 WARN("No default image list available\n");
2621 return -1;
2624 nCount = ImageList_GetImageCount(himlDef);
2626 /* Add bitmaps to the default image list */
2627 if (lpAddBmp->hInst == NULL)
2629 BITMAP bmp;
2630 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2631 HDC hdcImage, hdcBitmap;
2633 /* copy the bitmap before adding it so that the user's bitmap
2634 * doesn't get modified.
2636 GetObjectW ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2638 hdcImage = CreateCompatibleDC(0);
2639 hdcBitmap = CreateCompatibleDC(0);
2641 /* create new bitmap */
2642 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2643 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2644 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2646 /* Copy the user's image */
2647 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2648 hdcBitmap, 0, 0, SRCCOPY);
2650 SelectObject (hdcImage, hOldBitmapLoad);
2651 SelectObject (hdcBitmap, hOldBitmapBitmap);
2652 DeleteDC (hdcImage);
2653 DeleteDC (hdcBitmap);
2655 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2656 DeleteObject (hbmLoad);
2658 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2660 /* Add system bitmaps */
2661 switch (lpAddBmp->nID)
2663 case IDB_STD_SMALL_COLOR:
2664 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2665 MAKEINTRESOURCEW(IDB_STD_SMALL));
2666 nIndex = ImageList_AddMasked (himlDef,
2667 hbmLoad, comctl32_color.clrBtnFace);
2668 DeleteObject (hbmLoad);
2669 break;
2671 case IDB_STD_LARGE_COLOR:
2672 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2673 MAKEINTRESOURCEW(IDB_STD_LARGE));
2674 nIndex = ImageList_AddMasked (himlDef,
2675 hbmLoad, comctl32_color.clrBtnFace);
2676 DeleteObject (hbmLoad);
2677 break;
2679 case IDB_VIEW_SMALL_COLOR:
2680 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2681 MAKEINTRESOURCEW(IDB_VIEW_SMALL));
2682 nIndex = ImageList_AddMasked (himlDef,
2683 hbmLoad, comctl32_color.clrBtnFace);
2684 DeleteObject (hbmLoad);
2685 break;
2687 case IDB_VIEW_LARGE_COLOR:
2688 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2689 MAKEINTRESOURCEW(IDB_VIEW_LARGE));
2690 nIndex = ImageList_AddMasked (himlDef,
2691 hbmLoad, comctl32_color.clrBtnFace);
2692 DeleteObject (hbmLoad);
2693 break;
2695 case IDB_HIST_SMALL_COLOR:
2696 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2697 MAKEINTRESOURCEW(IDB_HIST_SMALL));
2698 nIndex = ImageList_AddMasked (himlDef,
2699 hbmLoad, comctl32_color.clrBtnFace);
2700 DeleteObject (hbmLoad);
2701 break;
2703 case IDB_HIST_LARGE_COLOR:
2704 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2705 MAKEINTRESOURCEW(IDB_HIST_LARGE));
2706 nIndex = ImageList_AddMasked (himlDef,
2707 hbmLoad, comctl32_color.clrBtnFace);
2708 DeleteObject (hbmLoad);
2709 break;
2711 default:
2712 nIndex = ImageList_GetImageCount (himlDef);
2713 ERR ("invalid imagelist!\n");
2714 break;
2717 else
2719 hbmLoad = LoadBitmapW (lpAddBmp->hInst, (LPWSTR)lpAddBmp->nID);
2720 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2721 DeleteObject (hbmLoad);
2724 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2726 if (infoPtr->nNumBitmapInfos == 0)
2728 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2730 else
2732 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2733 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2734 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2737 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2738 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2739 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2741 infoPtr->nNumBitmapInfos++;
2742 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2744 if (nIndex != -1)
2746 INT imagecount = ImageList_GetImageCount(himlDef);
2748 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2750 WARN("Desired images do not match received images : Previous image number %i Previous images in list %i added %i expecting total %i, Images in list %i\n",
2751 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2752 infoPtr->nNumBitmaps+nButtons,imagecount);
2754 infoPtr->nNumBitmaps = imagecount;
2756 else
2757 infoPtr->nNumBitmaps += nButtons;
2760 InvalidateRect(hwnd, NULL, TRUE);
2762 return nIndex;
2766 static LRESULT
2767 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2769 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2770 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2771 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2773 TRACE("adding %d buttons!\n", wParam);
2775 nAddButtons = (UINT)wParam;
2776 nOldButtons = infoPtr->nNumButtons;
2777 nNewButtons = nOldButtons + nAddButtons;
2779 if (infoPtr->nNumButtons == 0) {
2780 infoPtr->buttons =
2781 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2783 else {
2784 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2785 infoPtr->buttons =
2786 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2787 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2788 nOldButtons * sizeof(TBUTTON_INFO));
2789 Free (oldButtons);
2792 infoPtr->nNumButtons = nNewButtons;
2794 /* insert new button data */
2795 for (nCount = 0; nCount < nAddButtons; nCount++) {
2796 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2797 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2798 btnPtr->idCommand = lpTbb[nCount].idCommand;
2799 btnPtr->fsState = lpTbb[nCount].fsState;
2800 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2801 btnPtr->dwData = lpTbb[nCount].dwData;
2802 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2803 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2804 else
2805 btnPtr->iString = lpTbb[nCount].iString;
2806 btnPtr->bHot = FALSE;
2808 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2809 TTTOOLINFOW ti;
2811 ZeroMemory (&ti, sizeof(ti));
2812 ti.cbSize = sizeof(ti);
2813 ti.hwnd = hwnd;
2814 ti.uId = btnPtr->idCommand;
2815 ti.hinst = 0;
2816 ti.lpszText = LPSTR_TEXTCALLBACKW;
2818 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2819 0, (LPARAM)&ti);
2823 TOOLBAR_CalcToolbar (hwnd);
2825 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2827 InvalidateRect(hwnd, NULL, TRUE);
2829 return TRUE;
2833 static LRESULT
2834 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2836 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2837 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2838 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2840 TRACE("adding %d buttons!\n", wParam);
2842 nAddButtons = (UINT)wParam;
2843 nOldButtons = infoPtr->nNumButtons;
2844 nNewButtons = nOldButtons + nAddButtons;
2846 if (infoPtr->nNumButtons == 0) {
2847 infoPtr->buttons =
2848 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2850 else {
2851 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2852 infoPtr->buttons =
2853 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2854 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2855 nOldButtons * sizeof(TBUTTON_INFO));
2856 Free (oldButtons);
2859 infoPtr->nNumButtons = nNewButtons;
2861 /* insert new button data */
2862 for (nCount = 0; nCount < nAddButtons; nCount++) {
2863 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2864 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2865 btnPtr->idCommand = lpTbb[nCount].idCommand;
2866 btnPtr->fsState = lpTbb[nCount].fsState;
2867 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2868 btnPtr->dwData = lpTbb[nCount].dwData;
2869 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2870 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2871 else
2872 btnPtr->iString = lpTbb[nCount].iString;
2873 btnPtr->bHot = FALSE;
2875 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2876 TTTOOLINFOW ti;
2878 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2879 ti.cbSize = sizeof (TTTOOLINFOW);
2880 ti.hwnd = hwnd;
2881 ti.uId = btnPtr->idCommand;
2882 ti.hinst = 0;
2883 ti.lpszText = LPSTR_TEXTCALLBACKW;
2884 ti.lParam = lParam;
2886 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2887 0, (LPARAM)&ti);
2891 TOOLBAR_CalcToolbar (hwnd);
2893 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2895 InvalidateRect(hwnd, NULL, TRUE);
2897 return TRUE;
2901 static LRESULT
2902 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2904 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2905 INT nIndex;
2907 if ((wParam) && (HIWORD(lParam) == 0)) {
2908 char szString[256];
2909 INT len;
2910 TRACE("adding string from resource!\n");
2912 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam, szString, sizeof(szString));
2914 TRACE("len=%d \"%s\"\n", len, szString);
2915 nIndex = infoPtr->nNumStrings;
2916 if (infoPtr->nNumStrings == 0) {
2917 infoPtr->strings =
2918 Alloc (sizeof(LPWSTR));
2920 else {
2921 LPWSTR *oldStrings = infoPtr->strings;
2922 infoPtr->strings =
2923 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2924 memcpy (&infoPtr->strings[0], &oldStrings[0],
2925 sizeof(LPWSTR) * infoPtr->nNumStrings);
2926 Free (oldStrings);
2929 /*Alloc zeros out the allocated memory*/
2930 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2931 infoPtr->nNumStrings++;
2933 else {
2934 LPSTR p = (LPSTR)lParam;
2935 INT len;
2937 if (p == NULL)
2938 return -1;
2939 TRACE("adding string(s) from array!\n");
2941 nIndex = infoPtr->nNumStrings;
2942 while (*p) {
2943 len = strlen (p);
2944 TRACE("len=%d \"%s\"\n", len, p);
2946 if (infoPtr->nNumStrings == 0) {
2947 infoPtr->strings =
2948 Alloc (sizeof(LPWSTR));
2950 else {
2951 LPWSTR *oldStrings = infoPtr->strings;
2952 infoPtr->strings =
2953 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2954 memcpy (&infoPtr->strings[0], &oldStrings[0],
2955 sizeof(LPWSTR) * infoPtr->nNumStrings);
2956 Free (oldStrings);
2959 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2960 infoPtr->nNumStrings++;
2962 p += (len+1);
2966 return nIndex;
2970 static LRESULT
2971 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2973 #define MAX_RESOURCE_STRING_LENGTH 512
2974 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2975 INT nIndex;
2977 if ((wParam) && (HIWORD(lParam) == 0)) {
2978 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2979 INT len;
2980 TRACE("adding string from resource!\n");
2982 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2983 szString, MAX_RESOURCE_STRING_LENGTH);
2985 TRACE("len=%d %s\n", len, debugstr_w(szString));
2986 TRACE("First char: 0x%x\n", *szString);
2987 if (szString[0] == L'|')
2989 PWSTR p = szString + 1;
2991 nIndex = infoPtr->nNumStrings;
2992 while (*p != L'|' && *p != L'\0') {
2993 PWSTR np;
2995 if (infoPtr->nNumStrings == 0) {
2996 infoPtr->strings = Alloc (sizeof(LPWSTR));
2998 else
3000 LPWSTR *oldStrings = infoPtr->strings;
3001 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3002 memcpy(&infoPtr->strings[0], &oldStrings[0],
3003 sizeof(LPWSTR) * infoPtr->nNumStrings);
3004 Free(oldStrings);
3007 np=strchrW (p, '|');
3008 if (np!=NULL) {
3009 len = np - p;
3010 np++;
3011 } else {
3012 len = strlenW(p);
3013 np = p + len;
3015 TRACE("len=%d %s\n", len, debugstr_w(p));
3016 infoPtr->strings[infoPtr->nNumStrings] =
3017 Alloc (sizeof(WCHAR)*(len+1));
3018 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
3019 infoPtr->nNumStrings++;
3021 p = np;
3024 else
3026 nIndex = infoPtr->nNumStrings;
3027 if (infoPtr->nNumStrings == 0) {
3028 infoPtr->strings =
3029 Alloc (sizeof(LPWSTR));
3031 else {
3032 LPWSTR *oldStrings = infoPtr->strings;
3033 infoPtr->strings =
3034 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3035 memcpy (&infoPtr->strings[0], &oldStrings[0],
3036 sizeof(LPWSTR) * infoPtr->nNumStrings);
3037 Free (oldStrings);
3040 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
3041 infoPtr->nNumStrings++;
3044 else {
3045 LPWSTR p = (LPWSTR)lParam;
3046 INT len;
3048 if (p == NULL)
3049 return -1;
3050 TRACE("adding string(s) from array!\n");
3051 nIndex = infoPtr->nNumStrings;
3052 while (*p) {
3053 len = strlenW (p);
3055 TRACE("len=%d %s\n", len, debugstr_w(p));
3056 if (infoPtr->nNumStrings == 0) {
3057 infoPtr->strings =
3058 Alloc (sizeof(LPWSTR));
3060 else {
3061 LPWSTR *oldStrings = infoPtr->strings;
3062 infoPtr->strings =
3063 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3064 memcpy (&infoPtr->strings[0], &oldStrings[0],
3065 sizeof(LPWSTR) * infoPtr->nNumStrings);
3066 Free (oldStrings);
3069 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
3070 infoPtr->nNumStrings++;
3072 p += (len+1);
3076 return nIndex;
3080 static LRESULT
3081 TOOLBAR_AutoSize (HWND hwnd)
3083 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3084 RECT parent_rect;
3085 RECT window_rect;
3086 HWND parent;
3087 INT x, y;
3088 INT cx, cy;
3089 UINT uPosFlags = SWP_NOZORDER;
3091 TRACE("resize forced, style=%lx!\n", infoPtr->dwStyle);
3093 parent = GetParent (hwnd);
3094 GetClientRect(parent, &parent_rect);
3096 x = parent_rect.left;
3097 y = parent_rect.top;
3099 /* FIXME: we should be able to early out if nothing */
3100 /* has changed with nWidth != parent_rect width */
3102 if (infoPtr->dwStyle & CCS_NORESIZE) {
3103 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
3104 cx = 0;
3105 cy = 0;
3106 TOOLBAR_CalcToolbar (hwnd);
3108 else {
3109 infoPtr->nWidth = parent_rect.right - parent_rect.left;
3110 TOOLBAR_CalcToolbar (hwnd);
3111 InvalidateRect( hwnd, NULL, TRUE );
3112 cy = infoPtr->nHeight;
3113 cx = infoPtr->nWidth;
3115 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
3116 GetWindowRect(hwnd, &window_rect);
3117 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3118 y = window_rect.top;
3120 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
3121 GetWindowRect(hwnd, &window_rect);
3122 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3126 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3127 uPosFlags |= SWP_NOMOVE;
3129 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3130 cy += GetSystemMetrics(SM_CYEDGE);
3132 if (infoPtr->dwStyle & WS_BORDER)
3134 x = y = 1;
3135 cy += GetSystemMetrics(SM_CYEDGE);
3136 cx += GetSystemMetrics(SM_CXEDGE);
3139 infoPtr->bAutoSize = TRUE;
3140 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
3141 /* The following line makes sure that the infoPtr->bAutoSize is turned off
3142 * after the setwindowpos calls */
3143 infoPtr->bAutoSize = FALSE;
3145 return 0;
3149 static LRESULT
3150 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3152 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3154 return infoPtr->nNumButtons;
3158 static LRESULT
3159 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3161 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3163 infoPtr->dwStructSize = (DWORD)wParam;
3165 return 0;
3169 static LRESULT
3170 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3172 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3173 TBUTTON_INFO *btnPtr;
3174 INT nIndex;
3176 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3178 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3179 if (nIndex == -1)
3180 return FALSE;
3182 btnPtr = &infoPtr->buttons[nIndex];
3183 btnPtr->iBitmap = LOWORD(lParam);
3185 /* we HAVE to erase the background, the new bitmap could be */
3186 /* transparent */
3187 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3189 return TRUE;
3193 static LRESULT
3194 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3196 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3197 TBUTTON_INFO *btnPtr;
3198 INT nIndex;
3199 INT nOldIndex = -1;
3200 BOOL bChecked = FALSE;
3202 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3204 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3206 if (nIndex == -1)
3207 return FALSE;
3209 btnPtr = &infoPtr->buttons[nIndex];
3211 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3213 if (LOWORD(lParam) == FALSE)
3214 btnPtr->fsState &= ~TBSTATE_CHECKED;
3215 else {
3216 if (btnPtr->fsStyle & BTNS_GROUP) {
3217 nOldIndex =
3218 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3219 if (nOldIndex == nIndex)
3220 return 0;
3221 if (nOldIndex != -1)
3222 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3224 btnPtr->fsState |= TBSTATE_CHECKED;
3227 if( bChecked != LOWORD(lParam) )
3229 if (nOldIndex != -1)
3230 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3231 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3234 /* FIXME: Send a WM_NOTIFY?? */
3236 return TRUE;
3240 static LRESULT
3241 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3243 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3245 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3249 static LRESULT
3250 TOOLBAR_Customize (HWND hwnd)
3252 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3253 CUSTDLG_INFO custInfo;
3254 LRESULT ret;
3255 LPCVOID template;
3256 HRSRC hRes;
3257 NMHDR nmhdr;
3259 custInfo.tbInfo = infoPtr;
3260 custInfo.tbHwnd = hwnd;
3262 /* send TBN_BEGINADJUST notification */
3263 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3265 if (!(hRes = FindResourceW (COMCTL32_hModule,
3266 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3267 (LPWSTR)RT_DIALOG)))
3268 return FALSE;
3270 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3271 return FALSE;
3273 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3274 (LPDLGTEMPLATEW)template,
3275 hwnd,
3276 TOOLBAR_CustomizeDialogProc,
3277 (LPARAM)&custInfo);
3279 /* send TBN_ENDADJUST notification */
3280 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3282 return ret;
3286 static LRESULT
3287 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3289 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3290 INT nIndex = (INT)wParam;
3291 NMTOOLBARW nmtb;
3292 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3294 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3295 return FALSE;
3297 memset(&nmtb, 0, sizeof(nmtb));
3298 nmtb.iItem = btnPtr->idCommand;
3299 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3300 nmtb.tbButton.idCommand = btnPtr->idCommand;
3301 nmtb.tbButton.fsState = btnPtr->fsState;
3302 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3303 nmtb.tbButton.dwData = btnPtr->dwData;
3304 nmtb.tbButton.iString = btnPtr->iString;
3305 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3307 if ((infoPtr->hwndToolTip) &&
3308 !(btnPtr->fsStyle & BTNS_SEP)) {
3309 TTTOOLINFOW ti;
3311 ZeroMemory (&ti, sizeof(ti));
3312 ti.cbSize = sizeof(ti);
3313 ti.hwnd = hwnd;
3314 ti.uId = infoPtr->buttons[nIndex].idCommand;
3316 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
3319 if (infoPtr->nNumButtons == 1) {
3320 TRACE(" simple delete!\n");
3321 Free (infoPtr->buttons);
3322 infoPtr->buttons = NULL;
3323 infoPtr->nNumButtons = 0;
3325 else {
3326 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3327 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3329 infoPtr->nNumButtons--;
3330 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3331 if (nIndex > 0) {
3332 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3333 nIndex * sizeof(TBUTTON_INFO));
3336 if (nIndex < infoPtr->nNumButtons) {
3337 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3338 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3341 Free (oldButtons);
3344 TOOLBAR_CalcToolbar (hwnd);
3346 InvalidateRect (hwnd, NULL, TRUE);
3348 return TRUE;
3352 static LRESULT
3353 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3355 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3356 TBUTTON_INFO *btnPtr;
3357 INT nIndex;
3358 DWORD bState;
3360 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3362 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3364 if (nIndex == -1)
3365 return FALSE;
3367 btnPtr = &infoPtr->buttons[nIndex];
3369 bState = btnPtr->fsState & TBSTATE_ENABLED;
3371 /* update the toolbar button state */
3372 if(LOWORD(lParam) == FALSE) {
3373 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3374 } else {
3375 btnPtr->fsState |= TBSTATE_ENABLED;
3378 /* redraw the button only if the state of the button changed */
3379 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3380 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3382 return TRUE;
3386 static inline LRESULT
3387 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3389 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3391 return infoPtr->bAnchor;
3395 static LRESULT
3396 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3398 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3399 INT nIndex;
3401 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3402 if (nIndex == -1)
3403 return -1;
3405 return infoPtr->buttons[nIndex].iBitmap;
3409 static inline LRESULT
3410 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3412 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3416 static LRESULT
3417 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3419 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3420 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3421 INT nIndex = (INT)wParam;
3422 TBUTTON_INFO *btnPtr;
3424 if (lpTbb == NULL)
3425 return FALSE;
3427 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3428 return FALSE;
3430 btnPtr = &infoPtr->buttons[nIndex];
3431 lpTbb->iBitmap = btnPtr->iBitmap;
3432 lpTbb->idCommand = btnPtr->idCommand;
3433 lpTbb->fsState = btnPtr->fsState;
3434 lpTbb->fsStyle = btnPtr->fsStyle;
3435 lpTbb->bReserved[0] = 0;
3436 lpTbb->bReserved[1] = 0;
3437 lpTbb->dwData = btnPtr->dwData;
3438 lpTbb->iString = btnPtr->iString;
3440 return TRUE;
3444 static LRESULT
3445 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3447 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3448 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3449 TBUTTON_INFO *btnPtr;
3450 INT nIndex;
3452 if (lpTbInfo == NULL)
3453 return -1;
3454 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3455 return -1;
3457 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3458 lpTbInfo->dwMask & 0x80000000);
3459 if (nIndex == -1)
3460 return -1;
3462 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3464 if (lpTbInfo->dwMask & TBIF_COMMAND)
3465 lpTbInfo->idCommand = btnPtr->idCommand;
3466 if (lpTbInfo->dwMask & TBIF_IMAGE)
3467 lpTbInfo->iImage = btnPtr->iBitmap;
3468 if (lpTbInfo->dwMask & TBIF_LPARAM)
3469 lpTbInfo->lParam = btnPtr->dwData;
3470 if (lpTbInfo->dwMask & TBIF_SIZE)
3471 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3472 if (lpTbInfo->dwMask & TBIF_STATE)
3473 lpTbInfo->fsState = btnPtr->fsState;
3474 if (lpTbInfo->dwMask & TBIF_STYLE)
3475 lpTbInfo->fsStyle = btnPtr->fsStyle;
3476 if (lpTbInfo->dwMask & TBIF_TEXT) {
3477 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3478 can't use TOOLBAR_GetText here */
3479 LPWSTR lpText;
3480 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3481 lpText = (LPWSTR)btnPtr->iString;
3482 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3483 } else
3484 lpTbInfo->pszText[0] = '\0';
3486 return nIndex;
3490 static LRESULT
3491 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3493 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3494 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3495 TBUTTON_INFO *btnPtr;
3496 INT nIndex;
3498 if (lpTbInfo == NULL)
3499 return -1;
3500 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3501 return -1;
3503 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3504 lpTbInfo->dwMask & 0x80000000);
3505 if (nIndex == -1)
3506 return -1;
3508 btnPtr = &infoPtr->buttons[nIndex];
3510 if(!btnPtr)
3511 return -1;
3513 if (lpTbInfo->dwMask & TBIF_COMMAND)
3514 lpTbInfo->idCommand = btnPtr->idCommand;
3515 if (lpTbInfo->dwMask & TBIF_IMAGE)
3516 lpTbInfo->iImage = btnPtr->iBitmap;
3517 if (lpTbInfo->dwMask & TBIF_LPARAM)
3518 lpTbInfo->lParam = btnPtr->dwData;
3519 if (lpTbInfo->dwMask & TBIF_SIZE)
3520 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3521 if (lpTbInfo->dwMask & TBIF_STATE)
3522 lpTbInfo->fsState = btnPtr->fsState;
3523 if (lpTbInfo->dwMask & TBIF_STYLE)
3524 lpTbInfo->fsStyle = btnPtr->fsStyle;
3525 if (lpTbInfo->dwMask & TBIF_TEXT) {
3526 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3527 can't use TOOLBAR_GetText here */
3528 LPWSTR lpText;
3529 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3530 lpText = (LPWSTR)btnPtr->iString;
3531 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3532 } else
3533 lpTbInfo->pszText[0] = '\0';
3536 return nIndex;
3540 static LRESULT
3541 TOOLBAR_GetButtonSize (HWND hwnd)
3543 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3545 if (infoPtr->nNumButtons > 0)
3546 return MAKELONG((WORD)infoPtr->nButtonWidth,
3547 (WORD)infoPtr->nButtonHeight);
3548 else
3549 return MAKELONG(23,22);
3553 static LRESULT
3554 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3556 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3557 INT nIndex;
3558 LPWSTR lpText;
3560 if (lParam == 0)
3561 return -1;
3563 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3564 if (nIndex == -1)
3565 return -1;
3567 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3569 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3570 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3574 static LRESULT
3575 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3577 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3578 INT nIndex;
3579 LPWSTR lpText;
3580 LRESULT ret = 0;
3582 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3583 if (nIndex == -1)
3584 return -1;
3586 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3588 if (lpText)
3590 ret = strlenW (lpText);
3592 if (lParam)
3593 strcpyW ((LPWSTR)lParam, lpText);
3596 return ret;
3600 static LRESULT
3601 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3603 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3604 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3605 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3609 inline static LRESULT
3610 TOOLBAR_GetExtendedStyle (HWND hwnd)
3612 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3614 TRACE("\n");
3616 return infoPtr->dwExStyle;
3620 static LRESULT
3621 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3623 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3624 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3625 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3629 static LRESULT
3630 TOOLBAR_GetHotItem (HWND hwnd)
3632 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3634 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
3635 return -1;
3637 if (infoPtr->nHotItem < 0)
3638 return -1;
3640 return (LRESULT)infoPtr->nHotItem;
3644 static LRESULT
3645 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3647 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3648 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3649 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3653 static LRESULT
3654 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3656 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3657 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3659 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3661 *lptbim = infoPtr->tbim;
3663 return 0;
3667 static LRESULT
3668 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3670 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3672 TRACE("hwnd = %p\n", hwnd);
3674 return (LRESULT)infoPtr->clrInsertMark;
3678 static LRESULT
3679 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3681 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3682 TBUTTON_INFO *btnPtr;
3683 LPRECT lpRect;
3684 INT nIndex;
3686 nIndex = (INT)wParam;
3687 btnPtr = &infoPtr->buttons[nIndex];
3688 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3689 return FALSE;
3690 lpRect = (LPRECT)lParam;
3691 if (lpRect == NULL)
3692 return FALSE;
3693 if (btnPtr->fsState & TBSTATE_HIDDEN)
3694 return FALSE;
3696 lpRect->left = btnPtr->rect.left;
3697 lpRect->right = btnPtr->rect.right;
3698 lpRect->bottom = btnPtr->rect.bottom;
3699 lpRect->top = btnPtr->rect.top;
3701 return TRUE;
3705 static LRESULT
3706 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3708 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3709 LPSIZE lpSize = (LPSIZE)lParam;
3711 if (lpSize == NULL)
3712 return FALSE;
3714 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3715 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3717 TRACE("maximum size %ld x %ld\n",
3718 infoPtr->rcBound.right - infoPtr->rcBound.left,
3719 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3721 return TRUE;
3725 /* << TOOLBAR_GetObject >> */
3728 static LRESULT
3729 TOOLBAR_GetPadding (HWND hwnd)
3731 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3732 DWORD oldPad;
3734 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3735 return (LRESULT) oldPad;
3739 static LRESULT
3740 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3742 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3743 TBUTTON_INFO *btnPtr;
3744 LPRECT lpRect;
3745 INT nIndex;
3747 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3748 btnPtr = &infoPtr->buttons[nIndex];
3749 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3750 return FALSE;
3751 lpRect = (LPRECT)lParam;
3752 if (lpRect == NULL)
3753 return FALSE;
3755 lpRect->left = btnPtr->rect.left;
3756 lpRect->right = btnPtr->rect.right;
3757 lpRect->bottom = btnPtr->rect.bottom;
3758 lpRect->top = btnPtr->rect.top;
3760 return TRUE;
3764 static LRESULT
3765 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3767 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3769 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3770 return infoPtr->nRows;
3771 else
3772 return 1;
3776 static LRESULT
3777 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3779 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3780 INT nIndex;
3782 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3783 if (nIndex == -1)
3784 return -1;
3786 return infoPtr->buttons[nIndex].fsState;
3790 static LRESULT
3791 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3793 return GetWindowLongW(hwnd, GWL_STYLE);
3797 static LRESULT
3798 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3800 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3802 return infoPtr->nMaxTextRows;
3806 static LRESULT
3807 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3809 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3811 return (LRESULT)infoPtr->hwndToolTip;
3815 static LRESULT
3816 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3818 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3820 TRACE("%s hwnd=%p\n",
3821 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3823 return infoPtr->bUnicode;
3827 inline static LRESULT
3828 TOOLBAR_GetVersion (HWND hwnd)
3830 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3831 return infoPtr->iVersion;
3835 static LRESULT
3836 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3838 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3839 TBUTTON_INFO *btnPtr;
3840 INT nIndex;
3842 TRACE("\n");
3844 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3845 if (nIndex == -1)
3846 return FALSE;
3848 btnPtr = &infoPtr->buttons[nIndex];
3849 if (LOWORD(lParam) == FALSE)
3850 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3851 else
3852 btnPtr->fsState |= TBSTATE_HIDDEN;
3854 TOOLBAR_CalcToolbar (hwnd);
3856 InvalidateRect (hwnd, NULL, TRUE);
3858 return TRUE;
3862 inline static LRESULT
3863 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3865 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3869 static LRESULT
3870 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3872 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3873 TBUTTON_INFO *btnPtr;
3874 INT nIndex;
3875 DWORD oldState;
3877 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3878 if (nIndex == -1)
3879 return FALSE;
3881 btnPtr = &infoPtr->buttons[nIndex];
3882 oldState = btnPtr->fsState;
3883 if (LOWORD(lParam) == FALSE)
3884 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3885 else
3886 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3888 if(oldState != btnPtr->fsState)
3889 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3891 return TRUE;
3895 static LRESULT
3896 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3898 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3899 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3900 INT nIndex = (INT)wParam;
3901 TBUTTON_INFO *oldButtons;
3903 if (lpTbb == NULL)
3904 return FALSE;
3906 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3908 if (nIndex == -1) {
3909 /* EPP: this seems to be an undocumented call (from my IE4)
3910 * I assume in that case that:
3911 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3912 * - index of insertion is at the end of existing buttons
3913 * I only see this happen with nIndex == -1, but it could have a special
3914 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3916 nIndex = infoPtr->nNumButtons;
3918 } else if (nIndex < 0)
3919 return FALSE;
3921 /* If the string passed is not an index, assume address of string
3922 and do our own AddString */
3923 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3924 LPSTR ptr;
3925 INT len;
3927 TRACE("string %s passed instead of index, adding string\n",
3928 debugstr_a((LPSTR)lpTbb->iString));
3929 len = strlen((LPSTR)lpTbb->iString) + 2;
3930 ptr = Alloc(len);
3931 strcpy(ptr, (LPSTR)lpTbb->iString);
3932 ptr[len - 1] = 0; /* ended by two '\0' */
3933 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3934 Free(ptr);
3937 TRACE("inserting button index=%d\n", nIndex);
3938 if (nIndex > infoPtr->nNumButtons) {
3939 nIndex = infoPtr->nNumButtons;
3940 TRACE("adjust index=%d\n", nIndex);
3943 oldButtons = infoPtr->buttons;
3944 infoPtr->nNumButtons++;
3945 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3946 /* pre insert copy */
3947 if (nIndex > 0) {
3948 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3949 nIndex * sizeof(TBUTTON_INFO));
3952 /* insert new button */
3953 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3954 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3955 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3956 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3957 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3958 /* if passed string and not index, then add string */
3959 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3960 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3962 else
3963 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3965 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3966 TTTOOLINFOW ti;
3968 ZeroMemory (&ti, sizeof(ti));
3969 ti.cbSize = sizeof (ti);
3970 ti.hwnd = hwnd;
3971 ti.uId = lpTbb->idCommand;
3972 ti.hinst = 0;
3973 ti.lpszText = LPSTR_TEXTCALLBACKW;
3975 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3976 0, (LPARAM)&ti);
3979 /* post insert copy */
3980 if (nIndex < infoPtr->nNumButtons - 1) {
3981 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3982 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3985 Free (oldButtons);
3987 TOOLBAR_CalcToolbar (hwnd);
3989 InvalidateRect (hwnd, NULL, TRUE);
3991 return TRUE;
3995 static LRESULT
3996 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3998 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3999 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
4000 INT nIndex = (INT)wParam;
4001 TBUTTON_INFO *oldButtons;
4003 if (lpTbb == NULL)
4004 return FALSE;
4006 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
4008 if (nIndex == -1) {
4009 /* EPP: this seems to be an undocumented call (from my IE4)
4010 * I assume in that case that:
4011 * - lpTbb->iString is a string pointer (not a string index in strings[] table
4012 * - index of insertion is at the end of existing buttons
4013 * I only see this happen with nIndex == -1, but it could have a special
4014 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
4016 nIndex = infoPtr->nNumButtons;
4018 } else if (nIndex < 0)
4019 return FALSE;
4021 /* If the string passed is not an index, assume address of string
4022 and do our own AddString */
4023 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
4024 LPWSTR ptr;
4025 INT len;
4027 TRACE("string %s passed instead of index, adding string\n",
4028 debugstr_w((LPWSTR)lpTbb->iString));
4029 len = strlenW((LPWSTR)lpTbb->iString) + 2;
4030 ptr = Alloc(len*sizeof(WCHAR));
4031 strcpyW(ptr, (LPWSTR)lpTbb->iString);
4032 ptr[len - 1] = 0; /* ended by two '\0' */
4033 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
4034 Free(ptr);
4037 TRACE("inserting button index=%d\n", nIndex);
4038 if (nIndex > infoPtr->nNumButtons) {
4039 nIndex = infoPtr->nNumButtons;
4040 TRACE("adjust index=%d\n", nIndex);
4043 oldButtons = infoPtr->buttons;
4044 infoPtr->nNumButtons++;
4045 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
4046 /* pre insert copy */
4047 if (nIndex > 0) {
4048 memcpy (&infoPtr->buttons[0], &oldButtons[0],
4049 nIndex * sizeof(TBUTTON_INFO));
4052 /* insert new button */
4053 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
4054 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
4055 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
4056 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
4057 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
4058 /* if passed string and not index, then add string */
4059 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
4060 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
4062 else
4063 infoPtr->buttons[nIndex].iString = lpTbb->iString;
4065 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
4066 TTTOOLINFOW ti;
4068 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
4069 ti.cbSize = sizeof (TTTOOLINFOW);
4070 ti.hwnd = hwnd;
4071 ti.uId = lpTbb->idCommand;
4072 ti.hinst = 0;
4073 ti.lpszText = LPSTR_TEXTCALLBACKW;
4075 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
4076 0, (LPARAM)&ti);
4079 /* post insert copy */
4080 if (nIndex < infoPtr->nNumButtons - 1) {
4081 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
4082 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
4085 Free (oldButtons);
4087 TOOLBAR_CalcToolbar (hwnd);
4089 InvalidateRect (hwnd, NULL, TRUE);
4091 return TRUE;
4095 /* << TOOLBAR_InsertMarkHitTest >> */
4098 static LRESULT
4099 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
4101 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4102 INT nIndex;
4104 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4105 if (nIndex == -1)
4106 return FALSE;
4108 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
4112 static LRESULT
4113 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
4115 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4116 INT nIndex;
4118 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4119 if (nIndex == -1)
4120 return FALSE;
4122 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
4126 static LRESULT
4127 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
4129 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4130 INT nIndex;
4132 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4133 if (nIndex == -1)
4134 return TRUE;
4136 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
4140 static LRESULT
4141 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
4143 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4144 INT nIndex;
4146 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4147 if (nIndex == -1)
4148 return FALSE;
4150 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
4154 static LRESULT
4155 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4157 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4158 INT nIndex;
4160 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4161 if (nIndex == -1)
4162 return FALSE;
4164 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
4168 static LRESULT
4169 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
4171 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4172 INT nIndex;
4174 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4175 if (nIndex == -1)
4176 return FALSE;
4178 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
4182 static LRESULT
4183 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
4185 TBADDBITMAP tbab;
4186 tbab.hInst = (HINSTANCE)lParam;
4187 tbab.nID = (UINT_PTR)wParam;
4189 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
4191 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
4195 static LRESULT
4196 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
4198 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4199 WCHAR wAccel = (WCHAR)wParam;
4200 UINT* pIDButton = (UINT*)lParam;
4201 WCHAR wszAccel[] = {'&',wAccel,0};
4202 int i;
4204 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4205 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4207 for (i = 0; i < infoPtr->nNumButtons; i++)
4209 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4210 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4211 !(btnPtr->fsState & TBSTATE_HIDDEN))
4213 int iLen = strlenW(wszAccel);
4214 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4216 if (!lpszStr)
4217 continue;
4219 while (*lpszStr)
4221 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4223 lpszStr += 2;
4224 continue;
4226 if (!strncmpiW(lpszStr, wszAccel, iLen))
4228 *pIDButton = btnPtr->idCommand;
4229 return TRUE;
4231 lpszStr++;
4235 return FALSE;
4239 static LRESULT
4240 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4242 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4243 INT nIndex;
4244 DWORD oldState;
4245 TBUTTON_INFO *btnPtr;
4247 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4249 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4250 if (nIndex == -1)
4251 return FALSE;
4253 btnPtr = &infoPtr->buttons[nIndex];
4254 oldState = btnPtr->fsState;
4256 if (LOWORD(lParam))
4257 btnPtr->fsState |= TBSTATE_MARKED;
4258 else
4259 btnPtr->fsState &= ~TBSTATE_MARKED;
4261 if(oldState != btnPtr->fsState)
4262 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4264 return TRUE;
4268 /* fixes up an index of a button affected by a move */
4269 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4271 if (bMoveUp)
4273 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4274 (*pIndex)--;
4275 else if (*pIndex == nIndex)
4276 *pIndex = nMoveIndex;
4278 else
4280 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4281 (*pIndex)++;
4282 else if (*pIndex == nIndex)
4283 *pIndex = nMoveIndex;
4288 static LRESULT
4289 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4291 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4292 INT nIndex;
4293 INT nCount;
4294 INT nMoveIndex = (INT)lParam;
4295 TBUTTON_INFO button;
4297 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4299 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4300 if ((nIndex == -1) || (nMoveIndex < 0))
4301 return FALSE;
4303 if (nMoveIndex > infoPtr->nNumButtons - 1)
4304 nMoveIndex = infoPtr->nNumButtons - 1;
4306 button = infoPtr->buttons[nIndex];
4308 /* move button right */
4309 if (nIndex < nMoveIndex)
4311 nCount = nMoveIndex - nIndex;
4312 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4313 infoPtr->buttons[nMoveIndex] = button;
4315 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4316 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4317 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4318 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4320 else if (nIndex > nMoveIndex) /* move button left */
4322 nCount = nIndex - nMoveIndex;
4323 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4324 infoPtr->buttons[nMoveIndex] = button;
4326 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4327 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4328 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4329 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4332 TOOLBAR_CalcToolbar(hwnd);
4333 InvalidateRect(hwnd, NULL, TRUE);
4335 return TRUE;
4339 static LRESULT
4340 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4342 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4343 TBUTTON_INFO *btnPtr;
4344 INT nIndex;
4345 DWORD oldState;
4347 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4348 if (nIndex == -1)
4349 return FALSE;
4351 btnPtr = &infoPtr->buttons[nIndex];
4352 oldState = btnPtr->fsState;
4353 if (LOWORD(lParam) == FALSE)
4354 btnPtr->fsState &= ~TBSTATE_PRESSED;
4355 else
4356 btnPtr->fsState |= TBSTATE_PRESSED;
4358 if(oldState != btnPtr->fsState)
4359 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4361 return TRUE;
4364 /* FIXME: there might still be some confusion her between number of buttons
4365 * and number of bitmaps */
4366 static LRESULT
4367 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4369 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4370 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4371 HBITMAP hBitmap;
4372 int i = 0, nOldButtons = 0, pos = 0;
4373 int nOldBitmaps, nNewBitmaps = 0;
4374 HIMAGELIST himlDef = 0;
4376 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4377 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4378 lpReplace->nButtons);
4380 if (lpReplace->hInstOld == HINST_COMMCTRL)
4382 FIXME("changing standard bitmaps not implemented\n");
4383 return FALSE;
4385 else if (lpReplace->hInstOld != 0)
4387 FIXME("resources not in the current module not implemented\n");
4388 return FALSE;
4390 else
4392 hBitmap = (HBITMAP) lpReplace->nIDNew;
4395 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4396 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4397 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4398 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4399 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4401 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4402 nOldButtons = tbi->nButtons;
4403 tbi->nButtons = lpReplace->nButtons;
4404 tbi->hInst = lpReplace->hInstNew;
4405 tbi->nID = lpReplace->nIDNew;
4406 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4407 break;
4409 pos += tbi->nButtons;
4412 if (nOldButtons == 0)
4414 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4415 return FALSE;
4418 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4419 nOldBitmaps = ImageList_GetImageCount(himlDef);
4421 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4423 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4424 ImageList_Remove(himlDef, i);
4426 if (hBitmap)
4428 BITMAP bmp;
4429 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4430 HDC hdcImage, hdcBitmap;
4432 /* copy the bitmap before adding it so that the user's bitmap
4433 * doesn't get modified.
4435 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4437 hdcImage = CreateCompatibleDC(0);
4438 hdcBitmap = CreateCompatibleDC(0);
4440 /* create new bitmap */
4441 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4442 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4443 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4445 /* Copy the user's image */
4446 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4447 hdcBitmap, 0, 0, SRCCOPY);
4449 SelectObject (hdcImage, hOldBitmapLoad);
4450 SelectObject (hdcBitmap, hOldBitmapBitmap);
4451 DeleteDC (hdcImage);
4452 DeleteDC (hdcBitmap);
4454 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4455 nNewBitmaps = ImageList_GetImageCount(himlDef);
4456 DeleteObject (hbmLoad);
4459 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4461 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4462 pos, nOldBitmaps, nNewBitmaps);
4464 InvalidateRect(hwnd, NULL, TRUE);
4466 return TRUE;
4470 /* helper for TOOLBAR_SaveRestoreW */
4471 static BOOL
4472 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4474 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4475 debugstr_w(lpSave->pszValueName));
4477 return FALSE;
4481 /* helper for TOOLBAR_Restore */
4482 static void
4483 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4485 INT i;
4486 TTTOOLINFOW ti;
4488 ZeroMemory(&ti, sizeof(ti));
4489 ti.cbSize = sizeof(ti);
4490 ti.hwnd = infoPtr->hwndSelf;
4492 for (i = 0; i < infoPtr->nNumButtons; i++)
4494 if ((infoPtr->hwndToolTip) &&
4495 !(infoPtr->buttons[i].fsStyle & BTNS_SEP))
4497 ti.uId = infoPtr->buttons[i].idCommand;
4498 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
4502 Free(infoPtr->buttons);
4503 infoPtr->buttons = NULL;
4504 infoPtr->nNumButtons = 0;
4508 /* helper for TOOLBAR_SaveRestoreW */
4509 static BOOL
4510 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4512 LONG res;
4513 HKEY hkey = NULL;
4514 BOOL ret = FALSE;
4515 DWORD dwType;
4516 DWORD dwSize = 0;
4517 NMTBRESTORE nmtbr;
4519 /* restore toolbar information */
4520 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4521 debugstr_w(lpSave->pszValueName));
4523 memset(&nmtbr, 0, sizeof(nmtbr));
4525 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4526 KEY_QUERY_VALUE, &hkey);
4527 if (!res)
4528 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4529 NULL, &dwSize);
4530 if (!res && dwType != REG_BINARY)
4531 res = ERROR_FILE_NOT_FOUND;
4532 if (!res)
4534 nmtbr.pData = Alloc(dwSize);
4535 nmtbr.cbData = (UINT)dwSize;
4536 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4538 if (!res)
4539 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4540 (LPBYTE)nmtbr.pData, &dwSize);
4541 if (!res)
4543 nmtbr.pCurrent = nmtbr.pData;
4544 nmtbr.iItem = -1;
4545 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4546 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4548 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4550 INT i;
4552 /* remove all existing buttons as this function is designed to
4553 * restore the toolbar to a previously saved state */
4554 TOOLBAR_DeleteAllButtons(infoPtr);
4556 for (i = 0; i < nmtbr.cButtons; i++)
4558 nmtbr.iItem = i;
4559 nmtbr.tbButton.iBitmap = -1;
4560 nmtbr.tbButton.fsState = 0;
4561 nmtbr.tbButton.fsStyle = 0;
4562 nmtbr.tbButton.idCommand = 0;
4563 if (*nmtbr.pCurrent == (DWORD)-1)
4565 /* separator */
4566 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4567 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4569 else if (*nmtbr.pCurrent == (DWORD)-2)
4570 /* hidden button */
4571 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4572 else
4573 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4575 nmtbr.pCurrent++;
4577 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4579 /* can't contain real string as we don't know whether
4580 * the client put an ANSI or Unicode string in there */
4581 if (HIWORD(nmtbr.tbButton.iString))
4582 nmtbr.tbButton.iString = 0;
4584 TOOLBAR_InsertButtonW(infoPtr->hwndSelf, -1,
4585 (LPARAM)&nmtbr.tbButton);
4588 /* do legacy notifications */
4589 if (infoPtr->iVersion < 5)
4591 /* FIXME: send TBN_BEGINADJUST */
4592 FIXME("send TBN_GETBUTTONINFO for each button\n");
4593 /* FIXME: send TBN_ENDADJUST */
4596 /* remove all uninitialised buttons
4597 * note: loop backwards to avoid having to fixup i on a
4598 * delete */
4599 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4600 if (infoPtr->buttons[i].iBitmap == -1)
4601 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4603 /* only indicate success if at least one button survived */
4604 if (infoPtr->nNumButtons > 0) ret = TRUE;
4607 Free (nmtbr.pData);
4608 RegCloseKey(hkey);
4610 return ret;
4614 static LRESULT
4615 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4617 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4619 if (lpSave == NULL) return 0;
4621 if (wParam)
4622 return TOOLBAR_Save(infoPtr, lpSave);
4623 else
4624 return TOOLBAR_Restore(infoPtr, lpSave);
4628 static LRESULT
4629 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4631 LPWSTR pszValueName = 0, pszSubKey = 0;
4632 TBSAVEPARAMSW SaveW;
4633 LRESULT result = 0;
4634 int len;
4636 if (lpSave == NULL) return 0;
4638 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4639 pszSubKey = Alloc(len * sizeof(WCHAR));
4640 if (pszSubKey) goto exit;
4641 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4643 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4644 pszValueName = Alloc(len * sizeof(WCHAR));
4645 if (!pszValueName) goto exit;
4646 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4648 SaveW.pszValueName = pszValueName;
4649 SaveW.pszSubKey = pszSubKey;
4650 SaveW.hkr = lpSave->hkr;
4651 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4653 exit:
4654 Free (pszValueName);
4655 Free (pszSubKey);
4657 return result;
4661 static LRESULT
4662 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4664 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4665 BOOL bOldAnchor = infoPtr->bAnchor;
4667 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4669 infoPtr->bAnchor = (BOOL)wParam;
4671 /* Native does not remove the hot effect from an already hot button */
4673 return (LRESULT)bOldAnchor;
4677 static LRESULT
4678 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4680 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4681 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4683 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4685 if (wParam != 0)
4686 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4688 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4689 return FALSE;
4691 if (infoPtr->nNumButtons > 0)
4692 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4693 infoPtr->nNumButtons,
4694 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4695 LOWORD(lParam), HIWORD(lParam));
4697 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4698 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4701 if ((himlDef == infoPtr->himlInt) &&
4702 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4704 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4705 infoPtr->nBitmapHeight);
4708 return TRUE;
4712 static LRESULT
4713 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4715 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4716 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4717 TBUTTON_INFO *btnPtr;
4718 INT nIndex;
4719 RECT oldBtnRect;
4721 if (lptbbi == NULL)
4722 return FALSE;
4723 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4724 return FALSE;
4726 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4727 lptbbi->dwMask & 0x80000000);
4728 if (nIndex == -1)
4729 return FALSE;
4731 btnPtr = &infoPtr->buttons[nIndex];
4732 if (lptbbi->dwMask & TBIF_COMMAND)
4733 btnPtr->idCommand = lptbbi->idCommand;
4734 if (lptbbi->dwMask & TBIF_IMAGE)
4735 btnPtr->iBitmap = lptbbi->iImage;
4736 if (lptbbi->dwMask & TBIF_LPARAM)
4737 btnPtr->dwData = lptbbi->lParam;
4738 if (lptbbi->dwMask & TBIF_SIZE)
4739 btnPtr->cx = lptbbi->cx;
4740 if (lptbbi->dwMask & TBIF_STATE)
4741 btnPtr->fsState = lptbbi->fsState;
4742 if (lptbbi->dwMask & TBIF_STYLE)
4743 btnPtr->fsStyle = lptbbi->fsStyle;
4745 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4746 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4747 /* iString is index, zero it to make Str_SetPtr succeed */
4748 btnPtr->iString=0;
4750 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4753 /* save the button rect to see if we need to redraw the whole toolbar */
4754 oldBtnRect = btnPtr->rect;
4755 TOOLBAR_CalcToolbar(hwnd);
4757 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4758 InvalidateRect(hwnd, NULL, TRUE);
4759 else
4760 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4762 return TRUE;
4766 static LRESULT
4767 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4769 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4770 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4771 TBUTTON_INFO *btnPtr;
4772 INT nIndex;
4773 RECT oldBtnRect;
4775 if (lptbbi == NULL)
4776 return FALSE;
4777 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4778 return FALSE;
4780 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4781 lptbbi->dwMask & 0x80000000);
4782 if (nIndex == -1)
4783 return FALSE;
4785 btnPtr = &infoPtr->buttons[nIndex];
4786 if (lptbbi->dwMask & TBIF_COMMAND)
4787 btnPtr->idCommand = lptbbi->idCommand;
4788 if (lptbbi->dwMask & TBIF_IMAGE)
4789 btnPtr->iBitmap = lptbbi->iImage;
4790 if (lptbbi->dwMask & TBIF_LPARAM)
4791 btnPtr->dwData = lptbbi->lParam;
4792 if (lptbbi->dwMask & TBIF_SIZE)
4793 btnPtr->cx = lptbbi->cx;
4794 if (lptbbi->dwMask & TBIF_STATE)
4795 btnPtr->fsState = lptbbi->fsState;
4796 if (lptbbi->dwMask & TBIF_STYLE)
4797 btnPtr->fsStyle = lptbbi->fsStyle;
4799 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4800 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4801 /* iString is index, zero it to make Str_SetPtr succeed */
4802 btnPtr->iString=0;
4803 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4806 /* save the button rect to see if we need to redraw the whole toolbar */
4807 oldBtnRect = btnPtr->rect;
4808 TOOLBAR_CalcToolbar(hwnd);
4810 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4811 InvalidateRect(hwnd, NULL, TRUE);
4812 else
4813 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4815 return TRUE;
4819 static LRESULT
4820 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4822 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4823 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4825 if ((cx < 0) || (cy < 0))
4827 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4828 return FALSE;
4831 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4833 /* The documentation claims you can only change the button size before
4834 * any button has been added. But this is wrong.
4835 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4836 * it to the toolbar, and it checks that the return value is nonzero - mjm
4837 * Further testing shows that we must actually perform the change too.
4840 * The documentation also does not mention that if 0 is supplied for
4841 * either size, the system changes it to the default of 24 wide and
4842 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4844 infoPtr->nButtonWidth = (cx) ? cx : 24;
4845 infoPtr->nButtonHeight = (cy) ? cy : 22;
4846 return TRUE;
4850 static LRESULT
4851 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4853 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4855 /* if setting to current values, ignore */
4856 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4857 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4858 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4859 infoPtr->cxMin, infoPtr->cxMax);
4860 return TRUE;
4863 /* save new values */
4864 infoPtr->cxMin = (INT)LOWORD(lParam);
4865 infoPtr->cxMax = (INT)HIWORD(lParam);
4867 /* if both values are 0 then we are done */
4868 if (lParam == 0) {
4869 TRACE("setting both min and max to 0, norecalc\n");
4870 return TRUE;
4873 /* otherwise we need to recalc the toolbar and in some cases
4874 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4875 which doesn't actually draw - GA). */
4876 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4877 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4879 TOOLBAR_CalcToolbar (hwnd);
4881 InvalidateRect (hwnd, NULL, TRUE);
4883 return TRUE;
4887 static LRESULT
4888 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4890 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4891 INT nIndex = (INT)wParam;
4893 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4894 return FALSE;
4896 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4898 if (infoPtr->hwndToolTip) {
4900 FIXME("change tool tip!\n");
4904 return TRUE;
4908 static LRESULT
4909 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4911 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4912 HIMAGELIST himl = (HIMAGELIST)lParam;
4913 HIMAGELIST himlTemp;
4914 INT id = 0;
4916 if (infoPtr->iVersion >= 5)
4917 id = wParam;
4919 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4920 &infoPtr->cimlDis, himl, id);
4922 /* FIXME: redraw ? */
4924 return (LRESULT)himlTemp;
4928 static LRESULT
4929 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4931 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4932 DWORD dwTemp;
4934 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4936 dwTemp = infoPtr->dwDTFlags;
4937 infoPtr->dwDTFlags =
4938 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4940 return (LRESULT)dwTemp;
4943 /* This function differs a bit from what MSDN says it does:
4944 * 1. lParam contains extended style flags to OR with current style
4945 * (MSDN isn't clear on the OR bit)
4946 * 2. wParam appears to contain extended style flags to be reset
4947 * (MSDN says that this parameter is reserved)
4949 static LRESULT
4950 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4952 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4953 DWORD dwTemp;
4955 dwTemp = infoPtr->dwExStyle;
4956 infoPtr->dwExStyle &= ~wParam;
4957 infoPtr->dwExStyle |= (DWORD)lParam;
4959 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4961 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4962 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4963 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4965 TOOLBAR_CalcToolbar (hwnd);
4967 TOOLBAR_AutoSize(hwnd);
4969 InvalidateRect(hwnd, NULL, TRUE);
4971 return (LRESULT)dwTemp;
4975 static LRESULT
4976 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4978 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4979 HIMAGELIST himlTemp;
4980 HIMAGELIST himl = (HIMAGELIST)lParam;
4981 INT id = 0;
4983 if (infoPtr->iVersion >= 5)
4984 id = wParam;
4986 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4988 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4989 &infoPtr->cimlHot, himl, id);
4991 /* FIXME: redraw ? */
4993 return (LRESULT)himlTemp;
4997 /* Makes previous hot button no longer hot, makes the specified
4998 * button hot and sends appropriate notifications. dwReason is one or
4999 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
5000 * NOTE 1: this function does not validate nHit
5001 * NOTE 2: the name of this function is completely made up and
5002 * not based on any documentation from Microsoft. */
5003 static void
5004 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
5006 if (infoPtr->nHotItem != nHit)
5008 NMTBHOTITEM nmhotitem;
5009 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
5010 LRESULT no_highlight;
5012 /* Remove the effect of an old hot button if the button was
5013 drawn with the hot button effect */
5014 if(infoPtr->nHotItem >= 0)
5016 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5017 oldBtnPtr->bHot = FALSE;
5020 infoPtr->nHotItem = nHit;
5022 /* It's not a separator or in nowhere. It's a hot button. */
5023 if (nHit >= 0)
5024 btnPtr = &infoPtr->buttons[nHit];
5026 nmhotitem.dwFlags = dwReason;
5027 if (oldBtnPtr)
5028 nmhotitem.idOld = oldBtnPtr->idCommand;
5029 else
5030 nmhotitem.dwFlags |= HICF_ENTERING;
5031 if (btnPtr)
5032 nmhotitem.idNew = btnPtr->idCommand;
5033 else
5034 nmhotitem.dwFlags |= HICF_LEAVING;
5036 no_highlight = TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE);
5038 /* now invalidate the old and new buttons so they will be painted,
5039 * but only if they are enabled - disabled buttons cannot become hot */
5040 if (oldBtnPtr && (oldBtnPtr->fsState & TBSTATE_ENABLED))
5041 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
5042 if (btnPtr && !no_highlight && (btnPtr->fsState & TBSTATE_ENABLED))
5044 btnPtr->bHot = TRUE;
5045 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5050 static LRESULT
5051 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
5053 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5054 INT nOldHotItem = infoPtr->nHotItem;
5056 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
5058 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5059 wParam = -1;
5061 /* NOTE: an application can still remove the hot item even if anchor
5062 * highlighting is enabled */
5064 if (infoPtr->dwStyle & TBSTYLE_FLAT)
5065 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
5067 if (nOldHotItem < 0)
5068 return -1;
5070 return (LRESULT)nOldHotItem;
5074 static LRESULT
5075 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
5077 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5078 HIMAGELIST himlTemp;
5079 HIMAGELIST himl = (HIMAGELIST)lParam;
5080 INT i, id = 0;
5082 if (infoPtr->iVersion >= 5)
5083 id = wParam;
5085 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
5086 &infoPtr->cimlDef, himl, id);
5088 infoPtr->nNumBitmaps = 0;
5089 for (i = 0; i < infoPtr->cimlDef; i++)
5090 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
5092 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
5093 &infoPtr->nBitmapHeight))
5095 infoPtr->nBitmapWidth = 1;
5096 infoPtr->nBitmapHeight = 1;
5099 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
5100 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
5101 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
5103 InvalidateRect(hwnd, NULL, TRUE);
5105 return (LRESULT)himlTemp;
5109 static LRESULT
5110 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5112 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5114 infoPtr->nIndent = (INT)wParam;
5116 TRACE("\n");
5118 /* process only on indent changing */
5119 if(infoPtr->nIndent != (INT)wParam)
5121 infoPtr->nIndent = (INT)wParam;
5122 TOOLBAR_CalcToolbar (hwnd);
5123 InvalidateRect(hwnd, NULL, FALSE);
5126 return TRUE;
5130 static LRESULT
5131 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
5133 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5134 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
5136 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
5138 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
5140 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
5141 return 0;
5144 if ((lptbim->iButton == -1) ||
5145 ((lptbim->iButton < infoPtr->nNumButtons) &&
5146 (lptbim->iButton >= 0)))
5148 infoPtr->tbim = *lptbim;
5149 /* FIXME: don't need to update entire toolbar */
5150 InvalidateRect(hwnd, NULL, TRUE);
5152 else
5153 ERR("Invalid button index %d\n", lptbim->iButton);
5155 return 0;
5159 static LRESULT
5160 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
5162 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5164 infoPtr->clrInsertMark = (COLORREF)lParam;
5166 /* FIXME: don't need to update entire toolbar */
5167 InvalidateRect(hwnd, NULL, TRUE);
5169 return 0;
5173 static LRESULT
5174 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5176 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5178 infoPtr->nMaxTextRows = (INT)wParam;
5180 TOOLBAR_CalcToolbar(hwnd);
5181 return TRUE;
5185 /* MSDN gives slightly wrong info on padding.
5186 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
5187 * 2. It is not used to create a blank area between the edge of the button
5188 * and the text or image if TBSTYLE_LIST is set. It is used to control
5189 * the gap between the image and text.
5190 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
5191 * to control the bottom and right borders [with the border being
5192 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
5193 * is shared evenly on both sides of the button.
5194 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
5196 static LRESULT
5197 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
5199 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5200 DWORD oldPad;
5202 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5203 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
5204 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
5205 TRACE("cx=%ld, cy=%ld\n",
5206 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5207 return (LRESULT) oldPad;
5211 static LRESULT
5212 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5214 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5215 HWND hwndOldNotify;
5217 TRACE("\n");
5219 hwndOldNotify = infoPtr->hwndNotify;
5220 infoPtr->hwndNotify = (HWND)wParam;
5222 return (LRESULT)hwndOldNotify;
5226 static LRESULT
5227 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5229 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5230 LPRECT lprc = (LPRECT)lParam;
5232 TRACE("\n");
5234 if (LOWORD(wParam) > 1) {
5235 FIXME("multiple rows not supported!\n");
5238 if(infoPtr->nRows != LOWORD(wParam))
5240 infoPtr->nRows = LOWORD(wParam);
5242 /* recalculate toolbar */
5243 TOOLBAR_CalcToolbar (hwnd);
5245 /* repaint toolbar */
5246 InvalidateRect(hwnd, NULL, TRUE);
5249 /* return bounding rectangle */
5250 if (lprc) {
5251 lprc->left = infoPtr->rcBound.left;
5252 lprc->right = infoPtr->rcBound.right;
5253 lprc->top = infoPtr->rcBound.top;
5254 lprc->bottom = infoPtr->rcBound.bottom;
5257 return 0;
5261 static LRESULT
5262 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5264 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5265 TBUTTON_INFO *btnPtr;
5266 INT nIndex;
5268 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5269 if (nIndex == -1)
5270 return FALSE;
5272 btnPtr = &infoPtr->buttons[nIndex];
5274 /* if hidden state has changed the invalidate entire window and recalc */
5275 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5276 btnPtr->fsState = LOWORD(lParam);
5277 TOOLBAR_CalcToolbar (hwnd);
5278 InvalidateRect(hwnd, 0, TRUE);
5279 return TRUE;
5282 /* process state changing if current state doesn't match new state */
5283 if(btnPtr->fsState != LOWORD(lParam))
5285 btnPtr->fsState = LOWORD(lParam);
5286 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5289 return TRUE;
5293 static LRESULT
5294 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5296 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5298 return TRUE;
5302 inline static LRESULT
5303 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5305 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5307 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5309 infoPtr->hwndToolTip = (HWND)wParam;
5310 return 0;
5314 static LRESULT
5315 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5317 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5318 BOOL bTemp;
5320 TRACE("%s hwnd=%p\n",
5321 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5323 bTemp = infoPtr->bUnicode;
5324 infoPtr->bUnicode = (BOOL)wParam;
5326 return bTemp;
5330 static LRESULT
5331 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5333 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5335 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5336 comctl32_color.clrBtnHighlight :
5337 infoPtr->clrBtnHighlight;
5338 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5339 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5340 return 1;
5344 static LRESULT
5345 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5347 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5349 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5350 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5351 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5353 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5354 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5355 InvalidateRect(hwnd, NULL, TRUE);
5356 return 0;
5360 static LRESULT
5361 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5363 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5364 INT iOldVersion = infoPtr->iVersion;
5366 infoPtr->iVersion = iVersion;
5368 if (infoPtr->iVersion >= 5)
5369 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5371 return iOldVersion;
5375 static LRESULT
5376 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5378 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5379 WORD iString = HIWORD(wParam);
5380 WORD buffersize = LOWORD(wParam);
5381 LPSTR str = (LPSTR)lParam;
5382 LRESULT ret = -1;
5384 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5386 if (iString < infoPtr->nNumStrings)
5388 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5390 TRACE("returning %s\n", debugstr_a(str));
5392 else
5393 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5395 return ret;
5399 static LRESULT
5400 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5402 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5403 WORD iString = HIWORD(wParam);
5404 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5405 LPWSTR str = (LPWSTR)lParam;
5406 LRESULT ret = -1;
5408 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5410 if (iString < infoPtr->nNumStrings)
5412 len = min(len, strlenW(infoPtr->strings[iString]));
5413 ret = (len+1)*sizeof(WCHAR);
5414 memcpy(str, infoPtr->strings[iString], ret);
5415 str[len] = '\0';
5417 TRACE("returning %s\n", debugstr_w(str));
5419 else
5420 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5422 return ret;
5425 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5426 * is the maximum size of the toolbar? */
5427 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5429 SIZE * pSize = (SIZE*)lParam;
5430 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5431 return 0;
5435 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5436 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5437 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5438 * sends). */
5439 static LRESULT
5440 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5442 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5443 INT nOldHotItem = infoPtr->nHotItem;
5445 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5446 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5448 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5449 wParam = -1;
5451 /* NOTE: an application can still remove the hot item even if anchor
5452 * highlighting is enabled */
5454 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5456 GetFocus();
5458 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5461 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5462 * which controls the amount of spacing between the image and the text
5463 * of buttons for TBSTYLE_LIST toolbars. */
5464 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5466 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5468 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5470 if (lParam != 0)
5471 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5473 infoPtr->iListGap = (INT)wParam;
5475 InvalidateRect(hwnd, NULL, TRUE);
5477 return 0;
5480 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5481 * of image lists associated with the various states. */
5482 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5484 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5486 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5488 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5491 static LRESULT
5492 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5494 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5495 LPSIZE lpsize = (LPSIZE)lParam;
5497 if (lpsize == NULL)
5498 return FALSE;
5501 * Testing shows the following:
5502 * wParam = 0 adjust cx value
5503 * = 1 set cy value to max size.
5504 * lParam pointer to SIZE structure
5507 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5508 wParam, lParam, lpsize->cx, lpsize->cy);
5510 switch(wParam) {
5511 case 0:
5512 if (lpsize->cx == -1) {
5513 /* **** this is wrong, native measures each button and sets it */
5514 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5516 else if(HIWORD(lpsize->cx)) {
5517 RECT rc;
5518 HWND hwndParent = GetParent(hwnd);
5520 GetWindowRect(hwnd, &rc);
5521 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5522 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5523 rc.left, rc.top, rc.right, rc.bottom);
5524 lpsize->cx = max(rc.right-rc.left,
5525 infoPtr->rcBound.right - infoPtr->rcBound.left);
5527 else {
5528 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5530 break;
5531 case 1:
5532 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5533 /* lpsize->cy = infoPtr->nHeight; */
5534 break;
5535 default:
5536 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5537 wParam);
5538 return 0;
5540 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5541 lpsize->cx, lpsize->cy);
5542 return 1;
5545 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5547 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5549 InvalidateRect(hwnd, NULL, TRUE);
5550 return 1;
5554 static LRESULT
5555 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5557 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5558 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5559 LOGFONTW logFont;
5561 TRACE("hwnd = %p\n", hwnd);
5563 /* initialize info structure */
5564 infoPtr->nButtonHeight = 22;
5565 infoPtr->nButtonWidth = 24;
5566 infoPtr->nBitmapHeight = 15;
5567 infoPtr->nBitmapWidth = 16;
5569 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
5570 infoPtr->nMaxTextRows = 1;
5571 infoPtr->cxMin = -1;
5572 infoPtr->cxMax = -1;
5573 infoPtr->nNumBitmaps = 0;
5574 infoPtr->nNumStrings = 0;
5576 infoPtr->bCaptured = FALSE;
5577 infoPtr->nButtonDown = -1;
5578 infoPtr->nButtonDrag = -1;
5579 infoPtr->nOldHit = -1;
5580 infoPtr->nHotItem = -1;
5581 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5582 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5583 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5584 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5585 infoPtr->bDragOutSent = FALSE;
5586 infoPtr->iVersion = 0;
5587 infoPtr->hwndSelf = hwnd;
5588 infoPtr->bDoRedraw = TRUE;
5589 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5590 infoPtr->clrBtnShadow = CLR_DEFAULT;
5591 infoPtr->szPadding.cx = DEFPAD_CX;
5592 infoPtr->szPadding.cy = DEFPAD_CY;
5593 infoPtr->iListGap = DEFLISTGAP;
5594 infoPtr->dwStyle = dwStyle;
5595 infoPtr->tbim.iButton = -1;
5596 GetClientRect(hwnd, &infoPtr->client_rect);
5597 infoPtr->bUnicode = infoPtr->hwndNotify &&
5598 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5600 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5601 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5603 if (dwStyle & TBSTYLE_TOOLTIPS) {
5604 /* Create tooltip control */
5605 infoPtr->hwndToolTip =
5606 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
5607 CW_USEDEFAULT, CW_USEDEFAULT,
5608 CW_USEDEFAULT, CW_USEDEFAULT,
5609 hwnd, 0, 0, 0);
5611 /* Send NM_TOOLTIPSCREATED notification */
5612 if (infoPtr->hwndToolTip)
5614 NMTOOLTIPSCREATED nmttc;
5616 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5618 TOOLBAR_SendNotify (&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
5622 TOOLBAR_CheckStyle (hwnd, dwStyle);
5624 TOOLBAR_CalcToolbar(hwnd);
5626 return 0;
5630 static LRESULT
5631 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5633 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5635 /* delete tooltip control */
5636 if (infoPtr->hwndToolTip)
5637 DestroyWindow (infoPtr->hwndToolTip);
5639 /* delete temporary buffer for tooltip text */
5640 Free (infoPtr->pszTooltipText);
5642 /* delete button data */
5643 if (infoPtr->buttons)
5644 Free (infoPtr->buttons);
5646 /* delete strings */
5647 if (infoPtr->strings) {
5648 INT i;
5649 for (i = 0; i < infoPtr->nNumStrings; i++)
5650 if (infoPtr->strings[i])
5651 Free (infoPtr->strings[i]);
5653 Free (infoPtr->strings);
5656 /* destroy internal image list */
5657 if (infoPtr->himlInt)
5658 ImageList_Destroy (infoPtr->himlInt);
5660 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5661 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5662 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5664 /* delete default font */
5665 if (infoPtr->hFont)
5666 DeleteObject (infoPtr->hDefaultFont);
5668 /* free toolbar info data */
5669 Free (infoPtr);
5670 SetWindowLongPtrW (hwnd, 0, 0);
5672 return 0;
5676 static LRESULT
5677 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5679 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5680 NMTBCUSTOMDRAW tbcd;
5681 INT ret = FALSE;
5682 DWORD ntfret;
5684 /* the app has told us not to redraw the toolbar */
5685 if (!infoPtr->bDoRedraw)
5686 return FALSE;
5688 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5689 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5690 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5691 tbcd.nmcd.hdc = (HDC)wParam;
5692 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5693 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5695 /* FIXME: in general the return flags *can* be or'ed together */
5696 switch (infoPtr->dwBaseCustDraw)
5698 case CDRF_DODEFAULT:
5699 break;
5700 case CDRF_SKIPDEFAULT:
5701 return TRUE;
5702 default:
5703 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5704 hwnd, ntfret);
5708 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5709 * to my parent for processing.
5711 if (infoPtr->dwStyle & TBSTYLE_TRANSPARENT) {
5712 POINT pt, ptorig;
5713 HDC hdc = (HDC)wParam;
5714 HWND parent;
5716 pt.x = 0;
5717 pt.y = 0;
5718 parent = GetParent(hwnd);
5719 MapWindowPoints(hwnd, parent, &pt, 1);
5720 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5721 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5722 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5724 if (!ret)
5725 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5727 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5728 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5729 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5730 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5731 tbcd.nmcd.hdc = (HDC)wParam;
5732 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5733 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5734 switch (infoPtr->dwBaseCustDraw)
5736 case CDRF_DODEFAULT:
5737 break;
5738 case CDRF_SKIPDEFAULT:
5739 return TRUE;
5740 default:
5741 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5742 hwnd, ntfret);
5745 return ret;
5749 static LRESULT
5750 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5752 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5754 return (LRESULT)infoPtr->hFont;
5758 static LRESULT
5759 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5761 POINT pt;
5762 INT nHit;
5764 pt.x = (INT)LOWORD(lParam);
5765 pt.y = (INT)HIWORD(lParam);
5766 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5768 if (nHit >= 0)
5769 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5770 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5771 TOOLBAR_Customize (hwnd);
5773 return 0;
5777 static LRESULT
5778 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5780 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5781 TBUTTON_INFO *btnPtr;
5782 POINT pt;
5783 INT nHit;
5784 NMTOOLBARA nmtb;
5785 NMMOUSE nmmouse;
5786 BOOL bDragKeyPressed;
5788 TRACE("\n");
5790 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5791 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5792 else
5793 bDragKeyPressed = (wParam & MK_SHIFT);
5795 if (infoPtr->hwndToolTip)
5796 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5797 WM_LBUTTONDOWN, wParam, lParam);
5799 pt.x = (INT)LOWORD(lParam);
5800 pt.y = (INT)HIWORD(lParam);
5801 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5803 btnPtr = &infoPtr->buttons[nHit];
5805 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5807 infoPtr->nButtonDrag = nHit;
5808 SetCapture (hwnd);
5810 /* If drag cursor has not been loaded, load it.
5811 * Note: it doesn't need to be freed */
5812 if (!hCursorDrag)
5813 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5814 SetCursor(hCursorDrag);
5816 else if (nHit >= 0)
5818 RECT arrowRect;
5819 infoPtr->nOldHit = nHit;
5821 CopyRect(&arrowRect, &btnPtr->rect);
5822 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5824 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5825 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5826 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5827 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5828 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5829 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5831 LRESULT res;
5833 /* draw in pressed state */
5834 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5835 btnPtr->fsState |= TBSTATE_PRESSED;
5836 else
5837 btnPtr->bDropDownPressed = TRUE;
5838 RedrawWindow(hwnd,&btnPtr->rect,0,
5839 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5841 memset(&nmtb, 0, sizeof(nmtb));
5842 nmtb.iItem = btnPtr->idCommand;
5843 nmtb.rcButton = btnPtr->rect;
5844 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5845 TBN_DROPDOWN);
5846 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5848 if (res != TBDDRET_TREATPRESSED)
5850 MSG msg;
5852 /* redraw button in unpressed state */
5853 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5854 btnPtr->fsState &= ~TBSTATE_PRESSED;
5855 else
5856 btnPtr->bDropDownPressed = FALSE;
5857 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5859 /* find and set hot item
5860 * NOTE: native doesn't do this, but that is a bug */
5861 GetCursorPos(&pt);
5862 ScreenToClient(hwnd, &pt);
5863 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5864 if (!infoPtr->bAnchor || (nHit >= 0))
5865 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5867 /* remove any left mouse button down or double-click messages
5868 * so that we can get a toggle effect on the button */
5869 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5870 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5873 return 0;
5875 /* otherwise drop through and process as pushed */
5877 infoPtr->bCaptured = TRUE;
5878 infoPtr->nButtonDown = nHit;
5879 infoPtr->bDragOutSent = FALSE;
5881 btnPtr->fsState |= TBSTATE_PRESSED;
5883 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5885 if (btnPtr->fsState & TBSTATE_ENABLED)
5886 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5887 UpdateWindow(hwnd);
5888 SetCapture (hwnd);
5891 if (nHit >=0)
5893 memset(&nmtb, 0, sizeof(nmtb));
5894 nmtb.iItem = btnPtr->idCommand;
5895 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5898 nmmouse.dwHitInfo = nHit;
5900 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5901 if (nHit < 0)
5902 nmmouse.dwItemSpec = -1;
5903 else
5905 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5906 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5909 ClientToScreen(hwnd, &pt);
5910 nmmouse.pt = pt;
5912 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5913 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5915 return 0;
5918 static LRESULT
5919 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5921 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5922 TBUTTON_INFO *btnPtr;
5923 POINT pt;
5924 INT nHit;
5925 INT nOldIndex = -1;
5926 BOOL bSendMessage = TRUE;
5927 NMHDR hdr;
5928 NMMOUSE nmmouse;
5929 NMTOOLBARA nmtb;
5931 if (infoPtr->hwndToolTip)
5932 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5933 WM_LBUTTONUP, wParam, lParam);
5935 pt.x = (INT)LOWORD(lParam);
5936 pt.y = (INT)HIWORD(lParam);
5937 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5939 if (!infoPtr->bAnchor || (nHit >= 0))
5940 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5942 if (infoPtr->nButtonDrag >= 0) {
5943 RECT rcClient;
5944 NMHDR hdr;
5946 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5947 ReleaseCapture();
5948 /* reset cursor */
5949 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5951 GetClientRect(hwnd, &rcClient);
5952 if (PtInRect(&rcClient, pt))
5954 INT nButton = -1;
5955 if (nHit >= 0)
5956 nButton = nHit;
5957 else if (nHit < -1)
5958 nButton = -nHit;
5959 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5960 nButton = -nHit;
5962 if (nButton == infoPtr->nButtonDrag)
5964 /* if the button is moved sightly left and we have a
5965 * separator there then remove it */
5966 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5968 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5969 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5971 else /* else insert a separator before the dragged button */
5973 TBBUTTON tbb;
5974 memset(&tbb, 0, sizeof(tbb));
5975 tbb.fsStyle = BTNS_SEP;
5976 tbb.iString = -1;
5977 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5980 else
5982 if (nButton == -1)
5984 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5985 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5986 else
5987 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5989 else
5990 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5993 else
5995 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5996 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5999 /* button under cursor changed so need to re-set hot item */
6000 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
6001 infoPtr->nButtonDrag = -1;
6003 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
6005 else if (infoPtr->nButtonDown >= 0) {
6006 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6007 btnPtr->fsState &= ~TBSTATE_PRESSED;
6009 if (btnPtr->fsStyle & BTNS_CHECK) {
6010 if (btnPtr->fsStyle & BTNS_GROUP) {
6011 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
6012 nHit);
6013 if (nOldIndex == nHit)
6014 bSendMessage = FALSE;
6015 if ((nOldIndex != nHit) &&
6016 (nOldIndex != -1))
6017 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
6018 btnPtr->fsState |= TBSTATE_CHECKED;
6020 else {
6021 if (btnPtr->fsState & TBSTATE_CHECKED)
6022 btnPtr->fsState &= ~TBSTATE_CHECKED;
6023 else
6024 btnPtr->fsState |= TBSTATE_CHECKED;
6028 if (nOldIndex != -1)
6029 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
6032 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
6033 * that resets bCaptured and btn TBSTATE_PRESSED flags,
6034 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
6036 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
6037 ReleaseCapture ();
6038 infoPtr->nButtonDown = -1;
6040 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
6041 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
6042 NM_RELEASEDCAPTURE);
6044 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
6045 * TBN_BEGINDRAG
6047 memset(&nmtb, 0, sizeof(nmtb));
6048 nmtb.iItem = btnPtr->idCommand;
6049 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
6050 TBN_ENDDRAG);
6052 if (btnPtr->fsState & TBSTATE_ENABLED)
6054 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
6055 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
6059 /* !!! Undocumented - toolbar at 4.71 level and above sends
6060 * NM_CLICK with the NMMOUSE structure. */
6061 nmmouse.dwHitInfo = nHit;
6063 if (nmmouse.dwHitInfo < 0)
6064 nmmouse.dwItemSpec = -1;
6065 else
6067 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6068 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6071 ClientToScreen(hwnd, &pt);
6072 nmmouse.pt = pt;
6074 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
6075 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
6077 return 0;
6080 static LRESULT
6081 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
6083 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6084 INT nHit;
6085 NMMOUSE nmmouse;
6086 POINT pt;
6088 pt.x = LOWORD(lParam);
6089 pt.y = HIWORD(lParam);
6091 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
6092 nmmouse.dwHitInfo = nHit;
6094 if (nHit < 0) {
6095 nmmouse.dwItemSpec = -1;
6096 } else {
6097 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6098 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6101 ClientToScreen(hwnd, &pt);
6102 nmmouse.pt = pt;
6104 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
6105 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
6107 return 0;
6110 static LRESULT
6111 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
6113 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6114 NMHDR nmhdr;
6116 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
6117 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
6119 return 0;
6122 static LRESULT
6123 TOOLBAR_CaptureChanged(HWND hwnd)
6125 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6126 TBUTTON_INFO *btnPtr;
6128 infoPtr->bCaptured = FALSE;
6130 if (infoPtr->nButtonDown >= 0)
6132 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6133 btnPtr->fsState &= ~TBSTATE_PRESSED;
6135 infoPtr->nOldHit = -1;
6137 if (btnPtr->fsState & TBSTATE_ENABLED)
6138 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6140 return 0;
6143 static LRESULT
6144 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6146 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6147 TBUTTON_INFO *hotBtnPtr;
6149 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
6151 /* don't remove hot effects when in anchor highlighting mode or when a
6152 * drop-down button is pressed */
6153 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
6154 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6156 if (infoPtr->nOldHit < 0)
6157 return TRUE;
6159 /* If the last button we were over is depressed then make it not */
6160 /* depressed and redraw it */
6161 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6163 TBUTTON_INFO *btnPtr;
6164 RECT rc1;
6166 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6168 btnPtr->fsState &= ~TBSTATE_PRESSED;
6170 rc1 = hotBtnPtr->rect;
6171 InflateRect (&rc1, 1, 1);
6172 InvalidateRect (hwnd, &rc1, TRUE);
6175 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6177 NMTOOLBARW nmt;
6178 ZeroMemory(&nmt, sizeof(nmt));
6179 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6180 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6181 infoPtr->bDragOutSent = TRUE;
6184 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6186 return TRUE;
6189 static LRESULT
6190 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6192 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6193 POINT pt;
6194 TRACKMOUSEEVENT trackinfo;
6195 INT nHit;
6196 TBUTTON_INFO *btnPtr;
6198 if (infoPtr->dwStyle & TBSTYLE_FLAT) {
6199 /* fill in the TRACKMOUSEEVENT struct */
6200 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6201 trackinfo.dwFlags = TME_QUERY;
6202 trackinfo.hwndTrack = hwnd;
6203 trackinfo.dwHoverTime = HOVER_DEFAULT;
6205 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6206 _TrackMouseEvent(&trackinfo);
6208 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6209 if(!(trackinfo.dwFlags & TME_LEAVE)) {
6210 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6212 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6213 /* and can properly deactivate the hot toolbar button */
6214 _TrackMouseEvent(&trackinfo);
6218 if (infoPtr->hwndToolTip)
6219 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6220 WM_MOUSEMOVE, wParam, lParam);
6222 pt.x = (INT)LOWORD(lParam);
6223 pt.y = (INT)HIWORD(lParam);
6225 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6227 if ((infoPtr->dwStyle & TBSTYLE_FLAT) && (!infoPtr->bAnchor || (nHit >= 0)))
6228 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6230 if (infoPtr->nOldHit != nHit)
6232 if (infoPtr->bCaptured)
6234 if (!infoPtr->bDragOutSent)
6236 NMTOOLBARW nmt;
6237 ZeroMemory(&nmt, sizeof(nmt));
6238 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6239 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6240 infoPtr->bDragOutSent = TRUE;
6243 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6244 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6245 btnPtr->fsState &= ~TBSTATE_PRESSED;
6246 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6248 else if (nHit == infoPtr->nButtonDown) {
6249 btnPtr->fsState |= TBSTATE_PRESSED;
6250 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6252 infoPtr->nOldHit = nHit;
6256 return 0;
6260 inline static LRESULT
6261 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6263 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6264 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6265 /* else */
6266 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6270 inline static LRESULT
6271 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6273 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6274 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6276 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6280 static LRESULT
6281 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6283 TOOLBAR_INFO *infoPtr;
6284 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6285 DWORD styleadd = 0;
6287 /* allocate memory for info structure */
6288 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6289 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6291 /* paranoid!! */
6292 infoPtr->dwStructSize = sizeof(TBBUTTON);
6293 infoPtr->nRows = 1;
6295 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6296 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6297 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6298 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6301 /* native control does:
6302 * Get a lot of colors and brushes
6303 * WM_NOTIFYFORMAT
6304 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6305 * CreateFontIndirectW(adr1)
6306 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6307 * hdc = GetDC(toolbar)
6308 * GetSystemMetrics(0x48)
6309 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6310 * 0, 0, 0, 0, "MARLETT")
6311 * oldfnt = SelectObject(hdc, fnt2)
6312 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6313 * GetTextMetricsW(hdc, adr3)
6314 * SelectObject(hdc, oldfnt)
6315 * DeleteObject(fnt2)
6316 * ReleaseDC(hdc)
6317 * InvalidateRect(toolbar, 0, 1)
6318 * SetWindowLongW(toolbar, 0, addr)
6319 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6320 * WM_STYLECHANGING
6321 * CallWinEx old new
6322 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6323 * ie 2 0x4600094c 0x4600094c 0x4600894d
6324 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6325 * rebar 0x50008844 0x40008844 0x50008845
6326 * pager 0x50000844 0x40000844 0x50008845
6327 * IC35mgr 0x5400084e **nochange**
6328 * on entry to _NCCREATE 0x5400084e
6329 * rowlist 0x5400004e **nochange**
6330 * on entry to _NCCREATE 0x5400004e
6334 /* I think the code below is a bug, but it is the way that the native
6335 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6336 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6337 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6338 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6339 * Somehow, the only cases of this seem to be MFC programs.
6341 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6342 * does not occur in the WM_STYLECHANGING routine.
6343 * (Guy Albertelli 9/2001)
6346 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
6347 styleadd |= TBSTYLE_TRANSPARENT;
6348 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6349 styleadd |= CCS_TOP; /* default to top */
6350 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6353 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6357 static LRESULT
6358 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6360 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6361 RECT rcWindow;
6362 HDC hdc;
6364 if (dwStyle & WS_MINIMIZE)
6365 return 0; /* Nothing to do */
6367 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6369 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6370 return 0;
6372 if (!(dwStyle & CCS_NODIVIDER))
6374 GetWindowRect (hwnd, &rcWindow);
6375 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6376 if( dwStyle & WS_BORDER )
6377 OffsetRect (&rcWindow, 1, 1);
6378 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6381 ReleaseDC( hwnd, hdc );
6383 return 0;
6387 /* handles requests from the tooltip control on what text to display */
6388 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6390 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6392 TRACE("button index = %d\n", index);
6394 Free (infoPtr->pszTooltipText);
6395 infoPtr->pszTooltipText = NULL;
6397 if (index < 0)
6398 return 0;
6400 if (infoPtr->bUnicode)
6402 WCHAR wszBuffer[INFOTIPSIZE+1];
6403 NMTBGETINFOTIPW tbgit;
6404 unsigned int len; /* in chars */
6406 wszBuffer[0] = '\0';
6407 wszBuffer[INFOTIPSIZE] = '\0';
6409 tbgit.pszText = wszBuffer;
6410 tbgit.cchTextMax = INFOTIPSIZE;
6411 tbgit.iItem = lpnmtdi->hdr.idFrom;
6412 tbgit.lParam = infoPtr->buttons[index].dwData;
6414 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6416 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6418 len = strlenW(tbgit.pszText);
6419 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6421 /* need to allocate temporary buffer in infoPtr as there
6422 * isn't enough space in buffer passed to us by the
6423 * tooltip control */
6424 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6425 if (infoPtr->pszTooltipText)
6427 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6428 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6429 return 0;
6432 else if (len > 0)
6434 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6435 return 0;
6438 else
6440 CHAR szBuffer[INFOTIPSIZE+1];
6441 NMTBGETINFOTIPA tbgit;
6442 unsigned int len; /* in chars */
6444 szBuffer[0] = '\0';
6445 szBuffer[INFOTIPSIZE] = '\0';
6447 tbgit.pszText = szBuffer;
6448 tbgit.cchTextMax = INFOTIPSIZE;
6449 tbgit.iItem = lpnmtdi->hdr.idFrom;
6450 tbgit.lParam = infoPtr->buttons[index].dwData;
6452 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6454 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6456 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6457 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6459 /* need to allocate temporary buffer in infoPtr as there
6460 * isn't enough space in buffer passed to us by the
6461 * tooltip control */
6462 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6463 if (infoPtr->pszTooltipText)
6465 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
6466 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6467 return 0;
6470 else if (len > 0)
6472 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
6473 return 0;
6477 /* if button has text, but it is not shown then automatically
6478 * use that text as tooltip */
6479 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6480 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6482 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6483 unsigned int len = pszText ? strlenW(pszText) : 0;
6485 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6487 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6489 /* need to allocate temporary buffer in infoPtr as there
6490 * isn't enough space in buffer passed to us by the
6491 * tooltip control */
6492 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6493 if (infoPtr->pszTooltipText)
6495 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6496 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6497 return 0;
6500 else if (len > 0)
6502 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6503 return 0;
6507 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6509 /* last resort: send notification on to app */
6510 /* FIXME: find out what is really used here */
6511 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6515 inline static LRESULT
6516 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6518 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6519 LPNMHDR lpnmh = (LPNMHDR)lParam;
6521 switch (lpnmh->code)
6523 case PGN_CALCSIZE:
6525 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6527 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6528 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6529 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6530 lppgc->iWidth);
6532 else {
6533 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6534 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6535 lppgc->iHeight);
6537 return 0;
6540 case PGN_SCROLL:
6542 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6544 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6545 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6546 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6547 lppgs->iScroll, lppgs->iDir);
6548 return 0;
6551 case TTN_GETDISPINFOW:
6552 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6554 case TTN_GETDISPINFOA:
6555 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6556 return 0;
6558 default:
6559 return 0;
6564 static LRESULT
6565 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6567 LRESULT format;
6569 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6571 if (lParam == NF_QUERY)
6572 return NFR_UNICODE;
6574 if (lParam == NF_REQUERY) {
6575 format = SendMessageW(infoPtr->hwndNotify,
6576 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6577 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6578 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6579 format);
6580 format = NFR_ANSI;
6582 return format;
6584 return 0;
6588 static LRESULT
6589 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6591 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6592 HDC hdc;
6593 PAINTSTRUCT ps;
6595 /* fill ps.rcPaint with a default rect */
6596 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6598 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6600 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6601 ps.rcPaint.left, ps.rcPaint.top,
6602 ps.rcPaint.right, ps.rcPaint.bottom);
6604 TOOLBAR_Refresh (hwnd, hdc, &ps);
6605 if (!wParam) EndPaint (hwnd, &ps);
6607 return 0;
6611 static LRESULT
6612 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6613 /*****************************************************
6615 * Function;
6616 * Handles the WM_SETREDRAW message.
6618 * Documentation:
6619 * According to testing V4.71 of COMCTL32 returns the
6620 * *previous* status of the redraw flag (either 0 or 1)
6621 * instead of the MSDN documented value of 0 if handled.
6622 * (For laughs see the "consistency" with same function
6623 * in rebar.)
6625 *****************************************************/
6627 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6628 BOOL oldredraw = infoPtr->bDoRedraw;
6630 TRACE("set to %s\n",
6631 (wParam) ? "TRUE" : "FALSE");
6632 infoPtr->bDoRedraw = (BOOL) wParam;
6633 if (wParam) {
6634 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6636 return (oldredraw) ? 1 : 0;
6640 static LRESULT
6641 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6643 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6644 DWORD dwStyle = infoPtr->dwStyle;
6645 RECT parent_rect;
6646 RECT window_rect;
6647 HWND parent;
6648 INT x, y;
6649 INT cx, cy;
6650 INT flags;
6651 UINT uPosFlags = 0;
6653 /* Resize deadlock check */
6654 if (infoPtr->bAutoSize) {
6655 infoPtr->bAutoSize = FALSE;
6656 return 0;
6659 /* FIXME: optimize to only update size if the new size doesn't */
6660 /* match the current size */
6662 flags = (INT) wParam;
6664 /* FIXME for flags =
6665 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
6668 TRACE("sizing toolbar!\n");
6670 if (flags == SIZE_RESTORED) {
6671 /* width and height don't apply */
6672 parent = GetParent (hwnd);
6673 GetClientRect(parent, &parent_rect);
6674 x = parent_rect.left;
6675 y = parent_rect.top;
6677 if (dwStyle & CCS_NORESIZE) {
6678 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
6681 * this sets the working width of the toolbar, and
6682 * Calc Toolbar will not adjust it, only the height
6684 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6685 cy = infoPtr->nHeight;
6686 cx = infoPtr->nWidth;
6687 TOOLBAR_CalcToolbar (hwnd);
6688 infoPtr->nWidth = cx;
6689 infoPtr->nHeight = cy;
6691 else {
6692 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6693 TOOLBAR_CalcToolbar (hwnd);
6694 cy = infoPtr->nHeight;
6695 cx = infoPtr->nWidth;
6697 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
6698 GetWindowRect(hwnd, &window_rect);
6699 ScreenToClient(parent, (LPPOINT)&window_rect.left);
6700 y = window_rect.top;
6702 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
6703 GetWindowRect(hwnd, &window_rect);
6704 y = parent_rect.bottom -
6705 ( window_rect.bottom - window_rect.top);
6709 if (dwStyle & CCS_NOPARENTALIGN) {
6710 uPosFlags |= SWP_NOMOVE;
6711 cy = infoPtr->nHeight;
6712 cx = infoPtr->nWidth;
6715 if (!(dwStyle & CCS_NODIVIDER))
6716 cy += GetSystemMetrics(SM_CYEDGE);
6718 if (dwStyle & WS_BORDER)
6720 x = y = 1;
6721 cy += GetSystemMetrics(SM_CYEDGE);
6722 cx += GetSystemMetrics(SM_CXEDGE);
6725 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6727 RECT delta_width, delta_height, client, dummy;
6728 DWORD min_x, max_x, min_y, max_y;
6729 TBUTTON_INFO *btnPtr;
6730 INT i;
6732 GetClientRect(hwnd, &client);
6733 if(client.right > infoPtr->client_rect.right)
6735 min_x = infoPtr->client_rect.right;
6736 max_x = client.right;
6738 else
6740 max_x = infoPtr->client_rect.right;
6741 min_x = client.right;
6743 if(client.bottom > infoPtr->client_rect.bottom)
6745 min_y = infoPtr->client_rect.bottom;
6746 max_y = client.bottom;
6748 else
6750 max_y = infoPtr->client_rect.bottom;
6751 min_y = client.bottom;
6754 SetRect(&delta_width, min_x, 0, max_x, min_y);
6755 SetRect(&delta_height, 0, min_y, max_x, max_y);
6757 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6758 btnPtr = infoPtr->buttons;
6759 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6760 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6761 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6762 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6765 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
6766 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6768 GetClientRect(hwnd, &infoPtr->client_rect);
6769 return 0;
6773 static LRESULT
6774 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6776 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6778 if (nType == GWL_STYLE)
6780 if (lpStyle->styleNew & TBSTYLE_LIST)
6781 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6782 else
6783 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6785 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6786 (TBSTYLE_FLAT | TBSTYLE_LIST));
6787 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6789 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6791 infoPtr->dwStyle = lpStyle->styleNew;
6793 /* only resize if one of the CCS_* styles was changed */
6794 if ((infoPtr->dwStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6796 TOOLBAR_AutoSize (hwnd);
6798 InvalidateRect(hwnd, NULL, TRUE);
6802 return 0;
6806 static LRESULT
6807 TOOLBAR_SysColorChange (HWND hwnd)
6809 COMCTL32_RefreshSysColors();
6811 return 0;
6816 static LRESULT WINAPI
6817 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6819 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6821 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6822 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6824 if (!infoPtr && (uMsg != WM_NCCREATE))
6825 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6827 switch (uMsg)
6829 case TB_ADDBITMAP:
6830 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6832 case TB_ADDBUTTONSA:
6833 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6835 case TB_ADDBUTTONSW:
6836 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6838 case TB_ADDSTRINGA:
6839 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6841 case TB_ADDSTRINGW:
6842 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6844 case TB_AUTOSIZE:
6845 return TOOLBAR_AutoSize (hwnd);
6847 case TB_BUTTONCOUNT:
6848 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6850 case TB_BUTTONSTRUCTSIZE:
6851 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6853 case TB_CHANGEBITMAP:
6854 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6856 case TB_CHECKBUTTON:
6857 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6859 case TB_COMMANDTOINDEX:
6860 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6862 case TB_CUSTOMIZE:
6863 return TOOLBAR_Customize (hwnd);
6865 case TB_DELETEBUTTON:
6866 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6868 case TB_ENABLEBUTTON:
6869 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6871 case TB_GETANCHORHIGHLIGHT:
6872 return TOOLBAR_GetAnchorHighlight (hwnd);
6874 case TB_GETBITMAP:
6875 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6877 case TB_GETBITMAPFLAGS:
6878 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6880 case TB_GETBUTTON:
6881 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6883 case TB_GETBUTTONINFOA:
6884 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6886 case TB_GETBUTTONINFOW:
6887 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6889 case TB_GETBUTTONSIZE:
6890 return TOOLBAR_GetButtonSize (hwnd);
6892 case TB_GETBUTTONTEXTA:
6893 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6895 case TB_GETBUTTONTEXTW:
6896 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6898 case TB_GETDISABLEDIMAGELIST:
6899 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6901 case TB_GETEXTENDEDSTYLE:
6902 return TOOLBAR_GetExtendedStyle (hwnd);
6904 case TB_GETHOTIMAGELIST:
6905 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6907 case TB_GETHOTITEM:
6908 return TOOLBAR_GetHotItem (hwnd);
6910 case TB_GETIMAGELIST:
6911 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6913 case TB_GETINSERTMARK:
6914 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6916 case TB_GETINSERTMARKCOLOR:
6917 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6919 case TB_GETITEMRECT:
6920 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6922 case TB_GETMAXSIZE:
6923 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6925 /* case TB_GETOBJECT: */ /* 4.71 */
6927 case TB_GETPADDING:
6928 return TOOLBAR_GetPadding (hwnd);
6930 case TB_GETRECT:
6931 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6933 case TB_GETROWS:
6934 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6936 case TB_GETSTATE:
6937 return TOOLBAR_GetState (hwnd, wParam, lParam);
6939 case TB_GETSTRINGA:
6940 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6942 case TB_GETSTRINGW:
6943 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6945 case TB_GETSTYLE:
6946 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6948 case TB_GETTEXTROWS:
6949 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6951 case TB_GETTOOLTIPS:
6952 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6954 case TB_GETUNICODEFORMAT:
6955 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6957 case TB_HIDEBUTTON:
6958 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6960 case TB_HITTEST:
6961 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6963 case TB_INDETERMINATE:
6964 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6966 case TB_INSERTBUTTONA:
6967 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6969 case TB_INSERTBUTTONW:
6970 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6972 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6974 case TB_ISBUTTONCHECKED:
6975 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6977 case TB_ISBUTTONENABLED:
6978 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6980 case TB_ISBUTTONHIDDEN:
6981 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6983 case TB_ISBUTTONHIGHLIGHTED:
6984 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6986 case TB_ISBUTTONINDETERMINATE:
6987 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6989 case TB_ISBUTTONPRESSED:
6990 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6992 case TB_LOADIMAGES:
6993 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6995 case TB_MAPACCELERATORA:
6996 case TB_MAPACCELERATORW:
6997 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6999 case TB_MARKBUTTON:
7000 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
7002 case TB_MOVEBUTTON:
7003 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
7005 case TB_PRESSBUTTON:
7006 return TOOLBAR_PressButton (hwnd, wParam, lParam);
7008 case TB_REPLACEBITMAP:
7009 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
7011 case TB_SAVERESTOREA:
7012 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
7014 case TB_SAVERESTOREW:
7015 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
7017 case TB_SETANCHORHIGHLIGHT:
7018 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
7020 case TB_SETBITMAPSIZE:
7021 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
7023 case TB_SETBUTTONINFOA:
7024 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
7026 case TB_SETBUTTONINFOW:
7027 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
7029 case TB_SETBUTTONSIZE:
7030 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
7032 case TB_SETBUTTONWIDTH:
7033 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
7035 case TB_SETCMDID:
7036 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
7038 case TB_SETDISABLEDIMAGELIST:
7039 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
7041 case TB_SETDRAWTEXTFLAGS:
7042 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
7044 case TB_SETEXTENDEDSTYLE:
7045 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
7047 case TB_SETHOTIMAGELIST:
7048 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
7050 case TB_SETHOTITEM:
7051 return TOOLBAR_SetHotItem (hwnd, wParam);
7053 case TB_SETIMAGELIST:
7054 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
7056 case TB_SETINDENT:
7057 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
7059 case TB_SETINSERTMARK:
7060 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
7062 case TB_SETINSERTMARKCOLOR:
7063 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
7065 case TB_SETMAXTEXTROWS:
7066 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
7068 case TB_SETPADDING:
7069 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
7071 case TB_SETPARENT:
7072 return TOOLBAR_SetParent (hwnd, wParam, lParam);
7074 case TB_SETROWS:
7075 return TOOLBAR_SetRows (hwnd, wParam, lParam);
7077 case TB_SETSTATE:
7078 return TOOLBAR_SetState (hwnd, wParam, lParam);
7080 case TB_SETSTYLE:
7081 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
7083 case TB_SETTOOLTIPS:
7084 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
7086 case TB_SETUNICODEFORMAT:
7087 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
7089 case TB_UNKWN45D:
7090 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
7092 case TB_UNKWN45E:
7093 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
7095 case TB_UNKWN460:
7096 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
7098 case TB_UNKWN462:
7099 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
7101 case TB_UNKWN463:
7102 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
7104 case TB_UNKWN464:
7105 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
7107 /* Common Control Messages */
7109 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
7110 case CCM_GETCOLORSCHEME:
7111 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7113 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
7114 case CCM_SETCOLORSCHEME:
7115 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7117 case CCM_GETVERSION:
7118 return TOOLBAR_GetVersion (hwnd);
7120 case CCM_SETVERSION:
7121 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
7124 /* case WM_CHAR: */
7126 case WM_CREATE:
7127 return TOOLBAR_Create (hwnd, wParam, lParam);
7129 case WM_DESTROY:
7130 return TOOLBAR_Destroy (hwnd, wParam, lParam);
7132 case WM_ERASEBKGND:
7133 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
7135 case WM_GETFONT:
7136 return TOOLBAR_GetFont (hwnd, wParam, lParam);
7138 /* case WM_KEYDOWN: */
7139 /* case WM_KILLFOCUS: */
7141 case WM_LBUTTONDBLCLK:
7142 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
7144 case WM_LBUTTONDOWN:
7145 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
7147 case WM_LBUTTONUP:
7148 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
7150 case WM_RBUTTONUP:
7151 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
7153 case WM_RBUTTONDBLCLK:
7154 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
7156 case WM_MOUSEMOVE:
7157 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
7159 case WM_MOUSELEAVE:
7160 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
7162 case WM_CAPTURECHANGED:
7163 return TOOLBAR_CaptureChanged(hwnd);
7165 case WM_NCACTIVATE:
7166 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7168 case WM_NCCALCSIZE:
7169 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7171 case WM_NCCREATE:
7172 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7174 case WM_NCPAINT:
7175 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7177 case WM_NOTIFY:
7178 return TOOLBAR_Notify (hwnd, wParam, lParam);
7180 case WM_NOTIFYFORMAT:
7181 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7183 case WM_PAINT:
7184 return TOOLBAR_Paint (hwnd, wParam);
7186 case WM_SETREDRAW:
7187 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7189 case WM_SIZE:
7190 return TOOLBAR_Size (hwnd, wParam, lParam);
7192 case WM_STYLECHANGED:
7193 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7195 case WM_SYSCOLORCHANGE:
7196 return TOOLBAR_SysColorChange (hwnd);
7198 /* case WM_WININICHANGE: */
7200 case WM_CHARTOITEM:
7201 case WM_COMMAND:
7202 case WM_DRAWITEM:
7203 case WM_MEASUREITEM:
7204 case WM_VKEYTOITEM:
7205 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7207 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7208 case PGM_FORWARDMOUSE:
7209 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7211 default:
7212 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7213 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7214 uMsg, wParam, lParam);
7215 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7220 VOID
7221 TOOLBAR_Register (void)
7223 WNDCLASSW wndClass;
7225 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7226 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7227 wndClass.lpfnWndProc = ToolbarWindowProc;
7228 wndClass.cbClsExtra = 0;
7229 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7230 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7231 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7232 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7234 RegisterClassW (&wndClass);
7238 VOID
7239 TOOLBAR_Unregister (void)
7241 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7244 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7246 HIMAGELIST himlold;
7247 PIMLENTRY c = NULL;
7249 /* Check if the entry already exists */
7250 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7252 /* If this is a new entry we must create it and insert into the array */
7253 if (!c)
7255 PIMLENTRY *pnies;
7257 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7258 c->id = id;
7260 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7261 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7262 pnies[*cies] = c;
7263 (*cies)++;
7265 Free(*pies);
7266 *pies = pnies;
7269 himlold = c->himl;
7270 c->himl = himl;
7272 return himlold;
7276 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7278 int i;
7280 for (i = 0; i < *cies; i++)
7281 Free((*pies)[i]);
7283 Free(*pies);
7285 *cies = 0;
7286 *pies = NULL;
7290 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7292 PIMLENTRY c = NULL;
7294 if (pies != NULL)
7296 int i;
7298 for (i = 0; i < cies; i++)
7300 if (pies[i]->id == id)
7302 c = pies[i];
7303 break;
7308 return c;
7312 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7314 HIMAGELIST himlDef = 0;
7315 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7317 if (pie)
7318 himlDef = pie->himl;
7320 return himlDef;
7324 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7326 if (infoPtr->bUnicode)
7327 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7328 else
7330 CHAR Buffer[256];
7331 NMTOOLBARA nmtba;
7332 BOOL bRet = FALSE;
7334 nmtba.iItem = nmtb->iItem;
7335 nmtba.pszText = Buffer;
7336 nmtba.cchText = 256;
7337 ZeroMemory(nmtba.pszText, nmtba.cchText);
7339 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7341 int ccht = strlen(nmtba.pszText);
7342 if (ccht)
7343 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7344 nmtb->pszText, nmtb->cchText);
7346 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7347 bRet = TRUE;
7350 return bRet;
7355 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7356 int iItem, PCUSTOMBUTTON btnInfo)
7358 NMTOOLBARW nmtb;
7360 /* MSDN states that iItem is the index of the button, rather than the
7361 * command ID as used by every other NMTOOLBAR notification */
7362 nmtb.iItem = iItem;
7363 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7365 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);