Correct errors with move to kernel time functions.
[wine/multimedia.git] / dlls / comctl32 / toolbar.c
blobebb184b694483cf136f075b6cef2ff13f9638de2
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_REGISTERDROP
43 * - TBSTYLE_EX_DOUBLEBUFFER
44 * - Messages:
45 * - TB_GETINSERTMARK
46 * - TB_GETINSERTMARKCOLOR
47 * - TB_GETMETRICS
48 * - TB_GETOBJECT
49 * - TB_INSERTMARKHITTEST
50 * - TB_SETINSERTMARK
51 * - TB_SETMETRICS
52 * - Notifications:
53 * - NM_CHAR
54 * - NM_KEYDOWN
55 * - NM_RCLICK
56 * - NM_RDBLCLICK
57 * - TBN_DRAGOUT
58 * - TBN_GETOBJECT
59 * - TBN_RESTORE
60 * - TBN_SAVE
61 * - Button wrapping (under construction).
62 * - Fix TB_SETROWS.
63 * - iListGap custom draw support.
64 * - Customization dialog:
65 * - Minor buglet in 'available buttons' list:
66 * Buttons are not listed in MS-like order. MS seems to use a single
67 * internal list to store the button information of both listboxes.
68 * - Drag list support.
70 * Testing:
71 * - Run tests using Waite Group Windows95 API Bible Volume 2.
72 * The second cdrom contains executables addstr.exe, btncount.exe,
73 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
74 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
75 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
76 * setparnt.exe, setrows.exe, toolwnd.exe.
77 * - Microsofts controlspy examples.
78 * - Charles Petzold's 'Programming Windows': gadgets.exe
81 #include <stdarg.h>
82 #include <string.h>
84 #include "windef.h"
85 #include "winbase.h"
86 #include "wingdi.h"
87 #include "winuser.h"
88 #include "wine/unicode.h"
89 #include "winnls.h"
90 #include "commctrl.h"
91 #include "comctl32.h"
92 #include "wine/debug.h"
94 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
96 static HCURSOR hCursorDrag = NULL;
98 typedef struct
100 INT iBitmap;
101 INT idCommand;
102 BYTE fsState;
103 BYTE fsStyle;
104 DWORD dwData;
105 INT iString;
106 BOOL bHot;
107 INT nRow;
108 RECT rect;
109 INT cx; /* manually set size */
110 } TBUTTON_INFO;
112 typedef struct
114 UINT nButtons;
115 HINSTANCE hInst;
116 UINT nID;
117 } TBITMAP_INFO;
119 typedef struct
121 HIMAGELIST himl;
122 INT id;
123 } IMLENTRY, *PIMLENTRY;
125 typedef struct
127 DWORD dwStructSize; /* size of TBBUTTON struct */
128 INT nHeight; /* height of the toolbar */
129 INT nWidth; /* width of the toolbar */
130 RECT client_rect;
131 INT nButtonHeight;
132 INT nButtonWidth;
133 INT nBitmapHeight;
134 INT nBitmapWidth;
135 INT nIndent;
136 INT nRows; /* number of button rows */
137 INT nMaxTextRows; /* maximum number of text rows */
138 INT cxMin; /* minimum button width */
139 INT cxMax; /* maximum button width */
140 INT nNumButtons; /* number of buttons */
141 INT nNumBitmaps; /* number of bitmaps */
142 INT nNumStrings; /* number of strings */
143 INT nNumBitmapInfos;
144 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
145 BOOL bCaptured; /* mouse captured? */
146 INT nButtonDown; /* toolbar button being pressed or -1 if none */
147 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
148 INT nOldHit;
149 INT nHotItem; /* index of the "hot" item */
150 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
151 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
152 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
153 SIZE szPadding; /* padding values around button */
154 INT iListGap; /* default gap between text and image for toolbar with list style */
155 HFONT hDefaultFont;
156 HFONT hFont; /* text font */
157 HIMAGELIST himlInt; /* image list created internally */
158 PIMLENTRY *himlDef; /* default image list array */
159 INT cimlDef; /* default image list array count */
160 PIMLENTRY *himlHot; /* hot image list array */
161 INT cimlHot; /* hot image list array count */
162 PIMLENTRY *himlDis; /* disabled image list array */
163 INT cimlDis; /* disabled image list array count */
164 HWND hwndToolTip; /* handle to tool tip control */
165 HWND hwndNotify; /* handle to the window that gets notifications */
166 HWND hwndSelf; /* my own handle */
167 BOOL bTransparent; /* background transparency flag */
168 BOOL bBtnTranspnt; /* button transparency flag */
169 BOOL bAutoSize; /* auto size deadlock indicator */
170 BOOL bAnchor; /* anchor highlight enabled */
171 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
172 BOOL bDoRedraw; /* Redraw status */
173 DWORD dwExStyle; /* extended toolbar style */
174 DWORD dwDTFlags; /* DrawText flags */
176 COLORREF clrInsertMark; /* insert mark color */
177 COLORREF clrBtnHighlight; /* color for Flat Separator */
178 COLORREF clrBtnShadow; /* color for Flag Separator */
179 RECT rcBound; /* bounding rectangle */
180 INT iVersion;
181 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
182 * for TTN_GETDISPINFOW notification */
183 TBUTTON_INFO *buttons; /* pointer to button array */
184 LPWSTR *strings; /* pointer to string array */
185 TBITMAP_INFO *bitmaps;
186 } TOOLBAR_INFO, *PTOOLBAR_INFO;
189 /* used by customization dialog */
190 typedef struct
192 PTOOLBAR_INFO tbInfo;
193 HWND tbHwnd;
194 } CUSTDLG_INFO, *PCUSTDLG_INFO;
196 typedef struct
198 TBBUTTON btn;
199 BOOL bVirtual;
200 BOOL bRemovable;
201 WCHAR text[64];
202 } CUSTOMBUTTON, *PCUSTOMBUTTON;
204 typedef enum
206 IMAGE_LIST_DEFAULT,
207 IMAGE_LIST_HOT,
208 IMAGE_LIST_DISABLED
209 } IMAGE_LIST_TYPE;
211 #define SEPARATOR_WIDTH 8
212 #define TOP_BORDER 2
213 #define BOTTOM_BORDER 2
214 #define DDARROW_WIDTH 11
215 #define ARROW_HEIGHT 3
217 /* gap between border of button and text/image */
218 #define OFFSET_X 1
219 #define OFFSET_Y 1
220 /* how wide to treat the bitmap if it isn't present */
221 #define LIST_IMAGE_ABSENT_WIDTH 2
223 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
224 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
225 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
227 static inline int TOOLBAR_GetListTextOffset(TOOLBAR_INFO *infoPtr, INT iListGap)
229 return GetSystemMetrics(SM_CXEDGE) + iListGap - infoPtr->szPadding.cx/2;
232 /* Used to find undocumented extended styles */
233 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
234 TBSTYLE_EX_UNDOC1 | \
235 TBSTYLE_EX_MIXEDBUTTONS | \
236 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
238 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
239 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
240 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
241 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
242 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
244 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
245 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
246 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
247 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
248 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
249 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
251 static LRESULT
252 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
255 static LPWSTR
256 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
258 LPWSTR lpText = NULL;
260 /* NOTE: iString == -1 is undocumented */
261 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
262 lpText = (LPWSTR)btnPtr->iString;
263 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
264 lpText = infoPtr->strings[btnPtr->iString];
266 return lpText;
269 static void
270 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
272 if (TRACE_ON(toolbar)){
273 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
274 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
275 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
276 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
277 if (internal)
278 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
279 btn_num, bP->idCommand,
280 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
281 bP->rect.left, bP->rect.top,
282 bP->rect.right, bP->rect.bottom);
287 static void
288 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
290 if (TRACE_ON(toolbar)) {
291 INT i;
292 DWORD dwStyle;
294 dwStyle = GetWindowLongA (iP->hwndSelf, GWL_STYLE);
295 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
296 iP->hwndSelf, line,
297 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
298 iP->nNumStrings, dwStyle);
299 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
300 iP->hwndSelf, line,
301 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
302 (iP->bDoRedraw) ? "TRUE" : "FALSE");
303 for(i=0; i<iP->nNumButtons; i++) {
304 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
310 /***********************************************************************
311 * TOOLBAR_CheckStyle
313 * This function validates that the styles set are implemented and
314 * issues FIXME's warning of possible problems. In a perfect world this
315 * function should be null.
317 static void
318 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
320 if (dwStyle & TBSTYLE_REGISTERDROP)
321 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
325 static INT
326 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
328 if(!IsWindow(infoPtr->hwndSelf))
329 return 0; /* we have just been destroyed */
331 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
332 nmhdr->hwndFrom = infoPtr->hwndSelf;
333 nmhdr->code = code;
335 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
336 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
338 if (infoPtr->bNtfUnicode)
339 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
340 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
341 else
342 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
343 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
346 /***********************************************************************
347 * TOOLBAR_GetBitmapIndex
349 * This function returns the bitmap index associated with a button.
350 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
351 * is issued to retrieve the index.
353 static INT
354 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
356 INT ret = btnPtr->iBitmap;
358 if (ret == I_IMAGECALLBACK) {
359 /* issue TBN_GETDISPINFO */
360 NMTBDISPINFOA nmgd;
362 nmgd.idCommand = btnPtr->idCommand;
363 nmgd.lParam = btnPtr->dwData;
364 nmgd.dwMask = TBNF_IMAGE;
365 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
366 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
367 TBN_GETDISPINFOA);
368 if (nmgd.dwMask & TBNF_DI_SETITEM) {
369 btnPtr->iBitmap = nmgd.iImage;
371 ret = nmgd.iImage;
372 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
373 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
376 if (ret != I_IMAGENONE)
377 ret = GETIBITMAP(infoPtr, ret);
379 return ret;
383 static BOOL
384 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
386 HIMAGELIST himl;
387 INT id = GETHIMLID(infoPtr, index);
388 INT iBitmap = GETIBITMAP(infoPtr, index);
390 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
391 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
392 (index == I_IMAGECALLBACK))
393 return TRUE;
394 else
395 return FALSE;
399 /***********************************************************************
400 * TOOLBAR_GetImageListForDrawing
402 * This function validates the bitmap index (including I_IMAGECALLBACK
403 * functionality) and returns the corresponding image list.
405 static HIMAGELIST
406 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
408 HIMAGELIST himl;
410 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
411 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
412 ERR("index %d,%d is not valid, max %d\n",
413 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
414 return NULL;
417 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
418 if ((*index == I_IMAGECALLBACK) ||
419 (*index == I_IMAGENONE)) return NULL;
420 ERR("TBN_GETDISPINFO returned invalid index %d\n",
421 *index);
422 return NULL;
425 switch(imagelist)
427 case IMAGE_LIST_DEFAULT:
428 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
429 break;
430 case IMAGE_LIST_HOT:
431 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
432 break;
433 case IMAGE_LIST_DISABLED:
434 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
435 break;
436 default:
437 himl = NULL;
438 FIXME("Shouldn't reach here\n");
441 if (!himl)
442 TRACE("no image list\n");
444 return himl;
448 /***********************************************************************
449 * TOOLBAR_TestImageExist
451 * This function is similar to TOOLBAR_GetImageListForDrawing, except it does not
452 * return the image list. The I_IMAGECALLBACK functionality is implemented.
454 static BOOL
455 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
457 INT index;
459 if (!himl) return FALSE;
461 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
462 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
463 ERR("index %d is not valid, max %d\n",
464 btnPtr->iBitmap, infoPtr->nNumBitmaps);
465 return FALSE;
468 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
469 if ((index == I_IMAGECALLBACK) ||
470 (index == I_IMAGENONE)) return FALSE;
471 ERR("TBN_GETDISPINFO returned invalid index %d\n",
472 index);
473 return FALSE;
475 return TRUE;
479 static void
480 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
482 RECT myrect;
483 COLORREF oldcolor, newcolor;
485 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
486 myrect.right = myrect.left + 1;
487 myrect.top = lpRect->top + 2;
488 myrect.bottom = lpRect->bottom - 2;
490 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
491 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
492 oldcolor = SetBkColor (hdc, newcolor);
493 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
495 myrect.left = myrect.right;
496 myrect.right = myrect.left + 1;
498 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
499 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
500 SetBkColor (hdc, newcolor);
501 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
503 SetBkColor (hdc, oldcolor);
507 /***********************************************************************
508 * TOOLBAR_DrawDDFlatSeparator
510 * This function draws the separator that was flagged as BTNS_DROPDOWN.
511 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
512 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
513 * are horizontal as opposed to the vertical separators for not dropdown
514 * type.
516 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
518 static void
519 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
521 RECT myrect;
522 COLORREF oldcolor, newcolor;
524 myrect.left = lpRect->left;
525 myrect.right = lpRect->right;
526 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
527 myrect.bottom = myrect.top + 1;
529 InflateRect (&myrect, -2, 0);
531 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
532 myrect.left, myrect.top, myrect.right, myrect.bottom);
534 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
535 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
536 oldcolor = SetBkColor (hdc, newcolor);
537 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
539 myrect.top = myrect.bottom;
540 myrect.bottom = myrect.top + 1;
542 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
543 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
544 SetBkColor (hdc, newcolor);
545 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
547 SetBkColor (hdc, oldcolor);
551 static void
552 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
554 INT x, y;
555 HPEN hPen, hOldPen;
557 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
558 hOldPen = SelectObject ( hdc, hPen );
559 x = left + 2;
560 y = top;
561 MoveToEx (hdc, x, y, NULL);
562 LineTo (hdc, x+5, y++); x++;
563 MoveToEx (hdc, x, y, NULL);
564 LineTo (hdc, x+3, y++); x++;
565 MoveToEx (hdc, x, y, NULL);
566 LineTo (hdc, x+1, y++);
567 SelectObject( hdc, hOldPen );
568 DeleteObject( hPen );
572 * Draw the text string for this button.
573 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
574 * is non-zero, so we can simply check himlDef to see if we have
575 * an image list
577 static void
578 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
579 NMTBCUSTOMDRAW *tbcd)
581 HDC hdc = tbcd->nmcd.hdc;
582 HFONT hOldFont = 0;
583 COLORREF clrOld = 0;
584 COLORREF clrOldBk = 0;
585 int oldBkMode = 0;
586 UINT state = tbcd->nmcd.uItemState;
588 /* draw text */
589 if (lpText) {
590 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
591 rcText->left, rcText->top, rcText->right, rcText->bottom);
593 hOldFont = SelectObject (hdc, infoPtr->hFont);
594 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
595 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
597 else if (state & CDIS_DISABLED) {
598 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
599 OffsetRect (rcText, 1, 1);
600 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
601 SetTextColor (hdc, comctl32_color.clr3dShadow);
602 OffsetRect (rcText, -1, -1);
604 else if (state & CDIS_INDETERMINATE) {
605 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
607 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
608 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
609 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
610 oldBkMode = SetBkMode (hdc, OPAQUE); /* FIXME: should this be in the NMTBCUSTOMDRAW structure? */
612 else {
613 clrOld = SetTextColor (hdc, tbcd->clrText);
616 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
617 SetTextColor (hdc, clrOld);
618 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
620 SetBkColor (hdc, clrOldBk);
621 SetBkMode (hdc, oldBkMode);
623 SelectObject (hdc, hOldFont);
628 static void
629 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
631 HDC hdc = tbcd->nmcd.hdc;
632 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
633 COLORREF clrTextOld;
634 COLORREF clrBkOld;
635 INT cx = lpRect->right - lpRect->left;
636 INT cy = lpRect->bottom - lpRect->top;
637 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
638 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
639 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, PATCOPY);
640 SetBkColor(hdc, clrBkOld);
641 SetTextColor(hdc, clrTextOld);
642 SelectObject (hdc, hbr);
646 static void TOOLBAR_DrawMasked(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
647 HDC hdc, INT x, INT y)
649 int index;
650 HIMAGELIST himl =
651 TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
653 if (himl)
655 INT cx, cy;
656 HBITMAP hbmMask, hbmImage;
657 HDC hdcMask, hdcImage;
659 ImageList_GetIconSize(himl, &cx, &cy);
661 /* Create src image */
662 hdcImage = CreateCompatibleDC(hdc);
663 hbmImage = CreateBitmap(cx, cy, GetDeviceCaps(hdc,PLANES),
664 GetDeviceCaps(hdc,BITSPIXEL), NULL);
665 SelectObject(hdcImage, hbmImage);
666 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
667 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_NORMAL);
669 /* Create Mask */
670 hdcMask = CreateCompatibleDC(0);
671 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
672 SelectObject(hdcMask, hbmMask);
674 /* Remove the background and all white pixels */
675 SetBkColor(hdcImage, ImageList_GetBkColor(himl));
676 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, SRCCOPY);
677 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
678 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
680 /* draw the new mask 'etched' to hdc */
681 SetBkColor(hdc, RGB(255, 255, 255));
682 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
683 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
684 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
685 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
686 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
688 /* Cleanup */
689 DeleteObject(hbmImage);
690 DeleteDC(hdcImage);
691 DeleteObject (hbmMask);
692 DeleteDC(hdcMask);
697 static UINT
698 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
700 UINT retstate = 0;
702 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
703 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
704 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
705 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
706 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
707 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
708 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
709 return retstate;
712 /* draws the image on a toolbar button */
713 static void
714 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
716 HIMAGELIST himl = NULL;
717 BOOL draw_masked = FALSE;
718 INT index;
719 INT offset = 0;
720 UINT draw_flags = ILD_NORMAL;
722 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
724 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
725 if (!himl)
726 draw_masked = TRUE;
728 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && (GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & TBSTYLE_FLAT))
730 /* if hot, attempt to draw with hot image list, if fails,
731 use default image list */
732 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
733 if (!himl)
734 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
736 else
737 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
739 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
740 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
741 offset = 1;
743 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
744 (tbcd->nmcd.uItemState & CDIS_MARKED))
745 draw_flags |= ILD_BLEND50;
747 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
748 index, himl, left, top, offset);
750 if (draw_masked)
751 TOOLBAR_DrawMasked (infoPtr, btnPtr, tbcd->nmcd.hdc, left + offset, top + offset);
752 else if (himl)
753 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
756 /* draws a blank frame for a toolbar button */
757 static void
758 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd)
760 HDC hdc = tbcd->nmcd.hdc;
761 RECT rc = tbcd->nmcd.rc;
762 /* if the state is disabled or indeterminate then the button
763 * cannot have an interactive look like pressed or hot */
764 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
765 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
766 BOOL pressed_look = !non_interactive_state &&
767 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
768 (tbcd->nmcd.uItemState & CDIS_CHECKED));
770 /* app don't want us to draw any edges */
771 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
772 return;
774 if (flat)
776 if (pressed_look)
777 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
778 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
779 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
781 else
783 if (pressed_look)
784 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
785 else
786 DrawEdge (hdc, &rc, EDGE_RAISED,
787 BF_SOFT | BF_RECT | BF_MIDDLE);
791 static void
792 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow)
794 HDC hdc = tbcd->nmcd.hdc;
795 int offset = 0;
797 if (flat)
799 if ((tbcd->nmcd.uItemState & CDIS_SELECTED) || (tbcd->nmcd.uItemState & CDIS_CHECKED))
800 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
801 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
802 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
803 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
804 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
806 else
808 if ((tbcd->nmcd.uItemState & CDIS_SELECTED) || (tbcd->nmcd.uItemState & CDIS_CHECKED))
809 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
810 else
811 DrawEdge (hdc, rcArrow, EDGE_RAISED,
812 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
815 if (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
816 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
818 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
820 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
821 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
823 else
824 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
827 /* draws a complete toolbar button */
828 static void
829 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
831 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
832 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
833 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
834 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
835 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
836 BOOL drawSepDropDownArrow = hasDropDownArrow &&
837 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
838 RECT rc, rcArrow, rcBitmap, rcText;
839 LPWSTR lpText = NULL;
840 NMTBCUSTOMDRAW tbcd;
841 DWORD ntfret;
842 INT offset;
844 rc = btnPtr->rect;
845 CopyRect (&rcArrow, &rc);
846 CopyRect(&rcBitmap, &rc);
848 /* get a pointer to the text */
849 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
851 if (hasDropDownArrow)
853 int right;
855 if (dwStyle & TBSTYLE_FLAT)
856 right = max(rc.left, rc.right - DDARROW_WIDTH);
857 else
858 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
860 if (drawSepDropDownArrow)
861 rc.right = right;
863 rcArrow.left = right;
866 /* copy text rect after adjusting for drop-down arrow
867 * so that text is centred in the rectangle not containing
868 * the arrow */
869 CopyRect(&rcText, &rc);
871 /* Center the bitmap horizontally and vertically */
872 if (dwStyle & TBSTYLE_LIST)
873 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
874 else
875 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
877 if(lpText)
878 rcBitmap.top+= GetSystemMetrics(SM_CYEDGE) + OFFSET_Y;
879 else
880 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
882 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n",
883 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
884 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
885 TRACE ("iString: %x\n", btnPtr->iString);
886 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
888 /* draw text */
889 if (lpText) {
890 rcText.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
891 rcText.right -= GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
892 if (GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,btnPtr->iBitmap)) &&
893 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
895 if (dwStyle & TBSTYLE_LIST)
896 rcText.left += infoPtr->nBitmapWidth + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
897 else
898 rcText.top += GetSystemMetrics(SM_CYEDGE) + OFFSET_Y + infoPtr->nBitmapHeight + infoPtr->szPadding.cy/2;
900 else
901 if (dwStyle & TBSTYLE_LIST)
902 rcText.left += LIST_IMAGE_ABSENT_WIDTH + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
904 if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
905 OffsetRect (&rcText, 1, 1);
908 /* Initialize fields in all cases, because we use these later
909 * NOTE: applications can and do alter these to customize their
910 * toolbars */
911 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
912 tbcd.clrText = comctl32_color.clrBtnText;
913 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
914 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
915 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
916 tbcd.clrMark = comctl32_color.clrHighlight;
917 tbcd.clrHighlightHotTrack = 0;
918 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
919 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
920 /* MSDN says that this is the text rectangle.
921 * But (why always a but) tracing of v5.7 of native shows
922 * that this is really a *relative* rectangle based on the
923 * the nmcd.rc. Also the left and top are always 0 ignoring
924 * any bitmap that might be present. */
925 tbcd.rcText.left = 0;
926 tbcd.rcText.top = 0;
927 tbcd.rcText.right = rcText.right - rc.left;
928 tbcd.rcText.bottom = rcText.bottom - rc.top;
929 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
930 tbcd.nmcd.hdc = hdc;
931 tbcd.nmcd.rc = rc;
932 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
934 /* FIXME: what are these used for? */
935 tbcd.hbrLines = 0;
936 tbcd.hpenLines = 0;
938 /* Issue Item Prepaint notify */
939 infoPtr->dwItemCustDraw = 0;
940 infoPtr->dwItemCDFlag = 0;
941 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
943 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
944 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
945 tbcd.nmcd.lItemlParam = btnPtr->dwData;
946 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
947 /* reset these fields so the user can't alter the behaviour like native */
948 tbcd.nmcd.hdc = hdc;
949 tbcd.nmcd.rc = rc;
951 infoPtr->dwItemCustDraw = ntfret & 0xffff;
952 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
953 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
954 return;
955 /* save the only part of the rect that the user can change */
956 rcText.right = tbcd.rcText.right + rc.left;
957 rcText.bottom = tbcd.rcText.bottom + rc.top;
960 /* separator */
961 if (btnPtr->fsStyle & BTNS_SEP) {
962 /* with the FLAT style, iBitmap is the width and has already */
963 /* been taken into consideration in calculating the width */
964 /* so now we need to draw the vertical separator */
965 /* empirical tests show that iBitmap can/will be non-zero */
966 /* when drawing the vertical bar... */
967 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
968 if (btnPtr->fsStyle & BTNS_DROPDOWN)
969 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
970 else
971 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
973 else if (btnPtr->fsStyle != BTNS_SEP) {
974 FIXME("Draw some kind of separator: fsStyle=%x\n",
975 btnPtr->fsStyle);
977 goto FINALNOTIFY;
980 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
981 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
982 TOOLBAR_DrawPattern (&rc, &tbcd);
984 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
986 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
988 COLORREF oldclr;
990 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
991 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
992 if (hasDropDownArrow)
993 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
994 SetBkColor(hdc, oldclr);
998 TOOLBAR_DrawFrame(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd);
1000 if (drawSepDropDownArrow)
1001 TOOLBAR_DrawSepDDArrow(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd, &rcArrow);
1003 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1004 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1006 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1008 if (hasDropDownArrow && !drawSepDropDownArrow)
1010 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1012 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1013 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1015 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1017 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1018 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1020 else
1021 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1024 FINALNOTIFY:
1025 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1027 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1028 tbcd.nmcd.hdc = hdc;
1029 tbcd.nmcd.rc = rc;
1030 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1031 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1032 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1033 tbcd.rcText = rcText;
1034 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1035 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1036 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1042 static void
1043 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1045 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1046 TBUTTON_INFO *btnPtr;
1047 INT i, oldBKmode = 0;
1048 RECT rcTemp, rcClient;
1049 NMTBCUSTOMDRAW tbcd;
1050 DWORD ntfret;
1052 /* the app has told us not to redraw the toolbar */
1053 if (!infoPtr->bDoRedraw)
1054 return;
1056 /* if imagelist belongs to the app, it can be changed
1057 by the app after setting it */
1058 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1060 infoPtr->nNumBitmaps = 0;
1061 for (i = 0; i < infoPtr->cimlDef; i++)
1062 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1065 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1067 /* Send initial notify */
1068 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1069 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1070 tbcd.nmcd.hdc = hdc;
1071 tbcd.nmcd.rc = ps->rcPaint;
1072 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1073 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1075 if (infoPtr->bBtnTranspnt)
1076 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1078 GetClientRect(hwnd, &rcClient);
1080 /* redraw necessary buttons */
1081 btnPtr = infoPtr->buttons;
1082 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1084 BOOL bDraw;
1085 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1087 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1088 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1090 else
1091 bDraw = TRUE;
1092 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1093 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1094 if (bDraw)
1095 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1098 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1099 SetBkMode (hdc, oldBKmode);
1101 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1103 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1104 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1105 tbcd.nmcd.hdc = hdc;
1106 tbcd.nmcd.rc = ps->rcPaint;
1107 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1111 /***********************************************************************
1112 * TOOLBAR_MeasureString
1114 * This function gets the width and height of a string in pixels. This
1115 * is done first by using GetTextExtentPoint to get the basic width
1116 * and height. The DrawText is called with DT_CALCRECT to get the exact
1117 * width. The reason is because the text may have more than one "&" (or
1118 * prefix characters as M$ likes to call them). The prefix character
1119 * indicates where the underline goes, except for the string "&&" which
1120 * is reduced to a single "&". GetTextExtentPoint does not process these
1121 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1123 static void
1124 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1125 HDC hdc, LPSIZE lpSize)
1127 RECT myrect;
1129 lpSize->cx = 0;
1130 lpSize->cy = 0;
1132 if (infoPtr->nMaxTextRows > 0 &&
1133 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1134 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1135 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1137 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1139 if(lpText != NULL) {
1140 /* first get size of all the text */
1141 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1143 /* feed above size into the rectangle for DrawText */
1144 myrect.left = myrect.top = 0;
1145 myrect.right = lpSize->cx;
1146 myrect.bottom = lpSize->cy;
1148 /* Use DrawText to get true size as drawn (less pesky "&") */
1149 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1150 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1151 DT_NOPREFIX : 0));
1153 /* feed back to caller */
1154 lpSize->cx = myrect.right;
1155 lpSize->cy = myrect.bottom;
1159 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1162 /***********************************************************************
1163 * TOOLBAR_CalcStrings
1165 * This function walks through each string and measures it and returns
1166 * the largest height and width to caller.
1168 static void
1169 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1171 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1172 TBUTTON_INFO *btnPtr;
1173 INT i;
1174 SIZE sz;
1175 HDC hdc;
1176 HFONT hOldFont;
1178 lpSize->cx = 0;
1179 lpSize->cy = 0;
1181 if(infoPtr->nMaxTextRows == 0)
1182 return;
1184 hdc = GetDC (hwnd);
1185 hOldFont = SelectObject (hdc, infoPtr->hFont);
1187 btnPtr = infoPtr->buttons;
1188 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1189 if(TOOLBAR_HasText(infoPtr, btnPtr))
1191 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1192 if (sz.cx > lpSize->cx)
1193 lpSize->cx = sz.cx;
1194 if (sz.cy > lpSize->cy)
1195 lpSize->cy = sz.cy;
1199 SelectObject (hdc, hOldFont);
1200 ReleaseDC (hwnd, hdc);
1202 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1205 /***********************************************************************
1206 * TOOLBAR_WrapToolbar
1208 * This function walks through the buttons and separators in the
1209 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1210 * wrapping should occur based on the width of the toolbar window.
1211 * It does *not* calculate button placement itself. That task
1212 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1213 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1214 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1216 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1217 * vertical toolbar lists.
1220 static void
1221 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1223 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1224 TBUTTON_INFO *btnPtr;
1225 INT x, cx, i, j;
1226 RECT rc;
1227 BOOL bWrap, bButtonWrap;
1229 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1230 /* no layout is necessary. Applications may use this style */
1231 /* to perform their own layout on the toolbar. */
1232 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1233 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1235 btnPtr = infoPtr->buttons;
1236 x = infoPtr->nIndent;
1238 /* this can get the parents width, to know how far we can extend
1239 * this toolbar. We cannot use its height, as there may be multiple
1240 * toolbars in a rebar control
1242 GetClientRect( GetParent(hwnd), &rc );
1243 infoPtr->nWidth = rc.right - rc.left;
1244 bButtonWrap = FALSE;
1246 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1247 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1248 infoPtr->nIndent);
1250 for (i = 0; i < infoPtr->nNumButtons; i++ )
1252 bWrap = FALSE;
1253 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1255 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1256 continue;
1258 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1259 /* it is the actual width of the separator. This is used for */
1260 /* custom controls in toolbars. */
1261 /* */
1262 /* BTNS_DROPDOWN separators are treated as buttons for */
1263 /* width. - GA 8/01 */
1264 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1265 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1266 cx = (btnPtr[i].iBitmap > 0) ?
1267 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1268 else
1269 cx = infoPtr->nButtonWidth;
1271 /* Two or more adjacent separators form a separator group. */
1272 /* The first separator in a group should be wrapped to the */
1273 /* next row if the previous wrapping is on a button. */
1274 if( bButtonWrap &&
1275 (btnPtr[i].fsStyle & BTNS_SEP) &&
1276 (i + 1 < infoPtr->nNumButtons ) &&
1277 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1279 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1280 btnPtr[i].fsState |= TBSTATE_WRAP;
1281 x = infoPtr->nIndent;
1282 i++;
1283 bButtonWrap = FALSE;
1284 continue;
1287 /* The layout makes sure the bitmap is visible, but not the button. */
1288 /* Test added to also wrap after a button that starts a row but */
1289 /* is bigger than the area. - GA 8/01 */
1290 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1291 > infoPtr->nWidth ) ||
1292 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1294 BOOL bFound = FALSE;
1296 /* If the current button is a separator and not hidden, */
1297 /* go to the next until it reaches a non separator. */
1298 /* Wrap the last separator if it is before a button. */
1299 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1300 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1301 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1302 i < infoPtr->nNumButtons )
1304 i++;
1305 bFound = TRUE;
1308 if( bFound && i < infoPtr->nNumButtons )
1310 i--;
1311 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1312 i, btnPtr[i].fsStyle, x, cx);
1313 btnPtr[i].fsState |= TBSTATE_WRAP;
1314 x = infoPtr->nIndent;
1315 bButtonWrap = FALSE;
1316 continue;
1318 else if ( i >= infoPtr->nNumButtons)
1319 break;
1321 /* If the current button is not a separator, find the last */
1322 /* separator and wrap it. */
1323 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1325 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1326 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1328 bFound = TRUE;
1329 i = j;
1330 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1331 i, btnPtr[i].fsStyle, x, cx);
1332 x = infoPtr->nIndent;
1333 btnPtr[j].fsState |= TBSTATE_WRAP;
1334 bButtonWrap = FALSE;
1335 break;
1339 /* If no separator available for wrapping, wrap one of */
1340 /* non-hidden previous button. */
1341 if (!bFound)
1343 for ( j = i - 1;
1344 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1346 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1347 continue;
1349 bFound = TRUE;
1350 i = j;
1351 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1352 i, btnPtr[i].fsStyle, x, cx);
1353 x = infoPtr->nIndent;
1354 btnPtr[j].fsState |= TBSTATE_WRAP;
1355 bButtonWrap = TRUE;
1356 break;
1360 /* If all above failed, wrap the current button. */
1361 if (!bFound)
1363 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1364 i, btnPtr[i].fsStyle, x, cx);
1365 btnPtr[i].fsState |= TBSTATE_WRAP;
1366 bFound = TRUE;
1367 x = infoPtr->nIndent;
1368 if (btnPtr[i].fsStyle & BTNS_SEP )
1369 bButtonWrap = FALSE;
1370 else
1371 bButtonWrap = TRUE;
1374 else {
1375 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1376 i, btnPtr[i].fsStyle, x, cx);
1377 x += cx;
1383 /***********************************************************************
1384 * TOOLBAR_CalcToolbar
1386 * This function calculates button and separator placement. It first
1387 * calculates the button sizes, gets the toolbar window width and then
1388 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1389 * on. It assigns a new location to each item and sends this location to
1390 * the tooltip window if appropriate. Finally, it updates the rcBound
1391 * rect and calculates the new required toolbar window height.
1394 static void
1395 TOOLBAR_CalcToolbar (HWND hwnd)
1397 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1398 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1399 TBUTTON_INFO *btnPtr;
1400 INT i, nRows, nSepRows;
1401 INT x, y, cx, cy;
1402 SIZE sizeString;
1403 BOOL bWrap;
1404 BOOL usesBitmaps = FALSE;
1405 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1407 TOOLBAR_CalcStrings (hwnd, &sizeString);
1409 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1411 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1413 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1414 usesBitmaps = TRUE;
1416 if (dwStyle & TBSTYLE_LIST)
1418 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1419 0, sizeString.cy) + infoPtr->szPadding.cy;
1420 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1421 LIST_IMAGE_ABSENT_WIDTH) + sizeString.cx + infoPtr->szPadding.cx;
1422 if (sizeString.cx > 0)
1423 infoPtr->nButtonWidth += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1424 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1425 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1426 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1428 else {
1429 if (sizeString.cy > 0)
1431 if (usesBitmaps)
1432 infoPtr->nButtonHeight = sizeString.cy +
1433 infoPtr->szPadding.cy/2 + /* this is the space to separate text from bitmap */
1434 infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1435 else
1436 infoPtr->nButtonHeight = sizeString.cy + infoPtr->szPadding.cy;
1438 else
1439 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1441 if (sizeString.cx > infoPtr->nBitmapWidth)
1442 infoPtr->nButtonWidth = sizeString.cx + infoPtr->szPadding.cx;
1443 else
1444 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + infoPtr->szPadding.cx;
1447 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1448 infoPtr->nButtonWidth = infoPtr->cxMin;
1449 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1450 infoPtr->nButtonWidth = infoPtr->cxMax;
1452 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1454 x = infoPtr->nIndent;
1455 y = 0;
1457 /* from above, minimum is a button, and possible text */
1458 cx = infoPtr->nButtonWidth;
1460 /* cannot use just ButtonHeight, we may have no buttons! */
1461 if (infoPtr->nNumButtons > 0)
1462 infoPtr->nHeight = infoPtr->nButtonHeight;
1464 cy = infoPtr->nHeight;
1466 nRows = nSepRows = 0;
1468 infoPtr->rcBound.top = y;
1469 infoPtr->rcBound.left = x;
1470 infoPtr->rcBound.bottom = y + cy;
1471 infoPtr->rcBound.right = x;
1473 btnPtr = infoPtr->buttons;
1475 TRACE("cy=%d\n", cy);
1477 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1479 bWrap = FALSE;
1480 if (btnPtr->fsState & TBSTATE_HIDDEN)
1482 SetRectEmpty (&btnPtr->rect);
1483 continue;
1486 cy = infoPtr->nHeight;
1488 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1489 /* it is the actual width of the separator. This is used for */
1490 /* custom controls in toolbars. */
1491 if (btnPtr->fsStyle & BTNS_SEP) {
1492 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1493 cy = (btnPtr->iBitmap > 0) ?
1494 btnPtr->iBitmap : SEPARATOR_WIDTH;
1495 cx = infoPtr->nButtonWidth;
1497 else
1498 cx = (btnPtr->iBitmap > 0) ?
1499 btnPtr->iBitmap : SEPARATOR_WIDTH;
1501 else
1503 if (btnPtr->cx)
1504 cx = btnPtr->cx;
1505 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1506 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1508 SIZE sz;
1509 HDC hdc;
1510 HFONT hOldFont;
1512 hdc = GetDC (hwnd);
1513 hOldFont = SelectObject (hdc, infoPtr->hFont);
1515 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1517 SelectObject (hdc, hOldFont);
1518 ReleaseDC (hwnd, hdc);
1520 /* add space on for button frame, etc */
1521 cx = sz.cx + infoPtr->szPadding.cx;
1523 /* add list padding */
1524 if ((dwStyle & TBSTYLE_LIST) && sz.cx > 0)
1525 cx += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1527 if (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))
1529 if (dwStyle & TBSTYLE_LIST)
1530 cx += infoPtr->nBitmapWidth;
1531 else if (cx < (infoPtr->nBitmapWidth+infoPtr->szPadding.cx))
1532 cx = infoPtr->nBitmapWidth+infoPtr->szPadding.cx;
1534 else if (dwStyle & TBSTYLE_LIST)
1535 cx += LIST_IMAGE_ABSENT_WIDTH;
1537 else
1538 cx = infoPtr->nButtonWidth;
1540 /* if size has been set manually then don't add on extra space
1541 * for the drop down arrow */
1542 if (!btnPtr->cx && hasDropDownArrows &&
1543 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1544 cx += DDARROW_WIDTH;
1546 if (btnPtr->fsState & TBSTATE_WRAP )
1547 bWrap = TRUE;
1549 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1551 if (infoPtr->rcBound.left > x)
1552 infoPtr->rcBound.left = x;
1553 if (infoPtr->rcBound.right < x + cx)
1554 infoPtr->rcBound.right = x + cx;
1555 if (infoPtr->rcBound.bottom < y + cy)
1556 infoPtr->rcBound.bottom = y + cy;
1558 /* Set the toolTip only for non-hidden, non-separator button */
1559 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1561 TTTOOLINFOA ti;
1563 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1564 ti.cbSize = sizeof(TTTOOLINFOA);
1565 ti.hwnd = hwnd;
1566 ti.uId = btnPtr->idCommand;
1567 ti.rect = btnPtr->rect;
1568 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1569 0, (LPARAM)&ti);
1572 /* btnPtr->nRow is zero based. The space between the rows is */
1573 /* also considered as a row. */
1574 btnPtr->nRow = nRows + nSepRows;
1576 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1577 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1578 x, y, x+cx, y+cy);
1580 if( bWrap )
1582 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1583 y += cy;
1584 else
1586 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1587 /* it is the actual width of the separator. This is used for */
1588 /* custom controls in toolbars. */
1589 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1590 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1591 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1592 else
1593 y += cy;
1595 /* nSepRows is used to calculate the extra height follwoing */
1596 /* the last row. */
1597 nSepRows++;
1599 x = infoPtr->nIndent;
1601 /* Increment row number unless this is the last button */
1602 /* and it has Wrap set. */
1603 if (i != infoPtr->nNumButtons-1)
1604 nRows++;
1606 else
1607 x += cx;
1610 /* infoPtr->nRows is the number of rows on the toolbar */
1611 infoPtr->nRows = nRows + nSepRows + 1;
1613 #if 0
1614 /********************************************************************
1615 * The following while interesting, does not match the values *
1616 * created above for the button rectangles, nor the rcBound rect. *
1617 * We will comment it out and remove it later. *
1619 * The problem showed up as heights in the pager control that was *
1620 * wrong. *
1621 ********************************************************************/
1623 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1624 /* the last row. */
1625 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1626 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1627 nSepRows * (infoPtr->nBitmapHeight + 1) +
1628 BOTTOM_BORDER;
1629 #endif
1631 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1633 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1637 static INT
1638 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1640 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1641 TBUTTON_INFO *btnPtr;
1642 INT i;
1644 btnPtr = infoPtr->buttons;
1645 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1646 if (btnPtr->fsState & TBSTATE_HIDDEN)
1647 continue;
1649 if (btnPtr->fsStyle & BTNS_SEP) {
1650 if (PtInRect (&btnPtr->rect, *lpPt)) {
1651 TRACE(" ON SEPARATOR %d!\n", i);
1652 return -i;
1655 else {
1656 if (PtInRect (&btnPtr->rect, *lpPt)) {
1657 TRACE(" ON BUTTON %d!\n", i);
1658 return i;
1663 TRACE(" NOWHERE!\n");
1664 return -1;
1668 static INT
1669 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1671 TBUTTON_INFO *btnPtr;
1672 INT i;
1674 if (CommandIsIndex) {
1675 TRACE("command is really index command=%d\n", idCommand);
1676 if (idCommand >= infoPtr->nNumButtons) return -1;
1677 return idCommand;
1679 btnPtr = infoPtr->buttons;
1680 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1681 if (btnPtr->idCommand == idCommand) {
1682 TRACE("command=%d index=%d\n", idCommand, i);
1683 return i;
1686 TRACE("no index found for command=%d\n", idCommand);
1687 return -1;
1691 static INT
1692 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1694 TBUTTON_INFO *btnPtr;
1695 INT nRunIndex;
1697 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1698 return -1;
1700 /* check index button */
1701 btnPtr = &infoPtr->buttons[nIndex];
1702 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1703 if (btnPtr->fsState & TBSTATE_CHECKED)
1704 return nIndex;
1707 /* check previous buttons */
1708 nRunIndex = nIndex - 1;
1709 while (nRunIndex >= 0) {
1710 btnPtr = &infoPtr->buttons[nRunIndex];
1711 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1712 if (btnPtr->fsState & TBSTATE_CHECKED)
1713 return nRunIndex;
1715 else
1716 break;
1717 nRunIndex--;
1720 /* check next buttons */
1721 nRunIndex = nIndex + 1;
1722 while (nRunIndex < infoPtr->nNumButtons) {
1723 btnPtr = &infoPtr->buttons[nRunIndex];
1724 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1725 if (btnPtr->fsState & TBSTATE_CHECKED)
1726 return nRunIndex;
1728 else
1729 break;
1730 nRunIndex++;
1733 return -1;
1737 static VOID
1738 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1739 WPARAM wParam, LPARAM lParam)
1741 MSG msg;
1743 msg.hwnd = hwndMsg;
1744 msg.message = uMsg;
1745 msg.wParam = wParam;
1746 msg.lParam = lParam;
1747 msg.time = GetMessageTime ();
1748 msg.pt.x = LOWORD(GetMessagePos ());
1749 msg.pt.y = HIWORD(GetMessagePos ());
1751 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1755 /***********************************************************************
1756 * TOOLBAR_CustomizeDialogProc
1757 * This function implements the toolbar customization dialog.
1759 static INT_PTR CALLBACK
1760 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1762 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongA (hwnd, DWL_USER);
1763 PCUSTOMBUTTON btnInfo;
1764 NMTOOLBARA nmtb;
1765 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1767 switch (uMsg)
1769 case WM_INITDIALOG:
1770 custInfo = (PCUSTDLG_INFO)lParam;
1771 SetWindowLongA (hwnd, DWL_USER, (DWORD)custInfo);
1773 if (custInfo)
1775 WCHAR Buffer[256];
1776 int i = 0;
1777 int index;
1779 infoPtr = custInfo->tbInfo;
1781 /* send TBN_QUERYINSERT notification */
1782 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1784 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1785 return FALSE;
1787 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
1788 nmtb.iItem = (int)hwnd;
1789 /* Send TBN_INITCUSTOMIZE notification */
1790 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
1791 TBNRF_HIDEHELP)
1793 TRACE("TBNRF_HIDEHELP requested\n");
1794 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
1797 /* add items to 'toolbar buttons' list and check if removable */
1798 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1800 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1801 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1802 btnInfo->btn.fsStyle = BTNS_SEP;
1803 btnInfo->bVirtual = FALSE;
1804 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1806 /* send TBN_QUERYDELETE notification */
1807 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
1809 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1810 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1813 /* insert separator button into 'available buttons' list */
1814 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1815 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1816 btnInfo->btn.fsStyle = BTNS_SEP;
1817 btnInfo->bVirtual = FALSE;
1818 btnInfo->bRemovable = TRUE;
1819 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1820 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1821 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1823 /* insert all buttons into dsa */
1824 for (i = 0;; i++)
1826 /* send TBN_GETBUTTONINFO notification */
1827 NMTOOLBARW nmtb;
1828 nmtb.iItem = i;
1829 nmtb.pszText = Buffer;
1830 nmtb.cchText = 256;
1832 /* Clear previous button's text */
1833 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
1835 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
1836 break;
1838 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
1839 nmtb.tbButton.fsStyle, i,
1840 nmtb.tbButton.idCommand,
1841 nmtb.tbButton.iString,
1842 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
1843 : "");
1845 /* insert button into the apropriate list */
1846 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1847 if (index == -1)
1849 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1850 btnInfo->bVirtual = FALSE;
1851 btnInfo->bRemovable = TRUE;
1853 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1854 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX,
1855 LB_SETITEMDATA, index, (LPARAM)btnInfo);
1857 else
1859 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd,
1860 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1863 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1864 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
1866 if (lstrlenW(nmtb.pszText))
1867 lstrcpyW(btnInfo->text, nmtb.pszText);
1868 else if (nmtb.tbButton.iString >= 0 &&
1869 nmtb.tbButton.iString < infoPtr->nNumStrings)
1871 lstrcpyW(btnInfo->text,
1872 infoPtr->strings[nmtb.tbButton.iString]);
1877 /* select first item in the 'available' list */
1878 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1880 /* append 'virtual' separator button to the 'toolbar buttons' list */
1881 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1882 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1883 btnInfo->btn.fsStyle = BTNS_SEP;
1884 btnInfo->bVirtual = TRUE;
1885 btnInfo->bRemovable = FALSE;
1886 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1887 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1888 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1890 /* select last item in the 'toolbar' list */
1891 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1892 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1894 /* set focus and disable buttons */
1895 PostMessageA (hwnd, WM_USER, 0, 0);
1897 return TRUE;
1899 case WM_USER:
1900 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1901 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1902 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1903 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1904 return TRUE;
1906 case WM_CLOSE:
1907 EndDialog(hwnd, FALSE);
1908 return TRUE;
1910 case WM_COMMAND:
1911 switch (LOWORD(wParam))
1913 case IDC_TOOLBARBTN_LBOX:
1914 if (HIWORD(wParam) == LBN_SELCHANGE)
1916 PCUSTOMBUTTON btnInfo;
1917 NMTOOLBARA nmtb;
1918 int count;
1919 int index;
1921 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1922 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1924 /* send TBN_QUERYINSERT notification */
1925 nmtb.iItem = index;
1926 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1927 TBN_QUERYINSERT);
1929 /* get list box item */
1930 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1932 if (index == (count - 1))
1934 /* last item (virtual separator) */
1935 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1936 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1938 else if (index == (count - 2))
1940 /* second last item (last non-virtual item) */
1941 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1942 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1944 else if (index == 0)
1946 /* first item */
1947 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1948 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1950 else
1952 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1953 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1956 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1958 break;
1960 case IDC_MOVEUP_BTN:
1962 PCUSTOMBUTTON btnInfo;
1963 int index;
1964 int count;
1966 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1967 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1968 TRACE("Move up: index %d\n", index);
1970 /* send TBN_QUERYINSERT notification */
1971 nmtb.iItem = index;
1973 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1974 TBN_QUERYINSERT))
1976 NMHDR hdr;
1978 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1980 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1981 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1982 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1983 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1985 if (index <= 1)
1986 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1987 else if (index >= (count - 3))
1988 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1990 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1991 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1993 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
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 NMHDR hdr;
2015 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2017 /* move button down */
2018 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2019 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
2020 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
2021 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
2023 if (index == 0)
2024 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2025 else if (index >= (count - 3))
2026 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2028 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2029 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
2031 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2034 break;
2036 case IDC_REMOVE_BTN: /* remove button */
2038 PCUSTOMBUTTON btnInfo;
2039 int index;
2041 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2043 if (LB_ERR == index)
2044 break;
2046 TRACE("Remove: index %d\n", index);
2048 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX,
2049 LB_GETITEMDATA, index, 0);
2051 /* send TBN_QUERYDELETE notification */
2052 if (TOOLBAR_IsButtonRemovable(infoPtr, index, btnInfo))
2054 NMHDR hdr;
2056 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2057 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2058 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
2060 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2062 /* insert into 'available button' list */
2063 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2065 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
2066 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2068 else
2069 Free (btnInfo);
2071 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2074 break;
2075 case IDC_HELP_BTN:
2076 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2077 break;
2078 case IDC_RESET_BTN:
2079 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2080 break;
2082 case IDOK: /* Add button */
2084 int index;
2085 int count;
2087 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2088 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2089 TRACE("Add: index %d\n", index);
2091 /* send TBN_QUERYINSERT notification */
2092 nmtb.iItem = index;
2093 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2094 TBN_QUERYINSERT))
2096 NMHDR hdr;
2098 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
2100 if (index != 0)
2102 /* remove from 'available buttons' list */
2103 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
2104 if (index == count-1)
2105 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2106 else
2107 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
2109 else
2111 PCUSTOMBUTTON btnNew;
2113 /* duplicate 'separator' button */
2114 btnNew = (PCUSTOMBUTTON)Alloc (sizeof(CUSTOMBUTTON));
2115 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2116 btnInfo = btnNew;
2119 /* insert into 'toolbar button' list */
2120 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2121 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
2122 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2124 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
2126 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2129 break;
2131 case IDCANCEL:
2132 EndDialog(hwnd, FALSE);
2133 break;
2135 return TRUE;
2137 case WM_DESTROY:
2139 int count;
2140 int i;
2142 /* delete items from 'toolbar buttons' listbox*/
2143 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2144 for (i = 0; i < count; i++)
2146 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2147 Free(btnInfo);
2148 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2150 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2153 /* delete items from 'available buttons' listbox*/
2154 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2155 for (i = 0; i < count; i++)
2157 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2158 Free(btnInfo);
2159 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2161 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2163 return TRUE;
2165 case WM_DRAWITEM:
2166 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2168 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2169 DWORD dwStyle = GetWindowLongA (infoPtr->hwndSelf, GWL_STYLE);
2170 RECT rcButton;
2171 RECT rcText;
2172 HPEN hPen, hOldPen;
2173 HBRUSH hOldBrush;
2174 COLORREF oldText = 0;
2175 COLORREF oldBk = 0;
2177 /* get item data */
2178 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2179 if (btnInfo == NULL)
2181 FIXME("btnInfo invalid!\n");
2182 return TRUE;
2185 /* set colors and select objects */
2186 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2187 if (btnInfo->bVirtual)
2188 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2189 else
2190 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2191 hPen = CreatePen( PS_SOLID, 1,
2192 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2193 hOldPen = SelectObject (lpdis->hDC, hPen );
2194 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2196 /* fill background rectangle */
2197 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2198 lpdis->rcItem.right, lpdis->rcItem.bottom);
2200 /* calculate button and text rectangles */
2201 CopyRect (&rcButton, &lpdis->rcItem);
2202 InflateRect (&rcButton, -1, -1);
2203 CopyRect (&rcText, &rcButton);
2204 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2205 rcText.left = rcButton.right + 2;
2207 /* draw focus rectangle */
2208 if (lpdis->itemState & ODS_FOCUS)
2209 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2211 /* draw button */
2212 if (!(dwStyle & TBSTYLE_FLAT))
2213 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2215 /* draw image and text */
2216 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2217 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2218 btnInfo->btn.iBitmap));
2219 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2220 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2222 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2223 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2225 /* delete objects and reset colors */
2226 SelectObject (lpdis->hDC, hOldBrush);
2227 SelectObject (lpdis->hDC, hOldPen);
2228 SetBkColor (lpdis->hDC, oldBk);
2229 SetTextColor (lpdis->hDC, oldText);
2230 DeleteObject( hPen );
2231 return TRUE;
2233 return FALSE;
2235 case WM_MEASUREITEM:
2236 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2238 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2240 if (custInfo && custInfo->tbInfo)
2241 lpmis->itemHeight = custInfo->tbInfo->nBitmapHeight + 8;
2242 else
2243 lpmis->itemHeight = 15 + 8; /* default height */
2245 return TRUE;
2247 return FALSE;
2249 default:
2250 return FALSE;
2255 /***********************************************************************
2256 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2259 static LRESULT
2260 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2262 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2263 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2264 INT nIndex = 0, nButtons, nCount;
2265 HBITMAP hbmLoad;
2266 HIMAGELIST himlDef;
2268 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2269 if (!lpAddBmp)
2270 return -1;
2272 if (lpAddBmp->hInst == HINST_COMMCTRL)
2274 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2275 nButtons = 15;
2276 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2277 nButtons = 13;
2278 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2279 nButtons = 5;
2280 else
2281 return -1;
2283 TRACE ("adding %d internal bitmaps!\n", nButtons);
2285 /* Windows resize all the buttons to the size of a newly added standard image */
2286 if (lpAddBmp->nID & 1)
2288 /* large icons */
2289 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2290 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2292 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2293 MAKELPARAM((WORD)24, (WORD)24));
2294 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2295 MAKELPARAM((WORD)31, (WORD)30));
2297 else
2299 /* small icons */
2300 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2301 MAKELPARAM((WORD)16, (WORD)16));
2302 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2303 MAKELPARAM((WORD)22, (WORD)22));
2306 TOOLBAR_CalcToolbar (hwnd);
2308 else
2310 nButtons = (INT)wParam;
2311 if (nButtons <= 0)
2312 return -1;
2314 TRACE ("adding %d bitmaps!\n", nButtons);
2317 if (!infoPtr->cimlDef) {
2318 /* create new default image list */
2319 TRACE ("creating default image list!\n");
2321 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2322 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2323 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2324 infoPtr->himlInt = himlDef;
2326 else {
2327 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2330 if (!himlDef) {
2331 WARN("No default image list available\n");
2332 return -1;
2335 nCount = ImageList_GetImageCount(himlDef);
2337 /* Add bitmaps to the default image list */
2338 if (lpAddBmp->hInst == NULL)
2340 BITMAP bmp;
2341 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2342 HDC hdcImage, hdcBitmap;
2344 /* copy the bitmap before adding it so that the user's bitmap
2345 * doesn't get modified.
2347 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2349 hdcImage = CreateCompatibleDC(0);
2350 hdcBitmap = CreateCompatibleDC(0);
2352 /* create new bitmap */
2353 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2354 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2355 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2357 /* Copy the user's image */
2358 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2359 hdcBitmap, 0, 0, SRCCOPY);
2361 SelectObject (hdcImage, hOldBitmapLoad);
2362 SelectObject (hdcBitmap, hOldBitmapBitmap);
2363 DeleteDC (hdcImage);
2364 DeleteDC (hdcBitmap);
2366 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2367 DeleteObject (hbmLoad);
2369 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2371 /* Add system bitmaps */
2372 switch (lpAddBmp->nID)
2374 case IDB_STD_SMALL_COLOR:
2375 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2376 MAKEINTRESOURCEA(IDB_STD_SMALL));
2377 nIndex = ImageList_AddMasked (himlDef,
2378 hbmLoad, comctl32_color.clrBtnFace);
2379 DeleteObject (hbmLoad);
2380 break;
2382 case IDB_STD_LARGE_COLOR:
2383 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2384 MAKEINTRESOURCEA(IDB_STD_LARGE));
2385 nIndex = ImageList_AddMasked (himlDef,
2386 hbmLoad, comctl32_color.clrBtnFace);
2387 DeleteObject (hbmLoad);
2388 break;
2390 case IDB_VIEW_SMALL_COLOR:
2391 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2392 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2393 nIndex = ImageList_AddMasked (himlDef,
2394 hbmLoad, comctl32_color.clrBtnFace);
2395 DeleteObject (hbmLoad);
2396 break;
2398 case IDB_VIEW_LARGE_COLOR:
2399 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2400 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2401 nIndex = ImageList_AddMasked (himlDef,
2402 hbmLoad, comctl32_color.clrBtnFace);
2403 DeleteObject (hbmLoad);
2404 break;
2406 case IDB_HIST_SMALL_COLOR:
2407 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2408 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2409 nIndex = ImageList_AddMasked (himlDef,
2410 hbmLoad, comctl32_color.clrBtnFace);
2411 DeleteObject (hbmLoad);
2412 break;
2414 case IDB_HIST_LARGE_COLOR:
2415 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2416 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2417 nIndex = ImageList_AddMasked (himlDef,
2418 hbmLoad, comctl32_color.clrBtnFace);
2419 DeleteObject (hbmLoad);
2420 break;
2422 default:
2423 nIndex = ImageList_GetImageCount (himlDef);
2424 ERR ("invalid imagelist!\n");
2425 break;
2428 else
2430 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2431 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2432 DeleteObject (hbmLoad);
2435 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2437 if (infoPtr->nNumBitmapInfos == 0)
2439 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2441 else
2443 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2444 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2445 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2448 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2449 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2450 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2452 infoPtr->nNumBitmapInfos++;
2453 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2455 if (nIndex != -1)
2457 INT imagecount = ImageList_GetImageCount(himlDef);
2459 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2461 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",
2462 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2463 infoPtr->nNumBitmaps+nButtons,imagecount);
2465 infoPtr->nNumBitmaps = imagecount;
2467 else
2468 infoPtr->nNumBitmaps += nButtons;
2471 InvalidateRect(hwnd, NULL, TRUE);
2473 return nIndex;
2477 static LRESULT
2478 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2480 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2481 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2482 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2484 TRACE("adding %d buttons!\n", wParam);
2486 nAddButtons = (UINT)wParam;
2487 nOldButtons = infoPtr->nNumButtons;
2488 nNewButtons = nOldButtons + nAddButtons;
2490 if (infoPtr->nNumButtons == 0) {
2491 infoPtr->buttons =
2492 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2494 else {
2495 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2496 infoPtr->buttons =
2497 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2498 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2499 nOldButtons * sizeof(TBUTTON_INFO));
2500 Free (oldButtons);
2503 infoPtr->nNumButtons = nNewButtons;
2505 /* insert new button data */
2506 for (nCount = 0; nCount < nAddButtons; nCount++) {
2507 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2508 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2509 btnPtr->idCommand = lpTbb[nCount].idCommand;
2510 btnPtr->fsState = lpTbb[nCount].fsState;
2511 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2512 btnPtr->dwData = lpTbb[nCount].dwData;
2513 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2514 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2515 else
2516 btnPtr->iString = lpTbb[nCount].iString;
2517 btnPtr->bHot = FALSE;
2519 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2520 TTTOOLINFOA ti;
2522 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2523 ti.cbSize = sizeof (TTTOOLINFOA);
2524 ti.hwnd = hwnd;
2525 ti.uId = btnPtr->idCommand;
2526 ti.hinst = 0;
2527 ti.lpszText = LPSTR_TEXTCALLBACKA;
2529 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2530 0, (LPARAM)&ti);
2534 TOOLBAR_CalcToolbar (hwnd);
2536 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2538 InvalidateRect(hwnd, NULL, TRUE);
2540 return TRUE;
2544 static LRESULT
2545 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2547 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2548 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2549 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2551 TRACE("adding %d buttons!\n", wParam);
2553 nAddButtons = (UINT)wParam;
2554 nOldButtons = infoPtr->nNumButtons;
2555 nNewButtons = nOldButtons + nAddButtons;
2557 if (infoPtr->nNumButtons == 0) {
2558 infoPtr->buttons =
2559 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2561 else {
2562 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2563 infoPtr->buttons =
2564 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2565 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2566 nOldButtons * sizeof(TBUTTON_INFO));
2567 Free (oldButtons);
2570 infoPtr->nNumButtons = nNewButtons;
2572 /* insert new button data */
2573 for (nCount = 0; nCount < nAddButtons; nCount++) {
2574 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2575 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2576 btnPtr->idCommand = lpTbb[nCount].idCommand;
2577 btnPtr->fsState = lpTbb[nCount].fsState;
2578 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2579 btnPtr->dwData = lpTbb[nCount].dwData;
2580 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2581 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2582 else
2583 btnPtr->iString = lpTbb[nCount].iString;
2584 btnPtr->bHot = FALSE;
2586 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2587 TTTOOLINFOW ti;
2589 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2590 ti.cbSize = sizeof (TTTOOLINFOW);
2591 ti.hwnd = hwnd;
2592 ti.uId = btnPtr->idCommand;
2593 ti.hinst = 0;
2594 ti.lpszText = LPSTR_TEXTCALLBACKW;
2595 ti.lParam = lParam;
2597 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2598 0, (LPARAM)&ti);
2602 TOOLBAR_CalcToolbar (hwnd);
2604 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2606 InvalidateRect(hwnd, NULL, TRUE);
2608 return TRUE;
2612 static LRESULT
2613 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2615 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2616 INT nIndex;
2618 if ((wParam) && (HIWORD(lParam) == 0)) {
2619 char szString[256];
2620 INT len;
2621 TRACE("adding string from resource!\n");
2623 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2624 szString, 256);
2626 TRACE("len=%d \"%s\"\n", len, szString);
2627 nIndex = infoPtr->nNumStrings;
2628 if (infoPtr->nNumStrings == 0) {
2629 infoPtr->strings =
2630 Alloc (sizeof(LPWSTR));
2632 else {
2633 LPWSTR *oldStrings = infoPtr->strings;
2634 infoPtr->strings =
2635 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2636 memcpy (&infoPtr->strings[0], &oldStrings[0],
2637 sizeof(LPWSTR) * infoPtr->nNumStrings);
2638 Free (oldStrings);
2641 /*Alloc zeros out the allocated memory*/
2642 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2643 infoPtr->nNumStrings++;
2645 else {
2646 LPSTR p = (LPSTR)lParam;
2647 INT len;
2649 if (p == NULL)
2650 return -1;
2651 TRACE("adding string(s) from array!\n");
2653 nIndex = infoPtr->nNumStrings;
2654 while (*p) {
2655 len = strlen (p);
2656 TRACE("len=%d \"%s\"\n", len, p);
2658 if (infoPtr->nNumStrings == 0) {
2659 infoPtr->strings =
2660 Alloc (sizeof(LPWSTR));
2662 else {
2663 LPWSTR *oldStrings = infoPtr->strings;
2664 infoPtr->strings =
2665 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2666 memcpy (&infoPtr->strings[0], &oldStrings[0],
2667 sizeof(LPWSTR) * infoPtr->nNumStrings);
2668 Free (oldStrings);
2671 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2672 infoPtr->nNumStrings++;
2674 p += (len+1);
2678 return nIndex;
2682 static LRESULT
2683 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2685 #define MAX_RESOURCE_STRING_LENGTH 512
2686 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2687 INT nIndex;
2689 if ((wParam) && (HIWORD(lParam) == 0)) {
2690 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2691 INT len;
2692 TRACE("adding string from resource!\n");
2694 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2695 szString, MAX_RESOURCE_STRING_LENGTH);
2697 TRACE("len=%d %s\n", len, debugstr_w(szString));
2698 TRACE("First char: 0x%x\n", *szString);
2699 if (szString[0] == L'|')
2701 PWSTR p = szString + 1;
2703 nIndex = infoPtr->nNumStrings;
2704 while (*p != L'|' && *p != L'\0') {
2705 PWSTR np;
2707 if (infoPtr->nNumStrings == 0) {
2708 infoPtr->strings = Alloc (sizeof(LPWSTR));
2710 else
2712 LPWSTR *oldStrings = infoPtr->strings;
2713 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2714 memcpy(&infoPtr->strings[0], &oldStrings[0],
2715 sizeof(LPWSTR) * infoPtr->nNumStrings);
2716 Free(oldStrings);
2719 np=strchrW (p, '|');
2720 if (np!=NULL) {
2721 len = np - p;
2722 np++;
2723 } else {
2724 len = strlenW(p);
2725 np = p + len;
2727 TRACE("len=%d %s\n", len, debugstr_w(p));
2728 infoPtr->strings[infoPtr->nNumStrings] =
2729 Alloc (sizeof(WCHAR)*(len+1));
2730 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2731 infoPtr->nNumStrings++;
2733 p = np;
2736 else
2738 nIndex = infoPtr->nNumStrings;
2739 if (infoPtr->nNumStrings == 0) {
2740 infoPtr->strings =
2741 Alloc (sizeof(LPWSTR));
2743 else {
2744 LPWSTR *oldStrings = infoPtr->strings;
2745 infoPtr->strings =
2746 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2747 memcpy (&infoPtr->strings[0], &oldStrings[0],
2748 sizeof(LPWSTR) * infoPtr->nNumStrings);
2749 Free (oldStrings);
2752 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2753 infoPtr->nNumStrings++;
2756 else {
2757 LPWSTR p = (LPWSTR)lParam;
2758 INT len;
2760 if (p == NULL)
2761 return -1;
2762 TRACE("adding string(s) from array!\n");
2763 nIndex = infoPtr->nNumStrings;
2764 while (*p) {
2765 len = strlenW (p);
2767 TRACE("len=%d %s\n", len, debugstr_w(p));
2768 if (infoPtr->nNumStrings == 0) {
2769 infoPtr->strings =
2770 Alloc (sizeof(LPWSTR));
2772 else {
2773 LPWSTR *oldStrings = infoPtr->strings;
2774 infoPtr->strings =
2775 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2776 memcpy (&infoPtr->strings[0], &oldStrings[0],
2777 sizeof(LPWSTR) * infoPtr->nNumStrings);
2778 Free (oldStrings);
2781 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2782 infoPtr->nNumStrings++;
2784 p += (len+1);
2788 return nIndex;
2792 static LRESULT
2793 TOOLBAR_AutoSize (HWND hwnd)
2795 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2796 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2797 RECT parent_rect;
2798 RECT window_rect;
2799 HWND parent;
2800 INT x, y;
2801 INT cx, cy;
2802 UINT uPosFlags = SWP_NOZORDER;
2804 TRACE("resize forced, style=%lx!\n", dwStyle);
2806 parent = GetParent (hwnd);
2807 GetClientRect(parent, &parent_rect);
2809 x = parent_rect.left;
2810 y = parent_rect.top;
2812 /* FIXME: we should be able to early out if nothing */
2813 /* has changed with nWidth != parent_rect width */
2815 if (dwStyle & CCS_NORESIZE) {
2816 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2817 cx = 0;
2818 cy = 0;
2819 TOOLBAR_CalcToolbar (hwnd);
2821 else {
2822 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2823 TOOLBAR_CalcToolbar (hwnd);
2824 InvalidateRect( hwnd, NULL, TRUE );
2825 cy = infoPtr->nHeight;
2826 cx = infoPtr->nWidth;
2828 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
2829 GetWindowRect(hwnd, &window_rect);
2830 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2831 y = window_rect.top;
2833 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
2834 GetWindowRect(hwnd, &window_rect);
2835 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
2839 if (dwStyle & CCS_NOPARENTALIGN)
2840 uPosFlags |= SWP_NOMOVE;
2842 if (!(dwStyle & CCS_NODIVIDER))
2843 cy += GetSystemMetrics(SM_CYEDGE);
2845 if (dwStyle & WS_BORDER)
2847 x = y = 1;
2848 cy += GetSystemMetrics(SM_CYEDGE);
2849 cx += GetSystemMetrics(SM_CYEDGE);
2852 infoPtr->bAutoSize = TRUE;
2853 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
2854 /* The following line makes sure that the infoPtr->bAutoSize is turned off
2855 * after the setwindowpos calls */
2856 infoPtr->bAutoSize = FALSE;
2858 return 0;
2862 static LRESULT
2863 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2865 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2867 return infoPtr->nNumButtons;
2871 static LRESULT
2872 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2874 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2876 if (infoPtr == NULL) {
2877 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2878 ERR("infoPtr == NULL!\n");
2879 return 0;
2882 infoPtr->dwStructSize = (DWORD)wParam;
2884 return 0;
2888 static LRESULT
2889 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2891 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2892 TBUTTON_INFO *btnPtr;
2893 INT nIndex;
2895 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
2897 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2898 if (nIndex == -1)
2899 return FALSE;
2901 btnPtr = &infoPtr->buttons[nIndex];
2902 btnPtr->iBitmap = LOWORD(lParam);
2904 /* we HAVE to erase the background, the new bitmap could be */
2905 /* transparent */
2906 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2908 return TRUE;
2912 static LRESULT
2913 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2915 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2916 TBUTTON_INFO *btnPtr;
2917 INT nIndex;
2918 INT nOldIndex = -1;
2919 BOOL bChecked = FALSE;
2921 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2923 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
2925 if (nIndex == -1)
2926 return FALSE;
2928 btnPtr = &infoPtr->buttons[nIndex];
2930 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2932 if (LOWORD(lParam) == FALSE)
2933 btnPtr->fsState &= ~TBSTATE_CHECKED;
2934 else {
2935 if (btnPtr->fsStyle & BTNS_GROUP) {
2936 nOldIndex =
2937 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2938 if (nOldIndex == nIndex)
2939 return 0;
2940 if (nOldIndex != -1)
2941 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2943 btnPtr->fsState |= TBSTATE_CHECKED;
2946 if( bChecked != LOWORD(lParam) )
2948 if (nOldIndex != -1)
2949 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
2950 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2953 /* FIXME: Send a WM_NOTIFY?? */
2955 return TRUE;
2959 static LRESULT
2960 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2962 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2964 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2968 static LRESULT
2969 TOOLBAR_Customize (HWND hwnd)
2971 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2972 CUSTDLG_INFO custInfo;
2973 LRESULT ret;
2974 LPCVOID template;
2975 HRSRC hRes;
2976 NMHDR nmhdr;
2978 custInfo.tbInfo = infoPtr;
2979 custInfo.tbHwnd = hwnd;
2981 /* send TBN_BEGINADJUST notification */
2982 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2983 TBN_BEGINADJUST);
2985 if (!(hRes = FindResourceA (COMCTL32_hModule,
2986 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2987 (LPSTR)RT_DIALOG)))
2988 return FALSE;
2990 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2991 return FALSE;
2993 ret = DialogBoxIndirectParamA ((HINSTANCE)GetWindowLongA(hwnd, GWL_HINSTANCE),
2994 (LPDLGTEMPLATEA)template,
2995 hwnd,
2996 TOOLBAR_CustomizeDialogProc,
2997 (LPARAM)&custInfo);
2999 /* send TBN_ENDADJUST notification */
3000 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
3001 TBN_ENDADJUST);
3003 return ret;
3007 static LRESULT
3008 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3010 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3011 INT nIndex = (INT)wParam;
3012 NMTOOLBARW nmtb;
3014 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3015 return FALSE;
3017 memset(&nmtb, 0, sizeof(nmtb));
3018 nmtb.iItem = nIndex;
3019 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_DELETINGBUTTON);
3021 if ((infoPtr->hwndToolTip) &&
3022 !(infoPtr->buttons[nIndex].fsStyle & BTNS_SEP)) {
3023 TTTOOLINFOA ti;
3025 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3026 ti.cbSize = sizeof (TTTOOLINFOA);
3027 ti.hwnd = hwnd;
3028 ti.uId = infoPtr->buttons[nIndex].idCommand;
3030 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
3033 if (infoPtr->nNumButtons == 1) {
3034 TRACE(" simple delete!\n");
3035 Free (infoPtr->buttons);
3036 infoPtr->buttons = NULL;
3037 infoPtr->nNumButtons = 0;
3039 else {
3040 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3041 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3043 infoPtr->nNumButtons--;
3044 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3045 if (nIndex > 0) {
3046 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3047 nIndex * sizeof(TBUTTON_INFO));
3050 if (nIndex < infoPtr->nNumButtons) {
3051 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3052 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3055 Free (oldButtons);
3058 TOOLBAR_CalcToolbar (hwnd);
3060 InvalidateRect (hwnd, NULL, TRUE);
3062 return TRUE;
3066 static LRESULT
3067 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3069 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3070 TBUTTON_INFO *btnPtr;
3071 INT nIndex;
3072 DWORD bState;
3074 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3076 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3078 if (nIndex == -1)
3079 return FALSE;
3081 btnPtr = &infoPtr->buttons[nIndex];
3083 bState = btnPtr->fsState & TBSTATE_ENABLED;
3085 /* update the toolbar button state */
3086 if(LOWORD(lParam) == FALSE) {
3087 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3088 } else {
3089 btnPtr->fsState |= TBSTATE_ENABLED;
3092 /* redraw the button only if the state of the button changed */
3093 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3094 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3096 return TRUE;
3100 static inline LRESULT
3101 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3103 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3105 return infoPtr->bAnchor;
3109 static LRESULT
3110 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3112 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3113 INT nIndex;
3115 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3116 if (nIndex == -1)
3117 return -1;
3119 return infoPtr->buttons[nIndex].iBitmap;
3123 static inline LRESULT
3124 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3126 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3130 static LRESULT
3131 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3133 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3134 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3135 INT nIndex = (INT)wParam;
3136 TBUTTON_INFO *btnPtr;
3138 if (infoPtr == NULL)
3139 return FALSE;
3141 if (lpTbb == NULL)
3142 return FALSE;
3144 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3145 return FALSE;
3147 btnPtr = &infoPtr->buttons[nIndex];
3148 lpTbb->iBitmap = btnPtr->iBitmap;
3149 lpTbb->idCommand = btnPtr->idCommand;
3150 lpTbb->fsState = btnPtr->fsState;
3151 lpTbb->fsStyle = btnPtr->fsStyle;
3152 lpTbb->bReserved[0] = 0;
3153 lpTbb->bReserved[1] = 0;
3154 lpTbb->dwData = btnPtr->dwData;
3155 lpTbb->iString = btnPtr->iString;
3157 return TRUE;
3161 static LRESULT
3162 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3164 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3165 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3166 TBUTTON_INFO *btnPtr;
3167 INT nIndex;
3169 if (infoPtr == NULL)
3170 return -1;
3171 if (lpTbInfo == NULL)
3172 return -1;
3173 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3174 return -1;
3176 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3177 lpTbInfo->dwMask & 0x80000000);
3178 if (nIndex == -1)
3179 return -1;
3181 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3183 if (lpTbInfo->dwMask & TBIF_COMMAND)
3184 lpTbInfo->idCommand = btnPtr->idCommand;
3185 if (lpTbInfo->dwMask & TBIF_IMAGE)
3186 lpTbInfo->iImage = btnPtr->iBitmap;
3187 if (lpTbInfo->dwMask & TBIF_LPARAM)
3188 lpTbInfo->lParam = btnPtr->dwData;
3189 if (lpTbInfo->dwMask & TBIF_SIZE)
3190 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3191 if (lpTbInfo->dwMask & TBIF_STATE)
3192 lpTbInfo->fsState = btnPtr->fsState;
3193 if (lpTbInfo->dwMask & TBIF_STYLE)
3194 lpTbInfo->fsStyle = btnPtr->fsStyle;
3195 if (lpTbInfo->dwMask & TBIF_TEXT) {
3196 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3197 can't use TOOLBAR_GetText here */
3198 LPWSTR lpText;
3199 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3200 lpText = (LPWSTR)btnPtr->iString;
3201 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3202 } else
3203 lpTbInfo->pszText[0] = '\0';
3205 return nIndex;
3209 static LRESULT
3210 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3212 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3213 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3214 TBUTTON_INFO *btnPtr;
3215 INT nIndex;
3217 if (infoPtr == NULL)
3218 return -1;
3219 if (lpTbInfo == NULL)
3220 return -1;
3221 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3222 return -1;
3224 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3225 lpTbInfo->dwMask & 0x80000000);
3226 if (nIndex == -1)
3227 return -1;
3229 btnPtr = &infoPtr->buttons[nIndex];
3231 if(!btnPtr)
3232 return -1;
3234 if (lpTbInfo->dwMask & TBIF_COMMAND)
3235 lpTbInfo->idCommand = btnPtr->idCommand;
3236 if (lpTbInfo->dwMask & TBIF_IMAGE)
3237 lpTbInfo->iImage = btnPtr->iBitmap;
3238 if (lpTbInfo->dwMask & TBIF_LPARAM)
3239 lpTbInfo->lParam = btnPtr->dwData;
3240 if (lpTbInfo->dwMask & TBIF_SIZE)
3241 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3242 if (lpTbInfo->dwMask & TBIF_STATE)
3243 lpTbInfo->fsState = btnPtr->fsState;
3244 if (lpTbInfo->dwMask & TBIF_STYLE)
3245 lpTbInfo->fsStyle = btnPtr->fsStyle;
3246 if (lpTbInfo->dwMask & TBIF_TEXT) {
3247 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3248 can't use TOOLBAR_GetText here */
3249 LPWSTR lpText;
3250 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3251 lpText = (LPWSTR)btnPtr->iString;
3252 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3253 } else
3254 lpTbInfo->pszText[0] = '\0';
3257 return nIndex;
3261 static LRESULT
3262 TOOLBAR_GetButtonSize (HWND hwnd)
3264 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3266 if (infoPtr->nNumButtons > 0)
3267 return MAKELONG((WORD)infoPtr->nButtonWidth,
3268 (WORD)infoPtr->nButtonHeight);
3269 else
3270 return MAKELONG(8,7);
3274 static LRESULT
3275 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3277 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3278 INT nIndex;
3279 LPWSTR lpText;
3281 if (lParam == 0)
3282 return -1;
3284 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3285 if (nIndex == -1)
3286 return -1;
3288 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3290 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3291 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3295 static LRESULT
3296 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3298 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3299 INT nIndex;
3300 LPWSTR lpText;
3302 if (lParam == 0)
3303 return -1;
3305 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3306 if (nIndex == -1)
3307 return -1;
3309 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3311 strcpyW ((LPWSTR)lParam, lpText);
3313 return strlenW (lpText);
3317 static LRESULT
3318 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3320 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3321 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3322 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3326 inline static LRESULT
3327 TOOLBAR_GetExtendedStyle (HWND hwnd)
3329 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3331 TRACE("\n");
3333 return infoPtr->dwExStyle;
3337 static LRESULT
3338 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3340 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3341 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3342 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3346 static LRESULT
3347 TOOLBAR_GetHotItem (HWND hwnd)
3349 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3351 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
3352 return -1;
3354 if (infoPtr->nHotItem < 0)
3355 return -1;
3357 return (LRESULT)infoPtr->nHotItem;
3361 static LRESULT
3362 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3364 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3365 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3366 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3370 /* << TOOLBAR_GetInsertMark >> */
3371 /* << TOOLBAR_GetInsertMarkColor >> */
3374 static LRESULT
3375 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3377 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3378 TBUTTON_INFO *btnPtr;
3379 LPRECT lpRect;
3380 INT nIndex;
3382 if (infoPtr == NULL)
3383 return FALSE;
3384 nIndex = (INT)wParam;
3385 btnPtr = &infoPtr->buttons[nIndex];
3386 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3387 return FALSE;
3388 lpRect = (LPRECT)lParam;
3389 if (lpRect == NULL)
3390 return FALSE;
3391 if (btnPtr->fsState & TBSTATE_HIDDEN)
3392 return FALSE;
3394 lpRect->left = btnPtr->rect.left;
3395 lpRect->right = btnPtr->rect.right;
3396 lpRect->bottom = btnPtr->rect.bottom;
3397 lpRect->top = btnPtr->rect.top;
3399 return TRUE;
3403 static LRESULT
3404 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3406 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3407 LPSIZE lpSize = (LPSIZE)lParam;
3409 if (lpSize == NULL)
3410 return FALSE;
3412 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3413 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3415 TRACE("maximum size %ld x %ld\n",
3416 infoPtr->rcBound.right - infoPtr->rcBound.left,
3417 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3419 return TRUE;
3423 /* << TOOLBAR_GetObject >> */
3426 static LRESULT
3427 TOOLBAR_GetPadding (HWND hwnd)
3429 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3430 DWORD oldPad;
3432 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3433 return (LRESULT) oldPad;
3437 static LRESULT
3438 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3440 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3441 TBUTTON_INFO *btnPtr;
3442 LPRECT lpRect;
3443 INT nIndex;
3445 if (infoPtr == NULL)
3446 return FALSE;
3447 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3448 btnPtr = &infoPtr->buttons[nIndex];
3449 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3450 return FALSE;
3451 lpRect = (LPRECT)lParam;
3452 if (lpRect == NULL)
3453 return FALSE;
3455 lpRect->left = btnPtr->rect.left;
3456 lpRect->right = btnPtr->rect.right;
3457 lpRect->bottom = btnPtr->rect.bottom;
3458 lpRect->top = btnPtr->rect.top;
3460 return TRUE;
3464 static LRESULT
3465 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3467 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3469 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
3470 return infoPtr->nRows;
3471 else
3472 return 1;
3476 static LRESULT
3477 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3479 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3480 INT nIndex;
3482 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3483 if (nIndex == -1)
3484 return -1;
3486 return infoPtr->buttons[nIndex].fsState;
3490 static LRESULT
3491 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3493 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3494 INT nIndex;
3496 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3497 if (nIndex == -1)
3498 return -1;
3500 return infoPtr->buttons[nIndex].fsStyle;
3504 static LRESULT
3505 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3507 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3509 if (infoPtr == NULL)
3510 return 0;
3512 return infoPtr->nMaxTextRows;
3516 static LRESULT
3517 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3519 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3521 if (infoPtr == NULL)
3522 return 0;
3523 return (LRESULT)infoPtr->hwndToolTip;
3527 static LRESULT
3528 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3530 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3532 TRACE("%s hwnd=%p stub!\n",
3533 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3535 return infoPtr->bUnicode;
3539 inline static LRESULT
3540 TOOLBAR_GetVersion (HWND hwnd)
3542 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3543 return infoPtr->iVersion;
3547 static LRESULT
3548 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3550 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3551 TBUTTON_INFO *btnPtr;
3552 INT nIndex;
3554 TRACE("\n");
3556 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3557 if (nIndex == -1)
3558 return FALSE;
3560 btnPtr = &infoPtr->buttons[nIndex];
3561 if (LOWORD(lParam) == FALSE)
3562 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3563 else
3564 btnPtr->fsState |= TBSTATE_HIDDEN;
3566 TOOLBAR_CalcToolbar (hwnd);
3568 InvalidateRect (hwnd, NULL, TRUE);
3570 return TRUE;
3574 inline static LRESULT
3575 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3577 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3581 static LRESULT
3582 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3584 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3585 TBUTTON_INFO *btnPtr;
3586 INT nIndex;
3587 DWORD oldState;
3589 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3590 if (nIndex == -1)
3591 return FALSE;
3593 btnPtr = &infoPtr->buttons[nIndex];
3594 oldState = btnPtr->fsState;
3595 if (LOWORD(lParam) == FALSE)
3596 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3597 else
3598 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3600 if(oldState != btnPtr->fsState)
3601 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3603 return TRUE;
3607 static LRESULT
3608 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3610 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3611 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3612 INT nIndex = (INT)wParam;
3613 TBUTTON_INFO *oldButtons;
3615 if (lpTbb == NULL)
3616 return FALSE;
3618 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3620 if (nIndex == -1) {
3621 /* EPP: this seems to be an undocumented call (from my IE4)
3622 * I assume in that case that:
3623 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3624 * - index of insertion is at the end of existing buttons
3625 * I only see this happen with nIndex == -1, but it could have a special
3626 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3628 nIndex = infoPtr->nNumButtons;
3630 } else if (nIndex < 0)
3631 return FALSE;
3633 /* If the string passed is not an index, assume address of string
3634 and do our own AddString */
3635 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3636 LPSTR ptr;
3637 INT len;
3639 TRACE("string %s passed instead of index, adding string\n",
3640 debugstr_a((LPSTR)lpTbb->iString));
3641 len = strlen((LPSTR)lpTbb->iString) + 2;
3642 ptr = Alloc(len);
3643 strcpy(ptr, (LPSTR)lpTbb->iString);
3644 ptr[len - 1] = 0; /* ended by two '\0' */
3645 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3646 Free(ptr);
3649 TRACE("inserting button index=%d\n", nIndex);
3650 if (nIndex > infoPtr->nNumButtons) {
3651 nIndex = infoPtr->nNumButtons;
3652 TRACE("adjust index=%d\n", nIndex);
3655 oldButtons = infoPtr->buttons;
3656 infoPtr->nNumButtons++;
3657 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3658 /* pre insert copy */
3659 if (nIndex > 0) {
3660 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3661 nIndex * sizeof(TBUTTON_INFO));
3664 /* insert new button */
3665 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3666 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3667 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3668 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3669 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3670 /* if passed string and not index, then add string */
3671 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3672 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3674 else
3675 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3677 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3678 TTTOOLINFOA ti;
3680 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3681 ti.cbSize = sizeof (TTTOOLINFOA);
3682 ti.hwnd = hwnd;
3683 ti.uId = lpTbb->idCommand;
3684 ti.hinst = 0;
3685 ti.lpszText = LPSTR_TEXTCALLBACKA;
3687 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3688 0, (LPARAM)&ti);
3691 /* post insert copy */
3692 if (nIndex < infoPtr->nNumButtons - 1) {
3693 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3694 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3697 Free (oldButtons);
3699 TOOLBAR_CalcToolbar (hwnd);
3701 InvalidateRect (hwnd, NULL, TRUE);
3703 return TRUE;
3707 static LRESULT
3708 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3710 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3711 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3712 INT nIndex = (INT)wParam;
3713 TBUTTON_INFO *oldButtons;
3715 if (lpTbb == NULL)
3716 return FALSE;
3718 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3720 if (nIndex == -1) {
3721 /* EPP: this seems to be an undocumented call (from my IE4)
3722 * I assume in that case that:
3723 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3724 * - index of insertion is at the end of existing buttons
3725 * I only see this happen with nIndex == -1, but it could have a special
3726 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3728 nIndex = infoPtr->nNumButtons;
3730 } else if (nIndex < 0)
3731 return FALSE;
3733 /* If the string passed is not an index, assume address of string
3734 and do our own AddString */
3735 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3736 LPWSTR ptr;
3737 INT len;
3739 TRACE("string %s passed instead of index, adding string\n",
3740 debugstr_w((LPWSTR)lpTbb->iString));
3741 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3742 ptr = Alloc(len*sizeof(WCHAR));
3743 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3744 ptr[len - 1] = 0; /* ended by two '\0' */
3745 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3746 Free(ptr);
3749 TRACE("inserting button index=%d\n", nIndex);
3750 if (nIndex > infoPtr->nNumButtons) {
3751 nIndex = infoPtr->nNumButtons;
3752 TRACE("adjust index=%d\n", nIndex);
3755 oldButtons = infoPtr->buttons;
3756 infoPtr->nNumButtons++;
3757 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3758 /* pre insert copy */
3759 if (nIndex > 0) {
3760 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3761 nIndex * sizeof(TBUTTON_INFO));
3764 /* insert new button */
3765 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3766 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3767 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3768 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3769 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3770 /* if passed string and not index, then add string */
3771 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3772 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3774 else
3775 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3777 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3778 TTTOOLINFOW ti;
3780 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3781 ti.cbSize = sizeof (TTTOOLINFOW);
3782 ti.hwnd = hwnd;
3783 ti.uId = lpTbb->idCommand;
3784 ti.hinst = 0;
3785 ti.lpszText = LPSTR_TEXTCALLBACKW;
3787 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3788 0, (LPARAM)&ti);
3791 /* post insert copy */
3792 if (nIndex < infoPtr->nNumButtons - 1) {
3793 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3794 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3797 Free (oldButtons);
3799 TOOLBAR_CalcToolbar (hwnd);
3801 InvalidateRect (hwnd, NULL, TRUE);
3803 return TRUE;
3807 /* << TOOLBAR_InsertMarkHitTest >> */
3810 static LRESULT
3811 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3813 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3814 INT nIndex;
3816 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3817 if (nIndex == -1)
3818 return FALSE;
3820 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3824 static LRESULT
3825 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3827 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3828 INT nIndex;
3830 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3831 if (nIndex == -1)
3832 return FALSE;
3834 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3838 static LRESULT
3839 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3841 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3842 INT nIndex;
3844 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3845 if (nIndex == -1)
3846 return TRUE;
3848 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3852 static LRESULT
3853 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3855 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3856 INT nIndex;
3858 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3859 if (nIndex == -1)
3860 return FALSE;
3862 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3866 static LRESULT
3867 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3869 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3870 INT nIndex;
3872 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3873 if (nIndex == -1)
3874 return FALSE;
3876 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3880 static LRESULT
3881 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3883 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3884 INT nIndex;
3886 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3887 if (nIndex == -1)
3888 return FALSE;
3890 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3894 static LRESULT
3895 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3897 TBADDBITMAP tbab;
3898 tbab.hInst = (HINSTANCE)lParam;
3899 tbab.nID = (UINT_PTR)wParam;
3901 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3903 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3907 static LRESULT
3908 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3910 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3911 WCHAR wAccel = (WCHAR)wParam;
3912 UINT* pIDButton = (UINT*)lParam;
3913 WCHAR wszAccel[] = {'&',wAccel,0};
3914 int i;
3916 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3917 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3919 for (i = 0; i < infoPtr->nNumButtons; i++)
3921 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3922 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3923 !(btnPtr->fsState & TBSTATE_HIDDEN))
3925 int iLen = strlenW(wszAccel);
3926 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3928 if (!lpszStr)
3929 continue;
3931 while (*lpszStr)
3933 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3935 lpszStr += 2;
3936 continue;
3938 if (!strncmpiW(lpszStr, wszAccel, iLen))
3940 *pIDButton = btnPtr->idCommand;
3941 return TRUE;
3943 lpszStr++;
3947 return FALSE;
3951 static LRESULT
3952 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3954 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3955 INT nIndex;
3957 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3959 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3960 if (nIndex == -1)
3961 return FALSE;
3963 if (LOWORD(lParam))
3964 infoPtr->buttons[nIndex].fsState |= TBSTATE_MARKED;
3965 else
3966 infoPtr->buttons[nIndex].fsState &= ~TBSTATE_MARKED;
3968 return TRUE;
3972 /* fixes up an index of a button affected by a move */
3973 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
3975 if (bMoveUp)
3977 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
3978 (*pIndex)--;
3979 else if (*pIndex == nIndex)
3980 *pIndex = nMoveIndex;
3982 else
3984 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
3985 (*pIndex)++;
3986 else if (*pIndex == nIndex)
3987 *pIndex = nMoveIndex;
3992 static LRESULT
3993 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3995 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3996 INT nIndex;
3997 INT nCount;
3998 INT nMoveIndex = (INT)lParam;
3999 TBUTTON_INFO button;
4001 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4003 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4004 if ((nIndex == -1) || (nMoveIndex < 0))
4005 return FALSE;
4007 if (nMoveIndex > infoPtr->nNumButtons - 1)
4008 nMoveIndex = infoPtr->nNumButtons - 1;
4010 button = infoPtr->buttons[nIndex];
4012 /* move button right */
4013 if (nIndex < nMoveIndex)
4015 nCount = nMoveIndex - nIndex;
4016 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4017 infoPtr->buttons[nMoveIndex] = button;
4019 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4020 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4021 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4022 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4024 else if (nIndex > nMoveIndex) /* move button left */
4026 nCount = nIndex - nMoveIndex;
4027 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4028 infoPtr->buttons[nMoveIndex] = button;
4030 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4031 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4032 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4033 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4036 TOOLBAR_CalcToolbar(hwnd);
4037 InvalidateRect(hwnd, NULL, TRUE);
4039 return TRUE;
4043 static LRESULT
4044 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4046 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4047 TBUTTON_INFO *btnPtr;
4048 INT nIndex;
4049 DWORD oldState;
4051 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4052 if (nIndex == -1)
4053 return FALSE;
4055 btnPtr = &infoPtr->buttons[nIndex];
4056 oldState = btnPtr->fsState;
4057 if (LOWORD(lParam) == FALSE)
4058 btnPtr->fsState &= ~TBSTATE_PRESSED;
4059 else
4060 btnPtr->fsState |= TBSTATE_PRESSED;
4062 if(oldState != btnPtr->fsState)
4063 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4065 return TRUE;
4068 /* FIXME: there might still be some confusion her between number of buttons
4069 * and number of bitmaps */
4070 static LRESULT
4071 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4073 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4074 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4075 HBITMAP hBitmap;
4076 int i = 0, nOldButtons = 0, pos = 0;
4077 int nOldBitmaps, nNewBitmaps;
4078 HIMAGELIST himlDef = 0;
4080 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4081 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4082 lpReplace->nButtons);
4084 if (lpReplace->hInstOld == HINST_COMMCTRL)
4086 FIXME("changing standard bitmaps not implemented\n");
4087 return FALSE;
4089 else if (lpReplace->hInstOld != 0)
4091 FIXME("resources not in the current module not implemented\n");
4092 return FALSE;
4094 else
4096 hBitmap = (HBITMAP) lpReplace->nIDNew;
4099 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4100 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4101 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4102 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4103 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4105 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4106 nOldButtons = tbi->nButtons;
4107 tbi->nButtons = lpReplace->nButtons;
4108 tbi->hInst = lpReplace->hInstNew;
4109 tbi->nID = lpReplace->nIDNew;
4110 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4111 break;
4113 pos += tbi->nButtons;
4116 if (nOldButtons == 0)
4118 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4119 return FALSE;
4122 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4123 nOldBitmaps = ImageList_GetImageCount(himlDef);
4125 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4127 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4128 ImageList_Remove(himlDef, i);
4131 BITMAP bmp;
4132 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4133 HDC hdcImage, hdcBitmap;
4135 /* copy the bitmap before adding it so that the user's bitmap
4136 * doesn't get modified.
4138 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4140 hdcImage = CreateCompatibleDC(0);
4141 hdcBitmap = CreateCompatibleDC(0);
4143 /* create new bitmap */
4144 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4145 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4146 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4148 /* Copy the user's image */
4149 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4150 hdcBitmap, 0, 0, SRCCOPY);
4152 SelectObject (hdcImage, hOldBitmapLoad);
4153 SelectObject (hdcBitmap, hOldBitmapBitmap);
4154 DeleteDC (hdcImage);
4155 DeleteDC (hdcBitmap);
4157 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4158 nNewBitmaps = ImageList_GetImageCount(himlDef);
4159 DeleteObject (hbmLoad);
4162 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4164 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4165 pos, nOldBitmaps, nNewBitmaps);
4167 InvalidateRect(hwnd, NULL, TRUE);
4169 return TRUE;
4172 static LRESULT
4173 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4175 #if 0
4176 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4177 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
4179 if (lpSave == NULL) return 0;
4181 if ((BOOL)wParam) {
4182 /* save toolbar information */
4183 FIXME("save to \"%s\" \"%s\"\n",
4184 lpSave->pszSubKey, lpSave->pszValueName);
4188 else {
4189 /* restore toolbar information */
4191 FIXME("restore from \"%s\" \"%s\"\n",
4192 lpSave->pszSubKey, lpSave->pszValueName);
4196 #endif
4198 return 0;
4202 static LRESULT
4203 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4205 #if 0
4206 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4207 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
4209 if (lpSave == NULL)
4210 return 0;
4212 if ((BOOL)wParam) {
4213 /* save toolbar information */
4214 FIXME("save to \"%s\" \"%s\"\n",
4215 lpSave->pszSubKey, lpSave->pszValueName);
4219 else {
4220 /* restore toolbar information */
4222 FIXME("restore from \"%s\" \"%s\"\n",
4223 lpSave->pszSubKey, lpSave->pszValueName);
4227 #endif
4229 return 0;
4233 static LRESULT
4234 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4236 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4237 BOOL bOldAnchor = infoPtr->bAnchor;
4239 infoPtr->bAnchor = (BOOL)wParam;
4241 return (LRESULT)bOldAnchor;
4245 static LRESULT
4246 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4248 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4249 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4251 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4253 if (wParam != 0)
4254 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4256 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4257 return FALSE;
4259 if (infoPtr->nNumButtons > 0)
4260 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4261 infoPtr->nNumButtons,
4262 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4263 LOWORD(lParam), HIWORD(lParam));
4265 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4266 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4269 if ((himlDef == infoPtr->himlInt) &&
4270 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4272 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4273 infoPtr->nBitmapHeight);
4276 return TRUE;
4280 static LRESULT
4281 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4283 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4284 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4285 TBUTTON_INFO *btnPtr;
4286 INT nIndex;
4287 RECT oldBtnRect;
4289 if (lptbbi == NULL)
4290 return FALSE;
4291 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4292 return FALSE;
4294 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4295 lptbbi->dwMask & 0x80000000);
4296 if (nIndex == -1)
4297 return FALSE;
4299 btnPtr = &infoPtr->buttons[nIndex];
4300 if (lptbbi->dwMask & TBIF_COMMAND)
4301 btnPtr->idCommand = lptbbi->idCommand;
4302 if (lptbbi->dwMask & TBIF_IMAGE)
4303 btnPtr->iBitmap = lptbbi->iImage;
4304 if (lptbbi->dwMask & TBIF_LPARAM)
4305 btnPtr->dwData = lptbbi->lParam;
4306 if (lptbbi->dwMask & TBIF_SIZE)
4307 btnPtr->cx = lptbbi->cx;
4308 if (lptbbi->dwMask & TBIF_STATE)
4309 btnPtr->fsState = lptbbi->fsState;
4310 if (lptbbi->dwMask & TBIF_STYLE)
4311 btnPtr->fsStyle = lptbbi->fsStyle;
4313 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4314 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4315 /* iString is index, zero it to make Str_SetPtr succeed */
4316 btnPtr->iString=0;
4318 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4321 /* save the button rect to see if we need to redraw the whole toolbar */
4322 oldBtnRect = btnPtr->rect;
4323 TOOLBAR_CalcToolbar(hwnd);
4325 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4326 InvalidateRect(hwnd, NULL, TRUE);
4327 else
4328 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4330 return TRUE;
4334 static LRESULT
4335 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4337 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4338 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4339 TBUTTON_INFO *btnPtr;
4340 INT nIndex;
4341 RECT oldBtnRect;
4343 if (lptbbi == NULL)
4344 return FALSE;
4345 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4346 return FALSE;
4348 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4349 lptbbi->dwMask & 0x80000000);
4350 if (nIndex == -1)
4351 return FALSE;
4353 btnPtr = &infoPtr->buttons[nIndex];
4354 if (lptbbi->dwMask & TBIF_COMMAND)
4355 btnPtr->idCommand = lptbbi->idCommand;
4356 if (lptbbi->dwMask & TBIF_IMAGE)
4357 btnPtr->iBitmap = lptbbi->iImage;
4358 if (lptbbi->dwMask & TBIF_LPARAM)
4359 btnPtr->dwData = lptbbi->lParam;
4360 if (lptbbi->dwMask & TBIF_SIZE)
4361 btnPtr->cx = lptbbi->cx;
4362 if (lptbbi->dwMask & TBIF_STATE)
4363 btnPtr->fsState = lptbbi->fsState;
4364 if (lptbbi->dwMask & TBIF_STYLE)
4365 btnPtr->fsStyle = lptbbi->fsStyle;
4367 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4368 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4369 /* iString is index, zero it to make Str_SetPtr succeed */
4370 btnPtr->iString=0;
4371 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4374 /* save the button rect to see if we need to redraw the whole toolbar */
4375 oldBtnRect = btnPtr->rect;
4376 TOOLBAR_CalcToolbar(hwnd);
4378 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4379 InvalidateRect(hwnd, NULL, TRUE);
4380 else
4381 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4383 return TRUE;
4387 static LRESULT
4388 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4390 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4391 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4393 if ((cx < 0) || (cy < 0))
4395 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4396 return FALSE;
4399 /* The documentation claims you can only change the button size before
4400 * any button has been added. But this is wrong.
4401 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4402 * it to the toolbar, and it checks that the return value is nonzero - mjm
4403 * Further testing shows that we must actually perform the change too.
4406 * The documentation also does not mention that if 0 is supplied for
4407 * either size, the system changes it to the default of 24 wide and
4408 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4410 infoPtr->nButtonWidth = (cx) ? cx : 24;
4411 infoPtr->nButtonHeight = (cy) ? cy : 22;
4412 return TRUE;
4416 static LRESULT
4417 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4419 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4421 if (infoPtr == NULL) {
4422 TRACE("Toolbar not initialized yet?????\n");
4423 return FALSE;
4426 /* if setting to current values, ignore */
4427 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4428 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4429 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4430 infoPtr->cxMin, infoPtr->cxMax);
4431 return TRUE;
4434 /* save new values */
4435 infoPtr->cxMin = (INT)LOWORD(lParam);
4436 infoPtr->cxMax = (INT)HIWORD(lParam);
4438 /* if both values are 0 then we are done */
4439 if (lParam == 0) {
4440 TRACE("setting both min and max to 0, norecalc\n");
4441 return TRUE;
4444 /* otherwise we need to recalc the toolbar and in some cases
4445 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4446 which doesn't actually draw - GA). */
4447 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4448 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4450 TOOLBAR_CalcToolbar (hwnd);
4452 InvalidateRect (hwnd, NULL, TRUE);
4454 return TRUE;
4458 static LRESULT
4459 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4461 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4462 INT nIndex = (INT)wParam;
4464 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4465 return FALSE;
4467 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4469 if (infoPtr->hwndToolTip) {
4471 FIXME("change tool tip!\n");
4475 return TRUE;
4479 static LRESULT
4480 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4482 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4483 HIMAGELIST himl = (HIMAGELIST)lParam;
4484 HIMAGELIST himlTemp;
4485 INT id = 0;
4487 if (infoPtr->iVersion >= 5)
4488 id = wParam;
4490 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4491 &infoPtr->cimlDis, himl, id);
4493 /* FIXME: redraw ? */
4495 return (LRESULT)himlTemp;
4499 static LRESULT
4500 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4502 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4503 DWORD dwTemp;
4505 dwTemp = infoPtr->dwDTFlags;
4506 infoPtr->dwDTFlags =
4507 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4509 return (LRESULT)dwTemp;
4512 /* This function differs a bit from what MSDN says it does:
4513 * 1. lParam contains extended style flags to OR with current style
4514 * (MSDN isn't clear on the OR bit)
4515 * 2. wParam appears to contain extended style flags to be reset
4516 * (MSDN says that this parameter is reserved)
4518 static LRESULT
4519 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4521 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4522 DWORD dwTemp;
4524 dwTemp = infoPtr->dwExStyle;
4525 infoPtr->dwExStyle &= ~wParam;
4526 infoPtr->dwExStyle |= (DWORD)lParam;
4528 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4530 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4531 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4532 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4534 TOOLBAR_CalcToolbar (hwnd);
4536 TOOLBAR_AutoSize(hwnd);
4538 InvalidateRect(hwnd, NULL, TRUE);
4540 return (LRESULT)dwTemp;
4544 static LRESULT
4545 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4547 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4548 HIMAGELIST himlTemp;
4549 HIMAGELIST himl = (HIMAGELIST)lParam;
4550 INT id = 0;
4552 if (infoPtr->iVersion >= 5)
4553 id = wParam;
4555 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4557 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4558 &infoPtr->cimlHot, himl, id);
4560 /* FIXME: redraw ? */
4562 return (LRESULT)himlTemp;
4566 /* Makes previous hot button no longer hot, makes the specified
4567 * button hot and sends appropriate notifications. dwReason is one or
4568 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4569 * NOTE 1: this function does not validate nHit
4570 * NOTE 2: the name of this function is completely made up and
4571 * not based on any documentation from Microsoft. */
4572 static void
4573 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4575 if (infoPtr->nHotItem != nHit)
4577 NMTBHOTITEM nmhotitem;
4578 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4579 LRESULT no_highlight;
4581 /* Remove the effect of an old hot button if the button was
4582 drawn with the hot button effect */
4583 if(infoPtr->nHotItem >= 0)
4585 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4586 oldBtnPtr->bHot = FALSE;
4589 infoPtr->nHotItem = nHit;
4591 /* It's not a separator or in nowhere. It's a hot button. */
4592 if (nHit >= 0)
4593 btnPtr = &infoPtr->buttons[nHit];
4595 nmhotitem.dwFlags = dwReason;
4596 if (oldBtnPtr)
4597 nmhotitem.idOld = oldBtnPtr->idCommand;
4598 else
4599 nmhotitem.dwFlags |= HICF_ENTERING;
4600 if (btnPtr)
4601 nmhotitem.idNew = btnPtr->idCommand;
4602 else
4603 nmhotitem.dwFlags |= HICF_LEAVING;
4605 no_highlight = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4607 /* now invalidate the old and new buttons so they will be painted */
4608 if (oldBtnPtr)
4609 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4610 if (btnPtr && !no_highlight)
4612 btnPtr->bHot = TRUE;
4613 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4618 static LRESULT
4619 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4621 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4622 INT nOldHotItem = infoPtr->nHotItem;
4624 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4625 wParam = -2;
4627 if (GetWindowLongW(hwnd, GWL_STYLE) & TBSTYLE_FLAT)
4628 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4630 if (nOldHotItem < 0)
4631 return -1;
4633 return (LRESULT)nOldHotItem;
4637 static LRESULT
4638 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4640 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4641 HIMAGELIST himlTemp;
4642 HIMAGELIST himl = (HIMAGELIST)lParam;
4643 INT i, id = 0;
4645 if (infoPtr->iVersion >= 5)
4646 id = wParam;
4648 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4649 &infoPtr->cimlDef, himl, id);
4651 infoPtr->nNumBitmaps = 0;
4652 for (i = 0; i < infoPtr->cimlDef; i++)
4653 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4655 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4656 &infoPtr->nBitmapHeight);
4657 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4658 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4659 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4661 InvalidateRect(hwnd, NULL, TRUE);
4663 return (LRESULT)himlTemp;
4667 static LRESULT
4668 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4670 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4672 infoPtr->nIndent = (INT)wParam;
4674 TRACE("\n");
4676 /* process only on indent changing */
4677 if(infoPtr->nIndent != (INT)wParam)
4679 infoPtr->nIndent = (INT)wParam;
4680 TOOLBAR_CalcToolbar (hwnd);
4681 InvalidateRect(hwnd, NULL, FALSE);
4684 return TRUE;
4688 /* << TOOLBAR_SetInsertMark >> */
4691 static LRESULT
4692 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4694 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4696 infoPtr->clrInsertMark = (COLORREF)lParam;
4698 /* FIXME : redraw ??*/
4700 return 0;
4704 static LRESULT
4705 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4707 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4709 if (infoPtr == NULL)
4710 return FALSE;
4712 infoPtr->nMaxTextRows = (INT)wParam;
4714 TOOLBAR_CalcToolbar(hwnd);
4715 return TRUE;
4719 /* MSDN gives slightly wrong info on padding.
4720 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4721 * 2. It is not used to create a blank area between the edge of the button
4722 * and the text or image if TBSTYLE_LIST is set. It is used to control
4723 * the gap between the image and text.
4724 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4725 * to control the bottom and right borders [with the border being
4726 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4727 * is shared evenly on both sides of the button.
4729 static LRESULT
4730 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4732 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4733 DWORD oldPad;
4735 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4736 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4737 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4738 TRACE("cx=%ld, cy=%ld\n",
4739 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4740 return (LRESULT) oldPad;
4744 static LRESULT
4745 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4747 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4748 HWND hwndOldNotify;
4750 TRACE("\n");
4752 if (infoPtr == NULL)
4753 return 0;
4754 hwndOldNotify = infoPtr->hwndNotify;
4755 infoPtr->hwndNotify = (HWND)wParam;
4757 return (LRESULT)hwndOldNotify;
4761 static LRESULT
4762 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4764 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4765 LPRECT lprc = (LPRECT)lParam;
4767 TRACE("\n");
4769 if (LOWORD(wParam) > 1) {
4770 FIXME("multiple rows not supported!\n");
4773 if(infoPtr->nRows != LOWORD(wParam))
4775 infoPtr->nRows = LOWORD(wParam);
4777 /* recalculate toolbar */
4778 TOOLBAR_CalcToolbar (hwnd);
4780 /* repaint toolbar */
4781 InvalidateRect(hwnd, NULL, TRUE);
4784 /* return bounding rectangle */
4785 if (lprc) {
4786 lprc->left = infoPtr->rcBound.left;
4787 lprc->right = infoPtr->rcBound.right;
4788 lprc->top = infoPtr->rcBound.top;
4789 lprc->bottom = infoPtr->rcBound.bottom;
4792 return 0;
4796 static LRESULT
4797 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4799 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4800 TBUTTON_INFO *btnPtr;
4801 INT nIndex;
4803 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4804 if (nIndex == -1)
4805 return FALSE;
4807 btnPtr = &infoPtr->buttons[nIndex];
4809 /* if hidden state has changed the invalidate entire window and recalc */
4810 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4811 btnPtr->fsState = LOWORD(lParam);
4812 TOOLBAR_CalcToolbar (hwnd);
4813 InvalidateRect(hwnd, 0, TRUE);
4814 return TRUE;
4817 /* process state changing if current state doesn't match new state */
4818 if(btnPtr->fsState != LOWORD(lParam))
4820 btnPtr->fsState = LOWORD(lParam);
4821 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4824 return TRUE;
4828 static LRESULT
4829 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4831 SetWindowLongW(hwnd, GWL_STYLE, lParam);
4833 return TRUE;
4837 inline static LRESULT
4838 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4840 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4842 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
4844 if (infoPtr == NULL)
4845 return 0;
4846 infoPtr->hwndToolTip = (HWND)wParam;
4847 return 0;
4851 static LRESULT
4852 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4854 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4855 BOOL bTemp;
4857 TRACE("%s hwnd=%p stub!\n",
4858 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4860 bTemp = infoPtr->bUnicode;
4861 infoPtr->bUnicode = (BOOL)wParam;
4863 return bTemp;
4867 static LRESULT
4868 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4870 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4872 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4873 comctl32_color.clrBtnHighlight :
4874 infoPtr->clrBtnHighlight;
4875 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4876 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4877 return 1;
4881 static LRESULT
4882 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4884 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4886 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4887 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4888 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4890 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4891 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4892 InvalidateRect(hwnd, NULL, TRUE);
4893 return 0;
4897 static LRESULT
4898 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4900 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4901 INT iOldVersion = infoPtr->iVersion;
4903 infoPtr->iVersion = iVersion;
4905 if (infoPtr->iVersion >= 5)
4906 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
4908 return iOldVersion;
4912 static LRESULT
4913 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4915 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4916 WORD iString = HIWORD(wParam);
4917 WORD buffersize = LOWORD(wParam);
4918 LPSTR str = (LPSTR)lParam;
4919 LRESULT ret = -1;
4921 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
4923 if (iString < infoPtr->nNumStrings)
4925 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
4927 TRACE("returning %s\n", debugstr_a(str));
4929 else
4930 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4932 return ret;
4936 static LRESULT
4937 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4939 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4940 WORD iString = HIWORD(wParam);
4941 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
4942 LPWSTR str = (LPWSTR)lParam;
4943 LRESULT ret = -1;
4945 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
4947 if (iString < infoPtr->nNumStrings)
4949 len = min(len, strlenW(infoPtr->strings[iString]));
4950 ret = (len+1)*sizeof(WCHAR);
4951 memcpy(str, infoPtr->strings[iString], ret);
4952 str[len] = '\0';
4954 TRACE("returning %s\n", debugstr_w(str));
4956 else
4957 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4959 return ret;
4962 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
4963 * is the maximum size of the toolbar? */
4964 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
4966 SIZE * pSize = (SIZE*)lParam;
4967 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
4968 return 0;
4972 /* UNDOCUMENTED MESSAGE: This is an extended version of the
4973 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
4974 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
4975 * sends). */
4976 static LRESULT
4977 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
4979 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4980 INT nOldHotItem = infoPtr->nHotItem;
4982 TRACE("old item=%d, new item=%d, flags=%08lx\n",
4983 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
4985 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4986 wParam = -1;
4988 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
4990 GetFocus();
4992 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
4995 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
4996 * which controls the amount of spacing between the image and the text
4997 * of buttons for TBSTYLE_LIST toolbars. */
4998 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5000 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5002 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5004 if (lParam != 0)
5005 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5007 infoPtr->iListGap = (INT)wParam;
5009 TOOLBAR_CalcToolbar(hwnd);
5010 InvalidateRect(hwnd, NULL, TRUE);
5012 return 0;
5015 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5016 * of image lists associated with the various states. */
5017 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5019 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5021 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5023 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5026 static LRESULT
5027 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5029 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5030 LPSIZE lpsize = (LPSIZE)lParam;
5032 if (lpsize == NULL)
5033 return FALSE;
5036 * Testing shows the following:
5037 * wParam = 0 adjust cx value
5038 * = 1 set cy value to max size.
5039 * lParam pointer to SIZE structure
5042 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5043 wParam, lParam, lpsize->cx, lpsize->cy);
5045 switch(wParam) {
5046 case 0:
5047 if (lpsize->cx == -1) {
5048 /* **** this is wrong, native measures each button and sets it */
5049 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5051 else if(HIWORD(lpsize->cx)) {
5052 RECT rc;
5053 HWND hwndParent = GetParent(hwnd);
5055 GetWindowRect(hwnd, &rc);
5056 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5057 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5058 rc.left, rc.top, rc.right, rc.bottom);
5059 lpsize->cx = max(rc.right-rc.left,
5060 infoPtr->rcBound.right - infoPtr->rcBound.left);
5062 else {
5063 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5065 break;
5066 case 1:
5067 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5068 /* lpsize->cy = infoPtr->nHeight; */
5069 break;
5070 default:
5071 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5072 wParam);
5073 return 0;
5075 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5076 lpsize->cx, lpsize->cy);
5077 return 1;
5080 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5082 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5084 InvalidateRect(hwnd, NULL, TRUE);
5085 return 1;
5089 static LRESULT
5090 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5092 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5093 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5094 LOGFONTA logFont;
5096 TRACE("hwnd = %p\n", hwnd);
5098 /* initialize info structure */
5099 infoPtr->nButtonHeight = 22;
5100 infoPtr->nButtonWidth = 24;
5101 infoPtr->nBitmapHeight = 15;
5102 infoPtr->nBitmapWidth = 16;
5104 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
5105 infoPtr->nMaxTextRows = 1;
5106 infoPtr->cxMin = -1;
5107 infoPtr->cxMax = -1;
5108 infoPtr->nNumBitmaps = 0;
5109 infoPtr->nNumStrings = 0;
5111 infoPtr->bCaptured = FALSE;
5112 infoPtr->bUnicode = IsWindowUnicode (hwnd);
5113 infoPtr->nButtonDown = -1;
5114 infoPtr->nButtonDrag = -1;
5115 infoPtr->nOldHit = -1;
5116 infoPtr->nHotItem = -1;
5117 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5118 infoPtr->bTransparent = (dwStyle & TBSTYLE_TRANSPARENT);
5119 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5120 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
5121 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5122 infoPtr->iVersion = 0;
5123 infoPtr->hwndSelf = hwnd;
5124 infoPtr->bDoRedraw = TRUE;
5125 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5126 infoPtr->clrBtnShadow = CLR_DEFAULT;
5127 /* not sure where the +1 comes from, but this comes to the same value
5128 * as native so this is probably correct */
5129 infoPtr->szPadding.cx = 2*(GetSystemMetrics(SM_CXEDGE)+OFFSET_X) + 1;
5130 infoPtr->szPadding.cy = 2*(GetSystemMetrics(SM_CYEDGE)+OFFSET_Y);
5131 infoPtr->iListGap = infoPtr->szPadding.cx / 2;
5132 GetClientRect(hwnd, &infoPtr->client_rect);
5133 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
5135 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5136 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
5138 if (dwStyle & TBSTYLE_TOOLTIPS) {
5139 /* Create tooltip control */
5140 infoPtr->hwndToolTip =
5141 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
5142 CW_USEDEFAULT, CW_USEDEFAULT,
5143 CW_USEDEFAULT, CW_USEDEFAULT,
5144 hwnd, 0, 0, 0);
5146 /* Send NM_TOOLTIPSCREATED notification */
5147 if (infoPtr->hwndToolTip) {
5148 NMTOOLTIPSCREATED nmttc;
5150 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5152 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
5153 NM_TOOLTIPSCREATED);
5157 TOOLBAR_CheckStyle (hwnd, dwStyle);
5159 TOOLBAR_CalcToolbar(hwnd);
5161 return 0;
5165 static LRESULT
5166 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5168 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5170 /* delete tooltip control */
5171 if (infoPtr->hwndToolTip)
5172 DestroyWindow (infoPtr->hwndToolTip);
5174 /* delete temporary buffer for tooltip text */
5175 if (infoPtr->pszTooltipText)
5176 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5178 /* delete button data */
5179 if (infoPtr->buttons)
5180 Free (infoPtr->buttons);
5182 /* delete strings */
5183 if (infoPtr->strings) {
5184 INT i;
5185 for (i = 0; i < infoPtr->nNumStrings; i++)
5186 if (infoPtr->strings[i])
5187 Free (infoPtr->strings[i]);
5189 Free (infoPtr->strings);
5192 /* destroy internal image list */
5193 if (infoPtr->himlInt)
5194 ImageList_Destroy (infoPtr->himlInt);
5196 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5197 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5198 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5200 /* delete default font */
5201 if (infoPtr->hFont)
5202 DeleteObject (infoPtr->hDefaultFont);
5204 /* free toolbar info data */
5205 Free (infoPtr);
5206 SetWindowLongA (hwnd, 0, 0);
5208 return 0;
5212 static LRESULT
5213 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5215 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5216 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5217 NMTBCUSTOMDRAW tbcd;
5218 INT ret = FALSE;
5219 DWORD ntfret;
5221 if (dwStyle & TBSTYLE_CUSTOMERASE) {
5222 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5223 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5224 tbcd.nmcd.hdc = (HDC)wParam;
5225 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5226 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5228 /* FIXME: in general the return flags *can* be or'ed together */
5229 switch (infoPtr->dwBaseCustDraw)
5231 case CDRF_DODEFAULT:
5232 break;
5233 case CDRF_SKIPDEFAULT:
5234 return TRUE;
5235 default:
5236 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5237 hwnd, ntfret);
5241 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5242 * to my parent for processing.
5244 if (infoPtr->bTransparent) {
5245 POINT pt, ptorig;
5246 HDC hdc = (HDC)wParam;
5247 HWND parent;
5249 pt.x = 0;
5250 pt.y = 0;
5251 parent = GetParent(hwnd);
5252 MapWindowPoints(hwnd, parent, &pt, 1);
5253 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5254 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
5255 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5257 if (!ret)
5258 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
5260 if ((dwStyle & TBSTYLE_CUSTOMERASE) &&
5261 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5262 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5263 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5264 tbcd.nmcd.hdc = (HDC)wParam;
5265 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5266 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5267 switch (infoPtr->dwBaseCustDraw)
5269 case CDRF_DODEFAULT:
5270 break;
5271 case CDRF_SKIPDEFAULT:
5272 return TRUE;
5273 default:
5274 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5275 hwnd, ntfret);
5278 return ret;
5282 static LRESULT
5283 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5285 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5287 return (LRESULT)infoPtr->hFont;
5291 static LRESULT
5292 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5294 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5295 TBUTTON_INFO *btnPtr;
5296 POINT pt;
5297 INT nHit;
5299 pt.x = (INT)LOWORD(lParam);
5300 pt.y = (INT)HIWORD(lParam);
5301 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5303 if (nHit >= 0) {
5304 btnPtr = &infoPtr->buttons[nHit];
5305 if (!(btnPtr->fsState & TBSTATE_ENABLED))
5306 return 0;
5307 SetCapture (hwnd);
5308 infoPtr->bCaptured = TRUE;
5309 infoPtr->nButtonDown = nHit;
5311 btnPtr->fsState |= TBSTATE_PRESSED;
5313 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5315 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5316 TOOLBAR_Customize (hwnd);
5318 return 0;
5322 static LRESULT
5323 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5325 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5326 TBUTTON_INFO *btnPtr;
5327 POINT pt;
5328 INT nHit;
5329 NMTOOLBARA nmtb;
5330 BOOL bDragKeyPressed;
5332 if (GetWindowLongW(hwnd, GWL_STYLE) & TBSTYLE_ALTDRAG)
5333 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5334 else
5335 bDragKeyPressed = (wParam & MK_SHIFT);
5337 if (infoPtr->hwndToolTip)
5338 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5339 WM_LBUTTONDOWN, wParam, lParam);
5341 pt.x = (INT)LOWORD(lParam);
5342 pt.y = (INT)HIWORD(lParam);
5343 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5345 btnPtr = &infoPtr->buttons[nHit];
5347 if ((nHit >= 0) && bDragKeyPressed && (GetWindowLongW(hwnd, GWL_STYLE) & CCS_ADJUSTABLE))
5349 infoPtr->nButtonDrag = nHit;
5350 SetCapture (hwnd);
5352 /* If drag cursor has not been loaded, load it.
5353 * Note: it doesn't need to be freed */
5354 if (!hCursorDrag)
5355 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5356 SetCursor(hCursorDrag);
5358 else if (nHit >= 0)
5360 RECT arrowRect;
5361 infoPtr->nOldHit = nHit;
5363 CopyRect(&arrowRect, &btnPtr->rect);
5364 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5366 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5367 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5368 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5369 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5370 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5371 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5373 LRESULT res;
5375 /* draw in pressed state */
5376 btnPtr->fsState |= TBSTATE_PRESSED;
5377 RedrawWindow(hwnd,&btnPtr->rect,0,
5378 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5380 nmtb.iItem = btnPtr->idCommand;
5381 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
5382 nmtb.cchText = 0;
5383 nmtb.pszText = 0;
5384 CopyRect(&nmtb.rcButton, &btnPtr->rect);
5385 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5386 TBN_DROPDOWN);
5387 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5389 if (res != TBDDRET_TREATPRESSED)
5391 MSG msg;
5393 /* redraw button in unpressed state */
5394 btnPtr->fsState &= ~TBSTATE_PRESSED;
5395 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5397 /* find and set hot item
5398 * NOTE: native doesn't do this, but that is a bug */
5399 GetCursorPos(&pt);
5400 ScreenToClient(hwnd, &pt);
5401 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5402 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5404 /* remove any left mouse button down messages so that we can
5405 * get a toggle effect on the button */
5406 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE))
5409 return 0;
5411 /* otherwise drop through and process as pushed */
5413 infoPtr->bCaptured = TRUE;
5414 infoPtr->nButtonDown = nHit;
5416 btnPtr->fsState |= TBSTATE_PRESSED;
5418 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5420 if (btnPtr->fsState & TBSTATE_ENABLED)
5421 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5422 UpdateWindow(hwnd);
5423 SetCapture (hwnd);
5426 nmtb.iItem = btnPtr->idCommand;
5427 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5428 nmtb.tbButton.idCommand = btnPtr->idCommand;
5429 nmtb.tbButton.fsState = btnPtr->fsState;
5430 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5431 nmtb.tbButton.dwData = btnPtr->dwData;
5432 nmtb.tbButton.iString = btnPtr->iString;
5433 nmtb.cchText = 0; /* !!! not correct */
5434 nmtb.pszText = 0; /* !!! not correct */
5435 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5437 return 0;
5440 static LRESULT
5441 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5443 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5444 TBUTTON_INFO *btnPtr;
5445 POINT pt;
5446 INT nHit;
5447 INT nOldIndex = -1;
5448 BOOL bSendMessage = TRUE;
5449 NMHDR hdr;
5450 NMMOUSE nmmouse;
5451 NMTOOLBARA nmtb;
5453 if (infoPtr->hwndToolTip)
5454 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5455 WM_LBUTTONUP, wParam, lParam);
5457 pt.x = (INT)LOWORD(lParam);
5458 pt.y = (INT)HIWORD(lParam);
5459 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5461 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5463 if (infoPtr->nButtonDrag >= 0) {
5464 RECT rcClient;
5465 NMHDR hdr;
5467 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5468 ReleaseCapture();
5469 /* reset cursor */
5470 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5472 GetClientRect(hwnd, &rcClient);
5473 if (PtInRect(&rcClient, pt))
5475 INT nButton = -1;
5476 if (nHit >= 0)
5477 nButton = nHit;
5478 else if (nHit < -1)
5479 nButton = -nHit;
5480 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5481 nButton = -nHit;
5483 if (nButton == infoPtr->nButtonDrag)
5485 /* if the button is moved sightly left and we have a
5486 * separator there then remove it */
5487 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5489 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5490 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5492 else /* else insert a separator before the dragged button */
5494 TBBUTTON tbb;
5495 memset(&tbb, 0, sizeof(tbb));
5496 tbb.fsStyle = BTNS_SEP;
5497 tbb.iString = -1;
5498 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5501 else
5503 if (nButton == -1)
5505 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5506 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5507 else
5508 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5510 else
5511 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5514 else
5516 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5517 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5520 /* button under cursor changed so need to re-set hot item */
5521 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5522 infoPtr->nButtonDrag = -1;
5524 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5526 else if (infoPtr->nButtonDown >= 0) {
5527 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5528 btnPtr->fsState &= ~TBSTATE_PRESSED;
5530 if (btnPtr->fsStyle & BTNS_CHECK) {
5531 if (btnPtr->fsStyle & BTNS_GROUP) {
5532 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5533 nHit);
5534 if (nOldIndex == nHit)
5535 bSendMessage = FALSE;
5536 if ((nOldIndex != nHit) &&
5537 (nOldIndex != -1))
5538 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5539 btnPtr->fsState |= TBSTATE_CHECKED;
5541 else {
5542 if (btnPtr->fsState & TBSTATE_CHECKED)
5543 btnPtr->fsState &= ~TBSTATE_CHECKED;
5544 else
5545 btnPtr->fsState |= TBSTATE_CHECKED;
5549 if (nOldIndex != -1)
5550 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5553 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5554 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5555 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5557 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5558 ReleaseCapture ();
5559 infoPtr->nButtonDown = -1;
5561 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5562 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5563 NM_RELEASEDCAPTURE);
5565 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5566 * TBN_BEGINDRAG
5568 nmtb.iItem = btnPtr->idCommand;
5569 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5570 nmtb.tbButton.idCommand = btnPtr->idCommand;
5571 nmtb.tbButton.fsState = btnPtr->fsState;
5572 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5573 nmtb.tbButton.dwData = btnPtr->dwData;
5574 nmtb.tbButton.iString = btnPtr->iString;
5575 nmtb.cchText = 0; /* !!! not correct */
5576 nmtb.pszText = 0; /* !!! not correct */
5577 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5578 TBN_ENDDRAG);
5580 if (btnPtr->fsState & TBSTATE_ENABLED)
5582 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
5583 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5585 /* !!! Undocumented - toolbar at 4.71 level and above sends
5586 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
5587 * Only NM_RCLICK is documented.
5589 nmmouse.dwItemSpec = btnPtr->idCommand;
5590 nmmouse.dwItemData = btnPtr->dwData;
5591 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr, NM_CLICK);
5594 return 0;
5597 static LRESULT
5598 TOOLBAR_CaptureChanged(HWND hwnd)
5600 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5601 TBUTTON_INFO *btnPtr;
5603 infoPtr->bCaptured = FALSE;
5605 if (infoPtr->nButtonDown >= 0)
5607 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5608 btnPtr->fsState &= ~TBSTATE_PRESSED;
5610 infoPtr->nOldHit = -1;
5612 if (btnPtr->fsState & TBSTATE_ENABLED)
5613 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5615 return 0;
5618 static LRESULT
5619 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5621 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5622 TBUTTON_INFO *hotBtnPtr, *btnPtr;
5623 RECT rc1;
5625 TOOLBAR_SetHotItemEx(infoPtr, -1, HICF_MOUSE);
5627 if (infoPtr->nOldHit < 0)
5628 return TRUE;
5630 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5632 /* If the last button we were over is depressed then make it not */
5633 /* depressed and redraw it */
5634 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5636 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5638 btnPtr->fsState &= ~TBSTATE_PRESSED;
5640 rc1 = hotBtnPtr->rect;
5641 InflateRect (&rc1, 1, 1);
5642 InvalidateRect (hwnd, &rc1, TRUE);
5645 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5647 return TRUE;
5650 static LRESULT
5651 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5653 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5654 POINT pt;
5655 TRACKMOUSEEVENT trackinfo;
5656 INT nHit;
5657 TBUTTON_INFO *btnPtr;
5659 /* fill in the TRACKMOUSEEVENT struct */
5660 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5661 trackinfo.dwFlags = TME_QUERY;
5662 trackinfo.hwndTrack = hwnd;
5663 trackinfo.dwHoverTime = HOVER_DEFAULT;
5665 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5666 _TrackMouseEvent(&trackinfo);
5668 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5669 if(!(trackinfo.dwFlags & TME_LEAVE)) {
5670 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5672 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5673 /* and can properly deactivate the hot toolbar button */
5674 _TrackMouseEvent(&trackinfo);
5677 if (infoPtr->hwndToolTip)
5678 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5679 WM_MOUSEMOVE, wParam, lParam);
5681 pt.x = (INT)LOWORD(lParam);
5682 pt.y = (INT)HIWORD(lParam);
5684 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5686 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
5688 if (infoPtr->nOldHit != nHit)
5690 if (infoPtr->bCaptured)
5692 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5693 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5694 btnPtr->fsState &= ~TBSTATE_PRESSED;
5695 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5697 else if (nHit == infoPtr->nButtonDown) {
5698 btnPtr->fsState |= TBSTATE_PRESSED;
5699 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5701 infoPtr->nOldHit = nHit;
5705 return 0;
5709 inline static LRESULT
5710 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5712 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5713 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5714 /* else */
5715 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5719 inline static LRESULT
5720 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5722 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
5723 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5725 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5729 static LRESULT
5730 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5732 TOOLBAR_INFO *infoPtr;
5733 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5734 DWORD styleadd = 0;
5736 /* allocate memory for info structure */
5737 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
5738 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
5740 /* paranoid!! */
5741 infoPtr->dwStructSize = sizeof(TBBUTTON);
5742 infoPtr->nRows = 1;
5744 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5745 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
5746 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
5747 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
5750 /* native control does:
5751 * Get a lot of colors and brushes
5752 * WM_NOTIFYFORMAT
5753 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5754 * CreateFontIndirectA(adr1)
5755 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5756 * hdc = GetDC(toolbar)
5757 * GetSystemMetrics(0x48)
5758 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5759 * 0, 0, 0, 0, "MARLETT")
5760 * oldfnt = SelectObject(hdc, fnt2)
5761 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5762 * GetTextMetricsA(hdc, adr3)
5763 * SelectObject(hdc, oldfnt)
5764 * DeleteObject(fnt2)
5765 * ReleaseDC(hdc)
5766 * InvalidateRect(toolbar, 0, 1)
5767 * SetWindowLongA(toolbar, 0, addr)
5768 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5769 * WM_STYLECHANGING
5770 * CallWinEx old new
5771 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5772 * ie 2 0x4600094c 0x4600094c 0x4600894d
5773 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5774 * rebar 0x50008844 0x40008844 0x50008845
5775 * pager 0x50000844 0x40000844 0x50008845
5776 * IC35mgr 0x5400084e **nochange**
5777 * on entry to _NCCREATE 0x5400084e
5778 * rowlist 0x5400004e **nochange**
5779 * on entry to _NCCREATE 0x5400004e
5783 /* I think the code below is a bug, but it is the way that the native
5784 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5785 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5786 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5787 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5788 * Some how, the only cases of this seem to be MFC programs.
5790 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5791 * does not occur in the WM_STYLECHANGING routine.
5792 * (Guy Albertelli 9/2001)
5795 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5796 styleadd |= TBSTYLE_TRANSPARENT;
5797 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5798 styleadd |= CCS_TOP; /* default to top */
5799 SetWindowLongA (hwnd, GWL_STYLE, cs->style | styleadd);
5802 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5806 static LRESULT
5807 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5809 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5810 RECT rcWindow;
5811 HDC hdc;
5813 if (dwStyle & WS_MINIMIZE)
5814 return 0; /* Nothing to do */
5816 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5818 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5819 return 0;
5821 if (!(dwStyle & CCS_NODIVIDER))
5823 GetWindowRect (hwnd, &rcWindow);
5824 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5825 if( dwStyle & WS_BORDER )
5826 OffsetRect (&rcWindow, 1, 1);
5827 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5830 ReleaseDC( hwnd, hdc );
5832 return 0;
5836 /* handles requests from the tooltip control on what text to display */
5837 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
5839 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
5841 TRACE("button index = %d\n", index);
5843 if (infoPtr->pszTooltipText)
5845 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5846 infoPtr->pszTooltipText = NULL;
5849 if (index < 0)
5850 return 0;
5852 if (infoPtr->bNtfUnicode)
5854 WCHAR wszBuffer[INFOTIPSIZE+1];
5855 NMTBGETINFOTIPW tbgit;
5856 int len; /* in chars */
5858 wszBuffer[0] = '\0';
5859 wszBuffer[INFOTIPSIZE] = '\0';
5861 tbgit.pszText = wszBuffer;
5862 tbgit.cchTextMax = INFOTIPSIZE;
5863 tbgit.iItem = lpnmtdi->hdr.idFrom;
5864 tbgit.lParam = infoPtr->buttons[index].dwData;
5866 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
5868 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
5870 len = strlenW(tbgit.pszText);
5871 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5873 /* need to allocate temporary buffer in infoPtr as there
5874 * isn't enough space in buffer passed to us by the
5875 * tooltip control */
5876 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5877 if (infoPtr->pszTooltipText)
5879 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
5880 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5881 return 0;
5884 else if (len > 0)
5886 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
5887 return 0;
5890 else
5892 CHAR szBuffer[INFOTIPSIZE+1];
5893 NMTBGETINFOTIPA tbgit;
5894 int len; /* in chars */
5896 szBuffer[0] = '\0';
5897 szBuffer[INFOTIPSIZE] = '\0';
5899 tbgit.pszText = szBuffer;
5900 tbgit.cchTextMax = INFOTIPSIZE;
5901 tbgit.iItem = lpnmtdi->hdr.idFrom;
5902 tbgit.lParam = infoPtr->buttons[index].dwData;
5904 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
5906 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
5908 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
5909 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5911 /* need to allocate temporary buffer in infoPtr as there
5912 * isn't enough space in buffer passed to us by the
5913 * tooltip control */
5914 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5915 if (infoPtr->pszTooltipText)
5917 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
5918 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5919 return 0;
5922 else if (len > 0)
5924 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
5925 return 0;
5929 /* if button has text, but it is not shown then automatically
5930 * use that text as tooltip */
5931 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
5932 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
5934 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
5935 int len = pszText ? strlenW(pszText) : 0;
5937 TRACE("using button hidden text %s\n", debugstr_w(pszText));
5939 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5941 /* need to allocate temporary buffer in infoPtr as there
5942 * isn't enough space in buffer passed to us by the
5943 * tooltip control */
5944 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5945 if (infoPtr->pszTooltipText)
5947 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
5948 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5949 return 0;
5952 else if (len > 0)
5954 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
5955 return 0;
5959 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
5961 /* last resort: send notification on to app */
5962 /* FIXME: find out what is really used here */
5963 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
5967 inline static LRESULT
5968 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
5970 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5971 LPNMHDR lpnmh = (LPNMHDR)lParam;
5973 switch (lpnmh->code)
5975 case PGN_CALCSIZE:
5977 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
5979 if (lppgc->dwFlag == PGF_CALCWIDTH) {
5980 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
5981 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
5982 lppgc->iWidth);
5984 else {
5985 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5986 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
5987 lppgc->iHeight);
5989 return 0;
5992 case PGN_SCROLL:
5994 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
5996 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
5997 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
5998 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
5999 lppgs->iScroll, lppgs->iDir);
6000 return 0;
6003 case TTN_GETDISPINFOW:
6004 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6006 case TTN_GETDISPINFOA:
6007 FIXME("TTN_GETDISPINFOA - stub\n");
6008 return 0;
6010 default:
6011 return 0;
6016 static LRESULT
6017 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
6019 /* remove this routine when Toolbar is improved to pass infoPtr
6020 * around instead of hwnd.
6022 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6023 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
6027 static LRESULT
6028 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6030 INT i;
6032 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6034 if ((lParam == NF_QUERY) && ((HWND)wParam == infoPtr->hwndToolTip))
6035 return NFR_UNICODE;
6037 if (lParam == NF_REQUERY) {
6038 i = SendMessageA(infoPtr->hwndNotify,
6039 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6040 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
6041 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
6043 i = NFR_ANSI;
6045 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
6046 return (LRESULT)i;
6048 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
6052 static LRESULT
6053 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6055 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6056 HDC hdc;
6057 PAINTSTRUCT ps;
6059 /* fill ps.rcPaint with a default rect */
6060 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6062 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6064 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6065 ps.rcPaint.left, ps.rcPaint.top,
6066 ps.rcPaint.right, ps.rcPaint.bottom);
6068 TOOLBAR_Refresh (hwnd, hdc, &ps);
6069 if (!wParam) EndPaint (hwnd, &ps);
6071 return 0;
6075 static LRESULT
6076 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6077 /*****************************************************
6079 * Function;
6080 * Handles the WM_SETREDRAW message.
6082 * Documentation:
6083 * According to testing V4.71 of COMCTL32 returns the
6084 * *previous* status of the redraw flag (either 0 or 1)
6085 * instead of the MSDN documented value of 0 if handled.
6086 * (For laughs see the "consistency" with same function
6087 * in rebar.)
6089 *****************************************************/
6091 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6092 BOOL oldredraw = infoPtr->bDoRedraw;
6094 TRACE("set to %s\n",
6095 (wParam) ? "TRUE" : "FALSE");
6096 infoPtr->bDoRedraw = (BOOL) wParam;
6097 if (wParam) {
6098 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6100 return (oldredraw) ? 1 : 0;
6104 static LRESULT
6105 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6107 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6108 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
6109 RECT parent_rect;
6110 RECT window_rect;
6111 HWND parent;
6112 INT x, y;
6113 INT cx, cy;
6114 INT flags;
6115 UINT uPosFlags = 0;
6117 /* Resize deadlock check */
6118 if (infoPtr->bAutoSize) {
6119 infoPtr->bAutoSize = FALSE;
6120 return 0;
6123 /* FIXME: optimize to only update size if the new size doesn't */
6124 /* match the current size */
6126 flags = (INT) wParam;
6128 /* FIXME for flags =
6129 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
6132 TRACE("sizing toolbar!\n");
6134 if (flags == SIZE_RESTORED) {
6135 /* width and height don't apply */
6136 parent = GetParent (hwnd);
6137 GetClientRect(parent, &parent_rect);
6138 x = parent_rect.left;
6139 y = parent_rect.top;
6141 if (dwStyle & CCS_NORESIZE) {
6142 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
6145 * this sets the working width of the toolbar, and
6146 * Calc Toolbar will not adjust it, only the height
6148 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6149 cy = infoPtr->nHeight;
6150 cx = infoPtr->nWidth;
6151 TOOLBAR_CalcToolbar (hwnd);
6152 infoPtr->nWidth = cx;
6153 infoPtr->nHeight = cy;
6155 else {
6156 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6157 TOOLBAR_CalcToolbar (hwnd);
6158 cy = infoPtr->nHeight;
6159 cx = infoPtr->nWidth;
6161 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
6162 GetWindowRect(hwnd, &window_rect);
6163 ScreenToClient(parent, (LPPOINT)&window_rect.left);
6164 y = window_rect.top;
6166 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
6167 GetWindowRect(hwnd, &window_rect);
6168 y = parent_rect.bottom -
6169 ( window_rect.bottom - window_rect.top);
6173 if (dwStyle & CCS_NOPARENTALIGN) {
6174 uPosFlags |= SWP_NOMOVE;
6175 cy = infoPtr->nHeight;
6176 cx = infoPtr->nWidth;
6179 if (!(dwStyle & CCS_NODIVIDER))
6180 cy += GetSystemMetrics(SM_CYEDGE);
6182 if (dwStyle & WS_BORDER)
6184 x = y = 1;
6185 cy += GetSystemMetrics(SM_CYEDGE);
6186 cx += GetSystemMetrics(SM_CYEDGE);
6189 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6191 RECT delta_width, delta_height, client, dummy;
6192 DWORD min_x, max_x, min_y, max_y;
6193 TBUTTON_INFO *btnPtr;
6194 INT i;
6196 GetClientRect(hwnd, &client);
6197 if(client.right > infoPtr->client_rect.right)
6199 min_x = infoPtr->client_rect.right;
6200 max_x = client.right;
6202 else
6204 max_x = infoPtr->client_rect.right;
6205 min_x = client.right;
6207 if(client.bottom > infoPtr->client_rect.bottom)
6209 min_y = infoPtr->client_rect.bottom;
6210 max_y = client.bottom;
6212 else
6214 max_y = infoPtr->client_rect.bottom;
6215 min_y = client.bottom;
6218 SetRect(&delta_width, min_x, 0, max_x, min_y);
6219 SetRect(&delta_height, 0, min_y, max_x, max_y);
6221 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6222 btnPtr = infoPtr->buttons;
6223 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6224 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6225 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6226 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6229 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) == (SWP_NOSIZE | SWP_NOMOVE))
6230 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6232 GetClientRect(hwnd, &infoPtr->client_rect);
6233 return 0;
6237 static LRESULT
6238 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6240 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6242 if (nType == GWL_STYLE) {
6243 if (lpStyle->styleNew & TBSTYLE_LIST) {
6244 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
6246 else {
6247 infoPtr->dwDTFlags = DT_CENTER;
6249 infoPtr->bTransparent = (lpStyle->styleNew & TBSTYLE_TRANSPARENT);
6250 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6251 (TBSTYLE_FLAT | TBSTYLE_LIST));
6252 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6254 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6257 TOOLBAR_CalcToolbar(hwnd);
6259 TOOLBAR_AutoSize (hwnd);
6261 InvalidateRect(hwnd, NULL, TRUE);
6263 return 0;
6267 static LRESULT
6268 TOOLBAR_SysColorChange (HWND hwnd)
6270 COMCTL32_RefreshSysColors();
6272 return 0;
6277 static LRESULT WINAPI
6278 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6280 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6282 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6283 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6285 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
6286 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
6288 switch (uMsg)
6290 case TB_ADDBITMAP:
6291 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6293 case TB_ADDBUTTONSA:
6294 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6296 case TB_ADDBUTTONSW:
6297 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6299 case TB_ADDSTRINGA:
6300 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6302 case TB_ADDSTRINGW:
6303 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6305 case TB_AUTOSIZE:
6306 return TOOLBAR_AutoSize (hwnd);
6308 case TB_BUTTONCOUNT:
6309 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6311 case TB_BUTTONSTRUCTSIZE:
6312 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6314 case TB_CHANGEBITMAP:
6315 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6317 case TB_CHECKBUTTON:
6318 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6320 case TB_COMMANDTOINDEX:
6321 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6323 case TB_CUSTOMIZE:
6324 return TOOLBAR_Customize (hwnd);
6326 case TB_DELETEBUTTON:
6327 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6329 case TB_ENABLEBUTTON:
6330 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6332 case TB_GETANCHORHIGHLIGHT:
6333 return TOOLBAR_GetAnchorHighlight (hwnd);
6335 case TB_GETBITMAP:
6336 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6338 case TB_GETBITMAPFLAGS:
6339 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6341 case TB_GETBUTTON:
6342 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6344 case TB_GETBUTTONINFOA:
6345 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6347 case TB_GETBUTTONINFOW:
6348 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6350 case TB_GETBUTTONSIZE:
6351 return TOOLBAR_GetButtonSize (hwnd);
6353 case TB_GETBUTTONTEXTA:
6354 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6356 case TB_GETBUTTONTEXTW:
6357 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6359 case TB_GETDISABLEDIMAGELIST:
6360 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6362 case TB_GETEXTENDEDSTYLE:
6363 return TOOLBAR_GetExtendedStyle (hwnd);
6365 case TB_GETHOTIMAGELIST:
6366 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6368 case TB_GETHOTITEM:
6369 return TOOLBAR_GetHotItem (hwnd);
6371 case TB_GETIMAGELIST:
6372 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6374 /* case TB_GETINSERTMARK: */ /* 4.71 */
6375 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
6377 case TB_GETITEMRECT:
6378 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6380 case TB_GETMAXSIZE:
6381 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6383 /* case TB_GETOBJECT: */ /* 4.71 */
6385 case TB_GETPADDING:
6386 return TOOLBAR_GetPadding (hwnd);
6388 case TB_GETRECT:
6389 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6391 case TB_GETROWS:
6392 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6394 case TB_GETSTATE:
6395 return TOOLBAR_GetState (hwnd, wParam, lParam);
6397 case TB_GETSTRINGA:
6398 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6400 case TB_GETSTRINGW:
6401 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6403 case TB_GETSTYLE:
6404 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6406 case TB_GETTEXTROWS:
6407 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6409 case TB_GETTOOLTIPS:
6410 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6412 case TB_GETUNICODEFORMAT:
6413 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6415 case TB_HIDEBUTTON:
6416 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6418 case TB_HITTEST:
6419 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6421 case TB_INDETERMINATE:
6422 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6424 case TB_INSERTBUTTONA:
6425 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6427 case TB_INSERTBUTTONW:
6428 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6430 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6432 case TB_ISBUTTONCHECKED:
6433 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6435 case TB_ISBUTTONENABLED:
6436 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6438 case TB_ISBUTTONHIDDEN:
6439 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6441 case TB_ISBUTTONHIGHLIGHTED:
6442 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6444 case TB_ISBUTTONINDETERMINATE:
6445 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6447 case TB_ISBUTTONPRESSED:
6448 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6450 case TB_LOADIMAGES:
6451 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6453 case TB_MAPACCELERATORA:
6454 case TB_MAPACCELERATORW:
6455 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6457 case TB_MARKBUTTON:
6458 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6460 case TB_MOVEBUTTON:
6461 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6463 case TB_PRESSBUTTON:
6464 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6466 case TB_REPLACEBITMAP:
6467 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6469 case TB_SAVERESTOREA:
6470 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
6472 case TB_SAVERESTOREW:
6473 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
6475 case TB_SETANCHORHIGHLIGHT:
6476 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6478 case TB_SETBITMAPSIZE:
6479 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6481 case TB_SETBUTTONINFOA:
6482 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6484 case TB_SETBUTTONINFOW:
6485 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6487 case TB_SETBUTTONSIZE:
6488 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6490 case TB_SETBUTTONWIDTH:
6491 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6493 case TB_SETCMDID:
6494 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6496 case TB_SETDISABLEDIMAGELIST:
6497 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6499 case TB_SETDRAWTEXTFLAGS:
6500 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6502 case TB_SETEXTENDEDSTYLE:
6503 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6505 case TB_SETHOTIMAGELIST:
6506 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6508 case TB_SETHOTITEM:
6509 return TOOLBAR_SetHotItem (hwnd, wParam);
6511 case TB_SETIMAGELIST:
6512 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6514 case TB_SETINDENT:
6515 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6517 /* case TB_SETINSERTMARK: */ /* 4.71 */
6519 case TB_SETINSERTMARKCOLOR:
6520 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6522 case TB_SETMAXTEXTROWS:
6523 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6525 case TB_SETPADDING:
6526 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6528 case TB_SETPARENT:
6529 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6531 case TB_SETROWS:
6532 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6534 case TB_SETSTATE:
6535 return TOOLBAR_SetState (hwnd, wParam, lParam);
6537 case TB_SETSTYLE:
6538 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6540 case TB_SETTOOLTIPS:
6541 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6543 case TB_SETUNICODEFORMAT:
6544 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6546 case TB_UNKWN45D:
6547 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6549 case TB_UNKWN45E:
6550 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6552 case TB_UNKWN460:
6553 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6555 case TB_UNKWN462:
6556 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6558 case TB_UNKWN463:
6559 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6561 case TB_UNKWN464:
6562 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6564 /* Common Control Messages */
6566 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6567 case CCM_GETCOLORSCHEME:
6568 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6570 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6571 case CCM_SETCOLORSCHEME:
6572 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6574 case CCM_GETVERSION:
6575 return TOOLBAR_GetVersion (hwnd);
6577 case CCM_SETVERSION:
6578 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6581 /* case WM_CHAR: */
6583 case WM_CREATE:
6584 return TOOLBAR_Create (hwnd, wParam, lParam);
6586 case WM_DESTROY:
6587 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6589 case WM_ERASEBKGND:
6590 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6592 case WM_GETFONT:
6593 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6595 /* case WM_KEYDOWN: */
6596 /* case WM_KILLFOCUS: */
6598 case WM_LBUTTONDBLCLK:
6599 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6601 case WM_LBUTTONDOWN:
6602 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6604 case WM_LBUTTONUP:
6605 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6607 case WM_MOUSEMOVE:
6608 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6610 case WM_MOUSELEAVE:
6611 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6613 case WM_CAPTURECHANGED:
6614 return TOOLBAR_CaptureChanged(hwnd);
6616 case WM_NCACTIVATE:
6617 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6619 case WM_NCCALCSIZE:
6620 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6622 case WM_NCCREATE:
6623 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6625 case WM_NCPAINT:
6626 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6628 case WM_NOTIFY:
6629 return TOOLBAR_Notify (hwnd, wParam, lParam);
6631 case WM_NOTIFYFORMAT:
6632 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
6634 case WM_PAINT:
6635 return TOOLBAR_Paint (hwnd, wParam);
6637 case WM_SETREDRAW:
6638 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6640 case WM_SIZE:
6641 return TOOLBAR_Size (hwnd, wParam, lParam);
6643 case WM_STYLECHANGED:
6644 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6646 case WM_SYSCOLORCHANGE:
6647 return TOOLBAR_SysColorChange (hwnd);
6649 /* case WM_WININICHANGE: */
6651 case WM_CHARTOITEM:
6652 case WM_COMMAND:
6653 case WM_DRAWITEM:
6654 case WM_MEASUREITEM:
6655 case WM_VKEYTOITEM:
6656 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
6658 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6659 case PGM_FORWARDMOUSE:
6660 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6662 default:
6663 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6664 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6665 uMsg, wParam, lParam);
6666 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6668 return 0;
6672 VOID
6673 TOOLBAR_Register (void)
6675 WNDCLASSA wndClass;
6677 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
6678 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6679 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
6680 wndClass.cbClsExtra = 0;
6681 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6682 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
6683 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
6684 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
6686 RegisterClassA (&wndClass);
6690 VOID
6691 TOOLBAR_Unregister (void)
6693 UnregisterClassA (TOOLBARCLASSNAMEA, NULL);
6696 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6698 HIMAGELIST himlold;
6699 PIMLENTRY c = NULL;
6701 /* Check if the entry already exists */
6702 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6704 /* If this is a new entry we must create it and insert into the array */
6705 if (!c)
6707 PIMLENTRY *pnies;
6709 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
6710 c->id = id;
6712 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
6713 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6714 pnies[*cies] = c;
6715 (*cies)++;
6717 Free(*pies);
6718 *pies = pnies;
6721 himlold = c->himl;
6722 c->himl = himl;
6724 return himlold;
6728 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6730 int i;
6732 for (i = 0; i < *cies; i++)
6733 Free((*pies)[i]);
6735 Free(*pies);
6737 *cies = 0;
6738 *pies = NULL;
6742 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
6744 PIMLENTRY c = NULL;
6746 if (pies != NULL)
6748 int i;
6750 for (i = 0; i < cies; i++)
6752 if (pies[i]->id == id)
6754 c = pies[i];
6755 break;
6760 return c;
6764 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
6766 HIMAGELIST himlDef = 0;
6767 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6769 if (pie)
6770 himlDef = pie->himl;
6772 return himlDef;
6776 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6778 if (infoPtr->bUnicode)
6779 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
6780 else
6782 CHAR Buffer[256];
6783 NMTOOLBARA nmtba;
6784 BOOL bRet = FALSE;
6786 nmtba.iItem = nmtb->iItem;
6787 nmtba.pszText = Buffer;
6788 nmtba.cchText = 256;
6789 ZeroMemory(nmtba.pszText, nmtba.cchText);
6791 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
6793 int ccht = strlen(nmtba.pszText);
6794 if (ccht)
6795 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
6796 nmtb->pszText, nmtb->cchText);
6798 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
6799 bRet = TRUE;
6802 return bRet;
6807 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
6808 int iItem, PCUSTOMBUTTON btnInfo)
6810 NMTOOLBARA nmtb;
6812 nmtb.iItem = iItem;
6813 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
6815 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE);