Getting the string for a null field should not create an error. Add a
[wine/wine-kai.git] / dlls / comctl32 / toolbar.c
bloba9be00436a76ae0c2112e15988be2767adbbc6ff
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_GETMETRICS
46 * - TB_GETOBJECT
47 * - TB_INSERTMARKHITTEST
48 * - TB_SETMETRICS
49 * - Notifications:
50 * - NM_CHAR
51 * - NM_KEYDOWN
52 * - TBN_GETOBJECT
53 * - TBN_RESTORE
54 * - TBN_SAVE
55 * - Button wrapping (under construction).
56 * - Fix TB_SETROWS.
57 * - iListGap custom draw support.
58 * - Customization dialog:
59 * - Minor buglet in 'available buttons' list:
60 * Buttons are not listed in MS-like order. MS seems to use a single
61 * internal list to store the button information of both listboxes.
62 * - Drag list support.
64 * Testing:
65 * - Run tests using Waite Group Windows95 API Bible Volume 2.
66 * The second cdrom contains executables addstr.exe, btncount.exe,
67 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
68 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
69 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
70 * setparnt.exe, setrows.exe, toolwnd.exe.
71 * - Microsofts controlspy examples.
72 * - Charles Petzold's 'Programming Windows': gadgets.exe
75 #include <stdarg.h>
76 #include <string.h>
78 #include "windef.h"
79 #include "winbase.h"
80 #include "wingdi.h"
81 #include "winuser.h"
82 #include "wine/unicode.h"
83 #include "winnls.h"
84 #include "commctrl.h"
85 #include "comctl32.h"
86 #include "wine/debug.h"
88 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
90 static HCURSOR hCursorDrag = NULL;
92 typedef struct
94 INT iBitmap;
95 INT idCommand;
96 BYTE fsState;
97 BYTE fsStyle;
98 BYTE bHot;
99 BYTE bDropDownPressed;
100 DWORD dwData;
101 INT iString;
102 INT nRow;
103 RECT rect;
104 INT cx; /* manually set size */
105 } TBUTTON_INFO;
107 typedef struct
109 UINT nButtons;
110 HINSTANCE hInst;
111 UINT nID;
112 } TBITMAP_INFO;
114 typedef struct
116 HIMAGELIST himl;
117 INT id;
118 } IMLENTRY, *PIMLENTRY;
120 typedef struct
122 DWORD dwStructSize; /* size of TBBUTTON struct */
123 INT nHeight; /* height of the toolbar */
124 INT nWidth; /* width of the toolbar */
125 RECT client_rect;
126 RECT rcBound; /* bounding rectangle */
127 INT nButtonHeight;
128 INT nButtonWidth;
129 INT nBitmapHeight;
130 INT nBitmapWidth;
131 INT nIndent;
132 INT nRows; /* number of button rows */
133 INT nMaxTextRows; /* maximum number of text rows */
134 INT cxMin; /* minimum button width */
135 INT cxMax; /* maximum button width */
136 INT nNumButtons; /* number of buttons */
137 INT nNumBitmaps; /* number of bitmaps */
138 INT nNumStrings; /* number of strings */
139 INT nNumBitmapInfos;
140 INT nButtonDown; /* toolbar button being pressed or -1 if none */
141 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
142 INT nOldHit;
143 INT nHotItem; /* index of the "hot" item */
144 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
145 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
146 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
147 SIZE szPadding; /* padding values around button */
148 INT iListGap; /* default gap between text and image for toolbar with list style */
149 HFONT hDefaultFont;
150 HFONT hFont; /* text font */
151 HIMAGELIST himlInt; /* image list created internally */
152 PIMLENTRY *himlDef; /* default image list array */
153 INT cimlDef; /* default image list array count */
154 PIMLENTRY *himlHot; /* hot image list array */
155 INT cimlHot; /* hot image list array count */
156 PIMLENTRY *himlDis; /* disabled image list array */
157 INT cimlDis; /* disabled image list array count */
158 HWND hwndToolTip; /* handle to tool tip control */
159 HWND hwndNotify; /* handle to the window that gets notifications */
160 HWND hwndSelf; /* my own handle */
161 BOOL bBtnTranspnt; /* button transparency flag */
162 BOOL bAutoSize; /* auto size deadlock indicator */
163 BOOL bAnchor; /* anchor highlight enabled */
164 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
165 BOOL bDoRedraw; /* Redraw status */
166 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
167 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
168 BOOL bCaptured; /* mouse captured? */
169 DWORD dwStyle; /* regular toolbar style */
170 DWORD dwExStyle; /* extended toolbar style */
171 DWORD dwDTFlags; /* DrawText flags */
173 COLORREF clrInsertMark; /* insert mark color */
174 COLORREF clrBtnHighlight; /* color for Flat Separator */
175 COLORREF clrBtnShadow; /* color for Flag Separator */
176 INT iVersion;
177 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
178 * for TTN_GETDISPINFOW notification */
179 TBINSERTMARK tbim; /* info on insertion mark */
180 TBUTTON_INFO *buttons; /* pointer to button array */
181 LPWSTR *strings; /* pointer to string array */
182 TBITMAP_INFO *bitmaps;
183 } TOOLBAR_INFO, *PTOOLBAR_INFO;
186 /* used by customization dialog */
187 typedef struct
189 PTOOLBAR_INFO tbInfo;
190 HWND tbHwnd;
191 } CUSTDLG_INFO, *PCUSTDLG_INFO;
193 typedef struct
195 TBBUTTON btn;
196 BOOL bVirtual;
197 BOOL bRemovable;
198 WCHAR text[64];
199 } CUSTOMBUTTON, *PCUSTOMBUTTON;
201 typedef enum
203 IMAGE_LIST_DEFAULT,
204 IMAGE_LIST_HOT,
205 IMAGE_LIST_DISABLED
206 } IMAGE_LIST_TYPE;
208 #define SEPARATOR_WIDTH 8
209 #define TOP_BORDER 2
210 #define BOTTOM_BORDER 2
211 #define DDARROW_WIDTH 11
212 #define ARROW_HEIGHT 3
213 #define INSERTMARK_WIDTH 2
215 /* gap between border of button and text/image */
216 #define OFFSET_X 1
217 #define OFFSET_Y 1
218 /* how wide to treat the bitmap if it isn't present */
219 #define LIST_IMAGE_ABSENT_WIDTH 2
221 #define TOOLBAR_NOWHERE (-1)
223 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(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);
250 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
251 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
253 static LRESULT
254 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
257 static LPWSTR
258 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
260 LPWSTR lpText = NULL;
262 /* NOTE: iString == -1 is undocumented */
263 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
264 lpText = (LPWSTR)btnPtr->iString;
265 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
266 lpText = infoPtr->strings[btnPtr->iString];
268 return lpText;
271 static void
272 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
274 if (TRACE_ON(toolbar)){
275 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
276 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
277 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
278 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
279 if (internal)
280 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
281 btn_num, bP->idCommand,
282 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
283 bP->rect.left, bP->rect.top,
284 bP->rect.right, bP->rect.bottom);
289 static void
290 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
292 if (TRACE_ON(toolbar)) {
293 INT i;
295 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
296 iP->hwndSelf, line,
297 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
298 iP->nNumStrings, iP->dwStyle);
299 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
300 iP->hwndSelf, line,
301 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
302 (iP->bDoRedraw) ? "TRUE" : "FALSE");
303 for(i=0; i<iP->nNumButtons; i++) {
304 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
310 /***********************************************************************
311 * TOOLBAR_CheckStyle
313 * This function validates that the styles set are implemented and
314 * issues FIXME's warning of possible problems. In a perfect world this
315 * function should be null.
317 static void
318 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
320 if (dwStyle & TBSTYLE_REGISTERDROP)
321 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
325 static INT
326 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
328 if(!IsWindow(infoPtr->hwndSelf))
329 return 0; /* we have just been destroyed */
331 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
332 nmhdr->hwndFrom = infoPtr->hwndSelf;
333 nmhdr->code = code;
335 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
336 (infoPtr->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("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %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 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
638 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
639 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
640 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
641 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
642 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
643 SetBkColor(hdc, clrBkOld);
644 SetTextColor(hdc, clrTextOld);
645 SelectObject (hdc, hbr);
649 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
651 INT cx, cy;
652 HBITMAP hbmMask, hbmImage;
653 HDC hdcMask, hdcImage;
655 ImageList_GetIconSize(himl, &cx, &cy);
657 /* Create src image */
658 hdcImage = CreateCompatibleDC(hdc);
659 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
660 SelectObject(hdcImage, hbmImage);
661 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
662 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
664 /* Create Mask */
665 hdcMask = CreateCompatibleDC(0);
666 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
667 SelectObject(hdcMask, hbmMask);
669 /* Remove the background and all white pixels */
670 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
671 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
672 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
673 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
675 /* draw the new mask 'etched' to hdc */
676 SetBkColor(hdc, RGB(255, 255, 255));
677 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
678 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
679 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
680 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
681 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
683 /* Cleanup */
684 DeleteObject(hbmImage);
685 DeleteDC(hdcImage);
686 DeleteObject (hbmMask);
687 DeleteDC(hdcMask);
691 static UINT
692 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
694 UINT retstate = 0;
696 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
697 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
698 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
699 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
700 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
701 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
702 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
703 return retstate;
706 /* draws the image on a toolbar button */
707 static void
708 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
710 HIMAGELIST himl = NULL;
711 BOOL draw_masked = FALSE;
712 INT index;
713 INT offset = 0;
714 UINT draw_flags = ILD_NORMAL;
716 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
718 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
719 if (!himl)
721 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
722 draw_masked = TRUE;
725 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && (infoPtr->dwStyle & TBSTYLE_FLAT))
727 /* if hot, attempt to draw with hot image list, if fails,
728 use default image list */
729 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
730 if (!himl)
731 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
733 else
734 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
736 if (!himl)
737 return;
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 (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
752 else
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, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed)
794 HDC hdc = tbcd->nmcd.hdc;
795 int offset = 0;
796 BOOL pressed = bDropDownPressed ||
797 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
799 if (infoPtr->dwStyle & TBSTYLE_FLAT)
801 if (pressed)
802 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
803 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
804 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
805 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
806 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
808 else
810 if (pressed)
811 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
812 else
813 DrawEdge (hdc, rcArrow, EDGE_RAISED,
814 BF_SOFT | BF_RECT | BF_MIDDLE);
817 if (pressed)
818 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
820 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
822 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
823 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
825 else
826 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
829 /* draws a complete toolbar button */
830 static void
831 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
833 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
834 DWORD dwStyle = infoPtr->dwStyle;
835 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
836 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
837 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
838 BOOL drawSepDropDownArrow = hasDropDownArrow &&
839 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
840 RECT rc, rcArrow, rcBitmap, rcText;
841 LPWSTR lpText = NULL;
842 NMTBCUSTOMDRAW tbcd;
843 DWORD ntfret;
844 INT offset;
846 rc = btnPtr->rect;
847 CopyRect (&rcArrow, &rc);
848 CopyRect(&rcBitmap, &rc);
850 /* get a pointer to the text */
851 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
853 if (hasDropDownArrow)
855 int right;
857 if (dwStyle & TBSTYLE_FLAT)
858 right = max(rc.left, rc.right - DDARROW_WIDTH);
859 else
860 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
862 if (drawSepDropDownArrow)
863 rc.right = right;
865 rcArrow.left = right;
868 /* copy text rect after adjusting for drop-down arrow
869 * so that text is centred in the rectangle not containing
870 * the arrow */
871 CopyRect(&rcText, &rc);
873 /* Center the bitmap horizontally and vertically */
874 if (dwStyle & TBSTYLE_LIST)
875 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
876 else
877 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
879 if(lpText)
880 rcBitmap.top+= GetSystemMetrics(SM_CYEDGE) + OFFSET_Y;
881 else
882 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
884 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n",
885 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
886 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
887 TRACE ("iString: %x\n", btnPtr->iString);
888 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
890 /* draw text */
891 if (lpText) {
892 rcText.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
893 rcText.right -= GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
894 if (GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,btnPtr->iBitmap)) &&
895 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
897 if (dwStyle & TBSTYLE_LIST)
898 rcText.left += infoPtr->nBitmapWidth + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
899 else
900 rcText.top += GetSystemMetrics(SM_CYEDGE) + OFFSET_Y + infoPtr->nBitmapHeight + infoPtr->szPadding.cy/2;
902 else
903 if (dwStyle & TBSTYLE_LIST)
904 rcText.left += LIST_IMAGE_ABSENT_WIDTH + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
906 if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
907 OffsetRect (&rcText, 1, 1);
910 /* Initialize fields in all cases, because we use these later
911 * NOTE: applications can and do alter these to customize their
912 * toolbars */
913 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
914 tbcd.clrText = comctl32_color.clrBtnText;
915 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
916 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
917 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
918 tbcd.clrMark = comctl32_color.clrHighlight;
919 tbcd.clrHighlightHotTrack = 0;
920 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
921 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
922 /* MSDN says that this is the text rectangle.
923 * But (why always a but) tracing of v5.7 of native shows
924 * that this is really a *relative* rectangle based on the
925 * the nmcd.rc. Also the left and top are always 0 ignoring
926 * any bitmap that might be present. */
927 tbcd.rcText.left = 0;
928 tbcd.rcText.top = 0;
929 tbcd.rcText.right = rcText.right - rc.left;
930 tbcd.rcText.bottom = rcText.bottom - rc.top;
931 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
932 tbcd.nmcd.hdc = hdc;
933 tbcd.nmcd.rc = rc;
934 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
936 /* FIXME: what are these used for? */
937 tbcd.hbrLines = 0;
938 tbcd.hpenLines = 0;
940 /* Issue Item Prepaint notify */
941 infoPtr->dwItemCustDraw = 0;
942 infoPtr->dwItemCDFlag = 0;
943 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
945 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
946 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
947 tbcd.nmcd.lItemlParam = btnPtr->dwData;
948 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
949 /* reset these fields so the user can't alter the behaviour like native */
950 tbcd.nmcd.hdc = hdc;
951 tbcd.nmcd.rc = rc;
953 infoPtr->dwItemCustDraw = ntfret & 0xffff;
954 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
955 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
956 return;
957 /* save the only part of the rect that the user can change */
958 rcText.right = tbcd.rcText.right + rc.left;
959 rcText.bottom = tbcd.rcText.bottom + rc.top;
962 /* separator */
963 if (btnPtr->fsStyle & BTNS_SEP) {
964 /* with the FLAT style, iBitmap is the width and has already */
965 /* been taken into consideration in calculating the width */
966 /* so now we need to draw the vertical separator */
967 /* empirical tests show that iBitmap can/will be non-zero */
968 /* when drawing the vertical bar... */
969 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
970 if (btnPtr->fsStyle & BTNS_DROPDOWN)
971 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
972 else
973 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
975 else if (btnPtr->fsStyle != BTNS_SEP) {
976 FIXME("Draw some kind of separator: fsStyle=%x\n",
977 btnPtr->fsStyle);
979 goto FINALNOTIFY;
982 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
983 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
984 TOOLBAR_DrawPattern (&rc, &tbcd);
986 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
988 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
990 COLORREF oldclr;
992 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
993 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
994 if (hasDropDownArrow)
995 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
996 SetBkColor(hdc, oldclr);
1000 TOOLBAR_DrawFrame(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd);
1002 if (drawSepDropDownArrow)
1003 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
1005 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1006 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1008 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1010 if (hasDropDownArrow && !drawSepDropDownArrow)
1012 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1014 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1015 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1017 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1019 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1020 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1022 else
1023 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1026 FINALNOTIFY:
1027 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1029 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1030 tbcd.nmcd.hdc = hdc;
1031 tbcd.nmcd.rc = rc;
1032 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1033 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1034 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1035 tbcd.rcText = rcText;
1036 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1037 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1038 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1044 static void
1045 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1047 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1048 TBUTTON_INFO *btnPtr;
1049 INT i, oldBKmode = 0;
1050 RECT rcTemp, rcClient;
1051 NMTBCUSTOMDRAW tbcd;
1052 DWORD ntfret;
1054 /* the app has told us not to redraw the toolbar */
1055 if (!infoPtr->bDoRedraw)
1056 return;
1058 /* if imagelist belongs to the app, it can be changed
1059 by the app after setting it */
1060 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1062 infoPtr->nNumBitmaps = 0;
1063 for (i = 0; i < infoPtr->cimlDef; i++)
1064 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1067 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1069 /* Send initial notify */
1070 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1071 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1072 tbcd.nmcd.hdc = hdc;
1073 tbcd.nmcd.rc = ps->rcPaint;
1074 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1075 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1077 if (infoPtr->bBtnTranspnt)
1078 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1080 GetClientRect(hwnd, &rcClient);
1082 /* redraw necessary buttons */
1083 btnPtr = infoPtr->buttons;
1084 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1086 BOOL bDraw;
1087 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1089 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1090 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1092 else
1093 bDraw = TRUE;
1094 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1095 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1096 if (bDraw)
1097 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1100 /* draw insert mark if required */
1101 if (infoPtr->tbim.iButton != -1)
1103 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1104 RECT rcInsertMark;
1105 rcInsertMark.top = rcButton.top;
1106 rcInsertMark.bottom = rcButton.bottom;
1107 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1108 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1109 else
1110 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1111 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1114 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1115 SetBkMode (hdc, oldBKmode);
1117 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1119 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1120 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1121 tbcd.nmcd.hdc = hdc;
1122 tbcd.nmcd.rc = ps->rcPaint;
1123 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1127 /***********************************************************************
1128 * TOOLBAR_MeasureString
1130 * This function gets the width and height of a string in pixels. This
1131 * is done first by using GetTextExtentPoint to get the basic width
1132 * and height. The DrawText is called with DT_CALCRECT to get the exact
1133 * width. The reason is because the text may have more than one "&" (or
1134 * prefix characters as M$ likes to call them). The prefix character
1135 * indicates where the underline goes, except for the string "&&" which
1136 * is reduced to a single "&". GetTextExtentPoint does not process these
1137 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1139 static void
1140 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1141 HDC hdc, LPSIZE lpSize)
1143 RECT myrect;
1145 lpSize->cx = 0;
1146 lpSize->cy = 0;
1148 if (infoPtr->nMaxTextRows > 0 &&
1149 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1150 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1151 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1153 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1155 if(lpText != NULL) {
1156 /* first get size of all the text */
1157 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1159 /* feed above size into the rectangle for DrawText */
1160 myrect.left = myrect.top = 0;
1161 myrect.right = lpSize->cx;
1162 myrect.bottom = lpSize->cy;
1164 /* Use DrawText to get true size as drawn (less pesky "&") */
1165 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1166 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1167 DT_NOPREFIX : 0));
1169 /* feed back to caller */
1170 lpSize->cx = myrect.right;
1171 lpSize->cy = myrect.bottom;
1175 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1178 /***********************************************************************
1179 * TOOLBAR_CalcStrings
1181 * This function walks through each string and measures it and returns
1182 * the largest height and width to caller.
1184 static void
1185 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1187 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1188 TBUTTON_INFO *btnPtr;
1189 INT i;
1190 SIZE sz;
1191 HDC hdc;
1192 HFONT hOldFont;
1194 lpSize->cx = 0;
1195 lpSize->cy = 0;
1197 if(infoPtr->nMaxTextRows == 0)
1198 return;
1200 hdc = GetDC (hwnd);
1201 hOldFont = SelectObject (hdc, infoPtr->hFont);
1203 btnPtr = infoPtr->buttons;
1204 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1205 if(TOOLBAR_HasText(infoPtr, btnPtr))
1207 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1208 if (sz.cx > lpSize->cx)
1209 lpSize->cx = sz.cx;
1210 if (sz.cy > lpSize->cy)
1211 lpSize->cy = sz.cy;
1215 SelectObject (hdc, hOldFont);
1216 ReleaseDC (hwnd, hdc);
1218 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1221 /***********************************************************************
1222 * TOOLBAR_WrapToolbar
1224 * This function walks through the buttons and separators in the
1225 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1226 * wrapping should occur based on the width of the toolbar window.
1227 * It does *not* calculate button placement itself. That task
1228 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1229 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1230 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1232 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1233 * vertical toolbar lists.
1236 static void
1237 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1239 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1240 TBUTTON_INFO *btnPtr;
1241 INT x, cx, i, j;
1242 RECT rc;
1243 BOOL bWrap, bButtonWrap;
1245 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1246 /* no layout is necessary. Applications may use this style */
1247 /* to perform their own layout on the toolbar. */
1248 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1249 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1251 btnPtr = infoPtr->buttons;
1252 x = infoPtr->nIndent;
1254 /* this can get the parents width, to know how far we can extend
1255 * this toolbar. We cannot use its height, as there may be multiple
1256 * toolbars in a rebar control
1258 GetClientRect( GetParent(hwnd), &rc );
1259 infoPtr->nWidth = rc.right - rc.left;
1260 bButtonWrap = FALSE;
1262 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1263 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1264 infoPtr->nIndent);
1266 for (i = 0; i < infoPtr->nNumButtons; i++ )
1268 bWrap = FALSE;
1269 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1271 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1272 continue;
1274 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1275 /* it is the actual width of the separator. This is used for */
1276 /* custom controls in toolbars. */
1277 /* */
1278 /* BTNS_DROPDOWN separators are treated as buttons for */
1279 /* width. - GA 8/01 */
1280 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1281 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1282 cx = (btnPtr[i].iBitmap > 0) ?
1283 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1284 else
1285 cx = infoPtr->nButtonWidth;
1287 /* Two or more adjacent separators form a separator group. */
1288 /* The first separator in a group should be wrapped to the */
1289 /* next row if the previous wrapping is on a button. */
1290 if( bButtonWrap &&
1291 (btnPtr[i].fsStyle & BTNS_SEP) &&
1292 (i + 1 < infoPtr->nNumButtons ) &&
1293 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1295 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1296 btnPtr[i].fsState |= TBSTATE_WRAP;
1297 x = infoPtr->nIndent;
1298 i++;
1299 bButtonWrap = FALSE;
1300 continue;
1303 /* The layout makes sure the bitmap is visible, but not the button. */
1304 /* Test added to also wrap after a button that starts a row but */
1305 /* is bigger than the area. - GA 8/01 */
1306 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1307 > infoPtr->nWidth ) ||
1308 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1310 BOOL bFound = FALSE;
1312 /* If the current button is a separator and not hidden, */
1313 /* go to the next until it reaches a non separator. */
1314 /* Wrap the last separator if it is before a button. */
1315 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1316 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1317 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1318 i < infoPtr->nNumButtons )
1320 i++;
1321 bFound = TRUE;
1324 if( bFound && i < infoPtr->nNumButtons )
1326 i--;
1327 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1328 i, btnPtr[i].fsStyle, x, cx);
1329 btnPtr[i].fsState |= TBSTATE_WRAP;
1330 x = infoPtr->nIndent;
1331 bButtonWrap = FALSE;
1332 continue;
1334 else if ( i >= infoPtr->nNumButtons)
1335 break;
1337 /* If the current button is not a separator, find the last */
1338 /* separator and wrap it. */
1339 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1341 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1342 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1344 bFound = TRUE;
1345 i = j;
1346 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1347 i, btnPtr[i].fsStyle, x, cx);
1348 x = infoPtr->nIndent;
1349 btnPtr[j].fsState |= TBSTATE_WRAP;
1350 bButtonWrap = FALSE;
1351 break;
1355 /* If no separator available for wrapping, wrap one of */
1356 /* non-hidden previous button. */
1357 if (!bFound)
1359 for ( j = i - 1;
1360 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1362 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1363 continue;
1365 bFound = TRUE;
1366 i = j;
1367 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1368 i, btnPtr[i].fsStyle, x, cx);
1369 x = infoPtr->nIndent;
1370 btnPtr[j].fsState |= TBSTATE_WRAP;
1371 bButtonWrap = TRUE;
1372 break;
1376 /* If all above failed, wrap the current button. */
1377 if (!bFound)
1379 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1380 i, btnPtr[i].fsStyle, x, cx);
1381 btnPtr[i].fsState |= TBSTATE_WRAP;
1382 bFound = TRUE;
1383 x = infoPtr->nIndent;
1384 if (btnPtr[i].fsStyle & BTNS_SEP )
1385 bButtonWrap = FALSE;
1386 else
1387 bButtonWrap = TRUE;
1390 else {
1391 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1392 i, btnPtr[i].fsStyle, x, cx);
1393 x += cx;
1399 /***********************************************************************
1400 * TOOLBAR_CalcToolbar
1402 * This function calculates button and separator placement. It first
1403 * calculates the button sizes, gets the toolbar window width and then
1404 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1405 * on. It assigns a new location to each item and sends this location to
1406 * the tooltip window if appropriate. Finally, it updates the rcBound
1407 * rect and calculates the new required toolbar window height.
1410 static void
1411 TOOLBAR_CalcToolbar (HWND hwnd)
1413 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1414 DWORD dwStyle = infoPtr->dwStyle;
1415 TBUTTON_INFO *btnPtr;
1416 INT i, nRows, nSepRows;
1417 INT x, y, cx, cy;
1418 SIZE sizeString;
1419 BOOL bWrap;
1420 BOOL usesBitmaps = FALSE;
1421 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1423 TOOLBAR_CalcStrings (hwnd, &sizeString);
1425 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1427 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1429 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1430 usesBitmaps = TRUE;
1432 if (dwStyle & TBSTYLE_LIST)
1434 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1435 0, sizeString.cy) + infoPtr->szPadding.cy;
1436 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1437 LIST_IMAGE_ABSENT_WIDTH) + sizeString.cx + infoPtr->szPadding.cx;
1438 if (sizeString.cx > 0)
1439 infoPtr->nButtonWidth += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1440 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1441 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1442 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1444 else {
1445 if (sizeString.cy > 0)
1447 if (usesBitmaps)
1448 infoPtr->nButtonHeight = sizeString.cy +
1449 infoPtr->szPadding.cy/2 + /* this is the space to separate text from bitmap */
1450 infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1451 else
1452 infoPtr->nButtonHeight = sizeString.cy + infoPtr->szPadding.cy;
1454 else
1455 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1457 if (sizeString.cx > infoPtr->nBitmapWidth)
1458 infoPtr->nButtonWidth = sizeString.cx + infoPtr->szPadding.cx;
1459 else
1460 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + infoPtr->szPadding.cx;
1463 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1464 infoPtr->nButtonWidth = infoPtr->cxMin;
1465 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1466 infoPtr->nButtonWidth = infoPtr->cxMax;
1468 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1470 x = infoPtr->nIndent;
1471 y = 0;
1473 /* from above, minimum is a button, and possible text */
1474 cx = infoPtr->nButtonWidth;
1476 /* cannot use just ButtonHeight, we may have no buttons! */
1477 if (infoPtr->nNumButtons > 0)
1478 infoPtr->nHeight = infoPtr->nButtonHeight;
1480 cy = infoPtr->nHeight;
1482 nRows = nSepRows = 0;
1484 infoPtr->rcBound.top = y;
1485 infoPtr->rcBound.left = x;
1486 infoPtr->rcBound.bottom = y + cy;
1487 infoPtr->rcBound.right = x;
1489 btnPtr = infoPtr->buttons;
1491 TRACE("cy=%d\n", cy);
1493 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1495 bWrap = FALSE;
1496 if (btnPtr->fsState & TBSTATE_HIDDEN)
1498 SetRectEmpty (&btnPtr->rect);
1499 continue;
1502 cy = infoPtr->nHeight;
1504 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1505 /* it is the actual width of the separator. This is used for */
1506 /* custom controls in toolbars. */
1507 if (btnPtr->fsStyle & BTNS_SEP) {
1508 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1509 cy = (btnPtr->iBitmap > 0) ?
1510 btnPtr->iBitmap : SEPARATOR_WIDTH;
1511 cx = infoPtr->nButtonWidth;
1513 else
1514 cx = (btnPtr->iBitmap > 0) ?
1515 btnPtr->iBitmap : SEPARATOR_WIDTH;
1517 else
1519 if (btnPtr->cx)
1520 cx = btnPtr->cx;
1521 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1522 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1524 SIZE sz;
1525 HDC hdc;
1526 HFONT hOldFont;
1528 hdc = GetDC (hwnd);
1529 hOldFont = SelectObject (hdc, infoPtr->hFont);
1531 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1533 SelectObject (hdc, hOldFont);
1534 ReleaseDC (hwnd, hdc);
1536 /* add space on for button frame, etc */
1537 cx = sz.cx + infoPtr->szPadding.cx;
1539 /* add list padding */
1540 if ((dwStyle & TBSTYLE_LIST) && sz.cx > 0)
1541 cx += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1543 if (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))
1545 if (dwStyle & TBSTYLE_LIST)
1546 cx += infoPtr->nBitmapWidth;
1547 else if (cx < (infoPtr->nBitmapWidth+infoPtr->szPadding.cx))
1548 cx = infoPtr->nBitmapWidth+infoPtr->szPadding.cx;
1550 else if (dwStyle & TBSTYLE_LIST)
1551 cx += LIST_IMAGE_ABSENT_WIDTH;
1553 else
1554 cx = infoPtr->nButtonWidth;
1556 /* if size has been set manually then don't add on extra space
1557 * for the drop down arrow */
1558 if (!btnPtr->cx && hasDropDownArrows &&
1559 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1560 cx += DDARROW_WIDTH;
1562 if (btnPtr->fsState & TBSTATE_WRAP )
1563 bWrap = TRUE;
1565 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1567 if (infoPtr->rcBound.left > x)
1568 infoPtr->rcBound.left = x;
1569 if (infoPtr->rcBound.right < x + cx)
1570 infoPtr->rcBound.right = x + cx;
1571 if (infoPtr->rcBound.bottom < y + cy)
1572 infoPtr->rcBound.bottom = y + cy;
1574 /* Set the toolTip only for non-hidden, non-separator button */
1575 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1577 TTTOOLINFOA ti;
1579 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1580 ti.cbSize = sizeof(TTTOOLINFOA);
1581 ti.hwnd = hwnd;
1582 ti.uId = btnPtr->idCommand;
1583 ti.rect = btnPtr->rect;
1584 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1585 0, (LPARAM)&ti);
1588 /* btnPtr->nRow is zero based. The space between the rows is */
1589 /* also considered as a row. */
1590 btnPtr->nRow = nRows + nSepRows;
1592 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1593 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1594 x, y, x+cx, y+cy);
1596 if( bWrap )
1598 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1599 y += cy;
1600 else
1602 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1603 /* it is the actual width of the separator. This is used for */
1604 /* custom controls in toolbars. */
1605 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1606 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1607 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1608 else
1609 y += cy;
1611 /* nSepRows is used to calculate the extra height follwoing */
1612 /* the last row. */
1613 nSepRows++;
1615 x = infoPtr->nIndent;
1617 /* Increment row number unless this is the last button */
1618 /* and it has Wrap set. */
1619 if (i != infoPtr->nNumButtons-1)
1620 nRows++;
1622 else
1623 x += cx;
1626 /* infoPtr->nRows is the number of rows on the toolbar */
1627 infoPtr->nRows = nRows + nSepRows + 1;
1629 #if 0
1630 /********************************************************************
1631 * The following while interesting, does not match the values *
1632 * created above for the button rectangles, nor the rcBound rect. *
1633 * We will comment it out and remove it later. *
1635 * The problem showed up as heights in the pager control that was *
1636 * wrong. *
1637 ********************************************************************/
1639 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1640 /* the last row. */
1641 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1642 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1643 nSepRows * (infoPtr->nBitmapHeight + 1) +
1644 BOTTOM_BORDER;
1645 #endif
1647 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1649 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1653 static INT
1654 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1656 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1657 TBUTTON_INFO *btnPtr;
1658 INT i;
1660 btnPtr = infoPtr->buttons;
1661 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1662 if (btnPtr->fsState & TBSTATE_HIDDEN)
1663 continue;
1665 if (btnPtr->fsStyle & BTNS_SEP) {
1666 if (PtInRect (&btnPtr->rect, *lpPt)) {
1667 TRACE(" ON SEPARATOR %d!\n", i);
1668 return -i;
1671 else {
1672 if (PtInRect (&btnPtr->rect, *lpPt)) {
1673 TRACE(" ON BUTTON %d!\n", i);
1674 return i;
1679 TRACE(" NOWHERE!\n");
1680 return TOOLBAR_NOWHERE;
1684 static INT
1685 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1687 TBUTTON_INFO *btnPtr;
1688 INT i;
1690 if (CommandIsIndex) {
1691 TRACE("command is really index command=%d\n", idCommand);
1692 if (idCommand >= infoPtr->nNumButtons) return -1;
1693 return idCommand;
1695 btnPtr = infoPtr->buttons;
1696 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1697 if (btnPtr->idCommand == idCommand) {
1698 TRACE("command=%d index=%d\n", idCommand, i);
1699 return i;
1702 TRACE("no index found for command=%d\n", idCommand);
1703 return -1;
1707 static INT
1708 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1710 TBUTTON_INFO *btnPtr;
1711 INT nRunIndex;
1713 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1714 return -1;
1716 /* check index button */
1717 btnPtr = &infoPtr->buttons[nIndex];
1718 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1719 if (btnPtr->fsState & TBSTATE_CHECKED)
1720 return nIndex;
1723 /* check previous buttons */
1724 nRunIndex = nIndex - 1;
1725 while (nRunIndex >= 0) {
1726 btnPtr = &infoPtr->buttons[nRunIndex];
1727 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1728 if (btnPtr->fsState & TBSTATE_CHECKED)
1729 return nRunIndex;
1731 else
1732 break;
1733 nRunIndex--;
1736 /* check next buttons */
1737 nRunIndex = nIndex + 1;
1738 while (nRunIndex < infoPtr->nNumButtons) {
1739 btnPtr = &infoPtr->buttons[nRunIndex];
1740 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1741 if (btnPtr->fsState & TBSTATE_CHECKED)
1742 return nRunIndex;
1744 else
1745 break;
1746 nRunIndex++;
1749 return -1;
1753 static VOID
1754 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1755 WPARAM wParam, LPARAM lParam)
1757 MSG msg;
1759 msg.hwnd = hwndMsg;
1760 msg.message = uMsg;
1761 msg.wParam = wParam;
1762 msg.lParam = lParam;
1763 msg.time = GetMessageTime ();
1764 msg.pt.x = LOWORD(GetMessagePos ());
1765 msg.pt.y = HIWORD(GetMessagePos ());
1767 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1771 /***********************************************************************
1772 * TOOLBAR_CustomizeDialogProc
1773 * This function implements the toolbar customization dialog.
1775 static INT_PTR CALLBACK
1776 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1778 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
1779 PCUSTOMBUTTON btnInfo;
1780 NMTOOLBARA nmtb;
1781 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1783 switch (uMsg)
1785 case WM_INITDIALOG:
1786 custInfo = (PCUSTDLG_INFO)lParam;
1787 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
1789 if (custInfo)
1791 WCHAR Buffer[256];
1792 int i = 0;
1793 int index;
1795 infoPtr = custInfo->tbInfo;
1797 /* send TBN_QUERYINSERT notification */
1798 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1800 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1801 return FALSE;
1803 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
1804 nmtb.iItem = (int)hwnd;
1805 /* Send TBN_INITCUSTOMIZE notification */
1806 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
1807 TBNRF_HIDEHELP)
1809 TRACE("TBNRF_HIDEHELP requested\n");
1810 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
1813 /* add items to 'toolbar buttons' list and check if removable */
1814 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1816 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1817 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1818 btnInfo->btn.fsStyle = BTNS_SEP;
1819 btnInfo->bVirtual = FALSE;
1820 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1822 /* send TBN_QUERYDELETE notification */
1823 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
1825 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1826 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1829 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
1831 /* insert separator button into 'available buttons' list */
1832 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1833 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1834 btnInfo->btn.fsStyle = BTNS_SEP;
1835 btnInfo->bVirtual = FALSE;
1836 btnInfo->bRemovable = TRUE;
1837 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1838 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1839 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1841 /* insert all buttons into dsa */
1842 for (i = 0;; i++)
1844 /* send TBN_GETBUTTONINFO notification */
1845 NMTOOLBARW nmtb;
1846 nmtb.iItem = i;
1847 nmtb.pszText = Buffer;
1848 nmtb.cchText = 256;
1850 /* Clear previous button's text */
1851 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
1853 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
1854 break;
1856 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
1857 nmtb.tbButton.fsStyle, i,
1858 nmtb.tbButton.idCommand,
1859 nmtb.tbButton.iString,
1860 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
1861 : "");
1863 /* insert button into the apropriate list */
1864 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1865 if (index == -1)
1867 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1868 btnInfo->bVirtual = FALSE;
1869 btnInfo->bRemovable = TRUE;
1871 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1872 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX,
1873 LB_SETITEMDATA, index, (LPARAM)btnInfo);
1875 else
1877 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd,
1878 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1881 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1882 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
1884 if (lstrlenW(nmtb.pszText))
1885 lstrcpyW(btnInfo->text, nmtb.pszText);
1886 else if (nmtb.tbButton.iString >= 0 &&
1887 nmtb.tbButton.iString < infoPtr->nNumStrings)
1889 lstrcpyW(btnInfo->text,
1890 infoPtr->strings[nmtb.tbButton.iString]);
1895 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
1897 /* select first item in the 'available' list */
1898 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1900 /* append 'virtual' separator button to the 'toolbar buttons' list */
1901 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1902 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1903 btnInfo->btn.fsStyle = BTNS_SEP;
1904 btnInfo->bVirtual = TRUE;
1905 btnInfo->bRemovable = FALSE;
1906 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1907 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1908 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1910 /* select last item in the 'toolbar' list */
1911 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1912 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1914 /* set focus and disable buttons */
1915 PostMessageA (hwnd, WM_USER, 0, 0);
1917 return TRUE;
1919 case WM_USER:
1920 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1921 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1922 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1923 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1924 return TRUE;
1926 case WM_CLOSE:
1927 EndDialog(hwnd, FALSE);
1928 return TRUE;
1930 case WM_COMMAND:
1931 switch (LOWORD(wParam))
1933 case IDC_TOOLBARBTN_LBOX:
1934 if (HIWORD(wParam) == LBN_SELCHANGE)
1936 PCUSTOMBUTTON btnInfo;
1937 NMTOOLBARA nmtb;
1938 int count;
1939 int index;
1941 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1942 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1944 /* send TBN_QUERYINSERT notification */
1945 nmtb.iItem = index;
1946 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1947 TBN_QUERYINSERT);
1949 /* get list box item */
1950 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1952 if (index == (count - 1))
1954 /* last item (virtual separator) */
1955 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1956 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1958 else if (index == (count - 2))
1960 /* second last item (last non-virtual item) */
1961 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1962 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1964 else if (index == 0)
1966 /* first item */
1967 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1968 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1970 else
1972 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1973 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1976 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1978 break;
1980 case IDC_MOVEUP_BTN:
1982 PCUSTOMBUTTON btnInfo;
1983 int index;
1984 int count;
1986 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1987 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1988 TRACE("Move up: index %d\n", index);
1990 /* send TBN_QUERYINSERT notification */
1991 nmtb.iItem = index;
1993 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1994 TBN_QUERYINSERT))
1996 NMHDR hdr;
1998 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2000 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2001 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
2002 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
2003 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2005 if (index <= 1)
2006 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2007 else if (index >= (count - 3))
2008 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2010 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2011 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
2013 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2016 break;
2018 case IDC_MOVEDN_BTN: /* move down */
2020 PCUSTOMBUTTON btnInfo;
2021 int index;
2022 int count;
2024 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2025 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2026 TRACE("Move up: index %d\n", index);
2028 /* send TBN_QUERYINSERT notification */
2029 nmtb.iItem = index;
2030 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2031 TBN_QUERYINSERT))
2033 NMHDR hdr;
2035 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2037 /* move button down */
2038 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2039 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
2040 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
2041 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
2043 if (index == 0)
2044 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2045 else if (index >= (count - 3))
2046 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2048 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2049 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
2051 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2054 break;
2056 case IDC_REMOVE_BTN: /* remove button */
2058 PCUSTOMBUTTON btnInfo;
2059 int index;
2061 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2063 if (LB_ERR == index)
2064 break;
2066 TRACE("Remove: index %d\n", index);
2068 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX,
2069 LB_GETITEMDATA, index, 0);
2071 /* send TBN_QUERYDELETE notification */
2072 if (TOOLBAR_IsButtonRemovable(infoPtr, index, btnInfo))
2074 NMHDR hdr;
2076 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2077 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2078 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
2080 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2082 /* insert into 'available button' list */
2083 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2085 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
2086 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2088 else
2089 Free (btnInfo);
2091 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2094 break;
2095 case IDC_HELP_BTN:
2096 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2097 break;
2098 case IDC_RESET_BTN:
2099 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2100 break;
2102 case IDOK: /* Add button */
2104 int index;
2105 int count;
2107 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2108 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2109 TRACE("Add: index %d\n", index);
2111 /* send TBN_QUERYINSERT notification */
2112 nmtb.iItem = index;
2113 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2114 TBN_QUERYINSERT))
2116 NMHDR hdr;
2118 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
2120 if (index != 0)
2122 /* remove from 'available buttons' list */
2123 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
2124 if (index == count-1)
2125 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2126 else
2127 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
2129 else
2131 PCUSTOMBUTTON btnNew;
2133 /* duplicate 'separator' button */
2134 btnNew = (PCUSTOMBUTTON)Alloc (sizeof(CUSTOMBUTTON));
2135 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2136 btnInfo = btnNew;
2139 /* insert into 'toolbar button' list */
2140 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2141 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
2142 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2144 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
2146 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2149 break;
2151 case IDCANCEL:
2152 EndDialog(hwnd, FALSE);
2153 break;
2155 return TRUE;
2157 case WM_DESTROY:
2159 int count;
2160 int i;
2162 /* delete items from 'toolbar buttons' listbox*/
2163 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2164 for (i = 0; i < count; i++)
2166 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2167 Free(btnInfo);
2168 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2170 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2173 /* delete items from 'available buttons' listbox*/
2174 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2175 for (i = 0; i < count; i++)
2177 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2178 Free(btnInfo);
2179 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2181 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2183 return TRUE;
2185 case WM_DRAWITEM:
2186 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2188 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2189 RECT rcButton;
2190 RECT rcText;
2191 HPEN hPen, hOldPen;
2192 HBRUSH hOldBrush;
2193 COLORREF oldText = 0;
2194 COLORREF oldBk = 0;
2196 /* get item data */
2197 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2198 if (btnInfo == NULL)
2200 FIXME("btnInfo invalid!\n");
2201 return TRUE;
2204 /* set colors and select objects */
2205 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2206 if (btnInfo->bVirtual)
2207 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2208 else
2209 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2210 hPen = CreatePen( PS_SOLID, 1,
2211 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2212 hOldPen = SelectObject (lpdis->hDC, hPen );
2213 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2215 /* fill background rectangle */
2216 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2217 lpdis->rcItem.right, lpdis->rcItem.bottom);
2219 /* calculate button and text rectangles */
2220 CopyRect (&rcButton, &lpdis->rcItem);
2221 InflateRect (&rcButton, -1, -1);
2222 CopyRect (&rcText, &rcButton);
2223 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2224 rcText.left = rcButton.right + 2;
2226 /* draw focus rectangle */
2227 if (lpdis->itemState & ODS_FOCUS)
2228 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2230 /* draw button */
2231 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2232 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2234 /* draw image and text */
2235 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2236 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2237 btnInfo->btn.iBitmap));
2238 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2239 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2241 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2242 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2244 /* delete objects and reset colors */
2245 SelectObject (lpdis->hDC, hOldBrush);
2246 SelectObject (lpdis->hDC, hOldPen);
2247 SetBkColor (lpdis->hDC, oldBk);
2248 SetTextColor (lpdis->hDC, oldText);
2249 DeleteObject( hPen );
2250 return TRUE;
2252 return FALSE;
2254 case WM_MEASUREITEM:
2255 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2257 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2259 lpmis->itemHeight = 15 + 8; /* default height */
2261 return TRUE;
2263 return FALSE;
2265 default:
2266 return FALSE;
2271 /***********************************************************************
2272 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2275 static LRESULT
2276 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2278 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2279 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2280 INT nIndex = 0, nButtons, nCount;
2281 HBITMAP hbmLoad;
2282 HIMAGELIST himlDef;
2284 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2285 if (!lpAddBmp)
2286 return -1;
2288 if (lpAddBmp->hInst == HINST_COMMCTRL)
2290 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2291 nButtons = 15;
2292 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2293 nButtons = 13;
2294 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2295 nButtons = 5;
2296 else
2297 return -1;
2299 TRACE ("adding %d internal bitmaps!\n", nButtons);
2301 /* Windows resize all the buttons to the size of a newly added standard image */
2302 if (lpAddBmp->nID & 1)
2304 /* large icons */
2305 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2306 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2308 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2309 MAKELPARAM((WORD)24, (WORD)24));
2310 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2311 MAKELPARAM((WORD)31, (WORD)30));
2313 else
2315 /* small icons */
2316 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2317 MAKELPARAM((WORD)16, (WORD)16));
2318 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2319 MAKELPARAM((WORD)22, (WORD)22));
2322 TOOLBAR_CalcToolbar (hwnd);
2324 else
2326 nButtons = (INT)wParam;
2327 if (nButtons <= 0)
2328 return -1;
2330 TRACE ("adding %d bitmaps!\n", nButtons);
2333 if (!infoPtr->cimlDef) {
2334 /* create new default image list */
2335 TRACE ("creating default image list!\n");
2337 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2338 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2339 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2340 infoPtr->himlInt = himlDef;
2342 else {
2343 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2346 if (!himlDef) {
2347 WARN("No default image list available\n");
2348 return -1;
2351 nCount = ImageList_GetImageCount(himlDef);
2353 /* Add bitmaps to the default image list */
2354 if (lpAddBmp->hInst == NULL)
2356 BITMAP bmp;
2357 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2358 HDC hdcImage, hdcBitmap;
2360 /* copy the bitmap before adding it so that the user's bitmap
2361 * doesn't get modified.
2363 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2365 hdcImage = CreateCompatibleDC(0);
2366 hdcBitmap = CreateCompatibleDC(0);
2368 /* create new bitmap */
2369 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2370 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2371 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2373 /* Copy the user's image */
2374 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2375 hdcBitmap, 0, 0, SRCCOPY);
2377 SelectObject (hdcImage, hOldBitmapLoad);
2378 SelectObject (hdcBitmap, hOldBitmapBitmap);
2379 DeleteDC (hdcImage);
2380 DeleteDC (hdcBitmap);
2382 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2383 DeleteObject (hbmLoad);
2385 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2387 /* Add system bitmaps */
2388 switch (lpAddBmp->nID)
2390 case IDB_STD_SMALL_COLOR:
2391 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2392 MAKEINTRESOURCEA(IDB_STD_SMALL));
2393 nIndex = ImageList_AddMasked (himlDef,
2394 hbmLoad, comctl32_color.clrBtnFace);
2395 DeleteObject (hbmLoad);
2396 break;
2398 case IDB_STD_LARGE_COLOR:
2399 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2400 MAKEINTRESOURCEA(IDB_STD_LARGE));
2401 nIndex = ImageList_AddMasked (himlDef,
2402 hbmLoad, comctl32_color.clrBtnFace);
2403 DeleteObject (hbmLoad);
2404 break;
2406 case IDB_VIEW_SMALL_COLOR:
2407 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2408 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2409 nIndex = ImageList_AddMasked (himlDef,
2410 hbmLoad, comctl32_color.clrBtnFace);
2411 DeleteObject (hbmLoad);
2412 break;
2414 case IDB_VIEW_LARGE_COLOR:
2415 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2416 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2417 nIndex = ImageList_AddMasked (himlDef,
2418 hbmLoad, comctl32_color.clrBtnFace);
2419 DeleteObject (hbmLoad);
2420 break;
2422 case IDB_HIST_SMALL_COLOR:
2423 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2424 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2425 nIndex = ImageList_AddMasked (himlDef,
2426 hbmLoad, comctl32_color.clrBtnFace);
2427 DeleteObject (hbmLoad);
2428 break;
2430 case IDB_HIST_LARGE_COLOR:
2431 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2432 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2433 nIndex = ImageList_AddMasked (himlDef,
2434 hbmLoad, comctl32_color.clrBtnFace);
2435 DeleteObject (hbmLoad);
2436 break;
2438 default:
2439 nIndex = ImageList_GetImageCount (himlDef);
2440 ERR ("invalid imagelist!\n");
2441 break;
2444 else
2446 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2447 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2448 DeleteObject (hbmLoad);
2451 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2453 if (infoPtr->nNumBitmapInfos == 0)
2455 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2457 else
2459 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2460 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2461 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2464 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2465 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2466 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2468 infoPtr->nNumBitmapInfos++;
2469 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2471 if (nIndex != -1)
2473 INT imagecount = ImageList_GetImageCount(himlDef);
2475 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2477 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",
2478 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2479 infoPtr->nNumBitmaps+nButtons,imagecount);
2481 infoPtr->nNumBitmaps = imagecount;
2483 else
2484 infoPtr->nNumBitmaps += nButtons;
2487 InvalidateRect(hwnd, NULL, TRUE);
2489 return nIndex;
2493 static LRESULT
2494 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2496 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2497 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2498 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2500 TRACE("adding %d buttons!\n", wParam);
2502 nAddButtons = (UINT)wParam;
2503 nOldButtons = infoPtr->nNumButtons;
2504 nNewButtons = nOldButtons + nAddButtons;
2506 if (infoPtr->nNumButtons == 0) {
2507 infoPtr->buttons =
2508 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2510 else {
2511 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2512 infoPtr->buttons =
2513 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2514 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2515 nOldButtons * sizeof(TBUTTON_INFO));
2516 Free (oldButtons);
2519 infoPtr->nNumButtons = nNewButtons;
2521 /* insert new button data */
2522 for (nCount = 0; nCount < nAddButtons; nCount++) {
2523 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2524 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2525 btnPtr->idCommand = lpTbb[nCount].idCommand;
2526 btnPtr->fsState = lpTbb[nCount].fsState;
2527 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2528 btnPtr->dwData = lpTbb[nCount].dwData;
2529 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2530 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2531 else
2532 btnPtr->iString = lpTbb[nCount].iString;
2533 btnPtr->bHot = FALSE;
2535 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2536 TTTOOLINFOA ti;
2538 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2539 ti.cbSize = sizeof (TTTOOLINFOA);
2540 ti.hwnd = hwnd;
2541 ti.uId = btnPtr->idCommand;
2542 ti.hinst = 0;
2543 ti.lpszText = LPSTR_TEXTCALLBACKA;
2545 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2546 0, (LPARAM)&ti);
2550 TOOLBAR_CalcToolbar (hwnd);
2552 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2554 InvalidateRect(hwnd, NULL, TRUE);
2556 return TRUE;
2560 static LRESULT
2561 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2563 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2564 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2565 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2567 TRACE("adding %d buttons!\n", wParam);
2569 nAddButtons = (UINT)wParam;
2570 nOldButtons = infoPtr->nNumButtons;
2571 nNewButtons = nOldButtons + nAddButtons;
2573 if (infoPtr->nNumButtons == 0) {
2574 infoPtr->buttons =
2575 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2577 else {
2578 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2579 infoPtr->buttons =
2580 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2581 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2582 nOldButtons * sizeof(TBUTTON_INFO));
2583 Free (oldButtons);
2586 infoPtr->nNumButtons = nNewButtons;
2588 /* insert new button data */
2589 for (nCount = 0; nCount < nAddButtons; nCount++) {
2590 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2591 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2592 btnPtr->idCommand = lpTbb[nCount].idCommand;
2593 btnPtr->fsState = lpTbb[nCount].fsState;
2594 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2595 btnPtr->dwData = lpTbb[nCount].dwData;
2596 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2597 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2598 else
2599 btnPtr->iString = lpTbb[nCount].iString;
2600 btnPtr->bHot = FALSE;
2602 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2603 TTTOOLINFOW ti;
2605 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2606 ti.cbSize = sizeof (TTTOOLINFOW);
2607 ti.hwnd = hwnd;
2608 ti.uId = btnPtr->idCommand;
2609 ti.hinst = 0;
2610 ti.lpszText = LPSTR_TEXTCALLBACKW;
2611 ti.lParam = lParam;
2613 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2614 0, (LPARAM)&ti);
2618 TOOLBAR_CalcToolbar (hwnd);
2620 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2622 InvalidateRect(hwnd, NULL, TRUE);
2624 return TRUE;
2628 static LRESULT
2629 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2631 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2632 INT nIndex;
2634 if ((wParam) && (HIWORD(lParam) == 0)) {
2635 char szString[256];
2636 INT len;
2637 TRACE("adding string from resource!\n");
2639 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2640 szString, 256);
2642 TRACE("len=%d \"%s\"\n", len, szString);
2643 nIndex = infoPtr->nNumStrings;
2644 if (infoPtr->nNumStrings == 0) {
2645 infoPtr->strings =
2646 Alloc (sizeof(LPWSTR));
2648 else {
2649 LPWSTR *oldStrings = infoPtr->strings;
2650 infoPtr->strings =
2651 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2652 memcpy (&infoPtr->strings[0], &oldStrings[0],
2653 sizeof(LPWSTR) * infoPtr->nNumStrings);
2654 Free (oldStrings);
2657 /*Alloc zeros out the allocated memory*/
2658 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2659 infoPtr->nNumStrings++;
2661 else {
2662 LPSTR p = (LPSTR)lParam;
2663 INT len;
2665 if (p == NULL)
2666 return -1;
2667 TRACE("adding string(s) from array!\n");
2669 nIndex = infoPtr->nNumStrings;
2670 while (*p) {
2671 len = strlen (p);
2672 TRACE("len=%d \"%s\"\n", len, p);
2674 if (infoPtr->nNumStrings == 0) {
2675 infoPtr->strings =
2676 Alloc (sizeof(LPWSTR));
2678 else {
2679 LPWSTR *oldStrings = infoPtr->strings;
2680 infoPtr->strings =
2681 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2682 memcpy (&infoPtr->strings[0], &oldStrings[0],
2683 sizeof(LPWSTR) * infoPtr->nNumStrings);
2684 Free (oldStrings);
2687 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2688 infoPtr->nNumStrings++;
2690 p += (len+1);
2694 return nIndex;
2698 static LRESULT
2699 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2701 #define MAX_RESOURCE_STRING_LENGTH 512
2702 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2703 INT nIndex;
2705 if ((wParam) && (HIWORD(lParam) == 0)) {
2706 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2707 INT len;
2708 TRACE("adding string from resource!\n");
2710 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2711 szString, MAX_RESOURCE_STRING_LENGTH);
2713 TRACE("len=%d %s\n", len, debugstr_w(szString));
2714 TRACE("First char: 0x%x\n", *szString);
2715 if (szString[0] == L'|')
2717 PWSTR p = szString + 1;
2719 nIndex = infoPtr->nNumStrings;
2720 while (*p != L'|' && *p != L'\0') {
2721 PWSTR np;
2723 if (infoPtr->nNumStrings == 0) {
2724 infoPtr->strings = Alloc (sizeof(LPWSTR));
2726 else
2728 LPWSTR *oldStrings = infoPtr->strings;
2729 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2730 memcpy(&infoPtr->strings[0], &oldStrings[0],
2731 sizeof(LPWSTR) * infoPtr->nNumStrings);
2732 Free(oldStrings);
2735 np=strchrW (p, '|');
2736 if (np!=NULL) {
2737 len = np - p;
2738 np++;
2739 } else {
2740 len = strlenW(p);
2741 np = p + len;
2743 TRACE("len=%d %s\n", len, debugstr_w(p));
2744 infoPtr->strings[infoPtr->nNumStrings] =
2745 Alloc (sizeof(WCHAR)*(len+1));
2746 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2747 infoPtr->nNumStrings++;
2749 p = np;
2752 else
2754 nIndex = infoPtr->nNumStrings;
2755 if (infoPtr->nNumStrings == 0) {
2756 infoPtr->strings =
2757 Alloc (sizeof(LPWSTR));
2759 else {
2760 LPWSTR *oldStrings = infoPtr->strings;
2761 infoPtr->strings =
2762 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2763 memcpy (&infoPtr->strings[0], &oldStrings[0],
2764 sizeof(LPWSTR) * infoPtr->nNumStrings);
2765 Free (oldStrings);
2768 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2769 infoPtr->nNumStrings++;
2772 else {
2773 LPWSTR p = (LPWSTR)lParam;
2774 INT len;
2776 if (p == NULL)
2777 return -1;
2778 TRACE("adding string(s) from array!\n");
2779 nIndex = infoPtr->nNumStrings;
2780 while (*p) {
2781 len = strlenW (p);
2783 TRACE("len=%d %s\n", len, debugstr_w(p));
2784 if (infoPtr->nNumStrings == 0) {
2785 infoPtr->strings =
2786 Alloc (sizeof(LPWSTR));
2788 else {
2789 LPWSTR *oldStrings = infoPtr->strings;
2790 infoPtr->strings =
2791 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2792 memcpy (&infoPtr->strings[0], &oldStrings[0],
2793 sizeof(LPWSTR) * infoPtr->nNumStrings);
2794 Free (oldStrings);
2797 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2798 infoPtr->nNumStrings++;
2800 p += (len+1);
2804 return nIndex;
2808 static LRESULT
2809 TOOLBAR_AutoSize (HWND hwnd)
2811 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2812 RECT parent_rect;
2813 RECT window_rect;
2814 HWND parent;
2815 INT x, y;
2816 INT cx, cy;
2817 UINT uPosFlags = SWP_NOZORDER;
2819 TRACE("resize forced, style=%lx!\n", infoPtr->dwStyle);
2821 parent = GetParent (hwnd);
2822 GetClientRect(parent, &parent_rect);
2824 x = parent_rect.left;
2825 y = parent_rect.top;
2827 /* FIXME: we should be able to early out if nothing */
2828 /* has changed with nWidth != parent_rect width */
2830 if (infoPtr->dwStyle & CCS_NORESIZE) {
2831 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2832 cx = 0;
2833 cy = 0;
2834 TOOLBAR_CalcToolbar (hwnd);
2836 else {
2837 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2838 TOOLBAR_CalcToolbar (hwnd);
2839 InvalidateRect( hwnd, NULL, TRUE );
2840 cy = infoPtr->nHeight;
2841 cx = infoPtr->nWidth;
2843 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
2844 GetWindowRect(hwnd, &window_rect);
2845 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2846 y = window_rect.top;
2848 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
2849 GetWindowRect(hwnd, &window_rect);
2850 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
2854 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
2855 uPosFlags |= SWP_NOMOVE;
2857 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
2858 cy += GetSystemMetrics(SM_CYEDGE);
2860 if (infoPtr->dwStyle & WS_BORDER)
2862 x = y = 1;
2863 cy += GetSystemMetrics(SM_CYEDGE);
2864 cx += GetSystemMetrics(SM_CYEDGE);
2867 infoPtr->bAutoSize = TRUE;
2868 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
2869 /* The following line makes sure that the infoPtr->bAutoSize is turned off
2870 * after the setwindowpos calls */
2871 infoPtr->bAutoSize = FALSE;
2873 return 0;
2877 static LRESULT
2878 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2880 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2882 return infoPtr->nNumButtons;
2886 static LRESULT
2887 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2889 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2891 if (infoPtr == NULL) {
2892 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2893 ERR("infoPtr == NULL!\n");
2894 return 0;
2897 infoPtr->dwStructSize = (DWORD)wParam;
2899 return 0;
2903 static LRESULT
2904 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2906 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2907 TBUTTON_INFO *btnPtr;
2908 INT nIndex;
2910 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
2912 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2913 if (nIndex == -1)
2914 return FALSE;
2916 btnPtr = &infoPtr->buttons[nIndex];
2917 btnPtr->iBitmap = LOWORD(lParam);
2919 /* we HAVE to erase the background, the new bitmap could be */
2920 /* transparent */
2921 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2923 return TRUE;
2927 static LRESULT
2928 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2930 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2931 TBUTTON_INFO *btnPtr;
2932 INT nIndex;
2933 INT nOldIndex = -1;
2934 BOOL bChecked = FALSE;
2936 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2938 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
2940 if (nIndex == -1)
2941 return FALSE;
2943 btnPtr = &infoPtr->buttons[nIndex];
2945 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2947 if (LOWORD(lParam) == FALSE)
2948 btnPtr->fsState &= ~TBSTATE_CHECKED;
2949 else {
2950 if (btnPtr->fsStyle & BTNS_GROUP) {
2951 nOldIndex =
2952 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2953 if (nOldIndex == nIndex)
2954 return 0;
2955 if (nOldIndex != -1)
2956 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2958 btnPtr->fsState |= TBSTATE_CHECKED;
2961 if( bChecked != LOWORD(lParam) )
2963 if (nOldIndex != -1)
2964 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
2965 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2968 /* FIXME: Send a WM_NOTIFY?? */
2970 return TRUE;
2974 static LRESULT
2975 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2977 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2979 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2983 static LRESULT
2984 TOOLBAR_Customize (HWND hwnd)
2986 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2987 CUSTDLG_INFO custInfo;
2988 LRESULT ret;
2989 LPCVOID template;
2990 HRSRC hRes;
2991 NMHDR nmhdr;
2993 custInfo.tbInfo = infoPtr;
2994 custInfo.tbHwnd = hwnd;
2996 /* send TBN_BEGINADJUST notification */
2997 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2998 TBN_BEGINADJUST);
3000 if (!(hRes = FindResourceA (COMCTL32_hModule,
3001 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
3002 (LPSTR)RT_DIALOG)))
3003 return FALSE;
3005 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3006 return FALSE;
3008 ret = DialogBoxIndirectParamA ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3009 (LPDLGTEMPLATEA)template,
3010 hwnd,
3011 TOOLBAR_CustomizeDialogProc,
3012 (LPARAM)&custInfo);
3014 /* send TBN_ENDADJUST notification */
3015 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
3016 TBN_ENDADJUST);
3018 return ret;
3022 static LRESULT
3023 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3025 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3026 INT nIndex = (INT)wParam;
3027 NMTOOLBARW nmtb;
3029 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3030 return FALSE;
3032 memset(&nmtb, 0, sizeof(nmtb));
3033 nmtb.iItem = nIndex;
3034 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_DELETINGBUTTON);
3036 if ((infoPtr->hwndToolTip) &&
3037 !(infoPtr->buttons[nIndex].fsStyle & BTNS_SEP)) {
3038 TTTOOLINFOA ti;
3040 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3041 ti.cbSize = sizeof (TTTOOLINFOA);
3042 ti.hwnd = hwnd;
3043 ti.uId = infoPtr->buttons[nIndex].idCommand;
3045 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
3048 if (infoPtr->nNumButtons == 1) {
3049 TRACE(" simple delete!\n");
3050 Free (infoPtr->buttons);
3051 infoPtr->buttons = NULL;
3052 infoPtr->nNumButtons = 0;
3054 else {
3055 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3056 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3058 infoPtr->nNumButtons--;
3059 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3060 if (nIndex > 0) {
3061 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3062 nIndex * sizeof(TBUTTON_INFO));
3065 if (nIndex < infoPtr->nNumButtons) {
3066 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3067 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3070 Free (oldButtons);
3073 TOOLBAR_CalcToolbar (hwnd);
3075 InvalidateRect (hwnd, NULL, TRUE);
3077 return TRUE;
3081 static LRESULT
3082 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3084 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3085 TBUTTON_INFO *btnPtr;
3086 INT nIndex;
3087 DWORD bState;
3089 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3091 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3093 if (nIndex == -1)
3094 return FALSE;
3096 btnPtr = &infoPtr->buttons[nIndex];
3098 bState = btnPtr->fsState & TBSTATE_ENABLED;
3100 /* update the toolbar button state */
3101 if(LOWORD(lParam) == FALSE) {
3102 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3103 } else {
3104 btnPtr->fsState |= TBSTATE_ENABLED;
3107 /* redraw the button only if the state of the button changed */
3108 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3109 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3111 return TRUE;
3115 static inline LRESULT
3116 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3118 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3120 return infoPtr->bAnchor;
3124 static LRESULT
3125 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3127 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3128 INT nIndex;
3130 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3131 if (nIndex == -1)
3132 return -1;
3134 return infoPtr->buttons[nIndex].iBitmap;
3138 static inline LRESULT
3139 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3141 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3145 static LRESULT
3146 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3148 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3149 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3150 INT nIndex = (INT)wParam;
3151 TBUTTON_INFO *btnPtr;
3153 if (infoPtr == NULL)
3154 return FALSE;
3156 if (lpTbb == NULL)
3157 return FALSE;
3159 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3160 return FALSE;
3162 btnPtr = &infoPtr->buttons[nIndex];
3163 lpTbb->iBitmap = btnPtr->iBitmap;
3164 lpTbb->idCommand = btnPtr->idCommand;
3165 lpTbb->fsState = btnPtr->fsState;
3166 lpTbb->fsStyle = btnPtr->fsStyle;
3167 lpTbb->bReserved[0] = 0;
3168 lpTbb->bReserved[1] = 0;
3169 lpTbb->dwData = btnPtr->dwData;
3170 lpTbb->iString = btnPtr->iString;
3172 return TRUE;
3176 static LRESULT
3177 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3179 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3180 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3181 TBUTTON_INFO *btnPtr;
3182 INT nIndex;
3184 if (infoPtr == NULL)
3185 return -1;
3186 if (lpTbInfo == NULL)
3187 return -1;
3188 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3189 return -1;
3191 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3192 lpTbInfo->dwMask & 0x80000000);
3193 if (nIndex == -1)
3194 return -1;
3196 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3198 if (lpTbInfo->dwMask & TBIF_COMMAND)
3199 lpTbInfo->idCommand = btnPtr->idCommand;
3200 if (lpTbInfo->dwMask & TBIF_IMAGE)
3201 lpTbInfo->iImage = btnPtr->iBitmap;
3202 if (lpTbInfo->dwMask & TBIF_LPARAM)
3203 lpTbInfo->lParam = btnPtr->dwData;
3204 if (lpTbInfo->dwMask & TBIF_SIZE)
3205 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3206 if (lpTbInfo->dwMask & TBIF_STATE)
3207 lpTbInfo->fsState = btnPtr->fsState;
3208 if (lpTbInfo->dwMask & TBIF_STYLE)
3209 lpTbInfo->fsStyle = btnPtr->fsStyle;
3210 if (lpTbInfo->dwMask & TBIF_TEXT) {
3211 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3212 can't use TOOLBAR_GetText here */
3213 LPWSTR lpText;
3214 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3215 lpText = (LPWSTR)btnPtr->iString;
3216 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3217 } else
3218 lpTbInfo->pszText[0] = '\0';
3220 return nIndex;
3224 static LRESULT
3225 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3227 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3228 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3229 TBUTTON_INFO *btnPtr;
3230 INT nIndex;
3232 if (infoPtr == NULL)
3233 return -1;
3234 if (lpTbInfo == NULL)
3235 return -1;
3236 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3237 return -1;
3239 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3240 lpTbInfo->dwMask & 0x80000000);
3241 if (nIndex == -1)
3242 return -1;
3244 btnPtr = &infoPtr->buttons[nIndex];
3246 if(!btnPtr)
3247 return -1;
3249 if (lpTbInfo->dwMask & TBIF_COMMAND)
3250 lpTbInfo->idCommand = btnPtr->idCommand;
3251 if (lpTbInfo->dwMask & TBIF_IMAGE)
3252 lpTbInfo->iImage = btnPtr->iBitmap;
3253 if (lpTbInfo->dwMask & TBIF_LPARAM)
3254 lpTbInfo->lParam = btnPtr->dwData;
3255 if (lpTbInfo->dwMask & TBIF_SIZE)
3256 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3257 if (lpTbInfo->dwMask & TBIF_STATE)
3258 lpTbInfo->fsState = btnPtr->fsState;
3259 if (lpTbInfo->dwMask & TBIF_STYLE)
3260 lpTbInfo->fsStyle = btnPtr->fsStyle;
3261 if (lpTbInfo->dwMask & TBIF_TEXT) {
3262 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3263 can't use TOOLBAR_GetText here */
3264 LPWSTR lpText;
3265 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3266 lpText = (LPWSTR)btnPtr->iString;
3267 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3268 } else
3269 lpTbInfo->pszText[0] = '\0';
3272 return nIndex;
3276 static LRESULT
3277 TOOLBAR_GetButtonSize (HWND hwnd)
3279 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3281 if (infoPtr->nNumButtons > 0)
3282 return MAKELONG((WORD)infoPtr->nButtonWidth,
3283 (WORD)infoPtr->nButtonHeight);
3284 else
3285 return MAKELONG(8,7);
3289 static LRESULT
3290 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3292 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3293 INT nIndex;
3294 LPWSTR lpText;
3296 if (lParam == 0)
3297 return -1;
3299 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3300 if (nIndex == -1)
3301 return -1;
3303 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3305 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3306 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3310 static LRESULT
3311 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3313 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3314 INT nIndex;
3315 LPWSTR lpText;
3316 LRESULT ret = 0;
3318 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3319 if (nIndex == -1)
3320 return -1;
3322 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3324 if (lpText)
3326 ret = strlenW (lpText);
3328 if (lParam)
3329 strcpyW ((LPWSTR)lParam, lpText);
3332 return ret;
3336 static LRESULT
3337 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3339 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3340 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3341 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3345 inline static LRESULT
3346 TOOLBAR_GetExtendedStyle (HWND hwnd)
3348 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3350 TRACE("\n");
3352 return infoPtr->dwExStyle;
3356 static LRESULT
3357 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3359 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3360 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3361 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3365 static LRESULT
3366 TOOLBAR_GetHotItem (HWND hwnd)
3368 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3370 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
3371 return -1;
3373 if (infoPtr->nHotItem < 0)
3374 return -1;
3376 return (LRESULT)infoPtr->nHotItem;
3380 static LRESULT
3381 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3383 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3384 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3385 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3389 static LRESULT
3390 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3392 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3393 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3395 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3397 *lptbim = infoPtr->tbim;
3399 return 0;
3403 static LRESULT
3404 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3406 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3408 TRACE("hwnd = %p\n", hwnd);
3410 return (LRESULT)infoPtr->clrInsertMark;
3414 static LRESULT
3415 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3417 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3418 TBUTTON_INFO *btnPtr;
3419 LPRECT lpRect;
3420 INT nIndex;
3422 if (infoPtr == NULL)
3423 return FALSE;
3424 nIndex = (INT)wParam;
3425 btnPtr = &infoPtr->buttons[nIndex];
3426 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3427 return FALSE;
3428 lpRect = (LPRECT)lParam;
3429 if (lpRect == NULL)
3430 return FALSE;
3431 if (btnPtr->fsState & TBSTATE_HIDDEN)
3432 return FALSE;
3434 lpRect->left = btnPtr->rect.left;
3435 lpRect->right = btnPtr->rect.right;
3436 lpRect->bottom = btnPtr->rect.bottom;
3437 lpRect->top = btnPtr->rect.top;
3439 return TRUE;
3443 static LRESULT
3444 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3446 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3447 LPSIZE lpSize = (LPSIZE)lParam;
3449 if (lpSize == NULL)
3450 return FALSE;
3452 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3453 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3455 TRACE("maximum size %ld x %ld\n",
3456 infoPtr->rcBound.right - infoPtr->rcBound.left,
3457 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3459 return TRUE;
3463 /* << TOOLBAR_GetObject >> */
3466 static LRESULT
3467 TOOLBAR_GetPadding (HWND hwnd)
3469 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3470 DWORD oldPad;
3472 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3473 return (LRESULT) oldPad;
3477 static LRESULT
3478 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3480 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3481 TBUTTON_INFO *btnPtr;
3482 LPRECT lpRect;
3483 INT nIndex;
3485 if (infoPtr == NULL)
3486 return FALSE;
3487 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3488 btnPtr = &infoPtr->buttons[nIndex];
3489 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3490 return FALSE;
3491 lpRect = (LPRECT)lParam;
3492 if (lpRect == NULL)
3493 return FALSE;
3495 lpRect->left = btnPtr->rect.left;
3496 lpRect->right = btnPtr->rect.right;
3497 lpRect->bottom = btnPtr->rect.bottom;
3498 lpRect->top = btnPtr->rect.top;
3500 return TRUE;
3504 static LRESULT
3505 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3507 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3509 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3510 return infoPtr->nRows;
3511 else
3512 return 1;
3516 static LRESULT
3517 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3519 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3520 INT nIndex;
3522 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3523 if (nIndex == -1)
3524 return -1;
3526 return infoPtr->buttons[nIndex].fsState;
3530 static LRESULT
3531 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3533 return GetWindowLongW(hwnd, GWL_STYLE);
3537 static LRESULT
3538 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3540 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3542 if (infoPtr == NULL)
3543 return 0;
3545 return infoPtr->nMaxTextRows;
3549 static LRESULT
3550 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3552 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3554 if (infoPtr == NULL)
3555 return 0;
3556 return (LRESULT)infoPtr->hwndToolTip;
3560 static LRESULT
3561 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3563 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3565 TRACE("%s hwnd=%p stub!\n",
3566 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3568 return infoPtr->bUnicode;
3572 inline static LRESULT
3573 TOOLBAR_GetVersion (HWND hwnd)
3575 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3576 return infoPtr->iVersion;
3580 static LRESULT
3581 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3583 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3584 TBUTTON_INFO *btnPtr;
3585 INT nIndex;
3587 TRACE("\n");
3589 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3590 if (nIndex == -1)
3591 return FALSE;
3593 btnPtr = &infoPtr->buttons[nIndex];
3594 if (LOWORD(lParam) == FALSE)
3595 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3596 else
3597 btnPtr->fsState |= TBSTATE_HIDDEN;
3599 TOOLBAR_CalcToolbar (hwnd);
3601 InvalidateRect (hwnd, NULL, TRUE);
3603 return TRUE;
3607 inline static LRESULT
3608 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3610 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3614 static LRESULT
3615 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3617 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3618 TBUTTON_INFO *btnPtr;
3619 INT nIndex;
3620 DWORD oldState;
3622 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3623 if (nIndex == -1)
3624 return FALSE;
3626 btnPtr = &infoPtr->buttons[nIndex];
3627 oldState = btnPtr->fsState;
3628 if (LOWORD(lParam) == FALSE)
3629 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3630 else
3631 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3633 if(oldState != btnPtr->fsState)
3634 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3636 return TRUE;
3640 static LRESULT
3641 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3643 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3644 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3645 INT nIndex = (INT)wParam;
3646 TBUTTON_INFO *oldButtons;
3648 if (lpTbb == NULL)
3649 return FALSE;
3651 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3653 if (nIndex == -1) {
3654 /* EPP: this seems to be an undocumented call (from my IE4)
3655 * I assume in that case that:
3656 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3657 * - index of insertion is at the end of existing buttons
3658 * I only see this happen with nIndex == -1, but it could have a special
3659 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3661 nIndex = infoPtr->nNumButtons;
3663 } else if (nIndex < 0)
3664 return FALSE;
3666 /* If the string passed is not an index, assume address of string
3667 and do our own AddString */
3668 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3669 LPSTR ptr;
3670 INT len;
3672 TRACE("string %s passed instead of index, adding string\n",
3673 debugstr_a((LPSTR)lpTbb->iString));
3674 len = strlen((LPSTR)lpTbb->iString) + 2;
3675 ptr = Alloc(len);
3676 strcpy(ptr, (LPSTR)lpTbb->iString);
3677 ptr[len - 1] = 0; /* ended by two '\0' */
3678 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3679 Free(ptr);
3682 TRACE("inserting button index=%d\n", nIndex);
3683 if (nIndex > infoPtr->nNumButtons) {
3684 nIndex = infoPtr->nNumButtons;
3685 TRACE("adjust index=%d\n", nIndex);
3688 oldButtons = infoPtr->buttons;
3689 infoPtr->nNumButtons++;
3690 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3691 /* pre insert copy */
3692 if (nIndex > 0) {
3693 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3694 nIndex * sizeof(TBUTTON_INFO));
3697 /* insert new button */
3698 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3699 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3700 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3701 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3702 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3703 /* if passed string and not index, then add string */
3704 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3705 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3707 else
3708 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3710 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3711 TTTOOLINFOA ti;
3713 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3714 ti.cbSize = sizeof (TTTOOLINFOA);
3715 ti.hwnd = hwnd;
3716 ti.uId = lpTbb->idCommand;
3717 ti.hinst = 0;
3718 ti.lpszText = LPSTR_TEXTCALLBACKA;
3720 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3721 0, (LPARAM)&ti);
3724 /* post insert copy */
3725 if (nIndex < infoPtr->nNumButtons - 1) {
3726 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3727 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3730 Free (oldButtons);
3732 TOOLBAR_CalcToolbar (hwnd);
3734 InvalidateRect (hwnd, NULL, TRUE);
3736 return TRUE;
3740 static LRESULT
3741 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3743 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3744 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3745 INT nIndex = (INT)wParam;
3746 TBUTTON_INFO *oldButtons;
3748 if (lpTbb == NULL)
3749 return FALSE;
3751 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3753 if (nIndex == -1) {
3754 /* EPP: this seems to be an undocumented call (from my IE4)
3755 * I assume in that case that:
3756 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3757 * - index of insertion is at the end of existing buttons
3758 * I only see this happen with nIndex == -1, but it could have a special
3759 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3761 nIndex = infoPtr->nNumButtons;
3763 } else if (nIndex < 0)
3764 return FALSE;
3766 /* If the string passed is not an index, assume address of string
3767 and do our own AddString */
3768 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3769 LPWSTR ptr;
3770 INT len;
3772 TRACE("string %s passed instead of index, adding string\n",
3773 debugstr_w((LPWSTR)lpTbb->iString));
3774 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3775 ptr = Alloc(len*sizeof(WCHAR));
3776 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3777 ptr[len - 1] = 0; /* ended by two '\0' */
3778 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3779 Free(ptr);
3782 TRACE("inserting button index=%d\n", nIndex);
3783 if (nIndex > infoPtr->nNumButtons) {
3784 nIndex = infoPtr->nNumButtons;
3785 TRACE("adjust index=%d\n", nIndex);
3788 oldButtons = infoPtr->buttons;
3789 infoPtr->nNumButtons++;
3790 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3791 /* pre insert copy */
3792 if (nIndex > 0) {
3793 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3794 nIndex * sizeof(TBUTTON_INFO));
3797 /* insert new button */
3798 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3799 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3800 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3801 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3802 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3803 /* if passed string and not index, then add string */
3804 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3805 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3807 else
3808 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3810 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3811 TTTOOLINFOW ti;
3813 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3814 ti.cbSize = sizeof (TTTOOLINFOW);
3815 ti.hwnd = hwnd;
3816 ti.uId = lpTbb->idCommand;
3817 ti.hinst = 0;
3818 ti.lpszText = LPSTR_TEXTCALLBACKW;
3820 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3821 0, (LPARAM)&ti);
3824 /* post insert copy */
3825 if (nIndex < infoPtr->nNumButtons - 1) {
3826 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3827 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3830 Free (oldButtons);
3832 TOOLBAR_CalcToolbar (hwnd);
3834 InvalidateRect (hwnd, NULL, TRUE);
3836 return TRUE;
3840 /* << TOOLBAR_InsertMarkHitTest >> */
3843 static LRESULT
3844 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3846 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3847 INT nIndex;
3849 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3850 if (nIndex == -1)
3851 return FALSE;
3853 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3857 static LRESULT
3858 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3860 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3861 INT nIndex;
3863 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3864 if (nIndex == -1)
3865 return FALSE;
3867 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3871 static LRESULT
3872 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3874 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3875 INT nIndex;
3877 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3878 if (nIndex == -1)
3879 return TRUE;
3881 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3885 static LRESULT
3886 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3888 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3889 INT nIndex;
3891 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3892 if (nIndex == -1)
3893 return FALSE;
3895 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3899 static LRESULT
3900 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3902 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3903 INT nIndex;
3905 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3906 if (nIndex == -1)
3907 return FALSE;
3909 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3913 static LRESULT
3914 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3916 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3917 INT nIndex;
3919 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3920 if (nIndex == -1)
3921 return FALSE;
3923 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3927 static LRESULT
3928 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3930 TBADDBITMAP tbab;
3931 tbab.hInst = (HINSTANCE)lParam;
3932 tbab.nID = (UINT_PTR)wParam;
3934 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3936 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3940 static LRESULT
3941 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3943 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3944 WCHAR wAccel = (WCHAR)wParam;
3945 UINT* pIDButton = (UINT*)lParam;
3946 WCHAR wszAccel[] = {'&',wAccel,0};
3947 int i;
3949 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3950 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3952 for (i = 0; i < infoPtr->nNumButtons; i++)
3954 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3955 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3956 !(btnPtr->fsState & TBSTATE_HIDDEN))
3958 int iLen = strlenW(wszAccel);
3959 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3961 if (!lpszStr)
3962 continue;
3964 while (*lpszStr)
3966 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3968 lpszStr += 2;
3969 continue;
3971 if (!strncmpiW(lpszStr, wszAccel, iLen))
3973 *pIDButton = btnPtr->idCommand;
3974 return TRUE;
3976 lpszStr++;
3980 return FALSE;
3984 static LRESULT
3985 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3987 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3988 INT nIndex;
3990 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3992 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3993 if (nIndex == -1)
3994 return FALSE;
3996 if (LOWORD(lParam))
3997 infoPtr->buttons[nIndex].fsState |= TBSTATE_MARKED;
3998 else
3999 infoPtr->buttons[nIndex].fsState &= ~TBSTATE_MARKED;
4001 return TRUE;
4005 /* fixes up an index of a button affected by a move */
4006 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4008 if (bMoveUp)
4010 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4011 (*pIndex)--;
4012 else if (*pIndex == nIndex)
4013 *pIndex = nMoveIndex;
4015 else
4017 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4018 (*pIndex)++;
4019 else if (*pIndex == nIndex)
4020 *pIndex = nMoveIndex;
4025 static LRESULT
4026 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4028 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4029 INT nIndex;
4030 INT nCount;
4031 INT nMoveIndex = (INT)lParam;
4032 TBUTTON_INFO button;
4034 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4036 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4037 if ((nIndex == -1) || (nMoveIndex < 0))
4038 return FALSE;
4040 if (nMoveIndex > infoPtr->nNumButtons - 1)
4041 nMoveIndex = infoPtr->nNumButtons - 1;
4043 button = infoPtr->buttons[nIndex];
4045 /* move button right */
4046 if (nIndex < nMoveIndex)
4048 nCount = nMoveIndex - nIndex;
4049 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4050 infoPtr->buttons[nMoveIndex] = button;
4052 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4053 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4054 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4055 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4057 else if (nIndex > nMoveIndex) /* move button left */
4059 nCount = nIndex - nMoveIndex;
4060 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4061 infoPtr->buttons[nMoveIndex] = button;
4063 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4064 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4065 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4066 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4069 TOOLBAR_CalcToolbar(hwnd);
4070 InvalidateRect(hwnd, NULL, TRUE);
4072 return TRUE;
4076 static LRESULT
4077 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4079 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4080 TBUTTON_INFO *btnPtr;
4081 INT nIndex;
4082 DWORD oldState;
4084 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4085 if (nIndex == -1)
4086 return FALSE;
4088 btnPtr = &infoPtr->buttons[nIndex];
4089 oldState = btnPtr->fsState;
4090 if (LOWORD(lParam) == FALSE)
4091 btnPtr->fsState &= ~TBSTATE_PRESSED;
4092 else
4093 btnPtr->fsState |= TBSTATE_PRESSED;
4095 if(oldState != btnPtr->fsState)
4096 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4098 return TRUE;
4101 /* FIXME: there might still be some confusion her between number of buttons
4102 * and number of bitmaps */
4103 static LRESULT
4104 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4106 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4107 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4108 HBITMAP hBitmap;
4109 int i = 0, nOldButtons = 0, pos = 0;
4110 int nOldBitmaps, nNewBitmaps;
4111 HIMAGELIST himlDef = 0;
4113 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4114 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4115 lpReplace->nButtons);
4117 if (lpReplace->hInstOld == HINST_COMMCTRL)
4119 FIXME("changing standard bitmaps not implemented\n");
4120 return FALSE;
4122 else if (lpReplace->hInstOld != 0)
4124 FIXME("resources not in the current module not implemented\n");
4125 return FALSE;
4127 else
4129 hBitmap = (HBITMAP) lpReplace->nIDNew;
4132 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4133 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4134 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4135 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4136 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4138 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4139 nOldButtons = tbi->nButtons;
4140 tbi->nButtons = lpReplace->nButtons;
4141 tbi->hInst = lpReplace->hInstNew;
4142 tbi->nID = lpReplace->nIDNew;
4143 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4144 break;
4146 pos += tbi->nButtons;
4149 if (nOldButtons == 0)
4151 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4152 return FALSE;
4155 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4156 nOldBitmaps = ImageList_GetImageCount(himlDef);
4158 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4160 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4161 ImageList_Remove(himlDef, i);
4164 BITMAP bmp;
4165 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4166 HDC hdcImage, hdcBitmap;
4168 /* copy the bitmap before adding it so that the user's bitmap
4169 * doesn't get modified.
4171 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4173 hdcImage = CreateCompatibleDC(0);
4174 hdcBitmap = CreateCompatibleDC(0);
4176 /* create new bitmap */
4177 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4178 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4179 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4181 /* Copy the user's image */
4182 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4183 hdcBitmap, 0, 0, SRCCOPY);
4185 SelectObject (hdcImage, hOldBitmapLoad);
4186 SelectObject (hdcBitmap, hOldBitmapBitmap);
4187 DeleteDC (hdcImage);
4188 DeleteDC (hdcBitmap);
4190 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4191 nNewBitmaps = ImageList_GetImageCount(himlDef);
4192 DeleteObject (hbmLoad);
4195 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4197 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4198 pos, nOldBitmaps, nNewBitmaps);
4200 InvalidateRect(hwnd, NULL, TRUE);
4202 return TRUE;
4205 static LRESULT
4206 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4208 #if 0
4209 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4210 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
4212 if (lpSave == NULL) return 0;
4214 if ((BOOL)wParam) {
4215 /* save toolbar information */
4216 FIXME("save to \"%s\" \"%s\"\n",
4217 lpSave->pszSubKey, lpSave->pszValueName);
4221 else {
4222 /* restore toolbar information */
4224 FIXME("restore from \"%s\" \"%s\"\n",
4225 lpSave->pszSubKey, lpSave->pszValueName);
4229 #endif
4231 return 0;
4235 static LRESULT
4236 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4238 #if 0
4239 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4240 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
4242 if (lpSave == NULL)
4243 return 0;
4245 if ((BOOL)wParam) {
4246 /* save toolbar information */
4247 FIXME("save to \"%s\" \"%s\"\n",
4248 lpSave->pszSubKey, lpSave->pszValueName);
4252 else {
4253 /* restore toolbar information */
4255 FIXME("restore from \"%s\" \"%s\"\n",
4256 lpSave->pszSubKey, lpSave->pszValueName);
4260 #endif
4262 return 0;
4266 static LRESULT
4267 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4269 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4270 BOOL bOldAnchor = infoPtr->bAnchor;
4272 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4274 infoPtr->bAnchor = (BOOL)wParam;
4276 if (!infoPtr->bAnchor)
4277 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_OTHER);
4279 return (LRESULT)bOldAnchor;
4283 static LRESULT
4284 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4286 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4287 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4289 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4291 if (wParam != 0)
4292 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4294 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4295 return FALSE;
4297 if (infoPtr->nNumButtons > 0)
4298 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4299 infoPtr->nNumButtons,
4300 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4301 LOWORD(lParam), HIWORD(lParam));
4303 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4304 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4307 if ((himlDef == infoPtr->himlInt) &&
4308 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4310 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4311 infoPtr->nBitmapHeight);
4314 return TRUE;
4318 static LRESULT
4319 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4321 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4322 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4323 TBUTTON_INFO *btnPtr;
4324 INT nIndex;
4325 RECT oldBtnRect;
4327 if (lptbbi == NULL)
4328 return FALSE;
4329 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4330 return FALSE;
4332 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4333 lptbbi->dwMask & 0x80000000);
4334 if (nIndex == -1)
4335 return FALSE;
4337 btnPtr = &infoPtr->buttons[nIndex];
4338 if (lptbbi->dwMask & TBIF_COMMAND)
4339 btnPtr->idCommand = lptbbi->idCommand;
4340 if (lptbbi->dwMask & TBIF_IMAGE)
4341 btnPtr->iBitmap = lptbbi->iImage;
4342 if (lptbbi->dwMask & TBIF_LPARAM)
4343 btnPtr->dwData = lptbbi->lParam;
4344 if (lptbbi->dwMask & TBIF_SIZE)
4345 btnPtr->cx = lptbbi->cx;
4346 if (lptbbi->dwMask & TBIF_STATE)
4347 btnPtr->fsState = lptbbi->fsState;
4348 if (lptbbi->dwMask & TBIF_STYLE)
4349 btnPtr->fsStyle = lptbbi->fsStyle;
4351 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4352 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4353 /* iString is index, zero it to make Str_SetPtr succeed */
4354 btnPtr->iString=0;
4356 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4359 /* save the button rect to see if we need to redraw the whole toolbar */
4360 oldBtnRect = btnPtr->rect;
4361 TOOLBAR_CalcToolbar(hwnd);
4363 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4364 InvalidateRect(hwnd, NULL, TRUE);
4365 else
4366 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4368 return TRUE;
4372 static LRESULT
4373 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4375 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4376 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4377 TBUTTON_INFO *btnPtr;
4378 INT nIndex;
4379 RECT oldBtnRect;
4381 if (lptbbi == NULL)
4382 return FALSE;
4383 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4384 return FALSE;
4386 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4387 lptbbi->dwMask & 0x80000000);
4388 if (nIndex == -1)
4389 return FALSE;
4391 btnPtr = &infoPtr->buttons[nIndex];
4392 if (lptbbi->dwMask & TBIF_COMMAND)
4393 btnPtr->idCommand = lptbbi->idCommand;
4394 if (lptbbi->dwMask & TBIF_IMAGE)
4395 btnPtr->iBitmap = lptbbi->iImage;
4396 if (lptbbi->dwMask & TBIF_LPARAM)
4397 btnPtr->dwData = lptbbi->lParam;
4398 if (lptbbi->dwMask & TBIF_SIZE)
4399 btnPtr->cx = lptbbi->cx;
4400 if (lptbbi->dwMask & TBIF_STATE)
4401 btnPtr->fsState = lptbbi->fsState;
4402 if (lptbbi->dwMask & TBIF_STYLE)
4403 btnPtr->fsStyle = lptbbi->fsStyle;
4405 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4406 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4407 /* iString is index, zero it to make Str_SetPtr succeed */
4408 btnPtr->iString=0;
4409 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4412 /* save the button rect to see if we need to redraw the whole toolbar */
4413 oldBtnRect = btnPtr->rect;
4414 TOOLBAR_CalcToolbar(hwnd);
4416 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4417 InvalidateRect(hwnd, NULL, TRUE);
4418 else
4419 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4421 return TRUE;
4425 static LRESULT
4426 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4428 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4429 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4431 if ((cx < 0) || (cy < 0))
4433 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4434 return FALSE;
4437 /* The documentation claims you can only change the button size before
4438 * any button has been added. But this is wrong.
4439 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4440 * it to the toolbar, and it checks that the return value is nonzero - mjm
4441 * Further testing shows that we must actually perform the change too.
4444 * The documentation also does not mention that if 0 is supplied for
4445 * either size, the system changes it to the default of 24 wide and
4446 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4448 infoPtr->nButtonWidth = (cx) ? cx : 24;
4449 infoPtr->nButtonHeight = (cy) ? cy : 22;
4450 return TRUE;
4454 static LRESULT
4455 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4457 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4459 if (infoPtr == NULL) {
4460 TRACE("Toolbar not initialized yet?????\n");
4461 return FALSE;
4464 /* if setting to current values, ignore */
4465 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4466 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4467 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4468 infoPtr->cxMin, infoPtr->cxMax);
4469 return TRUE;
4472 /* save new values */
4473 infoPtr->cxMin = (INT)LOWORD(lParam);
4474 infoPtr->cxMax = (INT)HIWORD(lParam);
4476 /* if both values are 0 then we are done */
4477 if (lParam == 0) {
4478 TRACE("setting both min and max to 0, norecalc\n");
4479 return TRUE;
4482 /* otherwise we need to recalc the toolbar and in some cases
4483 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4484 which doesn't actually draw - GA). */
4485 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4486 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4488 TOOLBAR_CalcToolbar (hwnd);
4490 InvalidateRect (hwnd, NULL, TRUE);
4492 return TRUE;
4496 static LRESULT
4497 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4499 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4500 INT nIndex = (INT)wParam;
4502 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4503 return FALSE;
4505 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4507 if (infoPtr->hwndToolTip) {
4509 FIXME("change tool tip!\n");
4513 return TRUE;
4517 static LRESULT
4518 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4520 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4521 HIMAGELIST himl = (HIMAGELIST)lParam;
4522 HIMAGELIST himlTemp;
4523 INT id = 0;
4525 if (infoPtr->iVersion >= 5)
4526 id = wParam;
4528 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4529 &infoPtr->cimlDis, himl, id);
4531 /* FIXME: redraw ? */
4533 return (LRESULT)himlTemp;
4537 static LRESULT
4538 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4540 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4541 DWORD dwTemp;
4543 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4545 dwTemp = infoPtr->dwDTFlags;
4546 infoPtr->dwDTFlags =
4547 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4549 return (LRESULT)dwTemp;
4552 /* This function differs a bit from what MSDN says it does:
4553 * 1. lParam contains extended style flags to OR with current style
4554 * (MSDN isn't clear on the OR bit)
4555 * 2. wParam appears to contain extended style flags to be reset
4556 * (MSDN says that this parameter is reserved)
4558 static LRESULT
4559 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4561 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4562 DWORD dwTemp;
4564 dwTemp = infoPtr->dwExStyle;
4565 infoPtr->dwExStyle &= ~wParam;
4566 infoPtr->dwExStyle |= (DWORD)lParam;
4568 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4570 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4571 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4572 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4574 TOOLBAR_CalcToolbar (hwnd);
4576 TOOLBAR_AutoSize(hwnd);
4578 InvalidateRect(hwnd, NULL, TRUE);
4580 return (LRESULT)dwTemp;
4584 static LRESULT
4585 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4587 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4588 HIMAGELIST himlTemp;
4589 HIMAGELIST himl = (HIMAGELIST)lParam;
4590 INT id = 0;
4592 if (infoPtr->iVersion >= 5)
4593 id = wParam;
4595 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4597 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4598 &infoPtr->cimlHot, himl, id);
4600 /* FIXME: redraw ? */
4602 return (LRESULT)himlTemp;
4606 /* Makes previous hot button no longer hot, makes the specified
4607 * button hot and sends appropriate notifications. dwReason is one or
4608 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4609 * NOTE 1: this function does not validate nHit
4610 * NOTE 2: the name of this function is completely made up and
4611 * not based on any documentation from Microsoft. */
4612 static void
4613 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4615 if (infoPtr->nHotItem != nHit)
4617 NMTBHOTITEM nmhotitem;
4618 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4619 LRESULT no_highlight;
4621 if (nHit == TOOLBAR_NOWHERE && infoPtr->bAnchor)
4622 return;
4624 /* Remove the effect of an old hot button if the button was
4625 drawn with the hot button effect */
4626 if(infoPtr->nHotItem >= 0)
4628 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4629 oldBtnPtr->bHot = FALSE;
4632 infoPtr->nHotItem = nHit;
4634 /* It's not a separator or in nowhere. It's a hot button. */
4635 if (nHit >= 0)
4636 btnPtr = &infoPtr->buttons[nHit];
4638 nmhotitem.dwFlags = dwReason;
4639 if (oldBtnPtr)
4640 nmhotitem.idOld = oldBtnPtr->idCommand;
4641 else
4642 nmhotitem.dwFlags |= HICF_ENTERING;
4643 if (btnPtr)
4644 nmhotitem.idNew = btnPtr->idCommand;
4645 else
4646 nmhotitem.dwFlags |= HICF_LEAVING;
4648 no_highlight = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4650 /* now invalidate the old and new buttons so they will be painted */
4651 if (oldBtnPtr)
4652 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4653 if (btnPtr && !no_highlight)
4655 btnPtr->bHot = TRUE;
4656 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4661 static LRESULT
4662 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4664 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4665 INT nOldHotItem = infoPtr->nHotItem;
4667 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4668 wParam = -2;
4670 if (infoPtr->dwStyle & TBSTYLE_FLAT)
4671 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4673 if (nOldHotItem < 0)
4674 return -1;
4676 return (LRESULT)nOldHotItem;
4680 static LRESULT
4681 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4683 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4684 HIMAGELIST himlTemp;
4685 HIMAGELIST himl = (HIMAGELIST)lParam;
4686 INT i, id = 0;
4688 if (infoPtr->iVersion >= 5)
4689 id = wParam;
4691 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4692 &infoPtr->cimlDef, himl, id);
4694 infoPtr->nNumBitmaps = 0;
4695 for (i = 0; i < infoPtr->cimlDef; i++)
4696 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4698 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4699 &infoPtr->nBitmapHeight);
4700 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4701 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4702 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4704 InvalidateRect(hwnd, NULL, TRUE);
4706 return (LRESULT)himlTemp;
4710 static LRESULT
4711 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4713 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4715 infoPtr->nIndent = (INT)wParam;
4717 TRACE("\n");
4719 /* process only on indent changing */
4720 if(infoPtr->nIndent != (INT)wParam)
4722 infoPtr->nIndent = (INT)wParam;
4723 TOOLBAR_CalcToolbar (hwnd);
4724 InvalidateRect(hwnd, NULL, FALSE);
4727 return TRUE;
4731 static LRESULT
4732 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4734 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4735 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4737 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4739 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4741 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4742 return 0;
4745 if ((lptbim->iButton == -1) ||
4746 ((lptbim->iButton < infoPtr->nNumButtons) &&
4747 (lptbim->iButton >= 0)))
4749 infoPtr->tbim = *lptbim;
4750 /* FIXME: don't need to update entire toolbar */
4751 InvalidateRect(hwnd, NULL, TRUE);
4753 else
4754 ERR("Invalid button index %d\n", lptbim->iButton);
4756 return 0;
4760 static LRESULT
4761 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4763 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4765 infoPtr->clrInsertMark = (COLORREF)lParam;
4767 /* FIXME: don't need to update entire toolbar */
4768 InvalidateRect(hwnd, NULL, TRUE);
4770 return 0;
4774 static LRESULT
4775 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4777 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4779 if (infoPtr == NULL)
4780 return FALSE;
4782 infoPtr->nMaxTextRows = (INT)wParam;
4784 TOOLBAR_CalcToolbar(hwnd);
4785 return TRUE;
4789 /* MSDN gives slightly wrong info on padding.
4790 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4791 * 2. It is not used to create a blank area between the edge of the button
4792 * and the text or image if TBSTYLE_LIST is set. It is used to control
4793 * the gap between the image and text.
4794 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4795 * to control the bottom and right borders [with the border being
4796 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4797 * is shared evenly on both sides of the button.
4799 static LRESULT
4800 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4802 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4803 DWORD oldPad;
4805 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4806 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4807 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4808 TRACE("cx=%ld, cy=%ld\n",
4809 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4810 return (LRESULT) oldPad;
4814 static LRESULT
4815 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4817 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4818 HWND hwndOldNotify;
4820 TRACE("\n");
4822 if (infoPtr == NULL)
4823 return 0;
4824 hwndOldNotify = infoPtr->hwndNotify;
4825 infoPtr->hwndNotify = (HWND)wParam;
4827 return (LRESULT)hwndOldNotify;
4831 static LRESULT
4832 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4834 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4835 LPRECT lprc = (LPRECT)lParam;
4837 TRACE("\n");
4839 if (LOWORD(wParam) > 1) {
4840 FIXME("multiple rows not supported!\n");
4843 if(infoPtr->nRows != LOWORD(wParam))
4845 infoPtr->nRows = LOWORD(wParam);
4847 /* recalculate toolbar */
4848 TOOLBAR_CalcToolbar (hwnd);
4850 /* repaint toolbar */
4851 InvalidateRect(hwnd, NULL, TRUE);
4854 /* return bounding rectangle */
4855 if (lprc) {
4856 lprc->left = infoPtr->rcBound.left;
4857 lprc->right = infoPtr->rcBound.right;
4858 lprc->top = infoPtr->rcBound.top;
4859 lprc->bottom = infoPtr->rcBound.bottom;
4862 return 0;
4866 static LRESULT
4867 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4869 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4870 TBUTTON_INFO *btnPtr;
4871 INT nIndex;
4873 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4874 if (nIndex == -1)
4875 return FALSE;
4877 btnPtr = &infoPtr->buttons[nIndex];
4879 /* if hidden state has changed the invalidate entire window and recalc */
4880 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4881 btnPtr->fsState = LOWORD(lParam);
4882 TOOLBAR_CalcToolbar (hwnd);
4883 InvalidateRect(hwnd, 0, TRUE);
4884 return TRUE;
4887 /* process state changing if current state doesn't match new state */
4888 if(btnPtr->fsState != LOWORD(lParam))
4890 btnPtr->fsState = LOWORD(lParam);
4891 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4894 return TRUE;
4898 static LRESULT
4899 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4901 SetWindowLongW(hwnd, GWL_STYLE, lParam);
4903 return TRUE;
4907 inline static LRESULT
4908 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4910 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4912 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
4914 if (infoPtr == NULL)
4915 return 0;
4916 infoPtr->hwndToolTip = (HWND)wParam;
4917 return 0;
4921 static LRESULT
4922 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4924 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4925 BOOL bTemp;
4927 TRACE("%s hwnd=%p stub!\n",
4928 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4930 bTemp = infoPtr->bUnicode;
4931 infoPtr->bUnicode = (BOOL)wParam;
4933 return bTemp;
4937 static LRESULT
4938 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4940 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4942 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4943 comctl32_color.clrBtnHighlight :
4944 infoPtr->clrBtnHighlight;
4945 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4946 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4947 return 1;
4951 static LRESULT
4952 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4954 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4956 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4957 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4958 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4960 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4961 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4962 InvalidateRect(hwnd, NULL, TRUE);
4963 return 0;
4967 static LRESULT
4968 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4970 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4971 INT iOldVersion = infoPtr->iVersion;
4973 infoPtr->iVersion = iVersion;
4975 if (infoPtr->iVersion >= 5)
4976 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
4978 return iOldVersion;
4982 static LRESULT
4983 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4985 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4986 WORD iString = HIWORD(wParam);
4987 WORD buffersize = LOWORD(wParam);
4988 LPSTR str = (LPSTR)lParam;
4989 LRESULT ret = -1;
4991 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
4993 if (iString < infoPtr->nNumStrings)
4995 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
4997 TRACE("returning %s\n", debugstr_a(str));
4999 else
5000 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5002 return ret;
5006 static LRESULT
5007 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5009 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5010 WORD iString = HIWORD(wParam);
5011 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5012 LPWSTR str = (LPWSTR)lParam;
5013 LRESULT ret = -1;
5015 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5017 if (iString < infoPtr->nNumStrings)
5019 len = min(len, strlenW(infoPtr->strings[iString]));
5020 ret = (len+1)*sizeof(WCHAR);
5021 memcpy(str, infoPtr->strings[iString], ret);
5022 str[len] = '\0';
5024 TRACE("returning %s\n", debugstr_w(str));
5026 else
5027 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5029 return ret;
5032 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5033 * is the maximum size of the toolbar? */
5034 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5036 SIZE * pSize = (SIZE*)lParam;
5037 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5038 return 0;
5042 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5043 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5044 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5045 * sends). */
5046 static LRESULT
5047 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5049 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5050 INT nOldHotItem = infoPtr->nHotItem;
5052 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5053 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5055 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5056 wParam = -1;
5058 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5060 GetFocus();
5062 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5065 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5066 * which controls the amount of spacing between the image and the text
5067 * of buttons for TBSTYLE_LIST toolbars. */
5068 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5070 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5072 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5074 if (lParam != 0)
5075 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5077 infoPtr->iListGap = (INT)wParam;
5079 TOOLBAR_CalcToolbar(hwnd);
5080 InvalidateRect(hwnd, NULL, TRUE);
5082 return 0;
5085 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5086 * of image lists associated with the various states. */
5087 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5089 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5091 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5093 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5096 static LRESULT
5097 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5099 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5100 LPSIZE lpsize = (LPSIZE)lParam;
5102 if (lpsize == NULL)
5103 return FALSE;
5106 * Testing shows the following:
5107 * wParam = 0 adjust cx value
5108 * = 1 set cy value to max size.
5109 * lParam pointer to SIZE structure
5112 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5113 wParam, lParam, lpsize->cx, lpsize->cy);
5115 switch(wParam) {
5116 case 0:
5117 if (lpsize->cx == -1) {
5118 /* **** this is wrong, native measures each button and sets it */
5119 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5121 else if(HIWORD(lpsize->cx)) {
5122 RECT rc;
5123 HWND hwndParent = GetParent(hwnd);
5125 GetWindowRect(hwnd, &rc);
5126 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5127 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5128 rc.left, rc.top, rc.right, rc.bottom);
5129 lpsize->cx = max(rc.right-rc.left,
5130 infoPtr->rcBound.right - infoPtr->rcBound.left);
5132 else {
5133 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5135 break;
5136 case 1:
5137 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5138 /* lpsize->cy = infoPtr->nHeight; */
5139 break;
5140 default:
5141 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5142 wParam);
5143 return 0;
5145 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5146 lpsize->cx, lpsize->cy);
5147 return 1;
5150 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5152 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5154 InvalidateRect(hwnd, NULL, TRUE);
5155 return 1;
5159 static LRESULT
5160 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5162 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5163 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5164 LOGFONTA logFont;
5166 TRACE("hwnd = %p\n", hwnd);
5168 /* initialize info structure */
5169 infoPtr->nButtonHeight = 22;
5170 infoPtr->nButtonWidth = 24;
5171 infoPtr->nBitmapHeight = 15;
5172 infoPtr->nBitmapWidth = 16;
5174 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
5175 infoPtr->nMaxTextRows = 1;
5176 infoPtr->cxMin = -1;
5177 infoPtr->cxMax = -1;
5178 infoPtr->nNumBitmaps = 0;
5179 infoPtr->nNumStrings = 0;
5181 infoPtr->bCaptured = FALSE;
5182 infoPtr->bUnicode = IsWindowUnicode (hwnd);
5183 infoPtr->nButtonDown = -1;
5184 infoPtr->nButtonDrag = -1;
5185 infoPtr->nOldHit = -1;
5186 infoPtr->nHotItem = -1;
5187 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5188 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5189 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5190 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5191 infoPtr->bDragOutSent = FALSE;
5192 infoPtr->iVersion = 0;
5193 infoPtr->hwndSelf = hwnd;
5194 infoPtr->bDoRedraw = TRUE;
5195 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5196 infoPtr->clrBtnShadow = CLR_DEFAULT;
5197 /* not sure where the +1 comes from, but this comes to the same value
5198 * as native so this is probably correct */
5199 infoPtr->szPadding.cx = 2*(GetSystemMetrics(SM_CXEDGE)+OFFSET_X) + 1;
5200 infoPtr->szPadding.cy = 2*(GetSystemMetrics(SM_CYEDGE)+OFFSET_Y);
5201 infoPtr->iListGap = infoPtr->szPadding.cx / 2;
5202 infoPtr->dwStyle = dwStyle;
5203 infoPtr->tbim.iButton = -1;
5204 GetClientRect(hwnd, &infoPtr->client_rect);
5205 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
5207 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5208 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
5210 if (dwStyle & TBSTYLE_TOOLTIPS) {
5211 /* Create tooltip control */
5212 infoPtr->hwndToolTip =
5213 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
5214 CW_USEDEFAULT, CW_USEDEFAULT,
5215 CW_USEDEFAULT, CW_USEDEFAULT,
5216 hwnd, 0, 0, 0);
5218 /* Send NM_TOOLTIPSCREATED notification */
5219 if (infoPtr->hwndToolTip) {
5220 NMTOOLTIPSCREATED nmttc;
5222 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5224 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
5225 NM_TOOLTIPSCREATED);
5229 TOOLBAR_CheckStyle (hwnd, dwStyle);
5231 TOOLBAR_CalcToolbar(hwnd);
5233 return 0;
5237 static LRESULT
5238 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5240 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5242 /* delete tooltip control */
5243 if (infoPtr->hwndToolTip)
5244 DestroyWindow (infoPtr->hwndToolTip);
5246 /* delete temporary buffer for tooltip text */
5247 if (infoPtr->pszTooltipText)
5248 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5250 /* delete button data */
5251 if (infoPtr->buttons)
5252 Free (infoPtr->buttons);
5254 /* delete strings */
5255 if (infoPtr->strings) {
5256 INT i;
5257 for (i = 0; i < infoPtr->nNumStrings; i++)
5258 if (infoPtr->strings[i])
5259 Free (infoPtr->strings[i]);
5261 Free (infoPtr->strings);
5264 /* destroy internal image list */
5265 if (infoPtr->himlInt)
5266 ImageList_Destroy (infoPtr->himlInt);
5268 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5269 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5270 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5272 /* delete default font */
5273 if (infoPtr->hFont)
5274 DeleteObject (infoPtr->hDefaultFont);
5276 /* free toolbar info data */
5277 Free (infoPtr);
5278 SetWindowLongPtrW (hwnd, 0, 0);
5280 return 0;
5284 static LRESULT
5285 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5287 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5288 NMTBCUSTOMDRAW tbcd;
5289 INT ret = FALSE;
5290 DWORD ntfret;
5292 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5293 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5294 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5295 tbcd.nmcd.hdc = (HDC)wParam;
5296 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5297 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5299 /* FIXME: in general the return flags *can* be or'ed together */
5300 switch (infoPtr->dwBaseCustDraw)
5302 case CDRF_DODEFAULT:
5303 break;
5304 case CDRF_SKIPDEFAULT:
5305 return TRUE;
5306 default:
5307 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5308 hwnd, ntfret);
5312 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5313 * to my parent for processing.
5315 if (infoPtr->dwStyle & TBSTYLE_TRANSPARENT) {
5316 POINT pt, ptorig;
5317 HDC hdc = (HDC)wParam;
5318 HWND parent;
5320 pt.x = 0;
5321 pt.y = 0;
5322 parent = GetParent(hwnd);
5323 MapWindowPoints(hwnd, parent, &pt, 1);
5324 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5325 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
5326 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5328 if (!ret)
5329 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
5331 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5332 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5333 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5334 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5335 tbcd.nmcd.hdc = (HDC)wParam;
5336 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5337 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5338 switch (infoPtr->dwBaseCustDraw)
5340 case CDRF_DODEFAULT:
5341 break;
5342 case CDRF_SKIPDEFAULT:
5343 return TRUE;
5344 default:
5345 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5346 hwnd, ntfret);
5349 return ret;
5353 static LRESULT
5354 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5356 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5358 return (LRESULT)infoPtr->hFont;
5362 static LRESULT
5363 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5365 POINT pt;
5366 INT nHit;
5368 pt.x = (INT)LOWORD(lParam);
5369 pt.y = (INT)HIWORD(lParam);
5370 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5372 if (nHit >= 0)
5373 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5374 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5375 TOOLBAR_Customize (hwnd);
5377 return 0;
5381 static LRESULT
5382 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5384 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5385 TBUTTON_INFO *btnPtr;
5386 POINT pt;
5387 INT nHit;
5388 NMTOOLBARA nmtb;
5389 BOOL bDragKeyPressed;
5391 TRACE("\n");
5393 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5394 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5395 else
5396 bDragKeyPressed = (wParam & MK_SHIFT);
5398 if (infoPtr->hwndToolTip)
5399 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5400 WM_LBUTTONDOWN, wParam, lParam);
5402 pt.x = (INT)LOWORD(lParam);
5403 pt.y = (INT)HIWORD(lParam);
5404 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5406 btnPtr = &infoPtr->buttons[nHit];
5408 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5410 infoPtr->nButtonDrag = nHit;
5411 SetCapture (hwnd);
5413 /* If drag cursor has not been loaded, load it.
5414 * Note: it doesn't need to be freed */
5415 if (!hCursorDrag)
5416 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5417 SetCursor(hCursorDrag);
5419 else if (nHit >= 0)
5421 RECT arrowRect;
5422 infoPtr->nOldHit = nHit;
5424 CopyRect(&arrowRect, &btnPtr->rect);
5425 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5427 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5428 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5429 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5430 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5431 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5432 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5434 LRESULT res;
5436 /* draw in pressed state */
5437 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5438 btnPtr->fsState |= TBSTATE_PRESSED;
5439 else
5440 btnPtr->bDropDownPressed = TRUE;
5441 RedrawWindow(hwnd,&btnPtr->rect,0,
5442 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5444 nmtb.iItem = btnPtr->idCommand;
5445 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
5446 nmtb.cchText = 0;
5447 nmtb.pszText = 0;
5448 CopyRect(&nmtb.rcButton, &btnPtr->rect);
5449 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5450 TBN_DROPDOWN);
5451 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5453 if (res != TBDDRET_TREATPRESSED)
5455 MSG msg;
5457 /* redraw button in unpressed state */
5458 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5459 btnPtr->fsState &= ~TBSTATE_PRESSED;
5460 else
5461 btnPtr->bDropDownPressed = FALSE;
5462 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5464 /* find and set hot item
5465 * NOTE: native doesn't do this, but that is a bug */
5466 GetCursorPos(&pt);
5467 ScreenToClient(hwnd, &pt);
5468 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5469 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5471 /* remove any left mouse button down or double-click messages
5472 * so that we can get a toggle effect on the button */
5473 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5474 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5477 return 0;
5479 /* otherwise drop through and process as pushed */
5481 infoPtr->bCaptured = TRUE;
5482 infoPtr->nButtonDown = nHit;
5483 infoPtr->bDragOutSent = FALSE;
5485 btnPtr->fsState |= TBSTATE_PRESSED;
5487 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5489 if (btnPtr->fsState & TBSTATE_ENABLED)
5490 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5491 UpdateWindow(hwnd);
5492 SetCapture (hwnd);
5495 if (nHit >=0)
5497 nmtb.iItem = btnPtr->idCommand;
5498 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5499 nmtb.tbButton.idCommand = btnPtr->idCommand;
5500 nmtb.tbButton.fsState = btnPtr->fsState;
5501 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5502 nmtb.tbButton.dwData = btnPtr->dwData;
5503 nmtb.tbButton.iString = btnPtr->iString;
5504 nmtb.cchText = 0; /* !!! not correct */
5505 nmtb.pszText = 0; /* !!! not correct */
5506 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5509 return 0;
5512 static LRESULT
5513 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5515 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5516 TBUTTON_INFO *btnPtr;
5517 POINT pt;
5518 INT nHit;
5519 INT nOldIndex = -1;
5520 BOOL bSendMessage = TRUE;
5521 NMHDR hdr;
5522 NMMOUSE nmmouse;
5523 NMTOOLBARA nmtb;
5525 if (infoPtr->hwndToolTip)
5526 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5527 WM_LBUTTONUP, wParam, lParam);
5529 pt.x = (INT)LOWORD(lParam);
5530 pt.y = (INT)HIWORD(lParam);
5531 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5533 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5535 if (infoPtr->nButtonDrag >= 0) {
5536 RECT rcClient;
5537 NMHDR hdr;
5539 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5540 ReleaseCapture();
5541 /* reset cursor */
5542 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5544 GetClientRect(hwnd, &rcClient);
5545 if (PtInRect(&rcClient, pt))
5547 INT nButton = -1;
5548 if (nHit >= 0)
5549 nButton = nHit;
5550 else if (nHit < -1)
5551 nButton = -nHit;
5552 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5553 nButton = -nHit;
5555 if (nButton == infoPtr->nButtonDrag)
5557 /* if the button is moved sightly left and we have a
5558 * separator there then remove it */
5559 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5561 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5562 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5564 else /* else insert a separator before the dragged button */
5566 TBBUTTON tbb;
5567 memset(&tbb, 0, sizeof(tbb));
5568 tbb.fsStyle = BTNS_SEP;
5569 tbb.iString = -1;
5570 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5573 else
5575 if (nButton == -1)
5577 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5578 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5579 else
5580 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5582 else
5583 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5586 else
5588 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5589 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5592 /* button under cursor changed so need to re-set hot item */
5593 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5594 infoPtr->nButtonDrag = -1;
5596 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5598 else if (infoPtr->nButtonDown >= 0) {
5599 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5600 btnPtr->fsState &= ~TBSTATE_PRESSED;
5602 if (btnPtr->fsStyle & BTNS_CHECK) {
5603 if (btnPtr->fsStyle & BTNS_GROUP) {
5604 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5605 nHit);
5606 if (nOldIndex == nHit)
5607 bSendMessage = FALSE;
5608 if ((nOldIndex != nHit) &&
5609 (nOldIndex != -1))
5610 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5611 btnPtr->fsState |= TBSTATE_CHECKED;
5613 else {
5614 if (btnPtr->fsState & TBSTATE_CHECKED)
5615 btnPtr->fsState &= ~TBSTATE_CHECKED;
5616 else
5617 btnPtr->fsState |= TBSTATE_CHECKED;
5621 if (nOldIndex != -1)
5622 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5625 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5626 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5627 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5629 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5630 ReleaseCapture ();
5631 infoPtr->nButtonDown = -1;
5633 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5634 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5635 NM_RELEASEDCAPTURE);
5637 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5638 * TBN_BEGINDRAG
5640 nmtb.iItem = btnPtr->idCommand;
5641 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5642 nmtb.tbButton.idCommand = btnPtr->idCommand;
5643 nmtb.tbButton.fsState = btnPtr->fsState;
5644 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5645 nmtb.tbButton.dwData = btnPtr->dwData;
5646 nmtb.tbButton.iString = btnPtr->iString;
5647 nmtb.cchText = 0; /* !!! not correct */
5648 nmtb.pszText = 0; /* !!! not correct */
5649 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5650 TBN_ENDDRAG);
5652 if (btnPtr->fsState & TBSTATE_ENABLED)
5654 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
5655 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5657 /* !!! Undocumented - toolbar at 4.71 level and above sends
5658 * either NM_RCLICK or NM_CLICK with the NMMOUSE structure.
5659 * Only NM_RCLICK is documented.
5661 nmmouse.dwItemSpec = btnPtr->idCommand;
5662 nmmouse.dwItemData = btnPtr->dwData;
5663 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr, NM_CLICK);
5666 return 0;
5669 static LRESULT
5670 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5672 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5674 NMMOUSE nmmouse;
5675 POINT pt;
5677 pt.x = LOWORD(lParam);
5678 pt.y = HIWORD(lParam);
5680 nmmouse.dwHitInfo = TOOLBAR_InternalHitTest(hwnd, &pt);
5682 if (nmmouse.dwHitInfo < 0) {
5683 nmmouse.dwItemSpec = -1;
5684 } else {
5685 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5686 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5689 ClientToScreen(hwnd, &pt);
5690 memcpy(&nmmouse.pt, &pt, sizeof(POINT));
5692 TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK);
5694 return 0;
5697 static LRESULT
5698 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5700 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5702 NMMOUSE nmmouse;
5703 POINT pt;
5705 pt.x = LOWORD(lParam);
5706 pt.y = HIWORD(lParam);
5708 nmmouse.dwHitInfo = TOOLBAR_InternalHitTest(hwnd, &pt);
5710 if (nmmouse.dwHitInfo < 0)
5711 nmmouse.dwItemSpec = -1;
5712 else {
5713 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5714 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5717 ClientToScreen(hwnd, &pt);
5718 memcpy(&nmmouse.pt, &pt, sizeof(POINT));
5720 TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RDBLCLK);
5722 return 0;
5725 static LRESULT
5726 TOOLBAR_CaptureChanged(HWND hwnd)
5728 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5729 TBUTTON_INFO *btnPtr;
5731 infoPtr->bCaptured = FALSE;
5733 if (infoPtr->nButtonDown >= 0)
5735 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5736 btnPtr->fsState &= ~TBSTATE_PRESSED;
5738 infoPtr->nOldHit = -1;
5740 if (btnPtr->fsState & TBSTATE_ENABLED)
5741 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5743 return 0;
5746 static LRESULT
5747 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5749 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5750 TBUTTON_INFO *hotBtnPtr;
5752 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5754 /* don't remove hot effects when in drop-down */
5755 if (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed)
5756 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
5758 if (infoPtr->nOldHit < 0)
5759 return TRUE;
5761 /* If the last button we were over is depressed then make it not */
5762 /* depressed and redraw it */
5763 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5765 TBUTTON_INFO *btnPtr;
5766 RECT rc1;
5768 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5770 btnPtr->fsState &= ~TBSTATE_PRESSED;
5772 rc1 = hotBtnPtr->rect;
5773 InflateRect (&rc1, 1, 1);
5774 InvalidateRect (hwnd, &rc1, TRUE);
5777 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
5779 NMTOOLBARW nmt;
5780 ZeroMemory(&nmt, sizeof(nmt));
5781 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5782 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5783 infoPtr->bDragOutSent = TRUE;
5786 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5788 return TRUE;
5791 static LRESULT
5792 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5794 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5795 POINT pt;
5796 TRACKMOUSEEVENT trackinfo;
5797 INT nHit;
5798 TBUTTON_INFO *btnPtr;
5800 /* fill in the TRACKMOUSEEVENT struct */
5801 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5802 trackinfo.dwFlags = TME_QUERY;
5803 trackinfo.hwndTrack = hwnd;
5804 trackinfo.dwHoverTime = HOVER_DEFAULT;
5806 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5807 _TrackMouseEvent(&trackinfo);
5809 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5810 if(!(trackinfo.dwFlags & TME_LEAVE)) {
5811 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5813 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5814 /* and can properly deactivate the hot toolbar button */
5815 _TrackMouseEvent(&trackinfo);
5818 if (infoPtr->hwndToolTip)
5819 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5820 WM_MOUSEMOVE, wParam, lParam);
5822 pt.x = (INT)LOWORD(lParam);
5823 pt.y = (INT)HIWORD(lParam);
5825 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5827 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
5829 if (infoPtr->nOldHit != nHit)
5831 if (infoPtr->bCaptured)
5833 if (!infoPtr->bDragOutSent)
5835 NMTOOLBARW nmt;
5836 ZeroMemory(&nmt, sizeof(nmt));
5837 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5838 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5839 infoPtr->bDragOutSent = TRUE;
5842 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5843 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5844 btnPtr->fsState &= ~TBSTATE_PRESSED;
5845 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5847 else if (nHit == infoPtr->nButtonDown) {
5848 btnPtr->fsState |= TBSTATE_PRESSED;
5849 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5851 infoPtr->nOldHit = nHit;
5855 return 0;
5859 inline static LRESULT
5860 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5862 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5863 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5864 /* else */
5865 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5869 inline static LRESULT
5870 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5872 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
5873 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5875 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5879 static LRESULT
5880 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5882 TOOLBAR_INFO *infoPtr;
5883 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5884 DWORD styleadd = 0;
5886 /* allocate memory for info structure */
5887 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
5888 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
5890 /* paranoid!! */
5891 infoPtr->dwStructSize = sizeof(TBBUTTON);
5892 infoPtr->nRows = 1;
5894 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5895 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
5896 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
5897 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
5900 /* native control does:
5901 * Get a lot of colors and brushes
5902 * WM_NOTIFYFORMAT
5903 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5904 * CreateFontIndirectA(adr1)
5905 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5906 * hdc = GetDC(toolbar)
5907 * GetSystemMetrics(0x48)
5908 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5909 * 0, 0, 0, 0, "MARLETT")
5910 * oldfnt = SelectObject(hdc, fnt2)
5911 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5912 * GetTextMetricsA(hdc, adr3)
5913 * SelectObject(hdc, oldfnt)
5914 * DeleteObject(fnt2)
5915 * ReleaseDC(hdc)
5916 * InvalidateRect(toolbar, 0, 1)
5917 * SetWindowLongA(toolbar, 0, addr)
5918 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5919 * WM_STYLECHANGING
5920 * CallWinEx old new
5921 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5922 * ie 2 0x4600094c 0x4600094c 0x4600894d
5923 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5924 * rebar 0x50008844 0x40008844 0x50008845
5925 * pager 0x50000844 0x40000844 0x50008845
5926 * IC35mgr 0x5400084e **nochange**
5927 * on entry to _NCCREATE 0x5400084e
5928 * rowlist 0x5400004e **nochange**
5929 * on entry to _NCCREATE 0x5400004e
5933 /* I think the code below is a bug, but it is the way that the native
5934 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5935 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5936 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5937 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5938 * Some how, the only cases of this seem to be MFC programs.
5940 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5941 * does not occur in the WM_STYLECHANGING routine.
5942 * (Guy Albertelli 9/2001)
5945 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5946 styleadd |= TBSTYLE_TRANSPARENT;
5947 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5948 styleadd |= CCS_TOP; /* default to top */
5949 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
5952 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5956 static LRESULT
5957 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5959 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
5960 RECT rcWindow;
5961 HDC hdc;
5963 if (dwStyle & WS_MINIMIZE)
5964 return 0; /* Nothing to do */
5966 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5968 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5969 return 0;
5971 if (!(dwStyle & CCS_NODIVIDER))
5973 GetWindowRect (hwnd, &rcWindow);
5974 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5975 if( dwStyle & WS_BORDER )
5976 OffsetRect (&rcWindow, 1, 1);
5977 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5980 ReleaseDC( hwnd, hdc );
5982 return 0;
5986 /* handles requests from the tooltip control on what text to display */
5987 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
5989 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
5991 TRACE("button index = %d\n", index);
5993 if (infoPtr->pszTooltipText)
5995 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5996 infoPtr->pszTooltipText = NULL;
5999 if (index < 0)
6000 return 0;
6002 if (infoPtr->bNtfUnicode)
6004 WCHAR wszBuffer[INFOTIPSIZE+1];
6005 NMTBGETINFOTIPW tbgit;
6006 int len; /* in chars */
6008 wszBuffer[0] = '\0';
6009 wszBuffer[INFOTIPSIZE] = '\0';
6011 tbgit.pszText = wszBuffer;
6012 tbgit.cchTextMax = INFOTIPSIZE;
6013 tbgit.iItem = lpnmtdi->hdr.idFrom;
6014 tbgit.lParam = infoPtr->buttons[index].dwData;
6016 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6018 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6020 len = strlenW(tbgit.pszText);
6021 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6023 /* need to allocate temporary buffer in infoPtr as there
6024 * isn't enough space in buffer passed to us by the
6025 * tooltip control */
6026 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6027 if (infoPtr->pszTooltipText)
6029 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6030 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6031 return 0;
6034 else if (len > 0)
6036 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6037 return 0;
6040 else
6042 CHAR szBuffer[INFOTIPSIZE+1];
6043 NMTBGETINFOTIPA tbgit;
6044 int len; /* in chars */
6046 szBuffer[0] = '\0';
6047 szBuffer[INFOTIPSIZE] = '\0';
6049 tbgit.pszText = szBuffer;
6050 tbgit.cchTextMax = INFOTIPSIZE;
6051 tbgit.iItem = lpnmtdi->hdr.idFrom;
6052 tbgit.lParam = infoPtr->buttons[index].dwData;
6054 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6056 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6058 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6059 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6061 /* need to allocate temporary buffer in infoPtr as there
6062 * isn't enough space in buffer passed to us by the
6063 * tooltip control */
6064 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6065 if (infoPtr->pszTooltipText)
6067 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
6068 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6069 return 0;
6072 else if (len > 0)
6074 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
6075 return 0;
6079 /* if button has text, but it is not shown then automatically
6080 * use that text as tooltip */
6081 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6082 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6084 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6085 int len = pszText ? strlenW(pszText) : 0;
6087 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6089 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6091 /* need to allocate temporary buffer in infoPtr as there
6092 * isn't enough space in buffer passed to us by the
6093 * tooltip control */
6094 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6095 if (infoPtr->pszTooltipText)
6097 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6098 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6099 return 0;
6102 else if (len > 0)
6104 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6105 return 0;
6109 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6111 /* last resort: send notification on to app */
6112 /* FIXME: find out what is really used here */
6113 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6117 inline static LRESULT
6118 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6120 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6121 LPNMHDR lpnmh = (LPNMHDR)lParam;
6123 switch (lpnmh->code)
6125 case PGN_CALCSIZE:
6127 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6129 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6130 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6131 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6132 lppgc->iWidth);
6134 else {
6135 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6136 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6137 lppgc->iHeight);
6139 return 0;
6142 case PGN_SCROLL:
6144 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6146 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6147 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6148 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6149 lppgs->iScroll, lppgs->iDir);
6150 return 0;
6153 case TTN_GETDISPINFOW:
6154 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6156 case TTN_GETDISPINFOA:
6157 FIXME("TTN_GETDISPINFOA - stub\n");
6158 return 0;
6160 default:
6161 return 0;
6166 static LRESULT
6167 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
6169 /* remove this routine when Toolbar is improved to pass infoPtr
6170 * around instead of hwnd.
6172 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6173 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
6177 static LRESULT
6178 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6180 INT i;
6182 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6184 if ((lParam == NF_QUERY) && ((HWND)wParam == infoPtr->hwndToolTip))
6185 return NFR_UNICODE;
6187 if (lParam == NF_REQUERY) {
6188 i = SendMessageA(infoPtr->hwndNotify,
6189 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6190 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
6191 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
6193 i = NFR_ANSI;
6195 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
6196 return (LRESULT)i;
6198 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
6202 static LRESULT
6203 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6205 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6206 HDC hdc;
6207 PAINTSTRUCT ps;
6209 /* fill ps.rcPaint with a default rect */
6210 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6212 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6214 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6215 ps.rcPaint.left, ps.rcPaint.top,
6216 ps.rcPaint.right, ps.rcPaint.bottom);
6218 TOOLBAR_Refresh (hwnd, hdc, &ps);
6219 if (!wParam) EndPaint (hwnd, &ps);
6221 return 0;
6225 static LRESULT
6226 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6227 /*****************************************************
6229 * Function;
6230 * Handles the WM_SETREDRAW message.
6232 * Documentation:
6233 * According to testing V4.71 of COMCTL32 returns the
6234 * *previous* status of the redraw flag (either 0 or 1)
6235 * instead of the MSDN documented value of 0 if handled.
6236 * (For laughs see the "consistency" with same function
6237 * in rebar.)
6239 *****************************************************/
6241 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6242 BOOL oldredraw = infoPtr->bDoRedraw;
6244 TRACE("set to %s\n",
6245 (wParam) ? "TRUE" : "FALSE");
6246 infoPtr->bDoRedraw = (BOOL) wParam;
6247 if (wParam) {
6248 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6250 return (oldredraw) ? 1 : 0;
6254 static LRESULT
6255 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6257 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6258 DWORD dwStyle = infoPtr->dwStyle;
6259 RECT parent_rect;
6260 RECT window_rect;
6261 HWND parent;
6262 INT x, y;
6263 INT cx, cy;
6264 INT flags;
6265 UINT uPosFlags = 0;
6267 /* Resize deadlock check */
6268 if (infoPtr->bAutoSize) {
6269 infoPtr->bAutoSize = FALSE;
6270 return 0;
6273 /* FIXME: optimize to only update size if the new size doesn't */
6274 /* match the current size */
6276 flags = (INT) wParam;
6278 /* FIXME for flags =
6279 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
6282 TRACE("sizing toolbar!\n");
6284 if (flags == SIZE_RESTORED) {
6285 /* width and height don't apply */
6286 parent = GetParent (hwnd);
6287 GetClientRect(parent, &parent_rect);
6288 x = parent_rect.left;
6289 y = parent_rect.top;
6291 if (dwStyle & CCS_NORESIZE) {
6292 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
6295 * this sets the working width of the toolbar, and
6296 * Calc Toolbar will not adjust it, only the height
6298 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6299 cy = infoPtr->nHeight;
6300 cx = infoPtr->nWidth;
6301 TOOLBAR_CalcToolbar (hwnd);
6302 infoPtr->nWidth = cx;
6303 infoPtr->nHeight = cy;
6305 else {
6306 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6307 TOOLBAR_CalcToolbar (hwnd);
6308 cy = infoPtr->nHeight;
6309 cx = infoPtr->nWidth;
6311 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
6312 GetWindowRect(hwnd, &window_rect);
6313 ScreenToClient(parent, (LPPOINT)&window_rect.left);
6314 y = window_rect.top;
6316 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
6317 GetWindowRect(hwnd, &window_rect);
6318 y = parent_rect.bottom -
6319 ( window_rect.bottom - window_rect.top);
6323 if (dwStyle & CCS_NOPARENTALIGN) {
6324 uPosFlags |= SWP_NOMOVE;
6325 cy = infoPtr->nHeight;
6326 cx = infoPtr->nWidth;
6329 if (!(dwStyle & CCS_NODIVIDER))
6330 cy += GetSystemMetrics(SM_CYEDGE);
6332 if (dwStyle & WS_BORDER)
6334 x = y = 1;
6335 cy += GetSystemMetrics(SM_CYEDGE);
6336 cx += GetSystemMetrics(SM_CYEDGE);
6339 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6341 RECT delta_width, delta_height, client, dummy;
6342 DWORD min_x, max_x, min_y, max_y;
6343 TBUTTON_INFO *btnPtr;
6344 INT i;
6346 GetClientRect(hwnd, &client);
6347 if(client.right > infoPtr->client_rect.right)
6349 min_x = infoPtr->client_rect.right;
6350 max_x = client.right;
6352 else
6354 max_x = infoPtr->client_rect.right;
6355 min_x = client.right;
6357 if(client.bottom > infoPtr->client_rect.bottom)
6359 min_y = infoPtr->client_rect.bottom;
6360 max_y = client.bottom;
6362 else
6364 max_y = infoPtr->client_rect.bottom;
6365 min_y = client.bottom;
6368 SetRect(&delta_width, min_x, 0, max_x, min_y);
6369 SetRect(&delta_height, 0, min_y, max_x, max_y);
6371 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6372 btnPtr = infoPtr->buttons;
6373 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6374 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6375 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6376 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6379 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
6380 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6382 GetClientRect(hwnd, &infoPtr->client_rect);
6383 return 0;
6387 static LRESULT
6388 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6390 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6392 if (nType == GWL_STYLE) {
6393 if (lpStyle->styleNew & TBSTYLE_LIST) {
6394 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6396 else {
6397 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6399 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6400 (TBSTYLE_FLAT | TBSTYLE_LIST));
6401 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6403 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6405 infoPtr->dwStyle = lpStyle->styleNew;
6408 TOOLBAR_CalcToolbar(hwnd);
6410 TOOLBAR_AutoSize (hwnd);
6412 InvalidateRect(hwnd, NULL, TRUE);
6414 return 0;
6418 static LRESULT
6419 TOOLBAR_SysColorChange (HWND hwnd)
6421 COMCTL32_RefreshSysColors();
6423 return 0;
6428 static LRESULT WINAPI
6429 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6431 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6433 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6434 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6436 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
6437 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
6439 switch (uMsg)
6441 case TB_ADDBITMAP:
6442 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6444 case TB_ADDBUTTONSA:
6445 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6447 case TB_ADDBUTTONSW:
6448 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6450 case TB_ADDSTRINGA:
6451 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6453 case TB_ADDSTRINGW:
6454 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6456 case TB_AUTOSIZE:
6457 return TOOLBAR_AutoSize (hwnd);
6459 case TB_BUTTONCOUNT:
6460 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6462 case TB_BUTTONSTRUCTSIZE:
6463 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6465 case TB_CHANGEBITMAP:
6466 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6468 case TB_CHECKBUTTON:
6469 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6471 case TB_COMMANDTOINDEX:
6472 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6474 case TB_CUSTOMIZE:
6475 return TOOLBAR_Customize (hwnd);
6477 case TB_DELETEBUTTON:
6478 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6480 case TB_ENABLEBUTTON:
6481 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6483 case TB_GETANCHORHIGHLIGHT:
6484 return TOOLBAR_GetAnchorHighlight (hwnd);
6486 case TB_GETBITMAP:
6487 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6489 case TB_GETBITMAPFLAGS:
6490 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6492 case TB_GETBUTTON:
6493 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6495 case TB_GETBUTTONINFOA:
6496 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6498 case TB_GETBUTTONINFOW:
6499 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6501 case TB_GETBUTTONSIZE:
6502 return TOOLBAR_GetButtonSize (hwnd);
6504 case TB_GETBUTTONTEXTA:
6505 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6507 case TB_GETBUTTONTEXTW:
6508 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6510 case TB_GETDISABLEDIMAGELIST:
6511 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6513 case TB_GETEXTENDEDSTYLE:
6514 return TOOLBAR_GetExtendedStyle (hwnd);
6516 case TB_GETHOTIMAGELIST:
6517 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6519 case TB_GETHOTITEM:
6520 return TOOLBAR_GetHotItem (hwnd);
6522 case TB_GETIMAGELIST:
6523 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6525 case TB_GETINSERTMARK:
6526 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6528 case TB_GETINSERTMARKCOLOR:
6529 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6531 case TB_GETITEMRECT:
6532 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6534 case TB_GETMAXSIZE:
6535 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6537 /* case TB_GETOBJECT: */ /* 4.71 */
6539 case TB_GETPADDING:
6540 return TOOLBAR_GetPadding (hwnd);
6542 case TB_GETRECT:
6543 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6545 case TB_GETROWS:
6546 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6548 case TB_GETSTATE:
6549 return TOOLBAR_GetState (hwnd, wParam, lParam);
6551 case TB_GETSTRINGA:
6552 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6554 case TB_GETSTRINGW:
6555 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6557 case TB_GETSTYLE:
6558 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6560 case TB_GETTEXTROWS:
6561 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6563 case TB_GETTOOLTIPS:
6564 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6566 case TB_GETUNICODEFORMAT:
6567 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6569 case TB_HIDEBUTTON:
6570 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6572 case TB_HITTEST:
6573 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6575 case TB_INDETERMINATE:
6576 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6578 case TB_INSERTBUTTONA:
6579 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6581 case TB_INSERTBUTTONW:
6582 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6584 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6586 case TB_ISBUTTONCHECKED:
6587 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6589 case TB_ISBUTTONENABLED:
6590 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6592 case TB_ISBUTTONHIDDEN:
6593 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6595 case TB_ISBUTTONHIGHLIGHTED:
6596 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6598 case TB_ISBUTTONINDETERMINATE:
6599 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6601 case TB_ISBUTTONPRESSED:
6602 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6604 case TB_LOADIMAGES:
6605 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6607 case TB_MAPACCELERATORA:
6608 case TB_MAPACCELERATORW:
6609 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6611 case TB_MARKBUTTON:
6612 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6614 case TB_MOVEBUTTON:
6615 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6617 case TB_PRESSBUTTON:
6618 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6620 case TB_REPLACEBITMAP:
6621 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6623 case TB_SAVERESTOREA:
6624 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
6626 case TB_SAVERESTOREW:
6627 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
6629 case TB_SETANCHORHIGHLIGHT:
6630 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6632 case TB_SETBITMAPSIZE:
6633 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6635 case TB_SETBUTTONINFOA:
6636 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6638 case TB_SETBUTTONINFOW:
6639 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6641 case TB_SETBUTTONSIZE:
6642 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6644 case TB_SETBUTTONWIDTH:
6645 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6647 case TB_SETCMDID:
6648 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6650 case TB_SETDISABLEDIMAGELIST:
6651 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6653 case TB_SETDRAWTEXTFLAGS:
6654 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6656 case TB_SETEXTENDEDSTYLE:
6657 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6659 case TB_SETHOTIMAGELIST:
6660 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6662 case TB_SETHOTITEM:
6663 return TOOLBAR_SetHotItem (hwnd, wParam);
6665 case TB_SETIMAGELIST:
6666 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6668 case TB_SETINDENT:
6669 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6671 case TB_SETINSERTMARK:
6672 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6674 case TB_SETINSERTMARKCOLOR:
6675 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6677 case TB_SETMAXTEXTROWS:
6678 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6680 case TB_SETPADDING:
6681 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6683 case TB_SETPARENT:
6684 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6686 case TB_SETROWS:
6687 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6689 case TB_SETSTATE:
6690 return TOOLBAR_SetState (hwnd, wParam, lParam);
6692 case TB_SETSTYLE:
6693 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6695 case TB_SETTOOLTIPS:
6696 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6698 case TB_SETUNICODEFORMAT:
6699 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6701 case TB_UNKWN45D:
6702 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6704 case TB_UNKWN45E:
6705 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6707 case TB_UNKWN460:
6708 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6710 case TB_UNKWN462:
6711 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6713 case TB_UNKWN463:
6714 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6716 case TB_UNKWN464:
6717 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6719 /* Common Control Messages */
6721 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6722 case CCM_GETCOLORSCHEME:
6723 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6725 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6726 case CCM_SETCOLORSCHEME:
6727 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6729 case CCM_GETVERSION:
6730 return TOOLBAR_GetVersion (hwnd);
6732 case CCM_SETVERSION:
6733 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6736 /* case WM_CHAR: */
6738 case WM_CREATE:
6739 return TOOLBAR_Create (hwnd, wParam, lParam);
6741 case WM_DESTROY:
6742 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6744 case WM_ERASEBKGND:
6745 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6747 case WM_GETFONT:
6748 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6750 /* case WM_KEYDOWN: */
6751 /* case WM_KILLFOCUS: */
6753 case WM_LBUTTONDBLCLK:
6754 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6756 case WM_LBUTTONDOWN:
6757 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6759 case WM_LBUTTONUP:
6760 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6762 case WM_RBUTTONUP:
6763 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6765 case WM_RBUTTONDBLCLK:
6766 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6768 case WM_MOUSEMOVE:
6769 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6771 case WM_MOUSELEAVE:
6772 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6774 case WM_CAPTURECHANGED:
6775 return TOOLBAR_CaptureChanged(hwnd);
6777 case WM_NCACTIVATE:
6778 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6780 case WM_NCCALCSIZE:
6781 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6783 case WM_NCCREATE:
6784 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6786 case WM_NCPAINT:
6787 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6789 case WM_NOTIFY:
6790 return TOOLBAR_Notify (hwnd, wParam, lParam);
6792 case WM_NOTIFYFORMAT:
6793 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
6795 case WM_PAINT:
6796 return TOOLBAR_Paint (hwnd, wParam);
6798 case WM_SETREDRAW:
6799 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6801 case WM_SIZE:
6802 return TOOLBAR_Size (hwnd, wParam, lParam);
6804 case WM_STYLECHANGED:
6805 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6807 case WM_SYSCOLORCHANGE:
6808 return TOOLBAR_SysColorChange (hwnd);
6810 /* case WM_WININICHANGE: */
6812 case WM_CHARTOITEM:
6813 case WM_COMMAND:
6814 case WM_DRAWITEM:
6815 case WM_MEASUREITEM:
6816 case WM_VKEYTOITEM:
6817 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
6819 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6820 case PGM_FORWARDMOUSE:
6821 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6823 default:
6824 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6825 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6826 uMsg, wParam, lParam);
6827 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6829 return 0;
6833 VOID
6834 TOOLBAR_Register (void)
6836 WNDCLASSA wndClass;
6838 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
6839 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6840 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
6841 wndClass.cbClsExtra = 0;
6842 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6843 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
6844 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
6845 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
6847 RegisterClassA (&wndClass);
6851 VOID
6852 TOOLBAR_Unregister (void)
6854 UnregisterClassA (TOOLBARCLASSNAMEA, NULL);
6857 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6859 HIMAGELIST himlold;
6860 PIMLENTRY c = NULL;
6862 /* Check if the entry already exists */
6863 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6865 /* If this is a new entry we must create it and insert into the array */
6866 if (!c)
6868 PIMLENTRY *pnies;
6870 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
6871 c->id = id;
6873 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
6874 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6875 pnies[*cies] = c;
6876 (*cies)++;
6878 Free(*pies);
6879 *pies = pnies;
6882 himlold = c->himl;
6883 c->himl = himl;
6885 return himlold;
6889 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6891 int i;
6893 for (i = 0; i < *cies; i++)
6894 Free((*pies)[i]);
6896 Free(*pies);
6898 *cies = 0;
6899 *pies = NULL;
6903 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
6905 PIMLENTRY c = NULL;
6907 if (pies != NULL)
6909 int i;
6911 for (i = 0; i < cies; i++)
6913 if (pies[i]->id == id)
6915 c = pies[i];
6916 break;
6921 return c;
6925 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
6927 HIMAGELIST himlDef = 0;
6928 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6930 if (pie)
6931 himlDef = pie->himl;
6933 return himlDef;
6937 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6939 if (infoPtr->bUnicode)
6940 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
6941 else
6943 CHAR Buffer[256];
6944 NMTOOLBARA nmtba;
6945 BOOL bRet = FALSE;
6947 nmtba.iItem = nmtb->iItem;
6948 nmtba.pszText = Buffer;
6949 nmtba.cchText = 256;
6950 ZeroMemory(nmtba.pszText, nmtba.cchText);
6952 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
6954 int ccht = strlen(nmtba.pszText);
6955 if (ccht)
6956 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
6957 nmtb->pszText, nmtb->cchText);
6959 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
6960 bRet = TRUE;
6963 return bRet;
6968 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
6969 int iItem, PCUSTOMBUTTON btnInfo)
6971 NMTOOLBARA nmtb;
6973 nmtb.iItem = iItem;
6974 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
6976 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE);