Make the standard create_file request handle serial ports too, and
[wine.git] / dlls / comctl32 / toolbar.c
blobcdc2058eeb4d712bb6b8fb7d73d4542178589594
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 * - iListGap custom draw support.
69 * - Customization dialog:
70 * - Minor buglet in 'available buttons' list:
71 * Buttons are not listed in MS-like order. MS seems to use a single
72 * internal list to store the button information of both listboxes.
73 * - Drag list support.
75 * Testing:
76 * - Run tests using Waite Group Windows95 API Bible Volume 2.
77 * The second cdrom contains executables addstr.exe, btncount.exe,
78 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
79 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
80 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
81 * setparnt.exe, setrows.exe, toolwnd.exe.
82 * - Microsofts controlspy examples.
83 * - Charles Petzold's 'Programming Windows': gadgets.exe
86 #include <stdarg.h>
87 #include <string.h>
89 #include "windef.h"
90 #include "winbase.h"
91 #include "wingdi.h"
92 #include "winuser.h"
93 #include "wine/unicode.h"
94 #include "winnls.h"
95 #include "commctrl.h"
96 #include "comctl32.h"
97 #include "wine/debug.h"
99 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
101 typedef struct
103 INT iBitmap;
104 INT idCommand;
105 BYTE fsState;
106 BYTE fsStyle;
107 DWORD dwData;
108 INT iString;
109 BOOL bHot;
110 INT nRow;
111 RECT rect;
112 INT cx; /* manually set size */
113 } TBUTTON_INFO;
115 typedef struct
117 UINT nButtons;
118 HINSTANCE hInst;
119 UINT nID;
120 } TBITMAP_INFO;
122 typedef struct
124 HIMAGELIST himl;
125 INT id;
126 } IMLENTRY, *PIMLENTRY;
128 typedef struct
130 DWORD dwStructSize; /* size of TBBUTTON struct */
131 INT nHeight; /* height of the toolbar */
132 INT nWidth; /* width of the toolbar */
133 RECT client_rect;
134 INT nButtonHeight;
135 INT nButtonWidth;
136 INT nBitmapHeight;
137 INT nBitmapWidth;
138 INT nIndent;
139 INT nRows; /* number of button rows */
140 INT nMaxTextRows; /* maximum number of text rows */
141 INT cxMin; /* minimum button width */
142 INT cxMax; /* maximum button width */
143 INT nNumButtons; /* number of buttons */
144 INT nNumBitmaps; /* number of bitmaps */
145 INT nNumStrings; /* number of strings */
146 INT nNumBitmapInfos;
147 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
148 BOOL bCaptured; /* mouse captured? */
149 INT nButtonDown;
150 INT nOldHit;
151 INT nHotItem; /* index of the "hot" item */
152 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
153 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
154 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
155 SIZE szPadding; /* padding values around button */
156 INT iListGap; /* default gap between text and image for toolbar with list style */
157 HFONT hDefaultFont;
158 HFONT hFont; /* text font */
159 HIMAGELIST himlInt; /* image list created internally */
160 PIMLENTRY *himlDef; /* default image list array */
161 INT cimlDef; /* default image list array count */
162 PIMLENTRY *himlHot; /* hot image list array */
163 INT cimlHot; /* hot image list array count */
164 PIMLENTRY *himlDis; /* disabled image list array */
165 INT cimlDis; /* disabled image list array count */
166 HWND hwndToolTip; /* handle to tool tip control */
167 HWND hwndNotify; /* handle to the window that gets notifications */
168 HWND hwndSelf; /* my own handle */
169 BOOL bTransparent; /* background transparency flag */
170 BOOL bBtnTranspnt; /* button transparency flag */
171 BOOL bAutoSize; /* auto size deadlock indicator */
172 BOOL bAnchor; /* anchor highlight enabled */
173 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
174 BOOL bDoRedraw; /* Redraw status */
175 DWORD dwExStyle; /* extended toolbar style */
176 DWORD dwDTFlags; /* DrawText flags */
178 COLORREF clrInsertMark; /* insert mark color */
179 COLORREF clrBtnHighlight; /* color for Flat Separator */
180 COLORREF clrBtnShadow; /* color for Flag Separator */
181 RECT rcBound; /* bounding rectangle */
182 INT iVersion;
183 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
184 * for TTN_GETDISPINFOW notification */
185 TBUTTON_INFO *buttons; /* pointer to button array */
186 LPWSTR *strings; /* pointer to string array */
187 TBITMAP_INFO *bitmaps;
188 } TOOLBAR_INFO, *PTOOLBAR_INFO;
191 /* used by customization dialog */
192 typedef struct
194 PTOOLBAR_INFO tbInfo;
195 HWND tbHwnd;
196 } CUSTDLG_INFO, *PCUSTDLG_INFO;
198 typedef struct
200 TBBUTTON btn;
201 BOOL bVirtual;
202 BOOL bRemovable;
203 WCHAR text[64];
204 } CUSTOMBUTTON, *PCUSTOMBUTTON;
206 typedef enum
208 IMAGE_LIST_DEFAULT,
209 IMAGE_LIST_HOT,
210 IMAGE_LIST_DISABLED
211 } IMAGE_LIST_TYPE;
213 #define SEPARATOR_WIDTH 8
214 #define TOP_BORDER 2
215 #define BOTTOM_BORDER 2
216 #define DDARROW_WIDTH 11
217 #define ARROW_HEIGHT 3
219 /* gap between border of button and text/image */
220 #define OFFSET_X 1
221 #define OFFSET_Y 1
222 /* how wide to treat the bitmap if it isn't present */
223 #define LIST_IMAGE_ABSENT_WIDTH 2
225 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
226 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
227 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
229 static inline int TOOLBAR_GetListTextOffset(TOOLBAR_INFO *infoPtr, INT iListGap)
231 return GetSystemMetrics(SM_CXEDGE) + iListGap - infoPtr->szPadding.cx/2;
234 /* Used to find undocumented extended styles */
235 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
236 TBSTYLE_EX_UNDOC1 | \
237 TBSTYLE_EX_MIXEDBUTTONS | \
238 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
240 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
241 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
242 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
243 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
244 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
246 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
247 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
248 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
249 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
250 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
251 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
253 static LRESULT
254 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
257 static LPWSTR
258 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
260 LPWSTR lpText = NULL;
262 /* FIXME: iString == -1 is undocumented */
263 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
264 lpText = (LPWSTR)btnPtr->iString;
265 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
266 lpText = infoPtr->strings[btnPtr->iString];
268 return lpText;
271 static void
272 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
274 if (TRACE_ON(toolbar)){
275 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
276 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
277 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
278 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
279 if (internal)
280 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
281 btn_num, bP->idCommand,
282 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
283 bP->rect.left, bP->rect.top,
284 bP->rect.right, bP->rect.bottom);
289 static void
290 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
292 if (TRACE_ON(toolbar)) {
293 INT i;
294 DWORD dwStyle;
296 dwStyle = GetWindowLongA (iP->hwndSelf, GWL_STYLE);
297 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
298 iP->hwndSelf, line,
299 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
300 iP->nNumStrings, dwStyle);
301 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
302 iP->hwndSelf, line,
303 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
304 (iP->bDoRedraw) ? "TRUE" : "FALSE");
305 for(i=0; i<iP->nNumButtons; i++) {
306 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
312 /***********************************************************************
313 * TOOLBAR_CheckStyle
315 * This function validates that the styles set are implemented and
316 * issues FIXME's warning of possible problems. In a perfect world this
317 * function should be null.
319 static void
320 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
322 if (dwStyle & TBSTYLE_ALTDRAG)
323 FIXME("[%p] TBSTYLE_ALTDRAG not implemented\n", hwnd);
324 if (dwStyle & TBSTYLE_REGISTERDROP)
325 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
329 static INT
330 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
332 if(!IsWindow(infoPtr->hwndSelf))
333 return 0; /* we have just been destroyed */
335 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
336 nmhdr->hwndFrom = infoPtr->hwndSelf;
337 nmhdr->code = code;
339 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
340 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
342 if (infoPtr->bNtfUnicode)
343 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
344 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
345 else
346 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
347 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
350 /***********************************************************************
351 * TOOLBAR_GetBitmapIndex
353 * This function returns the bitmap index associated with a button.
354 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
355 * is issued to retrieve the index.
357 static INT
358 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
360 INT ret = btnPtr->iBitmap;
362 if (ret == I_IMAGECALLBACK) {
363 /* issue TBN_GETDISPINFO */
364 NMTBDISPINFOA nmgd;
366 nmgd.idCommand = btnPtr->idCommand;
367 nmgd.lParam = btnPtr->dwData;
368 nmgd.dwMask = TBNF_IMAGE;
369 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
370 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
371 TBN_GETDISPINFOA);
372 if (nmgd.dwMask & TBNF_DI_SETITEM) {
373 btnPtr->iBitmap = nmgd.iImage;
375 ret = nmgd.iImage;
376 TRACE("TBN_GETDISPINFOA returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
377 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
380 if (ret != I_IMAGENONE)
381 ret = GETIBITMAP(infoPtr, ret);
383 return ret;
387 static BOOL
388 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
390 HIMAGELIST himl;
391 INT id = GETHIMLID(infoPtr, index);
392 INT iBitmap = GETIBITMAP(infoPtr, index);
394 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
395 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
396 (index == I_IMAGECALLBACK))
397 return TRUE;
398 else
399 return FALSE;
403 /***********************************************************************
404 * TOOLBAR_GetImageListForDrawing
406 * This function validates the bitmap index (including I_IMAGECALLBACK
407 * functionality) and returns the corresponding image list.
409 static HIMAGELIST
410 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
412 HIMAGELIST himl;
414 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
415 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
416 ERR("index %d,%d is not valid, max %d\n",
417 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
418 return NULL;
421 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
422 if ((*index == I_IMAGECALLBACK) ||
423 (*index == I_IMAGENONE)) return NULL;
424 ERR("TBN_GETDISPINFO returned invalid index %d\n",
425 *index);
426 return NULL;
429 switch(imagelist)
431 case IMAGE_LIST_DEFAULT:
432 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
433 break;
434 case IMAGE_LIST_HOT:
435 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
436 break;
437 case IMAGE_LIST_DISABLED:
438 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
439 break;
440 default:
441 himl = NULL;
442 FIXME("Shouldn't reach here\n");
445 if (!himl)
446 TRACE("no image list\n");
448 return himl;
452 /***********************************************************************
453 * TOOLBAR_TestImageExist
455 * This function is similar to TOOLBAR_GetImageListForDrawing, except it does not
456 * return the image list. The I_IMAGECALLBACK functionality is implemented.
458 static BOOL
459 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
461 INT index;
463 if (!himl) return FALSE;
465 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
466 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
467 ERR("index %d is not valid, max %d\n",
468 btnPtr->iBitmap, infoPtr->nNumBitmaps);
469 return FALSE;
472 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
473 if ((index == I_IMAGECALLBACK) ||
474 (index == I_IMAGENONE)) return FALSE;
475 ERR("TBN_GETDISPINFO returned invalid index %d\n",
476 index);
477 return FALSE;
479 return TRUE;
483 static void
484 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
486 RECT myrect;
487 COLORREF oldcolor, newcolor;
489 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
490 myrect.right = myrect.left + 1;
491 myrect.top = lpRect->top + 2;
492 myrect.bottom = lpRect->bottom - 2;
494 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
495 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
496 oldcolor = SetBkColor (hdc, newcolor);
497 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
499 myrect.left = myrect.right;
500 myrect.right = myrect.left + 1;
502 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
503 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
504 SetBkColor (hdc, newcolor);
505 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
507 SetBkColor (hdc, oldcolor);
511 /***********************************************************************
512 * TOOLBAR_DrawDDFlatSeparator
514 * This function draws the separator that was flagged as BTNS_DROPDOWN.
515 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
516 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
517 * are horizontal as opposed to the vertical separators for not dropdown
518 * type.
520 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
522 static void
523 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
525 RECT myrect;
526 COLORREF oldcolor, newcolor;
528 myrect.left = lpRect->left;
529 myrect.right = lpRect->right;
530 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
531 myrect.bottom = myrect.top + 1;
533 InflateRect (&myrect, -2, 0);
535 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
536 myrect.left, myrect.top, myrect.right, myrect.bottom);
538 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
539 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
540 oldcolor = SetBkColor (hdc, newcolor);
541 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
543 myrect.top = myrect.bottom;
544 myrect.bottom = myrect.top + 1;
546 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
547 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
548 SetBkColor (hdc, newcolor);
549 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
551 SetBkColor (hdc, oldcolor);
555 static void
556 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
558 INT x, y;
559 HPEN hPen, hOldPen;
561 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
562 hOldPen = SelectObject ( hdc, hPen );
563 x = left + 2;
564 y = top;
565 MoveToEx (hdc, x, y, NULL);
566 LineTo (hdc, x+5, y++); x++;
567 MoveToEx (hdc, x, y, NULL);
568 LineTo (hdc, x+3, y++); x++;
569 MoveToEx (hdc, x, y, NULL);
570 LineTo (hdc, x+1, y++);
571 SelectObject( hdc, hOldPen );
572 DeleteObject( hPen );
576 * Draw the text string for this button.
577 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
578 * is non-zero, so we can simply check himlDef to see if we have
579 * an image list
581 static void
582 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
583 NMTBCUSTOMDRAW *tbcd)
585 HDC hdc = tbcd->nmcd.hdc;
586 HFONT hOldFont = 0;
587 COLORREF clrOld = 0;
588 COLORREF clrOldBk = 0;
589 int oldBkMode = 0;
590 UINT state = tbcd->nmcd.uItemState;
592 /* draw text */
593 if (lpText) {
594 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
595 rcText->left, rcText->top, rcText->right, rcText->bottom);
597 hOldFont = SelectObject (hdc, infoPtr->hFont);
598 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
599 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
601 else if (state & CDIS_DISABLED) {
602 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
603 OffsetRect (rcText, 1, 1);
604 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
605 SetTextColor (hdc, comctl32_color.clr3dShadow);
606 OffsetRect (rcText, -1, -1);
608 else if (state & CDIS_INDETERMINATE) {
609 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
611 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
612 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
613 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
614 oldBkMode = SetBkMode (hdc, OPAQUE); /* FIXME: should this be in the NMTBCUSTOMDRAW structure? */
616 else {
617 clrOld = SetTextColor (hdc, tbcd->clrText);
620 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
621 SetTextColor (hdc, clrOld);
622 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
624 SetBkColor (hdc, clrOldBk);
625 SetBkMode (hdc, oldBkMode);
627 SelectObject (hdc, hOldFont);
632 static void
633 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
635 HDC hdc = tbcd->nmcd.hdc;
636 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
637 COLORREF clrTextOld;
638 COLORREF clrBkOld;
639 INT cx = lpRect->right - lpRect->left;
640 INT cy = lpRect->bottom - lpRect->top;
641 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
642 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
643 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, PATCOPY);
644 SetBkColor(hdc, clrBkOld);
645 SetTextColor(hdc, clrTextOld);
646 SelectObject (hdc, hbr);
650 static void TOOLBAR_DrawMasked(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
651 HDC hdc, INT x, INT y)
653 int index;
654 HIMAGELIST himl =
655 TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
657 if (himl)
659 INT cx, cy;
660 HBITMAP hbmMask, hbmImage;
661 HDC hdcMask, hdcImage;
663 ImageList_GetIconSize(himl, &cx, &cy);
665 /* Create src image */
666 hdcImage = CreateCompatibleDC(hdc);
667 hbmImage = CreateBitmap(cx, cy, GetDeviceCaps(hdc,PLANES),
668 GetDeviceCaps(hdc,BITSPIXEL), NULL);
669 SelectObject(hdcImage, hbmImage);
670 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
671 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_NORMAL);
673 /* Create Mask */
674 hdcMask = CreateCompatibleDC(0);
675 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
676 SelectObject(hdcMask, hbmMask);
678 /* Remove the background and all white pixels */
679 SetBkColor(hdcImage, ImageList_GetBkColor(himl));
680 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, SRCCOPY);
681 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
682 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
684 /* draw the new mask 'etched' to hdc */
685 SetBkColor(hdc, RGB(255, 255, 255));
686 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
687 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
688 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
689 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
690 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
692 /* Cleanup */
693 DeleteObject(hbmImage);
694 DeleteDC(hdcImage);
695 DeleteObject (hbmMask);
696 DeleteDC(hdcMask);
701 static UINT
702 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
704 UINT retstate = 0;
706 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
707 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
708 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
709 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
710 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
711 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
712 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
713 return retstate;
716 /* draws the image on a toolbar button */
717 static void
718 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
720 HIMAGELIST himl = NULL;
721 BOOL draw_masked = FALSE;
722 INT index;
723 INT offset = 0;
724 UINT draw_flags = ILD_NORMAL;
726 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
728 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
729 if (!himl)
730 draw_masked = TRUE;
732 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && (GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & TBSTYLE_FLAT))
734 /* if hot, attempt to draw with hot image list, if fails,
735 use default image list */
736 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
737 if (!himl)
738 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
740 else
741 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
743 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
744 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
745 offset = 1;
747 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
748 (tbcd->nmcd.uItemState & CDIS_MARKED))
749 draw_flags |= ILD_BLEND50;
751 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
752 index, himl, left, top, offset);
754 if (draw_masked)
755 TOOLBAR_DrawMasked (infoPtr, btnPtr, tbcd->nmcd.hdc, left + offset, top + offset);
756 else if (himl)
757 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
760 /* draws a blank frame for a toolbar button */
761 static void
762 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd)
764 HDC hdc = tbcd->nmcd.hdc;
765 RECT rc = tbcd->nmcd.rc;
766 /* if the state is disabled or indeterminate then the button
767 * cannot have an interactive look like pressed or hot */
768 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
769 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
770 BOOL pressed_look = !non_interactive_state &&
771 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
772 (tbcd->nmcd.uItemState & CDIS_CHECKED));
774 /* app don't want us to draw any edges */
775 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
776 return;
778 if (flat)
780 if (pressed_look)
781 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
782 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
783 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
785 else
787 if (pressed_look)
788 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
789 else
790 DrawEdge (hdc, &rc, EDGE_RAISED,
791 BF_SOFT | BF_RECT | BF_MIDDLE);
795 static void
796 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow)
798 HDC hdc = tbcd->nmcd.hdc;
799 int offset = 0;
801 if (flat)
803 if ((tbcd->nmcd.uItemState & CDIS_SELECTED) || (tbcd->nmcd.uItemState & CDIS_CHECKED))
804 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
805 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
806 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
807 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
808 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
810 else
812 if ((tbcd->nmcd.uItemState & CDIS_SELECTED) || (tbcd->nmcd.uItemState & CDIS_CHECKED))
813 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
814 else
815 DrawEdge (hdc, rcArrow, EDGE_RAISED,
816 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
819 if (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
820 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
822 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
824 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
825 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
827 else
828 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
831 /* draws a complete toolbar button */
832 static void
833 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
835 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
836 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
837 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
838 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
839 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
840 BOOL drawSepDropDownArrow = hasDropDownArrow &&
841 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
842 RECT rc, rcArrow, rcBitmap, rcText;
843 LPWSTR lpText = NULL;
844 NMTBCUSTOMDRAW tbcd;
845 DWORD ntfret;
846 INT offset;
848 rc = btnPtr->rect;
849 CopyRect (&rcArrow, &rc);
850 CopyRect(&rcBitmap, &rc);
852 /* get a pointer to the text */
853 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
855 if (hasDropDownArrow)
857 int right;
859 if (dwStyle & TBSTYLE_FLAT)
860 right = max(rc.left, rc.right - DDARROW_WIDTH);
861 else
862 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
864 if (drawSepDropDownArrow)
865 rc.right = right;
867 rcArrow.left = right;
870 /* copy text rect after adjusting for drop-down arrow
871 * so that text is centred in the rectangle not containing
872 * the arrow */
873 CopyRect(&rcText, &rc);
875 /* Center the bitmap horizontally and vertically */
876 if (dwStyle & TBSTYLE_LIST)
877 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
878 else
879 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
881 if(lpText)
882 rcBitmap.top+= GetSystemMetrics(SM_CYEDGE) + OFFSET_Y;
883 else
884 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
886 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n",
887 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
888 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
889 TRACE ("iString: %x\n", btnPtr->iString);
890 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
892 /* draw text */
893 if (lpText) {
894 rcText.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
895 rcText.right -= GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
896 if (GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,btnPtr->iBitmap)) &&
897 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
899 if (dwStyle & TBSTYLE_LIST)
900 rcText.left += infoPtr->nBitmapWidth + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
901 else
902 rcText.top += GetSystemMetrics(SM_CYEDGE) + OFFSET_Y + infoPtr->nBitmapHeight + infoPtr->szPadding.cy/2;
904 else
905 if (dwStyle & TBSTYLE_LIST)
906 rcText.left += LIST_IMAGE_ABSENT_WIDTH + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
908 if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
909 OffsetRect (&rcText, 1, 1);
912 /* Initialize fields in all cases, because we use these later
913 * NOTE: applications can and do alter these to customize their
914 * toolbars */
915 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
916 tbcd.clrText = comctl32_color.clrBtnText;
917 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
918 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
919 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
920 tbcd.clrMark = comctl32_color.clrHighlight;
921 tbcd.clrHighlightHotTrack = 0;
922 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
923 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
924 /* MSDN says that this is the text rectangle.
925 * But (why always a but) tracing of v5.7 of native shows
926 * that this is really a *relative* rectangle based on the
927 * the nmcd.rc. Also the left and top are always 0 ignoring
928 * any bitmap that might be present. */
929 tbcd.rcText.left = 0;
930 tbcd.rcText.top = 0;
931 tbcd.rcText.right = rcText.right - rc.left;
932 tbcd.rcText.bottom = rcText.bottom - rc.top;
933 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
934 tbcd.nmcd.hdc = hdc;
935 tbcd.nmcd.rc = rc;
936 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
938 /* FIXME: what are these used for? */
939 tbcd.hbrLines = 0;
940 tbcd.hpenLines = 0;
942 /* Issue Item Prepaint notify */
943 infoPtr->dwItemCustDraw = 0;
944 infoPtr->dwItemCDFlag = 0;
945 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
947 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
948 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
949 tbcd.nmcd.lItemlParam = btnPtr->dwData;
950 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
951 /* reset these fields so the user can't alter the behaviour like native */
952 tbcd.nmcd.hdc = hdc;
953 tbcd.nmcd.rc = rc;
955 infoPtr->dwItemCustDraw = ntfret & 0xffff;
956 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
957 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
958 return;
959 /* save the only part of the rect that the user can change */
960 rcText.right = tbcd.rcText.right + rc.left;
961 rcText.bottom = tbcd.rcText.bottom + rc.top;
964 /* separator */
965 if (btnPtr->fsStyle & BTNS_SEP) {
966 /* with the FLAT style, iBitmap is the width and has already */
967 /* been taken into consideration in calculating the width */
968 /* so now we need to draw the vertical separator */
969 /* empirical tests show that iBitmap can/will be non-zero */
970 /* when drawing the vertical bar... */
971 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
972 if (btnPtr->fsStyle & BTNS_DROPDOWN)
973 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
974 else
975 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
977 else if (btnPtr->fsStyle != BTNS_SEP) {
978 FIXME("Draw some kind of separator: fsStyle=%x\n",
979 btnPtr->fsStyle);
981 goto FINALNOTIFY;
984 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
985 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
986 TOOLBAR_DrawPattern (&rc, &tbcd);
988 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
990 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
992 COLORREF oldclr;
994 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
995 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
996 if (hasDropDownArrow)
997 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
998 SetBkColor(hdc, oldclr);
1002 TOOLBAR_DrawFrame(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd);
1004 if (drawSepDropDownArrow)
1005 TOOLBAR_DrawSepDDArrow(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd, &rcArrow);
1007 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1008 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1010 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1012 if (hasDropDownArrow && !drawSepDropDownArrow)
1014 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1016 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1017 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1019 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1021 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1022 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1024 else
1025 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1028 FINALNOTIFY:
1029 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1031 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1032 tbcd.nmcd.hdc = hdc;
1033 tbcd.nmcd.rc = rc;
1034 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1035 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1036 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1037 tbcd.rcText = rcText;
1038 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1039 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1040 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1046 static void
1047 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1049 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1050 TBUTTON_INFO *btnPtr;
1051 INT i, oldBKmode = 0;
1052 RECT rcTemp, rcClient;
1053 NMTBCUSTOMDRAW tbcd;
1054 DWORD ntfret;
1056 /* the app has told us not to redraw the toolbar */
1057 if (!infoPtr->bDoRedraw)
1058 return;
1060 /* if imagelist belongs to the app, it can be changed
1061 by the app after setting it */
1062 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1064 infoPtr->nNumBitmaps = 0;
1065 for (i = 0; i < infoPtr->cimlDef; i++)
1066 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1069 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1071 /* Send initial notify */
1072 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1073 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1074 tbcd.nmcd.hdc = hdc;
1075 tbcd.nmcd.rc = ps->rcPaint;
1076 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1077 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1079 if (infoPtr->bBtnTranspnt)
1080 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1082 GetClientRect(hwnd, &rcClient);
1084 /* redraw necessary buttons */
1085 btnPtr = infoPtr->buttons;
1086 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1088 BOOL bDraw;
1089 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1091 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1092 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1094 else
1095 bDraw = TRUE;
1096 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1097 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1098 if (bDraw)
1099 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1102 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1103 SetBkMode (hdc, oldBKmode);
1105 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1107 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1108 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1109 tbcd.nmcd.hdc = hdc;
1110 tbcd.nmcd.rc = ps->rcPaint;
1111 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1115 /***********************************************************************
1116 * TOOLBAR_MeasureString
1118 * This function gets the width and height of a string in pixels. This
1119 * is done first by using GetTextExtentPoint to get the basic width
1120 * and height. The DrawText is called with DT_CALCRECT to get the exact
1121 * width. The reason is because the text may have more than one "&" (or
1122 * prefix characters as M$ likes to call them). The prefix character
1123 * indicates where the underline goes, except for the string "&&" which
1124 * is reduced to a single "&". GetTextExtentPoint does not process these
1125 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1127 static void
1128 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1129 HDC hdc, LPSIZE lpSize)
1131 RECT myrect;
1133 lpSize->cx = 0;
1134 lpSize->cy = 0;
1136 if (infoPtr->nMaxTextRows > 0 &&
1137 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1138 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1139 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1141 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1143 if(lpText != NULL) {
1144 /* first get size of all the text */
1145 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1147 /* feed above size into the rectangle for DrawText */
1148 myrect.left = myrect.top = 0;
1149 myrect.right = lpSize->cx;
1150 myrect.bottom = lpSize->cy;
1152 /* Use DrawText to get true size as drawn (less pesky "&") */
1153 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1154 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1155 DT_NOPREFIX : 0));
1157 /* feed back to caller */
1158 lpSize->cx = myrect.right;
1159 lpSize->cy = myrect.bottom;
1163 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1166 /***********************************************************************
1167 * TOOLBAR_CalcStrings
1169 * This function walks through each string and measures it and returns
1170 * the largest height and width to caller.
1172 static void
1173 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1175 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1176 TBUTTON_INFO *btnPtr;
1177 INT i;
1178 SIZE sz;
1179 HDC hdc;
1180 HFONT hOldFont;
1182 lpSize->cx = 0;
1183 lpSize->cy = 0;
1185 if(infoPtr->nMaxTextRows == 0)
1186 return;
1188 hdc = GetDC (hwnd);
1189 hOldFont = SelectObject (hdc, infoPtr->hFont);
1191 btnPtr = infoPtr->buttons;
1192 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1193 if(TOOLBAR_HasText(infoPtr, btnPtr))
1195 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1196 if (sz.cx > lpSize->cx)
1197 lpSize->cx = sz.cx;
1198 if (sz.cy > lpSize->cy)
1199 lpSize->cy = sz.cy;
1203 SelectObject (hdc, hOldFont);
1204 ReleaseDC (hwnd, hdc);
1206 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1209 /***********************************************************************
1210 * TOOLBAR_WrapToolbar
1212 * This function walks through the buttons and separators in the
1213 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1214 * wrapping should occur based on the width of the toolbar window.
1215 * It does *not* calculate button placement itself. That task
1216 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1217 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1218 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1220 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1221 * vertical toolbar lists.
1224 static void
1225 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1227 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1228 TBUTTON_INFO *btnPtr;
1229 INT x, cx, i, j;
1230 RECT rc;
1231 BOOL bWrap, bButtonWrap;
1233 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1234 /* no layout is necessary. Applications may use this style */
1235 /* to perform their own layout on the toolbar. */
1236 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1237 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1239 btnPtr = infoPtr->buttons;
1240 x = infoPtr->nIndent;
1242 /* this can get the parents width, to know how far we can extend
1243 * this toolbar. We cannot use its height, as there may be multiple
1244 * toolbars in a rebar control
1246 GetClientRect( GetParent(hwnd), &rc );
1247 infoPtr->nWidth = rc.right - rc.left;
1248 bButtonWrap = FALSE;
1250 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1251 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1252 infoPtr->nIndent);
1254 for (i = 0; i < infoPtr->nNumButtons; i++ )
1256 bWrap = FALSE;
1257 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1259 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1260 continue;
1262 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1263 /* it is the actual width of the separator. This is used for */
1264 /* custom controls in toolbars. */
1265 /* */
1266 /* BTNS_DROPDOWN separators are treated as buttons for */
1267 /* width. - GA 8/01 */
1268 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1269 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1270 cx = (btnPtr[i].iBitmap > 0) ?
1271 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1272 else
1273 cx = infoPtr->nButtonWidth;
1275 /* Two or more adjacent separators form a separator group. */
1276 /* The first separator in a group should be wrapped to the */
1277 /* next row if the previous wrapping is on a button. */
1278 if( bButtonWrap &&
1279 (btnPtr[i].fsStyle & BTNS_SEP) &&
1280 (i + 1 < infoPtr->nNumButtons ) &&
1281 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1283 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1284 btnPtr[i].fsState |= TBSTATE_WRAP;
1285 x = infoPtr->nIndent;
1286 i++;
1287 bButtonWrap = FALSE;
1288 continue;
1291 /* The layout makes sure the bitmap is visible, but not the button. */
1292 /* Test added to also wrap after a button that starts a row but */
1293 /* is bigger than the area. - GA 8/01 */
1294 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1295 > infoPtr->nWidth ) ||
1296 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1298 BOOL bFound = FALSE;
1300 /* If the current button is a separator and not hidden, */
1301 /* go to the next until it reaches a non separator. */
1302 /* Wrap the last separator if it is before a button. */
1303 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1304 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1305 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1306 i < infoPtr->nNumButtons )
1308 i++;
1309 bFound = TRUE;
1312 if( bFound && i < infoPtr->nNumButtons )
1314 i--;
1315 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1316 i, btnPtr[i].fsStyle, x, cx);
1317 btnPtr[i].fsState |= TBSTATE_WRAP;
1318 x = infoPtr->nIndent;
1319 bButtonWrap = FALSE;
1320 continue;
1322 else if ( i >= infoPtr->nNumButtons)
1323 break;
1325 /* If the current button is not a separator, find the last */
1326 /* separator and wrap it. */
1327 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1329 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1330 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1332 bFound = TRUE;
1333 i = j;
1334 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1335 i, btnPtr[i].fsStyle, x, cx);
1336 x = infoPtr->nIndent;
1337 btnPtr[j].fsState |= TBSTATE_WRAP;
1338 bButtonWrap = FALSE;
1339 break;
1343 /* If no separator available for wrapping, wrap one of */
1344 /* non-hidden previous button. */
1345 if (!bFound)
1347 for ( j = i - 1;
1348 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1350 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1351 continue;
1353 bFound = TRUE;
1354 i = j;
1355 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1356 i, btnPtr[i].fsStyle, x, cx);
1357 x = infoPtr->nIndent;
1358 btnPtr[j].fsState |= TBSTATE_WRAP;
1359 bButtonWrap = TRUE;
1360 break;
1364 /* If all above failed, wrap the current button. */
1365 if (!bFound)
1367 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1368 i, btnPtr[i].fsStyle, x, cx);
1369 btnPtr[i].fsState |= TBSTATE_WRAP;
1370 bFound = TRUE;
1371 x = infoPtr->nIndent;
1372 if (btnPtr[i].fsStyle & BTNS_SEP )
1373 bButtonWrap = FALSE;
1374 else
1375 bButtonWrap = TRUE;
1378 else {
1379 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1380 i, btnPtr[i].fsStyle, x, cx);
1381 x += cx;
1387 /***********************************************************************
1388 * TOOLBAR_CalcToolbar
1390 * This function calculates button and separator placement. It first
1391 * calculates the button sizes, gets the toolbar window width and then
1392 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1393 * on. It assigns a new location to each item and sends this location to
1394 * the tooltip window if appropriate. Finally, it updates the rcBound
1395 * rect and calculates the new required toolbar window height.
1398 static void
1399 TOOLBAR_CalcToolbar (HWND hwnd)
1401 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1402 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1403 TBUTTON_INFO *btnPtr;
1404 INT i, nRows, nSepRows;
1405 INT x, y, cx, cy;
1406 SIZE sizeString;
1407 BOOL bWrap;
1408 BOOL usesBitmaps = FALSE;
1409 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1411 TOOLBAR_CalcStrings (hwnd, &sizeString);
1413 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1415 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1417 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1418 usesBitmaps = TRUE;
1420 if (dwStyle & TBSTYLE_LIST)
1422 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1423 0, sizeString.cy) + infoPtr->szPadding.cy;
1424 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1425 LIST_IMAGE_ABSENT_WIDTH) + sizeString.cx + infoPtr->szPadding.cx;
1426 if (sizeString.cx > 0)
1427 infoPtr->nButtonWidth += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1428 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1429 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1430 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1432 else {
1433 if (sizeString.cy > 0)
1435 if (usesBitmaps)
1436 infoPtr->nButtonHeight = sizeString.cy +
1437 infoPtr->szPadding.cy/2 + /* this is the space to separate text from bitmap */
1438 infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1439 else
1440 infoPtr->nButtonHeight = sizeString.cy + infoPtr->szPadding.cy;
1442 else
1443 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1445 if (sizeString.cx > infoPtr->nBitmapWidth)
1446 infoPtr->nButtonWidth = sizeString.cx + infoPtr->szPadding.cx;
1447 else
1448 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + infoPtr->szPadding.cx;
1451 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1452 infoPtr->nButtonWidth = infoPtr->cxMin;
1453 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1454 infoPtr->nButtonWidth = infoPtr->cxMax;
1456 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1458 x = infoPtr->nIndent;
1459 y = 0;
1461 /* from above, minimum is a button, and possible text */
1462 cx = infoPtr->nButtonWidth;
1464 /* cannot use just ButtonHeight, we may have no buttons! */
1465 if (infoPtr->nNumButtons > 0)
1466 infoPtr->nHeight = infoPtr->nButtonHeight;
1468 cy = infoPtr->nHeight;
1470 nRows = nSepRows = 0;
1472 infoPtr->rcBound.top = y;
1473 infoPtr->rcBound.left = x;
1474 infoPtr->rcBound.bottom = y + cy;
1475 infoPtr->rcBound.right = x;
1477 btnPtr = infoPtr->buttons;
1479 TRACE("cy=%d\n", cy);
1481 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1483 bWrap = FALSE;
1484 if (btnPtr->fsState & TBSTATE_HIDDEN)
1486 SetRectEmpty (&btnPtr->rect);
1487 continue;
1490 cy = infoPtr->nHeight;
1492 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1493 /* it is the actual width of the separator. This is used for */
1494 /* custom controls in toolbars. */
1495 if (btnPtr->fsStyle & BTNS_SEP) {
1496 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1497 cy = (btnPtr->iBitmap > 0) ?
1498 btnPtr->iBitmap : SEPARATOR_WIDTH;
1499 cx = infoPtr->nButtonWidth;
1501 else
1502 cx = (btnPtr->iBitmap > 0) ?
1503 btnPtr->iBitmap : SEPARATOR_WIDTH;
1505 else
1507 if (btnPtr->cx)
1508 cx = btnPtr->cx;
1509 else 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 size has been set manually then don't add on extra space
1545 * for the drop down arrow */
1546 if (!btnPtr->cx && hasDropDownArrows &&
1547 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1548 cx += DDARROW_WIDTH;
1550 if (btnPtr->fsState & TBSTATE_WRAP )
1551 bWrap = TRUE;
1553 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1555 if (infoPtr->rcBound.left > x)
1556 infoPtr->rcBound.left = x;
1557 if (infoPtr->rcBound.right < x + cx)
1558 infoPtr->rcBound.right = x + cx;
1559 if (infoPtr->rcBound.bottom < y + cy)
1560 infoPtr->rcBound.bottom = y + cy;
1562 /* Set the toolTip only for non-hidden, non-separator button */
1563 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1565 TTTOOLINFOA ti;
1567 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1568 ti.cbSize = sizeof(TTTOOLINFOA);
1569 ti.hwnd = hwnd;
1570 ti.uId = btnPtr->idCommand;
1571 ti.rect = btnPtr->rect;
1572 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1573 0, (LPARAM)&ti);
1576 /* btnPtr->nRow is zero based. The space between the rows is */
1577 /* also considered as a row. */
1578 btnPtr->nRow = nRows + nSepRows;
1580 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1581 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1582 x, y, x+cx, y+cy);
1584 if( bWrap )
1586 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1587 y += cy;
1588 else
1590 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1591 /* it is the actual width of the separator. This is used for */
1592 /* custom controls in toolbars. */
1593 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1594 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1595 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1596 else
1597 y += cy;
1599 /* nSepRows is used to calculate the extra height follwoing */
1600 /* the last row. */
1601 nSepRows++;
1603 x = infoPtr->nIndent;
1605 /* Increment row number unless this is the last button */
1606 /* and it has Wrap set. */
1607 if (i != infoPtr->nNumButtons-1)
1608 nRows++;
1610 else
1611 x += cx;
1614 /* infoPtr->nRows is the number of rows on the toolbar */
1615 infoPtr->nRows = nRows + nSepRows + 1;
1617 #if 0
1618 /********************************************************************
1619 * The following while interesting, does not match the values *
1620 * created above for the button rectangles, nor the rcBound rect. *
1621 * We will comment it out and remove it later. *
1623 * The problem showed up as heights in the pager control that was *
1624 * wrong. *
1625 ********************************************************************/
1627 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1628 /* the last row. */
1629 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1630 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1631 nSepRows * (infoPtr->nBitmapHeight + 1) +
1632 BOTTOM_BORDER;
1633 #endif
1635 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1637 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1641 static INT
1642 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1644 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1645 TBUTTON_INFO *btnPtr;
1646 INT i;
1648 btnPtr = infoPtr->buttons;
1649 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1650 if (btnPtr->fsState & TBSTATE_HIDDEN)
1651 continue;
1653 if (btnPtr->fsStyle & BTNS_SEP) {
1654 if (PtInRect (&btnPtr->rect, *lpPt)) {
1655 TRACE(" ON SEPARATOR %d!\n", i);
1656 return -i;
1659 else {
1660 if (PtInRect (&btnPtr->rect, *lpPt)) {
1661 TRACE(" ON BUTTON %d!\n", i);
1662 return i;
1667 TRACE(" NOWHERE!\n");
1668 return -1;
1672 static INT
1673 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1675 TBUTTON_INFO *btnPtr;
1676 INT i;
1678 if (CommandIsIndex) {
1679 TRACE("command is really index command=%d\n", idCommand);
1680 if (idCommand >= infoPtr->nNumButtons) return -1;
1681 return idCommand;
1683 btnPtr = infoPtr->buttons;
1684 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1685 if (btnPtr->idCommand == idCommand) {
1686 TRACE("command=%d index=%d\n", idCommand, i);
1687 return i;
1690 TRACE("no index found for command=%d\n", idCommand);
1691 return -1;
1695 static INT
1696 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1698 TBUTTON_INFO *btnPtr;
1699 INT nRunIndex;
1701 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1702 return -1;
1704 /* check index button */
1705 btnPtr = &infoPtr->buttons[nIndex];
1706 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1707 if (btnPtr->fsState & TBSTATE_CHECKED)
1708 return nIndex;
1711 /* check previous buttons */
1712 nRunIndex = nIndex - 1;
1713 while (nRunIndex >= 0) {
1714 btnPtr = &infoPtr->buttons[nRunIndex];
1715 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1716 if (btnPtr->fsState & TBSTATE_CHECKED)
1717 return nRunIndex;
1719 else
1720 break;
1721 nRunIndex--;
1724 /* check next buttons */
1725 nRunIndex = nIndex + 1;
1726 while (nRunIndex < infoPtr->nNumButtons) {
1727 btnPtr = &infoPtr->buttons[nRunIndex];
1728 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1729 if (btnPtr->fsState & TBSTATE_CHECKED)
1730 return nRunIndex;
1732 else
1733 break;
1734 nRunIndex++;
1737 return -1;
1741 static VOID
1742 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1743 WPARAM wParam, LPARAM lParam)
1745 MSG msg;
1747 msg.hwnd = hwndMsg;
1748 msg.message = uMsg;
1749 msg.wParam = wParam;
1750 msg.lParam = lParam;
1751 msg.time = GetMessageTime ();
1752 msg.pt.x = LOWORD(GetMessagePos ());
1753 msg.pt.y = HIWORD(GetMessagePos ());
1755 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1759 /***********************************************************************
1760 * TOOLBAR_CustomizeDialogProc
1761 * This function implements the toolbar customization dialog.
1763 static INT_PTR CALLBACK
1764 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1766 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongA (hwnd, DWL_USER);
1767 PCUSTOMBUTTON btnInfo;
1768 NMTOOLBARA nmtb;
1769 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1771 switch (uMsg)
1773 case WM_INITDIALOG:
1774 custInfo = (PCUSTDLG_INFO)lParam;
1775 SetWindowLongA (hwnd, DWL_USER, (DWORD)custInfo);
1777 if (custInfo)
1779 WCHAR Buffer[256];
1780 int i = 0;
1781 int index;
1783 infoPtr = custInfo->tbInfo;
1785 /* send TBN_QUERYINSERT notification */
1786 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1788 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1789 return FALSE;
1791 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
1792 nmtb.iItem = (int)hwnd;
1793 /* Send TBN_INITCUSTOMIZE notification */
1794 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
1795 TBNRF_HIDEHELP)
1797 TRACE("TBNRF_HIDEHELP requested\n");
1798 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
1801 /* add items to 'toolbar buttons' list and check if removable */
1802 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1804 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1805 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1806 btnInfo->btn.fsStyle = BTNS_SEP;
1807 btnInfo->bVirtual = FALSE;
1808 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1810 /* send TBN_QUERYDELETE notification */
1811 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
1813 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1814 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1817 /* insert separator button into 'available buttons' list */
1818 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1819 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1820 btnInfo->btn.fsStyle = BTNS_SEP;
1821 btnInfo->bVirtual = FALSE;
1822 btnInfo->bRemovable = TRUE;
1823 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1824 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1825 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1827 /* insert all buttons into dsa */
1828 for (i = 0;; i++)
1830 /* send TBN_GETBUTTONINFO notification */
1831 NMTOOLBARW nmtb;
1832 nmtb.iItem = i;
1833 nmtb.pszText = Buffer;
1834 nmtb.cchText = 256;
1836 /* Clear previous button's text */
1837 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
1839 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
1840 break;
1842 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
1843 nmtb.tbButton.fsStyle, i,
1844 nmtb.tbButton.idCommand,
1845 nmtb.tbButton.iString,
1846 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
1847 : "");
1849 /* insert button into the apropriate list */
1850 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1851 if (index == -1)
1853 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1854 btnInfo->bVirtual = FALSE;
1855 btnInfo->bRemovable = TRUE;
1857 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1858 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX,
1859 LB_SETITEMDATA, index, (LPARAM)btnInfo);
1861 else
1863 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd,
1864 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1867 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1868 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
1870 if (lstrlenW(nmtb.pszText))
1871 lstrcpyW(btnInfo->text, nmtb.pszText);
1872 else if (nmtb.tbButton.iString >= 0 &&
1873 nmtb.tbButton.iString < infoPtr->nNumStrings)
1875 lstrcpyW(btnInfo->text,
1876 infoPtr->strings[nmtb.tbButton.iString]);
1881 /* select first item in the 'available' list */
1882 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1884 /* append 'virtual' separator button to the 'toolbar buttons' list */
1885 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1886 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1887 btnInfo->btn.fsStyle = BTNS_SEP;
1888 btnInfo->bVirtual = TRUE;
1889 btnInfo->bRemovable = FALSE;
1890 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1891 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1892 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1894 /* select last item in the 'toolbar' list */
1895 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1896 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1898 /* set focus and disable buttons */
1899 PostMessageA (hwnd, WM_USER, 0, 0);
1901 return TRUE;
1903 case WM_USER:
1904 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1905 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1906 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1907 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1908 return TRUE;
1910 case WM_CLOSE:
1911 EndDialog(hwnd, FALSE);
1912 return TRUE;
1914 case WM_COMMAND:
1915 switch (LOWORD(wParam))
1917 case IDC_TOOLBARBTN_LBOX:
1918 if (HIWORD(wParam) == LBN_SELCHANGE)
1920 PCUSTOMBUTTON btnInfo;
1921 NMTOOLBARA nmtb;
1922 int count;
1923 int index;
1925 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1926 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1928 /* send TBN_QUERYINSERT notification */
1929 nmtb.iItem = index;
1930 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1931 TBN_QUERYINSERT);
1933 /* get list box item */
1934 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1936 if (index == (count - 1))
1938 /* last item (virtual separator) */
1939 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1940 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1942 else if (index == (count - 2))
1944 /* second last item (last non-virtual item) */
1945 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1946 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1948 else if (index == 0)
1950 /* first item */
1951 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1952 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1954 else
1956 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1957 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1960 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1962 break;
1964 case IDC_MOVEUP_BTN:
1966 PCUSTOMBUTTON btnInfo;
1967 int index;
1968 int count;
1970 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1971 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1972 TRACE("Move up: index %d\n", index);
1974 /* send TBN_QUERYINSERT notification */
1975 nmtb.iItem = index;
1977 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1978 TBN_QUERYINSERT))
1980 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1982 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1983 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1984 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1985 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1987 if (index <= 1)
1988 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1989 else if (index >= (count - 3))
1990 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1992 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1993 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1996 break;
1998 case IDC_MOVEDN_BTN: /* move down */
2000 PCUSTOMBUTTON btnInfo;
2001 int index;
2002 int count;
2004 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2005 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2006 TRACE("Move up: index %d\n", index);
2008 /* send TBN_QUERYINSERT notification */
2009 nmtb.iItem = index;
2010 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2011 TBN_QUERYINSERT))
2013 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2015 /* move button down */
2016 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2017 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
2018 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
2019 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
2021 if (index == 0)
2022 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2023 else if (index >= (count - 3))
2024 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2026 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2027 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
2030 break;
2032 case IDC_REMOVE_BTN: /* remove button */
2034 PCUSTOMBUTTON btnInfo;
2035 int index;
2037 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2039 if (LB_ERR == index)
2040 break;
2042 TRACE("Remove: index %d\n", index);
2044 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX,
2045 LB_GETITEMDATA, index, 0);
2047 /* send TBN_QUERYDELETE notification */
2048 if (TOOLBAR_IsButtonRemovable(infoPtr, index, btnInfo))
2050 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2051 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2052 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
2054 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2056 /* insert into 'available button' list */
2057 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2059 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
2060 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2062 else
2063 Free (btnInfo);
2066 break;
2067 case IDC_HELP_BTN:
2068 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2069 break;
2070 case IDC_RESET_BTN:
2071 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2072 break;
2074 case IDOK: /* Add button */
2076 int index;
2077 int count;
2079 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2080 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2081 TRACE("Add: index %d\n", index);
2083 /* send TBN_QUERYINSERT notification */
2084 nmtb.iItem = index;
2085 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2086 TBN_QUERYINSERT))
2088 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
2090 if (index != 0)
2092 /* remove from 'available buttons' list */
2093 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
2094 if (index == count-1)
2095 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2096 else
2097 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
2099 else
2101 PCUSTOMBUTTON btnNew;
2103 /* duplicate 'separator' button */
2104 btnNew = (PCUSTOMBUTTON)Alloc (sizeof(CUSTOMBUTTON));
2105 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2106 btnInfo = btnNew;
2109 /* insert into 'toolbar button' list */
2110 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2111 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
2112 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2114 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
2117 break;
2119 case IDCANCEL:
2120 EndDialog(hwnd, FALSE);
2121 break;
2123 return TRUE;
2125 case WM_DESTROY:
2127 int count;
2128 int i;
2130 /* delete items from 'toolbar buttons' listbox*/
2131 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2132 for (i = 0; i < count; i++)
2134 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2135 Free(btnInfo);
2136 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2138 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2141 /* delete items from 'available buttons' listbox*/
2142 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2143 for (i = 0; i < count; i++)
2145 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2146 Free(btnInfo);
2147 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2149 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2151 return TRUE;
2153 case WM_DRAWITEM:
2154 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2156 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2157 DWORD dwStyle = GetWindowLongA (infoPtr->hwndSelf, GWL_STYLE);
2158 RECT rcButton;
2159 RECT rcText;
2160 HPEN hPen, hOldPen;
2161 HBRUSH hOldBrush;
2162 COLORREF oldText = 0;
2163 COLORREF oldBk = 0;
2165 /* get item data */
2166 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2167 if (btnInfo == NULL)
2169 FIXME("btnInfo invalid!\n");
2170 return TRUE;
2173 /* set colors and select objects */
2174 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2175 if (btnInfo->bVirtual)
2176 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2177 else
2178 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2179 hPen = CreatePen( PS_SOLID, 1,
2180 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2181 hOldPen = SelectObject (lpdis->hDC, hPen );
2182 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2184 /* fill background rectangle */
2185 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2186 lpdis->rcItem.right, lpdis->rcItem.bottom);
2188 /* calculate button and text rectangles */
2189 CopyRect (&rcButton, &lpdis->rcItem);
2190 InflateRect (&rcButton, -1, -1);
2191 CopyRect (&rcText, &rcButton);
2192 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2193 rcText.left = rcButton.right + 2;
2195 /* draw focus rectangle */
2196 if (lpdis->itemState & ODS_FOCUS)
2197 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2199 /* draw button */
2200 if (!(dwStyle & TBSTYLE_FLAT))
2201 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2203 /* draw image and text */
2204 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2205 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2206 btnInfo->btn.iBitmap));
2207 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2208 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2210 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2211 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2213 /* delete objects and reset colors */
2214 SelectObject (lpdis->hDC, hOldBrush);
2215 SelectObject (lpdis->hDC, hOldPen);
2216 SetBkColor (lpdis->hDC, oldBk);
2217 SetTextColor (lpdis->hDC, oldText);
2218 DeleteObject( hPen );
2219 return TRUE;
2221 return FALSE;
2223 case WM_MEASUREITEM:
2224 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2226 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2228 if (custInfo && custInfo->tbInfo)
2229 lpmis->itemHeight = custInfo->tbInfo->nBitmapHeight + 8;
2230 else
2231 lpmis->itemHeight = 15 + 8; /* default height */
2233 return TRUE;
2235 return FALSE;
2237 default:
2238 return FALSE;
2243 /***********************************************************************
2244 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2247 static LRESULT
2248 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2250 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2251 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2252 INT nIndex = 0, nButtons, nCount;
2253 HBITMAP hbmLoad;
2254 HIMAGELIST himlDef;
2256 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2257 if (!lpAddBmp)
2258 return -1;
2260 if (lpAddBmp->hInst == HINST_COMMCTRL)
2262 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2263 nButtons = 15;
2264 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2265 nButtons = 13;
2266 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2267 nButtons = 5;
2268 else
2269 return -1;
2271 TRACE ("adding %d internal bitmaps!\n", nButtons);
2273 /* Windows resize all the buttons to the size of a newly added standard image */
2274 if (lpAddBmp->nID & 1)
2276 /* large icons */
2277 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2278 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2280 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2281 MAKELPARAM((WORD)24, (WORD)24));
2282 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2283 MAKELPARAM((WORD)31, (WORD)30));
2285 else
2287 /* small icons */
2288 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2289 MAKELPARAM((WORD)16, (WORD)16));
2290 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2291 MAKELPARAM((WORD)22, (WORD)22));
2294 TOOLBAR_CalcToolbar (hwnd);
2296 else
2298 nButtons = (INT)wParam;
2299 if (nButtons <= 0)
2300 return -1;
2302 TRACE ("adding %d bitmaps!\n", nButtons);
2305 if (!infoPtr->cimlDef) {
2306 /* create new default image list */
2307 TRACE ("creating default image list!\n");
2309 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2310 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2311 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2312 infoPtr->himlInt = himlDef;
2314 else {
2315 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2318 if (!himlDef) {
2319 WARN("No default image list available\n");
2320 return -1;
2323 nCount = ImageList_GetImageCount(himlDef);
2325 /* Add bitmaps to the default image list */
2326 if (lpAddBmp->hInst == NULL)
2328 BITMAP bmp;
2329 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2330 HDC hdcImage, hdcBitmap;
2332 /* copy the bitmap before adding it so that the user's bitmap
2333 * doesn't get modified.
2335 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2337 hdcImage = CreateCompatibleDC(0);
2338 hdcBitmap = CreateCompatibleDC(0);
2340 /* create new bitmap */
2341 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2342 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2343 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2345 /* Copy the user's image */
2346 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2347 hdcBitmap, 0, 0, SRCCOPY);
2349 SelectObject (hdcImage, hOldBitmapLoad);
2350 SelectObject (hdcBitmap, hOldBitmapBitmap);
2351 DeleteDC (hdcImage);
2352 DeleteDC (hdcBitmap);
2354 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2355 DeleteObject (hbmLoad);
2357 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2359 /* Add system bitmaps */
2360 switch (lpAddBmp->nID)
2362 case IDB_STD_SMALL_COLOR:
2363 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2364 MAKEINTRESOURCEA(IDB_STD_SMALL));
2365 nIndex = ImageList_AddMasked (himlDef,
2366 hbmLoad, comctl32_color.clrBtnFace);
2367 DeleteObject (hbmLoad);
2368 break;
2370 case IDB_STD_LARGE_COLOR:
2371 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2372 MAKEINTRESOURCEA(IDB_STD_LARGE));
2373 nIndex = ImageList_AddMasked (himlDef,
2374 hbmLoad, comctl32_color.clrBtnFace);
2375 DeleteObject (hbmLoad);
2376 break;
2378 case IDB_VIEW_SMALL_COLOR:
2379 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2380 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2381 nIndex = ImageList_AddMasked (himlDef,
2382 hbmLoad, comctl32_color.clrBtnFace);
2383 DeleteObject (hbmLoad);
2384 break;
2386 case IDB_VIEW_LARGE_COLOR:
2387 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2388 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2389 nIndex = ImageList_AddMasked (himlDef,
2390 hbmLoad, comctl32_color.clrBtnFace);
2391 DeleteObject (hbmLoad);
2392 break;
2394 case IDB_HIST_SMALL_COLOR:
2395 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2396 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2397 nIndex = ImageList_AddMasked (himlDef,
2398 hbmLoad, comctl32_color.clrBtnFace);
2399 DeleteObject (hbmLoad);
2400 break;
2402 case IDB_HIST_LARGE_COLOR:
2403 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2404 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2405 nIndex = ImageList_AddMasked (himlDef,
2406 hbmLoad, comctl32_color.clrBtnFace);
2407 DeleteObject (hbmLoad);
2408 break;
2410 default:
2411 nIndex = ImageList_GetImageCount (himlDef);
2412 ERR ("invalid imagelist!\n");
2413 break;
2416 else
2418 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2419 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2420 DeleteObject (hbmLoad);
2423 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2425 if (infoPtr->nNumBitmapInfos == 0)
2427 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2429 else
2431 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2432 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2433 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2436 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2437 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2438 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2440 infoPtr->nNumBitmapInfos++;
2441 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2443 if (nIndex != -1)
2445 INT imagecount = ImageList_GetImageCount(himlDef);
2447 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2449 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",
2450 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2451 infoPtr->nNumBitmaps+nButtons,imagecount);
2453 infoPtr->nNumBitmaps = imagecount;
2455 else
2456 infoPtr->nNumBitmaps += nButtons;
2459 InvalidateRect(hwnd, NULL, TRUE);
2461 return nIndex;
2465 static LRESULT
2466 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2468 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2469 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2470 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2472 TRACE("adding %d buttons!\n", wParam);
2474 nAddButtons = (UINT)wParam;
2475 nOldButtons = infoPtr->nNumButtons;
2476 nNewButtons = nOldButtons + nAddButtons;
2478 if (infoPtr->nNumButtons == 0) {
2479 infoPtr->buttons =
2480 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2482 else {
2483 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2484 infoPtr->buttons =
2485 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2486 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2487 nOldButtons * sizeof(TBUTTON_INFO));
2488 Free (oldButtons);
2491 infoPtr->nNumButtons = nNewButtons;
2493 /* insert new button data */
2494 for (nCount = 0; nCount < nAddButtons; nCount++) {
2495 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2496 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2497 btnPtr->idCommand = lpTbb[nCount].idCommand;
2498 btnPtr->fsState = lpTbb[nCount].fsState;
2499 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2500 btnPtr->dwData = lpTbb[nCount].dwData;
2501 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2502 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2503 else
2504 btnPtr->iString = lpTbb[nCount].iString;
2505 btnPtr->bHot = FALSE;
2507 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2508 TTTOOLINFOA ti;
2510 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2511 ti.cbSize = sizeof (TTTOOLINFOA);
2512 ti.hwnd = hwnd;
2513 ti.uId = btnPtr->idCommand;
2514 ti.hinst = 0;
2515 ti.lpszText = LPSTR_TEXTCALLBACKA;
2517 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2518 0, (LPARAM)&ti);
2522 TOOLBAR_CalcToolbar (hwnd);
2524 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2526 InvalidateRect(hwnd, NULL, TRUE);
2528 return TRUE;
2532 static LRESULT
2533 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2535 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2536 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2537 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2539 TRACE("adding %d buttons!\n", wParam);
2541 nAddButtons = (UINT)wParam;
2542 nOldButtons = infoPtr->nNumButtons;
2543 nNewButtons = nOldButtons + nAddButtons;
2545 if (infoPtr->nNumButtons == 0) {
2546 infoPtr->buttons =
2547 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2549 else {
2550 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2551 infoPtr->buttons =
2552 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2553 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2554 nOldButtons * sizeof(TBUTTON_INFO));
2555 Free (oldButtons);
2558 infoPtr->nNumButtons = nNewButtons;
2560 /* insert new button data */
2561 for (nCount = 0; nCount < nAddButtons; nCount++) {
2562 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2563 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2564 btnPtr->idCommand = lpTbb[nCount].idCommand;
2565 btnPtr->fsState = lpTbb[nCount].fsState;
2566 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2567 btnPtr->dwData = lpTbb[nCount].dwData;
2568 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2569 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2570 else
2571 btnPtr->iString = lpTbb[nCount].iString;
2572 btnPtr->bHot = FALSE;
2574 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2575 TTTOOLINFOW ti;
2577 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2578 ti.cbSize = sizeof (TTTOOLINFOW);
2579 ti.hwnd = hwnd;
2580 ti.uId = btnPtr->idCommand;
2581 ti.hinst = 0;
2582 ti.lpszText = LPSTR_TEXTCALLBACKW;
2583 ti.lParam = lParam;
2585 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2586 0, (LPARAM)&ti);
2590 TOOLBAR_CalcToolbar (hwnd);
2592 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2594 InvalidateRect(hwnd, NULL, TRUE);
2596 return TRUE;
2600 static LRESULT
2601 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2603 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2604 INT nIndex;
2606 if ((wParam) && (HIWORD(lParam) == 0)) {
2607 char szString[256];
2608 INT len;
2609 TRACE("adding string from resource!\n");
2611 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2612 szString, 256);
2614 TRACE("len=%d \"%s\"\n", len, szString);
2615 nIndex = infoPtr->nNumStrings;
2616 if (infoPtr->nNumStrings == 0) {
2617 infoPtr->strings =
2618 Alloc (sizeof(LPWSTR));
2620 else {
2621 LPWSTR *oldStrings = infoPtr->strings;
2622 infoPtr->strings =
2623 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2624 memcpy (&infoPtr->strings[0], &oldStrings[0],
2625 sizeof(LPWSTR) * infoPtr->nNumStrings);
2626 Free (oldStrings);
2629 /*Alloc zeros out the allocated memory*/
2630 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2631 infoPtr->nNumStrings++;
2633 else {
2634 LPSTR p = (LPSTR)lParam;
2635 INT len;
2637 if (p == NULL)
2638 return -1;
2639 TRACE("adding string(s) from array!\n");
2641 nIndex = infoPtr->nNumStrings;
2642 while (*p) {
2643 len = strlen (p);
2644 TRACE("len=%d \"%s\"\n", len, p);
2646 if (infoPtr->nNumStrings == 0) {
2647 infoPtr->strings =
2648 Alloc (sizeof(LPWSTR));
2650 else {
2651 LPWSTR *oldStrings = infoPtr->strings;
2652 infoPtr->strings =
2653 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2654 memcpy (&infoPtr->strings[0], &oldStrings[0],
2655 sizeof(LPWSTR) * infoPtr->nNumStrings);
2656 Free (oldStrings);
2659 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2660 infoPtr->nNumStrings++;
2662 p += (len+1);
2666 return nIndex;
2670 static LRESULT
2671 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2673 #define MAX_RESOURCE_STRING_LENGTH 512
2674 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2675 INT nIndex;
2677 if ((wParam) && (HIWORD(lParam) == 0)) {
2678 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2679 INT len;
2680 TRACE("adding string from resource!\n");
2682 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2683 szString, MAX_RESOURCE_STRING_LENGTH);
2685 TRACE("len=%d %s\n", len, debugstr_w(szString));
2686 TRACE("First char: 0x%x\n", *szString);
2687 if (szString[0] == L'|')
2689 PWSTR p = szString + 1;
2691 nIndex = infoPtr->nNumStrings;
2692 while (*p != L'|' && *p != L'\0') {
2693 PWSTR np;
2695 if (infoPtr->nNumStrings == 0) {
2696 infoPtr->strings = Alloc (sizeof(LPWSTR));
2698 else
2700 LPWSTR *oldStrings = infoPtr->strings;
2701 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2702 memcpy(&infoPtr->strings[0], &oldStrings[0],
2703 sizeof(LPWSTR) * infoPtr->nNumStrings);
2704 Free(oldStrings);
2707 np=strchrW (p, '|');
2708 if (np!=NULL) {
2709 len = np - p;
2710 np++;
2711 } else {
2712 len = strlenW(p);
2713 np = p + len;
2715 TRACE("len=%d %s\n", len, debugstr_w(p));
2716 infoPtr->strings[infoPtr->nNumStrings] =
2717 Alloc (sizeof(WCHAR)*(len+1));
2718 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2719 infoPtr->nNumStrings++;
2721 p = np;
2724 else
2726 nIndex = infoPtr->nNumStrings;
2727 if (infoPtr->nNumStrings == 0) {
2728 infoPtr->strings =
2729 Alloc (sizeof(LPWSTR));
2731 else {
2732 LPWSTR *oldStrings = infoPtr->strings;
2733 infoPtr->strings =
2734 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2735 memcpy (&infoPtr->strings[0], &oldStrings[0],
2736 sizeof(LPWSTR) * infoPtr->nNumStrings);
2737 Free (oldStrings);
2740 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2741 infoPtr->nNumStrings++;
2744 else {
2745 LPWSTR p = (LPWSTR)lParam;
2746 INT len;
2748 if (p == NULL)
2749 return -1;
2750 TRACE("adding string(s) from array!\n");
2751 nIndex = infoPtr->nNumStrings;
2752 while (*p) {
2753 len = strlenW (p);
2755 TRACE("len=%d %s\n", len, debugstr_w(p));
2756 if (infoPtr->nNumStrings == 0) {
2757 infoPtr->strings =
2758 Alloc (sizeof(LPWSTR));
2760 else {
2761 LPWSTR *oldStrings = infoPtr->strings;
2762 infoPtr->strings =
2763 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2764 memcpy (&infoPtr->strings[0], &oldStrings[0],
2765 sizeof(LPWSTR) * infoPtr->nNumStrings);
2766 Free (oldStrings);
2769 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2770 infoPtr->nNumStrings++;
2772 p += (len+1);
2776 return nIndex;
2780 static LRESULT
2781 TOOLBAR_AutoSize (HWND hwnd)
2783 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2784 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2785 RECT parent_rect;
2786 RECT window_rect;
2787 HWND parent;
2788 INT x, y;
2789 INT cx, cy;
2790 UINT uPosFlags = SWP_NOZORDER;
2792 TRACE("resize forced, style=%lx!\n", dwStyle);
2794 parent = GetParent (hwnd);
2795 GetClientRect(parent, &parent_rect);
2797 x = parent_rect.left;
2798 y = parent_rect.top;
2800 /* FIXME: we should be able to early out if nothing */
2801 /* has changed with nWidth != parent_rect width */
2803 if (dwStyle & CCS_NORESIZE) {
2804 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2805 cx = 0;
2806 cy = 0;
2807 TOOLBAR_CalcToolbar (hwnd);
2809 else {
2810 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2811 TOOLBAR_CalcToolbar (hwnd);
2812 InvalidateRect( hwnd, NULL, TRUE );
2813 cy = infoPtr->nHeight;
2814 cx = infoPtr->nWidth;
2816 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
2817 GetWindowRect(hwnd, &window_rect);
2818 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2819 y = window_rect.top;
2821 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
2822 GetWindowRect(hwnd, &window_rect);
2823 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
2827 if (dwStyle & CCS_NOPARENTALIGN)
2828 uPosFlags |= SWP_NOMOVE;
2830 if (!(dwStyle & CCS_NODIVIDER))
2831 cy += GetSystemMetrics(SM_CYEDGE);
2833 if (dwStyle & WS_BORDER)
2835 x = y = 1;
2836 cy += GetSystemMetrics(SM_CYEDGE);
2837 cx += GetSystemMetrics(SM_CYEDGE);
2840 infoPtr->bAutoSize = TRUE;
2841 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
2842 /* The following line makes sure that the infoPtr->bAutoSize is turned off
2843 * after the setwindowpos calls */
2844 infoPtr->bAutoSize = FALSE;
2846 return 0;
2850 static LRESULT
2851 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2853 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2855 return infoPtr->nNumButtons;
2859 static LRESULT
2860 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2862 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2864 if (infoPtr == NULL) {
2865 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2866 ERR("infoPtr == NULL!\n");
2867 return 0;
2870 infoPtr->dwStructSize = (DWORD)wParam;
2872 return 0;
2876 static LRESULT
2877 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2879 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2880 TBUTTON_INFO *btnPtr;
2881 INT nIndex;
2883 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
2885 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2886 if (nIndex == -1)
2887 return FALSE;
2889 btnPtr = &infoPtr->buttons[nIndex];
2890 btnPtr->iBitmap = LOWORD(lParam);
2892 /* we HAVE to erase the background, the new bitmap could be */
2893 /* transparent */
2894 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2896 return TRUE;
2900 static LRESULT
2901 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2903 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2904 TBUTTON_INFO *btnPtr;
2905 INT nIndex;
2906 INT nOldIndex = -1;
2907 BOOL bChecked = FALSE;
2909 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2911 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
2913 if (nIndex == -1)
2914 return FALSE;
2916 btnPtr = &infoPtr->buttons[nIndex];
2918 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2920 if (LOWORD(lParam) == FALSE)
2921 btnPtr->fsState &= ~TBSTATE_CHECKED;
2922 else {
2923 if (btnPtr->fsStyle & BTNS_GROUP) {
2924 nOldIndex =
2925 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2926 if (nOldIndex == nIndex)
2927 return 0;
2928 if (nOldIndex != -1)
2929 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2931 btnPtr->fsState |= TBSTATE_CHECKED;
2934 if( bChecked != LOWORD(lParam) )
2936 if (nOldIndex != -1)
2937 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
2938 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2941 /* FIXME: Send a WM_NOTIFY?? */
2943 return TRUE;
2947 static LRESULT
2948 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2950 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2952 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2956 static LRESULT
2957 TOOLBAR_Customize (HWND hwnd)
2959 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2960 CUSTDLG_INFO custInfo;
2961 LRESULT ret;
2962 LPCVOID template;
2963 HRSRC hRes;
2964 NMHDR nmhdr;
2966 custInfo.tbInfo = infoPtr;
2967 custInfo.tbHwnd = hwnd;
2969 /* send TBN_BEGINADJUST notification */
2970 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2971 TBN_BEGINADJUST);
2973 if (!(hRes = FindResourceA (COMCTL32_hModule,
2974 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2975 (LPSTR)RT_DIALOG)))
2976 return FALSE;
2978 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2979 return FALSE;
2981 ret = DialogBoxIndirectParamA ((HINSTANCE)GetWindowLongA(hwnd, GWL_HINSTANCE),
2982 (LPDLGTEMPLATEA)template,
2983 hwnd,
2984 TOOLBAR_CustomizeDialogProc,
2985 (LPARAM)&custInfo);
2987 /* send TBN_ENDADJUST notification */
2988 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2989 TBN_ENDADJUST);
2991 return ret;
2995 static LRESULT
2996 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2998 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2999 INT nIndex = (INT)wParam;
3001 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3002 return FALSE;
3004 if ((infoPtr->hwndToolTip) &&
3005 !(infoPtr->buttons[nIndex].fsStyle & BTNS_SEP)) {
3006 TTTOOLINFOA ti;
3008 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3009 ti.cbSize = sizeof (TTTOOLINFOA);
3010 ti.hwnd = hwnd;
3011 ti.uId = infoPtr->buttons[nIndex].idCommand;
3013 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
3016 if (infoPtr->nNumButtons == 1) {
3017 TRACE(" simple delete!\n");
3018 Free (infoPtr->buttons);
3019 infoPtr->buttons = NULL;
3020 infoPtr->nNumButtons = 0;
3022 else {
3023 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3024 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3026 infoPtr->nNumButtons--;
3027 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3028 if (nIndex > 0) {
3029 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3030 nIndex * sizeof(TBUTTON_INFO));
3033 if (nIndex < infoPtr->nNumButtons) {
3034 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3035 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3038 Free (oldButtons);
3041 TOOLBAR_CalcToolbar (hwnd);
3043 InvalidateRect (hwnd, NULL, TRUE);
3045 return TRUE;
3049 static LRESULT
3050 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3052 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3053 TBUTTON_INFO *btnPtr;
3054 INT nIndex;
3055 DWORD bState;
3057 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3059 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3061 if (nIndex == -1)
3062 return FALSE;
3064 btnPtr = &infoPtr->buttons[nIndex];
3066 bState = btnPtr->fsState & TBSTATE_ENABLED;
3068 /* update the toolbar button state */
3069 if(LOWORD(lParam) == FALSE) {
3070 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3071 } else {
3072 btnPtr->fsState |= TBSTATE_ENABLED;
3075 /* redraw the button only if the state of the button changed */
3076 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3077 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3079 return TRUE;
3083 static inline LRESULT
3084 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3086 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3088 return infoPtr->bAnchor;
3092 static LRESULT
3093 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3095 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3096 INT nIndex;
3098 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3099 if (nIndex == -1)
3100 return -1;
3102 return infoPtr->buttons[nIndex].iBitmap;
3106 static inline LRESULT
3107 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3109 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3113 static LRESULT
3114 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3116 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3117 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3118 INT nIndex = (INT)wParam;
3119 TBUTTON_INFO *btnPtr;
3121 if (infoPtr == NULL)
3122 return FALSE;
3124 if (lpTbb == NULL)
3125 return FALSE;
3127 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3128 return FALSE;
3130 btnPtr = &infoPtr->buttons[nIndex];
3131 lpTbb->iBitmap = btnPtr->iBitmap;
3132 lpTbb->idCommand = btnPtr->idCommand;
3133 lpTbb->fsState = btnPtr->fsState;
3134 lpTbb->fsStyle = btnPtr->fsStyle;
3135 lpTbb->bReserved[0] = 0;
3136 lpTbb->bReserved[1] = 0;
3137 lpTbb->dwData = btnPtr->dwData;
3138 lpTbb->iString = btnPtr->iString;
3140 return TRUE;
3144 static LRESULT
3145 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3147 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3148 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3149 TBUTTON_INFO *btnPtr;
3150 INT nIndex;
3152 if (infoPtr == NULL)
3153 return -1;
3154 if (lpTbInfo == NULL)
3155 return -1;
3156 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3157 return -1;
3159 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3160 lpTbInfo->dwMask & 0x80000000);
3161 if (nIndex == -1)
3162 return -1;
3164 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3166 if (lpTbInfo->dwMask & TBIF_COMMAND)
3167 lpTbInfo->idCommand = btnPtr->idCommand;
3168 if (lpTbInfo->dwMask & TBIF_IMAGE)
3169 lpTbInfo->iImage = btnPtr->iBitmap;
3170 if (lpTbInfo->dwMask & TBIF_LPARAM)
3171 lpTbInfo->lParam = btnPtr->dwData;
3172 if (lpTbInfo->dwMask & TBIF_SIZE)
3173 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3174 if (lpTbInfo->dwMask & TBIF_STATE)
3175 lpTbInfo->fsState = btnPtr->fsState;
3176 if (lpTbInfo->dwMask & TBIF_STYLE)
3177 lpTbInfo->fsStyle = btnPtr->fsStyle;
3178 if (lpTbInfo->dwMask & TBIF_TEXT) {
3179 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3180 can't use TOOLBAR_GetText here */
3181 LPWSTR lpText;
3182 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3183 lpText = (LPWSTR)btnPtr->iString;
3184 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3185 } else
3186 lpTbInfo->pszText[0] = '\0';
3188 return nIndex;
3192 static LRESULT
3193 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3195 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3196 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3197 TBUTTON_INFO *btnPtr;
3198 INT nIndex;
3200 if (infoPtr == NULL)
3201 return -1;
3202 if (lpTbInfo == NULL)
3203 return -1;
3204 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3205 return -1;
3207 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3208 lpTbInfo->dwMask & 0x80000000);
3209 if (nIndex == -1)
3210 return -1;
3212 btnPtr = &infoPtr->buttons[nIndex];
3214 if(!btnPtr)
3215 return -1;
3217 if (lpTbInfo->dwMask & TBIF_COMMAND)
3218 lpTbInfo->idCommand = btnPtr->idCommand;
3219 if (lpTbInfo->dwMask & TBIF_IMAGE)
3220 lpTbInfo->iImage = btnPtr->iBitmap;
3221 if (lpTbInfo->dwMask & TBIF_LPARAM)
3222 lpTbInfo->lParam = btnPtr->dwData;
3223 if (lpTbInfo->dwMask & TBIF_SIZE)
3224 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3225 if (lpTbInfo->dwMask & TBIF_STATE)
3226 lpTbInfo->fsState = btnPtr->fsState;
3227 if (lpTbInfo->dwMask & TBIF_STYLE)
3228 lpTbInfo->fsStyle = btnPtr->fsStyle;
3229 if (lpTbInfo->dwMask & TBIF_TEXT) {
3230 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3231 can't use TOOLBAR_GetText here */
3232 LPWSTR lpText;
3233 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3234 lpText = (LPWSTR)btnPtr->iString;
3235 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3236 } else
3237 lpTbInfo->pszText[0] = '\0';
3240 return nIndex;
3244 static LRESULT
3245 TOOLBAR_GetButtonSize (HWND hwnd)
3247 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3249 if (infoPtr->nNumButtons > 0)
3250 return MAKELONG((WORD)infoPtr->nButtonWidth,
3251 (WORD)infoPtr->nButtonHeight);
3252 else
3253 return MAKELONG(8,7);
3257 static LRESULT
3258 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3260 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3261 INT nIndex;
3262 LPWSTR lpText;
3264 if (lParam == 0)
3265 return -1;
3267 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3268 if (nIndex == -1)
3269 return -1;
3271 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3273 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3274 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3278 static LRESULT
3279 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3281 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3282 INT nIndex;
3283 LPWSTR lpText;
3285 if (lParam == 0)
3286 return -1;
3288 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3289 if (nIndex == -1)
3290 return -1;
3292 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3294 strcpyW ((LPWSTR)lParam, lpText);
3296 return strlenW (lpText);
3300 static LRESULT
3301 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3303 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3304 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3305 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3309 inline static LRESULT
3310 TOOLBAR_GetExtendedStyle (HWND hwnd)
3312 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3314 TRACE("\n");
3316 return infoPtr->dwExStyle;
3320 static LRESULT
3321 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3323 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3324 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3325 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3329 static LRESULT
3330 TOOLBAR_GetHotItem (HWND hwnd)
3332 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3334 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
3335 return -1;
3337 if (infoPtr->nHotItem < 0)
3338 return -1;
3340 return (LRESULT)infoPtr->nHotItem;
3344 static LRESULT
3345 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3347 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3348 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3349 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3353 /* << TOOLBAR_GetInsertMark >> */
3354 /* << TOOLBAR_GetInsertMarkColor >> */
3357 static LRESULT
3358 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3360 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3361 TBUTTON_INFO *btnPtr;
3362 LPRECT lpRect;
3363 INT nIndex;
3365 if (infoPtr == NULL)
3366 return FALSE;
3367 nIndex = (INT)wParam;
3368 btnPtr = &infoPtr->buttons[nIndex];
3369 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3370 return FALSE;
3371 lpRect = (LPRECT)lParam;
3372 if (lpRect == NULL)
3373 return FALSE;
3374 if (btnPtr->fsState & TBSTATE_HIDDEN)
3375 return FALSE;
3377 lpRect->left = btnPtr->rect.left;
3378 lpRect->right = btnPtr->rect.right;
3379 lpRect->bottom = btnPtr->rect.bottom;
3380 lpRect->top = btnPtr->rect.top;
3382 return TRUE;
3386 static LRESULT
3387 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3389 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3390 LPSIZE lpSize = (LPSIZE)lParam;
3392 if (lpSize == NULL)
3393 return FALSE;
3395 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3396 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3398 TRACE("maximum size %ld x %ld\n",
3399 infoPtr->rcBound.right - infoPtr->rcBound.left,
3400 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3402 return TRUE;
3406 /* << TOOLBAR_GetObject >> */
3409 static LRESULT
3410 TOOLBAR_GetPadding (HWND hwnd)
3412 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3413 DWORD oldPad;
3415 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3416 return (LRESULT) oldPad;
3420 static LRESULT
3421 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3423 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3424 TBUTTON_INFO *btnPtr;
3425 LPRECT lpRect;
3426 INT nIndex;
3428 if (infoPtr == NULL)
3429 return FALSE;
3430 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3431 btnPtr = &infoPtr->buttons[nIndex];
3432 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3433 return FALSE;
3434 lpRect = (LPRECT)lParam;
3435 if (lpRect == NULL)
3436 return FALSE;
3438 lpRect->left = btnPtr->rect.left;
3439 lpRect->right = btnPtr->rect.right;
3440 lpRect->bottom = btnPtr->rect.bottom;
3441 lpRect->top = btnPtr->rect.top;
3443 return TRUE;
3447 static LRESULT
3448 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3450 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3452 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
3453 return infoPtr->nRows;
3454 else
3455 return 1;
3459 static LRESULT
3460 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3462 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3463 INT nIndex;
3465 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3466 if (nIndex == -1)
3467 return -1;
3469 return infoPtr->buttons[nIndex].fsState;
3473 static LRESULT
3474 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3476 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3477 INT nIndex;
3479 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3480 if (nIndex == -1)
3481 return -1;
3483 return infoPtr->buttons[nIndex].fsStyle;
3487 static LRESULT
3488 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3490 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3492 if (infoPtr == NULL)
3493 return 0;
3495 return infoPtr->nMaxTextRows;
3499 static LRESULT
3500 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3502 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3504 if (infoPtr == NULL)
3505 return 0;
3506 return (LRESULT)infoPtr->hwndToolTip;
3510 static LRESULT
3511 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3513 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3515 TRACE("%s hwnd=%p stub!\n",
3516 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3518 return infoPtr->bUnicode;
3522 inline static LRESULT
3523 TOOLBAR_GetVersion (HWND hwnd)
3525 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3526 return infoPtr->iVersion;
3530 static LRESULT
3531 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3533 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3534 TBUTTON_INFO *btnPtr;
3535 INT nIndex;
3537 TRACE("\n");
3539 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3540 if (nIndex == -1)
3541 return FALSE;
3543 btnPtr = &infoPtr->buttons[nIndex];
3544 if (LOWORD(lParam) == FALSE)
3545 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3546 else
3547 btnPtr->fsState |= TBSTATE_HIDDEN;
3549 TOOLBAR_CalcToolbar (hwnd);
3551 InvalidateRect (hwnd, NULL, TRUE);
3553 return TRUE;
3557 inline static LRESULT
3558 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3560 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3564 static LRESULT
3565 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3567 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3568 TBUTTON_INFO *btnPtr;
3569 INT nIndex;
3570 DWORD oldState;
3572 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3573 if (nIndex == -1)
3574 return FALSE;
3576 btnPtr = &infoPtr->buttons[nIndex];
3577 oldState = btnPtr->fsState;
3578 if (LOWORD(lParam) == FALSE)
3579 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3580 else
3581 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3583 if(oldState != btnPtr->fsState)
3584 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3586 return TRUE;
3590 static LRESULT
3591 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3593 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3594 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3595 INT nIndex = (INT)wParam;
3596 TBUTTON_INFO *oldButtons;
3598 if (lpTbb == NULL)
3599 return FALSE;
3601 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3603 if (nIndex == -1) {
3604 /* EPP: this seems to be an undocumented call (from my IE4)
3605 * I assume in that case that:
3606 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3607 * - index of insertion is at the end of existing buttons
3608 * I only see this happen with nIndex == -1, but it could have a special
3609 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3611 nIndex = infoPtr->nNumButtons;
3613 } else if (nIndex < 0)
3614 return FALSE;
3616 /* If the string passed is not an index, assume address of string
3617 and do our own AddString */
3618 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3619 LPSTR ptr;
3620 INT len;
3622 TRACE("string %s passed instead of index, adding string\n",
3623 debugstr_a((LPSTR)lpTbb->iString));
3624 len = strlen((LPSTR)lpTbb->iString) + 2;
3625 ptr = Alloc(len);
3626 strcpy(ptr, (LPSTR)lpTbb->iString);
3627 ptr[len - 1] = 0; /* ended by two '\0' */
3628 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3629 Free(ptr);
3632 TRACE("inserting button index=%d\n", nIndex);
3633 if (nIndex > infoPtr->nNumButtons) {
3634 nIndex = infoPtr->nNumButtons;
3635 TRACE("adjust index=%d\n", nIndex);
3638 oldButtons = infoPtr->buttons;
3639 infoPtr->nNumButtons++;
3640 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3641 /* pre insert copy */
3642 if (nIndex > 0) {
3643 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3644 nIndex * sizeof(TBUTTON_INFO));
3647 /* insert new button */
3648 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3649 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3650 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3651 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3652 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3653 /* if passed string and not index, then add string */
3654 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3655 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3657 else
3658 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3660 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3661 TTTOOLINFOA ti;
3663 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3664 ti.cbSize = sizeof (TTTOOLINFOA);
3665 ti.hwnd = hwnd;
3666 ti.uId = lpTbb->idCommand;
3667 ti.hinst = 0;
3668 ti.lpszText = LPSTR_TEXTCALLBACKA;
3670 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3671 0, (LPARAM)&ti);
3674 /* post insert copy */
3675 if (nIndex < infoPtr->nNumButtons - 1) {
3676 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3677 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3680 Free (oldButtons);
3682 TOOLBAR_CalcToolbar (hwnd);
3684 InvalidateRect (hwnd, NULL, TRUE);
3686 return TRUE;
3690 static LRESULT
3691 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3693 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3694 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3695 INT nIndex = (INT)wParam;
3696 TBUTTON_INFO *oldButtons;
3698 if (lpTbb == NULL)
3699 return FALSE;
3701 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3703 if (nIndex == -1) {
3704 /* EPP: this seems to be an undocumented call (from my IE4)
3705 * I assume in that case that:
3706 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3707 * - index of insertion is at the end of existing buttons
3708 * I only see this happen with nIndex == -1, but it could have a special
3709 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3711 nIndex = infoPtr->nNumButtons;
3713 } else if (nIndex < 0)
3714 return FALSE;
3716 /* If the string passed is not an index, assume address of string
3717 and do our own AddString */
3718 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3719 LPWSTR ptr;
3720 INT len;
3722 TRACE("string %s passed instead of index, adding string\n",
3723 debugstr_w((LPWSTR)lpTbb->iString));
3724 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3725 ptr = Alloc(len*sizeof(WCHAR));
3726 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3727 ptr[len - 1] = 0; /* ended by two '\0' */
3728 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3729 Free(ptr);
3732 TRACE("inserting button index=%d\n", nIndex);
3733 if (nIndex > infoPtr->nNumButtons) {
3734 nIndex = infoPtr->nNumButtons;
3735 TRACE("adjust index=%d\n", nIndex);
3738 oldButtons = infoPtr->buttons;
3739 infoPtr->nNumButtons++;
3740 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3741 /* pre insert copy */
3742 if (nIndex > 0) {
3743 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3744 nIndex * sizeof(TBUTTON_INFO));
3747 /* insert new button */
3748 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3749 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3750 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3751 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3752 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3753 /* if passed string and not index, then add string */
3754 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3755 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3757 else
3758 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3760 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3761 TTTOOLINFOW ti;
3763 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3764 ti.cbSize = sizeof (TTTOOLINFOW);
3765 ti.hwnd = hwnd;
3766 ti.uId = lpTbb->idCommand;
3767 ti.hinst = 0;
3768 ti.lpszText = LPSTR_TEXTCALLBACKW;
3770 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3771 0, (LPARAM)&ti);
3774 /* post insert copy */
3775 if (nIndex < infoPtr->nNumButtons - 1) {
3776 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3777 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3780 Free (oldButtons);
3782 TOOLBAR_CalcToolbar (hwnd);
3784 InvalidateRect (hwnd, NULL, TRUE);
3786 return TRUE;
3790 /* << TOOLBAR_InsertMarkHitTest >> */
3793 static LRESULT
3794 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3796 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3797 INT nIndex;
3799 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3800 if (nIndex == -1)
3801 return FALSE;
3803 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3807 static LRESULT
3808 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3810 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3811 INT nIndex;
3813 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3814 if (nIndex == -1)
3815 return FALSE;
3817 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3821 static LRESULT
3822 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3824 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3825 INT nIndex;
3827 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3828 if (nIndex == -1)
3829 return TRUE;
3831 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3835 static LRESULT
3836 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3838 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3839 INT nIndex;
3841 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3842 if (nIndex == -1)
3843 return FALSE;
3845 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3849 static LRESULT
3850 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3852 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3853 INT nIndex;
3855 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3856 if (nIndex == -1)
3857 return FALSE;
3859 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3863 static LRESULT
3864 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3866 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3867 INT nIndex;
3869 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3870 if (nIndex == -1)
3871 return FALSE;
3873 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3877 static LRESULT
3878 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3880 TBADDBITMAP tbab;
3881 tbab.hInst = (HINSTANCE)lParam;
3882 tbab.nID = (UINT_PTR)wParam;
3884 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3886 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3890 static LRESULT
3891 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3893 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3894 WCHAR wAccel = (WCHAR)wParam;
3895 UINT* pIDButton = (UINT*)lParam;
3896 WCHAR wszAccel[] = {'&',wAccel,0};
3897 int i;
3899 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3900 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3902 for (i = 0; i < infoPtr->nNumButtons; i++)
3904 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3905 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3906 !(btnPtr->fsState & TBSTATE_HIDDEN))
3908 int iLen = strlenW(wszAccel);
3909 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3911 if (!lpszStr)
3912 continue;
3914 while (*lpszStr)
3916 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3918 lpszStr += 2;
3919 continue;
3921 if (!strncmpiW(lpszStr, wszAccel, iLen))
3923 *pIDButton = btnPtr->idCommand;
3924 return TRUE;
3926 lpszStr++;
3930 return FALSE;
3934 static LRESULT
3935 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3937 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3938 INT nIndex;
3940 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3942 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3943 if (nIndex == -1)
3944 return FALSE;
3946 if (LOWORD(lParam))
3947 infoPtr->buttons[nIndex].fsState |= TBSTATE_MARKED;
3948 else
3949 infoPtr->buttons[nIndex].fsState &= ~TBSTATE_MARKED;
3951 return TRUE;
3954 /* << TOOLBAR_MoveButton >> */
3957 static LRESULT
3958 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3960 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3961 TBUTTON_INFO *btnPtr;
3962 INT nIndex;
3963 DWORD oldState;
3965 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3966 if (nIndex == -1)
3967 return FALSE;
3969 btnPtr = &infoPtr->buttons[nIndex];
3970 oldState = btnPtr->fsState;
3971 if (LOWORD(lParam) == FALSE)
3972 btnPtr->fsState &= ~TBSTATE_PRESSED;
3973 else
3974 btnPtr->fsState |= TBSTATE_PRESSED;
3976 if(oldState != btnPtr->fsState)
3977 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3979 return TRUE;
3982 /* FIXME: there might still be some confusion her between number of buttons
3983 * and number of bitmaps */
3984 static LRESULT
3985 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3987 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3988 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
3989 HBITMAP hBitmap;
3990 int i = 0, nOldButtons = 0, pos = 0;
3991 int nOldBitmaps, nNewBitmaps;
3992 HIMAGELIST himlDef = 0;
3994 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
3995 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
3996 lpReplace->nButtons);
3998 if (lpReplace->hInstOld == HINST_COMMCTRL)
4000 FIXME("changing standard bitmaps not implemented\n");
4001 return FALSE;
4003 else if (lpReplace->hInstOld != 0)
4005 FIXME("resources not in the current module not implemented\n");
4006 return FALSE;
4008 else
4010 hBitmap = (HBITMAP) lpReplace->nIDNew;
4013 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4014 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4015 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4016 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4017 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4019 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4020 nOldButtons = tbi->nButtons;
4021 tbi->nButtons = lpReplace->nButtons;
4022 tbi->hInst = lpReplace->hInstNew;
4023 tbi->nID = lpReplace->nIDNew;
4024 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4025 break;
4027 pos += tbi->nButtons;
4030 if (nOldButtons == 0)
4032 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4033 return FALSE;
4036 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4037 nOldBitmaps = ImageList_GetImageCount(himlDef);
4039 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4041 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4042 ImageList_Remove(himlDef, i);
4045 BITMAP bmp;
4046 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4047 HDC hdcImage, hdcBitmap;
4049 /* copy the bitmap before adding it so that the user's bitmap
4050 * doesn't get modified.
4052 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4054 hdcImage = CreateCompatibleDC(0);
4055 hdcBitmap = CreateCompatibleDC(0);
4057 /* create new bitmap */
4058 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4059 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4060 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4062 /* Copy the user's image */
4063 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4064 hdcBitmap, 0, 0, SRCCOPY);
4066 SelectObject (hdcImage, hOldBitmapLoad);
4067 SelectObject (hdcBitmap, hOldBitmapBitmap);
4068 DeleteDC (hdcImage);
4069 DeleteDC (hdcBitmap);
4071 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4072 nNewBitmaps = ImageList_GetImageCount(himlDef);
4073 DeleteObject (hbmLoad);
4076 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4078 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4079 pos, nOldBitmaps, nNewBitmaps);
4081 InvalidateRect(hwnd, NULL, TRUE);
4083 return TRUE;
4086 static LRESULT
4087 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4089 #if 0
4090 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4091 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
4093 if (lpSave == NULL) return 0;
4095 if ((BOOL)wParam) {
4096 /* save toolbar information */
4097 FIXME("save to \"%s\" \"%s\"\n",
4098 lpSave->pszSubKey, lpSave->pszValueName);
4102 else {
4103 /* restore toolbar information */
4105 FIXME("restore from \"%s\" \"%s\"\n",
4106 lpSave->pszSubKey, lpSave->pszValueName);
4110 #endif
4112 return 0;
4116 static LRESULT
4117 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4119 #if 0
4120 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4121 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
4123 if (lpSave == NULL)
4124 return 0;
4126 if ((BOOL)wParam) {
4127 /* save toolbar information */
4128 FIXME("save to \"%s\" \"%s\"\n",
4129 lpSave->pszSubKey, lpSave->pszValueName);
4133 else {
4134 /* restore toolbar information */
4136 FIXME("restore from \"%s\" \"%s\"\n",
4137 lpSave->pszSubKey, lpSave->pszValueName);
4141 #endif
4143 return 0;
4147 static LRESULT
4148 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4150 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4151 BOOL bOldAnchor = infoPtr->bAnchor;
4153 infoPtr->bAnchor = (BOOL)wParam;
4155 return (LRESULT)bOldAnchor;
4159 static LRESULT
4160 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4162 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4163 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4165 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4167 if (wParam != 0)
4168 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4170 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4171 return FALSE;
4173 if (infoPtr->nNumButtons > 0)
4174 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4175 infoPtr->nNumButtons,
4176 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4177 LOWORD(lParam), HIWORD(lParam));
4179 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4180 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4183 if ((himlDef == infoPtr->himlInt) &&
4184 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4186 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4187 infoPtr->nBitmapHeight);
4190 return TRUE;
4194 static LRESULT
4195 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4197 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4198 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4199 TBUTTON_INFO *btnPtr;
4200 INT nIndex;
4201 RECT oldBtnRect;
4203 if (lptbbi == NULL)
4204 return FALSE;
4205 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4206 return FALSE;
4208 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4209 lptbbi->dwMask & 0x80000000);
4210 if (nIndex == -1)
4211 return FALSE;
4213 btnPtr = &infoPtr->buttons[nIndex];
4214 if (lptbbi->dwMask & TBIF_COMMAND)
4215 btnPtr->idCommand = lptbbi->idCommand;
4216 if (lptbbi->dwMask & TBIF_IMAGE)
4217 btnPtr->iBitmap = lptbbi->iImage;
4218 if (lptbbi->dwMask & TBIF_LPARAM)
4219 btnPtr->dwData = lptbbi->lParam;
4220 if (lptbbi->dwMask & TBIF_SIZE)
4221 btnPtr->cx = lptbbi->cx;
4222 if (lptbbi->dwMask & TBIF_STATE)
4223 btnPtr->fsState = lptbbi->fsState;
4224 if (lptbbi->dwMask & TBIF_STYLE)
4225 btnPtr->fsStyle = lptbbi->fsStyle;
4227 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4228 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4229 /* iString is index, zero it to make Str_SetPtr succeed */
4230 btnPtr->iString=0;
4232 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4235 /* save the button rect to see if we need to redraw the whole toolbar */
4236 oldBtnRect = btnPtr->rect;
4237 TOOLBAR_CalcToolbar(hwnd);
4239 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4240 InvalidateRect(hwnd, NULL, TRUE);
4241 else
4242 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4244 return TRUE;
4248 static LRESULT
4249 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4251 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4252 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4253 TBUTTON_INFO *btnPtr;
4254 INT nIndex;
4255 RECT oldBtnRect;
4257 if (lptbbi == NULL)
4258 return FALSE;
4259 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4260 return FALSE;
4262 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4263 lptbbi->dwMask & 0x80000000);
4264 if (nIndex == -1)
4265 return FALSE;
4267 btnPtr = &infoPtr->buttons[nIndex];
4268 if (lptbbi->dwMask & TBIF_COMMAND)
4269 btnPtr->idCommand = lptbbi->idCommand;
4270 if (lptbbi->dwMask & TBIF_IMAGE)
4271 btnPtr->iBitmap = lptbbi->iImage;
4272 if (lptbbi->dwMask & TBIF_LPARAM)
4273 btnPtr->dwData = lptbbi->lParam;
4274 if (lptbbi->dwMask & TBIF_SIZE)
4275 btnPtr->cx = lptbbi->cx;
4276 if (lptbbi->dwMask & TBIF_STATE)
4277 btnPtr->fsState = lptbbi->fsState;
4278 if (lptbbi->dwMask & TBIF_STYLE)
4279 btnPtr->fsStyle = lptbbi->fsStyle;
4281 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4282 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4283 /* iString is index, zero it to make Str_SetPtr succeed */
4284 btnPtr->iString=0;
4285 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4288 /* save the button rect to see if we need to redraw the whole toolbar */
4289 oldBtnRect = btnPtr->rect;
4290 TOOLBAR_CalcToolbar(hwnd);
4292 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4293 InvalidateRect(hwnd, NULL, TRUE);
4294 else
4295 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4297 return TRUE;
4301 static LRESULT
4302 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4304 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4305 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4307 if ((cx < 0) || (cy < 0))
4309 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4310 return FALSE;
4313 /* The documentation claims you can only change the button size before
4314 * any button has been added. But this is wrong.
4315 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4316 * it to the toolbar, and it checks that the return value is nonzero - mjm
4317 * Further testing shows that we must actually perform the change too.
4320 * The documentation also does not mention that if 0 is supplied for
4321 * either size, the system changes it to the default of 24 wide and
4322 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4324 infoPtr->nButtonWidth = (cx) ? cx : 24;
4325 infoPtr->nButtonHeight = (cy) ? cy : 22;
4326 return TRUE;
4330 static LRESULT
4331 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4333 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4335 if (infoPtr == NULL) {
4336 TRACE("Toolbar not initialized yet?????\n");
4337 return FALSE;
4340 /* if setting to current values, ignore */
4341 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4342 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4343 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4344 infoPtr->cxMin, infoPtr->cxMax);
4345 return TRUE;
4348 /* save new values */
4349 infoPtr->cxMin = (INT)LOWORD(lParam);
4350 infoPtr->cxMax = (INT)HIWORD(lParam);
4352 /* if both values are 0 then we are done */
4353 if (lParam == 0) {
4354 TRACE("setting both min and max to 0, norecalc\n");
4355 return TRUE;
4358 /* otherwise we need to recalc the toolbar and in some cases
4359 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4360 which doesn't actually draw - GA). */
4361 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4362 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4364 TOOLBAR_CalcToolbar (hwnd);
4366 InvalidateRect (hwnd, NULL, TRUE);
4368 return TRUE;
4372 static LRESULT
4373 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4375 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4376 INT nIndex = (INT)wParam;
4378 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4379 return FALSE;
4381 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4383 if (infoPtr->hwndToolTip) {
4385 FIXME("change tool tip!\n");
4389 return TRUE;
4393 static LRESULT
4394 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4396 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4397 HIMAGELIST himl = (HIMAGELIST)lParam;
4398 HIMAGELIST himlTemp;
4399 INT id = 0;
4401 if (infoPtr->iVersion >= 5)
4402 id = wParam;
4404 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4405 &infoPtr->cimlDis, himl, id);
4407 /* FIXME: redraw ? */
4409 return (LRESULT)himlTemp;
4413 static LRESULT
4414 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4416 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4417 DWORD dwTemp;
4419 dwTemp = infoPtr->dwDTFlags;
4420 infoPtr->dwDTFlags =
4421 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4423 return (LRESULT)dwTemp;
4426 /* This function differs a bit from what MSDN says it does:
4427 * 1. lParam contains extended style flags to OR with current style
4428 * (MSDN isn't clear on the OR bit)
4429 * 2. wParam appears to contain extended style flags to be reset
4430 * (MSDN says that this parameter is reserved)
4432 static LRESULT
4433 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4435 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4436 DWORD dwTemp;
4438 dwTemp = infoPtr->dwExStyle;
4439 infoPtr->dwExStyle &= ~wParam;
4440 infoPtr->dwExStyle |= (DWORD)lParam;
4442 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4444 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4445 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4446 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4448 TOOLBAR_CalcToolbar (hwnd);
4450 TOOLBAR_AutoSize(hwnd);
4452 InvalidateRect(hwnd, NULL, TRUE);
4454 return (LRESULT)dwTemp;
4458 static LRESULT
4459 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4461 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4462 HIMAGELIST himlTemp;
4463 HIMAGELIST himl = (HIMAGELIST)lParam;
4464 INT id = 0;
4466 if (infoPtr->iVersion >= 5)
4467 id = wParam;
4469 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4471 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4472 &infoPtr->cimlHot, himl, id);
4474 /* FIXME: redraw ? */
4476 return (LRESULT)himlTemp;
4480 /* Makes previous hot button no longer hot, makes the specified
4481 * button hot and sends appropriate notifications. dwReason is one or
4482 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4483 * NOTE 1: this function does not validate nHit
4484 * NOTE 2: the name of this function is completely made up and
4485 * not based on any documentation from Microsoft. */
4486 static void
4487 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4489 if (infoPtr->nHotItem != nHit)
4491 NMTBHOTITEM nmhotitem;
4492 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4493 LRESULT no_highlight;
4495 /* Remove the effect of an old hot button if the button was
4496 drawn with the hot button effect */
4497 if(infoPtr->nHotItem >= 0)
4499 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4500 oldBtnPtr->bHot = FALSE;
4503 infoPtr->nHotItem = nHit;
4505 /* It's not a separator or in nowhere. It's a hot button. */
4506 if (nHit >= 0)
4507 btnPtr = &infoPtr->buttons[nHit];
4509 nmhotitem.dwFlags = dwReason;
4510 if (oldBtnPtr)
4511 nmhotitem.idOld = oldBtnPtr->idCommand;
4512 else
4513 nmhotitem.dwFlags |= HICF_ENTERING;
4514 if (btnPtr)
4515 nmhotitem.idNew = btnPtr->idCommand;
4516 else
4517 nmhotitem.dwFlags |= HICF_LEAVING;
4519 no_highlight = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4521 /* now invalidate the old and new buttons so they will be painted */
4522 if (oldBtnPtr)
4523 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4524 if (btnPtr && !no_highlight)
4526 btnPtr->bHot = TRUE;
4527 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4532 static LRESULT
4533 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4535 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4536 INT nOldHotItem = infoPtr->nHotItem;
4538 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4539 wParam = -2;
4541 if (GetWindowLongW(hwnd, GWL_STYLE) & TBSTYLE_FLAT)
4542 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4544 if (nOldHotItem < 0)
4545 return -1;
4547 return (LRESULT)nOldHotItem;
4551 static LRESULT
4552 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4554 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4555 HIMAGELIST himlTemp;
4556 HIMAGELIST himl = (HIMAGELIST)lParam;
4557 INT i, id = 0;
4559 if (infoPtr->iVersion >= 5)
4560 id = wParam;
4562 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4563 &infoPtr->cimlDef, himl, id);
4565 infoPtr->nNumBitmaps = 0;
4566 for (i = 0; i < infoPtr->cimlDef; i++)
4567 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4569 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4570 &infoPtr->nBitmapHeight);
4571 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4572 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4573 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4575 InvalidateRect(hwnd, NULL, TRUE);
4577 return (LRESULT)himlTemp;
4581 static LRESULT
4582 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4584 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4586 infoPtr->nIndent = (INT)wParam;
4588 TRACE("\n");
4590 /* process only on indent changing */
4591 if(infoPtr->nIndent != (INT)wParam)
4593 infoPtr->nIndent = (INT)wParam;
4594 TOOLBAR_CalcToolbar (hwnd);
4595 InvalidateRect(hwnd, NULL, FALSE);
4598 return TRUE;
4602 /* << TOOLBAR_SetInsertMark >> */
4605 static LRESULT
4606 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4608 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4610 infoPtr->clrInsertMark = (COLORREF)lParam;
4612 /* FIXME : redraw ??*/
4614 return 0;
4618 static LRESULT
4619 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4621 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4623 if (infoPtr == NULL)
4624 return FALSE;
4626 infoPtr->nMaxTextRows = (INT)wParam;
4628 TOOLBAR_CalcToolbar(hwnd);
4629 return TRUE;
4633 /* MSDN gives slightly wrong info on padding.
4634 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4635 * 2. It is not used to create a blank area between the edge of the button
4636 * and the text or image if TBSTYLE_LIST is set. It is used to control
4637 * the gap between the image and text.
4638 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4639 * to control the bottom and right borders [with the border being
4640 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4641 * is shared evenly on both sides of the button.
4643 static LRESULT
4644 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4646 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4647 DWORD oldPad;
4649 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4650 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4651 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4652 TRACE("cx=%ld, cy=%ld\n",
4653 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4654 return (LRESULT) oldPad;
4658 static LRESULT
4659 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4661 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4662 HWND hwndOldNotify;
4664 TRACE("\n");
4666 if (infoPtr == NULL)
4667 return 0;
4668 hwndOldNotify = infoPtr->hwndNotify;
4669 infoPtr->hwndNotify = (HWND)wParam;
4671 return (LRESULT)hwndOldNotify;
4675 static LRESULT
4676 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4678 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4679 LPRECT lprc = (LPRECT)lParam;
4681 TRACE("\n");
4683 if (LOWORD(wParam) > 1) {
4684 FIXME("multiple rows not supported!\n");
4687 if(infoPtr->nRows != LOWORD(wParam))
4689 infoPtr->nRows = LOWORD(wParam);
4691 /* recalculate toolbar */
4692 TOOLBAR_CalcToolbar (hwnd);
4694 /* repaint toolbar */
4695 InvalidateRect(hwnd, NULL, TRUE);
4698 /* return bounding rectangle */
4699 if (lprc) {
4700 lprc->left = infoPtr->rcBound.left;
4701 lprc->right = infoPtr->rcBound.right;
4702 lprc->top = infoPtr->rcBound.top;
4703 lprc->bottom = infoPtr->rcBound.bottom;
4706 return 0;
4710 static LRESULT
4711 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4713 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4714 TBUTTON_INFO *btnPtr;
4715 INT nIndex;
4717 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4718 if (nIndex == -1)
4719 return FALSE;
4721 btnPtr = &infoPtr->buttons[nIndex];
4723 /* if hidden state has changed the invalidate entire window and recalc */
4724 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4725 btnPtr->fsState = LOWORD(lParam);
4726 TOOLBAR_CalcToolbar (hwnd);
4727 InvalidateRect(hwnd, 0, TRUE);
4728 return TRUE;
4731 /* process state changing if current state doesn't match new state */
4732 if(btnPtr->fsState != LOWORD(lParam))
4734 btnPtr->fsState = LOWORD(lParam);
4735 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4738 return TRUE;
4742 static LRESULT
4743 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4745 SetWindowLongW(hwnd, GWL_STYLE, lParam);
4747 return TRUE;
4751 inline static LRESULT
4752 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4754 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4756 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
4758 if (infoPtr == NULL)
4759 return 0;
4760 infoPtr->hwndToolTip = (HWND)wParam;
4761 return 0;
4765 static LRESULT
4766 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4768 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4769 BOOL bTemp;
4771 TRACE("%s hwnd=%p stub!\n",
4772 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4774 bTemp = infoPtr->bUnicode;
4775 infoPtr->bUnicode = (BOOL)wParam;
4777 return bTemp;
4781 static LRESULT
4782 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4784 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4786 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4787 comctl32_color.clrBtnHighlight :
4788 infoPtr->clrBtnHighlight;
4789 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4790 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4791 return 1;
4795 static LRESULT
4796 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4798 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4800 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4801 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4802 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4804 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4805 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4806 InvalidateRect(hwnd, NULL, TRUE);
4807 return 0;
4811 static LRESULT
4812 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4814 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4815 INT iOldVersion = infoPtr->iVersion;
4817 infoPtr->iVersion = iVersion;
4819 if (infoPtr->iVersion >= 5)
4820 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
4822 return iOldVersion;
4826 static LRESULT
4827 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4829 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4830 WORD iString = HIWORD(wParam);
4831 WORD buffersize = LOWORD(wParam);
4832 LPSTR str = (LPSTR)lParam;
4833 LRESULT ret = -1;
4835 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
4837 if (iString < infoPtr->nNumStrings)
4839 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
4841 TRACE("returning %s\n", debugstr_a(str));
4843 else
4844 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4846 return ret;
4850 static LRESULT
4851 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4853 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4854 WORD iString = HIWORD(wParam);
4855 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
4856 LPWSTR str = (LPWSTR)lParam;
4857 LRESULT ret = -1;
4859 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
4861 if (iString < infoPtr->nNumStrings)
4863 len = min(len, strlenW(infoPtr->strings[iString]));
4864 ret = (len+1)*sizeof(WCHAR);
4865 memcpy(str, infoPtr->strings[iString], ret);
4866 str[len] = '\0';
4868 TRACE("returning %s\n", debugstr_w(str));
4870 else
4871 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4873 return ret;
4876 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
4877 * is the maximum size of the toolbar? */
4878 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
4880 SIZE * pSize = (SIZE*)lParam;
4881 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
4882 return 0;
4886 /* UNDOCUMENTED MESSAGE: This is an extended version of the
4887 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
4888 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
4889 * sends). */
4890 static LRESULT
4891 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
4893 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4894 INT nOldHotItem = infoPtr->nHotItem;
4896 TRACE("old item=%d, new item=%d, flags=%08lx\n",
4897 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
4899 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4900 wParam = -1;
4902 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
4904 GetFocus();
4906 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
4909 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
4910 * which controls the amount of spacing between the image and the text
4911 * of buttons for TBSTYLE_LIST toolbars. */
4912 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
4914 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4916 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
4918 if (lParam != 0)
4919 FIXME("lParam = 0x%08lx. Please report\n", lParam);
4921 infoPtr->iListGap = (INT)wParam;
4923 TOOLBAR_CalcToolbar(hwnd);
4924 InvalidateRect(hwnd, NULL, TRUE);
4926 return 0;
4929 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
4930 * of image lists associated with the various states. */
4931 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
4933 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4935 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
4937 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
4940 static LRESULT
4941 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
4943 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4944 LPSIZE lpsize = (LPSIZE)lParam;
4946 if (lpsize == NULL)
4947 return FALSE;
4950 * Testing shows the following:
4951 * wParam = 0 adjust cx value
4952 * = 1 set cy value to max size.
4953 * lParam pointer to SIZE structure
4956 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
4957 wParam, lParam, lpsize->cx, lpsize->cy);
4959 switch(wParam) {
4960 case 0:
4961 if (lpsize->cx == -1) {
4962 /* **** this is wrong, native measures each button and sets it */
4963 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4965 else if(HIWORD(lpsize->cx)) {
4966 RECT rc;
4967 HWND hwndParent = GetParent(hwnd);
4969 GetWindowRect(hwnd, &rc);
4970 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
4971 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
4972 rc.left, rc.top, rc.right, rc.bottom);
4973 lpsize->cx = max(rc.right-rc.left,
4974 infoPtr->rcBound.right - infoPtr->rcBound.left);
4976 else {
4977 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4979 break;
4980 case 1:
4981 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
4982 /* lpsize->cy = infoPtr->nHeight; */
4983 break;
4984 default:
4985 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
4986 wParam);
4987 return 0;
4989 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
4990 lpsize->cx, lpsize->cy);
4991 return 1;
4994 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
4996 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
4998 InvalidateRect(hwnd, NULL, TRUE);
4999 return 1;
5003 static LRESULT
5004 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5006 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5007 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5008 LOGFONTA logFont;
5010 TRACE("hwnd = %p\n", hwnd);
5012 /* initialize info structure */
5013 infoPtr->nButtonHeight = 22;
5014 infoPtr->nButtonWidth = 24;
5015 infoPtr->nBitmapHeight = 15;
5016 infoPtr->nBitmapWidth = 16;
5018 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
5019 infoPtr->nMaxTextRows = 1;
5020 infoPtr->cxMin = -1;
5021 infoPtr->cxMax = -1;
5022 infoPtr->nNumBitmaps = 0;
5023 infoPtr->nNumStrings = 0;
5025 infoPtr->bCaptured = FALSE;
5026 infoPtr->bUnicode = IsWindowUnicode (hwnd);
5027 infoPtr->nButtonDown = -1;
5028 infoPtr->nOldHit = -1;
5029 infoPtr->nHotItem = -1;
5030 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5031 infoPtr->bTransparent = (dwStyle & TBSTYLE_TRANSPARENT);
5032 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5033 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
5034 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5035 infoPtr->iVersion = 0;
5036 infoPtr->hwndSelf = hwnd;
5037 infoPtr->bDoRedraw = TRUE;
5038 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5039 infoPtr->clrBtnShadow = CLR_DEFAULT;
5040 /* not sure where the +1 comes from, but this comes to the same value
5041 * as native so this is probably correct */
5042 infoPtr->szPadding.cx = 2*(GetSystemMetrics(SM_CXEDGE)+OFFSET_X) + 1;
5043 infoPtr->szPadding.cy = 2*(GetSystemMetrics(SM_CYEDGE)+OFFSET_Y);
5044 infoPtr->iListGap = infoPtr->szPadding.cx / 2;
5045 GetClientRect(hwnd, &infoPtr->client_rect);
5046 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
5048 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5049 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
5051 if (dwStyle & TBSTYLE_TOOLTIPS) {
5052 /* Create tooltip control */
5053 infoPtr->hwndToolTip =
5054 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
5055 CW_USEDEFAULT, CW_USEDEFAULT,
5056 CW_USEDEFAULT, CW_USEDEFAULT,
5057 hwnd, 0, 0, 0);
5059 /* Send NM_TOOLTIPSCREATED notification */
5060 if (infoPtr->hwndToolTip) {
5061 NMTOOLTIPSCREATED nmttc;
5063 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5065 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
5066 NM_TOOLTIPSCREATED);
5070 TOOLBAR_CheckStyle (hwnd, dwStyle);
5072 TOOLBAR_CalcToolbar(hwnd);
5074 return 0;
5078 static LRESULT
5079 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5081 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5083 /* delete tooltip control */
5084 if (infoPtr->hwndToolTip)
5085 DestroyWindow (infoPtr->hwndToolTip);
5087 /* delete temporary buffer for tooltip text */
5088 if (infoPtr->pszTooltipText)
5089 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5091 /* delete button data */
5092 if (infoPtr->buttons)
5093 Free (infoPtr->buttons);
5095 /* delete strings */
5096 if (infoPtr->strings) {
5097 INT i;
5098 for (i = 0; i < infoPtr->nNumStrings; i++)
5099 if (infoPtr->strings[i])
5100 Free (infoPtr->strings[i]);
5102 Free (infoPtr->strings);
5105 /* destroy internal image list */
5106 if (infoPtr->himlInt)
5107 ImageList_Destroy (infoPtr->himlInt);
5109 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5110 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5111 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5113 /* delete default font */
5114 if (infoPtr->hFont)
5115 DeleteObject (infoPtr->hDefaultFont);
5117 /* free toolbar info data */
5118 Free (infoPtr);
5119 SetWindowLongA (hwnd, 0, 0);
5121 return 0;
5125 static LRESULT
5126 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5128 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5129 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5130 NMTBCUSTOMDRAW tbcd;
5131 INT ret = FALSE;
5132 DWORD ntfret;
5134 if (dwStyle & TBSTYLE_CUSTOMERASE) {
5135 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5136 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5137 tbcd.nmcd.hdc = (HDC)wParam;
5138 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5139 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5141 /* FIXME: in general the return flags *can* be or'ed together */
5142 switch (infoPtr->dwBaseCustDraw)
5144 case CDRF_DODEFAULT:
5145 break;
5146 case CDRF_SKIPDEFAULT:
5147 return TRUE;
5148 default:
5149 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5150 hwnd, ntfret);
5154 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5155 * to my parent for processing.
5157 if (infoPtr->bTransparent) {
5158 POINT pt, ptorig;
5159 HDC hdc = (HDC)wParam;
5160 HWND parent;
5162 pt.x = 0;
5163 pt.y = 0;
5164 parent = GetParent(hwnd);
5165 MapWindowPoints(hwnd, parent, &pt, 1);
5166 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5167 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
5168 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5170 if (!ret)
5171 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
5173 if ((dwStyle & TBSTYLE_CUSTOMERASE) &&
5174 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5175 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5176 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5177 tbcd.nmcd.hdc = (HDC)wParam;
5178 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5179 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5180 switch (infoPtr->dwBaseCustDraw)
5182 case CDRF_DODEFAULT:
5183 break;
5184 case CDRF_SKIPDEFAULT:
5185 return TRUE;
5186 default:
5187 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5188 hwnd, ntfret);
5191 return ret;
5195 static LRESULT
5196 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5198 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5200 return (LRESULT)infoPtr->hFont;
5204 static LRESULT
5205 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5207 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5208 TBUTTON_INFO *btnPtr;
5209 POINT pt;
5210 INT nHit;
5212 pt.x = (INT)LOWORD(lParam);
5213 pt.y = (INT)HIWORD(lParam);
5214 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5216 if (nHit >= 0) {
5217 btnPtr = &infoPtr->buttons[nHit];
5218 if (!(btnPtr->fsState & TBSTATE_ENABLED))
5219 return 0;
5220 SetCapture (hwnd);
5221 infoPtr->bCaptured = TRUE;
5222 infoPtr->nButtonDown = nHit;
5224 btnPtr->fsState |= TBSTATE_PRESSED;
5226 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5228 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5229 TOOLBAR_Customize (hwnd);
5231 return 0;
5235 static LRESULT
5236 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5238 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5239 TBUTTON_INFO *btnPtr;
5240 POINT pt;
5241 INT nHit;
5242 NMTOOLBARA nmtb;
5244 if (infoPtr->hwndToolTip)
5245 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5246 WM_LBUTTONDOWN, wParam, lParam);
5248 pt.x = (INT)LOWORD(lParam);
5249 pt.y = (INT)HIWORD(lParam);
5250 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5252 btnPtr = &infoPtr->buttons[nHit];
5254 if (nHit >= 0) {
5255 RECT arrowRect;
5256 infoPtr->nOldHit = nHit;
5258 CopyRect(&arrowRect, &btnPtr->rect);
5259 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5261 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5262 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5263 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5264 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5265 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5266 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5268 LRESULT res;
5270 /* draw in pressed state */
5271 btnPtr->fsState |= TBSTATE_PRESSED;
5272 RedrawWindow(hwnd,&btnPtr->rect,0,
5273 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5275 nmtb.iItem = btnPtr->idCommand;
5276 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
5277 nmtb.cchText = 0;
5278 nmtb.pszText = 0;
5279 CopyRect(&nmtb.rcButton, &btnPtr->rect);
5280 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5281 TBN_DROPDOWN);
5282 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5284 if (res != TBDDRET_TREATPRESSED)
5286 MSG msg;
5288 /* redraw button in unpressed state */
5289 btnPtr->fsState &= ~TBSTATE_PRESSED;
5290 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5292 /* find and set hot item
5293 * NOTE: native doesn't do this, but that is a bug */
5294 GetCursorPos(&pt);
5295 ScreenToClient(hwnd, &pt);
5296 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5297 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5299 /* remove any left mouse button down messages so that we can
5300 * get a toggle effect on the button */
5301 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE))
5304 return 0;
5306 /* otherwise drop through and process as pushed */
5308 infoPtr->bCaptured = TRUE;
5309 infoPtr->nButtonDown = nHit;
5311 btnPtr->fsState |= TBSTATE_PRESSED;
5313 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5315 if (btnPtr->fsState & TBSTATE_ENABLED)
5316 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5317 UpdateWindow(hwnd);
5318 SetCapture (hwnd);
5320 /* native issues the TBN_BEGINDRAG here */
5321 nmtb.iItem = btnPtr->idCommand;
5322 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5323 nmtb.tbButton.idCommand = btnPtr->idCommand;
5324 nmtb.tbButton.fsState = btnPtr->fsState;
5325 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5326 nmtb.tbButton.dwData = btnPtr->dwData;
5327 nmtb.tbButton.iString = btnPtr->iString;
5328 nmtb.cchText = 0; /* !!! not correct */
5329 nmtb.pszText = 0; /* !!! not correct */
5330 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5331 TBN_BEGINDRAG);
5334 return 0;
5337 static LRESULT
5338 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5340 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5341 TBUTTON_INFO *btnPtr;
5342 POINT pt;
5343 INT nHit;
5344 INT nOldIndex = -1;
5345 BOOL bSendMessage = TRUE;
5346 NMHDR hdr;
5347 NMMOUSE nmmouse;
5348 NMTOOLBARA nmtb;
5350 if (infoPtr->hwndToolTip)
5351 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5352 WM_LBUTTONUP, wParam, lParam);
5354 pt.x = (INT)LOWORD(lParam);
5355 pt.y = (INT)HIWORD(lParam);
5356 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5358 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5360 if (0 <= infoPtr->nButtonDown) {
5361 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5362 btnPtr->fsState &= ~TBSTATE_PRESSED;
5364 if (btnPtr->fsStyle & BTNS_CHECK) {
5365 if (btnPtr->fsStyle & BTNS_GROUP) {
5366 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5367 nHit);
5368 if (nOldIndex == nHit)
5369 bSendMessage = FALSE;
5370 if ((nOldIndex != nHit) &&
5371 (nOldIndex != -1))
5372 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5373 btnPtr->fsState |= TBSTATE_CHECKED;
5375 else {
5376 if (btnPtr->fsState & TBSTATE_CHECKED)
5377 btnPtr->fsState &= ~TBSTATE_CHECKED;
5378 else
5379 btnPtr->fsState |= TBSTATE_CHECKED;
5383 if (nOldIndex != -1)
5384 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5387 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5388 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5389 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5391 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5392 ReleaseCapture ();
5393 infoPtr->nButtonDown = -1;
5395 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5396 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5397 NM_RELEASEDCAPTURE);
5399 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5400 * TBN_BEGINDRAG
5402 nmtb.iItem = btnPtr->idCommand;
5403 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5404 nmtb.tbButton.idCommand = btnPtr->idCommand;
5405 nmtb.tbButton.fsState = btnPtr->fsState;
5406 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5407 nmtb.tbButton.dwData = btnPtr->dwData;
5408 nmtb.tbButton.iString = btnPtr->iString;
5409 nmtb.cchText = 0; /* !!! not correct */
5410 nmtb.pszText = 0; /* !!! not correct */
5411 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5412 TBN_ENDDRAG);
5414 if (btnPtr->fsState & TBSTATE_ENABLED)
5416 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
5417 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5419 /* !!! Undocumented - toolbar at 4.71 level and above sends
5420 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
5421 * Only NM_RCLICK is documented.
5423 nmmouse.dwItemSpec = btnPtr->idCommand;
5424 nmmouse.dwItemData = btnPtr->dwData;
5425 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr, NM_CLICK);
5428 return 0;
5431 static LRESULT
5432 TOOLBAR_CaptureChanged(HWND hwnd)
5434 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5435 TBUTTON_INFO *btnPtr;
5437 infoPtr->bCaptured = FALSE;
5439 if (infoPtr->nButtonDown >= 0)
5441 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5442 btnPtr->fsState &= ~TBSTATE_PRESSED;
5444 infoPtr->nOldHit = -1;
5446 if (btnPtr->fsState & TBSTATE_ENABLED)
5447 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5449 return 0;
5452 static LRESULT
5453 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5455 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5456 TBUTTON_INFO *hotBtnPtr, *btnPtr;
5457 RECT rc1;
5459 TOOLBAR_SetHotItemEx(infoPtr, -1, HICF_MOUSE);
5461 if (infoPtr->nOldHit < 0)
5462 return TRUE;
5464 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5466 /* If the last button we were over is depressed then make it not */
5467 /* depressed and redraw it */
5468 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5470 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5472 btnPtr->fsState &= ~TBSTATE_PRESSED;
5474 rc1 = hotBtnPtr->rect;
5475 InflateRect (&rc1, 1, 1);
5476 InvalidateRect (hwnd, &rc1, TRUE);
5479 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5481 return TRUE;
5484 static LRESULT
5485 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5487 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5488 POINT pt;
5489 TRACKMOUSEEVENT trackinfo;
5490 INT nHit;
5491 TBUTTON_INFO *btnPtr;
5493 /* fill in the TRACKMOUSEEVENT struct */
5494 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5495 trackinfo.dwFlags = TME_QUERY;
5496 trackinfo.hwndTrack = hwnd;
5497 trackinfo.dwHoverTime = HOVER_DEFAULT;
5499 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5500 _TrackMouseEvent(&trackinfo);
5502 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5503 if(!(trackinfo.dwFlags & TME_LEAVE)) {
5504 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5506 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5507 /* and can properly deactivate the hot toolbar button */
5508 _TrackMouseEvent(&trackinfo);
5511 if (infoPtr->hwndToolTip)
5512 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5513 WM_MOUSEMOVE, wParam, lParam);
5515 pt.x = (INT)LOWORD(lParam);
5516 pt.y = (INT)HIWORD(lParam);
5518 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5520 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
5522 if (infoPtr->nOldHit != nHit)
5524 if (infoPtr->bCaptured)
5526 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5527 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5528 btnPtr->fsState &= ~TBSTATE_PRESSED;
5529 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5531 else if (nHit == infoPtr->nButtonDown) {
5532 btnPtr->fsState |= TBSTATE_PRESSED;
5533 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5535 infoPtr->nOldHit = nHit;
5539 return 0;
5543 inline static LRESULT
5544 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5546 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5547 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5548 /* else */
5549 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5553 inline static LRESULT
5554 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5556 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
5557 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5559 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5563 static LRESULT
5564 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5566 TOOLBAR_INFO *infoPtr;
5567 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5568 DWORD styleadd = 0;
5570 /* allocate memory for info structure */
5571 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
5572 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
5574 /* paranoid!! */
5575 infoPtr->dwStructSize = sizeof(TBBUTTON);
5576 infoPtr->nRows = 1;
5578 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5579 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
5580 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
5581 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
5584 /* native control does:
5585 * Get a lot of colors and brushes
5586 * WM_NOTIFYFORMAT
5587 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5588 * CreateFontIndirectA(adr1)
5589 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5590 * hdc = GetDC(toolbar)
5591 * GetSystemMetrics(0x48)
5592 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5593 * 0, 0, 0, 0, "MARLETT")
5594 * oldfnt = SelectObject(hdc, fnt2)
5595 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5596 * GetTextMetricsA(hdc, adr3)
5597 * SelectObject(hdc, oldfnt)
5598 * DeleteObject(fnt2)
5599 * ReleaseDC(hdc)
5600 * InvalidateRect(toolbar, 0, 1)
5601 * SetWindowLongA(toolbar, 0, addr)
5602 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5603 * WM_STYLECHANGING
5604 * CallWinEx old new
5605 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5606 * ie 2 0x4600094c 0x4600094c 0x4600894d
5607 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5608 * rebar 0x50008844 0x40008844 0x50008845
5609 * pager 0x50000844 0x40000844 0x50008845
5610 * IC35mgr 0x5400084e **nochange**
5611 * on entry to _NCCREATE 0x5400084e
5612 * rowlist 0x5400004e **nochange**
5613 * on entry to _NCCREATE 0x5400004e
5617 /* I think the code below is a bug, but it is the way that the native
5618 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5619 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5620 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5621 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5622 * Some how, the only cases of this seem to be MFC programs.
5624 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5625 * does not occur in the WM_STYLECHANGING routine.
5626 * (Guy Albertelli 9/2001)
5629 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5630 styleadd |= TBSTYLE_TRANSPARENT;
5631 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5632 styleadd |= CCS_TOP; /* default to top */
5633 SetWindowLongA (hwnd, GWL_STYLE, cs->style | styleadd);
5636 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5640 static LRESULT
5641 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5643 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5644 RECT rcWindow;
5645 HDC hdc;
5647 if (dwStyle & WS_MINIMIZE)
5648 return 0; /* Nothing to do */
5650 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5652 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5653 return 0;
5655 if (!(dwStyle & CCS_NODIVIDER))
5657 GetWindowRect (hwnd, &rcWindow);
5658 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5659 if( dwStyle & WS_BORDER )
5660 OffsetRect (&rcWindow, 1, 1);
5661 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5664 ReleaseDC( hwnd, hdc );
5666 return 0;
5670 /* handles requests from the tooltip control on what text to display */
5671 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
5673 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
5675 TRACE("button index = %d\n", index);
5677 if (infoPtr->pszTooltipText)
5679 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5680 infoPtr->pszTooltipText = NULL;
5683 if (index < 0)
5684 return 0;
5686 if (infoPtr->bNtfUnicode)
5688 WCHAR wszBuffer[INFOTIPSIZE+1];
5689 NMTBGETINFOTIPW tbgit;
5690 int len; /* in chars */
5692 wszBuffer[0] = '\0';
5693 wszBuffer[INFOTIPSIZE] = '\0';
5695 tbgit.pszText = wszBuffer;
5696 tbgit.cchTextMax = INFOTIPSIZE;
5697 tbgit.iItem = lpnmtdi->hdr.idFrom;
5698 tbgit.lParam = infoPtr->buttons[index].dwData;
5700 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
5702 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
5704 len = strlenW(tbgit.pszText);
5705 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5707 /* need to allocate temporary buffer in infoPtr as there
5708 * isn't enough space in buffer passed to us by the
5709 * tooltip control */
5710 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5711 if (infoPtr->pszTooltipText)
5713 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
5714 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5715 return 0;
5718 else if (len > 0)
5720 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
5721 return 0;
5724 else
5726 CHAR szBuffer[INFOTIPSIZE+1];
5727 NMTBGETINFOTIPA tbgit;
5728 int len; /* in chars */
5730 szBuffer[0] = '\0';
5731 szBuffer[INFOTIPSIZE] = '\0';
5733 tbgit.pszText = szBuffer;
5734 tbgit.cchTextMax = INFOTIPSIZE;
5735 tbgit.iItem = lpnmtdi->hdr.idFrom;
5736 tbgit.lParam = infoPtr->buttons[index].dwData;
5738 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
5740 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
5742 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
5743 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5745 /* need to allocate temporary buffer in infoPtr as there
5746 * isn't enough space in buffer passed to us by the
5747 * tooltip control */
5748 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5749 if (infoPtr->pszTooltipText)
5751 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
5752 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5753 return 0;
5756 else if (len > 0)
5758 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
5759 return 0;
5763 /* if button has text, but it is not shown then automatically
5764 * use that text as tooltip */
5765 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
5766 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
5768 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
5769 int len = pszText ? strlenW(pszText) : 0;
5771 TRACE("using button hidden text %s\n", debugstr_w(pszText));
5773 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5775 /* need to allocate temporary buffer in infoPtr as there
5776 * isn't enough space in buffer passed to us by the
5777 * tooltip control */
5778 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5779 if (infoPtr->pszTooltipText)
5781 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
5782 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5783 return 0;
5786 else if (len > 0)
5788 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
5789 return 0;
5793 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
5795 /* last resort: send notification on to app */
5796 /* FIXME: find out what is really used here */
5797 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
5801 inline static LRESULT
5802 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
5804 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5805 LPNMHDR lpnmh = (LPNMHDR)lParam;
5807 switch (lpnmh->code)
5809 case PGN_CALCSIZE:
5811 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
5813 if (lppgc->dwFlag == PGF_CALCWIDTH) {
5814 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
5815 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
5816 lppgc->iWidth);
5818 else {
5819 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5820 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
5821 lppgc->iHeight);
5823 return 0;
5826 case PGN_SCROLL:
5828 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
5830 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
5831 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
5832 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
5833 lppgs->iScroll, lppgs->iDir);
5834 return 0;
5837 case TTN_GETDISPINFOW:
5838 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
5840 case TTN_GETDISPINFOA:
5841 FIXME("TTN_GETDISPINFOA - stub\n");
5842 return 0;
5844 default:
5845 return 0;
5850 static LRESULT
5851 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
5853 /* remove this routine when Toolbar is improved to pass infoPtr
5854 * around instead of hwnd.
5856 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5857 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
5861 static LRESULT
5862 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5864 INT i;
5866 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
5868 if ((lParam == NF_QUERY) && ((HWND)wParam == infoPtr->hwndToolTip))
5869 return NFR_UNICODE;
5871 if (lParam == NF_REQUERY) {
5872 i = SendMessageA(infoPtr->hwndNotify,
5873 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
5874 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
5875 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
5877 i = NFR_ANSI;
5879 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
5880 return (LRESULT)i;
5882 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
5886 static LRESULT
5887 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
5889 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5890 HDC hdc;
5891 PAINTSTRUCT ps;
5893 /* fill ps.rcPaint with a default rect */
5894 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
5896 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
5898 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
5899 ps.rcPaint.left, ps.rcPaint.top,
5900 ps.rcPaint.right, ps.rcPaint.bottom);
5902 TOOLBAR_Refresh (hwnd, hdc, &ps);
5903 if (!wParam) EndPaint (hwnd, &ps);
5905 return 0;
5909 static LRESULT
5910 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
5911 /*****************************************************
5913 * Function;
5914 * Handles the WM_SETREDRAW message.
5916 * Documentation:
5917 * According to testing V4.71 of COMCTL32 returns the
5918 * *previous* status of the redraw flag (either 0 or 1)
5919 * instead of the MSDN documented value of 0 if handled.
5920 * (For laughs see the "consistency" with same function
5921 * in rebar.)
5923 *****************************************************/
5925 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5926 BOOL oldredraw = infoPtr->bDoRedraw;
5928 TRACE("set to %s\n",
5929 (wParam) ? "TRUE" : "FALSE");
5930 infoPtr->bDoRedraw = (BOOL) wParam;
5931 if (wParam) {
5932 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
5934 return (oldredraw) ? 1 : 0;
5938 static LRESULT
5939 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
5941 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5942 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5943 RECT parent_rect;
5944 RECT window_rect;
5945 HWND parent;
5946 INT x, y;
5947 INT cx, cy;
5948 INT flags;
5949 UINT uPosFlags = 0;
5951 /* Resize deadlock check */
5952 if (infoPtr->bAutoSize) {
5953 infoPtr->bAutoSize = FALSE;
5954 return 0;
5957 /* FIXME: optimize to only update size if the new size doesn't */
5958 /* match the current size */
5960 flags = (INT) wParam;
5962 /* FIXME for flags =
5963 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
5966 TRACE("sizing toolbar!\n");
5968 if (flags == SIZE_RESTORED) {
5969 /* width and height don't apply */
5970 parent = GetParent (hwnd);
5971 GetClientRect(parent, &parent_rect);
5972 x = parent_rect.left;
5973 y = parent_rect.top;
5975 if (dwStyle & CCS_NORESIZE) {
5976 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
5979 * this sets the working width of the toolbar, and
5980 * Calc Toolbar will not adjust it, only the height
5982 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5983 cy = infoPtr->nHeight;
5984 cx = infoPtr->nWidth;
5985 TOOLBAR_CalcToolbar (hwnd);
5986 infoPtr->nWidth = cx;
5987 infoPtr->nHeight = cy;
5989 else {
5990 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5991 TOOLBAR_CalcToolbar (hwnd);
5992 cy = infoPtr->nHeight;
5993 cx = infoPtr->nWidth;
5995 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
5996 GetWindowRect(hwnd, &window_rect);
5997 ScreenToClient(parent, (LPPOINT)&window_rect.left);
5998 y = window_rect.top;
6000 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
6001 GetWindowRect(hwnd, &window_rect);
6002 y = parent_rect.bottom -
6003 ( window_rect.bottom - window_rect.top);
6007 if (dwStyle & CCS_NOPARENTALIGN) {
6008 uPosFlags |= SWP_NOMOVE;
6009 cy = infoPtr->nHeight;
6010 cx = infoPtr->nWidth;
6013 if (!(dwStyle & CCS_NODIVIDER))
6014 cy += GetSystemMetrics(SM_CYEDGE);
6016 if (dwStyle & WS_BORDER)
6018 x = y = 1;
6019 cy += GetSystemMetrics(SM_CYEDGE);
6020 cx += GetSystemMetrics(SM_CYEDGE);
6023 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6025 RECT delta_width, delta_height, client, dummy;
6026 DWORD min_x, max_x, min_y, max_y;
6027 TBUTTON_INFO *btnPtr;
6028 INT i;
6030 GetClientRect(hwnd, &client);
6031 if(client.right > infoPtr->client_rect.right)
6033 min_x = infoPtr->client_rect.right;
6034 max_x = client.right;
6036 else
6038 max_x = infoPtr->client_rect.right;
6039 min_x = client.right;
6041 if(client.bottom > infoPtr->client_rect.bottom)
6043 min_y = infoPtr->client_rect.bottom;
6044 max_y = client.bottom;
6046 else
6048 max_y = infoPtr->client_rect.bottom;
6049 min_y = client.bottom;
6052 SetRect(&delta_width, min_x, 0, max_x, min_y);
6053 SetRect(&delta_height, 0, min_y, max_x, max_y);
6055 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6056 btnPtr = infoPtr->buttons;
6057 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6058 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6059 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6060 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6063 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) == (SWP_NOSIZE | SWP_NOMOVE))
6064 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6066 GetClientRect(hwnd, &infoPtr->client_rect);
6067 return 0;
6071 static LRESULT
6072 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6074 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6076 if (nType == GWL_STYLE) {
6077 if (lpStyle->styleNew & TBSTYLE_LIST) {
6078 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
6080 else {
6081 infoPtr->dwDTFlags = DT_CENTER;
6083 infoPtr->bTransparent = (lpStyle->styleNew & TBSTYLE_TRANSPARENT);
6084 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6085 (TBSTYLE_FLAT | TBSTYLE_LIST));
6086 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6088 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6091 TOOLBAR_CalcToolbar(hwnd);
6093 TOOLBAR_AutoSize (hwnd);
6095 InvalidateRect(hwnd, NULL, TRUE);
6097 return 0;
6101 static LRESULT
6102 TOOLBAR_SysColorChange (HWND hwnd)
6104 COMCTL32_RefreshSysColors();
6106 return 0;
6111 static LRESULT WINAPI
6112 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6114 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6116 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6117 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6119 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
6120 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
6122 switch (uMsg)
6124 case TB_ADDBITMAP:
6125 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6127 case TB_ADDBUTTONSA:
6128 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6130 case TB_ADDBUTTONSW:
6131 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6133 case TB_ADDSTRINGA:
6134 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6136 case TB_ADDSTRINGW:
6137 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6139 case TB_AUTOSIZE:
6140 return TOOLBAR_AutoSize (hwnd);
6142 case TB_BUTTONCOUNT:
6143 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6145 case TB_BUTTONSTRUCTSIZE:
6146 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6148 case TB_CHANGEBITMAP:
6149 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6151 case TB_CHECKBUTTON:
6152 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6154 case TB_COMMANDTOINDEX:
6155 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6157 case TB_CUSTOMIZE:
6158 return TOOLBAR_Customize (hwnd);
6160 case TB_DELETEBUTTON:
6161 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6163 case TB_ENABLEBUTTON:
6164 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6166 case TB_GETANCHORHIGHLIGHT:
6167 return TOOLBAR_GetAnchorHighlight (hwnd);
6169 case TB_GETBITMAP:
6170 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6172 case TB_GETBITMAPFLAGS:
6173 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6175 case TB_GETBUTTON:
6176 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6178 case TB_GETBUTTONINFOA:
6179 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6181 case TB_GETBUTTONINFOW:
6182 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6184 case TB_GETBUTTONSIZE:
6185 return TOOLBAR_GetButtonSize (hwnd);
6187 case TB_GETBUTTONTEXTA:
6188 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6190 case TB_GETBUTTONTEXTW:
6191 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6193 case TB_GETDISABLEDIMAGELIST:
6194 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6196 case TB_GETEXTENDEDSTYLE:
6197 return TOOLBAR_GetExtendedStyle (hwnd);
6199 case TB_GETHOTIMAGELIST:
6200 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6202 case TB_GETHOTITEM:
6203 return TOOLBAR_GetHotItem (hwnd);
6205 case TB_GETIMAGELIST:
6206 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6208 /* case TB_GETINSERTMARK: */ /* 4.71 */
6209 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
6211 case TB_GETITEMRECT:
6212 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6214 case TB_GETMAXSIZE:
6215 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6217 /* case TB_GETOBJECT: */ /* 4.71 */
6219 case TB_GETPADDING:
6220 return TOOLBAR_GetPadding (hwnd);
6222 case TB_GETRECT:
6223 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6225 case TB_GETROWS:
6226 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6228 case TB_GETSTATE:
6229 return TOOLBAR_GetState (hwnd, wParam, lParam);
6231 case TB_GETSTRINGA:
6232 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6234 case TB_GETSTRINGW:
6235 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6237 case TB_GETSTYLE:
6238 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6240 case TB_GETTEXTROWS:
6241 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6243 case TB_GETTOOLTIPS:
6244 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6246 case TB_GETUNICODEFORMAT:
6247 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6249 case TB_HIDEBUTTON:
6250 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6252 case TB_HITTEST:
6253 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6255 case TB_INDETERMINATE:
6256 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6258 case TB_INSERTBUTTONA:
6259 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6261 case TB_INSERTBUTTONW:
6262 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6264 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6266 case TB_ISBUTTONCHECKED:
6267 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6269 case TB_ISBUTTONENABLED:
6270 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6272 case TB_ISBUTTONHIDDEN:
6273 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6275 case TB_ISBUTTONHIGHLIGHTED:
6276 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6278 case TB_ISBUTTONINDETERMINATE:
6279 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6281 case TB_ISBUTTONPRESSED:
6282 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6284 case TB_LOADIMAGES:
6285 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6287 case TB_MAPACCELERATORA:
6288 case TB_MAPACCELERATORW:
6289 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6291 case TB_MARKBUTTON:
6292 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6294 /* case TB_MOVEBUTTON: */ /* 4.71 */
6296 case TB_PRESSBUTTON:
6297 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6299 case TB_REPLACEBITMAP:
6300 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6302 case TB_SAVERESTOREA:
6303 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
6305 case TB_SAVERESTOREW:
6306 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
6308 case TB_SETANCHORHIGHLIGHT:
6309 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6311 case TB_SETBITMAPSIZE:
6312 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6314 case TB_SETBUTTONINFOA:
6315 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6317 case TB_SETBUTTONINFOW:
6318 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6320 case TB_SETBUTTONSIZE:
6321 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6323 case TB_SETBUTTONWIDTH:
6324 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6326 case TB_SETCMDID:
6327 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6329 case TB_SETDISABLEDIMAGELIST:
6330 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6332 case TB_SETDRAWTEXTFLAGS:
6333 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6335 case TB_SETEXTENDEDSTYLE:
6336 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6338 case TB_SETHOTIMAGELIST:
6339 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6341 case TB_SETHOTITEM:
6342 return TOOLBAR_SetHotItem (hwnd, wParam);
6344 case TB_SETIMAGELIST:
6345 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6347 case TB_SETINDENT:
6348 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6350 /* case TB_SETINSERTMARK: */ /* 4.71 */
6352 case TB_SETINSERTMARKCOLOR:
6353 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6355 case TB_SETMAXTEXTROWS:
6356 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6358 case TB_SETPADDING:
6359 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6361 case TB_SETPARENT:
6362 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6364 case TB_SETROWS:
6365 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6367 case TB_SETSTATE:
6368 return TOOLBAR_SetState (hwnd, wParam, lParam);
6370 case TB_SETSTYLE:
6371 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6373 case TB_SETTOOLTIPS:
6374 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6376 case TB_SETUNICODEFORMAT:
6377 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6379 case TB_UNKWN45D:
6380 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6382 case TB_UNKWN45E:
6383 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6385 case TB_UNKWN460:
6386 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6388 case TB_UNKWN462:
6389 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6391 case TB_UNKWN463:
6392 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6394 case TB_UNKWN464:
6395 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6397 /* Common Control Messages */
6399 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6400 case CCM_GETCOLORSCHEME:
6401 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6403 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6404 case CCM_SETCOLORSCHEME:
6405 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6407 case CCM_GETVERSION:
6408 return TOOLBAR_GetVersion (hwnd);
6410 case CCM_SETVERSION:
6411 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6414 /* case WM_CHAR: */
6416 case WM_CREATE:
6417 return TOOLBAR_Create (hwnd, wParam, lParam);
6419 case WM_DESTROY:
6420 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6422 case WM_ERASEBKGND:
6423 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6425 case WM_GETFONT:
6426 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6428 /* case WM_KEYDOWN: */
6429 /* case WM_KILLFOCUS: */
6431 case WM_LBUTTONDBLCLK:
6432 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6434 case WM_LBUTTONDOWN:
6435 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6437 case WM_LBUTTONUP:
6438 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6440 case WM_MOUSEMOVE:
6441 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6443 case WM_MOUSELEAVE:
6444 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6446 case WM_CAPTURECHANGED:
6447 return TOOLBAR_CaptureChanged(hwnd);
6449 case WM_NCACTIVATE:
6450 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6452 case WM_NCCALCSIZE:
6453 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6455 case WM_NCCREATE:
6456 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6458 case WM_NCPAINT:
6459 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6461 case WM_NOTIFY:
6462 return TOOLBAR_Notify (hwnd, wParam, lParam);
6464 case WM_NOTIFYFORMAT:
6465 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
6467 case WM_PAINT:
6468 return TOOLBAR_Paint (hwnd, wParam);
6470 case WM_SETREDRAW:
6471 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6473 case WM_SIZE:
6474 return TOOLBAR_Size (hwnd, wParam, lParam);
6476 case WM_STYLECHANGED:
6477 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6479 case WM_SYSCOLORCHANGE:
6480 return TOOLBAR_SysColorChange (hwnd);
6482 /* case WM_WININICHANGE: */
6484 case WM_CHARTOITEM:
6485 case WM_COMMAND:
6486 case WM_DRAWITEM:
6487 case WM_MEASUREITEM:
6488 case WM_VKEYTOITEM:
6489 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
6491 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6492 case PGM_FORWARDMOUSE:
6493 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6495 default:
6496 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6497 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6498 uMsg, wParam, lParam);
6499 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6501 return 0;
6505 VOID
6506 TOOLBAR_Register (void)
6508 WNDCLASSA wndClass;
6510 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
6511 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6512 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
6513 wndClass.cbClsExtra = 0;
6514 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6515 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
6516 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
6517 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
6519 RegisterClassA (&wndClass);
6523 VOID
6524 TOOLBAR_Unregister (void)
6526 UnregisterClassA (TOOLBARCLASSNAMEA, NULL);
6529 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6531 HIMAGELIST himlold;
6532 PIMLENTRY c = NULL;
6534 /* Check if the entry already exists */
6535 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6537 /* If this is a new entry we must create it and insert into the array */
6538 if (!c)
6540 PIMLENTRY *pnies;
6542 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
6543 c->id = id;
6545 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
6546 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6547 pnies[*cies] = c;
6548 (*cies)++;
6550 Free(*pies);
6551 *pies = pnies;
6554 himlold = c->himl;
6555 c->himl = himl;
6557 return himlold;
6561 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6563 int i;
6565 for (i = 0; i < *cies; i++)
6566 Free((*pies)[i]);
6568 Free(*pies);
6570 *cies = 0;
6571 *pies = NULL;
6575 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
6577 PIMLENTRY c = NULL;
6579 if (pies != NULL)
6581 int i;
6583 for (i = 0; i < cies; i++)
6585 if (pies[i]->id == id)
6587 c = pies[i];
6588 break;
6593 return c;
6597 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
6599 HIMAGELIST himlDef = 0;
6600 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6602 if (pie)
6603 himlDef = pie->himl;
6605 return himlDef;
6609 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6611 if (infoPtr->bUnicode)
6612 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
6613 else
6615 CHAR Buffer[256];
6616 NMTOOLBARA nmtba;
6617 BOOL bRet = FALSE;
6619 nmtba.iItem = nmtb->iItem;
6620 nmtba.pszText = Buffer;
6621 nmtba.cchText = 256;
6622 ZeroMemory(nmtba.pszText, nmtba.cchText);
6624 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
6626 int ccht = strlen(nmtba.pszText);
6627 if (ccht)
6628 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
6629 nmtb->pszText, nmtb->cchText);
6631 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
6632 bRet = TRUE;
6635 return bRet;
6640 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
6641 int iItem, PCUSTOMBUTTON btnInfo)
6643 NMTOOLBARA nmtb;
6645 nmtb.iItem = iItem;
6646 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
6648 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE);