Don't draw whole button pressed when separate dropdown pressed, just
[wine/multimedia.git] / dlls / comctl32 / toolbar.c
blobbb55d3b3106a5a537958a476e8deccdc39be880e
1 /*
2 * Toolbar control
4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * NOTES
24 * Differences between MSDN and actual native control operation:
25 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
26 * to the right of the bitmap. Otherwise, this style is
27 * identical to TBSTYLE_FLAT."
28 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
29 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
30 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
31 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
33 * This code was audited for completeness against the documented features
34 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
36 * Unless otherwise noted, we believe this code to be complete, as per
37 * the specification mentioned above.
38 * If you discover missing features or bugs please note them below.
40 * TODO:
41 * - Styles:
42 * - TBSTYLE_REGISTERDROP
43 * - TBSTYLE_EX_DOUBLEBUFFER
44 * - Messages:
45 * - TB_GETINSERTMARK
46 * - TB_GETINSERTMARKCOLOR
47 * - TB_GETMETRICS
48 * - TB_GETOBJECT
49 * - TB_INSERTMARKHITTEST
50 * - TB_SETINSERTMARK
51 * - TB_SETMETRICS
52 * - Notifications:
53 * - NM_CHAR
54 * - NM_KEYDOWN
55 * - TBN_GETOBJECT
56 * - TBN_RESTORE
57 * - TBN_SAVE
58 * - Button wrapping (under construction).
59 * - Fix TB_SETROWS.
60 * - iListGap custom draw support.
61 * - Customization dialog:
62 * - Minor buglet in 'available buttons' list:
63 * Buttons are not listed in MS-like order. MS seems to use a single
64 * internal list to store the button information of both listboxes.
65 * - Drag list support.
67 * Testing:
68 * - Run tests using Waite Group Windows95 API Bible Volume 2.
69 * The second cdrom contains executables addstr.exe, btncount.exe,
70 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
71 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
72 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
73 * setparnt.exe, setrows.exe, toolwnd.exe.
74 * - Microsofts controlspy examples.
75 * - Charles Petzold's 'Programming Windows': gadgets.exe
78 #include <stdarg.h>
79 #include <string.h>
81 #include "windef.h"
82 #include "winbase.h"
83 #include "wingdi.h"
84 #include "winuser.h"
85 #include "wine/unicode.h"
86 #include "winnls.h"
87 #include "commctrl.h"
88 #include "comctl32.h"
89 #include "wine/debug.h"
91 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
93 static HCURSOR hCursorDrag = NULL;
95 typedef struct
97 INT iBitmap;
98 INT idCommand;
99 BYTE fsState;
100 BYTE fsStyle;
101 BYTE bHot;
102 BYTE bDropDownPressed;
103 DWORD dwData;
104 INT iString;
105 INT nRow;
106 RECT rect;
107 INT cx; /* manually set size */
108 } TBUTTON_INFO;
110 typedef struct
112 UINT nButtons;
113 HINSTANCE hInst;
114 UINT nID;
115 } TBITMAP_INFO;
117 typedef struct
119 HIMAGELIST himl;
120 INT id;
121 } IMLENTRY, *PIMLENTRY;
123 typedef struct
125 DWORD dwStructSize; /* size of TBBUTTON struct */
126 INT nHeight; /* height of the toolbar */
127 INT nWidth; /* width of the toolbar */
128 RECT client_rect;
129 INT nButtonHeight;
130 INT nButtonWidth;
131 INT nBitmapHeight;
132 INT nBitmapWidth;
133 INT nIndent;
134 INT nRows; /* number of button rows */
135 INT nMaxTextRows; /* maximum number of text rows */
136 INT cxMin; /* minimum button width */
137 INT cxMax; /* maximum button width */
138 INT nNumButtons; /* number of buttons */
139 INT nNumBitmaps; /* number of bitmaps */
140 INT nNumStrings; /* number of strings */
141 INT nNumBitmapInfos;
142 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
143 BOOL bCaptured; /* mouse captured? */
144 INT nButtonDown; /* toolbar button being pressed or -1 if none */
145 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
146 INT nOldHit;
147 INT nHotItem; /* index of the "hot" item */
148 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
149 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
150 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
151 SIZE szPadding; /* padding values around button */
152 INT iListGap; /* default gap between text and image for toolbar with list style */
153 HFONT hDefaultFont;
154 HFONT hFont; /* text font */
155 HIMAGELIST himlInt; /* image list created internally */
156 PIMLENTRY *himlDef; /* default image list array */
157 INT cimlDef; /* default image list array count */
158 PIMLENTRY *himlHot; /* hot image list array */
159 INT cimlHot; /* hot image list array count */
160 PIMLENTRY *himlDis; /* disabled image list array */
161 INT cimlDis; /* disabled image list array count */
162 HWND hwndToolTip; /* handle to tool tip control */
163 HWND hwndNotify; /* handle to the window that gets notifications */
164 HWND hwndSelf; /* my own handle */
165 BOOL bBtnTranspnt; /* button transparency flag */
166 BOOL bAutoSize; /* auto size deadlock indicator */
167 BOOL bAnchor; /* anchor highlight enabled */
168 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
169 BOOL bDoRedraw; /* Redraw status */
170 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
171 DWORD dwStyle; /* regular toolbar style */
172 DWORD dwExStyle; /* extended toolbar style */
173 DWORD dwDTFlags; /* DrawText flags */
175 COLORREF clrInsertMark; /* insert mark color */
176 COLORREF clrBtnHighlight; /* color for Flat Separator */
177 COLORREF clrBtnShadow; /* color for Flag Separator */
178 RECT rcBound; /* bounding rectangle */
179 INT iVersion;
180 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
181 * for TTN_GETDISPINFOW notification */
182 TBUTTON_INFO *buttons; /* pointer to button array */
183 LPWSTR *strings; /* pointer to string array */
184 TBITMAP_INFO *bitmaps;
185 } TOOLBAR_INFO, *PTOOLBAR_INFO;
188 /* used by customization dialog */
189 typedef struct
191 PTOOLBAR_INFO tbInfo;
192 HWND tbHwnd;
193 } CUSTDLG_INFO, *PCUSTDLG_INFO;
195 typedef struct
197 TBBUTTON btn;
198 BOOL bVirtual;
199 BOOL bRemovable;
200 WCHAR text[64];
201 } CUSTOMBUTTON, *PCUSTOMBUTTON;
203 typedef enum
205 IMAGE_LIST_DEFAULT,
206 IMAGE_LIST_HOT,
207 IMAGE_LIST_DISABLED
208 } IMAGE_LIST_TYPE;
210 #define SEPARATOR_WIDTH 8
211 #define TOP_BORDER 2
212 #define BOTTOM_BORDER 2
213 #define DDARROW_WIDTH 11
214 #define ARROW_HEIGHT 3
216 /* gap between border of button and text/image */
217 #define OFFSET_X 1
218 #define OFFSET_Y 1
219 /* how wide to treat the bitmap if it isn't present */
220 #define LIST_IMAGE_ABSENT_WIDTH 2
222 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
223 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
224 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
226 static inline int TOOLBAR_GetListTextOffset(TOOLBAR_INFO *infoPtr, INT iListGap)
228 return GetSystemMetrics(SM_CXEDGE) + iListGap - infoPtr->szPadding.cx/2;
231 /* Used to find undocumented extended styles */
232 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
233 TBSTYLE_EX_UNDOC1 | \
234 TBSTYLE_EX_MIXEDBUTTONS | \
235 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
237 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
238 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
239 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
240 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
241 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
243 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
244 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
245 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
246 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
247 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
248 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
249 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
251 static LRESULT
252 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
255 static LPWSTR
256 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
258 LPWSTR lpText = NULL;
260 /* NOTE: iString == -1 is undocumented */
261 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
262 lpText = (LPWSTR)btnPtr->iString;
263 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
264 lpText = infoPtr->strings[btnPtr->iString];
266 return lpText;
269 static void
270 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
272 if (TRACE_ON(toolbar)){
273 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
274 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
275 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
276 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
277 if (internal)
278 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
279 btn_num, bP->idCommand,
280 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
281 bP->rect.left, bP->rect.top,
282 bP->rect.right, bP->rect.bottom);
287 static void
288 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
290 if (TRACE_ON(toolbar)) {
291 INT i;
293 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
294 iP->hwndSelf, line,
295 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
296 iP->nNumStrings, iP->dwStyle);
297 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
298 iP->hwndSelf, line,
299 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
300 (iP->bDoRedraw) ? "TRUE" : "FALSE");
301 for(i=0; i<iP->nNumButtons; i++) {
302 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
308 /***********************************************************************
309 * TOOLBAR_CheckStyle
311 * This function validates that the styles set are implemented and
312 * issues FIXME's warning of possible problems. In a perfect world this
313 * function should be null.
315 static void
316 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
318 if (dwStyle & TBSTYLE_REGISTERDROP)
319 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
323 static INT
324 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
326 if(!IsWindow(infoPtr->hwndSelf))
327 return 0; /* we have just been destroyed */
329 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
330 nmhdr->hwndFrom = infoPtr->hwndSelf;
331 nmhdr->code = code;
333 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
334 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
336 if (infoPtr->bNtfUnicode)
337 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
338 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
339 else
340 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
341 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
344 /***********************************************************************
345 * TOOLBAR_GetBitmapIndex
347 * This function returns the bitmap index associated with a button.
348 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
349 * is issued to retrieve the index.
351 static INT
352 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
354 INT ret = btnPtr->iBitmap;
356 if (ret == I_IMAGECALLBACK) {
357 /* issue TBN_GETDISPINFO */
358 NMTBDISPINFOA nmgd;
360 nmgd.idCommand = btnPtr->idCommand;
361 nmgd.lParam = btnPtr->dwData;
362 nmgd.dwMask = TBNF_IMAGE;
363 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
364 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
365 TBN_GETDISPINFOA);
366 if (nmgd.dwMask & TBNF_DI_SETITEM) {
367 btnPtr->iBitmap = nmgd.iImage;
369 ret = nmgd.iImage;
370 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
371 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
374 if (ret != I_IMAGENONE)
375 ret = GETIBITMAP(infoPtr, ret);
377 return ret;
381 static BOOL
382 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
384 HIMAGELIST himl;
385 INT id = GETHIMLID(infoPtr, index);
386 INT iBitmap = GETIBITMAP(infoPtr, index);
388 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
389 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
390 (index == I_IMAGECALLBACK))
391 return TRUE;
392 else
393 return FALSE;
397 /***********************************************************************
398 * TOOLBAR_GetImageListForDrawing
400 * This function validates the bitmap index (including I_IMAGECALLBACK
401 * functionality) and returns the corresponding image list.
403 static HIMAGELIST
404 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
406 HIMAGELIST himl;
408 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
409 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
410 ERR("index %d,%d is not valid, max %d\n",
411 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
412 return NULL;
415 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
416 if ((*index == I_IMAGECALLBACK) ||
417 (*index == I_IMAGENONE)) return NULL;
418 ERR("TBN_GETDISPINFO returned invalid index %d\n",
419 *index);
420 return NULL;
423 switch(imagelist)
425 case IMAGE_LIST_DEFAULT:
426 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
427 break;
428 case IMAGE_LIST_HOT:
429 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
430 break;
431 case IMAGE_LIST_DISABLED:
432 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
433 break;
434 default:
435 himl = NULL;
436 FIXME("Shouldn't reach here\n");
439 if (!himl)
440 TRACE("no image list\n");
442 return himl;
446 /***********************************************************************
447 * TOOLBAR_TestImageExist
449 * This function is similar to TOOLBAR_GetImageListForDrawing, except it does not
450 * return the image list. The I_IMAGECALLBACK functionality is implemented.
452 static BOOL
453 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
455 INT index;
457 if (!himl) return FALSE;
459 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
460 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
461 ERR("index %d is not valid, max %d\n",
462 btnPtr->iBitmap, infoPtr->nNumBitmaps);
463 return FALSE;
466 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
467 if ((index == I_IMAGECALLBACK) ||
468 (index == I_IMAGENONE)) return FALSE;
469 ERR("TBN_GETDISPINFO returned invalid index %d\n",
470 index);
471 return FALSE;
473 return TRUE;
477 static void
478 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
480 RECT myrect;
481 COLORREF oldcolor, newcolor;
483 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
484 myrect.right = myrect.left + 1;
485 myrect.top = lpRect->top + 2;
486 myrect.bottom = lpRect->bottom - 2;
488 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
489 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
490 oldcolor = SetBkColor (hdc, newcolor);
491 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
493 myrect.left = myrect.right;
494 myrect.right = myrect.left + 1;
496 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
497 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
498 SetBkColor (hdc, newcolor);
499 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
501 SetBkColor (hdc, oldcolor);
505 /***********************************************************************
506 * TOOLBAR_DrawDDFlatSeparator
508 * This function draws the separator that was flagged as BTNS_DROPDOWN.
509 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
510 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
511 * are horizontal as opposed to the vertical separators for not dropdown
512 * type.
514 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
516 static void
517 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
519 RECT myrect;
520 COLORREF oldcolor, newcolor;
522 myrect.left = lpRect->left;
523 myrect.right = lpRect->right;
524 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
525 myrect.bottom = myrect.top + 1;
527 InflateRect (&myrect, -2, 0);
529 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
530 myrect.left, myrect.top, myrect.right, myrect.bottom);
532 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
533 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
534 oldcolor = SetBkColor (hdc, newcolor);
535 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
537 myrect.top = myrect.bottom;
538 myrect.bottom = myrect.top + 1;
540 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
541 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
542 SetBkColor (hdc, newcolor);
543 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
545 SetBkColor (hdc, oldcolor);
549 static void
550 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
552 INT x, y;
553 HPEN hPen, hOldPen;
555 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
556 hOldPen = SelectObject ( hdc, hPen );
557 x = left + 2;
558 y = top;
559 MoveToEx (hdc, x, y, NULL);
560 LineTo (hdc, x+5, y++); x++;
561 MoveToEx (hdc, x, y, NULL);
562 LineTo (hdc, x+3, y++); x++;
563 MoveToEx (hdc, x, y, NULL);
564 LineTo (hdc, x+1, y++);
565 SelectObject( hdc, hOldPen );
566 DeleteObject( hPen );
570 * Draw the text string for this button.
571 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
572 * is non-zero, so we can simply check himlDef to see if we have
573 * an image list
575 static void
576 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
577 NMTBCUSTOMDRAW *tbcd)
579 HDC hdc = tbcd->nmcd.hdc;
580 HFONT hOldFont = 0;
581 COLORREF clrOld = 0;
582 COLORREF clrOldBk = 0;
583 int oldBkMode = 0;
584 UINT state = tbcd->nmcd.uItemState;
586 /* draw text */
587 if (lpText) {
588 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
589 rcText->left, rcText->top, rcText->right, rcText->bottom);
591 hOldFont = SelectObject (hdc, infoPtr->hFont);
592 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
593 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
595 else if (state & CDIS_DISABLED) {
596 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
597 OffsetRect (rcText, 1, 1);
598 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
599 SetTextColor (hdc, comctl32_color.clr3dShadow);
600 OffsetRect (rcText, -1, -1);
602 else if (state & CDIS_INDETERMINATE) {
603 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
605 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
606 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
607 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
608 oldBkMode = SetBkMode (hdc, OPAQUE); /* FIXME: should this be in the NMTBCUSTOMDRAW structure? */
610 else {
611 clrOld = SetTextColor (hdc, tbcd->clrText);
614 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
615 SetTextColor (hdc, clrOld);
616 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
618 SetBkColor (hdc, clrOldBk);
619 SetBkMode (hdc, oldBkMode);
621 SelectObject (hdc, hOldFont);
626 static void
627 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
629 HDC hdc = tbcd->nmcd.hdc;
630 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
631 COLORREF clrTextOld;
632 COLORREF clrBkOld;
633 INT cx = lpRect->right - lpRect->left;
634 INT cy = lpRect->bottom - lpRect->top;
635 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
636 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
637 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, PATCOPY);
638 SetBkColor(hdc, clrBkOld);
639 SetTextColor(hdc, clrTextOld);
640 SelectObject (hdc, hbr);
644 static void TOOLBAR_DrawMasked(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
645 HDC hdc, INT x, INT y)
647 int index;
648 HIMAGELIST himl =
649 TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
651 if (himl)
653 INT cx, cy;
654 HBITMAP hbmMask, hbmImage;
655 HDC hdcMask, hdcImage;
657 ImageList_GetIconSize(himl, &cx, &cy);
659 /* Create src image */
660 hdcImage = CreateCompatibleDC(hdc);
661 hbmImage = CreateBitmap(cx, cy, GetDeviceCaps(hdc,PLANES),
662 GetDeviceCaps(hdc,BITSPIXEL), NULL);
663 SelectObject(hdcImage, hbmImage);
664 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
665 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_NORMAL);
667 /* Create Mask */
668 hdcMask = CreateCompatibleDC(0);
669 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
670 SelectObject(hdcMask, hbmMask);
672 /* Remove the background and all white pixels */
673 SetBkColor(hdcImage, ImageList_GetBkColor(himl));
674 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, SRCCOPY);
675 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
676 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
678 /* draw the new mask 'etched' to hdc */
679 SetBkColor(hdc, RGB(255, 255, 255));
680 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
681 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
682 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
683 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
684 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
686 /* Cleanup */
687 DeleteObject(hbmImage);
688 DeleteDC(hdcImage);
689 DeleteObject (hbmMask);
690 DeleteDC(hdcMask);
695 static UINT
696 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
698 UINT retstate = 0;
700 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
701 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
702 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
703 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
704 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
705 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
706 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
707 return retstate;
710 /* draws the image on a toolbar button */
711 static void
712 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
714 HIMAGELIST himl = NULL;
715 BOOL draw_masked = FALSE;
716 INT index;
717 INT offset = 0;
718 UINT draw_flags = ILD_NORMAL;
720 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
722 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
723 if (!himl)
724 draw_masked = TRUE;
726 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && (infoPtr->dwStyle & TBSTYLE_FLAT))
728 /* if hot, attempt to draw with hot image list, if fails,
729 use default image list */
730 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
731 if (!himl)
732 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
734 else
735 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
737 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
738 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
739 offset = 1;
741 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
742 (tbcd->nmcd.uItemState & CDIS_MARKED))
743 draw_flags |= ILD_BLEND50;
745 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
746 index, himl, left, top, offset);
748 if (draw_masked)
749 TOOLBAR_DrawMasked (infoPtr, btnPtr, tbcd->nmcd.hdc, left + offset, top + offset);
750 else if (himl)
751 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
754 /* draws a blank frame for a toolbar button */
755 static void
756 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd)
758 HDC hdc = tbcd->nmcd.hdc;
759 RECT rc = tbcd->nmcd.rc;
760 /* if the state is disabled or indeterminate then the button
761 * cannot have an interactive look like pressed or hot */
762 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
763 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
764 BOOL pressed_look = !non_interactive_state &&
765 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
766 (tbcd->nmcd.uItemState & CDIS_CHECKED));
768 /* app don't want us to draw any edges */
769 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
770 return;
772 if (flat)
774 if (pressed_look)
775 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
776 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
777 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
779 else
781 if (pressed_look)
782 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
783 else
784 DrawEdge (hdc, &rc, EDGE_RAISED,
785 BF_SOFT | BF_RECT | BF_MIDDLE);
789 static void
790 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed)
792 HDC hdc = tbcd->nmcd.hdc;
793 int offset = 0;
794 BOOL pressed = bDropDownPressed ||
795 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
797 if (infoPtr->dwStyle & TBSTYLE_FLAT)
799 if (pressed)
800 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
801 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
802 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
803 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
804 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
806 else
808 if (pressed)
809 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
810 else
811 DrawEdge (hdc, rcArrow, EDGE_RAISED,
812 BF_SOFT | BF_RECT | BF_MIDDLE);
815 if (pressed)
816 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
818 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
820 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
821 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
823 else
824 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
827 /* draws a complete toolbar button */
828 static void
829 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
831 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
832 DWORD dwStyle = infoPtr->dwStyle;
833 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
834 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
835 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
836 BOOL drawSepDropDownArrow = hasDropDownArrow &&
837 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
838 RECT rc, rcArrow, rcBitmap, rcText;
839 LPWSTR lpText = NULL;
840 NMTBCUSTOMDRAW tbcd;
841 DWORD ntfret;
842 INT offset;
844 rc = btnPtr->rect;
845 CopyRect (&rcArrow, &rc);
846 CopyRect(&rcBitmap, &rc);
848 /* get a pointer to the text */
849 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
851 if (hasDropDownArrow)
853 int right;
855 if (dwStyle & TBSTYLE_FLAT)
856 right = max(rc.left, rc.right - DDARROW_WIDTH);
857 else
858 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
860 if (drawSepDropDownArrow)
861 rc.right = right;
863 rcArrow.left = right;
866 /* copy text rect after adjusting for drop-down arrow
867 * so that text is centred in the rectangle not containing
868 * the arrow */
869 CopyRect(&rcText, &rc);
871 /* Center the bitmap horizontally and vertically */
872 if (dwStyle & TBSTYLE_LIST)
873 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
874 else
875 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
877 if(lpText)
878 rcBitmap.top+= GetSystemMetrics(SM_CYEDGE) + OFFSET_Y;
879 else
880 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
882 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n",
883 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
884 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
885 TRACE ("iString: %x\n", btnPtr->iString);
886 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
888 /* draw text */
889 if (lpText) {
890 rcText.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
891 rcText.right -= GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
892 if (GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,btnPtr->iBitmap)) &&
893 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
895 if (dwStyle & TBSTYLE_LIST)
896 rcText.left += infoPtr->nBitmapWidth + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
897 else
898 rcText.top += GetSystemMetrics(SM_CYEDGE) + OFFSET_Y + infoPtr->nBitmapHeight + infoPtr->szPadding.cy/2;
900 else
901 if (dwStyle & TBSTYLE_LIST)
902 rcText.left += LIST_IMAGE_ABSENT_WIDTH + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
904 if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
905 OffsetRect (&rcText, 1, 1);
908 /* Initialize fields in all cases, because we use these later
909 * NOTE: applications can and do alter these to customize their
910 * toolbars */
911 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
912 tbcd.clrText = comctl32_color.clrBtnText;
913 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
914 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
915 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
916 tbcd.clrMark = comctl32_color.clrHighlight;
917 tbcd.clrHighlightHotTrack = 0;
918 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
919 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
920 /* MSDN says that this is the text rectangle.
921 * But (why always a but) tracing of v5.7 of native shows
922 * that this is really a *relative* rectangle based on the
923 * the nmcd.rc. Also the left and top are always 0 ignoring
924 * any bitmap that might be present. */
925 tbcd.rcText.left = 0;
926 tbcd.rcText.top = 0;
927 tbcd.rcText.right = rcText.right - rc.left;
928 tbcd.rcText.bottom = rcText.bottom - rc.top;
929 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
930 tbcd.nmcd.hdc = hdc;
931 tbcd.nmcd.rc = rc;
932 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
934 /* FIXME: what are these used for? */
935 tbcd.hbrLines = 0;
936 tbcd.hpenLines = 0;
938 /* Issue Item Prepaint notify */
939 infoPtr->dwItemCustDraw = 0;
940 infoPtr->dwItemCDFlag = 0;
941 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
943 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
944 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
945 tbcd.nmcd.lItemlParam = btnPtr->dwData;
946 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
947 /* reset these fields so the user can't alter the behaviour like native */
948 tbcd.nmcd.hdc = hdc;
949 tbcd.nmcd.rc = rc;
951 infoPtr->dwItemCustDraw = ntfret & 0xffff;
952 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
953 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
954 return;
955 /* save the only part of the rect that the user can change */
956 rcText.right = tbcd.rcText.right + rc.left;
957 rcText.bottom = tbcd.rcText.bottom + rc.top;
960 /* separator */
961 if (btnPtr->fsStyle & BTNS_SEP) {
962 /* with the FLAT style, iBitmap is the width and has already */
963 /* been taken into consideration in calculating the width */
964 /* so now we need to draw the vertical separator */
965 /* empirical tests show that iBitmap can/will be non-zero */
966 /* when drawing the vertical bar... */
967 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
968 if (btnPtr->fsStyle & BTNS_DROPDOWN)
969 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
970 else
971 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
973 else if (btnPtr->fsStyle != BTNS_SEP) {
974 FIXME("Draw some kind of separator: fsStyle=%x\n",
975 btnPtr->fsStyle);
977 goto FINALNOTIFY;
980 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
981 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
982 TOOLBAR_DrawPattern (&rc, &tbcd);
984 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
986 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
988 COLORREF oldclr;
990 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
991 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
992 if (hasDropDownArrow)
993 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
994 SetBkColor(hdc, oldclr);
998 TOOLBAR_DrawFrame(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd);
1000 if (drawSepDropDownArrow)
1001 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
1003 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1004 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1006 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1008 if (hasDropDownArrow && !drawSepDropDownArrow)
1010 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1012 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1013 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1015 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1017 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1018 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1020 else
1021 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1024 FINALNOTIFY:
1025 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1027 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1028 tbcd.nmcd.hdc = hdc;
1029 tbcd.nmcd.rc = rc;
1030 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1031 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1032 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1033 tbcd.rcText = rcText;
1034 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1035 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1036 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1042 static void
1043 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1045 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1046 TBUTTON_INFO *btnPtr;
1047 INT i, oldBKmode = 0;
1048 RECT rcTemp, rcClient;
1049 NMTBCUSTOMDRAW tbcd;
1050 DWORD ntfret;
1052 /* the app has told us not to redraw the toolbar */
1053 if (!infoPtr->bDoRedraw)
1054 return;
1056 /* if imagelist belongs to the app, it can be changed
1057 by the app after setting it */
1058 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1060 infoPtr->nNumBitmaps = 0;
1061 for (i = 0; i < infoPtr->cimlDef; i++)
1062 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1065 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1067 /* Send initial notify */
1068 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1069 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1070 tbcd.nmcd.hdc = hdc;
1071 tbcd.nmcd.rc = ps->rcPaint;
1072 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1073 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1075 if (infoPtr->bBtnTranspnt)
1076 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1078 GetClientRect(hwnd, &rcClient);
1080 /* redraw necessary buttons */
1081 btnPtr = infoPtr->buttons;
1082 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1084 BOOL bDraw;
1085 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1087 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1088 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1090 else
1091 bDraw = TRUE;
1092 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1093 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1094 if (bDraw)
1095 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1098 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1099 SetBkMode (hdc, oldBKmode);
1101 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1103 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1104 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1105 tbcd.nmcd.hdc = hdc;
1106 tbcd.nmcd.rc = ps->rcPaint;
1107 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1111 /***********************************************************************
1112 * TOOLBAR_MeasureString
1114 * This function gets the width and height of a string in pixels. This
1115 * is done first by using GetTextExtentPoint to get the basic width
1116 * and height. The DrawText is called with DT_CALCRECT to get the exact
1117 * width. The reason is because the text may have more than one "&" (or
1118 * prefix characters as M$ likes to call them). The prefix character
1119 * indicates where the underline goes, except for the string "&&" which
1120 * is reduced to a single "&". GetTextExtentPoint does not process these
1121 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1123 static void
1124 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1125 HDC hdc, LPSIZE lpSize)
1127 RECT myrect;
1129 lpSize->cx = 0;
1130 lpSize->cy = 0;
1132 if (infoPtr->nMaxTextRows > 0 &&
1133 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1134 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1135 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1137 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1139 if(lpText != NULL) {
1140 /* first get size of all the text */
1141 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1143 /* feed above size into the rectangle for DrawText */
1144 myrect.left = myrect.top = 0;
1145 myrect.right = lpSize->cx;
1146 myrect.bottom = lpSize->cy;
1148 /* Use DrawText to get true size as drawn (less pesky "&") */
1149 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1150 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1151 DT_NOPREFIX : 0));
1153 /* feed back to caller */
1154 lpSize->cx = myrect.right;
1155 lpSize->cy = myrect.bottom;
1159 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1162 /***********************************************************************
1163 * TOOLBAR_CalcStrings
1165 * This function walks through each string and measures it and returns
1166 * the largest height and width to caller.
1168 static void
1169 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1171 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1172 TBUTTON_INFO *btnPtr;
1173 INT i;
1174 SIZE sz;
1175 HDC hdc;
1176 HFONT hOldFont;
1178 lpSize->cx = 0;
1179 lpSize->cy = 0;
1181 if(infoPtr->nMaxTextRows == 0)
1182 return;
1184 hdc = GetDC (hwnd);
1185 hOldFont = SelectObject (hdc, infoPtr->hFont);
1187 btnPtr = infoPtr->buttons;
1188 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1189 if(TOOLBAR_HasText(infoPtr, btnPtr))
1191 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1192 if (sz.cx > lpSize->cx)
1193 lpSize->cx = sz.cx;
1194 if (sz.cy > lpSize->cy)
1195 lpSize->cy = sz.cy;
1199 SelectObject (hdc, hOldFont);
1200 ReleaseDC (hwnd, hdc);
1202 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1205 /***********************************************************************
1206 * TOOLBAR_WrapToolbar
1208 * This function walks through the buttons and separators in the
1209 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1210 * wrapping should occur based on the width of the toolbar window.
1211 * It does *not* calculate button placement itself. That task
1212 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1213 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1214 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1216 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1217 * vertical toolbar lists.
1220 static void
1221 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1223 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1224 TBUTTON_INFO *btnPtr;
1225 INT x, cx, i, j;
1226 RECT rc;
1227 BOOL bWrap, bButtonWrap;
1229 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1230 /* no layout is necessary. Applications may use this style */
1231 /* to perform their own layout on the toolbar. */
1232 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1233 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1235 btnPtr = infoPtr->buttons;
1236 x = infoPtr->nIndent;
1238 /* this can get the parents width, to know how far we can extend
1239 * this toolbar. We cannot use its height, as there may be multiple
1240 * toolbars in a rebar control
1242 GetClientRect( GetParent(hwnd), &rc );
1243 infoPtr->nWidth = rc.right - rc.left;
1244 bButtonWrap = FALSE;
1246 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1247 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1248 infoPtr->nIndent);
1250 for (i = 0; i < infoPtr->nNumButtons; i++ )
1252 bWrap = FALSE;
1253 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1255 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1256 continue;
1258 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1259 /* it is the actual width of the separator. This is used for */
1260 /* custom controls in toolbars. */
1261 /* */
1262 /* BTNS_DROPDOWN separators are treated as buttons for */
1263 /* width. - GA 8/01 */
1264 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1265 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1266 cx = (btnPtr[i].iBitmap > 0) ?
1267 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1268 else
1269 cx = infoPtr->nButtonWidth;
1271 /* Two or more adjacent separators form a separator group. */
1272 /* The first separator in a group should be wrapped to the */
1273 /* next row if the previous wrapping is on a button. */
1274 if( bButtonWrap &&
1275 (btnPtr[i].fsStyle & BTNS_SEP) &&
1276 (i + 1 < infoPtr->nNumButtons ) &&
1277 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1279 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1280 btnPtr[i].fsState |= TBSTATE_WRAP;
1281 x = infoPtr->nIndent;
1282 i++;
1283 bButtonWrap = FALSE;
1284 continue;
1287 /* The layout makes sure the bitmap is visible, but not the button. */
1288 /* Test added to also wrap after a button that starts a row but */
1289 /* is bigger than the area. - GA 8/01 */
1290 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1291 > infoPtr->nWidth ) ||
1292 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1294 BOOL bFound = FALSE;
1296 /* If the current button is a separator and not hidden, */
1297 /* go to the next until it reaches a non separator. */
1298 /* Wrap the last separator if it is before a button. */
1299 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1300 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1301 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1302 i < infoPtr->nNumButtons )
1304 i++;
1305 bFound = TRUE;
1308 if( bFound && i < infoPtr->nNumButtons )
1310 i--;
1311 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1312 i, btnPtr[i].fsStyle, x, cx);
1313 btnPtr[i].fsState |= TBSTATE_WRAP;
1314 x = infoPtr->nIndent;
1315 bButtonWrap = FALSE;
1316 continue;
1318 else if ( i >= infoPtr->nNumButtons)
1319 break;
1321 /* If the current button is not a separator, find the last */
1322 /* separator and wrap it. */
1323 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1325 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1326 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1328 bFound = TRUE;
1329 i = j;
1330 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1331 i, btnPtr[i].fsStyle, x, cx);
1332 x = infoPtr->nIndent;
1333 btnPtr[j].fsState |= TBSTATE_WRAP;
1334 bButtonWrap = FALSE;
1335 break;
1339 /* If no separator available for wrapping, wrap one of */
1340 /* non-hidden previous button. */
1341 if (!bFound)
1343 for ( j = i - 1;
1344 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1346 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1347 continue;
1349 bFound = TRUE;
1350 i = j;
1351 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1352 i, btnPtr[i].fsStyle, x, cx);
1353 x = infoPtr->nIndent;
1354 btnPtr[j].fsState |= TBSTATE_WRAP;
1355 bButtonWrap = TRUE;
1356 break;
1360 /* If all above failed, wrap the current button. */
1361 if (!bFound)
1363 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1364 i, btnPtr[i].fsStyle, x, cx);
1365 btnPtr[i].fsState |= TBSTATE_WRAP;
1366 bFound = TRUE;
1367 x = infoPtr->nIndent;
1368 if (btnPtr[i].fsStyle & BTNS_SEP )
1369 bButtonWrap = FALSE;
1370 else
1371 bButtonWrap = TRUE;
1374 else {
1375 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1376 i, btnPtr[i].fsStyle, x, cx);
1377 x += cx;
1383 /***********************************************************************
1384 * TOOLBAR_CalcToolbar
1386 * This function calculates button and separator placement. It first
1387 * calculates the button sizes, gets the toolbar window width and then
1388 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1389 * on. It assigns a new location to each item and sends this location to
1390 * the tooltip window if appropriate. Finally, it updates the rcBound
1391 * rect and calculates the new required toolbar window height.
1394 static void
1395 TOOLBAR_CalcToolbar (HWND hwnd)
1397 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1398 DWORD dwStyle = infoPtr->dwStyle;
1399 TBUTTON_INFO *btnPtr;
1400 INT i, nRows, nSepRows;
1401 INT x, y, cx, cy;
1402 SIZE sizeString;
1403 BOOL bWrap;
1404 BOOL usesBitmaps = FALSE;
1405 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1407 TOOLBAR_CalcStrings (hwnd, &sizeString);
1409 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1411 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1413 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1414 usesBitmaps = TRUE;
1416 if (dwStyle & TBSTYLE_LIST)
1418 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1419 0, sizeString.cy) + infoPtr->szPadding.cy;
1420 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1421 LIST_IMAGE_ABSENT_WIDTH) + sizeString.cx + infoPtr->szPadding.cx;
1422 if (sizeString.cx > 0)
1423 infoPtr->nButtonWidth += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1424 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1425 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1426 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1428 else {
1429 if (sizeString.cy > 0)
1431 if (usesBitmaps)
1432 infoPtr->nButtonHeight = sizeString.cy +
1433 infoPtr->szPadding.cy/2 + /* this is the space to separate text from bitmap */
1434 infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1435 else
1436 infoPtr->nButtonHeight = sizeString.cy + infoPtr->szPadding.cy;
1438 else
1439 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1441 if (sizeString.cx > infoPtr->nBitmapWidth)
1442 infoPtr->nButtonWidth = sizeString.cx + infoPtr->szPadding.cx;
1443 else
1444 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + infoPtr->szPadding.cx;
1447 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1448 infoPtr->nButtonWidth = infoPtr->cxMin;
1449 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1450 infoPtr->nButtonWidth = infoPtr->cxMax;
1452 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1454 x = infoPtr->nIndent;
1455 y = 0;
1457 /* from above, minimum is a button, and possible text */
1458 cx = infoPtr->nButtonWidth;
1460 /* cannot use just ButtonHeight, we may have no buttons! */
1461 if (infoPtr->nNumButtons > 0)
1462 infoPtr->nHeight = infoPtr->nButtonHeight;
1464 cy = infoPtr->nHeight;
1466 nRows = nSepRows = 0;
1468 infoPtr->rcBound.top = y;
1469 infoPtr->rcBound.left = x;
1470 infoPtr->rcBound.bottom = y + cy;
1471 infoPtr->rcBound.right = x;
1473 btnPtr = infoPtr->buttons;
1475 TRACE("cy=%d\n", cy);
1477 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1479 bWrap = FALSE;
1480 if (btnPtr->fsState & TBSTATE_HIDDEN)
1482 SetRectEmpty (&btnPtr->rect);
1483 continue;
1486 cy = infoPtr->nHeight;
1488 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1489 /* it is the actual width of the separator. This is used for */
1490 /* custom controls in toolbars. */
1491 if (btnPtr->fsStyle & BTNS_SEP) {
1492 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1493 cy = (btnPtr->iBitmap > 0) ?
1494 btnPtr->iBitmap : SEPARATOR_WIDTH;
1495 cx = infoPtr->nButtonWidth;
1497 else
1498 cx = (btnPtr->iBitmap > 0) ?
1499 btnPtr->iBitmap : SEPARATOR_WIDTH;
1501 else
1503 if (btnPtr->cx)
1504 cx = btnPtr->cx;
1505 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1506 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1508 SIZE sz;
1509 HDC hdc;
1510 HFONT hOldFont;
1512 hdc = GetDC (hwnd);
1513 hOldFont = SelectObject (hdc, infoPtr->hFont);
1515 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1517 SelectObject (hdc, hOldFont);
1518 ReleaseDC (hwnd, hdc);
1520 /* add space on for button frame, etc */
1521 cx = sz.cx + infoPtr->szPadding.cx;
1523 /* add list padding */
1524 if ((dwStyle & TBSTYLE_LIST) && sz.cx > 0)
1525 cx += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1527 if (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))
1529 if (dwStyle & TBSTYLE_LIST)
1530 cx += infoPtr->nBitmapWidth;
1531 else if (cx < (infoPtr->nBitmapWidth+infoPtr->szPadding.cx))
1532 cx = infoPtr->nBitmapWidth+infoPtr->szPadding.cx;
1534 else if (dwStyle & TBSTYLE_LIST)
1535 cx += LIST_IMAGE_ABSENT_WIDTH;
1537 else
1538 cx = infoPtr->nButtonWidth;
1540 /* if size has been set manually then don't add on extra space
1541 * for the drop down arrow */
1542 if (!btnPtr->cx && hasDropDownArrows &&
1543 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1544 cx += DDARROW_WIDTH;
1546 if (btnPtr->fsState & TBSTATE_WRAP )
1547 bWrap = TRUE;
1549 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1551 if (infoPtr->rcBound.left > x)
1552 infoPtr->rcBound.left = x;
1553 if (infoPtr->rcBound.right < x + cx)
1554 infoPtr->rcBound.right = x + cx;
1555 if (infoPtr->rcBound.bottom < y + cy)
1556 infoPtr->rcBound.bottom = y + cy;
1558 /* Set the toolTip only for non-hidden, non-separator button */
1559 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1561 TTTOOLINFOA ti;
1563 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1564 ti.cbSize = sizeof(TTTOOLINFOA);
1565 ti.hwnd = hwnd;
1566 ti.uId = btnPtr->idCommand;
1567 ti.rect = btnPtr->rect;
1568 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1569 0, (LPARAM)&ti);
1572 /* btnPtr->nRow is zero based. The space between the rows is */
1573 /* also considered as a row. */
1574 btnPtr->nRow = nRows + nSepRows;
1576 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1577 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1578 x, y, x+cx, y+cy);
1580 if( bWrap )
1582 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1583 y += cy;
1584 else
1586 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1587 /* it is the actual width of the separator. This is used for */
1588 /* custom controls in toolbars. */
1589 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1590 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1591 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1592 else
1593 y += cy;
1595 /* nSepRows is used to calculate the extra height follwoing */
1596 /* the last row. */
1597 nSepRows++;
1599 x = infoPtr->nIndent;
1601 /* Increment row number unless this is the last button */
1602 /* and it has Wrap set. */
1603 if (i != infoPtr->nNumButtons-1)
1604 nRows++;
1606 else
1607 x += cx;
1610 /* infoPtr->nRows is the number of rows on the toolbar */
1611 infoPtr->nRows = nRows + nSepRows + 1;
1613 #if 0
1614 /********************************************************************
1615 * The following while interesting, does not match the values *
1616 * created above for the button rectangles, nor the rcBound rect. *
1617 * We will comment it out and remove it later. *
1619 * The problem showed up as heights in the pager control that was *
1620 * wrong. *
1621 ********************************************************************/
1623 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1624 /* the last row. */
1625 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1626 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1627 nSepRows * (infoPtr->nBitmapHeight + 1) +
1628 BOTTOM_BORDER;
1629 #endif
1631 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1633 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1637 static INT
1638 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1640 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1641 TBUTTON_INFO *btnPtr;
1642 INT i;
1644 btnPtr = infoPtr->buttons;
1645 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1646 if (btnPtr->fsState & TBSTATE_HIDDEN)
1647 continue;
1649 if (btnPtr->fsStyle & BTNS_SEP) {
1650 if (PtInRect (&btnPtr->rect, *lpPt)) {
1651 TRACE(" ON SEPARATOR %d!\n", i);
1652 return -i;
1655 else {
1656 if (PtInRect (&btnPtr->rect, *lpPt)) {
1657 TRACE(" ON BUTTON %d!\n", i);
1658 return i;
1663 TRACE(" NOWHERE!\n");
1664 return -1;
1668 static INT
1669 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1671 TBUTTON_INFO *btnPtr;
1672 INT i;
1674 if (CommandIsIndex) {
1675 TRACE("command is really index command=%d\n", idCommand);
1676 if (idCommand >= infoPtr->nNumButtons) return -1;
1677 return idCommand;
1679 btnPtr = infoPtr->buttons;
1680 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1681 if (btnPtr->idCommand == idCommand) {
1682 TRACE("command=%d index=%d\n", idCommand, i);
1683 return i;
1686 TRACE("no index found for command=%d\n", idCommand);
1687 return -1;
1691 static INT
1692 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1694 TBUTTON_INFO *btnPtr;
1695 INT nRunIndex;
1697 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1698 return -1;
1700 /* check index button */
1701 btnPtr = &infoPtr->buttons[nIndex];
1702 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1703 if (btnPtr->fsState & TBSTATE_CHECKED)
1704 return nIndex;
1707 /* check previous buttons */
1708 nRunIndex = nIndex - 1;
1709 while (nRunIndex >= 0) {
1710 btnPtr = &infoPtr->buttons[nRunIndex];
1711 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1712 if (btnPtr->fsState & TBSTATE_CHECKED)
1713 return nRunIndex;
1715 else
1716 break;
1717 nRunIndex--;
1720 /* check next buttons */
1721 nRunIndex = nIndex + 1;
1722 while (nRunIndex < infoPtr->nNumButtons) {
1723 btnPtr = &infoPtr->buttons[nRunIndex];
1724 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1725 if (btnPtr->fsState & TBSTATE_CHECKED)
1726 return nRunIndex;
1728 else
1729 break;
1730 nRunIndex++;
1733 return -1;
1737 static VOID
1738 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1739 WPARAM wParam, LPARAM lParam)
1741 MSG msg;
1743 msg.hwnd = hwndMsg;
1744 msg.message = uMsg;
1745 msg.wParam = wParam;
1746 msg.lParam = lParam;
1747 msg.time = GetMessageTime ();
1748 msg.pt.x = LOWORD(GetMessagePos ());
1749 msg.pt.y = HIWORD(GetMessagePos ());
1751 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1755 /***********************************************************************
1756 * TOOLBAR_CustomizeDialogProc
1757 * This function implements the toolbar customization dialog.
1759 static INT_PTR CALLBACK
1760 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1762 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
1763 PCUSTOMBUTTON btnInfo;
1764 NMTOOLBARA nmtb;
1765 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1767 switch (uMsg)
1769 case WM_INITDIALOG:
1770 custInfo = (PCUSTDLG_INFO)lParam;
1771 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
1773 if (custInfo)
1775 WCHAR Buffer[256];
1776 int i = 0;
1777 int index;
1779 infoPtr = custInfo->tbInfo;
1781 /* send TBN_QUERYINSERT notification */
1782 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1784 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1785 return FALSE;
1787 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
1788 nmtb.iItem = (int)hwnd;
1789 /* Send TBN_INITCUSTOMIZE notification */
1790 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
1791 TBNRF_HIDEHELP)
1793 TRACE("TBNRF_HIDEHELP requested\n");
1794 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
1797 /* add items to 'toolbar buttons' list and check if removable */
1798 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1800 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1801 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1802 btnInfo->btn.fsStyle = BTNS_SEP;
1803 btnInfo->bVirtual = FALSE;
1804 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1806 /* send TBN_QUERYDELETE notification */
1807 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
1809 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1810 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1813 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
1815 /* insert separator button into 'available buttons' list */
1816 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1817 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1818 btnInfo->btn.fsStyle = BTNS_SEP;
1819 btnInfo->bVirtual = FALSE;
1820 btnInfo->bRemovable = TRUE;
1821 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1822 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1823 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1825 /* insert all buttons into dsa */
1826 for (i = 0;; i++)
1828 /* send TBN_GETBUTTONINFO notification */
1829 NMTOOLBARW nmtb;
1830 nmtb.iItem = i;
1831 nmtb.pszText = Buffer;
1832 nmtb.cchText = 256;
1834 /* Clear previous button's text */
1835 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
1837 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
1838 break;
1840 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
1841 nmtb.tbButton.fsStyle, i,
1842 nmtb.tbButton.idCommand,
1843 nmtb.tbButton.iString,
1844 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
1845 : "");
1847 /* insert button into the apropriate list */
1848 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1849 if (index == -1)
1851 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1852 btnInfo->bVirtual = FALSE;
1853 btnInfo->bRemovable = TRUE;
1855 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1856 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX,
1857 LB_SETITEMDATA, index, (LPARAM)btnInfo);
1859 else
1861 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd,
1862 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1865 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1866 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
1868 if (lstrlenW(nmtb.pszText))
1869 lstrcpyW(btnInfo->text, nmtb.pszText);
1870 else if (nmtb.tbButton.iString >= 0 &&
1871 nmtb.tbButton.iString < infoPtr->nNumStrings)
1873 lstrcpyW(btnInfo->text,
1874 infoPtr->strings[nmtb.tbButton.iString]);
1879 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
1881 /* select first item in the 'available' list */
1882 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1884 /* append 'virtual' separator button to the 'toolbar buttons' list */
1885 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1886 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1887 btnInfo->btn.fsStyle = BTNS_SEP;
1888 btnInfo->bVirtual = TRUE;
1889 btnInfo->bRemovable = FALSE;
1890 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1891 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1892 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1894 /* select last item in the 'toolbar' list */
1895 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1896 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1898 /* set focus and disable buttons */
1899 PostMessageA (hwnd, WM_USER, 0, 0);
1901 return TRUE;
1903 case WM_USER:
1904 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1905 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1906 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1907 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1908 return TRUE;
1910 case WM_CLOSE:
1911 EndDialog(hwnd, FALSE);
1912 return TRUE;
1914 case WM_COMMAND:
1915 switch (LOWORD(wParam))
1917 case IDC_TOOLBARBTN_LBOX:
1918 if (HIWORD(wParam) == LBN_SELCHANGE)
1920 PCUSTOMBUTTON btnInfo;
1921 NMTOOLBARA nmtb;
1922 int count;
1923 int index;
1925 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1926 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1928 /* send TBN_QUERYINSERT notification */
1929 nmtb.iItem = index;
1930 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1931 TBN_QUERYINSERT);
1933 /* get list box item */
1934 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1936 if (index == (count - 1))
1938 /* last item (virtual separator) */
1939 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1940 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1942 else if (index == (count - 2))
1944 /* second last item (last non-virtual item) */
1945 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1946 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1948 else if (index == 0)
1950 /* first item */
1951 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1952 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1954 else
1956 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1957 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1960 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1962 break;
1964 case IDC_MOVEUP_BTN:
1966 PCUSTOMBUTTON btnInfo;
1967 int index;
1968 int count;
1970 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1971 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1972 TRACE("Move up: index %d\n", index);
1974 /* send TBN_QUERYINSERT notification */
1975 nmtb.iItem = index;
1977 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1978 TBN_QUERYINSERT))
1980 NMHDR hdr;
1982 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1984 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1985 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1986 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1987 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1989 if (index <= 1)
1990 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1991 else if (index >= (count - 3))
1992 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1994 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1995 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1997 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2000 break;
2002 case IDC_MOVEDN_BTN: /* move down */
2004 PCUSTOMBUTTON btnInfo;
2005 int index;
2006 int count;
2008 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2009 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2010 TRACE("Move up: index %d\n", index);
2012 /* send TBN_QUERYINSERT notification */
2013 nmtb.iItem = index;
2014 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2015 TBN_QUERYINSERT))
2017 NMHDR hdr;
2019 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2021 /* move button down */
2022 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2023 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
2024 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
2025 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
2027 if (index == 0)
2028 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2029 else if (index >= (count - 3))
2030 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2032 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2033 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
2035 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2038 break;
2040 case IDC_REMOVE_BTN: /* remove button */
2042 PCUSTOMBUTTON btnInfo;
2043 int index;
2045 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2047 if (LB_ERR == index)
2048 break;
2050 TRACE("Remove: index %d\n", index);
2052 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX,
2053 LB_GETITEMDATA, index, 0);
2055 /* send TBN_QUERYDELETE notification */
2056 if (TOOLBAR_IsButtonRemovable(infoPtr, index, btnInfo))
2058 NMHDR hdr;
2060 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2061 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2062 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
2064 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2066 /* insert into 'available button' list */
2067 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2069 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
2070 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2072 else
2073 Free (btnInfo);
2075 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2078 break;
2079 case IDC_HELP_BTN:
2080 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2081 break;
2082 case IDC_RESET_BTN:
2083 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2084 break;
2086 case IDOK: /* Add button */
2088 int index;
2089 int count;
2091 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2092 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2093 TRACE("Add: index %d\n", index);
2095 /* send TBN_QUERYINSERT notification */
2096 nmtb.iItem = index;
2097 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2098 TBN_QUERYINSERT))
2100 NMHDR hdr;
2102 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
2104 if (index != 0)
2106 /* remove from 'available buttons' list */
2107 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
2108 if (index == count-1)
2109 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2110 else
2111 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
2113 else
2115 PCUSTOMBUTTON btnNew;
2117 /* duplicate 'separator' button */
2118 btnNew = (PCUSTOMBUTTON)Alloc (sizeof(CUSTOMBUTTON));
2119 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2120 btnInfo = btnNew;
2123 /* insert into 'toolbar button' list */
2124 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2125 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
2126 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2128 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
2130 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2133 break;
2135 case IDCANCEL:
2136 EndDialog(hwnd, FALSE);
2137 break;
2139 return TRUE;
2141 case WM_DESTROY:
2143 int count;
2144 int i;
2146 /* delete items from 'toolbar buttons' listbox*/
2147 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2148 for (i = 0; i < count; i++)
2150 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2151 Free(btnInfo);
2152 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2154 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2157 /* delete items from 'available buttons' listbox*/
2158 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2159 for (i = 0; i < count; i++)
2161 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2162 Free(btnInfo);
2163 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2165 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2167 return TRUE;
2169 case WM_DRAWITEM:
2170 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2172 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2173 RECT rcButton;
2174 RECT rcText;
2175 HPEN hPen, hOldPen;
2176 HBRUSH hOldBrush;
2177 COLORREF oldText = 0;
2178 COLORREF oldBk = 0;
2180 /* get item data */
2181 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2182 if (btnInfo == NULL)
2184 FIXME("btnInfo invalid!\n");
2185 return TRUE;
2188 /* set colors and select objects */
2189 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2190 if (btnInfo->bVirtual)
2191 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2192 else
2193 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2194 hPen = CreatePen( PS_SOLID, 1,
2195 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2196 hOldPen = SelectObject (lpdis->hDC, hPen );
2197 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2199 /* fill background rectangle */
2200 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2201 lpdis->rcItem.right, lpdis->rcItem.bottom);
2203 /* calculate button and text rectangles */
2204 CopyRect (&rcButton, &lpdis->rcItem);
2205 InflateRect (&rcButton, -1, -1);
2206 CopyRect (&rcText, &rcButton);
2207 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2208 rcText.left = rcButton.right + 2;
2210 /* draw focus rectangle */
2211 if (lpdis->itemState & ODS_FOCUS)
2212 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2214 /* draw button */
2215 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2216 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2218 /* draw image and text */
2219 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2220 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2221 btnInfo->btn.iBitmap));
2222 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2223 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2225 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2226 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2228 /* delete objects and reset colors */
2229 SelectObject (lpdis->hDC, hOldBrush);
2230 SelectObject (lpdis->hDC, hOldPen);
2231 SetBkColor (lpdis->hDC, oldBk);
2232 SetTextColor (lpdis->hDC, oldText);
2233 DeleteObject( hPen );
2234 return TRUE;
2236 return FALSE;
2238 case WM_MEASUREITEM:
2239 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2241 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2243 lpmis->itemHeight = 15 + 8; /* default height */
2245 return TRUE;
2247 return FALSE;
2249 default:
2250 return FALSE;
2255 /***********************************************************************
2256 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2259 static LRESULT
2260 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2262 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2263 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2264 INT nIndex = 0, nButtons, nCount;
2265 HBITMAP hbmLoad;
2266 HIMAGELIST himlDef;
2268 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2269 if (!lpAddBmp)
2270 return -1;
2272 if (lpAddBmp->hInst == HINST_COMMCTRL)
2274 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2275 nButtons = 15;
2276 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2277 nButtons = 13;
2278 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2279 nButtons = 5;
2280 else
2281 return -1;
2283 TRACE ("adding %d internal bitmaps!\n", nButtons);
2285 /* Windows resize all the buttons to the size of a newly added standard image */
2286 if (lpAddBmp->nID & 1)
2288 /* large icons */
2289 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2290 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2292 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2293 MAKELPARAM((WORD)24, (WORD)24));
2294 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2295 MAKELPARAM((WORD)31, (WORD)30));
2297 else
2299 /* small icons */
2300 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2301 MAKELPARAM((WORD)16, (WORD)16));
2302 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2303 MAKELPARAM((WORD)22, (WORD)22));
2306 TOOLBAR_CalcToolbar (hwnd);
2308 else
2310 nButtons = (INT)wParam;
2311 if (nButtons <= 0)
2312 return -1;
2314 TRACE ("adding %d bitmaps!\n", nButtons);
2317 if (!infoPtr->cimlDef) {
2318 /* create new default image list */
2319 TRACE ("creating default image list!\n");
2321 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2322 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2323 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2324 infoPtr->himlInt = himlDef;
2326 else {
2327 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2330 if (!himlDef) {
2331 WARN("No default image list available\n");
2332 return -1;
2335 nCount = ImageList_GetImageCount(himlDef);
2337 /* Add bitmaps to the default image list */
2338 if (lpAddBmp->hInst == NULL)
2340 BITMAP bmp;
2341 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2342 HDC hdcImage, hdcBitmap;
2344 /* copy the bitmap before adding it so that the user's bitmap
2345 * doesn't get modified.
2347 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2349 hdcImage = CreateCompatibleDC(0);
2350 hdcBitmap = CreateCompatibleDC(0);
2352 /* create new bitmap */
2353 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2354 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2355 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2357 /* Copy the user's image */
2358 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2359 hdcBitmap, 0, 0, SRCCOPY);
2361 SelectObject (hdcImage, hOldBitmapLoad);
2362 SelectObject (hdcBitmap, hOldBitmapBitmap);
2363 DeleteDC (hdcImage);
2364 DeleteDC (hdcBitmap);
2366 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2367 DeleteObject (hbmLoad);
2369 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2371 /* Add system bitmaps */
2372 switch (lpAddBmp->nID)
2374 case IDB_STD_SMALL_COLOR:
2375 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2376 MAKEINTRESOURCEA(IDB_STD_SMALL));
2377 nIndex = ImageList_AddMasked (himlDef,
2378 hbmLoad, comctl32_color.clrBtnFace);
2379 DeleteObject (hbmLoad);
2380 break;
2382 case IDB_STD_LARGE_COLOR:
2383 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2384 MAKEINTRESOURCEA(IDB_STD_LARGE));
2385 nIndex = ImageList_AddMasked (himlDef,
2386 hbmLoad, comctl32_color.clrBtnFace);
2387 DeleteObject (hbmLoad);
2388 break;
2390 case IDB_VIEW_SMALL_COLOR:
2391 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2392 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2393 nIndex = ImageList_AddMasked (himlDef,
2394 hbmLoad, comctl32_color.clrBtnFace);
2395 DeleteObject (hbmLoad);
2396 break;
2398 case IDB_VIEW_LARGE_COLOR:
2399 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2400 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2401 nIndex = ImageList_AddMasked (himlDef,
2402 hbmLoad, comctl32_color.clrBtnFace);
2403 DeleteObject (hbmLoad);
2404 break;
2406 case IDB_HIST_SMALL_COLOR:
2407 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2408 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2409 nIndex = ImageList_AddMasked (himlDef,
2410 hbmLoad, comctl32_color.clrBtnFace);
2411 DeleteObject (hbmLoad);
2412 break;
2414 case IDB_HIST_LARGE_COLOR:
2415 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2416 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2417 nIndex = ImageList_AddMasked (himlDef,
2418 hbmLoad, comctl32_color.clrBtnFace);
2419 DeleteObject (hbmLoad);
2420 break;
2422 default:
2423 nIndex = ImageList_GetImageCount (himlDef);
2424 ERR ("invalid imagelist!\n");
2425 break;
2428 else
2430 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2431 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2432 DeleteObject (hbmLoad);
2435 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2437 if (infoPtr->nNumBitmapInfos == 0)
2439 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2441 else
2443 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2444 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2445 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2448 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2449 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2450 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2452 infoPtr->nNumBitmapInfos++;
2453 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2455 if (nIndex != -1)
2457 INT imagecount = ImageList_GetImageCount(himlDef);
2459 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2461 WARN("Desired images do not match received images : Previous image number %i Previous images in list %i added %i expecting total %i, Images in list %i\n",
2462 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2463 infoPtr->nNumBitmaps+nButtons,imagecount);
2465 infoPtr->nNumBitmaps = imagecount;
2467 else
2468 infoPtr->nNumBitmaps += nButtons;
2471 InvalidateRect(hwnd, NULL, TRUE);
2473 return nIndex;
2477 static LRESULT
2478 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2480 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2481 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2482 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2484 TRACE("adding %d buttons!\n", wParam);
2486 nAddButtons = (UINT)wParam;
2487 nOldButtons = infoPtr->nNumButtons;
2488 nNewButtons = nOldButtons + nAddButtons;
2490 if (infoPtr->nNumButtons == 0) {
2491 infoPtr->buttons =
2492 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2494 else {
2495 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2496 infoPtr->buttons =
2497 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2498 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2499 nOldButtons * sizeof(TBUTTON_INFO));
2500 Free (oldButtons);
2503 infoPtr->nNumButtons = nNewButtons;
2505 /* insert new button data */
2506 for (nCount = 0; nCount < nAddButtons; nCount++) {
2507 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2508 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2509 btnPtr->idCommand = lpTbb[nCount].idCommand;
2510 btnPtr->fsState = lpTbb[nCount].fsState;
2511 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2512 btnPtr->dwData = lpTbb[nCount].dwData;
2513 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2514 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2515 else
2516 btnPtr->iString = lpTbb[nCount].iString;
2517 btnPtr->bHot = FALSE;
2519 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2520 TTTOOLINFOA ti;
2522 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2523 ti.cbSize = sizeof (TTTOOLINFOA);
2524 ti.hwnd = hwnd;
2525 ti.uId = btnPtr->idCommand;
2526 ti.hinst = 0;
2527 ti.lpszText = LPSTR_TEXTCALLBACKA;
2529 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2530 0, (LPARAM)&ti);
2534 TOOLBAR_CalcToolbar (hwnd);
2536 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2538 InvalidateRect(hwnd, NULL, TRUE);
2540 return TRUE;
2544 static LRESULT
2545 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2547 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2548 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2549 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2551 TRACE("adding %d buttons!\n", wParam);
2553 nAddButtons = (UINT)wParam;
2554 nOldButtons = infoPtr->nNumButtons;
2555 nNewButtons = nOldButtons + nAddButtons;
2557 if (infoPtr->nNumButtons == 0) {
2558 infoPtr->buttons =
2559 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2561 else {
2562 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2563 infoPtr->buttons =
2564 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2565 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2566 nOldButtons * sizeof(TBUTTON_INFO));
2567 Free (oldButtons);
2570 infoPtr->nNumButtons = nNewButtons;
2572 /* insert new button data */
2573 for (nCount = 0; nCount < nAddButtons; nCount++) {
2574 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2575 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2576 btnPtr->idCommand = lpTbb[nCount].idCommand;
2577 btnPtr->fsState = lpTbb[nCount].fsState;
2578 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2579 btnPtr->dwData = lpTbb[nCount].dwData;
2580 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2581 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2582 else
2583 btnPtr->iString = lpTbb[nCount].iString;
2584 btnPtr->bHot = FALSE;
2586 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2587 TTTOOLINFOW ti;
2589 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2590 ti.cbSize = sizeof (TTTOOLINFOW);
2591 ti.hwnd = hwnd;
2592 ti.uId = btnPtr->idCommand;
2593 ti.hinst = 0;
2594 ti.lpszText = LPSTR_TEXTCALLBACKW;
2595 ti.lParam = lParam;
2597 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2598 0, (LPARAM)&ti);
2602 TOOLBAR_CalcToolbar (hwnd);
2604 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2606 InvalidateRect(hwnd, NULL, TRUE);
2608 return TRUE;
2612 static LRESULT
2613 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2615 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2616 INT nIndex;
2618 if ((wParam) && (HIWORD(lParam) == 0)) {
2619 char szString[256];
2620 INT len;
2621 TRACE("adding string from resource!\n");
2623 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2624 szString, 256);
2626 TRACE("len=%d \"%s\"\n", len, szString);
2627 nIndex = infoPtr->nNumStrings;
2628 if (infoPtr->nNumStrings == 0) {
2629 infoPtr->strings =
2630 Alloc (sizeof(LPWSTR));
2632 else {
2633 LPWSTR *oldStrings = infoPtr->strings;
2634 infoPtr->strings =
2635 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2636 memcpy (&infoPtr->strings[0], &oldStrings[0],
2637 sizeof(LPWSTR) * infoPtr->nNumStrings);
2638 Free (oldStrings);
2641 /*Alloc zeros out the allocated memory*/
2642 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2643 infoPtr->nNumStrings++;
2645 else {
2646 LPSTR p = (LPSTR)lParam;
2647 INT len;
2649 if (p == NULL)
2650 return -1;
2651 TRACE("adding string(s) from array!\n");
2653 nIndex = infoPtr->nNumStrings;
2654 while (*p) {
2655 len = strlen (p);
2656 TRACE("len=%d \"%s\"\n", len, p);
2658 if (infoPtr->nNumStrings == 0) {
2659 infoPtr->strings =
2660 Alloc (sizeof(LPWSTR));
2662 else {
2663 LPWSTR *oldStrings = infoPtr->strings;
2664 infoPtr->strings =
2665 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2666 memcpy (&infoPtr->strings[0], &oldStrings[0],
2667 sizeof(LPWSTR) * infoPtr->nNumStrings);
2668 Free (oldStrings);
2671 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2672 infoPtr->nNumStrings++;
2674 p += (len+1);
2678 return nIndex;
2682 static LRESULT
2683 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2685 #define MAX_RESOURCE_STRING_LENGTH 512
2686 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2687 INT nIndex;
2689 if ((wParam) && (HIWORD(lParam) == 0)) {
2690 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2691 INT len;
2692 TRACE("adding string from resource!\n");
2694 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2695 szString, MAX_RESOURCE_STRING_LENGTH);
2697 TRACE("len=%d %s\n", len, debugstr_w(szString));
2698 TRACE("First char: 0x%x\n", *szString);
2699 if (szString[0] == L'|')
2701 PWSTR p = szString + 1;
2703 nIndex = infoPtr->nNumStrings;
2704 while (*p != L'|' && *p != L'\0') {
2705 PWSTR np;
2707 if (infoPtr->nNumStrings == 0) {
2708 infoPtr->strings = Alloc (sizeof(LPWSTR));
2710 else
2712 LPWSTR *oldStrings = infoPtr->strings;
2713 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2714 memcpy(&infoPtr->strings[0], &oldStrings[0],
2715 sizeof(LPWSTR) * infoPtr->nNumStrings);
2716 Free(oldStrings);
2719 np=strchrW (p, '|');
2720 if (np!=NULL) {
2721 len = np - p;
2722 np++;
2723 } else {
2724 len = strlenW(p);
2725 np = p + len;
2727 TRACE("len=%d %s\n", len, debugstr_w(p));
2728 infoPtr->strings[infoPtr->nNumStrings] =
2729 Alloc (sizeof(WCHAR)*(len+1));
2730 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2731 infoPtr->nNumStrings++;
2733 p = np;
2736 else
2738 nIndex = infoPtr->nNumStrings;
2739 if (infoPtr->nNumStrings == 0) {
2740 infoPtr->strings =
2741 Alloc (sizeof(LPWSTR));
2743 else {
2744 LPWSTR *oldStrings = infoPtr->strings;
2745 infoPtr->strings =
2746 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2747 memcpy (&infoPtr->strings[0], &oldStrings[0],
2748 sizeof(LPWSTR) * infoPtr->nNumStrings);
2749 Free (oldStrings);
2752 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2753 infoPtr->nNumStrings++;
2756 else {
2757 LPWSTR p = (LPWSTR)lParam;
2758 INT len;
2760 if (p == NULL)
2761 return -1;
2762 TRACE("adding string(s) from array!\n");
2763 nIndex = infoPtr->nNumStrings;
2764 while (*p) {
2765 len = strlenW (p);
2767 TRACE("len=%d %s\n", len, debugstr_w(p));
2768 if (infoPtr->nNumStrings == 0) {
2769 infoPtr->strings =
2770 Alloc (sizeof(LPWSTR));
2772 else {
2773 LPWSTR *oldStrings = infoPtr->strings;
2774 infoPtr->strings =
2775 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2776 memcpy (&infoPtr->strings[0], &oldStrings[0],
2777 sizeof(LPWSTR) * infoPtr->nNumStrings);
2778 Free (oldStrings);
2781 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2782 infoPtr->nNumStrings++;
2784 p += (len+1);
2788 return nIndex;
2792 static LRESULT
2793 TOOLBAR_AutoSize (HWND hwnd)
2795 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2796 RECT parent_rect;
2797 RECT window_rect;
2798 HWND parent;
2799 INT x, y;
2800 INT cx, cy;
2801 UINT uPosFlags = SWP_NOZORDER;
2803 TRACE("resize forced, style=%lx!\n", infoPtr->dwStyle);
2805 parent = GetParent (hwnd);
2806 GetClientRect(parent, &parent_rect);
2808 x = parent_rect.left;
2809 y = parent_rect.top;
2811 /* FIXME: we should be able to early out if nothing */
2812 /* has changed with nWidth != parent_rect width */
2814 if (infoPtr->dwStyle & CCS_NORESIZE) {
2815 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2816 cx = 0;
2817 cy = 0;
2818 TOOLBAR_CalcToolbar (hwnd);
2820 else {
2821 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2822 TOOLBAR_CalcToolbar (hwnd);
2823 InvalidateRect( hwnd, NULL, TRUE );
2824 cy = infoPtr->nHeight;
2825 cx = infoPtr->nWidth;
2827 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
2828 GetWindowRect(hwnd, &window_rect);
2829 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2830 y = window_rect.top;
2832 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
2833 GetWindowRect(hwnd, &window_rect);
2834 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
2838 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
2839 uPosFlags |= SWP_NOMOVE;
2841 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
2842 cy += GetSystemMetrics(SM_CYEDGE);
2844 if (infoPtr->dwStyle & WS_BORDER)
2846 x = y = 1;
2847 cy += GetSystemMetrics(SM_CYEDGE);
2848 cx += GetSystemMetrics(SM_CYEDGE);
2851 infoPtr->bAutoSize = TRUE;
2852 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
2853 /* The following line makes sure that the infoPtr->bAutoSize is turned off
2854 * after the setwindowpos calls */
2855 infoPtr->bAutoSize = FALSE;
2857 return 0;
2861 static LRESULT
2862 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2864 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2866 return infoPtr->nNumButtons;
2870 static LRESULT
2871 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2873 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2875 if (infoPtr == NULL) {
2876 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2877 ERR("infoPtr == NULL!\n");
2878 return 0;
2881 infoPtr->dwStructSize = (DWORD)wParam;
2883 return 0;
2887 static LRESULT
2888 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2890 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2891 TBUTTON_INFO *btnPtr;
2892 INT nIndex;
2894 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
2896 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2897 if (nIndex == -1)
2898 return FALSE;
2900 btnPtr = &infoPtr->buttons[nIndex];
2901 btnPtr->iBitmap = LOWORD(lParam);
2903 /* we HAVE to erase the background, the new bitmap could be */
2904 /* transparent */
2905 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2907 return TRUE;
2911 static LRESULT
2912 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2914 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2915 TBUTTON_INFO *btnPtr;
2916 INT nIndex;
2917 INT nOldIndex = -1;
2918 BOOL bChecked = FALSE;
2920 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2922 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
2924 if (nIndex == -1)
2925 return FALSE;
2927 btnPtr = &infoPtr->buttons[nIndex];
2929 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2931 if (LOWORD(lParam) == FALSE)
2932 btnPtr->fsState &= ~TBSTATE_CHECKED;
2933 else {
2934 if (btnPtr->fsStyle & BTNS_GROUP) {
2935 nOldIndex =
2936 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2937 if (nOldIndex == nIndex)
2938 return 0;
2939 if (nOldIndex != -1)
2940 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2942 btnPtr->fsState |= TBSTATE_CHECKED;
2945 if( bChecked != LOWORD(lParam) )
2947 if (nOldIndex != -1)
2948 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
2949 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2952 /* FIXME: Send a WM_NOTIFY?? */
2954 return TRUE;
2958 static LRESULT
2959 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2961 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2963 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2967 static LRESULT
2968 TOOLBAR_Customize (HWND hwnd)
2970 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2971 CUSTDLG_INFO custInfo;
2972 LRESULT ret;
2973 LPCVOID template;
2974 HRSRC hRes;
2975 NMHDR nmhdr;
2977 custInfo.tbInfo = infoPtr;
2978 custInfo.tbHwnd = hwnd;
2980 /* send TBN_BEGINADJUST notification */
2981 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2982 TBN_BEGINADJUST);
2984 if (!(hRes = FindResourceA (COMCTL32_hModule,
2985 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2986 (LPSTR)RT_DIALOG)))
2987 return FALSE;
2989 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2990 return FALSE;
2992 ret = DialogBoxIndirectParamA ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
2993 (LPDLGTEMPLATEA)template,
2994 hwnd,
2995 TOOLBAR_CustomizeDialogProc,
2996 (LPARAM)&custInfo);
2998 /* send TBN_ENDADJUST notification */
2999 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
3000 TBN_ENDADJUST);
3002 return ret;
3006 static LRESULT
3007 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3009 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3010 INT nIndex = (INT)wParam;
3011 NMTOOLBARW nmtb;
3013 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3014 return FALSE;
3016 memset(&nmtb, 0, sizeof(nmtb));
3017 nmtb.iItem = nIndex;
3018 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_DELETINGBUTTON);
3020 if ((infoPtr->hwndToolTip) &&
3021 !(infoPtr->buttons[nIndex].fsStyle & BTNS_SEP)) {
3022 TTTOOLINFOA ti;
3024 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3025 ti.cbSize = sizeof (TTTOOLINFOA);
3026 ti.hwnd = hwnd;
3027 ti.uId = infoPtr->buttons[nIndex].idCommand;
3029 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
3032 if (infoPtr->nNumButtons == 1) {
3033 TRACE(" simple delete!\n");
3034 Free (infoPtr->buttons);
3035 infoPtr->buttons = NULL;
3036 infoPtr->nNumButtons = 0;
3038 else {
3039 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3040 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3042 infoPtr->nNumButtons--;
3043 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3044 if (nIndex > 0) {
3045 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3046 nIndex * sizeof(TBUTTON_INFO));
3049 if (nIndex < infoPtr->nNumButtons) {
3050 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3051 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3054 Free (oldButtons);
3057 TOOLBAR_CalcToolbar (hwnd);
3059 InvalidateRect (hwnd, NULL, TRUE);
3061 return TRUE;
3065 static LRESULT
3066 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3068 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3069 TBUTTON_INFO *btnPtr;
3070 INT nIndex;
3071 DWORD bState;
3073 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3075 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3077 if (nIndex == -1)
3078 return FALSE;
3080 btnPtr = &infoPtr->buttons[nIndex];
3082 bState = btnPtr->fsState & TBSTATE_ENABLED;
3084 /* update the toolbar button state */
3085 if(LOWORD(lParam) == FALSE) {
3086 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3087 } else {
3088 btnPtr->fsState |= TBSTATE_ENABLED;
3091 /* redraw the button only if the state of the button changed */
3092 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3093 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3095 return TRUE;
3099 static inline LRESULT
3100 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3102 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3104 return infoPtr->bAnchor;
3108 static LRESULT
3109 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3111 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3112 INT nIndex;
3114 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3115 if (nIndex == -1)
3116 return -1;
3118 return infoPtr->buttons[nIndex].iBitmap;
3122 static inline LRESULT
3123 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3125 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3129 static LRESULT
3130 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3132 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3133 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3134 INT nIndex = (INT)wParam;
3135 TBUTTON_INFO *btnPtr;
3137 if (infoPtr == NULL)
3138 return FALSE;
3140 if (lpTbb == NULL)
3141 return FALSE;
3143 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3144 return FALSE;
3146 btnPtr = &infoPtr->buttons[nIndex];
3147 lpTbb->iBitmap = btnPtr->iBitmap;
3148 lpTbb->idCommand = btnPtr->idCommand;
3149 lpTbb->fsState = btnPtr->fsState;
3150 lpTbb->fsStyle = btnPtr->fsStyle;
3151 lpTbb->bReserved[0] = 0;
3152 lpTbb->bReserved[1] = 0;
3153 lpTbb->dwData = btnPtr->dwData;
3154 lpTbb->iString = btnPtr->iString;
3156 return TRUE;
3160 static LRESULT
3161 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3163 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3164 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3165 TBUTTON_INFO *btnPtr;
3166 INT nIndex;
3168 if (infoPtr == NULL)
3169 return -1;
3170 if (lpTbInfo == NULL)
3171 return -1;
3172 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3173 return -1;
3175 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3176 lpTbInfo->dwMask & 0x80000000);
3177 if (nIndex == -1)
3178 return -1;
3180 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3182 if (lpTbInfo->dwMask & TBIF_COMMAND)
3183 lpTbInfo->idCommand = btnPtr->idCommand;
3184 if (lpTbInfo->dwMask & TBIF_IMAGE)
3185 lpTbInfo->iImage = btnPtr->iBitmap;
3186 if (lpTbInfo->dwMask & TBIF_LPARAM)
3187 lpTbInfo->lParam = btnPtr->dwData;
3188 if (lpTbInfo->dwMask & TBIF_SIZE)
3189 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3190 if (lpTbInfo->dwMask & TBIF_STATE)
3191 lpTbInfo->fsState = btnPtr->fsState;
3192 if (lpTbInfo->dwMask & TBIF_STYLE)
3193 lpTbInfo->fsStyle = btnPtr->fsStyle;
3194 if (lpTbInfo->dwMask & TBIF_TEXT) {
3195 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3196 can't use TOOLBAR_GetText here */
3197 LPWSTR lpText;
3198 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3199 lpText = (LPWSTR)btnPtr->iString;
3200 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3201 } else
3202 lpTbInfo->pszText[0] = '\0';
3204 return nIndex;
3208 static LRESULT
3209 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3211 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3212 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3213 TBUTTON_INFO *btnPtr;
3214 INT nIndex;
3216 if (infoPtr == NULL)
3217 return -1;
3218 if (lpTbInfo == NULL)
3219 return -1;
3220 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3221 return -1;
3223 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3224 lpTbInfo->dwMask & 0x80000000);
3225 if (nIndex == -1)
3226 return -1;
3228 btnPtr = &infoPtr->buttons[nIndex];
3230 if(!btnPtr)
3231 return -1;
3233 if (lpTbInfo->dwMask & TBIF_COMMAND)
3234 lpTbInfo->idCommand = btnPtr->idCommand;
3235 if (lpTbInfo->dwMask & TBIF_IMAGE)
3236 lpTbInfo->iImage = btnPtr->iBitmap;
3237 if (lpTbInfo->dwMask & TBIF_LPARAM)
3238 lpTbInfo->lParam = btnPtr->dwData;
3239 if (lpTbInfo->dwMask & TBIF_SIZE)
3240 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3241 if (lpTbInfo->dwMask & TBIF_STATE)
3242 lpTbInfo->fsState = btnPtr->fsState;
3243 if (lpTbInfo->dwMask & TBIF_STYLE)
3244 lpTbInfo->fsStyle = btnPtr->fsStyle;
3245 if (lpTbInfo->dwMask & TBIF_TEXT) {
3246 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3247 can't use TOOLBAR_GetText here */
3248 LPWSTR lpText;
3249 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3250 lpText = (LPWSTR)btnPtr->iString;
3251 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3252 } else
3253 lpTbInfo->pszText[0] = '\0';
3256 return nIndex;
3260 static LRESULT
3261 TOOLBAR_GetButtonSize (HWND hwnd)
3263 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3265 if (infoPtr->nNumButtons > 0)
3266 return MAKELONG((WORD)infoPtr->nButtonWidth,
3267 (WORD)infoPtr->nButtonHeight);
3268 else
3269 return MAKELONG(8,7);
3273 static LRESULT
3274 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3276 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3277 INT nIndex;
3278 LPWSTR lpText;
3280 if (lParam == 0)
3281 return -1;
3283 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3284 if (nIndex == -1)
3285 return -1;
3287 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3289 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3290 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3294 static LRESULT
3295 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3297 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3298 INT nIndex;
3299 LPWSTR lpText;
3301 if (lParam == 0)
3302 return -1;
3304 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3305 if (nIndex == -1)
3306 return -1;
3308 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3310 strcpyW ((LPWSTR)lParam, lpText);
3312 return strlenW (lpText);
3316 static LRESULT
3317 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3319 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3320 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3321 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3325 inline static LRESULT
3326 TOOLBAR_GetExtendedStyle (HWND hwnd)
3328 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3330 TRACE("\n");
3332 return infoPtr->dwExStyle;
3336 static LRESULT
3337 TOOLBAR_GetHotImageList (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)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3345 static LRESULT
3346 TOOLBAR_GetHotItem (HWND hwnd)
3348 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3350 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
3351 return -1;
3353 if (infoPtr->nHotItem < 0)
3354 return -1;
3356 return (LRESULT)infoPtr->nHotItem;
3360 static LRESULT
3361 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3363 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3364 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3365 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3369 /* << TOOLBAR_GetInsertMark >> */
3370 /* << TOOLBAR_GetInsertMarkColor >> */
3373 static LRESULT
3374 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3376 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3377 TBUTTON_INFO *btnPtr;
3378 LPRECT lpRect;
3379 INT nIndex;
3381 if (infoPtr == NULL)
3382 return FALSE;
3383 nIndex = (INT)wParam;
3384 btnPtr = &infoPtr->buttons[nIndex];
3385 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3386 return FALSE;
3387 lpRect = (LPRECT)lParam;
3388 if (lpRect == NULL)
3389 return FALSE;
3390 if (btnPtr->fsState & TBSTATE_HIDDEN)
3391 return FALSE;
3393 lpRect->left = btnPtr->rect.left;
3394 lpRect->right = btnPtr->rect.right;
3395 lpRect->bottom = btnPtr->rect.bottom;
3396 lpRect->top = btnPtr->rect.top;
3398 return TRUE;
3402 static LRESULT
3403 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3405 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3406 LPSIZE lpSize = (LPSIZE)lParam;
3408 if (lpSize == NULL)
3409 return FALSE;
3411 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3412 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3414 TRACE("maximum size %ld x %ld\n",
3415 infoPtr->rcBound.right - infoPtr->rcBound.left,
3416 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3418 return TRUE;
3422 /* << TOOLBAR_GetObject >> */
3425 static LRESULT
3426 TOOLBAR_GetPadding (HWND hwnd)
3428 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3429 DWORD oldPad;
3431 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3432 return (LRESULT) oldPad;
3436 static LRESULT
3437 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3439 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3440 TBUTTON_INFO *btnPtr;
3441 LPRECT lpRect;
3442 INT nIndex;
3444 if (infoPtr == NULL)
3445 return FALSE;
3446 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3447 btnPtr = &infoPtr->buttons[nIndex];
3448 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3449 return FALSE;
3450 lpRect = (LPRECT)lParam;
3451 if (lpRect == NULL)
3452 return FALSE;
3454 lpRect->left = btnPtr->rect.left;
3455 lpRect->right = btnPtr->rect.right;
3456 lpRect->bottom = btnPtr->rect.bottom;
3457 lpRect->top = btnPtr->rect.top;
3459 return TRUE;
3463 static LRESULT
3464 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3466 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3468 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3469 return infoPtr->nRows;
3470 else
3471 return 1;
3475 static LRESULT
3476 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3478 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3479 INT nIndex;
3481 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3482 if (nIndex == -1)
3483 return -1;
3485 return infoPtr->buttons[nIndex].fsState;
3489 static LRESULT
3490 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3492 return GetWindowLongW(hwnd, GWL_STYLE);
3496 static LRESULT
3497 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3499 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3501 if (infoPtr == NULL)
3502 return 0;
3504 return infoPtr->nMaxTextRows;
3508 static LRESULT
3509 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3511 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3513 if (infoPtr == NULL)
3514 return 0;
3515 return (LRESULT)infoPtr->hwndToolTip;
3519 static LRESULT
3520 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3522 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3524 TRACE("%s hwnd=%p stub!\n",
3525 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3527 return infoPtr->bUnicode;
3531 inline static LRESULT
3532 TOOLBAR_GetVersion (HWND hwnd)
3534 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3535 return infoPtr->iVersion;
3539 static LRESULT
3540 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3542 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3543 TBUTTON_INFO *btnPtr;
3544 INT nIndex;
3546 TRACE("\n");
3548 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3549 if (nIndex == -1)
3550 return FALSE;
3552 btnPtr = &infoPtr->buttons[nIndex];
3553 if (LOWORD(lParam) == FALSE)
3554 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3555 else
3556 btnPtr->fsState |= TBSTATE_HIDDEN;
3558 TOOLBAR_CalcToolbar (hwnd);
3560 InvalidateRect (hwnd, NULL, TRUE);
3562 return TRUE;
3566 inline static LRESULT
3567 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3569 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3573 static LRESULT
3574 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3576 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3577 TBUTTON_INFO *btnPtr;
3578 INT nIndex;
3579 DWORD oldState;
3581 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3582 if (nIndex == -1)
3583 return FALSE;
3585 btnPtr = &infoPtr->buttons[nIndex];
3586 oldState = btnPtr->fsState;
3587 if (LOWORD(lParam) == FALSE)
3588 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3589 else
3590 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3592 if(oldState != btnPtr->fsState)
3593 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3595 return TRUE;
3599 static LRESULT
3600 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3602 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3603 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3604 INT nIndex = (INT)wParam;
3605 TBUTTON_INFO *oldButtons;
3607 if (lpTbb == NULL)
3608 return FALSE;
3610 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3612 if (nIndex == -1) {
3613 /* EPP: this seems to be an undocumented call (from my IE4)
3614 * I assume in that case that:
3615 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3616 * - index of insertion is at the end of existing buttons
3617 * I only see this happen with nIndex == -1, but it could have a special
3618 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3620 nIndex = infoPtr->nNumButtons;
3622 } else if (nIndex < 0)
3623 return FALSE;
3625 /* If the string passed is not an index, assume address of string
3626 and do our own AddString */
3627 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3628 LPSTR ptr;
3629 INT len;
3631 TRACE("string %s passed instead of index, adding string\n",
3632 debugstr_a((LPSTR)lpTbb->iString));
3633 len = strlen((LPSTR)lpTbb->iString) + 2;
3634 ptr = Alloc(len);
3635 strcpy(ptr, (LPSTR)lpTbb->iString);
3636 ptr[len - 1] = 0; /* ended by two '\0' */
3637 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3638 Free(ptr);
3641 TRACE("inserting button index=%d\n", nIndex);
3642 if (nIndex > infoPtr->nNumButtons) {
3643 nIndex = infoPtr->nNumButtons;
3644 TRACE("adjust index=%d\n", nIndex);
3647 oldButtons = infoPtr->buttons;
3648 infoPtr->nNumButtons++;
3649 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3650 /* pre insert copy */
3651 if (nIndex > 0) {
3652 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3653 nIndex * sizeof(TBUTTON_INFO));
3656 /* insert new button */
3657 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3658 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3659 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3660 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3661 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3662 /* if passed string and not index, then add string */
3663 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3664 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3666 else
3667 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3669 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3670 TTTOOLINFOA ti;
3672 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3673 ti.cbSize = sizeof (TTTOOLINFOA);
3674 ti.hwnd = hwnd;
3675 ti.uId = lpTbb->idCommand;
3676 ti.hinst = 0;
3677 ti.lpszText = LPSTR_TEXTCALLBACKA;
3679 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3680 0, (LPARAM)&ti);
3683 /* post insert copy */
3684 if (nIndex < infoPtr->nNumButtons - 1) {
3685 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3686 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3689 Free (oldButtons);
3691 TOOLBAR_CalcToolbar (hwnd);
3693 InvalidateRect (hwnd, NULL, TRUE);
3695 return TRUE;
3699 static LRESULT
3700 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3702 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3703 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3704 INT nIndex = (INT)wParam;
3705 TBUTTON_INFO *oldButtons;
3707 if (lpTbb == NULL)
3708 return FALSE;
3710 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3712 if (nIndex == -1) {
3713 /* EPP: this seems to be an undocumented call (from my IE4)
3714 * I assume in that case that:
3715 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3716 * - index of insertion is at the end of existing buttons
3717 * I only see this happen with nIndex == -1, but it could have a special
3718 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3720 nIndex = infoPtr->nNumButtons;
3722 } else if (nIndex < 0)
3723 return FALSE;
3725 /* If the string passed is not an index, assume address of string
3726 and do our own AddString */
3727 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3728 LPWSTR ptr;
3729 INT len;
3731 TRACE("string %s passed instead of index, adding string\n",
3732 debugstr_w((LPWSTR)lpTbb->iString));
3733 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3734 ptr = Alloc(len*sizeof(WCHAR));
3735 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3736 ptr[len - 1] = 0; /* ended by two '\0' */
3737 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3738 Free(ptr);
3741 TRACE("inserting button index=%d\n", nIndex);
3742 if (nIndex > infoPtr->nNumButtons) {
3743 nIndex = infoPtr->nNumButtons;
3744 TRACE("adjust index=%d\n", nIndex);
3747 oldButtons = infoPtr->buttons;
3748 infoPtr->nNumButtons++;
3749 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3750 /* pre insert copy */
3751 if (nIndex > 0) {
3752 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3753 nIndex * sizeof(TBUTTON_INFO));
3756 /* insert new button */
3757 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3758 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3759 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3760 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3761 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3762 /* if passed string and not index, then add string */
3763 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3764 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3766 else
3767 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3769 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3770 TTTOOLINFOW ti;
3772 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3773 ti.cbSize = sizeof (TTTOOLINFOW);
3774 ti.hwnd = hwnd;
3775 ti.uId = lpTbb->idCommand;
3776 ti.hinst = 0;
3777 ti.lpszText = LPSTR_TEXTCALLBACKW;
3779 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3780 0, (LPARAM)&ti);
3783 /* post insert copy */
3784 if (nIndex < infoPtr->nNumButtons - 1) {
3785 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3786 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3789 Free (oldButtons);
3791 TOOLBAR_CalcToolbar (hwnd);
3793 InvalidateRect (hwnd, NULL, TRUE);
3795 return TRUE;
3799 /* << TOOLBAR_InsertMarkHitTest >> */
3802 static LRESULT
3803 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3805 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3806 INT nIndex;
3808 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3809 if (nIndex == -1)
3810 return FALSE;
3812 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3816 static LRESULT
3817 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3819 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3820 INT nIndex;
3822 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3823 if (nIndex == -1)
3824 return FALSE;
3826 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3830 static LRESULT
3831 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3833 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3834 INT nIndex;
3836 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3837 if (nIndex == -1)
3838 return TRUE;
3840 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3844 static LRESULT
3845 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3847 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3848 INT nIndex;
3850 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3851 if (nIndex == -1)
3852 return FALSE;
3854 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3858 static LRESULT
3859 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3861 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3862 INT nIndex;
3864 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3865 if (nIndex == -1)
3866 return FALSE;
3868 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3872 static LRESULT
3873 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3875 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3876 INT nIndex;
3878 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3879 if (nIndex == -1)
3880 return FALSE;
3882 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3886 static LRESULT
3887 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3889 TBADDBITMAP tbab;
3890 tbab.hInst = (HINSTANCE)lParam;
3891 tbab.nID = (UINT_PTR)wParam;
3893 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3895 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3899 static LRESULT
3900 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3902 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3903 WCHAR wAccel = (WCHAR)wParam;
3904 UINT* pIDButton = (UINT*)lParam;
3905 WCHAR wszAccel[] = {'&',wAccel,0};
3906 int i;
3908 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3909 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3911 for (i = 0; i < infoPtr->nNumButtons; i++)
3913 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3914 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3915 !(btnPtr->fsState & TBSTATE_HIDDEN))
3917 int iLen = strlenW(wszAccel);
3918 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3920 if (!lpszStr)
3921 continue;
3923 while (*lpszStr)
3925 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3927 lpszStr += 2;
3928 continue;
3930 if (!strncmpiW(lpszStr, wszAccel, iLen))
3932 *pIDButton = btnPtr->idCommand;
3933 return TRUE;
3935 lpszStr++;
3939 return FALSE;
3943 static LRESULT
3944 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3946 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3947 INT nIndex;
3949 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3951 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3952 if (nIndex == -1)
3953 return FALSE;
3955 if (LOWORD(lParam))
3956 infoPtr->buttons[nIndex].fsState |= TBSTATE_MARKED;
3957 else
3958 infoPtr->buttons[nIndex].fsState &= ~TBSTATE_MARKED;
3960 return TRUE;
3964 /* fixes up an index of a button affected by a move */
3965 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
3967 if (bMoveUp)
3969 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
3970 (*pIndex)--;
3971 else if (*pIndex == nIndex)
3972 *pIndex = nMoveIndex;
3974 else
3976 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
3977 (*pIndex)++;
3978 else if (*pIndex == nIndex)
3979 *pIndex = nMoveIndex;
3984 static LRESULT
3985 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3987 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3988 INT nIndex;
3989 INT nCount;
3990 INT nMoveIndex = (INT)lParam;
3991 TBUTTON_INFO button;
3993 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
3995 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
3996 if ((nIndex == -1) || (nMoveIndex < 0))
3997 return FALSE;
3999 if (nMoveIndex > infoPtr->nNumButtons - 1)
4000 nMoveIndex = infoPtr->nNumButtons - 1;
4002 button = infoPtr->buttons[nIndex];
4004 /* move button right */
4005 if (nIndex < nMoveIndex)
4007 nCount = nMoveIndex - nIndex;
4008 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4009 infoPtr->buttons[nMoveIndex] = button;
4011 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4012 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4013 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4014 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4016 else if (nIndex > nMoveIndex) /* move button left */
4018 nCount = nIndex - nMoveIndex;
4019 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4020 infoPtr->buttons[nMoveIndex] = button;
4022 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4023 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4024 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4025 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4028 TOOLBAR_CalcToolbar(hwnd);
4029 InvalidateRect(hwnd, NULL, TRUE);
4031 return TRUE;
4035 static LRESULT
4036 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4038 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4039 TBUTTON_INFO *btnPtr;
4040 INT nIndex;
4041 DWORD oldState;
4043 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4044 if (nIndex == -1)
4045 return FALSE;
4047 btnPtr = &infoPtr->buttons[nIndex];
4048 oldState = btnPtr->fsState;
4049 if (LOWORD(lParam) == FALSE)
4050 btnPtr->fsState &= ~TBSTATE_PRESSED;
4051 else
4052 btnPtr->fsState |= TBSTATE_PRESSED;
4054 if(oldState != btnPtr->fsState)
4055 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4057 return TRUE;
4060 /* FIXME: there might still be some confusion her between number of buttons
4061 * and number of bitmaps */
4062 static LRESULT
4063 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4065 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4066 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4067 HBITMAP hBitmap;
4068 int i = 0, nOldButtons = 0, pos = 0;
4069 int nOldBitmaps, nNewBitmaps;
4070 HIMAGELIST himlDef = 0;
4072 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4073 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4074 lpReplace->nButtons);
4076 if (lpReplace->hInstOld == HINST_COMMCTRL)
4078 FIXME("changing standard bitmaps not implemented\n");
4079 return FALSE;
4081 else if (lpReplace->hInstOld != 0)
4083 FIXME("resources not in the current module not implemented\n");
4084 return FALSE;
4086 else
4088 hBitmap = (HBITMAP) lpReplace->nIDNew;
4091 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4092 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4093 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4094 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4095 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4097 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4098 nOldButtons = tbi->nButtons;
4099 tbi->nButtons = lpReplace->nButtons;
4100 tbi->hInst = lpReplace->hInstNew;
4101 tbi->nID = lpReplace->nIDNew;
4102 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4103 break;
4105 pos += tbi->nButtons;
4108 if (nOldButtons == 0)
4110 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4111 return FALSE;
4114 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4115 nOldBitmaps = ImageList_GetImageCount(himlDef);
4117 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4119 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4120 ImageList_Remove(himlDef, i);
4123 BITMAP bmp;
4124 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4125 HDC hdcImage, hdcBitmap;
4127 /* copy the bitmap before adding it so that the user's bitmap
4128 * doesn't get modified.
4130 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4132 hdcImage = CreateCompatibleDC(0);
4133 hdcBitmap = CreateCompatibleDC(0);
4135 /* create new bitmap */
4136 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4137 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4138 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4140 /* Copy the user's image */
4141 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4142 hdcBitmap, 0, 0, SRCCOPY);
4144 SelectObject (hdcImage, hOldBitmapLoad);
4145 SelectObject (hdcBitmap, hOldBitmapBitmap);
4146 DeleteDC (hdcImage);
4147 DeleteDC (hdcBitmap);
4149 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4150 nNewBitmaps = ImageList_GetImageCount(himlDef);
4151 DeleteObject (hbmLoad);
4154 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4156 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4157 pos, nOldBitmaps, nNewBitmaps);
4159 InvalidateRect(hwnd, NULL, TRUE);
4161 return TRUE;
4164 static LRESULT
4165 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4167 #if 0
4168 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4169 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
4171 if (lpSave == NULL) return 0;
4173 if ((BOOL)wParam) {
4174 /* save toolbar information */
4175 FIXME("save to \"%s\" \"%s\"\n",
4176 lpSave->pszSubKey, lpSave->pszValueName);
4180 else {
4181 /* restore toolbar information */
4183 FIXME("restore from \"%s\" \"%s\"\n",
4184 lpSave->pszSubKey, lpSave->pszValueName);
4188 #endif
4190 return 0;
4194 static LRESULT
4195 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4197 #if 0
4198 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4199 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
4201 if (lpSave == NULL)
4202 return 0;
4204 if ((BOOL)wParam) {
4205 /* save toolbar information */
4206 FIXME("save to \"%s\" \"%s\"\n",
4207 lpSave->pszSubKey, lpSave->pszValueName);
4211 else {
4212 /* restore toolbar information */
4214 FIXME("restore from \"%s\" \"%s\"\n",
4215 lpSave->pszSubKey, lpSave->pszValueName);
4219 #endif
4221 return 0;
4225 static LRESULT
4226 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4228 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4229 BOOL bOldAnchor = infoPtr->bAnchor;
4231 infoPtr->bAnchor = (BOOL)wParam;
4233 return (LRESULT)bOldAnchor;
4237 static LRESULT
4238 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4240 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4241 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4243 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4245 if (wParam != 0)
4246 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4248 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4249 return FALSE;
4251 if (infoPtr->nNumButtons > 0)
4252 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4253 infoPtr->nNumButtons,
4254 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4255 LOWORD(lParam), HIWORD(lParam));
4257 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4258 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4261 if ((himlDef == infoPtr->himlInt) &&
4262 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4264 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4265 infoPtr->nBitmapHeight);
4268 return TRUE;
4272 static LRESULT
4273 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4275 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4276 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4277 TBUTTON_INFO *btnPtr;
4278 INT nIndex;
4279 RECT oldBtnRect;
4281 if (lptbbi == NULL)
4282 return FALSE;
4283 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4284 return FALSE;
4286 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4287 lptbbi->dwMask & 0x80000000);
4288 if (nIndex == -1)
4289 return FALSE;
4291 btnPtr = &infoPtr->buttons[nIndex];
4292 if (lptbbi->dwMask & TBIF_COMMAND)
4293 btnPtr->idCommand = lptbbi->idCommand;
4294 if (lptbbi->dwMask & TBIF_IMAGE)
4295 btnPtr->iBitmap = lptbbi->iImage;
4296 if (lptbbi->dwMask & TBIF_LPARAM)
4297 btnPtr->dwData = lptbbi->lParam;
4298 if (lptbbi->dwMask & TBIF_SIZE)
4299 btnPtr->cx = lptbbi->cx;
4300 if (lptbbi->dwMask & TBIF_STATE)
4301 btnPtr->fsState = lptbbi->fsState;
4302 if (lptbbi->dwMask & TBIF_STYLE)
4303 btnPtr->fsStyle = lptbbi->fsStyle;
4305 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4306 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4307 /* iString is index, zero it to make Str_SetPtr succeed */
4308 btnPtr->iString=0;
4310 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4313 /* save the button rect to see if we need to redraw the whole toolbar */
4314 oldBtnRect = btnPtr->rect;
4315 TOOLBAR_CalcToolbar(hwnd);
4317 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4318 InvalidateRect(hwnd, NULL, TRUE);
4319 else
4320 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4322 return TRUE;
4326 static LRESULT
4327 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4329 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4330 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4331 TBUTTON_INFO *btnPtr;
4332 INT nIndex;
4333 RECT oldBtnRect;
4335 if (lptbbi == NULL)
4336 return FALSE;
4337 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4338 return FALSE;
4340 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4341 lptbbi->dwMask & 0x80000000);
4342 if (nIndex == -1)
4343 return FALSE;
4345 btnPtr = &infoPtr->buttons[nIndex];
4346 if (lptbbi->dwMask & TBIF_COMMAND)
4347 btnPtr->idCommand = lptbbi->idCommand;
4348 if (lptbbi->dwMask & TBIF_IMAGE)
4349 btnPtr->iBitmap = lptbbi->iImage;
4350 if (lptbbi->dwMask & TBIF_LPARAM)
4351 btnPtr->dwData = lptbbi->lParam;
4352 if (lptbbi->dwMask & TBIF_SIZE)
4353 btnPtr->cx = lptbbi->cx;
4354 if (lptbbi->dwMask & TBIF_STATE)
4355 btnPtr->fsState = lptbbi->fsState;
4356 if (lptbbi->dwMask & TBIF_STYLE)
4357 btnPtr->fsStyle = lptbbi->fsStyle;
4359 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4360 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4361 /* iString is index, zero it to make Str_SetPtr succeed */
4362 btnPtr->iString=0;
4363 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4366 /* save the button rect to see if we need to redraw the whole toolbar */
4367 oldBtnRect = btnPtr->rect;
4368 TOOLBAR_CalcToolbar(hwnd);
4370 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4371 InvalidateRect(hwnd, NULL, TRUE);
4372 else
4373 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4375 return TRUE;
4379 static LRESULT
4380 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4382 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4383 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4385 if ((cx < 0) || (cy < 0))
4387 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4388 return FALSE;
4391 /* The documentation claims you can only change the button size before
4392 * any button has been added. But this is wrong.
4393 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4394 * it to the toolbar, and it checks that the return value is nonzero - mjm
4395 * Further testing shows that we must actually perform the change too.
4398 * The documentation also does not mention that if 0 is supplied for
4399 * either size, the system changes it to the default of 24 wide and
4400 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4402 infoPtr->nButtonWidth = (cx) ? cx : 24;
4403 infoPtr->nButtonHeight = (cy) ? cy : 22;
4404 return TRUE;
4408 static LRESULT
4409 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4411 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4413 if (infoPtr == NULL) {
4414 TRACE("Toolbar not initialized yet?????\n");
4415 return FALSE;
4418 /* if setting to current values, ignore */
4419 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4420 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4421 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4422 infoPtr->cxMin, infoPtr->cxMax);
4423 return TRUE;
4426 /* save new values */
4427 infoPtr->cxMin = (INT)LOWORD(lParam);
4428 infoPtr->cxMax = (INT)HIWORD(lParam);
4430 /* if both values are 0 then we are done */
4431 if (lParam == 0) {
4432 TRACE("setting both min and max to 0, norecalc\n");
4433 return TRUE;
4436 /* otherwise we need to recalc the toolbar and in some cases
4437 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4438 which doesn't actually draw - GA). */
4439 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4440 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4442 TOOLBAR_CalcToolbar (hwnd);
4444 InvalidateRect (hwnd, NULL, TRUE);
4446 return TRUE;
4450 static LRESULT
4451 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4453 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4454 INT nIndex = (INT)wParam;
4456 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4457 return FALSE;
4459 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4461 if (infoPtr->hwndToolTip) {
4463 FIXME("change tool tip!\n");
4467 return TRUE;
4471 static LRESULT
4472 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4474 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4475 HIMAGELIST himl = (HIMAGELIST)lParam;
4476 HIMAGELIST himlTemp;
4477 INT id = 0;
4479 if (infoPtr->iVersion >= 5)
4480 id = wParam;
4482 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4483 &infoPtr->cimlDis, himl, id);
4485 /* FIXME: redraw ? */
4487 return (LRESULT)himlTemp;
4491 static LRESULT
4492 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4494 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4495 DWORD dwTemp;
4497 dwTemp = infoPtr->dwDTFlags;
4498 infoPtr->dwDTFlags =
4499 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4501 return (LRESULT)dwTemp;
4504 /* This function differs a bit from what MSDN says it does:
4505 * 1. lParam contains extended style flags to OR with current style
4506 * (MSDN isn't clear on the OR bit)
4507 * 2. wParam appears to contain extended style flags to be reset
4508 * (MSDN says that this parameter is reserved)
4510 static LRESULT
4511 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4513 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4514 DWORD dwTemp;
4516 dwTemp = infoPtr->dwExStyle;
4517 infoPtr->dwExStyle &= ~wParam;
4518 infoPtr->dwExStyle |= (DWORD)lParam;
4520 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4522 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4523 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4524 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4526 TOOLBAR_CalcToolbar (hwnd);
4528 TOOLBAR_AutoSize(hwnd);
4530 InvalidateRect(hwnd, NULL, TRUE);
4532 return (LRESULT)dwTemp;
4536 static LRESULT
4537 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4539 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4540 HIMAGELIST himlTemp;
4541 HIMAGELIST himl = (HIMAGELIST)lParam;
4542 INT id = 0;
4544 if (infoPtr->iVersion >= 5)
4545 id = wParam;
4547 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4549 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4550 &infoPtr->cimlHot, himl, id);
4552 /* FIXME: redraw ? */
4554 return (LRESULT)himlTemp;
4558 /* Makes previous hot button no longer hot, makes the specified
4559 * button hot and sends appropriate notifications. dwReason is one or
4560 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4561 * NOTE 1: this function does not validate nHit
4562 * NOTE 2: the name of this function is completely made up and
4563 * not based on any documentation from Microsoft. */
4564 static void
4565 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4567 if (infoPtr->nHotItem != nHit)
4569 NMTBHOTITEM nmhotitem;
4570 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4571 LRESULT no_highlight;
4573 /* Remove the effect of an old hot button if the button was
4574 drawn with the hot button effect */
4575 if(infoPtr->nHotItem >= 0)
4577 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4578 oldBtnPtr->bHot = FALSE;
4581 infoPtr->nHotItem = nHit;
4583 /* It's not a separator or in nowhere. It's a hot button. */
4584 if (nHit >= 0)
4585 btnPtr = &infoPtr->buttons[nHit];
4587 nmhotitem.dwFlags = dwReason;
4588 if (oldBtnPtr)
4589 nmhotitem.idOld = oldBtnPtr->idCommand;
4590 else
4591 nmhotitem.dwFlags |= HICF_ENTERING;
4592 if (btnPtr)
4593 nmhotitem.idNew = btnPtr->idCommand;
4594 else
4595 nmhotitem.dwFlags |= HICF_LEAVING;
4597 no_highlight = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4599 /* now invalidate the old and new buttons so they will be painted */
4600 if (oldBtnPtr)
4601 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4602 if (btnPtr && !no_highlight)
4604 btnPtr->bHot = TRUE;
4605 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4610 static LRESULT
4611 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4613 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4614 INT nOldHotItem = infoPtr->nHotItem;
4616 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4617 wParam = -2;
4619 if (infoPtr->dwStyle & TBSTYLE_FLAT)
4620 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4622 if (nOldHotItem < 0)
4623 return -1;
4625 return (LRESULT)nOldHotItem;
4629 static LRESULT
4630 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4632 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4633 HIMAGELIST himlTemp;
4634 HIMAGELIST himl = (HIMAGELIST)lParam;
4635 INT i, id = 0;
4637 if (infoPtr->iVersion >= 5)
4638 id = wParam;
4640 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4641 &infoPtr->cimlDef, himl, id);
4643 infoPtr->nNumBitmaps = 0;
4644 for (i = 0; i < infoPtr->cimlDef; i++)
4645 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4647 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4648 &infoPtr->nBitmapHeight);
4649 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4650 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4651 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4653 InvalidateRect(hwnd, NULL, TRUE);
4655 return (LRESULT)himlTemp;
4659 static LRESULT
4660 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4662 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4664 infoPtr->nIndent = (INT)wParam;
4666 TRACE("\n");
4668 /* process only on indent changing */
4669 if(infoPtr->nIndent != (INT)wParam)
4671 infoPtr->nIndent = (INT)wParam;
4672 TOOLBAR_CalcToolbar (hwnd);
4673 InvalidateRect(hwnd, NULL, FALSE);
4676 return TRUE;
4680 /* << TOOLBAR_SetInsertMark >> */
4683 static LRESULT
4684 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4686 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4688 infoPtr->clrInsertMark = (COLORREF)lParam;
4690 /* FIXME : redraw ??*/
4692 return 0;
4696 static LRESULT
4697 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4699 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4701 if (infoPtr == NULL)
4702 return FALSE;
4704 infoPtr->nMaxTextRows = (INT)wParam;
4706 TOOLBAR_CalcToolbar(hwnd);
4707 return TRUE;
4711 /* MSDN gives slightly wrong info on padding.
4712 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4713 * 2. It is not used to create a blank area between the edge of the button
4714 * and the text or image if TBSTYLE_LIST is set. It is used to control
4715 * the gap between the image and text.
4716 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4717 * to control the bottom and right borders [with the border being
4718 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4719 * is shared evenly on both sides of the button.
4721 static LRESULT
4722 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4724 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4725 DWORD oldPad;
4727 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4728 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4729 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4730 TRACE("cx=%ld, cy=%ld\n",
4731 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4732 return (LRESULT) oldPad;
4736 static LRESULT
4737 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4739 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4740 HWND hwndOldNotify;
4742 TRACE("\n");
4744 if (infoPtr == NULL)
4745 return 0;
4746 hwndOldNotify = infoPtr->hwndNotify;
4747 infoPtr->hwndNotify = (HWND)wParam;
4749 return (LRESULT)hwndOldNotify;
4753 static LRESULT
4754 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4756 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4757 LPRECT lprc = (LPRECT)lParam;
4759 TRACE("\n");
4761 if (LOWORD(wParam) > 1) {
4762 FIXME("multiple rows not supported!\n");
4765 if(infoPtr->nRows != LOWORD(wParam))
4767 infoPtr->nRows = LOWORD(wParam);
4769 /* recalculate toolbar */
4770 TOOLBAR_CalcToolbar (hwnd);
4772 /* repaint toolbar */
4773 InvalidateRect(hwnd, NULL, TRUE);
4776 /* return bounding rectangle */
4777 if (lprc) {
4778 lprc->left = infoPtr->rcBound.left;
4779 lprc->right = infoPtr->rcBound.right;
4780 lprc->top = infoPtr->rcBound.top;
4781 lprc->bottom = infoPtr->rcBound.bottom;
4784 return 0;
4788 static LRESULT
4789 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4791 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4792 TBUTTON_INFO *btnPtr;
4793 INT nIndex;
4795 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4796 if (nIndex == -1)
4797 return FALSE;
4799 btnPtr = &infoPtr->buttons[nIndex];
4801 /* if hidden state has changed the invalidate entire window and recalc */
4802 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4803 btnPtr->fsState = LOWORD(lParam);
4804 TOOLBAR_CalcToolbar (hwnd);
4805 InvalidateRect(hwnd, 0, TRUE);
4806 return TRUE;
4809 /* process state changing if current state doesn't match new state */
4810 if(btnPtr->fsState != LOWORD(lParam))
4812 btnPtr->fsState = LOWORD(lParam);
4813 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4816 return TRUE;
4820 static LRESULT
4821 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4823 SetWindowLongW(hwnd, GWL_STYLE, lParam);
4825 return TRUE;
4829 inline static LRESULT
4830 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4832 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4834 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
4836 if (infoPtr == NULL)
4837 return 0;
4838 infoPtr->hwndToolTip = (HWND)wParam;
4839 return 0;
4843 static LRESULT
4844 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4846 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4847 BOOL bTemp;
4849 TRACE("%s hwnd=%p stub!\n",
4850 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4852 bTemp = infoPtr->bUnicode;
4853 infoPtr->bUnicode = (BOOL)wParam;
4855 return bTemp;
4859 static LRESULT
4860 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4862 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4864 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4865 comctl32_color.clrBtnHighlight :
4866 infoPtr->clrBtnHighlight;
4867 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4868 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4869 return 1;
4873 static LRESULT
4874 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4876 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4878 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4879 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4880 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4882 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4883 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4884 InvalidateRect(hwnd, NULL, TRUE);
4885 return 0;
4889 static LRESULT
4890 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4892 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4893 INT iOldVersion = infoPtr->iVersion;
4895 infoPtr->iVersion = iVersion;
4897 if (infoPtr->iVersion >= 5)
4898 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
4900 return iOldVersion;
4904 static LRESULT
4905 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4907 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4908 WORD iString = HIWORD(wParam);
4909 WORD buffersize = LOWORD(wParam);
4910 LPSTR str = (LPSTR)lParam;
4911 LRESULT ret = -1;
4913 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
4915 if (iString < infoPtr->nNumStrings)
4917 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
4919 TRACE("returning %s\n", debugstr_a(str));
4921 else
4922 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4924 return ret;
4928 static LRESULT
4929 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4931 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4932 WORD iString = HIWORD(wParam);
4933 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
4934 LPWSTR str = (LPWSTR)lParam;
4935 LRESULT ret = -1;
4937 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
4939 if (iString < infoPtr->nNumStrings)
4941 len = min(len, strlenW(infoPtr->strings[iString]));
4942 ret = (len+1)*sizeof(WCHAR);
4943 memcpy(str, infoPtr->strings[iString], ret);
4944 str[len] = '\0';
4946 TRACE("returning %s\n", debugstr_w(str));
4948 else
4949 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4951 return ret;
4954 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
4955 * is the maximum size of the toolbar? */
4956 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
4958 SIZE * pSize = (SIZE*)lParam;
4959 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
4960 return 0;
4964 /* UNDOCUMENTED MESSAGE: This is an extended version of the
4965 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
4966 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
4967 * sends). */
4968 static LRESULT
4969 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
4971 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4972 INT nOldHotItem = infoPtr->nHotItem;
4974 TRACE("old item=%d, new item=%d, flags=%08lx\n",
4975 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
4977 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4978 wParam = -1;
4980 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
4982 GetFocus();
4984 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
4987 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
4988 * which controls the amount of spacing between the image and the text
4989 * of buttons for TBSTYLE_LIST toolbars. */
4990 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
4992 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4994 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
4996 if (lParam != 0)
4997 FIXME("lParam = 0x%08lx. Please report\n", lParam);
4999 infoPtr->iListGap = (INT)wParam;
5001 TOOLBAR_CalcToolbar(hwnd);
5002 InvalidateRect(hwnd, NULL, TRUE);
5004 return 0;
5007 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5008 * of image lists associated with the various states. */
5009 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5011 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5013 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5015 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5018 static LRESULT
5019 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5021 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5022 LPSIZE lpsize = (LPSIZE)lParam;
5024 if (lpsize == NULL)
5025 return FALSE;
5028 * Testing shows the following:
5029 * wParam = 0 adjust cx value
5030 * = 1 set cy value to max size.
5031 * lParam pointer to SIZE structure
5034 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5035 wParam, lParam, lpsize->cx, lpsize->cy);
5037 switch(wParam) {
5038 case 0:
5039 if (lpsize->cx == -1) {
5040 /* **** this is wrong, native measures each button and sets it */
5041 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5043 else if(HIWORD(lpsize->cx)) {
5044 RECT rc;
5045 HWND hwndParent = GetParent(hwnd);
5047 GetWindowRect(hwnd, &rc);
5048 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5049 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5050 rc.left, rc.top, rc.right, rc.bottom);
5051 lpsize->cx = max(rc.right-rc.left,
5052 infoPtr->rcBound.right - infoPtr->rcBound.left);
5054 else {
5055 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5057 break;
5058 case 1:
5059 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5060 /* lpsize->cy = infoPtr->nHeight; */
5061 break;
5062 default:
5063 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5064 wParam);
5065 return 0;
5067 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5068 lpsize->cx, lpsize->cy);
5069 return 1;
5072 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5074 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5076 InvalidateRect(hwnd, NULL, TRUE);
5077 return 1;
5081 static LRESULT
5082 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5084 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5085 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5086 LOGFONTA logFont;
5088 TRACE("hwnd = %p\n", hwnd);
5090 /* initialize info structure */
5091 infoPtr->nButtonHeight = 22;
5092 infoPtr->nButtonWidth = 24;
5093 infoPtr->nBitmapHeight = 15;
5094 infoPtr->nBitmapWidth = 16;
5096 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
5097 infoPtr->nMaxTextRows = 1;
5098 infoPtr->cxMin = -1;
5099 infoPtr->cxMax = -1;
5100 infoPtr->nNumBitmaps = 0;
5101 infoPtr->nNumStrings = 0;
5103 infoPtr->bCaptured = FALSE;
5104 infoPtr->bUnicode = IsWindowUnicode (hwnd);
5105 infoPtr->nButtonDown = -1;
5106 infoPtr->nButtonDrag = -1;
5107 infoPtr->nOldHit = -1;
5108 infoPtr->nHotItem = -1;
5109 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5110 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5111 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5112 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5113 infoPtr->bDragOutSent = FALSE;
5114 infoPtr->iVersion = 0;
5115 infoPtr->hwndSelf = hwnd;
5116 infoPtr->bDoRedraw = TRUE;
5117 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5118 infoPtr->clrBtnShadow = CLR_DEFAULT;
5119 /* not sure where the +1 comes from, but this comes to the same value
5120 * as native so this is probably correct */
5121 infoPtr->szPadding.cx = 2*(GetSystemMetrics(SM_CXEDGE)+OFFSET_X) + 1;
5122 infoPtr->szPadding.cy = 2*(GetSystemMetrics(SM_CYEDGE)+OFFSET_Y);
5123 infoPtr->iListGap = infoPtr->szPadding.cx / 2;
5124 infoPtr->dwStyle = dwStyle;
5125 GetClientRect(hwnd, &infoPtr->client_rect);
5126 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
5128 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5129 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
5131 if (dwStyle & TBSTYLE_TOOLTIPS) {
5132 /* Create tooltip control */
5133 infoPtr->hwndToolTip =
5134 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
5135 CW_USEDEFAULT, CW_USEDEFAULT,
5136 CW_USEDEFAULT, CW_USEDEFAULT,
5137 hwnd, 0, 0, 0);
5139 /* Send NM_TOOLTIPSCREATED notification */
5140 if (infoPtr->hwndToolTip) {
5141 NMTOOLTIPSCREATED nmttc;
5143 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5145 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
5146 NM_TOOLTIPSCREATED);
5150 TOOLBAR_CheckStyle (hwnd, dwStyle);
5152 TOOLBAR_CalcToolbar(hwnd);
5154 return 0;
5158 static LRESULT
5159 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5161 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5163 /* delete tooltip control */
5164 if (infoPtr->hwndToolTip)
5165 DestroyWindow (infoPtr->hwndToolTip);
5167 /* delete temporary buffer for tooltip text */
5168 if (infoPtr->pszTooltipText)
5169 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5171 /* delete button data */
5172 if (infoPtr->buttons)
5173 Free (infoPtr->buttons);
5175 /* delete strings */
5176 if (infoPtr->strings) {
5177 INT i;
5178 for (i = 0; i < infoPtr->nNumStrings; i++)
5179 if (infoPtr->strings[i])
5180 Free (infoPtr->strings[i]);
5182 Free (infoPtr->strings);
5185 /* destroy internal image list */
5186 if (infoPtr->himlInt)
5187 ImageList_Destroy (infoPtr->himlInt);
5189 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5190 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5191 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5193 /* delete default font */
5194 if (infoPtr->hFont)
5195 DeleteObject (infoPtr->hDefaultFont);
5197 /* free toolbar info data */
5198 Free (infoPtr);
5199 SetWindowLongPtrW (hwnd, 0, 0);
5201 return 0;
5205 static LRESULT
5206 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5208 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5209 NMTBCUSTOMDRAW tbcd;
5210 INT ret = FALSE;
5211 DWORD ntfret;
5213 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5214 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5215 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5216 tbcd.nmcd.hdc = (HDC)wParam;
5217 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5218 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5220 /* FIXME: in general the return flags *can* be or'ed together */
5221 switch (infoPtr->dwBaseCustDraw)
5223 case CDRF_DODEFAULT:
5224 break;
5225 case CDRF_SKIPDEFAULT:
5226 return TRUE;
5227 default:
5228 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5229 hwnd, ntfret);
5233 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5234 * to my parent for processing.
5236 if (infoPtr->dwStyle & TBSTYLE_TRANSPARENT) {
5237 POINT pt, ptorig;
5238 HDC hdc = (HDC)wParam;
5239 HWND parent;
5241 pt.x = 0;
5242 pt.y = 0;
5243 parent = GetParent(hwnd);
5244 MapWindowPoints(hwnd, parent, &pt, 1);
5245 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5246 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
5247 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5249 if (!ret)
5250 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
5252 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5253 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5254 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5255 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5256 tbcd.nmcd.hdc = (HDC)wParam;
5257 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5258 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5259 switch (infoPtr->dwBaseCustDraw)
5261 case CDRF_DODEFAULT:
5262 break;
5263 case CDRF_SKIPDEFAULT:
5264 return TRUE;
5265 default:
5266 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5267 hwnd, ntfret);
5270 return ret;
5274 static LRESULT
5275 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5277 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5279 return (LRESULT)infoPtr->hFont;
5283 static LRESULT
5284 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5286 POINT pt;
5287 INT nHit;
5289 pt.x = (INT)LOWORD(lParam);
5290 pt.y = (INT)HIWORD(lParam);
5291 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5293 if (nHit >= 0)
5294 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5295 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5296 TOOLBAR_Customize (hwnd);
5298 return 0;
5302 static LRESULT
5303 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5305 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5306 TBUTTON_INFO *btnPtr;
5307 POINT pt;
5308 INT nHit;
5309 NMTOOLBARA nmtb;
5310 BOOL bDragKeyPressed;
5312 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5313 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5314 else
5315 bDragKeyPressed = (wParam & MK_SHIFT);
5317 if (infoPtr->hwndToolTip)
5318 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5319 WM_LBUTTONDOWN, wParam, lParam);
5321 pt.x = (INT)LOWORD(lParam);
5322 pt.y = (INT)HIWORD(lParam);
5323 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5325 btnPtr = &infoPtr->buttons[nHit];
5327 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5329 infoPtr->nButtonDrag = nHit;
5330 SetCapture (hwnd);
5332 /* If drag cursor has not been loaded, load it.
5333 * Note: it doesn't need to be freed */
5334 if (!hCursorDrag)
5335 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5336 SetCursor(hCursorDrag);
5338 else if (nHit >= 0)
5340 RECT arrowRect;
5341 infoPtr->nOldHit = nHit;
5343 CopyRect(&arrowRect, &btnPtr->rect);
5344 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5346 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5347 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5348 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5349 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5350 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5351 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5353 LRESULT res;
5355 /* draw in pressed state */
5356 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5357 btnPtr->fsState |= TBSTATE_PRESSED;
5358 else
5359 btnPtr->bDropDownPressed = TRUE;
5360 RedrawWindow(hwnd,&btnPtr->rect,0,
5361 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5363 nmtb.iItem = btnPtr->idCommand;
5364 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
5365 nmtb.cchText = 0;
5366 nmtb.pszText = 0;
5367 CopyRect(&nmtb.rcButton, &btnPtr->rect);
5368 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5369 TBN_DROPDOWN);
5370 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5372 if (res != TBDDRET_TREATPRESSED)
5374 MSG msg;
5376 /* redraw button in unpressed state */
5377 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5378 btnPtr->fsState &= ~TBSTATE_PRESSED;
5379 else
5380 btnPtr->bDropDownPressed = FALSE;
5381 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5383 /* find and set hot item
5384 * NOTE: native doesn't do this, but that is a bug */
5385 GetCursorPos(&pt);
5386 ScreenToClient(hwnd, &pt);
5387 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5388 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5390 /* remove any left mouse button down or double-click messages
5391 * so that we can get a toggle effect on the button */
5392 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5393 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5396 return 0;
5398 /* otherwise drop through and process as pushed */
5400 infoPtr->bCaptured = TRUE;
5401 infoPtr->nButtonDown = nHit;
5402 infoPtr->bDragOutSent = FALSE;
5404 btnPtr->fsState |= TBSTATE_PRESSED;
5406 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5408 if (btnPtr->fsState & TBSTATE_ENABLED)
5409 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5410 UpdateWindow(hwnd);
5411 SetCapture (hwnd);
5414 if (nHit >=0)
5416 nmtb.iItem = btnPtr->idCommand;
5417 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5418 nmtb.tbButton.idCommand = btnPtr->idCommand;
5419 nmtb.tbButton.fsState = btnPtr->fsState;
5420 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5421 nmtb.tbButton.dwData = btnPtr->dwData;
5422 nmtb.tbButton.iString = btnPtr->iString;
5423 nmtb.cchText = 0; /* !!! not correct */
5424 nmtb.pszText = 0; /* !!! not correct */
5425 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5428 return 0;
5431 static LRESULT
5432 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5434 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5435 TBUTTON_INFO *btnPtr;
5436 POINT pt;
5437 INT nHit;
5438 INT nOldIndex = -1;
5439 BOOL bSendMessage = TRUE;
5440 NMHDR hdr;
5441 NMMOUSE nmmouse;
5442 NMTOOLBARA nmtb;
5444 if (infoPtr->hwndToolTip)
5445 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5446 WM_LBUTTONUP, wParam, lParam);
5448 pt.x = (INT)LOWORD(lParam);
5449 pt.y = (INT)HIWORD(lParam);
5450 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5452 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5454 if (infoPtr->nButtonDrag >= 0) {
5455 RECT rcClient;
5456 NMHDR hdr;
5458 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5459 ReleaseCapture();
5460 /* reset cursor */
5461 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5463 GetClientRect(hwnd, &rcClient);
5464 if (PtInRect(&rcClient, pt))
5466 INT nButton = -1;
5467 if (nHit >= 0)
5468 nButton = nHit;
5469 else if (nHit < -1)
5470 nButton = -nHit;
5471 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5472 nButton = -nHit;
5474 if (nButton == infoPtr->nButtonDrag)
5476 /* if the button is moved sightly left and we have a
5477 * separator there then remove it */
5478 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5480 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5481 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5483 else /* else insert a separator before the dragged button */
5485 TBBUTTON tbb;
5486 memset(&tbb, 0, sizeof(tbb));
5487 tbb.fsStyle = BTNS_SEP;
5488 tbb.iString = -1;
5489 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5492 else
5494 if (nButton == -1)
5496 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5497 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5498 else
5499 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5501 else
5502 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5505 else
5507 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5508 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5511 /* button under cursor changed so need to re-set hot item */
5512 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5513 infoPtr->nButtonDrag = -1;
5515 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5517 else if (infoPtr->nButtonDown >= 0) {
5518 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5519 btnPtr->fsState &= ~TBSTATE_PRESSED;
5521 if (btnPtr->fsStyle & BTNS_CHECK) {
5522 if (btnPtr->fsStyle & BTNS_GROUP) {
5523 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5524 nHit);
5525 if (nOldIndex == nHit)
5526 bSendMessage = FALSE;
5527 if ((nOldIndex != nHit) &&
5528 (nOldIndex != -1))
5529 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5530 btnPtr->fsState |= TBSTATE_CHECKED;
5532 else {
5533 if (btnPtr->fsState & TBSTATE_CHECKED)
5534 btnPtr->fsState &= ~TBSTATE_CHECKED;
5535 else
5536 btnPtr->fsState |= TBSTATE_CHECKED;
5540 if (nOldIndex != -1)
5541 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5544 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5545 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5546 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5548 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5549 ReleaseCapture ();
5550 infoPtr->nButtonDown = -1;
5552 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5553 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5554 NM_RELEASEDCAPTURE);
5556 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5557 * TBN_BEGINDRAG
5559 nmtb.iItem = btnPtr->idCommand;
5560 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5561 nmtb.tbButton.idCommand = btnPtr->idCommand;
5562 nmtb.tbButton.fsState = btnPtr->fsState;
5563 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5564 nmtb.tbButton.dwData = btnPtr->dwData;
5565 nmtb.tbButton.iString = btnPtr->iString;
5566 nmtb.cchText = 0; /* !!! not correct */
5567 nmtb.pszText = 0; /* !!! not correct */
5568 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5569 TBN_ENDDRAG);
5571 if (btnPtr->fsState & TBSTATE_ENABLED)
5573 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
5574 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5576 /* !!! Undocumented - toolbar at 4.71 level and above sends
5577 * either NM_RCLICK or NM_CLICK with the NMMOUSE structure.
5578 * Only NM_RCLICK is documented.
5580 nmmouse.dwItemSpec = btnPtr->idCommand;
5581 nmmouse.dwItemData = btnPtr->dwData;
5582 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr, NM_CLICK);
5585 return 0;
5588 static LRESULT
5589 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5591 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5593 NMMOUSE nmmouse;
5594 POINT pt;
5596 pt.x = LOWORD(lParam);
5597 pt.y = HIWORD(lParam);
5599 nmmouse.dwHitInfo = TOOLBAR_InternalHitTest(hwnd, &pt);
5601 if (nmmouse.dwHitInfo < 0) {
5602 nmmouse.dwItemSpec = -1;
5603 } else {
5604 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5605 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5608 ClientToScreen(hwnd, &pt);
5609 memcpy(&nmmouse.pt, &pt, sizeof(POINT));
5611 TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK);
5613 return 0;
5616 static LRESULT
5617 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5619 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5621 NMMOUSE nmmouse;
5622 POINT pt;
5624 pt.x = LOWORD(lParam);
5625 pt.y = HIWORD(lParam);
5627 nmmouse.dwHitInfo = TOOLBAR_InternalHitTest(hwnd, &pt);
5629 if (nmmouse.dwHitInfo < 0)
5630 nmmouse.dwItemSpec = -1;
5631 else {
5632 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5633 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5636 ClientToScreen(hwnd, &pt);
5637 memcpy(&nmmouse.pt, &pt, sizeof(POINT));
5639 TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RDBLCLK);
5641 return 0;
5644 static LRESULT
5645 TOOLBAR_CaptureChanged(HWND hwnd)
5647 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5648 TBUTTON_INFO *btnPtr;
5650 infoPtr->bCaptured = FALSE;
5652 if (infoPtr->nButtonDown >= 0)
5654 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5655 btnPtr->fsState &= ~TBSTATE_PRESSED;
5657 infoPtr->nOldHit = -1;
5659 if (btnPtr->fsState & TBSTATE_ENABLED)
5660 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5662 return 0;
5665 static LRESULT
5666 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5668 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5669 TBUTTON_INFO *hotBtnPtr;
5671 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5673 /* don't remove hot effects when in drop-down */
5674 if (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed)
5675 TOOLBAR_SetHotItemEx(infoPtr, -1, HICF_MOUSE);
5677 if (infoPtr->nOldHit < 0)
5678 return TRUE;
5680 /* If the last button we were over is depressed then make it not */
5681 /* depressed and redraw it */
5682 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5684 TBUTTON_INFO *btnPtr;
5685 RECT rc1;
5687 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5689 btnPtr->fsState &= ~TBSTATE_PRESSED;
5691 rc1 = hotBtnPtr->rect;
5692 InflateRect (&rc1, 1, 1);
5693 InvalidateRect (hwnd, &rc1, TRUE);
5696 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
5698 NMTOOLBARW nmt;
5699 ZeroMemory(&nmt, sizeof(nmt));
5700 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5701 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5702 infoPtr->bDragOutSent = TRUE;
5705 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5707 return TRUE;
5710 static LRESULT
5711 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5713 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5714 POINT pt;
5715 TRACKMOUSEEVENT trackinfo;
5716 INT nHit;
5717 TBUTTON_INFO *btnPtr;
5719 /* fill in the TRACKMOUSEEVENT struct */
5720 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5721 trackinfo.dwFlags = TME_QUERY;
5722 trackinfo.hwndTrack = hwnd;
5723 trackinfo.dwHoverTime = HOVER_DEFAULT;
5725 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5726 _TrackMouseEvent(&trackinfo);
5728 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5729 if(!(trackinfo.dwFlags & TME_LEAVE)) {
5730 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5732 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5733 /* and can properly deactivate the hot toolbar button */
5734 _TrackMouseEvent(&trackinfo);
5737 if (infoPtr->hwndToolTip)
5738 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5739 WM_MOUSEMOVE, wParam, lParam);
5741 pt.x = (INT)LOWORD(lParam);
5742 pt.y = (INT)HIWORD(lParam);
5744 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5746 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
5748 if (infoPtr->nOldHit != nHit)
5750 if (infoPtr->bCaptured)
5752 if (!infoPtr->bDragOutSent)
5754 NMTOOLBARW nmt;
5755 ZeroMemory(&nmt, sizeof(nmt));
5756 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5757 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5758 infoPtr->bDragOutSent = TRUE;
5761 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5762 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5763 btnPtr->fsState &= ~TBSTATE_PRESSED;
5764 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5766 else if (nHit == infoPtr->nButtonDown) {
5767 btnPtr->fsState |= TBSTATE_PRESSED;
5768 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5770 infoPtr->nOldHit = nHit;
5774 return 0;
5778 inline static LRESULT
5779 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5781 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5782 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5783 /* else */
5784 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5788 inline static LRESULT
5789 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5791 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
5792 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5794 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5798 static LRESULT
5799 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5801 TOOLBAR_INFO *infoPtr;
5802 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5803 DWORD styleadd = 0;
5805 /* allocate memory for info structure */
5806 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
5807 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
5809 /* paranoid!! */
5810 infoPtr->dwStructSize = sizeof(TBBUTTON);
5811 infoPtr->nRows = 1;
5813 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5814 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
5815 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
5816 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
5819 /* native control does:
5820 * Get a lot of colors and brushes
5821 * WM_NOTIFYFORMAT
5822 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5823 * CreateFontIndirectA(adr1)
5824 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5825 * hdc = GetDC(toolbar)
5826 * GetSystemMetrics(0x48)
5827 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5828 * 0, 0, 0, 0, "MARLETT")
5829 * oldfnt = SelectObject(hdc, fnt2)
5830 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5831 * GetTextMetricsA(hdc, adr3)
5832 * SelectObject(hdc, oldfnt)
5833 * DeleteObject(fnt2)
5834 * ReleaseDC(hdc)
5835 * InvalidateRect(toolbar, 0, 1)
5836 * SetWindowLongA(toolbar, 0, addr)
5837 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5838 * WM_STYLECHANGING
5839 * CallWinEx old new
5840 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5841 * ie 2 0x4600094c 0x4600094c 0x4600894d
5842 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5843 * rebar 0x50008844 0x40008844 0x50008845
5844 * pager 0x50000844 0x40000844 0x50008845
5845 * IC35mgr 0x5400084e **nochange**
5846 * on entry to _NCCREATE 0x5400084e
5847 * rowlist 0x5400004e **nochange**
5848 * on entry to _NCCREATE 0x5400004e
5852 /* I think the code below is a bug, but it is the way that the native
5853 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5854 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5855 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5856 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5857 * Some how, the only cases of this seem to be MFC programs.
5859 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5860 * does not occur in the WM_STYLECHANGING routine.
5861 * (Guy Albertelli 9/2001)
5864 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5865 styleadd |= TBSTYLE_TRANSPARENT;
5866 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5867 styleadd |= CCS_TOP; /* default to top */
5868 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
5871 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5875 static LRESULT
5876 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5878 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
5879 RECT rcWindow;
5880 HDC hdc;
5882 if (dwStyle & WS_MINIMIZE)
5883 return 0; /* Nothing to do */
5885 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5887 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5888 return 0;
5890 if (!(dwStyle & CCS_NODIVIDER))
5892 GetWindowRect (hwnd, &rcWindow);
5893 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5894 if( dwStyle & WS_BORDER )
5895 OffsetRect (&rcWindow, 1, 1);
5896 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5899 ReleaseDC( hwnd, hdc );
5901 return 0;
5905 /* handles requests from the tooltip control on what text to display */
5906 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
5908 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
5910 TRACE("button index = %d\n", index);
5912 if (infoPtr->pszTooltipText)
5914 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5915 infoPtr->pszTooltipText = NULL;
5918 if (index < 0)
5919 return 0;
5921 if (infoPtr->bNtfUnicode)
5923 WCHAR wszBuffer[INFOTIPSIZE+1];
5924 NMTBGETINFOTIPW tbgit;
5925 int len; /* in chars */
5927 wszBuffer[0] = '\0';
5928 wszBuffer[INFOTIPSIZE] = '\0';
5930 tbgit.pszText = wszBuffer;
5931 tbgit.cchTextMax = INFOTIPSIZE;
5932 tbgit.iItem = lpnmtdi->hdr.idFrom;
5933 tbgit.lParam = infoPtr->buttons[index].dwData;
5935 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
5937 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
5939 len = strlenW(tbgit.pszText);
5940 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5942 /* need to allocate temporary buffer in infoPtr as there
5943 * isn't enough space in buffer passed to us by the
5944 * tooltip control */
5945 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5946 if (infoPtr->pszTooltipText)
5948 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
5949 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5950 return 0;
5953 else if (len > 0)
5955 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
5956 return 0;
5959 else
5961 CHAR szBuffer[INFOTIPSIZE+1];
5962 NMTBGETINFOTIPA tbgit;
5963 int len; /* in chars */
5965 szBuffer[0] = '\0';
5966 szBuffer[INFOTIPSIZE] = '\0';
5968 tbgit.pszText = szBuffer;
5969 tbgit.cchTextMax = INFOTIPSIZE;
5970 tbgit.iItem = lpnmtdi->hdr.idFrom;
5971 tbgit.lParam = infoPtr->buttons[index].dwData;
5973 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
5975 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
5977 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
5978 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5980 /* need to allocate temporary buffer in infoPtr as there
5981 * isn't enough space in buffer passed to us by the
5982 * tooltip control */
5983 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5984 if (infoPtr->pszTooltipText)
5986 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
5987 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5988 return 0;
5991 else if (len > 0)
5993 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
5994 return 0;
5998 /* if button has text, but it is not shown then automatically
5999 * use that text as tooltip */
6000 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6001 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6003 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6004 int len = pszText ? strlenW(pszText) : 0;
6006 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6008 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6010 /* need to allocate temporary buffer in infoPtr as there
6011 * isn't enough space in buffer passed to us by the
6012 * tooltip control */
6013 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6014 if (infoPtr->pszTooltipText)
6016 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6017 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6018 return 0;
6021 else if (len > 0)
6023 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6024 return 0;
6028 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6030 /* last resort: send notification on to app */
6031 /* FIXME: find out what is really used here */
6032 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6036 inline static LRESULT
6037 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6039 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6040 LPNMHDR lpnmh = (LPNMHDR)lParam;
6042 switch (lpnmh->code)
6044 case PGN_CALCSIZE:
6046 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6048 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6049 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6050 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6051 lppgc->iWidth);
6053 else {
6054 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6055 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6056 lppgc->iHeight);
6058 return 0;
6061 case PGN_SCROLL:
6063 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6065 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6066 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6067 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6068 lppgs->iScroll, lppgs->iDir);
6069 return 0;
6072 case TTN_GETDISPINFOW:
6073 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6075 case TTN_GETDISPINFOA:
6076 FIXME("TTN_GETDISPINFOA - stub\n");
6077 return 0;
6079 default:
6080 return 0;
6085 static LRESULT
6086 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
6088 /* remove this routine when Toolbar is improved to pass infoPtr
6089 * around instead of hwnd.
6091 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6092 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
6096 static LRESULT
6097 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6099 INT i;
6101 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6103 if ((lParam == NF_QUERY) && ((HWND)wParam == infoPtr->hwndToolTip))
6104 return NFR_UNICODE;
6106 if (lParam == NF_REQUERY) {
6107 i = SendMessageA(infoPtr->hwndNotify,
6108 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6109 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
6110 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
6112 i = NFR_ANSI;
6114 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
6115 return (LRESULT)i;
6117 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
6121 static LRESULT
6122 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6124 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6125 HDC hdc;
6126 PAINTSTRUCT ps;
6128 /* fill ps.rcPaint with a default rect */
6129 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6131 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6133 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6134 ps.rcPaint.left, ps.rcPaint.top,
6135 ps.rcPaint.right, ps.rcPaint.bottom);
6137 TOOLBAR_Refresh (hwnd, hdc, &ps);
6138 if (!wParam) EndPaint (hwnd, &ps);
6140 return 0;
6144 static LRESULT
6145 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6146 /*****************************************************
6148 * Function;
6149 * Handles the WM_SETREDRAW message.
6151 * Documentation:
6152 * According to testing V4.71 of COMCTL32 returns the
6153 * *previous* status of the redraw flag (either 0 or 1)
6154 * instead of the MSDN documented value of 0 if handled.
6155 * (For laughs see the "consistency" with same function
6156 * in rebar.)
6158 *****************************************************/
6160 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6161 BOOL oldredraw = infoPtr->bDoRedraw;
6163 TRACE("set to %s\n",
6164 (wParam) ? "TRUE" : "FALSE");
6165 infoPtr->bDoRedraw = (BOOL) wParam;
6166 if (wParam) {
6167 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6169 return (oldredraw) ? 1 : 0;
6173 static LRESULT
6174 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6176 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6177 DWORD dwStyle = infoPtr->dwStyle;
6178 RECT parent_rect;
6179 RECT window_rect;
6180 HWND parent;
6181 INT x, y;
6182 INT cx, cy;
6183 INT flags;
6184 UINT uPosFlags = 0;
6186 /* Resize deadlock check */
6187 if (infoPtr->bAutoSize) {
6188 infoPtr->bAutoSize = FALSE;
6189 return 0;
6192 /* FIXME: optimize to only update size if the new size doesn't */
6193 /* match the current size */
6195 flags = (INT) wParam;
6197 /* FIXME for flags =
6198 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
6201 TRACE("sizing toolbar!\n");
6203 if (flags == SIZE_RESTORED) {
6204 /* width and height don't apply */
6205 parent = GetParent (hwnd);
6206 GetClientRect(parent, &parent_rect);
6207 x = parent_rect.left;
6208 y = parent_rect.top;
6210 if (dwStyle & CCS_NORESIZE) {
6211 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
6214 * this sets the working width of the toolbar, and
6215 * Calc Toolbar will not adjust it, only the height
6217 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6218 cy = infoPtr->nHeight;
6219 cx = infoPtr->nWidth;
6220 TOOLBAR_CalcToolbar (hwnd);
6221 infoPtr->nWidth = cx;
6222 infoPtr->nHeight = cy;
6224 else {
6225 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6226 TOOLBAR_CalcToolbar (hwnd);
6227 cy = infoPtr->nHeight;
6228 cx = infoPtr->nWidth;
6230 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
6231 GetWindowRect(hwnd, &window_rect);
6232 ScreenToClient(parent, (LPPOINT)&window_rect.left);
6233 y = window_rect.top;
6235 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
6236 GetWindowRect(hwnd, &window_rect);
6237 y = parent_rect.bottom -
6238 ( window_rect.bottom - window_rect.top);
6242 if (dwStyle & CCS_NOPARENTALIGN) {
6243 uPosFlags |= SWP_NOMOVE;
6244 cy = infoPtr->nHeight;
6245 cx = infoPtr->nWidth;
6248 if (!(dwStyle & CCS_NODIVIDER))
6249 cy += GetSystemMetrics(SM_CYEDGE);
6251 if (dwStyle & WS_BORDER)
6253 x = y = 1;
6254 cy += GetSystemMetrics(SM_CYEDGE);
6255 cx += GetSystemMetrics(SM_CYEDGE);
6258 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6260 RECT delta_width, delta_height, client, dummy;
6261 DWORD min_x, max_x, min_y, max_y;
6262 TBUTTON_INFO *btnPtr;
6263 INT i;
6265 GetClientRect(hwnd, &client);
6266 if(client.right > infoPtr->client_rect.right)
6268 min_x = infoPtr->client_rect.right;
6269 max_x = client.right;
6271 else
6273 max_x = infoPtr->client_rect.right;
6274 min_x = client.right;
6276 if(client.bottom > infoPtr->client_rect.bottom)
6278 min_y = infoPtr->client_rect.bottom;
6279 max_y = client.bottom;
6281 else
6283 max_y = infoPtr->client_rect.bottom;
6284 min_y = client.bottom;
6287 SetRect(&delta_width, min_x, 0, max_x, min_y);
6288 SetRect(&delta_height, 0, min_y, max_x, max_y);
6290 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6291 btnPtr = infoPtr->buttons;
6292 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6293 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6294 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6295 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6298 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
6299 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6301 GetClientRect(hwnd, &infoPtr->client_rect);
6302 return 0;
6306 static LRESULT
6307 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6309 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6311 if (nType == GWL_STYLE) {
6312 if (lpStyle->styleNew & TBSTYLE_LIST) {
6313 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6315 else {
6316 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6318 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6319 (TBSTYLE_FLAT | TBSTYLE_LIST));
6320 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6322 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6324 infoPtr->dwStyle = lpStyle->styleNew;
6327 TOOLBAR_CalcToolbar(hwnd);
6329 TOOLBAR_AutoSize (hwnd);
6331 InvalidateRect(hwnd, NULL, TRUE);
6333 return 0;
6337 static LRESULT
6338 TOOLBAR_SysColorChange (HWND hwnd)
6340 COMCTL32_RefreshSysColors();
6342 return 0;
6347 static LRESULT WINAPI
6348 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6350 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6352 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6353 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6355 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
6356 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
6358 switch (uMsg)
6360 case TB_ADDBITMAP:
6361 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6363 case TB_ADDBUTTONSA:
6364 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6366 case TB_ADDBUTTONSW:
6367 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6369 case TB_ADDSTRINGA:
6370 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6372 case TB_ADDSTRINGW:
6373 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6375 case TB_AUTOSIZE:
6376 return TOOLBAR_AutoSize (hwnd);
6378 case TB_BUTTONCOUNT:
6379 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6381 case TB_BUTTONSTRUCTSIZE:
6382 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6384 case TB_CHANGEBITMAP:
6385 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6387 case TB_CHECKBUTTON:
6388 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6390 case TB_COMMANDTOINDEX:
6391 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6393 case TB_CUSTOMIZE:
6394 return TOOLBAR_Customize (hwnd);
6396 case TB_DELETEBUTTON:
6397 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6399 case TB_ENABLEBUTTON:
6400 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6402 case TB_GETANCHORHIGHLIGHT:
6403 return TOOLBAR_GetAnchorHighlight (hwnd);
6405 case TB_GETBITMAP:
6406 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6408 case TB_GETBITMAPFLAGS:
6409 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6411 case TB_GETBUTTON:
6412 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6414 case TB_GETBUTTONINFOA:
6415 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6417 case TB_GETBUTTONINFOW:
6418 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6420 case TB_GETBUTTONSIZE:
6421 return TOOLBAR_GetButtonSize (hwnd);
6423 case TB_GETBUTTONTEXTA:
6424 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6426 case TB_GETBUTTONTEXTW:
6427 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6429 case TB_GETDISABLEDIMAGELIST:
6430 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6432 case TB_GETEXTENDEDSTYLE:
6433 return TOOLBAR_GetExtendedStyle (hwnd);
6435 case TB_GETHOTIMAGELIST:
6436 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6438 case TB_GETHOTITEM:
6439 return TOOLBAR_GetHotItem (hwnd);
6441 case TB_GETIMAGELIST:
6442 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6444 /* case TB_GETINSERTMARK: */ /* 4.71 */
6445 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
6447 case TB_GETITEMRECT:
6448 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6450 case TB_GETMAXSIZE:
6451 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6453 /* case TB_GETOBJECT: */ /* 4.71 */
6455 case TB_GETPADDING:
6456 return TOOLBAR_GetPadding (hwnd);
6458 case TB_GETRECT:
6459 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6461 case TB_GETROWS:
6462 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6464 case TB_GETSTATE:
6465 return TOOLBAR_GetState (hwnd, wParam, lParam);
6467 case TB_GETSTRINGA:
6468 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6470 case TB_GETSTRINGW:
6471 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6473 case TB_GETSTYLE:
6474 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6476 case TB_GETTEXTROWS:
6477 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6479 case TB_GETTOOLTIPS:
6480 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6482 case TB_GETUNICODEFORMAT:
6483 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6485 case TB_HIDEBUTTON:
6486 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6488 case TB_HITTEST:
6489 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6491 case TB_INDETERMINATE:
6492 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6494 case TB_INSERTBUTTONA:
6495 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6497 case TB_INSERTBUTTONW:
6498 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6500 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6502 case TB_ISBUTTONCHECKED:
6503 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6505 case TB_ISBUTTONENABLED:
6506 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6508 case TB_ISBUTTONHIDDEN:
6509 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6511 case TB_ISBUTTONHIGHLIGHTED:
6512 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6514 case TB_ISBUTTONINDETERMINATE:
6515 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6517 case TB_ISBUTTONPRESSED:
6518 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6520 case TB_LOADIMAGES:
6521 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6523 case TB_MAPACCELERATORA:
6524 case TB_MAPACCELERATORW:
6525 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6527 case TB_MARKBUTTON:
6528 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6530 case TB_MOVEBUTTON:
6531 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6533 case TB_PRESSBUTTON:
6534 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6536 case TB_REPLACEBITMAP:
6537 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6539 case TB_SAVERESTOREA:
6540 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
6542 case TB_SAVERESTOREW:
6543 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
6545 case TB_SETANCHORHIGHLIGHT:
6546 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6548 case TB_SETBITMAPSIZE:
6549 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6551 case TB_SETBUTTONINFOA:
6552 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6554 case TB_SETBUTTONINFOW:
6555 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6557 case TB_SETBUTTONSIZE:
6558 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6560 case TB_SETBUTTONWIDTH:
6561 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6563 case TB_SETCMDID:
6564 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6566 case TB_SETDISABLEDIMAGELIST:
6567 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6569 case TB_SETDRAWTEXTFLAGS:
6570 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6572 case TB_SETEXTENDEDSTYLE:
6573 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6575 case TB_SETHOTIMAGELIST:
6576 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6578 case TB_SETHOTITEM:
6579 return TOOLBAR_SetHotItem (hwnd, wParam);
6581 case TB_SETIMAGELIST:
6582 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6584 case TB_SETINDENT:
6585 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6587 /* case TB_SETINSERTMARK: */ /* 4.71 */
6589 case TB_SETINSERTMARKCOLOR:
6590 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6592 case TB_SETMAXTEXTROWS:
6593 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6595 case TB_SETPADDING:
6596 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6598 case TB_SETPARENT:
6599 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6601 case TB_SETROWS:
6602 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6604 case TB_SETSTATE:
6605 return TOOLBAR_SetState (hwnd, wParam, lParam);
6607 case TB_SETSTYLE:
6608 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6610 case TB_SETTOOLTIPS:
6611 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6613 case TB_SETUNICODEFORMAT:
6614 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6616 case TB_UNKWN45D:
6617 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6619 case TB_UNKWN45E:
6620 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6622 case TB_UNKWN460:
6623 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6625 case TB_UNKWN462:
6626 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6628 case TB_UNKWN463:
6629 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6631 case TB_UNKWN464:
6632 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6634 /* Common Control Messages */
6636 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6637 case CCM_GETCOLORSCHEME:
6638 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6640 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6641 case CCM_SETCOLORSCHEME:
6642 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6644 case CCM_GETVERSION:
6645 return TOOLBAR_GetVersion (hwnd);
6647 case CCM_SETVERSION:
6648 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6651 /* case WM_CHAR: */
6653 case WM_CREATE:
6654 return TOOLBAR_Create (hwnd, wParam, lParam);
6656 case WM_DESTROY:
6657 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6659 case WM_ERASEBKGND:
6660 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6662 case WM_GETFONT:
6663 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6665 /* case WM_KEYDOWN: */
6666 /* case WM_KILLFOCUS: */
6668 case WM_LBUTTONDBLCLK:
6669 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6671 case WM_LBUTTONDOWN:
6672 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6674 case WM_LBUTTONUP:
6675 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6677 case WM_RBUTTONUP:
6678 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6680 case WM_RBUTTONDBLCLK:
6681 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6683 case WM_MOUSEMOVE:
6684 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6686 case WM_MOUSELEAVE:
6687 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6689 case WM_CAPTURECHANGED:
6690 return TOOLBAR_CaptureChanged(hwnd);
6692 case WM_NCACTIVATE:
6693 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6695 case WM_NCCALCSIZE:
6696 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6698 case WM_NCCREATE:
6699 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6701 case WM_NCPAINT:
6702 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6704 case WM_NOTIFY:
6705 return TOOLBAR_Notify (hwnd, wParam, lParam);
6707 case WM_NOTIFYFORMAT:
6708 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
6710 case WM_PAINT:
6711 return TOOLBAR_Paint (hwnd, wParam);
6713 case WM_SETREDRAW:
6714 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6716 case WM_SIZE:
6717 return TOOLBAR_Size (hwnd, wParam, lParam);
6719 case WM_STYLECHANGED:
6720 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6722 case WM_SYSCOLORCHANGE:
6723 return TOOLBAR_SysColorChange (hwnd);
6725 /* case WM_WININICHANGE: */
6727 case WM_CHARTOITEM:
6728 case WM_COMMAND:
6729 case WM_DRAWITEM:
6730 case WM_MEASUREITEM:
6731 case WM_VKEYTOITEM:
6732 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
6734 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6735 case PGM_FORWARDMOUSE:
6736 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6738 default:
6739 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6740 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6741 uMsg, wParam, lParam);
6742 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6744 return 0;
6748 VOID
6749 TOOLBAR_Register (void)
6751 WNDCLASSA wndClass;
6753 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
6754 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6755 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
6756 wndClass.cbClsExtra = 0;
6757 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6758 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
6759 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
6760 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
6762 RegisterClassA (&wndClass);
6766 VOID
6767 TOOLBAR_Unregister (void)
6769 UnregisterClassA (TOOLBARCLASSNAMEA, NULL);
6772 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6774 HIMAGELIST himlold;
6775 PIMLENTRY c = NULL;
6777 /* Check if the entry already exists */
6778 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6780 /* If this is a new entry we must create it and insert into the array */
6781 if (!c)
6783 PIMLENTRY *pnies;
6785 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
6786 c->id = id;
6788 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
6789 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6790 pnies[*cies] = c;
6791 (*cies)++;
6793 Free(*pies);
6794 *pies = pnies;
6797 himlold = c->himl;
6798 c->himl = himl;
6800 return himlold;
6804 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6806 int i;
6808 for (i = 0; i < *cies; i++)
6809 Free((*pies)[i]);
6811 Free(*pies);
6813 *cies = 0;
6814 *pies = NULL;
6818 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
6820 PIMLENTRY c = NULL;
6822 if (pies != NULL)
6824 int i;
6826 for (i = 0; i < cies; i++)
6828 if (pies[i]->id == id)
6830 c = pies[i];
6831 break;
6836 return c;
6840 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
6842 HIMAGELIST himlDef = 0;
6843 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6845 if (pie)
6846 himlDef = pie->himl;
6848 return himlDef;
6852 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6854 if (infoPtr->bUnicode)
6855 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
6856 else
6858 CHAR Buffer[256];
6859 NMTOOLBARA nmtba;
6860 BOOL bRet = FALSE;
6862 nmtba.iItem = nmtb->iItem;
6863 nmtba.pszText = Buffer;
6864 nmtba.cchText = 256;
6865 ZeroMemory(nmtba.pszText, nmtba.cchText);
6867 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
6869 int ccht = strlen(nmtba.pszText);
6870 if (ccht)
6871 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
6872 nmtb->pszText, nmtb->cchText);
6874 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
6875 bRet = TRUE;
6878 return bRet;
6883 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
6884 int iItem, PCUSTOMBUTTON btnInfo)
6886 NMTOOLBARA nmtb;
6888 nmtb.iItem = iItem;
6889 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
6891 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE);