- Documentation update.
[wine.git] / dlls / comctl32 / toolbar.c
blob8181dfb6d674e82d705542759710e022c1c984aa
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 * Differences between MSDN and actual native control operation:
25 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
26 * to the right of the bitmap. Otherwise, this style is
27 * identical to TBSTYLE_FLAT."
28 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
29 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
30 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
31 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
33 * This code was audited for completeness against the documented features
34 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
36 * Unless otherwise noted, we believe this code to be complete, as per
37 * the specification mentioned above.
38 * If you discover missing features or bugs please note them below.
40 * TODO:
41 * - Styles:
42 * - TBSTYLE_ALTDRAG
43 * - TBSTYLE_REGISTERDROP
44 * - TBSTYLE_EX_DOUBLEBUFFER
45 * - Messages:
46 * - TB_GETINSERTMARK
47 * - TB_GETINSERTMARKCOLOR
48 * - TB_GETMETRICS
49 * - TB_GETOBJECT
50 * - TB_INSERTMARKHITTEST
51 * - TB_MOVEBUTTON
52 * - TB_SETINSERTMARK
53 * - TB_SETMETRICS
54 * - Notifications:
55 * - NM_CHAR
56 * - NM_KEYDOWN
57 * - NM_LDOWN
58 * - NM_RCLICK
59 * - NM_RDBLCLICK
60 * - TBN_DELETINGBUTTON
61 * - TBN_DRAGOUT
62 * - TBN_GETOBJECT
63 * - TBN_RESTORE
64 * - TBN_SAVE
65 * - TBN_TOOLBARCHANGE
66 * - Button wrapping (under construction).
67 * - Fix TB_SETROWS.
68 * - Fix TOOLBAR_SetButtonInfo32A/W.
69 * - iListGap custom draw support.
70 * - Customization dialog:
71 * - Minor buglet in 'available buttons' list:
72 * Buttons are not listed in MS-like order. MS seems to use a single
73 * internal list to store the button information of both listboxes.
74 * - Drag list support.
76 * Testing:
77 * - Run tests using Waite Group Windows95 API Bible Volume 2.
78 * The second cdrom contains executables addstr.exe, btncount.exe,
79 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
80 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
81 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
82 * setparnt.exe, setrows.exe, toolwnd.exe.
83 * - Microsofts controlspy examples.
84 * - Charles Petzold's 'Programming Windows': gadgets.exe
87 #include <stdarg.h>
88 #include <string.h>
90 #include "windef.h"
91 #include "winbase.h"
92 #include "wingdi.h"
93 #include "winuser.h"
94 #include "wine/unicode.h"
95 #include "winnls.h"
96 #include "commctrl.h"
97 #include "imagelist.h"
98 #include "comctl32.h"
99 #include "wine/debug.h"
101 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
103 typedef struct
105 INT iBitmap;
106 INT idCommand;
107 BYTE fsState;
108 BYTE fsStyle;
109 DWORD dwData;
110 INT iString;
112 BOOL bHot;
113 INT nRow;
114 RECT rect;
115 } TBUTTON_INFO;
117 typedef struct
119 UINT nButtons;
120 HINSTANCE hInst;
121 UINT nID;
122 } TBITMAP_INFO;
124 typedef struct
126 HIMAGELIST himl;
127 INT id;
128 } IMLENTRY, *PIMLENTRY;
130 typedef struct
132 DWORD dwStructSize; /* size of TBBUTTON struct */
133 INT nHeight; /* height of the toolbar */
134 INT nWidth; /* width of the toolbar */
135 RECT client_rect;
136 INT nButtonHeight;
137 INT nButtonWidth;
138 INT nBitmapHeight;
139 INT nBitmapWidth;
140 INT nIndent;
141 INT nRows; /* number of button rows */
142 INT nMaxTextRows; /* maximum number of text rows */
143 INT cxMin; /* minimum button width */
144 INT cxMax; /* maximum button width */
145 INT nNumButtons; /* number of buttons */
146 INT nNumBitmaps; /* number of bitmaps */
147 INT nNumStrings; /* number of strings */
148 INT nNumBitmapInfos;
149 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
150 BOOL bCaptured; /* mouse captured? */
151 INT nButtonDown;
152 INT nOldHit;
153 INT nHotItem; /* index of the "hot" item */
154 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
155 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
156 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
157 SIZE szPadding; /* padding values around button */
158 INT iListGap; /* default gap between text and image for toolbar with list style */
159 HFONT hDefaultFont;
160 HFONT hFont; /* text font */
161 HIMAGELIST himlInt; /* image list created internally */
162 PIMLENTRY *himlDef; /* default image list array */
163 INT cimlDef; /* default image list array count */
164 PIMLENTRY *himlHot; /* hot image list array */
165 INT cimlHot; /* hot image list array count */
166 PIMLENTRY *himlDis; /* disabled image list array */
167 INT cimlDis; /* disabled image list array count */
168 HWND hwndToolTip; /* handle to tool tip control */
169 HWND hwndNotify; /* handle to the window that gets notifications */
170 HWND hwndSelf; /* my own handle */
171 BOOL bTransparent; /* background transparency flag */
172 BOOL bBtnTranspnt; /* button transparency flag */
173 BOOL bAutoSize; /* auto size deadlock indicator */
174 BOOL bAnchor; /* anchor highlight enabled */
175 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
176 BOOL bDoRedraw; /* Redraw status */
177 DWORD dwExStyle; /* extended toolbar style */
178 DWORD dwDTFlags; /* DrawText flags */
180 COLORREF clrInsertMark; /* insert mark color */
181 COLORREF clrBtnHighlight; /* color for Flat Separator */
182 COLORREF clrBtnShadow; /* color for Flag Separator */
183 RECT rcBound; /* bounding rectangle */
184 INT iVersion;
185 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
186 * for TTN_GETDISPINFOW notification */
187 TBUTTON_INFO *buttons; /* pointer to button array */
188 LPWSTR *strings; /* pointer to string array */
189 TBITMAP_INFO *bitmaps;
190 } TOOLBAR_INFO, *PTOOLBAR_INFO;
193 /* used by customization dialog */
194 typedef struct
196 PTOOLBAR_INFO tbInfo;
197 HWND tbHwnd;
198 } CUSTDLG_INFO, *PCUSTDLG_INFO;
200 typedef struct
202 TBBUTTON btn;
203 BOOL bVirtual;
204 BOOL bRemovable;
205 WCHAR text[64];
206 } CUSTOMBUTTON, *PCUSTOMBUTTON;
208 typedef enum
210 IMAGE_LIST_DEFAULT,
211 IMAGE_LIST_HOT,
212 IMAGE_LIST_DISABLED
213 } IMAGE_LIST_TYPE;
215 #define SEPARATOR_WIDTH 8
216 #define TOP_BORDER 2
217 #define BOTTOM_BORDER 2
218 #define DDARROW_WIDTH 11
219 #define ARROW_HEIGHT 3
221 /* gap between border of button and text/image */
222 #define OFFSET_X 1
223 #define OFFSET_Y 1
224 /* how wide to treat the bitmap if it isn't present */
225 #define LIST_IMAGE_ABSENT_WIDTH 2
227 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
228 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
229 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
231 static inline int TOOLBAR_GetListTextOffset(TOOLBAR_INFO *infoPtr, INT iListGap)
233 return GetSystemMetrics(SM_CXEDGE) + iListGap - infoPtr->szPadding.cx/2;
236 /* Used to find undocumented extended styles */
237 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
238 TBSTYLE_EX_UNDOC1 | \
239 TBSTYLE_EX_MIXEDBUTTONS | \
240 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
242 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
243 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
244 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
245 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
246 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
248 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
249 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
250 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
251 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
252 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
253 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
255 static LRESULT
256 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
259 static LPWSTR
260 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
262 LPWSTR lpText = NULL;
264 /* FIXME: iString == -1 is undocumented */
265 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
266 lpText = (LPWSTR)btnPtr->iString;
267 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
268 lpText = infoPtr->strings[btnPtr->iString];
270 return lpText;
273 static void
274 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
276 if (TRACE_ON(toolbar)){
277 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
278 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
279 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
280 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
281 if (internal)
282 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
283 btn_num, bP->idCommand,
284 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
285 bP->rect.left, bP->rect.top,
286 bP->rect.right, bP->rect.bottom);
291 static void
292 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
294 if (TRACE_ON(toolbar)) {
295 INT i;
296 DWORD dwStyle;
298 dwStyle = GetWindowLongA (iP->hwndSelf, GWL_STYLE);
299 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
300 iP->hwndSelf, line,
301 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
302 iP->nNumStrings, dwStyle);
303 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
304 iP->hwndSelf, line,
305 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
306 (iP->bDoRedraw) ? "TRUE" : "FALSE");
307 for(i=0; i<iP->nNumButtons; i++) {
308 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
314 /***********************************************************************
315 * TOOLBAR_CheckStyle
317 * This function validates that the styles set are implemented and
318 * issues FIXME's warning of possible problems. In a perfect world this
319 * function should be null.
321 static void
322 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
324 if (dwStyle & TBSTYLE_ALTDRAG)
325 FIXME("[%p] TBSTYLE_ALTDRAG not implemented\n", hwnd);
326 if (dwStyle & TBSTYLE_REGISTERDROP)
327 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
331 static INT
332 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
334 if(!IsWindow(infoPtr->hwndSelf))
335 return 0; /* we have just been destroyed */
337 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
338 nmhdr->hwndFrom = infoPtr->hwndSelf;
339 nmhdr->code = code;
341 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
342 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
344 if (infoPtr->bNtfUnicode)
345 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
346 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
347 else
348 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
349 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
352 /***********************************************************************
353 * TOOLBAR_GetBitmapIndex
355 * This function returns the bitmap index associated with a button.
356 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
357 * is issued to retrieve the index.
359 static INT
360 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
362 INT ret = btnPtr->iBitmap;
364 if (ret == I_IMAGECALLBACK) {
365 /* issue TBN_GETDISPINFO */
366 NMTBDISPINFOA nmgd;
368 nmgd.idCommand = btnPtr->idCommand;
369 nmgd.lParam = btnPtr->dwData;
370 nmgd.dwMask = TBNF_IMAGE;
371 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
372 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
373 TBN_GETDISPINFOA);
374 if (nmgd.dwMask & TBNF_DI_SETITEM) {
375 btnPtr->iBitmap = nmgd.iImage;
377 ret = nmgd.iImage;
378 TRACE("TBN_GETDISPINFOA returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
379 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
382 if (ret != I_IMAGENONE)
383 ret = GETIBITMAP(infoPtr, ret);
385 return ret;
389 static BOOL
390 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
392 HIMAGELIST himl;
393 INT id = GETHIMLID(infoPtr, index);
394 INT iBitmap = GETIBITMAP(infoPtr, index);
396 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
397 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
398 (index == I_IMAGECALLBACK))
399 return TRUE;
400 else
401 return FALSE;
405 /***********************************************************************
406 * TOOLBAR_GetImageListForDrawing
408 * This function validates the bitmap index (including I_IMAGECALLBACK
409 * functionality) and returns the corresponding image list.
411 static HIMAGELIST
412 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
414 HIMAGELIST himl;
416 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
417 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
418 ERR("index %d,%d is not valid, max %d\n",
419 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
420 return NULL;
423 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
424 if ((*index == I_IMAGECALLBACK) ||
425 (*index == I_IMAGENONE)) return NULL;
426 ERR("TBN_GETDISPINFO returned invalid index %d\n",
427 *index);
428 return NULL;
431 switch(imagelist)
433 case IMAGE_LIST_DEFAULT:
434 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
435 break;
436 case IMAGE_LIST_HOT:
437 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
438 break;
439 case IMAGE_LIST_DISABLED:
440 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
441 break;
442 default:
443 himl = NULL;
444 FIXME("Shouldn't reach here\n");
447 if (!himl)
448 TRACE("no image list\n");
450 return himl;
454 /***********************************************************************
455 * TOOLBAR_TestImageExist
457 * This function is similar to TOOLBAR_GetImageListForDrawing, except it does not
458 * return the image list. The I_IMAGECALLBACK functionality is implemented.
460 static BOOL
461 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
463 INT index;
465 if (!himl) return FALSE;
467 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
468 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
469 ERR("index %d is not valid, max %d\n",
470 btnPtr->iBitmap, infoPtr->nNumBitmaps);
471 return FALSE;
474 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
475 if ((index == I_IMAGECALLBACK) ||
476 (index == I_IMAGENONE)) return FALSE;
477 ERR("TBN_GETDISPINFO returned invalid index %d\n",
478 index);
479 return FALSE;
481 return TRUE;
485 static void
486 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
488 RECT myrect;
489 COLORREF oldcolor, newcolor;
491 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
492 myrect.right = myrect.left + 1;
493 myrect.top = lpRect->top + 2;
494 myrect.bottom = lpRect->bottom - 2;
496 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
497 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
498 oldcolor = SetBkColor (hdc, newcolor);
499 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
501 myrect.left = myrect.right;
502 myrect.right = myrect.left + 1;
504 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
505 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
506 SetBkColor (hdc, newcolor);
507 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
509 SetBkColor (hdc, oldcolor);
513 /***********************************************************************
514 * TOOLBAR_DrawDDFlatSeparator
516 * This function draws the separator that was flagged as BTNS_DROPDOWN.
517 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
518 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
519 * are horizontal as opposed to the vertical separators for not dropdown
520 * type.
522 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
524 static void
525 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
527 RECT myrect;
528 COLORREF oldcolor, newcolor;
530 myrect.left = lpRect->left;
531 myrect.right = lpRect->right;
532 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
533 myrect.bottom = myrect.top + 1;
535 InflateRect (&myrect, -2, 0);
537 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
538 myrect.left, myrect.top, myrect.right, myrect.bottom);
540 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
541 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
542 oldcolor = SetBkColor (hdc, newcolor);
543 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
545 myrect.top = myrect.bottom;
546 myrect.bottom = myrect.top + 1;
548 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
549 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
550 SetBkColor (hdc, newcolor);
551 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
553 SetBkColor (hdc, oldcolor);
557 static void
558 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
560 INT x, y;
561 HPEN hPen, hOldPen;
563 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
564 hOldPen = SelectObject ( hdc, hPen );
565 x = left + 2;
566 y = top;
567 MoveToEx (hdc, x, y, NULL);
568 LineTo (hdc, x+5, y++); x++;
569 MoveToEx (hdc, x, y, NULL);
570 LineTo (hdc, x+3, y++); x++;
571 MoveToEx (hdc, x, y, NULL);
572 LineTo (hdc, x+1, y++);
573 SelectObject( hdc, hOldPen );
574 DeleteObject( hPen );
578 * Draw the text string for this button.
579 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
580 * is non-zero, so we can simply check himlDef to see if we have
581 * an image list
583 static void
584 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
585 NMTBCUSTOMDRAW *tbcd)
587 HDC hdc = tbcd->nmcd.hdc;
588 HFONT hOldFont = 0;
589 COLORREF clrOld = 0;
590 COLORREF clrOldBk = 0;
591 int oldBkMode = 0;
592 UINT state = tbcd->nmcd.uItemState;
594 /* draw text */
595 if (lpText) {
596 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
597 rcText->left, rcText->top, rcText->right, rcText->bottom);
599 hOldFont = SelectObject (hdc, infoPtr->hFont);
600 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
601 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
603 else if (state & CDIS_DISABLED) {
604 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
605 OffsetRect (rcText, 1, 1);
606 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
607 SetTextColor (hdc, comctl32_color.clr3dShadow);
608 OffsetRect (rcText, -1, -1);
610 else if (state & CDIS_INDETERMINATE) {
611 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
613 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
614 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
615 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
616 oldBkMode = SetBkMode (hdc, OPAQUE); /* FIXME: should this be in the NMTBCUSTOMDRAW structure? */
618 else {
619 clrOld = SetTextColor (hdc, tbcd->clrText);
622 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
623 SetTextColor (hdc, clrOld);
624 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
626 SetBkColor (hdc, clrOldBk);
627 SetBkMode (hdc, oldBkMode);
629 SelectObject (hdc, hOldFont);
634 static void
635 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
637 HDC hdc = tbcd->nmcd.hdc;
638 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
639 COLORREF clrTextOld;
640 COLORREF clrBkOld;
641 INT cx = lpRect->right - lpRect->left;
642 INT cy = lpRect->bottom - lpRect->top;
643 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
644 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
645 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, PATCOPY);
646 SetBkColor(hdc, clrBkOld);
647 SetTextColor(hdc, clrTextOld);
648 SelectObject (hdc, hbr);
652 static void TOOLBAR_DrawMasked(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
653 HDC hdc, INT x, INT y)
655 int index;
656 HIMAGELIST himl =
657 TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
659 if (himl)
661 INT cx, cy;
662 HBITMAP hbmMask, hbmImage;
663 HDC hdcMask, hdcImage;
665 ImageList_GetIconSize(himl, &cx, &cy);
667 /* Create src image */
668 hdcImage = CreateCompatibleDC(hdc);
669 hbmImage = CreateBitmap(cx, cy, GetDeviceCaps(hdc,PLANES),
670 GetDeviceCaps(hdc,BITSPIXEL), NULL);
671 SelectObject(hdcImage, hbmImage);
672 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
673 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_NORMAL);
675 /* Create Mask */
676 hdcMask = CreateCompatibleDC(0);
677 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
678 SelectObject(hdcMask, hbmMask);
680 /* Remove the background and all white pixels */
681 SetBkColor(hdcImage, ImageList_GetBkColor(himl));
682 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, SRCCOPY);
683 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
684 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
686 /* draw the new mask 'etched' to hdc */
687 SetBkColor(hdc, RGB(255, 255, 255));
688 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
689 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
690 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
691 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
692 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
694 /* Cleanup */
695 DeleteObject(hbmImage);
696 DeleteDC(hdcImage);
697 DeleteObject (hbmMask);
698 DeleteDC(hdcMask);
703 static UINT
704 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
706 UINT retstate = 0;
708 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
709 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
710 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
711 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
712 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
713 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
714 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
715 return retstate;
718 /* draws the image on a toolbar button */
719 static void
720 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
722 HIMAGELIST himl = NULL;
723 BOOL draw_masked = FALSE;
724 INT index;
725 INT offset = 0;
726 UINT draw_flags = ILD_NORMAL;
728 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
730 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
731 if (!himl)
732 draw_masked = TRUE;
734 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && (GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & TBSTYLE_FLAT))
736 /* if hot, attempt to draw with hot image list, if fails,
737 use default image list */
738 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
739 if (!himl)
740 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
742 else
743 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
745 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
746 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
747 offset = 1;
749 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
750 (tbcd->nmcd.uItemState & CDIS_MARKED))
751 draw_flags |= ILD_BLEND50;
753 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
754 index, himl, left, top, offset);
756 if (draw_masked)
757 TOOLBAR_DrawMasked (infoPtr, btnPtr, tbcd->nmcd.hdc, left + offset, top + offset);
758 else if (himl)
759 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
762 /* draws a blank frame for a toolbar button */
763 static void
764 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd)
766 HDC hdc = tbcd->nmcd.hdc;
767 RECT rc = tbcd->nmcd.rc;
768 /* if the state is disabled or indeterminate then the button
769 * cannot have an interactive look like pressed or hot */
770 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
771 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
772 BOOL pressed_look = !non_interactive_state &&
773 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
774 (tbcd->nmcd.uItemState & CDIS_CHECKED));
776 /* app don't want us to draw any edges */
777 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
778 return;
780 if (flat)
782 if (pressed_look)
783 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
784 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
785 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
787 else
789 if (pressed_look)
790 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
791 else
792 DrawEdge (hdc, &rc, EDGE_RAISED,
793 BF_SOFT | BF_RECT | BF_MIDDLE);
797 static void
798 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow)
800 HDC hdc = tbcd->nmcd.hdc;
801 int offset = 0;
803 if (flat)
805 if ((tbcd->nmcd.uItemState & CDIS_SELECTED) || (tbcd->nmcd.uItemState & CDIS_CHECKED))
806 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
807 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
808 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
809 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
810 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
812 else
814 if ((tbcd->nmcd.uItemState & CDIS_SELECTED) || (tbcd->nmcd.uItemState & CDIS_CHECKED))
815 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
816 else
817 DrawEdge (hdc, rcArrow, EDGE_RAISED,
818 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
821 if (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
822 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
824 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
826 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
827 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
829 else
830 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
833 /* draws a complete toolbar button */
834 static void
835 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
837 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
838 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
839 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
840 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
841 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
842 BOOL drawSepDropDownArrow = hasDropDownArrow &&
843 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
844 RECT rc, rcArrow, rcBitmap, rcText;
845 LPWSTR lpText = NULL;
846 NMTBCUSTOMDRAW tbcd;
847 DWORD ntfret;
848 INT offset;
850 rc = btnPtr->rect;
851 CopyRect (&rcArrow, &rc);
852 CopyRect(&rcBitmap, &rc);
854 /* get a pointer to the text */
855 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
857 if (hasDropDownArrow)
859 int right;
861 if (dwStyle & TBSTYLE_FLAT)
862 right = max(rc.left, rc.right - DDARROW_WIDTH);
863 else
864 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
866 if (drawSepDropDownArrow)
867 rc.right = right;
869 rcArrow.left = right;
872 /* copy text rect after adjusting for drop-down arrow
873 * so that text is centred in the rectangle not containing
874 * the arrow */
875 CopyRect(&rcText, &rc);
877 /* Center the bitmap horizontally and vertically */
878 if (dwStyle & TBSTYLE_LIST)
879 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
880 else
881 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
883 if(lpText)
884 rcBitmap.top+= GetSystemMetrics(SM_CYEDGE) + OFFSET_Y;
885 else
886 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
888 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n",
889 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
890 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
891 TRACE ("iString: %x\n", btnPtr->iString);
892 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
894 /* draw text */
895 if (lpText) {
896 rcText.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
897 rcText.right -= GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
898 if (GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,btnPtr->iBitmap)) &&
899 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
901 if (dwStyle & TBSTYLE_LIST)
902 rcText.left += infoPtr->nBitmapWidth + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
903 else
904 rcText.top += GetSystemMetrics(SM_CYEDGE) + OFFSET_Y + infoPtr->nBitmapHeight + infoPtr->szPadding.cy/2;
906 else
907 if (dwStyle & TBSTYLE_LIST)
908 rcText.left += LIST_IMAGE_ABSENT_WIDTH + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
910 if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
911 OffsetRect (&rcText, 1, 1);
914 /* Initialize fields in all cases, because we use these later
915 * NOTE: applications can and do alter these to customize their
916 * toolbars */
917 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
918 tbcd.clrText = comctl32_color.clrBtnText;
919 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
920 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
921 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
922 tbcd.clrMark = comctl32_color.clrHighlight;
923 tbcd.clrHighlightHotTrack = 0;
924 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
925 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
926 /* MSDN says that this is the text rectangle.
927 * But (why always a but) tracing of v5.7 of native shows
928 * that this is really a *relative* rectangle based on the
929 * the nmcd.rc. Also the left and top are always 0 ignoring
930 * any bitmap that might be present. */
931 tbcd.rcText.left = 0;
932 tbcd.rcText.top = 0;
933 tbcd.rcText.right = rcText.right - rc.left;
934 tbcd.rcText.bottom = rcText.bottom - rc.top;
935 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
936 tbcd.nmcd.hdc = hdc;
937 tbcd.nmcd.rc = rc;
938 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
940 /* FIXME: what are these used for? */
941 tbcd.hbrLines = 0;
942 tbcd.hpenLines = 0;
944 /* Issue Item Prepaint notify */
945 infoPtr->dwItemCustDraw = 0;
946 infoPtr->dwItemCDFlag = 0;
947 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
949 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
950 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
951 tbcd.nmcd.lItemlParam = btnPtr->dwData;
952 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
953 /* reset these fields so the user can't alter the behaviour like native */
954 tbcd.nmcd.hdc = hdc;
955 tbcd.nmcd.rc = rc;
957 infoPtr->dwItemCustDraw = ntfret & 0xffff;
958 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
959 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
960 return;
961 /* save the only part of the rect that the user can change */
962 rcText.right = tbcd.rcText.right + rc.left;
963 rcText.bottom = tbcd.rcText.bottom + rc.top;
966 /* separator */
967 if (btnPtr->fsStyle & BTNS_SEP) {
968 /* with the FLAT style, iBitmap is the width and has already */
969 /* been taken into consideration in calculating the width */
970 /* so now we need to draw the vertical separator */
971 /* empirical tests show that iBitmap can/will be non-zero */
972 /* when drawing the vertical bar... */
973 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
974 if (btnPtr->fsStyle & BTNS_DROPDOWN)
975 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
976 else
977 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
979 else if (btnPtr->fsStyle != BTNS_SEP) {
980 FIXME("Draw some kind of separator: fsStyle=%x\n",
981 btnPtr->fsStyle);
983 goto FINALNOTIFY;
986 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
987 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
988 TOOLBAR_DrawPattern (&rc, &tbcd);
990 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
992 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
994 COLORREF oldclr;
996 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
997 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
998 if (hasDropDownArrow)
999 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
1000 SetBkColor(hdc, oldclr);
1004 TOOLBAR_DrawFrame(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd);
1006 if (drawSepDropDownArrow)
1007 TOOLBAR_DrawSepDDArrow(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd, &rcArrow);
1009 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1010 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1012 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1014 if (hasDropDownArrow && !drawSepDropDownArrow)
1016 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1018 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1019 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1021 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1023 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1024 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1026 else
1027 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1030 FINALNOTIFY:
1031 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1033 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1034 tbcd.nmcd.hdc = hdc;
1035 tbcd.nmcd.rc = rc;
1036 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1037 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1038 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1039 tbcd.rcText = rcText;
1040 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1041 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1042 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1048 static void
1049 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1051 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1052 TBUTTON_INFO *btnPtr;
1053 INT i, oldBKmode = 0;
1054 RECT rcTemp, rcClient;
1055 NMTBCUSTOMDRAW tbcd;
1056 DWORD ntfret;
1058 /* the app has told us not to redraw the toolbar */
1059 if (!infoPtr->bDoRedraw)
1060 return;
1062 /* if imagelist belongs to the app, it can be changed
1063 by the app after setting it */
1064 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1066 infoPtr->nNumBitmaps = 0;
1067 for (i = 0; i < infoPtr->cimlDef; i++)
1068 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1071 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1073 /* Send initial notify */
1074 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1075 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1076 tbcd.nmcd.hdc = hdc;
1077 tbcd.nmcd.rc = ps->rcPaint;
1078 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1079 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1081 if (infoPtr->bBtnTranspnt)
1082 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1084 GetClientRect(hwnd, &rcClient);
1086 /* redraw necessary buttons */
1087 btnPtr = infoPtr->buttons;
1088 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1090 BOOL bDraw;
1091 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1093 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1094 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1096 else
1097 bDraw = TRUE;
1098 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1099 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1100 if (bDraw)
1101 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1104 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1105 SetBkMode (hdc, oldBKmode);
1107 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1109 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1110 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1111 tbcd.nmcd.hdc = hdc;
1112 tbcd.nmcd.rc = ps->rcPaint;
1113 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1117 /***********************************************************************
1118 * TOOLBAR_MeasureString
1120 * This function gets the width and height of a string in pixels. This
1121 * is done first by using GetTextExtentPoint to get the basic width
1122 * and height. The DrawText is called with DT_CALCRECT to get the exact
1123 * width. The reason is because the text may have more than one "&" (or
1124 * prefix characters as M$ likes to call them). The prefix character
1125 * indicates where the underline goes, except for the string "&&" which
1126 * is reduced to a single "&". GetTextExtentPoint does not process these
1127 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1129 static void
1130 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1131 HDC hdc, LPSIZE lpSize)
1133 RECT myrect;
1135 lpSize->cx = 0;
1136 lpSize->cy = 0;
1138 if (infoPtr->nMaxTextRows > 0 &&
1139 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1140 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1141 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1143 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1145 if(lpText != NULL) {
1146 /* first get size of all the text */
1147 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1149 /* feed above size into the rectangle for DrawText */
1150 myrect.left = myrect.top = 0;
1151 myrect.right = lpSize->cx;
1152 myrect.bottom = lpSize->cy;
1154 /* Use DrawText to get true size as drawn (less pesky "&") */
1155 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1156 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1157 DT_NOPREFIX : 0));
1159 /* feed back to caller */
1160 lpSize->cx = myrect.right;
1161 lpSize->cy = myrect.bottom;
1165 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1168 /***********************************************************************
1169 * TOOLBAR_CalcStrings
1171 * This function walks through each string and measures it and returns
1172 * the largest height and width to caller.
1174 static void
1175 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1177 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1178 TBUTTON_INFO *btnPtr;
1179 INT i;
1180 SIZE sz;
1181 HDC hdc;
1182 HFONT hOldFont;
1184 lpSize->cx = 0;
1185 lpSize->cy = 0;
1187 if(infoPtr->nMaxTextRows == 0)
1188 return;
1190 hdc = GetDC (hwnd);
1191 hOldFont = SelectObject (hdc, infoPtr->hFont);
1193 btnPtr = infoPtr->buttons;
1194 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1195 if(TOOLBAR_HasText(infoPtr, btnPtr))
1197 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1198 if (sz.cx > lpSize->cx)
1199 lpSize->cx = sz.cx;
1200 if (sz.cy > lpSize->cy)
1201 lpSize->cy = sz.cy;
1205 SelectObject (hdc, hOldFont);
1206 ReleaseDC (hwnd, hdc);
1208 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1211 /***********************************************************************
1212 * TOOLBAR_WrapToolbar
1214 * This function walks through the buttons and separators in the
1215 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1216 * wrapping should occur based on the width of the toolbar window.
1217 * It does *not* calculate button placement itself. That task
1218 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1219 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1220 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1222 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1223 * vertical toolbar lists.
1226 static void
1227 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1229 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1230 TBUTTON_INFO *btnPtr;
1231 INT x, cx, i, j;
1232 RECT rc;
1233 BOOL bWrap, bButtonWrap;
1235 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1236 /* no layout is necessary. Applications may use this style */
1237 /* to perform their own layout on the toolbar. */
1238 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1239 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1241 btnPtr = infoPtr->buttons;
1242 x = infoPtr->nIndent;
1244 /* this can get the parents width, to know how far we can extend
1245 * this toolbar. We cannot use its height, as there may be multiple
1246 * toolbars in a rebar control
1248 GetClientRect( GetParent(hwnd), &rc );
1249 infoPtr->nWidth = rc.right - rc.left;
1250 bButtonWrap = FALSE;
1252 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1253 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1254 infoPtr->nIndent);
1256 for (i = 0; i < infoPtr->nNumButtons; i++ )
1258 bWrap = FALSE;
1259 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1261 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1262 continue;
1264 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1265 /* it is the actual width of the separator. This is used for */
1266 /* custom controls in toolbars. */
1267 /* */
1268 /* BTNS_DROPDOWN separators are treated as buttons for */
1269 /* width. - GA 8/01 */
1270 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1271 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1272 cx = (btnPtr[i].iBitmap > 0) ?
1273 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1274 else
1275 cx = infoPtr->nButtonWidth;
1277 /* Two or more adjacent separators form a separator group. */
1278 /* The first separator in a group should be wrapped to the */
1279 /* next row if the previous wrapping is on a button. */
1280 if( bButtonWrap &&
1281 (btnPtr[i].fsStyle & BTNS_SEP) &&
1282 (i + 1 < infoPtr->nNumButtons ) &&
1283 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1285 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1286 btnPtr[i].fsState |= TBSTATE_WRAP;
1287 x = infoPtr->nIndent;
1288 i++;
1289 bButtonWrap = FALSE;
1290 continue;
1293 /* The layout makes sure the bitmap is visible, but not the button. */
1294 /* Test added to also wrap after a button that starts a row but */
1295 /* is bigger than the area. - GA 8/01 */
1296 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1297 > infoPtr->nWidth ) ||
1298 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1300 BOOL bFound = FALSE;
1302 /* If the current button is a separator and not hidden, */
1303 /* go to the next until it reaches a non separator. */
1304 /* Wrap the last separator if it is before a button. */
1305 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1306 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1307 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1308 i < infoPtr->nNumButtons )
1310 i++;
1311 bFound = TRUE;
1314 if( bFound && i < infoPtr->nNumButtons )
1316 i--;
1317 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1318 i, btnPtr[i].fsStyle, x, cx);
1319 btnPtr[i].fsState |= TBSTATE_WRAP;
1320 x = infoPtr->nIndent;
1321 bButtonWrap = FALSE;
1322 continue;
1324 else if ( i >= infoPtr->nNumButtons)
1325 break;
1327 /* If the current button is not a separator, find the last */
1328 /* separator and wrap it. */
1329 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1331 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1332 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1334 bFound = TRUE;
1335 i = j;
1336 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1337 i, btnPtr[i].fsStyle, x, cx);
1338 x = infoPtr->nIndent;
1339 btnPtr[j].fsState |= TBSTATE_WRAP;
1340 bButtonWrap = FALSE;
1341 break;
1345 /* If no separator available for wrapping, wrap one of */
1346 /* non-hidden previous button. */
1347 if (!bFound)
1349 for ( j = i - 1;
1350 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1352 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1353 continue;
1355 bFound = TRUE;
1356 i = j;
1357 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1358 i, btnPtr[i].fsStyle, x, cx);
1359 x = infoPtr->nIndent;
1360 btnPtr[j].fsState |= TBSTATE_WRAP;
1361 bButtonWrap = TRUE;
1362 break;
1366 /* If all above failed, wrap the current button. */
1367 if (!bFound)
1369 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1370 i, btnPtr[i].fsStyle, x, cx);
1371 btnPtr[i].fsState |= TBSTATE_WRAP;
1372 bFound = TRUE;
1373 x = infoPtr->nIndent;
1374 if (btnPtr[i].fsStyle & BTNS_SEP )
1375 bButtonWrap = FALSE;
1376 else
1377 bButtonWrap = TRUE;
1380 else {
1381 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1382 i, btnPtr[i].fsStyle, x, cx);
1383 x += cx;
1389 /***********************************************************************
1390 * TOOLBAR_CalcToolbar
1392 * This function calculates button and separator placement. It first
1393 * calculates the button sizes, gets the toolbar window width and then
1394 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1395 * on. It assigns a new location to each item and sends this location to
1396 * the tooltip window if appropriate. Finally, it updates the rcBound
1397 * rect and calculates the new required toolbar window height.
1400 static void
1401 TOOLBAR_CalcToolbar (HWND hwnd)
1403 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1404 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1405 TBUTTON_INFO *btnPtr;
1406 INT i, nRows, nSepRows;
1407 INT x, y, cx, cy;
1408 SIZE sizeString;
1409 BOOL bWrap;
1410 BOOL usesBitmaps = FALSE;
1411 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1413 TOOLBAR_CalcStrings (hwnd, &sizeString);
1415 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1417 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1419 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1420 usesBitmaps = TRUE;
1422 if (dwStyle & TBSTYLE_LIST)
1424 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1425 0, sizeString.cy) + infoPtr->szPadding.cy;
1426 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1427 LIST_IMAGE_ABSENT_WIDTH) + sizeString.cx + infoPtr->szPadding.cx;
1428 if (sizeString.cx > 0)
1429 infoPtr->nButtonWidth += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1430 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1431 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1432 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1434 else {
1435 if (sizeString.cy > 0)
1437 if (usesBitmaps)
1438 infoPtr->nButtonHeight = sizeString.cy +
1439 infoPtr->szPadding.cy/2 + /* this is the space to separate text from bitmap */
1440 infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1441 else
1442 infoPtr->nButtonHeight = sizeString.cy + infoPtr->szPadding.cy;
1444 else
1445 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1447 if (sizeString.cx > infoPtr->nBitmapWidth)
1448 infoPtr->nButtonWidth = sizeString.cx + infoPtr->szPadding.cx;
1449 else
1450 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + infoPtr->szPadding.cx;
1453 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1454 infoPtr->nButtonWidth = infoPtr->cxMin;
1455 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1456 infoPtr->nButtonWidth = infoPtr->cxMax;
1458 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1460 x = infoPtr->nIndent;
1461 y = 0;
1463 /* from above, minimum is a button, and possible text */
1464 cx = infoPtr->nButtonWidth;
1466 /* cannot use just ButtonHeight, we may have no buttons! */
1467 if (infoPtr->nNumButtons > 0)
1468 infoPtr->nHeight = infoPtr->nButtonHeight;
1470 cy = infoPtr->nHeight;
1472 nRows = nSepRows = 0;
1474 infoPtr->rcBound.top = y;
1475 infoPtr->rcBound.left = x;
1476 infoPtr->rcBound.bottom = y + cy;
1477 infoPtr->rcBound.right = x;
1479 btnPtr = infoPtr->buttons;
1481 TRACE("cy=%d\n", cy);
1483 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1485 bWrap = FALSE;
1486 if (btnPtr->fsState & TBSTATE_HIDDEN)
1488 SetRectEmpty (&btnPtr->rect);
1489 continue;
1492 cy = infoPtr->nHeight;
1494 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1495 /* it is the actual width of the separator. This is used for */
1496 /* custom controls in toolbars. */
1497 if (btnPtr->fsStyle & BTNS_SEP) {
1498 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1499 cy = (btnPtr->iBitmap > 0) ?
1500 btnPtr->iBitmap : SEPARATOR_WIDTH;
1501 cx = infoPtr->nButtonWidth;
1503 else
1504 cx = (btnPtr->iBitmap > 0) ?
1505 btnPtr->iBitmap : SEPARATOR_WIDTH;
1507 else
1509 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1510 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1512 SIZE sz;
1513 HDC hdc;
1514 HFONT hOldFont;
1516 hdc = GetDC (hwnd);
1517 hOldFont = SelectObject (hdc, infoPtr->hFont);
1519 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1521 SelectObject (hdc, hOldFont);
1522 ReleaseDC (hwnd, hdc);
1524 /* add space on for button frame, etc */
1525 cx = sz.cx + infoPtr->szPadding.cx;
1527 /* add list padding */
1528 if ((dwStyle & TBSTYLE_LIST) && sz.cx > 0)
1529 cx += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1531 if (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))
1533 if (dwStyle & TBSTYLE_LIST)
1534 cx += infoPtr->nBitmapWidth;
1535 else if (cx < (infoPtr->nBitmapWidth+infoPtr->szPadding.cx))
1536 cx = infoPtr->nBitmapWidth+infoPtr->szPadding.cx;
1538 else if (dwStyle & TBSTYLE_LIST)
1539 cx += LIST_IMAGE_ABSENT_WIDTH;
1541 else
1542 cx = infoPtr->nButtonWidth;
1544 if ((hasDropDownArrows && (btnPtr->fsStyle & BTNS_DROPDOWN)) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN))
1545 cx += DDARROW_WIDTH;
1547 if (btnPtr->fsState & TBSTATE_WRAP )
1548 bWrap = TRUE;
1550 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1552 if (infoPtr->rcBound.left > x)
1553 infoPtr->rcBound.left = x;
1554 if (infoPtr->rcBound.right < x + cx)
1555 infoPtr->rcBound.right = x + cx;
1556 if (infoPtr->rcBound.bottom < y + cy)
1557 infoPtr->rcBound.bottom = y + cy;
1559 /* Set the toolTip only for non-hidden, non-separator button */
1560 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1562 TTTOOLINFOA ti;
1564 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1565 ti.cbSize = sizeof(TTTOOLINFOA);
1566 ti.hwnd = hwnd;
1567 ti.uId = btnPtr->idCommand;
1568 ti.rect = btnPtr->rect;
1569 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1570 0, (LPARAM)&ti);
1573 /* btnPtr->nRow is zero based. The space between the rows is */
1574 /* also considered as a row. */
1575 btnPtr->nRow = nRows + nSepRows;
1577 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1578 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1579 x, y, x+cx, y+cy);
1581 if( bWrap )
1583 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1584 y += cy;
1585 else
1587 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1588 /* it is the actual width of the separator. This is used for */
1589 /* custom controls in toolbars. */
1590 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1591 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1592 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1593 else
1594 y += cy;
1596 /* nSepRows is used to calculate the extra height follwoing */
1597 /* the last row. */
1598 nSepRows++;
1600 x = infoPtr->nIndent;
1602 /* Increment row number unless this is the last button */
1603 /* and it has Wrap set. */
1604 if (i != infoPtr->nNumButtons-1)
1605 nRows++;
1607 else
1608 x += cx;
1611 /* infoPtr->nRows is the number of rows on the toolbar */
1612 infoPtr->nRows = nRows + nSepRows + 1;
1614 #if 0
1615 /********************************************************************
1616 * The following while interesting, does not match the values *
1617 * created above for the button rectangles, nor the rcBound rect. *
1618 * We will comment it out and remove it later. *
1620 * The problem showed up as heights in the pager control that was *
1621 * wrong. *
1622 ********************************************************************/
1624 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1625 /* the last row. */
1626 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1627 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1628 nSepRows * (infoPtr->nBitmapHeight + 1) +
1629 BOTTOM_BORDER;
1630 #endif
1632 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1634 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1638 static INT
1639 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1641 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1642 TBUTTON_INFO *btnPtr;
1643 INT i;
1645 btnPtr = infoPtr->buttons;
1646 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1647 if (btnPtr->fsState & TBSTATE_HIDDEN)
1648 continue;
1650 if (btnPtr->fsStyle & BTNS_SEP) {
1651 if (PtInRect (&btnPtr->rect, *lpPt)) {
1652 TRACE(" ON SEPARATOR %d!\n", i);
1653 return -i;
1656 else {
1657 if (PtInRect (&btnPtr->rect, *lpPt)) {
1658 TRACE(" ON BUTTON %d!\n", i);
1659 return i;
1664 TRACE(" NOWHERE!\n");
1665 return -1;
1669 static INT
1670 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1672 TBUTTON_INFO *btnPtr;
1673 INT i;
1675 if (CommandIsIndex) {
1676 TRACE("command is really index command=%d\n", idCommand);
1677 if (idCommand >= infoPtr->nNumButtons) return -1;
1678 return idCommand;
1680 btnPtr = infoPtr->buttons;
1681 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1682 if (btnPtr->idCommand == idCommand) {
1683 TRACE("command=%d index=%d\n", idCommand, i);
1684 return i;
1687 TRACE("no index found for command=%d\n", idCommand);
1688 return -1;
1692 static INT
1693 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1695 TBUTTON_INFO *btnPtr;
1696 INT nRunIndex;
1698 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1699 return -1;
1701 /* check index button */
1702 btnPtr = &infoPtr->buttons[nIndex];
1703 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1704 if (btnPtr->fsState & TBSTATE_CHECKED)
1705 return nIndex;
1708 /* check previous buttons */
1709 nRunIndex = nIndex - 1;
1710 while (nRunIndex >= 0) {
1711 btnPtr = &infoPtr->buttons[nRunIndex];
1712 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1713 if (btnPtr->fsState & TBSTATE_CHECKED)
1714 return nRunIndex;
1716 else
1717 break;
1718 nRunIndex--;
1721 /* check next buttons */
1722 nRunIndex = nIndex + 1;
1723 while (nRunIndex < infoPtr->nNumButtons) {
1724 btnPtr = &infoPtr->buttons[nRunIndex];
1725 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1726 if (btnPtr->fsState & TBSTATE_CHECKED)
1727 return nRunIndex;
1729 else
1730 break;
1731 nRunIndex++;
1734 return -1;
1738 static VOID
1739 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1740 WPARAM wParam, LPARAM lParam)
1742 MSG msg;
1744 msg.hwnd = hwndMsg;
1745 msg.message = uMsg;
1746 msg.wParam = wParam;
1747 msg.lParam = lParam;
1748 msg.time = GetMessageTime ();
1749 msg.pt.x = LOWORD(GetMessagePos ());
1750 msg.pt.y = HIWORD(GetMessagePos ());
1752 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1756 /***********************************************************************
1757 * TOOLBAR_CustomizeDialogProc
1758 * This function implements the toolbar customization dialog.
1760 static INT_PTR CALLBACK
1761 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1763 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongA (hwnd, DWL_USER);
1764 PCUSTOMBUTTON btnInfo;
1765 NMTOOLBARA nmtb;
1766 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1768 switch (uMsg)
1770 case WM_INITDIALOG:
1771 custInfo = (PCUSTDLG_INFO)lParam;
1772 SetWindowLongA (hwnd, DWL_USER, (DWORD)custInfo);
1774 if (custInfo)
1776 WCHAR Buffer[256];
1777 int i = 0;
1778 int index;
1780 infoPtr = custInfo->tbInfo;
1782 /* send TBN_QUERYINSERT notification */
1783 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1785 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1786 return FALSE;
1788 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
1789 nmtb.iItem = (int)hwnd;
1790 /* Send TBN_INITCUSTOMIZE notification */
1791 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
1792 TBNRF_HIDEHELP)
1794 TRACE("TBNRF_HIDEHELP requested\n");
1795 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
1798 /* add items to 'toolbar buttons' list and check if removable */
1799 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1801 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1802 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1803 btnInfo->btn.fsStyle = BTNS_SEP;
1804 btnInfo->bVirtual = FALSE;
1805 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1807 /* send TBN_QUERYDELETE notification */
1808 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
1810 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1811 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1814 /* insert separator button into 'available buttons' list */
1815 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1816 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1817 btnInfo->btn.fsStyle = BTNS_SEP;
1818 btnInfo->bVirtual = FALSE;
1819 btnInfo->bRemovable = TRUE;
1820 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1821 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1822 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1824 /* insert all buttons into dsa */
1825 for (i = 0;; i++)
1827 /* send TBN_GETBUTTONINFO notification */
1828 NMTOOLBARW nmtb;
1829 nmtb.iItem = i;
1830 nmtb.pszText = Buffer;
1831 nmtb.cchText = 256;
1833 /* Clear previous button's text */
1834 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
1836 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
1837 break;
1839 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
1840 nmtb.tbButton.fsStyle, i,
1841 nmtb.tbButton.idCommand,
1842 nmtb.tbButton.iString,
1843 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
1844 : "");
1846 /* insert button into the apropriate list */
1847 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1848 if (index == -1)
1850 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1851 btnInfo->bVirtual = FALSE;
1852 btnInfo->bRemovable = TRUE;
1854 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1855 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX,
1856 LB_SETITEMDATA, index, (LPARAM)btnInfo);
1858 else
1860 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd,
1861 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1864 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1865 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
1867 if (lstrlenW(nmtb.pszText))
1868 lstrcpyW(btnInfo->text, nmtb.pszText);
1869 else if (nmtb.tbButton.iString >= 0 &&
1870 nmtb.tbButton.iString < infoPtr->nNumStrings)
1872 lstrcpyW(btnInfo->text,
1873 infoPtr->strings[nmtb.tbButton.iString]);
1878 /* select first item in the 'available' list */
1879 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1881 /* append 'virtual' separator button to the 'toolbar buttons' list */
1882 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1883 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1884 btnInfo->btn.fsStyle = BTNS_SEP;
1885 btnInfo->bVirtual = TRUE;
1886 btnInfo->bRemovable = FALSE;
1887 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1888 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1889 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1891 /* select last item in the 'toolbar' list */
1892 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1893 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1895 /* set focus and disable buttons */
1896 PostMessageA (hwnd, WM_USER, 0, 0);
1898 return TRUE;
1900 case WM_USER:
1901 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1902 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1903 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1904 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1905 return TRUE;
1907 case WM_CLOSE:
1908 EndDialog(hwnd, FALSE);
1909 return TRUE;
1911 case WM_COMMAND:
1912 switch (LOWORD(wParam))
1914 case IDC_TOOLBARBTN_LBOX:
1915 if (HIWORD(wParam) == LBN_SELCHANGE)
1917 PCUSTOMBUTTON btnInfo;
1918 NMTOOLBARA nmtb;
1919 int count;
1920 int index;
1922 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1923 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1925 /* send TBN_QUERYINSERT notification */
1926 nmtb.iItem = index;
1927 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1928 TBN_QUERYINSERT);
1930 /* get list box item */
1931 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1933 if (index == (count - 1))
1935 /* last item (virtual separator) */
1936 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1937 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1939 else if (index == (count - 2))
1941 /* second last item (last non-virtual item) */
1942 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1943 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1945 else if (index == 0)
1947 /* first item */
1948 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1949 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1951 else
1953 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1954 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1957 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1959 break;
1961 case IDC_MOVEUP_BTN:
1963 PCUSTOMBUTTON btnInfo;
1964 int index;
1965 int count;
1967 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1968 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1969 TRACE("Move up: index %d\n", index);
1971 /* send TBN_QUERYINSERT notification */
1972 nmtb.iItem = index;
1974 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1975 TBN_QUERYINSERT))
1977 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1979 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1980 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1981 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1982 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1984 if (index <= 1)
1985 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1986 else if (index >= (count - 3))
1987 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1989 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1990 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1993 break;
1995 case IDC_MOVEDN_BTN: /* move down */
1997 PCUSTOMBUTTON btnInfo;
1998 int index;
1999 int count;
2001 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2002 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2003 TRACE("Move up: index %d\n", index);
2005 /* send TBN_QUERYINSERT notification */
2006 nmtb.iItem = index;
2007 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2008 TBN_QUERYINSERT))
2010 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2012 /* move button down */
2013 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2014 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
2015 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
2016 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
2018 if (index == 0)
2019 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2020 else if (index >= (count - 3))
2021 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2023 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2024 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
2027 break;
2029 case IDC_REMOVE_BTN: /* remove button */
2031 PCUSTOMBUTTON btnInfo;
2032 int index;
2034 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2036 if (LB_ERR == index)
2037 break;
2039 TRACE("Remove: index %d\n", index);
2041 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX,
2042 LB_GETITEMDATA, index, 0);
2044 /* send TBN_QUERYDELETE notification */
2045 if (TOOLBAR_IsButtonRemovable(infoPtr, index, btnInfo))
2047 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2048 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2049 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
2051 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2053 /* insert into 'available button' list */
2054 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2056 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
2057 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2059 else
2060 Free (btnInfo);
2063 break;
2064 case IDC_HELP_BTN:
2065 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2066 break;
2067 case IDC_RESET_BTN:
2068 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2069 break;
2071 case IDOK: /* Add button */
2073 int index;
2074 int count;
2076 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2077 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2078 TRACE("Add: index %d\n", index);
2080 /* send TBN_QUERYINSERT notification */
2081 nmtb.iItem = index;
2082 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2083 TBN_QUERYINSERT))
2085 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
2087 if (index != 0)
2089 /* remove from 'available buttons' list */
2090 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
2091 if (index == count-1)
2092 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2093 else
2094 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
2096 else
2098 PCUSTOMBUTTON btnNew;
2100 /* duplicate 'separator' button */
2101 btnNew = (PCUSTOMBUTTON)Alloc (sizeof(CUSTOMBUTTON));
2102 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2103 btnInfo = btnNew;
2106 /* insert into 'toolbar button' list */
2107 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2108 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
2109 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2111 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
2114 break;
2116 case IDCANCEL:
2117 EndDialog(hwnd, FALSE);
2118 break;
2120 return TRUE;
2122 case WM_DESTROY:
2124 int count;
2125 int i;
2127 /* delete items from 'toolbar buttons' listbox*/
2128 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2129 for (i = 0; i < count; i++)
2131 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2132 Free(btnInfo);
2133 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2135 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2138 /* delete items from 'available buttons' listbox*/
2139 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2140 for (i = 0; i < count; i++)
2142 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2143 Free(btnInfo);
2144 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2146 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2148 return TRUE;
2150 case WM_DRAWITEM:
2151 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2153 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2154 DWORD dwStyle = GetWindowLongA (infoPtr->hwndSelf, GWL_STYLE);
2155 RECT rcButton;
2156 RECT rcText;
2157 HPEN hPen, hOldPen;
2158 HBRUSH hOldBrush;
2159 COLORREF oldText = 0;
2160 COLORREF oldBk = 0;
2162 /* get item data */
2163 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2164 if (btnInfo == NULL)
2166 FIXME("btnInfo invalid!\n");
2167 return TRUE;
2170 /* set colors and select objects */
2171 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2172 if (btnInfo->bVirtual)
2173 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2174 else
2175 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2176 hPen = CreatePen( PS_SOLID, 1,
2177 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2178 hOldPen = SelectObject (lpdis->hDC, hPen );
2179 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2181 /* fill background rectangle */
2182 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2183 lpdis->rcItem.right, lpdis->rcItem.bottom);
2185 /* calculate button and text rectangles */
2186 CopyRect (&rcButton, &lpdis->rcItem);
2187 InflateRect (&rcButton, -1, -1);
2188 CopyRect (&rcText, &rcButton);
2189 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2190 rcText.left = rcButton.right + 2;
2192 /* draw focus rectangle */
2193 if (lpdis->itemState & ODS_FOCUS)
2194 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2196 /* draw button */
2197 if (!(dwStyle & TBSTYLE_FLAT))
2198 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2200 /* draw image and text */
2201 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2202 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2203 btnInfo->btn.iBitmap));
2204 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2205 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2207 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2208 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2210 /* delete objects and reset colors */
2211 SelectObject (lpdis->hDC, hOldBrush);
2212 SelectObject (lpdis->hDC, hOldPen);
2213 SetBkColor (lpdis->hDC, oldBk);
2214 SetTextColor (lpdis->hDC, oldText);
2215 DeleteObject( hPen );
2216 return TRUE;
2218 return FALSE;
2220 case WM_MEASUREITEM:
2221 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2223 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2225 if (custInfo && custInfo->tbInfo)
2226 lpmis->itemHeight = custInfo->tbInfo->nBitmapHeight + 8;
2227 else
2228 lpmis->itemHeight = 15 + 8; /* default height */
2230 return TRUE;
2232 return FALSE;
2234 default:
2235 return FALSE;
2240 /***********************************************************************
2241 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2244 static LRESULT
2245 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2247 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2248 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2249 INT nIndex = 0, nButtons, nCount;
2250 HBITMAP hbmLoad;
2251 HIMAGELIST himlDef;
2253 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2254 if (!lpAddBmp)
2255 return -1;
2257 if (lpAddBmp->hInst == HINST_COMMCTRL)
2259 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2260 nButtons = 15;
2261 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2262 nButtons = 13;
2263 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2264 nButtons = 5;
2265 else
2266 return -1;
2268 TRACE ("adding %d internal bitmaps!\n", nButtons);
2270 /* Windows resize all the buttons to the size of a newly added standard image */
2271 if (lpAddBmp->nID & 1)
2273 /* large icons */
2274 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2275 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2277 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2278 MAKELPARAM((WORD)24, (WORD)24));
2279 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2280 MAKELPARAM((WORD)31, (WORD)30));
2282 else
2284 /* small icons */
2285 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2286 MAKELPARAM((WORD)16, (WORD)16));
2287 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2288 MAKELPARAM((WORD)22, (WORD)22));
2291 TOOLBAR_CalcToolbar (hwnd);
2293 else
2295 nButtons = (INT)wParam;
2296 if (nButtons <= 0)
2297 return -1;
2299 TRACE ("adding %d bitmaps!\n", nButtons);
2302 if (!infoPtr->cimlDef) {
2303 /* create new default image list */
2304 TRACE ("creating default image list!\n");
2306 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2307 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2308 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2309 infoPtr->himlInt = himlDef;
2311 else {
2312 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2315 if (!himlDef) {
2316 WARN("No default image list available\n");
2317 return -1;
2320 nCount = ImageList_GetImageCount(himlDef);
2322 /* Add bitmaps to the default image list */
2323 if (lpAddBmp->hInst == NULL)
2325 BITMAP bmp;
2326 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2327 HDC hdcImage, hdcBitmap;
2329 /* copy the bitmap before adding it so that the user's bitmap
2330 * doesn't get modified.
2332 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2334 hdcImage = CreateCompatibleDC(0);
2335 hdcBitmap = CreateCompatibleDC(0);
2337 /* create new bitmap */
2338 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2339 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2340 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2342 /* Copy the user's image */
2343 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2344 hdcBitmap, 0, 0, SRCCOPY);
2346 SelectObject (hdcImage, hOldBitmapLoad);
2347 SelectObject (hdcBitmap, hOldBitmapBitmap);
2348 DeleteDC (hdcImage);
2349 DeleteDC (hdcBitmap);
2351 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2352 DeleteObject (hbmLoad);
2354 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2356 /* Add system bitmaps */
2357 switch (lpAddBmp->nID)
2359 case IDB_STD_SMALL_COLOR:
2360 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2361 MAKEINTRESOURCEA(IDB_STD_SMALL));
2362 nIndex = ImageList_AddMasked (himlDef,
2363 hbmLoad, comctl32_color.clrBtnFace);
2364 DeleteObject (hbmLoad);
2365 break;
2367 case IDB_STD_LARGE_COLOR:
2368 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2369 MAKEINTRESOURCEA(IDB_STD_LARGE));
2370 nIndex = ImageList_AddMasked (himlDef,
2371 hbmLoad, comctl32_color.clrBtnFace);
2372 DeleteObject (hbmLoad);
2373 break;
2375 case IDB_VIEW_SMALL_COLOR:
2376 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2377 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2378 nIndex = ImageList_AddMasked (himlDef,
2379 hbmLoad, comctl32_color.clrBtnFace);
2380 DeleteObject (hbmLoad);
2381 break;
2383 case IDB_VIEW_LARGE_COLOR:
2384 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2385 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2386 nIndex = ImageList_AddMasked (himlDef,
2387 hbmLoad, comctl32_color.clrBtnFace);
2388 DeleteObject (hbmLoad);
2389 break;
2391 case IDB_HIST_SMALL_COLOR:
2392 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2393 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2394 nIndex = ImageList_AddMasked (himlDef,
2395 hbmLoad, comctl32_color.clrBtnFace);
2396 DeleteObject (hbmLoad);
2397 break;
2399 case IDB_HIST_LARGE_COLOR:
2400 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2401 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2402 nIndex = ImageList_AddMasked (himlDef,
2403 hbmLoad, comctl32_color.clrBtnFace);
2404 DeleteObject (hbmLoad);
2405 break;
2407 default:
2408 nIndex = ImageList_GetImageCount (himlDef);
2409 ERR ("invalid imagelist!\n");
2410 break;
2413 else
2415 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2416 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2417 DeleteObject (hbmLoad);
2420 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2422 if (infoPtr->nNumBitmapInfos == 0)
2424 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2426 else
2428 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2429 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2430 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2433 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2434 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2435 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2437 infoPtr->nNumBitmapInfos++;
2438 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2440 if (nIndex != -1)
2442 INT imagecount = ImageList_GetImageCount(himlDef);
2444 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2446 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",
2447 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2448 infoPtr->nNumBitmaps+nButtons,imagecount);
2450 infoPtr->nNumBitmaps = imagecount;
2452 else
2453 infoPtr->nNumBitmaps += nButtons;
2456 InvalidateRect(hwnd, NULL, TRUE);
2458 return nIndex;
2462 static LRESULT
2463 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2465 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2466 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2467 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2469 TRACE("adding %d buttons!\n", wParam);
2471 nAddButtons = (UINT)wParam;
2472 nOldButtons = infoPtr->nNumButtons;
2473 nNewButtons = nOldButtons + nAddButtons;
2475 if (infoPtr->nNumButtons == 0) {
2476 infoPtr->buttons =
2477 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2479 else {
2480 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2481 infoPtr->buttons =
2482 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2483 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2484 nOldButtons * sizeof(TBUTTON_INFO));
2485 Free (oldButtons);
2488 infoPtr->nNumButtons = nNewButtons;
2490 /* insert new button data */
2491 for (nCount = 0; nCount < nAddButtons; nCount++) {
2492 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2493 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2494 btnPtr->idCommand = lpTbb[nCount].idCommand;
2495 btnPtr->fsState = lpTbb[nCount].fsState;
2496 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2497 btnPtr->dwData = lpTbb[nCount].dwData;
2498 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2499 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2500 else
2501 btnPtr->iString = lpTbb[nCount].iString;
2502 btnPtr->bHot = FALSE;
2504 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2505 TTTOOLINFOA ti;
2507 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2508 ti.cbSize = sizeof (TTTOOLINFOA);
2509 ti.hwnd = hwnd;
2510 ti.uId = btnPtr->idCommand;
2511 ti.hinst = 0;
2512 ti.lpszText = LPSTR_TEXTCALLBACKA;
2514 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2515 0, (LPARAM)&ti);
2519 TOOLBAR_CalcToolbar (hwnd);
2521 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2523 InvalidateRect(hwnd, NULL, TRUE);
2525 return TRUE;
2529 static LRESULT
2530 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2532 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2533 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2534 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2536 TRACE("adding %d buttons!\n", wParam);
2538 nAddButtons = (UINT)wParam;
2539 nOldButtons = infoPtr->nNumButtons;
2540 nNewButtons = nOldButtons + nAddButtons;
2542 if (infoPtr->nNumButtons == 0) {
2543 infoPtr->buttons =
2544 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2546 else {
2547 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2548 infoPtr->buttons =
2549 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2550 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2551 nOldButtons * sizeof(TBUTTON_INFO));
2552 Free (oldButtons);
2555 infoPtr->nNumButtons = nNewButtons;
2557 /* insert new button data */
2558 for (nCount = 0; nCount < nAddButtons; nCount++) {
2559 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2560 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2561 btnPtr->idCommand = lpTbb[nCount].idCommand;
2562 btnPtr->fsState = lpTbb[nCount].fsState;
2563 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2564 btnPtr->dwData = lpTbb[nCount].dwData;
2565 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2566 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2567 else
2568 btnPtr->iString = lpTbb[nCount].iString;
2569 btnPtr->bHot = FALSE;
2571 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2572 TTTOOLINFOW ti;
2574 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2575 ti.cbSize = sizeof (TTTOOLINFOW);
2576 ti.hwnd = hwnd;
2577 ti.uId = btnPtr->idCommand;
2578 ti.hinst = 0;
2579 ti.lpszText = LPSTR_TEXTCALLBACKW;
2580 ti.lParam = lParam;
2582 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2583 0, (LPARAM)&ti);
2587 TOOLBAR_CalcToolbar (hwnd);
2589 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2591 InvalidateRect(hwnd, NULL, TRUE);
2593 return TRUE;
2597 static LRESULT
2598 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2600 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2601 INT nIndex;
2603 if ((wParam) && (HIWORD(lParam) == 0)) {
2604 char szString[256];
2605 INT len;
2606 TRACE("adding string from resource!\n");
2608 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2609 szString, 256);
2611 TRACE("len=%d \"%s\"\n", len, szString);
2612 nIndex = infoPtr->nNumStrings;
2613 if (infoPtr->nNumStrings == 0) {
2614 infoPtr->strings =
2615 Alloc (sizeof(LPWSTR));
2617 else {
2618 LPWSTR *oldStrings = infoPtr->strings;
2619 infoPtr->strings =
2620 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2621 memcpy (&infoPtr->strings[0], &oldStrings[0],
2622 sizeof(LPWSTR) * infoPtr->nNumStrings);
2623 Free (oldStrings);
2626 /*Alloc zeros out the allocated memory*/
2627 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2628 infoPtr->nNumStrings++;
2630 else {
2631 LPSTR p = (LPSTR)lParam;
2632 INT len;
2634 if (p == NULL)
2635 return -1;
2636 TRACE("adding string(s) from array!\n");
2638 nIndex = infoPtr->nNumStrings;
2639 while (*p) {
2640 len = strlen (p);
2641 TRACE("len=%d \"%s\"\n", len, p);
2643 if (infoPtr->nNumStrings == 0) {
2644 infoPtr->strings =
2645 Alloc (sizeof(LPWSTR));
2647 else {
2648 LPWSTR *oldStrings = infoPtr->strings;
2649 infoPtr->strings =
2650 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2651 memcpy (&infoPtr->strings[0], &oldStrings[0],
2652 sizeof(LPWSTR) * infoPtr->nNumStrings);
2653 Free (oldStrings);
2656 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2657 infoPtr->nNumStrings++;
2659 p += (len+1);
2663 return nIndex;
2667 static LRESULT
2668 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2670 #define MAX_RESOURCE_STRING_LENGTH 512
2671 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2672 INT nIndex;
2674 if ((wParam) && (HIWORD(lParam) == 0)) {
2675 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2676 INT len;
2677 TRACE("adding string from resource!\n");
2679 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2680 szString, MAX_RESOURCE_STRING_LENGTH);
2682 TRACE("len=%d %s\n", len, debugstr_w(szString));
2683 TRACE("First char: 0x%x\n", *szString);
2684 if (szString[0] == L'|')
2686 PWSTR p = szString + 1;
2688 nIndex = infoPtr->nNumStrings;
2689 while (*p != L'|' && *p != L'\0') {
2690 PWSTR np;
2692 if (infoPtr->nNumStrings == 0) {
2693 infoPtr->strings = Alloc (sizeof(LPWSTR));
2695 else
2697 LPWSTR *oldStrings = infoPtr->strings;
2698 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2699 memcpy(&infoPtr->strings[0], &oldStrings[0],
2700 sizeof(LPWSTR) * infoPtr->nNumStrings);
2701 Free(oldStrings);
2704 np=strchrW (p, '|');
2705 if (np!=NULL) {
2706 len = np - p;
2707 np++;
2708 } else {
2709 len = strlenW(p);
2710 np = p + len;
2712 TRACE("len=%d %s\n", len, debugstr_w(p));
2713 infoPtr->strings[infoPtr->nNumStrings] =
2714 Alloc (sizeof(WCHAR)*(len+1));
2715 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2716 infoPtr->nNumStrings++;
2718 p = np;
2721 else
2723 nIndex = infoPtr->nNumStrings;
2724 if (infoPtr->nNumStrings == 0) {
2725 infoPtr->strings =
2726 Alloc (sizeof(LPWSTR));
2728 else {
2729 LPWSTR *oldStrings = infoPtr->strings;
2730 infoPtr->strings =
2731 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2732 memcpy (&infoPtr->strings[0], &oldStrings[0],
2733 sizeof(LPWSTR) * infoPtr->nNumStrings);
2734 Free (oldStrings);
2737 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2738 infoPtr->nNumStrings++;
2741 else {
2742 LPWSTR p = (LPWSTR)lParam;
2743 INT len;
2745 if (p == NULL)
2746 return -1;
2747 TRACE("adding string(s) from array!\n");
2748 nIndex = infoPtr->nNumStrings;
2749 while (*p) {
2750 len = strlenW (p);
2752 TRACE("len=%d %s\n", len, debugstr_w(p));
2753 if (infoPtr->nNumStrings == 0) {
2754 infoPtr->strings =
2755 Alloc (sizeof(LPWSTR));
2757 else {
2758 LPWSTR *oldStrings = infoPtr->strings;
2759 infoPtr->strings =
2760 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2761 memcpy (&infoPtr->strings[0], &oldStrings[0],
2762 sizeof(LPWSTR) * infoPtr->nNumStrings);
2763 Free (oldStrings);
2766 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2767 infoPtr->nNumStrings++;
2769 p += (len+1);
2773 return nIndex;
2777 static LRESULT
2778 TOOLBAR_AutoSize (HWND hwnd)
2780 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2781 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2782 RECT parent_rect;
2783 RECT window_rect;
2784 HWND parent;
2785 INT x, y;
2786 INT cx, cy;
2787 UINT uPosFlags = SWP_NOZORDER;
2789 TRACE("resize forced, style=%lx!\n", dwStyle);
2791 parent = GetParent (hwnd);
2792 GetClientRect(parent, &parent_rect);
2794 x = parent_rect.left;
2795 y = parent_rect.top;
2797 /* FIXME: we should be able to early out if nothing */
2798 /* has changed with nWidth != parent_rect width */
2800 if (dwStyle & CCS_NORESIZE) {
2801 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2802 cx = 0;
2803 cy = 0;
2804 TOOLBAR_CalcToolbar (hwnd);
2806 else {
2807 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2808 TOOLBAR_CalcToolbar (hwnd);
2809 InvalidateRect( hwnd, NULL, TRUE );
2810 cy = infoPtr->nHeight;
2811 cx = infoPtr->nWidth;
2813 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
2814 GetWindowRect(hwnd, &window_rect);
2815 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2816 y = window_rect.top;
2818 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
2819 GetWindowRect(hwnd, &window_rect);
2820 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
2824 if (dwStyle & CCS_NOPARENTALIGN)
2825 uPosFlags |= SWP_NOMOVE;
2827 if (!(dwStyle & CCS_NODIVIDER))
2828 cy += GetSystemMetrics(SM_CYEDGE);
2830 if (dwStyle & WS_BORDER)
2832 x = y = 1;
2833 cy += GetSystemMetrics(SM_CYEDGE);
2834 cx += GetSystemMetrics(SM_CYEDGE);
2837 infoPtr->bAutoSize = TRUE;
2838 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
2839 /* The following line makes sure that the infoPtr->bAutoSize is turned off
2840 * after the setwindowpos calls */
2841 infoPtr->bAutoSize = FALSE;
2843 return 0;
2847 static LRESULT
2848 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2850 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2852 return infoPtr->nNumButtons;
2856 static LRESULT
2857 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2859 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2861 if (infoPtr == NULL) {
2862 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2863 ERR("infoPtr == NULL!\n");
2864 return 0;
2867 infoPtr->dwStructSize = (DWORD)wParam;
2869 return 0;
2873 static LRESULT
2874 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2876 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2877 TBUTTON_INFO *btnPtr;
2878 INT nIndex;
2880 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
2882 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2883 if (nIndex == -1)
2884 return FALSE;
2886 btnPtr = &infoPtr->buttons[nIndex];
2887 btnPtr->iBitmap = LOWORD(lParam);
2889 /* we HAVE to erase the background, the new bitmap could be */
2890 /* transparent */
2891 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2893 return TRUE;
2897 static LRESULT
2898 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2900 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2901 TBUTTON_INFO *btnPtr;
2902 INT nIndex;
2903 INT nOldIndex = -1;
2904 BOOL bChecked = FALSE;
2906 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2908 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
2910 if (nIndex == -1)
2911 return FALSE;
2913 btnPtr = &infoPtr->buttons[nIndex];
2915 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2917 if (LOWORD(lParam) == FALSE)
2918 btnPtr->fsState &= ~TBSTATE_CHECKED;
2919 else {
2920 if (btnPtr->fsStyle & BTNS_GROUP) {
2921 nOldIndex =
2922 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2923 if (nOldIndex == nIndex)
2924 return 0;
2925 if (nOldIndex != -1)
2926 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2928 btnPtr->fsState |= TBSTATE_CHECKED;
2931 if( bChecked != LOWORD(lParam) )
2933 if (nOldIndex != -1)
2934 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
2935 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2938 /* FIXME: Send a WM_NOTIFY?? */
2940 return TRUE;
2944 static LRESULT
2945 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2947 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2949 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2953 static LRESULT
2954 TOOLBAR_Customize (HWND hwnd)
2956 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2957 CUSTDLG_INFO custInfo;
2958 LRESULT ret;
2959 LPCVOID template;
2960 HRSRC hRes;
2961 NMHDR nmhdr;
2963 custInfo.tbInfo = infoPtr;
2964 custInfo.tbHwnd = hwnd;
2966 /* send TBN_BEGINADJUST notification */
2967 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2968 TBN_BEGINADJUST);
2970 if (!(hRes = FindResourceA (COMCTL32_hModule,
2971 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2972 (LPSTR)RT_DIALOG)))
2973 return FALSE;
2975 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2976 return FALSE;
2978 ret = DialogBoxIndirectParamA ((HINSTANCE)GetWindowLongA(hwnd, GWL_HINSTANCE),
2979 (LPDLGTEMPLATEA)template,
2980 hwnd,
2981 TOOLBAR_CustomizeDialogProc,
2982 (LPARAM)&custInfo);
2984 /* send TBN_ENDADJUST notification */
2985 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2986 TBN_ENDADJUST);
2988 return ret;
2992 static LRESULT
2993 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2995 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2996 INT nIndex = (INT)wParam;
2998 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2999 return FALSE;
3001 if ((infoPtr->hwndToolTip) &&
3002 !(infoPtr->buttons[nIndex].fsStyle & BTNS_SEP)) {
3003 TTTOOLINFOA ti;
3005 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3006 ti.cbSize = sizeof (TTTOOLINFOA);
3007 ti.hwnd = hwnd;
3008 ti.uId = infoPtr->buttons[nIndex].idCommand;
3010 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
3013 if (infoPtr->nNumButtons == 1) {
3014 TRACE(" simple delete!\n");
3015 Free (infoPtr->buttons);
3016 infoPtr->buttons = NULL;
3017 infoPtr->nNumButtons = 0;
3019 else {
3020 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3021 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3023 infoPtr->nNumButtons--;
3024 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3025 if (nIndex > 0) {
3026 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3027 nIndex * sizeof(TBUTTON_INFO));
3030 if (nIndex < infoPtr->nNumButtons) {
3031 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3032 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3035 Free (oldButtons);
3038 TOOLBAR_CalcToolbar (hwnd);
3040 InvalidateRect (hwnd, NULL, TRUE);
3042 return TRUE;
3046 static LRESULT
3047 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3049 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3050 TBUTTON_INFO *btnPtr;
3051 INT nIndex;
3052 DWORD bState;
3054 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3056 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3058 if (nIndex == -1)
3059 return FALSE;
3061 btnPtr = &infoPtr->buttons[nIndex];
3063 bState = btnPtr->fsState & TBSTATE_ENABLED;
3065 /* update the toolbar button state */
3066 if(LOWORD(lParam) == FALSE) {
3067 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3068 } else {
3069 btnPtr->fsState |= TBSTATE_ENABLED;
3072 /* redraw the button only if the state of the button changed */
3073 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3074 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3076 return TRUE;
3080 static inline LRESULT
3081 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3083 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3085 return infoPtr->bAnchor;
3089 static LRESULT
3090 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3092 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3093 INT nIndex;
3095 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3096 if (nIndex == -1)
3097 return -1;
3099 return infoPtr->buttons[nIndex].iBitmap;
3103 static inline LRESULT
3104 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3106 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3110 static LRESULT
3111 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3113 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3114 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3115 INT nIndex = (INT)wParam;
3116 TBUTTON_INFO *btnPtr;
3118 if (infoPtr == NULL)
3119 return FALSE;
3121 if (lpTbb == NULL)
3122 return FALSE;
3124 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3125 return FALSE;
3127 btnPtr = &infoPtr->buttons[nIndex];
3128 lpTbb->iBitmap = btnPtr->iBitmap;
3129 lpTbb->idCommand = btnPtr->idCommand;
3130 lpTbb->fsState = btnPtr->fsState;
3131 lpTbb->fsStyle = btnPtr->fsStyle;
3132 lpTbb->bReserved[0] = 0;
3133 lpTbb->bReserved[1] = 0;
3134 lpTbb->dwData = btnPtr->dwData;
3135 lpTbb->iString = btnPtr->iString;
3137 return TRUE;
3141 static LRESULT
3142 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3144 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3145 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3146 TBUTTON_INFO *btnPtr;
3147 INT nIndex;
3149 if (infoPtr == NULL)
3150 return -1;
3151 if (lpTbInfo == NULL)
3152 return -1;
3153 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3154 return -1;
3156 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3157 lpTbInfo->dwMask & 0x80000000);
3158 if (nIndex == -1)
3159 return -1;
3161 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3163 if (lpTbInfo->dwMask & TBIF_COMMAND)
3164 lpTbInfo->idCommand = btnPtr->idCommand;
3165 if (lpTbInfo->dwMask & TBIF_IMAGE)
3166 lpTbInfo->iImage = btnPtr->iBitmap;
3167 if (lpTbInfo->dwMask & TBIF_LPARAM)
3168 lpTbInfo->lParam = btnPtr->dwData;
3169 if (lpTbInfo->dwMask & TBIF_SIZE)
3170 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3171 if (lpTbInfo->dwMask & TBIF_STATE)
3172 lpTbInfo->fsState = btnPtr->fsState;
3173 if (lpTbInfo->dwMask & TBIF_STYLE)
3174 lpTbInfo->fsStyle = btnPtr->fsStyle;
3175 if (lpTbInfo->dwMask & TBIF_TEXT) {
3176 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3177 can't use TOOLBAR_GetText here */
3178 LPWSTR lpText;
3179 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3180 lpText = (LPWSTR)btnPtr->iString;
3181 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3182 } else
3183 lpTbInfo->pszText[0] = '\0';
3185 return nIndex;
3189 static LRESULT
3190 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3192 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3193 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3194 TBUTTON_INFO *btnPtr;
3195 INT nIndex;
3197 if (infoPtr == NULL)
3198 return -1;
3199 if (lpTbInfo == NULL)
3200 return -1;
3201 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3202 return -1;
3204 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3205 lpTbInfo->dwMask & 0x80000000);
3206 if (nIndex == -1)
3207 return -1;
3209 btnPtr = &infoPtr->buttons[nIndex];
3211 if(!btnPtr)
3212 return -1;
3214 if (lpTbInfo->dwMask & TBIF_COMMAND)
3215 lpTbInfo->idCommand = btnPtr->idCommand;
3216 if (lpTbInfo->dwMask & TBIF_IMAGE)
3217 lpTbInfo->iImage = btnPtr->iBitmap;
3218 if (lpTbInfo->dwMask & TBIF_LPARAM)
3219 lpTbInfo->lParam = btnPtr->dwData;
3220 if (lpTbInfo->dwMask & TBIF_SIZE)
3221 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3222 if (lpTbInfo->dwMask & TBIF_STATE)
3223 lpTbInfo->fsState = btnPtr->fsState;
3224 if (lpTbInfo->dwMask & TBIF_STYLE)
3225 lpTbInfo->fsStyle = btnPtr->fsStyle;
3226 if (lpTbInfo->dwMask & TBIF_TEXT) {
3227 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3228 can't use TOOLBAR_GetText here */
3229 LPWSTR lpText;
3230 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3231 lpText = (LPWSTR)btnPtr->iString;
3232 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3233 } else
3234 lpTbInfo->pszText[0] = '\0';
3237 return nIndex;
3241 static LRESULT
3242 TOOLBAR_GetButtonSize (HWND hwnd)
3244 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3246 if (infoPtr->nNumButtons > 0)
3247 return MAKELONG((WORD)infoPtr->nButtonWidth,
3248 (WORD)infoPtr->nButtonHeight);
3249 else
3250 return MAKELONG(8,7);
3254 static LRESULT
3255 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3257 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3258 INT nIndex;
3259 LPWSTR lpText;
3261 if (lParam == 0)
3262 return -1;
3264 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3265 if (nIndex == -1)
3266 return -1;
3268 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3270 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3271 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3275 static LRESULT
3276 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3278 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3279 INT nIndex;
3280 LPWSTR lpText;
3282 if (lParam == 0)
3283 return -1;
3285 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3286 if (nIndex == -1)
3287 return -1;
3289 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3291 strcpyW ((LPWSTR)lParam, lpText);
3293 return strlenW (lpText);
3297 static LRESULT
3298 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3300 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3301 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3302 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3306 inline static LRESULT
3307 TOOLBAR_GetExtendedStyle (HWND hwnd)
3309 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3311 TRACE("\n");
3313 return infoPtr->dwExStyle;
3317 static LRESULT
3318 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3320 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3321 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3322 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3326 static LRESULT
3327 TOOLBAR_GetHotItem (HWND hwnd)
3329 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3331 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
3332 return -1;
3334 if (infoPtr->nHotItem < 0)
3335 return -1;
3337 return (LRESULT)infoPtr->nHotItem;
3341 static LRESULT
3342 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3344 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3345 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3346 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3350 /* << TOOLBAR_GetInsertMark >> */
3351 /* << TOOLBAR_GetInsertMarkColor >> */
3354 static LRESULT
3355 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3357 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3358 TBUTTON_INFO *btnPtr;
3359 LPRECT lpRect;
3360 INT nIndex;
3362 if (infoPtr == NULL)
3363 return FALSE;
3364 nIndex = (INT)wParam;
3365 btnPtr = &infoPtr->buttons[nIndex];
3366 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3367 return FALSE;
3368 lpRect = (LPRECT)lParam;
3369 if (lpRect == NULL)
3370 return FALSE;
3371 if (btnPtr->fsState & TBSTATE_HIDDEN)
3372 return FALSE;
3374 lpRect->left = btnPtr->rect.left;
3375 lpRect->right = btnPtr->rect.right;
3376 lpRect->bottom = btnPtr->rect.bottom;
3377 lpRect->top = btnPtr->rect.top;
3379 return TRUE;
3383 static LRESULT
3384 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3386 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3387 LPSIZE lpSize = (LPSIZE)lParam;
3389 if (lpSize == NULL)
3390 return FALSE;
3392 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3393 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3395 TRACE("maximum size %ld x %ld\n",
3396 infoPtr->rcBound.right - infoPtr->rcBound.left,
3397 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3399 return TRUE;
3403 /* << TOOLBAR_GetObject >> */
3406 static LRESULT
3407 TOOLBAR_GetPadding (HWND hwnd)
3409 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3410 DWORD oldPad;
3412 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3413 return (LRESULT) oldPad;
3417 static LRESULT
3418 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3420 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3421 TBUTTON_INFO *btnPtr;
3422 LPRECT lpRect;
3423 INT nIndex;
3425 if (infoPtr == NULL)
3426 return FALSE;
3427 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3428 btnPtr = &infoPtr->buttons[nIndex];
3429 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3430 return FALSE;
3431 lpRect = (LPRECT)lParam;
3432 if (lpRect == NULL)
3433 return FALSE;
3435 lpRect->left = btnPtr->rect.left;
3436 lpRect->right = btnPtr->rect.right;
3437 lpRect->bottom = btnPtr->rect.bottom;
3438 lpRect->top = btnPtr->rect.top;
3440 return TRUE;
3444 static LRESULT
3445 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3447 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3449 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
3450 return infoPtr->nRows;
3451 else
3452 return 1;
3456 static LRESULT
3457 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3459 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3460 INT nIndex;
3462 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3463 if (nIndex == -1)
3464 return -1;
3466 return infoPtr->buttons[nIndex].fsState;
3470 static LRESULT
3471 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3473 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3474 INT nIndex;
3476 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3477 if (nIndex == -1)
3478 return -1;
3480 return infoPtr->buttons[nIndex].fsStyle;
3484 static LRESULT
3485 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3487 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3489 if (infoPtr == NULL)
3490 return 0;
3492 return infoPtr->nMaxTextRows;
3496 static LRESULT
3497 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3499 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3501 if (infoPtr == NULL)
3502 return 0;
3503 return (LRESULT)infoPtr->hwndToolTip;
3507 static LRESULT
3508 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3510 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3512 TRACE("%s hwnd=%p stub!\n",
3513 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3515 return infoPtr->bUnicode;
3519 inline static LRESULT
3520 TOOLBAR_GetVersion (HWND hwnd)
3522 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3523 return infoPtr->iVersion;
3527 static LRESULT
3528 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3530 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3531 TBUTTON_INFO *btnPtr;
3532 INT nIndex;
3534 TRACE("\n");
3536 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3537 if (nIndex == -1)
3538 return FALSE;
3540 btnPtr = &infoPtr->buttons[nIndex];
3541 if (LOWORD(lParam) == FALSE)
3542 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3543 else
3544 btnPtr->fsState |= TBSTATE_HIDDEN;
3546 TOOLBAR_CalcToolbar (hwnd);
3548 InvalidateRect (hwnd, NULL, TRUE);
3550 return TRUE;
3554 inline static LRESULT
3555 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3557 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3561 static LRESULT
3562 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3564 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3565 TBUTTON_INFO *btnPtr;
3566 INT nIndex;
3567 DWORD oldState;
3569 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3570 if (nIndex == -1)
3571 return FALSE;
3573 btnPtr = &infoPtr->buttons[nIndex];
3574 oldState = btnPtr->fsState;
3575 if (LOWORD(lParam) == FALSE)
3576 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3577 else
3578 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3580 if(oldState != btnPtr->fsState)
3581 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3583 return TRUE;
3587 static LRESULT
3588 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3590 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3591 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3592 INT nIndex = (INT)wParam;
3593 TBUTTON_INFO *oldButtons;
3595 if (lpTbb == NULL)
3596 return FALSE;
3598 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3600 if (nIndex == -1) {
3601 /* EPP: this seems to be an undocumented call (from my IE4)
3602 * I assume in that case that:
3603 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3604 * - index of insertion is at the end of existing buttons
3605 * I only see this happen with nIndex == -1, but it could have a special
3606 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3608 nIndex = infoPtr->nNumButtons;
3610 } else if (nIndex < 0)
3611 return FALSE;
3613 /* If the string passed is not an index, assume address of string
3614 and do our own AddString */
3615 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3616 LPSTR ptr;
3617 INT len;
3619 TRACE("string %s passed instead of index, adding string\n",
3620 debugstr_a((LPSTR)lpTbb->iString));
3621 len = strlen((LPSTR)lpTbb->iString) + 2;
3622 ptr = Alloc(len);
3623 strcpy(ptr, (LPSTR)lpTbb->iString);
3624 ptr[len - 1] = 0; /* ended by two '\0' */
3625 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3626 Free(ptr);
3629 TRACE("inserting button index=%d\n", nIndex);
3630 if (nIndex > infoPtr->nNumButtons) {
3631 nIndex = infoPtr->nNumButtons;
3632 TRACE("adjust index=%d\n", nIndex);
3635 oldButtons = infoPtr->buttons;
3636 infoPtr->nNumButtons++;
3637 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3638 /* pre insert copy */
3639 if (nIndex > 0) {
3640 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3641 nIndex * sizeof(TBUTTON_INFO));
3644 /* insert new button */
3645 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3646 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3647 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3648 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3649 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3650 /* if passed string and not index, then add string */
3651 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3652 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3654 else
3655 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3657 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3658 TTTOOLINFOA ti;
3660 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3661 ti.cbSize = sizeof (TTTOOLINFOA);
3662 ti.hwnd = hwnd;
3663 ti.uId = lpTbb->idCommand;
3664 ti.hinst = 0;
3665 ti.lpszText = LPSTR_TEXTCALLBACKA;
3667 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3668 0, (LPARAM)&ti);
3671 /* post insert copy */
3672 if (nIndex < infoPtr->nNumButtons - 1) {
3673 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3674 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3677 Free (oldButtons);
3679 TOOLBAR_CalcToolbar (hwnd);
3681 InvalidateRect (hwnd, NULL, TRUE);
3683 return TRUE;
3687 static LRESULT
3688 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3690 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3691 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3692 INT nIndex = (INT)wParam;
3693 TBUTTON_INFO *oldButtons;
3695 if (lpTbb == NULL)
3696 return FALSE;
3698 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3700 if (nIndex == -1) {
3701 /* EPP: this seems to be an undocumented call (from my IE4)
3702 * I assume in that case that:
3703 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3704 * - index of insertion is at the end of existing buttons
3705 * I only see this happen with nIndex == -1, but it could have a special
3706 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3708 nIndex = infoPtr->nNumButtons;
3710 } else if (nIndex < 0)
3711 return FALSE;
3713 /* If the string passed is not an index, assume address of string
3714 and do our own AddString */
3715 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3716 LPWSTR ptr;
3717 INT len;
3719 TRACE("string %s passed instead of index, adding string\n",
3720 debugstr_w((LPWSTR)lpTbb->iString));
3721 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3722 ptr = Alloc(len*sizeof(WCHAR));
3723 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3724 ptr[len - 1] = 0; /* ended by two '\0' */
3725 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3726 Free(ptr);
3729 TRACE("inserting button index=%d\n", nIndex);
3730 if (nIndex > infoPtr->nNumButtons) {
3731 nIndex = infoPtr->nNumButtons;
3732 TRACE("adjust index=%d\n", nIndex);
3735 oldButtons = infoPtr->buttons;
3736 infoPtr->nNumButtons++;
3737 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3738 /* pre insert copy */
3739 if (nIndex > 0) {
3740 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3741 nIndex * sizeof(TBUTTON_INFO));
3744 /* insert new button */
3745 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3746 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3747 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3748 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3749 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3750 /* if passed string and not index, then add string */
3751 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3752 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3754 else
3755 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3757 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3758 TTTOOLINFOW ti;
3760 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3761 ti.cbSize = sizeof (TTTOOLINFOW);
3762 ti.hwnd = hwnd;
3763 ti.uId = lpTbb->idCommand;
3764 ti.hinst = 0;
3765 ti.lpszText = LPSTR_TEXTCALLBACKW;
3767 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3768 0, (LPARAM)&ti);
3771 /* post insert copy */
3772 if (nIndex < infoPtr->nNumButtons - 1) {
3773 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3774 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3777 Free (oldButtons);
3779 TOOLBAR_CalcToolbar (hwnd);
3781 InvalidateRect (hwnd, NULL, TRUE);
3783 return TRUE;
3787 /* << TOOLBAR_InsertMarkHitTest >> */
3790 static LRESULT
3791 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3793 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3794 INT nIndex;
3796 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3797 if (nIndex == -1)
3798 return FALSE;
3800 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3804 static LRESULT
3805 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3807 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3808 INT nIndex;
3810 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3811 if (nIndex == -1)
3812 return FALSE;
3814 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3818 static LRESULT
3819 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3821 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3822 INT nIndex;
3824 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3825 if (nIndex == -1)
3826 return TRUE;
3828 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3832 static LRESULT
3833 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3835 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3836 INT nIndex;
3838 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3839 if (nIndex == -1)
3840 return FALSE;
3842 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3846 static LRESULT
3847 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3849 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3850 INT nIndex;
3852 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3853 if (nIndex == -1)
3854 return FALSE;
3856 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3860 static LRESULT
3861 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3863 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3864 INT nIndex;
3866 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3867 if (nIndex == -1)
3868 return FALSE;
3870 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3874 static LRESULT
3875 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3877 TBADDBITMAP tbab;
3878 tbab.hInst = (HINSTANCE)lParam;
3879 tbab.nID = (UINT_PTR)wParam;
3881 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3883 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3887 static LRESULT
3888 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3890 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3891 WCHAR wAccel = (WCHAR)wParam;
3892 UINT* pIDButton = (UINT*)lParam;
3893 WCHAR wszAccel[] = {'&',wAccel,0};
3894 int i;
3896 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3897 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3899 for (i = 0; i < infoPtr->nNumButtons; i++)
3901 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3902 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3903 !(btnPtr->fsState & TBSTATE_HIDDEN))
3905 int iLen = strlenW(wszAccel);
3906 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3908 if (!lpszStr)
3909 continue;
3911 while (*lpszStr)
3913 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3915 lpszStr += 2;
3916 continue;
3918 if (!strncmpiW(lpszStr, wszAccel, iLen))
3920 *pIDButton = btnPtr->idCommand;
3921 return TRUE;
3923 lpszStr++;
3927 return FALSE;
3931 static LRESULT
3932 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3934 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3935 INT nIndex;
3937 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3939 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3940 if (nIndex == -1)
3941 return FALSE;
3943 if (LOWORD(lParam))
3944 infoPtr->buttons[nIndex].fsState |= TBSTATE_MARKED;
3945 else
3946 infoPtr->buttons[nIndex].fsState &= ~TBSTATE_MARKED;
3948 return TRUE;
3951 /* << TOOLBAR_MoveButton >> */
3954 static LRESULT
3955 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3957 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3958 TBUTTON_INFO *btnPtr;
3959 INT nIndex;
3960 DWORD oldState;
3962 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3963 if (nIndex == -1)
3964 return FALSE;
3966 btnPtr = &infoPtr->buttons[nIndex];
3967 oldState = btnPtr->fsState;
3968 if (LOWORD(lParam) == FALSE)
3969 btnPtr->fsState &= ~TBSTATE_PRESSED;
3970 else
3971 btnPtr->fsState |= TBSTATE_PRESSED;
3973 if(oldState != btnPtr->fsState)
3974 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3976 return TRUE;
3979 /* FIXME: there might still be some confusion her between number of buttons
3980 * and number of bitmaps */
3981 static LRESULT
3982 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3984 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3985 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
3986 HBITMAP hBitmap;
3987 int i = 0, nOldButtons = 0, pos = 0;
3988 int nOldBitmaps, nNewBitmaps;
3989 HIMAGELIST himlDef = 0;
3991 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
3992 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
3993 lpReplace->nButtons);
3995 if (lpReplace->hInstOld == HINST_COMMCTRL)
3997 FIXME("changing standard bitmaps not implemented\n");
3998 return FALSE;
4000 else if (lpReplace->hInstOld != 0)
4002 FIXME("resources not in the current module not implemented\n");
4003 return FALSE;
4005 else
4007 hBitmap = (HBITMAP) lpReplace->nIDNew;
4010 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4011 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4012 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4013 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4014 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4016 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4017 nOldButtons = tbi->nButtons;
4018 tbi->nButtons = lpReplace->nButtons;
4019 tbi->hInst = lpReplace->hInstNew;
4020 tbi->nID = lpReplace->nIDNew;
4021 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4022 break;
4024 pos += tbi->nButtons;
4027 if (nOldButtons == 0)
4029 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4030 return FALSE;
4033 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4034 nOldBitmaps = ImageList_GetImageCount(himlDef);
4036 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4038 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4039 ImageList_Remove(himlDef, i);
4042 BITMAP bmp;
4043 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4044 HDC hdcImage, hdcBitmap;
4046 /* copy the bitmap before adding it so that the user's bitmap
4047 * doesn't get modified.
4049 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4051 hdcImage = CreateCompatibleDC(0);
4052 hdcBitmap = CreateCompatibleDC(0);
4054 /* create new bitmap */
4055 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4056 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4057 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4059 /* Copy the user's image */
4060 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4061 hdcBitmap, 0, 0, SRCCOPY);
4063 SelectObject (hdcImage, hOldBitmapLoad);
4064 SelectObject (hdcBitmap, hOldBitmapBitmap);
4065 DeleteDC (hdcImage);
4066 DeleteDC (hdcBitmap);
4068 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4069 nNewBitmaps = ImageList_GetImageCount(himlDef);
4070 DeleteObject (hbmLoad);
4073 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4075 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4076 pos, nOldBitmaps, nNewBitmaps);
4078 InvalidateRect(hwnd, NULL, TRUE);
4080 return TRUE;
4083 static LRESULT
4084 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4086 #if 0
4087 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4088 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
4090 if (lpSave == NULL) return 0;
4092 if ((BOOL)wParam) {
4093 /* save toolbar information */
4094 FIXME("save to \"%s\" \"%s\"\n",
4095 lpSave->pszSubKey, lpSave->pszValueName);
4099 else {
4100 /* restore toolbar information */
4102 FIXME("restore from \"%s\" \"%s\"\n",
4103 lpSave->pszSubKey, lpSave->pszValueName);
4107 #endif
4109 return 0;
4113 static LRESULT
4114 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4116 #if 0
4117 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4118 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
4120 if (lpSave == NULL)
4121 return 0;
4123 if ((BOOL)wParam) {
4124 /* save toolbar information */
4125 FIXME("save to \"%s\" \"%s\"\n",
4126 lpSave->pszSubKey, lpSave->pszValueName);
4130 else {
4131 /* restore toolbar information */
4133 FIXME("restore from \"%s\" \"%s\"\n",
4134 lpSave->pszSubKey, lpSave->pszValueName);
4138 #endif
4140 return 0;
4144 static LRESULT
4145 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4147 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4148 BOOL bOldAnchor = infoPtr->bAnchor;
4150 infoPtr->bAnchor = (BOOL)wParam;
4152 return (LRESULT)bOldAnchor;
4156 static LRESULT
4157 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4159 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4160 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4162 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4163 return FALSE;
4165 if (infoPtr->nNumButtons > 0)
4166 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4167 infoPtr->nNumButtons,
4168 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4169 LOWORD(lParam), HIWORD(lParam));
4171 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4172 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4175 /* uses image list internals directly */
4176 if (himlDef) {
4177 himlDef->cx = infoPtr->nBitmapWidth;
4178 himlDef->cy = infoPtr->nBitmapHeight;
4181 return TRUE;
4185 static LRESULT
4186 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4188 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4189 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4190 TBUTTON_INFO *btnPtr;
4191 INT nIndex;
4193 if (lptbbi == NULL)
4194 return FALSE;
4195 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4196 return FALSE;
4198 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4199 lptbbi->dwMask & 0x80000000);
4200 if (nIndex == -1)
4201 return FALSE;
4203 btnPtr = &infoPtr->buttons[nIndex];
4204 if (lptbbi->dwMask & TBIF_COMMAND)
4205 btnPtr->idCommand = lptbbi->idCommand;
4206 if (lptbbi->dwMask & TBIF_IMAGE)
4207 btnPtr->iBitmap = lptbbi->iImage;
4208 if (lptbbi->dwMask & TBIF_LPARAM)
4209 btnPtr->dwData = lptbbi->lParam;
4210 /* if (lptbbi->dwMask & TBIF_SIZE) */
4211 /* btnPtr->cx = lptbbi->cx; */
4212 if (lptbbi->dwMask & TBIF_STATE)
4213 btnPtr->fsState = lptbbi->fsState;
4214 if (lptbbi->dwMask & TBIF_STYLE)
4215 btnPtr->fsStyle = lptbbi->fsStyle;
4217 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4218 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4219 /* iString is index, zero it to make Str_SetPtr succeed */
4220 btnPtr->iString=0;
4222 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4224 return TRUE;
4228 static LRESULT
4229 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4231 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4232 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4233 TBUTTON_INFO *btnPtr;
4234 INT nIndex;
4236 if (lptbbi == NULL)
4237 return FALSE;
4238 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4239 return FALSE;
4241 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4242 lptbbi->dwMask & 0x80000000);
4243 if (nIndex == -1)
4244 return FALSE;
4246 btnPtr = &infoPtr->buttons[nIndex];
4247 if (lptbbi->dwMask & TBIF_COMMAND)
4248 btnPtr->idCommand = lptbbi->idCommand;
4249 if (lptbbi->dwMask & TBIF_IMAGE)
4250 btnPtr->iBitmap = lptbbi->iImage;
4251 if (lptbbi->dwMask & TBIF_LPARAM)
4252 btnPtr->dwData = lptbbi->lParam;
4253 /* if (lptbbi->dwMask & TBIF_SIZE) */
4254 /* btnPtr->cx = lptbbi->cx; */
4255 if (lptbbi->dwMask & TBIF_STATE)
4256 btnPtr->fsState = lptbbi->fsState;
4257 if (lptbbi->dwMask & TBIF_STYLE)
4258 btnPtr->fsStyle = lptbbi->fsStyle;
4260 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4261 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4262 /* iString is index, zero it to make Str_SetPtr succeed */
4263 btnPtr->iString=0;
4264 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4266 return TRUE;
4270 static LRESULT
4271 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4273 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4274 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4276 if ((cx < 0) || (cy < 0))
4278 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4279 return FALSE;
4282 /* The documentation claims you can only change the button size before
4283 * any button has been added. But this is wrong.
4284 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4285 * it to the toolbar, and it checks that the return value is nonzero - mjm
4286 * Further testing shows that we must actually perform the change too.
4289 * The documentation also does not mention that if 0 is supplied for
4290 * either size, the system changes it to the default of 24 wide and
4291 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4293 infoPtr->nButtonWidth = (cx) ? cx : 24;
4294 infoPtr->nButtonHeight = (cy) ? cy : 22;
4295 return TRUE;
4299 static LRESULT
4300 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4302 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4304 if (infoPtr == NULL) {
4305 TRACE("Toolbar not initialized yet?????\n");
4306 return FALSE;
4309 /* if setting to current values, ignore */
4310 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4311 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4312 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4313 infoPtr->cxMin, infoPtr->cxMax);
4314 return TRUE;
4317 /* save new values */
4318 infoPtr->cxMin = (INT)LOWORD(lParam);
4319 infoPtr->cxMax = (INT)HIWORD(lParam);
4321 /* if both values are 0 then we are done */
4322 if (lParam == 0) {
4323 TRACE("setting both min and max to 0, norecalc\n");
4324 return TRUE;
4327 /* otherwise we need to recalc the toolbar and in some cases
4328 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4329 which doesn't actually draw - GA). */
4330 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4331 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4333 TOOLBAR_CalcToolbar (hwnd);
4335 InvalidateRect (hwnd, NULL, TRUE);
4337 return TRUE;
4341 static LRESULT
4342 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4344 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4345 INT nIndex = (INT)wParam;
4347 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4348 return FALSE;
4350 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4352 if (infoPtr->hwndToolTip) {
4354 FIXME("change tool tip!\n");
4358 return TRUE;
4362 static LRESULT
4363 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4365 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4366 HIMAGELIST himl = (HIMAGELIST)lParam;
4367 HIMAGELIST himlTemp;
4368 INT id = 0;
4370 if (infoPtr->iVersion >= 5)
4371 id = wParam;
4373 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4374 &infoPtr->cimlDis, himl, id);
4376 /* FIXME: redraw ? */
4378 return (LRESULT)himlTemp;
4382 static LRESULT
4383 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4385 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4386 DWORD dwTemp;
4388 dwTemp = infoPtr->dwDTFlags;
4389 infoPtr->dwDTFlags =
4390 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4392 return (LRESULT)dwTemp;
4395 /* This function differs a bit from what MSDN says it does:
4396 * 1. lParam contains extended style flags to OR with current style
4397 * (MSDN isn't clear on the OR bit)
4398 * 2. wParam appears to contain extended style flags to be reset
4399 * (MSDN says that this parameter is reserved)
4401 static LRESULT
4402 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4404 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4405 DWORD dwTemp;
4407 dwTemp = infoPtr->dwExStyle;
4408 infoPtr->dwExStyle &= ~wParam;
4409 infoPtr->dwExStyle |= (DWORD)lParam;
4411 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4413 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4414 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4415 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4417 TOOLBAR_CalcToolbar (hwnd);
4419 TOOLBAR_AutoSize(hwnd);
4421 InvalidateRect(hwnd, NULL, TRUE);
4423 return (LRESULT)dwTemp;
4427 static LRESULT
4428 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4430 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4431 HIMAGELIST himlTemp;
4432 HIMAGELIST himl = (HIMAGELIST)lParam;
4433 INT id = 0;
4435 if (infoPtr->iVersion >= 5)
4436 id = wParam;
4438 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4440 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4441 &infoPtr->cimlHot, himl, id);
4443 /* FIXME: redraw ? */
4445 return (LRESULT)himlTemp;
4449 /* Makes previous hot button no longer hot, makes the specified
4450 * button hot and sends appropriate notifications. dwReason is one or
4451 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4452 * NOTE 1: this function does not validate nHit
4453 * NOTE 2: the name of this function is completely made up and
4454 * not based on any documentation from Microsoft. */
4455 static void
4456 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4458 if (infoPtr->nHotItem != nHit)
4460 NMTBHOTITEM nmhotitem;
4461 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4462 LRESULT no_highlight;
4464 /* Remove the effect of an old hot button if the button was
4465 drawn with the hot button effect */
4466 if(infoPtr->nHotItem >= 0)
4468 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4469 oldBtnPtr->bHot = FALSE;
4472 infoPtr->nHotItem = nHit;
4474 /* It's not a separator or in nowhere. It's a hot button. */
4475 if (nHit >= 0)
4476 btnPtr = &infoPtr->buttons[nHit];
4478 nmhotitem.dwFlags = dwReason;
4479 if (oldBtnPtr)
4480 nmhotitem.idOld = oldBtnPtr->idCommand;
4481 else
4482 nmhotitem.dwFlags |= HICF_ENTERING;
4483 if (btnPtr)
4484 nmhotitem.idNew = btnPtr->idCommand;
4485 else
4486 nmhotitem.dwFlags |= HICF_LEAVING;
4488 no_highlight = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4490 /* now invalidate the old and new buttons so they will be painted */
4491 if (oldBtnPtr)
4492 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4493 if (btnPtr && !no_highlight)
4495 btnPtr->bHot = TRUE;
4496 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4501 static LRESULT
4502 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4504 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4505 INT nOldHotItem = infoPtr->nHotItem;
4507 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4508 wParam = -2;
4510 if (GetWindowLongW(hwnd, GWL_STYLE) & TBSTYLE_FLAT)
4511 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4513 if (nOldHotItem < 0)
4514 return -1;
4516 return (LRESULT)nOldHotItem;
4520 static LRESULT
4521 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4523 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4524 HIMAGELIST himlTemp;
4525 HIMAGELIST himl = (HIMAGELIST)lParam;
4526 INT i, id = 0;
4528 if (infoPtr->iVersion >= 5)
4529 id = wParam;
4531 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4532 &infoPtr->cimlDef, himl, id);
4534 infoPtr->nNumBitmaps = 0;
4535 for (i = 0; i < infoPtr->cimlDef; i++)
4536 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4538 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4539 &infoPtr->nBitmapHeight);
4540 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4541 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4542 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4544 InvalidateRect(hwnd, NULL, TRUE);
4546 return (LRESULT)himlTemp;
4550 static LRESULT
4551 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4553 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4555 infoPtr->nIndent = (INT)wParam;
4557 TRACE("\n");
4559 /* process only on indent changing */
4560 if(infoPtr->nIndent != (INT)wParam)
4562 infoPtr->nIndent = (INT)wParam;
4563 TOOLBAR_CalcToolbar (hwnd);
4564 InvalidateRect(hwnd, NULL, FALSE);
4567 return TRUE;
4571 /* << TOOLBAR_SetInsertMark >> */
4574 static LRESULT
4575 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4577 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4579 infoPtr->clrInsertMark = (COLORREF)lParam;
4581 /* FIXME : redraw ??*/
4583 return 0;
4587 static LRESULT
4588 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4590 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4592 if (infoPtr == NULL)
4593 return FALSE;
4595 infoPtr->nMaxTextRows = (INT)wParam;
4597 TOOLBAR_CalcToolbar(hwnd);
4598 return TRUE;
4602 /* MSDN gives slightly wrong info on padding.
4603 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4604 * 2. It is not used to create a blank area between the edge of the button
4605 * and the text or image if TBSTYLE_LIST is set. It is used to control
4606 * the gap between the image and text.
4607 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4608 * to control the bottom and right borders [with the border being
4609 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4610 * is shared evenly on both sides of the button.
4612 static LRESULT
4613 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4615 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4616 DWORD oldPad;
4618 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4619 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4620 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4621 TRACE("cx=%ld, cy=%ld\n",
4622 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4623 return (LRESULT) oldPad;
4627 static LRESULT
4628 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4630 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4631 HWND hwndOldNotify;
4633 TRACE("\n");
4635 if (infoPtr == NULL)
4636 return 0;
4637 hwndOldNotify = infoPtr->hwndNotify;
4638 infoPtr->hwndNotify = (HWND)wParam;
4640 return (LRESULT)hwndOldNotify;
4644 static LRESULT
4645 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4647 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4648 LPRECT lprc = (LPRECT)lParam;
4650 TRACE("\n");
4652 if (LOWORD(wParam) > 1) {
4653 FIXME("multiple rows not supported!\n");
4656 if(infoPtr->nRows != LOWORD(wParam))
4658 infoPtr->nRows = LOWORD(wParam);
4660 /* recalculate toolbar */
4661 TOOLBAR_CalcToolbar (hwnd);
4663 /* repaint toolbar */
4664 InvalidateRect(hwnd, NULL, TRUE);
4667 /* return bounding rectangle */
4668 if (lprc) {
4669 lprc->left = infoPtr->rcBound.left;
4670 lprc->right = infoPtr->rcBound.right;
4671 lprc->top = infoPtr->rcBound.top;
4672 lprc->bottom = infoPtr->rcBound.bottom;
4675 return 0;
4679 static LRESULT
4680 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4682 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4683 TBUTTON_INFO *btnPtr;
4684 INT nIndex;
4686 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4687 if (nIndex == -1)
4688 return FALSE;
4690 btnPtr = &infoPtr->buttons[nIndex];
4692 /* if hidden state has changed the invalidate entire window and recalc */
4693 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4694 btnPtr->fsState = LOWORD(lParam);
4695 TOOLBAR_CalcToolbar (hwnd);
4696 InvalidateRect(hwnd, 0, TRUE);
4697 return TRUE;
4700 /* process state changing if current state doesn't match new state */
4701 if(btnPtr->fsState != LOWORD(lParam))
4703 btnPtr->fsState = LOWORD(lParam);
4704 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4707 return TRUE;
4711 static LRESULT
4712 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4714 SetWindowLongW(hwnd, GWL_STYLE, lParam);
4716 return TRUE;
4720 inline static LRESULT
4721 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4723 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4725 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
4727 if (infoPtr == NULL)
4728 return 0;
4729 infoPtr->hwndToolTip = (HWND)wParam;
4730 return 0;
4734 static LRESULT
4735 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4737 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4738 BOOL bTemp;
4740 TRACE("%s hwnd=%p stub!\n",
4741 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4743 bTemp = infoPtr->bUnicode;
4744 infoPtr->bUnicode = (BOOL)wParam;
4746 return bTemp;
4750 static LRESULT
4751 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4753 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4755 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4756 comctl32_color.clrBtnHighlight :
4757 infoPtr->clrBtnHighlight;
4758 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4759 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4760 return 1;
4764 static LRESULT
4765 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4767 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4769 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4770 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4771 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4773 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4774 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4775 InvalidateRect(hwnd, NULL, TRUE);
4776 return 0;
4780 static LRESULT
4781 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4783 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4784 INT iOldVersion = infoPtr->iVersion;
4786 infoPtr->iVersion = iVersion;
4788 if (infoPtr->iVersion >= 5)
4789 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
4791 return iOldVersion;
4795 static LRESULT
4796 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4798 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4799 WORD iString = HIWORD(wParam);
4800 WORD buffersize = LOWORD(wParam);
4801 LPSTR str = (LPSTR)lParam;
4802 LRESULT ret = -1;
4804 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
4806 if (iString < infoPtr->nNumStrings)
4808 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
4810 TRACE("returning %s\n", debugstr_a(str));
4812 else
4813 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4815 return ret;
4819 static LRESULT
4820 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4822 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4823 WORD iString = HIWORD(wParam);
4824 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
4825 LPWSTR str = (LPWSTR)lParam;
4826 LRESULT ret = -1;
4828 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
4830 if (iString < infoPtr->nNumStrings)
4832 len = min(len, strlenW(infoPtr->strings[iString]));
4833 ret = (len+1)*sizeof(WCHAR);
4834 memcpy(str, infoPtr->strings[iString], ret);
4835 str[len] = '\0';
4837 TRACE("returning %s\n", debugstr_w(str));
4839 else
4840 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4842 return ret;
4845 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
4846 * is the maximum size of the toolbar? */
4847 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
4849 SIZE * pSize = (SIZE*)lParam;
4850 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
4851 return 0;
4855 /* UNDOCUMENTED MESSAGE: This is an extended version of the
4856 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
4857 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
4858 * sends). */
4859 static LRESULT
4860 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
4862 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4863 INT nOldHotItem = infoPtr->nHotItem;
4865 TRACE("old item=%d, new item=%d, flags=%08lx\n",
4866 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
4868 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4869 wParam = -1;
4871 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
4873 GetFocus();
4875 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
4878 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
4879 * which controls the amount of spacing between the image and the text
4880 * of buttons for TBSTYLE_LIST toolbars. */
4881 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
4883 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4885 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
4887 if (lParam != 0)
4888 FIXME("lParam = 0x%08lx. Please report\n", lParam);
4890 infoPtr->iListGap = (INT)wParam;
4892 TOOLBAR_CalcToolbar(hwnd);
4893 InvalidateRect(hwnd, NULL, TRUE);
4895 return 0;
4898 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
4899 * of image lists associated with the various states. */
4900 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
4902 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4904 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
4906 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
4909 static LRESULT
4910 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
4912 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4913 LPSIZE lpsize = (LPSIZE)lParam;
4915 if (lpsize == NULL)
4916 return FALSE;
4919 * Testing shows the following:
4920 * wParam = 0 adjust cx value
4921 * = 1 set cy value to max size.
4922 * lParam pointer to SIZE structure
4925 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
4926 wParam, lParam, lpsize->cx, lpsize->cy);
4928 switch(wParam) {
4929 case 0:
4930 if (lpsize->cx == -1) {
4931 /* **** this is wrong, native measures each button and sets it */
4932 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4934 else if(HIWORD(lpsize->cx)) {
4935 RECT rc;
4936 HWND hwndParent = GetParent(hwnd);
4938 GetWindowRect(hwnd, &rc);
4939 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
4940 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
4941 rc.left, rc.top, rc.right, rc.bottom);
4942 lpsize->cx = max(rc.right-rc.left,
4943 infoPtr->rcBound.right - infoPtr->rcBound.left);
4945 else {
4946 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4948 break;
4949 case 1:
4950 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
4951 /* lpsize->cy = infoPtr->nHeight; */
4952 break;
4953 default:
4954 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
4955 wParam);
4956 return 0;
4958 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
4959 lpsize->cx, lpsize->cy);
4960 return 1;
4963 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
4965 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
4967 InvalidateRect(hwnd, NULL, TRUE);
4968 return 1;
4972 static LRESULT
4973 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
4975 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4976 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4977 LOGFONTA logFont;
4979 TRACE("hwnd = %p\n", hwnd);
4981 /* initialize info structure */
4982 infoPtr->nButtonHeight = 22;
4983 infoPtr->nButtonWidth = 24;
4984 infoPtr->nBitmapHeight = 15;
4985 infoPtr->nBitmapWidth = 16;
4987 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
4988 infoPtr->nMaxTextRows = 1;
4989 infoPtr->cxMin = -1;
4990 infoPtr->cxMax = -1;
4991 infoPtr->nNumBitmaps = 0;
4992 infoPtr->nNumStrings = 0;
4994 infoPtr->bCaptured = FALSE;
4995 infoPtr->bUnicode = IsWindowUnicode (hwnd);
4996 infoPtr->nButtonDown = -1;
4997 infoPtr->nOldHit = -1;
4998 infoPtr->nHotItem = -1;
4999 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5000 infoPtr->bTransparent = (dwStyle & TBSTYLE_TRANSPARENT);
5001 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5002 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
5003 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5004 infoPtr->iVersion = 0;
5005 infoPtr->hwndSelf = hwnd;
5006 infoPtr->bDoRedraw = TRUE;
5007 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5008 infoPtr->clrBtnShadow = CLR_DEFAULT;
5009 /* not sure where the +1 comes from, but this comes to the same value
5010 * as native so this is probably correct */
5011 infoPtr->szPadding.cx = 2*(GetSystemMetrics(SM_CXEDGE)+OFFSET_X) + 1;
5012 infoPtr->szPadding.cy = 2*(GetSystemMetrics(SM_CYEDGE)+OFFSET_Y);
5013 infoPtr->iListGap = infoPtr->szPadding.cx / 2;
5014 GetClientRect(hwnd, &infoPtr->client_rect);
5015 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
5017 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5018 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
5020 if (dwStyle & TBSTYLE_TOOLTIPS) {
5021 /* Create tooltip control */
5022 infoPtr->hwndToolTip =
5023 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
5024 CW_USEDEFAULT, CW_USEDEFAULT,
5025 CW_USEDEFAULT, CW_USEDEFAULT,
5026 hwnd, 0, 0, 0);
5028 /* Send NM_TOOLTIPSCREATED notification */
5029 if (infoPtr->hwndToolTip) {
5030 NMTOOLTIPSCREATED nmttc;
5032 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5034 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
5035 NM_TOOLTIPSCREATED);
5039 TOOLBAR_CheckStyle (hwnd, dwStyle);
5041 TOOLBAR_CalcToolbar(hwnd);
5043 return 0;
5047 static LRESULT
5048 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5050 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5052 /* delete tooltip control */
5053 if (infoPtr->hwndToolTip)
5054 DestroyWindow (infoPtr->hwndToolTip);
5056 /* delete temporary buffer for tooltip text */
5057 if (infoPtr->pszTooltipText)
5058 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5060 /* delete button data */
5061 if (infoPtr->buttons)
5062 Free (infoPtr->buttons);
5064 /* delete strings */
5065 if (infoPtr->strings) {
5066 INT i;
5067 for (i = 0; i < infoPtr->nNumStrings; i++)
5068 if (infoPtr->strings[i])
5069 Free (infoPtr->strings[i]);
5071 Free (infoPtr->strings);
5074 /* destroy internal image list */
5075 if (infoPtr->himlInt)
5076 ImageList_Destroy (infoPtr->himlInt);
5078 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5079 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5080 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5082 /* delete default font */
5083 if (infoPtr->hFont)
5084 DeleteObject (infoPtr->hDefaultFont);
5086 /* free toolbar info data */
5087 Free (infoPtr);
5088 SetWindowLongA (hwnd, 0, 0);
5090 return 0;
5094 static LRESULT
5095 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5097 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5098 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5099 NMTBCUSTOMDRAW tbcd;
5100 INT ret = FALSE;
5101 DWORD ntfret;
5103 if (dwStyle & TBSTYLE_CUSTOMERASE) {
5104 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5105 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5106 tbcd.nmcd.hdc = (HDC)wParam;
5107 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5108 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5110 /* FIXME: in general the return flags *can* be or'ed together */
5111 switch (infoPtr->dwBaseCustDraw)
5113 case CDRF_DODEFAULT:
5114 break;
5115 case CDRF_SKIPDEFAULT:
5116 return TRUE;
5117 default:
5118 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5119 hwnd, ntfret);
5123 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5124 * to my parent for processing.
5126 if (infoPtr->bTransparent) {
5127 POINT pt, ptorig;
5128 HDC hdc = (HDC)wParam;
5129 HWND parent;
5131 pt.x = 0;
5132 pt.y = 0;
5133 parent = GetParent(hwnd);
5134 MapWindowPoints(hwnd, parent, &pt, 1);
5135 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5136 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
5137 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5139 if (!ret)
5140 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
5142 if ((dwStyle & TBSTYLE_CUSTOMERASE) &&
5143 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5144 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5145 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5146 tbcd.nmcd.hdc = (HDC)wParam;
5147 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5148 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5149 switch (infoPtr->dwBaseCustDraw)
5151 case CDRF_DODEFAULT:
5152 break;
5153 case CDRF_SKIPDEFAULT:
5154 return TRUE;
5155 default:
5156 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5157 hwnd, ntfret);
5160 return ret;
5164 static LRESULT
5165 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5167 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5169 return (LRESULT)infoPtr->hFont;
5173 static LRESULT
5174 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5176 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5177 TBUTTON_INFO *btnPtr;
5178 POINT pt;
5179 INT nHit;
5181 pt.x = (INT)LOWORD(lParam);
5182 pt.y = (INT)HIWORD(lParam);
5183 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5185 if (nHit >= 0) {
5186 btnPtr = &infoPtr->buttons[nHit];
5187 if (!(btnPtr->fsState & TBSTATE_ENABLED))
5188 return 0;
5189 SetCapture (hwnd);
5190 infoPtr->bCaptured = TRUE;
5191 infoPtr->nButtonDown = nHit;
5193 btnPtr->fsState |= TBSTATE_PRESSED;
5195 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5197 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5198 TOOLBAR_Customize (hwnd);
5200 return 0;
5204 static LRESULT
5205 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5207 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5208 TBUTTON_INFO *btnPtr;
5209 POINT pt;
5210 INT nHit;
5211 NMTOOLBARA nmtb;
5213 if (infoPtr->hwndToolTip)
5214 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5215 WM_LBUTTONDOWN, wParam, lParam);
5217 pt.x = (INT)LOWORD(lParam);
5218 pt.y = (INT)HIWORD(lParam);
5219 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5221 btnPtr = &infoPtr->buttons[nHit];
5223 if (nHit >= 0) {
5224 RECT arrowRect;
5225 infoPtr->nOldHit = nHit;
5227 CopyRect(&arrowRect, &btnPtr->rect);
5228 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5230 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5231 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5232 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5233 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5234 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5235 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5237 LRESULT res;
5239 /* draw in pressed state */
5240 btnPtr->fsState |= TBSTATE_PRESSED;
5241 RedrawWindow(hwnd,&btnPtr->rect,0,
5242 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5244 nmtb.iItem = btnPtr->idCommand;
5245 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
5246 nmtb.cchText = 0;
5247 nmtb.pszText = 0;
5248 CopyRect(&nmtb.rcButton, &btnPtr->rect);
5249 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5250 TBN_DROPDOWN);
5251 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5253 if (res != TBDDRET_TREATPRESSED)
5255 MSG msg;
5257 /* redraw button in unpressed state */
5258 btnPtr->fsState &= ~TBSTATE_PRESSED;
5259 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5261 /* find and set hot item
5262 * NOTE: native doesn't do this, but that is a bug */
5263 GetCursorPos(&pt);
5264 ScreenToClient(hwnd, &pt);
5265 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5266 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5268 /* remove any left mouse button down messages so that we can
5269 * get a toggle effect on the button */
5270 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE))
5273 return 0;
5275 /* otherwise drop through and process as pushed */
5277 infoPtr->bCaptured = TRUE;
5278 infoPtr->nButtonDown = nHit;
5280 btnPtr->fsState |= TBSTATE_PRESSED;
5282 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5284 if (btnPtr->fsState & TBSTATE_ENABLED)
5285 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5286 UpdateWindow(hwnd);
5287 SetCapture (hwnd);
5289 /* native issues the TBN_BEGINDRAG here */
5290 nmtb.iItem = btnPtr->idCommand;
5291 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5292 nmtb.tbButton.idCommand = btnPtr->idCommand;
5293 nmtb.tbButton.fsState = btnPtr->fsState;
5294 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5295 nmtb.tbButton.dwData = btnPtr->dwData;
5296 nmtb.tbButton.iString = btnPtr->iString;
5297 nmtb.cchText = 0; /* !!! not correct */
5298 nmtb.pszText = 0; /* !!! not correct */
5299 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5300 TBN_BEGINDRAG);
5303 return 0;
5306 static LRESULT
5307 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5309 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5310 TBUTTON_INFO *btnPtr;
5311 POINT pt;
5312 INT nHit;
5313 INT nOldIndex = -1;
5314 BOOL bSendMessage = TRUE;
5315 NMHDR hdr;
5316 NMMOUSE nmmouse;
5317 NMTOOLBARA nmtb;
5319 if (infoPtr->hwndToolTip)
5320 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5321 WM_LBUTTONUP, wParam, lParam);
5323 pt.x = (INT)LOWORD(lParam);
5324 pt.y = (INT)HIWORD(lParam);
5325 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5327 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5329 if (0 <= infoPtr->nButtonDown) {
5330 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5331 btnPtr->fsState &= ~TBSTATE_PRESSED;
5333 if (btnPtr->fsStyle & BTNS_CHECK) {
5334 if (btnPtr->fsStyle & BTNS_GROUP) {
5335 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5336 nHit);
5337 if (nOldIndex == nHit)
5338 bSendMessage = FALSE;
5339 if ((nOldIndex != nHit) &&
5340 (nOldIndex != -1))
5341 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5342 btnPtr->fsState |= TBSTATE_CHECKED;
5344 else {
5345 if (btnPtr->fsState & TBSTATE_CHECKED)
5346 btnPtr->fsState &= ~TBSTATE_CHECKED;
5347 else
5348 btnPtr->fsState |= TBSTATE_CHECKED;
5352 if (nOldIndex != -1)
5353 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5356 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5357 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5358 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5360 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5361 ReleaseCapture ();
5362 infoPtr->nButtonDown = -1;
5364 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5365 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5366 NM_RELEASEDCAPTURE);
5368 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5369 * TBN_BEGINDRAG
5371 nmtb.iItem = btnPtr->idCommand;
5372 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5373 nmtb.tbButton.idCommand = btnPtr->idCommand;
5374 nmtb.tbButton.fsState = btnPtr->fsState;
5375 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5376 nmtb.tbButton.dwData = btnPtr->dwData;
5377 nmtb.tbButton.iString = btnPtr->iString;
5378 nmtb.cchText = 0; /* !!! not correct */
5379 nmtb.pszText = 0; /* !!! not correct */
5380 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5381 TBN_ENDDRAG);
5383 if (btnPtr->fsState & TBSTATE_ENABLED)
5385 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
5386 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5388 /* !!! Undocumented - toolbar at 4.71 level and above sends
5389 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
5390 * Only NM_RCLICK is documented.
5392 nmmouse.dwItemSpec = btnPtr->idCommand;
5393 nmmouse.dwItemData = btnPtr->dwData;
5394 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr, NM_CLICK);
5397 return 0;
5400 static LRESULT
5401 TOOLBAR_CaptureChanged(HWND hwnd)
5403 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5404 TBUTTON_INFO *btnPtr;
5406 infoPtr->bCaptured = FALSE;
5408 if (infoPtr->nButtonDown >= 0)
5410 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5411 btnPtr->fsState &= ~TBSTATE_PRESSED;
5413 infoPtr->nOldHit = -1;
5415 if (btnPtr->fsState & TBSTATE_ENABLED)
5416 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5418 return 0;
5421 static LRESULT
5422 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5424 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5425 TBUTTON_INFO *hotBtnPtr, *btnPtr;
5426 RECT rc1;
5428 TOOLBAR_SetHotItemEx(infoPtr, -1, HICF_MOUSE);
5430 if (infoPtr->nOldHit < 0)
5431 return TRUE;
5433 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5435 /* If the last button we were over is depressed then make it not */
5436 /* depressed and redraw it */
5437 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5439 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5441 btnPtr->fsState &= ~TBSTATE_PRESSED;
5443 rc1 = hotBtnPtr->rect;
5444 InflateRect (&rc1, 1, 1);
5445 InvalidateRect (hwnd, &rc1, TRUE);
5448 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5450 return TRUE;
5453 static LRESULT
5454 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5456 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5457 POINT pt;
5458 TRACKMOUSEEVENT trackinfo;
5459 INT nHit;
5460 TBUTTON_INFO *btnPtr;
5462 /* fill in the TRACKMOUSEEVENT struct */
5463 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5464 trackinfo.dwFlags = TME_QUERY;
5465 trackinfo.hwndTrack = hwnd;
5466 trackinfo.dwHoverTime = HOVER_DEFAULT;
5468 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5469 _TrackMouseEvent(&trackinfo);
5471 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5472 if(!(trackinfo.dwFlags & TME_LEAVE)) {
5473 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5475 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5476 /* and can properly deactivate the hot toolbar button */
5477 _TrackMouseEvent(&trackinfo);
5480 if (infoPtr->hwndToolTip)
5481 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5482 WM_MOUSEMOVE, wParam, lParam);
5484 pt.x = (INT)LOWORD(lParam);
5485 pt.y = (INT)HIWORD(lParam);
5487 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5489 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
5491 if (infoPtr->nOldHit != nHit)
5493 if (infoPtr->bCaptured)
5495 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5496 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5497 btnPtr->fsState &= ~TBSTATE_PRESSED;
5498 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5500 else if (nHit == infoPtr->nButtonDown) {
5501 btnPtr->fsState |= TBSTATE_PRESSED;
5502 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5504 infoPtr->nOldHit = nHit;
5508 return 0;
5512 inline static LRESULT
5513 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5515 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5516 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5517 /* else */
5518 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5522 inline static LRESULT
5523 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5525 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
5526 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5528 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5532 static LRESULT
5533 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5535 TOOLBAR_INFO *infoPtr;
5536 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5537 DWORD styleadd = 0;
5539 /* allocate memory for info structure */
5540 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
5541 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
5543 /* paranoid!! */
5544 infoPtr->dwStructSize = sizeof(TBBUTTON);
5545 infoPtr->nRows = 1;
5547 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5548 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
5549 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
5550 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
5553 /* native control does:
5554 * Get a lot of colors and brushes
5555 * WM_NOTIFYFORMAT
5556 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5557 * CreateFontIndirectA(adr1)
5558 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5559 * hdc = GetDC(toolbar)
5560 * GetSystemMetrics(0x48)
5561 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5562 * 0, 0, 0, 0, "MARLETT")
5563 * oldfnt = SelectObject(hdc, fnt2)
5564 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5565 * GetTextMetricsA(hdc, adr3)
5566 * SelectObject(hdc, oldfnt)
5567 * DeleteObject(fnt2)
5568 * ReleaseDC(hdc)
5569 * InvalidateRect(toolbar, 0, 1)
5570 * SetWindowLongA(toolbar, 0, addr)
5571 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5572 * WM_STYLECHANGING
5573 * CallWinEx old new
5574 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5575 * ie 2 0x4600094c 0x4600094c 0x4600894d
5576 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5577 * rebar 0x50008844 0x40008844 0x50008845
5578 * pager 0x50000844 0x40000844 0x50008845
5579 * IC35mgr 0x5400084e **nochange**
5580 * on entry to _NCCREATE 0x5400084e
5581 * rowlist 0x5400004e **nochange**
5582 * on entry to _NCCREATE 0x5400004e
5586 /* I think the code below is a bug, but it is the way that the native
5587 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5588 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5589 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5590 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5591 * Some how, the only cases of this seem to be MFC programs.
5593 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5594 * does not occur in the WM_STYLECHANGING routine.
5595 * (Guy Albertelli 9/2001)
5598 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5599 styleadd |= TBSTYLE_TRANSPARENT;
5600 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5601 styleadd |= CCS_TOP; /* default to top */
5602 SetWindowLongA (hwnd, GWL_STYLE, cs->style | styleadd);
5605 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5609 static LRESULT
5610 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5612 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5613 RECT rcWindow;
5614 HDC hdc;
5616 if (dwStyle & WS_MINIMIZE)
5617 return 0; /* Nothing to do */
5619 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5621 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5622 return 0;
5624 if (!(dwStyle & CCS_NODIVIDER))
5626 GetWindowRect (hwnd, &rcWindow);
5627 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5628 if( dwStyle & WS_BORDER )
5629 OffsetRect (&rcWindow, 1, 1);
5630 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5633 ReleaseDC( hwnd, hdc );
5635 return 0;
5639 /* handles requests from the tooltip control on what text to display */
5640 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
5642 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
5644 TRACE("button index = %d\n", index);
5646 if (infoPtr->pszTooltipText)
5648 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5649 infoPtr->pszTooltipText = NULL;
5652 if (index < 0)
5653 return 0;
5655 if (infoPtr->bNtfUnicode)
5657 WCHAR wszBuffer[INFOTIPSIZE+1];
5658 NMTBGETINFOTIPW tbgit;
5659 int len; /* in chars */
5661 wszBuffer[0] = '\0';
5662 wszBuffer[INFOTIPSIZE] = '\0';
5664 tbgit.pszText = wszBuffer;
5665 tbgit.cchTextMax = INFOTIPSIZE;
5666 tbgit.iItem = lpnmtdi->hdr.idFrom;
5667 tbgit.lParam = infoPtr->buttons[index].dwData;
5669 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
5671 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
5673 len = strlenW(tbgit.pszText);
5674 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5676 /* need to allocate temporary buffer in infoPtr as there
5677 * isn't enough space in buffer passed to us by the
5678 * tooltip control */
5679 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5680 if (infoPtr->pszTooltipText)
5682 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
5683 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5684 return 0;
5687 else if (len > 0)
5689 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
5690 return 0;
5693 else
5695 CHAR szBuffer[INFOTIPSIZE+1];
5696 NMTBGETINFOTIPA tbgit;
5697 int len; /* in chars */
5699 szBuffer[0] = '\0';
5700 szBuffer[INFOTIPSIZE] = '\0';
5702 tbgit.pszText = szBuffer;
5703 tbgit.cchTextMax = INFOTIPSIZE;
5704 tbgit.iItem = lpnmtdi->hdr.idFrom;
5705 tbgit.lParam = infoPtr->buttons[index].dwData;
5707 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
5709 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
5711 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
5712 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5714 /* need to allocate temporary buffer in infoPtr as there
5715 * isn't enough space in buffer passed to us by the
5716 * tooltip control */
5717 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5718 if (infoPtr->pszTooltipText)
5720 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
5721 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5722 return 0;
5725 else if (len > 0)
5727 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
5728 return 0;
5732 /* if button has text, but it is not shown then automatically
5733 * use that text as tooltip */
5734 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
5735 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
5737 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
5738 int len = pszText ? strlenW(pszText) : 0;
5740 TRACE("using button hidden text %s\n", debugstr_w(pszText));
5742 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5744 /* need to allocate temporary buffer in infoPtr as there
5745 * isn't enough space in buffer passed to us by the
5746 * tooltip control */
5747 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5748 if (infoPtr->pszTooltipText)
5750 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
5751 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5752 return 0;
5755 else if (len > 0)
5757 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
5758 return 0;
5762 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
5764 /* last resort: send notification on to app */
5765 /* FIXME: find out what is really used here */
5766 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
5770 inline static LRESULT
5771 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
5773 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5774 LPNMHDR lpnmh = (LPNMHDR)lParam;
5776 switch (lpnmh->code)
5778 case PGN_CALCSIZE:
5780 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
5782 if (lppgc->dwFlag == PGF_CALCWIDTH) {
5783 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
5784 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
5785 lppgc->iWidth);
5787 else {
5788 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5789 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
5790 lppgc->iHeight);
5792 return 0;
5795 case PGN_SCROLL:
5797 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
5799 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
5800 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
5801 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
5802 lppgs->iScroll, lppgs->iDir);
5803 return 0;
5806 case TTN_GETDISPINFOW:
5807 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
5809 case TTN_GETDISPINFOA:
5810 FIXME("TTN_GETDISPINFOA - stub\n");
5811 return 0;
5813 default:
5814 return 0;
5819 static LRESULT
5820 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
5822 /* remove this routine when Toolbar is improved to pass infoPtr
5823 * around instead of hwnd.
5825 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5826 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
5830 static LRESULT
5831 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5833 INT i;
5835 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
5837 if ((lParam == NF_QUERY) && ((HWND)wParam == infoPtr->hwndToolTip))
5838 return NFR_UNICODE;
5840 if (lParam == NF_REQUERY) {
5841 i = SendMessageA(infoPtr->hwndNotify,
5842 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
5843 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
5844 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
5846 i = NFR_ANSI;
5848 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
5849 return (LRESULT)i;
5851 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
5855 static LRESULT
5856 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
5858 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5859 HDC hdc;
5860 PAINTSTRUCT ps;
5862 /* fill ps.rcPaint with a default rect */
5863 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
5865 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
5867 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
5868 ps.rcPaint.left, ps.rcPaint.top,
5869 ps.rcPaint.right, ps.rcPaint.bottom);
5871 TOOLBAR_Refresh (hwnd, hdc, &ps);
5872 if (!wParam) EndPaint (hwnd, &ps);
5874 return 0;
5878 static LRESULT
5879 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
5880 /*****************************************************
5882 * Function;
5883 * Handles the WM_SETREDRAW message.
5885 * Documentation:
5886 * According to testing V4.71 of COMCTL32 returns the
5887 * *previous* status of the redraw flag (either 0 or 1)
5888 * instead of the MSDN documented value of 0 if handled.
5889 * (For laughs see the "consistency" with same function
5890 * in rebar.)
5892 *****************************************************/
5894 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5895 BOOL oldredraw = infoPtr->bDoRedraw;
5897 TRACE("set to %s\n",
5898 (wParam) ? "TRUE" : "FALSE");
5899 infoPtr->bDoRedraw = (BOOL) wParam;
5900 if (wParam) {
5901 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
5903 return (oldredraw) ? 1 : 0;
5907 static LRESULT
5908 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
5910 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5911 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5912 RECT parent_rect;
5913 RECT window_rect;
5914 HWND parent;
5915 INT x, y;
5916 INT cx, cy;
5917 INT flags;
5918 UINT uPosFlags = 0;
5920 /* Resize deadlock check */
5921 if (infoPtr->bAutoSize) {
5922 infoPtr->bAutoSize = FALSE;
5923 return 0;
5926 /* FIXME: optimize to only update size if the new size doesn't */
5927 /* match the current size */
5929 flags = (INT) wParam;
5931 /* FIXME for flags =
5932 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
5935 TRACE("sizing toolbar!\n");
5937 if (flags == SIZE_RESTORED) {
5938 /* width and height don't apply */
5939 parent = GetParent (hwnd);
5940 GetClientRect(parent, &parent_rect);
5941 x = parent_rect.left;
5942 y = parent_rect.top;
5944 if (dwStyle & CCS_NORESIZE) {
5945 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
5948 * this sets the working width of the toolbar, and
5949 * Calc Toolbar will not adjust it, only the height
5951 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5952 cy = infoPtr->nHeight;
5953 cx = infoPtr->nWidth;
5954 TOOLBAR_CalcToolbar (hwnd);
5955 infoPtr->nWidth = cx;
5956 infoPtr->nHeight = cy;
5958 else {
5959 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5960 TOOLBAR_CalcToolbar (hwnd);
5961 cy = infoPtr->nHeight;
5962 cx = infoPtr->nWidth;
5964 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
5965 GetWindowRect(hwnd, &window_rect);
5966 ScreenToClient(parent, (LPPOINT)&window_rect.left);
5967 y = window_rect.top;
5969 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
5970 GetWindowRect(hwnd, &window_rect);
5971 y = parent_rect.bottom -
5972 ( window_rect.bottom - window_rect.top);
5976 if (dwStyle & CCS_NOPARENTALIGN) {
5977 uPosFlags |= SWP_NOMOVE;
5978 cy = infoPtr->nHeight;
5979 cx = infoPtr->nWidth;
5982 if (!(dwStyle & CCS_NODIVIDER))
5983 cy += GetSystemMetrics(SM_CYEDGE);
5985 if (dwStyle & WS_BORDER)
5987 x = y = 1;
5988 cy += GetSystemMetrics(SM_CYEDGE);
5989 cx += GetSystemMetrics(SM_CYEDGE);
5992 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
5994 RECT delta_width, delta_height, client, dummy;
5995 DWORD min_x, max_x, min_y, max_y;
5996 TBUTTON_INFO *btnPtr;
5997 INT i;
5999 GetClientRect(hwnd, &client);
6000 if(client.right > infoPtr->client_rect.right)
6002 min_x = infoPtr->client_rect.right;
6003 max_x = client.right;
6005 else
6007 max_x = infoPtr->client_rect.right;
6008 min_x = client.right;
6010 if(client.bottom > infoPtr->client_rect.bottom)
6012 min_y = infoPtr->client_rect.bottom;
6013 max_y = client.bottom;
6015 else
6017 max_y = infoPtr->client_rect.bottom;
6018 min_y = client.bottom;
6021 SetRect(&delta_width, min_x, 0, max_x, min_y);
6022 SetRect(&delta_height, 0, min_y, max_x, max_y);
6024 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6025 btnPtr = infoPtr->buttons;
6026 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6027 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6028 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6029 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6032 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) == (SWP_NOSIZE | SWP_NOMOVE))
6033 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6035 GetClientRect(hwnd, &infoPtr->client_rect);
6036 return 0;
6040 static LRESULT
6041 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6043 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6045 if (nType == GWL_STYLE) {
6046 if (lpStyle->styleNew & TBSTYLE_LIST) {
6047 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
6049 else {
6050 infoPtr->dwDTFlags = DT_CENTER;
6052 infoPtr->bTransparent = (lpStyle->styleNew & TBSTYLE_TRANSPARENT);
6053 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6054 (TBSTYLE_FLAT | TBSTYLE_LIST));
6055 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6057 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6060 TOOLBAR_CalcToolbar(hwnd);
6062 TOOLBAR_AutoSize (hwnd);
6064 InvalidateRect(hwnd, NULL, TRUE);
6066 return 0;
6070 static LRESULT
6071 TOOLBAR_SysColorChange (HWND hwnd)
6073 COMCTL32_RefreshSysColors();
6075 return 0;
6080 static LRESULT WINAPI
6081 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6083 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6085 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6086 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6088 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
6089 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
6091 switch (uMsg)
6093 case TB_ADDBITMAP:
6094 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6096 case TB_ADDBUTTONSA:
6097 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6099 case TB_ADDBUTTONSW:
6100 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6102 case TB_ADDSTRINGA:
6103 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6105 case TB_ADDSTRINGW:
6106 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6108 case TB_AUTOSIZE:
6109 return TOOLBAR_AutoSize (hwnd);
6111 case TB_BUTTONCOUNT:
6112 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6114 case TB_BUTTONSTRUCTSIZE:
6115 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6117 case TB_CHANGEBITMAP:
6118 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6120 case TB_CHECKBUTTON:
6121 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6123 case TB_COMMANDTOINDEX:
6124 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6126 case TB_CUSTOMIZE:
6127 return TOOLBAR_Customize (hwnd);
6129 case TB_DELETEBUTTON:
6130 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6132 case TB_ENABLEBUTTON:
6133 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6135 case TB_GETANCHORHIGHLIGHT:
6136 return TOOLBAR_GetAnchorHighlight (hwnd);
6138 case TB_GETBITMAP:
6139 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6141 case TB_GETBITMAPFLAGS:
6142 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6144 case TB_GETBUTTON:
6145 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6147 case TB_GETBUTTONINFOA:
6148 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6150 case TB_GETBUTTONINFOW:
6151 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6153 case TB_GETBUTTONSIZE:
6154 return TOOLBAR_GetButtonSize (hwnd);
6156 case TB_GETBUTTONTEXTA:
6157 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6159 case TB_GETBUTTONTEXTW:
6160 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6162 case TB_GETDISABLEDIMAGELIST:
6163 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6165 case TB_GETEXTENDEDSTYLE:
6166 return TOOLBAR_GetExtendedStyle (hwnd);
6168 case TB_GETHOTIMAGELIST:
6169 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6171 case TB_GETHOTITEM:
6172 return TOOLBAR_GetHotItem (hwnd);
6174 case TB_GETIMAGELIST:
6175 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6177 /* case TB_GETINSERTMARK: */ /* 4.71 */
6178 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
6180 case TB_GETITEMRECT:
6181 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6183 case TB_GETMAXSIZE:
6184 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6186 /* case TB_GETOBJECT: */ /* 4.71 */
6188 case TB_GETPADDING:
6189 return TOOLBAR_GetPadding (hwnd);
6191 case TB_GETRECT:
6192 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6194 case TB_GETROWS:
6195 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6197 case TB_GETSTATE:
6198 return TOOLBAR_GetState (hwnd, wParam, lParam);
6200 case TB_GETSTRINGA:
6201 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6203 case TB_GETSTRINGW:
6204 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6206 case TB_GETSTYLE:
6207 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6209 case TB_GETTEXTROWS:
6210 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6212 case TB_GETTOOLTIPS:
6213 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6215 case TB_GETUNICODEFORMAT:
6216 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6218 case TB_HIDEBUTTON:
6219 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6221 case TB_HITTEST:
6222 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6224 case TB_INDETERMINATE:
6225 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6227 case TB_INSERTBUTTONA:
6228 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6230 case TB_INSERTBUTTONW:
6231 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6233 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6235 case TB_ISBUTTONCHECKED:
6236 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6238 case TB_ISBUTTONENABLED:
6239 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6241 case TB_ISBUTTONHIDDEN:
6242 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6244 case TB_ISBUTTONHIGHLIGHTED:
6245 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6247 case TB_ISBUTTONINDETERMINATE:
6248 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6250 case TB_ISBUTTONPRESSED:
6251 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6253 case TB_LOADIMAGES:
6254 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6256 case TB_MAPACCELERATORA:
6257 case TB_MAPACCELERATORW:
6258 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6260 case TB_MARKBUTTON:
6261 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6263 /* case TB_MOVEBUTTON: */ /* 4.71 */
6265 case TB_PRESSBUTTON:
6266 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6268 case TB_REPLACEBITMAP:
6269 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6271 case TB_SAVERESTOREA:
6272 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
6274 case TB_SAVERESTOREW:
6275 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
6277 case TB_SETANCHORHIGHLIGHT:
6278 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6280 case TB_SETBITMAPSIZE:
6281 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6283 case TB_SETBUTTONINFOA:
6284 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6286 case TB_SETBUTTONINFOW:
6287 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6289 case TB_SETBUTTONSIZE:
6290 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6292 case TB_SETBUTTONWIDTH:
6293 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6295 case TB_SETCMDID:
6296 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6298 case TB_SETDISABLEDIMAGELIST:
6299 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6301 case TB_SETDRAWTEXTFLAGS:
6302 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6304 case TB_SETEXTENDEDSTYLE:
6305 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6307 case TB_SETHOTIMAGELIST:
6308 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6310 case TB_SETHOTITEM:
6311 return TOOLBAR_SetHotItem (hwnd, wParam);
6313 case TB_SETIMAGELIST:
6314 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6316 case TB_SETINDENT:
6317 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6319 /* case TB_SETINSERTMARK: */ /* 4.71 */
6321 case TB_SETINSERTMARKCOLOR:
6322 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6324 case TB_SETMAXTEXTROWS:
6325 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6327 case TB_SETPADDING:
6328 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6330 case TB_SETPARENT:
6331 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6333 case TB_SETROWS:
6334 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6336 case TB_SETSTATE:
6337 return TOOLBAR_SetState (hwnd, wParam, lParam);
6339 case TB_SETSTYLE:
6340 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6342 case TB_SETTOOLTIPS:
6343 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6345 case TB_SETUNICODEFORMAT:
6346 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6348 case TB_UNKWN45D:
6349 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6351 case TB_UNKWN45E:
6352 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6354 case TB_UNKWN460:
6355 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6357 case TB_UNKWN462:
6358 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6360 case TB_UNKWN463:
6361 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6363 case TB_UNKWN464:
6364 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6366 /* Common Control Messages */
6368 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6369 case CCM_GETCOLORSCHEME:
6370 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6372 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6373 case CCM_SETCOLORSCHEME:
6374 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6376 case CCM_GETVERSION:
6377 return TOOLBAR_GetVersion (hwnd);
6379 case CCM_SETVERSION:
6380 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6383 /* case WM_CHAR: */
6385 case WM_CREATE:
6386 return TOOLBAR_Create (hwnd, wParam, lParam);
6388 case WM_DESTROY:
6389 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6391 case WM_ERASEBKGND:
6392 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6394 case WM_GETFONT:
6395 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6397 /* case WM_KEYDOWN: */
6398 /* case WM_KILLFOCUS: */
6400 case WM_LBUTTONDBLCLK:
6401 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6403 case WM_LBUTTONDOWN:
6404 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6406 case WM_LBUTTONUP:
6407 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6409 case WM_MOUSEMOVE:
6410 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6412 case WM_MOUSELEAVE:
6413 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6415 case WM_CAPTURECHANGED:
6416 return TOOLBAR_CaptureChanged(hwnd);
6418 case WM_NCACTIVATE:
6419 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6421 case WM_NCCALCSIZE:
6422 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6424 case WM_NCCREATE:
6425 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6427 case WM_NCPAINT:
6428 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6430 case WM_NOTIFY:
6431 return TOOLBAR_Notify (hwnd, wParam, lParam);
6433 case WM_NOTIFYFORMAT:
6434 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
6436 case WM_PAINT:
6437 return TOOLBAR_Paint (hwnd, wParam);
6439 case WM_SETREDRAW:
6440 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6442 case WM_SIZE:
6443 return TOOLBAR_Size (hwnd, wParam, lParam);
6445 case WM_STYLECHANGED:
6446 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6448 case WM_SYSCOLORCHANGE:
6449 return TOOLBAR_SysColorChange (hwnd);
6451 /* case WM_WININICHANGE: */
6453 case WM_CHARTOITEM:
6454 case WM_COMMAND:
6455 case WM_DRAWITEM:
6456 case WM_MEASUREITEM:
6457 case WM_VKEYTOITEM:
6458 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
6460 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6461 case PGM_FORWARDMOUSE:
6462 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6464 default:
6465 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6466 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6467 uMsg, wParam, lParam);
6468 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6470 return 0;
6474 VOID
6475 TOOLBAR_Register (void)
6477 WNDCLASSA wndClass;
6479 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
6480 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6481 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
6482 wndClass.cbClsExtra = 0;
6483 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6484 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
6485 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
6486 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
6488 RegisterClassA (&wndClass);
6492 VOID
6493 TOOLBAR_Unregister (void)
6495 UnregisterClassA (TOOLBARCLASSNAMEA, NULL);
6498 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6500 HIMAGELIST himlold;
6501 PIMLENTRY c = NULL;
6503 /* Check if the entry already exists */
6504 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6506 /* If this is a new entry we must create it and insert into the array */
6507 if (!c)
6509 PIMLENTRY *pnies;
6511 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
6512 c->id = id;
6514 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
6515 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6516 pnies[*cies] = c;
6517 (*cies)++;
6519 Free(*pies);
6520 *pies = pnies;
6523 himlold = c->himl;
6524 c->himl = himl;
6526 return himlold;
6530 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6532 int i;
6534 for (i = 0; i < *cies; i++)
6535 Free((*pies)[i]);
6537 Free(*pies);
6539 *cies = 0;
6540 *pies = NULL;
6544 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
6546 PIMLENTRY c = NULL;
6548 if (pies != NULL)
6550 int i;
6552 for (i = 0; i < cies; i++)
6554 if (pies[i]->id == id)
6556 c = pies[i];
6557 break;
6562 return c;
6566 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
6568 HIMAGELIST himlDef = 0;
6569 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6571 if (pie)
6572 himlDef = pie->himl;
6574 return himlDef;
6578 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6580 if (infoPtr->bUnicode)
6581 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
6582 else
6584 CHAR Buffer[256];
6585 NMTOOLBARA nmtba;
6586 BOOL bRet = FALSE;
6588 nmtba.iItem = nmtb->iItem;
6589 nmtba.pszText = Buffer;
6590 nmtba.cchText = 256;
6591 ZeroMemory(nmtba.pszText, nmtba.cchText);
6593 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
6595 int ccht = strlen(nmtba.pszText);
6596 if (ccht)
6597 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
6598 nmtb->pszText, nmtb->cchText);
6600 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
6601 bRet = TRUE;
6604 return bRet;
6609 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
6610 int iItem, PCUSTOMBUTTON btnInfo)
6612 NMTOOLBARA nmtb;
6614 nmtb.iItem = iItem;
6615 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
6617 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE);